Example #1
0
 /**
  * Parse referer URL
  *
  * @param string $refererUrl
  * @param string $pageUrl
  * @return Referer
  */
 public function parse($refererUrl, $pageUrl = null)
 {
     $refererParts = static::parseUrl($refererUrl);
     if (!$refererParts) {
         return Referer::createInvalid();
     }
     $pageUrlParts = static::parseUrl($pageUrl);
     if ($pageUrlParts && $pageUrlParts['host'] === $refererParts['host'] || in_array($refererParts['host'], $this->internalHosts)) {
         return Referer::createInternal();
     }
     foreach ($this->internalHosts as $internalHost) {
         if ('*.' !== substr($internalHost, 0, 2)) {
             continue;
         }
         $domain_parts = explode('.', $refererParts['host']);
         if (is_array($domain_parts) && count($domain_parts) >= 2 && implode('.', array_slice($domain_parts, count($domain_parts) - 2, 2)) == substr($internalHost, 2, strlen($internalHost))) {
             return Referer::createInternal();
         }
     }
     $referer = $this->lookup($refererParts['host'], $refererParts['path']);
     if (!$referer) {
         return Referer::createUnknown();
     }
     $searchTerm = null;
     if ($referer['parameters']) {
         parse_str($refererParts['query'], $queryParts);
         foreach ($referer['parameters'] as $parameter) {
             $searchTerm = isset($queryParts[$parameter]) ? $queryParts[$parameter] : $searchTerm;
         }
     }
     return Referer::createKnown($referer['medium'], $referer['source'], $searchTerm);
 }
Example #2
0
 /**
  * Parse referer URL
  *
  * @param string $refererUrl
  * @param string $pageUrl
  * @return Referer
  */
 public function parse($refererUrl, $pageUrl = null)
 {
     $refererParts = static::parseUrl($refererUrl);
     if (!$refererParts) {
         return Referer::createInvalid();
     }
     $pageUrlParts = static::parseUrl($pageUrl);
     if ($pageUrlParts && $pageUrlParts['host'] === $refererParts['host'] || in_array($refererParts['host'], $this->internalHosts)) {
         return Referer::createInternal();
     }
     $referer = $this->lookup($refererParts['host'], $refererParts['path']);
     if (!$referer) {
         return Referer::createUnknown();
     }
     $searchTerm = null;
     if ($referer['parameters']) {
         parse_str($refererParts['query'], $queryParts);
         foreach ($referer['parameters'] as $parameter) {
             $searchTerm = isset($queryParts[$parameter]) ? $queryParts[$parameter] : $searchTerm;
         }
     }
     return Referer::createKnown($referer['medium'], $referer['source'], $searchTerm);
 }