Ok, the
"Parse error: syntax error, unexpected (T_CONSTANT_ENCAPSED_STRING)" was caused by exotic white space characters that are rendered as spaces. These ones for example:     or �. They're obviously invisible to the eye and you get them usually by copy-pasting code like I did with the Faceted Search example from the docs.
For anyone following, I fixed the issue by deleting all the white space characters, as discussed
here.
<?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->innerJoin('modResource', 'Resource');
$c->where(array(
'BibleVerse.book:LIKE' => '%' . $search . '%',
'BibleVerse.lsg:LIKE' => '%' . $search . '%',
'OR:BibleVerse.chapter:LIKE' => '%' . $search . '%',
'OR:BibleVerse.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('resource'),
'extract' => $extract
);
}
$hook->addFacet('verses', $results, $count);
return true;
?>