Piwik\UrlHelper::getLossyUrl PHP Метод

getLossyUrl() публичный статический Метод

Examples: www.example.com -> example.com search.example.com -> example.com m.example.com -> example.com de.example.com -> }.example.com example.de -> example.} example.co.uk -> example.}
public static getLossyUrl ( string $url ) : string
$url string
Результат string
    public static function getLossyUrl($url)
    {
        static $countries;
        if (!isset($countries)) {
            /** @var RegionDataProvider $regionDataProvider */
            $regionDataProvider = StaticContainer::get('Piwik\\Intl\\Data\\Provider\\RegionDataProvider');
            $countries = implode('|', array_keys($regionDataProvider->getCountryList(true)));
        }
        return preg_replace(array('/^(w+[0-9]*|search)\\./', '/(^|\\.)m\\./', '/(\\.(com|org|net|co|it|edu))?\\.(' . $countries . ')(\\/|$)/', '/(^|\\.)(' . $countries . ')\\./'), array('', '$1', '.{}$4', '$1{}.'), $url);
    }

Usage Example

Пример #1
0
 protected function getEngineHostFromUrl($host, $path, $query)
 {
     $searchEngines = $this->getDefinitions();
     $hostPattern = UrlHelper::getLossyUrl($host);
     /*
      * 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($host . $path, $searchEngines)) {
         $host = $host . $path;
     } elseif (array_key_exists($host, $searchEngines)) {
         // no need to change host
     } elseif (array_key_exists($hostPattern . $path, $searchEngines)) {
         $host = $hostPattern . $path;
     } elseif (array_key_exists($hostPattern, $searchEngines)) {
         $host = $hostPattern;
     } elseif (!array_key_exists($host, $searchEngines)) {
         if (!strncmp($query, 'cx=partner-pub-', 15)) {
             // Google custom search engine
             $host = 'google.com/cse';
         } elseif (!strncmp($path, '/pemonitorhosted/ws/results/', 28)) {
             // private-label search powered by InfoSpace Metasearch
             $host = 'wsdsold.infospace.com';
         } elseif (strpos($host, '.images.search.yahoo.com') != false) {
             // Yahoo! Images
             $host = 'images.search.yahoo.com';
         } elseif (strpos($host, '.search.yahoo.com') != false) {
             // Yahoo!
             $host = 'search.yahoo.com';
         } else {
             return false;
         }
     }
     return $host;
 }
All Usage Examples Of Piwik\UrlHelper::getLossyUrl