forked from anahitasocial/anahita
/
helper.php
331 lines (274 loc) · 9.13 KB
/
helper.php
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<?php
/**
* @version $Id: helper.php 14401 2010-01-26 14:10:00Z louis $
* @package Joomla.Framework
* @subpackage Application
* @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
// Check to ensure this file is within the rest of the framework
defined('JPATH_BASE') or die();
/**
* Application helper functions
*
* @static
* @package Joomla.Framework
* @subpackage Application
* @since 1.5
*/
class JApplicationHelper
{
/**
* Gets information on a specific client id. This method will be useful in
* future versions when we start mapping applications in the database.
*
* @access public
* @param int $id A client identifier
* @param boolean $byName If True, find the client by it's name
* @return mixed Object describing the client or false if not known
* @since 1.5
*/
public static function &getClientInfo($id = null, $byName = false)
{
static $clients;
// Only create the array if it does not exist
if (!is_array($clients))
{
$obj = new stdClass();
// Site Client
$obj->id = 0;
$obj->name = 'site';
$obj->path = JPATH_SITE;
$clients[0] = clone($obj);
// Administrator Client
$obj->id = 1;
$obj->name = 'administrator';
$obj->path = JPATH_ADMINISTRATOR;
$clients[1] = clone($obj);
// Installation Client
$obj->id = 2;
$obj->name = 'installation';
$obj->path = JPATH_INSTALLATION;
$clients[2] = clone($obj);
}
//If no client id has been passed return the whole array
if(is_null($id)) {
return $clients;
}
// Are we looking for client information by id or by name?
if (!$byName)
{
if (isset($clients[$id])){
return $clients[$id];
}
}
else
{
foreach ($clients as $client)
{
if ($client->name == strtolower($id)) {
return $client;
}
}
}
$null = null;
return $null;
}
/**
* Get a path
*
* @access public
* @param string $varname
* @param string $user_option
* @return string The requested path
* @since 1.0
*/
public static function getPath( $varname, $user_option=null )
{
// check needed for handling of custom/new module xml file loading
$check = ( ( $varname == 'mod0_xml' ) || ( $varname == 'mod1_xml' ) );
if ( !$user_option && !$check ) {
$user_option = JRequest::getCmd('option');
} else {
$user_option = JFilterInput::clean($user_option, 'path');
}
$result = null;
$name = substr( $user_option, 4 );
switch ($varname) {
case 'front':
$result = JApplicationHelper::_checkPath( DS.'components'.DS. $user_option .DS. $name .'.php', 0 );
break;
case 'html':
case 'front_html':
if ( !( $result = JApplicationHelper::_checkPath( DS.'templates'.DS. JApplication::getTemplate() .DS.'components'.DS. $name .'.html.php', 0 ) ) ) {
$result = JApplicationHelper::_checkPath( DS.'components'.DS. $user_option .DS. $name .'.html.php', 0 );
}
break;
case 'toolbar':
$result = JApplicationHelper::_checkPath( DS.'components'.DS. $user_option .DS.'toolbar.'. $name .'.php', -1 );
break;
case 'toolbar_html':
$result = JApplicationHelper::_checkPath( DS.'components'.DS. $user_option .DS.'toolbar.'. $name .'.html.php', -1 );
break;
case 'toolbar_default':
case 'toolbar_front':
$result = JApplicationHelper::_checkPath( DS.'includes'.DS.'HTML_toolbar.php', 0 );
break;
case 'admin':
$path = DS.'components'.DS. $user_option .DS.'admin.'. $name .'.php';
$result = JApplicationHelper::_checkPath( $path, -1 );
if ($result == null) {
$path = DS.'components'.DS. $user_option .DS. $name .'.php';
$result = JApplicationHelper::_checkPath( $path, -1 );
}
break;
case 'admin_html':
$path = DS.'components'.DS. $user_option .DS.'admin.'. $name .'.html.php';
$result = JApplicationHelper::_checkPath( $path, -1 );
break;
case 'admin_functions':
$path = DS.'components'.DS. $user_option .DS. $name .'.functions.php';
$result = JApplicationHelper::_checkPath( $path, -1 );
break;
case 'class':
if ( !( $result = JApplicationHelper::_checkPath( DS.'components'.DS. $user_option .DS. $name .'.class.php' ) ) ) {
$result = JApplicationHelper::_checkPath( DS.'includes'.DS. $name .'.php' );
}
break;
case 'helper':
$path = DS.'components'.DS. $user_option .DS. $name .'.helper.php';
$result = JApplicationHelper::_checkPath( $path );
break;
case 'com_xml':
$path = DS.'components'.DS. $user_option .DS. $name .'.xml';
$result = JApplicationHelper::_checkPath( $path, 1 );
break;
case 'mod0_xml':
$path = DS.'modules'.DS. $user_option .DS. $user_option. '.xml';
$result = JApplicationHelper::_checkPath( $path );
break;
case 'mod1_xml':
// admin modules
$path = DS.'modules'.DS. $user_option .DS. $user_option. '.xml';
$result = JApplicationHelper::_checkPath( $path, -1 );
break;
case 'bot_xml':
// legacy value
case 'plg_xml':
// Site plugins
$path = DS.'plugins'.DS. $user_option .'.xml';
$result = JApplicationHelper::_checkPath( $path, 0 );
break;
case 'menu_xml':
$path = DS.'components'.DS.'com_menus'.DS. $user_option .DS. $user_option .'.xml';
$result = JApplicationHelper::_checkPath( $path, -1 );
break;
}
return $result;
}
public static function parseXMLInstallFile($path)
{
// Read the file to see if it's a valid component XML file
$xml = & JFactory::getXMLParser('Simple');
if (!$xml->loadFile($path)) {
unset($xml);
return false;
}
/*
* Check for a valid XML root tag.
*
* Should be 'install', but for backward compatability we will accept 'mosinstall'.
*/
if ( !is_object($xml->document) || ($xml->document->name() != 'install' && $xml->document->name() != 'mosinstall')) {
unset($xml);
return false;
}
$data = array();
$data['legacy'] = $xml->document->name() == 'mosinstall';
$element = & $xml->document->name[0];
$data['name'] = $element ? $element->data() : '';
$data['type'] = $element ? $xml->document->attributes("type") : '';
$element = & $xml->document->creationDate[0];
$data['creationdate'] = $element ? $element->data() : JText::_('Unknown');
$element = & $xml->document->author[0];
$data['author'] = $element ? $element->data() : JText::_('Unknown');
$element = & $xml->document->copyright[0];
$data['copyright'] = $element ? $element->data() : '';
$element = & $xml->document->authorEmail[0];
$data['authorEmail'] = $element ? $element->data() : '';
$element = & $xml->document->authorUrl[0];
$data['authorUrl'] = $element ? $element->data() : '';
$element = & $xml->document->version[0];
$data['version'] = $element ? $element->data() : '';
$element = & $xml->document->description[0];
$data['description'] = $element ? $element->data() : '';
$element = & $xml->document->group[0];
$data['group'] = $element ? $element->data() : '';
return $data;
}
public static function parseXMLLangMetaFile($path)
{
// Read the file to see if it's a valid component XML file
$xml = & JFactory::getXMLParser('Simple');
if (!$xml->loadFile($path)) {
unset($xml);
return false;
}
/*
* Check for a valid XML root tag.
*
* Should be 'langMetaData'.
*/
if ($xml->document->name() != 'metafile') {
unset($xml);
return false;
}
$data = array();
$element = & $xml->document->name[0];
$data['name'] = $element ? $element->data() : '';
$data['type'] = $element ? $xml->document->attributes("type") : '';
$element = & $xml->document->creationDate[0];
$data['creationdate'] = $element ? $element->data() : JText::_('Unknown');
$element = & $xml->document->author[0];
$data['author'] = $element ? $element->data() : JText::_('Unknown');
$element = & $xml->document->copyright[0];
$data['copyright'] = $element ? $element->data() : '';
$element = & $xml->document->authorEmail[0];
$data['authorEmail'] = $element ? $element->data() : '';
$element = & $xml->document->authorUrl[0];
$data['authorUrl'] = $element ? $element->data() : '';
$element = & $xml->document->version[0];
$data['version'] = $element ? $element->data() : '';
$element = & $xml->document->description[0];
$data['description'] = $element ? $element->data() : '';
$element = & $xml->document->group[0];
$data['group'] = $element ? $element->group() : '';
return $data;
}
/**
* Tries to find a file in the administrator or site areas
*
* @access private
* @param string $parth A file name
* @param integer $checkAdmin 0 to check site only, 1 to check site and admin, -1 to check admin only
* @since 1.5
*/
private static function _checkPath( $path, $checkAdmin=1 )
{
$file = JPATH_SITE . $path;
if ($checkAdmin > -1 && file_exists( $file )) {
return $file;
} else if ($checkAdmin != 0) {
$file = JPATH_ADMINISTRATOR . $path;
if (file_exists( $file )) {
return $file;
}
}
return null;
}
}