Untitled
unknown
plain_text
a month ago
5.4 kB
3
Indexable
Never
<div id="searchResults"> <?php $searchResultsFor = isset($this->templateVars['Search::ResultsFor']) ? $this->templateVars['Search::ResultsFor'] : $this->lang['searchResultsFor']; $searchResultFor = isset($this->templateVars['Search::ResultFor']) ? $this->templateVars['Search::ResultFor'] : $this->lang['searchResultFor']; $searchNoResultsFor = isset($this->templateVars['Search::NoResultsFor']) ? $this->templateVars['Search::NoResultsFor'] : $this->lang['noSearchResultsFor']; $localeCode = isset($this->locale['localeCode']) ? $this->locale['localeCode'] : ''; ?> <?php if(!empty($this->searchResults)) : ?> <?php if (strpos($searchNoResultsFor, '%s') === false) { $searchNoResultsFor = $searchNoResultsFor . '%s'; } if (strpos($searchResultsFor, '%s') === false) { $searchResultsFor = '%s' . $searchResultsFor . '%s'; } if (strpos($searchResultFor, '%s') === false) { $searchResultFor = $searchResultFor . '%s'; } ?> <?php if(count($this->searchResults) > 1) : ?> <p><?=sprintf($searchResultsFor, count($this->searchResults), '"<em>' . $this->escape($this->keyword) . '</em>"')?></p> <?php else: ?> <p><?=sprintf($searchResultFor, '"<em>' . $this->escape($this->keyword) . '</em>"')?></p> <?php endif; ?> <?php $pageSize = 8; $currentPage = isset($this->request['p']) && (int) $this->request['p'] > 0 ? (int) $this->request['p'] : 1; $paginator = Zend_Paginator::factory($this->searchResults); $paginator->setItemCountPerPage($pageSize); $pageCount = $paginator->count(); $currentPage = ($currentPage > $pageCount) ? $pageCount : $currentPage; $paginator->setCurrentPageNumber($currentPage); $pages = $paginator->getPages(); $paginator->setView($this); ?> <?php if($pageCount > 1) : ?> <?=$this->paginationControl($paginator, null, '_pagination.phtml', array( 'request' => $this->request, 'keyword' => $this->keyword ))?> <?php endif;?> <?php foreach ($paginator->getCurrentItems() as $result) : ?> <?php $body = trim($result['body']); $searchBody = ''; $offset = 0; $hitLength = 100; $keywordLength = strlen($this->keyword); for($i = 0; $i < 3; $i++) { if($offset > strlen($body)) { break; } $offset = stripos($body, $this->keyword, $offset); if($offset === false) { break; } $start = ($offset - ($hitLength / 2) > 0) ? (int) $offset - ($hitLength / 2) : 0; $hitString = substr($body, $start, $hitLength); $offset += $hitLength; if($start !== 0) { $hitString = substr($hitString, strpos($hitString, ' ') + 1); if($i === 0) { $searchBody .= '...'; } } $searchBody .= $hitString; if($offset < strlen($body)) { $searchBody = substr($searchBody, 0, strrpos($searchBody, ' ')); $searchBody .= ' ... '; } } if(strlen($searchBody) == 0) { $searchBody = substr($body, 0, 200); if(200 < strlen($body)) { $searchBody = substr($searchBody, 0, strrpos($searchBody, ' ')); $searchBody .= ' ...'; } } ?> <?php if (!empty($localeCode) && !empty($this->locales[1])) : ?> <p> <strong><a href="<?=$localeCode?>/<?=$result['url']?>" data-matches="<?=$result['matches']?>"><?=trim($result['title'])?></a></strong><br /> <?=preg_replace('#('.$this->escape($this->keyword).')#i', '<strong>$1</strong>', $searchBody)?> <hr /> </p> <?php else : ?> <p> <strong><a href="<?=$result['url']?>" data-matches="<?=$result['matches']?>"><?=trim($result['title'])?></a></strong><br /> <?=preg_replace('#('.$this->escape($this->keyword).')#i', '<strong>$1</strong>', $searchBody)?> <hr /> </p> <?php endif; ?> <?php endforeach; ?> <?php if($pageCount > 1) : ?> <?=$this->paginationControl( $paginator, null, '_pagination.phtml', array( 'request' => $this->request, 'keyword' => $this->keyword ))?> <?php endif;?> <?php else: ?> <p><?=sprintf($searchNoResultsFor, '"<em>' . $this->escape($this->keyword) . '</em>"')?></p> <?php endif; ?> </div>