messages.php
2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* @package Joomla.Administrator
* @subpackage com_messages
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
use Joomla\Utilities\ArrayHelper;
/**
* JHtml administrator messages class.
*
* @since 1.6
*/
class JHtmlMessages
{
/**
* Get the HTML code of the state switcher
*
* @param int $value The state value
* @param int $i Row number
* @param boolean $canChange Can the user change the state?
*
* @return string
*
* @since 1.6
*
* @deprecated 4.0 Use JHtmlMessages::status() instead
*/
public static function state($value = 0, $i = 0, $canChange = false)
{
// Log deprecated message
try
{
JLog::add(
sprintf('%s() is deprecated. Use JHtmlMessages::status() instead.', __METHOD__),
JLog::WARNING,
'deprecated'
);
}
catch (RuntimeException $exception)
{
// Informational log only
}
// Note: $i is required but has to be an optional argument in the function call due to argument order
if (null === $i)
{
throw new InvalidArgumentException('$i is a required argument in JHtmlMessages::state');
}
// Note: $canChange is required but has to be an optional argument in the function call due to argument order
if (null === $canChange)
{
throw new InvalidArgumentException('$canChange is a required argument in JHtmlMessages::state');
}
return static::status($i, $value, $canChange);
}
/**
* Get the HTML code of the state switcher
*
* @param int $i Row number
* @param int $value The state value
* @param boolean $canChange Can the user change the state?
*
* @return string
*
* @since 3.4
*/
public static function status($i, $value = 0, $canChange = false)
{
// Array of image, task, title, action.
$states = array(
-2 => array('trash', 'messages.unpublish', 'JTRASHED', 'COM_MESSAGES_MARK_AS_UNREAD'),
1 => array('publish', 'messages.unpublish', 'COM_MESSAGES_OPTION_READ', 'COM_MESSAGES_MARK_AS_UNREAD'),
0 => array('unpublish', 'messages.publish', 'COM_MESSAGES_OPTION_UNREAD', 'COM_MESSAGES_MARK_AS_READ'),
);
$state = ArrayHelper::getValue($states, (int) $value, $states[0]);
$icon = $state[0];
if ($canChange)
{
$html = '<a href="#" onclick="return listItemTask(\'cb' . $i . '\',\'' . $state[1] . '\')" class="btn btn-micro hasTooltip'
. ($value == 1 ? ' active' : '') . '" title="' . JHtml::_('tooltipText', $state[3])
. '"><span class="icon-' . $icon . '" aria-hidden="true"></span></a>';
}
return $html;
}
}