Source for file helper.php

Documentation is available at helper.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Libraries
  4.  * @subpackage  Application
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Application helper functions
  14.  *
  15.  * @package     Joomla.Libraries
  16.  * @subpackage  Application
  17.  * @since       1.5
  18.  */
  19. {
  20.     /**
  21.      * Client information array
  22.      *
  23.      * @var    array 
  24.      * @since  1.6
  25.      */
  26.     protected static $_clients null;
  27.  
  28.     /**
  29.      * Return the name of the request component [main component]
  30.      *
  31.      * @param   string  $default  The default option
  32.      *
  33.      * @return  string  Option (e.g. com_something)
  34.      *
  35.      * @since   1.6
  36.      */
  37.     public static function getComponentName($default null)
  38.     {
  39.         static $option;
  40.  
  41.         if ($option)
  42.         {
  43.             return $option;
  44.         }
  45.  
  46.         $input JFactory::getApplication()->input;
  47.         $option strtolower($input->get('option'));
  48.  
  49.         if (empty($option))
  50.         {
  51.             $option $default;
  52.         }
  53.  
  54.         $input->set('option'$option);
  55.         return $option;
  56.     }
  57.  
  58.     /**
  59.      * Provides a secure hash based on a seed
  60.      *
  61.      * @param   string  $seed  Seed string.
  62.      *
  63.      * @return  string  A secure hash
  64.      *
  65.      * @since   3.2
  66.      */
  67.     public static function getHash($seed)
  68.     {
  69.         return md5(JFactory::getConfig()->get('secret'$seed);
  70.     }
  71.  
  72.     /**
  73.      * This method transliterates a string into an URL
  74.      * safe string or returns a URL safe UTF-8 string
  75.      * based on the global configuration
  76.      *
  77.      * @param   string  $string  String to process
  78.      *
  79.      * @return  string  Processed string
  80.      *
  81.      * @since   3.2
  82.      */
  83.     public static function stringURLSafe($string)
  84.     {
  85.         if (JFactory::getConfig()->get('unicodeslugs'== 1)
  86.         {
  87.             $output JFilterOutput::stringURLUnicodeSlug($string);
  88.         }
  89.         else
  90.         {
  91.             $output JFilterOutput::stringURLSafe($string);
  92.         }
  93.  
  94.         return $output;
  95.     }
  96.  
  97.     /**
  98.      * Gets information on a specific client id.  This method will be useful in
  99.      * future versions when we start mapping applications in the database.
  100.      *
  101.      * This method will return a client information array if called
  102.      * with no arguments which can be used to add custom application information.
  103.      *
  104.      * @param   integer  $id      A client identifier
  105.      * @param   boolean  $byName  If True, find the client by its name
  106.      *
  107.      * @return  mixed  Object describing the client or false if not known
  108.      *
  109.      * @since   1.5
  110.      */
  111.     public static function getClientInfo($id null$byName false)
  112.     {
  113.         // Only create the array if it does not exist
  114.         if (self::$_clients === null)
  115.         {
  116.             $obj new stdClass;
  117.  
  118.             // Site Client
  119.             $obj->id 0;
  120.             $obj->name 'site';
  121.             $obj->path JPATH_SITE;
  122.             self::$_clients[0clone $obj;
  123.  
  124.             // Administrator Client
  125.             $obj->id 1;
  126.             $obj->name 'administrator';
  127.             $obj->path JPATH_ADMINISTRATOR;
  128.             self::$_clients[1clone $obj;
  129.  
  130.             // Installation Client
  131.             $obj->id 2;
  132.             $obj->name 'installation';
  133.             $obj->path JPATH_INSTALLATION;
  134.             self::$_clients[2clone $obj;
  135.         }
  136.  
  137.         // If no client id has been passed return the whole array
  138.         if (is_null($id))
  139.         {
  140.             return self::$_clients;
  141.         }
  142.  
  143.         // Are we looking for client information by id or by name?
  144.         if (!$byName)
  145.         {
  146.             if (isset(self::$_clients[$id]))
  147.             {
  148.                 return self::$_clients[$id];
  149.             }
  150.         }
  151.         else
  152.         {
  153.             foreach (self::$_clients as $client)
  154.             {
  155.                 if ($client->name == strtolower($id))
  156.                 {
  157.                     return $client;
  158.                 }
  159.             }
  160.         }
  161.  
  162.         return null;
  163.     }
  164.  
  165.     /**
  166.      * Adds information for a client.
  167.      *
  168.      * @param   mixed  $client  A client identifier either an array or object
  169.      *
  170.      * @return  boolean  True if the information is added. False on error
  171.      *
  172.      * @since   1.6
  173.      */
  174.     public static function addClientInfo($client)
  175.     {
  176.         if (is_array($client))
  177.         {
  178.             $client = (object) $client;
  179.         }
  180.  
  181.         if (!is_object($client))
  182.         {
  183.             return false;
  184.         }
  185.  
  186.         $info self::getClientInfo();
  187.  
  188.         if (!isset($client->id))
  189.         {
  190.             $client->id count($info);
  191.         }
  192.  
  193.         self::$_clients[$client->idclone $client;
  194.  
  195.         return true;
  196.     }
  197.  
  198.     /**
  199.      * Parse a XML install manifest file.
  200.      *
  201.      * XML Root tag should be 'install' except for languages which use meta file.
  202.      *
  203.      * @param   string  $path  Full path to XML file.
  204.      *
  205.      * @return  array  XML metadata.
  206.      *
  207.      * @since       1.5
  208.      * @deprecated  4.0 Use JInstaller::parseXMLInstallFile instead.
  209.      */
  210.     public static function parseXMLInstallFile($path)
  211.     {
  212.         JLog::add('JApplicationHelper::parseXMLInstallFile is deprecated. Use JInstaller::parseXMLInstallFile instead.'JLog::WARNING'deprecated');
  213.         return JInstaller::parseXMLInstallFile($path);
  214.     }
  215.  
  216.     /**
  217.      * Parse a XML language meta file.
  218.      *
  219.      * XML Root tag  for languages which is meta file.
  220.      *
  221.      * @param   string  $path  Full path to XML file.
  222.      *
  223.      * @return  array  XML metadata.
  224.      *
  225.      * @since       1.5
  226.      * @deprecated  4.0 Use JInstaller::parseXMLInstallFile instead.
  227.      */
  228.     public static function parseXMLLangMetaFile($path)
  229.     {
  230.         JLog::add('JApplicationHelper::parseXMLLangMetaFile is deprecated. Use JInstaller::parseXMLInstallFile instead.'JLog::WARNING'deprecated');
  231.  
  232.         // Read the file to see if it's a valid component XML file
  233.         $xml simplexml_load_file($path);
  234.  
  235.         if (!$xml)
  236.         {
  237.             return false;
  238.         }
  239.  
  240.         /*
  241.          * Check for a valid XML root tag.
  242.          *
  243.          * Should be 'metafile'.
  244.          */
  245.         if ($xml->getName(!= 'metafile')
  246.         {
  247.             unset($xml);
  248.             return false;
  249.         }
  250.  
  251.         $data array();
  252.  
  253.         $data['name'= (string) $xml->name;
  254.         $data['type'$xml->attributes()->type;
  255.  
  256.         $data['creationDate'((string) $xml->creationDate? (string) $xml->creationDate JText::_('JLIB_UNKNOWN');
  257.         $data['author'((string) $xml->author? (string) $xml->author JText::_('JLIB_UNKNOWN');
  258.  
  259.         $data['copyright'= (string) $xml->copyright;
  260.         $data['authorEmail'= (string) $xml->authorEmail;
  261.         $data['authorUrl'= (string) $xml->authorUrl;
  262.         $data['version'= (string) $xml->version;
  263.         $data['description'= (string) $xml->description;
  264.         $data['group'= (string) $xml->group;
  265.  
  266.         return $data;
  267.     }
  268. }

Documentation generated on Tue, 19 Nov 2013 15:04:30 +0100 by phpDocumentor 1.4.3