We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30585
    • 833 Posts
    Hi guys,

    I'm getting a syntax error with the following snippet. I read somewhere that this is usually caused by a missing bracket or quotation mark, but I just don't see where that may be.
    Parse error: syntax error, unexpected ''lsg:LIKE'' (T_CONSTANT_ENCAPSED_STRING), expecting ')' in /home/mysite/public_html/core/cache/includes/elements/modsnippet/84.include.cache.php on line 26


    
    <?php
    /**
     * @package bible
     */
    
    /* this snippet searches the bible_verses table based on the supplied search query*/
    
    //Load the class
    $base_path = !empty($base_path) ? $base_path : $modx->getOption('core_path').'components/bible/';
    //Adds the package to xPDO, and allows us to use all of xPDO's functions with the model
    $result = $modx->addPackage('bible',$base_path.'model/'); 
    
    // Check if package was added successfuly 
    if (! $result) {
        return 'Failed to add package';
    }
    
    // Search in the bible_verses table
    $c = $modx->newQuery('BibleVerse');
    $c->where(array(
        'lsg:LIKE' => '%'.$search.'%',
        'OR:book:LIKE' => '%'.$search.'%',
        'OR:chapter:LIKE' => '%'.$search.'%',
        'OR:verse:LIKE' => '%'.$search.'%',
    ));
    $count = $modx->getCount('BibleVerse',$c);
    $c->select(array(
        'id','book','chapter','verse','lsg', 'resource'
    ));
    $c->limit($limit,$offset);
    $verses = $modx->getCollection('BibleVerse',$c);
     
    $results = array();
    foreach ($verses as $verse) {   
      // Extract text and add highlighting
      // Use functions of the SimpleSearch class
      $searchObj = new SimpleSearch($modx,array());
      $searchObj->parseSearchString($search);
       
      $extract = $verse->get('lsg');
      $extract = $searchObj->createExtract($extract, 200, $search,'…'); 
      $extract = preg_replace("#\[\[(.*?)\]\]#si", '', $extract); // cleanup extract
      $extract = str_replace(array('[[',']]'), '', $extract);
      $extract = $searchObj->addHighlighting($extract, 'sisea-highlight', 'span'); // highlighting class and tag
          
      $results[] = array(
            'id' => $verse->get('id'),
            'pagetitle' => $verse->get('chapter'), 
            'longtitle' => $verse->get('verse'), 
            'introtext' => $verse->get('lsg'), 
            'link' => $verse->get('book'), 
            'extract' => $extract
        );
    }
    $hook->addFacet('verses',$results,$count);
         
    return true;


    This is a direct copy from the docs with a few edits=> SimpleSearch.Faceted Search Through PostHooks
    Any idea what I'm missing?

    This question has been answered by treigh. See the first response.

    [ed. note: treigh last edited this post 12 years, 6 months ago.]
      A MODx Fanatic
      • 3749
      • 24,544 Posts
      I you sure that's the snippet with the ID of 84?

      I can't find anything wrong with the code and my code editor agrees.

      The offending line is supposed to be near line 26 and there doesn't appear to be anything wrong there.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 30585
        • 833 Posts
        Quote from: BobRay at Mar 18, 2014, 12:09 PM
        I you sure that's the snippet with the ID of 84?

        I can't find anything wrong with the code and my code editor agrees.

        The offending line is supposed to be near line 26 and there doesn't appear to be anything wrong there.

        Hey Bob,

        The snippet's ID is indeed 84.

        Here are my snippet calls:
        <h1 class="bbl-h2">[[*pagetitle]]</h1>
        [[!SimpleSearchForm? &landing=`2190` &tpl=`tplBibleSearchForm`]]
        [[!SimpleSearch? &toPlaceholder=`sisea.results` &postHooks=`bibleVerseHook` &facetLimit=`5`]]
        <p>NORMAL</p>
        [[+sisea.results]]
        <p>FACETED</p>
        [[+sisea.verses.results]]


        I opened the cached snipped from core/cache/includes/elements/modsnippet/84.include.cache.php on line 26
        and here's the code once it's executed:

        <?php
        function elements_modsnippet_84($scriptProperties= array()) {
        global $modx;
        if (is_array($scriptProperties)) {
        extract($scriptProperties, EXTR_SKIP);
        }
        /**
         * @package bible
         */
        
        /* this snippet searches the bible_verses table based on the supplied search query*/
        
        //Load the class
        $base_path = !empty($base_path) ? $base_path : $modx->getOption('core_path').'components/bible/';
        //Adds the package to xPDO, and allows us to use all of xPDO's functions with the model
        $result = $modx->addPackage('bible',$base_path.'model/'); 
        
        // Check if package was added successfuly 
        if (! $result) {
            return 'Failed to add package';
        }
        
        // Search in the bible_verses table
        $c = $modx->newQuery('bibleVerse');
        $c->where(array(
            'lsg:LIKE' => '%'.$search.'%',
            'OR:book:LIKE' => '%'.$search.'%',
            'OR:chapter:LIKE' => '%'.$search.'%',
            'OR:verse:LIKE' => '%'.$search.'%',
        ));
        $count = $modx->getCount('bibleVerse',$c);
        $c->select(array(
            'id','book','chapter','verse','lsg', 'resource'
        ));
        $c->limit($limit,$offset);
        $verses = $modx->getCollection('bibleVerse',$c);
         
        $results = array();
        foreach ($verses as $verse) {   
          // Extract text and add highlighting
          // Use functions of the SimpleSearch class
          $searchObj = new SimpleSearch($modx,array());
          $searchObj->parseSearchString($search);
           
          $extract = $verse->get('lsg');
          $extract = $searchObj->createExtract($extract, 200, $search,'…'); // number of chard and char to use for ellipsis 
          $extract = preg_replace("#\[\[(.*?)\]\]#si", '', $extract); // cleanup extract
          $extract = str_replace(array('[[',']]'), '', $extract);
          $extract = $searchObj->addHighlighting($extract, 'sisea-highlight', 'span'); // highlighting class and tag
              
          $results[] = array(
                'id' => $verse->get('id'),
                'pagetitle' => $verse->get('chapter'), 
                'longtitle' => $verse->get('verse'), 
                'introtext' => $verse->get('lsg'), 
                'link' => $verse->get('book'), 
                'extract' => $extract
            );
        }
        $hook->addFacet('verses',$results,$count);
             
        return true;
        }
        


        Anything?
          A MODx Fanatic
          • 3749
          • 24,544 Posts
          I can't find anything wrong with that other than the fact that $search, $offset, $limit, and $hook are undefined.
          I suspect that the error is in the class file of the package you're loading, or a file that it includes.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 30585
            • 833 Posts
            Thanks for your help Bob.

            I'll keep digging. The package works fine with other custom snippets though -- it's is rather strgnge.
              A MODx Fanatic
              • 3749
              • 24,544 Posts
              Feel free to post the class file code here.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 30585
                • 833 Posts
                Hey Bob,

                Here's what's inside core/components/bible/model/bible/mysql/bibleverse.class.php

                <?php
                require_once (dirname(dirname(__FILE__)) . '/bibleverse.class.php');
                class bibleVerse_mysql extends bibleVerse {}


                And while we're at it, here's the core/components/bible/model/bible/mysql/bibleverse.map.inc.php

                <?php
                $xpdo_meta_map['bibleVerse']= array (
                  'package' => 'bible',
                  'version' => '1.1',
                  'table' => 'bible_verses',
                  'extends' => 'xPDOSimpleObject',
                  'fields' => 
                  array (
                    'book' => 0,
                    'resource' => 0,
                    'chapter' => 0,
                    'verse' => 0,
                    'lsg' => 'None',
                    'darby' => 'None',
                    'ostervald' => 'None',
                    'martin' => 'None',
                    'is_promesse' => 0,
                  ),
                  'fieldMeta' => 
                  array (
                    'book' => 
                    array (
                      'dbtype' => 'INT',
                      'precision' => '3',
                      'phptype' => 'integer',
                      'null' => false,
                      'default' => 0,
                    ),
                    'resource' => 
                    array (
                      'dbtype' => 'INT',
                      'precision' => '11',
                      'phptype' => 'integer',
                      'null' => false,
                      'default' => 0,
                    ),
                    'chapter' => 
                    array (
                      'dbtype' => 'INT',
                      'precision' => '3',
                      'phptype' => 'integer',
                      'null' => false,
                      'default' => 0,
                    ),
                    'verse' => 
                    array (
                      'dbtype' => 'INT',
                      'precision' => '3',
                      'phptype' => 'integer',
                      'null' => false,
                      'default' => 0,
                    ),
                    'lsg' => 
                    array (
                      'dbtype' => 'text',
                      'phptype' => 'string',
                      'null' => false,
                      'default' => 'None',
                    ),
                    'darby' => 
                    array (
                      'dbtype' => 'text',
                      'phptype' => 'string',
                      'null' => false,
                      'default' => 'None',
                    ),
                    'ostervald' => 
                    array (
                      'dbtype' => 'text',
                      'phptype' => 'string',
                      'null' => false,
                      'default' => 'None',
                    ),
                    'martin' => 
                    array (
                      'dbtype' => 'text',
                      'phptype' => 'string',
                      'null' => false,
                      'default' => 'None',
                    ),
                    'is_promesse' => 
                    array (
                      'dbtype' => 'int',
                      'precision' => '1',
                      'attributes' => 'unsigned',
                      'phptype' => 'integer',
                      'null' => false,
                      'default' => 0,
                    ),
                  ),
                  'indexes' => 
                  array (
                    'lsg' => 
                    array (
                      'alias' => 'lsg',
                      'primary' => false,
                      'unique' => false,
                      'type' => 'BTREE',
                      'columns' => 
                      array (
                        'lsg' => 
                        array (
                          'length' => '',
                          'collation' => 'A',
                          'null' => false,
                        ),
                      ),
                    ),
                  ),
                  'aggregates' => 
                  array (
                    'Resource' => 
                    array (
                      'class' => 'modResource',
                      'local' => 'resource',
                      'foreign' => 'id',
                      'cardinality' => 'one',
                      'owner' => 'foreign',
                    ),
                    'Book' => 
                    array (
                      'class' => 'bibleBook',
                      'local' => 'book',
                      'foreign' => 'id',
                      'cardinality' => 'one',
                      'owner' => 'foreign',
                    ),
                  ),
                );
                


                These files were created and updated via MIGXdb.
                  A MODx Fanatic
                  • 3749
                  • 24,544 Posts
                  Hmm... a closer reading of the error message suggests that the problem is with this array, though there's no PHP syntax error in this part of it that I can see:

                  $c->where(array(
                      'lsg:LIKE' => '%'.$search.'%',
                      'OR:book:LIKE' => '%'.$search.'%',
                      'OR:chapter:LIKE' => '%'.$search.'%',
                      'OR:verse:LIKE' => '%'.$search.'%',
                  ));



                  Do you know what $search is set to?

                  BTW, since this is an issue involving MIGXdb, you might get a better answer in a MIGX-related thread. I'm not an expert in any of the MIGX family of extras.
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 30585
                    • 833 Posts
                    Funny you mentioned it. It looks like $search is actually not set to anything at all. I guess the idea was to pass the value of the searchIndex of the SimpleSearch snippet. I tried doing this: $search = $_GET['search'];, but it didn't work. This is supposed to be a posthook for SimpleSearch.
                      A MODx Fanatic
                      • 3749
                      • 24,544 Posts
                      I've never used SimpleSearch, but it might be $hook->getValue('search') if it's like other snippets with postHooks.
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting