Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/application/helper.php

Documentation is available at helper.php

  1. <?php
  2. /**
  3. @version        $Id: application.php 5801 2006-11-18 16:28:10Z chrisdavenport $
  4. @package        Joomla.Framework
  5. @subpackage    Application
  6. @copyright    Copyright (C) 2005 - 2007 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. {
  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.      * @return    mixed    Object describing the client or false if not known
  35.      * @since    1.5
  36.      */
  37.     function getClientInfo($id null$byName false)
  38.     {
  39.         global $mainframe;
  40.  
  41.         static $clients;
  42.  
  43.         if(!isset($id)) {
  44.             $id $mainframe->getClientId();
  45.         }
  46.  
  47.         // Only create the array if it does not exist
  48.         if (!is_array($clients))
  49.         {
  50.             $obj new stdClass();
  51.  
  52.             // Site Client
  53.             $obj->id        0;
  54.             $obj->name    'site';
  55.             $obj->path    JPATH_SITE;
  56.             $clients[0clone($obj);
  57.  
  58.             // Administrator Client
  59.             $obj->id        1;
  60.             $obj->name    'administrator';
  61.             $obj->path    JPATH_ADMINISTRATOR;
  62.             $clients[1clone($obj);
  63.  
  64.             // Installation Client
  65.             $obj->id        2;
  66.             $obj->name    'installation';
  67.             $obj->path    JPATH_INSTALLATION;
  68.             $clients[2clone($obj);
  69.         }
  70.  
  71.         /*
  72.          * Are we looking for client information by id or by name?
  73.          */
  74.         if (!$byName)
  75.         {
  76.             if (!isset($clients[$id])){
  77.                 return false;
  78.             else {
  79.                 return $clients[$id];
  80.             }
  81.         }
  82.         else
  83.         {
  84.             foreach ($clients as $client{
  85.                 if ($client->name == strtolower($id)) {
  86.                     return $client;
  87.                 }
  88.             }
  89.             return false;
  90.         }
  91.     }
  92.  
  93.     /**
  94.     * Get a path
  95.     *
  96.     * @access public
  97.     * @param string $varname 
  98.     * @param string $user_option 
  99.     * @return string The requested path
  100.     * @since 1.0
  101.     */
  102.     function getPath$varname$user_option=null )
  103.     {
  104.         // check needed for handling of custom/new module xml file loading
  105.         $check ( ( $varname == 'mod0_xml' || $varname == 'mod1_xml' ) );
  106.  
  107.         if !$user_option && !$check {
  108.             $user_option JRequest::getVar('option'null);
  109.         }
  110.  
  111.         $result null;
  112.         $name     substr$user_option);
  113.  
  114.         switch ($varname{
  115.             case 'front':
  116.                 $result JApplicationHelper::_checkPathDS.'components'.DS$user_option .DS$name .'.php');
  117.                 break;
  118.  
  119.             case 'html':
  120.             case 'front_html':
  121.                 if !$result JApplicationHelper::_checkPathDS.'templates'.DSJApplication::getTemplate(.DS.'components'.DS$name .'.html.php') ) ) {
  122.                     $result JApplicationHelper::_checkPathDS.'components'.DS$user_option .DS$name .'.html.php');
  123.                 }
  124.                 break;
  125.  
  126.             case 'toolbar':
  127.                 $result JApplicationHelper::_checkPathDS.'components'.DS$user_option .DS.'toolbar.'$name .'.php'-);
  128.                 break;
  129.  
  130.             case 'toolbar_html':
  131.                 $result JApplicationHelper::_checkPathDS.'components'.DS$user_option .DS.'toolbar.'$name .'.html.php'-);
  132.                 break;
  133.  
  134.             case 'toolbar_default':
  135.             case 'toolbar_front':
  136.                 $result JApplicationHelper::_checkPathDS.'includes'.DS.'HTML_toolbar.php');
  137.                 break;
  138.  
  139.             case 'admin':
  140.                 $path     DS.'components'.DS$user_option .DS.'admin.'$name .'.php';
  141.                 $result JApplicationHelper::_checkPath$path-);
  142.                 break;
  143.  
  144.             case 'admin_html':
  145.                 $path    DS.'components'.DS$user_option .DS.'admin.'$name .'.html.php';
  146.                 $result JApplicationHelper::_checkPath$path-);
  147.                 break;
  148.  
  149.             case 'admin_functions':
  150.                 $path    DS.'components'.DS$user_option .DS$name .'.functions.php';
  151.                 $result JApplicationHelper::_checkPath$path-);
  152.                 break;
  153.  
  154.             case 'class':
  155.                 if !$result JApplicationHelper::_checkPathDS.'components'.DS$user_option .DS$name .'.class.php' ) ) ) {
  156.                     $result JApplicationHelper::_checkPathDS.'includes'.DS$name .'.php' );
  157.                 }
  158.                 break;
  159.  
  160.             case 'helper':
  161.                 $path    DS.'components'.DS$user_option .DS$name .'.helper.php';
  162.                 $result JApplicationHelper::_checkPath$path );
  163.                 break;
  164.  
  165.             case 'com_xml':
  166.                 $path     DS.'components'.DS$user_option .DS$name .'.xml';
  167.                 $result JApplicationHelper::_checkPath$path);
  168.                 break;
  169.  
  170.             case 'mod0_xml':
  171.                 $path DS.'modules'.DS$user_option .DS$user_option'.xml';
  172.                 $result JApplicationHelper::_checkPath$path );
  173.                 break;
  174.  
  175.             case 'mod1_xml':
  176.                 // admin modules
  177.                 $path DS.'modules'.DS$user_option .DS$user_option'.xml';
  178.                 $result JApplicationHelper::_checkPath$path-);
  179.                 break;
  180.  
  181.             case 'bot_xml':
  182.                 // legacy value
  183.             case 'plg_xml':
  184.                 // Site plugins
  185.                 $path     DS.'plugins'.DS$user_option .'.xml';
  186.                 $result JApplicationHelper::_checkPath$path);
  187.                 break;
  188.  
  189.             case 'menu_xml':
  190.                 $path     DS.'components'.DS.'com_menus'.DS$user_option .DS$user_option .'.xml';
  191.                 $result JApplicationHelper::_checkPath$path-);
  192.                 break;
  193.         }
  194.  
  195.         return $result;
  196.     }
  197.  
  198.     function parseXMLInstallFile($path)
  199.     {
  200.         // Read the file to see if it's a valid component XML file
  201.         $xml JFactory::getXMLParser('Simple');
  202.  
  203.         if (!$xml->loadFile($path)) {
  204.             unset($xml);
  205.             return false;
  206.         }
  207.  
  208.         /*
  209.          * Check for a valid XML root tag.
  210.          *
  211.          * Should be 'install', but for backward compatability we will accept 'mosinstall'.
  212.          */
  213.         if ($xml->document->name(!= 'install' && $xml->document->name(!= 'mosinstall'{
  214.             unset($xml);
  215.             return false;
  216.         }
  217.  
  218.         $data array();
  219.  
  220.         $element $xml->document->name[0];
  221.         $data['name'$element $element->data('';
  222.         $data['type'$element $xml->document->attributes("type"'';
  223.  
  224.         $element $xml->document->creationdate[0];
  225.         $data['creationdate'$element $element->data('Unknown';
  226.  
  227.         $element $xml->document->author[0];
  228.         $data['author'$element $element->data('Unknown';
  229.  
  230.         $element $xml->document->copyright[0];
  231.         $data['copyright'$element $element->data('';
  232.  
  233.         $element $xml->document->authoremail[0];
  234.         $data['authorEmail'$element $element->data('';
  235.  
  236.         $element $xml->document->authorurl[0];
  237.         $data['authorUrl'$element $element->data('';
  238.  
  239.         $element $xml->document->version[0];
  240.         $data['version'$element $element->data('';
  241.  
  242.         $element $xml->document->description[0];
  243.         $data['description'$element $element->data('';
  244.  
  245.         $element $xml->document->group[0];
  246.         $data['group'$element $element->data('';
  247.  
  248.         return $data;
  249.     }
  250.  
  251.     function parseXMLLangMetaFile($path)
  252.     {
  253.         // Read the file to see if it's a valid component XML file
  254.         $xml JFactory::getXMLParser('Simple');
  255.  
  256.         if (!$xml->loadFile($path)) {
  257.             unset($xml);
  258.             return false;
  259.         }
  260.  
  261.         /*
  262.          * Check for a valid XML root tag.
  263.          *
  264.          * Should be 'langMetaData'.
  265.          */
  266.         if ($xml->document->name(!= 'metafile'{
  267.             unset($xml);
  268.             return false;
  269.         }
  270.  
  271.         $data array();
  272.  
  273.         $element $xml->document->name[0];
  274.         $data['name'$element $element->data('';
  275.         $data['type'$element $xml->document->attributes("type"'';
  276.  
  277.         $element $xml->document->creationdate[0];
  278.         $data['creationdate'$element $element->data('Unknown';
  279.  
  280.         $element $xml->document->author[0];
  281.         $data['author'$element $element->data('Unknown';
  282.  
  283.         $element $xml->document->copyright[0];
  284.         $data['copyright'$element $element->data('';
  285.  
  286.         $element $xml->document->authoremail[0];
  287.         $data['authorEmail'$element $element->data('';
  288.  
  289.         $element $xml->document->authorurl[0];
  290.         $data['authorUrl'$element $element->data('';
  291.  
  292.         $element $xml->document->version[0];
  293.         $data['version'$element $element->data('';
  294.  
  295.         $element $xml->document->description[0];
  296.         $data['description'$element $element->data('';
  297.  
  298.         $element $xml->document->group[0];
  299.         $data['group'$element $element->group('';
  300.         return $data;
  301.     }
  302.  
  303.     /**
  304.      * Tries to find a file in the administrator or site areas
  305.      *
  306.      * @access private
  307.      * @param string     $parth            A file name
  308.      * @param integer     $checkAdmin        0 to check site only, 1 to check site and admin, -1 to check admin only
  309.      * @since 1.5
  310.      */
  311.     function _checkPath$path$checkAdmin=)
  312.     {
  313.         $file JPATH_SITE $path;
  314.         if ($checkAdmin > -&& file_exists$file )) {
  315.             return $file;
  316.         else if ($checkAdmin != 0{
  317.             $file JPATH_ADMINISTRATOR $path;
  318.             if (file_exists$file )) {
  319.                 return $file;
  320.             }
  321.         }
  322.  
  323.         return null;
  324.     }
  325.  
  326. }
  327. ?>

Documentation generated on Mon, 05 Mar 2007 21:05:57 +0000 by phpDocumentor 1.3.1