1 <?php
2 3 4 5 6 7 8
9
10 defined('JPATH_PLATFORM') or die;
11
12 use Joomla\String\StringHelper;
13
14 15 16 17 18
19 abstract class JHtmlList
20 {
21 22 23 24 25 26 27 28 29 30 31 32 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 81 82 83 84 85 86 87 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', 1, JText::_('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 (StringHelper::strlen($items[$i]->text) > $chop)
111 {
112 $text = StringHelper::substr($items[$i]->text, 0, $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 129 130 131 132 133 134 135 136 137 138 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, $name, array('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 171 172 173 174 175 176 177 178 179 180 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 219 220 221 222 223 224 225 226 227 228 229 230 231 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 }
271