/** * Takes page summaries for RSS pages and the current query * and draws list of news links and a link to the news link subsearch * page if applicable. * * @param array $feed_pages page data from news feeds * @param string $base_query the query_string prefix * @param string $query the current search query * @param string $subsearch name of subsearch page this image group on * @param boolean $open_in_tabs whether new links should be opened in * tabs */ function render($feed_pages, $base_query, $query, $subsearch, $open_in_tabs = false) { if ($subsearch != 'news') { $not_news = true; ?> <h2><a href="<?php e("{$base_query}&q={$query}&s=news"); ?> " ><?php e(tl('feeds_helper_view_feed_results', $query)); ?> </a></h2> <?php } else { $not_news = false; } ?> <div class="feed-list"> <?php $time = time(); foreach ($feed_pages as $page) { $pub_date = $page[self::SUMMARY_OFFSET][0][4]; $encode_source = urlencode(urlencode($page[self::SOURCE_NAME])); if (isset($page[self::URL])) { if (strncmp($page[self::URL], "url|", 4) == 0) { $url_parts = explode("|", $page[self::URL]); $url = $url_parts[1]; $title = UrlParser::simplifyUrl($url, 60); $subtitle = "title='" . $page[self::URL] . "'"; } else { $url = $page[self::URL]; $title = $page[self::TITLE]; if (strlen(trim($title)) == 0) { $title = UrlParser::simplifyUrl($url, 60); } $subtitle = ""; } } else { $url = ""; $title = isset($page[self::TITLE]) ? $page[self::TITLE] : ""; $subtitle = ""; } $pub_date = $this->getPubdateString($time, $pub_date); if ($not_news) { ?> <div class="blockquote"> <a href="<?php e($page[self::URL]); ?> " rel="nofollow" <?php if ($open_in_tabs) { ?> target="_blank" <?php } ?> ><?php e($page[self::TITLE]); ?> </a> <a class="gray-link" rel='nofollow' href="<?php e($base_query . "&q=media:news:" . $encode_source . "&s=news"); ?> " ><?php e($page[self::SOURCE_NAME] . "</a>" . "<span class='gray'> - {$pub_date}</span>"); ?> </span> </div> <?php } else { ?> <div class="results"> <h2><a href="<?php e($page[self::URL]); ?> " rel="nofollow" <?php if ($open_in_tabs) { ?> target="_blank" <?php } ?> ><?php e($page[self::TITLE]); ?> </a>. <a class="gray-link" rel='nofollow' href="<?php e($base_query . "&q=media:news:" . $encode_source . "&s=news"); ?> " ><?php e($page[self::SOURCE_NAME] . "</a>" . "<span class='gray'> - {$pub_date}</span>"); ?> </h2> <p class="echo-link" <?php e($subtitle); ?> ><?php e(UrlParser::simplifyUrl($url, 100) . " "); ?> </p> <?php $description = isset($page[self::DESCRIPTION]) ? $page[self::DESCRIPTION] : ""; e("<p>{$description}</p>"); ?> </div> <?php } } ?> </div> <?php }
/** * Tests simplifyUrl function used on SERP pages */ function simplifyUrlTestCase() { $test_urls = array(array("http://www.example.com/", 100, "www.example.com", "HTTP Domain only"), array("https://www.example.com/", 100, "www.example.com", "HTTPS Domain only"), array("http://www.superreallylongexample.com/", 25, "www.superreallylonge...e.com", "Domain truncate"), array("http://www.example.com/word1/word2/word3/word4", 25, "www.example.com/word...word4", "Path truncate")); foreach ($test_urls as $test_url) { $result = UrlParser::simplifyUrl($test_url[0], $test_url[1]); $this->assertEqual($result, $test_url[2], $test_url[3]); } }
/** * Used to draw the results of a query to the Yioop Search Engine * * @param array $data an associative array containing a PAGES field needed * to render search result */ function renderSearchResults($data) { $is_landing = !isset($data['PAGES']) && !isset($data['MORE']); $logged_in = isset($data["ADMIN"]) && $data["ADMIN"]; $token_string = $logged_in ? CSRF_TOKEN . "=" . $data[CSRF_TOKEN] . "&" : ""; $token_string_amp = $logged_in ? CSRF_TOKEN . "=" . $data[CSRF_TOKEN] . "&" : ""; ?> <div <?php if (WORD_SUGGEST) { e('id="spell-check"'); } ?> class="spell"><span class="hidden" > </span></div> <h2 class="serp-stats"><?php if (MOBILE) { } else { $num_results = min($data['TOTAL_ROWS'], $data['LIMIT'] + $data['RESULTS_PER_PAGE']); $limit = min($data['LIMIT'] + 1, $num_results); ?> <?php e(tl('search_view_calculated', $data['ELAPSED_TIME'])); ?> <?php e(tl('search_view_results', $limit, $num_results, $data['TOTAL_ROWS'])); } ?> </h2> <?php if (!$is_landing && in_array(AD_LOCATION, array('top', 'both'))) { ?> <div class="top-adscript"><?php e($data['TOP_ADSCRIPT']); ?> </div> <?php } ?> <?php if (!$is_landing && !MOBILE && in_array(AD_LOCATION, array('side', 'both'))) { ?> <div class="side-adscript"><?php e($data['SIDE_ADSCRIPT']); ?> </div> <?php } ?> <?php $similar_words = $data['THESAURUS_VARIANTS']; $use_thesaurus = WORD_SUGGEST && count($similar_words) > 0 && !MOBILE; if ($use_thesaurus) { ?> <div id="thesaurus-results" class="thesaurus"> <?php e(tl('search_view_thesaurus_results')); foreach ($similar_words as $word) { e("<br />"); ?> <span><a href="?<?php e($token_string_amp); ?> its=<?php e($data['its']); ?> &q=<?php e($word); ?> "><?php e($word); ?> </a></span> <?php } ?> </div> <?php } if ($use_thesaurus) { ?> <div class="thesaurus-serp-results"> <?php } else { ?> <div class="serp-results"> <?php } ?> <?php foreach ($data['PAGES'] as $page) { if (isset($page[self::URL])) { if (substr($page[self::URL], 0, 4) == "url|") { $url_parts = explode("|", $page[self::URL]); $url = $url_parts[1]; $link_url = $url; $title = UrlParser::simplifyUrl($url, 60); $subtitle = "title='" . $page[self::URL] . "'"; } else { $url = $page[self::URL]; if (substr($url, 0, 7) == "record:") { $link_url = "?" . $token_string . "c=search&a=cache&q=" . $data['QUERY'] . "&arg=" . urlencode($url) . "&its=" . $page[self::CRAWL_TIME]; } else { $link_url = $url; } $title = mb_convert_encoding($page[self::TITLE], "UTF-8", "UTF-8"); if (strlen(trim($title)) == 0) { $title = UrlParser::simplifyUrl($url, 60); } $subtitle = ""; } } else { $url = ""; $link_url = $url; $title = isset($page[self::TITLE]) ? $page[self::TITLE] : ""; $subtitle = ""; } ?> <div class='result'> <?php $subsearch = isset($data["SUBSEARCH"]) ? $data["SUBSEARCH"] : ""; $base_query = "?" . $token_string_amp . "c=search"; if (isset($page['IMAGES'])) { $this->helper("images")->render($page['IMAGES'], $base_query . "&q={$data['QUERY']}", $subsearch); e(" </div>"); continue; } else { if (isset($page['FEEDS'])) { $this->helper("feeds")->render($page['FEEDS'], $base_query, $data['QUERY'], $subsearch, $data['OPEN_IN_TABS']); e(" </div>"); continue; } } ?> <h2> <?php if (strpos($link_url, self::GIT_EXTENSION)) { ?> <a href="?<?php e($token_string_amp); ?> c=search&a=cache&q=<?php e($data['QUERY']); ?> &arg=<?php e(urlencode($url)); ?> &its=<?php e($page[self::CRAWL_TIME]); ?> &repository=git" rel='nofollow'> <?php } else { ?> <a href="<?php e(htmlentities($link_url)); ?> " rel="nofollow" <?php if ($data["OPEN_IN_TABS"]) { ?> target="_blank" <?php } ?> > <?php } if (isset($page[self::THUMB]) && $page[self::THUMB] != 'NULL') { ?> <img src="<?php e($page[self::THUMB]); ?> " alt="<?php e($title); ?> " /> <?php $check_video = false; } else { echo $title; if (isset($page[self::TYPE])) { $this->helper("filetype")->render($page[self::TYPE]); } $check_video = true; } ?> </a> </h2> <?php if ($check_video) { $this->helper("videourl")->render($url, $data['VIDEO_SOURCES'], $data["OPEN_IN_TABS"]); } if (!MOBILE && isset($page[self::WORD_CLOUD]) && is_array($page[self::WORD_CLOUD])) { ?> <p><span class="echo-link" <?php e($subtitle); ?> ><?php e(UrlParser::simplifyUrl($url, 40) . " "); ?> </span><?php $cloud = $page[self::WORD_CLOUD]; $i = 1; e("<span class='word-cloud-spacer'>" . tl('search_view_word_cloud') . "</span>"); $len = 0; foreach ($cloud as $word) { $len += strlen($word); if ($len > 40) { break; } ?> <span class="word-cloud"> <a class='word-cloud-<?php e($i); ?> ' href="?<?php e($token_string_amp); ?> its=<?php e($data['its']); ?> &q=<?php e($word); ?> "><?php e($this->helper("displayresults")->render($word) . "</a></span>"); $i++; } } else { ?> <p><span class="echo-link" <?php e($subtitle); ?> ><?php e(UrlParser::simplifyUrl($url, 100) . " "); ?> </span><?php } ?> </p> <?php if (!isset($page[self::ROBOT_METAS]) || !in_array("NOSNIPPET", $page[self::ROBOT_METAS])) { $description = isset($page[self::DESCRIPTION]) ? $page[self::DESCRIPTION] : ""; $description = mb_convert_encoding($description, "UTF-8", "UTF-8"); e("<p>" . $this->helper("displayresults")->render($description) . "</p>"); } ?> <p class="serp-links-score"><?php $aux_link_flag = false; if (isset($page[self::TYPE]) && $page[self::TYPE] != "link") { if (CACHE_LINK && (!isset($page[self::ROBOT_METAS]) || !(in_array("NOARCHIVE", $page[self::ROBOT_METAS]) || in_array("NONE", $page[self::ROBOT_METAS])))) { $aux_link_flag = true; ?> <a href="?<?php e($token_string_amp); ?> c=search&a=cache&q=<?php e($data['QUERY']); ?> &arg=<?php e(urlencode($url)); ?> &its=<?php e($page[self::CRAWL_TIME]); ?> " rel='nofollow'> <?php if ($page[self::TYPE] == "text/html" || stristr($page[self::TYPE], "image")) { e(tl('search_view_cache')); } else { e(tl('search_view_as_text')); } ?> </a>. <?php } if (SIMILAR_LINK) { $aux_link_flag = true; ?> <a href="?<?php e($token_string_amp); ?> c=search&a=related&arg=<?php e(urlencode($url)); ?> &<?php ?> its=<?php e($page[self::CRAWL_TIME]); ?> " rel='nofollow'><?php e(tl('search_view_similar')); ?> </a>. <?php } if (IN_LINK) { $aux_link_flag = true; ?> <a href="?<?php e($token_string_amp); ?> c=search&q=<?php e(urlencode("link:" . $url)); ?> &<?php ?> its=<?php e($page[self::CRAWL_TIME]); ?> " rel='nofollow'><?php e(tl('search_view_inlink')); ?> </a>. <?php } if (IP_LINK && isset($page[self::IP_ADDRESSES])) { foreach ($page[self::IP_ADDRESSES] as $address) { ?> <a href="?<?php e($token_string_amp); ?> c=search&q=<?php e(urlencode('ip:' . $address)); ?> &<?php ?> its=<?php e($data['its']); ?> " rel='nofollow'>IP:<?php e("{$address}"); ?> </a>. <?php } } ?> <?php } if (MOBILE && $aux_link_flag) { e("<br />"); } if (isset($page[self::SCORE])) { ?> <span title="<?php e(tl('search_view_rank', number_format($page[self::DOC_RANK], 2)) . "\n"); e(tl('search_view_relevancy', number_format($page[self::RELEVANCE], 2)) . "\n"); e(tl('search_view_proximity', number_format($page[self::PROXIMITY], 2)) . "\n"); if (isset($page[self::THESAURUS_SCORE]) && $page[self::THESAURUS_SCORE] > 0) { e(tl('search_view_thesaurus_score', number_format($page[self::THESAURUS_SCORE], 2)) . "\n"); } if (isset($page[self::USER_RANKS])) { foreach ($page[self::USER_RANKS] as $label => $score) { e($label . ":" . number_format($score / 6553.6, 2) . "\n"); } } ?> " ><?php e(tl('search_view_score', $page[self::SCORE])); ?> </span> <?php } ?> </p> </div> <?php } //end foreach $append_url = isset($data["ADMIN"]) && $data["ADMIN"] ? "&" . CSRF_TOKEN . "=" . $data[CSRF_TOKEN] : ""; $this->helper("pagination")->render($data['PAGING_QUERY'] . $append_url . "&its=" . $data['its'], $data['LIMIT'], $data['RESULTS_PER_PAGE'], $data['TOTAL_ROWS']); ?> </div> <?php }