From 7824731f179fa3120a3d30db237359463d36c0ac Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Aug 2019 00:34:42 +0200 Subject: [PATCH] NEW Add feature to search a string into containers --- htdocs/core/ajax/pingresult.php | 3 +- htdocs/core/lib/website.lib.php | 39 +++++++++-- htdocs/langs/en_US/errors.lang | 1 + htdocs/langs/en_US/website.lang | 4 +- htdocs/main.inc.php | 2 +- htdocs/website/index.php | 117 ++++++++++++++++++++++++++------ 6 files changed, 135 insertions(+), 31 deletions(-) diff --git a/htdocs/core/ajax/pingresult.php b/htdocs/core/ajax/pingresult.php index 9b46546f5c3..3055942f89a 100644 --- a/htdocs/core/ajax/pingresult.php +++ b/htdocs/core/ajax/pingresult.php @@ -17,8 +17,7 @@ /** * \file htdocs/core/ajax/pingresult.php - * \brief File to save result of anonymous ping - * Example: captureserver/public/index.php?action=dolibarrping + * \brief File to save result of an anonymous ping into database (1 ping is done per installation) */ if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Disables token renewal diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php index e9507b8556d..405a0687eae 100644 --- a/htdocs/core/lib/website.lib.php +++ b/htdocs/core/lib/website.lib.php @@ -575,6 +575,8 @@ function getPagesFromSearchCriterias($type, $algo, $searchstring, $max = 25) $error = 0; $arrayresult = array('code'=>'', 'list'=>array()); + if (! is_object($weblangs)) $weblangs = $langs; + if (empty($searchstring)) { $error++; @@ -583,24 +585,38 @@ function getPagesFromSearchCriterias($type, $algo, $searchstring, $max = 25) } elseif (dol_strlen($searchstring) < 2) { + $weblangs->load("errors"); $error++; $arrayresult['code']='KO'; - $arrayresult['message']=$weblangs->trans("SearchCriteriaTooSmall"); + $arrayresult['message']=$weblangs->trans("ErrorSearchCriteriaTooSmall"); } - elseif (! in_array($type, array('page'))) + elseif (! in_array($type, array('', 'page'))) { $error++; $arrayresult['code']='KO'; $arrayresult['message']='Bad value for parameter $type'; } - if (! $error && in_array($algo, array('meta', 'metacontent'))) + $searchdone = 0; + + if (! $error && in_array($algo, array('meta', 'metacontent', 'content'))) { $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'website_page'; - $sql.= " WHERE fk_website = ".$website->id." AND type_container = '".$db->escape($type)."'"; - $sql.= " AND (title LIKE '%".$db->escape($searchstring)."%' OR description LIKE '%".$db->escape($searchstring)."%'"; - if ($algo == 'metacontent') $sql.= " OR content LIKE '%".$db->escape($searchstring)."%'"; - $sql.= " OR keywords LIKE '".$db->escape($searchstring).",%' OR keywords LIKE '% ".$db->escape($searchstring)."%')"; // TODO Use a better way to scan keywords + $sql.= " WHERE fk_website = ".$website->id; + if ($type) $sql.= " AND type_container = '".$db->escape($type)."'"; + $sql.= " AND ("; + $searchalgo = ''; + if ($algo == 'meta' || $algo == 'metacontent') + { + $searchalgo.= ($searchalgo?' OR ':'')."title LIKE '%".$db->escape($searchstring)."%' OR description LIKE '%".$db->escape($searchstring)."%'"; + $searchalgo.= ($searchalgo?' OR ':'')."keywords LIKE '".$db->escape($searchstring).",%' OR keywords LIKE '% ".$db->escape($searchstring)."%'"; // TODO Use a better way to scan keywords + } + if ($algo == 'metacontent' || $algo == 'content') + { + $searchalgo.= ($searchalgo?' OR ':'')."content LIKE '%".$db->escape($searchstring)."%'"; + } + $sql.=$searchalgo; + $sql.= ")"; $sql.= $db->plimit($max); $resql = $db->query($sql); @@ -631,6 +647,15 @@ function getPagesFromSearchCriterias($type, $algo, $searchstring, $max = 25) $arrayresult['code']=$db->lasterrno(); $arrayresult['message']=$db->lasterror(); } + + $searchdone = 1; + } + + if (! $searchdone) + { + $error++; + $arrayresult['code']='KO'; + $arrayresult['message']='No supported algorithm found'; } return $arrayresult; diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 4c8e761da9a..f8c3c1a1aee 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -218,6 +218,7 @@ ErrorVariableKeyForContentMustBeSet=Error, the constant with name %s (with text ErrorURLMustStartWithHttp=URL %s must start with http:// or https:// ErrorNewRefIsAlreadyUsed=Error, the new reference is already used ErrorDeletePaymentLinkedToAClosedInvoiceNotPossible=Error, delete payment linked to a closed invoice is not possible. +ErrorSearchCriteriaTooSmall=Search criteria too small. # Warnings WarningParamUploadMaxFileSizeHigherThanPostMaxSize=Your PHP parameter upload_max_filesize (%s) is higher than PHP parameter post_max_size (%s). This is not a consistent setup. WarningPasswordSetWithNoAccount=A password was set for this member. However, no user account was created. So this password is stored but can't be used to login to Dolibarr. It may be used by an external module/interface but if you don't need to define any login nor password for a member, you can disable option "Manage a login for each member" from Member module setup. If you need to manage a login but don't need any password, you can keep this field empty to avoid this warning. Note: Email can also be used as a login if the member is linked to a user. diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang index efad38c14f5..72b73d1c479 100644 --- a/htdocs/langs/en_US/website.lang +++ b/htdocs/langs/en_US/website.lang @@ -103,4 +103,6 @@ NotAllowedToAddDynamicContent=You don't have permission to add or edit PHP dynam ReplaceWebsiteContent=Search or Replace website content DeleteAlsoJs=Delete also all javascript files specific to this website? DeleteAlsoMedias=Delete also all medias files specific to this website? -MyWebsitePages=My website pages \ No newline at end of file +MyWebsitePages=My website pages +SearchReplaceInto=Search | Replace into +ReplaceString=New string \ No newline at end of file diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index e1a1f333d1d..2ba5e3b484a 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -2344,7 +2344,7 @@ if (! function_exists("llxFooter")) url: "https://ping.dolibarr.org/", timeout: 500, // timeout milliseconds cache: false, - data: { hash_algo: "md5", hash_unique_id: "file->instance_unique_id); ?>", action: "dolibarrping", version: "", entity: entity; ?> }, + data: { hash_algo: "md5", hash_unique_id: "file->instance_unique_id); ?>", action: "dolibarrping", version: "", entity: entity; ?> }, success: function (data, status, xhr) { // success callback function (data contains body of response) console.log("Ping ok"); $.ajax({ diff --git a/htdocs/website/index.php b/htdocs/website/index.php index 77b70261a4c..0e9724b66c4 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -302,6 +302,12 @@ if ($action == 'unsetshowsubcontainers') exit; } +if (($action == 'replacesite' || $action == 'replacesiteconfirm') && empty(GETPOST('searchstring'))) +{ + $action = 'replacesite'; +} + + // Add directory /* if ($action == 'adddir' && $permtouploadfile) @@ -1793,9 +1799,10 @@ $moreheadjs.=''."\n"; llxHeader($moreheadcss.$moreheadjs, $langs->trans("WebsiteSetup"), $help_url, '', 0, 0, $arrayofjs, $arrayofcss, '', '', ''."\n".'
'); -print "\n".'
'; - +print "\n"; +print ''; print ''; + if ($action == 'createsite') { print ''; @@ -1842,7 +1849,11 @@ if ($action == 'file_manager') } if ($action == 'replacesite') { - print ''; + print ''; +} +if ($action == 'replacesiteconfirm') +{ + print ''; } print '
'; @@ -1954,7 +1965,6 @@ if (! GETPOST('hide_websitemenu')) '; */ - //print ''.dol_escape_htmltag($langs->trans("Replace")).'" name="replacesite">'; print 'ref.'" class="button nobordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("ReplaceWebsiteContent")).'">'; } @@ -2005,10 +2015,10 @@ if (! GETPOST('hide_websitemenu')) print '
'; } - if (in_array($action, array('editcss','editmenu','file_manager','replacesite'))) + if (in_array($action, array('editcss','editmenu','file_manager','replacesite','replacesiteconfirm'))) { - if (preg_match('/^create/', $action) && $action != 'file_manager' && $action != 'replacesite') print ''; - if (preg_match('/^edit/', $action) && $action != 'file_manager' && $action != 'replacesite') print ''; + 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 ''; } @@ -2286,7 +2296,7 @@ if (! GETPOST('hide_websitemenu')) // TODO Add js to save alias like we save virtual host name and use dynamic virtual host for url of id=previewpageext } - if (! in_array($action, array('editcss','editmenu','file_manager','replacesite','createsite','createcontainer','createfromclone','createpagefromclone','deletesite'))) + if (! in_array($action, array('editcss','editmenu','file_manager','replacesite','replacesiteconfirm','createsite','createcontainer','createfromclone','createpagefromclone','deletesite'))) { if (preg_match('/^create/', $action)) print ''; if (preg_match('/^edit/', $action)) print ''; @@ -2992,18 +3002,6 @@ if ($action == 'editfile' || $action == 'file_manager') print '
'; } -if ($action == 'replacesite') -{ - print ''."\n"; - print '

'; - - print load_fiche_titre($langs->trans("ReplaceWebsiteContent")); - - print '
'.$langs->trans("FeatureNotYetAvailable").''; - - print '
'; -} - if ($action == 'editmenu') { print ''."\n"; @@ -3053,6 +3051,85 @@ print "
\n"; print "\n"; +if ($action == 'replacesite' || $action == 'replacesiteconfirm') +{ + print '
'; + print ''; + print ''; + + + print ''."\n"; + print '

'; + + print load_fiche_titre($langs->trans("ReplaceWebsiteContent")); + + print '
'; + + print '
'; + print '
'; + print $langs->trans("SearchReplaceInto"); + print '
'; + print '
'; + print ' '.$langs->trans("Content"); + print ' '.$langs->trans("Title").' | '.$langs->trans("Description").' | '.$langs->trans("Keywords"); + print '
'; + print '
'; + + print '
'; + print '
'; + print $langs->trans("SearchString"); + print '
'; + print '
'; + print ''; + print '
'; + print '
'; + + print '
'; + + print '
'; + + print ''; + + if ($action == 'replacesiteconfirm') + { + $algo = ''; + if (GETPOST('optionmeta')) $algo.='meta'; + if (GETPOST('optioncontent')) $algo.='content'; + + $listofpages = getPagesFromSearchCriterias('', $algo, GETPOST('searchstring', 'none'), 1000); + + print '
'; + print '
'; + + if ($listofpages['code'] == 'OK') + { + foreach($listofpages['list'] as $websitepagefound) + { + print '
'.$websitepagefound->title.' - '.$websitepagefound->description.'
'; + } + } + else + { + print $listofpages['message']; + } + } + + if ($action == 'replacesiteconfirm') + { + print '
'; + print '
'; + print $langs->trans("ReplaceString"); + print '
'; + print '
'; + print ''; + print ''; + print '
'; + print '
'; + } + + print ''; +} + if ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone') { if ($pageid > 0 && $atleastonepage)