From 58449a825aaddf2f9bd223cdb89fd6c74775440f Mon Sep 17 00:00:00 2001 From: mattab Date: Tue, 18 Feb 2014 13:30:41 +1300 Subject: Finishing clearing the console command to allow piwik domain --- core/UrlHelper.php | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'core/UrlHelper.php') diff --git a/core/UrlHelper.php b/core/UrlHelper.php index dbdb04dfd2..2ce26ba165 100644 --- a/core/UrlHelper.php +++ b/core/UrlHelper.php @@ -456,4 +456,41 @@ class UrlHelper 'keywords' => $key, ); } + + /** + * Returns the query part from any valid url and adds additional parameters to the query part if needed. + * + * @param string $url Any url eg `"http://example.com/piwik/?foo=bar"` + * @param array $additionalParamsToAdd If not empty the given parameters will be added to the query. + * + * @return string eg. `"foo=bar&foo2=bar2"` + * @api + */ + public static function getQueryFromUrl($url, array $additionalParamsToAdd = array()) + { + $url = @parse_url($url); + $query = ''; + + if (!empty($url['query'])) { + $query .= $url['query']; + } + + if (!empty($additionalParamsToAdd)) { + if (!empty($query)) { + $query .= '&'; + } + + $query .= Url::getQueryStringFromParameters($additionalParamsToAdd); + } + + return $query; + } + + public static function getHostFromUrl($url) + { + if (!UrlHelper::isLookLikeUrl($url)) { + $url = "http://" . $url; + } + return parse_url($url, PHP_URL_HOST); + } } -- cgit v1.2.3