1 <?php
2 /**
3 * @package Joomla.Libraries
4 * @subpackage Version
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 * Version information class for the Joomla CMS.
14 *
15 * @since 1.0
16 */
17 final class JVersion
18 {
19 /**
20 * Product name.
21 *
22 * @var string
23 * @since 3.5
24 */
25 const PRODUCT = 'Joomla!';
26
27 /**
28 * Release version.
29 *
30 * @var string
31 * @since 3.5
32 */
33 const RELEASE = '3.7';
34
35 /**
36 * Maintenance version.
37 *
38 * @var string
39 * @since 3.5
40 */
41 const DEV_LEVEL = '3';
42
43 /**
44 * Development status.
45 *
46 * @var string
47 * @since 3.5
48 */
49 const DEV_STATUS = 'Stable';
50
51 /**
52 * Build number.
53 *
54 * @var string
55 * @since 3.5
56 */
57 const BUILD = '';
58
59 /**
60 * Code name.
61 *
62 * @var string
63 * @since 3.5
64 */
65 const CODENAME = 'Amani';
66
67 /**
68 * Release date.
69 *
70 * @var string
71 * @since 3.5
72 */
73 const RELDATE = '4-July-2017';
74
75 /**
76 * Release time.
77 *
78 * @var string
79 * @since 3.5
80 */
81 const RELTIME = '08:03';
82
83 /**
84 * Release timezone.
85 *
86 * @var string
87 * @since 3.5
88 */
89 const RELTZ = 'GMT';
90
91 /**
92 * Copyright Notice.
93 *
94 * @var string
95 * @since 3.5
96 */
97 const COPYRIGHT = 'Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.';
98
99 /**
100 * Link text.
101 *
102 * @var string
103 * @since 3.5
104 */
105 const URL = '<a href="https://www.joomla.org">Joomla!</a> is Free Software released under the GNU General Public License.';
106
107 /**
108 * Magic getter providing access to constants previously defined as class member vars.
109 *
110 * @param string $name The name of the property.
111 *
112 * @return mixed A value if the property name is valid.
113 *
114 * @since 3.5
115 * @deprecated 4.0 Access the constants directly
116 */
117 public function __get($name)
118 {
119 if (defined("JVersion::$name"))
120 {
121 JLog::add(
122 'Accessing JVersion data through class member variables is deprecated, use the corresponding constant instead.',
123 JLog::WARNING,
124 'deprecated'
125 );
126
127 return constant("JVersion::$name");
128 }
129
130 $trace = debug_backtrace();
131 trigger_error(
132 'Undefined constant via __get(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'],
133 E_USER_NOTICE
134 );
135 }
136
137 /**
138 * Check if we are in development mode
139 *
140 * @return boolean
141 *
142 * @since 3.4.3
143 */
144 public function isInDevelopmentState()
145 {
146 return strtolower(self::DEV_STATUS) !== 'stable';
147 }
148
149 /**
150 * Compares two a "PHP standardized" version number against the current Joomla version.
151 *
152 * @param string $minimum The minimum version of the Joomla which is compatible.
153 *
154 * @return boolean True if the version is compatible.
155 *
156 * @link https://secure.php.net/version_compare
157 * @since 1.0
158 */
159 public function isCompatible($minimum)
160 {
161 return version_compare(JVERSION, $minimum, 'ge');
162 }
163
164 /**
165 * Method to get the help file version.
166 *
167 * @return string Version suffix for help files.
168 *
169 * @since 1.0
170 */
171 public function getHelpVersion()
172 {
173 return '.' . str_replace('.', '', self::RELEASE);
174 }
175
176 /**
177 * Gets a "PHP standardized" version string for the current Joomla.
178 *
179 * @return string Version string.
180 *
181 * @since 1.5
182 */
183 public function getShortVersion()
184 {
185 return self::RELEASE . '.' . self::DEV_LEVEL;
186 }
187
188 /**
189 * Gets a version string for the current Joomla with all release information.
190 *
191 * @return string Complete version string.
192 *
193 * @since 1.5
194 */
195 public function getLongVersion()
196 {
197 return self::PRODUCT . ' ' . self::RELEASE . '.' . self::DEV_LEVEL . ' '
198 . self::DEV_STATUS . ' [ ' . self::CODENAME . ' ] ' . self::RELDATE . ' '
199 . self::RELTIME . ' ' . self::RELTZ;
200 }
201
202 /**
203 * Returns the user agent.
204 *
205 * @param string $component Name of the component.
206 * @param bool $mask Mask as Mozilla/5.0 or not.
207 * @param bool $add_version Add version afterwards to component.
208 *
209 * @return string User Agent.
210 *
211 * @since 1.0
212 */
213 public function getUserAgent($component = null, $mask = false, $add_version = true)
214 {
215 if ($component === null)
216 {
217 $component = 'Framework';
218 }
219
220 if ($add_version)
221 {
222 $component .= '/' . self::RELEASE;
223 }
224
225 // If masked pretend to look like Mozilla 5.0 but still identify ourselves.
226 if ($mask)
227 {
228 return 'Mozilla/5.0 ' . self::PRODUCT . '/' . self::RELEASE . '.' . self::DEV_LEVEL . ($component ? ' ' . $component : '');
229 }
230 else
231 {
232 return self::PRODUCT . '/' . self::RELEASE . '.' . self::DEV_LEVEL . ($component ? ' ' . $component : '');
233 }
234 }
235
236 /**
237 * Generate a media version string for assets
238 * Public to allow third party developers to use it
239 *
240 * @return string
241 *
242 * @since 3.2
243 */
244 public function generateMediaVersion()
245 {
246 $date = new JDate;
247
248 return md5($this->getLongVersion() . JFactory::getConfig()->get('secret') . $date->toSql());
249 }
250
251 /**
252 * Gets a media version which is used to append to Joomla core media files.
253 *
254 * This media version is used to append to Joomla core media in order to trick browsers into
255 * reloading the CSS and JavaScript, because they think the files are renewed.
256 * The media version is renewed after Joomla core update, install, discover_install and uninstallation.
257 *
258 * @return string The media version.
259 *
260 * @since 3.2
261 */
262 public function getMediaVersion()
263 {
264 // Load the media version and cache it for future use
265 static $mediaVersion = null;
266
267 if ($mediaVersion === null)
268 {
269 // Get the joomla library params
270 $params = JLibraryHelper::getParams('joomla');
271
272 // Get the media version
273 $mediaVersion = $params->get('mediaversion', '');
274
275 // Refresh assets in debug mode or when the media version is not set
276 if (JDEBUG || empty($mediaVersion))
277 {
278 $mediaVersion = $this->generateMediaVersion();
279
280 $this->setMediaVersion($mediaVersion);
281 }
282 }
283
284 return $mediaVersion;
285 }
286
287 /**
288 * Function to refresh the media version
289 *
290 * @return JVersion Instance of $this to allow chaining.
291 *
292 * @since 3.2
293 */
294 public function refreshMediaVersion()
295 {
296 $newMediaVersion = $this->generateMediaVersion();
297
298 return $this->setMediaVersion($newMediaVersion);
299 }
300
301 /**
302 * Sets the media version which is used to append to Joomla core media files.
303 *
304 * @param string $mediaVersion The media version.
305 *
306 * @return JVersion Instance of $this to allow chaining.
307 *
308 * @since 3.2
309 */
310 public function setMediaVersion($mediaVersion)
311 {
312 // Do not allow empty media versions
313 if (!empty($mediaVersion))
314 {
315 // Get library parameters
316 $params = JLibraryHelper::getParams('joomla');
317
318 $params->set('mediaversion', $mediaVersion);
319
320 // Save modified params
321 JLibraryHelper::saveParams('joomla', $params);
322 }
323
324 return $this;
325 }
326 }
327