Exemple #1
0
 public static function _($url, $xhtml = true, $ssl = null)
 {
     $app = MFactory::getApplication();
     $router = $app->getRouter();
     if (!$router) {
         return null;
     }
     if (strpos($url, '&') !== 0 && strpos($url, 'index.php') !== 0) {
         return $url;
     }
     $uri = $router->build($url);
     $url = $uri->toString(array('path', 'query', 'fragment'));
     $url = preg_replace('/\\s/u', '%20', $url);
     if ((int) $ssl) {
         $uri = MUri::getInstance();
         static $prefix;
         if (!$prefix) {
             $prefix = $uri->toString(array('host', 'port'));
         }
         $scheme = (int) $ssl === 1 ? 'https' : 'http';
         if (!preg_match('#^/#', $url)) {
             $url = '/' . $url;
         }
         $url = $scheme . '://' . $prefix . $url;
     }
     if ($xhtml) {
         $url = htmlspecialchars($url);
     }
     return $url;
 }
Exemple #2
0
 public static function getUri($uri = 'SERVER')
 {
     mimport('framework.environment.uri');
     return MUri::getInstance($uri);
 }
Exemple #3
0
 public function redirect($url, $msg = '', $msgType = 'message', $moved = false)
 {
     // Check for relative internal links.
     if (preg_match('#^index2?\\.php#', $url)) {
         $url = MUri::base() . $url;
     }
     // Strip out any line breaks.
     $url = preg_split("/[\r\n]/", $url);
     $url = $url[0];
     // If we don't start with a http we need to fix this before we proceed.
     // We could validly start with something else (e.g. ftp), though this would
     // be unlikely and isn't supported by this API.
     if (!preg_match('#^http#i', $url)) {
         $uri = MUri::getInstance();
         $prefix = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
         if ($url[0] == '/') {
             // We just need the prefix since we have a path relative to the root.
             $url = $prefix . $url;
         } else {
             // It's relative to where we are now, so lets add that.
             $parts = explode('/', $uri->toString(array('path')));
             array_pop($parts);
             $path = implode('/', $parts) . '/';
             $url = $prefix . $path . $url;
         }
     }
     // If the message exists, enqueue it.
     if (trim($msg)) {
         $this->enqueueMessage($msg, $msgType);
     }
     // Persist messages if they exist.
     if (count($this->_messageQueue)) {
         $session = MFactory::getSession();
         $session->set('application.queue', $this->_messageQueue);
     }
     // WP redirect
     if ($this->isAdmin()) {
         $option = str_replace('com_', '', MRequest::getCmd('option'));
         $url = str_replace('index.php?', 'admin.php?page=' . $option . '&', $url);
     }
     // If the headers have been sent, then we cannot send an additional location header
     // so we will output a javascript redirect statement.
     if (headers_sent()) {
         echo "<script>document.location.href='" . str_replace("'", "&apos;", $url) . "';</script>\n";
     } else {
         mimport('phputf8.utils.ascii');
         mimport('framework.environment.browser');
         $document = MFactory::getDocument();
         $navigator = MBrowser::getInstance();
         if ($navigator->isBrowser('msie') && !utf8_is_ascii($url)) {
             // MSIE type browser and/or server cause issues when url contains utf8 character,so use a javascript redirect method
             echo '<html><head><meta http-equiv="content-type" content="text/html; charset=' . $document->getCharset() . '" />' . '<script>document.location.href=\'' . str_replace("'", "&apos;", $url) . '\';</script></head></html>';
         } elseif (!$moved and $navigator->isBrowser('konqueror')) {
             // WebKit browser (identified as konqueror by Joomla!) - Do not use 303, as it causes subresources
             // reload (https://bugs.webkit.org/show_bug.cgi?id=38690)
             echo '<html><head><meta http-equiv="content-type" content="text/html; charset=' . $document->getCharset() . '" />' . '<meta http-equiv="refresh" content="0; url=' . str_replace("'", "&apos;", $url) . '" /></head></html>';
         } else {
             // All other browsers, use the more efficient HTTP header method
             header($moved ? 'HTTP/1.1 301 Moved Permanently' : 'HTTP/1.1 303 See other');
             header('Location: ' . $url);
             header('Content-Type: text/html; charset=' . $document->getCharset());
         }
     }
     $this->close();
 }
Exemple #4
0
 protected function _buildRawRoute(&$uri)
 {
     $app = MFactory::getApplication();
     $option = str_replace('com_', '', $uri->getVar('option'));
     if (!$app->isAdmin()) {
         $option_get = str_replace('com_', '', MRequest::getWord('option', ''));
         if ($option == $option_get) {
             $page_id = MRequest::getInt('page_id');
         } else {
             $page_id = null;
         }
         if (empty($page_id) and !empty($option)) {
             $page_id = MFactory::getWOption($option . '_page_id');
         }
         if (!empty($page_id)) {
             $uri->setVar('page_id', $page_id);
         }
     } else {
         $format = $uri->getVar('format');
         $url = $uri->get('_uri');
         if ($format == 'raw') {
             $url = str_replace('index.php?', MURL_ADMIN . '/admin-ajax.php?client=admin&action=' . $option . '&page=' . $option . '&', $url);
         } else {
             if ($option == 'config') {
                 $page = str_replace('com_', '', $uri->getVar('component'));
                 $url = 'admin.php?page=' . $page . '&option=com_' . $page . '&view=config';
             } else {
                 $url = str_replace('index.php?', 'admin.php?page=' . $option . '&', $url);
             }
         }
         $uri = MUri::getInstance($url);
     }
 }