Просмотр файла system/inc/classes/pclzip.class.php

Размер файла: 123.06Kb
  1. <?php
  2.  
  3. if (!defined('PCLZIP_READ_BLOCK_SIZE')) {define( 'PCLZIP_READ_BLOCK_SIZE', 2048 );}
  4. if (!defined('PCLZIP_SEPARATOR')) {define( 'PCLZIP_SEPARATOR', ',' );}
  5. if (!defined('PCLZIP_ERROR_EXTERNAL')) {define( 'PCLZIP_ERROR_EXTERNAL', 0 );}
  6. if (!defined('PCLZIP_TEMPORARY_DIR')) {define( 'PCLZIP_TEMPORARY_DIR', '' );}
  7. if (!defined('PCLZIP_TEMPORARY_FILE_RATIO')) {define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.47 );}
  8.  
  9. $g_pclzip_version = "2.8.2";
  10.  
  11. define( 'PCLZIP_ERR_USER_ABORTED', 2 );
  12. define( 'PCLZIP_ERR_NO_ERROR', 0 );
  13. define( 'PCLZIP_ERR_WRITE_OPEN_FAIL', -1 );
  14. define( 'PCLZIP_ERR_READ_OPEN_FAIL', -2 );
  15. define( 'PCLZIP_ERR_INVALID_PARAMETER', -3 );
  16. define( 'PCLZIP_ERR_MISSING_FILE', -4 );
  17. define( 'PCLZIP_ERR_FILENAME_TOO_LONG', -5 );
  18. define( 'PCLZIP_ERR_INVALID_ZIP', -6 );
  19. define( 'PCLZIP_ERR_BAD_EXTRACTED_FILE', -7 );
  20. define( 'PCLZIP_ERR_DIR_CREATE_FAIL', -8 );
  21. define( 'PCLZIP_ERR_BAD_EXTENSION', -9 );
  22. define( 'PCLZIP_ERR_BAD_FORMAT', -10 );
  23. define( 'PCLZIP_ERR_DELETE_FILE_FAIL', -11 );
  24. define( 'PCLZIP_ERR_RENAME_FILE_FAIL', -12 );
  25. define( 'PCLZIP_ERR_BAD_CHECKSUM', -13 );
  26. define( 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14 );
  27. define( 'PCLZIP_ERR_MISSING_OPTION_VALUE', -15 );
  28. define( 'PCLZIP_ERR_INVALID_OPTION_VALUE', -16 );
  29. define( 'PCLZIP_ERR_ALREADY_A_DIRECTORY', -17 );
  30. define( 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18 );
  31. define( 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19 );
  32. define( 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', -20 );
  33. define( 'PCLZIP_ERR_DIRECTORY_RESTRICTION', -21 );
  34.  
  35. define( 'PCLZIP_OPT_PATH', 77001 );
  36. define( 'PCLZIP_OPT_ADD_PATH', 77002 );
  37. define( 'PCLZIP_OPT_REMOVE_PATH', 77003 );
  38. define( 'PCLZIP_OPT_REMOVE_ALL_PATH', 77004 );
  39. define( 'PCLZIP_OPT_SET_CHMOD', 77005 );
  40. define( 'PCLZIP_OPT_EXTRACT_AS_STRING', 77006 );
  41. define( 'PCLZIP_OPT_NO_COMPRESSION', 77007 );
  42. define( 'PCLZIP_OPT_BY_NAME', 77008 );
  43. define( 'PCLZIP_OPT_BY_INDEX', 77009 );
  44. define( 'PCLZIP_OPT_BY_EREG', 77010 );
  45. define( 'PCLZIP_OPT_BY_PREG', 77011 );
  46. define( 'PCLZIP_OPT_COMMENT', 77012 );
  47. define( 'PCLZIP_OPT_ADD_COMMENT', 77013 );
  48. define( 'PCLZIP_OPT_PREPEND_COMMENT', 77014 );
  49. define( 'PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015 );
  50. define( 'PCLZIP_OPT_REPLACE_NEWER', 77016 );
  51. define( 'PCLZIP_OPT_STOP_ON_ERROR', 77017 );
  52. define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 );
  53. define( 'PCLZIP_OPT_TEMP_FILE_THRESHOLD', 77020 );
  54. define( 'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD', 77020 ); define( 'PCLZIP_OPT_TEMP_FILE_ON', 77021 );
  55. define( 'PCLZIP_OPT_ADD_TEMP_FILE_ON', 77021 ); define( 'PCLZIP_OPT_TEMP_FILE_OFF', 77022 );
  56. define( 'PCLZIP_OPT_ADD_TEMP_FILE_OFF', 77022 );
  57. define( 'PCLZIP_ATT_FILE_NAME', 79001 );
  58. define( 'PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002 );
  59. define( 'PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003 );
  60. define( 'PCLZIP_ATT_FILE_MTIME', 79004 );
  61. define( 'PCLZIP_ATT_FILE_CONTENT', 79005 );
  62. define( 'PCLZIP_ATT_FILE_COMMENT', 79006 );
  63.  
  64. define( 'PCLZIP_CB_PRE_EXTRACT', 78001 );
  65. define( 'PCLZIP_CB_POST_EXTRACT', 78002 );
  66. define( 'PCLZIP_CB_PRE_ADD', 78003 );
  67. define( 'PCLZIP_CB_POST_ADD', 78004 );
  68.  
  69. class PclZip {
  70. var $zipname = '';
  71. var $zip_fd = 0;
  72. var $error_code = 1;
  73. var $error_string = '';
  74. var $magic_quotes_status;
  75.  
  76. function PclZip($p_zipname)
  77. {
  78.  
  79. if (!function_exists('gzopen'))
  80. {
  81. die('Abort '.basename(__FILE__).' : Missing zlib extensions');
  82. }
  83.  
  84. $this->zipname = $p_zipname;
  85. $this->zip_fd = 0;
  86. $this->magic_quotes_status = -1;
  87.  
  88. return;
  89. }
  90. function create($p_filelist)
  91. {
  92. $v_result=1;
  93.  
  94. $this->privErrorReset();
  95.  
  96. $v_options = array();
  97. $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
  98.  
  99. $v_size = func_num_args();
  100.  
  101. if ($v_size > 1) {
  102. $v_arg_list = func_get_args();
  103.  
  104. array_shift($v_arg_list);
  105. $v_size--;
  106.  
  107. if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
  108.  
  109. $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
  110. array (PCLZIP_OPT_REMOVE_PATH => 'optional',
  111. PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
  112. PCLZIP_OPT_ADD_PATH => 'optional',
  113. PCLZIP_CB_PRE_ADD => 'optional',
  114. PCLZIP_CB_POST_ADD => 'optional',
  115. PCLZIP_OPT_NO_COMPRESSION => 'optional',
  116. PCLZIP_OPT_COMMENT => 'optional',
  117. PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
  118. PCLZIP_OPT_TEMP_FILE_ON => 'optional',
  119. PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
  120. ));
  121. if ($v_result != 1) {
  122. return 0;
  123. }
  124. }
  125.  
  126. else {
  127.  
  128. $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0];
  129.  
  130. if ($v_size == 2) {
  131. $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
  132. }
  133. else if ($v_size > 2) {
  134. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
  135. "Invalid number / type of arguments");
  136. return 0;
  137. }
  138. }
  139. }
  140. $this->privOptionDefaultThreshold($v_options);
  141.  
  142. $v_string_list = array();
  143. $v_att_list = array();
  144. $v_filedescr_list = array();
  145. $p_result_list = array();
  146. if (is_array($p_filelist)) {
  147. if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
  148. $v_att_list = $p_filelist;
  149. }
  150. else {
  151. $v_string_list = $p_filelist;
  152. }
  153. }
  154.  
  155. else if (is_string($p_filelist)) {
  156. $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
  157. }
  158.  
  159. else {
  160. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
  161. return 0;
  162. }
  163. if (sizeof($v_string_list) != 0) {
  164. foreach ($v_string_list as $v_string) {
  165. if ($v_string != '') {
  166. $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
  167. }
  168. else {
  169. }
  170. }
  171. }
  172. $v_supported_attributes
  173. = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
  174. ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
  175. ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
  176. ,PCLZIP_ATT_FILE_MTIME => 'optional'
  177. ,PCLZIP_ATT_FILE_CONTENT => 'optional'
  178. ,PCLZIP_ATT_FILE_COMMENT => 'optional'
  179. );
  180. foreach ($v_att_list as $v_entry) {
  181. $v_result = $this->privFileDescrParseAtt($v_entry,
  182. $v_filedescr_list[],
  183. $v_options,
  184. $v_supported_attributes);
  185. if ($v_result != 1) {
  186. return 0;
  187. }
  188. }
  189.  
  190. $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
  191. if ($v_result != 1) {
  192. return 0;
  193. }
  194.  
  195. $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options);
  196. if ($v_result != 1) {
  197. return 0;
  198. }
  199.  
  200. return $p_result_list;
  201. }
  202. function add($p_filelist)
  203. {
  204. $v_result=1;
  205.  
  206. $this->privErrorReset();
  207.  
  208. $v_options = array();
  209. $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
  210.  
  211. $v_size = func_num_args();
  212.  
  213. if ($v_size > 1) {
  214. $v_arg_list = func_get_args();
  215.  
  216. array_shift($v_arg_list);
  217. $v_size--;
  218.  
  219. if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
  220.  
  221. $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
  222. array (PCLZIP_OPT_REMOVE_PATH => 'optional',
  223. PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
  224. PCLZIP_OPT_ADD_PATH => 'optional',
  225. PCLZIP_CB_PRE_ADD => 'optional',
  226. PCLZIP_CB_POST_ADD => 'optional',
  227. PCLZIP_OPT_NO_COMPRESSION => 'optional',
  228. PCLZIP_OPT_COMMENT => 'optional',
  229. PCLZIP_OPT_ADD_COMMENT => 'optional',
  230. PCLZIP_OPT_PREPEND_COMMENT => 'optional',
  231. PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
  232. PCLZIP_OPT_TEMP_FILE_ON => 'optional',
  233. PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
  234. ));
  235. if ($v_result != 1) {
  236. return 0;
  237. }
  238. }
  239.  
  240. else {
  241.  
  242. $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0];
  243.  
  244. if ($v_size == 2) {
  245. $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
  246. }
  247. else if ($v_size > 2) {
  248. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
  249.  
  250. return 0;
  251. }
  252. }
  253. }
  254.  
  255. $this->privOptionDefaultThreshold($v_options);
  256.  
  257. $v_string_list = array();
  258. $v_att_list = array();
  259. $v_filedescr_list = array();
  260. $p_result_list = array();
  261. if (is_array($p_filelist)) {
  262. if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
  263. $v_att_list = $p_filelist;
  264. }
  265. else {
  266. $v_string_list = $p_filelist;
  267. }
  268. }
  269.  
  270. else if (is_string($p_filelist)) {
  271. $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
  272. }
  273.  
  274. else {
  275. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist");
  276. return 0;
  277. }
  278. if (sizeof($v_string_list) != 0) {
  279. foreach ($v_string_list as $v_string) {
  280. $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
  281. }
  282. }
  283. $v_supported_attributes
  284. = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
  285. ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
  286. ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
  287. ,PCLZIP_ATT_FILE_MTIME => 'optional'
  288. ,PCLZIP_ATT_FILE_CONTENT => 'optional'
  289. ,PCLZIP_ATT_FILE_COMMENT => 'optional'
  290. );
  291. foreach ($v_att_list as $v_entry) {
  292. $v_result = $this->privFileDescrParseAtt($v_entry,
  293. $v_filedescr_list[],
  294. $v_options,
  295. $v_supported_attributes);
  296. if ($v_result != 1) {
  297. return 0;
  298. }
  299. }
  300.  
  301. $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
  302. if ($v_result != 1) {
  303. return 0;
  304. }
  305.  
  306. $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options);
  307. if ($v_result != 1) {
  308. return 0;
  309. }
  310.  
  311. return $p_result_list;
  312. }
  313. function listContent()
  314. {
  315. $v_result=1;
  316.  
  317. $this->privErrorReset();
  318.  
  319. if (!$this->privCheckFormat()) {
  320. return(0);
  321. }
  322.  
  323. $p_list = array();
  324. if (($v_result = $this->privList($p_list)) != 1)
  325. {
  326. unset($p_list);
  327. return(0);
  328. }
  329.  
  330. return $p_list;
  331. }
  332. function extract()
  333. {
  334. $v_result=1;
  335.  
  336. $this->privErrorReset();
  337.  
  338. if (!$this->privCheckFormat()) {
  339. return(0);
  340. }
  341.  
  342. $v_options = array();
  343. $v_path = '';
  344. $v_remove_path = "";
  345. $v_remove_all_path = false;
  346.  
  347. $v_size = func_num_args();
  348.  
  349. $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
  350.  
  351. if ($v_size > 0) {
  352. $v_arg_list = func_get_args();
  353.  
  354. if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
  355.  
  356. $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
  357. array (PCLZIP_OPT_PATH => 'optional',
  358. PCLZIP_OPT_REMOVE_PATH => 'optional',
  359. PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
  360. PCLZIP_OPT_ADD_PATH => 'optional',
  361. PCLZIP_CB_PRE_EXTRACT => 'optional',
  362. PCLZIP_CB_POST_EXTRACT => 'optional',
  363. PCLZIP_OPT_SET_CHMOD => 'optional',
  364. PCLZIP_OPT_BY_NAME => 'optional',
  365. PCLZIP_OPT_BY_EREG => 'optional',
  366. PCLZIP_OPT_BY_PREG => 'optional',
  367. PCLZIP_OPT_BY_INDEX => 'optional',
  368. PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
  369. PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',
  370. PCLZIP_OPT_REPLACE_NEWER => 'optional'
  371. ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
  372. ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
  373. PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
  374. PCLZIP_OPT_TEMP_FILE_ON => 'optional',
  375. PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
  376. ));
  377. if ($v_result != 1) {
  378. return 0;
  379. }
  380.  
  381. if (isset($v_options[PCLZIP_OPT_PATH])) {
  382. $v_path = $v_options[PCLZIP_OPT_PATH];
  383. }
  384. if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
  385. $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
  386. }
  387. if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
  388. $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
  389. }
  390. if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
  391. if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
  392. $v_path .= '/';
  393. }
  394. $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
  395. }
  396. }
  397.  
  398. else {
  399.  
  400. $v_path = $v_arg_list[0];
  401.  
  402. if ($v_size == 2) {
  403. $v_remove_path = $v_arg_list[1];
  404. }
  405. else if ($v_size > 2) {
  406. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
  407.  
  408. return 0;
  409. }
  410. }
  411. }
  412.  
  413. $this->privOptionDefaultThreshold($v_options);
  414.  
  415. $p_list = array();
  416. $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path,
  417. $v_remove_all_path, $v_options);
  418. if ($v_result < 1) {
  419. unset($p_list);
  420. return(0);
  421. }
  422.  
  423. return $p_list;
  424. }
  425.  
  426. function extractByIndex($p_index)
  427. {
  428. $v_result=1;
  429.  
  430. $this->privErrorReset();
  431.  
  432. if (!$this->privCheckFormat()) {
  433. return(0);
  434. }
  435.  
  436. $v_options = array();
  437. $v_path = '';
  438. $v_remove_path = "";
  439. $v_remove_all_path = false;
  440.  
  441. $v_size = func_num_args();
  442.  
  443. $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
  444.  
  445. if ($v_size > 1) {
  446. $v_arg_list = func_get_args();
  447.  
  448. array_shift($v_arg_list);
  449. $v_size--;
  450.  
  451. if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
  452.  
  453. $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
  454. array (PCLZIP_OPT_PATH => 'optional',
  455. PCLZIP_OPT_REMOVE_PATH => 'optional',
  456. PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
  457. PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
  458. PCLZIP_OPT_ADD_PATH => 'optional',
  459. PCLZIP_CB_PRE_EXTRACT => 'optional',
  460. PCLZIP_CB_POST_EXTRACT => 'optional',
  461. PCLZIP_OPT_SET_CHMOD => 'optional',
  462. PCLZIP_OPT_REPLACE_NEWER => 'optional'
  463. ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
  464. ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
  465. PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
  466. PCLZIP_OPT_TEMP_FILE_ON => 'optional',
  467. PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
  468. ));
  469. if ($v_result != 1) {
  470. return 0;
  471. }
  472.  
  473. if (isset($v_options[PCLZIP_OPT_PATH])) {
  474. $v_path = $v_options[PCLZIP_OPT_PATH];
  475. }
  476. if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
  477. $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
  478. }
  479. if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
  480. $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
  481. }
  482. if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
  483. if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
  484. $v_path .= '/';
  485. }
  486. $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
  487. }
  488. if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {
  489. $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
  490. }
  491. else {
  492. }
  493. }
  494.  
  495. else {
  496.  
  497. $v_path = $v_arg_list[0];
  498.  
  499. if ($v_size == 2) {
  500. $v_remove_path = $v_arg_list[1];
  501. }
  502. else if ($v_size > 2) {
  503. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
  504.  
  505. return 0;
  506. }
  507. }
  508. }
  509.  
  510. $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index);
  511. $v_options_trick = array();
  512. $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick,
  513. array (PCLZIP_OPT_BY_INDEX => 'optional' ));
  514. if ($v_result != 1) {
  515. return 0;
  516. }
  517. $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];
  518.  
  519. $this->privOptionDefaultThreshold($v_options);
  520.  
  521. if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {
  522. return(0);
  523. }
  524.  
  525. return $p_list;
  526. }
  527. function delete()
  528. {
  529. $v_result=1;
  530.  
  531. $this->privErrorReset();
  532.  
  533. if (!$this->privCheckFormat()) {
  534. return(0);
  535. }
  536.  
  537. $v_options = array();
  538.  
  539. $v_size = func_num_args();
  540.  
  541. if ($v_size > 0) {
  542. $v_arg_list = func_get_args();
  543.  
  544. $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
  545. array (PCLZIP_OPT_BY_NAME => 'optional',
  546. PCLZIP_OPT_BY_EREG => 'optional',
  547. PCLZIP_OPT_BY_PREG => 'optional',
  548. PCLZIP_OPT_BY_INDEX => 'optional' ));
  549. if ($v_result != 1) {
  550. return 0;
  551. }
  552. }
  553.  
  554. $this->privDisableMagicQuotes();
  555.  
  556. $v_list = array();
  557. if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) {
  558. $this->privSwapBackMagicQuotes();
  559. unset($v_list);
  560. return(0);
  561. }
  562.  
  563. $this->privSwapBackMagicQuotes();
  564.  
  565. return $v_list;
  566. }
  567. function deleteByIndex($p_index)
  568. {
  569. $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index);
  570.  
  571. return $p_list;
  572. }
  573. function properties()
  574. {
  575.  
  576. $this->privErrorReset();
  577.  
  578. $this->privDisableMagicQuotes();
  579.  
  580. if (!$this->privCheckFormat()) {
  581. $this->privSwapBackMagicQuotes();
  582. return(0);
  583. }
  584.  
  585. $v_prop = array();
  586. $v_prop['comment'] = '';
  587. $v_prop['nb'] = 0;
  588. $v_prop['status'] = 'not_exist';
  589.  
  590. if (@is_file($this->zipname))
  591. {
  592. if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
  593. {
  594. $this->privSwapBackMagicQuotes();
  595. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
  596.  
  597. return 0;
  598. }
  599.  
  600. $v_central_dir = array();
  601. if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
  602. {
  603. $this->privSwapBackMagicQuotes();
  604. return 0;
  605. }
  606.  
  607. $this->privCloseFd();
  608.  
  609. $v_prop['comment'] = $v_central_dir['comment'];
  610. $v_prop['nb'] = $v_central_dir['entries'];
  611. $v_prop['status'] = 'ok';
  612. }
  613.  
  614. $this->privSwapBackMagicQuotes();
  615.  
  616. return $v_prop;
  617. }
  618. function duplicate($p_archive)
  619. {
  620. $v_result = 1;
  621.  
  622. $this->privErrorReset();
  623.  
  624. if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip'))
  625. {
  626.  
  627. $v_result = $this->privDuplicate($p_archive->zipname);
  628. }
  629.  
  630. else if (is_string($p_archive))
  631. {
  632.  
  633. if (!is_file($p_archive)) {
  634. PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'");
  635. $v_result = PCLZIP_ERR_MISSING_FILE;
  636. }
  637. else {
  638. $v_result = $this->privDuplicate($p_archive);
  639. }
  640. }
  641.  
  642. else
  643. {
  644. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
  645. $v_result = PCLZIP_ERR_INVALID_PARAMETER;
  646. }
  647.  
  648. return $v_result;
  649. }
  650. function merge($p_archive_to_add)
  651. {
  652. $v_result = 1;
  653.  
  654. $this->privErrorReset();
  655.  
  656. if (!$this->privCheckFormat()) {
  657. return(0);
  658. }
  659.  
  660. if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip'))
  661. {
  662.  
  663. $v_result = $this->privMerge($p_archive_to_add);
  664. }
  665.  
  666. else if (is_string($p_archive_to_add))
  667. {
  668.  
  669. $v_object_archive = new PclZip($p_archive_to_add);
  670.  
  671. $v_result = $this->privMerge($v_object_archive);
  672. }
  673.  
  674. else
  675. {
  676. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
  677. $v_result = PCLZIP_ERR_INVALID_PARAMETER;
  678. }
  679.  
  680. return $v_result;
  681. }
  682.  
  683.  
  684. function errorCode()
  685. {
  686. if (PCLZIP_ERROR_EXTERNAL == 1) {
  687. return(PclErrorCode());
  688. }
  689. else {
  690. return($this->error_code);
  691. }
  692. }
  693. function errorName($p_with_code=false)
  694. {
  695. $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',
  696. PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',
  697. PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',
  698. PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',
  699. PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',
  700. PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',
  701. PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',
  702. PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',
  703. PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',
  704. PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',
  705. PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',
  706. PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',
  707. PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',
  708. PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',
  709. PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',
  710. PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',
  711. PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE',
  712. PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION',
  713. PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION'
  714. ,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE'
  715. ,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION'
  716. );
  717.  
  718. if (isset($v_name[$this->error_code])) {
  719. $v_value = $v_name[$this->error_code];
  720. }
  721. else {
  722. $v_value = 'NoName';
  723. }
  724.  
  725. if ($p_with_code) {
  726. return($v_value.' ('.$this->error_code.')');
  727. }
  728. else {
  729. return($v_value);
  730. }
  731. }
  732. function errorInfo($p_full=false)
  733. {
  734. if (PCLZIP_ERROR_EXTERNAL == 1) {
  735. return(PclErrorString());
  736. }
  737. else {
  738. if ($p_full) {
  739. return($this->errorName(true)." : ".$this->error_string);
  740. }
  741. else {
  742. return($this->error_string." [code ".$this->error_code."]");
  743. }
  744. }
  745. }
  746.  
  747.  
  748.  
  749.  
  750. function privCheckFormat($p_level=0)
  751. {
  752. $v_result = true;
  753.  
  754. clearstatcache();
  755.  
  756. $this->privErrorReset();
  757.  
  758. if (!is_file($this->zipname)) {
  759. PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'");
  760. return(false);
  761. }
  762.  
  763. if (!is_readable($this->zipname)) {
  764. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'");
  765. return(false);
  766. }
  767.  
  768. return $v_result;
  769. }
  770. function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false)
  771. {
  772. $v_result=1;
  773. $i=0;
  774. while ($i<$p_size) {
  775.  
  776. if (!isset($v_requested_options[$p_options_list[$i]])) {
  777. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method");
  778.  
  779. return PclZip::errorCode();
  780. }
  781.  
  782. switch ($p_options_list[$i]) {
  783. case PCLZIP_OPT_PATH :
  784. case PCLZIP_OPT_REMOVE_PATH :
  785. case PCLZIP_OPT_ADD_PATH :
  786. if (($i+1) >= $p_size) {
  787. PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  788.  
  789. return PclZip::errorCode();
  790. }
  791.  
  792. $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
  793. $i++;
  794. break;
  795.  
  796. case PCLZIP_OPT_TEMP_FILE_THRESHOLD :
  797. if (($i+1) >= $p_size) {
  798. PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  799. return PclZip::errorCode();
  800. }
  801. if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
  802. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
  803. return PclZip::errorCode();
  804. }
  805. $v_value = $p_options_list[$i+1];
  806. if ((!is_integer($v_value)) || ($v_value<0)) {
  807. PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  808. return PclZip::errorCode();
  809. }
  810.  
  811. $v_result_list[$p_options_list[$i]] = $v_value*1048576;
  812. $i++;
  813. break;
  814.  
  815. case PCLZIP_OPT_TEMP_FILE_ON :
  816. if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
  817. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
  818. return PclZip::errorCode();
  819. }
  820. $v_result_list[$p_options_list[$i]] = true;
  821. break;
  822.  
  823. case PCLZIP_OPT_TEMP_FILE_OFF :
  824. if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) {
  825. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'");
  826. return PclZip::errorCode();
  827. }
  828. if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
  829. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'");
  830. return PclZip::errorCode();
  831. }
  832. $v_result_list[$p_options_list[$i]] = true;
  833. break;
  834.  
  835. case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION :
  836. if (($i+1) >= $p_size) {
  837. PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  838.  
  839. return PclZip::errorCode();
  840. }
  841.  
  842. if ( is_string($p_options_list[$i+1])
  843. && ($p_options_list[$i+1] != '')) {
  844. $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
  845. $i++;
  846. }
  847. else {
  848. }
  849. break;
  850.  
  851. case PCLZIP_OPT_BY_NAME :
  852. if (($i+1) >= $p_size) {
  853. PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  854.  
  855. return PclZip::errorCode();
  856. }
  857.  
  858. if (is_string($p_options_list[$i+1])) {
  859. $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1];
  860. }
  861. else if (is_array($p_options_list[$i+1])) {
  862. $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
  863. }
  864. else {
  865. PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  866.  
  867. return PclZip::errorCode();
  868. }
  869. $i++;
  870. break;
  871.  
  872. case PCLZIP_OPT_BY_EREG :
  873. $p_options_list[$i] = PCLZIP_OPT_BY_PREG;
  874. case PCLZIP_OPT_BY_PREG :
  875. if (($i+1) >= $p_size) {
  876. PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  877.  
  878. return PclZip::errorCode();
  879. }
  880.  
  881. if (is_string($p_options_list[$i+1])) {
  882. $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
  883. }
  884. else {
  885. PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  886.  
  887. return PclZip::errorCode();
  888. }
  889. $i++;
  890. break;
  891.  
  892. case PCLZIP_OPT_COMMENT :
  893. case PCLZIP_OPT_ADD_COMMENT :
  894. case PCLZIP_OPT_PREPEND_COMMENT :
  895. if (($i+1) >= $p_size) {
  896. PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE,
  897. "Missing parameter value for option '"
  898. .PclZipUtilOptionText($p_options_list[$i])
  899. ."'");
  900.  
  901. return PclZip::errorCode();
  902. }
  903.  
  904. if (is_string($p_options_list[$i+1])) {
  905. $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
  906. }
  907. else {
  908. PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE,
  909. "Wrong parameter value for option '"
  910. .PclZipUtilOptionText($p_options_list[$i])
  911. ."'");
  912.  
  913. return PclZip::errorCode();
  914. }
  915. $i++;
  916. break;
  917.  
  918. case PCLZIP_OPT_BY_INDEX :
  919. if (($i+1) >= $p_size) {
  920. PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  921.  
  922. return PclZip::errorCode();
  923. }
  924.  
  925. $v_work_list = array();
  926. if (is_string($p_options_list[$i+1])) {
  927.  
  928. $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', '');
  929.  
  930. $v_work_list = explode(",", $p_options_list[$i+1]);
  931. }
  932. else if (is_integer($p_options_list[$i+1])) {
  933. $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1];
  934. }
  935. else if (is_array($p_options_list[$i+1])) {
  936. $v_work_list = $p_options_list[$i+1];
  937. }
  938. else {
  939. PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  940.  
  941. return PclZip::errorCode();
  942. }
  943. $v_sort_flag=false;
  944. $v_sort_value=0;
  945. for ($j=0; $j<sizeof($v_work_list); $j++) {
  946. $v_item_list = explode("-", $v_work_list[$j]);
  947. $v_size_item_list = sizeof($v_item_list);
  948. if ($v_size_item_list == 1) {
  949. $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
  950. $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0];
  951. }
  952. elseif ($v_size_item_list == 2) {
  953. $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0];
  954. $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1];
  955. }
  956. else {
  957. PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  958.  
  959. return PclZip::errorCode();
  960. }
  961.  
  962.  
  963. if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) {
  964. $v_sort_flag=true;
  965.  
  966. PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  967.  
  968. return PclZip::errorCode();
  969. }
  970. $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start'];
  971. }
  972. if ($v_sort_flag) {
  973. }
  974.  
  975. $i++;
  976. break;
  977.  
  978. case PCLZIP_OPT_REMOVE_ALL_PATH :
  979. case PCLZIP_OPT_EXTRACT_AS_STRING :
  980. case PCLZIP_OPT_NO_COMPRESSION :
  981. case PCLZIP_OPT_EXTRACT_IN_OUTPUT :
  982. case PCLZIP_OPT_REPLACE_NEWER :
  983. case PCLZIP_OPT_STOP_ON_ERROR :
  984. $v_result_list[$p_options_list[$i]] = true;
  985. break;
  986.  
  987. case PCLZIP_OPT_SET_CHMOD :
  988. if (($i+1) >= $p_size) {
  989. PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  990.  
  991. return PclZip::errorCode();
  992. }
  993.  
  994. $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
  995. $i++;
  996. break;
  997.  
  998. case PCLZIP_CB_PRE_EXTRACT :
  999. case PCLZIP_CB_POST_EXTRACT :
  1000. case PCLZIP_CB_PRE_ADD :
  1001. case PCLZIP_CB_POST_ADD :
  1002.  
  1003. if (($i+1) >= $p_size) {
  1004. PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  1005.  
  1006. return PclZip::errorCode();
  1007. }
  1008.  
  1009. $v_function_name = $p_options_list[$i+1];
  1010.  
  1011. if (!function_exists($v_function_name)) {
  1012. PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'");
  1013.  
  1014. return PclZip::errorCode();
  1015. }
  1016.  
  1017. $v_result_list[$p_options_list[$i]] = $v_function_name;
  1018. $i++;
  1019. break;
  1020.  
  1021. default :
  1022. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
  1023. "Unknown parameter '"
  1024. .$p_options_list[$i]."'");
  1025.  
  1026. return PclZip::errorCode();
  1027. }
  1028.  
  1029. $i++;
  1030. }
  1031.  
  1032. if ($v_requested_options !== false) {
  1033. for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
  1034. if ($v_requested_options[$key] == 'mandatory') {
  1035. if (!isset($v_result_list[$key])) {
  1036. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
  1037.  
  1038. return PclZip::errorCode();
  1039. }
  1040. }
  1041. }
  1042. }
  1043. if (!isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
  1044. }
  1045.  
  1046. return $v_result;
  1047. }
  1048. function privOptionDefaultThreshold(&$p_options)
  1049. {
  1050. $v_result=1;
  1051. if (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
  1052. || isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) {
  1053. return $v_result;
  1054. }
  1055. $v_memory_limit = ini_get('memory_limit');
  1056. $v_memory_limit = trim($v_memory_limit);
  1057. $last = strtolower(substr($v_memory_limit, -1));
  1058. if($last == 'g')
  1059. $v_memory_limit = $v_memory_limit*1073741824;
  1060. if($last == 'm')
  1061. $v_memory_limit = $v_memory_limit*1048576;
  1062. if($last == 'k')
  1063. $v_memory_limit = $v_memory_limit*1024;
  1064. $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*PCLZIP_TEMPORARY_FILE_RATIO);
  1065.  
  1066. if ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] < 1048576) {
  1067. unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]);
  1068. }
  1069. return $v_result;
  1070. }
  1071. function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false)
  1072. {
  1073. $v_result=1;
  1074. foreach ($p_file_list as $v_key => $v_value) {
  1075. if (!isset($v_requested_options[$v_key])) {
  1076. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file");
  1077.  
  1078. return PclZip::errorCode();
  1079. }
  1080.  
  1081. switch ($v_key) {
  1082. case PCLZIP_ATT_FILE_NAME :
  1083. if (!is_string($v_value)) {
  1084. PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
  1085. return PclZip::errorCode();
  1086. }
  1087.  
  1088. $p_filedescr['filename'] = PclZipUtilPathReduction($v_value);
  1089. if ($p_filedescr['filename'] == '') {
  1090. PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'");
  1091. return PclZip::errorCode();
  1092. }
  1093.  
  1094. break;
  1095.  
  1096. case PCLZIP_ATT_FILE_NEW_SHORT_NAME :
  1097. if (!is_string($v_value)) {
  1098. PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
  1099. return PclZip::errorCode();
  1100. }
  1101.  
  1102. $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value);
  1103.  
  1104. if ($p_filedescr['new_short_name'] == '') {
  1105. PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'");
  1106. return PclZip::errorCode();
  1107. }
  1108. break;
  1109.  
  1110. case PCLZIP_ATT_FILE_NEW_FULL_NAME :
  1111. if (!is_string($v_value)) {
  1112. PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
  1113. return PclZip::errorCode();
  1114. }
  1115.  
  1116. $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value);
  1117.  
  1118. if ($p_filedescr['new_full_name'] == '') {
  1119. PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'");
  1120. return PclZip::errorCode();
  1121. }
  1122. break;
  1123.  
  1124. case PCLZIP_ATT_FILE_COMMENT :
  1125. if (!is_string($v_value)) {
  1126. PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
  1127. return PclZip::errorCode();
  1128. }
  1129.  
  1130. $p_filedescr['comment'] = $v_value;
  1131. break;
  1132.  
  1133. case PCLZIP_ATT_FILE_MTIME :
  1134. if (!is_integer($v_value)) {
  1135. PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'");
  1136. return PclZip::errorCode();
  1137. }
  1138.  
  1139. $p_filedescr['mtime'] = $v_value;
  1140. break;
  1141.  
  1142. case PCLZIP_ATT_FILE_CONTENT :
  1143. $p_filedescr['content'] = $v_value;
  1144. break;
  1145.  
  1146. default :
  1147. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
  1148. "Unknown parameter '".$v_key."'");
  1149.  
  1150. return PclZip::errorCode();
  1151. }
  1152.  
  1153. if ($v_requested_options !== false) {
  1154. for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
  1155. if ($v_requested_options[$key] == 'mandatory') {
  1156. if (!isset($p_file_list[$key])) {
  1157. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
  1158. return PclZip::errorCode();
  1159. }
  1160. }
  1161. }
  1162. }
  1163. }
  1164. return $v_result;
  1165. }
  1166. function privFileDescrExpand(&$p_filedescr_list, &$p_options)
  1167. {
  1168. $v_result=1;
  1169. $v_result_list = array();
  1170. for ($i=0; $i<sizeof($p_filedescr_list); $i++) {
  1171. $v_descr = $p_filedescr_list[$i];
  1172. $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false);
  1173. $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']);
  1174. if (file_exists($v_descr['filename'])) {
  1175. if (@is_file($v_descr['filename'])) {
  1176. $v_descr['type'] = 'file';
  1177. }
  1178. else if (@is_dir($v_descr['filename'])) {
  1179. $v_descr['type'] = 'folder';
  1180. }
  1181. else if (@is_link($v_descr['filename'])) {
  1182. continue;
  1183. }
  1184. else {
  1185. continue;
  1186. }
  1187. }
  1188. else if (isset($v_descr['content'])) {
  1189. $v_descr['type'] = 'virtual_file';
  1190. }
  1191. else {
  1192. PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exist");
  1193.  
  1194. return PclZip::errorCode();
  1195. }
  1196. $this->privCalculateStoredFilename($v_descr, $p_options);
  1197. $v_result_list[sizeof($v_result_list)] = $v_descr;
  1198. if ($v_descr['type'] == 'folder') {
  1199. $v_dirlist_descr = array();
  1200. $v_dirlist_nb = 0;
  1201. if ($v_folder_handler = @opendir($v_descr['filename'])) {
  1202. while (($v_item_handler = @readdir($v_folder_handler)) !== false) {
  1203.  
  1204. if (($v_item_handler == '.') || ($v_item_handler == '..')) {
  1205. continue;
  1206. }
  1207. $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler;
  1208. if (($v_descr['stored_filename'] != $v_descr['filename'])
  1209. && (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) {
  1210. if ($v_descr['stored_filename'] != '') {
  1211. $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler;
  1212. }
  1213. else {
  1214. $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler;
  1215. }
  1216. }
  1217. $v_dirlist_nb++;
  1218. }
  1219. @closedir($v_folder_handler);
  1220. }
  1221. else {
  1222. }
  1223. if ($v_dirlist_nb != 0) {
  1224. if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) {
  1225. return $v_result;
  1226. }
  1227. $v_result_list = array_merge($v_result_list, $v_dirlist_descr);
  1228. }
  1229. else {
  1230. }
  1231. unset($v_dirlist_descr);
  1232. }
  1233. }
  1234. $p_filedescr_list = $v_result_list;
  1235.  
  1236. return $v_result;
  1237. }
  1238. function privCreate($p_filedescr_list, &$p_result_list, &$p_options)
  1239. {
  1240. $v_result=1;
  1241. $v_list_detail = array();
  1242. $this->privDisableMagicQuotes();
  1243.  
  1244. if (($v_result = $this->privOpenFd('wb')) != 1)
  1245. {
  1246. return $v_result;
  1247. }
  1248.  
  1249. $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options);
  1250.  
  1251. $this->privCloseFd();
  1252.  
  1253. $this->privSwapBackMagicQuotes();
  1254.  
  1255. return $v_result;
  1256. }
  1257. function privAdd($p_filedescr_list, &$p_result_list, &$p_options)
  1258. {
  1259. $v_result=1;
  1260. $v_list_detail = array();
  1261.  
  1262. if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0))
  1263. {
  1264.  
  1265. $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options);
  1266.  
  1267. return $v_result;
  1268. }
  1269. $this->privDisableMagicQuotes();
  1270.  
  1271. if (($v_result=$this->privOpenFd('rb')) != 1)
  1272. {
  1273. $this->privSwapBackMagicQuotes();
  1274.  
  1275. return $v_result;
  1276. }
  1277.  
  1278. $v_central_dir = array();
  1279. if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
  1280. {
  1281. $this->privCloseFd();
  1282. $this->privSwapBackMagicQuotes();
  1283. return $v_result;
  1284. }
  1285.  
  1286. @rewind($this->zip_fd);
  1287.  
  1288. $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
  1289.  
  1290. if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
  1291. {
  1292. $this->privCloseFd();
  1293. $this->privSwapBackMagicQuotes();
  1294.  
  1295. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
  1296.  
  1297. return PclZip::errorCode();
  1298. }
  1299.  
  1300. $v_size = $v_central_dir['offset'];
  1301. while ($v_size != 0)
  1302. {
  1303. $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  1304. $v_buffer = fread($this->zip_fd, $v_read_size);
  1305. @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
  1306. $v_size -= $v_read_size;
  1307. }
  1308.  
  1309. $v_swap = $this->zip_fd;
  1310. $this->zip_fd = $v_zip_temp_fd;
  1311. $v_zip_temp_fd = $v_swap;
  1312.  
  1313. $v_header_list = array();
  1314. if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
  1315. {
  1316. fclose($v_zip_temp_fd);
  1317. $this->privCloseFd();
  1318. @unlink($v_zip_temp_name);
  1319. $this->privSwapBackMagicQuotes();
  1320.  
  1321. return $v_result;
  1322. }
  1323.  
  1324. $v_offset = @ftell($this->zip_fd);
  1325.  
  1326. $v_size = $v_central_dir['size'];
  1327. while ($v_size != 0)
  1328. {
  1329. $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  1330. $v_buffer = @fread($v_zip_temp_fd, $v_read_size);
  1331. @fwrite($this->zip_fd, $v_buffer, $v_read_size);
  1332. $v_size -= $v_read_size;
  1333. }
  1334.  
  1335. for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++)
  1336. {
  1337. if ($v_header_list[$i]['status'] == 'ok') {
  1338. if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
  1339. fclose($v_zip_temp_fd);
  1340. $this->privCloseFd();
  1341. @unlink($v_zip_temp_name);
  1342. $this->privSwapBackMagicQuotes();
  1343.  
  1344. return $v_result;
  1345. }
  1346. $v_count++;
  1347. }
  1348.  
  1349. $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
  1350. }
  1351.  
  1352. $v_comment = $v_central_dir['comment'];
  1353. if (isset($p_options[PCLZIP_OPT_COMMENT])) {
  1354. $v_comment = $p_options[PCLZIP_OPT_COMMENT];
  1355. }
  1356. if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) {
  1357. $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT];
  1358. }
  1359. if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) {
  1360. $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment;
  1361. }
  1362.  
  1363. $v_size = @ftell($this->zip_fd)-$v_offset;
  1364.  
  1365. if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1)
  1366. {
  1367. unset($v_header_list);
  1368. $this->privSwapBackMagicQuotes();
  1369.  
  1370. return $v_result;
  1371. }
  1372.  
  1373. $v_swap = $this->zip_fd;
  1374. $this->zip_fd = $v_zip_temp_fd;
  1375. $v_zip_temp_fd = $v_swap;
  1376.  
  1377. $this->privCloseFd();
  1378.  
  1379. @fclose($v_zip_temp_fd);
  1380.  
  1381. $this->privSwapBackMagicQuotes();
  1382.  
  1383. @unlink($this->zipname);
  1384.  
  1385. PclZipUtilRename($v_zip_temp_name, $this->zipname);
  1386.  
  1387. return $v_result;
  1388. }
  1389. function privOpenFd($p_mode)
  1390. {
  1391. $v_result=1;
  1392.  
  1393. if ($this->zip_fd != 0)
  1394. {
  1395. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open');
  1396.  
  1397. return PclZip::errorCode();
  1398. }
  1399.  
  1400. if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0)
  1401. {
  1402. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode');
  1403.  
  1404. return PclZip::errorCode();
  1405. }
  1406.  
  1407. return $v_result;
  1408. }
  1409. function privCloseFd()
  1410. {
  1411. $v_result=1;
  1412.  
  1413. if ($this->zip_fd != 0)
  1414. @fclose($this->zip_fd);
  1415. $this->zip_fd = 0;
  1416.  
  1417. return $v_result;
  1418. }
  1419. function privAddList($p_filedescr_list, &$p_result_list, &$p_options)
  1420. {
  1421. $v_result=1;
  1422.  
  1423. $v_header_list = array();
  1424. if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
  1425. {
  1426. return $v_result;
  1427. }
  1428.  
  1429. $v_offset = @ftell($this->zip_fd);
  1430.  
  1431. for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++)
  1432. {
  1433. if ($v_header_list[$i]['status'] == 'ok') {
  1434. if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
  1435. return $v_result;
  1436. }
  1437. $v_count++;
  1438. }
  1439.  
  1440. $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
  1441. }
  1442.  
  1443. $v_comment = '';
  1444. if (isset($p_options[PCLZIP_OPT_COMMENT])) {
  1445. $v_comment = $p_options[PCLZIP_OPT_COMMENT];
  1446. }
  1447.  
  1448. $v_size = @ftell($this->zip_fd)-$v_offset;
  1449.  
  1450. if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1)
  1451. {
  1452. unset($v_header_list);
  1453.  
  1454. return $v_result;
  1455. }
  1456.  
  1457. return $v_result;
  1458. }
  1459. function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options)
  1460. {
  1461. $v_result=1;
  1462. $v_header = array();
  1463.  
  1464. $v_nb = sizeof($p_result_list);
  1465.  
  1466. for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) {
  1467. $p_filedescr_list[$j]['filename']
  1468. = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false);
  1469.  
  1470. if ($p_filedescr_list[$j]['filename'] == "") {
  1471. continue;
  1472. }
  1473.  
  1474. if ( ($p_filedescr_list[$j]['type'] != 'virtual_file')
  1475. && (!file_exists($p_filedescr_list[$j]['filename']))) {
  1476. PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exist");
  1477. return PclZip::errorCode();
  1478. }
  1479.  
  1480. if ( ($p_filedescr_list[$j]['type'] == 'file')
  1481. || ($p_filedescr_list[$j]['type'] == 'virtual_file')
  1482. || ( ($p_filedescr_list[$j]['type'] == 'folder')
  1483. && ( !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])
  1484. || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))
  1485. ) {
  1486.  
  1487. $v_result = $this->privAddFile($p_filedescr_list[$j], $v_header,
  1488. $p_options);
  1489. if ($v_result != 1) {
  1490. return $v_result;
  1491. }
  1492.  
  1493. $p_result_list[$v_nb++] = $v_header;
  1494. }
  1495. }
  1496.  
  1497. return $v_result;
  1498. }
  1499. function privAddFile($p_filedescr, &$p_header, &$p_options)
  1500. {
  1501. $v_result=1;
  1502. $p_filename = $p_filedescr['filename'];
  1503.  
  1504. if ($p_filename == "") {
  1505. PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)");
  1506.  
  1507. return PclZip::errorCode();
  1508. }
  1509.  
  1510. clearstatcache();
  1511. $p_header['version'] = 20;
  1512. $p_header['version_extracted'] = 10;
  1513. $p_header['flag'] = 0;
  1514. $p_header['compression'] = 0;
  1515. $p_header['crc'] = 0;
  1516. $p_header['compressed_size'] = 0;
  1517. $p_header['filename_len'] = strlen($p_filename);
  1518. $p_header['extra_len'] = 0;
  1519. $p_header['disk'] = 0;
  1520. $p_header['internal'] = 0;
  1521. $p_header['offset'] = 0;
  1522. $p_header['filename'] = $p_filename;
  1523. $p_header['stored_filename'] = $p_filedescr['stored_filename'];
  1524. $p_header['extra'] = '';
  1525. $p_header['status'] = 'ok';
  1526. $p_header['index'] = -1;
  1527.  
  1528. if ($p_filedescr['type']=='file') {
  1529. $p_header['external'] = 0x00000000;
  1530. $p_header['size'] = filesize($p_filename);
  1531. }
  1532. else if ($p_filedescr['type']=='folder') {
  1533. $p_header['external'] = 0x00000010;
  1534. $p_header['mtime'] = filemtime($p_filename);
  1535. $p_header['size'] = filesize($p_filename);
  1536. }
  1537. else if ($p_filedescr['type'] == 'virtual_file') {
  1538. $p_header['external'] = 0x00000000;
  1539. $p_header['size'] = strlen($p_filedescr['content']);
  1540. }
  1541.  
  1542. if (isset($p_filedescr['mtime'])) {
  1543. $p_header['mtime'] = $p_filedescr['mtime'];
  1544. }
  1545. else if ($p_filedescr['type'] == 'virtual_file') {
  1546. $p_header['mtime'] = time();
  1547. }
  1548. else {
  1549. $p_header['mtime'] = filemtime($p_filename);
  1550. }
  1551.  
  1552. if (isset($p_filedescr['comment'])) {
  1553. $p_header['comment_len'] = strlen($p_filedescr['comment']);
  1554. $p_header['comment'] = $p_filedescr['comment'];
  1555. }
  1556. else {
  1557. $p_header['comment_len'] = 0;
  1558. $p_header['comment'] = '';
  1559. }
  1560.  
  1561. if (isset($p_options[PCLZIP_CB_PRE_ADD])) {
  1562.  
  1563. $v_local_header = array();
  1564. $this->privConvertHeader2FileInfo($p_header, $v_local_header);
  1565.  
  1566. $v_result = $p_options[PCLZIP_CB_PRE_ADD](PCLZIP_CB_PRE_ADD, $v_local_header);
  1567. if ($v_result == 0) {
  1568. $p_header['status'] = "skipped";
  1569. $v_result = 1;
  1570. }
  1571.  
  1572. if ($p_header['stored_filename'] != $v_local_header['stored_filename']) {
  1573. $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']);
  1574. }
  1575. }
  1576.  
  1577. if ($p_header['stored_filename'] == "") {
  1578. $p_header['status'] = "filtered";
  1579. }
  1580. if (strlen($p_header['stored_filename']) > 0xFF) {
  1581. $p_header['status'] = 'filename_too_long';
  1582. }
  1583.  
  1584. if ($p_header['status'] == 'ok') {
  1585.  
  1586. if ($p_filedescr['type'] == 'file') {
  1587. if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF]))
  1588. && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
  1589. || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
  1590. && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) {
  1591. $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options);
  1592. if ($v_result < PCLZIP_ERR_NO_ERROR) {
  1593. return $v_result;
  1594. }
  1595. }
  1596. else {
  1597.  
  1598. if (($v_file = @fopen($p_filename, "rb")) == 0) {
  1599. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
  1600. return PclZip::errorCode();
  1601. }
  1602.  
  1603. $v_content = @fread($v_file, $p_header['size']);
  1604.  
  1605. @fclose($v_file);
  1606.  
  1607. $p_header['crc'] = @crc32($v_content);
  1608. if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
  1609. $p_header['compressed_size'] = $p_header['size'];
  1610. $p_header['compression'] = 0;
  1611. }
  1612. else {
  1613. $v_content = @gzdeflate($v_content);
  1614.  
  1615. $p_header['compressed_size'] = strlen($v_content);
  1616. $p_header['compression'] = 8;
  1617. }
  1618. if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
  1619. @fclose($v_file);
  1620. return $v_result;
  1621. }
  1622.  
  1623. @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
  1624.  
  1625. }
  1626.  
  1627. }
  1628.  
  1629. else if ($p_filedescr['type'] == 'virtual_file') {
  1630. $v_content = $p_filedescr['content'];
  1631.  
  1632. $p_header['crc'] = @crc32($v_content);
  1633. if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
  1634. $p_header['compressed_size'] = $p_header['size'];
  1635. $p_header['compression'] = 0;
  1636. }
  1637. else {
  1638. $v_content = @gzdeflate($v_content);
  1639.  
  1640. $p_header['compressed_size'] = strlen($v_content);
  1641. $p_header['compression'] = 8;
  1642. }
  1643. if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
  1644. @fclose($v_file);
  1645. return $v_result;
  1646. }
  1647.  
  1648. @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
  1649. }
  1650.  
  1651. else if ($p_filedescr['type'] == 'folder') {
  1652. if (@substr($p_header['stored_filename'], -1) != '/') {
  1653. $p_header['stored_filename'] .= '/';
  1654. }
  1655.  
  1656. $p_header['size'] = 0;
  1657. $p_header['external'] = 0x00000010;
  1658. if (($v_result = $this->privWriteFileHeader($p_header)) != 1)
  1659. {
  1660. return $v_result;
  1661. }
  1662. }
  1663. }
  1664.  
  1665. if (isset($p_options[PCLZIP_CB_POST_ADD])) {
  1666.  
  1667. $v_local_header = array();
  1668. $this->privConvertHeader2FileInfo($p_header, $v_local_header);
  1669.  
  1670. $v_result = $p_options[PCLZIP_CB_POST_ADD](PCLZIP_CB_POST_ADD, $v_local_header);
  1671. if ($v_result == 0) {
  1672. $v_result = 1;
  1673. }
  1674.  
  1675. }
  1676.  
  1677. return $v_result;
  1678. }
  1679. function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options)
  1680. {
  1681. $v_result=PCLZIP_ERR_NO_ERROR;
  1682. $p_filename = $p_filedescr['filename'];
  1683.  
  1684.  
  1685. if (($v_file = @fopen($p_filename, "rb")) == 0) {
  1686. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
  1687. return PclZip::errorCode();
  1688. }
  1689.  
  1690. $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
  1691. if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) {
  1692. fclose($v_file);
  1693. PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
  1694. return PclZip::errorCode();
  1695. }
  1696.  
  1697. $v_size = filesize($p_filename);
  1698. while ($v_size != 0) {
  1699. $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  1700. $v_buffer = @fread($v_file, $v_read_size);
  1701. @gzputs($v_file_compressed, $v_buffer, $v_read_size);
  1702. $v_size -= $v_read_size;
  1703. }
  1704.  
  1705. @fclose($v_file);
  1706. @gzclose($v_file_compressed);
  1707.  
  1708. if (filesize($v_gzip_temp_name) < 18) {
  1709. PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes');
  1710. return PclZip::errorCode();
  1711. }
  1712.  
  1713. if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) {
  1714. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
  1715. return PclZip::errorCode();
  1716. }
  1717.  
  1718. $v_binary_data = @fread($v_file_compressed, 10);
  1719. $v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data);
  1720.  
  1721. $v_data_header['os'] = bin2hex($v_data_header['os']);
  1722.  
  1723. @fseek($v_file_compressed, filesize($v_gzip_temp_name)-8);
  1724. $v_binary_data = @fread($v_file_compressed, 8);
  1725. $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data);
  1726.  
  1727. $p_header['compression'] = ord($v_data_header['cm']);
  1728. $p_header['crc'] = $v_data_footer['crc'];
  1729. $p_header['compressed_size'] = filesize($v_gzip_temp_name)-18;
  1730.  
  1731. @fclose($v_file_compressed);
  1732.  
  1733. if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
  1734. return $v_result;
  1735. }
  1736.  
  1737. if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0)
  1738. {
  1739. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
  1740. return PclZip::errorCode();
  1741. }
  1742.  
  1743. fseek($v_file_compressed, 10);
  1744. $v_size = $p_header['compressed_size'];
  1745. while ($v_size != 0)
  1746. {
  1747. $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  1748. $v_buffer = @fread($v_file_compressed, $v_read_size);
  1749. @fwrite($this->zip_fd, $v_buffer, $v_read_size);
  1750. $v_size -= $v_read_size;
  1751. }
  1752.  
  1753. @fclose($v_file_compressed);
  1754.  
  1755. @unlink($v_gzip_temp_name);
  1756. return $v_result;
  1757. }
  1758. function privCalculateStoredFilename(&$p_filedescr, &$p_options)
  1759. {
  1760. $v_result=1;
  1761. $p_filename = $p_filedescr['filename'];
  1762. if (isset($p_options[PCLZIP_OPT_ADD_PATH])) {
  1763. $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH];
  1764. }
  1765. else {
  1766. $p_add_dir = '';
  1767. }
  1768. if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) {
  1769. $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH];
  1770. }
  1771. else {
  1772. $p_remove_dir = '';
  1773. }
  1774. if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
  1775. $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH];
  1776. }
  1777. else {
  1778. $p_remove_all_dir = 0;
  1779. }
  1780.  
  1781.  
  1782. if (isset($p_filedescr['new_full_name'])) {
  1783. $v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']);
  1784. }
  1785. else {
  1786.  
  1787. if (isset($p_filedescr['new_short_name'])) {
  1788. $v_path_info = pathinfo($p_filename);
  1789. $v_dir = '';
  1790. if ($v_path_info['dirname'] != '') {
  1791. $v_dir = $v_path_info['dirname'].'/';
  1792. }
  1793. $v_stored_filename = $v_dir.$p_filedescr['new_short_name'];
  1794. }
  1795. else {
  1796. $v_stored_filename = $p_filename;
  1797. }
  1798.  
  1799. if ($p_remove_all_dir) {
  1800. $v_stored_filename = basename($p_filename);
  1801. }
  1802. else if ($p_remove_dir != "") {
  1803. if (substr($p_remove_dir, -1) != '/')
  1804. $p_remove_dir .= "/";
  1805.  
  1806. if ( (substr($p_filename, 0, 2) == "./")
  1807. || (substr($p_remove_dir, 0, 2) == "./")) {
  1808. if ( (substr($p_filename, 0, 2) == "./")
  1809. && (substr($p_remove_dir, 0, 2) != "./")) {
  1810. $p_remove_dir = "./".$p_remove_dir;
  1811. }
  1812. if ( (substr($p_filename, 0, 2) != "./")
  1813. && (substr($p_remove_dir, 0, 2) == "./")) {
  1814. $p_remove_dir = substr($p_remove_dir, 2);
  1815. }
  1816. }
  1817.  
  1818. $v_compare = PclZipUtilPathInclusion($p_remove_dir,
  1819. $v_stored_filename);
  1820. if ($v_compare > 0) {
  1821. if ($v_compare == 2) {
  1822. $v_stored_filename = "";
  1823. }
  1824. else {
  1825. $v_stored_filename = substr($v_stored_filename,
  1826. strlen($p_remove_dir));
  1827. }
  1828. }
  1829. }
  1830. $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename);
  1831. if ($p_add_dir != "") {
  1832. if (substr($p_add_dir, -1) == "/")
  1833. $v_stored_filename = $p_add_dir.$v_stored_filename;
  1834. else
  1835. $v_stored_filename = $p_add_dir."/".$v_stored_filename;
  1836. }
  1837. }
  1838.  
  1839. $v_stored_filename = PclZipUtilPathReduction($v_stored_filename);
  1840. $p_filedescr['stored_filename'] = $v_stored_filename;
  1841. return $v_result;
  1842. }
  1843. function privWriteFileHeader(&$p_header)
  1844. {
  1845. $v_result=1;
  1846.  
  1847. $p_header['offset'] = ftell($this->zip_fd);
  1848.  
  1849. $v_date = getdate($p_header['mtime']);
  1850. $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
  1851. $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
  1852.  
  1853. $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50,
  1854. $p_header['version_extracted'], $p_header['flag'],
  1855. $p_header['compression'], $v_mtime, $v_mdate,
  1856. $p_header['crc'], $p_header['compressed_size'],
  1857. $p_header['size'],
  1858. strlen($p_header['stored_filename']),
  1859. $p_header['extra_len']);
  1860.  
  1861. fputs($this->zip_fd, $v_binary_data, 30);
  1862.  
  1863. if (strlen($p_header['stored_filename']) != 0)
  1864. {
  1865. fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
  1866. }
  1867. if ($p_header['extra_len'] != 0)
  1868. {
  1869. fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
  1870. }
  1871.  
  1872. return $v_result;
  1873. }
  1874. function privWriteCentralFileHeader(&$p_header)
  1875. {
  1876. $v_result=1;
  1877.  
  1878. $v_date = getdate($p_header['mtime']);
  1879. $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
  1880. $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
  1881.  
  1882.  
  1883. $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50,
  1884. $p_header['version'], $p_header['version_extracted'],
  1885. $p_header['flag'], $p_header['compression'],
  1886. $v_mtime, $v_mdate, $p_header['crc'],
  1887. $p_header['compressed_size'], $p_header['size'],
  1888. strlen($p_header['stored_filename']),
  1889. $p_header['extra_len'], $p_header['comment_len'],
  1890. $p_header['disk'], $p_header['internal'],
  1891. $p_header['external'], $p_header['offset']);
  1892.  
  1893. fputs($this->zip_fd, $v_binary_data, 46);
  1894.  
  1895. if (strlen($p_header['stored_filename']) != 0)
  1896. {
  1897. fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
  1898. }
  1899. if ($p_header['extra_len'] != 0)
  1900. {
  1901. fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
  1902. }
  1903. if ($p_header['comment_len'] != 0)
  1904. {
  1905. fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']);
  1906. }
  1907.  
  1908. return $v_result;
  1909. }
  1910. function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment)
  1911. {
  1912. $v_result=1;
  1913.  
  1914. $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries,
  1915. $p_nb_entries, $p_size,
  1916. $p_offset, strlen($p_comment));
  1917.  
  1918. fputs($this->zip_fd, $v_binary_data, 22);
  1919.  
  1920. if (strlen($p_comment) != 0)
  1921. {
  1922. fputs($this->zip_fd, $p_comment, strlen($p_comment));
  1923. }
  1924.  
  1925. return $v_result;
  1926. }
  1927. function privList(&$p_list)
  1928. {
  1929. $v_result=1;
  1930.  
  1931. $this->privDisableMagicQuotes();
  1932.  
  1933. if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
  1934. {
  1935. $this->privSwapBackMagicQuotes();
  1936. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
  1937.  
  1938. return PclZip::errorCode();
  1939. }
  1940.  
  1941. $v_central_dir = array();
  1942. if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
  1943. {
  1944. $this->privSwapBackMagicQuotes();
  1945. return $v_result;
  1946. }
  1947.  
  1948. @rewind($this->zip_fd);
  1949. if (@fseek($this->zip_fd, $v_central_dir['offset']))
  1950. {
  1951. $this->privSwapBackMagicQuotes();
  1952.  
  1953. PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
  1954.  
  1955. return PclZip::errorCode();
  1956. }
  1957.  
  1958. for ($i=0; $i<$v_central_dir['entries']; $i++)
  1959. {
  1960. if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
  1961. {
  1962. $this->privSwapBackMagicQuotes();
  1963. return $v_result;
  1964. }
  1965. $v_header['index'] = $i;
  1966.  
  1967. $this->privConvertHeader2FileInfo($v_header, $p_list[$i]);
  1968. unset($v_header);
  1969. }
  1970.  
  1971. $this->privCloseFd();
  1972.  
  1973. $this->privSwapBackMagicQuotes();
  1974.  
  1975. return $v_result;
  1976. }
  1977. function privConvertHeader2FileInfo($p_header, &$p_info)
  1978. {
  1979. $v_result=1;
  1980.  
  1981. $v_temp_path = PclZipUtilPathReduction($p_header['filename']);
  1982. $p_info['filename'] = $v_temp_path;
  1983. $v_temp_path = PclZipUtilPathReduction($p_header['stored_filename']);
  1984. $p_info['stored_filename'] = $v_temp_path;
  1985. $p_info['size'] = $p_header['size'];
  1986. $p_info['compressed_size'] = $p_header['compressed_size'];
  1987. $p_info['mtime'] = $p_header['mtime'];
  1988. $p_info['comment'] = $p_header['comment'];
  1989. $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010);
  1990. $p_info['index'] = $p_header['index'];
  1991. $p_info['status'] = $p_header['status'];
  1992. $p_info['crc'] = $p_header['crc'];
  1993.  
  1994. return $v_result;
  1995. }
  1996. function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
  1997. {
  1998. $v_result=1;
  1999.  
  2000. $this->privDisableMagicQuotes();
  2001.  
  2002. if ( ($p_path == "")
  2003. || ( (substr($p_path, 0, 1) != "/")
  2004. && (substr($p_path, 0, 3) != "../")
  2005. && (substr($p_path,1,2)!=":/")))
  2006. $p_path = "./".$p_path;
  2007.  
  2008. if (($p_path != "./") && ($p_path != "/"))
  2009. {
  2010. while (substr($p_path, -1) == "/")
  2011. {
  2012. $p_path = substr($p_path, 0, strlen($p_path)-1);
  2013. }
  2014. }
  2015.  
  2016. if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/'))
  2017. {
  2018. $p_remove_path .= '/';
  2019. }
  2020. $p_remove_path_size = strlen($p_remove_path);
  2021.  
  2022. if (($v_result = $this->privOpenFd('rb')) != 1)
  2023. {
  2024. $this->privSwapBackMagicQuotes();
  2025. return $v_result;
  2026. }
  2027.  
  2028. $v_central_dir = array();
  2029. if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
  2030. {
  2031. $this->privCloseFd();
  2032. $this->privSwapBackMagicQuotes();
  2033.  
  2034. return $v_result;
  2035. }
  2036.  
  2037. $v_pos_entry = $v_central_dir['offset'];
  2038.  
  2039. $j_start = 0;
  2040. for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
  2041. {
  2042.  
  2043. @rewind($this->zip_fd);
  2044. if (@fseek($this->zip_fd, $v_pos_entry))
  2045. {
  2046. $this->privCloseFd();
  2047. $this->privSwapBackMagicQuotes();
  2048.  
  2049. PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
  2050.  
  2051. return PclZip::errorCode();
  2052. }
  2053.  
  2054. $v_header = array();
  2055. if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
  2056. {
  2057. $this->privCloseFd();
  2058. $this->privSwapBackMagicQuotes();
  2059.  
  2060. return $v_result;
  2061. }
  2062.  
  2063. $v_header['index'] = $i;
  2064.  
  2065. $v_pos_entry = ftell($this->zip_fd);
  2066.  
  2067. $v_extract = false;
  2068.  
  2069. if ( (isset($p_options[PCLZIP_OPT_BY_NAME]))
  2070. && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
  2071.  
  2072. for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) {
  2073.  
  2074. if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
  2075.  
  2076. if ( (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
  2077. && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
  2078. $v_extract = true;
  2079. }
  2080. }
  2081. elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
  2082. $v_extract = true;
  2083. }
  2084. }
  2085. }
  2086.  
  2087. else if ( (isset($p_options[PCLZIP_OPT_BY_PREG]))
  2088. && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
  2089.  
  2090. if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) {
  2091. $v_extract = true;
  2092. }
  2093. }
  2094.  
  2095. else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX]))
  2096. && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
  2097. for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) {
  2098.  
  2099. if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
  2100. $v_extract = true;
  2101. }
  2102. if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
  2103. $j_start = $j+1;
  2104. }
  2105.  
  2106. if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
  2107. break;
  2108. }
  2109. }
  2110. }
  2111.  
  2112. else {
  2113. $v_extract = true;
  2114. }
  2115.  
  2116. if ( ($v_extract)
  2117. && ( ($v_header['compression'] != 8)
  2118. && ($v_header['compression'] != 0))) {
  2119. $v_header['status'] = 'unsupported_compression';
  2120.  
  2121. if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
  2122. && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
  2123.  
  2124. $this->privSwapBackMagicQuotes();
  2125. PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION,
  2126. "Filename '".$v_header['stored_filename']."' is "
  2127. ."compressed by an unsupported compression "
  2128. ."method (".$v_header['compression'].") ");
  2129.  
  2130. return PclZip::errorCode();
  2131. }
  2132. }
  2133. if (($v_extract) && (($v_header['flag'] & 1) == 1)) {
  2134. $v_header['status'] = 'unsupported_encryption';
  2135.  
  2136. if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
  2137. && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
  2138.  
  2139. $this->privSwapBackMagicQuotes();
  2140.  
  2141. PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION,
  2142. "Unsupported encryption for "
  2143. ." filename '".$v_header['stored_filename']
  2144. ."'");
  2145.  
  2146. return PclZip::errorCode();
  2147. }
  2148. }
  2149.  
  2150. if (($v_extract) && ($v_header['status'] != 'ok')) {
  2151. $v_result = $this->privConvertHeader2FileInfo($v_header,
  2152. $p_file_list[$v_nb_extracted++]);
  2153. if ($v_result != 1) {
  2154. $this->privCloseFd();
  2155. $this->privSwapBackMagicQuotes();
  2156. return $v_result;
  2157. }
  2158.  
  2159. $v_extract = false;
  2160. }
  2161. if ($v_extract)
  2162. {
  2163.  
  2164. @rewind($this->zip_fd);
  2165. if (@fseek($this->zip_fd, $v_header['offset']))
  2166. {
  2167. $this->privCloseFd();
  2168.  
  2169. $this->privSwapBackMagicQuotes();
  2170.  
  2171. PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
  2172.  
  2173. return PclZip::errorCode();
  2174. }
  2175.  
  2176. if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) {
  2177.  
  2178. $v_string = '';
  2179.  
  2180. $v_result1 = $this->privExtractFileAsString($v_header, $v_string, $p_options);
  2181. if ($v_result1 < 1) {
  2182. $this->privCloseFd();
  2183. $this->privSwapBackMagicQuotes();
  2184. return $v_result1;
  2185. }
  2186.  
  2187. if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1)
  2188. {
  2189. $this->privCloseFd();
  2190. $this->privSwapBackMagicQuotes();
  2191.  
  2192. return $v_result;
  2193. }
  2194.  
  2195. $p_file_list[$v_nb_extracted]['content'] = $v_string;
  2196.  
  2197. $v_nb_extracted++;
  2198. if ($v_result1 == 2) {
  2199. break;
  2200. }
  2201. }
  2202. elseif ( (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT]))
  2203. && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) {
  2204. $v_result1 = $this->privExtractFileInOutput($v_header, $p_options);
  2205. if ($v_result1 < 1) {
  2206. $this->privCloseFd();
  2207. $this->privSwapBackMagicQuotes();
  2208. return $v_result1;
  2209. }
  2210.  
  2211. if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) {
  2212. $this->privCloseFd();
  2213. $this->privSwapBackMagicQuotes();
  2214. return $v_result;
  2215. }
  2216.  
  2217. if ($v_result1 == 2) {
  2218. break;
  2219. }
  2220. }
  2221. else {
  2222. $v_result1 = $this->privExtractFile($v_header,
  2223. $p_path, $p_remove_path,
  2224. $p_remove_all_path,
  2225. $p_options);
  2226. if ($v_result1 < 1) {
  2227. $this->privCloseFd();
  2228. $this->privSwapBackMagicQuotes();
  2229. return $v_result1;
  2230. }
  2231.  
  2232. if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1)
  2233. {
  2234. $this->privCloseFd();
  2235. $this->privSwapBackMagicQuotes();
  2236.  
  2237. return $v_result;
  2238. }
  2239.  
  2240. if ($v_result1 == 2) {
  2241. break;
  2242. }
  2243. }
  2244. }
  2245. }
  2246.  
  2247. $this->privCloseFd();
  2248. $this->privSwapBackMagicQuotes();
  2249.  
  2250. return $v_result;
  2251. }
  2252. function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
  2253. {
  2254. $v_result=1;
  2255.  
  2256. if (($v_result = $this->privReadFileHeader($v_header)) != 1)
  2257. {
  2258. return $v_result;
  2259. }
  2260.  
  2261.  
  2262. if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
  2263. }
  2264.  
  2265. if ($p_remove_all_path == true) {
  2266. if (($p_entry['external']&0x00000010)==0x00000010) {
  2267.  
  2268. $p_entry['status'] = "filtered";
  2269.  
  2270. return $v_result;
  2271. }
  2272.  
  2273. $p_entry['filename'] = basename($p_entry['filename']);
  2274. }
  2275.  
  2276. else if ($p_remove_path != "")
  2277. {
  2278. if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2)
  2279. {
  2280.  
  2281. $p_entry['status'] = "filtered";
  2282.  
  2283. return $v_result;
  2284. }
  2285.  
  2286. $p_remove_path_size = strlen($p_remove_path);
  2287. if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path)
  2288. {
  2289.  
  2290. $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size);
  2291.  
  2292. }
  2293. }
  2294.  
  2295. if ($p_path != '') {
  2296. $p_entry['filename'] = $p_path."/".$p_entry['filename'];
  2297. }
  2298. if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) {
  2299. $v_inclusion
  2300. = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION],
  2301. $p_entry['filename']);
  2302. if ($v_inclusion == 0) {
  2303.  
  2304. PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION,
  2305. "Filename '".$p_entry['filename']."' is "
  2306. ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION");
  2307.  
  2308. return PclZip::errorCode();
  2309. }
  2310. }
  2311.  
  2312. if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
  2313.  
  2314. $v_local_header = array();
  2315. $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
  2316.  
  2317. $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
  2318. if ($v_result == 0) {
  2319. $p_entry['status'] = "skipped";
  2320. $v_result = 1;
  2321. }
  2322. if ($v_result == 2) {
  2323. $p_entry['status'] = "aborted";
  2324. $v_result = PCLZIP_ERR_USER_ABORTED;
  2325. }
  2326.  
  2327. $p_entry['filename'] = $v_local_header['filename'];
  2328. }
  2329.  
  2330.  
  2331. if ($p_entry['status'] == 'ok') {
  2332.  
  2333. if (file_exists($p_entry['filename']))
  2334. {
  2335.  
  2336. if (is_dir($p_entry['filename']))
  2337. {
  2338.  
  2339. $p_entry['status'] = "already_a_directory";
  2340. if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
  2341. && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
  2342.  
  2343. PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY,
  2344. "Filename '".$p_entry['filename']."' is "
  2345. ."already used by an existing directory");
  2346.  
  2347. return PclZip::errorCode();
  2348. }
  2349. }
  2350. else if (!is_writeable($p_entry['filename']))
  2351. {
  2352.  
  2353. $p_entry['status'] = "write_protected";
  2354.  
  2355. if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
  2356. && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
  2357.  
  2358. PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
  2359. "Filename '".$p_entry['filename']."' exists "
  2360. ."and is write protected");
  2361.  
  2362. return PclZip::errorCode();
  2363. }
  2364. }
  2365.  
  2366. else if (filemtime($p_entry['filename']) > $p_entry['mtime'])
  2367. {
  2368. if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER]))
  2369. && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) {
  2370. }
  2371. else {
  2372. $p_entry['status'] = "newer_exist";
  2373.  
  2374. if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
  2375. && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
  2376.  
  2377. PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
  2378. "Newer version of '".$p_entry['filename']."' exists "
  2379. ."and option PCLZIP_OPT_REPLACE_NEWER is not selected");
  2380.  
  2381. return PclZip::errorCode();
  2382. }
  2383. }
  2384. }
  2385. else {
  2386. }
  2387. }
  2388.  
  2389. else {
  2390. if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/'))
  2391. $v_dir_to_check = $p_entry['filename'];
  2392. else if (!strstr($p_entry['filename'], "/"))
  2393. $v_dir_to_check = "";
  2394. else
  2395. $v_dir_to_check = dirname($p_entry['filename']);
  2396.  
  2397. if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) {
  2398. $p_entry['status'] = "path_creation_fail";
  2399. $v_result = 1;
  2400. }
  2401. }
  2402. }
  2403.  
  2404. if ($p_entry['status'] == 'ok') {
  2405.  
  2406. if (!(($p_entry['external']&0x00000010)==0x00000010))
  2407. {
  2408. if ($p_entry['compression'] == 0) {
  2409.  
  2410. if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0)
  2411. {
  2412.  
  2413. $p_entry['status'] = "write_error";
  2414.  
  2415. return $v_result;
  2416. }
  2417.  
  2418.  
  2419. $v_size = $p_entry['compressed_size'];
  2420. while ($v_size != 0)
  2421. {
  2422. $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  2423. $v_buffer = @fread($this->zip_fd, $v_read_size);
  2424. @fwrite($v_dest_file, $v_buffer, $v_read_size);
  2425. $v_size -= $v_read_size;
  2426. }
  2427.  
  2428. fclose($v_dest_file);
  2429.  
  2430. touch($p_entry['filename'], $p_entry['mtime']);
  2431.  
  2432. }
  2433. else {
  2434. if (($p_entry['flag'] & 1) == 1) {
  2435. PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'File \''.$p_entry['filename'].'\' is encrypted. Encrypted files are not supported.');
  2436. return PclZip::errorCode();
  2437. }
  2438.  
  2439.  
  2440. if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF]))
  2441. && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
  2442. || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
  2443. && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])) ) ) {
  2444. $v_result = $this->privExtractFileUsingTempFile($p_entry, $p_options);
  2445. if ($v_result < PCLZIP_ERR_NO_ERROR) {
  2446. return $v_result;
  2447. }
  2448. }
  2449. else {
  2450.  
  2451. $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
  2452. $v_file_content = @gzinflate($v_buffer);
  2453. unset($v_buffer);
  2454. if ($v_file_content === FALSE) {
  2455. $p_entry['status'] = "error";
  2456. return $v_result;
  2457. }
  2458. if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
  2459. $p_entry['status'] = "write_error";
  2460. return $v_result;
  2461. }
  2462. @fwrite($v_dest_file, $v_file_content, $p_entry['size']);
  2463. unset($v_file_content);
  2464. @fclose($v_dest_file);
  2465. }
  2466.  
  2467. @touch($p_entry['filename'], $p_entry['mtime']);
  2468. }
  2469.  
  2470. if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) {
  2471.  
  2472. @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]);
  2473. }
  2474.  
  2475. }
  2476. }
  2477.  
  2478. if ($p_entry['status'] == "aborted") {
  2479. $p_entry['status'] = "skipped";
  2480. }
  2481. elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
  2482.  
  2483. $v_local_header = array();
  2484. $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
  2485.  
  2486. $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
  2487.  
  2488. if ($v_result == 2) {
  2489. $v_result = PCLZIP_ERR_USER_ABORTED;
  2490. }
  2491. }
  2492.  
  2493. return $v_result;
  2494. }
  2495. function privExtractFileUsingTempFile(&$p_entry, &$p_options)
  2496. {
  2497. $v_result=1;
  2498. $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
  2499. if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) {
  2500. fclose($v_file);
  2501. PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
  2502. return PclZip::errorCode();
  2503. }
  2504.  
  2505.  
  2506. $v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3));
  2507. @fwrite($v_dest_file, $v_binary_data, 10);
  2508.  
  2509. $v_size = $p_entry['compressed_size'];
  2510. while ($v_size != 0)
  2511. {
  2512. $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  2513. $v_buffer = @fread($this->zip_fd, $v_read_size);
  2514. @fwrite($v_dest_file, $v_buffer, $v_read_size);
  2515. $v_size -= $v_read_size;
  2516. }
  2517.  
  2518. $v_binary_data = pack('VV', $p_entry['crc'], $p_entry['size']);
  2519. @fwrite($v_dest_file, $v_binary_data, 8);
  2520.  
  2521. @fclose($v_dest_file);
  2522.  
  2523. if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
  2524. $p_entry['status'] = "write_error";
  2525. return $v_result;
  2526. }
  2527.  
  2528. if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) {
  2529. @fclose($v_dest_file);
  2530. $p_entry['status'] = "read_error";
  2531. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
  2532. return PclZip::errorCode();
  2533. }
  2534.  
  2535.  
  2536. $v_size = $p_entry['size'];
  2537. while ($v_size != 0) {
  2538. $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  2539. $v_buffer = @gzread($v_src_file, $v_read_size);
  2540. @fwrite($v_dest_file, $v_buffer, $v_read_size);
  2541. $v_size -= $v_read_size;
  2542. }
  2543. @fclose($v_dest_file);
  2544. @gzclose($v_src_file);
  2545.  
  2546. @unlink($v_gzip_temp_name);
  2547. return $v_result;
  2548. }
  2549. function privExtractFileInOutput(&$p_entry, &$p_options)
  2550. {
  2551. $v_result=1;
  2552.  
  2553. if (($v_result = $this->privReadFileHeader($v_header)) != 1) {
  2554. return $v_result;
  2555. }
  2556.  
  2557.  
  2558. if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
  2559. }
  2560.  
  2561. if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
  2562.  
  2563. $v_local_header = array();
  2564. $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
  2565.  
  2566. $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
  2567. if ($v_result == 0) {
  2568. $p_entry['status'] = "skipped";
  2569. $v_result = 1;
  2570. }
  2571.  
  2572. if ($v_result == 2) {
  2573. $p_entry['status'] = "aborted";
  2574. $v_result = PCLZIP_ERR_USER_ABORTED;
  2575. }
  2576.  
  2577. $p_entry['filename'] = $v_local_header['filename'];
  2578. }
  2579.  
  2580. if ($p_entry['status'] == 'ok') {
  2581.  
  2582. if (!(($p_entry['external']&0x00000010)==0x00000010)) {
  2583. if ($p_entry['compressed_size'] == $p_entry['size']) {
  2584.  
  2585. $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
  2586.  
  2587. echo $v_buffer;
  2588. unset($v_buffer);
  2589. }
  2590. else {
  2591.  
  2592. $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
  2593. $v_file_content = gzinflate($v_buffer);
  2594. unset($v_buffer);
  2595.  
  2596. echo $v_file_content;
  2597. unset($v_file_content);
  2598. }
  2599. }
  2600. }
  2601.  
  2602. if ($p_entry['status'] == "aborted") {
  2603. $p_entry['status'] = "skipped";
  2604. }
  2605.  
  2606. elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
  2607.  
  2608. $v_local_header = array();
  2609. $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
  2610.  
  2611. $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
  2612.  
  2613. if ($v_result == 2) {
  2614. $v_result = PCLZIP_ERR_USER_ABORTED;
  2615. }
  2616. }
  2617.  
  2618. return $v_result;
  2619. }
  2620. function privExtractFileAsString(&$p_entry, &$p_string, &$p_options)
  2621. {
  2622. $v_result=1;
  2623.  
  2624. $v_header = array();
  2625. if (($v_result = $this->privReadFileHeader($v_header)) != 1)
  2626. {
  2627. return $v_result;
  2628. }
  2629.  
  2630.  
  2631. if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
  2632. }
  2633.  
  2634. if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
  2635.  
  2636. $v_local_header = array();
  2637. $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
  2638.  
  2639. $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
  2640. if ($v_result == 0) {
  2641. $p_entry['status'] = "skipped";
  2642. $v_result = 1;
  2643. }
  2644. if ($v_result == 2) {
  2645. $p_entry['status'] = "aborted";
  2646. $v_result = PCLZIP_ERR_USER_ABORTED;
  2647. }
  2648.  
  2649. $p_entry['filename'] = $v_local_header['filename'];
  2650. }
  2651.  
  2652.  
  2653. if ($p_entry['status'] == 'ok') {
  2654.  
  2655. if (!(($p_entry['external']&0x00000010)==0x00000010)) {
  2656. if ($p_entry['compression'] == 0) {
  2657. $p_string = @fread($this->zip_fd, $p_entry['compressed_size']);
  2658. }
  2659. else {
  2660. $v_data = @fread($this->zip_fd, $p_entry['compressed_size']);
  2661. if (($p_string = @gzinflate($v_data)) === FALSE) {
  2662. }
  2663. }
  2664. }
  2665. else {
  2666. }
  2667. }
  2668.  
  2669. if ($p_entry['status'] == "aborted") {
  2670. $p_entry['status'] = "skipped";
  2671. }
  2672. elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
  2673.  
  2674. $v_local_header = array();
  2675. $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
  2676. $v_local_header['content'] = $p_string;
  2677. $p_string = '';
  2678.  
  2679. $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
  2680.  
  2681. $p_string = $v_local_header['content'];
  2682. unset($v_local_header['content']);
  2683.  
  2684. if ($v_result == 2) {
  2685. $v_result = PCLZIP_ERR_USER_ABORTED;
  2686. }
  2687. }
  2688.  
  2689. return $v_result;
  2690. }
  2691. function privReadFileHeader(&$p_header)
  2692. {
  2693. $v_result=1;
  2694.  
  2695. $v_binary_data = @fread($this->zip_fd, 4);
  2696. $v_data = unpack('Vid', $v_binary_data);
  2697.  
  2698. if ($v_data['id'] != 0x04034b50)
  2699. {
  2700.  
  2701. PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
  2702.  
  2703. return PclZip::errorCode();
  2704. }
  2705.  
  2706. $v_binary_data = fread($this->zip_fd, 26);
  2707.  
  2708. if (strlen($v_binary_data) != 26)
  2709. {
  2710. $p_header['filename'] = "";
  2711. $p_header['status'] = "invalid_header";
  2712.  
  2713. PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
  2714.  
  2715. return PclZip::errorCode();
  2716. }
  2717.  
  2718. $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data);
  2719.  
  2720. $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']);
  2721.  
  2722. if ($v_data['extra_len'] != 0) {
  2723. $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']);
  2724. }
  2725. else {
  2726. $p_header['extra'] = '';
  2727. }
  2728.  
  2729. $p_header['version_extracted'] = $v_data['version'];
  2730. $p_header['compression'] = $v_data['compression'];
  2731. $p_header['size'] = $v_data['size'];
  2732. $p_header['compressed_size'] = $v_data['compressed_size'];
  2733. $p_header['crc'] = $v_data['crc'];
  2734. $p_header['flag'] = $v_data['flag'];
  2735. $p_header['filename_len'] = $v_data['filename_len'];
  2736.  
  2737. $p_header['mdate'] = $v_data['mdate'];
  2738. $p_header['mtime'] = $v_data['mtime'];
  2739. if ($p_header['mdate'] && $p_header['mtime'])
  2740. {
  2741. $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
  2742. $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
  2743. $v_seconde = ($p_header['mtime'] & 0x001F)*2;
  2744.  
  2745. $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
  2746. $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
  2747. $v_day = $p_header['mdate'] & 0x001F;
  2748.  
  2749. $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
  2750.  
  2751. }
  2752. else
  2753. {
  2754. $p_header['mtime'] = time();
  2755. }
  2756.  
  2757. $p_header['stored_filename'] = $p_header['filename'];
  2758.  
  2759. $p_header['status'] = "ok";
  2760.  
  2761. return $v_result;
  2762. }
  2763. function privReadCentralFileHeader(&$p_header)
  2764. {
  2765. $v_result=1;
  2766.  
  2767. $v_binary_data = @fread($this->zip_fd, 4);
  2768. $v_data = unpack('Vid', $v_binary_data);
  2769.  
  2770. if ($v_data['id'] != 0x02014b50)
  2771. {
  2772.  
  2773. PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
  2774.  
  2775. return PclZip::errorCode();
  2776. }
  2777.  
  2778. $v_binary_data = fread($this->zip_fd, 42);
  2779.  
  2780. if (strlen($v_binary_data) != 42)
  2781. {
  2782. $p_header['filename'] = "";
  2783. $p_header['status'] = "invalid_header";
  2784.  
  2785. PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
  2786.  
  2787. return PclZip::errorCode();
  2788. }
  2789.  
  2790. $p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data);
  2791.  
  2792. if ($p_header['filename_len'] != 0)
  2793. $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']);
  2794. else
  2795. $p_header['filename'] = '';
  2796.  
  2797. if ($p_header['extra_len'] != 0)
  2798. $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']);
  2799. else
  2800. $p_header['extra'] = '';
  2801.  
  2802. if ($p_header['comment_len'] != 0)
  2803. $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']);
  2804. else
  2805. $p_header['comment'] = '';
  2806.  
  2807. if (1)
  2808. {
  2809. $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
  2810. $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
  2811. $v_seconde = ($p_header['mtime'] & 0x001F)*2;
  2812.  
  2813. $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
  2814. $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
  2815. $v_day = $p_header['mdate'] & 0x001F;
  2816.  
  2817. $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
  2818.  
  2819. }
  2820. else
  2821. {
  2822. $p_header['mtime'] = time();
  2823. }
  2824.  
  2825. $p_header['stored_filename'] = $p_header['filename'];
  2826.  
  2827. $p_header['status'] = 'ok';
  2828.  
  2829. if (substr($p_header['filename'], -1) == '/') {
  2830. $p_header['external'] = 0x00000010;
  2831. }
  2832.  
  2833.  
  2834. return $v_result;
  2835. }
  2836. function privCheckFileHeaders(&$p_local_header, &$p_central_header)
  2837. {
  2838. $v_result=1;
  2839.  
  2840. if ($p_local_header['filename'] != $p_central_header['filename']) {
  2841. }
  2842. if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) {
  2843. }
  2844. if ($p_local_header['flag'] != $p_central_header['flag']) {
  2845. }
  2846. if ($p_local_header['compression'] != $p_central_header['compression']) {
  2847. }
  2848. if ($p_local_header['mtime'] != $p_central_header['mtime']) {
  2849. }
  2850. if ($p_local_header['filename_len'] != $p_central_header['filename_len']) {
  2851. }
  2852. if (($p_local_header['flag'] & 8) == 8) {
  2853. $p_local_header['size'] = $p_central_header['size'];
  2854. $p_local_header['compressed_size'] = $p_central_header['compressed_size'];
  2855. $p_local_header['crc'] = $p_central_header['crc'];
  2856. }
  2857.  
  2858. return $v_result;
  2859. }
  2860. function privReadEndCentralDir(&$p_central_dir)
  2861. {
  2862. $v_result=1;
  2863.  
  2864. $v_size = filesize($this->zipname);
  2865. @fseek($this->zip_fd, $v_size);
  2866. if (@ftell($this->zip_fd) != $v_size)
  2867. {
  2868. PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\'');
  2869.  
  2870. return PclZip::errorCode();
  2871. }
  2872.  
  2873. $v_found = 0;
  2874. if ($v_size > 26) {
  2875. @fseek($this->zip_fd, $v_size-22);
  2876. if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22))
  2877. {
  2878. PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
  2879.  
  2880. return PclZip::errorCode();
  2881. }
  2882.  
  2883. $v_binary_data = @fread($this->zip_fd, 4);
  2884. $v_data = @unpack('Vid', $v_binary_data);
  2885.  
  2886. if ($v_data['id'] == 0x06054b50) {
  2887. $v_found = 1;
  2888. }
  2889.  
  2890. $v_pos = ftell($this->zip_fd);
  2891. }
  2892.  
  2893. if (!$v_found) {
  2894. $v_maximum_size = 65557; if ($v_maximum_size > $v_size)
  2895. $v_maximum_size = $v_size;
  2896. @fseek($this->zip_fd, $v_size-$v_maximum_size);
  2897. if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size))
  2898. {
  2899. PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
  2900.  
  2901. return PclZip::errorCode();
  2902. }
  2903.  
  2904. $v_pos = ftell($this->zip_fd);
  2905. $v_bytes = 0x00000000;
  2906. while ($v_pos < $v_size)
  2907. {
  2908. $v_byte = @fread($this->zip_fd, 1);
  2909.  
  2910. $v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte);
  2911.  
  2912. if ($v_bytes == 0x504b0506)
  2913. {
  2914. $v_pos++;
  2915. break;
  2916. }
  2917.  
  2918. $v_pos++;
  2919. }
  2920.  
  2921. if ($v_pos == $v_size)
  2922. {
  2923.  
  2924. PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature");
  2925.  
  2926. return PclZip::errorCode();
  2927. }
  2928. }
  2929.  
  2930. $v_binary_data = fread($this->zip_fd, 18);
  2931.  
  2932. if (strlen($v_binary_data) != 18)
  2933. {
  2934.  
  2935. PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data));
  2936.  
  2937. return PclZip::errorCode();
  2938. }
  2939.  
  2940. $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data);
  2941.  
  2942. if (($v_pos + $v_data['comment_size'] + 18) != $v_size) {
  2943.  
  2944. if (0) {
  2945. PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT,
  2946. 'The central dir is not at the end of the archive.'
  2947. .' Some trailing bytes exists after the archive.');
  2948.  
  2949. return PclZip::errorCode();
  2950. }
  2951. }
  2952.  
  2953. if ($v_data['comment_size'] != 0) {
  2954. $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']);
  2955. }
  2956. else
  2957. $p_central_dir['comment'] = '';
  2958.  
  2959. $p_central_dir['entries'] = $v_data['entries'];
  2960. $p_central_dir['disk_entries'] = $v_data['disk_entries'];
  2961. $p_central_dir['offset'] = $v_data['offset'];
  2962. $p_central_dir['size'] = $v_data['size'];
  2963. $p_central_dir['disk'] = $v_data['disk'];
  2964. $p_central_dir['disk_start'] = $v_data['disk_start'];
  2965.  
  2966. return $v_result;
  2967. }
  2968. function privDeleteByRule(&$p_result_list, &$p_options)
  2969. {
  2970. $v_result=1;
  2971. $v_list_detail = array();
  2972.  
  2973. if (($v_result=$this->privOpenFd('rb')) != 1)
  2974. {
  2975. return $v_result;
  2976. }
  2977.  
  2978. $v_central_dir = array();
  2979. if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
  2980. {
  2981. $this->privCloseFd();
  2982. return $v_result;
  2983. }
  2984.  
  2985. @rewind($this->zip_fd);
  2986.  
  2987. $v_pos_entry = $v_central_dir['offset'];
  2988. @rewind($this->zip_fd);
  2989. if (@fseek($this->zip_fd, $v_pos_entry))
  2990. {
  2991. $this->privCloseFd();
  2992.  
  2993. PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
  2994.  
  2995. return PclZip::errorCode();
  2996. }
  2997.  
  2998. $v_header_list = array();
  2999. $j_start = 0;
  3000. for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
  3001. {
  3002.  
  3003. $v_header_list[$v_nb_extracted] = array();
  3004. if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1)
  3005. {
  3006. $this->privCloseFd();
  3007.  
  3008. return $v_result;
  3009. }
  3010.  
  3011.  
  3012. $v_header_list[$v_nb_extracted]['index'] = $i;
  3013.  
  3014. $v_found = false;
  3015.  
  3016. if ( (isset($p_options[PCLZIP_OPT_BY_NAME]))
  3017. && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
  3018.  
  3019. for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) {
  3020.  
  3021. if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") {
  3022.  
  3023. if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
  3024. && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
  3025. $v_found = true;
  3026. }
  3027. elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010)
  3028. && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
  3029. $v_found = true;
  3030. }
  3031. }
  3032. elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
  3033. $v_found = true;
  3034. }
  3035. }
  3036. }
  3037.  
  3038. else if ( (isset($p_options[PCLZIP_OPT_BY_PREG]))
  3039. && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
  3040.  
  3041. if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
  3042. $v_found = true;
  3043. }
  3044. }
  3045.  
  3046. else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX]))
  3047. && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
  3048.  
  3049. for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) {
  3050.  
  3051. if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
  3052. $v_found = true;
  3053. }
  3054. if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
  3055. $j_start = $j+1;
  3056. }
  3057.  
  3058. if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
  3059. break;
  3060. }
  3061. }
  3062. }
  3063. else {
  3064. $v_found = true;
  3065. }
  3066.  
  3067. if ($v_found)
  3068. {
  3069. unset($v_header_list[$v_nb_extracted]);
  3070. }
  3071. else
  3072. {
  3073. $v_nb_extracted++;
  3074. }
  3075. }
  3076.  
  3077. if ($v_nb_extracted > 0) {
  3078.  
  3079. $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
  3080.  
  3081. $v_temp_zip = new PclZip($v_zip_temp_name);
  3082.  
  3083. if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) {
  3084. $this->privCloseFd();
  3085.  
  3086. return $v_result;
  3087. }
  3088.  
  3089. for ($i=0; $i<sizeof($v_header_list); $i++) {
  3090.  
  3091. @rewind($this->zip_fd);
  3092. if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) {
  3093. $this->privCloseFd();
  3094. $v_temp_zip->privCloseFd();
  3095. @unlink($v_zip_temp_name);
  3096.  
  3097. PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
  3098.  
  3099. return PclZip::errorCode();
  3100. }
  3101.  
  3102. $v_local_header = array();
  3103. if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) {
  3104. $this->privCloseFd();
  3105. $v_temp_zip->privCloseFd();
  3106. @unlink($v_zip_temp_name);
  3107.  
  3108. return $v_result;
  3109. }
  3110. if ($this->privCheckFileHeaders($v_local_header,
  3111. $v_header_list[$i]) != 1) {
  3112. }
  3113. unset($v_local_header);
  3114.  
  3115. if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) {
  3116. $this->privCloseFd();
  3117. $v_temp_zip->privCloseFd();
  3118. @unlink($v_zip_temp_name);
  3119.  
  3120. return $v_result;
  3121. }
  3122.  
  3123. if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) {
  3124. $this->privCloseFd();
  3125. $v_temp_zip->privCloseFd();
  3126. @unlink($v_zip_temp_name);
  3127.  
  3128. return $v_result;
  3129. }
  3130. }
  3131.  
  3132. $v_offset = @ftell($v_temp_zip->zip_fd);
  3133.  
  3134. for ($i=0; $i<sizeof($v_header_list); $i++) {
  3135. if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) {
  3136. $v_temp_zip->privCloseFd();
  3137. $this->privCloseFd();
  3138. @unlink($v_zip_temp_name);
  3139.  
  3140. return $v_result;
  3141. }
  3142.  
  3143. $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
  3144. }
  3145.  
  3146.  
  3147. $v_comment = '';
  3148. if (isset($p_options[PCLZIP_OPT_COMMENT])) {
  3149. $v_comment = $p_options[PCLZIP_OPT_COMMENT];
  3150. }
  3151.  
  3152. $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset;
  3153.  
  3154. if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) {
  3155. unset($v_header_list);
  3156. $v_temp_zip->privCloseFd();
  3157. $this->privCloseFd();
  3158. @unlink($v_zip_temp_name);
  3159.  
  3160. return $v_result;
  3161. }
  3162.  
  3163. $v_temp_zip->privCloseFd();
  3164. $this->privCloseFd();
  3165.  
  3166. @unlink($this->zipname);
  3167.  
  3168. PclZipUtilRename($v_zip_temp_name, $this->zipname);
  3169. unset($v_temp_zip);
  3170. }
  3171. else if ($v_central_dir['entries'] != 0) {
  3172. $this->privCloseFd();
  3173.  
  3174. if (($v_result = $this->privOpenFd('wb')) != 1) {
  3175. return $v_result;
  3176. }
  3177.  
  3178. if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) {
  3179. return $v_result;
  3180. }
  3181.  
  3182. $this->privCloseFd();
  3183. }
  3184.  
  3185. return $v_result;
  3186. }
  3187. function privDirCheck($p_dir, $p_is_dir=false)
  3188. {
  3189. $v_result = 1;
  3190.  
  3191.  
  3192. if (($p_is_dir) && (substr($p_dir, -1)=='/'))
  3193. {
  3194. $p_dir = substr($p_dir, 0, strlen($p_dir)-1);
  3195. }
  3196.  
  3197. if ((is_dir($p_dir)) || ($p_dir == ""))
  3198. {
  3199. return 1;
  3200. }
  3201.  
  3202. $p_parent_dir = dirname($p_dir);
  3203.  
  3204. if ($p_parent_dir != $p_dir)
  3205. {
  3206. if ($p_parent_dir != "")
  3207. {
  3208. if (($v_result = $this->privDirCheck($p_parent_dir)) != 1)
  3209. {
  3210. return $v_result;
  3211. }
  3212. }
  3213. }
  3214.  
  3215. if (!@mkdir($p_dir, 0777))
  3216. {
  3217. PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'");
  3218.  
  3219. return PclZip::errorCode();
  3220. }
  3221.  
  3222. return $v_result;
  3223. }
  3224. function privMerge(&$p_archive_to_add)
  3225. {
  3226. $v_result=1;
  3227.  
  3228. if (!is_file($p_archive_to_add->zipname))
  3229. {
  3230.  
  3231. $v_result = 1;
  3232.  
  3233. return $v_result;
  3234. }
  3235.  
  3236. if (!is_file($this->zipname))
  3237. {
  3238.  
  3239. $v_result = $this->privDuplicate($p_archive_to_add->zipname);
  3240.  
  3241. return $v_result;
  3242. }
  3243.  
  3244. if (($v_result=$this->privOpenFd('rb')) != 1)
  3245. {
  3246. return $v_result;
  3247. }
  3248.  
  3249. $v_central_dir = array();
  3250. if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
  3251. {
  3252. $this->privCloseFd();
  3253. return $v_result;
  3254. }
  3255.  
  3256. @rewind($this->zip_fd);
  3257.  
  3258. if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1)
  3259. {
  3260. $this->privCloseFd();
  3261.  
  3262. return $v_result;
  3263. }
  3264.  
  3265. $v_central_dir_to_add = array();
  3266. if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1)
  3267. {
  3268. $this->privCloseFd();
  3269. $p_archive_to_add->privCloseFd();
  3270.  
  3271. return $v_result;
  3272. }
  3273.  
  3274. @rewind($p_archive_to_add->zip_fd);
  3275.  
  3276. $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
  3277.  
  3278. if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
  3279. {
  3280. $this->privCloseFd();
  3281. $p_archive_to_add->privCloseFd();
  3282.  
  3283. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
  3284.  
  3285. return PclZip::errorCode();
  3286. }
  3287.  
  3288. $v_size = $v_central_dir['offset'];
  3289. while ($v_size != 0)
  3290. {
  3291. $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  3292. $v_buffer = fread($this->zip_fd, $v_read_size);
  3293. @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
  3294. $v_size -= $v_read_size;
  3295. }
  3296.  
  3297. $v_size = $v_central_dir_to_add['offset'];
  3298. while ($v_size != 0)
  3299. {
  3300. $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  3301. $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size);
  3302. @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
  3303. $v_size -= $v_read_size;
  3304. }
  3305.  
  3306. $v_offset = @ftell($v_zip_temp_fd);
  3307.  
  3308. $v_size = $v_central_dir['size'];
  3309. while ($v_size != 0)
  3310. {
  3311. $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  3312. $v_buffer = @fread($this->zip_fd, $v_read_size);
  3313. @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
  3314. $v_size -= $v_read_size;
  3315. }
  3316.  
  3317. $v_size = $v_central_dir_to_add['size'];
  3318. while ($v_size != 0)
  3319. {
  3320. $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  3321. $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size);
  3322. @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
  3323. $v_size -= $v_read_size;
  3324. }
  3325.  
  3326. $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment'];
  3327.  
  3328. $v_size = @ftell($v_zip_temp_fd)-$v_offset;
  3329.  
  3330. $v_swap = $this->zip_fd;
  3331. $this->zip_fd = $v_zip_temp_fd;
  3332. $v_zip_temp_fd = $v_swap;
  3333.  
  3334. if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1)
  3335. {
  3336. $this->privCloseFd();
  3337. $p_archive_to_add->privCloseFd();
  3338. @fclose($v_zip_temp_fd);
  3339. $this->zip_fd = null;
  3340.  
  3341. unset($v_header_list);
  3342.  
  3343. return $v_result;
  3344. }
  3345.  
  3346. $v_swap = $this->zip_fd;
  3347. $this->zip_fd = $v_zip_temp_fd;
  3348. $v_zip_temp_fd = $v_swap;
  3349.  
  3350. $this->privCloseFd();
  3351. $p_archive_to_add->privCloseFd();
  3352.  
  3353. @fclose($v_zip_temp_fd);
  3354.  
  3355. @unlink($this->zipname);
  3356.  
  3357. PclZipUtilRename($v_zip_temp_name, $this->zipname);
  3358.  
  3359. return $v_result;
  3360. }
  3361. function privDuplicate($p_archive_filename)
  3362. {
  3363. $v_result=1;
  3364.  
  3365. if (!is_file($p_archive_filename))
  3366. {
  3367.  
  3368. $v_result = 1;
  3369.  
  3370. return $v_result;
  3371. }
  3372.  
  3373. if (($v_result=$this->privOpenFd('wb')) != 1)
  3374. {
  3375. return $v_result;
  3376. }
  3377.  
  3378. if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0)
  3379. {
  3380. $this->privCloseFd();
  3381.  
  3382. PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode');
  3383.  
  3384. return PclZip::errorCode();
  3385. }
  3386.  
  3387. $v_size = filesize($p_archive_filename);
  3388. while ($v_size != 0)
  3389. {
  3390. $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
  3391. $v_buffer = fread($v_zip_temp_fd, $v_read_size);
  3392. @fwrite($this->zip_fd, $v_buffer, $v_read_size);
  3393. $v_size -= $v_read_size;
  3394. }
  3395.  
  3396. $this->privCloseFd();
  3397.  
  3398. @fclose($v_zip_temp_fd);
  3399.  
  3400. return $v_result;
  3401. }
  3402. function privErrorLog($p_error_code=0, $p_error_string='')
  3403. {
  3404. if (PCLZIP_ERROR_EXTERNAL == 1) {
  3405. PclError($p_error_code, $p_error_string);
  3406. }
  3407. else {
  3408. $this->error_code = $p_error_code;
  3409. $this->error_string = $p_error_string;
  3410. }
  3411. }
  3412. function privErrorReset()
  3413. {
  3414. if (PCLZIP_ERROR_EXTERNAL == 1) {
  3415. PclErrorReset();
  3416. }
  3417. else {
  3418. $this->error_code = 0;
  3419. $this->error_string = '';
  3420. }
  3421. }
  3422. function privDisableMagicQuotes()
  3423. {
  3424. $v_result=1;
  3425.  
  3426. if ( (!function_exists("get_magic_quotes_runtime"))
  3427. || (!function_exists("set_magic_quotes_runtime"))) {
  3428. return $v_result;
  3429. }
  3430.  
  3431. if ($this->magic_quotes_status != -1) {
  3432. return $v_result;
  3433. }
  3434.  
  3435. $this->magic_quotes_status = @get_magic_quotes_runtime();
  3436.  
  3437. if ($this->magic_quotes_status == 1) {
  3438. @set_magic_quotes_runtime(0);
  3439. }
  3440.  
  3441. return $v_result;
  3442. }
  3443. function privSwapBackMagicQuotes()
  3444. {
  3445. $v_result=1;
  3446.  
  3447. if ( (!function_exists("get_magic_quotes_runtime"))
  3448. || (!function_exists("set_magic_quotes_runtime"))) {
  3449. return $v_result;
  3450. }
  3451.  
  3452. if ($this->magic_quotes_status != -1) {
  3453. return $v_result;
  3454. }
  3455.  
  3456. if ($this->magic_quotes_status == 1) {
  3457. @set_magic_quotes_runtime($this->magic_quotes_status);
  3458. }
  3459.  
  3460. return $v_result;
  3461. }
  3462. }
  3463. function PclZipUtilPathReduction($p_dir)
  3464. {
  3465. $v_result = "";
  3466.  
  3467. if ($p_dir != "") {
  3468. $v_list = explode("/", $p_dir);
  3469.  
  3470. $v_skip = 0;
  3471. for ($i=sizeof($v_list)-1; $i>=0; $i--) {
  3472. if ($v_list[$i] == ".") {
  3473. }
  3474. else if ($v_list[$i] == "..") {
  3475. $v_skip++;
  3476. }
  3477. else if ($v_list[$i] == "") {
  3478. if ($i == 0) {
  3479. $v_result = "/".$v_result;
  3480. if ($v_skip > 0) {
  3481. $v_result = $p_dir;
  3482. $v_skip = 0;
  3483. }
  3484. }
  3485. else if ($i == (sizeof($v_list)-1)) {
  3486. $v_result = $v_list[$i];
  3487. }
  3488. else {
  3489. }
  3490. }
  3491. else {
  3492. if ($v_skip > 0) {
  3493. $v_skip--;
  3494. }
  3495. else {
  3496. $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:"");
  3497. }
  3498. }
  3499. }
  3500. if ($v_skip > 0) {
  3501. while ($v_skip > 0) {
  3502. $v_result = '../'.$v_result;
  3503. $v_skip--;
  3504. }
  3505. }
  3506. }
  3507.  
  3508. return $v_result;
  3509. }
  3510. function PclZipUtilPathInclusion($p_dir, $p_path)
  3511. {
  3512. $v_result = 1;
  3513. if ( ($p_dir == '.')
  3514. || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) {
  3515. $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1);
  3516. }
  3517. if ( ($p_path == '.')
  3518. || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) {
  3519. $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1);
  3520. }
  3521.  
  3522. $v_list_dir = explode("/", $p_dir);
  3523. $v_list_dir_size = sizeof($v_list_dir);
  3524. $v_list_path = explode("/", $p_path);
  3525. $v_list_path_size = sizeof($v_list_path);
  3526.  
  3527. $i = 0;
  3528. $j = 0;
  3529. while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) {
  3530.  
  3531. if ($v_list_dir[$i] == '') {
  3532. $i++;
  3533. continue;
  3534. }
  3535. if ($v_list_path[$j] == '') {
  3536. $j++;
  3537. continue;
  3538. }
  3539.  
  3540. if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != '')) {
  3541. $v_result = 0;
  3542. }
  3543.  
  3544. $i++;
  3545. $j++;
  3546. }
  3547.  
  3548. if ($v_result) {
  3549. while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++;
  3550. while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++;
  3551.  
  3552. if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) {
  3553. $v_result = 2;
  3554. }
  3555. else if ($i < $v_list_dir_size) {
  3556. $v_result = 0;
  3557. }
  3558. }
  3559.  
  3560. return $v_result;
  3561. }
  3562. function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0)
  3563. {
  3564. $v_result = 1;
  3565.  
  3566. if ($p_mode==0)
  3567. {
  3568. while ($p_size != 0)
  3569. {
  3570. $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
  3571. $v_buffer = @fread($p_src, $v_read_size);
  3572. @fwrite($p_dest, $v_buffer, $v_read_size);
  3573. $p_size -= $v_read_size;
  3574. }
  3575. }
  3576. else if ($p_mode==1)
  3577. {
  3578. while ($p_size != 0)
  3579. {
  3580. $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
  3581. $v_buffer = @gzread($p_src, $v_read_size);
  3582. @fwrite($p_dest, $v_buffer, $v_read_size);
  3583. $p_size -= $v_read_size;
  3584. }
  3585. }
  3586. else if ($p_mode==2)
  3587. {
  3588. while ($p_size != 0)
  3589. {
  3590. $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
  3591. $v_buffer = @fread($p_src, $v_read_size);
  3592. @gzwrite($p_dest, $v_buffer, $v_read_size);
  3593. $p_size -= $v_read_size;
  3594. }
  3595. }
  3596. else if ($p_mode==3)
  3597. {
  3598. while ($p_size != 0)
  3599. {
  3600. $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
  3601. $v_buffer = @gzread($p_src, $v_read_size);
  3602. @gzwrite($p_dest, $v_buffer, $v_read_size);
  3603. $p_size -= $v_read_size;
  3604. }
  3605. }
  3606.  
  3607. return $v_result;
  3608. }
  3609. function PclZipUtilRename($p_src, $p_dest)
  3610. {
  3611. $v_result = 1;
  3612.  
  3613. if (!@rename($p_src, $p_dest)) {
  3614.  
  3615. if (!@copy($p_src, $p_dest)) {
  3616. $v_result = 0;
  3617. }
  3618. else if (!@unlink($p_src)) {
  3619. $v_result = 0;
  3620. }
  3621. }
  3622.  
  3623. return $v_result;
  3624. }
  3625. function PclZipUtilOptionText($p_option)
  3626. {
  3627. $v_list = get_defined_constants();
  3628. for (reset($v_list); $v_key = key($v_list); next($v_list)) {
  3629. $v_prefix = substr($v_key, 0, 10);
  3630. if (( ($v_prefix == 'PCLZIP_OPT')
  3631. || ($v_prefix == 'PCLZIP_CB_')
  3632. || ($v_prefix == 'PCLZIP_ATT'))
  3633. && ($v_list[$v_key] == $p_option)) {
  3634. return $v_key;
  3635. }
  3636. }
  3637. $v_result = 'Unknown';
  3638.  
  3639. return $v_result;
  3640. }
  3641. function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true)
  3642. {
  3643. if (stristr(php_uname(), 'windows')) {
  3644. if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) {
  3645. $p_path = substr($p_path, $v_position+1);
  3646. }
  3647. if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {
  3648. $p_path = strtr($p_path, '\\', '/');
  3649. }
  3650. }
  3651. return $p_path;
  3652. }
  3653. function Comments_Shcms()
  3654. {
  3655. global $filepath;
  3656. $zip = new ZipArchive;
  3657.  
  3658. if ($zip->open($filepath) === TRUE)
  3659.  
  3660. {
  3661.  
  3662. $zip->setArchiveComment(utf8_win('SHCMS Engine - CMS система управления сайтом '));
  3663.  
  3664. $zip->addFromString('ReadMe_SHCMS.txt','SHCMS Engine - CMS система управления сайтом
  3665.  
  3666. Официальныый сайт: shcms.ru
  3667. ');
  3668.  
  3669. $zip->close();
  3670.  
  3671.  
  3672. }
  3673. }
  3674. ?>