本文整理汇总了PHP中Piwik\UrlHelper类的典型用法代码示例。如果您正苦于以下问题:PHP UrlHelper类的具体用法?PHP UrlHelper怎么用?PHP UrlHelper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UrlHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPathFromUrl
/**
* Returns path component from a URL
*
* @param string $url
* @return string path
*/
function getPathFromUrl($url)
{
$path = UrlHelper::getPathAndQueryFromUrl($url);
if (empty($path)) {
return 'index';
}
return $path;
}
示例2: checkUrls
/**
* Check that the array of URLs are valid URLs
*
* @param array $urls
* @throws Exception if any of the urls is not valid
*/
public function checkUrls($urls)
{
$urls = $this->cleanParameterUrls($urls);
foreach ($urls as $url) {
if (!UrlHelper::isLookLikeUrl($url)) {
throw new Exception(sprintf(Piwik::translate('SitesManager_ExceptionInvalidUrl'), $url));
}
}
}
示例3: initHostAndQueryString
/**
* @param InputInterface $input
*/
protected function initHostAndQueryString(InputInterface $input)
{
$_GET = array();
$hostname = $input->getOption('piwik-domain');
Url::setHost($hostname);
$query = $input->getArgument('url-query');
$query = UrlHelper::getArrayFromQueryString($query);
foreach ($query as $name => $value) {
$_GET[$name] = $value;
}
}
示例4: getKeywordPosition
public function getKeywordPosition()
{
if ($this->getReferrerType() == 'search' && strpos($this->getReferrerName(), 'Google') !== false) {
$url = @parse_url($this->details['referer_url']);
if (empty($url['query'])) {
return null;
}
$position = UrlHelper::getParameterFromQueryString($url['query'], 'cd');
if (!empty($position)) {
return $position;
}
}
return null;
}
示例5: index
/**
* Main Plugin Index
*
* @return mixed
* @throws \Exception
*/
public function index()
{
Piwik::checkUserHasSomeAdminAccess();
if (isset($_SERVER['REQUEST_METHOD']) && 'POST' == $_SERVER['REQUEST_METHOD']) {
// Cannot use Common::getRequestVar, because the function remove whitespaces and newline breaks
$postedSiteData = isset($_POST['site']) ? $_POST['site'] : null;
if (is_array($postedSiteData) && count($postedSiteData) > 0) {
foreach ($postedSiteData as $id => $site) {
if (!isset($site['css'], $site['file'])) {
continue;
}
// Check URL
if (!UrlHelper::isLookLikeUrl($site['file'])) {
$site['file'] = null;
}
API::getInstance()->saveSite($id, $site['css'], $site['file']);
}
// Redirect to, clear POST vars
$this->redirectToIndex('CustomOptOut', 'index');
return;
}
}
$view = new View('@CustomOptOut/index.twig');
Site::clearCache();
if (Piwik::hasUserSuperUserAccess()) {
$sitesRaw = APISiteManager::getInstance()->getAllSites();
} else {
$sitesRaw = APISiteManager::getInstance()->getSitesWithAdminAccess();
}
// Gets sites after Site.setSite hook was called
$sites = array_values(Site::getSites());
if (count($sites) != count($sitesRaw)) {
throw new \Exception("One or more website are missing or invalid.");
}
foreach ($sites as &$site) {
$site['alias_urls'] = APISiteManager::getInstance()->getSiteUrlsFromId($site['idsite']);
}
$view->adminSites = $sites;
$view->adminSitesCount = count($sites);
$view->language = LanguagesManager::getLanguageCodeForCurrentUser();
$view->isEditorEnabled = API::getInstance()->isCssEditorEnabled();
$view->editorTheme = API::getInstance()->getEditorTheme();
$view->showOldLinks = false;
$this->setBasicVariablesView($view);
return $view->render();
}
示例6: render
public function render()
{
$idSite = Common::getRequestVar('idSite');
$site = new Site($idSite);
$url = urldecode(Common::getRequestVar('url', '', 'string'));
if (!empty($url) && strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0) {
$url = 'http://' . $url;
}
if (empty($url) || !UrlHelper::isLookLikeUrl($url)) {
$url = $site->getMainUrl();
}
$dataTable = API::getInstance()->getRank($url);
/** @var \Piwik\DataTable\Renderer\Php $renderer */
$renderer = Renderer::factory('php');
$renderer->setSerialize(false);
return $this->renderTemplate('getRank', array('urlToRank' => Url::getHostFromUrl($url), 'ranks' => $renderer->render($dataTable)));
}
示例7: getRank
function getRank()
{
$idSite = Common::getRequestVar('idSite');
$site = new Site($idSite);
$url = urldecode(Common::getRequestVar('url', '', 'string'));
if (!empty($url) && strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0) {
$url = 'http://' . $url;
}
if (empty($url) || !UrlHelper::isLookLikeUrl($url)) {
$url = $site->getMainUrl();
}
$dataTable = API::getInstance()->getRank($url);
$view = new View('@SEO/getRank');
$view->urlToRank = RankChecker::extractDomainFromUrl($url);
/** @var \Piwik\DataTable\Renderer\Php $renderer */
$renderer = Renderer::factory('php');
$renderer->setSerialize(false);
$view->ranks = $renderer->render($dataTable);
return $view->render();
}
示例8: redirect
/**
* Output redirection page instead of linking directly to avoid
* exposing the referrer on the Piwik demo.
*
* @internal param string $url (via $_GET)
*/
public function redirect()
{
$url = Common::getRequestVar('url', '', 'string', $_GET);
if (!UrlHelper::isLookLikeUrl($url)) {
die('Please check the &url= parameter: it should to be a valid URL');
}
// validate referrer
$referrer = Url::getReferrer();
if (empty($referrer) || !Url::isLocalUrl($referrer)) {
die('Invalid Referrer detected - This means that your web browser is not sending the "Referrer URL" which is
required to proceed with the redirect. Verify your browser settings and add-ons, to check why your browser
is not sending this referrer.
<br/><br/>You can access the page at: ' . $url);
}
// mask visits to *.piwik.org
if (!self::isPiwikUrl($url)) {
Piwik::checkUserHasSomeViewAccess();
}
Common::sendHeader('Content-Type: text/html; charset=utf-8');
echo '<html><head><meta http-equiv="refresh" content="0;url=' . $url . '" /></head></html>';
exit;
}
示例9: getEngineHostFromUrl
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;
}
示例10: getRequestParametersGET
/**
* Returns the original request parameters in the current query string as an array mapping
* query parameter names with values. The result of this function will not be affected
* by any modifications to `$_GET` and will not include parameters in `$_POST`.
*
* @return array
*/
public static function getRequestParametersGET()
{
if (empty($_SERVER['QUERY_STRING'])) {
return array();
}
$GET = UrlHelper::getArrayFromQueryString($_SERVER['QUERY_STRING']);
return $GET;
}
示例11: initPiwikHost
protected function initPiwikHost(InputInterface $input)
{
$piwikHostname = $input->getParameterOption('--piwik-domain');
if (empty($piwikHostname)) {
$piwikHostname = $input->getParameterOption('--url');
}
$piwikHostname = UrlHelper::getHostFromUrl($piwikHostname);
Url::setHost($piwikHostname);
}
示例12: extractUtmDetailsFromUrl
/**
* Extracts the utm query parameters into array
* @return array
*/
private function extractUtmDetailsFromUrl()
{
$query = $this->currentUrlParse['query'];
$params = UrlHelper::getArrayFromQueryString($query);
return array('utm_campaign' => isset($params['utm_campaign']) ? $params['utm_campaign'] : '', 'utm_term' => isset($params['utm_term']) ? $params['utm_term'] : '', 'utm_medium' => isset($params['utm_medium']) ? $params['utm_medium'] : '', 'utm_content' => isset($params['utm_content']) ? $params['utm_content'] : '', 'utm_source' => isset($params['utm_source']) ? $params['utm_source'] : '');
}
示例13: getHostFromUrl
public static function getHostFromUrl($url)
{
if (!UrlHelper::isLookLikeUrl($url)) {
$url = "http://" . $url;
}
return parse_url($url, PHP_URL_HOST);
}
示例14: isValidUrl
/**
* Tests if the URL is a valid URL
*
* @param string $url
* @return bool
*/
private function isValidUrl($url)
{
return UrlHelper::isLookLikeUrl($url);
}
示例15: executeAsyncCli
private function executeAsyncCli($url, Output $output, $cmdId)
{
$this->processes[] = new Process($cmdId);
$url = $this->appendTestmodeParamToUrlIfNeeded($url);
$query = UrlHelper::getQueryFromUrl($url, array('pid' => $cmdId));
$hostname = UrlHelper::getHostFromUrl($url);
$command = $this->buildCommand($hostname, $query, $output->getPathToFile());
Log::debug($command);
shell_exec($command);
}