From f3de6cfd3275b29cbee9323d6fb57c316415c53c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 23 Jul 2017 17:44:26 +0200 Subject: [PATCH] Support for robots and .htaccess file --- htdocs/websites/index.php | 125 ++++++++++++++++++++++++++++++++++---- 1 file changed, 112 insertions(+), 13 deletions(-) diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index c8ba93c86f1..0f1e813e3ed 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -138,6 +138,8 @@ global $dolibarr_main_data_root; $pathofwebsite=$dolibarr_main_data_root.'/websites/'.$website; $filehtmlheader=$pathofwebsite.'/htmlheader.html'; $filecss=$pathofwebsite.'/styles.css.php'; +$filerobot=$pathofwebsite.'/robots.txt'; +$filehtaccess=$pathofwebsite.'/.htaccess'; $filetpl=$pathofwebsite.'/page'.$pageid.'.tpl.php'; $fileindex=$pathofwebsite.'/index.php'; @@ -311,7 +313,6 @@ if ($action == 'updatecss') $csscontent.= '$tmp = ob_get_contents(); ob_end_clean(); dolWebsiteOutput($tmp);'."\n"; $csscontent.= "// END PHP ?>"."\n"; - dol_syslog("Save file css into ".$filecss); dol_mkdir($pathofwebsite); @@ -326,6 +327,70 @@ if ($action == 'updatecss') } + // Css file + $robotcontent =''; + + /*$robotcontent.= "\n";*/ + + $robotcontent.= GETPOST('WEBSITE_ROBOT'); + + /*$robotcontent.= "\n".'"."\n";*/ + + dol_syslog("Save file robot into ".$filerobot); + + dol_mkdir($pathofwebsite); + $result = file_put_contents($filerobot, $robotcontent); + if (! empty($conf->global->MAIN_UMASK)) + @chmod($filerobot, octdec($conf->global->MAIN_UMASK)); + + if (! $result) + { + $error++; + setEventMessages('Failed to write file '.$filerobot, null, 'errors'); + } + + + // Css file + $htaccesscontent =''; + + /*$robotcontent.= "\n";*/ + + $htaccesscontent.= GETPOST('WEBSITE_HTACCESS'); + + /*$robotcontent.= "\n".'"."\n";*/ + + dol_syslog("Save file htaccess into ".$filehtaccess); + + dol_mkdir($pathofwebsite); + $result = file_put_contents($filehtaccess, $htaccesscontent); + if (! empty($conf->global->MAIN_UMASK)) + @chmod($filehtaccess, octdec($conf->global->MAIN_UMASK)); + + if (! $result) + { + $error++; + setEventMessages('Failed to write file '.$filehtaccess, null, 'errors'); + } + + // Message if no error if (! $error) { setEventMessages($langs->trans("Saved"), null, 'mesgs'); @@ -1098,30 +1163,49 @@ if ($action == 'editcss') $csscontent = @file_get_contents($filecss); // Clean the php css file to remove php code and get only css part $csscontent = preg_replace('/<\?php \/\/ BEGIN PHP.*END PHP \?>\n*/ims', '', $csscontent); - $csscontent.= GETPOST('WEBSITE_CSS_INLINE'); - if (! trim($csscontent)) $csscontent='/* CSS content (all pages) */'."\n".'body.bodywebsite { margin: 0; }'; - $htmlheader = @file_get_contents($filehtmlheader); // Clean the php htmlheader file to remove php code and get only html part $htmlheader = preg_replace('/<\?php \/\/ BEGIN PHP.*END PHP \?>\n*/ims', '', $htmlheader); - if (! trim($htmlheader)) $htmlheader=''."\n".''."\n".''; else $htmlheader=''."\n".$htmlheader."\n".''; + $robotcontent = @file_get_contents($filerobot); + // Clean the php htmlheader file to remove php code and get only html part + $robotcontent = preg_replace('/<\?php \/\/ BEGIN PHP.*END PHP \?>\n*/ims', '', $robotcontent); + if (! trim($robotcontent)) + { + $robotcontent.="# Robot file. Generated with ".DOL_APPLICATION_TITLE."\n"; + $robotcontent.="User-agent: *\n"; + $robotcontent.="Allow: /public/\n"; + $robotcontent.="Disallow: /administrator/\n"; + } + + $htaccesscontent = @file_get_contents($filehtaccess); + // Clean the php htmlheader file to remove php code and get only html part + $htaccesscontent = preg_replace('/<\?php \/\/ BEGIN PHP.*END PHP \?>\n*/ims', '', $htaccesscontent); + if (! trim($htaccesscontent)) + { + $htaccesscontent.="# Order allow,deny\n"; + $htaccesscontent.="# Deny from all\n"; + } + //else $htaccesscontent=''."\n".$htaccesscontent."\n".'';*/ + dol_fiche_head(); print ''."\n"; print ''; + // Website print ''; + // CSS file print ''; + // Common HTML header print ''; + + // Robot file + print ''; + + // .htaccess + print ''; print '
'; print $langs->trans('WebSite'); print ''; print $website; print '
'; print $langs->trans('WEBSITE_CSS_INLINE'); print ''; @@ -1129,11 +1213,9 @@ if ($action == 'editcss') $doleditor=new DolEditor('WEBSITE_CSS_INLINE', $csscontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', ''); print $doleditor->Create(1, '', true, 'CSS', 'css'); - /*print '';*/ print '
'; print $langs->trans('WEBSITE_HTML_HEADER'); print ''; @@ -1141,9 +1223,26 @@ if ($action == 'editcss') $doleditor=new DolEditor('WEBSITE_HTML_HEADER', $htmlheader, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', ''); print $doleditor->Create(1, '', true, 'HTML Header', 'html'); - /*print '';*/ + print '
'; + print $langs->trans('WEBSITE_ROBOT'); + print ''; + + $doleditor=new DolEditor('WEBSITE_ROBOT', $robotcontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', ''); + print $doleditor->Create(1, '', true, 'Robot file', 'txt'); + + print '
'; + print $langs->trans('WEBSITE_HTACCESS'); + print ''; + + $doleditor=new DolEditor('WEBSITE_HTACCESS', $htaccesscontent, '', '220', 'ace', 'In', true, false, 'ace', 0, '100%', ''); + print $doleditor->Create(1, '', true, $langs->trans("File").' .htaccess', 'txt'); + print '
'; @@ -1242,7 +1341,7 @@ if ($action == 'editsource') * Editing global variables not related to a specific theme */ - $csscontent = @file_get_contents($filecss); + //$csscontent = @file_get_contents($filecss); $contentforedit = ''; /*$contentforedit.='