Complex classes like tx_crawler_lib often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use tx_crawler_lib, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 32 | class tx_crawler_lib { |
||
| 33 | |||
| 34 | var $setID = 0; |
||
| 35 | var $processID =''; |
||
| 36 | var $max_CLI_exec_time = 3600; // One hour is max stalled time for the CLI (If the process has had the status "start" for 3600 seconds it will be regarded stalled and a new process is started. |
||
| 37 | |||
| 38 | var $duplicateTrack = array(); |
||
| 39 | var $downloadUrls = array(); |
||
| 40 | |||
| 41 | var $incomingProcInstructions = array(); |
||
| 42 | var $incomingConfigurationSelection = array(); |
||
| 43 | |||
| 44 | |||
| 45 | var $registerQueueEntriesInternallyOnly = array(); |
||
| 46 | var $queueEntries = array(); |
||
| 47 | var $urlList = array(); |
||
| 48 | |||
| 49 | var $debugMode=FALSE; |
||
| 50 | |||
| 51 | var $extensionSettings=array(); |
||
| 52 | |||
| 53 | var $MP = false; // mount point |
||
| 54 | |||
| 55 | protected $processFilename; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Holds the internal access mode can be 'gui','cli' or 'cli_im' |
||
| 59 | * |
||
| 60 | * @var string |
||
| 61 | */ |
||
| 62 | protected $accessMode; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var \TYPO3\CMS\Core\Database\DatabaseConnection |
||
| 66 | */ |
||
| 67 | private $db; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
||
| 71 | */ |
||
| 72 | private $backendUser; |
||
| 73 | |||
| 74 | const CLI_STATUS_NOTHING_PROCCESSED = 0; |
||
| 75 | const CLI_STATUS_REMAIN = 1; //queue not empty |
||
| 76 | const CLI_STATUS_PROCESSED = 2; //(some) queue items where processed |
||
| 77 | const CLI_STATUS_ABORTED = 4; //instance didn't finish |
||
| 78 | const CLI_STATUS_POLLABLE_PROCESSED = 8; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Method to set the accessMode can be gui, cli or cli_im |
||
| 82 | * |
||
| 83 | * @return string |
||
| 84 | */ |
||
| 85 | 1 | public function getAccessMode() { |
|
| 86 | 1 | return $this->accessMode; |
|
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @param string $accessMode |
||
| 91 | */ |
||
| 92 | 1 | public function setAccessMode($accessMode) { |
|
| 93 | 1 | $this->accessMode = $accessMode; |
|
| 94 | 1 | } |
|
| 95 | |||
| 96 | /** |
||
| 97 | * Set disabled status to prevent processes from being processed |
||
| 98 | * |
||
| 99 | * @param bool $disabled (optional, defaults to true) |
||
| 100 | * @return void |
||
| 101 | */ |
||
| 102 | 3 | public function setDisabled($disabled = true) { |
|
| 103 | 3 | if ($disabled) { |
|
| 104 | 2 | \TYPO3\CMS\Core\Utility\GeneralUtility::writeFile($this->processFilename, ''); |
|
| 105 | } else { |
||
| 106 | 1 | if (is_file($this->processFilename)) { |
|
| 107 | 1 | unlink($this->processFilename); |
|
| 108 | } |
||
| 109 | } |
||
| 110 | 3 | } |
|
| 111 | |||
| 112 | /** |
||
| 113 | * Get disable status |
||
| 114 | * |
||
| 115 | * @return bool true if disabled |
||
| 116 | */ |
||
| 117 | 3 | public function getDisabled() { |
|
| 118 | 3 | if (is_file($this->processFilename)) { |
|
| 119 | 2 | return true; |
|
| 120 | } else { |
||
| 121 | 1 | return false; |
|
| 122 | } |
||
| 123 | } |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @param string $filenameWithPath |
||
| 127 | * |
||
| 128 | * @return void |
||
| 129 | */ |
||
| 130 | 4 | public function setProcessFilename($filenameWithPath) |
|
| 131 | { |
||
| 132 | 4 | $this->processFilename = $filenameWithPath; |
|
| 133 | 4 | } |
|
| 134 | |||
| 135 | /** |
||
| 136 | * @return string |
||
| 137 | */ |
||
| 138 | 1 | public function getProcessFilename() |
|
| 139 | { |
||
| 140 | 1 | return $this->processFilename; |
|
| 141 | } |
||
| 142 | |||
| 143 | |||
| 144 | |||
| 145 | /************************************ |
||
| 146 | * |
||
| 147 | * Getting URLs based on Page TSconfig |
||
| 148 | * |
||
| 149 | ************************************/ |
||
| 150 | |||
| 151 | 23 | public function __construct() { |
|
| 152 | 23 | $this->db = $GLOBALS['TYPO3_DB']; |
|
| 153 | 23 | $this->backendUser = $GLOBALS['BE_USER']; |
|
| 154 | 23 | $this->processFilename = PATH_site.'typo3temp/tx_crawler.proc'; |
|
| 155 | |||
| 156 | 23 | $settings = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['crawler']); |
|
| 157 | 23 | $settings = is_array($settings) ? $settings : array(); |
|
| 158 | |||
| 159 | // read ext_em_conf_template settings and set |
||
| 160 | 23 | $this->setExtensionSettings($settings); |
|
| 161 | |||
| 162 | |||
| 163 | // set defaults: |
||
| 164 | 23 | if (\TYPO3\CMS\Core\Utility\MathUtility::convertToPositiveInteger($this->extensionSettings['countInARun']) == 0) { |
|
| 165 | 1 | $this->extensionSettings['countInARun'] = 100; |
|
| 166 | } |
||
| 167 | |||
| 168 | 23 | $this->extensionSettings['processLimit'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->extensionSettings['processLimit'],1,99,1); |
|
| 169 | 23 | } |
|
| 170 | |||
| 171 | /** |
||
| 172 | * Sets the extensions settings (unserialized pendant of $TYPO3_CONF_VARS['EXT']['extConf']['crawler']). |
||
| 173 | * |
||
| 174 | * @param array $extensionSettings |
||
| 175 | * @return void |
||
| 176 | */ |
||
| 177 | 31 | public function setExtensionSettings(array $extensionSettings) { |
|
| 178 | 31 | $this->extensionSettings = $extensionSettings; |
|
| 179 | 31 | } |
|
| 180 | |||
| 181 | /** |
||
| 182 | * Check if the given page should be crawled |
||
| 183 | * |
||
| 184 | * @param array $pageRow |
||
| 185 | * @return false|string false if the page should be crawled (not excluded), true / skipMessage if it should be skipped |
||
| 186 | * @author Fabrizio Branca <[email protected]> |
||
| 187 | */ |
||
| 188 | 6 | public function checkIfPageShouldBeSkipped(array $pageRow) { |
|
| 189 | |||
| 190 | 6 | $skipPage = false; |
|
| 191 | 6 | $skipMessage = 'Skipped'; // message will be overwritten later |
|
| 192 | |||
| 193 | // if page is hidden |
||
| 194 | 6 | if (!$this->extensionSettings['crawlHiddenPages']) { |
|
| 195 | 6 | if ($pageRow['hidden']) { |
|
| 196 | 1 | $skipPage = true; |
|
| 197 | 1 | $skipMessage = 'Because page is hidden'; |
|
| 198 | } |
||
| 199 | } |
||
| 200 | |||
| 201 | 6 | if (!$skipPage) { |
|
| 202 | 5 | if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList('3,4', $pageRow['doktype']) || $pageRow['doktype']>=199) { |
|
| 203 | 3 | $skipPage = true; |
|
| 204 | 3 | $skipMessage = 'Because doktype is not allowed'; |
|
| 205 | } |
||
| 206 | } |
||
| 207 | |||
| 208 | 6 | if (!$skipPage) { |
|
| 209 | 2 | if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['excludeDoktype'])) { |
|
| 210 | 2 | foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['excludeDoktype'] as $key => $doktypeList) { |
|
| 211 | 1 | if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList($doktypeList, $pageRow['doktype'])) { |
|
| 212 | 1 | $skipPage = true; |
|
| 213 | 1 | $skipMessage = 'Doktype was excluded by "'.$key.'"'; |
|
| 214 | 1 | break; |
|
| 215 | } |
||
| 216 | } |
||
| 217 | } |
||
| 218 | } |
||
| 219 | |||
| 220 | 6 | if (!$skipPage) { |
|
| 221 | // veto hook |
||
| 222 | 1 | if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['pageVeto'])) { |
|
| 223 | foreach($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['pageVeto'] as $key => $func) { |
||
| 224 | $params = array( |
||
| 225 | 'pageRow' => $pageRow |
||
| 226 | ); |
||
| 227 | // expects "false" if page is ok and "true" or a skipMessage if this page should _not_ be crawled |
||
| 228 | $veto = \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($func, $params, $this); |
||
| 229 | if ($veto !== false) { |
||
| 230 | $skipPage = true; |
||
| 231 | if (is_string($veto)) { |
||
| 232 | $skipMessage = $veto; |
||
| 233 | } else { |
||
| 234 | $skipMessage = 'Veto from hook "'.htmlspecialchars($key).'"'; |
||
| 235 | } |
||
| 236 | // no need to execute other hooks if a previous one return a veto |
||
| 237 | break; |
||
| 238 | } |
||
| 239 | } |
||
| 240 | } |
||
| 241 | } |
||
| 242 | |||
| 243 | 6 | return $skipPage ? $skipMessage : false; |
|
| 244 | } |
||
| 245 | |||
| 246 | /** |
||
| 247 | * Wrapper method for getUrlsForPageId() |
||
| 248 | * It returns an array of configurations and no urls! |
||
| 249 | * |
||
| 250 | * @param array $pageRow Page record with at least dok-type and uid columns. |
||
| 251 | * @param string $skipMessage |
||
| 252 | * @return array Result (see getUrlsForPageId()) |
||
| 253 | * @see getUrlsForPageId() |
||
| 254 | */ |
||
| 255 | 2 | public function getUrlsForPageRow(array $pageRow, &$skipMessage = '') { |
|
| 256 | 2 | $message = $this->checkIfPageShouldBeSkipped($pageRow); |
|
| 257 | |||
| 258 | 2 | if ($message === false) { |
|
| 259 | 1 | $forceSsl = ($pageRow['url_scheme'] === 2) ? true : false; |
|
| 260 | 1 | $res = $this->getUrlsForPageId($pageRow['uid'], $forceSsl); |
|
| 261 | 1 | $skipMessage = ''; |
|
| 262 | } else { |
||
| 263 | 1 | $skipMessage = $message; |
|
| 264 | 1 | $res = array(); |
|
| 265 | } |
||
| 266 | |||
| 267 | 2 | return $res; |
|
| 268 | } |
||
| 269 | |||
| 270 | /** |
||
| 271 | * This method is used to count if there are ANY unprocessed queue entries |
||
| 272 | * of a given page_id and the configuration which matches a given hash. |
||
| 273 | * If there if none, we can skip an inner detail check |
||
| 274 | * |
||
| 275 | * @param int $uid |
||
| 276 | * @param string $configurationHash |
||
| 277 | * @return boolean |
||
| 278 | */ |
||
| 279 | protected function noUnprocessedQueueEntriesForPageWithConfigurationHashExist($uid,$configurationHash) { |
||
| 280 | $configurationHash = $this->db->fullQuoteStr($configurationHash,'tx_crawler_queue'); |
||
| 281 | $res = $this->db->exec_SELECTquery('count(*) as anz','tx_crawler_queue',"page_id=".intval($uid)." AND configuration_hash=".$configurationHash." AND exec_time=0"); |
||
| 282 | $row = $this->db->sql_fetch_assoc($res); |
||
| 283 | |||
| 284 | return ($row['anz'] == 0); |
||
| 285 | } |
||
| 286 | |||
| 287 | /** |
||
| 288 | * Creates a list of URLs from input array (and submits them to queue if asked for) |
||
| 289 | * See Web > Info module script + "indexed_search"'s crawler hook-client using this! |
||
| 290 | * |
||
| 291 | * @param array Information about URLs from pageRow to crawl. |
||
| 292 | * @param array Page row |
||
| 293 | * @param integer Unix time to schedule indexing to, typically time() |
||
| 294 | * @param integer Number of requests per minute (creates the interleave between requests) |
||
| 295 | * @param boolean If set, submits the URLs to queue |
||
| 296 | * @param boolean If set (and submitcrawlUrls is false) will fill $downloadUrls with entries) |
||
| 297 | * @param array Array which is passed by reference and contains the an id per url to secure we will not crawl duplicates |
||
| 298 | * @param array Array which will be filled with URLS for download if flag is set. |
||
| 299 | * @param array Array of processing instructions |
||
| 300 | * @return string List of URLs (meant for display in backend module) |
||
| 301 | * |
||
| 302 | */ |
||
| 303 | function urlListFromUrlArray( |
||
|
|
|||
| 304 | array $vv, |
||
| 305 | array $pageRow, |
||
| 306 | $scheduledTime, |
||
| 307 | $reqMinute, |
||
| 308 | $submitCrawlUrls, |
||
| 309 | $downloadCrawlUrls, |
||
| 310 | array &$duplicateTrack, |
||
| 311 | array &$downloadUrls, |
||
| 312 | array $incomingProcInstructions) { |
||
| 313 | |||
| 314 | // realurl support (thanks to Ingo Renner) |
||
| 315 | if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('realurl') && $vv['subCfg']['realurl']) { |
||
| 316 | |||
| 317 | /** @var tx_realurl $urlObj */ |
||
| 318 | $urlObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_realurl'); |
||
| 319 | |||
| 320 | if (!empty($vv['subCfg']['baseUrl'])) { |
||
| 321 | $urlParts = parse_url($vv['subCfg']['baseUrl']); |
||
| 322 | $host = strtolower($urlParts['host']); |
||
| 323 | $urlObj->host = $host; |
||
| 324 | |||
| 325 | // First pass, finding configuration OR pointer string: |
||
| 326 | $urlObj->extConf = isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl'][$urlObj->host]) ? $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl'][$urlObj->host] : $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['_DEFAULT']; |
||
| 327 | |||
| 328 | // If it turned out to be a string pointer, then look up the real config: |
||
| 329 | if (is_string($urlObj->extConf)) { |
||
| 330 | $urlObj->extConf = is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl'][$urlObj->extConf]) ? $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl'][$urlObj->extConf] : $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['_DEFAULT']; |
||
| 331 | } |
||
| 332 | |||
| 333 | } |
||
| 334 | |||
| 335 | if (!$GLOBALS['TSFE']->sys_page) { |
||
| 336 | $GLOBALS['TSFE']->sys_page = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Frontend\Page\PageRepository'); |
||
| 337 | } |
||
| 338 | if (!$GLOBALS['TSFE']->csConvObj) { |
||
| 339 | $GLOBALS['TSFE']->csConvObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Charset\CharsetConverter'); |
||
| 340 | } |
||
| 341 | if (!$GLOBALS['TSFE']->tmpl->rootLine[0]['uid']) { |
||
| 342 | $GLOBALS['TSFE']->tmpl->rootLine[0]['uid'] = $urlObj->extConf['pagePath']['rootpage_id']; |
||
| 343 | } |
||
| 344 | } |
||
| 345 | |||
| 346 | if (is_array($vv['URLs'])) { |
||
| 347 | $configurationHash = md5(serialize($vv)); |
||
| 348 | $skipInnerCheck = $this->noUnprocessedQueueEntriesForPageWithConfigurationHashExist($pageRow['uid'],$configurationHash); |
||
| 349 | |||
| 350 | foreach($vv['URLs'] as $urlQuery) { |
||
| 351 | |||
| 352 | if ($this->drawURLs_PIfilter($vv['subCfg']['procInstrFilter'], $incomingProcInstructions)) { |
||
| 353 | |||
| 354 | // Calculate cHash: |
||
| 355 | if ($vv['subCfg']['cHash']) { |
||
| 356 | /* @var $cacheHash \TYPO3\CMS\Frontend\Page\CacheHashCalculator */ |
||
| 357 | $cacheHash = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Frontend\Page\CacheHashCalculator'); |
||
| 358 | $urlQuery .= '&cHash=' . $cacheHash->generateForParameters($urlQuery); |
||
| 359 | } |
||
| 360 | |||
| 361 | // Create key by which to determine unique-ness: |
||
| 362 | $uKey = $urlQuery.'|'.$vv['subCfg']['userGroups'].'|'.$vv['subCfg']['baseUrl'].'|'.$vv['subCfg']['procInstrFilter']; |
||
| 363 | |||
| 364 | // realurl support (thanks to Ingo Renner) |
||
| 365 | $urlQuery = 'index.php' . $urlQuery; |
||
| 366 | if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('realurl') && $vv['subCfg']['realurl']) { |
||
| 367 | $params = array( |
||
| 368 | 'LD' => array( |
||
| 369 | 'totalURL' => $urlQuery |
||
| 370 | ), |
||
| 371 | 'TCEmainHook' => true |
||
| 372 | ); |
||
| 373 | $urlObj->encodeSpURL($params); |
||
| 374 | $urlQuery = $params['LD']['totalURL']; |
||
| 375 | } |
||
| 376 | |||
| 377 | // Scheduled time: |
||
| 378 | $schTime = $scheduledTime + round(count($duplicateTrack)*(60/$reqMinute)); |
||
| 379 | $schTime = floor($schTime/60)*60; |
||
| 380 | |||
| 381 | if (isset($duplicateTrack[$uKey])) { |
||
| 382 | |||
| 383 | //if the url key is registered just display it and do not resubmit is |
||
| 384 | $urlList = '<em><span class="typo3-dimmed">'.htmlspecialchars($urlQuery).'</span></em><br/>'; |
||
| 385 | |||
| 386 | } else { |
||
| 387 | |||
| 388 | $urlList = '['.date('d.m.y H:i', $schTime).'] '.htmlspecialchars($urlQuery); |
||
| 389 | $this->urlList[] = '['.date('d.m.y H:i', $schTime).'] '.$urlQuery; |
||
| 390 | |||
| 391 | $theUrl = ($vv['subCfg']['baseUrl'] ? $vv['subCfg']['baseUrl'] : \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL')) . $urlQuery; |
||
| 392 | |||
| 393 | // Submit for crawling! |
||
| 394 | if ($submitCrawlUrls) { |
||
| 395 | $added = $this->addUrl( |
||
| 396 | $pageRow['uid'], |
||
| 397 | $theUrl, |
||
| 398 | $vv['subCfg'], |
||
| 399 | $scheduledTime, |
||
| 400 | $configurationHash, |
||
| 401 | $skipInnerCheck |
||
| 402 | ); |
||
| 403 | if ($added === false) { |
||
| 404 | $urlList .= ' (Url already existed)'; |
||
| 405 | } |
||
| 406 | } elseif ($downloadCrawlUrls) { |
||
| 407 | $downloadUrls[$theUrl] = $theUrl; |
||
| 408 | } |
||
| 409 | |||
| 410 | $urlList .= '<br />'; |
||
| 411 | } |
||
| 412 | $duplicateTrack[$uKey] = TRUE; |
||
| 413 | } |
||
| 414 | } |
||
| 415 | } else { |
||
| 416 | $urlList = 'ERROR - no URL generated'; |
||
| 417 | } |
||
| 418 | |||
| 419 | return $urlList; |
||
| 420 | } |
||
| 421 | |||
| 422 | /** |
||
| 423 | * Returns true if input processing instruction is among registered ones. |
||
| 424 | * |
||
| 425 | * @param string $piString PI to test |
||
| 426 | * @param array $incomingProcInstructions Processing instructions |
||
| 427 | * @return boolean TRUE if found |
||
| 428 | */ |
||
| 429 | 5 | public function drawURLs_PIfilter($piString, array $incomingProcInstructions) { |
|
| 430 | 5 | if (empty($incomingProcInstructions)) { |
|
| 431 | 1 | return TRUE; |
|
| 432 | } |
||
| 433 | |||
| 434 | 4 | foreach($incomingProcInstructions as $pi) { |
|
| 435 | 4 | if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList($piString, $pi)) { |
|
| 436 | 4 | return TRUE; |
|
| 437 | } |
||
| 438 | } |
||
| 439 | 2 | } |
|
| 440 | |||
| 441 | |||
| 442 | public function getPageTSconfigForId($id) { |
||
| 463 | |||
| 464 | /** |
||
| 465 | * This methods returns an array of configurations. |
||
| 466 | * And no urls! |
||
| 467 | * |
||
| 468 | * @param integer $id Page ID |
||
| 469 | * @param bool $forceSsl Use https |
||
| 470 | * @return array Configurations from pages and configuration records |
||
| 471 | */ |
||
| 472 | protected function getUrlsForPageId($id, $forceSsl = false) { |
||
| 473 | |||
| 474 | /** |
||
| 475 | * Get configuration from tsConfig |
||
| 476 | */ |
||
| 477 | |||
| 478 | // Get page TSconfig for page ID: |
||
| 479 | $pageTSconfig = $this->getPageTSconfigForId($id); |
||
| 480 | |||
| 481 | $res = array(); |
||
| 482 | |||
| 483 | if (is_array($pageTSconfig) && is_array($pageTSconfig['tx_crawler.']['crawlerCfg.'])) { |
||
| 484 | $crawlerCfg = $pageTSconfig['tx_crawler.']['crawlerCfg.']; |
||
| 485 | |||
| 486 | if (is_array($crawlerCfg['paramSets.'])) { |
||
| 487 | foreach($crawlerCfg['paramSets.'] as $key => $values) { |
||
| 488 | if (!is_array($values)) { |
||
| 489 | |||
| 490 | // Sub configuration for a single configuration string: |
||
| 491 | $subCfg = (array)$crawlerCfg['paramSets.'][$key.'.']; |
||
| 492 | $subCfg['key'] = $key; |
||
| 493 | |||
| 494 | if (strcmp($subCfg['procInstrFilter'],'')) { |
||
| 495 | $subCfg['procInstrFilter'] = implode(',',\TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',',$subCfg['procInstrFilter'])); |
||
| 496 | } |
||
| 497 | $pidOnlyList = implode(',',\TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',',$subCfg['pidsOnly'],1)); |
||
| 498 | |||
| 499 | // process configuration if it is not page-specific or if the specific page is the current page: |
||
| 500 | if (!strcmp($subCfg['pidsOnly'],'') || \TYPO3\CMS\Core\Utility\GeneralUtility::inList($pidOnlyList,$id)) { |
||
| 501 | |||
| 502 | // add trailing slash if not present |
||
| 503 | if (!empty($subCfg['baseUrl']) && substr($subCfg['baseUrl'], -1) != '/') { |
||
| 504 | $subCfg['baseUrl'] .= '/'; |
||
| 505 | } |
||
| 506 | |||
| 507 | // Explode, process etc.: |
||
| 508 | $res[$key] = array(); |
||
| 509 | $res[$key]['subCfg'] = $subCfg; |
||
| 510 | $res[$key]['paramParsed'] = $this->parseParams($values); |
||
| 511 | $res[$key]['paramExpanded'] = $this->expandParameters($res[$key]['paramParsed'],$id); |
||
| 512 | $res[$key]['origin'] = 'pagets'; |
||
| 513 | |||
| 514 | // recognize MP value |
||
| 515 | if(!$this->MP){ |
||
| 516 | $res[$key]['URLs'] = $this->compileUrls($res[$key]['paramExpanded'],array('?id='.$id)); |
||
| 517 | } else { |
||
| 518 | $res[$key]['URLs'] = $this->compileUrls($res[$key]['paramExpanded'],array('?id='.$id.'&MP='.$this->MP)); |
||
| 519 | } |
||
| 520 | } |
||
| 521 | } |
||
| 522 | } |
||
| 523 | |||
| 524 | } |
||
| 525 | } |
||
| 526 | |||
| 527 | /** |
||
| 528 | * Get configuration from tx_crawler_configuration records |
||
| 529 | */ |
||
| 530 | |||
| 531 | // get records along the rootline |
||
| 532 | $rootLine = \TYPO3\CMS\Backend\Utility\BackendUtility::BEgetRootLine($id); |
||
| 533 | |||
| 534 | foreach ($rootLine as $page) { |
||
| 535 | $configurationRecordsForCurrentPage = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordsByField( |
||
| 536 | 'tx_crawler_configuration', |
||
| 537 | 'pid', |
||
| 538 | intval($page['uid']), |
||
| 539 | \TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields('tx_crawler_configuration') . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('tx_crawler_configuration') |
||
| 540 | ); |
||
| 541 | |||
| 542 | if (is_array($configurationRecordsForCurrentPage)) { |
||
| 543 | foreach ($configurationRecordsForCurrentPage as $configurationRecord) { |
||
| 544 | |||
| 545 | // check access to the configuration record |
||
| 546 | if (empty($configurationRecord['begroups']) || $GLOBALS['BE_USER']->isAdmin() || $this->hasGroupAccess($GLOBALS['BE_USER']->user['usergroup_cached_list'], $configurationRecord['begroups'])) { |
||
| 547 | |||
| 548 | $pidOnlyList = implode(',',\TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',',$configurationRecord['pidsonly'],1)); |
||
| 549 | |||
| 550 | // process configuration if it is not page-specific or if the specific page is the current page: |
||
| 551 | if (!strcmp($configurationRecord['pidsonly'],'') || \TYPO3\CMS\Core\Utility\GeneralUtility::inList($pidOnlyList,$id)) { |
||
| 552 | $key = $configurationRecord['name']; |
||
| 553 | |||
| 554 | // don't overwrite previously defined paramSets |
||
| 555 | if (!isset($res[$key])) { |
||
| 556 | |||
| 557 | /* @var $TSparserObject \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser */ |
||
| 558 | $TSparserObject = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser'); |
||
| 559 | $TSparserObject->parse($configurationRecord['processing_instruction_parameters_ts']); |
||
| 560 | |||
| 561 | $subCfg = array( |
||
| 562 | 'procInstrFilter' => $configurationRecord['processing_instruction_filter'], |
||
| 563 | 'procInstrParams.' => $TSparserObject->setup, |
||
| 564 | 'baseUrl' => $this->getBaseUrlForConfigurationRecord( |
||
| 565 | $configurationRecord['base_url'], |
||
| 566 | $configurationRecord['sys_domain_base_url'], |
||
| 567 | $forceSsl |
||
| 568 | ), |
||
| 569 | 'realurl' => $configurationRecord['realurl'], |
||
| 570 | 'cHash' => $configurationRecord['chash'], |
||
| 571 | 'userGroups' => $configurationRecord['fegroups'], |
||
| 572 | 'exclude' => $configurationRecord['exclude'], |
||
| 573 | 'key' => $key, |
||
| 574 | ); |
||
| 575 | |||
| 576 | // add trailing slash if not present |
||
| 577 | if (!empty($subCfg['baseUrl']) && substr($subCfg['baseUrl'], -1) != '/') { |
||
| 578 | $subCfg['baseUrl'] .= '/'; |
||
| 579 | } |
||
| 580 | if (!in_array($id, $this->expandExcludeString($subCfg['exclude']))) { |
||
| 581 | $res[$key] = array(); |
||
| 582 | $res[$key]['subCfg'] = $subCfg; |
||
| 583 | $res[$key]['paramParsed'] = $this->parseParams($configurationRecord['configuration']); |
||
| 584 | $res[$key]['paramExpanded'] = $this->expandParameters($res[$key]['paramParsed'], $id); |
||
| 585 | $res[$key]['URLs'] = $this->compileUrls($res[$key]['paramExpanded'], array('?id=' . $id)); |
||
| 586 | $res[$key]['origin'] = 'tx_crawler_configuration_'.$configurationRecord['uid']; |
||
| 587 | } |
||
| 588 | } |
||
| 589 | } |
||
| 590 | } |
||
| 591 | } |
||
| 592 | } |
||
| 593 | } |
||
| 594 | |||
| 595 | if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['processUrls'])) { |
||
| 596 | foreach($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['processUrls'] as $func) { |
||
| 597 | $params = array( |
||
| 598 | 'res' => &$res, |
||
| 599 | ); |
||
| 600 | \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($func, $params, $this); |
||
| 601 | } |
||
| 602 | } |
||
| 603 | |||
| 604 | return $res; |
||
| 605 | } |
||
| 606 | |||
| 607 | /** |
||
| 608 | * Checks if a domain record exist and returns the base-url based on the record. If not the given baseUrl string is used. |
||
| 609 | * |
||
| 610 | * @param string $baseUrl |
||
| 611 | * @param integer $sysDomainUid |
||
| 612 | * @param bool $ssl |
||
| 613 | * @return string |
||
| 614 | */ |
||
| 615 | protected function getBaseUrlForConfigurationRecord($baseUrl, $sysDomainUid, $ssl = false) { |
||
| 634 | |||
| 635 | function getConfigurationsForBranch($rootid, $depth) { |
||
| 680 | |||
| 681 | /** |
||
| 682 | * Check if a user has access to an item |
||
| 683 | * (e.g. get the group list of the current logged in user from $GLOBALS['TSFE']->gr_list) |
||
| 684 | * |
||
| 685 | * @see \TYPO3\CMS\Frontend\Page\PageRepository::getMultipleGroupsWhereClause() |
||
| 686 | * @param string $groupList Comma-separated list of (fe_)group UIDs from a user |
||
| 687 | * @param string $accessList Comma-separated list of (fe_)group UIDs of the item to access |
||
| 688 | * @return bool TRUE if at least one of the users group UIDs is in the access list or the access list is empty |
||
| 689 | * @author Fabrizio Branca <[email protected]> |
||
| 690 | * @since 2009-01-19 |
||
| 691 | */ |
||
| 692 | 3 | function hasGroupAccess($groupList, $accessList) { |
|
| 703 | |||
| 704 | /** |
||
| 705 | * Parse GET vars of input Query into array with key=>value pairs |
||
| 706 | * |
||
| 707 | * @param string $inputQuery Input query string |
||
| 708 | * @return array Keys are Get var names, values are the values of the GET vars. |
||
| 709 | */ |
||
| 710 | 3 | function parseParams($inputQuery) { |
|
| 724 | |||
| 725 | /** |
||
| 726 | * Will expand the parameters configuration to individual values. This follows a certain syntax of the value of each parameter. |
||
| 727 | * Syntax of values: |
||
| 728 | * - Basically: If the value is wrapped in [...] it will be expanded according to the following syntax, otherwise the value is taken literally |
||
| 729 | * - Configuration is splitted by "|" and the parts are processed individually and finally added together |
||
| 730 | * - For each configuration part: |
||
| 731 | * - "[int]-[int]" = Integer range, will be expanded to all values in between, values included, starting from low to high (max. 1000). Example "1-34" or "-40--30" |
||
| 732 | * - "_TABLE:[TCA table name];[_PID:[optional page id, default is current page]];[_ENABLELANG:1]" = Look up of table records from PID, filtering out deleted records. Example "_TABLE:tt_content; _PID:123" |
||
| 733 | * _ENABLELANG:1 picks only original records without their language overlays |
||
| 734 | * - Default: Literal value |
||
| 735 | * |
||
| 736 | * @param array Array with key (GET var name) and values (value of GET var which is configuration for expansion) |
||
| 737 | * @param integer Current page ID |
||
| 738 | * @return array Array with key (GET var name) with the value being an array of all possible values for that key. |
||
| 739 | */ |
||
| 740 | function expandParameters($paramArray, $pid) { |
||
| 741 | global $TCA; |
||
| 742 | |||
| 743 | // Traverse parameter names: |
||
| 744 | foreach($paramArray as $p => $v) { |
||
| 745 | $v = trim($v); |
||
| 746 | |||
| 747 | // If value is encapsulated in square brackets it means there are some ranges of values to find, otherwise the value is literal |
||
| 748 | if (substr($v,0,1)==='[' && substr($v,-1)===']') { |
||
| 749 | // So, find the value inside brackets and reset the paramArray value as an array. |
||
| 750 | $v = substr($v,1,-1); |
||
| 751 | $paramArray[$p] = array(); |
||
| 752 | |||
| 753 | // Explode parts and traverse them: |
||
| 754 | $parts = explode('|',$v); |
||
| 755 | foreach($parts as $pV) { |
||
| 756 | |||
| 757 | // Look for integer range: (fx. 1-34 or -40--30 // reads minus 40 to minus 30) |
||
| 758 | if (preg_match('/^(-?[0-9]+)\s*-\s*(-?[0-9]+)$/',trim($pV),$reg)) { // Integer range: |
||
| 759 | |||
| 760 | // Swap if first is larger than last: |
||
| 761 | if ($reg[1] > $reg[2]) { |
||
| 762 | $temp = $reg[2]; |
||
| 763 | $reg[2] = $reg[1]; |
||
| 764 | $reg[1] = $temp; |
||
| 765 | } |
||
| 766 | |||
| 767 | // Traverse range, add values: |
||
| 768 | $runAwayBrake = 1000; // Limit to size of range! |
||
| 769 | for($a=$reg[1]; $a<=$reg[2];$a++) { |
||
| 770 | $paramArray[$p][] = $a; |
||
| 771 | $runAwayBrake--; |
||
| 772 | if ($runAwayBrake<=0) { |
||
| 773 | break; |
||
| 774 | } |
||
| 775 | } |
||
| 776 | } elseif (substr(trim($pV),0,7)=='_TABLE:') { |
||
| 777 | |||
| 778 | // Parse parameters: |
||
| 779 | $subparts = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(';',$pV); |
||
| 780 | $subpartParams = array(); |
||
| 781 | foreach($subparts as $spV) { |
||
| 782 | list($pKey,$pVal) = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(':',$spV); |
||
| 783 | $subpartParams[$pKey] = $pVal; |
||
| 784 | } |
||
| 785 | |||
| 786 | // Table exists: |
||
| 787 | if (isset($TCA[$subpartParams['_TABLE']])) { |
||
| 788 | $lookUpPid = isset($subpartParams['_PID']) ? intval($subpartParams['_PID']) : $pid; |
||
| 789 | $pidField = isset($subpartParams['_PIDFIELD']) ? trim($subpartParams['_PIDFIELD']) : 'pid'; |
||
| 790 | $where = isset($subpartParams['_WHERE']) ? $subpartParams['_WHERE'] : ''; |
||
| 791 | $addTable = isset($subpartParams['_ADDTABLE']) ? $subpartParams['_ADDTABLE'] : ''; |
||
| 792 | |||
| 793 | $fieldName = $subpartParams['_FIELD'] ? $subpartParams['_FIELD'] : 'uid'; |
||
| 794 | if ($fieldName==='uid' || $TCA[$subpartParams['_TABLE']]['columns'][$fieldName]) { |
||
| 795 | |||
| 796 | $andWhereLanguage = ''; |
||
| 797 | $transOrigPointerField = $TCA[$subpartParams['_TABLE']]['ctrl']['transOrigPointerField']; |
||
| 798 | |||
| 799 | if ($subpartParams['_ENABLELANG'] && $transOrigPointerField) { |
||
| 800 | $andWhereLanguage = ' AND ' . $this->db->quoteStr($transOrigPointerField, $subpartParams['_TABLE']) .' <= 0 '; |
||
| 801 | } |
||
| 802 | |||
| 803 | $where = $this->db->quoteStr($pidField, $subpartParams['_TABLE']) .'='.intval($lookUpPid) . ' ' . |
||
| 804 | $andWhereLanguage . $where; |
||
| 805 | |||
| 806 | $rows = $this->db->exec_SELECTgetRows( |
||
| 807 | $fieldName, |
||
| 808 | $subpartParams['_TABLE'] . $addTable, |
||
| 809 | $where . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($subpartParams['_TABLE']), |
||
| 810 | '', |
||
| 811 | '', |
||
| 812 | '', |
||
| 813 | $fieldName |
||
| 814 | ); |
||
| 815 | |||
| 816 | if (is_array($rows)) { |
||
| 817 | $paramArray[$p] = array_merge($paramArray[$p],array_keys($rows)); |
||
| 818 | } |
||
| 819 | } |
||
| 820 | } |
||
| 821 | } else { // Just add value: |
||
| 822 | $paramArray[$p][] = $pV; |
||
| 823 | } |
||
| 824 | // Hook for processing own expandParameters place holder |
||
| 825 | if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['crawler/class.tx_crawler_lib.php']['expandParameters'])) { |
||
| 826 | $_params = array( |
||
| 827 | 'pObj' => &$this, |
||
| 828 | 'paramArray' => &$paramArray, |
||
| 829 | 'currentKey' => $p, |
||
| 830 | 'currentValue' => $pV, |
||
| 831 | 'pid' => $pid |
||
| 832 | ); |
||
| 833 | foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['crawler/class.tx_crawler_lib.php']['expandParameters'] as $key => $_funcRef) { |
||
| 834 | \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this); |
||
| 835 | } |
||
| 836 | } |
||
| 837 | } |
||
| 838 | |||
| 839 | // Make unique set of values and sort array by key: |
||
| 840 | $paramArray[$p] = array_unique($paramArray[$p]); |
||
| 841 | ksort($paramArray); |
||
| 842 | } else { |
||
| 843 | // Set the literal value as only value in array: |
||
| 844 | $paramArray[$p] = array($v); |
||
| 845 | } |
||
| 846 | } |
||
| 847 | |||
| 848 | return $paramArray; |
||
| 849 | } |
||
| 850 | |||
| 851 | /** |
||
| 852 | * Compiling URLs from parameter array (output of expandParameters()) |
||
| 853 | * The number of URLs will be the multiplication of the number of parameter values for each key |
||
| 854 | * |
||
| 855 | * @param array $paramArray Output of expandParameters(): Array with keys (GET var names) and for each an array of values |
||
| 856 | * @param array $urls URLs accumulated in this array (for recursion) |
||
| 857 | * @return array URLs accumulated, if number of urls exceed 'maxCompileUrls' it will return false as an error! |
||
| 858 | */ |
||
| 859 | 3 | public function compileUrls($paramArray, $urls = array()) { |
|
| 884 | |||
| 885 | /************************************ |
||
| 886 | * |
||
| 887 | * Crawler log |
||
| 888 | * |
||
| 889 | ************************************/ |
||
| 890 | |||
| 891 | /** |
||
| 892 | * Return array of records from crawler queue for input page ID |
||
| 893 | * |
||
| 894 | * @param integer $id Page ID for which to look up log entries. |
||
| 895 | * @param string $filter Filter: "all" => all entries, "pending" => all that is not yet run, "finished" => all complete ones |
||
| 896 | * @param boolean $doFlush If TRUE, then entries selected at DELETED(!) instead of selected! |
||
| 897 | * @param boolean $doFullFlush |
||
| 898 | * @param integer $itemsPerPage Limit the amount of entries per page default is 10 |
||
| 899 | * @return array |
||
| 900 | */ |
||
| 901 | public function getLogEntriesForPageId($id, $filter = '', $doFlush = FALSE, $doFullFlush = FALSE, $itemsPerPage = 10) { |
||
| 926 | |||
| 927 | /** |
||
| 928 | * Return array of records from crawler queue for input set ID |
||
| 929 | * |
||
| 930 | * @param integer Set ID for which to look up log entries. |
||
| 931 | * @param string Filter: "all" => all entries, "pending" => all that is not yet run, "finished" => all complete ones |
||
| 932 | * @param boolean If TRUE, then entries selected at DELETED(!) instead of selected! |
||
| 933 | * @param integer Limit the amount of entires per page default is 10 |
||
| 934 | * @return array |
||
| 935 | */ |
||
| 936 | public function getLogEntriesForSetId($set_id,$filter='',$doFlush=FALSE, $doFullFlush=FALSE, $itemsPerPage=10) { |
||
| 960 | |||
| 961 | /** |
||
| 962 | * Removes queue entires |
||
| 963 | * |
||
| 964 | * @param $where SQL related filter for the entries which should be removed |
||
| 965 | * @return void |
||
| 966 | */ |
||
| 967 | protected function flushQueue($where='') { |
||
| 980 | |||
| 981 | /** |
||
| 982 | * Adding call back entries to log (called from hooks typically, see indexed search class "class.crawler.php" |
||
| 983 | * |
||
| 984 | * @param integer Set ID |
||
| 985 | * @param array Parameters to pass to call back function |
||
| 986 | * @param string Call back object reference, eg. 'EXT:indexed_search/class.crawler.php:&tx_indexedsearch_crawler' |
||
| 987 | * @param integer Page ID to attach it to |
||
| 988 | * @param integer Time at which to activate |
||
| 989 | * @return void |
||
| 990 | */ |
||
| 991 | function addQueueEntry_callBack($setId,$params,$callBack,$page_id=0,$schedule=0) { |
||
| 1008 | |||
| 1009 | |||
| 1010 | |||
| 1011 | |||
| 1012 | |||
| 1013 | |||
| 1014 | |||
| 1015 | |||
| 1016 | |||
| 1017 | |||
| 1018 | |||
| 1019 | /************************************ |
||
| 1020 | * |
||
| 1021 | * URL setting |
||
| 1022 | * |
||
| 1023 | ************************************/ |
||
| 1024 | |||
| 1025 | /** |
||
| 1026 | * Setting a URL for crawling: |
||
| 1027 | * |
||
| 1028 | * @param integer Page ID |
||
| 1029 | * @param string Complete URL |
||
| 1030 | * @param array Sub configuration array (from TS config) |
||
| 1031 | * @param integer Scheduled-time |
||
| 1032 | * @param string (optional) configuration hash |
||
| 1033 | * @param bool (optional) skip inner duplication check |
||
| 1034 | * @return bool true if the url was added, false if it already existed |
||
| 1035 | */ |
||
| 1036 | function addUrl ( |
||
| 1102 | |||
| 1103 | /** |
||
| 1104 | * This method determines duplicates for a queue entry with the same parameters and this timestamp. |
||
| 1105 | * If the timestamp is in the past, it will check if there is any unprocessed queue entry in the past. |
||
| 1106 | * If the timestamp is in the future it will check, if the queued entry has exactly the same timestamp |
||
| 1107 | * |
||
| 1108 | * @param int $tstamp |
||
| 1109 | * @param string $parameters |
||
| 1110 | * @author Fabrizio Branca |
||
| 1111 | * @author Timo Schmidt |
||
| 1112 | * @return array; |
||
| 1113 | */ |
||
| 1114 | protected function getDuplicateRowsIfExist($tstamp,$fieldArray){ |
||
| 1154 | |||
| 1155 | /** |
||
| 1156 | * Returns the current system time |
||
| 1157 | * |
||
| 1158 | * @author Timo Schmidt <[email protected]> |
||
| 1159 | * @return int |
||
| 1160 | */ |
||
| 1161 | public function getCurrentTime(){ |
||
| 1164 | |||
| 1165 | |||
| 1166 | |||
| 1167 | /************************************ |
||
| 1168 | * |
||
| 1169 | * URL reading |
||
| 1170 | * |
||
| 1171 | ************************************/ |
||
| 1172 | |||
| 1173 | /** |
||
| 1174 | * Read URL for single queue entry |
||
| 1175 | * |
||
| 1176 | * @param integer $queueId |
||
| 1177 | * @param boolean $force If set, will process even if exec_time has been set! |
||
| 1178 | * @return integer |
||
| 1179 | */ |
||
| 1180 | function readUrl($queueId, $force = FALSE) { |
||
| 1247 | |||
| 1248 | /** |
||
| 1249 | * Read URL for not-yet-inserted log-entry |
||
| 1250 | * |
||
| 1251 | * @param integer Queue field array, |
||
| 1252 | * @return string |
||
| 1253 | */ |
||
| 1254 | function readUrlFromArray($field_array) { |
||
| 1269 | |||
| 1270 | /** |
||
| 1271 | * Read URL for a queue record |
||
| 1272 | * |
||
| 1273 | * @param array Queue record |
||
| 1274 | * @return string Result output. |
||
| 1275 | */ |
||
| 1276 | function readUrl_exec($queueRec) { |
||
| 1305 | |||
| 1306 | /** |
||
| 1307 | * Gets the content of a URL. |
||
| 1308 | * |
||
| 1309 | * @param string $originalUrl URL to read |
||
| 1310 | * @param string $crawlerId Crawler ID string (qid + hash to verify) |
||
| 1311 | * @param integer $timeout Timeout time |
||
| 1312 | * @param integer $recursion Recursion limiter for 302 redirects |
||
| 1313 | * @return array Array with content |
||
| 1314 | */ |
||
| 1315 | 2 | function requestUrl($originalUrl, $crawlerId, $timeout=2, $recursion=10) { |
|
| 1398 | |||
| 1399 | /** |
||
| 1400 | * Gets the base path of the website frontend. |
||
| 1401 | * (e.g. if you call http://mydomain.com/cms/index.php in |
||
| 1402 | * the browser the base path is "/cms/") |
||
| 1403 | * |
||
| 1404 | * @return string Base path of the website frontend |
||
| 1405 | */ |
||
| 1406 | protected function getFrontendBasePath() { |
||
| 1428 | |||
| 1429 | /** |
||
| 1430 | * Executes a shell command and returns the outputted result. |
||
| 1431 | * |
||
| 1432 | * @param string $command Shell command to be executed |
||
| 1433 | * @return string Outputted result of the command execution |
||
| 1434 | */ |
||
| 1435 | protected function executeShellCommand($command) { |
||
| 1439 | |||
| 1440 | /** |
||
| 1441 | * Reads HTTP response from the given stream. |
||
| 1442 | * |
||
| 1443 | * @param resource $streamPointer Pointer to connection stream. |
||
| 1444 | * @return array Associative array with the following items: |
||
| 1445 | * headers <array> Response headers sent by server. |
||
| 1446 | * content <array> Content, with each line as an array item. |
||
| 1447 | */ |
||
| 1448 | protected function getHttpResponseFromStream($streamPointer) { |
||
| 1470 | |||
| 1471 | /** |
||
| 1472 | * @param message |
||
| 1473 | */ |
||
| 1474 | 2 | protected function log($message) { |
|
| 1479 | |||
| 1480 | /** |
||
| 1481 | * Builds HTTP request headers. |
||
| 1482 | * |
||
| 1483 | * @param array $url |
||
| 1484 | * @param string $crawlerId |
||
| 1485 | * |
||
| 1486 | * @return array |
||
| 1487 | */ |
||
| 1488 | 6 | protected function buildRequestHeaderArray(array $url, $crawlerId) { |
|
| 1503 | |||
| 1504 | /** |
||
| 1505 | * Check if the submitted HTTP-Header contains a redirect location and built new crawler-url |
||
| 1506 | * |
||
| 1507 | * @param array HTTP Header |
||
| 1508 | * @param string HTTP Auth. User |
||
| 1509 | * @param string HTTP Auth. Password |
||
| 1510 | * @return string URL from redirection |
||
| 1511 | */ |
||
| 1512 | 12 | protected function getRequestUrlFrom302Header($headers,$user='',$pass='') { |
|
| 1532 | |||
| 1533 | |||
| 1534 | |||
| 1535 | |||
| 1536 | |||
| 1537 | |||
| 1538 | |||
| 1539 | |||
| 1540 | /************************** |
||
| 1541 | * |
||
| 1542 | * tslib_fe hooks: |
||
| 1543 | * |
||
| 1544 | **************************/ |
||
| 1545 | |||
| 1546 | /** |
||
| 1547 | * Initialization hook (called after database connection) |
||
| 1548 | * Takes the "HTTP_X_T3CRAWLER" header and looks up queue record and verifies if the session comes from the system (by comparing hashes) |
||
| 1549 | * |
||
| 1550 | * @param array Parameters from frontend |
||
| 1551 | * @param object TSFE object (reference under PHP5) |
||
| 1552 | * @return void |
||
| 1553 | */ |
||
| 1554 | function fe_init(&$params, $ref) { |
||
| 1571 | |||
| 1572 | |||
| 1573 | |||
| 1574 | /***************************** |
||
| 1575 | * |
||
| 1576 | * Compiling URLs to crawl - tools |
||
| 1577 | * |
||
| 1578 | *****************************/ |
||
| 1579 | |||
| 1580 | /** |
||
| 1581 | * @param integer Root page id to start from. |
||
| 1582 | * @param integer Depth of tree, 0=only id-page, 1= on sublevel, 99 = infinite |
||
| 1583 | * @param integer Unix Time when the URL is timed to be visited when put in queue |
||
| 1584 | * @param integer Number of requests per minute (creates the interleave between requests) |
||
| 1585 | * @param boolean If set, submits the URLs to queue in database (real crawling) |
||
| 1586 | * @param boolean If set (and submitcrawlUrls is false) will fill $downloadUrls with entries) |
||
| 1587 | * @param array Array of processing instructions |
||
| 1588 | * @param array Array of configuration keys |
||
| 1589 | * @return string HTML code |
||
| 1590 | */ |
||
| 1591 | function getPageTreeAndUrls( |
||
| 1685 | |||
| 1686 | /** |
||
| 1687 | * Expands exclude string. |
||
| 1688 | * |
||
| 1689 | * @param string $excludeString Exclude string |
||
| 1690 | * @return array Array of page ids. |
||
| 1691 | */ |
||
| 1692 | public function expandExcludeString($excludeString) { |
||
| 1736 | |||
| 1737 | /** |
||
| 1738 | * Create the rows for display of the page tree |
||
| 1739 | * For each page a number of rows are shown displaying GET variable configuration |
||
| 1740 | * |
||
| 1741 | * @param array Page row |
||
| 1742 | * @param string Page icon and title for row |
||
| 1743 | * @return string HTML <tr> content (one or more) |
||
| 1744 | */ |
||
| 1745 | public function drawURLs_addRowsForPage(array $pageRow, $pageTitleAndIcon) { |
||
| 1746 | |||
| 1747 | $skipMessage = ''; |
||
| 1748 | |||
| 1749 | // Get list of configurations |
||
| 1750 | $configurations = $this->getUrlsForPageRow($pageRow, $skipMessage); |
||
| 1751 | |||
| 1752 | if (count($this->incomingConfigurationSelection) > 0) { |
||
| 1753 | // remove configuration that does not match the current selection |
||
| 1754 | foreach ($configurations as $confKey => $confArray) { |
||
| 1755 | if (!in_array($confKey, $this->incomingConfigurationSelection)) { |
||
| 1756 | unset($configurations[$confKey]); |
||
| 1757 | } |
||
| 1758 | } |
||
| 1759 | } |
||
| 1760 | |||
| 1761 | // Traverse parameter combinations: |
||
| 1762 | $c = 0; |
||
| 1763 | $cc = 0; |
||
| 1764 | $content = ''; |
||
| 1765 | if (count($configurations)) { |
||
| 1766 | foreach($configurations as $confKey => $confArray) { |
||
| 1767 | |||
| 1768 | // Title column: |
||
| 1769 | if (!$c) { |
||
| 1770 | $titleClm = '<td rowspan="'.count($configurations).'">'.$pageTitleAndIcon.'</td>'; |
||
| 1771 | } else { |
||
| 1772 | $titleClm = ''; |
||
| 1773 | } |
||
| 1774 | |||
| 1775 | |||
| 1776 | if (!in_array($pageRow['uid'], $this->expandExcludeString($confArray['subCfg']['exclude']))) { |
||
| 1777 | |||
| 1778 | // URL list: |
||
| 1779 | $urlList = $this->urlListFromUrlArray( |
||
| 1780 | $confArray, |
||
| 1781 | $pageRow, |
||
| 1782 | $this->scheduledTime, |
||
| 1783 | $this->reqMinute, |
||
| 1784 | $this->submitCrawlUrls, |
||
| 1785 | $this->downloadCrawlUrls, |
||
| 1786 | $this->duplicateTrack, |
||
| 1787 | $this->downloadUrls, |
||
| 1788 | $this->incomingProcInstructions // if empty the urls won't be filtered by processing instructions |
||
| 1789 | ); |
||
| 1790 | |||
| 1791 | // Expanded parameters: |
||
| 1792 | $paramExpanded = ''; |
||
| 1793 | $calcAccu = array(); |
||
| 1794 | $calcRes = 1; |
||
| 1795 | foreach($confArray['paramExpanded'] as $gVar => $gVal) { |
||
| 1796 | $paramExpanded.= ' |
||
| 1797 | <tr> |
||
| 1798 | <td class="bgColor4-20">'.htmlspecialchars('&'.$gVar.'=').'<br/>'. |
||
| 1799 | '('.count($gVal).')'. |
||
| 1800 | '</td> |
||
| 1801 | <td class="bgColor4" nowrap="nowrap">'.nl2br(htmlspecialchars(implode(chr(10),$gVal))).'</td> |
||
| 1802 | </tr> |
||
| 1803 | '; |
||
| 1804 | $calcRes*= count($gVal); |
||
| 1805 | $calcAccu[] = count($gVal); |
||
| 1806 | } |
||
| 1807 | $paramExpanded = '<table class="lrPadding c-list param-expanded">'.$paramExpanded.'</table>'; |
||
| 1808 | $paramExpanded.= 'Comb: '.implode('*',$calcAccu).'='.$calcRes; |
||
| 1809 | |||
| 1810 | // Options |
||
| 1811 | $optionValues = ''; |
||
| 1812 | if ($confArray['subCfg']['userGroups']) { |
||
| 1813 | $optionValues.='User Groups: '.$confArray['subCfg']['userGroups'].'<br/>'; |
||
| 1814 | } |
||
| 1815 | if ($confArray['subCfg']['baseUrl']) { |
||
| 1816 | $optionValues.='Base Url: '.$confArray['subCfg']['baseUrl'].'<br/>'; |
||
| 1817 | } |
||
| 1818 | if ($confArray['subCfg']['procInstrFilter']) { |
||
| 1819 | $optionValues.='ProcInstr: '.$confArray['subCfg']['procInstrFilter'].'<br/>'; |
||
| 1820 | } |
||
| 1821 | |||
| 1822 | // Compile row: |
||
| 1823 | $content .= ' |
||
| 1824 | <tr class="bgColor' . ($c%2 ? '-20':'-10') . '"> |
||
| 1825 | ' . $titleClm . ' |
||
| 1826 | <td>' . htmlspecialchars($confKey) . '</td> |
||
| 1827 | <td>' . nl2br(htmlspecialchars(rawurldecode(trim(str_replace('&', chr(10) . '&', \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl('', $confArray['paramParsed'])))))) . '</td> |
||
| 1828 | <td>'.$paramExpanded.'</td> |
||
| 1829 | <td nowrap="nowrap">' . $urlList . '</td> |
||
| 1830 | <td nowrap="nowrap">' . $optionValues . '</td> |
||
| 1831 | <td nowrap="nowrap">' . \TYPO3\CMS\Core\Utility\DebugUtility::viewArray($confArray['subCfg']['procInstrParams.']) . '</td> |
||
| 1832 | </tr>'; |
||
| 1833 | } else { |
||
| 1834 | |||
| 1835 | $content .= '<tr class="bgColor'.($c%2 ? '-20':'-10') . '"> |
||
| 1836 | '.$titleClm.' |
||
| 1837 | <td>'.htmlspecialchars($confKey).'</td> |
||
| 1838 | <td colspan="5"><em>No entries</em> (Page is excluded in this configuration)</td> |
||
| 1839 | </tr>'; |
||
| 1840 | |||
| 1841 | } |
||
| 1842 | |||
| 1843 | |||
| 1844 | $c++; |
||
| 1845 | } |
||
| 1846 | } else { |
||
| 1847 | $message = !empty($skipMessage) ? ' ('.$skipMessage.')' : ''; |
||
| 1848 | |||
| 1849 | // Compile row: |
||
| 1850 | $content.= ' |
||
| 1851 | <tr class="bgColor-20" style="border-bottom: 1px solid black;"> |
||
| 1852 | <td>'.$pageTitleAndIcon.'</td> |
||
| 1853 | <td colspan="6"><em>No entries</em>'.$message.'</td> |
||
| 1854 | </tr>'; |
||
| 1855 | } |
||
| 1856 | |||
| 1857 | return $content; |
||
| 1858 | } |
||
| 1859 | |||
| 1860 | /** |
||
| 1861 | * |
||
| 1862 | * @return int |
||
| 1863 | */ |
||
| 1864 | function getUnprocessedItemsCount() { |
||
| 1876 | |||
| 1877 | |||
| 1878 | |||
| 1879 | |||
| 1880 | |||
| 1881 | |||
| 1882 | |||
| 1883 | |||
| 1884 | /***************************** |
||
| 1885 | * |
||
| 1886 | * CLI functions |
||
| 1887 | * |
||
| 1888 | *****************************/ |
||
| 1889 | |||
| 1890 | /** |
||
| 1891 | * Main function for running from Command Line PHP script (cron job) |
||
| 1892 | * See ext/crawler/cli/crawler_cli.phpsh for details |
||
| 1893 | * |
||
| 1894 | * @return int number of remaining items or false if error |
||
| 1895 | */ |
||
| 1896 | function CLI_main() { |
||
| 1935 | |||
| 1936 | /** |
||
| 1937 | * Function executed by crawler_im.php cli script. |
||
| 1938 | * |
||
| 1939 | * @return void |
||
| 1940 | */ |
||
| 1941 | function CLI_main_im() { |
||
| 1942 | $this->setAccessMode('cli_im'); |
||
| 1943 | |||
| 1944 | $cliObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tx_crawler_cli_im'); |
||
| 1945 | |||
| 1946 | // Force user to admin state and set workspace to "Live": |
||
| 1947 | $this->backendUser->user['admin'] = 1; |
||
| 1948 | $this->backendUser->setWorkspace(0); |
||
| 1949 | |||
| 1950 | // Print help |
||
| 1951 | if (!isset($cliObj->cli_args['_DEFAULT'][1])) { |
||
| 1952 | $cliObj->cli_validateArgs(); |
||
| 1953 | $cliObj->cli_help(); |
||
| 1954 | exit; |
||
| 1955 | } |
||
| 1956 | |||
| 1957 | $cliObj->cli_validateArgs(); |
||
| 1958 | |||
| 1959 | if ($cliObj->cli_argValue('-o')==='exec') { |
||
| 1960 | $this->registerQueueEntriesInternallyOnly=TRUE; |
||
| 1961 | } |
||
| 1962 | |||
| 1963 | if (isset($cliObj->cli_args['_DEFAULT'][2])) { |
||
| 1964 | // Crawler is called over TYPO3 BE |
||
| 1965 | $pageId = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($cliObj->cli_args['_DEFAULT'][2], 0); |
||
| 1966 | } else { |
||
| 1967 | // Crawler is called over cli |
||
| 1968 | $pageId = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($cliObj->cli_args['_DEFAULT'][1], 0); |
||
| 1969 | } |
||
| 1970 | |||
| 1971 | $configurationKeys = $this->getConfigurationKeys($cliObj); |
||
| 1972 | |||
| 1973 | if(!is_array($configurationKeys)){ |
||
| 1974 | $configurations = $this->getUrlsForPageId($pageId); |
||
| 1975 | if(is_array($configurations)){ |
||
| 1976 | $configurationKeys = array_keys($configurations); |
||
| 1977 | }else{ |
||
| 1978 | $configurationKeys = array(); |
||
| 1979 | } |
||
| 1980 | } |
||
| 1981 | |||
| 1982 | if($cliObj->cli_argValue('-o')==='queue' || $cliObj->cli_argValue('-o')==='exec'){ |
||
| 1983 | |||
| 1984 | $reason = new tx_crawler_domain_reason(); |
||
| 1985 | $reason->setReason(tx_crawler_domain_reason::REASON_GUI_SUBMIT); |
||
| 1986 | $reason->setDetailText('The cli script of the crawler added to the queue'); |
||
| 1987 | tx_crawler_domain_events_dispatcher::getInstance()->post( |
||
| 1988 | 'invokeQueueChange', |
||
| 1989 | $this->setID, |
||
| 1990 | array( 'reason' => $reason ) |
||
| 1991 | ); |
||
| 1992 | } |
||
| 1993 | |||
| 1994 | if ($this->extensionSettings['cleanUpOldQueueEntries']) { |
||
| 1995 | $this->cleanUpOldQueueEntries(); |
||
| 1996 | } |
||
| 1997 | |||
| 1998 | $this->setID = \TYPO3\CMS\Core\Utility\GeneralUtility::md5int(microtime()); |
||
| 1999 | $this->getPageTreeAndUrls( |
||
| 2000 | $pageId, |
||
| 2001 | \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($cliObj->cli_argValue('-d'),0,99), |
||
| 2002 | $this->getCurrentTime(), |
||
| 2003 | \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($cliObj->cli_isArg('-n') ? $cliObj->cli_argValue('-n') : 30,1,1000), |
||
| 2004 | $cliObj->cli_argValue('-o')==='queue' || $cliObj->cli_argValue('-o')==='exec', |
||
| 2005 | $cliObj->cli_argValue('-o')==='url', |
||
| 2006 | \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',',$cliObj->cli_argValue('-proc'),1), |
||
| 2007 | $configurationKeys |
||
| 2008 | ); |
||
| 2009 | |||
| 2010 | if ($cliObj->cli_argValue('-o')==='url') { |
||
| 2011 | $cliObj->cli_echo(implode(chr(10),$this->downloadUrls).chr(10),1); |
||
| 2012 | } elseif ($cliObj->cli_argValue('-o')==='exec') { |
||
| 2013 | $cliObj->cli_echo("Executing ".count($this->urlList)." requests right away:\n\n"); |
||
| 2014 | $cliObj->cli_echo(implode(chr(10),$this->urlList).chr(10)); |
||
| 2015 | $cliObj->cli_echo("\nProcessing:\n"); |
||
| 2016 | |||
| 2017 | foreach($this->queueEntries as $queueRec) { |
||
| 2018 | $p = unserialize($queueRec['parameters']); |
||
| 2019 | $cliObj->cli_echo($p['url'].' ('.implode(',',$p['procInstructions']).') => '); |
||
| 2020 | |||
| 2021 | $result = $this->readUrlFromArray($queueRec); |
||
| 2022 | |||
| 2023 | $requestResult = unserialize($result['content']); |
||
| 2024 | if (is_array($requestResult)) { |
||
| 2025 | $resLog = is_array($requestResult['log']) ? chr(10).chr(9).chr(9).implode(chr(10).chr(9).chr(9),$requestResult['log']) : ''; |
||
| 2026 | $cliObj->cli_echo('OK: '.$resLog.chr(10)); |
||
| 2027 | } else { |
||
| 2028 | $cliObj->cli_echo('Error checking Crawler Result: '.substr(preg_replace('/\s+/',' ',strip_tags($result['content'])),0,30000).'...'.chr(10)); |
||
| 2029 | } |
||
| 2030 | } |
||
| 2031 | } elseif ($cliObj->cli_argValue('-o')==='queue') { |
||
| 2032 | $cliObj->cli_echo("Putting ".count($this->urlList)." entries in queue:\n\n"); |
||
| 2033 | $cliObj->cli_echo(implode(chr(10),$this->urlList).chr(10)); |
||
| 2034 | } else { |
||
| 2035 | $cliObj->cli_echo(count($this->urlList)." entries found for processing. (Use -o to decide action):\n\n",1); |
||
| 2036 | $cliObj->cli_echo(implode(chr(10),$this->urlList).chr(10),1); |
||
| 2037 | } |
||
| 2038 | } |
||
| 2039 | |||
| 2040 | /** |
||
| 2041 | * Function executed by crawler_im.php cli script. |
||
| 2042 | * |
||
| 2043 | * @return bool |
||
| 2044 | */ |
||
| 2045 | function CLI_main_flush() { |
||
| 2082 | |||
| 2083 | /** |
||
| 2084 | * Obtains configuration keys from the CLI arguments |
||
| 2085 | * |
||
| 2086 | * @param tx_crawler_cli_im $cliObj Command line object |
||
| 2087 | * @return mixed Array of keys or null if no keys found |
||
| 2088 | */ |
||
| 2089 | protected function getConfigurationKeys(tx_crawler_cli_im &$cliObj) { |
||
| 2093 | |||
| 2094 | /** |
||
| 2095 | * Running the functionality of the CLI (crawling URLs from queue) |
||
| 2096 | * |
||
| 2097 | * @param int $countInARun |
||
| 2098 | * @param int $sleepTime |
||
| 2099 | * @param int $sleepAfterFinish |
||
| 2100 | * @return string Status message |
||
| 2101 | */ |
||
| 2102 | public function CLI_run($countInARun, $sleepTime, $sleepAfterFinish) { |
||
| 2103 | $result = 0; |
||
| 2104 | $counter = 0; |
||
| 2105 | |||
| 2106 | // First, run hooks: |
||
| 2107 | $this->CLI_runHooks(); |
||
| 2108 | |||
| 2109 | // Clean up the queue |
||
| 2110 | if (intval($this->extensionSettings['purgeQueueDays']) > 0) { |
||
| 2111 | $purgeDate = $this->getCurrentTime() - 24 * 60 * 60 * intval($this->extensionSettings['purgeQueueDays']); |
||
| 2112 | $del = $this->db->exec_DELETEquery( |
||
| 2113 | 'tx_crawler_queue', |
||
| 2114 | 'exec_time!=0 AND exec_time<' . $purgeDate |
||
| 2115 | ); |
||
| 2116 | } |
||
| 2117 | |||
| 2118 | // Select entries: |
||
| 2119 | //TODO Shouldn't this reside within the transaction? |
||
| 2120 | $rows = $this->db->exec_SELECTgetRows( |
||
| 2121 | 'qid,scheduled', |
||
| 2122 | 'tx_crawler_queue', |
||
| 2123 | 'exec_time=0 |
||
| 2124 | AND process_scheduled= 0 |
||
| 2125 | AND scheduled<='.$this->getCurrentTime(), |
||
| 2126 | '', |
||
| 2127 | 'scheduled, qid', |
||
| 2128 | intval($countInARun) |
||
| 2129 | ); |
||
| 2130 | |||
| 2131 | if (count($rows)>0) { |
||
| 2132 | $quidList = array(); |
||
| 2133 | |||
| 2134 | foreach($rows as $r) { |
||
| 2135 | $quidList[] = $r['qid']; |
||
| 2136 | } |
||
| 2137 | |||
| 2138 | $processId = $this->CLI_buildProcessId(); |
||
| 2139 | |||
| 2140 | //reserve queue entrys for process |
||
| 2141 | $this->db->sql_query('BEGIN'); |
||
| 2142 | //TODO make sure we're not taking assigned queue-entires |
||
| 2143 | $this->db->exec_UPDATEquery( |
||
| 2144 | 'tx_crawler_queue', |
||
| 2145 | 'qid IN ('.implode(',',$quidList).')', |
||
| 2146 | array( |
||
| 2147 | 'process_scheduled' => intval($this->getCurrentTime()), |
||
| 2148 | 'process_id' => $processId |
||
| 2149 | ) |
||
| 2150 | ); |
||
| 2151 | |||
| 2152 | //save the number of assigned queue entrys to determine who many have been processed later |
||
| 2153 | $numberOfAffectedRows = $this->db->sql_affected_rows(); |
||
| 2154 | $this->db->exec_UPDATEquery( |
||
| 2155 | 'tx_crawler_process', |
||
| 2156 | "process_id = '".$processId."'" , |
||
| 2157 | array( |
||
| 2158 | 'assigned_items_count' => intval($numberOfAffectedRows) |
||
| 2159 | ) |
||
| 2160 | ); |
||
| 2161 | |||
| 2162 | if($numberOfAffectedRows == count($quidList)) { |
||
| 2163 | $this->db->sql_query('COMMIT'); |
||
| 2164 | } else { |
||
| 2165 | $this->db->sql_query('ROLLBACK'); |
||
| 2166 | $this->CLI_debug("Nothing processed due to multi-process collision (".$this->CLI_buildProcessId().")"); |
||
| 2167 | return ( $result | self::CLI_STATUS_ABORTED ); |
||
| 2168 | } |
||
| 2169 | |||
| 2170 | |||
| 2171 | |||
| 2172 | foreach($rows as $r) { |
||
| 2173 | $result |= $this->readUrl($r['qid']); |
||
| 2174 | |||
| 2175 | $counter++; |
||
| 2176 | usleep(intval($sleepTime)); // Just to relax the system |
||
| 2177 | |||
| 2178 | // if during the start and the current read url the cli has been disable we need to return from the function |
||
| 2179 | // mark the process NOT as ended. |
||
| 2180 | if ($this->getDisabled()) { |
||
| 2181 | return ( $result | self::CLI_STATUS_ABORTED ); |
||
| 2182 | } |
||
| 2183 | |||
| 2184 | if (!$this->CLI_checkIfProcessIsActive($this->CLI_buildProcessId())) { |
||
| 2185 | $this->CLI_debug("conflict / timeout (".$this->CLI_buildProcessId().")"); |
||
| 2186 | |||
| 2187 | //TODO might need an additional returncode |
||
| 2188 | $result |= self::CLI_STATUS_ABORTED; |
||
| 2189 | break; //possible timeout |
||
| 2190 | } |
||
| 2191 | } |
||
| 2192 | |||
| 2193 | sleep(intval($sleepAfterFinish)); |
||
| 2194 | |||
| 2195 | $msg = 'Rows: '.$counter; |
||
| 2196 | $this->CLI_debug($msg." (".$this->CLI_buildProcessId().")"); |
||
| 2197 | |||
| 2198 | } else { |
||
| 2199 | $this->CLI_debug("Nothing within queue which needs to be processed (".$this->CLI_buildProcessId().")"); |
||
| 2200 | } |
||
| 2201 | |||
| 2202 | if($counter > 0) { |
||
| 2203 | $result |= self::CLI_STATUS_PROCESSED; |
||
| 2204 | } |
||
| 2205 | |||
| 2206 | return $result; |
||
| 2207 | } |
||
| 2208 | |||
| 2209 | /** |
||
| 2210 | * Activate hooks |
||
| 2211 | * |
||
| 2212 | * @return void |
||
| 2213 | */ |
||
| 2214 | function CLI_runHooks() { |
||
| 2225 | |||
| 2226 | /** |
||
| 2227 | * Try to acquire a new process with the given id |
||
| 2228 | * also performs some auto-cleanup for orphan processes |
||
| 2229 | * @todo preemption might not be the most elegant way to clean up |
||
| 2230 | * |
||
| 2231 | * @param string $id identification string for the process |
||
| 2232 | * @return boolean determines whether the attempt to get resources was successful |
||
| 2233 | */ |
||
| 2234 | function CLI_checkAndAcquireNewProcess($id) { |
||
| 2291 | |||
| 2292 | /** |
||
| 2293 | * Release a process and the required resources |
||
| 2294 | * |
||
| 2295 | * @param mixed $releaseIds string with a single process-id or array with multiple process-ids |
||
| 2296 | * @param boolean $withinLock show whether the DB-actions are included within an existing lock |
||
| 2297 | * @return boolean |
||
| 2298 | */ |
||
| 2299 | function CLI_releaseProcesses($releaseIds, $withinLock=false) { |
||
| 2357 | |||
| 2358 | /** |
||
| 2359 | * Delete processes marked as deleted |
||
| 2360 | * |
||
| 2361 | * @return void |
||
| 2362 | */ |
||
| 2363 | public function CLI_deleteProcessesMarkedDeleted() { |
||
| 2366 | |||
| 2367 | /** |
||
| 2368 | * Check if there are still resources left for the process with the given id |
||
| 2369 | * Used to determine timeouts and to ensure a proper cleanup if there's a timeout |
||
| 2370 | * |
||
| 2371 | * @param string identification string for the process |
||
| 2372 | * @return boolean determines if the process is still active / has resources |
||
| 2373 | * |
||
| 2374 | * FIXME: Please remove Transaction, not needed as only a select query. |
||
| 2375 | */ |
||
| 2376 | function CLI_checkIfProcessIsActive($pid) { |
||
| 2393 | |||
| 2394 | /** |
||
| 2395 | * Create a unique Id for the current process |
||
| 2396 | * |
||
| 2397 | * @return string the ID |
||
| 2398 | */ |
||
| 2399 | 2 | function CLI_buildProcessId() { |
|
| 2405 | |||
| 2406 | /** |
||
| 2407 | * @param bool $get_as_float |
||
| 2408 | * |
||
| 2409 | * @return mixed |
||
| 2410 | */ |
||
| 2411 | protected function microtime($get_as_float = false ) |
||
| 2415 | |||
| 2416 | /** |
||
| 2417 | * Prints a message to the stdout (only if debug-mode is enabled) |
||
| 2418 | * |
||
| 2419 | * @param string $msg the message |
||
| 2420 | */ |
||
| 2421 | function CLI_debug($msg) { |
||
| 2426 | |||
| 2427 | |||
| 2428 | |||
| 2429 | /** |
||
| 2430 | * Get URL content by making direct request to TYPO3. |
||
| 2431 | * |
||
| 2432 | * @param string $url Page URL |
||
| 2433 | * @param int $crawlerId Crawler-ID |
||
| 2434 | * @return array |
||
| 2435 | */ |
||
| 2436 | 2 | protected function sendDirectRequest($url, $crawlerId) { |
|
| 2461 | |||
| 2462 | /** |
||
| 2463 | * Cleans up entries that stayed for too long in the queue. These are: |
||
| 2464 | * - processed entries that are over 1.5 days in age |
||
| 2465 | * - scheduled entries that are over 7 days old |
||
| 2466 | * |
||
| 2467 | * @return void |
||
| 2468 | */ |
||
| 2469 | protected function cleanUpOldQueueEntries() { |
||
| 2477 | |||
| 2478 | /** |
||
| 2479 | * Initializes a TypoScript Frontend necessary for using TypoScript and TypoLink functions |
||
| 2480 | * |
||
| 2481 | * @param int $id |
||
| 2482 | * @param int $typeNum |
||
| 2483 | * |
||
| 2484 | * @return void |
||
| 2485 | */ |
||
| 2486 | protected function initTSFE($id = 1, $typeNum = 0) { |
||
| 2504 | } |
||
| 2505 | |||
| 2506 | 1 | if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/crawler/class.tx_crawler_lib.php']) { |
|
| 2507 | include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/crawler/class.tx_crawler_lib.php']); |
||
| 2508 | } |
||
| 2509 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.