contentadministrator.php
3.75 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/**
* @package Joomla.Administrator
* @subpackage com_content
*
* @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;
JLoader::register('ContentHelper', JPATH_ADMINISTRATOR . '/components/com_content/helpers/content.php');
/**
* Content HTML helper
*
* @since 3.0
*/
abstract class JHtmlContentAdministrator
{
/**
* Render the list of associated items
*
* @param integer $articleid The article item id
*
* @return string The language HTML
*
* @throws Exception
*/
public static function association($articleid)
{
// Defaults
$html = '';
// Get the associations
if ($associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $articleid))
{
foreach ($associations as $tag => $associated)
{
$associations[$tag] = (int) $associated->id;
}
// Get the associated menu items
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('c.*')
->select('l.sef as lang_sef')
->select('l.lang_code')
->from('#__content as c')
->select('cat.title as category_title')
->join('LEFT', '#__categories as cat ON cat.id=c.catid')
->where('c.id IN (' . implode(',', array_values($associations)) . ')')
->where('c.id != ' . $articleid)
->join('LEFT', '#__languages as l ON c.language=l.lang_code')
->select('l.image')
->select('l.title as language_title');
$db->setQuery($query);
try
{
$items = $db->loadObjectList('id');
}
catch (RuntimeException $e)
{
throw new Exception($e->getMessage(), 500, $e);
}
if ($items)
{
foreach ($items as &$item)
{
$text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX';
$url = JRoute::_('index.php?option=com_content&task=article.edit&id=' . (int) $item->id);
$tooltip = htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '<br />' . JText::sprintf('JCATEGORY_SPRINTF', $item->category_title);
$classes = 'hasPopover label label-association label-' . $item->lang_sef;
$item->link = '<a href="' . $url . '" title="' . $item->language_title . '" class="' . $classes
. '" data-content="' . $tooltip . '" data-placement="top">'
. $text . '</a>';
}
}
JHtml::_('bootstrap.popover');
$html = JLayoutHelper::render('joomla.content.associations', $items);
}
return $html;
}
/**
* Show the feature/unfeature links
*
* @param integer $value The state value
* @param integer $i Row number
* @param boolean $canChange Is user allowed to change?
*
* @return string HTML code
*/
public static function featured($value = 0, $i, $canChange = true)
{
JHtml::_('bootstrap.tooltip');
// Array of image, task, title, action
$states = array(
0 => array('unfeatured', 'articles.featured', 'COM_CONTENT_UNFEATURED', 'JGLOBAL_TOGGLE_FEATURED'),
1 => array('featured', 'articles.unfeatured', 'COM_CONTENT_FEATURED', 'JGLOBAL_TOGGLE_FEATURED'),
);
$state = ArrayHelper::getValue($states, (int) $value, $states[1]);
$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>';
}
else
{
$html = '<a class="btn btn-micro hasTooltip disabled' . ($value == 1 ? ' active' : '') . '" title="'
. JHtml::_('tooltipText', $state[2]) . '"><span class="icon-' . $icon . '" aria-hidden="true"></span></a>';
}
return $html;
}
}