Source for file modules.php

Documentation is available at modules.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_modules
  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.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * Modules component helper.
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_modules
  17.  * @since       1.6
  18.  */
  19. abstract class ModulesHelper
  20. {
  21.     /**
  22.      * Configure the Linkbar.
  23.      *
  24.      * @param   string  $vName  The name of the active view.
  25.      */
  26.     public static function addSubmenu($vName)
  27.     {
  28.         // Not used in this component.
  29.     }
  30.  
  31.     /**
  32.      * Gets a list of the actions that can be performed.
  33.      *
  34.      * @param   integer  The module ID.
  35.      *
  36.      * @return  JObject 
  37.      */
  38.     public static function getActions($moduleId 0)
  39.     {
  40.         $user    JFactory::getUser();
  41.         $result    new JObject;
  42.  
  43.         if (empty($moduleId))
  44.         {
  45.             $assetName 'com_modules';
  46.         }
  47.         else
  48.         {
  49.             $assetName 'com_modules.module.'.(int) $moduleId;
  50.         }
  51.  
  52.         $actions JAccess::getActionsFromFile(
  53.             JPATH_ADMINISTRATOR '/components/com_modules/access.xml'"/access/section[@name='component']/"
  54.         );
  55.  
  56.         foreach ($actions as $action)
  57.         {
  58.             $result->set($action->name$user->authorise($action->name$assetName));
  59.         }
  60.  
  61.         return $result;
  62.     }
  63.  
  64.     /**
  65.      * Get a list of filter options for the state of a module.
  66.      *
  67.      * @return  array  An array of JHtmlOption elements.
  68.      */
  69.     public static function getStateOptions()
  70.     {
  71.         // Build the filter options.
  72.         $options    array();
  73.         $options[]    JHtml::_('select.option',    '1',    JText::_('JPUBLISHED'));
  74.         $options[]    JHtml::_('select.option',    '0',    JText::_('JUNPUBLISHED'));
  75.         $options[]    JHtml::_('select.option',    '-2',    JText::_('JTRASHED'));
  76.         return $options;
  77.     }
  78.  
  79.     /**
  80.      * Get a list of filter options for the application clients.
  81.      *
  82.      * @return  array  An array of JHtmlOption elements.
  83.      */
  84.     public static function getClientOptions()
  85.     {
  86.         // Build the filter options.
  87.         $options    array();
  88.         $options[]    JHtml::_('select.option''0'JText::_('JSITE'));
  89.         $options[]    JHtml::_('select.option''1'JText::_('JADMINISTRATOR'));
  90.         return $options;
  91.     }
  92.  
  93.     /**
  94.      * Get a list of modules positions
  95.      *
  96.      * @param   integer  $clientId  Client ID
  97.      *
  98.      * @return  array  A list of positions
  99.      */
  100.     public static function getPositions($clientId$editPositions false)
  101.     {
  102.         $db        JFactory::getDbo();
  103.         $query    $db->getQuery(true)
  104.             ->select('DISTINCT(position)')
  105.             ->from('#__modules')
  106.             ->where($db->quoteName('client_id'' = ' . (int) $clientId)
  107.             ->order('position');
  108.  
  109.         $db->setQuery($query);
  110.  
  111.         try
  112.         {
  113.             $positions $db->loadColumn();
  114.             $positions is_array($positions$positions array();
  115.         }
  116.         catch (RuntimeException $e)
  117.         {
  118.             JError::raiseWarning(500$e->getMessage());
  119.             return;
  120.         }
  121.  
  122.         // Build the list
  123.         $options array();
  124.         foreach ($positions as $position)
  125.         {
  126.             if (!$position && !$editPositions)
  127.             {
  128.                 $options[]    JHtml::_('select.option''none'':: ' JText::_('JNONE'' ::');
  129.  
  130.             }
  131.             else
  132.             {
  133.                 $options[]    JHtml::_('select.option'$position$position);
  134.             }
  135.         }
  136.         return $options;
  137.     }
  138.  
  139.     /**
  140.      * Return a list of templates
  141.      *
  142.      * @param   integer  $clientId  Client ID
  143.      * @param   string   $state     State
  144.      * @param   string   $template  Template name
  145.      *
  146.      * @return  array  List of templates
  147.      */
  148.     public static function getTemplates($clientId 0$state ''$template '')
  149.     {
  150.         $db JFactory::getDbo();
  151.  
  152.         // Get the database object and a new query object.
  153.         $query    $db->getQuery(true);
  154.  
  155.         // Build the query.
  156.         $query->select('element, name, enabled')
  157.             ->from('#__extensions')
  158.             ->where('client_id = ' . (int) $clientId)
  159.             ->where('type = ' $db->quote('template'));
  160.         if ($state != '')
  161.         {
  162.             $query->where('enabled = ' $db->quote($state));
  163.         }
  164.  
  165.         if ($template != '')
  166.         {
  167.             $query->where('element = ' $db->quote($template));
  168.         }
  169.  
  170.         // Set the query and load the templates.
  171.         $db->setQuery($query);
  172.         $templates $db->loadObjectList('element');
  173.         return $templates;
  174.     }
  175.  
  176.     /**
  177.      * Get a list of the unique modules installed in the client application.
  178.      *
  179.      * @param   int  $clientId  The client id.
  180.      *
  181.      * @return  array  Array of unique modules
  182.      */
  183.     public static function getModules($clientId)
  184.     {
  185.         $db        JFactory::getDbo();
  186.         $query    $db->getQuery(true)
  187.             ->select('element AS value, name AS text')
  188.             ->from('#__extensions as e')
  189.             ->where('e.client_id = ' . (int) $clientId)
  190.             ->where('type = ' $db->quote('module'))
  191.             ->join('LEFT''#__modules as m ON m.module=e.element AND m.client_id=e.client_id')
  192.             ->where('m.module IS NOT NULL')
  193.             ->group('element,name');
  194.  
  195.         $db->setQuery($query);
  196.         $modules $db->loadObjectList();
  197.         $lang JFactory::getLanguage();
  198.  
  199.         foreach ($modules as $i => $module)
  200.         {
  201.             $extension $module->value;
  202.             $path $clientId JPATH_ADMINISTRATOR JPATH_SITE;
  203.             $source $path "/modules/$extension";
  204.                 $lang->load("$extension.sys"$pathnullfalsetrue)
  205.             ||    $lang->load("$extension.sys"$sourcenullfalsetrue);
  206.             $modules[$i]->text JText::_($module->text);
  207.         }
  208.         JArrayHelper::sortObjects($modules'text'1truetrue);
  209.         return $modules;
  210.     }
  211.  
  212.     /**
  213.      * Get a list of the assignment options for modules to menus.
  214.      *
  215.      * @param   int  $clientId  The client id.
  216.      *
  217.      * @return  array 
  218.      */
  219.     public static function getAssignmentOptions($clientId)
  220.     {
  221.         $options array();
  222.         $options[JHtml::_('select.option''0''COM_MODULES_OPTION_MENU_ALL');
  223.         $options[JHtml::_('select.option''-''COM_MODULES_OPTION_MENU_NONE');
  224.  
  225.         if ($clientId == 0)
  226.         {
  227.             $options[JHtml::_('select.option''1''COM_MODULES_OPTION_MENU_INCLUDE');
  228.             $options[JHtml::_('select.option''-1''COM_MODULES_OPTION_MENU_EXCLUDE');
  229.         }
  230.  
  231.         return $options;
  232.     }
  233.  
  234.     /**
  235.      * Return a translated module position name
  236.      *
  237.      * @param   string  $template  Template name
  238.      * @param   string  $position  Position name
  239.      *
  240.      * @return  string  Return a translated position name
  241.      *
  242.      * @since   3.0
  243.      */
  244.     public static function getTranslatedModulePosition($clientId$template$position)
  245.     {
  246.         // Template translation
  247.         $lang JFactory::getLanguage();
  248.         $path $clientId JPATH_ADMINISTRATOR JPATH_SITE;
  249.  
  250.         $lang->load('tpl_'.$template.'.sys'$pathnullfalsefalse)
  251.         ||    $lang->load('tpl_'.$template.'.sys'$path.'/templates/'.$templatenullfalsefalse)
  252.         ||    $lang->load('tpl_'.$template.'.sys'$path$lang->getDefault()falsefalse)
  253.         ||    $lang->load('tpl_'.$template.'.sys'$path.'/templates/'.$template$lang->getDefault()falsefalse);
  254.  
  255.         $langKey strtoupper('TPL_' $template '_POSITION_' $position);
  256.         $text JText::_($langKey);
  257.  
  258.         // Avoid untranslated strings
  259.         if (!self::isTranslatedText($langKey$text))
  260.         {
  261.             // Modules component translation
  262.             $langKey strtoupper('COM_MODULES_POSITION_' $position);
  263.             $text JText::_($langKey);
  264.  
  265.             // Avoid untranslated strings
  266.             if (!self::isTranslatedText($langKey$text))
  267.             {
  268.                 // Try to humanize the position name
  269.                 $text ucfirst(preg_replace('/^' $template '\-/'''$position));
  270.                 $text ucwords(str_replace(array('-''_')' '$text));
  271.             }
  272.         }
  273.  
  274.         return $text;
  275.     }
  276.  
  277.     /**
  278.      * Check if the string was translated
  279.      *
  280.      * @param   string  $langKey  Language file text key
  281.      * @param   string  $text     The "translated" text to be checked
  282.      *
  283.      * @return  boolean  Return true for translated text
  284.      *
  285.      * @since   3.0
  286.      */
  287.     public static function isTranslatedText($langKey$text)
  288.     {
  289.         return $text !== $langKey;
  290.     }
  291.  
  292.     /**
  293.      * Create and return a new Option
  294.      *
  295.      * @param   string  $value  The option value [optional]
  296.      * @param   string  $text   The option text [optional]
  297.      *
  298.      * @return  object  The option as an object (stdClass instance)
  299.      *
  300.      * @since   3.0
  301.      */
  302.     public static function createOption($value ''$text '')
  303.     {
  304.         if (empty($text))
  305.         {
  306.             $text $value;
  307.         }
  308.  
  309.         $option new stdClass;
  310.         $option->value $value;
  311.         $option->text  $text;
  312.  
  313.         return $option;
  314.     }
  315.  
  316.     /**
  317.      * Create and return a new Option Group
  318.      *
  319.      * @param   string  $label    Value and label for group [optional]
  320.      * @param   array   $options  Array of options to insert into group [optional]
  321.      *
  322.      * @return  array  Return the new group as an array
  323.      *
  324.      * @since   3.0
  325.      */
  326.     public static function createOptionGroup($label ''$options array())
  327.     {
  328.         $group array();
  329.         $group['value'$label;
  330.         $group['text']  $label;
  331.         $group['items'$options;
  332.  
  333.         return $group;
  334.     }
  335. }

Documentation generated on Tue, 19 Nov 2013 15:08:53 +0100 by phpDocumentor 1.4.3