Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
  1:  <?php
  2: 
  3: /**
  4:  *
  5:  * @package Module
  6:  * @subpackage search_result
  7:  * @version SVN Revision $Rev:$
  8:  * @author marcus.gnass@4fb.de
  9:  * @copyright four for business AG
 10:  * @link http://www.4fb.de
 11:  */
 12: 
 13: /**
 14:  *
 15:  * @author marcus.gnass
 16:  */
 17: class SearchResultModule {
 18: 
 19:     /**
 20:      *
 21:      * @var unknown_type
 22:      */
 23:     protected $_countValues;
 24: 
 25:     /**
 26:      *
 27:      * @var unknown_type
 28:      */
 29:     protected $_searchResultCount = 0;
 30: 
 31:     /**
 32:      *
 33:      * @var array
 34:      */
 35:     protected $_label;
 36: 
 37:     /**
 38:      *
 39:      * @var int
 40:      */
 41:     protected $_itemsPerPage;
 42: 
 43:     /**
 44:      *
 45:      * @var int
 46:      */
 47:     protected $_maxTeaserTextLen;
 48: 
 49:     /**
 50:      *
 51:      * @var string
 52:      */
 53:     protected $_searchTerm;
 54: 
 55:     /**
 56:      *
 57:      * @var string
 58:      */
 59:     protected $_dispSearchTerm = NULL;
 60: 
 61:     /**
 62:      *
 63:      * @var string
 64:      */
 65:     protected $_prepSearchTerm = NULL;
 66: 
 67:     /**
 68:      *
 69:      * @var array
 70:      */
 71:     protected $_searchResultData = NULL;
 72: 
 73:     /**
 74:      *
 75:      * @var cSearchResult
 76:      */
 77:     protected $_searchResults = NULL;
 78: 
 79:     /**
 80:      *
 81:      * @var int
 82:      */
 83:     protected $_numberOfPages = NULL;
 84: 
 85:     /**
 86:      *
 87:      * @param array $options
 88:      */
 89:     public function __construct(array $options = NULL) {
 90: 
 91:         // generic way to set options
 92:         if (NULL !== $options) {
 93:             foreach ($options as $name => $value) {
 94:                 $name = '_' . $name;
 95:                 $this->$name = $value;
 96:             }
 97:         }
 98: 
 99:         // get global variables from registry (the nice way)
100:         $this->_cfg = cRegistry::getConfig();
101:         $this->_db = cRegistry::getDb();
102:         $this->_client = cRegistry::getClientId();
103:         $this->_lang = cRegistry::getLanguageId();
104:         $this->_idcat = cRegistry::getCategoryId();
105:         $this->_idart = cRegistry::getArticleId();
106:         $this->_sess = cRegistry::getSession();
107: 
108:         // get global variables (the ugly way)
109:         global $sArtSpecs;
110:         $this->_artSpecs = $sArtSpecs;
111: 
112:         // perform first preparation of searchterm
113:         $searchTerm = $this->_searchTerm;
114:         $searchTerm = stripslashes($searchTerm);
115:         $searchTerm = strip_tags($searchTerm);
116:         $searchTerm = conHtmlentities($searchTerm);
117: 
118:         $searchTerm = urldecode($searchTerm);
119:         $searchTerm = str_replace(' + ', ' AND ', $searchTerm);
120:         $searchTerm = str_replace(' - ', ' NOT ', $searchTerm);
121: 
122:         // that's the search term suitable for display
123:         $this->_dispSearchTerm = $searchTerm;
124: 
125:         // now parse search term and set search options
126:         if (strlen(trim($searchTerm)) > 0) {
127:             $searchTerm = conHtmlEntityDecode($searchTerm);
128:             if (false === stristr($searchTerm, ' or ')) {
129:                 $this->_combine = 'and';
130:             } else {
131:                 $this->_combine = 'or';
132:             }
133: 
134:             $searchTerm = htmlentities($searchTerm, ENT_COMPAT, 'UTF-8');
135:             $searchTerm = (trim(strtolower($searchTerm)));
136:             $searchTerm = html_entity_decode($searchTerm, ENT_COMPAT, 'UTF-8');
137: 
138:             $searchTerm = str_replace(' and ', ' ', $searchTerm);
139:             $searchTerm = str_replace(' or ', ' ', $searchTerm);
140:         }
141: 
142:         // that's the search term suitable for the search itself
143:         $this->_prepSearchTerm = $searchTerm;
144: 
145:         // perform search
146:         $this->_performSearch();
147:     }
148: 
149:     /**
150:      */
151:     public function render() {
152:         $tpl = cSmartyFrontend::getInstance();
153: 
154:         $tpl->assign('label', $this->_label);
155:         $tpl->assign('searchTerm', $this->_dispSearchTerm);
156:         $tpl->assign('currentPage', $this->_page);
157: 
158:         $tpl->assign('results', $this->_getResults());
159:         $tpl->assign('msgResult', $this->_msgResult);
160:         $tpl->assign('msgRange', $this->_msgRange);
161:         $tpl->assign('prev', $this->_getPreviousLink());
162:         $tpl->assign('next', $this->_getNextLink());
163:         $tpl->assign('pages', $this->_getPageLinks());
164: 
165:         // determine action & method for search form
166:         // depends upon if plugin mod_rewrite is enabled
167:         if (class_exists('ModRewrite') && ModRewrite::isEnabled()) {
168:             $tpl->assign('action', cUri::getInstance()->build(array(
169:                 'idart' => cRegistry::getArticleLanguageId(),
170:                 'lang' => cRegistry::getLanguageId()
171:             )));
172:         } else {
173:             $tpl->assign('action', 'front_content.php');
174:             $tpl->assign('idart', cRegistry::getArticleLanguageId());
175:             $tpl->assign('idlang', cRegistry::getLanguageId());
176:         }
177: 
178:         $tpl->display($this->_templateName);
179:     }
180: 
181:     /**
182:      */
183:     protected function _performSearch() {
184: 
185:         // build search object
186:         // only certain content types will be searched
187:         $search = new cSearch(array(
188:             // use db function regexp
189:             'db' => 'regexp',
190:             // combine searchterms with and
191:             'combine' => $this->_combine,
192:             // => searchrange specified in 'cat_tree', 'categories' and
193:             // 'articles' is excluded, otherwise included (exclusive)
194:             'exclude' => false,
195:             // searchrange
196:             'cat_tree' => $this->_getSearchableIdcats(),
197:             // array of article specifications
198:             // => search only articles with these artspecs
199:             'artspecs' => $this->_getArticleSpecs(),
200:             // => do not search articles or articles in categories which are
201:             // offline or protected
202:             'protected' => true
203:         ));
204:         $search->setCmsOptions(array(
205:             'head',
206:             'html',
207:             'htmlhead',
208:             'htmltext',
209:             'text'
210:         ));
211:         if (strlen($this->_prepSearchTerm) > 1) {
212:             $searchResultArray = $search->searchIndex($this->_prepSearchTerm, '');
213: 
214:             $searchResultCount = 0;
215:             if (false !== $searchResultArray) {
216: 
217:                 $this->_searchResultCount = count($searchResultArray);
218: 
219:                 // get search results
220:                 $this->_searchResults = new cSearchResult($searchResultArray, $this->_itemsPerPage);
221: 
222:                 // get number of pages
223:                 $this->_numberOfPages = $this->_searchResults->getNumberOfPages();
224: 
225:                 // html-tags to emphasize the located searchterms
226:                 $this->_searchResults->setReplacement('<strong>', '</strong>');
227:             }
228: 
229:             // create message to display
230:             if (0 === $this->_searchResultCount) {
231:                 $this->_msgResult = sprintf($this->_label['msgNoResultsFound'], $this->_dispSearchTerm);
232:             } else {
233:                 $this->_msgResult = sprintf($this->_label['msgResultsFound'], $this->_dispSearchTerm, $this->_searchResultCount);
234:             }
235:         }
236:     }
237: 
238:     /**
239:      *
240:      * @return string
241:      */
242:     protected function _getMsgResult() {
243:         return $this->_msgResult;
244:     }
245: 
246:     /**
247:      *
248:      * @param unknown_type $count
249:      * @param unknown_type $countIdarts
250:      */
251:     protected function _setMsgResult($count, $countIdarts) {
252:         $this->_countValues = $count;
253: 
254:         // $this->_numberOfPages = 1;
255:         if (0 === $this->_searchResultCount) {
256:             $this->_msgResult = sprintf($this->_label['msgNoResultsFound'], $this->_dispSearchTerm);
257:         } else {
258:             $this->_msgResult = sprintf($this->_label['msgResultsFound'], $this->_dispSearchTerm, $this->_searchResultCount);
259:         }
260:     }
261: 
262:     /**
263:      * Returns IDCATs of setting searchable/idcats as array.
264:      * Default value is 1.
265:      *
266:      * @return array
267:      */
268:     protected function _getSearchableIdcats() {
269:         $searchableIdcats = getEffectiveSetting('searchable', 'idcats', 1);
270:         $searchableIdcats = explode(',', $searchableIdcats);
271: 
272:         return $searchableIdcats;
273:     }
274: 
275:     /**
276:      * Get all article specs of current client in current language.
277:      *
278:      * TODO use cApiArticleSpecificationCollection instead
279:      *
280:      * @return array
281:      */
282:     protected function _getArticleSpecs() {
283:         $sql = "-- getArticleSpecs()
284:             SELECT
285:                 idartspec
286:                 , artspec
287:             FROM
288:                 " . $this->_cfg['tab']['art_spec'] . "
289:             WHERE
290:                 client = $this->_client
291:                 AND lang = $this->_lang
292:                 AND online = 1
293:             ;";
294: 
295:         $this->_db->query($sql);
296: 
297:         $aArtSpecs = array();
298:         while ($this->_db->next_record()) {
299:             $aArtSpecs[] = $this->_db->f('idartspec');
300:         }
301:         $aArtSpecs[] = 0;
302: 
303:         return $aArtSpecs;
304:     }
305: 
306:     /**
307:      *
308:      * @return array
309:      */
310:     protected function _getResults() {
311:         if (NULL === $this->_searchResults) {
312:             return array();
313:         }
314: 
315:         // get current result page
316:         $searchResultPage = $this->_searchResults->getSearchResultPage($this->_page);
317: 
318:         // skip if current page has no results
319:         if (0 == count($searchResultPage) > 0) {
320:             return array();
321:         }
322: 
323:         // build single search result on result page
324:         $entries = array();
325:         $i = 0;
326:         foreach (array_keys($searchResultPage) as $idart) {
327: 
328:             $i++;
329: 
330:             // get absolute number of current search result
331:             $number = $this->_itemsPerPage * ($this->_page - 1) + $i;
332: 
333:             // get headlines
334:             $headlines = $this->_searchResults->getSearchContent($idart, 'HTMLHEAD', 1);
335:             $headline = cApiStrTrimAfterWord($headlines[0], $this->_maxTeaserTextLen);
336: 
337:             // get subheadlines
338:             $subheadlines = $this->_searchResults->getSearchContent($idart, 'HTMLHEAD', 2);
339:             $subheadline = cApiStrTrimAfterWord($subheadlines[0], $this->_maxTeaserTextLen);
340: 
341:             // get paragraphs
342:             $paragraphs = $this->_searchResults->getSearchContent($idart, 'HTML', 1);
343:             $paragraph = cApiStrTrimAfterWord($paragraphs[0], $this->_maxTeaserTextLen);
344: 
345:             // get similarity
346:             $similarity = $this->_searchResults->getSimilarity($idart);
347:             $similarity = sprintf("%.0f", $similarity);
348: 
349:             // build link to that result page
350:             $href = cUri::getInstance()->build(array(
351:                 'lang' => cRegistry::getLanguageId(),
352:                 'idcat' => $this->_searchResults->getArtCat($idart),
353:                 'idart' => $idart
354:             ));
355: 
356:             // assemble entry
357:             $entries[] = array(
358:                 'number' => $number,
359:                 'headline' => $headline,
360:                 'subheadline' => $subheadline,
361:                 'paragraph' => $paragraph,
362:                 'similarity' => $similarity,
363:                 'href' => $href
364:             );
365:         }
366: 
367:         $lower = ($this->_page - 1) * $this->_itemsPerPage + 1;
368:         $upper = $lower + count($entries) - 1;
369:         $total = $this->_searchResults->getNumberOfResults();
370: 
371:         $this->_msgRange = sprintf($this->_label['msgRange'], $lower, $upper, $total);
372: 
373:         return $entries;
374:     }
375: 
376:     /**
377:      *
378:      * @return string
379:      */
380:     protected function _getPreviousLink() {
381: 
382:         // skip if there are no previous pages
383:         if (1 >= $this->_page) {
384:             return '';
385:         }
386: 
387:         // build link to previous result page
388:         $url = $this->_getPageLink($this->_dispSearchTerm, $this->_page - 1);
389: 
390:         return $url;
391:     }
392: 
393:     /**
394:      *
395:      * @return string
396:      */
397:     protected function _getNextLink() {
398: 
399:         // skip if there are no next pages
400:         if ($this->_page >= $this->_numberOfPages) {
401:             return '';
402:         }
403: 
404:         // build link to next result page
405:         $url = $this->_getPageLink($this->_dispSearchTerm, $this->_page + 1);
406: 
407:         return $url;
408:     }
409: 
410:     /**
411:      * Build links to other result pages.
412:      *
413:      * @return string
414:      */
415:     protected function _getPageLinks() {
416:         $pageLinks = array();
417:         for ($i = 1; $i <= $this->_numberOfPages; $i++) {
418:             $pageLinks[$i] = $this->_getPageLink($this->_dispSearchTerm, $i);
419:         }
420: 
421:         return $pageLinks;
422:     }
423: 
424:     /**
425:      * This method builds URLs for each result link and the pagination links.
426:      *
427:      *
428:      * @param string $searchTerm
429:      * @param int $page
430:      * @return mixed
431:      */
432:     protected function _getPageLink($searchTerm = NULL, $page = NULL) {
433: 
434:         // define standard params
435:         $params = array(
436:             'lang' => $this->_lang,
437:             'idcat' => $this->_idcat,
438:             'idart' => $this->_idart
439:         );
440:         // add optional params if given
441:         if (NULL !== $searchTerm) {
442:             $params['search_term'] = $searchTerm;
443:         }
444:         if (NULL !== $page) {
445:             $params['page'] = $page . $this->_artSpecs;
446:         }
447:         // store unaltered params for later use
448:         $defaultParams = $params;
449: 
450:         // define special params when 'front_content' or 'MR' url builders are
451:         // *NOT* used in this case the standard params are wrapped as 'search'
452:         // and lang, idcat & level are aded cause they are needed to build the
453:         // category path
454:         $url_builder = array(
455:             'front_content',
456:             'MR'
457:         );
458:         if (false === in_array($this->_cfg['url_builder']['name'], $url_builder)) {
459:             $params = array(
460:                 'search' => $params,
461:                 'lang' => $this->_lang,
462:                 'idcat' => $this->_idcat,
463:                 'level' => 1
464:             );
465:         }
466: 
467:         try {
468:             $url = cUri::getInstance()->build($params);
469:         } catch (cInvalidArgumentException $e) {
470:             $url = $this->_sess->url(implode('?', array(
471:                 'front_content.php',
472:                 implode('&', $defaultParams)
473:             )));
474:         }
475: 
476:         return $url;
477:     }
478: 
479: }
480: 
481: ?>
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen