Esempio n. 1
0
 function test_getSearchEngineHostFromUrl()
 {
     $data = array('http://www.google.com/cse' => array('www.google.com', 'www.google.com/cse'), 'http://www.google.com' => array('www.google.com', 'www.google.com'));
     foreach ($data as $url => $expected) {
         $this->assertEqual(Piwik_getSearchEngineHostFromUrl($url), $expected[0], $url);
         $this->assertEqual(Piwik_getSearchEngineHostPathFromUrl($url), $expected[1], $url);
     }
 }
Esempio n. 2
0
/**
 * Return search engine URL for URL and keyword
 *
 * @see core/DataFiles/SearchEnginges.php
 *
 * @param string $url Domain name, e.g., search.piwik.org
 * @param string $keyword Keyword, e.g., web+analytics
 * @return string URL, e.g., http://search.piwik.org/q=web+analytics
 */
function Piwik_getSearchEngineUrlFromUrlAndKeyword($url, $keyword)
{
	$searchEngineUrls = Piwik_Common::getSearchEngineUrls();
	$keyword = urlencode($keyword);
	$keyword = str_replace(urlencode('+'), urlencode(' '), $keyword);
	$path = @$searchEngineUrls[Piwik_getSearchEngineHostPathFromUrl($url)][2];
	if(empty($path))
	{
		return false;
	}
	$path = str_replace("{k}", $keyword, $path);
	return $url . (substr($url, -1) != '/' ? '/' : '') . $path;
}
Esempio n. 3
0
/**
 * Return search engine URL for URL and keyword
 *
 * @see core/DataFiles/SearchEnginges.php
 *
 * @param string $url Domain name, e.g., search.piwik.org
 * @param string $keyword Keyword, e.g., web+analytics
 * @return string URL, e.g., http://search.piwik.org/q=web+analytics
 */
function Piwik_getSearchEngineUrlFromUrlAndKeyword($url, $keyword)
{
    if ($keyword === Piwik_Referers::LABEL_KEYWORD_NOT_DEFINED) {
        return 'http://piwik.org/faq/general/#faq_144';
    }
    $searchEngineUrls = Piwik_Common::getSearchEngineUrls();
    $keyword = urlencode($keyword);
    $keyword = str_replace(urlencode('+'), urlencode(' '), $keyword);
    $path = @$searchEngineUrls[Piwik_getSearchEngineHostPathFromUrl($url)][2];
    if (empty($path)) {
        return false;
    }
    $path = str_replace("{k}", $keyword, $path);
    return $url . (substr($url, -1) != '/' ? '/' : '') . $path;
}