1 <?php
2 /**
3 * @package Joomla.Libraries
4 * @subpackage Helper
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE.txt
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 /**
13 * Helper for standard content style extensions.
14 * This class mainly simplifies static helper methods often repeated in individual components
15 *
16 * @since 3.1
17 */
18 class JHelperContent
19 {
20 /**
21 * Configure the Linkbar. Must be implemented by each extension.
22 *
23 * @param string $vName The name of the active view.
24 *
25 * @return void
26 *
27 * @since 3.1
28 */
29 public static function addSubmenu($vName)
30 {
31 }
32
33 /**
34 * Gets a list of the actions that can be performed.
35 *
36 * @param integer $categoryId The category ID.
37 * @param integer $id The item ID.
38 * @param string $assetName The asset name
39 *
40 * @return JObject
41 *
42 * @since 3.1
43 * @deprecated 3.2 Use JHelperContent::getActions() instead
44 */
45 public static function _getActions($categoryId = 0, $id = 0, $assetName = '')
46 {
47 // Log usage of deprecated function
48 JLog::add(__METHOD__ . '() is deprecated, use JHelperContent::getActions() with new arguments order instead.', JLog::WARNING, 'deprecated');
49
50 // Reverted a change for version 2.5.6
51 $user = JFactory::getUser();
52 $result = new JObject;
53
54 $path = JPATH_ADMINISTRATOR . '/components/' . $assetName . '/access.xml';
55
56 if (empty($id) && empty($categoryId))
57 {
58 $section = 'component';
59 }
60 elseif (empty($id))
61 {
62 $section = 'category';
63 $assetName .= '.category.' . (int) $categoryId;
64 }
65 else
66 {
67 // Used only in com_content
68 $section = 'article';
69 $assetName .= '.article.' . (int) $id;
70 }
71
72 $actions = JAccess::getActionsFromFile($path, "/access/section[@name='" . $section . "']/");
73
74 foreach ($actions as $action)
75 {
76 $result->set($action->name, $user->authorise($action->name, $assetName));
77 }
78
79 return $result;
80 }
81
82 /**
83 * Gets a list of the actions that can be performed.
84 *
85 * @param string $component The component name.
86 * @param string $section The access section name.
87 * @param integer $id The item ID.
88 *
89 * @return JObject
90 *
91 * @since 3.2
92 */
93 public static function getActions($component = '', $section = '', $id = 0)
94 {
95 // Check for deprecated arguments order
96 if (is_int($component) || $component === null)
97 {
98 $result = self::_getActions($component, $section, $id);
99
100 return $result;
101 }
102
103 $assetName = $component;
104
105 if ($section && $id)
106 {
107 $assetName .= '.' . $section . '.' . (int) $id;
108 }
109
110 $result = new JObject;
111
112 $user = JFactory::getUser();
113
114 $actions = JAccess::getActionsFromFile(
115 JPATH_ADMINISTRATOR . '/components/' . $component . '/access.xml', '/access/section[@name="component"]/'
116 );
117
118 if ($actions === false)
119 {
120 JLog::add(
121 JText::sprintf('JLIB_ERROR_COMPONENTS_ACL_CONFIGURATION_FILE_MISSING_OR_IMPROPERLY_STRUCTURED', $component), JLog::ERROR, 'jerror'
122 );
123
124 return $result;
125 }
126
127 foreach ($actions as $action)
128 {
129 $result->set($action->name, $user->authorise($action->name, $assetName));
130 }
131
132 return $result;
133 }
134
135 /**
136 * Gets the current language
137 *
138 * @param boolean $detectBrowser Flag indicating whether to use the browser language as a fallback.
139 *
140 * @return string The language string
141 *
142 * @since 3.1
143 * @note JHelper::getCurrentLanguage is the preferred method
144 */
145 public static function getCurrentLanguage($detectBrowser = true)
146 {
147 $app = JFactory::getApplication();
148 $langCode = $app->input->cookie->getString(JApplicationHelper::getHash('language'));
149
150 // No cookie - let's try to detect browser language or use site default
151 if (!$langCode)
152 {
153 if ($detectBrowser)
154 {
155 $langCode = JLanguageHelper::detectLanguage();
156 }
157 else
158 {
159 $langCode = JComponentHelper::getParams('com_languages')->get('site', 'en-GB');
160 }
161 }
162
163 return $langCode;
164 }
165
166 /**
167 * Gets the associated language ID
168 *
169 * @param string $langCode The language code to look up
170 *
171 * @return integer The language ID
172 *
173 * @since 3.1
174 * @note JHelper::getLanguage() is the preferred method.
175 */
176 public static function getLanguageId($langCode)
177 {
178 $db = JFactory::getDbo();
179 $query = $db->getQuery(true)
180 ->select('lang_id')
181 ->from('#__languages')
182 ->where($db->quoteName('lang_code') . ' = ' . $db->quote($langCode));
183 $db->setQuery($query);
184
185 return $db->loadResult();
186 }
187
188 /**
189 * Gets a row of data from a table
190 *
191 * @param JTable $table JTable instance for a row.
192 *
193 * @return array Associative array of all columns and values for a row in a table.
194 *
195 * @since 3.1
196 */
197 public function getRowData(JTable $table)
198 {
199 $data = new JHelper;
200
201 return $data->getRowData($table);
202 }
203 }
204