Source for file help.php

Documentation is available at help.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Libraries
  4.  * @subpackage  Help
  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.  * Help system class
  14.  *
  15.  * @package     Joomla.Libraries
  16.  * @subpackage  Help
  17.  * @since       1.5
  18.  */
  19. class JHelp
  20. {
  21.     /**
  22.      * Create a URL for a given help key reference
  23.      *
  24.      * @param   string   $ref           The name of the help screen (its key reference)
  25.      * @param   boolean  $useComponent  Use the help file in the component directory
  26.      * @param   string   $override      Use this URL instead of any other
  27.      * @param   string   $component     Name of component (or null for current component)
  28.      *
  29.      * @return  string 
  30.      *
  31.      * @since   1.5
  32.      */
  33.     public static function createURL($ref$useComponent false$override null$component null)
  34.     {
  35.         $local false;
  36.         $app JFactory::getApplication();
  37.  
  38.         if (is_null($component))
  39.         {
  40.             $component JApplicationHelper::getComponentName();
  41.         }
  42.  
  43.         //  Determine the location of the help file.  At this stage the URL
  44.         //  can contain substitution codes that will be replaced later.
  45.  
  46.         if ($override)
  47.         {
  48.             $url $override;
  49.         }
  50.         else
  51.         {
  52.             // Get the user help URL.
  53.             $user JFactory::getUser();
  54.             $url $user->getParam('helpsite');
  55.  
  56.             // If user hasn't specified a help URL, then get the global one.
  57.             if ($url == '')
  58.             {
  59.                 $url $app->getCfg('helpurl');
  60.             }
  61.  
  62.             // Component help URL overrides user and global.
  63.             if ($useComponent)
  64.             {
  65.                 // Look for help URL in component parameters.
  66.                 $params JComponentHelper::getParams($component);
  67.                 $url $params->get('helpURL');
  68.  
  69.                 if ($url == '')
  70.                 {
  71.                     $local true;
  72.                     $url 'components/{component}/help/{language}/{keyref}';
  73.                 }
  74.             }
  75.  
  76.             // Set up a local help URL.
  77.             if (!$url)
  78.             {
  79.                 $local true;
  80.                 $url 'help/{language}/{keyref}';
  81.             }
  82.         }
  83.  
  84.         // If the URL is local then make sure we have a valid file extension on the URL.
  85.         if ($local)
  86.         {
  87.             if (!preg_match('#\.html$|\.xml$#i'$ref))
  88.             {
  89.                 $url .= '.html';
  90.             }
  91.         }
  92.  
  93.         /*
  94.          *  Replace substitution codes in the URL.
  95.          */
  96.         $lang JFactory::getLanguage();
  97.         $version new JVersion;
  98.         $jver explode('.'$version->getShortVersion());
  99.         $jlang explode('-'$lang->getTag());
  100.  
  101.         $debug $lang->setDebug(false);
  102.         $keyref JText::_($ref);
  103.         $lang->setDebug($debug);
  104.  
  105.         // Replace substitution codes in help URL.
  106.         $search array(
  107.             // Application name (eg. 'Administrator')
  108.             '{app}',
  109.             // Component name (eg. 'com_content')
  110.             '{component}',
  111.             // Help screen key reference
  112.             '{keyref}',
  113.             // Full language code (eg. 'en-GB')
  114.             '{language}',
  115.             // Short language code (eg. 'en')
  116.             '{langcode}',
  117.             // Region code (eg. 'GB')
  118.             '{langregion}',
  119.             // Joomla major version number
  120.             '{major}',
  121.             // Joomla minor version number
  122.             '{minor}',
  123.             // Joomla maintenance version number
  124.             '{maintenance}'
  125.         );
  126.  
  127.         $replace array(
  128.             // {app}
  129.             $app->getName(),
  130.             // {component}
  131.             $component,
  132.             // {keyref}
  133.             $keyref,
  134.             // {language}
  135.             $lang->getTag(),
  136.             // {langcode}
  137.             $jlang[0],
  138.             // {langregion}
  139.             $jlang[1],
  140.             // {major}
  141.             $jver[0],
  142.             // {minor}
  143.             $jver[1],
  144.             // {maintenance}
  145.             $jver[2]
  146.         );
  147.  
  148.         // If the help file is local then check it exists.
  149.         // If it doesn't then fallback to English.
  150.         if ($local)
  151.         {
  152.             $try str_replace($search$replace$url);
  153.  
  154.             if (!is_file(JPATH_BASE '/' $try))
  155.             {
  156.                 $replace[3'en-GB';
  157.                 $replace[4'en';
  158.                 $replace[5'GB';
  159.             }
  160.         }
  161.  
  162.         $url str_replace($search$replace$url);
  163.  
  164.         return $url;
  165.     }
  166.  
  167.     /**
  168.      * Builds a list of the help sites which can be used in a select option.
  169.      *
  170.      * @param   string  $pathToXml  Path to an XML file.
  171.      *
  172.      * @return  array  An array of arrays (text, value, selected).
  173.      *
  174.      * @since   1.5
  175.      */
  176.     public static function createSiteList($pathToXml)
  177.     {
  178.         $list array();
  179.         $xml false;
  180.  
  181.         if (!empty($pathToXml))
  182.         {
  183.             $xml simplexml_load_file($pathToXml);
  184.         }
  185.  
  186.         if (!$xml)
  187.         {
  188.             $option['text''English (GB) help.joomla.org';
  189.             $option['value''http://help.joomla.org';
  190.             $list[$option;
  191.         }
  192.         else
  193.         {
  194.             $option array();
  195.  
  196.             foreach ($xml->sites->site as $site)
  197.             {
  198.                 $option['text'= (string) $site;
  199.                 $option['value'= (string) $site->attributes()->url;
  200.  
  201.                 $list[$option;
  202.             }
  203.         }
  204.  
  205.         return $list;
  206.     }
  207. }

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