[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/libraries/joomla/ -> methods.php (source)

   1  <?php
   2  /**
   3  * @version        $Id: methods.php 14401 2010-01-26 14:10:00Z louis $
   4  * @package        Joomla.Framework
   5  * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   6  * @license        GNU/GPL, see LICENSE.php
   7  * Joomla! is free software. This version may have been modified pursuant
   8  * to the GNU General Public License, and as distributed it includes or
   9  * is derivative of works licensed under the GNU General Public License or
  10  * other free or open source software licenses.
  11  * See COPYRIGHT.php for copyright notices and details.
  12  */
  13  
  14  // Check to ensure this file is within the rest of the framework
  15  defined('JPATH_BASE') or die();
  16  
  17  /**
  18   * Route handling class
  19   *
  20   * @static
  21   * @package     Joomla.Framework
  22   * @since        1.5
  23   */
  24  class JRoute
  25  {
  26      /**
  27       * Translates an internal Joomla URL to a humanly readible URL.
  28       *
  29       * @access public
  30       * @param     string      $url     Absolute or Relative URI to Joomla resource
  31       * @param     boolean  $xhtml Replace & by &amp; for xml compilance
  32       * @param    int         $ssl    Secure state for the resolved URI
  33       *          1: Make URI secure using global secure site URI
  34       *          0: Leave URI in the same secure state as it was passed to the function
  35       *         -1: Make URI unsecure using the global unsecure site URI
  36       * @return The translated humanly readible URL
  37       */
  38      function _($url, $xhtml = true, $ssl = null)
  39      {
  40          // Get the router
  41          $app    = &JFactory::getApplication();
  42          $router = &$app->getRouter();
  43  
  44          // Make sure that we have our router
  45          if (! $router) {
  46              return null;
  47          }
  48  
  49          if ( (strpos($url, '&') !== 0 ) && (strpos($url, 'index.php') !== 0) ) {
  50              return $url;
  51           }
  52  
  53          // Build route
  54          $uri = &$router->build($url);
  55          $url = $uri->toString(array('path', 'query', 'fragment'));
  56  
  57          // Replace spaces
  58          $url = preg_replace('/\s/u', '%20', $url);
  59  
  60          /*
  61           * Get the secure/unsecure URLs.
  62  
  63           * If the first 5 characters of the BASE are 'https', then we are on an ssl connection over
  64           * https and need to set our secure URL to the current request URL, if not, and the scheme is
  65           * 'http', then we need to do a quick string manipulation to switch schemes.
  66           */
  67          $ssl    = (int) $ssl;
  68          if ( $ssl )
  69          {
  70              $uri             =& JURI::getInstance();
  71  
  72              // Get additional parts
  73              static $prefix;
  74              if ( ! $prefix ) {
  75                  $prefix = $uri->toString( array('host', 'port'));
  76                  //$prefix .= JURI::base(true);
  77              }
  78  
  79              // Determine which scheme we want
  80              $scheme    = ( $ssl === 1 ) ? 'https' : 'http';
  81  
  82              // Make sure our url path begins with a slash
  83              if ( ! preg_match('#^/#', $url) ) {
  84                  $url    = '/' . $url;
  85              }
  86  
  87              // Build the URL
  88              $url    = $scheme . '://' . $prefix . $url;
  89          }
  90  
  91          if($xhtml) {
  92              $url = str_replace( '&', '&amp;', $url );
  93          }
  94  
  95          return $url;
  96      }
  97  }
  98  
  99  /**
 100   * Text  handling class
 101   *
 102   * @static
 103   * @package     Joomla.Framework
 104   * @subpackage    Language
 105   * @since        1.5
 106   */
 107  class JText
 108  {
 109      /**
 110       * Translates a string into the current language
 111       *
 112       * @access    public
 113       * @param    string $string The string to translate
 114       * @param    boolean    $jsSafe        Make the result javascript safe
 115       * @since    1.5
 116       *
 117       */
 118      function _($string, $jsSafe = false)
 119      {
 120          $lang =& JFactory::getLanguage();
 121          return $lang->_($string, $jsSafe);
 122      }
 123  
 124      /**
 125       * Passes a string thru an sprintf
 126       *
 127       * @access    public
 128       * @param    format The format string
 129       * @param    mixed Mixed number of arguments for the sprintf function
 130       * @since    1.5
 131       */
 132  	function sprintf($string)
 133      {
 134          $lang =& JFactory::getLanguage();
 135          $args = func_get_args();
 136          if (count($args) > 0) {
 137              $args[0] = $lang->_($args[0]);
 138              return call_user_func_array('sprintf', $args);
 139          }
 140          return '';
 141      }
 142  
 143      /**
 144       * Passes a string thru an printf
 145       *
 146       * @access    public
 147       * @param    format The format string
 148       * @param    mixed Mixed number of arguments for the sprintf function
 149       * @since    1.5
 150       */
 151  	function printf($string)
 152      {
 153          $lang =& JFactory::getLanguage();
 154          $args = func_get_args();
 155          if (count($args) > 0) {
 156              $args[0] = $lang->_($args[0]);
 157              return call_user_func_array('printf', $args);
 158          }
 159          return '';
 160      }
 161  
 162  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1