本文整理汇总了PHP中JRouter::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP JRouter::getInstance方法的具体用法?PHP JRouter::getInstance怎么用?PHP JRouter::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JRouter
的用法示例。
在下文中一共展示了JRouter::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUri
/**
* Get Uri
*
* @param string $url URL
*
* @return JUri
*/
public function getUri($url = 'SERVER')
{
static $uriArray = array();
if (!array_key_exists($url, $uriArray)) {
// This will enable both SEF and non-SEF URI to be parsed properly
$router = clone JRouter::getInstance('site');
$uri = clone JUri::getInstance($url);
$langCode = JLanguageHelper::detectLanguage();
$lang = $uri->getVar('lang', $langCode);
$uri->setVar('lang', $lang);
$sefs = JLanguageHelper::getLanguages('lang_code');
if (isset($sefs[$lang])) {
$lang = $sefs[$lang]->sef;
$uri->setVar('lang', $lang);
}
$router->setVars(array(), false);
$query = $router->parse($uri);
$query = array_merge($query, $uri->getQuery(true));
$uri->setQuery($query);
// We are removing format because of default value is csv if present and if not set
// and we are never going to remember csv page in a browser history anyway
$uri->delVar('format');
$uriArray[$url] = $uri;
}
return $uriArray[$url];
}
示例2: DefaultViewEventCatRowNew
function DefaultViewEventCatRowNew($view, $row, $args = "")
{
// I choost not to use $row->fgcolor()
$fgcolor = "inherit";
$router = JRouter::getInstance("site");
$vars = $router->getVars();
$vars["catids"] = $row->catid();
if (array_key_exists("Itemid", $vars) && is_null($vars["Itemid"])) {
$vars["Itemid"] = JRequest::getInt("Itemid", 0);
}
$eventlink = "index.php?";
foreach ($vars as $key => $val) {
$eventlink .= $key . "=" . $val . "&";
}
$eventlink = substr($eventlink, 0, strlen($eventlink) - 1);
$eventlink = JRoute::_($eventlink);
?>
<a class="ev_link_cat" href="<?php
echo $eventlink;
?>
" style="color:<?php
echo $fgcolor;
?>
;" title="<?php
echo JEventsHTML::special($row->catname());
?>
"><?php
echo $row->catname();
?>
</a>
<?php
}
示例3: browse
/**
* Browse the given uri.
*
* @param string $uri The uri
* @param boolean $duplicateLast True to duplicate the last element if it's the same.
*
* @return void
*/
public function browse($uri = null, $duplicateLast = false)
{
// This will enable both SEF and non-SEF URI to be parsed properly
$router = JRouter::getInstance('site');
if (null === $uri) {
$uri = Juri::getInstance();
} else {
$uri = Juri::getInstance($uri);
}
// We are removing format because of default value is csv if present and if not set
// and we are never going to remember csv page in a browser history anyway
$uri->delVar('format');
$query = $router->parse($uri);
$uri = 'index.php?' . Juri::getInstance()->buildQuery($query);
$this->history->enqueue($uri, $duplicateLast);
}
示例4: getContentRoute
function getContentRoute($url)
{
static $router;
// Only get the router once.
if (!is_object($router)) {
// Import dependencies.
jimport('joomla.application.router');
require_once JPATH_SITE . DS . 'includes' . DS . 'application.php';
// Get the site router.
$config =& JFactory::getConfig();
$router = JRouter::getInstance('site');
$router->setMode($config->getValue('sef', 1));
}
// Build the route.
$uri =& $router->build($url);
$route = $uri->toString(array('path', 'query', 'fragment'));
// Strip out the base portion of the route.
$route = str_replace('administrator/', '', $route);
return $route;
}
示例5: getRouter
public static function getRouter($name = null, array $options = array())
{
$name = 'administrator';
try {
$router = \JRouter::getInstance($name, $options);
} catch (\Exception $e) {
return null;
}
return $router;
}
示例6: getRouter
/**
* getRouter
*
* @return \JRouterSite
*/
protected static function getRouter()
{
return \JRouter::getInstance('site', ['mode' => JROUTER_MODE_SEF]);
}
示例7: testGetInstanceException
/**
* Tests the exception thrown by the getInstance() method
*
* @return void
* @since 3.4
* @expectedException RuntimeException
* @testdox getInstance() throws a RuntimeException, if a router for an unknown client is requested
*/
public function testGetInstanceException()
{
JRouter::getInstance('unknown');
}
示例8: DefaultLoadedFromTemplate
//.........这里部分代码省略.........
}
if (is_null($templates[$template_name])) {
return false;
}
$catids = $event->catids() && count($event->catids()) ? $event->catids() : array($event->catid());
$catids[] = 0;
// find the overlap
$catids = array_intersect($catids, array_keys($templates[$template_name]));
// At present must be an EXACT category match - no inheriting allowed!
if (count($catids) == 0) {
if (!isset($templates[$template_name][0]) || $templates[$template_name][0]->value == "") {
return false;
}
}
$template = false;
foreach ($catids as $catid) {
// use the first matching non-empty layout
if ($templates[$template_name][$catid]->value != "") {
$template = $templates[$template_name][$catid];
break;
}
}
if (!$template) {
return false;
}
$template_value = $template->value;
$specialmodules = $template->params;
$matchesarray = $template->matchesarray;
} else {
// This is a special scenario where we call this function externally e.g. from RSVP Pro messages
// In this scenario we have not gone through the displaycustomfields plugin
static $pluginscalled = array();
if (!isset($pluginscalled[$event->rp_id()])) {
$dispatcher = JDispatcher::getInstance();
JPluginHelper::importPlugin("jevents");
$customresults = $dispatcher->trigger('onDisplayCustomFields', array(&$event));
$pluginscalled[$event->rp_id()] = $event;
} else {
$event = $pluginscalled[$event->rp_id()];
}
// Adjust template_value to include dynamic module output then strip it out afterwards
if ($specialmodules) {
$modids = $specialmodules->get("modid", array());
if (count($modids) > 0) {
$modvals = $specialmodules->get("modval", array());
// not sure how this can arise :(
if (is_object($modvals)) {
$modvals = get_object_vars($modvals);
}
for ($count = 0; $count < count($modids) && $count < count($modvals) && trim($modids[$count]) != ""; $count++) {
$template_value .= "{{module start:MODULESTART#" . $modids[$count] . "}}";
// cleaned later!
//$template_value .= preg_replace_callback('|{{.*?}}|', 'cleanLabels', $modvals[$count]);
$template_value .= $modvals[$count];
$template_value .= "{{module end:MODULEEND}}";
}
}
}
// strip carriage returns other wise the preg replace doesn;y work - needed because wysiwyg editor may add the carriage return in the template field
$template_value = str_replace("\r", '', $template_value);
$template_value = str_replace("\n", '', $template_value);
// non greedy replacement - because of the ?
$template_value = preg_replace_callback('|{{.*?}}|', 'cleanLabels', $template_value);
$matchesarray = array();
preg_match_all('|{{.*?}}|', $template_value, $matchesarray);
}
示例9: getContentPath
/**
* Method to get the path (SEF route) for a content item.
*
* @param string $url The non-SEF route to the content item.
*
* @return string The path for the content item.
*
* @since 2.5
*/
public static function getContentPath($url)
{
static $router;
// Only get the router once.
if (!$router instanceof JRouter) {
jimport('joomla.application.router');
include_once JPATH_SITE . '/includes/application.php';
// Get and configure the site router.
$config = JFactory::getConfig();
$router = JRouter::getInstance('site');
$router->setMode($config->get('sef', 1));
}
// Build the relative route.
$uri = $router->build($url);
$route = $uri->toString(array('path', 'query', 'fragment'));
$route = str_replace(JURI::base(true) . '/', '', $route);
return $route;
}
示例10: render
/**
*
* JT3 Framework render
*/
public function render()
{
$replace = array();
$matches = array();
parent::loadLayout();
$data = $this->_html;
if (preg_match_all('#<jdoc:include\\ type="([^"]+)" (.*)\\/>#iU', $data, $matches)) {
$cache_exclude = parent::getParam('cache_exclude');
$cache_exclude = new JRegistry($cache_exclude);
$nc_com = explode(',', $cache_exclude->get('component'));
$nc_pos = explode(',', $cache_exclude->get('position'));
$replace = array();
$matches[0] = array_reverse($matches[0]);
$matches[1] = array_reverse($matches[1]);
$matches[2] = array_reverse($matches[2]);
$count = count($matches[1]);
$option = JRequest::getCmd('option');
$headindex = -1;
//for none cache items
$nonecachesearch = array();
$nonecachereplace = array();
//search for item load in template (css, images, js)
$regex = '/(href|src)=("|\')([^"\']*\\/templates\\/' . T3_ACTIVE_TEMPLATE . '\\/([^"\']*))\\2/';
for ($i = 0; $i < $count; $i++) {
$attribs = JUtility::parseAttributes($matches[2][$i]);
$type = $matches[1][$i];
$name = isset($attribs['name']) ? $attribs['name'] : null;
//no cache => no cache for all jdoc include except head
//cache: exclude modules positions & components listed in cache exclude param
//check if head
if ($type == 'head') {
$headindex = $i;
} else {
$content = parent::getBuffer($type, $name, $attribs);
$renderer = $this->loadRenderer('module');
$poweradmin = JRequest::getCmd('poweradmin', 0);
$vsm_changeposition = JRequest::getCmd('vsm_changeposition', 0);
//Add a div wrapper for showing block information
if ($poweradmin == 1) {
//If the page requested to render position only
if ($vsm_changeposition == 1) {
if ($type == 'modules') {
$content = '<div class="jsn-element-container_inner">' . '<div class="jsn-poweradmin-position clearafter" id="' . $name . '-jsnposition">
<p>' . $name . '</p>
</div>
</div>
';
} else {
if ($type == 'module') {
$key = "mod.{$name}";
} else {
if ($type == 'component') {
$content = '<div class="jsn-component-container" id="jsnrender-component"><div class="jsn-show-component-container"><p>' . parent::getTitle() . '</p></div></div>';
} else {
$key = "{$type}.{$name}";
}
}
}
} else {
if ($type == 'modules') {
$buffer = '';
foreach (JModuleHelper::getModules($name) as $mod) {
$buffer .= '<div class="poweradmin-module-item" id="' . $mod->id . '-jsnposition" ><div id="moduleid-' . $mod->id . '-content">' . $renderer->render($mod, $attribs) . '</div></div>';
}
$content = '<div class="jsn-element-container_inner">' . '<div class="jsn-poweradmin-position clearafter" id="' . $name . '-jsnposition">
' . $buffer . '
</div>
</div>
';
} else {
if ($type == 'module') {
$key = "mod.{$name}";
} else {
if ($type == 'component') {
$app = JFactory::getApplication();
$itemid = JRequest::getVar('itemid', '');
$menu = $app->getMenu();
if ($itemid) {
$menuItem = $menu->getItem($itemid);
} else {
$menuItem = $menu->getActive();
}
$uri = JURI::getInstance();
$route = JRouter::getInstance('site');
$params = $route->parse($uri);
if (empty($params['id']) && !empty($menuItem->id)) {
$uri->parse($menuItem->link);
$params = $route->parse($uri);
}
if (!empty($params['option'])) {
$key = array_search($params['option'], array('', 'com_content', 'com_categories', 'com_banner', 'com_weblinks', 'com_contact', 'com_newsfeeds', 'com_search', 'com_redirect'));
if ($key) {
if (!empty($params['id'])) {
if ($params['view'] == 'category') {
$editLink = 'option=com_categories&task=category.edit&id=' . $params['id'] . '&extension=' . $params['option'] . '&tmpl=component';
$task = 'category.apply';
//.........这里部分代码省略.........
示例11: getUrlVars
public function getUrlVars($url)
{
$router = JRouter::getInstance('site');
$origVars = $router->getVars();
$router->setVars(array(), false);
// DO NOT use JURI::getInstance! Re-routing on the same instance causes big issues
$juri = new JURI($url);
// Odd hack to prevent the parsing of the URL to redirect to the https version in certain circumstances
$jConfig = JFactory::getConfig();
$forceSSL = $jConfig->get('force_ssl');
$jConfig->set('force_ssl', 0);
$queryVars = $router->parse($juri);
$jConfig->set('force_ssl', $forceSSL);
// Reset the router back to it's original state
$router->setVars($origVars);
return $queryVars;
}
示例12: testGetInstanceException
/**
* Tests the getInstance() method throwing a proper exception
*
* @return void
*
* @since 3.4
* @expectedException RuntimeException
*/
public function testGetInstanceException()
{
// Check if a proper exception is thrown if there is no router class
$object = JRouter::getInstance('exception');
}
示例13: getDebugInformation
/**
* Generates parameter information for the debug mode
*
* @return string String with all needed information of the called page
*/
private function getDebugInformation()
{
$uri = JUri::getInstance();
$debug_output = '';
if (JFactory::getApplication()->isSite()) {
$debug_array = array_filter(JRouter::getInstance('site')->parse($uri));
} else {
$debug_output = str_replace('&', ',', $uri->getQuery());
if (empty($debug_output)) {
$debug_array['option'] = $this->request->getWord('option');
$debug_array['view'] = $this->request->getWord('view');
$debug_array['layout'] = $this->request->getWord('layout');
$debug_array = array_filter($debug_array);
}
}
if (!empty($debug_array)) {
$debug_output = array();
foreach ($debug_array as $key => $value) {
if (!empty($value)) {
$debug_output[] = $key . '=' . $value;
}
}
$debug_output = implode(',', $debug_output);
}
return $debug_output;
}
示例14: getRouter
/**
* Returns the application JRouter object.
*
* @param string $name The name of the application.
* @param array $options An optional associative array of configuration settings.
*
* @return JRouter
*
* @since 3.2
*/
public static function getRouter($name = null, array $options = array())
{
if (!isset($name)) {
$app = JFactory::getApplication();
$name = $app->getName();
}
return JRouter::getInstance($name, $options);
}
示例15: getRouter
/**
* Returns the application JRouter object.
*
* @param string $name The name of the application.
* @param array $options An optional associative array of configuration settings.
*
* @return JRouter
*
* @since 3.2
*/
public static function getRouter($name = null, array $options = array())
{
if (!isset($name)) {
$app = JFactory::getApplication();
$name = $app->getName();
}
try {
$router = JRouter::getInstance($name, $options);
} catch (Exception $e) {
return null;
}
return $router;
}