We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20413
    • 2,877 Posts
    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
      @hawproductions | http://mrhaw.com/

      Infograph: MODX Advanced Install in 7 steps:
      http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

      Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
      http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
      • 5811
      • 1,717 Posts
      As I understand you have a first ajaxSearch call in your template and a second on page 8. Is the page 8 use the same template ? This could explain that you have twice the mrhawStripInput function declaration.

      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
        • 20413
        • 2,877 Posts
        grin

        U are right that makes sense will try it!! smiley
          @hawproductions | http://mrhaw.com/

          Infograph: MODX Advanced Install in 7 steps:
          http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

          Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
          http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
          • 20413
          • 2,877 Posts
          I got it working and I learned some php!! SUPER THANK YOU!!!  ;D

          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
            @hawproductions | http://mrhaw.com/

            Infograph: MODX Advanced Install in 7 steps:
            http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

            Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
            http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
            • 20413
            • 2,877 Posts
            The above WORKED in one way.

            ...

            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']);
                }
            
              @hawproductions | http://mrhaw.com/

              Infograph: MODX Advanced Install in 7 steps:
              http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

              Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
              http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
              • 20413
              • 2,877 Posts
              Dear coroico!  smiley

              Im sorry for my last stupid post, basically my question is: IS the StripSnipp and StripSnippet
              functions removed from AjaxSearch?
                @hawproductions | http://mrhaw.com/

                Infograph: MODX Advanced Install in 7 steps:
                http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

                Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
                http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
                • 5811
                • 1,717 Posts
                StripSnipp and StripSnippet parameters don’t exist with the version 1.8.1.

                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 !
                  • 20413
                  • 2,877 Posts
                  SWEEEET THANKS FOR ALL YOUR HELP!!  cool
                    @hawproductions | http://mrhaw.com/

                    Infograph: MODX Advanced Install in 7 steps:
                    http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

                    Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
                    http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower