本文整理汇总了PHP中JString::parse_url方法的典型用法代码示例。如果您正苦于以下问题:PHP JString::parse_url方法的具体用法?PHP JString::parse_url怎么用?PHP JString::parse_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JString
的用法示例。
在下文中一共展示了JString::parse_url方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ajaxGetRender
/**
*
* Ajax render to store in session
*/
public function ajaxGetRender()
{
/** load libraries for the system rener **/
JSNFactory::localimport('libraries.joomlashine.mode.rawmode');
JSNFactory::localimport('libraries.joomlashine.menu.menuitems');
/** get url **/
$render_url = JRequest::getVar('render_url', '');
$urlRender = base64_decode($render_url);
$session = JSession::getInstance('files', array('name' => 'jsnpoweradmin'));
if ($render_url == '') {
$urlRender = JSNDatabase::getDefaultPage()->link;
}
$currUri = new JURI($urlRender);
if (!$currUri->hasVar('Itemid')) {
$currUri->setVar('Itemid', JSNDatabase::getDefaultPage()->id);
}
$urlString = $currUri->toString();
$session->set('rawmode_render_url', base64_encode($urlString));
$parts = JString::parse_url($urlString);
if (!empty($parts['query'])) {
parse_str($parts['query'], $params);
} else {
$params = array();
}
$jsntemplate = JSNFactory::getTemplate();
$jsnrawmode = JSNRawmode::getInstance($params);
$jsnrawmode->setParam('positions', $jsntemplate->loadXMLPositions());
$jsnrawmode->renderAll();
$session = JSession::getInstance('files', array('name' => 'jsnajaxgetrender'));
$session->set('component', $jsnrawmode->getHTML('component'));
$session->set('jsondata', $jsnrawmode->getScript('positions', 'JSON'));
jexit('success');
}
示例2: test
/**
* Method to test an external or internal url for all valid parts.
*
* @param SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @param Registry $input An optional Registry object with the entire data set to validate against the entire form.
* @param JForm $form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 11.1
* @link http://www.w3.org/Addressing/URL/url-spec.txt
* @see JString
*/
public function test(SimpleXMLElement $element, $value, $group = null, Registry $input = null, JForm $form = null)
{
// If the field is empty and not required, the field is valid.
$required = (string) $element['required'] == 'true' || (string) $element['required'] == 'required';
if (!$required && empty($value)) {
return true;
}
$urlParts = JString::parse_url($value);
// See http://www.w3.org/Addressing/URL/url-spec.txt
// Use the full list or optionally specify a list of permitted schemes.
if ($element['schemes'] == '') {
$scheme = array('http', 'https', 'ftp', 'ftps', 'gopher', 'mailto', 'news', 'prospero', 'telnet', 'rlogin', 'sftp', 'tn3270', 'wais', 'url', 'mid', 'cid', 'nntp', 'tel', 'urn', 'ldap', 'file', 'fax', 'modem', 'git');
} else {
$scheme = explode(',', $element['schemes']);
}
/*
* Note that parse_url() does not always parse accurately without a scheme,
* but at least the path should be set always. Note also that parse_url()
* returns False for seriously malformed URLs instead of an associative array.
* @see https://secure.php.net/manual/en/function.parse-url.php
*/
if ($urlParts === false or !array_key_exists('scheme', $urlParts)) {
/*
* The function parse_url() returned false (seriously malformed URL) or no scheme
* was found and the relative option is not set: in both cases the field is not valid.
*/
if ($urlParts === false or !$element['relative']) {
return false;
}
// The best we can do for the rest is make sure that the path exists and is valid UTF-8.
if (!array_key_exists('path', $urlParts) || !JString::valid((string) $urlParts['path'])) {
return false;
}
// The internal URL seems to be good.
return true;
}
// Scheme found, check all parts found.
$urlScheme = (string) $urlParts['scheme'];
$urlScheme = strtolower($urlScheme);
if (in_array($urlScheme, $scheme) == false) {
return false;
}
// For some schemes here must be two slashes.
$scheme = array('http', 'https', 'ftp', 'ftps', 'gopher', 'wais', 'prospero', 'sftp', 'telnet', 'git');
if (in_array($urlScheme, $scheme) && substr($value, strlen($urlScheme), 3) !== '://') {
return false;
}
// The best we can do for the rest is make sure that the strings are valid UTF-8
// and the port is an integer.
if (array_key_exists('host', $urlParts) && !JString::valid((string) $urlParts['host'])) {
return false;
}
if (array_key_exists('port', $urlParts) && !is_int((int) $urlParts['port'])) {
return false;
}
if (array_key_exists('path', $urlParts) && !JString::valid((string) $urlParts['path'])) {
return false;
}
return true;
}
示例3: test
/**
* Method to test an external url for a valid parts.
*
* @param object &$element The JXmlElement object representing the <field /> tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @param object &$input An optional JRegistry object with the entire data set to validate against the entire form.
* @param object &$form The form object for which the field is being tested.
*
* @return boolean True if the value is valid, false otherwise.
*
* @since 11.1
* @throws JException on invalid rule.
* @link http://www.w3.org/Addressing/URL/url-spec.txt
* @see Jstring
*/
public function test(&$element, $value, $group = null, &$input = null, &$form = null)
{
// If the field is empty and not required, the field is valid.
$required = ((string) $element['required'] == 'true' || (string) $element['required'] == 'required');
if (!$required && empty($value))
{
return true;
}
$urlParts = JString::parse_url($value);
// See http://www.w3.org/Addressing/URL/url-spec.txt
// Use the full list or optionally specify a list of permitted schemes.
if ($element['schemes'] == '')
{
$scheme = array('http', 'https', 'ftp', 'ftps', 'gopher', 'mailto', 'news', 'prospero', 'telnet', 'rlogin', 'tn3270', 'wais', 'url',
'mid', 'cid', 'nntp', 'tel', 'urn', 'ldap', 'file', 'fax', 'modem');
}
else
{
$scheme = explode(',', $element['schemes']);
}
// This rule is only for full URLs with schemes because parse_url does not parse
// accurately without a scheme.
// @see http://php.net/manual/en/function.parse-url.php
if (!array_key_exists('scheme', $urlParts))
{
return false;
}
$urlScheme = (string) $urlParts['scheme'];
$urlScheme = strtolower($urlScheme);
if (in_array($urlScheme, $scheme) == false)
{
return false;
}
// For some schemes here must be two slashes.
if (($urlScheme == 'http' || $urlScheme == 'https' || $urlScheme == 'ftp' || $urlScheme == 'sftp' || $urlScheme == 'gopher'
|| $urlScheme == 'wais' || $urlScheme == 'gopher' || $urlScheme == 'prospero' || $urlScheme == 'telnet')
&& ((substr($value, strlen($urlScheme), 3)) !== '://'))
{
return false;
}
// The best we can do for the rest is make sure that the strings are valid UTF-8
// and the port is an integer.
if (array_key_exists('host', $urlParts) && !JString::valid((string) $urlParts['host']))
{
return false;
}
if (array_key_exists('port', $urlParts) && !is_int((int) $urlParts['port']))
{
return false;
}
if (array_key_exists('path', $urlParts) && !JString::valid((string) $urlParts['path']))
{
return false;
}
return true;
}
示例4: Internal_AutoDetectURLs
/**
* @param $string
* @return array
*/
function Internal_AutoDetectURLs($string)
{
$search = preg_split('/(?xi)
\\b
(
(?:
(?:https?|ftp):\\/\\/
|
www\\d{0,3}\\.
|
mailto:
|
(?:[a-zA-Z0-9._-]{2,}@)
)
(?:
[^\\s()<>]+
|
\\((?:[^\\s()<>]+|(\\(?:[^\\s()<>]+\\)))*\\)
)+
(?:
\\((?:[^\\s()<>]+|(\\(?:[^\\s()<>]+\\)))*\\)
|
[^\\s`!()\\[\\]{};:\'"\\.,<>?«»“”‘’]
)
)/u', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
$output = array();
foreach ($search as $index => $token) {
if ($index & 1) {
if (preg_match("/^(https?|ftp|mailto):/ui", $token)) {
// Protocol has been provided, so just use it as-is.
$url = $token;
} else {
// Add scheme to emails and raw domain URLs.
$url = (strpos($token, '@') ? 'mailto:' : 'http://') . $token;
}
// Never start URL from the middle of text (except for punctuation).
$invalid = preg_match('#[^\\s`!()\\[\\]{};\'"\\.,<>?«»“”‘’]$#u', $search[$index - 1]);
$invalid |= !$this->IsValidURL($url, true);
// We have a full, complete, and properly-formatted URL, with protocol.
// Now we need to apply the $this->url_pattern template to turn it into HTML.
$params = JString::parse_url($url);
if (!$invalid && substr($url, 0, 7) == 'mailto:') {
$email = JString::substr($url, 7);
$output[$index] = JHtml::_('email.cloak', $email, $this->IsValidEmail($email));
} elseif ($invalid || empty($params['host']) || !empty($params['pass'])) {
$output[$index - 1] .= $token;
$output[$index] = '';
} else {
$params['url'] = $url;
$params['link'] = $url;
$params['text'] = $token;
$output[$index] = $this->FillTemplate($this->url_pattern, $params);
}
} else {
$output[$index] = $token;
}
}
return $output;
}
示例5: buildRule
public function buildRule(&$router, &$uri)
{
$sef = $uri->getVar('lang');
if (empty($sef)) {
$sef = self::$lang_codes[self::$tag]->sef;
} elseif (!isset(self::$sefs[$sef])) {
$sef = self::$default_sef;
}
$Itemid = $uri->getVar('Itemid');
if (!is_null($Itemid)) {
if ($item = JFactory::getApplication()->getMenu()->getItem($Itemid)) {
if ($item->home && $uri->getVar('option') != 'com_search') {
$link = $item->link;
$parts = JString::parse_url($link);
if (isset($parts['query']) && strpos($parts['query'], '&')) {
$parts['query'] = str_replace('&', '&', $parts['query']);
}
parse_str($parts['query'], $vars);
// test if the url contains same vars as in menu link
$test = true;
foreach ($uri->getQuery(true) as $key => $value) {
if (!in_array($key, array('format', 'Itemid', 'lang')) && !(isset($vars[$key]) && $vars[$key] == $value)) {
$test = false;
break;
}
}
if ($test) {
foreach ($vars as $key => $value) {
$uri->delVar($key);
}
$uri->delVar('Itemid');
}
}
} else {
$uri->delVar('Itemid');
}
}
if (self::$mode_sef) {
$uri->delVar('lang');
if ($this->params->get('remove_default_prefix', 0) == 0 || $sef != self::$default_sef || $sef != self::$lang_codes[self::$tag]->sef || $this->params->get('detect_browser', 1) && JLanguageHelper::detectLanguage() != self::$tag && !self::$cookie) {
$uri->setPath($uri->getPath() . '/' . $sef . '/');
} else {
$uri->setPath($uri->getPath());
}
} else {
$uri->setVar('lang', $sef);
}
}
示例6: display
/**
* Display function
*/
public function display($tpl = null)
{
if (function_exists('error_reporting')) {
error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE & ~E_STRICT);
}
/** load libraries for the system rener **/
JSNFactory::localimport('libraries.joomlashine.mode.rawmode');
JSNFactory::localimport('libraries.joomlashine.menu.menuitems');
/** Assignment variables **/
$jsntemplate = JSNFactory::getTemplate();
$jsnmenuitems = JSNMenuitems::getInstance();
/** get url **/
$render_url = JRequest::getVar('render_url', '');
$session = JSession::getInstance('files', array('name' => 'jsnpoweradmin'));
if ($render_url == '' && $session->get('rawmode_render_url')) {
$render_url = $session->get('rawmode_render_url');
}
$urlRender = base64_decode($render_url);
if ($render_url == '') {
$urlRender = JSNDatabase::getDefaultPage()->link;
}
$currUri = new JURI($urlRender);
if (!$currUri->hasVar('Itemid')) {
$currUri->setVar('Itemid', JSNDatabase::getDefaultPage()->id);
}
$urlString = $currUri->toString();
$session->set('rawmode_render_url', base64_encode($urlString));
$parts = JString::parse_url($urlString);
if (!empty($parts['query'])) {
parse_str($parts['query'], $params);
} else {
$params = array();
}
$jsnrawmode = JSNRawmode::getInstance($params);
$jsnrawmode->setParam('positions', $jsntemplate->loadXMLPositions());
$jsnrawmode->renderAll();
$this->assign('component', $jsnrawmode->getHTML('component'));
$this->assign('modules', $jsnrawmode->getHTML('positions'));
$this->assign('jsnmenuitems', $jsnmenuitems);
$this->assign('urlRender', $urlRender);
/** add toolbar buttons **/
$this->addToolBar();
/** add scripts and css **/
//$this->addMedia( $currUri->getVar('Itemid'), $urlString, array());//$jsnrawmode->getScript('positions', 'Array'));
$this->addMedia($currUri->getVar('Itemid'), $urlString, $jsnrawmode->getScript('positions', 'Array'));
return parent::display();
}
示例7: getInputType
/**
* Get image type for input url or path of file.
* @return mixed
*/
protected function getInputType()
{
if (!isset($this->in['type'])) {
$this->debug && JFactory::getApplication()->enqueueMessage('ImageHelper::getInputType');
if (is_string($this->image)) {
$path = $this->image;
} else {
$path = @$this->image['src'];
}
if (is_string($path)) {
$ps = JString::parse_url($path);
if (array_key_exists('path', $ps) && !empty($ps['path'])) {
$isHttp = isset($ps['scheme']) && in_array($ps['scheme'], array('http', 'https'));
if (!$isHttp || JURI::isInternal($path)) {
$path = $ps['path'];
} else {
// is extenal url.
$this->in['type'] = 'url';
$this->in['src'] = $path;
return $this->in['type'];
}
}
} else {
if (!$path) {
$this->errors[] = 'Image path must be string or stored in array_argument[src]!';
}
}
//var_dump('Path: ', $path);
if (!file_exists($path)) {
$this->errors[] = 'Image path is not exists!';
} else {
//var_dump('EXISTS');
$this->in['src'] = realpath($path);
$infor = array();
if (!function_exists('exif_imagetype')) {
$intype = exif_imagetype($path);
} else {
$infor = getimagesize($path);
$intype = @$infor[2];
}
switch ($intype) {
case IMAGETYPE_PNG:
$this->in['type'] = IMAGETYPE_PNG;
break;
case IMAGETYPE_GIF:
$this->in['type'] = IMAGETYPE_GIF;
break;
case IMAGETYPE_JPEG:
$this->in['type'] = IMAGETYPE_JPEG;
break;
default:
}
}
}
return $this->in['type'];
}
示例8: urlToUTF8
/**
* Transforms a Punycode URL to a UTF-8 URL
*
* @param string $uri The Punycode URL to transform
*
* @return string The UTF-8 URL
*
* @since 3.1.2
*/
public static function urlToUTF8($uri)
{
if (empty($uri)) {
return;
}
$parsed = JString::parse_url($uri);
if (!isset($parsed['host']) || $parsed['host'] == '') {
// If there is no host we do not need to convert it.
return $uri;
}
$host = $parsed['host'];
$hostExploded = explode('.', $host);
$newhost = '';
foreach ($hostExploded as $hostex) {
$hostex = self::fromPunycode($hostex);
$newhost .= $hostex . '.';
}
$newhost = substr($newhost, 0, -1);
$newuri = '';
if (!empty($parsed['scheme'])) {
// Assume :// is required although it is not always.
$newuri .= $parsed['scheme'] . '://';
}
if (!empty($newhost)) {
$newuri .= $newhost;
}
if (!empty($parsed['port'])) {
$newuri .= ':' . $parsed['port'];
}
if (!empty($parsed['path'])) {
$newuri .= $parsed['path'];
}
if (!empty($parsed['query'])) {
$newuri .= '?' . $parsed['query'];
}
if (!empty($parsed['fragment'])) {
$newuri .= '#' . $parsed['fragment'];
}
return $newuri;
}
示例9: buildRule
public function buildRule(&$router, &$uri)
{
$sef = $uri->getVar('lang');
if (empty($sef)) {
$sef = self::$lang_codes[self::$tag]->sef;
} elseif (!isset(self::$sefs[$sef])) {
$sef = self::$default_sef;
}
$Itemid = $uri->getVar('Itemid');
if (!is_null($Itemid)) {
if ($item = JFactory::getApplication()->getMenu()->getItem($Itemid)) {
if ($item->home && $uri->getVar('option') != 'com_search') {
$link = $item->link;
$parts = JString::parse_url($link);
if (isset($parts['query']) && strpos($parts['query'], '&')) {
$parts['query'] = str_replace('&', '&', $parts['query']);
}
parse_str($parts['query'], $vars);
// test if the url contains same vars as in menu link
$test = true;
foreach ($vars as $key => $value) {
if ($uri->hasVar($key) && $uri->getVar($key) != $value) {
$test = false;
break;
}
}
if ($test) {
foreach ($vars as $key => $value) {
$uri->delVar($key);
}
$uri->delVar('Itemid');
}
}
} else {
$uri->delVar('Itemid');
}
}
if (self::$mode_sef) {
$uri->delVar('lang');
$uri->setPath($uri->getPath() . '/' . $sef . '/');
} else {
$uri->setVar('lang', $sef);
}
}
示例10: testParse_Url
/**
* @group String
* @covers JString::parse_url
*/
public function testParse_Url()
{
$url = 'http://localhost/joomla_development/j16_trunk/administrator/index.php?option=com_contact&view=contact&layout=edit&id=5';
$expected = parse_url($url);
$actual = JString::parse_url($url);
$this->assertEquals($expected, $actual, 'Line: ' . __LINE__ . ' Results should be equal');
$url = 'http://joomla.org/mytestpath/È';
$expected = parse_url($url);
// Fix up path for UTF-8 characters
$expected['path'] = '/mytestpath/È';
$actual = JString::parse_url($url);
$this->assertEquals($expected, $actual, 'Line: ' . __LINE__ . ' Results should be equal');
// Test special characters in URL
$url = 'http://mydomain.com/!*\'();:@&=+$,/?%#[]';
$expected = parse_url($url);
$actual = JString::parse_url($url);
$this->assertEquals($expected, $actual, 'Line: ' . __LINE__ . ' Results should be equal');
}
示例11: parse
/**
* Parse a given URI and populate the class fields.
*
* @param string $uri The URI string to parse.
*
* @return boolean True on success.
*
* @since 11.1
*/
public function parse($uri)
{
// Initialise variables
$retval = false;
// Set the original URI to fall back on
$this->_uri = $uri;
// Parse the URI and populate the object fields. If URI is parsed properly,
// set method return value to true.
if ($_parts = JString::parse_url($uri)) {
$retval = true;
}
// We need to replace & with & for parse_str to work right...
if (isset($_parts['query']) && strpos($_parts['query'], '&')) {
$_parts['query'] = str_replace('&', '&', $_parts['query']);
}
$this->_scheme = isset($_parts['scheme']) ? $_parts['scheme'] : null;
$this->_user = isset($_parts['user']) ? $_parts['user'] : null;
$this->_pass = isset($_parts['pass']) ? $_parts['pass'] : null;
$this->_host = isset($_parts['host']) ? $_parts['host'] : null;
$this->_port = isset($_parts['port']) ? $_parts['port'] : null;
$this->_path = isset($_parts['path']) ? $_parts['path'] : null;
$this->_query = isset($_parts['query']) ? $_parts['query'] : null;
$this->_fragment = isset($_parts['fragment']) ? $_parts['fragment'] : null;
// Parse the query
if (isset($_parts['query'])) {
parse_str($_parts['query'], $this->_vars);
}
return $retval;
}
示例12: download_file
/**
* Downloads the file from remote server to specified location on local server. Uses regular file operations or cURL or sockets (whichever available first) to download the file.
*
* @param url $source_url url of the source file
* @param string $target_folder target folder name, should end with DS
* @param string $target_file target file name.
*/
public static function download_file($source_url, $target_folder, $target_file)
{
if (file_exists($target_file)) {
JFile::delete($target_file);
} else {
JFolder::create($target_folder);
}
//try to connect via fopen
if (function_exists('fopen') && ini_get('allow_url_fopen')) {
//set socket timeout
ini_set('default_socket_timeout', 5);
$handle = fopen($source_url, 'rb');
if ($handle) {
$download = fopen($target_folder . $target_file, "wb");
if ($download) {
while (!feof($handle)) {
fwrite($download, fread($handle, 1024 * 8), 1024 * 8);
}
}
}
if ($handle) {
fclose($handle);
}
} else {
if (function_exists('curl_init') && function_exists('curl_exec')) {
$fh = fopen($target_folder . $target_file, "w");
$options = array(CURLOPT_FILE => $fh, CURLOPT_URL => $source_url, CURLOPT_TIMEOUT => 28800, CURLOPT_FAILONERROR => 1, CURLOPT_HEADER => 0, CURLOPT_TIMEOUT => 5);
$ch = curl_init();
curl_setopt_array($ch, $options);
curl_exec($ch);
curl_close($ch);
fclose($fh);
} else {
if (function_exists('fsockopen') && $data == '') {
$errno = 0;
$errstr = '';
$parts = JString::parse_url($source_url);
$hostname = $parts['host'];
unset($parts['scheme']);
unset($parts['host']);
$filename = CJFunctions::join_url($parts);
//timeout handling: 5s for the socket and 5s for the stream = 10s
$fsock = fsockopen($hostname, 80, $errno, $errstr, 5);
if ($fsock) {
fputs($fsock, 'GET ' . $filename . ' HTTP/1.1\\r\\n');
fputs($fsock, 'HOST: ' . $hostname . '\\r\\n');
fputs($fsock, 'Connection: close\\r\\n\\r\\n');
//force stream timeout...
stream_set_blocking($fsock, 1);
stream_set_timeout($fsock, 5);
$get_info = false;
$download = fopen($target_folder . $target_file, 'wb');
while (!feof($fsock)) {
if ($get_info) {
fwrite($download, fread($handle, 1024 * 8), 1024 * 8);
} else {
if (fgets($fsock, 8192) == '\\r\\n') {
$get_info = true;
}
}
}
fclose($fsock);
}
}
}
}
}
示例13: testParse_Url
/**
* @return array
*
* @since 11.2
* @covers JString::parse_url
*/
public function testParse_Url()
{
$url = 'http://localhost/joomla_development/j16_trunk/administrator/index.php?option=com_contact&view=contact&layout=edit&id=5';
$expected = parse_url($url);
$actual = JString::parse_url($url);
$this->assertEquals($expected, $actual, 'Line: ' . __LINE__ . ' Results should be equal');
// Test all parts of query
$url = 'https://john:doe@www.google.com:80/folder/page.html#id?var=kay&var2=key&true';
$expected = parse_url($url);
$actual = JString::parse_url($url);
$this->assertEquals($expected, $actual, 'Line: ' . __LINE__ . ' Results should be equal');
// Test special characters in URL
$url = 'http://joomla.org/mytestpath/È';
$expected = parse_url($url);
// Fix up path for UTF-8 characters
$expected['path'] = '/mytestpath/È';
$actual = JString::parse_url($url);
$this->assertEquals($expected, $actual, 'Line: ' . __LINE__ . ' Results should be equal');
// Test special characters in URL
$url = 'http://mydomain.com/!*\'();:@&=+$,/?%#[]" \\';
$expected = parse_url($url);
$actual = JString::parse_url($url);
$this->assertEquals($expected, $actual, 'Line: ' . __LINE__ . ' Results should be equal');
// Test url encoding in URL
$url = 'http://mydomain.com/%21%2A%27%28%29%3B%3A%40%26%3D%24%2C%2F%3F%25%23%5B%22%20%5C';
$expected = parse_url($url);
$actual = JString::parse_url($url);
$this->assertEquals($expected, $actual, 'Line: ' . __LINE__ . ' Results should be equal');
// Test a mix of the above
$url = 'http://john:doe@mydomain.com:80/%È21%25È3*%(';
$expected = parse_url($url);
// Fix up path for UTF-8 characters
$expected['path'] = '/%È21%25È3*%(';
$actual = JString::parse_url($url);
$this->assertEquals($expected, $actual, 'Line: ' . __LINE__ . ' Results should be equal');
// Test invalild URL
$url = 'http:///mydomain.com';
$expected = parse_url($url);
$actual = JString::parse_url($url);
$this->assertEquals($expected, $actual, 'Line: ' . __LINE__ . ' Results should be equal');
}
示例14: getAssociatedArticle
public function getAssociatedArticle($id)
{
$associated_id = 0;
require_once JPATH_SITE . '/components/com_content/helpers/route.php';
require_once JPATH_SITE . '/components/com_content/helpers/association.php';
$result = ContentHelperAssociation::getAssociations($id, 'article');
$tag = JFactory::getLanguage()->getTag();
if (isset($result[$tag])) {
$parts = JString::parse_url($result[$tag]);
parse_str($parts['query'], $vars);
if (isset($vars['id'])) {
$splits = explode(':', $vars['id']);
}
$associated_id = (int) $splits[0];
}
if (isset($associated_id) && $associated_id) {
$id = $associated_id;
}
return $id;
}
示例15: parse
/**
* Parse a given URI and populate the class fields.
*
* @param string $uri The URI string to parse.
*
* @return boolean True on success.
*
* @since 11.1
*/
public function parse($uri)
{
// Set the original URI to fall back on
$this->uri = $uri;
/*
* Parse the URI and populate the object fields. If URI is parsed properly,
* set method return value to true.
*/
$parts = JString::parse_url($uri);
$retval = $parts ? true : false;
// We need to replace & with & for parse_str to work right...
if (isset($parts['query']) && strpos($parts['query'], '&')) {
$parts['query'] = str_replace('&', '&', $parts['query']);
}
$this->scheme = isset($parts['scheme']) ? $parts['scheme'] : null;
$this->user = isset($parts['user']) ? $parts['user'] : null;
$this->pass = isset($parts['pass']) ? $parts['pass'] : null;
$this->host = isset($parts['host']) ? $parts['host'] : null;
$this->port = isset($parts['port']) ? $parts['port'] : null;
$this->path = isset($parts['path']) ? $parts['path'] : null;
$this->query = isset($parts['query']) ? $parts['query'] : null;
$this->fragment = isset($parts['fragment']) ? $parts['fragment'] : null;
// Parse the query
if (isset($parts['query'])) {
parse_str($parts['query'], $this->vars);
}
return $retval;
}