PageRenderTime 67ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 2ms

/kickstart.php

https://github.com/finchiefin/olympian
PHP | 9572 lines | 7194 code | 838 blank | 1540 comment | 847 complexity | a2c20af0fdfc8fd5f81a5213274f83a1 MD5 | raw file
Possible License(s): GPL-2.0, Apache-2.0, LGPL-2.1, BSD-3-Clause, JSON

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * Akeeba Kickstart
  4. * A JSON-powered archive extraction tool
  5. *
  6. * @copyright 2010-2013 Nicholas K. Dionysopoulos / AkeebaBackup.com
  7. * @license GNU GPL v2 or - at your option - any later version
  8. * @package akeebabackup
  9. * @subpackage kickstart
  10. */
  11. /*
  12. Akeeba Kickstart - The server-side archive extraction wizard
  13. Copyright (C) 2008-2013 Nicholas K. Dionysopoulos / AkeebaBackup.com
  14. This program is free software: you can redistribute it and/or modify
  15. it under the terms of the GNU General Public License as published by
  16. the Free Software Foundation, either version 3 of the License, or
  17. (at your option) any later version.
  18. This program is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. GNU General Public License for more details.
  22. You should have received a copy of the GNU General Public License
  23. along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. define('KICKSTART',1);
  26. define('VERSION', '3.8.0');
  27. define('KICKSTARTPRO', '0');
  28. // Uncomment the following line to enable Kickstart's debug mode
  29. //define('KSDEBUG', 1);
  30. if(!defined('KSROOTDIR'))
  31. {
  32. define('KSROOTDIR', dirname(__FILE__));
  33. }
  34. if(defined('KSDEBUG')) {
  35. ini_set('error_log', KSROOTDIR.'/kickstart_error_log' );
  36. if(file_exists(KSROOTDIR.'/kickstart_error_log')) {
  37. @unlink(KSROOTDIR.'/kickstart_error_log');
  38. }
  39. error_reporting(E_ALL | E_STRICT);
  40. } else {
  41. @error_reporting(E_NONE);
  42. }
  43. // ==========================================================================================
  44. // IIS missing REQUEST_URI workaround
  45. // ==========================================================================================
  46. /*
  47. * Based REQUEST_URI for IIS Servers 1.0 by NeoSmart Technologies
  48. * The proper method to solve IIS problems is to take a look at this:
  49. * http://neosmart.net/dl.php?id=7
  50. */
  51. //This file should be located in the same directory as php.exe or php5isapi.dll
  52. if (!isset($_SERVER['REQUEST_URI']))
  53. {
  54. if (isset($_SERVER['HTTP_REQUEST_URI']))
  55. {
  56. $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_REQUEST_URI'];
  57. //Good to go!
  58. }
  59. else
  60. {
  61. //Someone didn't follow the instructions!
  62. if(isset($_SERVER['SCRIPT_NAME']))
  63. $_SERVER['HTTP_REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
  64. else
  65. $_SERVER['HTTP_REQUEST_URI'] = $_SERVER['PHP_SELF'];
  66. if($_SERVER['QUERY_STRING']){
  67. $_SERVER['HTTP_REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
  68. }
  69. //WARNING: This is a workaround!
  70. //For guaranteed compatibility, HTTP_REQUEST_URI *MUST* be defined!
  71. //See product documentation for instructions!
  72. $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_REQUEST_URI'];
  73. }
  74. }
  75. // Define the cacert.pem location, if it exists
  76. $cacertpem = KSROOTDIR . '/cacert.pem';
  77. if(is_file($cacertpem)) {
  78. if(is_readable($cacertpem)) {
  79. define('AKEEBA_CACERT_PEM', $cacertpem);
  80. }
  81. }
  82. unset($cacertpem);
  83. // Loads other PHP files containing extra Kickstart features
  84. $dh = @opendir(KSROOTDIR);
  85. if($dh === false) return;
  86. while($filename = readdir($dh)) {
  87. if(!is_file($filename)) continue;
  88. if(substr($filename, 0, 10) != 'kickstart.') continue;
  89. if(substr($filename, -4) != '.php') continue;
  90. include_once $filename;
  91. }
  92. /**
  93. * Akeeba Restore
  94. * A JSON-powered JPA, JPS and ZIP archive extraction library
  95. *
  96. * @copyright 2010-2013 Nicholas K. Dionysopoulos / Akeeba Ltd.
  97. * @license GNU GPL v2 or - at your option - any later version
  98. * @package akeebabackup
  99. * @subpackage kickstart
  100. */
  101. define('_AKEEBA_RESTORATION', 1);
  102. defined('DS') or define('DS', DIRECTORY_SEPARATOR);
  103. // Unarchiver run states
  104. define('AK_STATE_NOFILE', 0); // File header not read yet
  105. define('AK_STATE_HEADER', 1); // File header read; ready to process data
  106. define('AK_STATE_DATA', 2); // Processing file data
  107. define('AK_STATE_DATAREAD', 3); // Finished processing file data; ready to post-process
  108. define('AK_STATE_POSTPROC', 4); // Post-processing
  109. define('AK_STATE_DONE', 5); // Done with post-processing
  110. /* Windows system detection */
  111. if(!defined('_AKEEBA_IS_WINDOWS'))
  112. {
  113. if (function_exists('php_uname'))
  114. define('_AKEEBA_IS_WINDOWS', stristr(php_uname(), 'windows'));
  115. else
  116. define('_AKEEBA_IS_WINDOWS', DIRECTORY_SEPARATOR == '\\');
  117. }
  118. // Get the file's root
  119. if(!defined('KSROOTDIR'))
  120. {
  121. define('KSROOTDIR', dirname(__FILE__));
  122. }
  123. if(!defined('KSLANGDIR'))
  124. {
  125. define('KSLANGDIR', KSROOTDIR);
  126. }
  127. // Make sure the locale is correct for basename() to work
  128. if(function_exists('setlocale'))
  129. {
  130. @setlocale(LC_ALL, 'en_US.UTF8');
  131. }
  132. // fnmatch not available on non-POSIX systems
  133. // Thanks to soywiz@php.net for this usefull alternative function [http://gr2.php.net/fnmatch]
  134. if (!function_exists('fnmatch')) {
  135. function fnmatch($pattern, $string) {
  136. return @preg_match(
  137. '/^' . strtr(addcslashes($pattern, '/\\.+^$(){}=!<>|'),
  138. array('*' => '.*', '?' => '.?')) . '$/i', $string
  139. );
  140. }
  141. }
  142. // Unicode-safe binary data length function
  143. if (!function_exists('akstringlen'))
  144. {
  145. if(function_exists('mb_strlen')) {
  146. function akstringlen($string) { return mb_strlen($string,'8bit'); }
  147. } else {
  148. function akstringlen($string) { return strlen($string); }
  149. }
  150. }
  151. /**
  152. * Gets a query parameter from GET or POST data
  153. * @param $key
  154. * @param $default
  155. */
  156. function getQueryParam( $key, $default = null )
  157. {
  158. $value = null;
  159. if(array_key_exists($key, $_REQUEST)) {
  160. $value = $_REQUEST[$key];
  161. } elseif(array_key_exists($key, $_POST)) {
  162. $value = $_POST[$key];
  163. } elseif(array_key_exists($key, $_GET)) {
  164. $value = $_GET[$key];
  165. } else {
  166. return $default;
  167. }
  168. if(get_magic_quotes_gpc() && !is_null($value)) $value=stripslashes($value);
  169. return $value;
  170. }
  171. // Debugging function
  172. function debugMsg($msg)
  173. {
  174. if(!defined('KSDEBUG')) return;
  175. $fp = fopen('debug.txt','at');
  176. fwrite($fp, $msg."\n");
  177. fclose($fp);
  178. }
  179. /**
  180. * Akeeba Restore
  181. * A JSON-powered JPA, JPS and ZIP archive extraction library
  182. *
  183. * @copyright 2010-2013 Nicholas K. Dionysopoulos / Akeeba Ltd.
  184. * @license GNU GPL v2 or - at your option - any later version
  185. * @package akeebabackup
  186. * @subpackage kickstart
  187. */
  188. /**
  189. * Akeeba Backup's JSON compatibility layer
  190. *
  191. * On systems where json_encode and json_decode are not available, Akeeba
  192. * Backup will attempt to use PEAR's Services_JSON library to emulate them.
  193. * A copy of this library is included in this file and will be used if and
  194. * only if it isn't already loaded, e.g. due to PEAR's auto-loading, or a
  195. * 3PD extension loading it for its own purposes.
  196. */
  197. /**
  198. * Converts to and from JSON format.
  199. *
  200. * JSON (JavaScript Object Notation) is a lightweight data-interchange
  201. * format. It is easy for humans to read and write. It is easy for machines
  202. * to parse and generate. It is based on a subset of the JavaScript
  203. * Programming Language, Standard ECMA-262 3rd Edition - December 1999.
  204. * This feature can also be found in Python. JSON is a text format that is
  205. * completely language independent but uses conventions that are familiar
  206. * to programmers of the C-family of languages, including C, C++, C#, Java,
  207. * JavaScript, Perl, TCL, and many others. These properties make JSON an
  208. * ideal data-interchange language.
  209. *
  210. * This package provides a simple encoder and decoder for JSON notation. It
  211. * is intended for use with client-side Javascript applications that make
  212. * use of HTTPRequest to perform server communication functions - data can
  213. * be encoded into JSON notation for use in a client-side javascript, or
  214. * decoded from incoming Javascript requests. JSON format is native to
  215. * Javascript, and can be directly eval()'ed with no further parsing
  216. * overhead
  217. *
  218. * All strings should be in ASCII or UTF-8 format!
  219. *
  220. * LICENSE: Redistribution and use in source and binary forms, with or
  221. * without modification, are permitted provided that the following
  222. * conditions are met: Redistributions of source code must retain the
  223. * above copyright notice, this list of conditions and the following
  224. * disclaimer. Redistributions in binary form must reproduce the above
  225. * copyright notice, this list of conditions and the following disclaimer
  226. * in the documentation and/or other materials provided with the
  227. * distribution.
  228. *
  229. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  230. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  231. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  232. * NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  233. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  234. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  235. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  236. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  237. * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  238. * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  239. * DAMAGE.
  240. *
  241. * @category
  242. * @package Services_JSON
  243. * @author Michal Migurski <mike-json@teczno.com>
  244. * @author Matt Knapp <mdknapp[at]gmail[dot]com>
  245. * @author Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
  246. * @copyright 2005 Michal Migurski
  247. * @version CVS: $Id: restore.php 612 2011-05-19 08:26:26Z nikosdion $
  248. * @license http://www.opensource.org/licenses/bsd-license.php
  249. * @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
  250. */
  251. if(!defined('JSON_FORCE_OBJECT'))
  252. {
  253. define('JSON_FORCE_OBJECT', 1);
  254. }
  255. if(!defined('SERVICES_JSON_SLICE'))
  256. {
  257. /**
  258. * Marker constant for Services_JSON::decode(), used to flag stack state
  259. */
  260. define('SERVICES_JSON_SLICE', 1);
  261. /**
  262. * Marker constant for Services_JSON::decode(), used to flag stack state
  263. */
  264. define('SERVICES_JSON_IN_STR', 2);
  265. /**
  266. * Marker constant for Services_JSON::decode(), used to flag stack state
  267. */
  268. define('SERVICES_JSON_IN_ARR', 3);
  269. /**
  270. * Marker constant for Services_JSON::decode(), used to flag stack state
  271. */
  272. define('SERVICES_JSON_IN_OBJ', 4);
  273. /**
  274. * Marker constant for Services_JSON::decode(), used to flag stack state
  275. */
  276. define('SERVICES_JSON_IN_CMT', 5);
  277. /**
  278. * Behavior switch for Services_JSON::decode()
  279. */
  280. define('SERVICES_JSON_LOOSE_TYPE', 16);
  281. /**
  282. * Behavior switch for Services_JSON::decode()
  283. */
  284. define('SERVICES_JSON_SUPPRESS_ERRORS', 32);
  285. }
  286. /**
  287. * Converts to and from JSON format.
  288. *
  289. * Brief example of use:
  290. *
  291. * <code>
  292. * // create a new instance of Services_JSON
  293. * $json = new Services_JSON();
  294. *
  295. * // convert a complexe value to JSON notation, and send it to the browser
  296. * $value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4)));
  297. * $output = $json->encode($value);
  298. *
  299. * print($output);
  300. * // prints: ["foo","bar",[1,2,"baz"],[3,[4]]]
  301. *
  302. * // accept incoming POST data, assumed to be in JSON notation
  303. * $input = file_get_contents('php://input', 1000000);
  304. * $value = $json->decode($input);
  305. * </code>
  306. */
  307. if(!class_exists('Akeeba_Services_JSON'))
  308. {
  309. class Akeeba_Services_JSON
  310. {
  311. /**
  312. * constructs a new JSON instance
  313. *
  314. * @param int $use object behavior flags; combine with boolean-OR
  315. *
  316. * possible values:
  317. * - SERVICES_JSON_LOOSE_TYPE: loose typing.
  318. * "{...}" syntax creates associative arrays
  319. * instead of objects in decode().
  320. * - SERVICES_JSON_SUPPRESS_ERRORS: error suppression.
  321. * Values which can't be encoded (e.g. resources)
  322. * appear as NULL instead of throwing errors.
  323. * By default, a deeply-nested resource will
  324. * bubble up with an error, so all return values
  325. * from encode() should be checked with isError()
  326. */
  327. function Akeeba_Services_JSON($use = 0)
  328. {
  329. $this->use = $use;
  330. }
  331. /**
  332. * convert a string from one UTF-16 char to one UTF-8 char
  333. *
  334. * Normally should be handled by mb_convert_encoding, but
  335. * provides a slower PHP-only method for installations
  336. * that lack the multibye string extension.
  337. *
  338. * @param string $utf16 UTF-16 character
  339. * @return string UTF-8 character
  340. * @access private
  341. */
  342. function utf162utf8($utf16)
  343. {
  344. // oh please oh please oh please oh please oh please
  345. if(function_exists('mb_convert_encoding')) {
  346. return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
  347. }
  348. $bytes = (ord($utf16{0}) << 8) | ord($utf16{1});
  349. switch(true) {
  350. case ((0x7F & $bytes) == $bytes):
  351. // this case should never be reached, because we are in ASCII range
  352. // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  353. return chr(0x7F & $bytes);
  354. case (0x07FF & $bytes) == $bytes:
  355. // return a 2-byte UTF-8 character
  356. // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  357. return chr(0xC0 | (($bytes >> 6) & 0x1F))
  358. . chr(0x80 | ($bytes & 0x3F));
  359. case (0xFFFF & $bytes) == $bytes:
  360. // return a 3-byte UTF-8 character
  361. // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  362. return chr(0xE0 | (($bytes >> 12) & 0x0F))
  363. . chr(0x80 | (($bytes >> 6) & 0x3F))
  364. . chr(0x80 | ($bytes & 0x3F));
  365. }
  366. // ignoring UTF-32 for now, sorry
  367. return '';
  368. }
  369. /**
  370. * convert a string from one UTF-8 char to one UTF-16 char
  371. *
  372. * Normally should be handled by mb_convert_encoding, but
  373. * provides a slower PHP-only method for installations
  374. * that lack the multibye string extension.
  375. *
  376. * @param string $utf8 UTF-8 character
  377. * @return string UTF-16 character
  378. * @access private
  379. */
  380. function utf82utf16($utf8)
  381. {
  382. // oh please oh please oh please oh please oh please
  383. if(function_exists('mb_convert_encoding')) {
  384. return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
  385. }
  386. switch(strlen($utf8)) {
  387. case 1:
  388. // this case should never be reached, because we are in ASCII range
  389. // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  390. return $utf8;
  391. case 2:
  392. // return a UTF-16 character from a 2-byte UTF-8 char
  393. // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  394. return chr(0x07 & (ord($utf8{0}) >> 2))
  395. . chr((0xC0 & (ord($utf8{0}) << 6))
  396. | (0x3F & ord($utf8{1})));
  397. case 3:
  398. // return a UTF-16 character from a 3-byte UTF-8 char
  399. // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  400. return chr((0xF0 & (ord($utf8{0}) << 4))
  401. | (0x0F & (ord($utf8{1}) >> 2)))
  402. . chr((0xC0 & (ord($utf8{1}) << 6))
  403. | (0x7F & ord($utf8{2})));
  404. }
  405. // ignoring UTF-32 for now, sorry
  406. return '';
  407. }
  408. /**
  409. * encodes an arbitrary variable into JSON format
  410. *
  411. * @param mixed $var any number, boolean, string, array, or object to be encoded.
  412. * see argument 1 to Services_JSON() above for array-parsing behavior.
  413. * if var is a strng, note that encode() always expects it
  414. * to be in ASCII or UTF-8 format!
  415. *
  416. * @return mixed JSON string representation of input var or an error if a problem occurs
  417. * @access public
  418. */
  419. function encode($var)
  420. {
  421. switch (gettype($var)) {
  422. case 'boolean':
  423. return $var ? 'true' : 'false';
  424. case 'NULL':
  425. return 'null';
  426. case 'integer':
  427. return (int) $var;
  428. case 'double':
  429. case 'float':
  430. return (float) $var;
  431. case 'string':
  432. // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
  433. $ascii = '';
  434. $strlen_var = strlen($var);
  435. /*
  436. * Iterate over every character in the string,
  437. * escaping with a slash or encoding to UTF-8 where necessary
  438. */
  439. for ($c = 0; $c < $strlen_var; ++$c) {
  440. $ord_var_c = ord($var{$c});
  441. switch (true) {
  442. case $ord_var_c == 0x08:
  443. $ascii .= '\b';
  444. break;
  445. case $ord_var_c == 0x09:
  446. $ascii .= '\t';
  447. break;
  448. case $ord_var_c == 0x0A:
  449. $ascii .= '\n';
  450. break;
  451. case $ord_var_c == 0x0C:
  452. $ascii .= '\f';
  453. break;
  454. case $ord_var_c == 0x0D:
  455. $ascii .= '\r';
  456. break;
  457. case $ord_var_c == 0x22:
  458. case $ord_var_c == 0x2F:
  459. case $ord_var_c == 0x5C:
  460. // double quote, slash, slosh
  461. $ascii .= '\\'.$var{$c};
  462. break;
  463. case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
  464. // characters U-00000000 - U-0000007F (same as ASCII)
  465. $ascii .= $var{$c};
  466. break;
  467. case (($ord_var_c & 0xE0) == 0xC0):
  468. // characters U-00000080 - U-000007FF, mask 110XXXXX
  469. // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  470. $char = pack('C*', $ord_var_c, ord($var{$c + 1}));
  471. $c += 1;
  472. $utf16 = $this->utf82utf16($char);
  473. $ascii .= sprintf('\u%04s', bin2hex($utf16));
  474. break;
  475. case (($ord_var_c & 0xF0) == 0xE0):
  476. // characters U-00000800 - U-0000FFFF, mask 1110XXXX
  477. // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  478. $char = pack('C*', $ord_var_c,
  479. ord($var{$c + 1}),
  480. ord($var{$c + 2}));
  481. $c += 2;
  482. $utf16 = $this->utf82utf16($char);
  483. $ascii .= sprintf('\u%04s', bin2hex($utf16));
  484. break;
  485. case (($ord_var_c & 0xF8) == 0xF0):
  486. // characters U-00010000 - U-001FFFFF, mask 11110XXX
  487. // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  488. $char = pack('C*', $ord_var_c,
  489. ord($var{$c + 1}),
  490. ord($var{$c + 2}),
  491. ord($var{$c + 3}));
  492. $c += 3;
  493. $utf16 = $this->utf82utf16($char);
  494. $ascii .= sprintf('\u%04s', bin2hex($utf16));
  495. break;
  496. case (($ord_var_c & 0xFC) == 0xF8):
  497. // characters U-00200000 - U-03FFFFFF, mask 111110XX
  498. // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  499. $char = pack('C*', $ord_var_c,
  500. ord($var{$c + 1}),
  501. ord($var{$c + 2}),
  502. ord($var{$c + 3}),
  503. ord($var{$c + 4}));
  504. $c += 4;
  505. $utf16 = $this->utf82utf16($char);
  506. $ascii .= sprintf('\u%04s', bin2hex($utf16));
  507. break;
  508. case (($ord_var_c & 0xFE) == 0xFC):
  509. // characters U-04000000 - U-7FFFFFFF, mask 1111110X
  510. // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  511. $char = pack('C*', $ord_var_c,
  512. ord($var{$c + 1}),
  513. ord($var{$c + 2}),
  514. ord($var{$c + 3}),
  515. ord($var{$c + 4}),
  516. ord($var{$c + 5}));
  517. $c += 5;
  518. $utf16 = $this->utf82utf16($char);
  519. $ascii .= sprintf('\u%04s', bin2hex($utf16));
  520. break;
  521. }
  522. }
  523. return '"'.$ascii.'"';
  524. case 'array':
  525. /*
  526. * As per JSON spec if any array key is not an integer
  527. * we must treat the the whole array as an object. We
  528. * also try to catch a sparsely populated associative
  529. * array with numeric keys here because some JS engines
  530. * will create an array with empty indexes up to
  531. * max_index which can cause memory issues and because
  532. * the keys, which may be relevant, will be remapped
  533. * otherwise.
  534. *
  535. * As per the ECMA and JSON specification an object may
  536. * have any string as a property. Unfortunately due to
  537. * a hole in the ECMA specification if the key is a
  538. * ECMA reserved word or starts with a digit the
  539. * parameter is only accessible using ECMAScript's
  540. * bracket notation.
  541. */
  542. // treat as a JSON object
  543. if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) {
  544. $properties = array_map(array($this, 'name_value'),
  545. array_keys($var),
  546. array_values($var));
  547. foreach($properties as $property) {
  548. if(Akeeba_Services_JSON::isError($property)) {
  549. return $property;
  550. }
  551. }
  552. return '{' . join(',', $properties) . '}';
  553. }
  554. // treat it like a regular array
  555. $elements = array_map(array($this, 'encode'), $var);
  556. foreach($elements as $element) {
  557. if(Akeeba_Services_JSON::isError($element)) {
  558. return $element;
  559. }
  560. }
  561. return '[' . join(',', $elements) . ']';
  562. case 'object':
  563. $vars = get_object_vars($var);
  564. $properties = array_map(array($this, 'name_value'),
  565. array_keys($vars),
  566. array_values($vars));
  567. foreach($properties as $property) {
  568. if(Akeeba_Services_JSON::isError($property)) {
  569. return $property;
  570. }
  571. }
  572. return '{' . join(',', $properties) . '}';
  573. default:
  574. return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS)
  575. ? 'null'
  576. : new Akeeba_Services_JSON_Error(gettype($var)." can not be encoded as JSON string");
  577. }
  578. }
  579. /**
  580. * array-walking function for use in generating JSON-formatted name-value pairs
  581. *
  582. * @param string $name name of key to use
  583. * @param mixed $value reference to an array element to be encoded
  584. *
  585. * @return string JSON-formatted name-value pair, like '"name":value'
  586. * @access private
  587. */
  588. function name_value($name, $value)
  589. {
  590. $encoded_value = $this->encode($value);
  591. if(Akeeba_Services_JSON::isError($encoded_value)) {
  592. return $encoded_value;
  593. }
  594. return $this->encode(strval($name)) . ':' . $encoded_value;
  595. }
  596. /**
  597. * reduce a string by removing leading and trailing comments and whitespace
  598. *
  599. * @param $str string string value to strip of comments and whitespace
  600. *
  601. * @return string string value stripped of comments and whitespace
  602. * @access private
  603. */
  604. function reduce_string($str)
  605. {
  606. $str = preg_replace(array(
  607. // eliminate single line comments in '// ...' form
  608. '#^\s*//(.+)$#m',
  609. // eliminate multi-line comments in '/* ... */' form, at start of string
  610. '#^\s*/\*(.+)\*/#Us',
  611. // eliminate multi-line comments in '/* ... */' form, at end of string
  612. '#/\*(.+)\*/\s*$#Us'
  613. ), '', $str);
  614. // eliminate extraneous space
  615. return trim($str);
  616. }
  617. /**
  618. * decodes a JSON string into appropriate variable
  619. *
  620. * @param string $str JSON-formatted string
  621. *
  622. * @return mixed number, boolean, string, array, or object
  623. * corresponding to given JSON input string.
  624. * See argument 1 to Akeeba_Services_JSON() above for object-output behavior.
  625. * Note that decode() always returns strings
  626. * in ASCII or UTF-8 format!
  627. * @access public
  628. */
  629. function decode($str)
  630. {
  631. $str = $this->reduce_string($str);
  632. switch (strtolower($str)) {
  633. case 'true':
  634. return true;
  635. case 'false':
  636. return false;
  637. case 'null':
  638. return null;
  639. default:
  640. $m = array();
  641. if (is_numeric($str)) {
  642. // Lookie-loo, it's a number
  643. // This would work on its own, but I'm trying to be
  644. // good about returning integers where appropriate:
  645. // return (float)$str;
  646. // Return float or int, as appropriate
  647. return ((float)$str == (integer)$str)
  648. ? (integer)$str
  649. : (float)$str;
  650. } elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) {
  651. // STRINGS RETURNED IN UTF-8 FORMAT
  652. $delim = substr($str, 0, 1);
  653. $chrs = substr($str, 1, -1);
  654. $utf8 = '';
  655. $strlen_chrs = strlen($chrs);
  656. for ($c = 0; $c < $strlen_chrs; ++$c) {
  657. $substr_chrs_c_2 = substr($chrs, $c, 2);
  658. $ord_chrs_c = ord($chrs{$c});
  659. switch (true) {
  660. case $substr_chrs_c_2 == '\b':
  661. $utf8 .= chr(0x08);
  662. ++$c;
  663. break;
  664. case $substr_chrs_c_2 == '\t':
  665. $utf8 .= chr(0x09);
  666. ++$c;
  667. break;
  668. case $substr_chrs_c_2 == '\n':
  669. $utf8 .= chr(0x0A);
  670. ++$c;
  671. break;
  672. case $substr_chrs_c_2 == '\f':
  673. $utf8 .= chr(0x0C);
  674. ++$c;
  675. break;
  676. case $substr_chrs_c_2 == '\r':
  677. $utf8 .= chr(0x0D);
  678. ++$c;
  679. break;
  680. case $substr_chrs_c_2 == '\\"':
  681. case $substr_chrs_c_2 == '\\\'':
  682. case $substr_chrs_c_2 == '\\\\':
  683. case $substr_chrs_c_2 == '\\/':
  684. if (($delim == '"' && $substr_chrs_c_2 != '\\\'') ||
  685. ($delim == "'" && $substr_chrs_c_2 != '\\"')) {
  686. $utf8 .= $chrs{++$c};
  687. }
  688. break;
  689. case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)):
  690. // single, escaped unicode character
  691. $utf16 = chr(hexdec(substr($chrs, ($c + 2), 2)))
  692. . chr(hexdec(substr($chrs, ($c + 4), 2)));
  693. $utf8 .= $this->utf162utf8($utf16);
  694. $c += 5;
  695. break;
  696. case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F):
  697. $utf8 .= $chrs{$c};
  698. break;
  699. case ($ord_chrs_c & 0xE0) == 0xC0:
  700. // characters U-00000080 - U-000007FF, mask 110XXXXX
  701. //see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  702. $utf8 .= substr($chrs, $c, 2);
  703. ++$c;
  704. break;
  705. case ($ord_chrs_c & 0xF0) == 0xE0:
  706. // characters U-00000800 - U-0000FFFF, mask 1110XXXX
  707. // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  708. $utf8 .= substr($chrs, $c, 3);
  709. $c += 2;
  710. break;
  711. case ($ord_chrs_c & 0xF8) == 0xF0:
  712. // characters U-00010000 - U-001FFFFF, mask 11110XXX
  713. // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  714. $utf8 .= substr($chrs, $c, 4);
  715. $c += 3;
  716. break;
  717. case ($ord_chrs_c & 0xFC) == 0xF8:
  718. // characters U-00200000 - U-03FFFFFF, mask 111110XX
  719. // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  720. $utf8 .= substr($chrs, $c, 5);
  721. $c += 4;
  722. break;
  723. case ($ord_chrs_c & 0xFE) == 0xFC:
  724. // characters U-04000000 - U-7FFFFFFF, mask 1111110X
  725. // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
  726. $utf8 .= substr($chrs, $c, 6);
  727. $c += 5;
  728. break;
  729. }
  730. }
  731. return $utf8;
  732. } elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
  733. // array, or object notation
  734. if ($str{0} == '[') {
  735. $stk = array(SERVICES_JSON_IN_ARR);
  736. $arr = array();
  737. } else {
  738. if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
  739. $stk = array(SERVICES_JSON_IN_OBJ);
  740. $obj = array();
  741. } else {
  742. $stk = array(SERVICES_JSON_IN_OBJ);
  743. $obj = new stdClass();
  744. }
  745. }
  746. array_push($stk, array('what' => SERVICES_JSON_SLICE,
  747. 'where' => 0,
  748. 'delim' => false));
  749. $chrs = substr($str, 1, -1);
  750. $chrs = $this->reduce_string($chrs);
  751. if ($chrs == '') {
  752. if (reset($stk) == SERVICES_JSON_IN_ARR) {
  753. return $arr;
  754. } else {
  755. return $obj;
  756. }
  757. }
  758. //print("\nparsing {$chrs}\n");
  759. $strlen_chrs = strlen($chrs);
  760. for ($c = 0; $c <= $strlen_chrs; ++$c) {
  761. $top = end($stk);
  762. $substr_chrs_c_2 = substr($chrs, $c, 2);
  763. if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) {
  764. // found a comma that is not inside a string, array, etc.,
  765. // OR we've reached the end of the character list
  766. $slice = substr($chrs, $top['where'], ($c - $top['where']));
  767. array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false));
  768. //print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
  769. if (reset($stk) == SERVICES_JSON_IN_ARR) {
  770. // we are in an array, so just push an element onto the stack
  771. array_push($arr, $this->decode($slice));
  772. } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
  773. // we are in an object, so figure
  774. // out the property name and set an
  775. // element in an associative array,
  776. // for now
  777. $parts = array();
  778. if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
  779. // "name":value pair
  780. $key = $this->decode($parts[1]);
  781. $val = $this->decode($parts[2]);
  782. if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
  783. $obj[$key] = $val;
  784. } else {
  785. $obj->$key = $val;
  786. }
  787. } elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
  788. // name:value pair, where name is unquoted
  789. $key = $parts[1];
  790. $val = $this->decode($parts[2]);
  791. if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
  792. $obj[$key] = $val;
  793. } else {
  794. $obj->$key = $val;
  795. }
  796. }
  797. }
  798. } elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) {
  799. // found a quote, and we are not inside a string
  800. array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c}));
  801. //print("Found start of string at {$c}\n");
  802. } elseif (($chrs{$c} == $top['delim']) &&
  803. ($top['what'] == SERVICES_JSON_IN_STR) &&
  804. ((strlen(substr($chrs, 0, $c)) - strlen(rtrim(substr($chrs, 0, $c), '\\'))) % 2 != 1)) {
  805. // found a quote, we're in a string, and it's not escaped
  806. // we know that it's not escaped becase there is _not_ an
  807. // odd number of backslashes at the end of the string so far
  808. array_pop($stk);
  809. //print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
  810. } elseif (($chrs{$c} == '[') &&
  811. in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
  812. // found a left-bracket, and we are in an array, object, or slice
  813. array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false));
  814. //print("Found start of array at {$c}\n");
  815. } elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) {
  816. // found a right-bracket, and we're in an array
  817. array_pop($stk);
  818. //print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
  819. } elseif (($chrs{$c} == '{') &&
  820. in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
  821. // found a left-brace, and we are in an array, object, or slice
  822. array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false));
  823. //print("Found start of object at {$c}\n");
  824. } elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) {
  825. // found a right-brace, and we're in an object
  826. array_pop($stk);
  827. //print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
  828. } elseif (($substr_chrs_c_2 == '/*') &&
  829. in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
  830. // found a comment start, and we are in an array, object, or slice
  831. array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false));
  832. $c++;
  833. //print("Found start of comment at {$c}\n");
  834. } elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) {
  835. // found a comment end, and we're in one now
  836. array_pop($stk);
  837. $c++;
  838. for ($i = $top['where']; $i <= $c; ++$i)
  839. $chrs = substr_replace($chrs, ' ', $i, 1);
  840. //print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
  841. }
  842. }
  843. if (reset($stk) == SERVICES_JSON_IN_ARR) {
  844. return $arr;
  845. } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
  846. return $obj;
  847. }
  848. }
  849. }
  850. }
  851. function isError($data, $code = null)
  852. {
  853. if (class_exists('pear')) {
  854. return PEAR::isError($data, $code);
  855. } elseif (is_object($data) && (get_class($data) == 'services_json_error' ||
  856. is_subclass_of($data, 'services_json_error'))) {
  857. return true;
  858. }
  859. return false;
  860. }
  861. }
  862. class Akeeba_Services_JSON_Error
  863. {
  864. function Akeeba_Services_JSON_Error($message = 'unknown error', $code = null,
  865. $mode = null, $options = null, $userinfo = null)
  866. {
  867. }
  868. }
  869. }
  870. if(!function_exists('json_encode'))
  871. {
  872. function json_encode($value, $options = 0) {
  873. $flags = SERVICES_JSON_LOOSE_TYPE;
  874. if( $options & JSON_FORCE_OBJECT ) $flags = 0;
  875. $encoder = new Akeeba_Services_JSON($flags);
  876. return $encoder->encode($value);
  877. }
  878. }
  879. if(!function_exists('json_decode'))
  880. {
  881. function json_decode($value, $assoc = false)
  882. {
  883. $flags = 0;
  884. if($assoc) $flags = SERVICES_JSON_LOOSE_TYPE;
  885. $decoder = new Akeeba_Services_JSON($flags);
  886. return $decoder->decode($value);
  887. }
  888. }
  889. /**
  890. * Akeeba Restore
  891. * A JSON-powered JPA, JPS and ZIP archive extraction library
  892. *
  893. * @copyright 2010-2013 Nicholas K. Dionysopoulos / Akeeba Ltd.
  894. * @license GNU GPL v2 or - at your option - any later version
  895. * @package akeebabackup
  896. * @subpackage kickstart
  897. */
  898. /**
  899. * The base class of Akeeba Engine objects. Allows for error and warnings logging
  900. * and propagation. Largely based on the Joomla! 1.5 JObject class.
  901. */
  902. abstract class AKAbstractObject
  903. {
  904. /** @var array An array of errors */
  905. private $_errors = array();
  906. /** @var array The queue size of the $_errors array. Set to 0 for infinite size. */
  907. protected $_errors_queue_size = 0;
  908. /** @var array An array of warnings */
  909. private $_warnings = array();
  910. /** @var array The queue size of the $_warnings array. Set to 0 for infinite size. */
  911. protected $_warnings_queue_size = 0;
  912. /**
  913. * Public constructor, makes sure we are instanciated only by the factory class
  914. */
  915. public function __construct()
  916. {
  917. /*
  918. // Assisted Singleton pattern
  919. if(function_exists('debug_backtrace'))
  920. {
  921. $caller=debug_backtrace();
  922. if(
  923. ($caller[1]['class'] != 'AKFactory') &&
  924. ($caller[2]['class'] != 'AKFactory') &&
  925. ($caller[3]['class'] != 'AKFactory') &&
  926. ($caller[4]['class'] != 'AKFactory')
  927. ) {
  928. var_dump(debug_backtrace());
  929. trigger_error("You can't create direct descendants of ".__CLASS__, E_USER_ERROR);
  930. }
  931. }
  932. */
  933. }
  934. /**
  935. * Get the most recent error message
  936. * @param integer $i Optional error index
  937. * @return string Error message
  938. */
  939. public function getError($i = null)
  940. {
  941. return $this->getItemFromArray($this->_errors, $i);
  942. }
  943. /**
  944. * Return all errors, if any
  945. * @return array Array of error messages
  946. */
  947. public function getErrors()
  948. {
  949. return $this->_errors;
  950. }
  951. /**
  952. * Add an error message
  953. * @param string $error Error message
  954. */
  955. public function setError($error)
  956. {
  957. if($this->_errors_queue_size > 0)
  958. {
  959. if(count($this->_errors) >= $this->_errors_queue_size)
  960. {
  961. array_shift($this->_errors);
  962. }
  963. }
  964. array_push($this->_errors, $error);
  965. }
  966. /**
  967. * Resets all error messages
  968. */
  969. public function resetErrors()
  970. {
  971. $this->_errors = array();
  972. }
  973. /**
  974. * Get the most recent warning message
  975. * @param integer $i Optional warning index
  976. * @return string Error message
  977. */
  978. public function getWarning($i = null)
  979. {
  980. return $this->getItemFromArray($this->_warnings, $i);
  981. }
  982. /**
  983. * Return all warnings, if any
  984. * @return array Array of error messages
  985. */
  986. public function getWarnings()
  987. {
  988. return $this->_warnings;
  989. }
  990. /**
  991. * Add an error message
  992. * @param string $error Error message
  993. */
  994. public function setWarning($warning)
  995. {
  996. if($this->_warnings_queue_size > 0)
  997. {
  998. if(count($this->_warnings) >= $this->_warnings_queue_size)
  999. {
  1000. array_shift($this->_warnings);
  1001. }
  1002. }
  1003. array_push($this->_warnings, $warning);
  1004. }
  1005. /**
  1006. * Resets all warning messages
  1007. */
  1008. public function resetWarnings()
  1009. {
  1010. $this->_warnings = array();
  1011. }
  1012. /**
  1013. * Propagates errors and warnings to a foreign object. The foreign object SHOULD
  1014. * implement the setError() and/or setWarning() methods but DOESN'T HAVE TO be of
  1015. * AKAbstractObject type. For example, this can even be used to propagate to a
  1016. * JObject instance in Joomla!. Propagated items will be removed from ourself.
  1017. * @param object $object The object to propagate errors and warnings to.
  1018. */
  1019. public function propagateToObject(&$object)
  1020. {
  1021. // Skip non-objects
  1022. if(!is_object($object)) return;
  1023. if( method_exists($object,'setError') )
  1024. {
  1025. if(!empty($this->_errors))
  1026. {
  1027. foreach($this->_errors as $error)
  1028. {
  1029. $object->setError($error);
  1030. }
  1031. $this->_errors = array();
  1032. }
  1033. }
  1034. if( method_exists($object,'setWarning') )
  1035. {
  1036. if(!empty($this->_warnings))
  1037. {
  1038. foreach($this->_warnings as $warning)
  1039. {
  1040. $object->setWarning($warning);
  1041. }
  1042. $this->_warnings = array();
  1043. }
  1044. }
  1045. }
  1046. /**
  1047. * Propagates errors and warnings from a foreign object. Each propagated list is
  1048. * then cleared on the foreign object, as long as it implements resetErrors() and/or
  1049. * resetWarnings() methods.
  1050. * @param object $object The object to propagate errors and warnings from
  1051. */
  1052. public function propagateFromObject(&$object)
  1053. {
  1054. if( method_exists($object,'getErrors') )
  1055. {
  1056. $errors = $object->getErrors();
  1057. if(!empty($errors))
  1058. {
  1059. foreach($errors as $error)
  1060. {
  1061. $this->setError($error);
  1062. }
  1063. }
  1064. if(method_exists($object,'resetErrors'))
  1065. {
  1066. $object->resetErrors();
  1067. }
  1068. }
  1069. if( method_exists($object,'getWarnings') )
  1070. {
  1071. $warnings = $object->getWarnings();
  1072. if(!empty($warnings))
  1073. {
  1074. foreach($warnings as $warning)
  1075. {
  1076. $this->setWarning($warning);
  1077. }
  1078. }
  1079. if(method_exists($object,'resetWarnings'))
  1080. {
  1081. $object->resetWarnings();
  1082. }
  1083. }
  1084. }
  1085. /**
  1086. * Sets the size of the error queue (acts like a LIFO buffer)
  1087. * @param int $newSize The new queue size. Set to 0 for infinite length.
  1088. */
  1089. protected function setErrorsQueueSize($newSize = 0)
  1090. {
  1091. $this->_errors_queue_size = (int)$newSize;
  1092. }
  1093. /**
  1094. * Sets the size of the warnings queue (acts like a LIFO buffer)
  1095. * @param int $newSize The new queue size. Set to 0 for infinite length.
  1096. */
  1097. protected function setWarningsQueueSize($newSize = 0)
  1098. {
  1099. $this->_warnings_queue_size = (int)$newSize;
  1100. }
  1101. /**
  1102. * Returns the last item of a LIFO string message queue, or a specific item
  1103. * if so specified.
  1104. * @param array $array An array of strings, holding messages
  1105. * @param int $i Optional message index
  1106. * @return mixed The message string, or false if the key doesn't exist
  1107. */
  1108. private function getItemFromArray($array, $i = null)
  1109. {
  1110. // Find the item
  1111. if ( $i === null) {
  1112. // Default, return the last item
  1113. $item = end($array);
  1114. }
  1115. else
  1116. if ( ! array_key_exists($i, $array) ) {
  1117. // If $i has been specified but does not exist, return false
  1118. return false;
  1119. }
  1120. else
  1121. {
  1122. $item = $array[$i];
  1123. }
  1124. return $item;
  1125. }
  1126. }
  1127. /**
  1128. * Akeeba Restore
  1129. * A JSON-powered JPA, JPS and ZIP archive extraction library
  1130. *
  1131. * @copyright 2010-2013 Nicholas K. Dionysopoulos / Akeeba Ltd.
  1132. * @license GNU GPL v2 or - at your option - any later version
  1133. * @package akeebabackup
  1134. * @subpackage kickstart
  1135. */
  1136. /**
  1137. * The superclass of all Akeeba Kickstart parts. The "parts" are intelligent stateful
  1138. * classes which perform a single procedure and have preparation, running and
  1139. * finalization phases. The transition between phases is handled automatically by
  1140. * this superclass' tick() final public method, which should be the ONLY public API
  1141. * exposed to the rest of the Akeeba Engine.
  1142. */
  1143. abstract class AKAbstractPart extends AKAbstractObject
  1144. {
  1145. /**
  1146. * Indicates whether this part has finished its initialisation cycle
  1147. * @var boolean
  1148. */
  1149. protected $isPrepared = false;
  1150. /**
  1151. * Indicates whether this part has more work to do (it's in running state)
  1152. * @var boolean
  1153. */
  1154. protected $isRunning = false;
  1155. /**
  1156. * Indicates whether this part has finished its finalization cycle
  1157. * @var boolean
  1158. */
  1159. protected $isFinished = false;
  1160. /**
  1161. * Indicates whether this part has finished its run cycle
  1162. * @var boolean
  1163. */
  1164. protected $hasRan = false;
  1165. /**
  1166. * The name of the engine part (a.k.a. Domain), used in return table
  1167. * generation.
  1168. * @var string
  1169. */
  1170. protected $active_domain = "";
  1171. /**
  1172. * The step this engine part is in. Used verbatim in return table and
  1173. * should be set by the code in the _run() method.
  1174. * @var string
  1175. */
  1176. protected $active_step = "";
  1177. /**
  1178. * A more detailed description of the step this engine part is in. Used
  1179. * verbatim in return table and should be set by the code in the _run()
  1180. * method.
  1181. * @var string
  1182. */
  1183. protected $active_substep = "";
  1184. /**
  1185. * Any configuration variables, in the form of an array.
  1186. * @var array
  1187. */
  1188. protected $_parametersArray = array();
  1189. /** @var string The database root key */
  1190. protected $databaseRoot = array();
  1191. /** @var int Last reported warnings's position in array */
  1192. private $warnings_pointer = -1;
  1193. /** @var array An array of observers */
  1194. protected $observers = array();
  1195. /**
  1196. * Runs the preparation for this part. Should set _isPrepared
  1197. * to true
  1198. */
  1199. abstract protected function _prepare();
  1200. /**
  1201. * Runs the finalisation process for this part. Should set
  1202. * _isFinished to true.
  1203. */
  1204. abstract protected function _finalize();
  1205. /**
  1206. * Runs the main functionality loop for this part. Upon calling,
  1207. * should set the _isRunning to true. When it finished, should set
  1208. * the _hasRan to true. If an error is encountered, setError should
  1209. * be used.
  1210. */
  1211. abstract protected function _run();
  1212. /**
  1213. * Sets the BREAKFLAG, which instructs this engine part that the current step must break immediately,
  1214. * in fear of timing…

Large files files are truncated, but you can click here to view the full file