<![CDATA[ [SOLVED] Exclude placeholders! - My Forums]]> https://forums.modx.com/thread/?thread=48015 <![CDATA[SOLVED]]> https://forums.modx.com/thread/48015/solved-exclude-placeholders?page=2#dis-post-277871 ]]> mrhaw Nov 21, 2008, 10:18 PM https://forums.modx.com/thread/48015/solved-exclude-placeholders?page=2#dis-post-277871 <![CDATA[Re: !!RE-OPEN Exclude placeholders!]]> https://forums.modx.com/thread/48015/solved-exclude-placeholders?page=2#dis-post-277870
By default, the search inputs are stripped by the defaultStripInput function. This function execute the following strips:
  function defaultStripInput($searchString){

    if ($searchString !== ''){  
      // Remove escape characters
      $searchString = stripslashes($searchString);

      // Remove modx sensitive tags
      $searchString = stripTags($searchString);

      // Strip HTML tags
      $searchString = stripHtml($searchString);  
    }  
    return $searchString;
  }


If the stripTags function is not efficient for you, you should build your own stripInput function and improve the stripTags function.

For instance to avoid some input search terms like (pagetitle, longtitle, ...), change the previous stripOtherTags function defined in the previous posts by:
function stripOtherTags($text){
  // Regular expressions to remove +something+
  $modRegExArray[] = '~\+(.*?)\+~';   // +phx+
  // Regular expressions to remove some bad words
  $badWords = array('pagetitle','longtitle','intro');        // any bad words you want
  foreach($badWords as $bw) $modRegExArray[] = '~'.$bw.'~';   
  
  // Remove modx sensitive tags
  foreach ($modRegExArray as $mReg)$text = preg_replace($mReg,'',$text);
  return $text;
}
And this will do it !]]>
coroico Nov 21, 2008, 11:12 AM https://forums.modx.com/thread/48015/solved-exclude-placeholders?page=2#dis-post-277870
<![CDATA[Re: !!RE-OPEN Exclude placeholders!]]> https://forums.modx.com/thread/48015/solved-exclude-placeholders?page=2#dis-post-277869

Im sorry for my last stupid post, basically my question is: IS the StripSnipp and StripSnippet
functions removed from AjaxSearch?]]>
mrhaw Nov 21, 2008, 03:41 AM https://forums.modx.com/thread/48015/solved-exclude-placeholders?page=2#dis-post-277869
<![CDATA[!!RE-OPEN Exclude placeholders!]]> https://forums.modx.com/thread/48015/solved-exclude-placeholders?page=2#dis-post-277868
...

That is I cannot longer find a placeholder-name (e.g Snippet, chunk, tv) as search-term if
search for it between *_* or +_+ or !_!

but I can still find it searching for it now without the *_* or +_+ (e.g "pagetitle")

So it DID NOT exclude the placeholder.
I saw there was a StripSnip or StripSnippet function! How would I put in that in my config?

Ajax Search 1.5:
 // $stripSnip [ true | false ]
   // Strip out snippet calls etc from the search string?
   $stripSnip = true;

   // $stripSnippets [ true | false ]
   // Strip out snippet names so users will not be able to "search" to see what snippets are used in your content. This is a security benefit, as users will not be able to search for what pages use specific snippets.
   $stripSnippets = true;


I had 0.9.6.2 and just upgraded
to 0.9.6.3RC2 without any different result. And latest AjaxSearch 1.8.1

Could I make a list of bad words to exclude? &searchWordList is not it...

//
http://modxcms.com/forums/index.php/topic,1028.0.html
// Remove snippet names
  if ($stripSnippets && $searchString != ''){
    // get all the snippet names

    $tbl = $etomite->dbConfig['dbase'] . "." . $etomite->dbConfig['table_prefix'] . "site_snippets";
    $snippetSql = "SELECT $tbl.name FROM $tbl;";
    $snippetRs = $etomite->dbQuery($snippetSql);
    $snippetCount = $etomite->recordCount($snippetRs);
    $snippetNameArray = array();
    for ($s = 0; $s < $snippetCount; $s++){
      $thisSnippetRow = $etomite->fetchRow($snippetRs);
      $snippetNameArray[] = strtolower($thisSnippetRow['name']);
    }
]]>
mrhaw Nov 15, 2008, 08:28 PM https://forums.modx.com/thread/48015/solved-exclude-placeholders?page=2#dis-post-277868
<![CDATA[Re: Exclude placeholders!]]> https://forums.modx.com/thread/48015/solved-exclude-placeholders?page=2#dis-post-277867
my config file:
<?php

// How to improve the default stripInput function to strip some new input strings ?
// In this example we would like strip +someting+ or *something* input strings
// for that we define a new stripInput function: myOwnStripInput
// we reuse the functions stripslashes, stripTags and stripHtml provided by AS
// we add the function stripOtherTags
// in the snippet call add &stripInput=`myOwnStripInput` or defined it in this config file

$debug = -2; // to allow a debug trace with firePhp

if (!function_exists('myOwnStripInput'))
{
function myOwnStripInput($searchString) {

    if ($searchString !== ''){  
      // Remove escape characters
      $searchString = stripslashes($searchString);

      // Remove modx sensitive tags
      $searchString = stripTags($searchString);

      // Remove +something+ substring too
      $searchString = stripOtherTags($searchString);  

      // Strip HTML tags
      $searchString = stripHtml($searchString);  
    }  
    return $searchString;
  }
}
if (!function_exists('stripOtherTags'))
{
function stripOtherTags($text) {

  // Regular expressions to remove +something+
  $modRegExArray[] = '~\+(.*?)\+~';   // +something+
  $modRegExArray[] = '~\*(.*?)\*~';   // *something*

  // Remove modx sensitive tags
  foreach ($modRegExArray as $mReg)$text = preg_replace($mReg,'',$text);
  return $text;
 }
}
?>


For further questions: http://modxcms.com/forums/index.php/topic,30450.0.html]]>
mrhaw Nov 10, 2008, 06:20 AM https://forums.modx.com/thread/48015/solved-exclude-placeholders?page=2#dis-post-277867
<![CDATA[Re: Exclude placeholders!]]> https://forums.modx.com/thread/48015/solved-exclude-placeholders?page=2#dis-post-277866

U are right that makes sense will try it!! smiley]]>
mrhaw Nov 10, 2008, 05:43 AM https://forums.modx.com/thread/48015/solved-exclude-placeholders?page=2#dis-post-277866
<![CDATA[Re: Exclude placeholders!]]> https://forums.modx.com/thread/48015/solved-exclude-placeholders?page=2#dis-post-277865
Otherwise to avoid the pb of redeclaration replace in your config file :
function mrhawStripInput($searchString) {
by
if (!function_exists('mrhawStripInput')) function mrhawStripInput($searchString) {


[EDIT] And do the same thing for function stripOtherTags]]>
coroico Nov 10, 2008, 05:36 AM https://forums.modx.com/thread/48015/solved-exclude-placeholders?page=2#dis-post-277865
<![CDATA[Re: Exclude placeholders!]]> https://forums.modx.com/thread/48015/solved-exclude-placeholders?page=2#dis-post-277864 Fatal error: Cannot redeclare myownstripinput() (previously declared in .../html/assets/snippets/ajaxSearch/configs/mrhaw.config.php:12) in .../html/assets/snippets/ajaxSearch/configs/mrhaw.config.php on line 28

Snippet call in template:
[!AjaxSearch? &ajaxSearch=`0` &highlightResult=`0` &debug=`-2` &AS_landing=`8` &extract=`99` &config=`mrhaw` &stripInput=`myOwnStripInput`!]


Snippet call on landing page id 8:
[!AjaxSearch? &ajaxSearch=`0` &AS_showForm=`0` &extract=`99` &config=`mrhaw` &stripInput=`myOwnStripInput` &highlightResult=`0`!]

mrhaw.config.php:
<?php

// How to improve the default stripInput function to strip some new input strings ?
// In this example we would like strip +someting+ or *something* input strings
// for that we define a new stripInput function: myOwnStripInput
// we reuse the functions stripslashes, stripTags and stripHtml provided by AS
// we add the function stripOtherTags
// in the snippet call add &stripInput=`myOwnStripInput` or defined it in this config file

$debug = -2; // to allow a debug trace with firePhp

function myOwnStripInput($searchString){

    if ($searchString !== ''){  
      // Remove escape characters
      $searchString = stripslashes($searchString);

      // Remove modx sensitive tags
      $searchString = stripTags($searchString);

      // Remove +something+ substring too
      $searchString = stripOtherTags($searchString);  

      // Strip HTML tags
      $searchString = stripHtml($searchString);  
    }  
    return $searchString;
  }

function stripOtherTags($text){
  // Regular expressions to remove +something+
  $modRegExArray[] = '~\+(.*?)\+~';   // +something+
  $modRegExArray[] = '~\*(.*?)\*~';   // *something*

  // Remove modx sensitive tags
  foreach ($modRegExArray as $mReg)$text = preg_replace($mReg,'',$text);
  return $text;
}

?>


undecided


//If I exclude &highlightResult=`0` from the snippet it just output the snippet in cached brackets [[ ]] on the screen
and wont work at all...

This problem has probably nothing to do with ajaxsearch undecided]]>
mrhaw Nov 10, 2008, 04:48 AM https://forums.modx.com/thread/48015/solved-exclude-placeholders?page=2#dis-post-277864
<![CDATA[Re: Exclude placeholders!]]> https://forums.modx.com/thread/48015/solved-exclude-placeholders#dis-post-277863 stripInput demo on the AjaxSearch demo site.

Take care the snippet call of your landing page should contains &config=`mrhaw` &stripInput=`mrhawStripInput` even if the input form is not displayed. See the landing page of the stripInput demo]]>
coroico Nov 09, 2008, 05:45 AM https://forums.modx.com/thread/48015/solved-exclude-placeholders#dis-post-277863
<![CDATA[Re: Exclude placeholders!]]> https://forums.modx.com/thread/48015/solved-exclude-placeholders#dis-post-277862 typing junk in it and get errors...

But if I in the non-ajax search also put it in the landing/result page snippet call  - it didnt work.

the latest debug:
[8-Nov-08 06:22:23]  AjaxSearch 1.8.1 - Php5.2.6 - MySql 4.1.25-Debian_mt1
[8-Nov-08 06:22:23]  AjaxSearch - Configuration file mrhaw : 
<?php
function mrhawStripInput($searchString){

    if ($searchString !== ''){  
      // Remove escape characters
      $searchString = stripslashes($searchString);

      // Remove modx sensitive tags
      $searchString = stripTags($searchString);

      // Remove +something+ substring too
      $searchString = stripOtherTags($searchString);  

      // Strip HTML tags
      $searchString = stripHtml($searchString);  
    }  
    return $searchString;
  }

function stripOtherTags($text){
  // Regular expressions to remove +something+
  $modRegExArray[] = '~\+(.*?)\+~';   // +phx+

  // Remove modx sensitive tags
  foreach ($modRegExArray as $mReg)$text = preg_replace($mReg,'',$text);
  return $text;
}
[8-Nov-08 06:22:23]  AjaxSearch - User configuration - Before parameter checking : Array
(
    [config] => mrhaw
    [version] => 1.8.1
    [debug] => 3
    [language] => english
    [ajaxSearch] => 0
    [advSearch] => oneword
    [whereSearch] => content|tv
    [subSearch] => 5,1
    [withTvs] => 
    [order] => publishedon,pagetitle
    [rank] => pagetitle:100,extract
    [minChars] => 3
    [AS_showForm] => 1
    [resultsPage] => 0
    [grabMax] => 10
    [extract] => 1:content,description,introtext,tv_content
    [extractLength] => 200
    [extractEllips] => ...
    [extractSeparator] => <br />
    [formatDate] => d/m/y : H:i:s
    [highlightResult] => 0
    [pageLinkSeparator] =>  | 
    [AS_landing] => 8
    [AS_showResults] => 1
    [idType] => parents
    [parents] => 
    [documents] => 
    [depth] => 10
    [hideMenu] => 2
    [hideLink] => 1
    [filter] => 
    [tplLayout] => @FILE:assets/snippets/ajaxSearch/templates/layout.tpl.html
    [tplResults] => @FILE:assets/snippets/ajaxSearch/templates/results.tpl.html
    [tplResult] => @FILE:assets/snippets/ajaxSearch/templates/result.tpl.html
    [tplPaging] => @FILE:assets/snippets/ajaxSearch/templates/paging.tpl.html
    [stripInput] => mrhawStripInput
    [stripOutput] => defaultStripOutput
    [searchWordList] => 
    [breadcrumbs] => 0
    [tvPhx] => 0
    [clearDefault] => 0
    [jsClearDefault] => assets/snippets/ajaxSearch/js/clearDefault.js
)

[8-Nov-08 06:22:23]  AjaxSearch - tplResult template @FILE:assets/snippets/ajaxSearch/templates/result.tpl.html : <div class="[+as.resultClass+]">
  <a class="[+as.resultLinkClass+]" href="[+as.resultLink+]" title="[+as.longtitle+]">[+as.pagetitle+]</a>
[+as.descriptionShow:is=`1`:then=`
  <span class="[+as.descriptionClass+]">[+as.description+]</span>
`+]
[+as.extractShow:is=`1`:then=`
  <div class="[+as.extractClass+]"><p>[+as.extract+]</p></div>
`+]
[+as.breadcrumbsShow:is=`1`:then=`
  <span class="[+as.breadcrumbsClass+]">[+as.breadcrumbs+]</span>
`+]
</div>
[8-Nov-08 06:22:23]  AjaxSearch - tplResults template@FILE:assets/snippets/ajaxSearch/templates/results.tpl.html : [+as.noResults:is=`1`:then=`
  <div class="[+as.noResultClass+]">
    [+as.noResultText+]
  </div>
`:else=`
  <p class="ajaxSearch_resultsInfo">[+as.resultInfoText+]</p>
  [+as.paging+]
  [+as.listResults+]
  [+as.paging+]
`+]
[8-Nov-08 06:22:23]  AjaxSearch - tplResult template@FILE:assets/snippets/ajaxSearch/templates/layout.tpl.html : [+as.showForm:is=`1`:then=`
<form [+as.formId+] action="[+as.formAction+]" method="post">
    <fieldset class="form3">
		<input type="hidden" name="advSearch" value="[+as.advSearch+]" />
    <label for="ajaxSearch_input">
      <input id="ajaxSearch_input" class="cleardefault" type="text" name="search" value="[+as.inputValue+]"[+as.inputOptions+] />
    </label>
    <label for="ajaxSearch_submit">
      <input id="ajaxSearch_submit" type="submit" name="sub" class="button" value="" />
    </label>
    </fieldset>
</form>
`+]
[+as.showIntro:is=`1`:then=`
<p class="ajaxSearch_intro" id="ajaxSearch_intro">[+as.introMessage+]</p>
`+]
[+as.showResults:is=`1`:then=`
[+as.results+]
`+]


The good thing  smiley is that I can turn off highlightning which is causing problem by outputing
example: <span="ajax_higlightning ajax_higlightning1 ">bla bla</span> all over in important code.

I’m running 0.9.6.2 - My other websites has 0.9.6.1p2 and no PHx installed, but are on same server with same mysql
and php. On those its all good except it finds word/term: "modx" on all pages... ?

Well, I am thankful for your help.  cool]]>
mrhaw Nov 08, 2008, 07:34 PM https://forums.modx.com/thread/48015/solved-exclude-placeholders#dis-post-277862