ulrikkold

prepareResultRowTemplateData_postProc hook in indexed_search

Nov 15th, 2012
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.03 KB | None | 0 0
  1. <?php
  2. /* * *************************************************************
  3.  *  Copyright notice
  4.  *
  5.  *  (c) 2012 Ulrik Høyer Kold ([email protected])
  6.  *  All rights reserved
  7.  *
  8.  *  This script is part of the TYPO3 project. The TYPO3 project is
  9.  *  free software; you can redistribute it and/or modify
  10.  *  it under the terms of the GNU General Public License as published by
  11.  *  the Free Software Foundation; either version 2 of the License, or
  12.  *  (at your option) any later version.
  13.  *
  14.  *  The GNU General Public License can be found at
  15.  *  http://www.gnu.org/copyleft/gpl.html.
  16.  *  A copy is found in the textfile GPL.txt and important notices to the license
  17.  *  from the author is found in LICENSE.txt distributed with these scripts.
  18.  *
  19.  *
  20.  *  This script is distributed in the hope that it will be useful,
  21.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  22.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23.  *  GNU General Public License for more details.
  24.  *
  25.  *  This copyright notice MUST APPEAR in all copies of the script!
  26.  * ************************************************************* */
  27. /**
  28.  * Index search frontend example hook
  29.  *
  30.  * @author  Ulrik Høyer Kold <[email protected]>
  31.  */
  32.  
  33. /**
  34.  * Index search frontend - EXAMPLE hook for alternative searching / display etc.
  35.  * Hooks are configured in ext_localconf.php as key => hook-reference pairs in $TYPO3_CONF_VARS['EXTCONF']['indexed_search']['pi1_hooks']. See example in ext_localconf.php for "indexed_search"
  36.  * Each hook must have an entry, the key must match the hook-key in class.tx_indexed_search.php and generally the key equals the function name in the hook object (a convension used)
  37.  *
  38.  * @package TYPO3
  39.  * @subpackage tx_indexedsearch
  40.  * @author  Ulrik Høyer Kold <[email protected]>
  41.  */
  42. class tx_indexedsearch_pihook {
  43.  
  44.     var $pObj;  // Is set to a reference to the parent object, "pi1/class.indexedsearch.php"
  45.  
  46.     /**
  47.      * EXAMPLE of how you can post process the initialized values in the frontend plugin.
  48.      * The example reverses the order of elements in the ranking selector box. You can modify other values like this or add / remove items.
  49.      *
  50.      * This hook is activated by this key / value pair in ext_localconf.php
  51.      *      'initialize_postProc' => 'EXT:indexed_search/example/class.pihook.php:&tx_indexedsearch_pihook',
  52.      *
  53.      * @return  void
  54.      */
  55.  
  56.     function initialize_postProc() {
  57.         $this->pObj->optValues['order'] = array_reverse($this->pObj->optValues['order']);
  58.     }
  59.  
  60.     /**
  61.      * Providing an alternative search algorithm!
  62.      *
  63.      * @param   array       Array of search words
  64.      * @return  array       Array of first row, result rows, count
  65.      */
  66. #   function getResultRows($sWArr)  {
  67. #   }
  68.  
  69.     /**
  70.      * Example of how the content displayed in the result rows can be post processed before rendered into HTML.
  71.      * This example simply shows how the description field is wrapped in italics and the path is hidden by setting it blank.
  72.      *
  73.      * @param   array       Template Content (generated from result row) being processed.
  74.      * @param   array       Result row
  75.      * @param   boolean     If set, the result row is a sub-row.
  76.      * @return  array       Template Content returned.
  77.      */
  78.     function prepareResultRowTemplateData_postProc($tmplContent, $row, $headerOnly) {
  79.  
  80.         if ($row['show_resume']) {
  81.             $markedSW = '';
  82.  
  83.             if (tx_indexedsearch_util::isTableUsed('index_fulltext')) {
  84.                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'index_fulltext, index_phash, pages', 'index_fulltext.phash=' . intval($row['phash']) . ' AND index_fulltext.phash=index_phash.phash AND index_phash.data_page_id = pages.uid');
  85.             } else {
  86.                 $res = FALSE;
  87.             }
  88.  
  89.             if ($res) {
  90.                 if ($ftdrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
  91.                    
  92.                     // Cut HTTP references after some length
  93.                     $markedSW = preg_replace('/(http:\/\/[^ ]{60})([^ ]+)/i', '$1...', $ftdrow['fulltextdata']);
  94.                    
  95.                     // strip the title
  96.                     $markedSW = preg_replace('/^' . preg_quote($ftdrow['title'],'/') . '/', '', trim($markedSW));
  97.                     $markedSW = preg_replace('/^,/', '', trim($markedSW));
  98.                    
  99.                     // strip the description
  100.                     $markedSW = preg_replace('/^' . preg_quote($ftdrow['description'],'/') . '/', '', trim($markedSW));
  101.                     $markedSW = preg_replace('/^,/', '', trim($markedSW));
  102.                    
  103.                     // strip the keywords - they are next in the fulltextdata field.
  104.                     $markedSW = preg_replace('/^' . preg_quote($ftdrow['keywords'],'/') . '/', '', trim($markedSW));
  105.                     $markedSW = preg_replace('/^,/', '', trim($markedSW));
  106.                    
  107.                     // strip the title again ...
  108.                     $markedSW = preg_replace('/^' . preg_quote($ftdrow['title'],'/') . '/', '', trim($markedSW));
  109.                     $markedSW = preg_replace('/^,/', '', trim($markedSW));
  110.                    
  111.                     $markedSW = $this->pObj->markupSWpartsOfString($markedSW);
  112.                    
  113.                 }
  114.                 $GLOBALS['TYPO3_DB']->sql_free_result($res);
  115.             }
  116.  
  117.             if (!trim($markedSW)) {
  118.                 $outputStr = $GLOBALS['TSFE']->csConvObj->crop('utf-8', $row['item_description'], $lgd);
  119.                 $outputStr = htmlspecialchars($outputStr);
  120.             }
  121.             $output = $this->utf8_to_currentCharset($outputStr ? $outputStr : $markedSW);
  122.             $tmplContent['description'] = $output;
  123.         }
  124.  
  125.         return $tmplContent;
  126.     }
  127.    
  128.    
  129.     /**
  130.      * Converts the input string from utf-8 to the backend charset.
  131.      *
  132.      * @param   string      String to convert (utf-8)
  133.      * @return  string      Converted string (backend charset if different from utf-8)
  134.      */
  135.     function utf8_to_currentCharset($str)   {
  136.         return $GLOBALS['TSFE']->csConv($str,'utf-8');
  137.     }    
  138.  
  139. }
Advertisement
Add Comment
Please, Sign In to add comment