Fix pb of recursive include in website module

This commit is contained in:
Laurent Destailleur 2017-07-20 16:49:20 +02:00
parent 84f621fde3
commit 3b8f60f90e
8 changed files with 115 additions and 45 deletions

View File

@ -64,3 +64,38 @@ function dolWebsiteOutput($content)
print $content; print $content;
} }
/**
* Clean an HTML page to report only content, so we can include it into another page
* It outputs content of file sanitized from html and body part.
*
* @param string $contentfile Path to file to include (must include website root. Example: 'mywebsite/mypage.php')
* @return void
*/
function dolIncludeHtmlContent($contentfile)
{
global $conf, $db, $langs, $mysoc, $user, $website;
global $includehtmlcontentopened;
$MAXLEVEL=20;
$fullpathfile=DOL_DATA_ROOT.'/websites/'.$contentfile;
//$content = file_get_contents($fullpathfile);
//print preg_replace(array('/^.*<body[^>]*>/ims','/<\/body>.*$/ims'), array('', ''), $content);*/
if (empty($includehtmlcontentopened)) $includehtmlcontentopened=0;
$includehtmlcontentopened++;
if ($includehtmlcontentopened > $MAXLEVEL)
{
print 'ERROR: RECURSIVE CONTENT LEVEL. Depth of recursive call is more than the limit of '.$MAXLEVEL.".\n";
return;
}
$res = include $fullpathfile; // Include because we want to execute code content
if (! $res)
{
print 'ERROR: FAILED TO INCLUDE PAGE '.$contentfile.".\n";
}
$includehtmlcontentopened--;
}

View File

@ -0,0 +1,28 @@
<?php
/* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/
/**
* \file htdocs/core/website.inc.php
* \brief Common file loaded used by all website pages (after master.inc.php)
* The global variable $website must be defined.
*/
include_once DOL_DOCUMENT_ROOT.'/websites/class/website.class.php';
$website=new Website($db);
$website->fetch(0,$websitekey);

View File

@ -19,8 +19,9 @@ AddPage=Add page
HomePage=Home Page HomePage=Home Page
PreviewOfSiteNotYetAvailable=Preview of your website <strong>%s</strong> not yet available. You must first add a page. PreviewOfSiteNotYetAvailable=Preview of your website <strong>%s</strong> not yet available. You must first add a page.
RequestedPageHasNoContentYet=Requested page with id %s has no content yet, or cache file .tpl.php was removed. Edit content of the page to solve this. RequestedPageHasNoContentYet=Requested page with id %s has no content yet, or cache file .tpl.php was removed. Edit content of the page to solve this.
PageDeleted=Page '%s' of website %s deleted PageContent=Page/Content
PageAdded=Page '%s' added PageDeleted=Page/Content '%s' of website %s deleted
PageAdded=Page/Content '%s' added
ViewSiteInNewTab=View site in new tab ViewSiteInNewTab=View site in new tab
ViewPageInNewTab=View page in new tab ViewPageInNewTab=View page in new tab
SetAsHomePage=Set as Home page SetAsHomePage=Set as Home page
@ -30,3 +31,5 @@ SetHereVirtualHost=If you can create, on your web server (Apache, Nginx, ...), a
PreviewSiteServedByWebServer=Preview %s in a new tab.<br><br>The %s will be served by an external web server (like Apache, Nginx, IIS). You must install and setup this server before to point to directory:<br><strong>%s</strong><br>URL served by external server:<br><strong>%s</strong> PreviewSiteServedByWebServer=Preview %s in a new tab.<br><br>The %s will be served by an external web server (like Apache, Nginx, IIS). You must install and setup this server before to point to directory:<br><strong>%s</strong><br>URL served by external server:<br><strong>%s</strong>
PreviewSiteServedByDolibarr=Preview %s in a new tab.<br><br>The %s will be served by Dolibarr server so it does not need any extra web server (like Apache, Nginx, IIS) to be installed.<br>The inconvenient is that URL of pages are not user friendly and start with path of your Dolibarr.<br>URL served by Dolibarr:<br><strong>%s</strong><br><br>To use your own external web server to serve this web site, create a virtual host on your web server that point on directory<br><strong>%s</strong><br>then enter the name of this virtual server and click on the other preview button. PreviewSiteServedByDolibarr=Preview %s in a new tab.<br><br>The %s will be served by Dolibarr server so it does not need any extra web server (like Apache, Nginx, IIS) to be installed.<br>The inconvenient is that URL of pages are not user friendly and start with path of your Dolibarr.<br>URL served by Dolibarr:<br><strong>%s</strong><br><br>To use your own external web server to serve this web site, create a virtual host on your web server that point on directory<br><strong>%s</strong><br>then enter the name of this virtual server and click on the other preview button.
NoPageYet=No pages yet NoPageYet=No pages yet
SyntaxHelp=Help on code syntax
YouCanEditHtmlSource=You can edit HTML source code using the "Source" button in editor. You can also include PHP code into this source using tags <strong>&lt;?php ?&gt;</strong>. The following global variables are available: $conf, $langs, $db, $mysoc, $user, $website.<br>You can also include content of another Page/Content with the following syntax: <strong>&lt;?php dolIncludeHtmlContent($websitekey.'/contentaliastoinclude.php'); ?&gt;</strong>

View File

@ -47,7 +47,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$error=0; $error=0;
$website=GETPOST('website', 'alpha'); $websitekey=GETPOST('website', 'alpha');
$pageid=GETPOST('page', 'alpha')?GETPOST('page', 'alpha'):GETPOST('pageid', 'alpha'); $pageid=GETPOST('page', 'alpha')?GETPOST('page', 'alpha'):GETPOST('pageid', 'alpha');
$accessallowed = 1; $accessallowed = 1;
@ -69,7 +69,7 @@ if (empty($pageid))
require_once DOL_DOCUMENT_ROOT.'/websites/class/websitepage.class.php'; require_once DOL_DOCUMENT_ROOT.'/websites/class/websitepage.class.php';
$object=new Website($db); $object=new Website($db);
$object->fetch(0, $website); $object->fetch(0, $websitekey);
if (empty($object->id)) if (empty($object->id))
{ {
if (empty($pageid)) if (empty($pageid))
@ -125,11 +125,11 @@ if ($pageid == 'css') // No more used ?
//if (empty($dolibarr_nocache)) header('Cache-Control: max-age=3600, public, must-revalidate'); //if (empty($dolibarr_nocache)) header('Cache-Control: max-age=3600, public, must-revalidate');
//else //else
header('Cache-Control: no-cache'); header('Cache-Control: no-cache');
$original_file=$dolibarr_main_data_root.'/websites/'.$website.'/styles.css.php'; $original_file=$dolibarr_main_data_root.'/websites/'.$websitekey.'/styles.css.php';
} }
else else
{ {
$original_file=$dolibarr_main_data_root.'/websites/'.$website.'/page'.$pageid.'.tpl.php'; $original_file=$dolibarr_main_data_root.'/websites/'.$websitekey.'/page'.$pageid.'.tpl.php';
} }
// Find the subdirectory name as the reference // Find the subdirectory name as the reference

View File

@ -3347,6 +3347,11 @@ a.websitebuttonsitepreview img {
width: 26px; width: 26px;
display: inline-block; display: inline-block;
} }
.websitehelp {
vertical-align: middle;
float: right;
padding-top: 8px;
}
/* ============================================================================== */ /* ============================================================================== */

View File

@ -3428,7 +3428,11 @@ a.websitebuttonsitepreview img {
.websiteiframenoborder { .websiteiframenoborder {
border: 0px; border: 0px;
} }
.websitehelp {
vertical-align: middle;
float: right;
padding-top: 8px;
}
/* ============================================================================== */ /* ============================================================================== */
/* Module agenda */ /* Module agenda */

View File

@ -48,11 +48,6 @@ class Website extends CommonObject
*/ */
public $table_element = 'website'; public $table_element = 'website';
/**
* @var WebsitePage[] Lines of all pages
*/
public $lines = array();
/** /**
* @var int * @var int
*/ */
@ -87,12 +82,6 @@ class Website extends CommonObject
public $virtualhost; public $virtualhost;
public $records;
/**
*/
/** /**
* Constructor * Constructor
* *
@ -218,7 +207,7 @@ class Website extends CommonObject
$sql .= " t.tms"; $sql .= " t.tms";
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
if (null !== $ref) { if (null !== $ref) {
$sql .= ' WHERE t.ref = ' . '\'' . $ref . '\''; $sql .= " WHERE t.ref = '" . $this->db->escape($ref) . "'";
} else { } else {
$sql .= ' WHERE t.rowid = ' . $id; $sql .= ' WHERE t.rowid = ' . $id;
} }

View File

@ -245,7 +245,7 @@ if ($action == 'updatecss')
// Html header file // Html header file
$htmlheadercontent = '<!-- BEGIN DOLIBARR-WEBSITE-ADDED-HEADER -->'."\n"; $htmlheadercontent = '<!-- BEGIN DOLIBARR-WEBSITE-ADDED-HEADER -->'."\n";
$htmlheadercontent.= '<!-- File generated to save common html header - YOU CAN MODIFY DIRECTLY THIS FILE. Change affects all pages of website. -->'."\n"; $htmlheadercontent.= '<!-- File generated to save common html header - YOU CAN MODIFY DIRECTLY THE FILE header.html. Change affects all pages of website. -->'."\n";
$htmlheadercontent.= '<!-- END -->'."\n"; $htmlheadercontent.= '<!-- END -->'."\n";
$htmlheadercontent.= GETPOST('WEBSITE_HTML_HEADER'); $htmlheadercontent.= GETPOST('WEBSITE_HTML_HEADER');
@ -264,7 +264,7 @@ if ($action == 'updatecss')
// Css file // Css file
$csscontent = '<!-- BEGIN DOLIBARR-WEBSITE-ADDED-HEADER -->'."\n"; $csscontent = '<!-- BEGIN DOLIBARR-WEBSITE-ADDED-HEADER -->'."\n";
$csscontent.= '<!-- File generated to wrap the css file - YOU CAN MODIFY DIRECTLY THIS FILE. Change affects all pages of website. -->'."\n"; $csscontent.= '<!-- File generated to wrap the css file - YOU CAN MODIFY DIRECTLY THE FILE styles.css.php. Change affects all pages of website. -->'."\n";
$csscontent.= '<?php '."\n"; $csscontent.= '<?php '."\n";
$csscontent.= "header('Content-type: text/css');\n"; $csscontent.= "header('Content-type: text/css');\n";
$csscontent.= "?>"."\n"; $csscontent.= "?>"."\n";
@ -372,12 +372,13 @@ if ($action == 'updatemeta')
// Now generate the master.inc.php page // Now generate the master.inc.php page
dol_syslog("We regenerate the master file"); dol_syslog("We regenerate the master file (because we update meta)");
dol_delete_file($filemaster); dol_delete_file($filemaster);
$mastercontent = '<?php'."\n"; $mastercontent = '<?php'."\n";
$mastercontent.= '// File generated to link to the master file - DO NOT MODIFY - It is just an include'."\n"; $mastercontent.= '// File generated to link to the master file - DO NOT MODIFY - It is just an include'."\n";
$mastercontent.= "if (! defined('USEDOLIBARRSERVER')) require '".DOL_DOCUMENT_ROOT."/master.inc.php';\n"; $mastercontent.= "if (! defined('USEDOLIBARRSERVER')) require '".DOL_DOCUMENT_ROOT."/master.inc.php';\n";
$mastercontent.= '$website = new WebSite($db)'."\n";
$mastercontent.= '?>'."\n"; $mastercontent.= '?>'."\n";
$result = file_put_contents($filemaster, $mastercontent); $result = file_put_contents($filemaster, $mastercontent);
if (! empty($conf->global->MAIN_UMASK)) if (! empty($conf->global->MAIN_UMASK))
@ -565,8 +566,10 @@ if ($action == 'updatecontent' || GETPOST('refreshsite') || GETPOST('refreshpage
$tplcontent =''; $tplcontent ='';
$tplcontent.= "<?php // BEGIN PHP\n"; $tplcontent.= "<?php // BEGIN PHP\n";
$tplcontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
$tplcontent.= "if (! defined('USEDOLIBARRSERVER')) { require './master.inc.php'; } // Not already loaded"."\n"; $tplcontent.= "if (! defined('USEDOLIBARRSERVER')) { require './master.inc.php'; } // Not already loaded"."\n";
$tplcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n"; $tplcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
$tplcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
$tplcontent.= "ob_start();\n"; $tplcontent.= "ob_start();\n";
$tplcontent.= "// END PHP ?>\n"; $tplcontent.= "// END PHP ?>\n";
$tplcontent.= '<html>'."\n"; $tplcontent.= '<html>'."\n";
@ -746,12 +749,9 @@ if (count($object->records) > 0)
$urlext=$virtualurl; $urlext=$virtualurl;
$urlint=$urlwithroot.'/public/websites/index.php?website='.$website; $urlint=$urlwithroot.'/public/websites/index.php?website='.$website;
//if (! empty($object->virtualhost)) print '<a class="websitebuttonsitepreview" id="previewsiteext" href="'.$urlext.'" target="tab'.$website.'ext" alt="'.dol_escape_htmltag($langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $dataroot, $urlext)).'">';
//{ print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $dataroot, $urlext?$urlext:$langs->trans("VirtualHostUrlNotDefined")), 1, 'preview_ext');
print '<a class="websitebuttonsitepreview" id="previewsiteext" href="'.$urlext.'" target="tab'.$website.'" alt="'.dol_escape_htmltag($langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $dataroot, $urlext)).'">'; print '</a>';
print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $dataroot, $urlext?$urlext:$langs->trans("VirtualHostUrlNotDefined")), 1, 'preview_ext');
print '</a>';
//}
print '<a class="websitebuttonsitepreview" id="previewsite" href="'.$urlwithroot.'/public/websites/index.php?website='.$website.'" target="tab'.$website.'" alt="'.dol_escape_htmltag($langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $urlint)).'">'; print '<a class="websitebuttonsitepreview" id="previewsite" href="'.$urlwithroot.'/public/websites/index.php?website='.$website.'" target="tab'.$website.'" alt="'.dol_escape_htmltag($langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $urlint)).'">';
print $form->textwithpicto('', $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $urlint, $dataroot), 1, 'preview'); print $form->textwithpicto('', $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $urlint, $dataroot), 1, 'preview');
@ -822,7 +822,6 @@ if (count($object->records) > 0)
} }
print '<input type="submit" class="button" name="refreshpage" value="'.$langs->trans("Load").'"'.($atleastonepage?'':' disabled="disabled"').'>'; print '<input type="submit" class="button" name="refreshpage" value="'.$langs->trans("Load").'"'.($atleastonepage?'':' disabled="disabled"').'>';
//print $form->selectarray('page', $array);
if ($action == 'preview') if ($action == 'preview')
{ {
@ -843,8 +842,6 @@ if (count($object->records) > 0)
} }
} }
print '</div>';
print '<div class="websiteselection">';
print '</div>'; print '</div>';
print '<div class="websitetools">'; print '<div class="websitetools">';
@ -859,7 +856,6 @@ if (count($object->records) > 0)
print '<div class="websiteinputurl">'; print '<div class="websiteinputurl">';
print '<input type="text" id="previewpageurl" class="minwidth200imp" name="previewsite" value="'.$pagealias.'" disabled="disabled">'; print '<input type="text" id="previewpageurl" class="minwidth200imp" name="previewsite" value="'.$pagealias.'" disabled="disabled">';
//print '<input type="submit" class="button" name="previewwebsite" target="tab'.$website.'" value="'.$langs->trans("ViewSiteInNewTab").'">';
$htmltext=$langs->trans("PageNameAliasHelp", $langs->transnoentitiesnoconv("EditPageMeta")); $htmltext=$langs->trans("PageNameAliasHelp", $langs->transnoentitiesnoconv("EditPageMeta"));
print $form->textwithpicto('', $htmltext, 1, 'help', '', 0, 2, 'helppagealias'); print $form->textwithpicto('', $htmltext, 1, 'help', '', 0, 2, 'helppagealias');
print '</div>'; print '</div>';
@ -867,7 +863,7 @@ if (count($object->records) > 0)
if (! empty($object->virtualhost)) if (! empty($object->virtualhost))
{ {
$urlext=$virtualurl.'/'.$pagealias.'.php'; $urlext=$virtualurl.'/'.$pagealias.'.php';
print '<a class="websitebuttonsitepreview" id="previewpageext" href="'.$urlext.'" target="tab'.$website.'" alt="'.dol_escape_htmltag($langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $urlext)).'">'; print '<a class="websitebuttonsitepreview" id="previewpageext" href="'.$urlext.'" target="tab'.$website.'ext" alt="'.dol_escape_htmltag($langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $urlext)).'">';
print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $urlext?$urlext:$langs->trans("VirtualHostUrlNotDefined")), 1, 'preview_ext'); print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $urlext?$urlext:$langs->trans("VirtualHostUrlNotDefined")), 1, 'preview_ext');
print '</a>'; print '</a>';
} }
@ -894,6 +890,16 @@ if (count($object->records) > 0)
print '</div>'; print '</div>';
print '<div class="websitehelp">';
if (GETPOST('editcontent', 'alpha'))
{
$htmltext=$langs->transnoentitiesnoconv("YouCanEditHtmlSource");
print $form->textwithpicto($langs->trans("SyntaxHelp"), $htmltext, 1, 'help', 'inline-block', 0, 2, 'tooltipsubstitution');
}
print '</div>';
if ($action == 'preview') if ($action == 'preview')
{ {
// Adding jquery code to change on the fly url of preview ext // Adding jquery code to change on the fly url of preview ext