Source for file list.php

Documentation is available at list.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 different select lists
  14.  *
  15.  * @package     Joomla.Libraries
  16.  * @subpackage  HTML
  17.  * @since       1.5
  18.  */
  19. abstract class JHtmlList
  20. {
  21.     /**
  22.      * Build the select list to choose an image
  23.      *
  24.      * @param   string  $name        The name of the field
  25.      * @param   string  $active      The selected item
  26.      * @param   string  $javascript  Alternative javascript
  27.      * @param   string  $directory   Directory the images are stored in
  28.      * @param   string  $extensions  Allowed extensions
  29.      *
  30.      * @return  array  Image names
  31.      *
  32.      * @since   1.5
  33.      */
  34.     public static function images($name$active null$javascript null$directory null$extensions "bmp|gif|jpg|png")
  35.     {
  36.         if (!$directory)
  37.         {
  38.             $directory '/images/';
  39.         }
  40.  
  41.         if (!$javascript)
  42.         {
  43.             $javascript "onchange=\"if (document.forms.adminForm." $name
  44.                 . ".options[selectedIndex].value!='') {document.imagelib.src='..$directory' + document.forms.adminForm.$name
  45.                 . ".options[selectedIndex].value} else {document.imagelib.src='media/system/images/blank.png'}\"";
  46.         }
  47.  
  48.         $imageFiles new DirectoryIterator(JPATH_SITE '/' $directory);
  49.         $images array(JHtml::_('select.option'''JText::_('JOPTION_SELECT_IMAGE')));
  50.  
  51.         foreach ($imageFiles as $file)
  52.         {
  53.             $fileName $file->getFilename();
  54.  
  55.             if (!$file->isFile())
  56.             {
  57.                 continue;
  58.             }
  59.  
  60.             if (preg_match('#(' $extensions ')$#'$fileName))
  61.             {
  62.                 $images[JHtml::_('select.option'$fileName);
  63.             }
  64.         }
  65.  
  66.         $images JHtml::_(
  67.             'select.genericlist',
  68.             $images,
  69.             $name,
  70.             array(
  71.                 'list.attr' => 'class="inputbox" size="1" ' $javascript,
  72.                 'list.select' => $active
  73.             )
  74.         );
  75.  
  76.         return $images;
  77.     }
  78.  
  79.     /**
  80.      * Returns an array of options
  81.      *
  82.      * @param   string   $query  SQL with 'ordering' AS value and 'name field' AS text
  83.      * @param   integer  $chop   The length of the truncated headline
  84.      *
  85.      * @return  array  An array of objects formatted for JHtml list processing
  86.      *
  87.      * @since   1.5
  88.      */
  89.     public static function genericordering($query$chop 30)
  90.     {
  91.         $db JFactory::getDbo();
  92.         $options array();
  93.         $db->setQuery($query);
  94.  
  95.         $items $db->loadObjectList();
  96.  
  97.         if (empty($items))
  98.         {
  99.             $options[JHtml::_('select.option'1JText::_('JOPTION_ORDER_FIRST'));
  100.  
  101.             return $options;
  102.         }
  103.  
  104.         $options[JHtml::_('select.option'0'0 ' JText::_('JOPTION_ORDER_FIRST'));
  105.  
  106.         for ($i 0$n count($items)$i $n$i++)
  107.         {
  108.             $items[$i]->text JText::_($items[$i]->text);
  109.  
  110.             if (JString::strlen($items[$i]->text$chop)
  111.             {
  112.                 $text JString::substr($items[$i]->text0$chop"...";
  113.             }
  114.             else
  115.             {
  116.                 $text $items[$i]->text;
  117.             }
  118.  
  119.             $options[JHtml::_('select.option'$items[$i]->value$items[$i]->value '. ' $text);
  120.         }
  121.  
  122.         $options[JHtml::_('select.option'$items[$i 1]->value 1($items[$i 1]->value 1' ' JText::_('JOPTION_ORDER_LAST'));
  123.  
  124.         return $options;
  125.     }
  126.  
  127.     /**
  128.      * Build the select list for Ordering derived from a query
  129.      *
  130.      * @param   integer  $name      The scalar value
  131.      * @param   string   $query     The query
  132.      * @param   string   $attribs   HTML tag attributes
  133.      * @param   string   $selected  The selected item
  134.      * @param   integer  $neworder  1 if new and first, -1 if new and last, 0  or null if existing item
  135.      *
  136.      * @return  string   HTML markup for the select list
  137.      *
  138.      * @since   1.6
  139.      */
  140.     public static function ordering($name$query$attribs null$selected null$neworder null)
  141.     {
  142.         if (empty($attribs))
  143.         {
  144.             $attribs 'class="inputbox" size="1"';
  145.         }
  146.  
  147.         if (empty($neworder))
  148.         {
  149.             $orders JHtml::_('list.genericordering'$query);
  150.             $html JHtml::_('select.genericlist'$orders$namearray('list.attr' => $attribs'list.select' => (int) $selected));
  151.         }
  152.         else
  153.         {
  154.             if ($neworder 0)
  155.             {
  156.                 $text JText::_('JGLOBAL_NEWITEMSLAST_DESC');
  157.             }
  158.             elseif ($neworder <= 0)
  159.             {
  160.                 $text JText::_('JGLOBAL_NEWITEMSFIRST_DESC');
  161.             }
  162.  
  163.             $html '<input type="hidden" name="' $name '" value="' . (int) $selected '" /><span class="readonly">' $text '</span>';
  164.         }
  165.  
  166.         return $html;
  167.     }
  168.  
  169.     /**
  170.      * Select list of active users
  171.      *
  172.      * @param   string   $name        The name of the field
  173.      * @param   string   $active      The active user
  174.      * @param   integer  $nouser      If set include an option to select no user
  175.      * @param   string   $javascript  Custom javascript
  176.      * @param   string   $order       Specify a field to order by
  177.      *
  178.      * @return  string   The HTML for a list of users list of users
  179.      *
  180.      * @since   1.5
  181.      */
  182.     public static function users($name$active$nouser 0$javascript null$order 'name')
  183.     {
  184.         $db JFactory::getDbo();
  185.         $query $db->getQuery(true)
  186.             ->select('u.id AS value, u.name AS text')
  187.             ->from('#__users AS u')
  188.             ->join('LEFT''#__user_usergroup_map AS m ON m.user_id = u.id')
  189.             ->where('u.block = 0')
  190.             ->order($order)
  191.             ->group('u.id');
  192.         $db->setQuery($query);
  193.  
  194.         if ($nouser)
  195.         {
  196.             $users[JHtml::_('select.option''0'JText::_('JOPTION_NO_USER'));
  197.             $users array_merge($users$db->loadObjectList());
  198.         }
  199.         else
  200.         {
  201.             $users $db->loadObjectList();
  202.         }
  203.  
  204.         $users JHtml::_(
  205.             'select.genericlist',
  206.             $users,
  207.             $name,
  208.             array(
  209.                 'list.attr' => 'class="inputbox" size="1" ' $javascript,
  210.                 'list.select' => $active
  211.             )
  212.         );
  213.  
  214.         return $users;
  215.     }
  216.  
  217.     /**
  218.      * Select list of positions - generally used for location of images
  219.      *
  220.      * @param   string   $name        Name of the field
  221.      * @param   string   $active      The active value
  222.      * @param   string   $javascript  Alternative javascript
  223.      * @param   boolean  $none        Null if not assigned
  224.      * @param   boolean  $center      Null if not assigned
  225.      * @param   boolean  $left        Null if not assigned
  226.      * @param   boolean  $right       Null if not assigned
  227.      * @param   boolean  $id          Null if not assigned
  228.      *
  229.      * @return  array  The positions
  230.      *
  231.      * @since   1.5
  232.      */
  233.     public static function positions($name$active null$javascript null$none true$center true$left true$right true,
  234.         $id false)
  235.     {
  236.         $pos array();
  237.  
  238.         if ($none)
  239.         {
  240.             $pos[''JText::_('JNONE');
  241.         }
  242.  
  243.         if ($center)
  244.         {
  245.             $pos['center'JText::_('JGLOBAL_CENTER');
  246.         }
  247.  
  248.         if ($left)
  249.         {
  250.             $pos['left'JText::_('JGLOBAL_LEFT');
  251.         }
  252.  
  253.         if ($right)
  254.         {
  255.             $pos['right'JText::_('JGLOBAL_RIGHT');
  256.         }
  257.  
  258.         $positions JHtml::_(
  259.             'select.genericlist'$pos$name,
  260.             array(
  261.                 'id' => $id,
  262.                 'list.attr' => 'class="inputbox" size="1"' $javascript,
  263.                 'list.select' => $active,
  264.                 'option.key' => null,
  265.             )
  266.         );
  267.  
  268.         return $positions;
  269.     }
  270. }

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