コード例 #1
0
 /**
  * Conducts a search and displays the results.
  * This function gets the search results from the database, dependent
  * of the search string.
  *
  * @version 11. 10. 2006
  * @param   array  $conf         The plugin's configuration vars
  * @param   string $searchstring The string of search words
  * @param   array  $param        The parameter array for this function. Obsolete, since
  *                               this array is identical to the this->piVars array.
  * @return  string               The search results
  */
 function searchfind($conf, $searchstring, $param)
 {
     $template = $this->cObj->fileResource($conf['template']);
     $template = $this->cObj->getSubpart($template, "###SEARCHRESULT###");
     $template_sub = $this->cObj->getSubpart($template, "###SEARCHRESULT_SUB###");
     // Language dependent markers
     $marker = array('###LABEL_RESULTS###' => $this->pi_getLL('search.results'), '###LABEL_TOPICINFO###' => $this->pi_getLL('search.topicinfo'), '###LABEL_REPLIES###' => $this->pi_getLL('search.replies'), '###LABEL_SOLVED###' => $this->pi_getLL('search.solved'), '###LABEL_CRUSER###' => $this->pi_getLL('search.cruser'), '###LABEL_CRDATE###' => $this->pi_getLL('search.crdate'), '###LLL_SEARCHRESULTS###' => $this->pi_getLL('search.searchresults'), '###IMG_CORNER###' => $conf['path_img'] . 'search-haken.gif', '###IMG_BACKGROUND###' => $conf['path_img'] . 'search-back.gif');
     // Replace all special characters with space characters
     $orgsearchstring = $searchstring;
     $searchstring = str_replace('"', ' ', $searchstring);
     $searchstring = str_replace('+', ' ', $searchstring);
     $searchstring = str_replace('=', ' ', $searchstring);
     //$pattern			= "/[^a-zA-Z0-9äüöÄÜÖß\*:\$._]/";
     //$pattern			= '/[^[\w\*]]/';
     //$pattern			= '/[\W^\*]/';
     $pattern = '/[^\\w\\*]/';
     #$searchstring = utf8_decode($searchstring);
     $searchstring = preg_replace($pattern, " ", $searchstring);
     //$searchstring		= utf8_encode($searchstring);
     $post_id_array = $this->get_search_results($searchstring, $param);
     if (!is_array($post_id_array)) {
         $word_array = explode(' ', $searchstring);
         $good_words = array();
         $bad_words = array();
         $good_word_count = 0;
         foreach ($word_array as $val) {
             if (strtolower(substr($val, 0, 5)) == 'user:'******'min_length']) {
                 // Check if search word is negated
                 if (substr($val, 0, 1) == '-') {
                     $val = substr($val, 1);
                     $word_id = $this->word_id($val);
                     if ($word_id) {
                         foreach ($word_id as $wordval) {
                             array_push($bad_words, $wordval);
                         }
                     }
                 } else {
                     $word_id = $this->word_id($val);
                     if ($word_id) {
                         $good_word_count++;
                         foreach ($word_id as $wordval) {
                             array_push($good_words, $wordval);
                         }
                     }
                 }
             }
         }
         if (count($good_words) > 0 || isset($username)) {
             $good_posts = $this->find_posts($good_words, $param, $good_word_count, $username);
         }
         if (count($bad_words) > 0) {
             $bad_posts = $this->find_posts($bad_words, $param);
         }
         if ($bad_posts and $good_posts) {
             // Remove bad posts
             $post_id_array = array_diff($good_posts, $bad_posts);
         } else {
             $post_id_array = $good_posts;
         }
         if (count($post_id_array) > 0) {
             $post_id_array = array_flip($post_id_array);
         }
         // Write search result to database for later requests
         $userGroups = $GLOBALS['TSFE']->fe_user->groupData['uid'];
         sort($userGroups);
         $insertArray = array('pid' => $this->getStoragePID(), 'tstamp' => $GLOBALS['EXEC_TIME'], 'cruser_id' => is_array($GLOBALS['TSFE']->fe_user->user) ? $GLOBALS['TSFE']->fe_user->user['uid'] : 0, 'search_string' => $searchstring, 'array_string' => serialize($post_id_array), 'search_place' => $param['search_place'], 'solved' => isset($param['solved']) ? $param['solved'] : '', 'search_order' => $param['search_order'], 'groupPost' => $param['groupPost'], 'user_groups' => implode(',', $userGroups));
         $this->databaseHandle->exec_INSERTquery('tx_mmforum_searchresults', $insertArray);
         if ($conf['debug_mode'] == 1) {
             echo '<h1>Suche Indiziert</h1>';
         }
     }
     $treffer = count($post_id_array);
     $content = '';
     if ($treffer > 0) {
         $find_array_split = array_chunk($post_id_array, $conf['show_items'], true);
         // Array in Pages Aufteilen
         if (empty($param['page'])) {
             $param['page'] = 0;
         }
         if (!intval($this->conf['doNotUsePageBrowseExtension']) === 0) {
             $page = $param['page'] - 1;
         } else {
             $page = $param['page'];
         }
         $post_id_array = $find_array_split[$page];
         foreach ($post_id_array as $post_id => $values) {
             $topic_id = $this->tx_mmforum_pi1->get_topic_id($post_id);
             $topic_info = $this->topic_information($topic_id);
             $post_info = $this->post_information($post_id);
             $post_text = $this->get_posttext($post_id);
             $post_text = $this->clear_phpBB($post_text);
             $linkparams['tx_mmforum_pi1'] = array('action' => 'list_post', 'tid' => $topic_id, 'pid' => $post_id, 'sword' => addslashes($orgsearchstring));
             if ($this->tx_mmforum_pi1->getIsRealURL()) {
                 $linkparams['tx_mmforum_pi1']['fid'] = $topic_info['forum_id'];
             }
             $post_text = $this->escape(tx_mmforum_tools::textCut($post_text, 350, ''));
             $word_array = explode(" ", $searchstring);
             // Cleaning empty elements
             foreach ($word_array as $key => $value) {
                 if ($value == '') {
                     unset($word_array[$key]);
                 }
             }
             $word_array = array_values($word_array);
             // Highlight Text with each word
             foreach ($word_array as $word) {
                 $word = str_replace('$', '\\$', $word);
                 $replace = $this->cObj->wrap("\\0", $this->conf['matchWrap']);
                 $post_text = preg_replace("/{$word}/i", $replace, $post_text);
             }
             $marker['###TITLE###'] = $this->pi_linkToPage($this->escape($topic_info['topic_title']), $conf['pid_forum'], '', $linkparams);
             $marker['###SHORTTEXT###'] = $post_text;
             $dummylinkParams['tx_mmforum_pi1'] = array('action' => 'list_post', 'tid' => $topic_id);
             if ($this->tx_mmforum_pi1->getIsRealURL()) {
                 $dummylinkParams['tx_mmforum_pi1']['fid'] = $topic_info['forum_id'];
             }
             #$link = GeneralUtility::getIndpEnv("HTTP_HOST").'/'.$this->pi_getPageLink($conf['pid_forum'],'',$dummylinkParams);
             $link = $this->tx_mmforum_pi1->getAbsUrl($this->pi_getPageLink($conf['pid_forum'], '', $dummylinkParams));
             $link = $this->cObj->stdWrap($link, $conf['postPath.']);
             $marker['###POSTPATH###'] = $this->pi_linkToPage($link, $conf['pid_forum'], '_self', $linkparams);
             $marker['###VIEWS###'] = intval($topic_info['topic_views']);
             $marker['###ANSWERS###'] = intval($topic_info['topic_replies']);
             $marker['###CRDATE###'] = date("d.m.Y", $post_info['crdate']);
             $marker['###CRUSER###'] = tx_mmforum_pi4::get_username($post_info['poster_id']);
             if ($topic_info['solved'] == 1) {
                 $marker['###SOLVED###'] = $this->pi_getLL('search.yes');
                 $marker['###SOLVEDIMAGE###'] = '<img src="' . $conf['path_img'] . $conf['images.']['solved'] . '" title="' . $this->pi_getLL('search.topicSolved') . '" alt="' . $this->pi_getLL('search.topicSolved') . '" />';
             } else {
                 $marker['###SOLVED###'] = $this->pi_getLL('search.no');
                 $marker['###SOLVEDIMAGE###'] = '';
             }
             // Include hooks
             if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['mm_forum']['search']['additionalPostMarkers'])) {
                 foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['mm_forum']['search']['additionalPostMarkers'] as $userFunction) {
                     $params = array('marker' => $marker, 'topic_info' => $topic_info, 'post_info' => $post_info, 'post_text' => $post_text);
                     $marker = GeneralUtility::callUserFunction($userFunction, $params, $this);
                 }
             }
             $content .= $this->cObj->substituteMarkerArrayCached($template_sub, $marker);
         }
         $marker['###TREFFER###'] = $treffer;
         $marker['###PAGES###'] = $this->pagebar($treffer, $conf['show_items'], $param);
         $template = $this->cObj->substituteMarkerArrayCached($template, $marker);
         $content = $this->cObj->substituteSubpart($template, '###SEARCHRESULT_SUB###', $content);
     } else {
         $content = $this->pi_getLL('search.noResults');
     }
     return $content;
 }