| [ Index ] |
|
Code source de Typo3 4.1.3 |
1 <?php 2 /*************************************************************** 3 * Copyright notice 4 * 5 * (c) 2001-2005 Kasper Skaarhoj (kasperYYYY@typo3.com) 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 crawler hook example 29 * 30 * $Id: class.crawlerhook.php 1421 2006-04-10 09:27:15Z mundaun $ 31 * 32 * @author Kasper Skårhøj <kasperYYYY@typo3.com> 33 */ 34 /** 35 * [CLASS/FUNCTION INDEX of SCRIPT] 36 * 37 * 38 * 39 * 57: class tx_indexedsearch_crawlerhook 40 * 64: function initMessage() 41 * 80: function indexOperation($cfgRec,&$session_data,$params,&$pObj) 42 * 43 * TOTAL FUNCTIONS: 2 44 * (This index is automatically created/updated by the extension "extdeveval") 45 * 46 */ 47 48 49 50 /** 51 * Index search crawler hook example 52 * 53 * @package TYPO3 54 * @subpackage tx_indexedsearch 55 * @author Kasper Skårhøj <kasperYYYY@typo3.com> 56 */ 57 class tx_indexedsearch_crawlerhook { 58 59 /** 60 * Function is called when an indexing session starts according to the time intervals set for the indexing configuration. 61 * 62 * @return string Return a text string for the first, initiating queue entry for the crawler. 63 */ 64 function initMessage() { 65 return 'Start of Custom Example Indexing session!'; 66 } 67 68 /** 69 * This will do two things: 70 * 1) Carry out actual indexing of content (one or more items) 71 * 2) Add one or more new entries into the crawlers queue so we are called again (another instance) for further indexing in the session (optional of course, if all indexing is done, we add no new entries) 72 * 73 * @param array Indexing Configuration Record (the record which holds the information that lead to this indexing session...) 74 * @param array Session data variable. Passed by reference. Changed content is saved and passed back upon next instance in the session. 75 * @param array Params array from the queue entry. 76 * @param object Grant Parent Object (from "crawler" extension) 77 * @param object Parent Object (from "indexed_search" extension) 78 * @return void 79 */ 80 function indexOperation($cfgRec,&$session_data,$params,&$pObj) { 81 82 // Init session data array if not already: 83 if (!is_array($session_data)) { 84 $session_data = array( 85 'step' => 0 86 ); 87 } 88 89 // Increase step counter (this is just an example of how the session data can be used - to track how many instances of indexing is left) 90 $session_data['step']++; 91 92 93 switch((int)$session_data['step']) { 94 case 1: // Indexing Example: Content accessed with GET parameters added to URL: 95 96 // Load indexer if not yet [DON'T CHANGE]: 97 $pObj->loadIndexerClass(); 98 99 // Get rootline from the Indexing Record (needed because the indexer relates all search results to a position in the page tree!) [DON'T CHANGE]: 100 $rl = $pObj->getUidRootLineForClosestTemplate($cfgRec['pid']); 101 102 // Set up language uid, if any: 103 $sys_language_uid = 0; 104 105 // Set up 2 example items to index: 106 $exampleItems = array( 107 array( 108 'ID' => '123', 109 'title' => 'Title of Example 1', 110 'content' => 'Vestibulum leo turpis, fringilla sit amet, semper eget, vestibulum ut, arcu. Vestibulum mauris orci, vulputate quis, congue eget, nonummy' 111 ), 112 array( 113 'ID' => 'example2', 114 'title' => 'Title of Example 2', 115 'content' => 'Cras tortor turpis, vulputate non, accumsan a, pretium in, magna. Cras turpis turpis, pretium pulvinar, pretium vel, nonummy eu.' 116 ) 117 ); 118 119 // For each item, index it (this is what you might like to do in batches of like 100 items if all your content spans thousands of items!) 120 foreach($exampleItems as $item) { 121 122 // Prepare the GET variables array that must be added to the page URL in order to view result: 123 parse_str('&itemID='.rawurlencode($item['ID']), $GETparams); 124 125 // Prepare indexer (make instance, initialize it, set special features for indexing parameterized content - probably none of this should be changed by you) [DON'T CHANGE]: 126 $indexerObj = &t3lib_div::makeInstance('tx_indexedsearch_indexer'); 127 $indexerObj->backend_initIndexer($cfgRec['pid'], 0, $sys_language_uid, '', $rl, $GETparams, FALSE); 128 $indexerObj->backend_setFreeIndexUid($cfgRec['uid'], $cfgRec['set_id']); 129 $indexerObj->forceIndexing = TRUE; 130 131 // Indexing the content of the item (see tx_indexedsearch_indexer::backend_indexAsTYPO3Page() for options) 132 $indexerObj->backend_indexAsTYPO3Page( 133 $item['title'], 134 '', 135 '', 136 $item['content'], 137 $GLOBALS['LANG']->charSet, // Charset of content - MUST be set. 138 $item['tstamp'], // Last-modified date 139 $item['create_date'], // Created date 140 $item['ID'] 141 ); 142 } 143 break; 144 case 2: // Indexing Example: Content accessed directly in file system: 145 146 // Load indexer if not yet [DON'T CHANGE]: 147 $pObj->loadIndexerClass(); 148 149 // Get rootline from the Indexing Record (needed because the indexer relates all search results to a position in the page tree!) [DON'T CHANGE]: 150 $rl = $pObj->getUidRootLineForClosestTemplate($cfgRec['pid']); 151 152 // Set up language uid, if any: 153 $sys_language_uid = 0; 154 155 // Prepare indexer (make instance, initialize it, set special features for indexing parameterized content - probably none of this should be changed by you) [DON'T CHANGE]: 156 $indexerObj = &t3lib_div::makeInstance('tx_indexedsearch_indexer'); 157 $indexerObj->backend_initIndexer($cfgRec['pid'], 0, $sys_language_uid, '', $rl); 158 $indexerObj->backend_setFreeIndexUid($cfgRec['uid'], $cfgRec['set_id']); 159 $indexerObj->hash['phash'] = -1; // To avoid phash_t3 being written to file sections (otherwise they are removed when page is reindexed!!!) 160 161 // Index document: 162 $indexerObj->indexRegularDocument('fileadmin/templates/index.html', TRUE); 163 break; 164 case 3: // Indexing Example: Content accessed on External URLs: 165 166 // Load indexer if not yet. 167 $pObj->loadIndexerClass(); 168 169 // Index external URL: 170 $indexerObj = &t3lib_div::makeInstance('tx_indexedsearch_indexer'); 171 $indexerObj->backend_initIndexer($cfgRec['pid'], 0, $sys_language_uid, '', $rl); 172 $indexerObj->backend_setFreeIndexUid($cfgRec['uid'], $cfgRec['set_id']); 173 $indexerObj->hash['phash'] = -1; // To avoid phash_t3 being written to file sections (otherwise they are removed when page is reindexed!!!) 174 175 // Index external URL (HTML only): 176 $indexerObj->indexExternalUrl('http://www.google.com/'); 177 break; 178 } 179 180 // Finally, set entry for next indexing instance (if all steps are not completed) 181 if ($session_data['step']<=3) { 182 $title = 'Step #'.$session_data['step'].' of 3'; // Just information field. Never mind that the field is called "url" - this is what will be shown in the "crawler" log. Could be a URL - or whatever else tells what that indexing instance will do. 183 $pObj->addQueueEntryForHook($cfgRec, $title); 184 } 185 } 186 } 187 188 189 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/indexed_search/example/class.crawlerhook.php']) { 190 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/indexed_search/example/class.crawlerhook.php']); 191 } 192 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Nov 25 17:13:16 2007 | par Balluche grâce à PHPXref 0.7 |
|