Source for file select.php

Documentation is available at select.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Libraries
  4.  * @subpackage  HTML
  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.  * Utility class for creating HTML select lists
  14.  *
  15.  * @package     Joomla.Libraries
  16.  * @subpackage  HTML
  17.  * @since       1.5
  18.  */
  19. abstract class JHtmlSelect
  20. {
  21.     /**
  22.      * Default values for options. Organized by option group.
  23.      *
  24.      * @var     array 
  25.      * @since   1.5
  26.      */
  27.     static protected $optionDefaults = array(
  28.         'option' => array('option.attr' => null'option.disable' => 'disable''option.id' => null'option.key' => 'value',
  29.             'option.key.toHtml' => true'option.label' => null'option.label.toHtml' => true'option.text' => 'text',
  30.             'option.text.toHtml' => true));
  31.  
  32.     /**
  33.      * Generates a yes/no radio list.
  34.      *
  35.      * @param   string  $name      The value of the HTML name attribute
  36.      * @param   array   $attribs   Additional HTML attributes for the <select> tag
  37.      * @param   string  $selected  The key that is selected
  38.      * @param   string  $yes       Language key for Yes
  39.      * @param   string  $no        Language key for no
  40.      * @param   string  $id        The id for the field
  41.      *
  42.      * @return  string  HTML for the radio list
  43.      *
  44.      * @since   1.5
  45.      * @see     JFormFieldRadio
  46.      */
  47.     public static function booleanlist($name$attribs array()$selected null$yes 'JYES'$no 'JNO'$id false)
  48.     {
  49.         $arr array(JHtml::_('select.option''0'JText::_($no))JHtml::_('select.option''1'JText::_($yes)));
  50.  
  51.         return JHtml::_('select.radiolist'$arr$name$attribs'value''text'(int) $selected$id);
  52.     }
  53.  
  54.     /**
  55.      * Generates an HTML selection list.
  56.      *
  57.      * @param   array    $data       An array of objects, arrays, or scalars.
  58.      * @param   string   $name       The value of the HTML name attribute.
  59.      * @param   mixed    $attribs    Additional HTML attributes for the <select> tag. This
  60.      *                                can be an array of attributes, or an array of options. Treated as options
  61.      *                                if it is the last argument passed. Valid options are:
  62.      *                                Format options, see {@see JHtml::$formatOptions}.
  63.      *                                Selection options, see {@see JHtmlSelect::options()}.
  64.      *                                list.attr, string|array: Additional attributes for the select
  65.      *                                element.
  66.      *                                id, string: Value to use as the select element id attribute.
  67.      *                                Defaults to the same as the name.
  68.      *                                list.select, string|array: Identifies one or more option elements
  69.      *                                to be selected, based on the option key values.
  70.      * @param   string   $optKey     The name of the object variable for the option value. If
  71.      *                                set to null, the index of the value array is used.
  72.      * @param   string   $optText    The name of the object variable for the option text.
  73.      * @param   mixed    $selected   The key that is selected (accepts an array or a string).
  74.      * @param   mixed    $idtag      Value of the field id or null by default
  75.      * @param   boolean  $translate  True to translate
  76.      *
  77.      * @return  string  HTML for the select list.
  78.      *
  79.      * @since   1.5
  80.      */
  81.     public static function genericlist($data$name$attribs null$optKey 'value'$optText 'text'$selected null$idtag false,
  82.         $translate false)
  83.     {
  84.         // Set default options
  85.         $options array_merge(JHtml::$formatOptionsarray('format.depth' => 0'id' => false));
  86.  
  87.         if (is_array($attribs&& func_num_args(== 3)
  88.         {
  89.             // Assume we have an options array
  90.             $options array_merge($options$attribs);
  91.         }
  92.         else
  93.         {
  94.             // Get options from the parameters
  95.             $options['id'$idtag;
  96.             $options['list.attr'$attribs;
  97.             $options['list.translate'$translate;
  98.             $options['option.key'$optKey;
  99.             $options['option.text'$optText;
  100.             $options['list.select'$selected;
  101.         }
  102.  
  103.         $attribs '';
  104.  
  105.         if (isset($options['list.attr']))
  106.         {
  107.             if (is_array($options['list.attr']))
  108.             {
  109.                 $attribs JArrayHelper::toString($options['list.attr']);
  110.             }
  111.             else
  112.             {
  113.                 $attribs $options['list.attr'];
  114.             }
  115.  
  116.             if ($attribs != '')
  117.             {
  118.                 $attribs ' ' $attribs;
  119.             }
  120.         }
  121.  
  122.         $id $options['id'!== false $options['id'$name;
  123.         $id str_replace(array('['']')''$id);
  124.  
  125.         $baseIndent str_repeat($options['format.indent']$options['format.depth']++);
  126.         $html $baseIndent '<select' ($id !== '' ' id="' $id '"' ''' name="' $name '"' $attribs '>' $options['format.eol']
  127.             . static::options($data$options$baseIndent '</select>' $options['format.eol'];
  128.  
  129.         return $html;
  130.     }
  131.  
  132.     /**
  133.      * Method to build a list with suggestions
  134.      *
  135.      * @param   array    $data       An array of objects, arrays, or values.
  136.      * @param   string   $optKey     The name of the object variable for the option value. If
  137.      *                                set to null, the index of the value array is used.
  138.      * @param   string   $optText    The name of the object variable for the option text.
  139.      * @param   mixed    $idtag      Value of the field id or null by default
  140.      * @param   boolean  $translate  True to translate
  141.      *
  142.      * @return  string  HTML for the select list
  143.      *
  144.      * @since   3.2
  145.      */
  146.     public static function suggestionlist($data$optKey 'value'$optText 'text'$idtag$translate false)
  147.     {
  148.         // Set default options
  149.         $options array_merge(JHtml::$formatOptionsarray('format.depth' => 0'id' => false));
  150.  
  151.         // Get options from the parameters
  152.         $options['id'$idtag;
  153.         $options['list.attr'null;
  154.         $options['list.translate'$translate;
  155.         $options['option.key'$optKey;
  156.         $options['option.text'$optText;
  157.         $options['list.select'null;
  158.  
  159.         $id ' id="' $idtag '"';
  160.  
  161.         $baseIndent str_repeat($options['format.indent']$options['format.depth']++);
  162.         $html $baseIndent '<datalist' $id '>' $options['format.eol']
  163.             . static::options($data$options$baseIndent '</datalist>' $options['format.eol'];
  164.  
  165.         return $html;
  166.     }
  167.  
  168.     /**
  169.      * Generates a grouped HTML selection list from nested arrays.
  170.      *
  171.      * @param   array   $data     An array of groups, each of which is an array of options.
  172.      * @param   string  $name     The value of the HTML name attribute
  173.      * @param   array   $options  Options, an array of key/value pairs. Valid options are:
  174.      *                             Format options, {@see JHtml::$formatOptions}.
  175.      *                             Selection options. See {@see JHtmlSelect::options()}.
  176.      *                             group.id: The property in each group to use as the group id
  177.      *                             attribute. Defaults to none.
  178.      *                             group.label: The property in each group to use as the group
  179.      *                             label. Defaults to "text". If set to null, the data array index key is
  180.      *                             used.
  181.      *                             group.items: The property in each group to use as the array of
  182.      *                             items in the group. Defaults to "items". If set to null, group.id and
  183.      *                             group. label are forced to null and the data element is assumed to be a
  184.      *                             list of selections.
  185.      *                             id: Value to use as the select element id attribute. Defaults to
  186.      *                             the same as the name.
  187.      *                             list.attr: Attributes for the select element. Can be a string or
  188.      *                             an array of key/value pairs. Defaults to none.
  189.      *                             list.select: either the value of one selected option or an array
  190.      *                             of selected options. Default: none.
  191.      *                             list.translate: Boolean. If set, text and labels are translated via
  192.      *                             JText::_().
  193.      *
  194.      * @return  string  HTML for the select list
  195.      *
  196.      * @since   1.5
  197.      * @throws  RuntimeException If a group has contents that cannot be processed.
  198.      */
  199.     public static function groupedlist($data$name$options array())
  200.     {
  201.         // Set default options and overwrite with anything passed in
  202.         $options array_merge(
  203.             JHtml::$formatOptions,
  204.             array('format.depth' => 0'group.items' => 'items''group.label' => 'text''group.label.toHtml' => true'id' => false),
  205.             $options
  206.         );
  207.  
  208.         // Apply option rules
  209.         if ($options['group.items'=== null)
  210.         {
  211.             $options['group.label'null;
  212.         }
  213.  
  214.         $attribs '';
  215.  
  216.         if (isset($options['list.attr']))
  217.         {
  218.             if (is_array($options['list.attr']))
  219.             {
  220.                 $attribs JArrayHelper::toString($options['list.attr']);
  221.             }
  222.             else
  223.             {
  224.                 $attribs $options['list.attr'];
  225.             }
  226.  
  227.             if ($attribs != '')
  228.             {
  229.                 $attribs ' ' $attribs;
  230.             }
  231.         }
  232.  
  233.         $id $options['id'!== false $options['id'$name;
  234.         $id str_replace(array('['']')''$id);
  235.  
  236.         // Disable groups in the options.
  237.         $options['groups'false;
  238.  
  239.         $baseIndent str_repeat($options['format.indent']$options['format.depth']++);
  240.         $html $baseIndent '<select' ($id !== '' ' id="' $id '"' ''' name="' $name '"' $attribs '>' $options['format.eol'];
  241.         $groupIndent str_repeat($options['format.indent']$options['format.depth']++);
  242.  
  243.         foreach ($data as $dataKey => $group)
  244.         {
  245.             $label $dataKey;
  246.             $id '';
  247.             $noGroup is_int($dataKey);
  248.  
  249.             if ($options['group.items'== null)
  250.             {
  251.                 // Sub-list is an associative array
  252.                 $subList $group;
  253.             }
  254.             elseif (is_array($group))
  255.             {
  256.                 // Sub-list is in an element of an array.
  257.                 $subList $group[$options['group.items']];
  258.  
  259.                 if (isset($group[$options['group.label']]))
  260.                 {
  261.                     $label $group[$options['group.label']];
  262.                     $noGroup false;
  263.                 }
  264.  
  265.                 if (isset($options['group.id']&& isset($group[$options['group.id']]))
  266.                 {
  267.                     $id $group[$options['group.id']];
  268.                     $noGroup false;
  269.                 }
  270.             }
  271.             elseif (is_object($group))
  272.             {
  273.                 // Sub-list is in a property of an object
  274.                 $subList $group->$options['group.items'];
  275.  
  276.                 if (isset($group->$options['group.label']))
  277.                 {
  278.                     $label $group->$options['group.label'];
  279.                     $noGroup false;
  280.                 }
  281.  
  282.                 if (isset($options['group.id']&& isset($group->$options['group.id']))
  283.                 {
  284.                     $id $group->$options['group.id'];
  285.                     $noGroup false;
  286.                 }
  287.             }
  288.             else
  289.             {
  290.                 throw new RuntimeException('Invalid group contents.'1);
  291.             }
  292.  
  293.             if ($noGroup)
  294.             {
  295.                 $html .= static::options($subList$options);
  296.             }
  297.             else
  298.             {
  299.                 $html .= $groupIndent '<optgroup' (empty($id'' ' id="' $id '"'' label="'
  300.                     . ($options['group.label.toHtml'htmlspecialchars($labelENT_COMPAT'UTF-8'$label'">' $options['format.eol']
  301.                     . static::options($subList$options$groupIndent '</optgroup>' $options['format.eol'];
  302.             }
  303.         }
  304.  
  305.         $html .= $baseIndent '</select>' $options['format.eol'];
  306.  
  307.         return $html;
  308.     }
  309.  
  310.     /**
  311.      * Generates a selection list of integers.
  312.      *
  313.      * @param   integer  $start     The start integer
  314.      * @param   integer  $end       The end integer
  315.      * @param   integer  $inc       The increment
  316.      * @param   string   $name      The value of the HTML name attribute
  317.      * @param   mixed    $attribs   Additional HTML attributes for the <select> tag, an array of
  318.      *                               attributes, or an array of options. Treated as options if it is the last
  319.      *                               argument passed.
  320.      * @param   mixed    $selected  The key that is selected
  321.      * @param   string   $format    The printf format to be applied to the number
  322.      *
  323.      * @return  string   HTML for the select list
  324.      *
  325.      * @since   1.5
  326.      */
  327.     public static function integerlist($start$end$inc$name$attribs null$selected null$format '')
  328.     {
  329.         // Set default options
  330.         $options array_merge(JHtml::$formatOptionsarray('format.depth' => 0'option.format' => '''id' => null));
  331.  
  332.         if (is_array($attribs&& func_num_args(== 5)
  333.         {
  334.             // Assume we have an options array
  335.             $options array_merge($options$attribs);
  336.  
  337.             // Extract the format and remove it from downstream options
  338.             $format $options['option.format'];
  339.             unset($options['option.format']);
  340.         }
  341.         else
  342.         {
  343.             // Get options from the parameters
  344.             $options['list.attr'$attribs;
  345.             $options['list.select'$selected;
  346.         }
  347.  
  348.         $start = (int) $start;
  349.         $end   = (int) $end;
  350.         $inc   = (int) $inc;
  351.  
  352.         $data array();
  353.  
  354.         for ($i $start$i <= $end$i += $inc)
  355.         {
  356.             $data[$i$format sprintf($format$i$i;
  357.         }
  358.  
  359.         // Tell genericlist() to use array keys
  360.         $options['option.key'null;
  361.  
  362.         return JHtml::_('select.genericlist'$data$name$options);
  363.     }
  364.  
  365.     /**
  366.      * Create a placeholder for an option group.
  367.      *
  368.      * @param   string  $text     The text for the option
  369.      * @param   string  $optKey   The returned object property name for the value
  370.      * @param   string  $optText  The returned object property name for the text
  371.      *
  372.      * @return  object 
  373.      *
  374.      * @deprecated  4.0  Use JHtmlSelect::groupedList()
  375.      * @see     JHtmlSelect::groupedList()
  376.      * @since   1.5
  377.      */
  378.     public static function optgroup($text$optKey 'value'$optText 'text')
  379.     {
  380.         JLog::add('JHtmlSelect::optgroup() is deprecated, use JHtmlSelect::groupedList() instead.'JLog::WARNING'deprecated');
  381.  
  382.         // Set initial state
  383.         static $state 'open';
  384.  
  385.         // Toggle between open and close states:
  386.         switch ($state)
  387.         {
  388.             case 'open':
  389.                 $obj new stdClass;
  390.                 $obj->$optKey '<OPTGROUP>';
  391.                 $obj->$optText $text;
  392.                 $state 'close';
  393.                 break;
  394.             case 'close':
  395.                 $obj new stdClass;
  396.                 $obj->$optKey '</OPTGROUP>';
  397.                 $obj->$optText $text;
  398.                 $state 'open';
  399.                 break;
  400.         }
  401.  
  402.         return $obj;
  403.     }
  404.  
  405.     /**
  406.      * Create an object that represents an option in an option list.
  407.      *
  408.      * @param   string   $value    The value of the option
  409.      * @param   string   $text     The text for the option
  410.      * @param   mixed    $optKey   If a string, the returned object property name for
  411.      *                              the value. If an array, options. Valid options are:
  412.      *                              attr: String|array. Additional attributes for this option.
  413.      *                              Defaults to none.
  414.      *                              disable: Boolean. If set, this option is disabled.
  415.      *                              label: String. The value for the option label.
  416.      *                              option.attr: The property in each option array to use for
  417.      *                              additional selection attributes. Defaults to none.
  418.      *                              option.disable: The property that will hold the disabled state.
  419.      *                              Defaults to "disable".
  420.      *                              option.key: The property that will hold the selection value.
  421.      *                              Defaults to "value".
  422.      *                              option.label: The property in each option array to use as the
  423.      *                              selection label attribute. If a "label" option is provided, defaults to
  424.      *                              "label", if no label is given, defaults to null (none).
  425.      *                              option.text: The property that will hold the the displayed text.
  426.      *                              Defaults to "text". If set to null, the option array is assumed to be a
  427.      *                              list of displayable scalars.
  428.      * @param   string   $optText  The property that will hold the the displayed text. This
  429.      *                              parameter is ignored if an options array is passed.
  430.      * @param   boolean  $disable  Not used.
  431.      *
  432.      * @return  object 
  433.      *
  434.      * @since   1.5
  435.      */
  436.     public static function option($value$text ''$optKey 'value'$optText 'text'$disable false)
  437.     {
  438.         $options array('attr' => null'disable' => false'option.attr' => null'option.disable' => 'disable''option.key' => 'value',
  439.             'option.label' => null'option.text' => 'text');
  440.  
  441.         if (is_array($optKey))
  442.         {
  443.             // Merge in caller's options
  444.             $options array_merge($options$optKey);
  445.         }
  446.         else
  447.         {
  448.             // Get options from the parameters
  449.             $options['option.key'$optKey;
  450.             $options['option.text'$optText;
  451.             $options['disable'$disable;
  452.         }
  453.  
  454.         $obj new stdClass;
  455.         $obj->$options['option.key'$value;
  456.         $obj->$options['option.text'trim($text$text $value;
  457.  
  458.         /*
  459.          * If a label is provided, save it. If no label is provided and there is
  460.          * a label name, initialise to an empty string.
  461.          */
  462.         $hasProperty $options['option.label'!== null;
  463.  
  464.         if (isset($options['label']))
  465.         {
  466.             $labelProperty $hasProperty $options['option.label''label';
  467.             $obj->$labelProperty $options['label'];
  468.         }
  469.         elseif ($hasProperty)
  470.         {
  471.             $obj->$options['option.label''';
  472.         }
  473.  
  474.         // Set attributes only if there is a property and a value
  475.         if ($options['attr'!== null)
  476.         {
  477.             $obj->$options['option.attr'$options['attr'];
  478.         }
  479.  
  480.         // Set disable only if it has a property and a value
  481.         if ($options['disable'!== null)
  482.         {
  483.             $obj->$options['option.disable'$options['disable'];
  484.         }
  485.  
  486.         return $obj;
  487.     }
  488.  
  489.     /**
  490.      * Generates the option tags for an HTML select list (with no select tag
  491.      * surrounding the options).
  492.      *
  493.      * @param   array    $arr        An array of objects, arrays, or values.
  494.      * @param   mixed    $optKey     If a string, this is the name of the object variable for
  495.      *                                the option value. If null, the index of the array of objects is used. If
  496.      *                                an array, this is a set of options, as key/value pairs. Valid options are:
  497.      *                                -Format options, {@see JHtml::$formatOptions}.
  498.      *                                -groups: Boolean. If set, looks for keys with the value
  499.      *                                 "&lt;optgroup>" and synthesizes groups from them. Deprecated. Defaults
  500.      *                                 true for backwards compatibility.
  501.      *                                -list.select: either the value of one selected option or an array
  502.      *                                 of selected options. Default: none.
  503.      *                                -list.translate: Boolean. If set, text and labels are translated via
  504.      *                                 JText::_(). Default is false.
  505.      *                                -option.id: The property in each option array to use as the
  506.      *                                 selection id attribute. Defaults to none.
  507.      *                                -option.key: The property in each option array to use as the
  508.      *                                 selection value. Defaults to "value". If set to null, the index of the
  509.      *                                 option array is used.
  510.      *                                -option.label: The property in each option array to use as the
  511.      *                                 selection label attribute. Defaults to null (none).
  512.      *                                -option.text: The property in each option array to use as the
  513.      *                                displayed text. Defaults to "text". If set to null, the option array is
  514.      *                                assumed to be a list of displayable scalars.
  515.      *                                -option.attr: The property in each option array to use for
  516.      *                                 additional selection attributes. Defaults to none.
  517.      *                                -option.disable: The property that will hold the disabled state.
  518.      *                                 Defaults to "disable".
  519.      *                                -option.key: The property that will hold the selection value.
  520.      *                                 Defaults to "value".
  521.      *                                -option.text: The property that will hold the the displayed text.
  522.      *                                Defaults to "text". If set to null, the option array is assumed to be a
  523.      *                                list of displayable scalars.
  524.      * @param   string   $optText    The name of the object variable for the option text.
  525.      * @param   mixed    $selected   The key that is selected (accepts an array or a string)
  526.      * @param   boolean  $translate  Translate the option values.
  527.      *
  528.      * @return  string  HTML for the select list
  529.      *
  530.      * @since   1.5
  531.      */
  532.     public static function options($arr$optKey 'value'$optText 'text'$selected null$translate false)
  533.     {
  534.         $options array_merge(
  535.             JHtml::$formatOptions,
  536.             static::$optionDefaults['option'],
  537.             array('format.depth' => 0'groups' => true'list.select' => null'list.translate' => false)
  538.         );
  539.  
  540.         if (is_array($optKey))
  541.         {
  542.             // Set default options and overwrite with anything passed in
  543.             $options array_merge($options$optKey);
  544.         }
  545.         else
  546.         {
  547.             // Get options from the parameters
  548.             $options['option.key'$optKey;
  549.             $options['option.text'$optText;
  550.             $options['list.select'$selected;
  551.             $options['list.translate'$translate;
  552.         }
  553.  
  554.         $html '';
  555.         $baseIndent str_repeat($options['format.indent']$options['format.depth']);
  556.  
  557.         foreach ($arr as $elementKey => &$element)
  558.         {
  559.             $attr '';
  560.             $extra '';
  561.             $label '';
  562.             $id '';
  563.  
  564.             if (is_array($element))
  565.             {
  566.                 $key $options['option.key'=== null $elementKey $element[$options['option.key']];
  567.                 $text $element[$options['option.text']];
  568.  
  569.                 if (isset($element[$options['option.attr']]))
  570.                 {
  571.                     $attr $element[$options['option.attr']];
  572.                 }
  573.  
  574.                 if (isset($element[$options['option.id']]))
  575.                 {
  576.                     $id $element[$options['option.id']];
  577.                 }
  578.  
  579.                 if (isset($element[$options['option.label']]))
  580.                 {
  581.                     $label $element[$options['option.label']];
  582.                 }
  583.  
  584.                 if (isset($element[$options['option.disable']]&& $element[$options['option.disable']])
  585.                 {
  586.                     $extra .= ' disabled="disabled"';
  587.                 }
  588.             }
  589.             elseif (is_object($element))
  590.             {
  591.                 $key $options['option.key'=== null $elementKey $element->$options['option.key'];
  592.                 $text $element->$options['option.text'];
  593.  
  594.                 if (isset($element->$options['option.attr']))
  595.                 {
  596.                     $attr $element->$options['option.attr'];
  597.                 }
  598.  
  599.                 if (isset($element->$options['option.id']))
  600.                 {
  601.                     $id $element->$options['option.id'];
  602.                 }
  603.  
  604.                 if (isset($element->$options['option.label']))
  605.                 {
  606.                     $label $element->$options['option.label'];
  607.                 }
  608.  
  609.                 if (isset($element->$options['option.disable']&& $element->$options['option.disable'])
  610.                 {
  611.                     $extra .= ' disabled="disabled"';
  612.                 }
  613.             }
  614.             else
  615.             {
  616.                 // This is a simple associative array
  617.                 $key $elementKey;
  618.                 $text $element;
  619.             }
  620.  
  621.             /*
  622.              * The use of options that contain optgroup HTML elements was
  623.              * somewhat hacked for J1.5. J1.6 introduces the grouplist() method
  624.              * to handle this better. The old solution is retained through the
  625.              * "groups" option, which defaults true in J1.6, but should be
  626.              * deprecated at some point in the future.
  627.              */
  628.  
  629.             $key = (string) $key;
  630.  
  631.             if ($options['groups'&& $key == '<OPTGROUP>')
  632.             {
  633.                 $html .= $baseIndent '<optgroup label="' ($options['list.translate'JText::_($text$text'">' $options['format.eol'];
  634.                 $baseIndent str_repeat($options['format.indent']++$options['format.depth']);
  635.             }
  636.             elseif ($options['groups'&& $key == '</OPTGROUP>')
  637.             {
  638.                 $baseIndent str_repeat($options['format.indent']--$options['format.depth']);
  639.                 $html .= $baseIndent '</optgroup>' $options['format.eol'];
  640.             }
  641.             else
  642.             {
  643.                 // If no string after hyphen - take hyphen out
  644.                 $splitText preg_split('/ -[\s]*/'$text2PREG_SPLIT_NO_EMPTY);
  645.                 $text = isset($splitText[0]$splitText[0'';
  646.  
  647.                 if (!empty($splitText[1]))
  648.                 {
  649.                     $text .= ' - ' $splitText[1];
  650.                 }
  651.  
  652.                 if ($options['list.translate'&& !empty($label))
  653.                 {
  654.                     $label JText::_($label);
  655.                 }
  656.  
  657.                 if ($options['option.label.toHtml'])
  658.                 {
  659.                     $label htmlentities($label);
  660.                 }
  661.  
  662.                 if (is_array($attr))
  663.                 {
  664.                     $attr JArrayHelper::toString($attr);
  665.                 }
  666.                 else
  667.                 {
  668.                     $attr trim($attr);
  669.                 }
  670.  
  671.                 $extra ($id ' id="' $id '"' ''($label ' label="' $label '"' ''($attr ' ' $attr ''$extra;
  672.  
  673.                 if (is_array($options['list.select']))
  674.                 {
  675.                     foreach ($options['list.select'as $val)
  676.                     {
  677.                         $key2 is_object($val$val->$options['option.key'$val;
  678.  
  679.                         if ($key == $key2)
  680.                         {
  681.                             $extra .= ' selected="selected"';
  682.                             break;
  683.                         }
  684.                     }
  685.                 }
  686.                 elseif ((string) $key == (string) $options['list.select'])
  687.                 {
  688.                     $extra .= ' selected="selected"';
  689.                 }
  690.  
  691.                 if ($options['list.translate'])
  692.                 {
  693.                     $text JText::_($text);
  694.                 }
  695.  
  696.                 // Generate the option, encoding as required
  697.                 $html .= $baseIndent '<option value="' ($options['option.key.toHtml'htmlspecialchars($keyENT_COMPAT'UTF-8'$key'"'
  698.                     . $extra '>';
  699.                 $html .= $options['option.text.toHtml'htmlentities(html_entity_decode($textENT_COMPAT'UTF-8')ENT_COMPAT'UTF-8'$text;
  700.                 $html .= '</option>' $options['format.eol'];
  701.             }
  702.         }
  703.  
  704.         return $html;
  705.     }
  706.  
  707.     /**
  708.      * Generates an HTML radio list.
  709.      *
  710.      * @param   array    $data       An array of objects
  711.      * @param   string   $name       The value of the HTML name attribute
  712.      * @param   string   $attribs    Additional HTML attributes for the <select> tag
  713.      * @param   mixed    $optKey     The key that is selected
  714.      * @param   string   $optText    The name of the object variable for the option value
  715.      * @param   string   $selected   The name of the object variable for the option text
  716.      * @param   boolean  $idtag      Value of the field id or null by default
  717.      * @param   boolean  $translate  True if options will be translated
  718.      *
  719.      * @return  string  HTML for the select list
  720.      *
  721.      * @since   1.5
  722.      */
  723.     public static function radiolist($data$name$attribs null$optKey 'value'$optText 'text'$selected null$idtag false,
  724.         $translate false)
  725.     {
  726.         reset($data);
  727.  
  728.         if (is_array($attribs))
  729.         {
  730.             $attribs JArrayHelper::toString($attribs);
  731.         }
  732.  
  733.         $id_text $idtag $idtag $name;
  734.  
  735.         $html '<div class="controls">';
  736.  
  737.         foreach ($data as $obj)
  738.         {
  739.             $k $obj->$optKey;
  740.             $t $translate JText::_($obj->$optText$obj->$optText;
  741.             $id (isset($obj->id$obj->id null);
  742.  
  743.             $extra '';
  744.             $id $id $obj->id $id_text $k;
  745.  
  746.             if (is_array($selected))
  747.             {
  748.                 foreach ($selected as $val)
  749.                 {
  750.                     $k2 is_object($val$val->$optKey $val;
  751.  
  752.                     if ($k == $k2)
  753.                     {
  754.                         $extra .= ' selected="selected" ';
  755.                         break;
  756.                     }
  757.                 }
  758.             }
  759.             else
  760.             {
  761.                 $extra .= ((string) $k == (string) $selected ' checked="checked" ' '');
  762.             }
  763.  
  764.             $html .= "\n\t" '<label for="' $id '" id="' $id '-lbl" class="radio">';
  765.             $html .= "\n\t\n\t" '<input type="radio" name="' $name '" id="' $id '" value="' $k '" ' $extra
  766.                 . $attribs ' >' $t;
  767.             $html .= "\n\t" '</label>';
  768.         }
  769.  
  770.         $html .= "\n";
  771.         $html .= '</div>';
  772.         $html .= "\n";
  773.  
  774.         return $html;
  775.     }
  776. }

Documentation generated on Tue, 19 Nov 2013 15:12:50 +0100 by phpDocumentor 1.4.3