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 JHtmlTag
20 {
21 22 23 24 25 26
27 protected static $items = array();
28
29 30 31 32 33 34 35 36 37 38
39 public static function options($config = array('filter.published' => array(0, 1)))
40 {
41 $hash = md5(serialize($config));
42
43 if (!isset(static::$items[$hash]))
44 {
45 $config = (array) $config;
46 $db = JFactory::getDbo();
47 $query = $db->getQuery(true)
48 ->select('a.id, a.title, a.level')
49 ->from('#__tags AS a')
50 ->where('a.parent_id > 0');
51
52
53 if (isset($config['filter.published']))
54 {
55 if (is_numeric($config['filter.published']))
56 {
57 $query->where('a.published = ' . (int) $config['filter.published']);
58 }
59 elseif (is_array($config['filter.published']))
60 {
61 $config['filter.published'] = ArrayHelper::toInteger($config['filter.published']);
62 $query->where('a.published IN (' . implode(',', $config['filter.published']) . ')');
63 }
64 }
65
66
67 if (isset($config['filter.language']))
68 {
69 if (is_string($config['filter.language']))
70 {
71 $query->where('a.language = ' . $db->quote($config['filter.language']));
72 }
73 elseif (is_array($config['filter.language']))
74 {
75 foreach ($config['filter.language'] as &$language)
76 {
77 $language = $db->quote($language);
78 }
79
80 $query->where('a.language IN (' . implode(',', $config['filter.language']) . ')');
81 }
82 }
83
84 $query->order('a.lft');
85
86 $db->setQuery($query);
87 $items = $db->loadObjectList();
88
89
90 static::$items[$hash] = array();
91
92 foreach ($items as &$item)
93 {
94 $repeat = ($item->level - 1 >= 0) ? $item->level - 1 : 0;
95 $item->title = str_repeat('- ', $repeat) . $item->title;
96 static::$items[$hash][] = JHtml::_('select.option', $item->id, $item->title);
97 }
98 }
99
100 return static::$items[$hash];
101 }
102
103 104 105 106 107 108 109 110 111
112 public static function tags($config = array('filter.published' => array(0, 1)))
113 {
114 $hash = md5(serialize($config));
115 $config = (array) $config;
116 $db = JFactory::getDbo();
117 $query = $db->getQuery(true)
118 ->select('a.id, a.title, a.level, a.parent_id')
119 ->from('#__tags AS a')
120 ->where('a.parent_id > 0');
121
122
123 if (isset($config['filter.published']))
124 {
125 if (is_numeric($config['filter.published']))
126 {
127 $query->where('a.published = ' . (int) $config['filter.published']);
128 }
129 elseif (is_array($config['filter.published']))
130 {
131 $config['filter.published'] = ArrayHelper::toInteger($config['filter.published']);
132 $query->where('a.published IN (' . implode(',', $config['filter.published']) . ')');
133 }
134 }
135
136 $query->order('a.lft');
137
138 $db->setQuery($query);
139 $items = $db->loadObjectList();
140
141
142 static::$items[$hash] = array();
143
144 foreach ($items as &$item)
145 {
146 $repeat = ($item->level - 1 >= 0) ? $item->level - 1 : 0;
147 $item->title = str_repeat('- ', $repeat) . $item->title;
148 static::$items[$hash][] = JHtml::_('select.option', $item->id, $item->title);
149 }
150
151 return static::$items[$hash];
152 }
153
154 155 156 157 158 159 160 161 162 163
164 public static function ajaxfield($selector = '#jform_tags', $allowCustom = true)
165 {
166
167 $params = JComponentHelper::getParams('com_tags');
168 $minTermLength = (int) $params->get('min_term_length', 3);
169
170 $displayData = array(
171 'minTermLength' => $minTermLength,
172 'selector' => $selector,
173 'allowCustom' => JFactory::getUser()->authorise('core.create', 'com_tags') ? $allowCustom : false,
174 );
175
176 JLayoutHelper::render('joomla.html.tag', $displayData);
177
178 return;
179 }
180 }
181