本文整理汇总了PHP中JUri::setQuery方法的典型用法代码示例。如果您正苦于以下问题:PHP JUri::setQuery方法的具体用法?PHP JUri::setQuery怎么用?PHP JUri::setQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JUri
的用法示例。
在下文中一共展示了JUri::setQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authenticate
/**
* Get the access token or redict to the authentication URL.
*
* @return string The access token
*
* @since 12.3
*/
public function authenticate()
{
if ($data['code'] = $this->input->get('code', false, 'raw')) {
$data['grant_type'] = 'authorization_code';
$data['redirect_uri'] = $this->getOption('redirecturi');
$data['client_id'] = $this->getOption('clientid');
$data['client_secret'] = $this->getOption('clientsecret');
if ($this->provider->systemName == 'linkedin') {
$data['redirect_uri'] = urlencode($this->getOption('redirecturi'));
$uri = new JUri($this->getOption('tokenurl'));
$uri->setQuery($data);
$response = $this->transport->request('POST', $uri, null, array());
} else {
$response = $this->http->post($this->getOption('tokenurl'), $data);
}
if ($response->code >= 200 && $response->code < 400) {
if (strpos($response->headers['Content-Type'], 'application/json') !== false) {
$token = array_merge(json_decode($response->body, true), array('created' => time()));
} else {
parse_str($response->body, $token);
$token = array_merge($token, array('created' => time()));
}
$this->setToken($token);
return $token;
} else {
throw new RuntimeException('Error code ' . $response->code . ' received requesting access token: ' . $response->body . '.');
}
}
if ($this->getOption('sendheaders')) {
$this->application->redirect($this->createUrl());
}
return false;
}
示例2: quickRouting
/**
* route
*
* @return void
*
* @throws \Exception
*/
public static function quickRouting()
{
$app = \JFactory::getApplication();
$input = $app->input;
if ($app->isSite()) {
$closure = function (\JRouterSite $router, \JUri $uri) use($input, $app) {
$route = $uri->getPath();
$route = trim($route, '/');
// Admin
if ($route == 'admin') {
$uri = \JUri::getInstance();
$target = new \JUri(\JUri::root() . 'administrator');
$target->setQuery($uri->getQuery());
$app->redirect($target);
}
return array();
};
$router = $app::getRouter();
$router->attachParseRule($closure, JVERSION >= 3.4 ? $router::PROCESS_BEFORE : null);
} else {
if ($input->get('goezset') !== null) {
$plugin = \JTable::getInstance('Extension');
if ($plugin->load(array('name' => 'plg_system_ezset'))) {
$extId = $plugin->extension_id;
$app->redirect(\JRoute::_('index.php?option=com_plugins&task=plugin.edit&extension_id=' . $extId, false));
exit;
}
}
}
}
示例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: _
/**
* Build by resource.
*
* @param string $resource The resource key to find our route.
* @param array $data The url query data.
* @param boolean $xhtml Replace & by & for XML compilance.
* @param integer $ssl Secure state for the resolved URI.
* 1: Make URI secure using global secure site URI.
* 2: Make URI unsecure using the global unsecure site URI.
*
* @return string Route url.
*/
public static function _($resource, $data = array(), $xhtml = true, $ssl = null)
{
$resource = explode('.', $resource, 2);
if (count($resource) == 2) {
$data['option'] = $resource[0];
$data['_resource'] = $resource[1];
} elseif (count($resource) == 1) {
$data['option'] = $resource[0];
$data['_resource'] = null;
}
$url = new \JUri();
$url->setQuery($data);
$url->setPath('index.php');
return \JRoute::_((string) $url, $xhtml, $ssl);
}
示例5: 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|bool Translated text.
*/
public static function gTranslate($text, $SourceLan, $ResultLan)
{
$url = new \JUri();
// For Google 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 false;
}
$url->setQuery($query);
$url->toString();
$response = CurlHelper::get((string) $url);
if (empty($response->body)) {
return '';
}
$json = new \JRegistry();
$json->loadString($response->body, 'json');
$r = $json->get('data.translations');
return $r[0]->translatedText;
}
示例6: redirectBack
/**
* Redirect back to the referrer page.
*
* If there's no referrer or it's external, Kunena will return to forum home page.
* Also redirects back to tasks are prevented.
*
* @param string $anchor
*/
protected function redirectBack($anchor = '')
{
$default = JUri::base() . ($this->app->isSite() ? ltrim(KunenaRoute::_('index.php?option=com_kunena'), '/') : '');
$referrer = $this->app->input->server->getString('HTTP_REFERER');
$uri = JUri::getInstance($referrer ? $referrer : $default);
if (JUri::isInternal($uri->toString())) {
// Parse route.
$vars = $this->app->getRouter()->parse($uri);
$uri = new JUri('index.php');
$uri->setQuery($vars);
// Make sure we do not return into a task.
$uri->delVar('task');
$uri->delVar(JSession::getFormToken());
} else {
$uri = JUri::getInstance($default);
}
if ($anchor) {
$uri->setFragment($anchor);
}
$this->app->redirect(JRoute::_($uri->toString()));
}
示例7: cache
/**
* Caches a harvested record.
*
* @param JObject $harvest The harvest configuration.
* @param SimpleXmlElement $data An OAI record as an instance of the SimpleXmlElement class.
*/
protected function cache($harvest, $data)
{
$params = new \Joomla\Registry\Registry();
$params->loadString($harvest->params);
if (isset($data->header->identifier)) {
$context = 'joai.' . $params->get('discovery.plugin.metadata');
$dispatcher = JEventDispatcher::getInstance();
JPluginHelper::importPlugin("joai");
$array = $dispatcher->trigger('onJOaiHarvestMetadata', array($context, $data->metadata));
$cache = array("metadata" => JArrayHelper::getValue($array, 0));
if ($params->get('harvest_type') !== self::METADATA) {
$metadataPrefix = $params->get('discovery.plugin.assets');
$queries = array('verb' => 'GetRecord', 'identifier' => (string) $data->header->identifier, 'metadataPrefix' => $metadataPrefix);
$url = new JUri($params->get('discovery.url'));
$url->setQuery($queries);
$http = JHttpFactory::getHttp();
$response = $http->get($url);
if ((int) $response->code == 200) {
$context = 'joai.' . $metadataPrefix;
$node = simplexml_load_string($response->body);
$array = $dispatcher->trigger('onJOaiHarvestAssets', array($context, $node));
$cache["assets"] = JArrayHelper::getValue($array, 0, array());
} else {
throw new Exception((string) $response, (int) $response->code);
}
}
$table = JTable::getInstance('Cache', 'JHarvestTable');
$table->set('id', (string) $data->header->identifier);
$table->set('data', json_encode($cache));
$table->set('harvest_id', (int) $harvest->id);
$table->store();
}
}
示例8: createUri
/**
* Create a uri based on a full or partial url string
*
* @param string $url The URI or an associative array
*
* @return JUri
*
* @since 3.2
*/
protected function createUri($url)
{
if (!is_array($url) && substr($url, 0, 1) != '&') {
return new JUri($url);
}
$uri = new JUri('index.php');
if (is_string($url)) {
$vars = array();
if (strpos($url, '&') !== false) {
$url = str_replace('&', '&', $url);
}
parse_str($url, $vars);
} else {
$vars = $url;
}
$vars = array_merge($this->getVars(), $vars);
foreach ($vars as $key => $var) {
if ($var == "") {
unset($vars[$key]);
}
}
$uri->setQuery($vars);
return $uri;
}
示例9: _getPrototypeURIForPagination
/**
* Returns a JUri instance with a prototype URI used as the base for the
* other URIs created by the JSON renderer
*
* @return JUri The prototype JUri instance
*/
protected function _getPrototypeURIForPagination()
{
$protoUri = new JUri('index.php');
$protoUri->setQuery($this->input->getData());
$protoUri->delVar('savestate');
$protoUri->delVar('base_path');
return $protoUri;
}
示例10: buildRule
/**
* @param JRouter $router
* @param JUri $uri
*/
function buildRule(&$router, &$uri)
{
$MobileJoomla_Device =& MobileJoomla::getDevice();
if ($MobileJoomla_Device['markup'] != $MobileJoomla_Device['default_markup']) {
switch ($uri->getVar('format')) {
case 'feed':
case 'json':
case 'xml':
return;
}
switch ($uri->getVar('type')) {
case 'rss':
case 'atom':
return;
}
if ((is_a($router, 'shRouter') || class_exists('Sh404sefClassRouter')) && $uri->getVar('Itemid') && count($uri->getQuery(true)) == 2) {
$itemid = $uri->getVar('Itemid');
$app = JFactory::getApplication();
$menu = $app->getMenu();
$item = $menu->getItem($itemid);
$uri->setQuery($item->query);
$uri->setVar('Itemid', $itemid);
$uri->setVar('device', $MobileJoomla_Device['markup']);
} else {
$uri->setVar('device', $MobileJoomla_Device['markup']);
}
}
}
示例11: _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) {
if ($limitstart = $uri->getVar('limitstart')) {
$uri->setVar('start', (int) $limitstart);
$uri->delVar('limitstart');
}
}
$uri->setPath($route);
}
示例12: getMultilingualDocument
/**
* @todo A bruteforce/messy way to get multilingual information out of DSpace
* and into JSolr.
*/
private function getMultilingualDocument($record)
{
$languages = array();
// DSpace handles languages and translations horribly.
foreach (JLanguageHelper::getLanguages() as $language) {
$code = $language->lang_code;
// we need to handle en_US differently in DSpace.
if (JString::strtolower($code) == 'en-us') {
$code = 'en_US';
}
$languages[] = JString::strtolower(JArrayHelper::getValue(explode("-", $code), 0));
}
$fields = array();
foreach ($languages as $language) {
foreach ($record->metadata as $item) {
$field = $item->schema . '.' . $item->element;
if ($item->qualifier) {
$field .= '.' . $item->qualifier;
}
$field .= '.' . $language;
$fields[] = $field;
}
}
$vars = array();
$vars['q'] = '*:*';
$vars['fq'] = "(search.resourceid:" . $record->id . "%20AND%20search.resourcetype:2)";
$vars['fl'] = implode(',', $fields);
$url = new JUri($this->params->get('rest_url') . '/discover.json');
$url->setQuery($vars);
$http = JHttpFactory::getHttp();
$response = $http->get((string) $url);
if ((int) $response->code !== 200) {
throw new Exception($response->body, $response->code);
}
$response = json_decode($response->body);
if (isset($response->response->docs)) {
$document = JArrayHelper::getValue($response->response->docs, 0);
$document = JArrayHelper::fromObject($document);
foreach ($fields as $field) {
if (array_key_exists($field, $document)) {
$parts = explode(".", $field);
$popped = $parts;
array_pop($popped);
$popped = implode(".", $popped);
foreach (JArrayHelper::getValue($document, $field) as $value) {
$found = false;
while (($item = current($record->metadata)) && !$found) {
$raw = $item->schema . '.' . $item->element;
if ($item->qualifier) {
$raw .= '.' . $item->qualifier;
}
if ($popped == $raw) {
if ($item->value == $value) {
$key = key($record->metadata);
$record->metadata[$key]->lang = JArrayHelper::getValue($parts, count($parts) - 1);
$found = true;
}
}
next($record->metadata);
}
reset($record->metadata);
}
}
}
}
return $record;
}
示例13: createURI
/**
* Create a uri based on a full or partial url string
*
* @param string $url The URI or an associative array
*
* @return JUri
*
* @since 3.2
*/
protected function createURI($url)
{
if (is_array($url)) {
$uri = new JUri('index.php');
$uri->setQuery($url);
return $uri;
} elseif (substr($url, 0, 1) == '&') {
$vars = array();
if (strpos($url, '&') !== false) {
$url = str_replace('&', '&', $url);
}
parse_str($url, $vars);
$vars = array_merge($this->getVars(), $vars);
foreach ($vars as $key => $var) {
if ($var == "") {
unset($vars[$key]);
}
}
$url = 'index.php?' . JUri::buildQuery($vars);
}
// Decompose link into url component parts
return new JUri($url);
}
示例14: editTitle
/**
* Build the edit link.
*
* @param string $title Title of link, default is an icon.
* @param string $task View name to build task: `{view}.edit.edit`.
* @param int $id Edit id.
* @param array $query URL query array.
* @param array $attribs Link element attributes.
*
* @return string
*/
public function editTitle($title = null, $task = null, $id = null, $query = array(), $attribs = array())
{
$canEdit = $this->state->get('access.canEdit', true);
$canEditOwn = $this->state->get('access.canEditOwn', true);
$item = $this->current;
$pkName = $this->config->get('field.pk');
$titleField = $this->config->get('field.title');
$title = $title ?: $this->escape($item->{$titleField});
$defaultQuery = array('option' => $this->config->get('option'), 'task' => $task ?: $this->config->get('view_item') . '.edit.edit', $pkName => $id ?: $this->current->{$pkName});
$query = array_merge($defaultQuery, $query);
$uri = new \JUri();
$uri->setQuery($query);
if ($canEdit || $canEditOwn) {
return \JHtml::link($uri, $title, $attribs);
} else {
return $item->{$titleField};
}
}
示例15: onJHarvestRetrieve
/**
* Captures the onJHarvestRetrieve event, retrieving records via the configured
* OpenSearch results.
*
* @param JObject $harvest The harvest information.
*/
public function onJHarvestRetrieve($harvest)
{
if ($harvest->get('params')->get('discovery.type') != 'opensearch') {
return;
}
$templateUrl = $harvest->get('params')->get('discovery.url');
$http = JHttpFactory::getHttp();
$parameters = array("{startIndex?}" => 0, "{startPage?}" => 0, "{count?}" => 100, "{language}" => urlencode(JFactory::getLanguage()->getName()), "{inputEncoding}" => "UTF-8", "{outputEncoding}" => "UTF-8");
$dom = new DomDocument();
$count = 0;
// the number of records to retrieve.
do {
$url = new JUri($templateUrl);
$queries = $url->getQuery(true);
foreach ($queries as $keyq => $valueq) {
if (array_key_exists($valueq, $parameters)) {
$queries[$keyq] = $parameters[$valueq];
}
}
$url->setQuery($queries);
$response = $http->get($url);
if ((int) $response->code === 200) {
$reader = new XMLReader();
$reader->xml($response->body);
while ($reader->read()) {
if ($reader->nodeType == XmlReader::ELEMENT) {
if ($reader->localName == 'entry') {
$entry = simplexml_import_dom($dom->importNode($reader->expand(), true));
$this->cache($harvest, $entry);
}
if ($reader->localName == 'item') {
$entry = simplexml_import_dom($dom->importNode($reader->expand(), true));
$this->cache($harvest, $entry);
}
if ($reader->localName == 'totalResults') {
$totalResults = simplexml_import_dom($dom->importNode($reader->expand(), true));
if (!$count) {
$count = (int) $totalResults;
}
}
}
}
}
$parameters['{startIndex?}'] += $parameters['{count?}'];
$parameters['{startPage?}'] += 1;
} while ($parameters['{startIndex?}'] < $count);
}