Exemple #1
0
 public function create(string $uri, array $query)
 {
     $query = Query::createFromPairs($query);
     $uri = Http::createFromString($uri);
     $modifier = new MergeQuery($query->__toString());
     return (string) $modifier->__invoke($uri);
 }
/**
 * Sanitizes URLS by removing things and adding other things.
 * @param  [type] $url The URL to sanitize.
 * @return [type]      The sanitized URL.
 */
function sanitizeURL($url)
{
    $rulesetMinus = array('imdb.com' => ['ref_', 'pf_rd_m', 'pf_rd_s', 'pf_rd_p', 'pf_rd_r', 'pf_rd_t', 'pf_rd_i'], 'amazon.com' => ['ref_', 'pf_rd_m', 'pf_rd_s', 'pf_rd_p', 'pf_rd_r', 'pf_rd_t', 'pf_rd_i', 'qid', 'psc', 'keywords', 'sr', 'ref', 'refRID', 'btkr', 'ie', 'camp', 'creative', 'creativeASIN', 'linkCode', 'tag', 'linkID', 'redirect'], 'amazon.co.uk' => ['ref_', 'pf_rd_m', 'pf_rd_s', 'pf_rd_p', 'pf_rd_r', 'pf_rd_t', 'pf_rd_i', 'qid', 'psc', 'keywords', 'sr', 'ref', 'refRID', 'btkr', 'ie', 'camp', 'creative', 'creativeASIN', 'linkCode', 'tag', 'linkID', 'redirect']);
    $rulesetPlus = array('amazon.com' => ['tag=csicon-20'], 'amazon.co.uk' => ['tag=csicon-21']);
    $uri = HttpUri::createFromString($url);
    $domain = $uri->host->getRegisterableDomain();
    if (array_key_exists($domain, $rulesetMinus)) {
        $uri = HttpUri::createFromString($url);
        $modifier = new removeQueryKeys($rulesetMinus[$domain]);
        $url = $modifier->__invoke($uri);
    }
    if (array_key_exists($domain, $rulesetPlus)) {
        foreach ($rulesetPlus[$domain] as $key) {
            $uri = HttpUri::createFromString($url);
            $modifier = new MergeQuery(strval($key));
            $url = $modifier->__invoke($uri);
        }
    }
    return $url;
}