PageRenderTime 69ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 1ms

/administrator/components/com_joomlaupdate/restore.php

https://bitbucket.org/biojazzard/joomla-eboracast
PHP | 5746 lines | 3936 code | 669 blank | 1141 comment | 678 complexity | ea02f90b93f77806fcba40778f468afa MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, MIT, BSD-3-Clause

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

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

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