[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/libraries/joomla/application/ -> helper.php (source)

   1  <?php
   2  /**
   3  * @version        $Id: helper.php 14401 2010-01-26 14:10:00Z louis $
   4  * @package        Joomla.Framework
   5  * @subpackage    Application
   6  * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   7  * @license        GNU/GPL, see LICENSE.php
   8  * Joomla! is free software. This version may have been modified pursuant
   9  * to the GNU General Public License, and as distributed it includes or
  10  * is derivative of works licensed under the GNU General Public License or
  11  * other free or open source software licenses.
  12  * See COPYRIGHT.php for copyright notices and details.
  13  */
  14  
  15  // Check to ensure this file is within the rest of the framework
  16  defined('JPATH_BASE') or die();
  17  
  18  /**
  19   * Application helper functions
  20   *
  21   * @static
  22   * @package        Joomla.Framework
  23   * @subpackage    Application
  24   * @since        1.5
  25   */
  26  class JApplicationHelper
  27  {
  28      /**
  29       * Gets information on a specific client id.  This method will be useful in
  30       * future versions when we start mapping applications in the database.
  31       *
  32       * @access    public
  33       * @param    int            $id        A client identifier
  34       * @param    boolean        $byName    If True, find the client by it's name
  35       * @return    mixed    Object describing the client or false if not known
  36       * @since    1.5
  37       */
  38      function &getClientInfo($id = null, $byName = false)
  39      {
  40          static $clients;
  41  
  42          // Only create the array if it does not exist
  43          if (!is_array($clients))
  44          {
  45              $obj = new stdClass();
  46  
  47              // Site Client
  48              $obj->id        = 0;
  49              $obj->name    = 'site';
  50              $obj->path    = JPATH_SITE;
  51              $clients[0] = clone($obj);
  52  
  53              // Administrator Client
  54              $obj->id        = 1;
  55              $obj->name    = 'administrator';
  56              $obj->path    = JPATH_ADMINISTRATOR;
  57              $clients[1] = clone($obj);
  58  
  59              // Installation Client
  60              $obj->id        = 2;
  61              $obj->name    = 'installation';
  62              $obj->path    = JPATH_INSTALLATION;
  63              $clients[2] = clone($obj);
  64  
  65              // XMLRPC Client
  66              $obj->id        = 3;
  67              $obj->name    = 'xmlrpc';
  68              $obj->path    = JPATH_XMLRPC;
  69              $clients[3] = clone($obj);
  70          }
  71  
  72          //If no client id has been passed return the whole array
  73          if(is_null($id)) {
  74              return $clients;
  75          }
  76  
  77          // Are we looking for client information by id or by name?
  78          if (!$byName)
  79          {
  80              if (isset($clients[$id])){
  81                  return $clients[$id];
  82              }
  83          }
  84          else
  85          {
  86              foreach ($clients as $client)
  87              {
  88                  if ($client->name == strtolower($id)) {
  89                      return $client;
  90                  }
  91              }
  92          }
  93          $null = null;
  94          return $null;
  95      }
  96  
  97      /**
  98      * Get a path
  99      *
 100      * @access public
 101      * @param string $varname
 102      * @param string $user_option
 103      * @return string The requested path
 104      * @since 1.0
 105      */
 106  	function getPath( $varname, $user_option=null )
 107      {
 108          // check needed for handling of custom/new module xml file loading
 109          $check = ( ( $varname == 'mod0_xml' ) || ( $varname == 'mod1_xml' ) );
 110  
 111          if ( !$user_option && !$check ) {
 112              $user_option = JRequest::getCmd('option');
 113          } else {
 114              $user_option = JFilterInput::clean($user_option, 'path');
 115          }
 116  
 117          $result = null;
 118          $name     = substr( $user_option, 4 );
 119  
 120          switch ($varname) {
 121              case 'front':
 122                  $result = JApplicationHelper::_checkPath( DS.'components'.DS. $user_option .DS. $name .'.php', 0 );
 123                  break;
 124  
 125              case 'html':
 126              case 'front_html':
 127                  if ( !( $result = JApplicationHelper::_checkPath( DS.'templates'.DS. JApplication::getTemplate() .DS.'components'.DS. $name .'.html.php', 0 ) ) ) {
 128                      $result = JApplicationHelper::_checkPath( DS.'components'.DS. $user_option .DS. $name .'.html.php', 0 );
 129                  }
 130                  break;
 131  
 132              case 'toolbar':
 133                  $result = JApplicationHelper::_checkPath( DS.'components'.DS. $user_option .DS.'toolbar.'. $name .'.php', -1 );
 134                  break;
 135  
 136              case 'toolbar_html':
 137                  $result = JApplicationHelper::_checkPath( DS.'components'.DS. $user_option .DS.'toolbar.'. $name .'.html.php', -1 );
 138                  break;
 139  
 140              case 'toolbar_default':
 141              case 'toolbar_front':
 142                  $result = JApplicationHelper::_checkPath( DS.'includes'.DS.'HTML_toolbar.php', 0 );
 143                  break;
 144  
 145              case 'admin':
 146                  $path     = DS.'components'.DS. $user_option .DS.'admin.'. $name .'.php';
 147                  $result = JApplicationHelper::_checkPath( $path, -1 );
 148                  if ($result == null) {
 149                      $path = DS.'components'.DS. $user_option .DS. $name .'.php';
 150                      $result = JApplicationHelper::_checkPath( $path, -1 );
 151                  }
 152                  break;
 153  
 154              case 'admin_html':
 155                  $path    = DS.'components'.DS. $user_option .DS.'admin.'. $name .'.html.php';
 156                  $result = JApplicationHelper::_checkPath( $path, -1 );
 157                  break;
 158  
 159              case 'admin_functions':
 160                  $path    = DS.'components'.DS. $user_option .DS. $name .'.functions.php';
 161                  $result = JApplicationHelper::_checkPath( $path, -1 );
 162                  break;
 163  
 164              case 'class':
 165                  if ( !( $result = JApplicationHelper::_checkPath( DS.'components'.DS. $user_option .DS. $name .'.class.php' ) ) ) {
 166                      $result = JApplicationHelper::_checkPath( DS.'includes'.DS. $name .'.php' );
 167                  }
 168                  break;
 169  
 170              case 'helper':
 171                  $path    = DS.'components'.DS. $user_option .DS. $name .'.helper.php';
 172                  $result = JApplicationHelper::_checkPath( $path );
 173                  break;
 174  
 175              case 'com_xml':
 176                  $path     = DS.'components'.DS. $user_option .DS. $name .'.xml';
 177                  $result = JApplicationHelper::_checkPath( $path, 1 );
 178                  break;
 179  
 180              case 'mod0_xml':
 181                  $path = DS.'modules'.DS. $user_option .DS. $user_option. '.xml';
 182                  $result = JApplicationHelper::_checkPath( $path );
 183                  break;
 184  
 185              case 'mod1_xml':
 186                  // admin modules
 187                  $path = DS.'modules'.DS. $user_option .DS. $user_option. '.xml';
 188                  $result = JApplicationHelper::_checkPath( $path, -1 );
 189                  break;
 190  
 191              case 'bot_xml':
 192                  // legacy value
 193              case 'plg_xml':
 194                  // Site plugins
 195                  $path     = DS.'plugins'.DS. $user_option .'.xml';
 196                  $result = JApplicationHelper::_checkPath( $path, 0 );
 197                  break;
 198  
 199              case 'menu_xml':
 200                  $path     = DS.'components'.DS.'com_menus'.DS. $user_option .DS. $user_option .'.xml';
 201                  $result = JApplicationHelper::_checkPath( $path, -1 );
 202                  break;
 203          }
 204  
 205          return $result;
 206      }
 207  
 208  	function parseXMLInstallFile($path)
 209      {
 210          // Read the file to see if it's a valid component XML file
 211          $xml = & JFactory::getXMLParser('Simple');
 212  
 213          if (!$xml->loadFile($path)) {
 214              unset($xml);
 215              return false;
 216          }
 217  
 218          /*
 219           * Check for a valid XML root tag.
 220           *
 221           * Should be 'install', but for backward compatability we will accept 'mosinstall'.
 222           */
 223          if ( !is_object($xml->document) || ($xml->document->name() != 'install' && $xml->document->name() != 'mosinstall')) {
 224              unset($xml);
 225              return false;
 226          }
 227  
 228          $data = array();
 229          $data['legacy'] = $xml->document->name() == 'mosinstall';
 230  
 231          $element = & $xml->document->name[0];
 232          $data['name'] = $element ? $element->data() : '';
 233          $data['type'] = $element ? $xml->document->attributes("type") : '';
 234  
 235          $element = & $xml->document->creationDate[0];
 236          $data['creationdate'] = $element ? $element->data() : JText::_('Unknown');
 237  
 238          $element = & $xml->document->author[0];
 239          $data['author'] = $element ? $element->data() : JText::_('Unknown');
 240  
 241          $element = & $xml->document->copyright[0];
 242          $data['copyright'] = $element ? $element->data() : '';
 243  
 244          $element = & $xml->document->authorEmail[0];
 245          $data['authorEmail'] = $element ? $element->data() : '';
 246  
 247          $element = & $xml->document->authorUrl[0];
 248          $data['authorUrl'] = $element ? $element->data() : '';
 249  
 250          $element = & $xml->document->version[0];
 251          $data['version'] = $element ? $element->data() : '';
 252  
 253          $element = & $xml->document->description[0];
 254          $data['description'] = $element ? $element->data() : '';
 255  
 256          $element = & $xml->document->group[0];
 257          $data['group'] = $element ? $element->data() : '';
 258  
 259          return $data;
 260      }
 261  
 262  	function parseXMLLangMetaFile($path)
 263      {
 264          // Read the file to see if it's a valid component XML file
 265          $xml = & JFactory::getXMLParser('Simple');
 266  
 267          if (!$xml->loadFile($path)) {
 268              unset($xml);
 269              return false;
 270          }
 271  
 272          /*
 273           * Check for a valid XML root tag.
 274           *
 275           * Should be 'langMetaData'.
 276           */
 277          if ($xml->document->name() != 'metafile') {
 278              unset($xml);
 279              return false;
 280          }
 281  
 282          $data = array();
 283  
 284          $element = & $xml->document->name[0];
 285          $data['name'] = $element ? $element->data() : '';
 286          $data['type'] = $element ? $xml->document->attributes("type") : '';
 287  
 288          $element = & $xml->document->creationDate[0];
 289          $data['creationdate'] = $element ? $element->data() : JText::_('Unknown');
 290  
 291          $element = & $xml->document->author[0];
 292  
 293          $data['author'] = $element ? $element->data() : JText::_('Unknown');
 294  
 295          $element = & $xml->document->copyright[0];
 296          $data['copyright'] = $element ? $element->data() : '';
 297  
 298          $element = & $xml->document->authorEmail[0];
 299          $data['authorEmail'] = $element ? $element->data() : '';
 300  
 301          $element = & $xml->document->authorUrl[0];
 302          $data['authorUrl'] = $element ? $element->data() : '';
 303  
 304          $element = & $xml->document->version[0];
 305          $data['version'] = $element ? $element->data() : '';
 306  
 307          $element = & $xml->document->description[0];
 308          $data['description'] = $element ? $element->data() : '';
 309  
 310          $element = & $xml->document->group[0];
 311          $data['group'] = $element ? $element->group() : '';
 312          return $data;
 313      }
 314  
 315      /**
 316       * Tries to find a file in the administrator or site areas
 317       *
 318       * @access private
 319       * @param string     $parth            A file name
 320       * @param integer     $checkAdmin        0 to check site only, 1 to check site and admin, -1 to check admin only
 321       * @since 1.5
 322       */
 323  	function _checkPath( $path, $checkAdmin=1 )
 324      {
 325          $file = JPATH_SITE . $path;
 326          if ($checkAdmin > -1 && file_exists( $file )) {
 327              return $file;
 328          } else if ($checkAdmin != 0) {
 329              $file = JPATH_ADMINISTRATOR . $path;
 330              if (file_exists( $file )) {
 331                  return $file;
 332              }
 333          }
 334  
 335          return null;
 336      }
 337  }


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