[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Joomla! Content Management System 5 * 6 * @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org> 7 * @license GNU General Public License version 2 or later; see LICENSE.txt 8 */ 9 10 namespace Joomla\CMS\HTML\Helpers; 11 12 use Joomla\CMS\Factory; 13 use Joomla\CMS\HTML\HTMLHelper; 14 use Joomla\CMS\Language\Text; 15 use Joomla\CMS\Layout\LayoutHelper; 16 use Joomla\Utilities\ArrayHelper; 17 18 // phpcs:disable PSR1.Files.SideEffects 19 \defined('JPATH_PLATFORM') or die; 20 // phpcs:enable PSR1.Files.SideEffects 21 22 /** 23 * Utility class for creating HTML Grids 24 * 25 * @since 1.6 26 */ 27 abstract class JGrid 28 { 29 /** 30 * Returns an action on a grid 31 * 32 * @param integer $i The row index 33 * @param string $task The task to fire 34 * @param string|array $prefix An optional task prefix or an array of options 35 * @param string $activeTitle An optional active tooltip to display if $enable is true 36 * @param string $inactiveTitle An optional inactive tooltip to display if $enable is true 37 * @param boolean $tip An optional setting for tooltip 38 * @param string $activeClass An optional active HTML class 39 * @param string $inactiveClass An optional inactive HTML class 40 * @param boolean $enabled An optional setting for access control on the action. 41 * @param boolean $translate An optional setting for translation. 42 * @param string $checkbox An optional prefix for checkboxes. 43 * @param string $formId An optional form selector. 44 * 45 * @return string The HTML markup 46 * 47 * @since 1.6 48 */ 49 public static function action( 50 $i, 51 $task, 52 $prefix = '', 53 $activeTitle = '', 54 $inactiveTitle = '', 55 $tip = false, 56 $activeClass = '', 57 $inactiveClass = '', 58 $enabled = true, 59 $translate = true, 60 $checkbox = 'cb', 61 $formId = null 62 ) { 63 if (is_array($prefix)) { 64 $options = $prefix; 65 $activeTitle = array_key_exists('active_title', $options) ? $options['active_title'] : $activeTitle; 66 $inactiveTitle = array_key_exists('inactive_title', $options) ? $options['inactive_title'] : $inactiveTitle; 67 $tip = array_key_exists('tip', $options) ? $options['tip'] : $tip; 68 $activeClass = array_key_exists('active_class', $options) ? $options['active_class'] : $activeClass; 69 $inactiveClass = array_key_exists('inactive_class', $options) ? $options['inactive_class'] : $inactiveClass; 70 $enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled; 71 $translate = array_key_exists('translate', $options) ? $options['translate'] : $translate; 72 $checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox; 73 $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : ''; 74 } 75 76 if ($tip) { 77 $title = $enabled ? $activeTitle : $inactiveTitle; 78 $title = $translate ? Text::_($title) : $title; 79 $ariaid = $checkbox . $task . $i . '-desc'; 80 81 // Don't show empty tooltip. 82 if ($title === '') { 83 $tip = false; 84 } 85 } 86 87 if ($enabled) { 88 $html[] = '<a class="tbody-icon' . ($activeClass === 'publish' ? ' active' : '') . '"'; 89 90 if ($formId !== null) { 91 $html[] = ' href="javascript:void(0);" onclick="return Joomla.listItemTask(\'' . $checkbox . $i . '\',\'' . $prefix . 92 $task . '\',\'' . $formId . '\')"'; 93 } else { 94 $html[] = ' href="javascript:void(0);" onclick="return Joomla.listItemTask(\'' . $checkbox . $i . '\',\'' . $prefix . $task . '\')"'; 95 } 96 97 $html[] = $tip ? ' aria-labelledby="' . $ariaid . '"' : ''; 98 $html[] = '>'; 99 $html[] = LayoutHelper::render('joomla.icon.iconclass', ['icon' => $activeClass]); 100 $html[] = '</a>'; 101 $html[] = $tip ? '<div role="tooltip" id="' . $ariaid . '">' . $title . '</div>' : ''; 102 } else { 103 $html[] = '<span class="tbody-icon jgrid"'; 104 $html[] = $tip ? ' aria-labelledby="' . $ariaid . '"' : ''; 105 $html[] = '>'; 106 $html[] = LayoutHelper::render('joomla.icon.iconclass', ['icon' => $inactiveClass]); 107 $html[] = '</span>'; 108 $html[] = $tip ? '<div role="tooltip" id="' . $ariaid . '">' . $title . '</div>' : ''; 109 } 110 111 return implode($html); 112 } 113 114 /** 115 * Returns a state on a grid 116 * 117 * @param array $states array of value/state. Each state is an array of the form 118 * (task, text, active title, inactive title, tip (boolean), HTML active class, HTML inactive class) 119 * or ('task'=>task, 'text'=>text, 'active_title'=>active title, 120 * 'inactive_title'=>inactive title, 'tip'=>boolean, 'active_class'=>html active class, 121 * 'inactive_class'=>html inactive class) 122 * @param integer $value The state value. 123 * @param integer $i The row index 124 * @param string|array $prefix An optional task prefix or an array of options 125 * @param boolean $enabled An optional setting for access control on the action. 126 * @param boolean $translate An optional setting for translation. 127 * @param string $checkbox An optional prefix for checkboxes. 128 * @param string $formId An optional form selector. 129 * 130 * @return string The HTML markup 131 * 132 * @since 1.6 133 */ 134 public static function state($states, $value, $i, $prefix = '', $enabled = true, $translate = true, $checkbox = 'cb', $formId = null) 135 { 136 if (is_array($prefix)) { 137 $options = $prefix; 138 $enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled; 139 $translate = array_key_exists('translate', $options) ? $options['translate'] : $translate; 140 $checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox; 141 $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : ''; 142 } 143 144 $state = ArrayHelper::getValue($states, (int) $value, $states[0]); 145 $task = array_key_exists('task', $state) ? $state['task'] : $state[0]; 146 $text = array_key_exists('text', $state) ? $state['text'] : (array_key_exists(1, $state) ? $state[1] : ''); 147 $activeTitle = array_key_exists('active_title', $state) ? $state['active_title'] : (array_key_exists(2, $state) ? $state[2] : ''); 148 $inactiveTitle = array_key_exists('inactive_title', $state) ? $state['inactive_title'] : (array_key_exists(3, $state) ? $state[3] : ''); 149 $tip = array_key_exists('tip', $state) ? $state['tip'] : (array_key_exists(4, $state) ? $state[4] : false); 150 $activeClass = array_key_exists('active_class', $state) ? $state['active_class'] : (array_key_exists(5, $state) ? $state[5] : ''); 151 $inactiveClass = array_key_exists('inactive_class', $state) ? $state['inactive_class'] : (array_key_exists(6, $state) ? $state[6] : ''); 152 153 return static::action( 154 $i, 155 $task, 156 $prefix, 157 $activeTitle, 158 $inactiveTitle, 159 $tip, 160 $activeClass, 161 $inactiveClass, 162 $enabled, 163 $translate, 164 $checkbox, 165 $formId 166 ); 167 } 168 169 /** 170 * Returns a published state on a grid 171 * 172 * @param integer $value The state value. 173 * @param integer $i The row index 174 * @param string|array $prefix An optional task prefix or an array of options 175 * @param boolean $enabled An optional setting for access control on the action. 176 * @param string $checkbox An optional prefix for checkboxes. 177 * @param string $publishUp An optional start publishing date. 178 * @param string $publishDown An optional finish publishing date. 179 * @param string $formId An optional form selector. 180 * 181 * @return string The HTML markup 182 * 183 * @see JHtmlJGrid::state() 184 * @since 1.6 185 */ 186 public static function published( 187 $value, 188 $i, 189 $prefix = '', 190 $enabled = true, 191 $checkbox = 'cb', 192 $publishUp = null, 193 $publishDown = null, 194 $formId = null 195 ) { 196 if (is_array($prefix)) { 197 $options = $prefix; 198 $enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled; 199 $checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox; 200 $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : ''; 201 } 202 203 $states = array( 204 1 => array('unpublish', 'JPUBLISHED', 'JLIB_HTML_UNPUBLISH_ITEM', 'JPUBLISHED', true, 'publish', 'publish'), 205 0 => array('publish', 'JUNPUBLISHED', 'JLIB_HTML_PUBLISH_ITEM', 'JUNPUBLISHED', true, 'unpublish', 'unpublish'), 206 2 => array('unpublish', 'JARCHIVED', 'JLIB_HTML_UNPUBLISH_ITEM', 'JARCHIVED', true, 'archive', 'archive'), 207 -2 => array('publish', 'JTRASHED', 'JLIB_HTML_PUBLISH_ITEM', 'JTRASHED', true, 'trash', 'trash'), 208 ); 209 210 // Special state for dates 211 if ($publishUp || $publishDown) { 212 $nullDate = Factory::getDbo()->getNullDate(); 213 $nowDate = Factory::getDate()->toUnix(); 214 215 $tz = Factory::getUser()->getTimezone(); 216 217 $publishUp = ($publishUp !== null && $publishUp !== $nullDate) ? Factory::getDate($publishUp, 'UTC')->setTimezone($tz) : false; 218 $publishDown = ($publishDown !== null && $publishDown !== $nullDate) ? Factory::getDate($publishDown, 'UTC')->setTimezone($tz) : false; 219 220 // Create tip text, only we have publish up or down settings 221 $tips = array(); 222 223 if ($publishUp) { 224 $tips[] = Text::sprintf('JLIB_HTML_PUBLISHED_START', HTMLHelper::_('date', $publishUp, Text::_('DATE_FORMAT_LC5'), 'UTC')); 225 } 226 227 if ($publishDown) { 228 $tips[] = Text::sprintf('JLIB_HTML_PUBLISHED_FINISHED', HTMLHelper::_('date', $publishDown, Text::_('DATE_FORMAT_LC5'), 'UTC')); 229 } 230 231 $tip = empty($tips) ? false : implode('<br>', $tips); 232 233 // Add tips and special titles 234 foreach ($states as $key => $state) { 235 // Create special titles for published items 236 if ($key == 1) { 237 $states[$key][2] = $states[$key][3] = 'JLIB_HTML_PUBLISHED_ITEM'; 238 239 if ($publishUp > $nullDate && $nowDate < $publishUp->toUnix()) { 240 $states[$key][2] = $states[$key][3] = 'JLIB_HTML_PUBLISHED_PENDING_ITEM'; 241 $states[$key][5] = $states[$key][6] = 'pending'; 242 } 243 244 if ($publishDown > $nullDate && $nowDate > $publishDown->toUnix()) { 245 $states[$key][2] = $states[$key][3] = 'JLIB_HTML_PUBLISHED_EXPIRED_ITEM'; 246 $states[$key][5] = $states[$key][6] = 'expired'; 247 } 248 } 249 250 // Add tips to titles 251 if ($tip) { 252 $states[$key][1] = Text::_($states[$key][1]); 253 $states[$key][2] = Text::_($states[$key][2]) . '<br>' . $tip; 254 $states[$key][3] = Text::_($states[$key][3]) . '<br>' . $tip; 255 $states[$key][4] = true; 256 } 257 } 258 259 return static::state($states, $value, $i, array('prefix' => $prefix, 'translate' => !$tip), $enabled, true, $checkbox, $formId); 260 } 261 262 return static::state($states, $value, $i, $prefix, $enabled, true, $checkbox, $formId); 263 } 264 265 /** 266 * Returns an isDefault state on a grid 267 * 268 * @param integer $value The state value. 269 * @param integer $i The row index 270 * @param string|array $prefix An optional task prefix or an array of options 271 * @param boolean $enabled An optional setting for access control on the action. 272 * @param string $checkbox An optional prefix for checkboxes. 273 * @param string $formId An optional form selector. 274 * @param string $active_class The class for active items. 275 * @param string $inactive_class The class for inactive items. 276 * 277 * @return string The HTML markup 278 * 279 * @see JHtmlJGrid::state() 280 * @since 1.6 281 */ 282 public static function isdefault($value, $i, $prefix = '', $enabled = true, $checkbox = 'cb', $formId = null, $active_class = 'icon-color-featured icon-star', $inactive_class = 'icon-unfeatured') 283 { 284 if (is_array($prefix)) { 285 $options = $prefix; 286 $enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled; 287 $checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox; 288 $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : ''; 289 } 290 291 $states = array( 292 0 => array('setDefault', '', 'JLIB_HTML_SETDEFAULT_ITEM', '', 1, $inactive_class, $inactive_class), 293 1 => array('unsetDefault', 'JDEFAULT', 'JLIB_HTML_UNSETDEFAULT_ITEM', 'JDEFAULT', 1, $active_class, $active_class), 294 ); 295 296 return static::state($states, $value, $i, $prefix, $enabled, true, $checkbox, $formId); 297 } 298 299 /** 300 * Returns an array of standard published state filter options. 301 * 302 * @param array $config An array of configuration options. 303 * This array can contain a list of key/value pairs where values are boolean 304 * and keys can be taken from 'published', 'unpublished', 'archived', 'trash', 'all'. 305 * These pairs determine which values are displayed. 306 * 307 * @return array The array of standard published state filter options 308 * 309 * @since 1.6 310 */ 311 public static function publishedOptions($config = array()) 312 { 313 // Build the active state filter options. 314 $options = array(); 315 316 if (!array_key_exists('published', $config) || $config['published']) { 317 $options[] = HTMLHelper::_('select.option', '1', 'JPUBLISHED'); 318 } 319 320 if (!array_key_exists('unpublished', $config) || $config['unpublished']) { 321 $options[] = HTMLHelper::_('select.option', '0', 'JUNPUBLISHED'); 322 } 323 324 if (!array_key_exists('archived', $config) || $config['archived']) { 325 $options[] = HTMLHelper::_('select.option', '2', 'JARCHIVED'); 326 } 327 328 if (!array_key_exists('trash', $config) || $config['trash']) { 329 $options[] = HTMLHelper::_('select.option', '-2', 'JTRASHED'); 330 } 331 332 if (!array_key_exists('all', $config) || $config['all']) { 333 $options[] = HTMLHelper::_('select.option', '*', 'JALL'); 334 } 335 336 return $options; 337 } 338 339 /** 340 * Returns a checked-out icon 341 * 342 * @param integer $i The row index. 343 * @param string $editorName The name of the editor. 344 * @param string $time The time that the object was checked out. 345 * @param string|array $prefix An optional task prefix or an array of options 346 * @param boolean $enabled True to enable the action. 347 * @param string $checkbox An optional prefix for checkboxes. 348 * @param string $formId An optional form selector. 349 * 350 * @return string The HTML markup 351 * 352 * @since 1.6 353 */ 354 public static function checkedout($i, $editorName, $time, $prefix = '', $enabled = false, $checkbox = 'cb', $formId = null) 355 { 356 if (is_array($prefix)) { 357 $options = $prefix; 358 $enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled; 359 $checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox; 360 $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : ''; 361 } 362 363 $text = $editorName . '<br>' . HTMLHelper::_('date', $time, Text::_('DATE_FORMAT_LC')) . '<br>' . HTMLHelper::_('date', $time, 'H:i'); 364 $activeTitle = HTMLHelper::_('tooltipText', Text::_('JLIB_HTML_CHECKIN'), $text, 0); 365 $inactiveTitle = HTMLHelper::_('tooltipText', Text::_('JLIB_HTML_CHECKED_OUT'), $text, 0); 366 367 return static::action( 368 $i, 369 'checkin', 370 $prefix, 371 html_entity_decode($activeTitle, ENT_QUOTES, 'UTF-8'), 372 html_entity_decode($inactiveTitle, ENT_QUOTES, 'UTF-8'), 373 true, 374 'checkedout', 375 'checkedout', 376 $enabled, 377 false, 378 $checkbox, 379 $formId 380 ); 381 } 382 383 /** 384 * Creates an order-up action icon. 385 * 386 * @param integer $i The row index. 387 * @param string $task An optional task to fire. 388 * @param string|array $prefix An optional task prefix or an array of options 389 * @param string $text An optional text to display 390 * @param boolean $enabled An optional setting for access control on the action. 391 * @param string $checkbox An optional prefix for checkboxes. 392 * @param string $formId An optional form selector. 393 * 394 * @return string The HTML markup 395 * 396 * @since 1.6 397 */ 398 public static function orderUp($i, $task = 'orderup', $prefix = '', $text = 'JLIB_HTML_MOVE_UP', $enabled = true, $checkbox = 'cb', $formId = null) 399 { 400 if (is_array($prefix)) { 401 $options = $prefix; 402 $text = array_key_exists('text', $options) ? $options['text'] : $text; 403 $enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled; 404 $checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox; 405 $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : ''; 406 } 407 408 return static::action($i, $task, $prefix, $text, $text, false, 'uparrow', 'uparrow_disabled', $enabled, true, $checkbox, $formId); 409 } 410 411 /** 412 * Creates an order-down action icon. 413 * 414 * @param integer $i The row index. 415 * @param string $task An optional task to fire. 416 * @param string|array $prefix An optional task prefix or an array of options 417 * @param string $text An optional text to display 418 * @param boolean $enabled An optional setting for access control on the action. 419 * @param string $checkbox An optional prefix for checkboxes. 420 * @param string $formId An optional form selector. 421 * 422 * @return string The HTML markup 423 * 424 * @since 1.6 425 */ 426 public static function orderDown( 427 $i, 428 $task = 'orderdown', 429 $prefix = '', 430 $text = 'JLIB_HTML_MOVE_DOWN', 431 $enabled = true, 432 $checkbox = 'cb', 433 $formId = null 434 ) { 435 if (is_array($prefix)) { 436 $options = $prefix; 437 $text = array_key_exists('text', $options) ? $options['text'] : $text; 438 $enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled; 439 $checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox; 440 $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : ''; 441 } 442 443 return static::action($i, $task, $prefix, $text, $text, false, 'downarrow', 'downarrow_disabled', $enabled, true, $checkbox, $formId); 444 } 445 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |