1 <?php
2 3 4 5 6 7 8
9
10 defined('JPATH_PLATFORM') or die;
11
12 use Joomla\Utilities\ArrayHelper;
13
14 15 16 17 18
19 abstract class JHtmlJGrid
20 {
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
41 public static function action($i, $task, $prefix = '', $text = '', $active_title = '', $inactive_title = '', $tip = false, $active_class = '',
42 $inactive_class = '', $enabled = true, $translate = true, $checkbox = 'cb')
43 {
44 if (is_array($prefix))
45 {
46 $options = $prefix;
47 $active_title = array_key_exists('active_title', $options) ? $options['active_title'] : $active_title;
48 $inactive_title = array_key_exists('inactive_title', $options) ? $options['inactive_title'] : $inactive_title;
49 $tip = array_key_exists('tip', $options) ? $options['tip'] : $tip;
50 $active_class = array_key_exists('active_class', $options) ? $options['active_class'] : $active_class;
51 $inactive_class = array_key_exists('inactive_class', $options) ? $options['inactive_class'] : $inactive_class;
52 $enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled;
53 $translate = array_key_exists('translate', $options) ? $options['translate'] : $translate;
54 $checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox;
55 $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : '';
56 }
57
58 if ($tip)
59 {
60 JHtml::_('bootstrap.tooltip');
61
62 $title = $enabled ? $active_title : $inactive_title;
63 $title = $translate ? JText::_($title) : $title;
64 $title = JHtml::_('tooltipText', $title, '', 0);
65 }
66
67 if ($enabled)
68 {
69 $html[] = '<a class="btn btn-micro' . ($active_class === 'publish' ? ' active' : '') . ($tip ? ' hasTooltip' : '') . '"';
70 $html[] = ' href="javascript:void(0);" onclick="return listItemTask(\'' . $checkbox . $i . '\',\'' . $prefix . $task . '\')"';
71 $html[] = $tip ? ' title="' . $title . '"' : '';
72 $html[] = '>';
73 $html[] = '<span class="icon-' . $active_class . '" aria-hidden="true"></span>';
74 $html[] = '</a>';
75 }
76 else
77 {
78 $html[] = '<a class="btn btn-micro disabled jgrid' . ($tip ? ' hasTooltip' : '') . '"';
79 $html[] = $tip ? ' title="' . $title . '"' : '';
80 $html[] = '>';
81
82 if ($active_class === 'protected')
83 {
84 $html[] = '<span class="icon-lock"></span>';
85 }
86 else
87 {
88 $html[] = '<span class="icon-' . $inactive_class . '"></span>';
89 }
90
91 $html[] = '</a>';
92 }
93
94 return implode($html);
95 }
96
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
116 public static function state($states, $value, $i, $prefix = '', $enabled = true, $translate = true, $checkbox = 'cb')
117 {
118 if (is_array($prefix))
119 {
120 $options = $prefix;
121 $enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled;
122 $translate = array_key_exists('translate', $options) ? $options['translate'] : $translate;
123 $checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox;
124 $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : '';
125 }
126
127 $state = ArrayHelper::getValue($states, (int) $value, $states[0]);
128 $task = array_key_exists('task', $state) ? $state['task'] : $state[0];
129 $text = array_key_exists('text', $state) ? $state['text'] : (array_key_exists(1, $state) ? $state[1] : '');
130 $active_title = array_key_exists('active_title', $state) ? $state['active_title'] : (array_key_exists(2, $state) ? $state[2] : '');
131 $inactive_title = array_key_exists('inactive_title', $state) ? $state['inactive_title'] : (array_key_exists(3, $state) ? $state[3] : '');
132 $tip = array_key_exists('tip', $state) ? $state['tip'] : (array_key_exists(4, $state) ? $state[4] : false);
133 $active_class = array_key_exists('active_class', $state) ? $state['active_class'] : (array_key_exists(5, $state) ? $state[5] : '');
134 $inactive_class = array_key_exists('inactive_class', $state) ? $state['inactive_class'] : (array_key_exists(6, $state) ? $state[6] : '');
135
136 return static::action(
137 $i, $task, $prefix, $text, $active_title, $inactive_title, $tip,
138 $active_class, $inactive_class, $enabled, $translate, $checkbox
139 );
140 }
141
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
158 public static function published($value, $i, $prefix = '', $enabled = true, $checkbox = 'cb', $publish_up = null, $publish_down = null)
159 {
160 if (is_array($prefix))
161 {
162 $options = $prefix;
163 $enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled;
164 $checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox;
165 $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : '';
166 }
167
168 $states = array(
169 1 => array('unpublish', 'JPUBLISHED', 'JLIB_HTML_UNPUBLISH_ITEM', 'JPUBLISHED', true, 'publish', 'publish'),
170 0 => array('publish', 'JUNPUBLISHED', 'JLIB_HTML_PUBLISH_ITEM', 'JUNPUBLISHED', true, 'unpublish', 'unpublish'),
171 2 => array('unpublish', 'JARCHIVED', 'JLIB_HTML_UNPUBLISH_ITEM', 'JARCHIVED', true, 'archive', 'archive'),
172 -2 => array('publish', 'JTRASHED', 'JLIB_HTML_PUBLISH_ITEM', 'JTRASHED', true, 'trash', 'trash'),
173 );
174
175
176 if ($publish_up || $publish_down)
177 {
178 $nullDate = JFactory::getDbo()->getNullDate();
179 $nowDate = JFactory::getDate()->toUnix();
180
181 $tz = JFactory::getUser()->getTimezone();
182
183 $publish_up = ($publish_up != $nullDate) ? JFactory::getDate($publish_up, 'UTC')->setTimeZone($tz) : false;
184 $publish_down = ($publish_down != $nullDate) ? JFactory::getDate($publish_down, 'UTC')->setTimeZone($tz) : false;
185
186
187 $tips = array();
188
189 if ($publish_up)
190 {
191 $tips[] = JText::sprintf('JLIB_HTML_PUBLISHED_START', $publish_up->format(JDate::$format, true));
192 }
193
194 if ($publish_down)
195 {
196 $tips[] = JText::sprintf('JLIB_HTML_PUBLISHED_FINISHED', $publish_down->format(JDate::$format, true));
197 }
198
199 $tip = empty($tips) ? false : implode('<br />', $tips);
200
201
202 foreach ($states as $key => $state)
203 {
204
205 if ($key == 1)
206 {
207 $states[$key][2] = $states[$key][3] = 'JLIB_HTML_PUBLISHED_ITEM';
208
209 if ($publish_up > $nullDate && $nowDate < $publish_up->toUnix())
210 {
211 $states[$key][2] = $states[$key][3] = 'JLIB_HTML_PUBLISHED_PENDING_ITEM';
212 $states[$key][5] = $states[$key][6] = 'pending';
213 }
214
215 if ($publish_down > $nullDate && $nowDate > $publish_down->toUnix())
216 {
217 $states[$key][2] = $states[$key][3] = 'JLIB_HTML_PUBLISHED_EXPIRED_ITEM';
218 $states[$key][5] = $states[$key][6] = 'expired';
219 }
220 }
221
222
223 if ($tip)
224 {
225 $states[$key][1] = JText::_($states[$key][1]);
226 $states[$key][2] = JText::_($states[$key][2]) . '<br />' . $tip;
227 $states[$key][3] = JText::_($states[$key][3]) . '<br />' . $tip;
228 $states[$key][4] = true;
229 }
230 }
231
232 return static::state($states, $value, $i, array('prefix' => $prefix, 'translate' => !$tip), $enabled, true, $checkbox);
233 }
234
235 return static::state($states, $value, $i, $prefix, $enabled, true, $checkbox);
236 }
237
238 239 240 241 242 243 244 245 246 247 248 249 250 251
252 public static function isdefault($value, $i, $prefix = '', $enabled = true, $checkbox = 'cb')
253 {
254 if (is_array($prefix))
255 {
256 $options = $prefix;
257 $enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled;
258 $checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox;
259 $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : '';
260 }
261
262 $states = array(
263 0 => array('setDefault', '', 'JLIB_HTML_SETDEFAULT_ITEM', '', 1, 'unfeatured', 'unfeatured'),
264 1 => array('unsetDefault', 'JDEFAULT', 'JLIB_HTML_UNSETDEFAULT_ITEM', 'JDEFAULT', 1, 'featured', 'featured'),
265 );
266
267 return static::state($states, $value, $i, $prefix, $enabled, true, $checkbox);
268 }
269
270 271 272 273 274 275 276 277 278 279 280 281
282 public static function publishedOptions($config = array())
283 {
284
285 $options = array();
286
287 if (!array_key_exists('published', $config) || $config['published'])
288 {
289 $options[] = JHtml::_('select.option', '1', 'JPUBLISHED');
290 }
291
292 if (!array_key_exists('unpublished', $config) || $config['unpublished'])
293 {
294 $options[] = JHtml::_('select.option', '0', 'JUNPUBLISHED');
295 }
296
297 if (!array_key_exists('archived', $config) || $config['archived'])
298 {
299 $options[] = JHtml::_('select.option', '2', 'JARCHIVED');
300 }
301
302 if (!array_key_exists('trash', $config) || $config['trash'])
303 {
304 $options[] = JHtml::_('select.option', '-2', 'JTRASHED');
305 }
306
307 if (!array_key_exists('all', $config) || $config['all'])
308 {
309 $options[] = JHtml::_('select.option', '*', 'JALL');
310 }
311
312 return $options;
313 }
314
315 316 317 318 319 320 321 322 323 324 325 326 327 328
329 public static function checkedout($i, $editorName, $time, $prefix = '', $enabled = false, $checkbox = 'cb')
330 {
331 JHtml::_('bootstrap.tooltip');
332
333 if (is_array($prefix))
334 {
335 $options = $prefix;
336 $enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled;
337 $checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox;
338 $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : '';
339 }
340
341 $text = $editorName . '<br />' . JHtml::_('date', $time, JText::_('DATE_FORMAT_LC')) . '<br />' . JHtml::_('date', $time, 'H:i');
342 $active_title = JHtml::_('tooltipText', JText::_('JLIB_HTML_CHECKIN'), $text, 0);
343 $inactive_title = JHtml::_('tooltipText', JText::_('JLIB_HTML_CHECKED_OUT'), $text, 0);
344
345 return static::action(
346 $i, 'checkin', $prefix, JText::_('JLIB_HTML_CHECKED_OUT'), html_entity_decode($active_title, ENT_QUOTES, 'UTF-8'),
347 html_entity_decode($inactive_title, ENT_QUOTES, 'UTF-8'), true, 'checkedout', 'checkedout', $enabled, false, $checkbox
348 );
349 }
350
351 352 353 354 355 356 357 358 359 360 361 362 363 364
365 public static function orderUp($i, $task = 'orderup', $prefix = '', $text = 'JLIB_HTML_MOVE_UP', $enabled = true, $checkbox = 'cb')
366 {
367 if (is_array($prefix))
368 {
369 $options = $prefix;
370 $text = array_key_exists('text', $options) ? $options['text'] : $text;
371 $enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled;
372 $checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox;
373 $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : '';
374 }
375
376 return static::action($i, $task, $prefix, $text, $text, $text, false, 'uparrow', 'uparrow_disabled', $enabled, true, $checkbox);
377 }
378
379 380 381 382 383 384 385 386 387 388 389 390 391 392
393 public static function orderDown($i, $task = 'orderdown', $prefix = '', $text = 'JLIB_HTML_MOVE_DOWN', $enabled = true, $checkbox = 'cb')
394 {
395 if (is_array($prefix))
396 {
397 $options = $prefix;
398 $text = array_key_exists('text', $options) ? $options['text'] : $text;
399 $enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled;
400 $checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox;
401 $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : '';
402 }
403
404 return static::action($i, $task, $prefix, $text, $text, $text, false, 'downarrow', 'downarrow_disabled', $enabled, true, $checkbox);
405 }
406 }
407