PageRenderTime 62ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 1ms

/administrator/includes/pcl/pclzip.lib.php

https://github.com/DimaSamodurov/erasvit
PHP | 4981 lines | 2233 code | 722 blank | 2026 comment | 677 complexity | 58e4c8ddb0760f829d3710437c99357b MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-3-Clause

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

  1. <?php
  2. /**
  3. * @version $Id: pclzip.lib.php 10381 2008-06-01 03:35:53Z pasamio $
  4. * @package Joomla
  5. */
  6. // --------------------------------------------------------------------------------
  7. // PhpConcept Library - Zip Module 2.1
  8. // --------------------------------------------------------------------------------
  9. // License GNU/LGPL - Vincent Blavet - December 2003
  10. // http://www.phpconcept.net
  11. // --------------------------------------------------------------------------------
  12. //
  13. // Presentation :
  14. // PclZip is a PHP library that manage ZIP archives.
  15. // So far tests show that archives generated by PclZip are readable by
  16. // WinZip application and other tools.
  17. //
  18. // Description :
  19. // See readme.txt and http://www.phpconcept.net
  20. //
  21. // Warning :
  22. // This library and the associated files are non commercial, non professional
  23. // work.
  24. // It should not have unexpected results. However if any damage is caused by
  25. // this software the author can not be responsible.
  26. // The use of this software is at the risk of the user.
  27. //
  28. // --------------------------------------------------------------------------------
  29. // $Id: pclzip.lib.php 10381 2008-06-01 03:35:53Z pasamio $
  30. // --------------------------------------------------------------------------------
  31. // ----- Constants
  32. define( 'PCLZIP_READ_BLOCK_SIZE', 2048 );
  33. // ----- File list separator
  34. // In version 1.x of PclZip, the separator for file list is a space
  35. // (which is not a very smart choice, specifically for windows paths !).
  36. // A better separator should be a comma (,). This constant gives you the
  37. // abilty to change that.
  38. // However notice that changing this value, may have impact on existing
  39. // scripts, using space separated filenames.
  40. // Recommanded values for compatibility with older versions :
  41. //define( 'PCLZIP_SEPARATOR', ' ' );
  42. // Recommanded values for smart separation of filenames.
  43. define( 'PCLZIP_SEPARATOR', ',' );
  44. // ----- Error configuration
  45. // 0 : PclZip Class integrated error handling
  46. // 1 : PclError external library error handling. By enabling this
  47. // you must ensure that you have included PclError library.
  48. // [2,...] : reserved for futur use
  49. define( 'PCLZIP_ERROR_EXTERNAL', 0 );
  50. // ----- Optional static temporary directory
  51. // By default temporary files are generated in the script current
  52. // path.
  53. // If defined :
  54. // - MUST BE terminated by a '/'.
  55. // - MUST be a valid, already created directory
  56. // Samples :
  57. // define( 'PCLZIP_TEMPORARY_DIR', '/temp/' );
  58. // define( 'PCLZIP_TEMPORARY_DIR', 'C:/Temp/' );
  59. define( 'PCLZIP_TEMPORARY_DIR', '' );
  60. // --------------------------------------------------------------------------------
  61. // ***** UNDER THIS LINE NOTHING NEEDS TO BE MODIFIED *****
  62. // --------------------------------------------------------------------------------
  63. // ----- Global variables
  64. $g_pclzip_version = "2.1";
  65. // ----- Error codes
  66. // -1 : Unable to open file in binary write mode
  67. // -2 : Unable to open file in binary read mode
  68. // -3 : Invalid parameters
  69. // -4 : File does not exist
  70. // -5 : Filename is too long (max. 255)
  71. // -6 : Not a valid zip file
  72. // -7 : Invalid extracted file size
  73. // -8 : Unable to create directory
  74. // -9 : Invalid archive extension
  75. // -10 : Invalid archive format
  76. // -11 : Unable to delete file (unlink)
  77. // -12 : Unable to rename file (rename)
  78. // -13 : Invalid header checksum
  79. // -14 : Invalid archive size
  80. define( 'PCLZIP_ERR_USER_ABORTED', 2 );
  81. define( 'PCLZIP_ERR_NO_ERROR', 0 );
  82. define( 'PCLZIP_ERR_WRITE_OPEN_FAIL', -1 );
  83. define( 'PCLZIP_ERR_READ_OPEN_FAIL', -2 );
  84. define( 'PCLZIP_ERR_INVALID_PARAMETER', -3 );
  85. define( 'PCLZIP_ERR_MISSING_FILE', -4 );
  86. define( 'PCLZIP_ERR_FILENAME_TOO_LONG', -5 );
  87. define( 'PCLZIP_ERR_INVALID_ZIP', -6 );
  88. define( 'PCLZIP_ERR_BAD_EXTRACTED_FILE', -7 );
  89. define( 'PCLZIP_ERR_DIR_CREATE_FAIL', -8 );
  90. define( 'PCLZIP_ERR_BAD_EXTENSION', -9 );
  91. define( 'PCLZIP_ERR_BAD_FORMAT', -10 );
  92. define( 'PCLZIP_ERR_DELETE_FILE_FAIL', -11 );
  93. define( 'PCLZIP_ERR_RENAME_FILE_FAIL', -12 );
  94. define( 'PCLZIP_ERR_BAD_CHECKSUM', -13 );
  95. define( 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14 );
  96. define( 'PCLZIP_ERR_MISSING_OPTION_VALUE', -15 );
  97. define( 'PCLZIP_ERR_INVALID_OPTION_VALUE', -16 );
  98. // ----- Options values
  99. define( 'PCLZIP_OPT_PATH', 77001 );
  100. define( 'PCLZIP_OPT_ADD_PATH', 77002 );
  101. define( 'PCLZIP_OPT_REMOVE_PATH', 77003 );
  102. define( 'PCLZIP_OPT_REMOVE_ALL_PATH', 77004 );
  103. define( 'PCLZIP_OPT_SET_CHMOD', 77005 );
  104. define( 'PCLZIP_OPT_EXTRACT_AS_STRING', 77006 );
  105. define( 'PCLZIP_OPT_NO_COMPRESSION', 77007 );
  106. define( 'PCLZIP_OPT_BY_NAME', 77008 );
  107. define( 'PCLZIP_OPT_BY_INDEX', 77009 );
  108. define( 'PCLZIP_OPT_BY_EREG', 77010 );
  109. define( 'PCLZIP_OPT_BY_PREG', 77011 );
  110. define( 'PCLZIP_OPT_COMMENT', 77012 );
  111. define( 'PCLZIP_OPT_ADD_COMMENT', 77013 );
  112. define( 'PCLZIP_OPT_PREPEND_COMMENT', 77014 );
  113. define( 'PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015 );
  114. // ----- Call backs values
  115. define( 'PCLZIP_CB_PRE_EXTRACT', 78001 );
  116. define( 'PCLZIP_CB_POST_EXTRACT', 78002 );
  117. define( 'PCLZIP_CB_PRE_ADD', 78003 );
  118. define( 'PCLZIP_CB_POST_ADD', 78004 );
  119. /* For futur use
  120. define( 'PCLZIP_CB_PRE_LIST', 78005 );
  121. define( 'PCLZIP_CB_POST_LIST', 78006 );
  122. define( 'PCLZIP_CB_PRE_DELETE', 78007 );
  123. define( 'PCLZIP_CB_POST_DELETE', 78008 );
  124. */
  125. // --------------------------------------------------------------------------------
  126. // Class : PclZip
  127. // Description :
  128. // PclZip is the class that represent a Zip archive.
  129. // The public methods allow the manipulation of the archive.
  130. // Attributes :
  131. // Attributes must not be accessed directly.
  132. // Methods :
  133. // PclZip() : Object creator
  134. // create() : Creates the Zip archive
  135. // listContent() : List the content of the Zip archive
  136. // extract() : Extract the content of the archive
  137. // properties() : List the properties of the archive
  138. // --------------------------------------------------------------------------------
  139. class PclZip
  140. {
  141. // ----- Filename of the zip file
  142. var $zipname = '';
  143. // ----- File descriptor of the zip file
  144. var $zip_fd = 0;
  145. // ----- Internal error handling
  146. var $error_code = 1;
  147. var $error_string = '';
  148. // --------------------------------------------------------------------------------
  149. // Function : PclZip()
  150. // Description :
  151. // Creates a PclZip object and set the name of the associated Zip archive
  152. // filename.
  153. // Note that no real action is taken, if the archive does not exist it is not
  154. // created. Use create() for that.
  155. // --------------------------------------------------------------------------------
  156. function PclZip($p_zipname)
  157. {
  158. //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::PclZip', "zipname=$p_zipname");
  159. // ----- Tests the zlib
  160. if (!function_exists('gzopen'))
  161. {
  162. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 1, "zlib extension seems to be missing");
  163. die('Abort '.basename(__FILE__).' : Missing zlib extensions');
  164. }
  165. // ----- Set the attributes
  166. $this->zipname = $p_zipname;
  167. $this->zip_fd = 0;
  168. // ----- Return
  169. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 1);
  170. return;
  171. }
  172. // --------------------------------------------------------------------------------
  173. // --------------------------------------------------------------------------------
  174. // Function :
  175. // create($p_filelist, $p_add_dir="", $p_remove_dir="")
  176. // create($p_filelist, $p_option, $p_option_value, ...)
  177. // Description :
  178. // This method supports two different synopsis. The first one is historical.
  179. // This method creates a Zip Archive. The Zip file is created in the
  180. // filesystem. The files and directories indicated in $p_filelist
  181. // are added in the archive. See the parameters description for the
  182. // supported format of $p_filelist.
  183. // When a directory is in the list, the directory and its content is added
  184. // in the archive.
  185. // In this synopsis, the function takes an optional variable list of
  186. // options. See bellow the supported options.
  187. // Parameters :
  188. // $p_filelist : An array containing file or directory names, or
  189. // a string containing one filename or one directory name, or
  190. // a string containing a list of filenames and/or directory
  191. // names separated by spaces.
  192. // $p_add_dir : A path to add before the real path of the archived file,
  193. //in order to have it memorized in the archive.
  194. // $p_remove_dir : A path to remove from the real path of the file to archive,
  195. // in order to have a shorter path memorized in the archive.
  196. // When $p_add_dir and $p_remove_dir are set, $p_remove_dir
  197. // is removed first, before $p_add_dir is added.
  198. // Options :
  199. // PCLZIP_OPT_ADD_PATH :
  200. // PCLZIP_OPT_REMOVE_PATH :
  201. // PCLZIP_OPT_REMOVE_ALL_PATH :
  202. // PCLZIP_OPT_COMMENT :
  203. // PCLZIP_CB_PRE_ADD :
  204. // PCLZIP_CB_POST_ADD :
  205. // Return Values :
  206. // 0 on failure,
  207. // The list of the added files, with a status of the add action.
  208. // (see PclZip::listContent() for list entry format)
  209. // --------------------------------------------------------------------------------
  210. // function create($p_filelist, $p_add_dir="", $p_remove_dir="")
  211. function create($p_filelist /*, options */)
  212. {
  213. //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::create', "filelist='$p_filelist', ...");
  214. $v_result=1;
  215. // ----- Reset the error handler
  216. $this->privErrorReset();
  217. // ----- Set default values
  218. $v_options = array();
  219. $v_add_path = "";
  220. $v_remove_path = "";
  221. $v_remove_all_path = false;
  222. $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
  223. // ----- Look for variable options arguments
  224. $v_size = func_num_args();
  225. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
  226. // ----- Look for arguments
  227. if ($v_size > 1) {
  228. // ----- Get the arguments
  229. $v_arg_list = &func_get_args();
  230. // ----- Remove form the options list the first argument
  231. array_shift($v_arg_list);
  232. $v_size--;
  233. // ----- Look for first arg
  234. if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
  235. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected");
  236. // ----- Parse the options
  237. $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
  238. array (PCLZIP_OPT_REMOVE_PATH => 'optional',
  239. PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
  240. PCLZIP_OPT_ADD_PATH => 'optional',
  241. PCLZIP_CB_PRE_ADD => 'optional',
  242. PCLZIP_CB_POST_ADD => 'optional',
  243. PCLZIP_OPT_NO_COMPRESSION => 'optional',
  244. PCLZIP_OPT_COMMENT => 'optional' ));
  245. if ($v_result != 1) {
  246. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  247. return 0;
  248. }
  249. // ----- Set the arguments
  250. if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
  251. $v_add_path = $v_options[PCLZIP_OPT_ADD_PATH];
  252. }
  253. if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
  254. $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
  255. }
  256. if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
  257. $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
  258. }
  259. }
  260. // ----- Look for 2 args
  261. // Here we need to support the first historic synopsis of the
  262. // method.
  263. else {
  264. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");
  265. // ----- Get the first argument
  266. $v_add_path = $v_arg_list[0];
  267. // ----- Look for the optional second argument
  268. if ($v_size == 2) {
  269. $v_remove_path = $v_arg_list[1];
  270. }
  271. else if ($v_size > 2) {
  272. // ----- Error log
  273. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
  274. "Invalid number / type of arguments");
  275. // ----- Return
  276. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  277. return 0;
  278. }
  279. }
  280. }
  281. // ----- Trace
  282. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "add_path='$v_add_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_all_path?'true':'false')."'");
  283. // ----- Look if the $p_filelist is really an array
  284. $p_result_list = array();
  285. if (is_array($p_filelist))
  286. {
  287. // ----- Call the create fct
  288. $v_result = $this->privCreate($p_filelist, $p_result_list, $v_add_path, $v_remove_path, $v_remove_all_path, $v_options);
  289. }
  290. // ----- Look if the $p_filelist is a string
  291. else if (is_string($p_filelist))
  292. {
  293. // ----- Create a list with the elements from the string
  294. $v_list = explode(PCLZIP_SEPARATOR, $p_filelist);
  295. // ----- Call the create fct
  296. $v_result = $this->privCreate($v_list, $p_result_list, $v_add_path, $v_remove_path, $v_remove_all_path, $v_options);
  297. }
  298. // ----- Invalid variable
  299. else
  300. {
  301. // ----- Error log
  302. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
  303. $v_result = PCLZIP_ERR_INVALID_PARAMETER;
  304. }
  305. if ($v_result != 1)
  306. {
  307. // ----- Return
  308. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  309. return 0;
  310. }
  311. // ----- Return
  312. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list);
  313. return $p_result_list;
  314. }
  315. // --------------------------------------------------------------------------------
  316. // --------------------------------------------------------------------------------
  317. // Function :
  318. // add($p_filelist, $p_add_dir="", $p_remove_dir="")
  319. // add($p_filelist, $p_option, $p_option_value, ...)
  320. // Description :
  321. // This method supports two synopsis. The first one is historical.
  322. // This methods add the list of files in an existing archive.
  323. // If a file with the same name already exists, it is added at the end of the
  324. // archive, the first one is still present.
  325. // If the archive does not exist, it is created.
  326. // Parameters :
  327. // $p_filelist : An array containing file or directory names, or
  328. // a string containing one filename or one directory name, or
  329. // a string containing a list of filenames and/or directory
  330. // names separated by spaces.
  331. // $p_add_dir : A path to add before the real path of the archived file,
  332. //in order to have it memorized in the archive.
  333. // $p_remove_dir : A path to remove from the real path of the file to archive,
  334. // in order to have a shorter path memorized in the archive.
  335. // When $p_add_dir and $p_remove_dir are set, $p_remove_dir
  336. // is removed first, before $p_add_dir is added.
  337. // Options :
  338. // PCLZIP_OPT_ADD_PATH :
  339. // PCLZIP_OPT_REMOVE_PATH :
  340. // PCLZIP_OPT_REMOVE_ALL_PATH :
  341. // PCLZIP_OPT_COMMENT :
  342. // PCLZIP_OPT_ADD_COMMENT :
  343. // PCLZIP_OPT_PREPEND_COMMENT :
  344. // PCLZIP_CB_PRE_ADD :
  345. // PCLZIP_CB_POST_ADD :
  346. // Return Values :
  347. // 0 on failure,
  348. // The list of the added files, with a status of the add action.
  349. // (see PclZip::listContent() for list entry format)
  350. // --------------------------------------------------------------------------------
  351. // function add($p_filelist, $p_add_dir="", $p_remove_dir="")
  352. function add($p_filelist /* options */)
  353. {
  354. //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::add', "filelist='$p_filelist', ...");
  355. $v_result=1;
  356. // ----- Reset the error handler
  357. $this->privErrorReset();
  358. // ----- Set default values
  359. $v_options = array();
  360. $v_add_path = "";
  361. $v_remove_path = "";
  362. $v_remove_all_path = false;
  363. $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
  364. // ----- Look for variable options arguments
  365. $v_size = func_num_args();
  366. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
  367. // ----- Look for arguments
  368. if ($v_size > 1) {
  369. // ----- Get the arguments
  370. $v_arg_list = &func_get_args();
  371. // ----- Remove form the options list the first argument
  372. array_shift($v_arg_list);
  373. $v_size--;
  374. // ----- Look for first arg
  375. if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
  376. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options detected");
  377. // ----- Parse the options
  378. $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
  379. array (PCLZIP_OPT_REMOVE_PATH => 'optional',
  380. PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
  381. PCLZIP_OPT_ADD_PATH => 'optional',
  382. PCLZIP_CB_PRE_ADD => 'optional',
  383. PCLZIP_CB_POST_ADD => 'optional',
  384. PCLZIP_OPT_NO_COMPRESSION => 'optional',
  385. PCLZIP_OPT_COMMENT => 'optional',
  386. PCLZIP_OPT_ADD_COMMENT => 'optional',
  387. PCLZIP_OPT_PREPEND_COMMENT => 'optional' ));
  388. if ($v_result != 1) {
  389. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  390. return 0;
  391. }
  392. // ----- Set the arguments
  393. if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
  394. $v_add_path = $v_options[PCLZIP_OPT_ADD_PATH];
  395. }
  396. if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
  397. $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
  398. }
  399. if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
  400. $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
  401. }
  402. }
  403. // ----- Look for 2 args
  404. // Here we need to support the first historic synopsis of the
  405. // method.
  406. else {
  407. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");
  408. // ----- Get the first argument
  409. $v_add_path = $v_arg_list[0];
  410. // ----- Look for the optional second argument
  411. if ($v_size == 2) {
  412. $v_remove_path = $v_arg_list[1];
  413. }
  414. else if ($v_size > 2) {
  415. // ----- Error log
  416. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
  417. // ----- Return
  418. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  419. return 0;
  420. }
  421. }
  422. }
  423. // ----- Trace
  424. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "add_path='$v_add_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_all_path?'true':'false')."'");
  425. // ----- Look if the $p_filelist is really an array
  426. $p_result_list = array();
  427. if (is_array($p_filelist))
  428. {
  429. // ----- Call the create fct
  430. $v_result = $this->privAdd($p_filelist, $p_result_list, $v_add_path, $v_remove_path, $v_remove_all_path, $v_options);
  431. }
  432. // ----- Look if the $p_filelist is a string
  433. else if (is_string($p_filelist))
  434. {
  435. // ----- Create a list with the elements from the string
  436. $v_list = explode(PCLZIP_SEPARATOR, $p_filelist);
  437. // ----- Call the create fct
  438. $v_result = $this->privAdd($v_list, $p_result_list, $v_add_path, $v_remove_path, $v_remove_all_path, $v_options);
  439. }
  440. // ----- Invalid variable
  441. else
  442. {
  443. // ----- Error log
  444. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
  445. $v_result = PCLZIP_ERR_INVALID_PARAMETER;
  446. }
  447. if ($v_result != 1)
  448. {
  449. // ----- Return
  450. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  451. return 0;
  452. }
  453. // ----- Return
  454. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_result_list);
  455. return $p_result_list;
  456. }
  457. // --------------------------------------------------------------------------------
  458. // --------------------------------------------------------------------------------
  459. // Function : listContent()
  460. // Description :
  461. // This public method, gives the list of the files and directories, with their
  462. // properties.
  463. // The properties of each entries in the list are (used also in other functions) :
  464. // filename : Name of the file. For a create or add action it is the filename
  465. //given by the user. For an extract function it is the filename
  466. //of the extracted file.
  467. // stored_filename : Name of the file / directory stored in the archive.
  468. // size : Size of the stored file.
  469. // compressed_size : Size of the file's data compressed in the archive
  470. // (without the headers overhead)
  471. // mtime : Last known modification date of the file (UNIX timestamp)
  472. // comment : Comment associated with the file
  473. // folder : true | false
  474. // index : index of the file in the archive
  475. // status : status of the action (depending of the action) :
  476. // Values are :
  477. //ok : OK !
  478. //filtered : the file / dir is not extracted (filtered by user)
  479. //already_a_directory : the file can not be extracted because a
  480. // directory with the same name already exists
  481. //write_protected : the file can not be extracted because a file
  482. // with the same name already exists and is
  483. // write protected
  484. //newer_exist : the file was not extracted because a newer file exists
  485. //path_creation_fail : the file is not extracted because the folder
  486. // does not exists and can not be created
  487. //write_error : the file was not extracted because there was a
  488. // error while writing the file
  489. //read_error : the file was not extracted because there was a error
  490. // while reading the file
  491. //invalid_header : the file was not extracted because of an archive
  492. // format error (bad file header)
  493. // Note that each time a method can continue operating when there
  494. // is an action error on a file, the error is only logged in the file status.
  495. // Return Values :
  496. // 0 on an unrecoverable failure,
  497. // The list of the files in the archive.
  498. // --------------------------------------------------------------------------------
  499. function listContent()
  500. {
  501. //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, 'PclZip::listContent', "");
  502. $v_result=1;
  503. // ----- Reset the error handler
  504. $this->privErrorReset();
  505. // ----- Check archive
  506. if (!$this->privCheckFormat()) {
  507. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  508. return(0);
  509. }
  510. // ----- Call the extracting fct
  511. $p_list = array();
  512. if (($v_result = $this->privList($p_list)) != 1)
  513. {
  514. unset($p_list);
  515. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
  516. return(0);
  517. }
  518. // ----- Return
  519. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);
  520. return $p_list;
  521. }
  522. // --------------------------------------------------------------------------------
  523. // --------------------------------------------------------------------------------
  524. // Function :
  525. // extract($p_path="./", $p_remove_path="")
  526. // extract([$p_option, $p_option_value, ...])
  527. // Description :
  528. // This method supports two synopsis. The first one is historical.
  529. // This method extract all the files / directories from the archive to the
  530. // folder indicated in $p_path.
  531. // If you want to ignore the 'root' part of path of the memorized files
  532. // you can indicate this in the optional $p_remove_path parameter.
  533. // By default, if a newer file with the same name already exists, the
  534. // file is not extracted.
  535. //
  536. // If both PCLZIP_OPT_PATH and PCLZIP_OPT_ADD_PATH aoptions
  537. // are used, the path indicated in PCLZIP_OPT_ADD_PATH is append
  538. // at the end of the path value of PCLZIP_OPT_PATH.
  539. // Parameters :
  540. // $p_path : Path where the files and directories are to be extracted
  541. // $p_remove_path : First part ('root' part) of the memorized path
  542. //(if any similar) to remove while extracting.
  543. // Options :
  544. // PCLZIP_OPT_PATH :
  545. // PCLZIP_OPT_ADD_PATH :
  546. // PCLZIP_OPT_REMOVE_PATH :
  547. // PCLZIP_OPT_REMOVE_ALL_PATH :
  548. // PCLZIP_CB_PRE_EXTRACT :
  549. // PCLZIP_CB_POST_EXTRACT :
  550. // Return Values :
  551. // 0 or a negative value on failure,
  552. // The list of the extracted files, with a status of the action.
  553. // (see PclZip::listContent() for list entry format)
  554. // --------------------------------------------------------------------------------
  555. //function extract($p_path="./", $p_remove_path="")
  556. function extract(/* options */)
  557. {
  558. //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extract", "");
  559. $v_result=1;
  560. // ----- Reset the error handler
  561. $this->privErrorReset();
  562. // ----- Check archive
  563. if (!$this->privCheckFormat()) {
  564. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  565. return(0);
  566. }
  567. // ----- Set default values
  568. $v_options = array();
  569. $v_path = "./";
  570. $v_remove_path = "";
  571. $v_remove_all_path = false;
  572. // ----- Look for variable options arguments
  573. $v_size = func_num_args();
  574. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
  575. // ----- Default values for option
  576. $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
  577. // ----- Look for arguments
  578. if ($v_size > 0) {
  579. // ----- Get the arguments
  580. $v_arg_list = func_get_args();
  581. // ----- Look for first arg
  582. if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
  583. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options");
  584. // ----- Parse the options
  585. $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
  586. array (PCLZIP_OPT_PATH => 'optional',
  587. PCLZIP_OPT_REMOVE_PATH => 'optional',
  588. PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
  589. PCLZIP_OPT_ADD_PATH => 'optional',
  590. PCLZIP_CB_PRE_EXTRACT => 'optional',
  591. PCLZIP_CB_POST_EXTRACT => 'optional',
  592. PCLZIP_OPT_SET_CHMOD => 'optional',
  593. PCLZIP_OPT_BY_NAME => 'optional',
  594. PCLZIP_OPT_BY_EREG => 'optional',
  595. PCLZIP_OPT_BY_PREG => 'optional',
  596. PCLZIP_OPT_BY_INDEX => 'optional',
  597. PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
  598. PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional' ));
  599. if ($v_result != 1) {
  600. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  601. return 0;
  602. }
  603. // ----- Set the arguments
  604. if (isset($v_options[PCLZIP_OPT_PATH])) {
  605. $v_path = $v_options[PCLZIP_OPT_PATH];
  606. }
  607. if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
  608. $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
  609. }
  610. if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
  611. $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
  612. }
  613. if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
  614. // ----- Check for '/' in last path char
  615. if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
  616. $v_path .= '/';
  617. }
  618. $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
  619. }
  620. }
  621. // ----- Look for 2 args
  622. // Here we need to support the first historic synopsis of the
  623. // method.
  624. else {
  625. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");
  626. // ----- Get the first argument
  627. $v_path = $v_arg_list[0];
  628. // ----- Look for the optional second argument
  629. if ($v_size == 2) {
  630. $v_remove_path = $v_arg_list[1];
  631. }
  632. else if ($v_size > 2) {
  633. // ----- Error log
  634. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
  635. // ----- Return
  636. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
  637. return 0;
  638. }
  639. }
  640. }
  641. // ----- Trace
  642. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "path='$v_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_path?'true':'false')."'");
  643. // ----- Call the extracting fct
  644. $p_list = array();
  645. $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path,
  646. $v_remove_all_path, $v_options);
  647. if ($v_result < 1) {
  648. unset($p_list);
  649. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
  650. return(0);
  651. }
  652. // ----- Return
  653. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);
  654. return $p_list;
  655. }
  656. // --------------------------------------------------------------------------------
  657. // --------------------------------------------------------------------------------
  658. // Function :
  659. // extractByIndex($p_index, $p_path="./", $p_remove_path="")
  660. // extractByIndex($p_index, [$p_option, $p_option_value, ...])
  661. // Description :
  662. // This method supports two synopsis. The first one is historical.
  663. // This method is doing a partial extract of the archive.
  664. // The extracted files or folders are identified by their index in the
  665. // archive (from 0 to n).
  666. // Note that if the index identify a folder, only the folder entry is
  667. // extracted, not all the files included in the archive.
  668. // Parameters :
  669. // $p_index : A single index (integer) or a string of indexes of files to
  670. // extract. The form of the string is "0,4-6,8-12" with only numbers
  671. // and '-' for range or ',' to separate ranges. No spaces or ';'
  672. // are allowed.
  673. // $p_path : Path where the files and directories are to be extracted
  674. // $p_remove_path : First part ('root' part) of the memorized path
  675. //(if any similar) to remove while extracting.
  676. // Options :
  677. // PCLZIP_OPT_PATH :
  678. // PCLZIP_OPT_ADD_PATH :
  679. // PCLZIP_OPT_REMOVE_PATH :
  680. // PCLZIP_OPT_REMOVE_ALL_PATH :
  681. // PCLZIP_OPT_EXTRACT_AS_STRING : The files are extracted as strings and
  682. // not as files.
  683. // The resulting content is in a new field 'content' in the file
  684. // structure.
  685. // This option must be used alone (any other options are ignored).
  686. // PCLZIP_CB_PRE_EXTRACT :
  687. // PCLZIP_CB_POST_EXTRACT :
  688. // Return Values :
  689. // 0 on failure,
  690. // The list of the extracted files, with a status of the action.
  691. // (see PclZip::listContent() for list entry format)
  692. // --------------------------------------------------------------------------------
  693. function extractByIndex($p_index /* $options */)
  694. {
  695. //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::extractByIndex", "index='$p_index', ...");
  696. $v_result=1;
  697. // ----- Reset the error handler
  698. $this->privErrorReset();
  699. // ----- Check archive
  700. if (!$this->privCheckFormat()) {
  701. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  702. return(0);
  703. }
  704. // ----- Set default values
  705. $v_options = array();
  706. $v_path = "./";
  707. $v_remove_path = "";
  708. $v_remove_all_path = false;
  709. // ----- Look for variable options arguments
  710. $v_size = func_num_args();
  711. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
  712. // ----- Default values for option
  713. $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
  714. // ----- Look for arguments
  715. if ($v_size > 1) {
  716. // ----- Get the arguments
  717. $v_arg_list = &func_get_args();
  718. // ----- Remove form the options list the first argument
  719. array_shift($v_arg_list);
  720. $v_size--;
  721. // ----- Look for first arg
  722. if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
  723. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Variable list of options");
  724. // ----- Parse the options
  725. $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
  726. array (PCLZIP_OPT_PATH => 'optional',
  727. PCLZIP_OPT_REMOVE_PATH => 'optional',
  728. PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
  729. PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
  730. PCLZIP_OPT_ADD_PATH => 'optional',
  731. PCLZIP_CB_PRE_EXTRACT => 'optional',
  732. PCLZIP_CB_POST_EXTRACT => 'optional',
  733. PCLZIP_OPT_SET_CHMOD => 'optional' ));
  734. if ($v_result != 1) {
  735. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  736. return 0;
  737. }
  738. // ----- Set the arguments
  739. if (isset($v_options[PCLZIP_OPT_PATH])) {
  740. $v_path = $v_options[PCLZIP_OPT_PATH];
  741. }
  742. if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
  743. $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
  744. }
  745. if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
  746. $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
  747. }
  748. if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
  749. // ----- Check for '/' in last path char
  750. if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
  751. $v_path .= '/';
  752. }
  753. $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
  754. }
  755. if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {
  756. $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
  757. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Option PCLZIP_OPT_EXTRACT_AS_STRING not set.");
  758. }
  759. else {
  760. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Option PCLZIP_OPT_EXTRACT_AS_STRING set.");
  761. }
  762. }
  763. // ----- Look for 2 args
  764. // Here we need to support the first historic synopsis of the
  765. // method.
  766. else {
  767. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Static synopsis");
  768. // ----- Get the first argument
  769. $v_path = $v_arg_list[0];
  770. // ----- Look for the optional second argument
  771. if ($v_size == 2) {
  772. $v_remove_path = $v_arg_list[1];
  773. }
  774. else if ($v_size > 2) {
  775. // ----- Error log
  776. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
  777. // ----- Return
  778. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  779. return 0;
  780. }
  781. }
  782. }
  783. // ----- Trace
  784. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "index='$p_index', path='$v_path', remove_path='$v_remove_path', remove_all_path='".($v_remove_path?'true':'false')."'");
  785. // ----- Trick
  786. // Here I want to reuse extractByRule(), so I need to parse the $p_index
  787. // with privParseOptions()
  788. $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index);
  789. $v_options_trick = array();
  790. $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick,
  791. array (PCLZIP_OPT_BY_INDEX => 'optional' ));
  792. if ($v_result != 1) {
  793. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  794. return 0;
  795. }
  796. $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];
  797. // ----- Call the extracting fct
  798. if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {
  799. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
  800. return(0);
  801. }
  802. // ----- Return
  803. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);
  804. return $p_list;
  805. }
  806. // --------------------------------------------------------------------------------
  807. // --------------------------------------------------------------------------------
  808. // Function :
  809. // delete([$p_option, $p_option_value, ...])
  810. // Description :
  811. // Parameters :
  812. // None
  813. // Options :
  814. // PCLZIP_OPT_BY_INDEX :
  815. // Return Values :
  816. // 0 on failure,
  817. // The list of the files which are still present in the archive.
  818. // (see PclZip::listContent() for list entry format)
  819. // --------------------------------------------------------------------------------
  820. function delete(/* options */)
  821. {
  822. //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::delete", "");
  823. $v_result=1;
  824. // ----- Reset the error handler
  825. $this->privErrorReset();
  826. // ----- Check archive
  827. if (!$this->privCheckFormat()) {
  828. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  829. return(0);
  830. }
  831. // ----- Set default values
  832. $v_options = array();
  833. // ----- Look for variable options arguments
  834. $v_size = func_num_args();
  835. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "$v_size arguments passed to the method");
  836. // ----- Look for no arguments
  837. if ($v_size <= 0) {
  838. // ----- Error log
  839. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing arguments");
  840. // ----- Return
  841. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
  842. return 0;
  843. }
  844. // ----- Get the arguments
  845. $v_arg_list = &func_get_args();
  846. // ----- Parse the options
  847. $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
  848. array (PCLZIP_OPT_BY_NAME => 'optional',
  849. PCLZIP_OPT_BY_EREG => 'optional',
  850. PCLZIP_OPT_BY_PREG => 'optional',
  851. PCLZIP_OPT_BY_INDEX => 'optional' ));
  852. if ($v_result != 1) {
  853. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  854. return 0;
  855. }
  856. // ----- Check that at least one rule is set
  857. if ( (!isset($v_options[PCLZIP_OPT_BY_NAME]))
  858. && (!isset($v_options[PCLZIP_OPT_BY_EREG]))
  859. && (!isset($v_options[PCLZIP_OPT_BY_PREG]))
  860. && (!isset($v_options[PCLZIP_OPT_BY_INDEX]))) {
  861. // ----- Error log
  862. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "At least one filtering rule must be set");
  863. // ----- Return
  864. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
  865. return 0;
  866. }
  867. // ----- Call the delete fct
  868. $v_list = array();
  869. if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1)
  870. {
  871. unset($v_list);
  872. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0, PclZip::errorInfo());
  873. return(0);
  874. }
  875. // ----- Return
  876. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_list);
  877. return $v_list;
  878. }
  879. // --------------------------------------------------------------------------------
  880. // --------------------------------------------------------------------------------
  881. // Function : deleteByIndex()
  882. // Description :
  883. // ***** Deprecated *****
  884. // delete(PCLZIP_OPT_BY_INDEX, $p_index) should be prefered.
  885. // --------------------------------------------------------------------------------
  886. function deleteByIndex($p_index)
  887. {
  888. //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::deleteByIndex", "index='$p_index'");
  889. $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index);
  890. // ----- Return
  891. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $p_list);
  892. return $p_list;
  893. }
  894. // --------------------------------------------------------------------------------
  895. // --------------------------------------------------------------------------------
  896. // Function : properties()
  897. // Description :
  898. // This method gives the properties of the archive.
  899. // The properties are :
  900. // nb : Number of files in the archive
  901. // comment : Comment associated with the archive file
  902. // status : not_exist, ok
  903. // Parameters :
  904. // None
  905. // Return Values :
  906. // 0 on failure,
  907. // An array with the archive properties.
  908. // --------------------------------------------------------------------------------
  909. function properties()
  910. {
  911. //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::properties", "");
  912. // ----- Reset the error handler
  913. $this->privErrorReset();
  914. // ----- Check archive
  915. if (!$this->privCheckFormat()) {
  916. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  917. return(0);
  918. }
  919. // ----- Default properties
  920. $v_prop = array();
  921. $v_prop['comment'] = '';
  922. $v_prop['nb'] = 0;
  923. $v_prop['status'] = 'not_exist';
  924. // ----- Look if file exists
  925. if (@is_file($this->zipname))
  926. {
  927. // ----- Open the zip file
  928. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");
  929. if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
  930. {
  931. // ----- Error log
  932. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
  933. // ----- Return
  934. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), 0);
  935. return 0;
  936. }
  937. // ----- Read the central directory informations
  938. $v_central_dir = array();
  939. if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
  940. {
  941. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  942. return 0;
  943. }
  944. // ----- Close the zip file
  945. $this->privCloseFd();
  946. // ----- Set the user attributes
  947. $v_prop['comment'] = $v_central_dir['comment'];
  948. $v_prop['nb'] = $v_central_dir['entries'];
  949. $v_prop['status'] = 'ok';
  950. }
  951. // ----- Return
  952. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_prop);
  953. return $v_prop;
  954. }
  955. // --------------------------------------------------------------------------------
  956. // --------------------------------------------------------------------------------
  957. // Function : duplicate()
  958. // Description :
  959. // This method creates an archive by copying the content of an other one. If
  960. // the archive already exist, it is replaced by the new one without any warning.
  961. // Parameters :
  962. // $p_archive : The filename of a valid archive, or
  963. //a valid PclZip object.
  964. // Return Values :
  965. // 1 on success.
  966. // 0 or a negative value on error (error code).
  967. // --------------------------------------------------------------------------------
  968. function duplicate($p_archive)
  969. {
  970. //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::duplicate", "");
  971. $v_result = 1;
  972. // ----- Reset the error handler
  973. $this->privErrorReset();
  974. // ----- Look if the $p_archive is a PclZip object
  975. if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip'))
  976. {
  977. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is valid PclZip object '".$p_archive->zipname."'");
  978. // ----- Duplicate the archive
  979. $v_result = $this->privDuplicate($p_archive->zipname);
  980. }
  981. // ----- Look if the $p_archive is a string (so a filename)
  982. else if (is_string($p_archive))
  983. {
  984. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "The parameter is a filename '$p_archive'");
  985. // ----- Check that $p_archive is a valid zip file
  986. // TBC : Should also check the archive format
  987. if (!is_file($p_archive)) {
  988. // ----- Error log
  989. PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'");
  990. $v_result = PCLZIP_ERR_MISSING_FILE;
  991. }
  992. else {
  993. // ----- Duplicate the archive
  994. $v_result = $this->privDuplicate($p_archive);
  995. }
  996. }
  997. // ----- Invalid variable
  998. else
  999. {
  1000. // ----- Error log
  1001. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
  1002. $v_result = PCLZIP_ERR_INVALID_PARAMETER;
  1003. }
  1004. // ----- Return
  1005. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  1006. return $v_result;
  1007. }
  1008. // --------------------------------------------------------------------------------
  1009. // --------------------------------------------------------------------------------
  1010. // Function : merge()
  1011. // Description :
  1012. // This method merge the $p_archive_to_add archive at the end of the current
  1013. // one ($this).
  1014. // If the archive ($this) does not exist, the merge becomes a duplicate.
  1015. // If the $p_archive_to_add archive does not exist, the merge is a success.
  1016. // Parameters :
  1017. // $p_archive_to_add : It can be directly the filename of a valid zip archive,
  1018. // or a PclZip object archive.
  1019. // Return Values :
  1020. // 1 on success,
  1021. // 0 or negative values on error (see below).
  1022. // --------------------------------------------------------------------------------
  1023. function merge($p_archive_to_add)
  1024. {
  1025. //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::merge", "");
  1026. $v_result = 1;
  1027. // ----- Reset the error handler
  1028. $this->privErrorReset();
  1029. // ----- Check archive
  1030. if (!$this->privCheckFormat()) {
  1031. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, 0);
  1032. return(0);
  1033. }
  1034. // ----- Look if the $p_archive_to_add is a PclZip object
  1035. if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip'))
  1036. {
  1037. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is valid PclZip object");
  1038. // ----- Merge the archive
  1039. $v_result = $this->privMerge($p_archive_to_add);
  1040. }
  1041. // ----- Look if the $p_archive_to_add is a string (so a filename)
  1042. else if (is_string($p_archive_to_add))
  1043. {
  1044. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 3, "The parameter is a filename");
  1045. // ----- Create a temporary archive
  1046. $v_object_archive = new PclZip($p_archive_to_add);
  1047. // ----- Merge the archive
  1048. $v_result = $this->privMerge($v_object_archive);
  1049. }
  1050. // ----- Invalid variable
  1051. else
  1052. {
  1053. // ----- Error log
  1054. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
  1055. $v_result = PCLZIP_ERR_INVALID_PARAMETER;
  1056. }
  1057. // ----- Return
  1058. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  1059. return $v_result;
  1060. }
  1061. // --------------------------------------------------------------------------------
  1062. // --------------------------------------------------------------------------------
  1063. // Function : errorCode()
  1064. // Description :
  1065. // Parameters :
  1066. // --------------------------------------------------------------------------------
  1067. function errorCode()
  1068. {
  1069. if (PCLZIP_ERROR_EXTERNAL == 1) {
  1070. return(PclErrorCode());
  1071. }
  1072. else {
  1073. return($this->error_code);
  1074. }
  1075. }
  1076. // --------------------------------------------------------------------------------
  1077. // --------------------------------------------------------------------------------
  1078. // Function : errorName()
  1079. // Description :
  1080. // Parameters :
  1081. // --------------------------------------------------------------------------------
  1082. function errorName($p_with_code=false)
  1083. {
  1084. $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',
  1085. PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',
  1086. PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',
  1087. PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',
  1088. PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',
  1089. PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',
  1090. PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',
  1091. PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',
  1092. PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',
  1093. PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',
  1094. PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',
  1095. PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',
  1096. PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',
  1097. PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',
  1098. PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',
  1099. PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',
  1100. PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE' );
  1101. if (isset($v_name[$this->error_code])) {
  1102. $v_value = $v_name[$this->error_code];
  1103. }
  1104. else {
  1105. $v_value = 'NoName';
  1106. }
  1107. if ($p_with_code) {
  1108. return($v_value.' ('.$this->error_code.')');
  1109. }
  1110. else {
  1111. return($v_value);
  1112. }
  1113. }
  1114. // --------------------------------------------------------------------------------
  1115. // --------------------------------------------------------------------------------
  1116. // Function : errorInfo()
  1117. // Description :
  1118. // Parameters :
  1119. // --------------------------------------------------------------------------------
  1120. function errorInfo($p_full=false)
  1121. {
  1122. if (PCLZIP_ERROR_EXTERNAL == 1) {
  1123. return(PclErrorString());
  1124. }
  1125. else {
  1126. if ($p_full) {
  1127. return($this->errorName(true)." : ".$this->error_string);
  1128. }
  1129. else {
  1130. return($this->error_string." [code ".$this->error_code."]");
  1131. }
  1132. }
  1133. }
  1134. // --------------------------------------------------------------------------------
  1135. // --------------------------------------------------------------------------------
  1136. // ***** UNDER THIS LINE ARE DEFINED PRIVATE INTERNAL FUNCTIONS *****
  1137. // **********
  1138. // ***** THESES FUNCTIONS MUST NOT BE USED DIRECTLY *****
  1139. // --------------------------------------------------------------------------------
  1140. // --------------------------------------------------------------------------------
  1141. // Function : privCheckFormat()
  1142. // Description :
  1143. // This method check that the archive exists and is a valid zip archive.
  1144. // Several level of check exists. (futur)
  1145. // Parameters :
  1146. // $p_level : Level of check. Default 0.
  1147. // 0 : Check the first bytes (magic codes) (default value))
  1148. // 1 : 0 + Check the central directory (futur)
  1149. // 2 : 1 + Check each file header (futur)
  1150. // Return Values :
  1151. // true on success,
  1152. // false on error, the error code is set.
  1153. // --------------------------------------------------------------------------------
  1154. function privCheckFormat($p_level=0)
  1155. {
  1156. //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privCheckFormat", "");
  1157. $v_result = true;
  1158. // ----- Reset the file system cache
  1159. clearstatcache();
  1160. // ----- Reset the error handler
  1161. $this->privErrorReset();
  1162. // ----- Look if the file exits
  1163. if (!is_file($this->zipname)) {
  1164. // ----- Error log
  1165. PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'");
  1166. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo());
  1167. return(false);
  1168. }
  1169. // ----- Check that the file is readeable
  1170. if (!is_readable($this->zipname)) {
  1171. // ----- Error log
  1172. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'");
  1173. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, false, PclZip::errorInfo());
  1174. return(false);
  1175. }
  1176. // ----- Check the magic code
  1177. // TBC
  1178. // ----- Check the central header
  1179. // TBC
  1180. // ----- Check each file header
  1181. // TBC
  1182. // ----- Return
  1183. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, $v_result);
  1184. return $v_result;
  1185. }
  1186. // --------------------------------------------------------------------------------
  1187. // --------------------------------------------------------------------------------
  1188. // Function : privParseOptions()
  1189. // Description :
  1190. // This internal methods reads the variable list of arguments ($p_options_list,
  1191. // $p_size) and generate an array with the options and values ($v_result_list).
  1192. // $v_requested_options contains the options that can be present and those that
  1193. // must be present.
  1194. // $v_requested_options is an array, with the option value as key, and 'optional',
  1195. // or 'mandatory' as value.
  1196. // Parameters :
  1197. // See above.
  1198. // Return Values :
  1199. // 1 on success.
  1200. // 0 on failure.
  1201. // --------------------------------------------------------------------------------
  1202. function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false)
  1203. {
  1204. //--(MAGIC-PclTrace)--//PclTraceFctStart(__FILE__, __LINE__, "PclZip::privParseOptions", "");
  1205. $v_result=1;
  1206. // ----- Read the options
  1207. $i=0;
  1208. while ($i<$p_size) {
  1209. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 4, "Looking for table index $i, option = '".PclZipUtilOptionText($p_options_list[$i])."(".$p_options_list[$i].")'");
  1210. // ----- Check if the option is requested
  1211. if (!isset($v_requested_options[$p_options_list[$i]])) {
  1212. // ----- Error log
  1213. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method");
  1214. // ----- Return
  1215. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1216. return PclZip::errorCode();
  1217. }
  1218. // ----- Look for next option
  1219. switch ($p_options_list[$i]) {
  1220. // ----- Look for options that request a path value
  1221. case PCLZIP_OPT_PATH :
  1222. case PCLZIP_OPT_REMOVE_PATH :
  1223. case PCLZIP_OPT_ADD_PATH :
  1224. // ----- Check the number of parameters
  1225. if (($i+1) >= $p_size) {
  1226. // ----- Error log
  1227. PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  1228. // ----- Return
  1229. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__, PclZip::errorCode(), PclZip::errorInfo());
  1230. return PclZip::errorCode();
  1231. }
  1232. // ----- Get the value
  1233. $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], false);
  1234. //--(MAGIC-PclTrace)--//PclTraceFctMessage(__FILE__, __LINE__, 2, "".PclZipUtilOptionText($p_options_list[$i])." = '".$v_result_list[$p_options_list[$i]]."'");
  1235. $i++;
  1236. break;
  1237. // ----- Look for options that request an array of string for value
  1238. case PCLZIP_OPT_BY_NAME :
  1239. // ----- Check the number of parameters
  1240. if (($i+1) >= $p_size) {
  1241. // ----- Error log
  1242. PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  1243. // ----- Return
  1244. //--(MAGIC-PclTrace)--//PclTraceFctEnd(__FILE__, __LINE__,…

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