diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php index 37f01a0ffe3..336a82b4697 100644 --- a/htdocs/core/lib/website.lib.php +++ b/htdocs/core/lib/website.lib.php @@ -64,3 +64,38 @@ function dolWebsiteOutput($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('/^.*]*>/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--; +} + diff --git a/htdocs/core/website.inc.php b/htdocs/core/website.inc.php new file mode 100644 index 00000000000..65db787734a --- /dev/null +++ b/htdocs/core/website.inc.php @@ -0,0 +1,28 @@ + + * +* 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 . +* 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); diff --git a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql index faf196a9802..386ae968505 100644 --- a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql +++ b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql @@ -573,3 +573,7 @@ UPDATE llx_bank SET label= '(CustomerInvoicePayment)' WHERE label= 'Règlement c UPDATE llx_bank SET label= '(payment_salary)' WHERE label LIKE 'Règlement salaire'; ALTER TABLE llx_mailing_cibles MODIFY COLUMN source_url varchar(255); + +-- VPGSQL8.2 CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_website FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms(); +-- VPGSQL8.2 CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_website_page FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms(); + diff --git a/htdocs/install/pgsql/functions/functions.sql b/htdocs/install/pgsql/functions/functions.sql index 2e4125e39e4..06ef2ed41e3 100644 --- a/htdocs/install/pgsql/functions/functions.sql +++ b/htdocs/install/pgsql/functions/functions.sql @@ -163,6 +163,8 @@ CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_user_extrafields FOR CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_usergroup FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms(); CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_usergroup_extrafields FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms(); CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_product_price_by_qty FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms(); +CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_website FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms(); +CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_website_page FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms(); -- Add triggers for timestamp fields named date_m diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang index db890ca56af..07304f2a464 100644 --- a/htdocs/langs/en_US/website.lang +++ b/htdocs/langs/en_US/website.lang @@ -19,8 +19,9 @@ AddPage=Add page HomePage=Home Page PreviewOfSiteNotYetAvailable=Preview of your website %s 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. -PageDeleted=Page '%s' of website %s deleted -PageAdded=Page '%s' added +PageContent=Page/Content +PageDeleted=Page/Content '%s' of website %s deleted +PageAdded=Page/Content '%s' added ViewSiteInNewTab=View site in new tab ViewPageInNewTab=View page in new tab SetAsHomePage=Set as Home page @@ -30,4 +31,6 @@ SetHereVirtualHost=If you can create, on your web server (Apache, Nginx, ...), a PreviewSiteServedByWebServer=Preview %s in a new tab.

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:
%s
URL served by external server:
%s PreviewSiteServedByDolibarr=Preview %s in a new tab.

The %s will be served by Dolibarr server so it does not need any extra web server (like Apache, Nginx, IIS) to be installed.
The inconvenient is that URL of pages are not user friendly and start with path of your Dolibarr.
URL served by Dolibarr:
%s

To use your own external web server to serve this web site, create a virtual host on your web server that point on directory
%s
then enter the name of this virtual server and click on the other preview button. VirtualHostUrlNotDefined=URL of the virtual host served by external web server not defined -NoPageYet=No pages yet \ No newline at end of file +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 <?php ?>. The following global variables are available: $conf, $langs, $db, $mysoc, $user, $website.
You can also include content of another Page/Content with the following syntax: <?php dolIncludeHtmlContent($websitekey.'/contentaliastoinclude.php'); ?> diff --git a/htdocs/public/websites/index.php b/htdocs/public/websites/index.php index 0bc85dce463..a2dcbfc3dc6 100644 --- a/htdocs/public/websites/index.php +++ b/htdocs/public/websites/index.php @@ -47,7 +47,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $error=0; -$website=GETPOST('website', 'alpha'); +$websitekey=GETPOST('website', 'alpha'); $pageid=GETPOST('page', 'alpha')?GETPOST('page', 'alpha'):GETPOST('pageid', 'alpha'); $accessallowed = 1; @@ -69,7 +69,7 @@ if (empty($pageid)) require_once DOL_DOCUMENT_ROOT.'/websites/class/websitepage.class.php'; $object=new Website($db); - $object->fetch(0, $website); + $object->fetch(0, $websitekey); if (empty($object->id)) { 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'); //else 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 { - $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 diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index a42ed7bf6a0..06015d69a2b 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -3353,6 +3353,11 @@ a.websitebuttonsitepreview img { a.websitebuttonsitepreviewdisabled img { opacity: 0.2; } +.websitehelp { + vertical-align: middle; + float: right; + padding-top: 8px; +} /* ============================================================================== */ diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index 4a396fadc7b..11fd6b9650a 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -3428,10 +3428,17 @@ a.websitebuttonsitepreview img { width: 26px; display: inline-block; } +a.websitebuttonsitepreviewdisabled img { + opacity: 0.2; +} .websiteiframenoborder { border: 0px; } - +.websitehelp { + vertical-align: middle; + float: right; + padding-top: 8px; +} /* ============================================================================== */ /* Module agenda */ diff --git a/htdocs/websites/class/website.class.php b/htdocs/websites/class/website.class.php index 167e186e124..df8d4b07e79 100644 --- a/htdocs/websites/class/website.class.php +++ b/htdocs/websites/class/website.class.php @@ -48,11 +48,6 @@ class Website extends CommonObject */ public $table_element = 'website'; - /** - * @var WebsitePage[] Lines of all pages - */ - public $lines = array(); - /** * @var int */ @@ -87,12 +82,6 @@ class Website extends CommonObject public $virtualhost; - public $records; - - /** - */ - - /** * Constructor * @@ -146,8 +135,8 @@ class Website extends CommonObject $sql.= 'status,'; $sql.= 'fk_default_home,'; $sql.= 'virtualhost,'; - $sql.= 'fk_user_create'; - $sql.= 'date_creation'; + $sql.= 'fk_user_create,'; + $sql.= 'date_creation,'; $sql.= 'tmps'; $sql .= ') VALUES ('; $sql .= ' '.(! isset($this->entity)?'NULL':$this->entity).','; @@ -222,7 +211,7 @@ class Website extends CommonObject $sql .= " t.tms"; $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; if (null !== $ref) { - $sql .= ' WHERE t.ref = ' . '\'' . $ref . '\''; + $sql .= " WHERE t.ref = '" . $this->db->escape($ref) . "'"; } else { $sql .= ' WHERE t.rowid = ' . $id; } diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index 874679892d5..3a03c16a17c 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -379,12 +379,13 @@ if ($action == 'updatemeta') // 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); $mastercontent = ''."\n"; $result = file_put_contents($filemaster, $mastercontent); if (! empty($conf->global->MAIN_UMASK)) @@ -572,8 +573,10 @@ if ($action == 'updatecontent' || ($action == 'preview' && (GETPOST('refreshsite $tplcontent =''; $tplcontent.= "\n"; $tplcontent.= ''."\n"; @@ -759,8 +762,8 @@ if (count($object->records) > 0) $urlext=$virtualurl; $urlint=$urlwithroot.'/public/websites/index.php?website='.$website; - print '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 '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 ''; print 'transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $urlint)).'">'; @@ -832,7 +835,6 @@ if (count($object->records) > 0) } print ''; - //print $form->selectarray('page', $array); if ($action == 'preview') { @@ -853,8 +855,6 @@ if (count($object->records) > 0) } } - print ''; - print '
'; print '
'; print '
'; + print '
'; + if (GETPOST('editcontent', 'alpha')) + { + $htmltext=$langs->transnoentitiesnoconv("YouCanEditHtmlSource"); + print $form->textwithpicto($langs->trans("SyntaxHelp"), $htmltext, 1, 'help', 'inline-block', 0, 2, 'tooltipsubstitution'); + } + print '
'; + + + if ($action == 'preview') { // Adding jquery code to change on the fly url of preview ext