diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php index af0114c9c97..60016b2f2e9 100644 --- a/htdocs/core/lib/website.lib.php +++ b/htdocs/core/lib/website.lib.php @@ -725,37 +725,39 @@ function getPagesFromSearchCriterias($type, $algo, $searchstring, $max = 25) if (! $error && (empty($max) || ($found < $max)) && (preg_match('/sitefiles/', $algo))) { - $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'website'; - $sql.= " WHERE rowid = ".$website->id; - $sql.= " AND ("; - $searchalgo = ''; - // TODO - $searchalgo.= '...'; + global $dolibarr_main_data_root; - $sql.=$searchalgo; - $sql.= ")"; - $sql.= $db->plimit($max); + $pathofwebsite=$dolibarr_main_data_root.'/website/'.$website->ref; + $filehtmlheader=$pathofwebsite.'/htmlheader.html'; + $filecss=$pathofwebsite.'/styles.css.php'; + $filejs=$pathofwebsite.'/javascript.js.php'; + $filerobot=$pathofwebsite.'/robots.txt'; + $filehtaccess=$pathofwebsite.'/.htaccess'; + $filemanifestjson=$pathofwebsite.'/manifest.json.php'; + $filereadme=$pathofwebsite.'/README.md'; - $resql = $db->query($sql); - if ($resql) + $filecontent = file_get_contents($filehtmlheader); + if ((empty($max) || ($found < $max)) && preg_match('/'.preg_quote($searchstring, '/').'/', $filecontent)) { - $i = 0; - while (($obj = $db->fetch_object($resql)) && ($i < $max || $max == 0)) - { - if ($obj->rowid > 0) - { - $tmpwebsitepage = new WebsitePage($db); - $tmpwebsitepage->fetch($obj->rowid); - if ($tmpwebsitepage->id > 0) $arrayresult['list'][]=$tmpwebsitepage; - } - $i++; - } + $arrayresult['list'][]=array('type'=>'website_htmlheadercontent'); } - else + + $filecontent = file_get_contents($filecss); + if ((empty($max) || ($found < $max)) && preg_match('/'.preg_quote($searchstring, '/').'/', $filecontent)) { - $error++; - $arrayresult['code']=$db->lasterrno(); - $arrayresult['message']=$db->lasterror(); + $arrayresult['list'][]=array('type'=>'website_csscontent'); + } + + $filecontent = file_get_contents($filejs); + if ((empty($max) || ($found < $max)) && preg_match('/'.preg_quote($searchstring, '/').'/', $filecontent)) + { + $arrayresult['list'][]=array('type'=>'website_jscontent'); + } + + $filerobot = file_get_contents($filerobot); + if ((empty($max) || ($found < $max)) && preg_match('/'.preg_quote($searchstring, '/').'/', $filecontent)) + { + $arrayresult['list'][]=array('type'=>'website_robotcontent'); } $searchdone = 1; diff --git a/htdocs/website/index.php b/htdocs/website/index.php index f98024a726d..1a2dc531dd1 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -53,6 +53,9 @@ $pageref=GETPOST('pageref', 'aZ09'); $action=GETPOST('action', 'aZ09'); $confirm=GETPOST('confirm', 'alpha'); $cancel=GETPOST('cancel', 'alpha'); +$contextpage= GETPOST('contextpage', 'aZ')?GETPOST('contextpage', 'aZ'):'bomlist'; // To manage different context of search +$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page +$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') $type_container=GETPOST('WEBSITE_TYPE_CONTAINER', 'alpha'); @@ -270,9 +273,21 @@ if (GETPOST('refreshsite', 'alpha') || GETPOST('refreshsite.x', 'alpha') || GETP } if (GETPOST('refreshpage', 'alpha') && ! in_array($action, array('updatecss'))) $action='preview'; +// Cancel +if ($cancel) +{ + $action = 'preview'; + if ($backtopage) + { + header("Location: ".$backtopage); + exit; + } +} -$backtopage=$_SERVER["PHP_SELF"].'?file_manager=1&website='.$websitekey.'&pageid='.$pageid.(GETPOST('section_dir', 'alpha')?'§ion_dir='.urlencode(GETPOST('section_dir', 'alpha')):''); // used after a confirm_deletefile into actions_linkedfiles.inc.php +$savbacktopage = $backtopage; +$backtopage = $_SERVER["PHP_SELF"].'?file_manager=1&website='.$websitekey.'&pageid='.$pageid.(GETPOST('section_dir', 'alpha')?'§ion_dir='.urlencode(GETPOST('section_dir', 'alpha')):''); // used after a confirm_deletefile into actions_linkedfiles.inc.php include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php'; +$backtopage = $savbacktopage; if ($action == 'renamefile') $action='file_manager'; // After actions_linkedfiles, if action were renamefile, we set it to 'file_manager' @@ -984,7 +999,8 @@ if ($action == 'delete') // Update css if ($action == 'updatecss') { - if (GETPOST('refreshsite', 'alpha') || GETPOST('refreshpage', 'alpha')) // If we tried to reload another site/page, we stay on editcss mode. + // If we tried to reload another site/page, we stay on editcss mode. + if (GETPOST('refreshsite') || GETPOST('refreshsite_x') || GETPOST('refreshsite.x') || GETPOST('refreshpage') || GETPOST('refreshpage_x') || GETPOST('refreshpage.x')) { $action='editcss'; } @@ -1221,6 +1237,12 @@ if ($action == 'updatecss') } $action='preview'; + + if ($backtopage) + { + header("Location: ".$backtopage); + exit; + } } } } @@ -1861,6 +1883,7 @@ llxHeader($moreheadcss.$moreheadjs, $langs->trans("WebsiteSetup"), $help_url, '' print "\n"; print '
'; print ''; +print ''; if ($action == 'createsite') { @@ -2081,7 +2104,7 @@ if (! GETPOST('hide_websitemenu')) { if (preg_match('/^create/', $action) && $action != 'file_manager' && $action != 'replacesite' && $action != 'replacesiteconfirm') print ''; if (preg_match('/^edit/', $action) && $action != 'file_manager' && $action != 'replacesite' && $action != 'replacesiteconfirm') print ''; - if ($action != 'preview') print ''; + if ($action != 'preview') print ''; } print ''; @@ -2500,7 +2523,8 @@ if ($action == 'editcss') print '
'; print '
'; - if (GETPOST('editcss', 'alpha') || GETPOST('refreshpage', 'alpha')) + + if (! GETPOSTISSET('WEBSITE_CSS_INLINE')) { $csscontent = @file_get_contents($filecss); // Clean the php css file to remove php code and get only css part @@ -2508,11 +2532,11 @@ if ($action == 'editcss') } else { - $csscontent = GETPOST('WEBSITE_CSS_INLINE'); + $csscontent = GETPOST('WEBSITE_CSS_INLINE', 'none'); } if (! trim($csscontent)) $csscontent='/* CSS content (all pages) */'."\n"."body.bodywebsite { margin: 0; font-family: 'Open Sans', sans-serif; }\n.bodywebsite h1 { margin-top: 0; margin-bottom: 0; padding: 10px;}"; - if (GETPOST('editcss', 'alpha') || GETPOST('refreshpage', 'alpha')) + if (! GETPOSTISSET('WEBSITE_JS_INLINE')) { $jscontent = @file_get_contents($filejs); // Clean the php js file to remove php code and get only js part @@ -2520,11 +2544,11 @@ if ($action == 'editcss') } else { - $jscontent = GETPOST('WEBSITE_JS_INLINE'); + $jscontent = GETPOST('WEBSITE_JS_INLINE', 'none'); } if (! trim($jscontent)) $jscontent='/* JS content (all pages) */'."\n"; - if (GETPOST('editcss', 'alpha') || GETPOST('refreshpage', 'alpha')) + if (! GETPOSTISSET('WEBSITE_HTML_HEADER')) { $htmlheadercontent = @file_get_contents($filehtmlheader); // Clean the php htmlheader file to remove php code and get only html part @@ -2532,7 +2556,7 @@ if ($action == 'editcss') } else { - $htmlheadercontent = GETPOST('WEBSITE_HTML_HEADER'); + $htmlheadercontent = GETPOST('WEBSITE_HTML_HEADER', 'none'); } if (! trim($htmlheadercontent)) { @@ -2547,7 +2571,7 @@ if ($action == 'editcss') $htmlheadercontent=''."\n".trim($htmlheadercontent)."\n".''; } - if (GETPOST('editcss', 'alpha') || GETPOST('refreshpage', 'alpha')) + if (! GETPOSTISSET('WEBSITE_ROBOT')) { $robotcontent = @file_get_contents($filerobot); // Clean the php htmlheader file to remove php code and get only html part @@ -2555,7 +2579,7 @@ if ($action == 'editcss') } else { - $robotcontent = GETPOST('WEBSITE_ROBOT'); + $robotcontent = GETPOST('WEBSITE_ROBOT', 'nothtml'); } if (! trim($robotcontent)) { @@ -2565,7 +2589,7 @@ if ($action == 'editcss') $robotcontent.="Disallow: /administrator/\n"; } - if (GETPOST('editcss', 'alpha') || GETPOST('refreshpage', 'alpha')) + if (! GETPOSTISSET('WEBSITE_HTACCESS')) { $htaccesscontent = @file_get_contents($filehtaccess); // Clean the php htaccesscontent file to remove php code and get only html part @@ -2573,7 +2597,7 @@ if ($action == 'editcss') } else { - $htaccesscontent = GETPOST('WEBSITE_HTACCESS'); + $htaccesscontent = GETPOST('WEBSITE_HTACCESS', 'nohtml'); } if (! trim($htaccesscontent)) { @@ -2582,7 +2606,7 @@ if ($action == 'editcss') } - if (GETPOST('editcss', 'alpha') || GETPOST('refreshpage', 'alpha')) + if (! GETPOSTISSET('WEBSITE_MANIFEST_JSON')) { $manifestjsoncontent = @file_get_contents($filemanifestjson); // Clean the manifestjson file to remove php code and get only html part @@ -2590,14 +2614,14 @@ if ($action == 'editcss') } else { - $manifestjsoncontent = GETPOST('WEBSITE_MANIFEST_JSON'); + $manifestjsoncontent = GETPOST('WEBSITE_MANIFEST_JSON', 'none'); } if (! trim($manifestjsoncontent)) { //$manifestjsoncontent.=""; } - if (GETPOST('editcss', 'alpha') || GETPOST('refreshpage', 'alpha')) + if (! GETPOSTISSET('WEBSITE_README')) { $readmecontent = @file_get_contents($filereadme); // Clean the readme file to remove php code and get only html part @@ -2605,7 +2629,7 @@ if ($action == 'editcss') } else { - $readmecontent = GETPOST('WEBSITE_README'); + $readmecontent = GETPOST('WEBSITE_README', 'none'); } if (! trim($readmecontent)) { @@ -3196,6 +3220,8 @@ print "\n"; if ($action == 'replacesite' || $action == 'replacesiteconfirm') { + $searchkey = GETPOST('searchstring', 'none'); + print '
'; print ''; print ''; @@ -3225,7 +3251,7 @@ if ($action == 'replacesite' || $action == 'replacesiteconfirm') print $langs->trans("SearchString"); print '
'; print '
'; - print ''; + print ''; print '
'; print ''; @@ -3242,17 +3268,65 @@ if ($action == 'replacesite' || $action == 'replacesiteconfirm') if (GETPOST('optioncontent')) $algo.='content'; if (GETPOST('optionsitefiles')) $algo.='sitefiles'; - $listofpages = getPagesFromSearchCriterias('', $algo, GETPOST('searchstring', 'none'), 1000); + $listofpages = getPagesFromSearchCriterias('', $algo, $searchkey, 1000); print '
'; print '
'; if ($listofpages['code'] == 'OK') { - foreach($listofpages['list'] as $websitepagefound) + print '
'; + + if ($action == 'replacesiteconfirm') { - print '
'.$websitepagefound->title.' - '.$websitepagefound->description.'
'; + print '
'; + print '
'; + print $langs->trans("ReplaceString"); + print '
'; + print '
'; + print ''; + print ''; + print '
'; + print '
'; + print '
'; } + + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + foreach($listofpages['list'] as $answerrecord) + { + if (get_class($answerrecord) == 'WebsitePage') + { + print ''; + print ''; + print ''; + print ''; + print ''; + } + else + { + print ''; + print ''; + print ''; + print ''; + print ''; + } + } + print '
'.$langs->trans("Type").''.$langs->trans("Link").''.$langs->trans("Description").'
'.$langs->trans("Container").''; + print ''.$answerrecord->title.''; + print ''.$answerrecord->description; + print '
'.$answerrecord['type'].''; + $backtopageurl = $_SERVER["PHP_SELF"].'?action=replacesiteconfirm&searchstring='.urlencode($searchkey).'&optioncontent='.GETPOST('optioncontent','az09').'&optionmeta='.GETPOST('optionmeta','az09').'&optionsitefiles='.GETPOST('optionsitefiles','az09'); + print 'ref.'&backtopage='.urlencode($backtopageurl).'">'.$langs->trans("EditCss").''; + print ''; + print '
'; + print '
'; } else { @@ -3260,19 +3334,6 @@ if ($action == 'replacesite' || $action == 'replacesiteconfirm') } } - if ($action == 'replacesiteconfirm') - { - print '
'; - print '
'; - print $langs->trans("ReplaceString"); - print '
'; - print '
'; - print ''; - print ''; - print '
'; - print '
'; - } - print ''; }