diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 0c310b92dd6..965bca72824 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -722,6 +722,7 @@ class Form else { jQuery(".massaction").hide(); + jQuery(".massactionother").hide(); } } @@ -743,10 +744,12 @@ class Form if ($(this).val() != \'0\') { jQuery(".massactionconfirmed").prop(\'disabled\', false); + jQuery(".massactionother").show(); } else { jQuery(".massactionconfirmed").prop(\'disabled\', true); + jQuery(".massactionother").hide(); } }); }); diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php index af8840b33ae..770bc3fda88 100644 --- a/htdocs/core/lib/website.lib.php +++ b/htdocs/core/lib/website.lib.php @@ -793,7 +793,7 @@ function getPagesFromSearchCriterias($type, $algo, $searchstring, $max = 25, $so { $tmpwebsitepage = new WebsitePage($db); $tmpwebsitepage->fetch($obj->rowid); - if ($tmpwebsitepage->id > 0) $arrayresult['list'][] = $tmpwebsitepage; + if ($tmpwebsitepage->id > 0) $arrayresult['list'][$obj->rowid] = $tmpwebsitepage; $found++; } $i++; diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang index 222eeb6df0d..c3e9870266f 100644 --- a/htdocs/langs/en_US/website.lang +++ b/htdocs/langs/en_US/website.lang @@ -126,4 +126,5 @@ MainLanguage=Main language OtherLanguages=Other languages UseManifest=Provide a manifest.json file PublicAuthorAlias=Public author alias -AvailableLanguagesAreDefinedIntoWebsiteProperties=Available languages are defined into website properties \ No newline at end of file +AvailableLanguagesAreDefinedIntoWebsiteProperties=Available languages are defined into website properties +ReplacementDoneInXPages=Replacement done in %s pages or containers \ No newline at end of file diff --git a/htdocs/website/index.php b/htdocs/website/index.php index 9f823935bcb..a34cfce2206 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -52,9 +52,12 @@ $websitekey = GETPOST('website', 'alpha'); $page = GETPOST('page', 'alpha'); $pageid = GETPOST('pageid', 'int'); $pageref = GETPOST('pageref', 'alphanohtml'); + $action = GETPOST('action', 'aZ09'); +$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists) $confirm = GETPOST('confirm', 'alpha'); $cancel = GETPOST('cancel', 'alpha'); +$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list $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') @@ -260,6 +263,23 @@ $manifestjsoncontentdefault .= '{ }] }'; +$listofpages = array(); + +$algo = ''; +if (GETPOST('optionmeta')) $algo .= 'meta'; +if (GETPOST('optioncontent')) $algo .= 'content'; +if (GETPOST('optionsitefiles')) $algo .= 'sitefiles'; + +if (empty($sortfield)) { + $sortfield = 'pageurl'; $sortorder = 'ASC'; +} + +$searchkey = GETPOST('searchstring', 'none'); + +if ($action == 'replacesiteconfirm') { + $listofpages = getPagesFromSearchCriterias('', $algo, $searchkey, 1000, $sortfield, $sortorder); +} + /* @@ -340,11 +360,67 @@ if ($action == 'unsetshowsubcontainers') exit; } -if (($action == 'replacesite' || $action == 'replacesiteconfirm') && empty(GETPOST('searchstring'))) +if (($action == 'replacesite' || $action == 'replacesiteconfirm') && ! $searchkey) { $action = 'replacesite'; } +// Replacement of string into pages +if ($massaction == 'replace') +{ + $replacestring = GETPOST('replacestring', 'alphanohtml'); + if (! $replacestring) { + setEventMessages("ErrorReplaceStringEmpty", null, 'errors'); + } + else { + $nbreplacement = 0; + + foreach($toselect as $keyselected) { + $objectpage = $listofpages['list'][$keyselected]; + if ($objectpage->pageurl) { + dol_syslog("Replace string into page ".$objectpage->pageurl); + + if (GETPOST('optioncontent', 'aZ09')) { + $objectpage->content = str_replace($searchkey, $replacestring, $objectpage->content); + } + if (GETPOST('optionmeta', 'aZ09')) { + $objectpage->title = str_replace($searchkey, $replacestring, $objectpage->title); + $objectpage->description = str_replace($searchkey, $replacestring, $objectpage->description); + $objectpage->keywords = str_replace($searchkey, $replacestring, $objectpage->keywords); + } + + if (!empty($objectpage->content)) + { + $filealias = $pathofwebsite.'/'.$objectpage->pageurl.'.php'; + $filetpl = $pathofwebsite.'/page'.$objectpage->id.'.tpl.php'; + + // Save page alias + $result = dolSavePageAlias($filealias, $object, $objectpage); + if (!$result) + { + setEventMessages('Failed to write file '.basename($filealias), null, 'errors'); + } + + // Save page of content + $result = dolSavePageContent($filetpl, $object, $objectpage); + if ($result) + { + $nbreplacement++; + } else { + $error++; + setEventMessages('Failed to write file '.$filetpl, null, 'errors'); + $action = 'createcontainer'; + break; + } + } + } + } + if (! $error) { + setEventMessages($langs->trans("ReplacementDoneInXPages", $nbreplacement), null, 'mesgs'); + } + } +} + // Add directory /* @@ -3397,10 +3473,8 @@ print "\n"; print "\n"; -if ($action == 'replacesite' || $action == 'replacesiteconfirm') +if ($action == 'replacesite' || $action == 'replacesiteconfirm' || $massaction == 'replace') { - $searchkey = GETPOST('searchstring', 'none'); - print '