PageRenderTime 170ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/joomla/application/helper.php

https://gitlab.com/endomorphosis/greenrenaissancejoomla
PHP | 332 lines | 203 code | 58 blank | 71 comment | 30 complexity | 5f3d7466f497a8b69187159956586c82 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: helper.php 10027 2008-02-12 21:13:18Z ian $
  4. * @package Joomla.Framework
  5. * @subpackage Application
  6. * @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
  7. * @license GNU/GPL, see LICENSE.php
  8. * Joomla! is free software. This version may have been modified pursuant
  9. * to the GNU General Public License, and as distributed it includes or
  10. * is derivative of works licensed under the GNU General Public License or
  11. * other free or open source software licenses.
  12. * See COPYRIGHT.php for copyright notices and details.
  13. */
  14. // Check to ensure this file is within the rest of the framework
  15. defined('JPATH_BASE') or die();
  16. /**
  17. * Application helper functions
  18. *
  19. * @static
  20. * @package Joomla.Framework
  21. * @subpackage Application
  22. * @since 1.5
  23. */
  24. class JApplicationHelper
  25. {
  26. /**
  27. * Gets information on a specific client id. This method will be useful in
  28. * future versions when we start mapping applications in the database.
  29. *
  30. * @access public
  31. * @param int $id A client identifier
  32. * @param boolean $byName If True, find the client by it's name
  33. * @return mixed Object describing the client or false if not known
  34. * @since 1.5
  35. */
  36. function &getClientInfo($id = null, $byName = false)
  37. {
  38. static $clients;
  39. // Only create the array if it does not exist
  40. if (!is_array($clients))
  41. {
  42. $obj = new stdClass();
  43. // Site Client
  44. $obj->id = 0;
  45. $obj->name = 'site';
  46. $obj->path = JPATH_SITE;
  47. $clients[0] = clone($obj);
  48. // Administrator Client
  49. $obj->id = 1;
  50. $obj->name = 'administrator';
  51. $obj->path = JPATH_ADMINISTRATOR;
  52. $clients[1] = clone($obj);
  53. // Installation Client
  54. $obj->id = 2;
  55. $obj->name = 'installation';
  56. $obj->path = JPATH_INSTALLATION;
  57. $clients[2] = clone($obj);
  58. // XMLRPC Client
  59. $obj->id = 3;
  60. $obj->name = 'xmlrpc';
  61. $obj->path = JPATH_XMLRPC;
  62. $clients[3] = clone($obj);
  63. }
  64. //If no client id has been passed return the whole array
  65. if(is_null($id)) {
  66. return $clients;
  67. }
  68. // Are we looking for client information by id or by name?
  69. if (!$byName)
  70. {
  71. if (isset($clients[$id])){
  72. return $clients[$id];
  73. }
  74. }
  75. else
  76. {
  77. foreach ($clients as $client)
  78. {
  79. if ($client->name == strtolower($id)) {
  80. return $client;
  81. }
  82. }
  83. }
  84. $null = null;
  85. return $null;
  86. }
  87. /**
  88. * Get a path
  89. *
  90. * @access public
  91. * @param string $varname
  92. * @param string $user_option
  93. * @return string The requested path
  94. * @since 1.0
  95. */
  96. function getPath( $varname, $user_option=null )
  97. {
  98. // check needed for handling of custom/new module xml file loading
  99. $check = ( ( $varname == 'mod0_xml' ) || ( $varname == 'mod1_xml' ) );
  100. if ( !$user_option && !$check ) {
  101. $user_option = JRequest::getCmd('option');
  102. } else {
  103. $user_option = JFilterInput::clean($user_option, 'path');
  104. }
  105. $result = null;
  106. $name = substr( $user_option, 4 );
  107. switch ($varname) {
  108. case 'front':
  109. $result = JApplicationHelper::_checkPath( DS.'components'.DS. $user_option .DS. $name .'.php', 0 );
  110. break;
  111. case 'html':
  112. case 'front_html':
  113. if ( !( $result = JApplicationHelper::_checkPath( DS.'templates'.DS. JApplication::getTemplate() .DS.'components'.DS. $name .'.html.php', 0 ) ) ) {
  114. $result = JApplicationHelper::_checkPath( DS.'components'.DS. $user_option .DS. $name .'.html.php', 0 );
  115. }
  116. break;
  117. case 'toolbar':
  118. $result = JApplicationHelper::_checkPath( DS.'components'.DS. $user_option .DS.'toolbar.'. $name .'.php', -1 );
  119. break;
  120. case 'toolbar_html':
  121. $result = JApplicationHelper::_checkPath( DS.'components'.DS. $user_option .DS.'toolbar.'. $name .'.html.php', -1 );
  122. break;
  123. case 'toolbar_default':
  124. case 'toolbar_front':
  125. $result = JApplicationHelper::_checkPath( DS.'includes'.DS.'HTML_toolbar.php', 0 );
  126. break;
  127. case 'admin':
  128. $path = DS.'components'.DS. $user_option .DS.'admin.'. $name .'.php';
  129. $result = JApplicationHelper::_checkPath( $path, -1 );
  130. break;
  131. case 'admin_html':
  132. $path = DS.'components'.DS. $user_option .DS.'admin.'. $name .'.html.php';
  133. $result = JApplicationHelper::_checkPath( $path, -1 );
  134. break;
  135. case 'admin_functions':
  136. $path = DS.'components'.DS. $user_option .DS. $name .'.functions.php';
  137. $result = JApplicationHelper::_checkPath( $path, -1 );
  138. break;
  139. case 'class':
  140. if ( !( $result = JApplicationHelper::_checkPath( DS.'components'.DS. $user_option .DS. $name .'.class.php' ) ) ) {
  141. $result = JApplicationHelper::_checkPath( DS.'includes'.DS. $name .'.php' );
  142. }
  143. break;
  144. case 'helper':
  145. $path = DS.'components'.DS. $user_option .DS. $name .'.helper.php';
  146. $result = JApplicationHelper::_checkPath( $path );
  147. break;
  148. case 'com_xml':
  149. $path = DS.'components'.DS. $user_option .DS. $name .'.xml';
  150. $result = JApplicationHelper::_checkPath( $path, 1 );
  151. break;
  152. case 'mod0_xml':
  153. $path = DS.'modules'.DS. $user_option .DS. $user_option. '.xml';
  154. $result = JApplicationHelper::_checkPath( $path );
  155. break;
  156. case 'mod1_xml':
  157. // admin modules
  158. $path = DS.'modules'.DS. $user_option .DS. $user_option. '.xml';
  159. $result = JApplicationHelper::_checkPath( $path, -1 );
  160. break;
  161. case 'bot_xml':
  162. // legacy value
  163. case 'plg_xml':
  164. // Site plugins
  165. $path = DS.'plugins'.DS. $user_option .'.xml';
  166. $result = JApplicationHelper::_checkPath( $path, 0 );
  167. break;
  168. case 'menu_xml':
  169. $path = DS.'components'.DS.'com_menus'.DS. $user_option .DS. $user_option .'.xml';
  170. $result = JApplicationHelper::_checkPath( $path, -1 );
  171. break;
  172. }
  173. return $result;
  174. }
  175. function parseXMLInstallFile($path)
  176. {
  177. // Read the file to see if it's a valid component XML file
  178. $xml = & JFactory::getXMLParser('Simple');
  179. if (!$xml->loadFile($path)) {
  180. unset($xml);
  181. return false;
  182. }
  183. /*
  184. * Check for a valid XML root tag.
  185. *
  186. * Should be 'install', but for backward compatability we will accept 'mosinstall'.
  187. */
  188. if ( !is_object($xml->document) || ($xml->document->name() != 'install' && $xml->document->name() != 'mosinstall')) {
  189. unset($xml);
  190. return false;
  191. }
  192. $data = array();
  193. $element = & $xml->document->name[0];
  194. $data['name'] = $element ? $element->data() : '';
  195. $data['type'] = $element ? $xml->document->attributes("type") : '';
  196. $element = & $xml->document->creationDate[0];
  197. $data['creationdate'] = $element ? $element->data() : 'Unknown';
  198. $element = & $xml->document->author[0];
  199. $data['author'] = $element ? $element->data() : 'Unknown';
  200. $element = & $xml->document->copyright[0];
  201. $data['copyright'] = $element ? $element->data() : '';
  202. $element = & $xml->document->authoremail[0];
  203. $data['authorEmail'] = $element ? $element->data() : '';
  204. $element = & $xml->document->authorurl[0];
  205. $data['authorUrl'] = $element ? $element->data() : '';
  206. $element = & $xml->document->version[0];
  207. $data['version'] = $element ? $element->data() : '';
  208. $element = & $xml->document->description[0];
  209. $data['description'] = $element ? $element->data() : '';
  210. $element = & $xml->document->group[0];
  211. $data['group'] = $element ? $element->data() : '';
  212. return $data;
  213. }
  214. function parseXMLLangMetaFile($path)
  215. {
  216. // Read the file to see if it's a valid component XML file
  217. $xml = & JFactory::getXMLParser('Simple');
  218. if (!$xml->loadFile($path)) {
  219. unset($xml);
  220. return false;
  221. }
  222. /*
  223. * Check for a valid XML root tag.
  224. *
  225. * Should be 'langMetaData'.
  226. */
  227. if ($xml->document->name() != 'metafile') {
  228. unset($xml);
  229. return false;
  230. }
  231. $data = array();
  232. $element = & $xml->document->name[0];
  233. $data['name'] = $element ? $element->data() : '';
  234. $data['type'] = $element ? $xml->document->attributes("type") : '';
  235. $element = & $xml->document->creationDate[0];
  236. $data['creationdate'] = $element ? $element->data() : 'Unknown';
  237. $element = & $xml->document->author[0];
  238. $data['author'] = $element ? $element->data() : 'Unknown';
  239. $element = & $xml->document->copyright[0];
  240. $data['copyright'] = $element ? $element->data() : '';
  241. $element = & $xml->document->authorEmail[0];
  242. $data['authorEmail'] = $element ? $element->data() : '';
  243. $element = & $xml->document->authorUrl[0];
  244. $data['authorUrl'] = $element ? $element->data() : '';
  245. $element = & $xml->document->version[0];
  246. $data['version'] = $element ? $element->data() : '';
  247. $element = & $xml->document->description[0];
  248. $data['description'] = $element ? $element->data() : '';
  249. $element = & $xml->document->group[0];
  250. $data['group'] = $element ? $element->group() : '';
  251. return $data;
  252. }
  253. /**
  254. * Tries to find a file in the administrator or site areas
  255. *
  256. * @access private
  257. * @param string $parth A file name
  258. * @param integer $checkAdmin 0 to check site only, 1 to check site and admin, -1 to check admin only
  259. * @since 1.5
  260. */
  261. function _checkPath( $path, $checkAdmin=1 )
  262. {
  263. $file = JPATH_SITE . $path;
  264. if ($checkAdmin > -1 && file_exists( $file )) {
  265. return $file;
  266. } else if ($checkAdmin != 0) {
  267. $file = JPATH_ADMINISTRATOR . $path;
  268. if (file_exists( $file )) {
  269. return $file;
  270. }
  271. }
  272. return null;
  273. }
  274. }