本文整理汇总了PHP中JURI::setQuery方法的典型用法代码示例。如果您正苦于以下问题:PHP JURI::setQuery方法的具体用法?PHP JURI::setQuery怎么用?PHP JURI::setQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JURI
的用法示例。
在下文中一共展示了JURI::setQuery方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildRoute
/**
* Method to build the router
*
* @param JRouter $router JRouter instance
* @param JURI $uri Current JURI instance
*
* @return null
*/
public function buildRoute($router, $uri)
{
if ($uri->getVar('view') == 'article') {
$query = $uri->getQuery();
$query = preg_replace('/\\&id=([0-9]+):([a-z0-9\\-\\_]+)/', '&id=\\2', $query);
$uri->setQuery($query);
}
}
示例2: testSetQuery
public function testSetQuery() {
$this->object->setQuery('somevar=somevalue');
$this->assertThat(
$this->object->getQuery(),
$this->equalTo('somevar=somevalue')
);
}
示例3: testSetQuery
/**
* Test the setQuery method.
*
* @return void
*
* @since 11.1
* @covers JURI::setQuery
*/
public function testSetQuery()
{
$this->object->setQuery('somevar=somevalue');
$this->assertThat($this->object->getQuery(), $this->equalTo('somevar=somevalue'));
$this->object->setQuery('somevar=somevalue&test=true');
$this->assertThat($this->object->getQuery(), $this->equalTo('somevar=somevalue&test=true'));
$this->object->setQuery(array('somevar' => 'somevalue', 'test' => 'true'));
$this->assertThat($this->object->getQuery(), $this->equalTo('somevar=somevalue&test=true'));
}
示例4: 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();
}
}
}
示例5: 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;
}
示例6: 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();
}
示例7: 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;
}
示例8: JURI
function _uriToUrl($uri, $removeVariables = null)
{
// Create new JURI object
$url = new JURI($uri->toString(array('path', 'query', 'fragment')));
// Remove variables if needed
if (!empty($removeVariables)) {
if (is_array($removeVariables)) {
foreach ($removeVariables as $var) {
$url->delVar($var);
}
} else {
$url->delVar($removeVariables);
}
}
// sort variables
$vars = $url->getQuery(true);
ksort($vars);
// Move option to beginning
if (isset($vars['option'])) {
$opt = $vars['option'];
unset($vars['option']);
$vars = array_merge(array('option' => $opt), $vars);
}
// Set vars
$url->setQuery($vars);
// Create string for db
return $url->toString(array('path', 'query'));
}
示例9: urldecode
function _parseSefUrl(&$uri, &$oldUri)
{
$mainframe =& JFactory::getApplication();
$db =& JFactory::getDBO();
$sefConfig =& SEFConfig::getConfig();
$route = $uri->getPath();
$oldRoute = $jSef = str_replace(' ', '+', urldecode($oldUri->getPath()));
$oldRoute = ltrim($oldRoute, '/');
//Get the variables from the uri
$vars = $uri->getQuery(true);
// Should we generate canonical link automatically?
$generateCanonical = count($vars) > 0;
// handle an empty URL (special case)
if (empty($route)) {
if (count($vars) > 0 || count($_POST) > 0) {
$redir = false;
} else {
$redir = true;
}
JoomSEF::_determineLanguage(JRequest::getVar('lang'), $redir, $redir);
$menu =& JSite::getMenu(true);
// if route is empty AND option is set in the query, assume it's non-sef url, and parse apropriately
if (isset($vars['option']) || isset($vars['Itemid'])) {
return JoomSEF::_parseRawRoute($uri);
}
$item = $menu->getDefault();
//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']);
// Create automatic canonical link if set to
if ($generateCanonical) {
$extAuto = 2;
if (isset($vars['option'])) {
$params =& SEFTools::getExtParams($vars['option']);
$extAuto = $params->get('autoCanonical', 2);
}
$autoCanonical = $extAuto == 2 ? $sefConfig->autoCanonical : $extAuto;
if ($extAuto) {
JoomSEF::set('sef.link.canonical', JURI::root());
}
}
// MetaTags for frontpage
$db->setQuery("SELECT `id` FROM `#__plugins` WHERE `element` = 'joomsef' AND `folder` = 'system' AND `published` = '1'");
if ($db->loadResult()) {
// ... and frontpage has meta tags
// If JoomFish installed, get all the URLs for frontpage and try to find the correct language
$lang = JRequest::getVar('lang');
$query = "SELECT * FROM `#__sefurls` WHERE (`sefurl` = '' OR `sefurl` = 'index.php') AND `trashed` = '0'";
if (SEFTools::JoomFishInstalled() && !is_null($lang)) {
$db->setQuery($query);
$sefRows = $db->loadObjectList();
if (is_array($sefRows) && count($sefRows) > 0) {
$noLang = null;
foreach ($sefRows as $row) {
if (preg_match('/[?&]lang=' . $lang . '($|&)/', $row->origurl) > 0) {
$sefRow = $row;
break;
}
// Save the first URL with no lang variable
if (is_null($noLang)) {
if (preg_match('/[?&]lang=[^&]*/', $row->origurl) == 0) {
$noLang = $row;
}
}
}
// If not found, try to use the one without lang variable
if (empty($sefRow) && !is_null($noLang)) {
$sefRow = $noLang;
}
}
} else {
// Try to find it the old way
$db->setQuery($query . ' LIMIT 1');
$sefRow = $db->loadObject();
}
if (!empty($sefRow)) {
$mainframe =& JFactory::getApplication();
if (!empty($sefRow->metatitle)) {
JoomSEF::set('sef.meta.title', $sefRow->metatitle);
}
if (!empty($sefRow->metadesc)) {
JoomSEF::set('sef.meta.desc', $sefRow->metadesc);
}
if (!empty($sefRow->metakey)) {
JoomSEF::set('sef.meta.key', $sefRow->metakey);
}
if (!empty($sefRow->metalang)) {
JoomSEF::set('sef.meta.lang', $sefRow->metalang);
}
if (!empty($sefRow->metarobots)) {
JoomSEF::set('sef.meta.robots', $sefRow->metarobots);
}
if (!empty($sefRow->metagoogle)) {
JoomSEF::set('sef.meta.google', $sefRow->metagoogle);
}
if (!empty($sefRow->canonicallink)) {
JoomSEF::set('sef.link.canonical', $sefRow->canonicallink);
//.........这里部分代码省略.........
示例10: 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);
}
示例11: setQuery
/**
* setQuery
*
* @param $queries
*
* @return void
*/
public function setQuery($queries)
{
$this->uri->setQuery($queries);
}
示例12: _processBuildRules
/**
* Process the build uri query data based on custom defined rules
*
* @param JURI $uri The URI
*
* @return void
*/
protected function _processBuildRules($uri)
{
// Make sure any menu vars are used if no others are specified
if ($this->_mode != JROUTER_MODE_SEF && $uri->getVar('Itemid') && count($uri->getQuery(true)) == 2) {
$app = JApplication::getInstance('site');
$menu = $app->getMenu();
// Get the active menu item
$itemid = $uri->getVar('Itemid');
$item = $menu->getItem($itemid);
if ($item) {
$uri->setQuery($item->query);
}
$uri->setVar('Itemid', $itemid);
}
// Process the attached build rules
parent::_processBuildRules($uri);
// Get the path data
$route = $uri->getPath();
if ($this->_mode == JROUTER_MODE_SEF && $route) {
$app = JApplication::getInstance('site');
if ($limitstart = $uri->getVar('limitstart')) {
$uri->setVar('start', (int) $limitstart);
$uri->delVar('limitstart');
}
}
$uri->setPath($route);
}
示例13: array
static function append_sid($hook, $url, $params = false, $is_amp = true, $session_id = false)
{
global $_SID, $_EXTRA_URL;
$arrParams = array();
$arrExtra = array();
$anchor = '';
JForumHook::fixPage();
$config =& JFactory::getConfig();
if ($url == '.php') {
$url = '/' . $config->getValue('config.phpbb_path') . '/index.php';
}
// Assign sid if session id is not specified
if ($session_id === false) {
$session_id = $_SID;
}
//Clean the url and the params first
if ($is_amp) {
$url = str_replace('&', '&', $url);
if (!is_array($params)) {
$params = str_replace('&', '&', $params);
}
}
$amp_delim = $is_amp ? '&' : '&';
$url_delim = strpos($url, '?') === false ? '?' : $amp_delim;
// Process the parameters array
if (is_array($params)) {
foreach ($params as $key => $item) {
if ($item === NULL) {
continue;
}
if ($key == '#') {
$anchor = '#' . $item;
continue;
}
$arrParams[$key] = $item;
}
} else {
if (strpos($params, '#') !== false) {
list($params, $anchor) = explode('#', $params, 2);
$anchor = '#' . $anchor;
}
parse_str($params, $arrParams);
}
//Process the extra array
if (!empty($_EXTRA_URL)) {
$extra = implode('&', $_EXTRA_URL);
parse_str($extra, $arrExtra);
}
//Create the URL
$uri = new JURI($url);
$query = $uri->getQuery(true);
$query = $query + $arrParams + $arrExtra;
$uri->setQuery($query);
//Set session id variable
if ($session_id) {
$uri->setVar('sid', $session_id);
}
//Set fragment
if ($anchor) {
$uri->setFragment($anchor);
}
$view = basename($uri->getPath(), '.php');
if (!$uri->getVar('rb_v') && $view != "style") {
if (JRequest::getVar('rb_v') == 'adm') {
if (strpos($url, $config->getValue('config.phpbb_path')) === false) {
$view = 'adm';
}
}
if (stripos($url, $config->getValue('config.phpbb_path') . '/adm') !== false) {
$view = 'adm';
}
if ($view != 'index') {
$uri->setVar('rb_v', $view);
}
}
if ($view != 'style') {
$url = 'index.php' . $uri->toString(array('query', 'fragment'));
// {} getting lost in encoding
$url = str_replace(array('%7B', '%7D'), array('{', '}'), $url);
return urldecode(JURI::base() . JRoute::_($url, $is_amp));
} else {
$url = 'style.php' . $uri->toString(array('query', 'fragment'));
$url = str_replace(array('%7B', '%7D'), array('{', '}'), $url);
return urldecode(JPATH_ROOT . '/' . $config->getValue('config.phpbb_path') . '/' . $url);
}
}