/** * Checks that base HREF is extracted correctly * * @return void */ public function textExtractBaseHref() { $baseHref = 'http://example.com/'; $html = '<html><head><Base Href="' . $baseHref . '" /></head></html>'; $result = $this->indexer->extractHyperLinks($html); $this->assertEquals($baseHref, $result, 'Incorrect base href was extracted'); }
/** * Returns a COMPLETE list of phash-integers matching the search-result composed of the search-words in the sWArr array. * The list of phash integers are unsorted and should be used for subsequent selection of index_phash records for display of the result. * * @param array Search word array * @return string List of integers */ function getPhashList($sWArr) { // Initialize variables: $c = 0; $totalHashList = array(); // This array accumulates the phash-values $this->wSelClauses = array(); // Traverse searchwords; for each, select all phash integers and merge/diff/intersect them with previous word (based on operator) foreach ($sWArr as $k => $v) { // Making the query for a single search word based on the search-type $sWord = $v['sword']; // $GLOBALS['TSFE']->csConvObj->conv_case('utf-8',$v['sword'],'toLower'); // lower-case all of them... $theType = (string) $this->piVars['type']; if (strstr($sWord, ' ')) { $theType = 20; } // If there are spaces in the search-word, make a full text search instead. $GLOBALS['TT']->push('SearchWord "' . $sWord . '" - $theType=' . $theType); $res = ''; $wSel = ''; // Perform search for word: switch ($theType) { case '1': // Part of word $wSel = "IW.baseword LIKE '%" . $GLOBALS['TYPO3_DB']->quoteStr($sWord, 'index_words') . "%'"; $res = $this->execPHashListQuery($wSel, ' AND is_stopword=0'); break; case '2': // First part of word $wSel = "IW.baseword LIKE '" . $GLOBALS['TYPO3_DB']->quoteStr($sWord, 'index_words') . "%'"; $res = $this->execPHashListQuery($wSel, ' AND is_stopword=0'); break; case '3': // Last part of word $wSel = "IW.baseword LIKE '%" . $GLOBALS['TYPO3_DB']->quoteStr($sWord, 'index_words') . "'"; $res = $this->execPHashListQuery($wSel, ' AND is_stopword=0'); break; case '10': // Sounds like $wSel = 'IW.metaphone = ' . $this->indexerObj->metaphone($sWord); $res = $this->execPHashListQuery($wSel, ' AND is_stopword=0'); break; case '20': // Sentence $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('ISEC.phash', 'index_section ISEC, index_fulltext IFT', 'IFT.fulltextdata LIKE \'%' . $GLOBALS['TYPO3_DB']->quoteStr($sWord, 'index_fulltext') . '%\' AND ISEC.phash = IFT.phash ' . $this->sectionTableWhere(), 'ISEC.phash'); $wSel = '1=1'; if ($this->piVars['type'] == 20) { $this->piVars['order'] = 'mtime'; } // If there is a fulltext search for a sentence there is a likeliness that sorting cannot be done by the rankings from the rel-table (because no relations will exist for the sentence in the word-table). So therefore mtime is used instaed. It is not required, but otherwise some hits may be left out. break; default: // Distinct word $wSel = 'IW.wid = ' . ($hash = $this->indexerObj->md5inthash($sWord)); $res = $this->execPHashListQuery($wSel, ' AND is_stopword=0'); break; } // Accumulate the word-select clauses $this->wSelClauses[] = $wSel; // If there was a query to do, then select all phash-integers which resulted from this. if ($res) { // Get phash list by searching for it: $phashList = array(); while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $phashList[] = $row['phash']; } $GLOBALS['TYPO3_DB']->sql_free_result($res); // Here the phash list are merged with the existing result based on whether we are dealing with OR, NOT or AND operations. if ($c) { switch ($v['oper']) { case 'OR': $totalHashList = array_unique(array_merge($phashList, $totalHashList)); break; case 'AND NOT': $totalHashList = array_diff($totalHashList, $phashList); break; default: // AND... $totalHashList = array_intersect($totalHashList, $phashList); break; } } else { $totalHashList = $phashList; // First search } } $GLOBALS['TT']->pull(); $c++; } return implode(',', $totalHashList); }
/** * Show details for metaphone value * * @param integer Metaphone integer hash * @return string HTML content */ function showDetailsForMetaphone($metaphone) { // Finding top-20 on frequency for this phash: $ftrows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('index_words.*', 'index_words', 'index_words.metaphone = ' . intval($metaphone), '', 'index_words.baseword', ''); if (count($ftrows)) { $content .= '<h4>Metaphone: ' . $this->indexerObj->metaphone($ftrows[0]['baseword'], 1) . '</h4>'; $content .= ' <tr class="tableheader bgColor5"> <td>Word</td> <td>Is stopword?</td> </tr>'; if (is_array($ftrows)) { foreach ($ftrows as $wDat) { $content .= ' <tr class="bgColor4"> <td>' . $this->linkWordDetails(htmlspecialchars($wDat['baseword']), $wDat['wid']) . '</td> <td>' . htmlspecialchars($wDat['is_stopword'] ? 'YES' : 'No') . '</td> </tr>'; } } $content = ' <table border="0" cellspacing="1" cellpadding="2" class="c-list">' . $content . ' </table>'; if ($this->indexerObj->metaphone($ftrows[0]['baseword']) != $metaphone) { $content .= 'ERROR: Metaphone string and hash did not match for some reason!?'; } // Add go-back link: $content = $content . $this->linkList(); } return $content; }
/** * Generating the form for new guestbook entries * * @return string $content : the form (HTML) */ function displayForm() { if (is_array($this->LOCAL_LANG) && count($this->LOCAL_LANG) > 0) { $markerArray = $this->initFormMarkerArray(); $markerArray['###PID###'] = $GLOBALS["TSFE"]->id; $url = $this->getUrl($GLOBALS["TSFE"]->id); $markerArray['###ACTION_URL###'] = htmlspecialchars($url); $markerArray['###FORM_ERROR###'] = ''; $markerArray['###FORM_ERROR_FIELDS###'] = ''; // <Frank Nägler added onErrorHook> if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ve_guestbook']['onErrorHook'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ve_guestbook']['onErrorHook'] as $_classRef) { $_procObj =& t3lib_div::getUserObj($_classRef); $_procObj->onErrorProcessor($error, $this); } } // </Frank Nägler added onErrorHook> $this->postvars = t3lib_div::_GP('tx_veguestbook_pi1') ? t3lib_div::_GP('tx_veguestbook_pi1') : array(); if (isset($this->postvars['submitted']) && $this->postvars['submitted'] == 1) { foreach ($this->postvars as $key => $value) { $value = $this->local_cObj->removeBadHTML($value, array()); $this->postvars[$key] = $value; } if (isset($this->postvars['homepage'])) { if (!strstr($this->postvars['homepage'], 'http://') && !empty($this->postvars['homepage'])) { $this->postvars['homepage'] = 'http://' . $this->postvars['homepage']; } } foreach ($this->postvars as $k => $v) { $markerArray['###VALUE_' . strtoupper($k) . '###'] = stripslashes($v); } $error = $this->checkForm(); if (!empty($error)) { $markerArray['###FORM_ERROR###'] = $this->pi_getLL('form_error'); $markerArray['###FORM_ERROR_FIELDS###'] = $error; } else { $db_fields = array('firstname', 'surname', 'email', 'homepage', 'place', 'entry', 'entrycomment'); $saveData['uid'] = ''; $saveData['pid'] = $this->config['pid_list']; $saveData['tstamp'] = time(); $saveData['crdate'] = time(); $saveData['deleted'] = '0'; $saveData['sys_language_uid'] = $this->sys_language_uid; $saveData['remote_addr'] = $_SERVER['REMOTE_ADDR']; if ($this->for_tt_news) { $saveData['uid_tt_news'] = $this->tt_news['tx_news_pi1[news]']; } if ($this->config['manual_backend_release'] == 1) { $saveData['hidden'] = '1'; } else { $saveData['hidden'] = '0'; } foreach ($this->postvars as $k => $v) { if (in_array($k, $db_fields)) { if ($this->config['allowedTags']) { $v = strip_tags($v, $this->config['allowedTags']); } $saveData[$k] = $this->local_cObj->removeBadHTML($v, array()); } } if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ve_guestbook']['preEntryInsertHook'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ve_guestbook']['preEntryInsertHook'] as $_classRef) { $_procObj =& t3lib_div::getUserObj($_classRef); $saveData = $_procObj->preEntryInsertProcessor($saveData, $this); } } $insert = $GLOBALS['TYPO3_DB']->exec_INSERTquery($this->strEntryTable, $saveData); if ($insert) { if (!empty($this->config['notify_mail'])) { $this->sendNotificationMail($this->config['notify_mail']); } if (!empty($this->postvars['email']) && $this->config['feedback_mail']) { $this->sendFeedbackMail($this->postvars['email']); } if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ve_guestbook']['postEntryInsertedHook'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ve_guestbook']['postEntryInsertedHook'] as $_classRef) { $_procObj =& t3lib_div::getUserObj($_classRef); $_procObj->postEntryInsertedProcessor($this); } } // clear cache $TCE = t3lib_div::makeInstance('t3lib_TCEmain'); $TCE->admin = 1; // Clear cache for pages entered in TSconfig: if ($this->config['clearCacheCmdOnInsert']) { $commands = t3lib_div::trimExplode(',', strtolower($this->config['clearCacheCmdOnInsert']), 1); $commands = array_unique($commands); foreach ($commands as $commandPart) { $GLOBALS['TSFE']->clearPageCacheContent_pidList($commandPart); } } $GLOBALS['TSFE']->clearPageCacheContent_pidList($GLOBALS['TSFE']->id); $GLOBALS['TSFE']->clearPageCacheContent_pidList($this->config['redirect_page']); // clear index if (t3lib_extMgm::isLoaded('indexed_search')) { $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('phash', 'index_phash', ' data_page_id = ' . $this->config['redirect_page']); if ($res) { while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $phash = (int) $row['phash']; if ($phash > 0) { tx_indexedsearch_indexer::removeOldIndexedPages($phash); } } } } header('Location: ' . $this->getUrl($this->config['redirect_page'])); } } } // Pre-fill form data if FE user in logged in if (!$this->postvars && $GLOBALS['TSFE']->loginUser) { $surname_pos = strpos($GLOBALS['TSFE']->fe_user->user['name'], ' '); $markerArray['###VALUE_FIRSTNAME###'] = substr($GLOBALS['TSFE']->fe_user->user['name'], 0, $surname_pos); $markerArray['###VALUE_SURNAME###'] = substr($GLOBALS['TSFE']->fe_user->user['name'], $surname_pos + 1); $markerArray['###VALUE_EMAIL###'] = $GLOBALS['TSFE']->fe_user->user['email']; $markerArray['###VALUE_HOMEPAGE###'] = $GLOBALS['TSFE']->fe_user->user['www']; $markerArray['###VALUE_PLACE###'] = $GLOBALS['TSFE']->fe_user->user['city']; } $markerArray = $this->markObligationFields($markerArray); $this->status = 'displayForm'; // Adds hook for processing of extra item markers if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ve_guestbook']['extraItemMarkerHook'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ve_guestbook']['extraItemMarkerHook'] as $_classRef) { $_procObj =& t3lib_div::getUserObj($_classRef); $markerArray = $_procObj->extraItemMarkerProcessor($markerArray, $row, $this->config, $this); } } $template = $this->cObj->getSubpart($this->templateCode, '###TEMPLATE_FORM###'); if (!$GLOBALS['TSFE']->loginUser) { if (is_object($this->freeCap) and $this->config['captcha'] == 'sr_freecap') { $markerArray = array_merge($markerArray, $this->freeCap->makeCaptcha()); $template = $this->cObj->substituteSubpart($template, '###CAPTCHA_INSERT###', ''); } elseif (t3lib_extMgm::isLoaded('captcha') and $this->config['captcha'] == 'captcha') { $markerArray['###CAPTCHA_IMAGE###'] = '<img src="' . t3lib_extMgm::siteRelPath('captcha') . 'captcha/captcha.php" alt="" />'; $template = $this->cObj->substituteSubpart($template, '###SR_FREECAP_INSERT###', ''); } else { $template = $this->cObj->substituteSubpart($template, '###SR_FREECAP_INSERT###', ''); $template = $this->cObj->substituteSubpart($template, '###CAPTCHA_INSERT###', ''); } } else { $template = $this->cObj->substituteSubpart($template, '###SR_FREECAP_INSERT###', ''); $template = $this->cObj->substituteSubpart($template, '###CAPTCHA_INSERT###', ''); } $form = $this->cObj->substituteMarkerArrayCached($template, $markerArray, array(), array()); $form = preg_replace('/###[A-Za-z_1234567890]+###/', '', $form); return $form; } }