本文整理汇总了PHP中Uri::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Uri::getInstance方法的具体用法?PHP Uri::getInstance怎么用?PHP Uri::getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Uri
的用法示例。
在下文中一共展示了Uri::getInstance方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseUrl
/**
* Parse url and reroute with routes.xml rules if found
*
* @return Uri Return the instance of Uri (rerouted or not)
*/
public function parseUrl()
{
// Get new instance of Uri
$uriInst = Uri::getInstance();
// Remove first / from uri
$uri = trim($uriInst->getUri(false), '/');
// Init vars
$defaultRedirect = null;
// Parse routes
foreach ($this->_routes as $route) {
// Converts shortcuts to regexp
$rule = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $route->attributes()->rule));
// Rule match to uri
if (preg_match('#^' . $rule . '$#', $uri)) {
// Is there any back reference
if (strpos($route->attributes()->redirect, '$') !== false && strpos($rule, '(') !== false) {
$uri = preg_replace('#^' . $rule . '$#', $route->attributes()->redirect, $uri);
} else {
$uri = $route->attributes()->redirect;
}
// Define rerouted uri to current instance of Uri
return $uriInst->setUri($uri);
}
if ($rule === 'default') {
$defaultRedirect = (string) $route->attributes()->redirect . '/' . $uri;
}
}
if (!$uriInst->isDefined() && $defaultRedirect !== null) {
$uriInst->setUri($defaultRedirect);
}
return $uriInst;
}
示例2: redirect
public function redirect($location, $statusCode = 302)
{
if (substr($location, 0, 4) != 'http') {
$location = Uri::getInstance()->location(ltrim($location, '/'));
}
self::$statusText = 'Location: ' . $location;
self::$statusCode = $statusCode;
return '<html><head><meta http-equiv="refresh" content="0; url=' . $location . '" /></head><body></body></html>';
}
示例3: _getActionClassName
/**
* Get action class name from called action and module
*
* @return void
*/
private function _getActionClassName()
{
if ($this->_module !== null) {
// Action is not defined,
if ($this->_action === null) {
$this->_action = self::DEFAULT_MODULE_ACTION;
}
// Build class Name
$className = 'm_' . $this->_module . '_action_' . $this->_action;
// Check if class exists
if (!class_exists($className)) {
throw new RuntimeException('Class ' . $className . ' not found !', E_USER_ERROR);
}
// Check if default action method exists
if (!method_exists($className, self::DEFAULT_ACTION_METHOD)) {
trigger_error('Method ' . self::DEFAULT_ACTION_METHOD . ' not found in ' . $className, E_USER_ERROR);
}
// Add args to default method
if ($this->_args === null) {
$this->_args = Uri::getInstance()->segmentsSlice(2);
}
// Set class name
$this->_className = $className;
// Instanciate action class
$this->_classInstance = new $this->_className();
}
}
示例4: partialView
function partialView($filename)
{
$this->page_active = strtolower(get_class($this));
$this->menuHelper = MenuHelper::getInstance();
$pages = $this->menuHelper->getNavBar($this->page_active, $this->sub_menu_active);
$addmarging = strcmp(get_class($this), "Accueil") === 0 ? "margin-0" : "margin_bottom40";
if (!empty($this->vars)) {
foreach ($this->vars as $key => $value) {
$this->tpl->assign($key, $value);
}
}
$uri = Uri::getInstance()->getFragment();
$home = "";
if (isset($uri[0])) {
$home = $uri[0];
unset($uri[0]);
}
$this->displayTpl($filename);
}
示例5: refresh
/**
* This function will refresh the current page. Useful for forms but beware on loops.
*/
function refresh()
{
$url = Uri::getInstance()->getHost(true) . $_SERVER['REQUEST_URI'];
redirect($url);
}
示例6: render
/**
* Render the feed.
*
* @param string $name The name of the element to render
* @param array $params Array of values
* @param string $content Override the output of the renderer
*
* @return string The output of the script
*
* @see JDocumentRenderer::render()
* @since 11.1
*/
public function render($name = '', $params = null, $content = null)
{
$app = Factory::getApplication();
// Gets and sets timezone offset from site configuration
$tz = new DateTimeZone($app->getCfg('offset'));
$now = Factory::getDate();
$now->setTimeZone($tz);
$data = $this->_doc;
$uri = Uri::getInstance();
$url = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
$syndicationURL = Route::_('&format=feed&type=atom');
if ($app->getCfg('sitename_pagetitles', 0) == 1) {
$title = Text::sprintf('JPAGETITLE', $app->getCfg('sitename'), $data->title);
} elseif ($app->getCfg('sitename_pagetitles', 0) == 2) {
$title = Text::sprintf('JPAGETITLE', $data->title, $app->getCfg('sitename'));
} else {
$title = $data->title;
}
$feed_title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8');
$feed = "<feed xmlns=\"http://www.w3.org/2005/Atom\" ";
if ($data->language != "") {
$feed .= " xml:lang=\"" . $data->language . "\"";
}
$feed .= ">\n";
$feed .= "\t<title type=\"text\">" . $feed_title . "</title>\n";
$feed .= "\t<subtitle type=\"text\">" . htmlspecialchars($data->description, ENT_COMPAT, 'UTF-8') . "</subtitle>\n";
if (empty($data->category) === false) {
if (is_array($data->category)) {
foreach ($data->category as $cat) {
$feed .= "\t<category term=\"" . htmlspecialchars($cat, ENT_COMPAT, 'UTF-8') . "\" />\n";
}
} else {
$feed .= "\t<category term=\"" . htmlspecialchars($data->category, ENT_COMPAT, 'UTF-8') . "\" />\n";
}
}
$feed .= "\t<link rel=\"alternate\" type=\"text/html\" href=\"" . $url . "\"/>\n";
$feed .= "\t<id>" . str_replace(' ', '%20', $data->getBase()) . "</id>\n";
$feed .= "\t<updated>" . htmlspecialchars($now->toISO8601(true), ENT_COMPAT, 'UTF-8') . "</updated>\n";
if ($data->editor != "") {
$feed .= "\t<author>\n";
$feed .= "\t\t<name>" . $data->editor . "</name>\n";
if ($data->editorEmail != "") {
$feed .= "\t\t<email>" . htmlspecialchars($data->editorEmail, ENT_COMPAT, 'UTF-8') . "</email>\n";
}
$feed .= "\t</author>\n";
}
$feed .= "\t<generator uri=\"http://joomla.org\" version=\"1.6\">" . $data->getGenerator() . "</generator>\n";
$feed .= ' <link rel="self" type="application/atom+xml" href="' . str_replace(' ', '%20', $url . $syndicationURL) . "\"/>\n";
for ($i = 0, $count = count($data->items); $i < $count; $i++) {
$feed .= "\t<entry>\n";
$feed .= "\t\t<title>" . htmlspecialchars(strip_tags($data->items[$i]->title), ENT_COMPAT, 'UTF-8') . "</title>\n";
$feed .= ' <link rel="alternate" type="text/html" href="' . $url . $data->items[$i]->link . "\"/>\n";
if ($data->items[$i]->date == "") {
$data->items[$i]->date = $now->toUnix();
}
$itemDate = Factory::getDate($data->items[$i]->date);
$itemDate->setTimeZone($tz);
$feed .= "\t\t<published>" . htmlspecialchars($itemDate->toISO8601(true), ENT_COMPAT, 'UTF-8') . "</published>\n";
$feed .= "\t\t<updated>" . htmlspecialchars($itemDate->toISO8601(true), ENT_COMPAT, 'UTF-8') . "</updated>\n";
if (empty($data->items[$i]->guid) === true) {
$feed .= "\t\t<id>" . str_replace(' ', '%20', $url . $data->items[$i]->link) . "</id>\n";
} else {
$feed .= "\t\t<id>" . htmlspecialchars($data->items[$i]->guid, ENT_COMPAT, 'UTF-8') . "</id>\n";
}
if ($data->items[$i]->author != "") {
$feed .= "\t\t<author>\n";
$feed .= "\t\t\t<name>" . htmlspecialchars($data->items[$i]->author, ENT_COMPAT, 'UTF-8') . "</name>\n";
if ($data->items[$i]->authorEmail != "") {
$feed .= "\t\t\t<email>" . htmlspecialchars($data->items[$i]->authorEmail, ENT_COMPAT, 'UTF-8') . "</email>\n";
}
$feed .= "\t\t</author>\n";
}
if ($data->items[$i]->description != "") {
$feed .= "\t\t<summary type=\"html\">" . htmlspecialchars($data->items[$i]->description, ENT_COMPAT, 'UTF-8') . "</summary>\n";
$feed .= "\t\t<content type=\"html\">" . htmlspecialchars($data->items[$i]->description, ENT_COMPAT, 'UTF-8') . "</content>\n";
}
if (empty($data->items[$i]->category) === false) {
if (is_array($data->items[$i]->category)) {
foreach ($data->items[$i]->category as $cat) {
$feed .= "\t\t<category term=\"" . htmlspecialchars($cat, ENT_COMPAT, 'UTF-8') . "\" />\n";
}
} else {
$feed .= "\t\t<category term=\"" . htmlspecialchars($data->items[$i]->category, ENT_COMPAT, 'UTF-8') . "\" />\n";
}
}
if ($data->items[$i]->enclosure != null) {
$feed .= "\t\t<link rel=\"enclosure\" href=\"" . $data->items[$i]->enclosure->url . "\" type=\"" . $data->items[$i]->enclosure->type . "\" length=\"" . $data->items[$i]->enclosure->length . "\" />\n";
}
//.........这里部分代码省略.........
示例7: showConfigurationError
/**
* Stop script and show a configuration error page
*
* @return void
*/
public static function showConfigurationError()
{
while (ob_get_level()) {
ob_end_clean();
}
set_header(404);
$uri = Uri::getInstance()->getUri(false);
$tpl = Template::getInstance();
$tpl->setTemplateDir(HOOKS_DIR . DS . 'errors');
$tpl->addTemplateDir(FW_DIR . DS . 'errors');
$tpl->assign('uri', $uri);
$tpl->assign('routeFilePath', trim(CACHE_DIR . DS . 'routes.xml'));
$tpl->assign('tests', self::environmentTests());
try {
$tpl->setTemplate('configuration.html')->render();
} catch (Exception $exc) {
echo $exc->getMessage();
}
die;
}
示例8: filterField
/**
* Method to apply an input filter to a value based on field data.
*
* @param string $element The XML element object representation of the form field.
* @param mixed $value The value to filter for the field.
*
* @return mixed The filtered value.
*
* @since 11.1
*/
protected function filterField($element, $value)
{
// Make sure there is a valid SimpleXMLElement.
if (!$element instanceof SimpleXMLElement) {
return false;
}
// Get the field filter type.
$filter = (string) $element['filter'];
// Process the input value based on the filter.
$return = null;
switch (strtoupper($filter)) {
// Access Control Rules.
case 'RULES':
$return = array();
foreach ((array) $value as $action => $ids) {
// Build the rules array.
$return[$action] = array();
foreach ($ids as $id => $p) {
if ($p !== '') {
$return[$action][$id] = $p == '1' || $p == 'true' ? true : false;
}
}
}
break;
// Do nothing, thus leaving the return value as null.
// Do nothing, thus leaving the return value as null.
case 'UNSET':
break;
// No Filter.
// No Filter.
case 'RAW':
$return = $value;
break;
// Filter the input as an array of integers.
// Filter the input as an array of integers.
case 'INT_ARRAY':
// Make sure the input is an array.
if (is_object($value)) {
$value = get_object_vars($value);
}
$value = is_array($value) ? $value : array($value);
ArrayHelper::toInteger($value);
$return = $value;
break;
// Filter safe HTML.
// Filter safe HTML.
case 'SAFEHTML':
$return = Input::getInstance(null, null, 1, 1)->clean($value, 'string');
break;
// Convert a date to UTC based on the server timezone offset.
// Convert a date to UTC based on the server timezone offset.
case 'SERVER_UTC':
if ((int) $value > 0) {
// Get the server timezone setting.
$offset = Factory::getConfig()->get('offset');
// Return an SQL formatted datetime string in UTC.
$return = Factory::getDate($value, $offset)->toSql();
} else {
$return = '';
}
break;
// Convert a date to UTC based on the user timezone offset.
// Convert a date to UTC based on the user timezone offset.
case 'USER_UTC':
if ((int) $value > 0) {
// Get the user timezone setting defaulting to the server timezone setting.
$offset = Factory::getUser()->getParam('timezone', Factory::getConfig()->get('offset'));
// Return a MySQL formatted datetime string in UTC.
$return = Factory::getDate($value, $offset)->toSql();
} else {
$return = '';
}
break;
// Ensures a protocol is present in the saved field. Only use when
// the only permitted protocols requre '://'. See JFormRuleUrl for list of these.
// Ensures a protocol is present in the saved field. Only use when
// the only permitted protocols requre '://'. See JFormRuleUrl for list of these.
case 'URL':
if (empty($value)) {
return;
}
$value = Input::getInstance()->clean($value, 'html');
$value = trim($value);
// Check for a protocol
$protocol = parse_url($value, PHP_URL_SCHEME);
// If there is no protocol and the relative option is not specified,
// we assume that it is an external URL and prepend http://.
if ($element['type'] == 'url' && !$protocol && !$element['relative'] || !$element['type'] == 'url' && !$protocol) {
$protocol = 'http';
// If it looks like an internal link, then add the root.
//.........这里部分代码省略.........