PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/OX/Plugin/ParserBase.php

https://github.com/orchestra-io/sample-openx
PHP | 308 lines | 253 code | 22 blank | 33 comment | 7 complexity | ccf3a758930f41ff2ef53df79d0fc12e MD5 | raw file
  1. <?php
  2. /*
  3. +---------------------------------------------------------------------------+
  4. | OpenX v${RELEASE_MAJOR_MINOR} |
  5. | =======${RELEASE_MAJOR_MINOR_DOUBLE_UNDERLINE} |
  6. | |
  7. | Copyright (c) 2003-2009 OpenX Limited |
  8. | For contact details, see: http://www.openx.org/ |
  9. | |
  10. | This program is free software; you can redistribute it and/or modify |
  11. | it under the terms of the GNU General Public License as published by |
  12. | the Free Software Foundation; either version 2 of the License, or |
  13. | (at your option) any later version. |
  14. | |
  15. | This program is distributed in the hope that it will be useful, |
  16. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  17. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  18. | GNU General Public License for more details. |
  19. | |
  20. | You should have received a copy of the GNU General Public License |
  21. | along with this program; if not, write to the Free Software |
  22. | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
  23. +---------------------------------------------------------------------------+
  24. $Id: ParserBase.php 47378 2009-12-11 19:42:32Z matthieu.aubry $
  25. */
  26. require_once 'XML/Parser.php';
  27. /**
  28. * Parses an XML plugin install file
  29. *
  30. * @package OpenXPlugin
  31. * @author Monique Szpak <monique.szpak@openx.org>
  32. */
  33. class OX_ParserBase extends XML_Parser
  34. {
  35. var $aPlugin = array();
  36. var $aInstall = array();
  37. var $aUninstall = array();
  38. var $aConf = array();
  39. var $aSettings = array();
  40. var $aPrefs = array();
  41. var $aFiles = array();
  42. var $aFile = array();
  43. var $aSyscheck = array();
  44. var $aDbms = array();
  45. var $aPhp = array();
  46. var $aDepends = array();
  47. var $aData = array();
  48. var $aAllFiles = array();
  49. var $elements = array();
  50. var $element = '';
  51. var $count = 0;
  52. var $error;
  53. function __construct()
  54. {
  55. // force ISO-8859-1 due to different defaults for PHP4 and PHP5
  56. // todo: this probably needs to be investigated some more andcleaned up
  57. parent::XML_Parser('ISO-8859-1');
  58. }
  59. function OX_ParserBase()
  60. {
  61. $this->__construct();
  62. }
  63. private function _initArray()
  64. {
  65. $this->aSettings = array();
  66. $this->aPrefs = array();
  67. $this->aFiles = array();
  68. $this->aFile = array();
  69. $this->aDbms = array();
  70. $this->aPhp = array();
  71. $this->aDepends = array();
  72. $this->aConf = array(
  73. 'option' =>'',
  74. 'settings' =>array(),
  75. 'preferences' =>array(),
  76. );
  77. $this->aSyscheck = array(
  78. 'php' =>array(),
  79. 'dbms' =>array(),
  80. 'depends' =>array(),
  81. );
  82. $this->aInstall = array(
  83. 'conf' =>array(),
  84. 'syscheck' =>array(),
  85. 'files' =>array(),
  86. 'prescript' =>'',
  87. 'postscript' =>'',
  88. );
  89. $this->aUninstall = array(
  90. 'prescript' =>'',
  91. 'postscript' =>'',
  92. );
  93. $this->aPlugin = array(
  94. 'name' => '',
  95. 'creationdate' => '',
  96. 'author' => '',
  97. 'authoremail' => '',
  98. 'authorurl' => '',
  99. 'license' => '',
  100. 'description' => '',
  101. 'version' => '',
  102. 'oxversion' => '',
  103. 'extends' => '',
  104. 'install' => array(),
  105. 'upgrade' => array(),
  106. 'uninstall' => array(),
  107. );
  108. }
  109. private function _assignArray()
  110. {
  111. $this->aConf['settings'] = $this->aSettings;
  112. $this->aConf['preferences'] = $this->aPrefs;
  113. $this->aSyscheck['dbms'] = $this->aDbms;
  114. $this->aSyscheck['php'] = $this->aPhp;
  115. $this->aSyscheck['depends'] = $this->aDepends;
  116. $this->aInstall['conf'] = $this->aConf;
  117. $this->aInstall['syscheck'] = $this->aSyscheck;
  118. $this->aInstall['files'] = $this->aFiles;
  119. $this->aPlugin['install'] = $this->aInstall;
  120. $this->aPlugin['uninstall'] = $this->aUninstall;
  121. $this->aPlugin['upgrade'] = @$this->aUpgrade;
  122. $this->aPlugin['allfiles'] = $this->aAllFiles;
  123. }
  124. function startHandler($xp, $element, $attribs)
  125. {
  126. $this->elements[$this->count++] = strtolower($element);
  127. $this->element = implode('-', $this->elements);
  128. switch ($this->element)
  129. {
  130. case 'plugin':
  131. $this->_initArray();
  132. break;
  133. case 'plugin-install-files-file':
  134. $this->aData = array();
  135. foreach ($attribs AS $k => $v)
  136. {
  137. $this->aData[strtolower($k)] = $v;
  138. }
  139. break;
  140. case 'plugin-install-syscheck-depends-plugin':
  141. $this->aData = array();
  142. foreach ($attribs AS $k => $v)
  143. {
  144. $this->aData[strtolower($k)] = $v;
  145. }
  146. break;
  147. case 'plugin-install-syscheck-dbms':
  148. $this->aData = array();
  149. break;
  150. case 'plugin-install-syscheck-php-setting':
  151. $this->aData = array();
  152. foreach ($attribs AS $k => $v)
  153. {
  154. $this->aData[strtolower($k)] = $v;
  155. }
  156. break;
  157. }
  158. }
  159. function endHandler($xp, $element)
  160. {
  161. switch ($this->element)
  162. {
  163. case 'plugin':
  164. $this->_assignArray();
  165. break;
  166. case 'plugin-install-files-file':
  167. $this->aFiles[] = $this->aData;
  168. $this->aAllFiles[] = $this->aData;
  169. break;
  170. case 'plugin-install-syscheck-depends-plugin':
  171. $this->aDepends[] = $this->aData;
  172. break;
  173. case 'plugin-install-syscheck-dbms':
  174. $this->aDbms[] = $this->aData;
  175. break;
  176. case 'plugin-install-syscheck-php-setting':
  177. $this->aPhp[] = $this->aData;
  178. break;
  179. case 'plugin-install-prescript':
  180. $this->aAllFiles[] = array('name'=>$this->aInstall['prescript'], 'path'=>OX_PLUGIN_GROUPPATH.'/etc/');
  181. break;
  182. case 'plugin-install-postscript':
  183. $this->aAllFiles[] = array('name'=>$this->aInstall['postscript'], 'path'=>OX_PLUGIN_GROUPPATH.'/etc/');
  184. break;
  185. case 'plugin-uninstall-prescript':
  186. $this->aAllFiles[] = array('name'=>$this->aUninstall['prescript'], 'path'=>OX_PLUGIN_GROUPPATH.'/etc/');
  187. break;
  188. case 'plugin-uninstall-postscript':
  189. $this->aAllFiles[] = array('name'=>$this->aUninstall['postscript'], 'path'=>OX_PLUGIN_GROUPPATH.'/etc/');
  190. break;
  191. }
  192. unset($this->elements[--$this->count]);
  193. $this->element = implode('-', $this->elements);
  194. }
  195. function cdataHandler($xp, $data)
  196. {
  197. switch ($this->element)
  198. {
  199. case 'plugin-install-files-file':
  200. @$this->aData['name'] .= $data;
  201. break;
  202. case 'plugin-install-syscheck-depends-plugin':
  203. @$this->aData['name'] .= $data;
  204. break;
  205. case 'plugin-install-syscheck-php-setting':
  206. @$this->aData['value'] .= $data;
  207. break;
  208. case 'plugin-install-syscheck-dbms-name':
  209. @$this->aData['name'] .= $data;
  210. break;
  211. case 'plugin-install-syscheck-dbms-supported':
  212. @$this->aData['supported'] .= $data;
  213. break;
  214. case 'plugin-install-syscheck-dbms-version':
  215. @$this->aData['version'] .= $data;
  216. break;
  217. case 'plugin-install-syscheck-dbms-engine':
  218. @$this->aData['engine'][] .= $data;
  219. break;
  220. case 'plugin-install-syscheck-dbms-grant':
  221. @$this->aData['grant'][] .= $data;
  222. break;
  223. case 'plugin-install-prescript':
  224. @$this->aInstall['prescript'] .= $data;
  225. break;
  226. case 'plugin-install-postscript':
  227. @$this->aInstall['postscript'] .= $data;
  228. break;
  229. case 'plugin-uninstall-prescript':
  230. @$this->aUninstall['prescript'] .= $data;
  231. break;
  232. case 'plugin-uninstall-postscript':
  233. @$this->aUninstall['postscript'] .= $data;
  234. break;
  235. case 'plugin-version':
  236. // Fix potential issues with lowercase RC's
  237. @$this->aPlugin['version'] = preg_replace('/rc([0-9]+)$/', 'RC$1', $data);
  238. break;
  239. case 'plugin-name':
  240. case 'plugin-creationdate':
  241. case 'plugin-author':
  242. case 'plugin-authoremail':
  243. case 'plugin-authorurl':
  244. case 'plugin-license':
  245. case 'plugin-oxversion':
  246. case 'plugin-extends':
  247. case 'plugin-description':
  248. @$this->aPlugin[str_replace('plugin-','',$this->element)] .= $data;
  249. break;
  250. }
  251. }
  252. function raiseError($msg = null, $xmlecode = 0, $xp = null, $ecode = OX_PLUGIN_ERROR_PARSE)
  253. {
  254. if (is_null($this->error))
  255. {
  256. $error = '';
  257. if (is_resource($msg))
  258. {
  259. $error.= 'Parser error: '.xml_error_string(xml_get_error_code($msg));
  260. $xp = $msg;
  261. }
  262. else
  263. {
  264. $error.= 'Parser error: '.$msg;
  265. if (!is_resource($xp)) {
  266. $xp = $this->parser;
  267. }
  268. }
  269. if (is_resource($xp))
  270. {
  271. $byte = @xml_get_current_byte_index($xp);
  272. $line = @xml_get_current_line_number($xp);
  273. $column = @xml_get_current_column_number($xp);
  274. $error.= " - Byte: $byte; Line: $line; Col: $column";
  275. }
  276. $error.= "\n";
  277. $mode = 0;
  278. $options = 0;
  279. $userinfo = '';
  280. $this->error = PEAR::raiseError($error, $code, $mode, $options, $userinfo);
  281. return $this->error;
  282. }
  283. return $this->error;
  284. }
  285. }
  286. ?>