本文整理汇总了PHP中JURI::setPath方法的典型用法代码示例。如果您正苦于以下问题:PHP JURI::setPath方法的具体用法?PHP JURI::setPath怎么用?PHP JURI::setPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JURI
的用法示例。
在下文中一共展示了JURI::setPath方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSetPath
public function testSetPath() {
$this->object->setPath('/this/is/a/path/to/a/file.htm');
$this->assertThat(
$this->object->getPath(),
$this->equalTo('/this/is/a/path/to/a/file.htm')
);
}
示例2: parseRoute
/**
* Method to parse the router
*
* @param JRouter $router JRouter instance
* @param JURI $uri Current JURI instance
*
* @return array
*/
public function parseRoute($router, $uri)
{
$path = $uri->getPath();
$segments = explode('/', $path);
$alias = end($segments);
if (preg_match('/^([0-9])\\-/', $alias) == false) {
$alias = preg_replace('/\\-$/', '', $alias);
$slug = $this->getSlugByAlias($alias);
if (!empty($slug)) {
$path = str_replace($alias, $slug, $path);
$uri->setPath($path);
}
}
return array();
}
示例3: testQuery
/**
* Returns the path generated by the Simple Custom Router when building the
* given query.
* The query should not contain the leading '?'; it must be just the query
* itself.
*
* @param string $query The query to build.
* @return string The generated path, if any.
*/
public function testQuery($query)
{
$simpleCustomRouter = new SimpleCustomRouter();
$uri = new JURI();
$uri->setPath('index.php');
$uri->setQuery($query);
$siteRouter = null;
$simpleCustomRouter->build($siteRouter, $uri);
if ($uri->getPath() == 'index.php') {
return '';
} else {
if ($uri->getQuery() == '') {
return $uri->getPath();
} else {
return $uri->getPath() . '?' . $uri->getQuery();
}
}
}
示例4: gTranslate
function gTranslate($text, $SourceLan, $ResultLan)
{
$url = new JURI();
// for APIv2
$url->setHost('https://www.googleapis.com/');
$url->setPath('language/translate/v2');
$query['key'] = 'AIzaSyC04nF4KXjfR2VQ0jsFm5vEd9LbyiXqbKw';
$query['q'] = urlencode($text);
$query['source'] = $SourceLan;
$query['target'] = $ResultLan;
if (!$text) {
return;
}
$url->setQuery($query);
$url->toString();
$response = AKHelper::_('curl.getPage', $url->toString());
$json = new JRegistry($response);
$r = $json->get('data.translations');
return $r[0]->translatedText;
}
示例5: pathAddHost
/**
* Give a relative path, return path with host.
*
* @param string $path A system path.
*
* @return string Path with host added.
*/
public static function pathAddHost($path)
{
if (!$path) {
return;
}
// build path
$uri = new JURI($path);
if ($uri->getHost()) {
return $path;
}
$uri->parse(JURI::root());
$root_path = $uri->getPath();
if (strpos($path, $root_path) === 0) {
$num = JString::strlen($root_path);
$path = JString::substr($path, $num);
}
$uri->setPath($uri->getPath() . $path);
$uri->setScheme('http');
$uri->setQuery(null);
return $uri->toString();
}
示例6: gTranslate
/**
* A method to do Google translate.
*
* @param string $text String to translate.
* @param string $SourceLan Translate from this language, eg: 'zh-tw'. Empty will auto detect.
* @param string $ResultLan Translate to this language, eg: 'en'. Empty will auto detect.
*
* @return string Translated text.
*/
public static function gTranslate($text, $SourceLan, $ResultLan)
{
$url = new JURI();
// for APIv2
$url->setHost('https://www.googleapis.com/');
$url->setPath('language/translate/v2');
$query['key'] = self::APT_KEY;
$query['q'] = urlencode($text);
$query['source'] = $SourceLan;
$query['target'] = $ResultLan;
if (!$text) {
return;
}
$url->setQuery($query);
$url->toString();
$response = AKHelper::_('curl.getPage', $url->toString());
$json = new JRegistry();
$json->loadString($response);
$r = $json->get('data.translations');
return $r[0]->translatedText;
}
示例7: parse
//.........这里部分代码省略.........
if ($sefConfig->redirectSlash) {
$request = $_SERVER["REQUEST_URI"];
$noBase = substr_replace($request, '', 0, strlen(JURI::base(true)));
if ($request != "/" && $noBase != "/" && substr($request, -1) == '/') {
$mainframe->redirect(rtrim($request, "/"), '', 'message');
JFactory::getApplication()->close();
}
}
// Redirect the index.php (need to check this before index.php removal)
if ($sefConfig->fixIndexPhp && $path == 'index.php' && count($_POST) == 0) {
$q = $uri->getQuery(true);
if (count($q) == 0) {
$newUrl = JURI::root();
if (substr($newUrl, -1) != '/') {
$newUrl .= '/';
}
$mainframe->redirect($newUrl, '', 'message', true);
exit;
}
}
// Try the 301 Alias redirect
if (count($_POST) == 0) {
JoomSEF::_parseAlias($path, $uri->getQuery(true));
}
// Disable non-SEF redirect for index2.php links
// EDIT: don't even parse index2.php links!
if (substr($path, 0, 10) == 'index2.php') {
//$sefConfig->nonSefRedirect = false;
return $uri->getQuery(true);
}
// Redirect old /index.php/ links if set to
if ($sefConfig->fixIndexPhp && substr($path, 0, 10) == 'index.php/' && count($_POST) == 0) {
$newUrl = JURI::root();
if (substr($newUrl, -1) != '/') {
$newUrl .= '/';
}
$newUrl .= substr($path, 10);
$mainframe->redirect($newUrl, '', 'message', true);
exit;
}
// remove prefix (both index.php and index2.php)
$path = preg_replace('/^index2?.php/i', '', $path);
// remove slashes again to be sure there aren't any left
$path = ltrim($path, '/');
// replace spaces with our replacement character
// (mainly for '+' handling, but may be useful in some other situations too)
$path = str_replace(' ', $sefConfig->replacement, $path);
// set the route
$uri->setPath($path);
// host name handling
if (SEFTools::JoomFishInstalled() && $sefConfig->langPlacement == _COM_SEF_LANG_DOMAIN && !JPluginHelper::isEnabled('system', 'jfrouter')) {
// different domains for languages handling
$host = $uri->toString(array('host'));
$host = trim($host, '/');
$code = null;
foreach ($sefConfig->jfSubDomains as $langCode => $domain) {
if ($host == $domain) {
// if main language is not selected, use the first corresponding domain
if ($sefConfig->mainLanguage == '0') {
$code = $langCode;
break;
} else {
if ($langCode == $sefConfig->mainLanguage) {
$code = $langCode;
break;
} else {
if (is_null($code)) {
$code = $langCode;
}
}
}
}
}
// we found a matching domain
if (!is_null($code)) {
JRequest::setVar('lang', $code);
$config =& JFactory::getConfig();
$config->set('joomsef.domain_lang', $code);
}
}
// parse the url
$vars = JoomSEF::_parseSefUrl($uri, $oldUri);
// handle custom site name for extensions
if (isset($vars['option'])) {
$params =& SEFTools::getExtParams($vars['option']);
$useSitename = $params->get('useSitename', '1');
$customSitename = trim($params->get('customSitename', ''));
$config =& JFactory::getConfig();
if ($useSitename == '0') {
// don't use site name
$config->setValue('sitename', '');
} elseif (!empty($customSitename)) {
// use custom site name
$config->setValue('sitename', $customSitename);
}
}
// trigger onSefUnload patches
$mainframe->triggerEvent('onSefUnload');
return $vars;
}
示例8: shNormalizeNonSefUri
function shNormalizeNonSefUri(&$uri, $menu = null, $removeSlugs = true)
{
// put back a J!1.5 non-sef url to J! 1.0.x format
// Get the route
$route = $uri->getPath();
//Get the query vars
$vars = $uri->getQuery(true);
// fix some problems in incoming URLs
if (!empty($vars['Itemid'])) {
// sometimes we get doubles : ?Itemid=xx?Itemid=xx
$vars['Itemid'] = intval($vars['Itemid']);
$uri->setQuery($vars);
}
// fix urls obtained through a single Itemid, in menus : url is option=com_xxx&Itemid=yy
if (count($vars) == 2 && $uri->getVar('Itemid')) {
if (empty($menu)) {
$menu =& shRouter::shGetMenu();
}
$shItem = $menu->getItem($vars['Itemid']);
if (!empty($shItem)) {
// we found the menu item
$url = $shItem->link . '&Itemid=' . $shItem->id;
$uri = new JURI($url);
// rebuild $uri based on this new url
$uri->setPath($route);
$vars = $uri->getQuery(true);
}
}
if ($removeSlugs !== false) {
$vars = shRemoveSlugs($vars, $removeSlugs);
}
$uri->setQuery($vars);
}
示例9: _buildSefRoute
/**
* Function to build a sef route
*
* @param JURI $uri The uri
*
* @return void
*/
protected function _buildSefRoute($uri)
{
// Get the route
$route = $uri->getPath();
// Get the query data
$query = $uri->getQuery(true);
if (!isset($query['option'])) {
return;
}
$app = JApplication::getInstance('site');
$menu = $app->getMenu();
/*
* Build the component route
*/
$component = preg_replace('/[^A-Z0-9_\\.-]/i', '', $query['option']);
$tmp = '';
// Use the component routing handler if it exists
$path = JPATH_SITE . '/components/' . $component . '/router.php';
// Use the custom routing handler if it exists
if (file_exists($path) && !empty($query)) {
require_once $path;
$function = substr($component, 4) . 'BuildRoute';
$function = str_replace(array("-", "."), "", $function);
$parts = $function($query);
// Encode the route segments
if ($component != 'com_search') {
// Cheep fix on searches
$parts = $this->_encodeSegments($parts);
} else {
// Fix up search for URL
$total = count($parts);
for ($i = 0; $i < $total; $i++) {
// Urlencode twice because it is decoded once after redirect
$parts[$i] = urlencode(urlencode(stripcslashes($parts[$i])));
}
}
$result = implode('/', $parts);
$tmp = $result != "" ? $result : '';
}
/*
* Build the application route
*/
$built = false;
if (isset($query['Itemid']) && !empty($query['Itemid'])) {
$item = $menu->getItem($query['Itemid']);
if (is_object($item) && $query['option'] == $item->component) {
if (!$item->home || $item->language != '*') {
$tmp = !empty($tmp) ? $item->route . '/' . $tmp : $item->route;
}
$built = true;
}
}
if (!$built) {
$tmp = 'component/' . substr($query['option'], 4) . '/' . $tmp;
}
if ($tmp) {
$route .= '/' . $tmp;
} elseif ($route == 'index.php') {
$route = '';
}
// Unset unneeded query information
if (isset($item) && $query['option'] == $item->component) {
unset($query['Itemid']);
}
unset($query['option']);
// Set query again in the URI
$uri->setQuery($query);
$uri->setPath($route);
}
示例10: parse
function parse(&$siteRouter, &$uri)
{
if ($this->parsing) {
return array();
}
$this->parsing = true;
$uri->setPath(JURI::base(true) . '/' . $uri->getPath());
$mainframe = JFactory::getApplication();
$router = $mainframe->get('mijosef.global.jrouter');
$router->setMode(JROUTER_MODE_DONT_PARSE);
// Fix the missing question mark
if (count($_POST) == 0) {
$url = $uri->toString();
$new_url = preg_replace('/^([^?&]*)&([^?]+=[^?]*)$/', '$1?$2', $url);
// Redirect if question mark fixed
if ($new_url != $url) {
$mainframe->redirect($new_url, '', 'message', true);
}
}
// Check if URI is string
if (is_string($uri)) {
$uri = JURI::getInstance($uri);
}
// Backlink plugin compatibility
if (JPluginHelper::isEnabled('system', 'backlink')) {
$joomla_request = $_SERVER['REQUEST_URI'];
$real_request = $uri->toString(array('path', 'query'));
if ($real_request != $joomla_request) {
$uri = new JURI($joomla_request);
}
}
// We'll use it for Joomla! SEF to MijoSEF redirection
$old_uri = clone $uri;
// get path
$path = $uri->getPath();
// remove basepath
$path = substr_replace($path, '', 0, strlen(JURI::base(true)));
// remove slashes
$path = ltrim($path, '/');
// Check if the URL starts with index2.php
if (substr($path, 0, 10) == 'index2.php') {
return $uri->getQuery(true);
}
// remove prefix (both index.php and index2.php)
$path = preg_replace('/^index2?.php/i', '', $path);
// remove slashes again to be sure there aren't any left
$path = ltrim($path, '/');
// replace spaces with our replacement character
$path = str_replace(' ', $this->MijosefConfig->replacement_character, $path);
// set the route
$uri->setPath($path);
$vars = Mijosef::get('uri')->parseURI($uri, $old_uri);
// Parsing done
$this->parsing = false;
// Fix the start variable
if ($start = $uri->getVar('start')) {
$uri->delVar('start');
$vars['limitstart'] = $start;
}
$menu = Mijosef::get('utility')->getMenu();
// Handle an empty URL (special case)
if (empty($vars['Itemid']) && empty($vars['option'])) {
$item = Mijosef::get('uri')->getDefaultMenuItem();
if (!is_object($item)) {
return $vars;
}
// set the information in the request
$vars = $item->query;
// get the itemid
$vars['Itemid'] = $item->id;
// set the active menu item
$menu->setActive($vars['Itemid']);
// set vars
$this->setRequestVars($vars);
return $vars;
}
// Get the item id, if it hasn't been set force it to null
if (empty($vars['Itemid'])) {
$vars['Itemid'] = JRequest::getInt('Itemid', null);
}
// Get the variables from the uri
$this->setVars($vars);
// No option? Get the full information from the itemid
if (empty($vars['option'])) {
$item = $menu->getItem($this->getVar('Itemid'));
if (!is_object($item)) {
return $vars;
}
// No default item set
$vars = $vars + $item->query;
}
// Set the active menu item
$menu->setActive($this->getVar('Itemid'));
Mijosef::get('language')->parseLang($vars);
// Set vars
$this->setRequestVars($vars);
return $vars;
}
示例11: JURI
function _finalizeURI($uri, $route)
{
// Prepare non-SEF part
if ($this->attributes->non_sef_part != '' && strstr($route, '?')) {
$this->attributes->non_sef_part = str_replace('?', '&', $this->attributes->non_sef_part);
}
// Get domain
$url = self::getDomain();
// Add non-SEF vars
if ($this->MijosefConfig->append_non_sef == 1) {
$url .= $route . $this->attributes->non_sef_part;
} else {
$url .= $route;
}
// Add fragment
$fragment = $uri->getFragment();
if (!empty($fragment)) {
$url .= '#' . $fragment;
}
// Finally return new URI
$uri = new JURI($url);
$uri->setPath(JString::substr($uri->getPath(), JString::strlen(JURI::base(true))));
return $uri;
}