Work on website module

This commit is contained in:
Laurent Destailleur
2018-09-24 17:12:51 +02:00
parent 9dc4ad4cc3
commit f1b0bd2a5d
4 changed files with 48 additions and 32 deletions

View File

@@ -96,7 +96,7 @@ function dolWebsiteOutput($content)
global $db, $langs, $conf, $user;
global $dolibarr_main_url_root, $dolibarr_main_data_root;
dol_syslog("dolWebsiteOutput start (mode=".(defined('USEDOLIBARRSERVER')?'USEDOLIBARRSERVER':'').')');
dol_syslog("dolWebsiteOutput start (USEDOLIBARRSERVER=".(defined('USEDOLIBARRSERVER')?'1':'')." (USEDOLIBARREDITOR=".(defined('USEDOLIBARREDITOR')?'1':'').')');
// Define $urlwithroot
$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
@@ -104,8 +104,11 @@ function dolWebsiteOutput($content)
//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
// Note: This seems never called when page is output inside the website editor (search 'REPLACEMENT OF LINKS When page called by website editor')
if (defined('USEDOLIBARRSERVER')) // REPLACEMENT OF LINKS When page called from Dolibarr server
if (defined('USEDOLIBARREDITOR'))
{
// Do nothing
}
elseif (defined('USEDOLIBARRSERVER') || defined('USEDOLIBARREDITOR')) // REPLACEMENT OF LINKS When page called from Dolibarr server
{
global $website;
@@ -536,7 +539,7 @@ function dolSaveMasterFile($filemaster)
$mastercontent = '<?php'."\n";
$mastercontent.= '// File generated to link to the master file - DO NOT MODIFY - It is just an include'."\n";
$mastercontent.= "if (! defined('USEDOLIBARRSERVER')) require_once '".DOL_DOCUMENT_ROOT."/master.inc.php';\n";
$mastercontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) require_once '".DOL_DOCUMENT_ROOT."/master.inc.php';\n";
$mastercontent.= '?>'."\n";
$result = file_put_contents($filemaster, $mastercontent);
if (! empty($conf->global->MAIN_UMASK))
@@ -598,7 +601,7 @@ function dolSavePageContent($filetpl, $object, $objectpage)
$tplcontent ='';
$tplcontent.= "<?php // BEGIN PHP\n";
$tplcontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
$tplcontent.= "if (! defined('USEDOLIBARRSERVER')) { require_once './master.inc.php'; } // Not already loaded"."\n";
$tplcontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './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/website.inc.php';\n";
$tplcontent.= "ob_start();\n";
@@ -663,7 +666,7 @@ function dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper)
$indexcontent = '<?php'."\n";
$indexcontent.= "// BEGIN PHP File generated to provide an index.php as Home Page or alias redirector - DO NOT MODIFY - It is just a generated wrapper.\n";
$indexcontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
$indexcontent.= "if (! defined('USEDOLIBARRSERVER')) { require_once './master.inc.php'; } // Load master if not already loaded\n";
$indexcontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Load master if not already loaded\n";
$indexcontent.= 'if (! empty($_GET[\'pageref\']) || ! empty($_GET[\'pagealiasalt\']) || ! empty($_GET[\'pageid\'])) {'."\n";
$indexcontent.= " require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
$indexcontent.= " require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
@@ -679,7 +682,7 @@ function dolSaveIndexPage($pathofwebsite, $fileindex, $filetpl, $filewrapper)
$wrappercontent = '<?php'."\n";
$wrappercontent.= "// BEGIN PHP File generated to provide a wrapper.php - DO NOT MODIFY - It is just a generated wrapper.\n";
$wrappercontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
$wrappercontent.= "if (! defined('USEDOLIBARRSERVER')) { require_once './master.inc.php'; } // Load master if not already loaded\n";
$wrappercontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Load master if not already loaded\n";
$wrappercontent.= '$original_file=str_replace("../","/", GETPOST("file","alpha"));'."\n";
$wrappercontent.= 'if ($_GET["modulepart"] == "mycompany" && preg_match(\'/^\/?logos\//\', $original_file)) readfile(dol_osencode($conf->mycompany->dir_output."/".$original_file));'."\n";
$wrappercontent.= "else print 'Bad value for modulepart or file';\n";

View File

@@ -639,10 +639,11 @@ class Website extends CommonObject
if (! $error)
{
$filetpl=$pathofwebsitenew.'/page'.$newidforhome.'.tpl.php';
$filewrapper=$pathofwebsitenew.'/wrapper.php';
// Generate the index.php page to be the home page
//-------------------------------------------------
$result = dolSaveIndexPage($pathofwebsitenew, $fileindex, $filetpl);
$result = dolSaveIndexPage($pathofwebsitenew, $fileindex, $filetpl, $filewrapper);
}
}

View File

@@ -130,7 +130,7 @@ class WebsitePage extends CommonObject
* Load object in memory from the database
*
* @param int $id Id object.
* - If this is 0, the value into $page will be used. If not found of $page not defined, the default page of website_id will be used or the first page found if not set.
* - If this is 0, the value into $page will be used. If not found or $page not defined, the default page of website_id will be used or the first page found if not set.
* - If value is < 0, we must exclude this ID.
* @param string $website_id Web site id (page name must also be filled if this parameter is used)
* @param string $page Page name (website id must also be filled if this parameter is used)

View File

@@ -109,7 +109,35 @@ if ($websitekey)
}
$website = $object;
// Define pageid if pageif and pageref not received as parameter
// Check pageid received as aprameter
if ($pageid < 0) $pageid = 0;
if (($pageid > 0 || $pageref) && $action != 'addcontainer')
{
$res = $objectpage->fetch($pageid, ($object->id > 0 ? $object->id : null), $pageref);
// Check if pageid is inside the new website, if not we reset param pageid
if ($res >= 0 && $object->id > 0)
{
if ($objectpage->fk_website != $object->id) // We have a bad page.
{
$res = $objectpage->fetch(0, $object->id, ''); // We search first page of web site
if ($res == 0) // Page was not found, we reset it
{
$objectpage=new WebsitePage($db);
}
else // We found a page, we set pageid to it.
{
$pageid = $objectpage->id;
}
}
else // We have a valid page. We force pageid for the case we got the page with a fetch on ref.
{
$pageid = $objectpage->id;
}
}
}
// Define pageid if pageid and pageref not received as parameter or was wrong
if (empty($pageid) && empty($pageref) && $object->id > 0 && $action != 'createcontainer')
{
$pageid = $object->fk_default_home;
@@ -129,22 +157,6 @@ if (empty($pageid) && empty($pageref) && $object->id > 0 && $action != 'createco
}
}
if ($pageid < 0) $pageid = 0;
if (($pageid > 0 || $pageref) && $action != 'addcontainer')
{
$res = $objectpage->fetch($pageid, ($object->id > 0 ? $object->id : null), $pageref);
// Check if pageid is inside the new website, if not we reset param pageid
if ($object->id > 0 && ($objectpage->fk_website != $object->id))
{
$res = $objectpage->fetch(0, $object->id, '');;
if ($res == 0) // Page was not found, we reset it
{
$objectpage=new WebsitePage($db);
}
}
$pageid = $objectpage->id;
}
global $dolibarr_main_data_root;
$pathofwebsite=$dolibarr_main_data_root.'/website/'.$websitekey;
@@ -836,7 +848,7 @@ if ($action == 'updatecss')
/* We disable php code since htmlheader is never executed as an include but only read by fgets_content.
$htmlheadercontent.= "<?php // BEGIN PHP\n";
$htmlheadercontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
$htmlheadercontent.= "if (! defined('USEDOLIBARRSERVER')) { require_once './master.inc.php'; } // Not already loaded"."\n";
$htmlheadercontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Not already loaded"."\n";
$htmlheadercontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
$htmlheadercontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
$htmlheadercontent.= "ob_start();\n";
@@ -859,7 +871,7 @@ if ($action == 'updatecss')
$csscontent.= "<?php // BEGIN PHP\n";
$csscontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
$csscontent.= "if (! defined('USEDOLIBARRSERVER')) { require_once dirname(__FILE__).'/master.inc.php'; } // Not already loaded"."\n"; // For the css, we need to set path of master using the dirname of css file.
$csscontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once dirname(__FILE__).'/master.inc.php'; } // Not already loaded"."\n"; // For the css, we need to set path of master using the dirname of css file.
$csscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
$csscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
$csscontent.= "ob_start();\n";
@@ -891,7 +903,7 @@ if ($action == 'updatecss')
$jscontent.= "<?php // BEGIN PHP\n";
$jscontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
$jscontent.= "if (! defined('USEDOLIBARRSERVER')) { require_once dirname(__FILE__).'/master.inc.php'; } // Not already loaded"."\n"; // For the css, we need to set path of master using the dirname of css file.
$jscontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once dirname(__FILE__).'/master.inc.php'; } // Not already loaded"."\n"; // For the css, we need to set path of master using the dirname of css file.
$jscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
$jscontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
$jscontent.= "ob_start();\n";
@@ -923,7 +935,7 @@ if ($action == 'updatecss')
/*$robotcontent.= "<?php // BEGIN PHP\n";
$robotcontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
$robotcontent.= "if (! defined('USEDOLIBARRSERVER')) { require_once './master.inc.php'; } // Not already loaded"."\n";
$robotcontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Not already loaded"."\n";
$robotcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
$robotcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
$robotcontent.= "ob_start();\n";
@@ -955,7 +967,7 @@ if ($action == 'updatecss')
/*$robotcontent.= "<?php // BEGIN PHP\n";
$robotcontent.= '$websitekey=basename(dirname(__FILE__));'."\n";
$robotcontent.= "if (! defined('USEDOLIBARRSERVER')) { require_once './master.inc.php'; } // Not already loaded"."\n";
$robotcontent.= "if (! defined('USEDOLIBARRSERVER') && ! defined('USEDOLIBARREDITOR')) { require_once './master.inc.php'; } // Not already loaded"."\n";
$robotcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/lib/website.lib.php';\n";
$robotcontent.= "require_once DOL_DOCUMENT_ROOT.'/core/website.inc.php';\n";
$robotcontent.= "ob_start();\n";
@@ -2632,7 +2644,7 @@ if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpa
// If mode WEBSITE_SUBCONTAINERSINLINE is on
if (! empty($conf->global->WEBSITE_SUBCONTAINERSINLINE))
{
define('USEDOLIBARRSERVER', 1);
define('USEDOLIBARREDITOR', 1);
//var_dump($filetpl);
$filephp = $filetpl;
ob_start();