コード例 #1
0
ファイル: Parser.php プロジェクト: arshanam/inbound-rocket
 /**
  * Parse referer URL
  *
  * @param string $refererUrl
  * @param string $pageUrl
  * @return Referer
  */
 public function parse($refererUrl, $pageUrl = null)
 {
     $refererParts = $this->parseUrl($refererUrl);
     if (!$refererParts) {
         return Referer::createInvalid();
     }
     $pageUrlParts = $this->parseUrl($pageUrl);
     //print_r($refererParts);
     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 (is_array($referer['parameters'])) {
         parse_str($refererParts['query'], $queryParts);
         //foreach ($queryParts as $key => $parameter) {
         $searchTerm = isset($queryParts['q']) ? $queryParts['q'] : $searchTerm;
         //}
     }
     return Referer::createKnown($referer['medium'], $referer['source'], $searchTerm);
 }