當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Common::getSearchEngineNames方法代碼示例

本文整理匯總了PHP中Piwik\Common::getSearchEngineNames方法的典型用法代碼示例。如果您正苦於以下問題:PHP Common::getSearchEngineNames方法的具體用法?PHP Common::getSearchEngineNames怎麽用?PHP Common::getSearchEngineNames使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Piwik\Common的用法示例。


在下文中一共展示了Common::getSearchEngineNames方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getSearchEngineUrlFromName

/**
 * Return search engine URL by name
 *
 * @see core/DataFiles/SearchEnginges.php
 *
 * @param string $name
 * @return string URL
 */
function getSearchEngineUrlFromName($name)
{
    $searchEngineNames = Common::getSearchEngineNames();
    if (isset($searchEngineNames[$name])) {
        $url = 'http://' . $searchEngineNames[$name];
    } else {
        $url = 'URL unknown!';
    }
    return $url;
}
開發者ID:carriercomm,項目名稱:piwik,代碼行數:18,代碼來源:functions.php

示例2: extractSearchEngineInformationFromUrl

 /**
  * Extracts a keyword from a raw not encoded URL.
  * Will only extract keyword if a known search engine has been detected.
  * Returns the keyword:
  * - in UTF8: automatically converted from other charsets when applicable
  * - strtolowered: "QUErY test!" will return "query test!"
  * - trimmed: extra spaces before and after are removed
  *
  * Lists of supported search engines can be found in /core/DataFiles/SearchEngines.php
  * The function returns false when a keyword couldn't be found.
  *     eg. if the url is "http://www.google.com/partners.html" this will return false,
  *       as the google keyword parameter couldn't be found.
  *
  * @see unit tests in /tests/core/Common.test.php
  * @param string $referrerUrl URL referrer URL, eg. $_SERVER['HTTP_REFERER']
  * @return array|bool   false if a keyword couldn't be extracted,
  *                        or array(
  *                            'name' => 'Google',
  *                            'keywords' => 'my searched keywords')
  */
 public static function extractSearchEngineInformationFromUrl($referrerUrl)
 {
     $referrerParsed = @parse_url($referrerUrl);
     $referrerHost = '';
     if (isset($referrerParsed['host'])) {
         $referrerHost = $referrerParsed['host'];
     }
     if (empty($referrerHost)) {
         return false;
     }
     // some search engines (eg. Bing Images) use the same domain
     // as an existing search engine (eg. Bing), we must also use the url path
     $referrerPath = '';
     if (isset($referrerParsed['path'])) {
         $referrerPath = $referrerParsed['path'];
     }
     // no search query
     if (!isset($referrerParsed['query'])) {
         $referrerParsed['query'] = '';
     }
     $query = $referrerParsed['query'];
     // Google Referrers URLs sometimes have the fragment which contains the keyword
     if (!empty($referrerParsed['fragment'])) {
         $query .= '&' . $referrerParsed['fragment'];
     }
     $searchEngines = Common::getSearchEngineUrls();
     $hostPattern = self::getLossyUrl($referrerHost);
     /*
      * Try to get the best matching 'host' in definitions
      * 1. check if host + path matches an definition
      * 2. check if host only matches
      * 3. check if host pattern + path matches
      * 4. check if host pattern matches
      * 5. special handling
      */
     if (array_key_exists($referrerHost . $referrerPath, $searchEngines)) {
         $referrerHost = $referrerHost . $referrerPath;
     } elseif (array_key_exists($referrerHost, $searchEngines)) {
         // no need to change host
     } elseif (array_key_exists($hostPattern . $referrerPath, $searchEngines)) {
         $referrerHost = $hostPattern . $referrerPath;
     } elseif (array_key_exists($hostPattern, $searchEngines)) {
         $referrerHost = $hostPattern;
     } elseif (!array_key_exists($referrerHost, $searchEngines)) {
         if (!strncmp($query, 'cx=partner-pub-', 15)) {
             // Google custom search engine
             $referrerHost = 'google.com/cse';
         } elseif (!strncmp($referrerPath, '/pemonitorhosted/ws/results/', 28)) {
             // private-label search powered by InfoSpace Metasearch
             $referrerHost = 'wsdsold.infospace.com';
         } elseif (strpos($referrerHost, '.images.search.yahoo.com') != false) {
             // Yahoo! Images
             $referrerHost = 'images.search.yahoo.com';
         } elseif (strpos($referrerHost, '.search.yahoo.com') != false) {
             // Yahoo!
             $referrerHost = 'search.yahoo.com';
         } else {
             return false;
         }
     }
     $searchEngineName = $searchEngines[$referrerHost][0];
     $variableNames = null;
     if (isset($searchEngines[$referrerHost][1])) {
         $variableNames = $searchEngines[$referrerHost][1];
     }
     if (!$variableNames) {
         $searchEngineNames = Common::getSearchEngineNames();
         $url = $searchEngineNames[$searchEngineName];
         $variableNames = $searchEngines[$url][1];
     }
     if (!is_array($variableNames)) {
         $variableNames = array($variableNames);
     }
     $key = null;
     if ($searchEngineName === 'Google Images' || $searchEngineName === 'Google' && strpos($referrerUrl, '/imgres') !== false) {
         if (strpos($query, '&prev') !== false) {
             $query = urldecode(trim(self::getParameterFromQueryString($query, 'prev')));
             $query = str_replace('&', '&', strstr($query, '?'));
         }
         $searchEngineName = 'Google Images';
//.........這裏部分代碼省略.........
開發者ID:CaptainSharf,項目名稱:SSAD_Project,代碼行數:101,代碼來源:UrlHelper.php


注:本文中的Piwik\Common::getSearchEngineNames方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。