Guest User

Untitled

a guest
Jan 6th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3.  * $RCSfile$
  4.  *
  5.  * Description: Search output box
  6.  *
  7.  * @version 1.0.1
  8.  * @author Willi Man
  9.  * @copyright four for business AG <www.4fb.de>
  10.  *
  11.  * {@internal
  12.  * created 2004-05-04
  13.  * modified 2005-07-12 Andreas Lindner
  14.  * modified 2008-04-11 Rudi Bieller
  15.  * modified 2008-05-06 Rudi Bieller Added CON_SEARCH_MAXLEN_TEASERTEXT; Fixed <nobr> to be xhtml compliant;
  16.  *                       Removed $action, $sCatName = getCategoryName($cat_id, $db); which was not used at all and
  17.  *                       added a default output in case article/module was called directly (strlen(trim($searchterm)) == 0)
  18.  * }}
  19.  *
  20.  * $Id$
  21.  */
  22.  
  23. #System properties in use:
  24. #Type: searchrange, Name: include
  25. #Contains comma-separated list of cats to be included into search (sub-cats are included automatically)
  26. #Logical combination of search terms with AND or OR
  27.  
  28. define('CON_SEARCH_ITEMSPERPAGE', 10);
  29. define('CON_SEARCH_MAXLEN_TEASERTEXT', 200);
  30.  
  31. #Includes
  32. cInclude('includes', 'functions.api.string.php');
  33.  
  34. #Initiliaze template object
  35. if (!is_object($tpl)) {
  36.     $tpl = new Template;
  37. }
  38. $tpl->reset();
  39.  
  40. #Settings
  41. $oArticleProp = new Article_Property($db, $cfg);
  42.  
  43. $cApiClient = new cApiClient($client);
  44. $sSearchRange = $cApiClient->getProperty('searchrange', 'include');
  45. $aSearchRange = explode(',', $sSearchRange);
  46.  
  47. #Multilingual settings
  48. $sYourSearchFor = mi18n("Ihre Suche nach");
  49. $sMore = mi18n("mehr");
  50.  
  51. #Get search term and pre-process it
  52. if (isset($_GET['searchterm'])) {
  53.     $searchterm = urldecode(conHtmlentities(strip_tags(stripslashes($_GET['searchterm']))));
  54. } elseif (isset($_POST['searchterm'])) {
  55.     $searchterm = urldecode(conHtmlentities(strip_tags(stripslashes($_POST['searchterm']))));
  56. }
  57. $searchterm = str_replace(' + ', ' AND ', $searchterm);
  58. $searchterm = str_replace(' - ', ' NOT ', $searchterm);
  59. $searchterm_display = $searchterm;
  60.  
  61. #Get all article specs
  62. $sql = "SELECT
  63.        idartspec, artspec
  64.    FROM
  65.        " . $cfg['tab']['art_spec'] . "
  66.    WHERE
  67.        client=$client AND
  68.        lang=$lang AND
  69.        online=1";
  70.  
  71. $db->query($sql);
  72. $aArtSpecs = array();
  73. $c = 1;
  74. $d = 1;
  75. $e = 1;
  76. while ($db->next_record()) {
  77.     $aArtSpecs[] = $db->f('idartspec');
  78. }
  79. $aArtSpecs[] = 0;
  80.  
  81. if (strlen(trim($searchterm)) > 0) {
  82.     #Fix for PHP < 4.3
  83.    if (!function_exists('conHtmlEntityDecode')) {
  84.  
  85.         function conHtmlEntityDecode($given_html, $quote_style = ENT_QUOTES) {
  86.             $trans_table = array_flip(conGetHtmlTranslationTable(HTML_SPECIALCHARS, $quote_style));
  87.             $trans_table['&#39;'] = "'";
  88.             return (strtr($given_html, $trans_table));
  89.         }
  90.  
  91.     }
  92.  
  93.     #Parse search term and set search options
  94.    $searchterm = conHtmlEntityDecode($searchterm);
  95.  
  96.     if (stristr($searchterm, ' or ') === FALSE) {
  97.         $combine = 'and';
  98.     } else {
  99.         $combine = 'or';
  100.     }
  101.     $searchterm = str_replace(' and ', ' ', strtolower($searchterm));
  102.     $searchterm = str_replace(' or ', ' ', strtolower($searchterm));
  103.  
  104.     $options = array(
  105.         'db' => 'regexp', // use db function regexp
  106.         'combine' => $combine, // combine searchterms with and
  107.         'exclude' => false, // => searchrange specified in 'cat_tree', 'categories' and 'articles' is excluded, otherwise included (exclusive)
  108.         'cat_tree' => $aSearchRange, // searchrange
  109.         'artspecs' => $aArtSpecs, // array of article specifications => search only articles with these artspecs
  110.         'protected' => true // => do not search articles or articles in categories which are offline or protected
  111.     );
  112.  
  113.     $search = new Search($options);
  114.  
  115.     $cms_options = array("head", "html", "htmlhead", "htmltext", "text"); // search only in these cms-types
  116.     $search->setCmsOptions($cms_options);
  117.  
  118.     #Execute search
  119.    $aSearchResults = $search->searchIndex($searchterm, '');
  120.  
  121.     #Build results page
  122.    if (count($aSearchResults) > 0) {
  123.         $tpl->set('s', 'result_page', mi18n("Ergebnis-Seite") . ':');
  124.  
  125.         $imgMesssageRight = '<div class="searchImg"><img src="http://www.weltdertutorials.de/cms/images/rightNewsletter.png" /></div>';
  126.         $pTagvorRight = '<p id="message" class="message">';
  127.         $pTagnachRight = '</p>';
  128.         #Build meessage
  129.        $message = $imgMesssageRight . $pTagvorRight . $sYourSearchFor . " '" . conHtmlSpecialChars(strip_tags($searchterm_display)) . "' " . mi18n("hat $$$ Treffer ergeben") . ":" . $pTagnachRight;
  130.         $message = str_replace('$$$', count($aSearchResults), $message);
  131.         $tpl->set('s', 'MESSAGE', $message);
  132.  
  133.         #Number of results per page
  134.        $number_of_results = CON_SEARCH_ITEMSPERPAGE;
  135.         $oSearchResults = new SearchResult($aSearchResults, $number_of_results);
  136.  
  137.         $num_res = $oSearchResults->getNumberOfResults() + $pdf_count;
  138.         $num_pages = $oSearchResults->getNumberOfPages();
  139.         $oSearchResults->setReplacement('<strong>', '</strong>'); // html-tags to emphasize the located searchterms
  140.         #Get current result page
  141.        if (isset($_GET['page']) && is_numeric($_GET['page']) && $_GET['page'] > 0) {
  142.             $page = $_GET['page'];
  143.             $res_page = $oSearchResults->getSearchResultPage($page);
  144.         } else {
  145.             $page = 1;
  146.             $res_page = $oSearchResults->getSearchResultPage($page);
  147.         }
  148.  
  149.         #Build links to other result pages
  150.        for ($i = 1; $i <= $num_pages; $i++) {
  151.             // this is just for sample client - modify to your needs!
  152.             if ($cfg['url_builder']['name'] == 'front_content' || $cfg['url_builder']['name'] == 'MR') {
  153.                 $aParams = array('lang' => $lang, 'idcat' => $idcat, 'idart' => $idart, 'searchterm' => $searchterm_display, 'page' => ($i . $sArtSpecs));
  154.             } else {
  155.                 $aParams = array('search' => array('lang' => $lang, 'idcat' => $idcat, 'idart' => $idart, 'searchterm' => $searchterm_display, 'page' => ($i . $sArtSpecs)),
  156.                     'idcat' => $idcat, // needed to build category path
  157.                     'lang' => $lang, // needed to build category path
  158.                     'level' => 1); // needed to build category path
  159.             }
  160.             try {
  161.                 $nextlink = Contenido_Url::getInstance()->build($aParams);
  162.             } catch (InvalidArgumentException $e) {
  163.                 $nextlink = $sess->url('front_content.php?idcat=' . $idcat . '&amp;idart=' . $idart . '&amp;searchterm=' . $searchterm_display . '&amp;page=' . $i . $sArtSpecs);
  164.             }
  165.             if ($i == $page) {
  166.                 $nextlinks .= '<span style="white-space:nowrap;">&nbsp;<strong>' . $i . '</strong>&nbsp;</span>';
  167.             } else {
  168.                 $nextlinks .= '<span style="white-space:nowrap;">&nbsp;<a href="' . $nextlink . '" title="' . $i . '. ' . mi18n("Ergebnisseite anzeigen") . '">' . $i . '</a>&nbsp;</span>';
  169.             }
  170.         }
  171.         $tpl->set('s', 'PAGES', $nextlinks);
  172.  
  173.         #Build link to next result page
  174.        if ($page < $num_pages) {
  175.             $n = $page + 1;
  176.             // this is just for sample client - modify to your needs!
  177.  
  178.             if ($cfg['url_builder']['name'] == 'front_content' || $cfg['url_builder']['name'] == 'MR') {
  179.                 $aParams = array('lang' => $lang, 'idcat' => $idcat, 'idart' => $idart, 'searchterm' => $searchterm_display, 'page' => ($n . $sArtSpecs));
  180.             } else {
  181.                 $aParams = array('search' => array('lang' => $lang, 'idcat' => $idcat, 'idart' => $idart, 'searchterm' => $searchterm_display, 'page' => ($n . $sArtSpecs)),
  182.                     'idcat' => $idcat, // needed to build category path
  183.                     'lang' => $lang, // needed to build category path
  184.                     'level' => 1); // needed to build category path
  185.             }
  186.             try {
  187.                 $next = Contenido_Url::getInstance()->build($aParams);
  188.             } catch (InvalidArgumentException $e) {
  189.                 $next = $sess->url('front_content.php?idcat=' . $idcat . '&amp;idart=' . $idart . '&amp;searchterm=' . $searchterm . '&amp;page=' . $n . $sArtSpecs);
  190.             }
  191.             $nextpage .= '&nbsp;<a href="' . $next . '" title="' . mi18n("nächste Ergebnisseite anzeigen") . '">' . mi18n("vor") . '&nbsp;&nbsp;<img src="images/link_pfeil_klein.gif" alt="" /></a>';
  192.             $tpl->set('s', 'NEXT', $nextpage);
  193.         } else {
  194.             $tpl->set('s', 'NEXT', '');
  195.         }
  196.  
  197.         #Build link to previous result page
  198.        if ($page > 1) {
  199.             $p = $page - 1;
  200.             // this is just for sample client - modify to your needs!
  201.             if ($cfg['url_builder']['name'] == 'front_content' || $cfg['url_builder']['name'] == 'MR') {
  202.                 $aParams = array('lang' => $lang, 'idcat' => $idcat, 'idart' => $idart, 'searchterm' => $searchterm_display, 'page' => ($p . $sArtSpecs));
  203.             } else {
  204.                 $aParams = array('search' => array('lang' => $lang, 'idcat' => $idcat, 'idart' => $idart, 'searchterm' => $searchterm_display, 'page' => ($p . $sArtSpecs)),
  205.                     'idcat' => $idcat, // needed to build category path
  206.                     'lang' => $lang, // needed to build category path
  207.                     'level' => 1); // needed to build category path
  208.             }
  209.             try {
  210.                 $pre = Contenido_Url::getInstance()->build($aParams);
  211.             } catch (InvalidArgumentException $e) {
  212.                 $pre = $sess->url('front_content.php?idcat=' . $idcat . '&amp;idart=' . $idart . '&amp;searchterm=' . $searchterm . '&amp;page=' . $p . $sArtSpecs);
  213.             }
  214.             $prevpage .= '<a href="' . $pre . '" title="' . mi18n("vorherige Ergebnisseite anzeigen") . '"><img src="images/link_pfeil_klein_links.gif" alt="" />&nbsp;&nbsp;' . mi18n("zurück") . '</a>&nbsp;';
  215.             $tpl->set('s', 'PREV', $prevpage);
  216.         } else {
  217.             $tpl->set('s', 'PREV', '');
  218.         }
  219.  
  220.         if (count($res_page) > 0) {
  221.             $i = 1;
  222.             #Build single search result on result page
  223.            foreach ($res_page as $key => $val) {
  224.                 $num = $i + (($page - 1) * $number_of_results);
  225.                 $oArt = new Article($key, $client, $lang);
  226.                 #Get publishing date of article
  227.                $pub_system = $oArt->getField('published');
  228.                 $pub_user = trim(strip_tags($oArt->getContent('HEAD', 90)));
  229.                 if ($pub_user != '') {
  230.                     $show_pub_date = "[" . $pub_user . "]";
  231.                 } else {
  232.                     $show_pub_date = '';
  233.                     if ($pub_system[8] != '0') {
  234.                         $show_pub_date .= $pub_system[8];
  235.                     }
  236.                     $show_pub_date .= $pub_system[9] . '.';
  237.                     if ($pub_system[5] != '0') {
  238.                         $show_pub_date .= $pub_system[5];
  239.                     }
  240.                     $show_pub_date .= $pub_system[6] . "." . $pub_system[0] . $pub_system[1] . $pub_system[2] . $pub_system[3] . "]";
  241.                     $show_pub_date = "[" . $show_pub_date;
  242.                 }
  243.  
  244.                 #Get text and headline of current article
  245.                $iCurrentArtSpec = $oArticleProp->getArticleSpecification($key, $lang);
  246.                 $aHeadline = $oSearchResults->getSearchContent($key, 'HTMLHEAD', 1);
  247.                 $aSubheadline = $oSearchResults->getSearchContent($key, 'HTMLHEAD', 2);
  248.                 $text = $oSearchResults->getSearchContent($key, 'HTML', 1);
  249.                 $text = capiStrTrimAfterWord($text[0], CON_SEARCH_MAXLEN_TEASERTEXT);
  250.                 $headline = capiStrTrimAfterWord($aHeadline[0], CON_SEARCH_MAXLEN_TEASERTEXT); # conflict with capiStrTrimAfterWord and setReplacement('<strong>', '</strong>')
  251.                $subheadline = capiStrTrimAfterWord($aSubheadline[0], CON_SEARCH_MAXLEN_TEASERTEXT);
  252.  
  253.                 $cat_id = $oSearchResults->getArtCat($key);
  254.                 $similarity = $oSearchResults->getSimilarity($key);
  255.                 $similarity = sprintf("%.0f", $similarity);
  256.  
  257.                 #Send output to template
  258.                // this is just for sample client - modify to your needs!
  259.                 if ($cfg['url_builder']['name'] == 'front_content' || $cfg['url_builder']['name'] == 'MR') {
  260.                     $aParams = array('lang' => $lang, 'idcat' => $cat_id, 'idart' => $key);
  261.                 } else {
  262.                     $aParams = array('search' => array('lang' => $lang, 'idcat' => $cat_id, 'idart' => $key),
  263.                         'idcat' => $idcat, // needed to build category path
  264.                         'lang' => $lang, // needed to build category path
  265.                         'level' => 1); // needed to build category path
  266.                 }
  267.                 try {
  268.                     $href = Contenido_Url::getInstance()->build($aParams);
  269.                 } catch (InvalidArgumentException $e) {
  270.                     $href = $sess->url("front_content.php?idcat=$cat_id&amp;idart=$key");
  271.                 }
  272.                 $tpl->set('d', 'more', $sMore);
  273.                 $tpl->set('d', 'HREF', $href);
  274.                 $tpl->set('d', 'TITLE', mi18n("Link zu Suchergebnis") . ' ' . $i);
  275.                 $tpl->set('d', 'NUM', $num);
  276.                 $tpl->set('d', 'CATNAME', $headline);
  277.                 $tpl->set('d', 'HEADLINE', $text);
  278.                 $tpl->set('d', 'SUBHEADLINE', $subheadline);
  279.                 $tpl->set('d', 'SIMILARITY', $similarity);
  280.                 $tpl->set('d', 'TARGET', '_self');
  281.                 $tpl->set('d', 'PUB_DATE', $show_pub_date);
  282.                 $tpl->next();
  283.                 $i++;
  284.             }
  285.             $tpl->generate('templates/search_output.html');
  286.         }
  287.     } else {
  288.         #No results
  289.        $imgMesssageFalse = '<div class="searchImg"><img src="http://www.weltdertutorials.de/cms/images/falseNewsletter.png" /></div>';
  290.         $pTagvorFalse = '<p id="message" class="message">';
  291.         $pTagnachFalse = '</p>';
  292.         $tpl->set('s', 'MESSAGE', $imgMesssageFalse . $pTagvorFalse . $sYourSearchFor . " '" . conHtmlSpecialChars(strip_tags($searchterm)) . "' " . mi18n("hat leider keine Treffer ergeben") . " ." . $pTagnachFalse);
  293.         $tpl->set('s', 'NEXT', '');
  294.         $tpl->set('s', 'PREV', '');
  295.         $tpl->set('s', 'PAGES', '');
  296.         $tpl->set('s', 'result_page', '');
  297.         $tpl->generate('templates/search_output.html');
  298.     }
  299. } else {
  300.     echo '<div id="searchResults">';
  301.     echo '<h1>' . mi18n("Keine Suchergebnisse - Bitte suchen Sie über das Sucheingabefeld!") . '</h1>';
  302.     echo '</div>';
  303. }
  304.  
  305. class Article_Property {
  306.  
  307.     var $globalConfig;
  308.     var $oDBInstance;
  309.  
  310.     /**
  311.      * Constructor
  312.      * Hint: Call constructor with Article_Property($db, $cfg);
  313.      * @param  oDBInstance instance of class DB_Contenido
  314.      * @param  globalConfig
  315.      */
  316.     function Article_Property($oDBInstance, $globalConfig) {
  317.         $this->globalConfig = $globalConfig;
  318.         $this->oDBInstance = $oDBInstance;
  319.     }
  320.  
  321.     /**
  322.      * Get specification of an article
  323.      *
  324.      * @param   $iArticleId
  325.      * @return  id of article specification
  326.      */
  327.     function getArticleSpecification($iArticleId, $iLangId) {
  328.  
  329.         $sqlString = "
  330.                    SELECT
  331.                        artspec
  332.                    FROM
  333.                        " . $this->globalConfig['tab']['art_lang'] . "
  334.                    WHERE
  335.                        idart = '" . $iArticleId . "' AND
  336.                        idlang = '" . $iLangId . "'
  337.                    ";
  338.  
  339.         #echo "<pre>$sqlString</pre>";
  340.        $this->oDBInstance->query($sqlString);
  341.  
  342.         if ($this->oDBInstance->next_record()) {
  343.             return $this->oDBInstance->f('artspec');
  344.         } else {
  345.             return false;
  346.         }
  347.     }
  348.  
  349. }
  350.  
  351. ?>
Advertisement
Add Comment
Please, Sign In to add comment