@@ -28,6 +28,11 @@ discard block |
||
| 28 | 28 | define('PCLZIP_TEMPORARY_DIR', _DIR_TMP); |
| 29 | 29 | } |
| 30 | 30 | if (!function_exists('gzopen') && function_exists('gzopen64')) { |
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @param string $filename |
|
| 34 | + * @param string $mode |
|
| 35 | + */ |
|
| 31 | 36 | function gzopen($filename, $mode, $use_include_path = 0) { |
| 32 | 37 | return gzopen64($filename, $mode, $use_include_path); |
| 33 | 38 | } |
@@ -221,6 +226,10 @@ discard block |
||
| 221 | 226 | // Note that no real action is taken, if the archive does not exist it is not |
| 222 | 227 | // created. Use create() for that. |
| 223 | 228 | // -------------------------------------------------------------------------------- |
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * @param string $p_zipname |
|
| 232 | + */ |
|
| 224 | 233 | function PclZip($p_zipname) |
| 225 | 234 | { |
| 226 | 235 | |
@@ -2344,6 +2353,10 @@ discard block |
||
| 2344 | 2353 | // Description : |
| 2345 | 2354 | // Parameters : |
| 2346 | 2355 | // -------------------------------------------------------------------------------- |
| 2356 | + |
|
| 2357 | + /** |
|
| 2358 | + * @param string $p_mode |
|
| 2359 | + */ |
|
| 2347 | 2360 | function privOpenFd($p_mode) |
| 2348 | 2361 | { |
| 2349 | 2362 | $v_result=1; |
@@ -4160,6 +4173,10 @@ discard block |
||
| 4160 | 4173 | // Parameters : |
| 4161 | 4174 | // Return Values : |
| 4162 | 4175 | // -------------------------------------------------------------------------------- |
| 4176 | + |
|
| 4177 | + /** |
|
| 4178 | + * @param string $p_string |
|
| 4179 | + */ |
|
| 4163 | 4180 | function privExtractFileAsString(&$p_entry, &$p_string, &$p_options) |
| 4164 | 4181 | { |
| 4165 | 4182 | $v_result=1; |
@@ -5053,6 +5070,10 @@ discard block |
||
| 5053 | 5070 | // Parameters : |
| 5054 | 5071 | // Return Values : |
| 5055 | 5072 | // -------------------------------------------------------------------------------- |
| 5073 | + |
|
| 5074 | + /** |
|
| 5075 | + * @param PclZip $p_archive_to_add |
|
| 5076 | + */ |
|
| 5056 | 5077 | function privMerge(&$p_archive_to_add) |
| 5057 | 5078 | { |
| 5058 | 5079 | $v_result=1; |
@@ -5560,6 +5581,11 @@ discard block |
||
| 5560 | 5581 | // 3 : src & dest gzip |
| 5561 | 5582 | // Return Values : |
| 5562 | 5583 | // -------------------------------------------------------------------------------- |
| 5584 | + |
|
| 5585 | + /** |
|
| 5586 | + * @param integer $p_src |
|
| 5587 | + * @param integer $p_dest |
|
| 5588 | + */ |
|
| 5563 | 5589 | function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0) |
| 5564 | 5590 | { |
| 5565 | 5591 | $v_result = 1; |
@@ -5622,6 +5648,11 @@ discard block |
||
| 5622 | 5648 | // Return Values : |
| 5623 | 5649 | // 1 on success, 0 on failure. |
| 5624 | 5650 | // -------------------------------------------------------------------------------- |
| 5651 | + |
|
| 5652 | + /** |
|
| 5653 | + * @param string $p_src |
|
| 5654 | + * @param string $p_dest |
|
| 5655 | + */ |
|
| 5625 | 5656 | function PclZipUtilRename($p_src, $p_dest) |
| 5626 | 5657 | { |
| 5627 | 5658 | $v_result = 1; |
@@ -22,181 +22,181 @@ discard block |
||
| 22 | 22 | // The use of this software is at the risk of the user. |
| 23 | 23 | // |
| 24 | 24 | |
| 25 | - // personnalisations spip |
|
| 26 | - if (!defined('PCLZIP_TEMPORARY_DIR')) { |
|
| 25 | + // personnalisations spip |
|
| 26 | + if (!defined('PCLZIP_TEMPORARY_DIR')) { |
|
| 27 | 27 | define('PCLZIP_TEMPORARY_DIR', _DIR_TMP); |
| 28 | - } |
|
| 29 | - if (!function_exists('gzopen') && function_exists('gzopen64')) { |
|
| 28 | + } |
|
| 29 | + if (!function_exists('gzopen') && function_exists('gzopen64')) { |
|
| 30 | 30 | function gzopen($filename, $mode, $use_include_path = 0) { |
| 31 | - return gzopen64($filename, $mode, $use_include_path); |
|
| 31 | + return gzopen64($filename, $mode, $use_include_path); |
|
| 32 | + } |
|
| 32 | 33 | } |
| 33 | - } |
|
| 34 | - // fin personnalisations spip |
|
| 34 | + // fin personnalisations spip |
|
| 35 | 35 | |
| 36 | - // ----- Constants |
|
| 37 | - if (!defined('PCLZIP_READ_BLOCK_SIZE')) { |
|
| 36 | + // ----- Constants |
|
| 37 | + if (!defined('PCLZIP_READ_BLOCK_SIZE')) { |
|
| 38 | 38 | define( 'PCLZIP_READ_BLOCK_SIZE', 2048 ); |
| 39 | - } |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - // ----- File list separator |
|
| 42 | - // In version 1.x of PclZip, the separator for file list is a space |
|
| 43 | - // (which is not a very smart choice, specifically for windows paths !). |
|
| 44 | - // A better separator should be a comma (,). This constant gives you the |
|
| 45 | - // abilty to change that. |
|
| 46 | - // However notice that changing this value, may have impact on existing |
|
| 47 | - // scripts, using space separated filenames. |
|
| 48 | - // Recommanded values for compatibility with older versions : |
|
| 49 | - //define( 'PCLZIP_SEPARATOR', ' ' ); |
|
| 50 | - // Recommanded values for smart separation of filenames. |
|
| 51 | - if (!defined('PCLZIP_SEPARATOR')) { |
|
| 41 | + // ----- File list separator |
|
| 42 | + // In version 1.x of PclZip, the separator for file list is a space |
|
| 43 | + // (which is not a very smart choice, specifically for windows paths !). |
|
| 44 | + // A better separator should be a comma (,). This constant gives you the |
|
| 45 | + // abilty to change that. |
|
| 46 | + // However notice that changing this value, may have impact on existing |
|
| 47 | + // scripts, using space separated filenames. |
|
| 48 | + // Recommanded values for compatibility with older versions : |
|
| 49 | + //define( 'PCLZIP_SEPARATOR', ' ' ); |
|
| 50 | + // Recommanded values for smart separation of filenames. |
|
| 51 | + if (!defined('PCLZIP_SEPARATOR')) { |
|
| 52 | 52 | define( 'PCLZIP_SEPARATOR', ',' ); |
| 53 | - } |
|
| 54 | - |
|
| 55 | - // ----- Error configuration |
|
| 56 | - // 0 : PclZip Class integrated error handling |
|
| 57 | - // 1 : PclError external library error handling. By enabling this |
|
| 58 | - // you must ensure that you have included PclError library. |
|
| 59 | - // [2,...] : reserved for futur use |
|
| 60 | - if (!defined('PCLZIP_ERROR_EXTERNAL')) { |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + // ----- Error configuration |
|
| 56 | + // 0 : PclZip Class integrated error handling |
|
| 57 | + // 1 : PclError external library error handling. By enabling this |
|
| 58 | + // you must ensure that you have included PclError library. |
|
| 59 | + // [2,...] : reserved for futur use |
|
| 60 | + if (!defined('PCLZIP_ERROR_EXTERNAL')) { |
|
| 61 | 61 | define( 'PCLZIP_ERROR_EXTERNAL', 0 ); |
| 62 | - } |
|
| 63 | - |
|
| 64 | - // ----- Optional static temporary directory |
|
| 65 | - // By default temporary files are generated in the script current |
|
| 66 | - // path. |
|
| 67 | - // If defined : |
|
| 68 | - // - MUST BE terminated by a '/'. |
|
| 69 | - // - MUST be a valid, already created directory |
|
| 70 | - // Samples : |
|
| 71 | - // define( 'PCLZIP_TEMPORARY_DIR', '/temp/' ); |
|
| 72 | - // define( 'PCLZIP_TEMPORARY_DIR', 'C:/Temp/' ); |
|
| 73 | - if (!defined('PCLZIP_TEMPORARY_DIR')) { |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + // ----- Optional static temporary directory |
|
| 65 | + // By default temporary files are generated in the script current |
|
| 66 | + // path. |
|
| 67 | + // If defined : |
|
| 68 | + // - MUST BE terminated by a '/'. |
|
| 69 | + // - MUST be a valid, already created directory |
|
| 70 | + // Samples : |
|
| 71 | + // define( 'PCLZIP_TEMPORARY_DIR', '/temp/' ); |
|
| 72 | + // define( 'PCLZIP_TEMPORARY_DIR', 'C:/Temp/' ); |
|
| 73 | + if (!defined('PCLZIP_TEMPORARY_DIR')) { |
|
| 74 | 74 | define( 'PCLZIP_TEMPORARY_DIR', '' ); |
| 75 | - } |
|
| 76 | - |
|
| 77 | - // ----- Optional threshold ratio for use of temporary files |
|
| 78 | - // Pclzip sense the size of the file to add/extract and decide to |
|
| 79 | - // use or not temporary file. The algorythm is looking for |
|
| 80 | - // memory_limit of PHP and apply a ratio. |
|
| 81 | - // threshold = memory_limit * ratio. |
|
| 82 | - // Recommended values are under 0.5. Default 0.47. |
|
| 83 | - // Samples : |
|
| 84 | - // define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.5 ); |
|
| 85 | - if (!defined('PCLZIP_TEMPORARY_FILE_RATIO')) { |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + // ----- Optional threshold ratio for use of temporary files |
|
| 78 | + // Pclzip sense the size of the file to add/extract and decide to |
|
| 79 | + // use or not temporary file. The algorythm is looking for |
|
| 80 | + // memory_limit of PHP and apply a ratio. |
|
| 81 | + // threshold = memory_limit * ratio. |
|
| 82 | + // Recommended values are under 0.5. Default 0.47. |
|
| 83 | + // Samples : |
|
| 84 | + // define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.5 ); |
|
| 85 | + if (!defined('PCLZIP_TEMPORARY_FILE_RATIO')) { |
|
| 86 | 86 | define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.47 ); |
| 87 | - } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | 89 | // -------------------------------------------------------------------------------- |
| 90 | 90 | // ***** UNDER THIS LINE NOTHING NEEDS TO BE MODIFIED ***** |
| 91 | 91 | // -------------------------------------------------------------------------------- |
| 92 | 92 | |
| 93 | - // ----- Global variables |
|
| 94 | - $g_pclzip_version = "2.8.2"; |
|
| 95 | - |
|
| 96 | - // ----- Error codes |
|
| 97 | - // -1 : Unable to open file in binary write mode |
|
| 98 | - // -2 : Unable to open file in binary read mode |
|
| 99 | - // -3 : Invalid parameters |
|
| 100 | - // -4 : File does not exist |
|
| 101 | - // -5 : Filename is too long (max. 255) |
|
| 102 | - // -6 : Not a valid zip file |
|
| 103 | - // -7 : Invalid extracted file size |
|
| 104 | - // -8 : Unable to create directory |
|
| 105 | - // -9 : Invalid archive extension |
|
| 106 | - // -10 : Invalid archive format |
|
| 107 | - // -11 : Unable to delete file (unlink) |
|
| 108 | - // -12 : Unable to rename file (rename) |
|
| 109 | - // -13 : Invalid header checksum |
|
| 110 | - // -14 : Invalid archive size |
|
| 111 | - define( 'PCLZIP_ERR_USER_ABORTED', 2 ); |
|
| 112 | - define( 'PCLZIP_ERR_NO_ERROR', 0 ); |
|
| 113 | - define( 'PCLZIP_ERR_WRITE_OPEN_FAIL', -1 ); |
|
| 114 | - define( 'PCLZIP_ERR_READ_OPEN_FAIL', -2 ); |
|
| 115 | - define( 'PCLZIP_ERR_INVALID_PARAMETER', -3 ); |
|
| 116 | - define( 'PCLZIP_ERR_MISSING_FILE', -4 ); |
|
| 117 | - define( 'PCLZIP_ERR_FILENAME_TOO_LONG', -5 ); |
|
| 118 | - define( 'PCLZIP_ERR_INVALID_ZIP', -6 ); |
|
| 119 | - define( 'PCLZIP_ERR_BAD_EXTRACTED_FILE', -7 ); |
|
| 120 | - define( 'PCLZIP_ERR_DIR_CREATE_FAIL', -8 ); |
|
| 121 | - define( 'PCLZIP_ERR_BAD_EXTENSION', -9 ); |
|
| 122 | - define( 'PCLZIP_ERR_BAD_FORMAT', -10 ); |
|
| 123 | - define( 'PCLZIP_ERR_DELETE_FILE_FAIL', -11 ); |
|
| 124 | - define( 'PCLZIP_ERR_RENAME_FILE_FAIL', -12 ); |
|
| 125 | - define( 'PCLZIP_ERR_BAD_CHECKSUM', -13 ); |
|
| 126 | - define( 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14 ); |
|
| 127 | - define( 'PCLZIP_ERR_MISSING_OPTION_VALUE', -15 ); |
|
| 128 | - define( 'PCLZIP_ERR_INVALID_OPTION_VALUE', -16 ); |
|
| 129 | - define( 'PCLZIP_ERR_ALREADY_A_DIRECTORY', -17 ); |
|
| 130 | - define( 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18 ); |
|
| 131 | - define( 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19 ); |
|
| 132 | - define( 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', -20 ); |
|
| 133 | - define( 'PCLZIP_ERR_DIRECTORY_RESTRICTION', -21 ); |
|
| 134 | - |
|
| 135 | - // ----- Options values |
|
| 136 | - define( 'PCLZIP_OPT_PATH', 77001 ); |
|
| 137 | - define( 'PCLZIP_OPT_ADD_PATH', 77002 ); |
|
| 138 | - define( 'PCLZIP_OPT_REMOVE_PATH', 77003 ); |
|
| 139 | - define( 'PCLZIP_OPT_REMOVE_ALL_PATH', 77004 ); |
|
| 140 | - define( 'PCLZIP_OPT_SET_CHMOD', 77005 ); |
|
| 141 | - define( 'PCLZIP_OPT_EXTRACT_AS_STRING', 77006 ); |
|
| 142 | - define( 'PCLZIP_OPT_NO_COMPRESSION', 77007 ); |
|
| 143 | - define( 'PCLZIP_OPT_BY_NAME', 77008 ); |
|
| 144 | - define( 'PCLZIP_OPT_BY_INDEX', 77009 ); |
|
| 145 | - define( 'PCLZIP_OPT_BY_EREG', 77010 ); |
|
| 146 | - define( 'PCLZIP_OPT_BY_PREG', 77011 ); |
|
| 147 | - define( 'PCLZIP_OPT_COMMENT', 77012 ); |
|
| 148 | - define( 'PCLZIP_OPT_ADD_COMMENT', 77013 ); |
|
| 149 | - define( 'PCLZIP_OPT_PREPEND_COMMENT', 77014 ); |
|
| 150 | - define( 'PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015 ); |
|
| 151 | - define( 'PCLZIP_OPT_REPLACE_NEWER', 77016 ); |
|
| 152 | - define( 'PCLZIP_OPT_STOP_ON_ERROR', 77017 ); |
|
| 153 | - // Having big trouble with crypt. Need to multiply 2 long int |
|
| 154 | - // which is not correctly supported by PHP ... |
|
| 155 | - //define( 'PCLZIP_OPT_CRYPT', 77018 ); |
|
| 156 | - define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 ); |
|
| 157 | - define( 'PCLZIP_OPT_TEMP_FILE_THRESHOLD', 77020 ); |
|
| 158 | - define( 'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD', 77020 ); // alias |
|
| 159 | - define( 'PCLZIP_OPT_TEMP_FILE_ON', 77021 ); |
|
| 160 | - define( 'PCLZIP_OPT_ADD_TEMP_FILE_ON', 77021 ); // alias |
|
| 161 | - define( 'PCLZIP_OPT_TEMP_FILE_OFF', 77022 ); |
|
| 162 | - define( 'PCLZIP_OPT_ADD_TEMP_FILE_OFF', 77022 ); // alias |
|
| 93 | + // ----- Global variables |
|
| 94 | + $g_pclzip_version = "2.8.2"; |
|
| 95 | + |
|
| 96 | + // ----- Error codes |
|
| 97 | + // -1 : Unable to open file in binary write mode |
|
| 98 | + // -2 : Unable to open file in binary read mode |
|
| 99 | + // -3 : Invalid parameters |
|
| 100 | + // -4 : File does not exist |
|
| 101 | + // -5 : Filename is too long (max. 255) |
|
| 102 | + // -6 : Not a valid zip file |
|
| 103 | + // -7 : Invalid extracted file size |
|
| 104 | + // -8 : Unable to create directory |
|
| 105 | + // -9 : Invalid archive extension |
|
| 106 | + // -10 : Invalid archive format |
|
| 107 | + // -11 : Unable to delete file (unlink) |
|
| 108 | + // -12 : Unable to rename file (rename) |
|
| 109 | + // -13 : Invalid header checksum |
|
| 110 | + // -14 : Invalid archive size |
|
| 111 | + define( 'PCLZIP_ERR_USER_ABORTED', 2 ); |
|
| 112 | + define( 'PCLZIP_ERR_NO_ERROR', 0 ); |
|
| 113 | + define( 'PCLZIP_ERR_WRITE_OPEN_FAIL', -1 ); |
|
| 114 | + define( 'PCLZIP_ERR_READ_OPEN_FAIL', -2 ); |
|
| 115 | + define( 'PCLZIP_ERR_INVALID_PARAMETER', -3 ); |
|
| 116 | + define( 'PCLZIP_ERR_MISSING_FILE', -4 ); |
|
| 117 | + define( 'PCLZIP_ERR_FILENAME_TOO_LONG', -5 ); |
|
| 118 | + define( 'PCLZIP_ERR_INVALID_ZIP', -6 ); |
|
| 119 | + define( 'PCLZIP_ERR_BAD_EXTRACTED_FILE', -7 ); |
|
| 120 | + define( 'PCLZIP_ERR_DIR_CREATE_FAIL', -8 ); |
|
| 121 | + define( 'PCLZIP_ERR_BAD_EXTENSION', -9 ); |
|
| 122 | + define( 'PCLZIP_ERR_BAD_FORMAT', -10 ); |
|
| 123 | + define( 'PCLZIP_ERR_DELETE_FILE_FAIL', -11 ); |
|
| 124 | + define( 'PCLZIP_ERR_RENAME_FILE_FAIL', -12 ); |
|
| 125 | + define( 'PCLZIP_ERR_BAD_CHECKSUM', -13 ); |
|
| 126 | + define( 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14 ); |
|
| 127 | + define( 'PCLZIP_ERR_MISSING_OPTION_VALUE', -15 ); |
|
| 128 | + define( 'PCLZIP_ERR_INVALID_OPTION_VALUE', -16 ); |
|
| 129 | + define( 'PCLZIP_ERR_ALREADY_A_DIRECTORY', -17 ); |
|
| 130 | + define( 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18 ); |
|
| 131 | + define( 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19 ); |
|
| 132 | + define( 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', -20 ); |
|
| 133 | + define( 'PCLZIP_ERR_DIRECTORY_RESTRICTION', -21 ); |
|
| 134 | + |
|
| 135 | + // ----- Options values |
|
| 136 | + define( 'PCLZIP_OPT_PATH', 77001 ); |
|
| 137 | + define( 'PCLZIP_OPT_ADD_PATH', 77002 ); |
|
| 138 | + define( 'PCLZIP_OPT_REMOVE_PATH', 77003 ); |
|
| 139 | + define( 'PCLZIP_OPT_REMOVE_ALL_PATH', 77004 ); |
|
| 140 | + define( 'PCLZIP_OPT_SET_CHMOD', 77005 ); |
|
| 141 | + define( 'PCLZIP_OPT_EXTRACT_AS_STRING', 77006 ); |
|
| 142 | + define( 'PCLZIP_OPT_NO_COMPRESSION', 77007 ); |
|
| 143 | + define( 'PCLZIP_OPT_BY_NAME', 77008 ); |
|
| 144 | + define( 'PCLZIP_OPT_BY_INDEX', 77009 ); |
|
| 145 | + define( 'PCLZIP_OPT_BY_EREG', 77010 ); |
|
| 146 | + define( 'PCLZIP_OPT_BY_PREG', 77011 ); |
|
| 147 | + define( 'PCLZIP_OPT_COMMENT', 77012 ); |
|
| 148 | + define( 'PCLZIP_OPT_ADD_COMMENT', 77013 ); |
|
| 149 | + define( 'PCLZIP_OPT_PREPEND_COMMENT', 77014 ); |
|
| 150 | + define( 'PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015 ); |
|
| 151 | + define( 'PCLZIP_OPT_REPLACE_NEWER', 77016 ); |
|
| 152 | + define( 'PCLZIP_OPT_STOP_ON_ERROR', 77017 ); |
|
| 153 | + // Having big trouble with crypt. Need to multiply 2 long int |
|
| 154 | + // which is not correctly supported by PHP ... |
|
| 155 | + //define( 'PCLZIP_OPT_CRYPT', 77018 ); |
|
| 156 | + define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 ); |
|
| 157 | + define( 'PCLZIP_OPT_TEMP_FILE_THRESHOLD', 77020 ); |
|
| 158 | + define( 'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD', 77020 ); // alias |
|
| 159 | + define( 'PCLZIP_OPT_TEMP_FILE_ON', 77021 ); |
|
| 160 | + define( 'PCLZIP_OPT_ADD_TEMP_FILE_ON', 77021 ); // alias |
|
| 161 | + define( 'PCLZIP_OPT_TEMP_FILE_OFF', 77022 ); |
|
| 162 | + define( 'PCLZIP_OPT_ADD_TEMP_FILE_OFF', 77022 ); // alias |
|
| 163 | 163 | |
| 164 | - // ----- File description attributes |
|
| 165 | - define( 'PCLZIP_ATT_FILE_NAME', 79001 ); |
|
| 166 | - define( 'PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002 ); |
|
| 167 | - define( 'PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003 ); |
|
| 168 | - define( 'PCLZIP_ATT_FILE_MTIME', 79004 ); |
|
| 169 | - define( 'PCLZIP_ATT_FILE_CONTENT', 79005 ); |
|
| 170 | - define( 'PCLZIP_ATT_FILE_COMMENT', 79006 ); |
|
| 171 | - |
|
| 172 | - // ----- Call backs values |
|
| 173 | - define( 'PCLZIP_CB_PRE_EXTRACT', 78001 ); |
|
| 174 | - define( 'PCLZIP_CB_POST_EXTRACT', 78002 ); |
|
| 175 | - define( 'PCLZIP_CB_PRE_ADD', 78003 ); |
|
| 176 | - define( 'PCLZIP_CB_POST_ADD', 78004 ); |
|
| 177 | - /* For futur use |
|
| 164 | + // ----- File description attributes |
|
| 165 | + define( 'PCLZIP_ATT_FILE_NAME', 79001 ); |
|
| 166 | + define( 'PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002 ); |
|
| 167 | + define( 'PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003 ); |
|
| 168 | + define( 'PCLZIP_ATT_FILE_MTIME', 79004 ); |
|
| 169 | + define( 'PCLZIP_ATT_FILE_CONTENT', 79005 ); |
|
| 170 | + define( 'PCLZIP_ATT_FILE_COMMENT', 79006 ); |
|
| 171 | + |
|
| 172 | + // ----- Call backs values |
|
| 173 | + define( 'PCLZIP_CB_PRE_EXTRACT', 78001 ); |
|
| 174 | + define( 'PCLZIP_CB_POST_EXTRACT', 78002 ); |
|
| 175 | + define( 'PCLZIP_CB_PRE_ADD', 78003 ); |
|
| 176 | + define( 'PCLZIP_CB_POST_ADD', 78004 ); |
|
| 177 | + /* For futur use |
|
| 178 | 178 | define( 'PCLZIP_CB_PRE_LIST', 78005 ); |
| 179 | 179 | define( 'PCLZIP_CB_POST_LIST', 78006 ); |
| 180 | 180 | define( 'PCLZIP_CB_PRE_DELETE', 78007 ); |
| 181 | 181 | define( 'PCLZIP_CB_POST_DELETE', 78008 ); |
| 182 | 182 | */ |
| 183 | 183 | |
| 184 | - // -------------------------------------------------------------------------------- |
|
| 185 | - // Class : PclZip |
|
| 186 | - // Description : |
|
| 187 | - // PclZip is the class that represent a Zip archive. |
|
| 188 | - // The public methods allow the manipulation of the archive. |
|
| 189 | - // Attributes : |
|
| 190 | - // Attributes must not be accessed directly. |
|
| 191 | - // Methods : |
|
| 192 | - // PclZip() : Object creator |
|
| 193 | - // create() : Creates the Zip archive |
|
| 194 | - // listContent() : List the content of the Zip archive |
|
| 195 | - // extract() : Extract the content of the archive |
|
| 196 | - // properties() : List the properties of the archive |
|
| 197 | - // -------------------------------------------------------------------------------- |
|
| 198 | - class PclZip |
|
| 199 | - { |
|
| 184 | + // -------------------------------------------------------------------------------- |
|
| 185 | + // Class : PclZip |
|
| 186 | + // Description : |
|
| 187 | + // PclZip is the class that represent a Zip archive. |
|
| 188 | + // The public methods allow the manipulation of the archive. |
|
| 189 | + // Attributes : |
|
| 190 | + // Attributes must not be accessed directly. |
|
| 191 | + // Methods : |
|
| 192 | + // PclZip() : Object creator |
|
| 193 | + // create() : Creates the Zip archive |
|
| 194 | + // listContent() : List the content of the Zip archive |
|
| 195 | + // extract() : Extract the content of the archive |
|
| 196 | + // properties() : List the properties of the archive |
|
| 197 | + // -------------------------------------------------------------------------------- |
|
| 198 | + class PclZip |
|
| 199 | + { |
|
| 200 | 200 | // ----- Filename of the zip file |
| 201 | 201 | var $zipname = ''; |
| 202 | 202 | |
@@ -212,21 +212,21 @@ discard block |
||
| 212 | 212 | // The class can then disable the magic_quotes and reset it after |
| 213 | 213 | var $magic_quotes_status; |
| 214 | 214 | |
| 215 | - // -------------------------------------------------------------------------------- |
|
| 216 | - // Function : PclZip() |
|
| 217 | - // Description : |
|
| 218 | - // Creates a PclZip object and set the name of the associated Zip archive |
|
| 219 | - // filename. |
|
| 220 | - // Note that no real action is taken, if the archive does not exist it is not |
|
| 221 | - // created. Use create() for that. |
|
| 222 | - // -------------------------------------------------------------------------------- |
|
| 223 | - function PclZip($p_zipname) |
|
| 224 | - { |
|
| 215 | + // -------------------------------------------------------------------------------- |
|
| 216 | + // Function : PclZip() |
|
| 217 | + // Description : |
|
| 218 | + // Creates a PclZip object and set the name of the associated Zip archive |
|
| 219 | + // filename. |
|
| 220 | + // Note that no real action is taken, if the archive does not exist it is not |
|
| 221 | + // created. Use create() for that. |
|
| 222 | + // -------------------------------------------------------------------------------- |
|
| 223 | + function PclZip($p_zipname) |
|
| 224 | + { |
|
| 225 | 225 | |
| 226 | 226 | // ----- Tests the zlib |
| 227 | 227 | if (!function_exists('gzopen')) |
| 228 | 228 | { |
| 229 | - die('Abort '.basename(__FILE__).' : Missing zlib extensions'); |
|
| 229 | + die('Abort '.basename(__FILE__).' : Missing zlib extensions'); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | // ----- Set the attributes |
@@ -236,48 +236,48 @@ discard block |
||
| 236 | 236 | |
| 237 | 237 | // ----- Return |
| 238 | 238 | return; |
| 239 | - } |
|
| 240 | - // -------------------------------------------------------------------------------- |
|
| 241 | - |
|
| 242 | - // -------------------------------------------------------------------------------- |
|
| 243 | - // Function : |
|
| 244 | - // create($p_filelist, $p_add_dir="", $p_remove_dir="") |
|
| 245 | - // create($p_filelist, $p_option, $p_option_value, ...) |
|
| 246 | - // Description : |
|
| 247 | - // This method supports two different synopsis. The first one is historical. |
|
| 248 | - // This method creates a Zip Archive. The Zip file is created in the |
|
| 249 | - // filesystem. The files and directories indicated in $p_filelist |
|
| 250 | - // are added in the archive. See the parameters description for the |
|
| 251 | - // supported format of $p_filelist. |
|
| 252 | - // When a directory is in the list, the directory and its content is added |
|
| 253 | - // in the archive. |
|
| 254 | - // In this synopsis, the function takes an optional variable list of |
|
| 255 | - // options. See bellow the supported options. |
|
| 256 | - // Parameters : |
|
| 257 | - // $p_filelist : An array containing file or directory names, or |
|
| 258 | - // a string containing one filename or one directory name, or |
|
| 259 | - // a string containing a list of filenames and/or directory |
|
| 260 | - // names separated by spaces. |
|
| 261 | - // $p_add_dir : A path to add before the real path of the archived file, |
|
| 262 | - // in order to have it memorized in the archive. |
|
| 263 | - // $p_remove_dir : A path to remove from the real path of the file to archive, |
|
| 264 | - // in order to have a shorter path memorized in the archive. |
|
| 265 | - // When $p_add_dir and $p_remove_dir are set, $p_remove_dir |
|
| 266 | - // is removed first, before $p_add_dir is added. |
|
| 267 | - // Options : |
|
| 268 | - // PCLZIP_OPT_ADD_PATH : |
|
| 269 | - // PCLZIP_OPT_REMOVE_PATH : |
|
| 270 | - // PCLZIP_OPT_REMOVE_ALL_PATH : |
|
| 271 | - // PCLZIP_OPT_COMMENT : |
|
| 272 | - // PCLZIP_CB_PRE_ADD : |
|
| 273 | - // PCLZIP_CB_POST_ADD : |
|
| 274 | - // Return Values : |
|
| 275 | - // 0 on failure, |
|
| 276 | - // The list of the added files, with a status of the add action. |
|
| 277 | - // (see PclZip::listContent() for list entry format) |
|
| 278 | - // -------------------------------------------------------------------------------- |
|
| 279 | - function create($p_filelist) |
|
| 280 | - { |
|
| 239 | + } |
|
| 240 | + // -------------------------------------------------------------------------------- |
|
| 241 | + |
|
| 242 | + // -------------------------------------------------------------------------------- |
|
| 243 | + // Function : |
|
| 244 | + // create($p_filelist, $p_add_dir="", $p_remove_dir="") |
|
| 245 | + // create($p_filelist, $p_option, $p_option_value, ...) |
|
| 246 | + // Description : |
|
| 247 | + // This method supports two different synopsis. The first one is historical. |
|
| 248 | + // This method creates a Zip Archive. The Zip file is created in the |
|
| 249 | + // filesystem. The files and directories indicated in $p_filelist |
|
| 250 | + // are added in the archive. See the parameters description for the |
|
| 251 | + // supported format of $p_filelist. |
|
| 252 | + // When a directory is in the list, the directory and its content is added |
|
| 253 | + // in the archive. |
|
| 254 | + // In this synopsis, the function takes an optional variable list of |
|
| 255 | + // options. See bellow the supported options. |
|
| 256 | + // Parameters : |
|
| 257 | + // $p_filelist : An array containing file or directory names, or |
|
| 258 | + // a string containing one filename or one directory name, or |
|
| 259 | + // a string containing a list of filenames and/or directory |
|
| 260 | + // names separated by spaces. |
|
| 261 | + // $p_add_dir : A path to add before the real path of the archived file, |
|
| 262 | + // in order to have it memorized in the archive. |
|
| 263 | + // $p_remove_dir : A path to remove from the real path of the file to archive, |
|
| 264 | + // in order to have a shorter path memorized in the archive. |
|
| 265 | + // When $p_add_dir and $p_remove_dir are set, $p_remove_dir |
|
| 266 | + // is removed first, before $p_add_dir is added. |
|
| 267 | + // Options : |
|
| 268 | + // PCLZIP_OPT_ADD_PATH : |
|
| 269 | + // PCLZIP_OPT_REMOVE_PATH : |
|
| 270 | + // PCLZIP_OPT_REMOVE_ALL_PATH : |
|
| 271 | + // PCLZIP_OPT_COMMENT : |
|
| 272 | + // PCLZIP_CB_PRE_ADD : |
|
| 273 | + // PCLZIP_CB_POST_ADD : |
|
| 274 | + // Return Values : |
|
| 275 | + // 0 on failure, |
|
| 276 | + // The list of the added files, with a status of the add action. |
|
| 277 | + // (see PclZip::listContent() for list entry format) |
|
| 278 | + // -------------------------------------------------------------------------------- |
|
| 279 | + function create($p_filelist) |
|
| 280 | + { |
|
| 281 | 281 | $v_result=1; |
| 282 | 282 | |
| 283 | 283 | // ----- Reset the error handler |
@@ -292,53 +292,53 @@ discard block |
||
| 292 | 292 | |
| 293 | 293 | // ----- Look for arguments |
| 294 | 294 | if ($v_size > 1) { |
| 295 | - // ----- Get the arguments |
|
| 296 | - $v_arg_list = func_get_args(); |
|
| 295 | + // ----- Get the arguments |
|
| 296 | + $v_arg_list = func_get_args(); |
|
| 297 | 297 | |
| 298 | - // ----- Remove from the options list the first argument |
|
| 299 | - array_shift($v_arg_list); |
|
| 300 | - $v_size--; |
|
| 298 | + // ----- Remove from the options list the first argument |
|
| 299 | + array_shift($v_arg_list); |
|
| 300 | + $v_size--; |
|
| 301 | 301 | |
| 302 | - // ----- Look for first arg |
|
| 303 | - if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
|
| 302 | + // ----- Look for first arg |
|
| 303 | + if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
|
| 304 | 304 | |
| 305 | 305 | // ----- Parse the options |
| 306 | 306 | $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
| 307 | 307 | array (PCLZIP_OPT_REMOVE_PATH => 'optional', |
| 308 | - PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
|
| 309 | - PCLZIP_OPT_ADD_PATH => 'optional', |
|
| 310 | - PCLZIP_CB_PRE_ADD => 'optional', |
|
| 311 | - PCLZIP_CB_POST_ADD => 'optional', |
|
| 312 | - PCLZIP_OPT_NO_COMPRESSION => 'optional', |
|
| 313 | - PCLZIP_OPT_COMMENT => 'optional', |
|
| 314 | - PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', |
|
| 315 | - PCLZIP_OPT_TEMP_FILE_ON => 'optional', |
|
| 316 | - PCLZIP_OPT_TEMP_FILE_OFF => 'optional' |
|
| 317 | - //, PCLZIP_OPT_CRYPT => 'optional' |
|
| 318 | - )); |
|
| 308 | + PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
|
| 309 | + PCLZIP_OPT_ADD_PATH => 'optional', |
|
| 310 | + PCLZIP_CB_PRE_ADD => 'optional', |
|
| 311 | + PCLZIP_CB_POST_ADD => 'optional', |
|
| 312 | + PCLZIP_OPT_NO_COMPRESSION => 'optional', |
|
| 313 | + PCLZIP_OPT_COMMENT => 'optional', |
|
| 314 | + PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', |
|
| 315 | + PCLZIP_OPT_TEMP_FILE_ON => 'optional', |
|
| 316 | + PCLZIP_OPT_TEMP_FILE_OFF => 'optional' |
|
| 317 | + //, PCLZIP_OPT_CRYPT => 'optional' |
|
| 318 | + )); |
|
| 319 | 319 | if ($v_result != 1) { |
| 320 | - return 0; |
|
| 320 | + return 0; |
|
| 321 | + } |
|
| 321 | 322 | } |
| 322 | - } |
|
| 323 | 323 | |
| 324 | - // ----- Look for 2 args |
|
| 325 | - // Here we need to support the first historic synopsis of the |
|
| 326 | - // method. |
|
| 327 | - else { |
|
| 324 | + // ----- Look for 2 args |
|
| 325 | + // Here we need to support the first historic synopsis of the |
|
| 326 | + // method. |
|
| 327 | + else { |
|
| 328 | 328 | |
| 329 | 329 | // ----- Get the first argument |
| 330 | 330 | $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0]; |
| 331 | 331 | |
| 332 | 332 | // ----- Look for the optional second argument |
| 333 | 333 | if ($v_size == 2) { |
| 334 | - $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; |
|
| 334 | + $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; |
|
| 335 | 335 | } |
| 336 | 336 | else if ($v_size > 2) { |
| 337 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, |
|
| 338 | - "Invalid number / type of arguments"); |
|
| 339 | - return 0; |
|
| 337 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, |
|
| 338 | + "Invalid number / type of arguments"); |
|
| 339 | + return 0; |
|
| 340 | + } |
|
| 340 | 341 | } |
| 341 | - } |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | // ----- Look for default option values |
@@ -353,114 +353,114 @@ discard block |
||
| 353 | 353 | // ----- Look if the $p_filelist is really an array |
| 354 | 354 | if (is_array($p_filelist)) { |
| 355 | 355 | |
| 356 | - // ----- Look if the first element is also an array |
|
| 357 | - // This will mean that this is a file description entry |
|
| 358 | - if (isset($p_filelist[0]) && is_array($p_filelist[0])) { |
|
| 356 | + // ----- Look if the first element is also an array |
|
| 357 | + // This will mean that this is a file description entry |
|
| 358 | + if (isset($p_filelist[0]) && is_array($p_filelist[0])) { |
|
| 359 | 359 | $v_att_list = $p_filelist; |
| 360 | - } |
|
| 360 | + } |
|
| 361 | 361 | |
| 362 | - // ----- The list is a list of string names |
|
| 363 | - else { |
|
| 362 | + // ----- The list is a list of string names |
|
| 363 | + else { |
|
| 364 | 364 | $v_string_list = $p_filelist; |
| 365 | - } |
|
| 365 | + } |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | // ----- Look if the $p_filelist is a string |
| 369 | 369 | else if (is_string($p_filelist)) { |
| 370 | - // ----- Create a list from the string |
|
| 371 | - $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist); |
|
| 370 | + // ----- Create a list from the string |
|
| 371 | + $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | // ----- Invalid variable type for $p_filelist |
| 375 | 375 | else { |
| 376 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist"); |
|
| 377 | - return 0; |
|
| 376 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist"); |
|
| 377 | + return 0; |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | // ----- Reformat the string list |
| 381 | 381 | if (sizeof($v_string_list) != 0) { |
| 382 | - foreach ($v_string_list as $v_string) { |
|
| 382 | + foreach ($v_string_list as $v_string) { |
|
| 383 | 383 | if ($v_string != '') { |
| 384 | - $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; |
|
| 384 | + $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; |
|
| 385 | 385 | } |
| 386 | 386 | else { |
| 387 | 387 | } |
| 388 | - } |
|
| 388 | + } |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | // ----- For each file in the list check the attributes |
| 392 | 392 | $v_supported_attributes |
| 393 | 393 | = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' |
| 394 | - ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' |
|
| 395 | - ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' |
|
| 396 | - ,PCLZIP_ATT_FILE_MTIME => 'optional' |
|
| 397 | - ,PCLZIP_ATT_FILE_CONTENT => 'optional' |
|
| 398 | - ,PCLZIP_ATT_FILE_COMMENT => 'optional' |
|
| 399 | - ); |
|
| 394 | + ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' |
|
| 395 | + ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' |
|
| 396 | + ,PCLZIP_ATT_FILE_MTIME => 'optional' |
|
| 397 | + ,PCLZIP_ATT_FILE_CONTENT => 'optional' |
|
| 398 | + ,PCLZIP_ATT_FILE_COMMENT => 'optional' |
|
| 399 | + ); |
|
| 400 | 400 | foreach ($v_att_list as $v_entry) { |
| 401 | - $v_result = $this->privFileDescrParseAtt($v_entry, |
|
| 402 | - $v_filedescr_list[], |
|
| 403 | - $v_options, |
|
| 404 | - $v_supported_attributes); |
|
| 405 | - if ($v_result != 1) { |
|
| 401 | + $v_result = $this->privFileDescrParseAtt($v_entry, |
|
| 402 | + $v_filedescr_list[], |
|
| 403 | + $v_options, |
|
| 404 | + $v_supported_attributes); |
|
| 405 | + if ($v_result != 1) { |
|
| 406 | 406 | return 0; |
| 407 | - } |
|
| 407 | + } |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | // ----- Expand the filelist (expand directories) |
| 411 | 411 | $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options); |
| 412 | 412 | if ($v_result != 1) { |
| 413 | - return 0; |
|
| 413 | + return 0; |
|
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | // ----- Call the create fct |
| 417 | 417 | $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options); |
| 418 | 418 | if ($v_result != 1) { |
| 419 | - return 0; |
|
| 419 | + return 0; |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | // ----- Return |
| 423 | 423 | return $p_result_list; |
| 424 | - } |
|
| 425 | - // -------------------------------------------------------------------------------- |
|
| 426 | - |
|
| 427 | - // -------------------------------------------------------------------------------- |
|
| 428 | - // Function : |
|
| 429 | - // add($p_filelist, $p_add_dir="", $p_remove_dir="") |
|
| 430 | - // add($p_filelist, $p_option, $p_option_value, ...) |
|
| 431 | - // Description : |
|
| 432 | - // This method supports two synopsis. The first one is historical. |
|
| 433 | - // This methods add the list of files in an existing archive. |
|
| 434 | - // If a file with the same name already exists, it is added at the end of the |
|
| 435 | - // archive, the first one is still present. |
|
| 436 | - // If the archive does not exist, it is created. |
|
| 437 | - // Parameters : |
|
| 438 | - // $p_filelist : An array containing file or directory names, or |
|
| 439 | - // a string containing one filename or one directory name, or |
|
| 440 | - // a string containing a list of filenames and/or directory |
|
| 441 | - // names separated by spaces. |
|
| 442 | - // $p_add_dir : A path to add before the real path of the archived file, |
|
| 443 | - // in order to have it memorized in the archive. |
|
| 444 | - // $p_remove_dir : A path to remove from the real path of the file to archive, |
|
| 445 | - // in order to have a shorter path memorized in the archive. |
|
| 446 | - // When $p_add_dir and $p_remove_dir are set, $p_remove_dir |
|
| 447 | - // is removed first, before $p_add_dir is added. |
|
| 448 | - // Options : |
|
| 449 | - // PCLZIP_OPT_ADD_PATH : |
|
| 450 | - // PCLZIP_OPT_REMOVE_PATH : |
|
| 451 | - // PCLZIP_OPT_REMOVE_ALL_PATH : |
|
| 452 | - // PCLZIP_OPT_COMMENT : |
|
| 453 | - // PCLZIP_OPT_ADD_COMMENT : |
|
| 454 | - // PCLZIP_OPT_PREPEND_COMMENT : |
|
| 455 | - // PCLZIP_CB_PRE_ADD : |
|
| 456 | - // PCLZIP_CB_POST_ADD : |
|
| 457 | - // Return Values : |
|
| 458 | - // 0 on failure, |
|
| 459 | - // The list of the added files, with a status of the add action. |
|
| 460 | - // (see PclZip::listContent() for list entry format) |
|
| 461 | - // -------------------------------------------------------------------------------- |
|
| 462 | - function add($p_filelist) |
|
| 463 | - { |
|
| 424 | + } |
|
| 425 | + // -------------------------------------------------------------------------------- |
|
| 426 | + |
|
| 427 | + // -------------------------------------------------------------------------------- |
|
| 428 | + // Function : |
|
| 429 | + // add($p_filelist, $p_add_dir="", $p_remove_dir="") |
|
| 430 | + // add($p_filelist, $p_option, $p_option_value, ...) |
|
| 431 | + // Description : |
|
| 432 | + // This method supports two synopsis. The first one is historical. |
|
| 433 | + // This methods add the list of files in an existing archive. |
|
| 434 | + // If a file with the same name already exists, it is added at the end of the |
|
| 435 | + // archive, the first one is still present. |
|
| 436 | + // If the archive does not exist, it is created. |
|
| 437 | + // Parameters : |
|
| 438 | + // $p_filelist : An array containing file or directory names, or |
|
| 439 | + // a string containing one filename or one directory name, or |
|
| 440 | + // a string containing a list of filenames and/or directory |
|
| 441 | + // names separated by spaces. |
|
| 442 | + // $p_add_dir : A path to add before the real path of the archived file, |
|
| 443 | + // in order to have it memorized in the archive. |
|
| 444 | + // $p_remove_dir : A path to remove from the real path of the file to archive, |
|
| 445 | + // in order to have a shorter path memorized in the archive. |
|
| 446 | + // When $p_add_dir and $p_remove_dir are set, $p_remove_dir |
|
| 447 | + // is removed first, before $p_add_dir is added. |
|
| 448 | + // Options : |
|
| 449 | + // PCLZIP_OPT_ADD_PATH : |
|
| 450 | + // PCLZIP_OPT_REMOVE_PATH : |
|
| 451 | + // PCLZIP_OPT_REMOVE_ALL_PATH : |
|
| 452 | + // PCLZIP_OPT_COMMENT : |
|
| 453 | + // PCLZIP_OPT_ADD_COMMENT : |
|
| 454 | + // PCLZIP_OPT_PREPEND_COMMENT : |
|
| 455 | + // PCLZIP_CB_PRE_ADD : |
|
| 456 | + // PCLZIP_CB_POST_ADD : |
|
| 457 | + // Return Values : |
|
| 458 | + // 0 on failure, |
|
| 459 | + // The list of the added files, with a status of the add action. |
|
| 460 | + // (see PclZip::listContent() for list entry format) |
|
| 461 | + // -------------------------------------------------------------------------------- |
|
| 462 | + function add($p_filelist) |
|
| 463 | + { |
|
| 464 | 464 | $v_result=1; |
| 465 | 465 | |
| 466 | 466 | // ----- Reset the error handler |
@@ -475,57 +475,57 @@ discard block |
||
| 475 | 475 | |
| 476 | 476 | // ----- Look for arguments |
| 477 | 477 | if ($v_size > 1) { |
| 478 | - // ----- Get the arguments |
|
| 479 | - $v_arg_list = func_get_args(); |
|
| 478 | + // ----- Get the arguments |
|
| 479 | + $v_arg_list = func_get_args(); |
|
| 480 | 480 | |
| 481 | - // ----- Remove form the options list the first argument |
|
| 482 | - array_shift($v_arg_list); |
|
| 483 | - $v_size--; |
|
| 481 | + // ----- Remove form the options list the first argument |
|
| 482 | + array_shift($v_arg_list); |
|
| 483 | + $v_size--; |
|
| 484 | 484 | |
| 485 | - // ----- Look for first arg |
|
| 486 | - if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
|
| 485 | + // ----- Look for first arg |
|
| 486 | + if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
|
| 487 | 487 | |
| 488 | 488 | // ----- Parse the options |
| 489 | 489 | $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
| 490 | 490 | array (PCLZIP_OPT_REMOVE_PATH => 'optional', |
| 491 | - PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
|
| 492 | - PCLZIP_OPT_ADD_PATH => 'optional', |
|
| 493 | - PCLZIP_CB_PRE_ADD => 'optional', |
|
| 494 | - PCLZIP_CB_POST_ADD => 'optional', |
|
| 495 | - PCLZIP_OPT_NO_COMPRESSION => 'optional', |
|
| 496 | - PCLZIP_OPT_COMMENT => 'optional', |
|
| 497 | - PCLZIP_OPT_ADD_COMMENT => 'optional', |
|
| 498 | - PCLZIP_OPT_PREPEND_COMMENT => 'optional', |
|
| 499 | - PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', |
|
| 500 | - PCLZIP_OPT_TEMP_FILE_ON => 'optional', |
|
| 501 | - PCLZIP_OPT_TEMP_FILE_OFF => 'optional' |
|
| 502 | - //, PCLZIP_OPT_CRYPT => 'optional' |
|
| 503 | - )); |
|
| 491 | + PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
|
| 492 | + PCLZIP_OPT_ADD_PATH => 'optional', |
|
| 493 | + PCLZIP_CB_PRE_ADD => 'optional', |
|
| 494 | + PCLZIP_CB_POST_ADD => 'optional', |
|
| 495 | + PCLZIP_OPT_NO_COMPRESSION => 'optional', |
|
| 496 | + PCLZIP_OPT_COMMENT => 'optional', |
|
| 497 | + PCLZIP_OPT_ADD_COMMENT => 'optional', |
|
| 498 | + PCLZIP_OPT_PREPEND_COMMENT => 'optional', |
|
| 499 | + PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', |
|
| 500 | + PCLZIP_OPT_TEMP_FILE_ON => 'optional', |
|
| 501 | + PCLZIP_OPT_TEMP_FILE_OFF => 'optional' |
|
| 502 | + //, PCLZIP_OPT_CRYPT => 'optional' |
|
| 503 | + )); |
|
| 504 | 504 | if ($v_result != 1) { |
| 505 | - return 0; |
|
| 505 | + return 0; |
|
| 506 | + } |
|
| 506 | 507 | } |
| 507 | - } |
|
| 508 | 508 | |
| 509 | - // ----- Look for 2 args |
|
| 510 | - // Here we need to support the first historic synopsis of the |
|
| 511 | - // method. |
|
| 512 | - else { |
|
| 509 | + // ----- Look for 2 args |
|
| 510 | + // Here we need to support the first historic synopsis of the |
|
| 511 | + // method. |
|
| 512 | + else { |
|
| 513 | 513 | |
| 514 | 514 | // ----- Get the first argument |
| 515 | 515 | $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0]; |
| 516 | 516 | |
| 517 | 517 | // ----- Look for the optional second argument |
| 518 | 518 | if ($v_size == 2) { |
| 519 | - $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; |
|
| 519 | + $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; |
|
| 520 | 520 | } |
| 521 | 521 | else if ($v_size > 2) { |
| 522 | - // ----- Error log |
|
| 523 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); |
|
| 522 | + // ----- Error log |
|
| 523 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); |
|
| 524 | 524 | |
| 525 | - // ----- Return |
|
| 526 | - return 0; |
|
| 525 | + // ----- Return |
|
| 526 | + return 0; |
|
| 527 | + } |
|
| 527 | 528 | } |
| 528 | - } |
|
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | // ----- Look for default option values |
@@ -540,116 +540,116 @@ discard block |
||
| 540 | 540 | // ----- Look if the $p_filelist is really an array |
| 541 | 541 | if (is_array($p_filelist)) { |
| 542 | 542 | |
| 543 | - // ----- Look if the first element is also an array |
|
| 544 | - // This will mean that this is a file description entry |
|
| 545 | - if (isset($p_filelist[0]) && is_array($p_filelist[0])) { |
|
| 543 | + // ----- Look if the first element is also an array |
|
| 544 | + // This will mean that this is a file description entry |
|
| 545 | + if (isset($p_filelist[0]) && is_array($p_filelist[0])) { |
|
| 546 | 546 | $v_att_list = $p_filelist; |
| 547 | - } |
|
| 547 | + } |
|
| 548 | 548 | |
| 549 | - // ----- The list is a list of string names |
|
| 550 | - else { |
|
| 549 | + // ----- The list is a list of string names |
|
| 550 | + else { |
|
| 551 | 551 | $v_string_list = $p_filelist; |
| 552 | - } |
|
| 552 | + } |
|
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | // ----- Look if the $p_filelist is a string |
| 556 | 556 | else if (is_string($p_filelist)) { |
| 557 | - // ----- Create a list from the string |
|
| 558 | - $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist); |
|
| 557 | + // ----- Create a list from the string |
|
| 558 | + $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist); |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | // ----- Invalid variable type for $p_filelist |
| 562 | 562 | else { |
| 563 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist"); |
|
| 564 | - return 0; |
|
| 563 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist"); |
|
| 564 | + return 0; |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | // ----- Reformat the string list |
| 568 | 568 | if (sizeof($v_string_list) != 0) { |
| 569 | - foreach ($v_string_list as $v_string) { |
|
| 569 | + foreach ($v_string_list as $v_string) { |
|
| 570 | 570 | $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; |
| 571 | - } |
|
| 571 | + } |
|
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | // ----- For each file in the list check the attributes |
| 575 | 575 | $v_supported_attributes |
| 576 | 576 | = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' |
| 577 | - ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' |
|
| 578 | - ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' |
|
| 579 | - ,PCLZIP_ATT_FILE_MTIME => 'optional' |
|
| 580 | - ,PCLZIP_ATT_FILE_CONTENT => 'optional' |
|
| 581 | - ,PCLZIP_ATT_FILE_COMMENT => 'optional' |
|
| 582 | - ); |
|
| 577 | + ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' |
|
| 578 | + ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' |
|
| 579 | + ,PCLZIP_ATT_FILE_MTIME => 'optional' |
|
| 580 | + ,PCLZIP_ATT_FILE_CONTENT => 'optional' |
|
| 581 | + ,PCLZIP_ATT_FILE_COMMENT => 'optional' |
|
| 582 | + ); |
|
| 583 | 583 | foreach ($v_att_list as $v_entry) { |
| 584 | - $v_result = $this->privFileDescrParseAtt($v_entry, |
|
| 585 | - $v_filedescr_list[], |
|
| 586 | - $v_options, |
|
| 587 | - $v_supported_attributes); |
|
| 588 | - if ($v_result != 1) { |
|
| 584 | + $v_result = $this->privFileDescrParseAtt($v_entry, |
|
| 585 | + $v_filedescr_list[], |
|
| 586 | + $v_options, |
|
| 587 | + $v_supported_attributes); |
|
| 588 | + if ($v_result != 1) { |
|
| 589 | 589 | return 0; |
| 590 | - } |
|
| 590 | + } |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | // ----- Expand the filelist (expand directories) |
| 594 | 594 | $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options); |
| 595 | 595 | if ($v_result != 1) { |
| 596 | - return 0; |
|
| 596 | + return 0; |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | // ----- Call the create fct |
| 600 | 600 | $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options); |
| 601 | 601 | if ($v_result != 1) { |
| 602 | - return 0; |
|
| 602 | + return 0; |
|
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | // ----- Return |
| 606 | 606 | return $p_result_list; |
| 607 | - } |
|
| 608 | - // -------------------------------------------------------------------------------- |
|
| 609 | - |
|
| 610 | - // -------------------------------------------------------------------------------- |
|
| 611 | - // Function : listContent() |
|
| 612 | - // Description : |
|
| 613 | - // This public method, gives the list of the files and directories, with their |
|
| 614 | - // properties. |
|
| 615 | - // The properties of each entries in the list are (used also in other functions) : |
|
| 616 | - // filename : Name of the file. For a create or add action it is the filename |
|
| 617 | - // given by the user. For an extract function it is the filename |
|
| 618 | - // of the extracted file. |
|
| 619 | - // stored_filename : Name of the file / directory stored in the archive. |
|
| 620 | - // size : Size of the stored file. |
|
| 621 | - // compressed_size : Size of the file's data compressed in the archive |
|
| 622 | - // (without the headers overhead) |
|
| 623 | - // mtime : Last known modification date of the file (UNIX timestamp) |
|
| 624 | - // comment : Comment associated with the file |
|
| 625 | - // folder : true | false |
|
| 626 | - // index : index of the file in the archive |
|
| 627 | - // status : status of the action (depending of the action) : |
|
| 628 | - // Values are : |
|
| 629 | - // ok : OK ! |
|
| 630 | - // filtered : the file / dir is not extracted (filtered by user) |
|
| 631 | - // already_a_directory : the file can not be extracted because a |
|
| 632 | - // directory with the same name already exists |
|
| 633 | - // write_protected : the file can not be extracted because a file |
|
| 634 | - // with the same name already exists and is |
|
| 635 | - // write protected |
|
| 636 | - // newer_exist : the file was not extracted because a newer file exists |
|
| 637 | - // path_creation_fail : the file is not extracted because the folder |
|
| 638 | - // does not exist and can not be created |
|
| 639 | - // write_error : the file was not extracted because there was a |
|
| 640 | - // error while writing the file |
|
| 641 | - // read_error : the file was not extracted because there was a error |
|
| 642 | - // while reading the file |
|
| 643 | - // invalid_header : the file was not extracted because of an archive |
|
| 644 | - // format error (bad file header) |
|
| 645 | - // Note that each time a method can continue operating when there |
|
| 646 | - // is an action error on a file, the error is only logged in the file status. |
|
| 647 | - // Return Values : |
|
| 648 | - // 0 on an unrecoverable failure, |
|
| 649 | - // The list of the files in the archive. |
|
| 650 | - // -------------------------------------------------------------------------------- |
|
| 651 | - function listContent() |
|
| 652 | - { |
|
| 607 | + } |
|
| 608 | + // -------------------------------------------------------------------------------- |
|
| 609 | + |
|
| 610 | + // -------------------------------------------------------------------------------- |
|
| 611 | + // Function : listContent() |
|
| 612 | + // Description : |
|
| 613 | + // This public method, gives the list of the files and directories, with their |
|
| 614 | + // properties. |
|
| 615 | + // The properties of each entries in the list are (used also in other functions) : |
|
| 616 | + // filename : Name of the file. For a create or add action it is the filename |
|
| 617 | + // given by the user. For an extract function it is the filename |
|
| 618 | + // of the extracted file. |
|
| 619 | + // stored_filename : Name of the file / directory stored in the archive. |
|
| 620 | + // size : Size of the stored file. |
|
| 621 | + // compressed_size : Size of the file's data compressed in the archive |
|
| 622 | + // (without the headers overhead) |
|
| 623 | + // mtime : Last known modification date of the file (UNIX timestamp) |
|
| 624 | + // comment : Comment associated with the file |
|
| 625 | + // folder : true | false |
|
| 626 | + // index : index of the file in the archive |
|
| 627 | + // status : status of the action (depending of the action) : |
|
| 628 | + // Values are : |
|
| 629 | + // ok : OK ! |
|
| 630 | + // filtered : the file / dir is not extracted (filtered by user) |
|
| 631 | + // already_a_directory : the file can not be extracted because a |
|
| 632 | + // directory with the same name already exists |
|
| 633 | + // write_protected : the file can not be extracted because a file |
|
| 634 | + // with the same name already exists and is |
|
| 635 | + // write protected |
|
| 636 | + // newer_exist : the file was not extracted because a newer file exists |
|
| 637 | + // path_creation_fail : the file is not extracted because the folder |
|
| 638 | + // does not exist and can not be created |
|
| 639 | + // write_error : the file was not extracted because there was a |
|
| 640 | + // error while writing the file |
|
| 641 | + // read_error : the file was not extracted because there was a error |
|
| 642 | + // while reading the file |
|
| 643 | + // invalid_header : the file was not extracted because of an archive |
|
| 644 | + // format error (bad file header) |
|
| 645 | + // Note that each time a method can continue operating when there |
|
| 646 | + // is an action error on a file, the error is only logged in the file status. |
|
| 647 | + // Return Values : |
|
| 648 | + // 0 on an unrecoverable failure, |
|
| 649 | + // The list of the files in the archive. |
|
| 650 | + // -------------------------------------------------------------------------------- |
|
| 651 | + function listContent() |
|
| 652 | + { |
|
| 653 | 653 | $v_result=1; |
| 654 | 654 | |
| 655 | 655 | // ----- Reset the error handler |
@@ -657,56 +657,56 @@ discard block |
||
| 657 | 657 | |
| 658 | 658 | // ----- Check archive |
| 659 | 659 | if (!$this->privCheckFormat()) { |
| 660 | - return(0); |
|
| 660 | + return(0); |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | // ----- Call the extracting fct |
| 664 | 664 | $p_list = array(); |
| 665 | 665 | if (($v_result = $this->privList($p_list)) != 1) |
| 666 | 666 | { |
| 667 | - unset($p_list); |
|
| 668 | - return(0); |
|
| 667 | + unset($p_list); |
|
| 668 | + return(0); |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | // ----- Return |
| 672 | 672 | return $p_list; |
| 673 | - } |
|
| 674 | - // -------------------------------------------------------------------------------- |
|
| 675 | - |
|
| 676 | - // -------------------------------------------------------------------------------- |
|
| 677 | - // Function : |
|
| 678 | - // extract($p_path="./", $p_remove_path="") |
|
| 679 | - // extract([$p_option, $p_option_value, ...]) |
|
| 680 | - // Description : |
|
| 681 | - // This method supports two synopsis. The first one is historical. |
|
| 682 | - // This method extract all the files / directories from the archive to the |
|
| 683 | - // folder indicated in $p_path. |
|
| 684 | - // If you want to ignore the 'root' part of path of the memorized files |
|
| 685 | - // you can indicate this in the optional $p_remove_path parameter. |
|
| 686 | - // By default, if a newer file with the same name already exists, the |
|
| 687 | - // file is not extracted. |
|
| 688 | - // |
|
| 689 | - // If both PCLZIP_OPT_PATH and PCLZIP_OPT_ADD_PATH aoptions |
|
| 690 | - // are used, the path indicated in PCLZIP_OPT_ADD_PATH is append |
|
| 691 | - // at the end of the path value of PCLZIP_OPT_PATH. |
|
| 692 | - // Parameters : |
|
| 693 | - // $p_path : Path where the files and directories are to be extracted |
|
| 694 | - // $p_remove_path : First part ('root' part) of the memorized path |
|
| 695 | - // (if any similar) to remove while extracting. |
|
| 696 | - // Options : |
|
| 697 | - // PCLZIP_OPT_PATH : |
|
| 698 | - // PCLZIP_OPT_ADD_PATH : |
|
| 699 | - // PCLZIP_OPT_REMOVE_PATH : |
|
| 700 | - // PCLZIP_OPT_REMOVE_ALL_PATH : |
|
| 701 | - // PCLZIP_CB_PRE_EXTRACT : |
|
| 702 | - // PCLZIP_CB_POST_EXTRACT : |
|
| 703 | - // Return Values : |
|
| 704 | - // 0 or a negative value on failure, |
|
| 705 | - // The list of the extracted files, with a status of the action. |
|
| 706 | - // (see PclZip::listContent() for list entry format) |
|
| 707 | - // -------------------------------------------------------------------------------- |
|
| 708 | - function extract() |
|
| 709 | - { |
|
| 673 | + } |
|
| 674 | + // -------------------------------------------------------------------------------- |
|
| 675 | + |
|
| 676 | + // -------------------------------------------------------------------------------- |
|
| 677 | + // Function : |
|
| 678 | + // extract($p_path="./", $p_remove_path="") |
|
| 679 | + // extract([$p_option, $p_option_value, ...]) |
|
| 680 | + // Description : |
|
| 681 | + // This method supports two synopsis. The first one is historical. |
|
| 682 | + // This method extract all the files / directories from the archive to the |
|
| 683 | + // folder indicated in $p_path. |
|
| 684 | + // If you want to ignore the 'root' part of path of the memorized files |
|
| 685 | + // you can indicate this in the optional $p_remove_path parameter. |
|
| 686 | + // By default, if a newer file with the same name already exists, the |
|
| 687 | + // file is not extracted. |
|
| 688 | + // |
|
| 689 | + // If both PCLZIP_OPT_PATH and PCLZIP_OPT_ADD_PATH aoptions |
|
| 690 | + // are used, the path indicated in PCLZIP_OPT_ADD_PATH is append |
|
| 691 | + // at the end of the path value of PCLZIP_OPT_PATH. |
|
| 692 | + // Parameters : |
|
| 693 | + // $p_path : Path where the files and directories are to be extracted |
|
| 694 | + // $p_remove_path : First part ('root' part) of the memorized path |
|
| 695 | + // (if any similar) to remove while extracting. |
|
| 696 | + // Options : |
|
| 697 | + // PCLZIP_OPT_PATH : |
|
| 698 | + // PCLZIP_OPT_ADD_PATH : |
|
| 699 | + // PCLZIP_OPT_REMOVE_PATH : |
|
| 700 | + // PCLZIP_OPT_REMOVE_ALL_PATH : |
|
| 701 | + // PCLZIP_CB_PRE_EXTRACT : |
|
| 702 | + // PCLZIP_CB_POST_EXTRACT : |
|
| 703 | + // Return Values : |
|
| 704 | + // 0 or a negative value on failure, |
|
| 705 | + // The list of the extracted files, with a status of the action. |
|
| 706 | + // (see PclZip::listContent() for list entry format) |
|
| 707 | + // -------------------------------------------------------------------------------- |
|
| 708 | + function extract() |
|
| 709 | + { |
|
| 710 | 710 | $v_result=1; |
| 711 | 711 | |
| 712 | 712 | // ----- Reset the error handler |
@@ -714,7 +714,7 @@ discard block |
||
| 714 | 714 | |
| 715 | 715 | // ----- Check archive |
| 716 | 716 | if (!$this->privCheckFormat()) { |
| 717 | - return(0); |
|
| 717 | + return(0); |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | // ----- Set default values |
@@ -732,77 +732,77 @@ discard block |
||
| 732 | 732 | |
| 733 | 733 | // ----- Look for arguments |
| 734 | 734 | if ($v_size > 0) { |
| 735 | - // ----- Get the arguments |
|
| 736 | - $v_arg_list = func_get_args(); |
|
| 735 | + // ----- Get the arguments |
|
| 736 | + $v_arg_list = func_get_args(); |
|
| 737 | 737 | |
| 738 | - // ----- Look for first arg |
|
| 739 | - if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
|
| 738 | + // ----- Look for first arg |
|
| 739 | + if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
|
| 740 | 740 | |
| 741 | 741 | // ----- Parse the options |
| 742 | 742 | $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
| 743 | 743 | array (PCLZIP_OPT_PATH => 'optional', |
| 744 | - PCLZIP_OPT_REMOVE_PATH => 'optional', |
|
| 745 | - PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
|
| 746 | - PCLZIP_OPT_ADD_PATH => 'optional', |
|
| 747 | - PCLZIP_CB_PRE_EXTRACT => 'optional', |
|
| 748 | - PCLZIP_CB_POST_EXTRACT => 'optional', |
|
| 749 | - PCLZIP_OPT_SET_CHMOD => 'optional', |
|
| 750 | - PCLZIP_OPT_BY_NAME => 'optional', |
|
| 751 | - PCLZIP_OPT_BY_EREG => 'optional', |
|
| 752 | - PCLZIP_OPT_BY_PREG => 'optional', |
|
| 753 | - PCLZIP_OPT_BY_INDEX => 'optional', |
|
| 754 | - PCLZIP_OPT_EXTRACT_AS_STRING => 'optional', |
|
| 755 | - PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional', |
|
| 756 | - PCLZIP_OPT_REPLACE_NEWER => 'optional' |
|
| 757 | - ,PCLZIP_OPT_STOP_ON_ERROR => 'optional' |
|
| 758 | - ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional', |
|
| 759 | - PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', |
|
| 760 | - PCLZIP_OPT_TEMP_FILE_ON => 'optional', |
|
| 761 | - PCLZIP_OPT_TEMP_FILE_OFF => 'optional' |
|
| 762 | - )); |
|
| 744 | + PCLZIP_OPT_REMOVE_PATH => 'optional', |
|
| 745 | + PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
|
| 746 | + PCLZIP_OPT_ADD_PATH => 'optional', |
|
| 747 | + PCLZIP_CB_PRE_EXTRACT => 'optional', |
|
| 748 | + PCLZIP_CB_POST_EXTRACT => 'optional', |
|
| 749 | + PCLZIP_OPT_SET_CHMOD => 'optional', |
|
| 750 | + PCLZIP_OPT_BY_NAME => 'optional', |
|
| 751 | + PCLZIP_OPT_BY_EREG => 'optional', |
|
| 752 | + PCLZIP_OPT_BY_PREG => 'optional', |
|
| 753 | + PCLZIP_OPT_BY_INDEX => 'optional', |
|
| 754 | + PCLZIP_OPT_EXTRACT_AS_STRING => 'optional', |
|
| 755 | + PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional', |
|
| 756 | + PCLZIP_OPT_REPLACE_NEWER => 'optional' |
|
| 757 | + ,PCLZIP_OPT_STOP_ON_ERROR => 'optional' |
|
| 758 | + ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional', |
|
| 759 | + PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', |
|
| 760 | + PCLZIP_OPT_TEMP_FILE_ON => 'optional', |
|
| 761 | + PCLZIP_OPT_TEMP_FILE_OFF => 'optional' |
|
| 762 | + )); |
|
| 763 | 763 | if ($v_result != 1) { |
| 764 | - return 0; |
|
| 764 | + return 0; |
|
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | // ----- Set the arguments |
| 768 | 768 | if (isset($v_options[PCLZIP_OPT_PATH])) { |
| 769 | - $v_path = $v_options[PCLZIP_OPT_PATH]; |
|
| 769 | + $v_path = $v_options[PCLZIP_OPT_PATH]; |
|
| 770 | 770 | } |
| 771 | 771 | if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) { |
| 772 | - $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH]; |
|
| 772 | + $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH]; |
|
| 773 | 773 | } |
| 774 | 774 | if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
| 775 | - $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH]; |
|
| 775 | + $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH]; |
|
| 776 | 776 | } |
| 777 | 777 | if (isset($v_options[PCLZIP_OPT_ADD_PATH])) { |
| 778 | - // ----- Check for '/' in last path char |
|
| 779 | - if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) { |
|
| 778 | + // ----- Check for '/' in last path char |
|
| 779 | + if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) { |
|
| 780 | 780 | $v_path .= '/'; |
| 781 | - } |
|
| 782 | - $v_path .= $v_options[PCLZIP_OPT_ADD_PATH]; |
|
| 781 | + } |
|
| 782 | + $v_path .= $v_options[PCLZIP_OPT_ADD_PATH]; |
|
| 783 | + } |
|
| 783 | 784 | } |
| 784 | - } |
|
| 785 | 785 | |
| 786 | - // ----- Look for 2 args |
|
| 787 | - // Here we need to support the first historic synopsis of the |
|
| 788 | - // method. |
|
| 789 | - else { |
|
| 786 | + // ----- Look for 2 args |
|
| 787 | + // Here we need to support the first historic synopsis of the |
|
| 788 | + // method. |
|
| 789 | + else { |
|
| 790 | 790 | |
| 791 | 791 | // ----- Get the first argument |
| 792 | 792 | $v_path = $v_arg_list[0]; |
| 793 | 793 | |
| 794 | 794 | // ----- Look for the optional second argument |
| 795 | 795 | if ($v_size == 2) { |
| 796 | - $v_remove_path = $v_arg_list[1]; |
|
| 796 | + $v_remove_path = $v_arg_list[1]; |
|
| 797 | 797 | } |
| 798 | 798 | else if ($v_size > 2) { |
| 799 | - // ----- Error log |
|
| 800 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); |
|
| 799 | + // ----- Error log |
|
| 800 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); |
|
| 801 | 801 | |
| 802 | - // ----- Return |
|
| 803 | - return 0; |
|
| 802 | + // ----- Return |
|
| 803 | + return 0; |
|
| 804 | + } |
|
| 804 | 805 | } |
| 805 | - } |
|
| 806 | 806 | } |
| 807 | 807 | |
| 808 | 808 | // ----- Look for default option values |
@@ -813,57 +813,57 @@ discard block |
||
| 813 | 813 | // ----- Call the extracting fct |
| 814 | 814 | $p_list = array(); |
| 815 | 815 | $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, |
| 816 | - $v_remove_all_path, $v_options); |
|
| 816 | + $v_remove_all_path, $v_options); |
|
| 817 | 817 | if ($v_result < 1) { |
| 818 | - unset($p_list); |
|
| 819 | - return(0); |
|
| 818 | + unset($p_list); |
|
| 819 | + return(0); |
|
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | // ----- Return |
| 823 | 823 | return $p_list; |
| 824 | - } |
|
| 825 | - // -------------------------------------------------------------------------------- |
|
| 826 | - |
|
| 827 | - |
|
| 828 | - // -------------------------------------------------------------------------------- |
|
| 829 | - // Function : |
|
| 830 | - // extractByIndex($p_index, $p_path="./", $p_remove_path="") |
|
| 831 | - // extractByIndex($p_index, [$p_option, $p_option_value, ...]) |
|
| 832 | - // Description : |
|
| 833 | - // This method supports two synopsis. The first one is historical. |
|
| 834 | - // This method is doing a partial extract of the archive. |
|
| 835 | - // The extracted files or folders are identified by their index in the |
|
| 836 | - // archive (from 0 to n). |
|
| 837 | - // Note that if the index identify a folder, only the folder entry is |
|
| 838 | - // extracted, not all the files included in the archive. |
|
| 839 | - // Parameters : |
|
| 840 | - // $p_index : A single index (integer) or a string of indexes of files to |
|
| 841 | - // extract. The form of the string is "0,4-6,8-12" with only numbers |
|
| 842 | - // and '-' for range or ',' to separate ranges. No spaces or ';' |
|
| 843 | - // are allowed. |
|
| 844 | - // $p_path : Path where the files and directories are to be extracted |
|
| 845 | - // $p_remove_path : First part ('root' part) of the memorized path |
|
| 846 | - // (if any similar) to remove while extracting. |
|
| 847 | - // Options : |
|
| 848 | - // PCLZIP_OPT_PATH : |
|
| 849 | - // PCLZIP_OPT_ADD_PATH : |
|
| 850 | - // PCLZIP_OPT_REMOVE_PATH : |
|
| 851 | - // PCLZIP_OPT_REMOVE_ALL_PATH : |
|
| 852 | - // PCLZIP_OPT_EXTRACT_AS_STRING : The files are extracted as strings and |
|
| 853 | - // not as files. |
|
| 854 | - // The resulting content is in a new field 'content' in the file |
|
| 855 | - // structure. |
|
| 856 | - // This option must be used alone (any other options are ignored). |
|
| 857 | - // PCLZIP_CB_PRE_EXTRACT : |
|
| 858 | - // PCLZIP_CB_POST_EXTRACT : |
|
| 859 | - // Return Values : |
|
| 860 | - // 0 on failure, |
|
| 861 | - // The list of the extracted files, with a status of the action. |
|
| 862 | - // (see PclZip::listContent() for list entry format) |
|
| 863 | - // -------------------------------------------------------------------------------- |
|
| 864 | - //function extractByIndex($p_index, options...) |
|
| 865 | - function extractByIndex($p_index) |
|
| 866 | - { |
|
| 824 | + } |
|
| 825 | + // -------------------------------------------------------------------------------- |
|
| 826 | + |
|
| 827 | + |
|
| 828 | + // -------------------------------------------------------------------------------- |
|
| 829 | + // Function : |
|
| 830 | + // extractByIndex($p_index, $p_path="./", $p_remove_path="") |
|
| 831 | + // extractByIndex($p_index, [$p_option, $p_option_value, ...]) |
|
| 832 | + // Description : |
|
| 833 | + // This method supports two synopsis. The first one is historical. |
|
| 834 | + // This method is doing a partial extract of the archive. |
|
| 835 | + // The extracted files or folders are identified by their index in the |
|
| 836 | + // archive (from 0 to n). |
|
| 837 | + // Note that if the index identify a folder, only the folder entry is |
|
| 838 | + // extracted, not all the files included in the archive. |
|
| 839 | + // Parameters : |
|
| 840 | + // $p_index : A single index (integer) or a string of indexes of files to |
|
| 841 | + // extract. The form of the string is "0,4-6,8-12" with only numbers |
|
| 842 | + // and '-' for range or ',' to separate ranges. No spaces or ';' |
|
| 843 | + // are allowed. |
|
| 844 | + // $p_path : Path where the files and directories are to be extracted |
|
| 845 | + // $p_remove_path : First part ('root' part) of the memorized path |
|
| 846 | + // (if any similar) to remove while extracting. |
|
| 847 | + // Options : |
|
| 848 | + // PCLZIP_OPT_PATH : |
|
| 849 | + // PCLZIP_OPT_ADD_PATH : |
|
| 850 | + // PCLZIP_OPT_REMOVE_PATH : |
|
| 851 | + // PCLZIP_OPT_REMOVE_ALL_PATH : |
|
| 852 | + // PCLZIP_OPT_EXTRACT_AS_STRING : The files are extracted as strings and |
|
| 853 | + // not as files. |
|
| 854 | + // The resulting content is in a new field 'content' in the file |
|
| 855 | + // structure. |
|
| 856 | + // This option must be used alone (any other options are ignored). |
|
| 857 | + // PCLZIP_CB_PRE_EXTRACT : |
|
| 858 | + // PCLZIP_CB_POST_EXTRACT : |
|
| 859 | + // Return Values : |
|
| 860 | + // 0 on failure, |
|
| 861 | + // The list of the extracted files, with a status of the action. |
|
| 862 | + // (see PclZip::listContent() for list entry format) |
|
| 863 | + // -------------------------------------------------------------------------------- |
|
| 864 | + //function extractByIndex($p_index, options...) |
|
| 865 | + function extractByIndex($p_index) |
|
| 866 | + { |
|
| 867 | 867 | $v_result=1; |
| 868 | 868 | |
| 869 | 869 | // ----- Reset the error handler |
@@ -871,7 +871,7 @@ discard block |
||
| 871 | 871 | |
| 872 | 872 | // ----- Check archive |
| 873 | 873 | if (!$this->privCheckFormat()) { |
| 874 | - return(0); |
|
| 874 | + return(0); |
|
| 875 | 875 | } |
| 876 | 876 | |
| 877 | 877 | // ----- Set default values |
@@ -889,81 +889,81 @@ discard block |
||
| 889 | 889 | |
| 890 | 890 | // ----- Look for arguments |
| 891 | 891 | if ($v_size > 1) { |
| 892 | - // ----- Get the arguments |
|
| 893 | - $v_arg_list = func_get_args(); |
|
| 892 | + // ----- Get the arguments |
|
| 893 | + $v_arg_list = func_get_args(); |
|
| 894 | 894 | |
| 895 | - // ----- Remove form the options list the first argument |
|
| 896 | - array_shift($v_arg_list); |
|
| 897 | - $v_size--; |
|
| 895 | + // ----- Remove form the options list the first argument |
|
| 896 | + array_shift($v_arg_list); |
|
| 897 | + $v_size--; |
|
| 898 | 898 | |
| 899 | - // ----- Look for first arg |
|
| 900 | - if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
|
| 899 | + // ----- Look for first arg |
|
| 900 | + if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) { |
|
| 901 | 901 | |
| 902 | 902 | // ----- Parse the options |
| 903 | 903 | $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
| 904 | 904 | array (PCLZIP_OPT_PATH => 'optional', |
| 905 | - PCLZIP_OPT_REMOVE_PATH => 'optional', |
|
| 906 | - PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
|
| 907 | - PCLZIP_OPT_EXTRACT_AS_STRING => 'optional', |
|
| 908 | - PCLZIP_OPT_ADD_PATH => 'optional', |
|
| 909 | - PCLZIP_CB_PRE_EXTRACT => 'optional', |
|
| 910 | - PCLZIP_CB_POST_EXTRACT => 'optional', |
|
| 911 | - PCLZIP_OPT_SET_CHMOD => 'optional', |
|
| 912 | - PCLZIP_OPT_REPLACE_NEWER => 'optional' |
|
| 913 | - ,PCLZIP_OPT_STOP_ON_ERROR => 'optional' |
|
| 914 | - ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional', |
|
| 915 | - PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', |
|
| 916 | - PCLZIP_OPT_TEMP_FILE_ON => 'optional', |
|
| 917 | - PCLZIP_OPT_TEMP_FILE_OFF => 'optional' |
|
| 918 | - )); |
|
| 905 | + PCLZIP_OPT_REMOVE_PATH => 'optional', |
|
| 906 | + PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
|
| 907 | + PCLZIP_OPT_EXTRACT_AS_STRING => 'optional', |
|
| 908 | + PCLZIP_OPT_ADD_PATH => 'optional', |
|
| 909 | + PCLZIP_CB_PRE_EXTRACT => 'optional', |
|
| 910 | + PCLZIP_CB_POST_EXTRACT => 'optional', |
|
| 911 | + PCLZIP_OPT_SET_CHMOD => 'optional', |
|
| 912 | + PCLZIP_OPT_REPLACE_NEWER => 'optional' |
|
| 913 | + ,PCLZIP_OPT_STOP_ON_ERROR => 'optional' |
|
| 914 | + ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional', |
|
| 915 | + PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional', |
|
| 916 | + PCLZIP_OPT_TEMP_FILE_ON => 'optional', |
|
| 917 | + PCLZIP_OPT_TEMP_FILE_OFF => 'optional' |
|
| 918 | + )); |
|
| 919 | 919 | if ($v_result != 1) { |
| 920 | - return 0; |
|
| 920 | + return 0; |
|
| 921 | 921 | } |
| 922 | 922 | |
| 923 | 923 | // ----- Set the arguments |
| 924 | 924 | if (isset($v_options[PCLZIP_OPT_PATH])) { |
| 925 | - $v_path = $v_options[PCLZIP_OPT_PATH]; |
|
| 925 | + $v_path = $v_options[PCLZIP_OPT_PATH]; |
|
| 926 | 926 | } |
| 927 | 927 | if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) { |
| 928 | - $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH]; |
|
| 928 | + $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH]; |
|
| 929 | 929 | } |
| 930 | 930 | if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
| 931 | - $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH]; |
|
| 931 | + $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH]; |
|
| 932 | 932 | } |
| 933 | 933 | if (isset($v_options[PCLZIP_OPT_ADD_PATH])) { |
| 934 | - // ----- Check for '/' in last path char |
|
| 935 | - if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) { |
|
| 934 | + // ----- Check for '/' in last path char |
|
| 935 | + if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) { |
|
| 936 | 936 | $v_path .= '/'; |
| 937 | - } |
|
| 938 | - $v_path .= $v_options[PCLZIP_OPT_ADD_PATH]; |
|
| 937 | + } |
|
| 938 | + $v_path .= $v_options[PCLZIP_OPT_ADD_PATH]; |
|
| 939 | 939 | } |
| 940 | 940 | if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) { |
| 941 | - $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; |
|
| 941 | + $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; |
|
| 942 | 942 | } |
| 943 | 943 | else { |
| 944 | 944 | } |
| 945 | - } |
|
| 945 | + } |
|
| 946 | 946 | |
| 947 | - // ----- Look for 2 args |
|
| 948 | - // Here we need to support the first historic synopsis of the |
|
| 949 | - // method. |
|
| 950 | - else { |
|
| 947 | + // ----- Look for 2 args |
|
| 948 | + // Here we need to support the first historic synopsis of the |
|
| 949 | + // method. |
|
| 950 | + else { |
|
| 951 | 951 | |
| 952 | 952 | // ----- Get the first argument |
| 953 | 953 | $v_path = $v_arg_list[0]; |
| 954 | 954 | |
| 955 | 955 | // ----- Look for the optional second argument |
| 956 | 956 | if ($v_size == 2) { |
| 957 | - $v_remove_path = $v_arg_list[1]; |
|
| 957 | + $v_remove_path = $v_arg_list[1]; |
|
| 958 | 958 | } |
| 959 | 959 | else if ($v_size > 2) { |
| 960 | - // ----- Error log |
|
| 961 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); |
|
| 960 | + // ----- Error log |
|
| 961 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); |
|
| 962 | 962 | |
| 963 | - // ----- Return |
|
| 964 | - return 0; |
|
| 963 | + // ----- Return |
|
| 964 | + return 0; |
|
| 965 | + } |
|
| 965 | 966 | } |
| 966 | - } |
|
| 967 | 967 | } |
| 968 | 968 | |
| 969 | 969 | // ----- Trace |
@@ -990,29 +990,29 @@ discard block |
||
| 990 | 990 | |
| 991 | 991 | // ----- Return |
| 992 | 992 | return $p_list; |
| 993 | - } |
|
| 994 | - // -------------------------------------------------------------------------------- |
|
| 995 | - |
|
| 996 | - // -------------------------------------------------------------------------------- |
|
| 997 | - // Function : |
|
| 998 | - // delete([$p_option, $p_option_value, ...]) |
|
| 999 | - // Description : |
|
| 1000 | - // This method removes files from the archive. |
|
| 1001 | - // If no parameters are given, then all the archive is emptied. |
|
| 1002 | - // Parameters : |
|
| 1003 | - // None or optional arguments. |
|
| 1004 | - // Options : |
|
| 1005 | - // PCLZIP_OPT_BY_INDEX : |
|
| 1006 | - // PCLZIP_OPT_BY_NAME : |
|
| 1007 | - // PCLZIP_OPT_BY_EREG : |
|
| 1008 | - // PCLZIP_OPT_BY_PREG : |
|
| 1009 | - // Return Values : |
|
| 1010 | - // 0 on failure, |
|
| 1011 | - // The list of the files which are still present in the archive. |
|
| 1012 | - // (see PclZip::listContent() for list entry format) |
|
| 1013 | - // -------------------------------------------------------------------------------- |
|
| 1014 | - function delete() |
|
| 1015 | - { |
|
| 993 | + } |
|
| 994 | + // -------------------------------------------------------------------------------- |
|
| 995 | + |
|
| 996 | + // -------------------------------------------------------------------------------- |
|
| 997 | + // Function : |
|
| 998 | + // delete([$p_option, $p_option_value, ...]) |
|
| 999 | + // Description : |
|
| 1000 | + // This method removes files from the archive. |
|
| 1001 | + // If no parameters are given, then all the archive is emptied. |
|
| 1002 | + // Parameters : |
|
| 1003 | + // None or optional arguments. |
|
| 1004 | + // Options : |
|
| 1005 | + // PCLZIP_OPT_BY_INDEX : |
|
| 1006 | + // PCLZIP_OPT_BY_NAME : |
|
| 1007 | + // PCLZIP_OPT_BY_EREG : |
|
| 1008 | + // PCLZIP_OPT_BY_PREG : |
|
| 1009 | + // Return Values : |
|
| 1010 | + // 0 on failure, |
|
| 1011 | + // The list of the files which are still present in the archive. |
|
| 1012 | + // (see PclZip::listContent() for list entry format) |
|
| 1013 | + // -------------------------------------------------------------------------------- |
|
| 1014 | + function delete() |
|
| 1015 | + { |
|
| 1016 | 1016 | $v_result=1; |
| 1017 | 1017 | |
| 1018 | 1018 | // ----- Reset the error handler |
@@ -1020,7 +1020,7 @@ discard block |
||
| 1020 | 1020 | |
| 1021 | 1021 | // ----- Check archive |
| 1022 | 1022 | if (!$this->privCheckFormat()) { |
| 1023 | - return(0); |
|
| 1023 | + return(0); |
|
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | 1026 | // ----- Set default values |
@@ -1031,18 +1031,18 @@ discard block |
||
| 1031 | 1031 | |
| 1032 | 1032 | // ----- Look for arguments |
| 1033 | 1033 | if ($v_size > 0) { |
| 1034 | - // ----- Get the arguments |
|
| 1035 | - $v_arg_list = func_get_args(); |
|
| 1034 | + // ----- Get the arguments |
|
| 1035 | + $v_arg_list = func_get_args(); |
|
| 1036 | 1036 | |
| 1037 | - // ----- Parse the options |
|
| 1038 | - $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
|
| 1037 | + // ----- Parse the options |
|
| 1038 | + $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
|
| 1039 | 1039 | array (PCLZIP_OPT_BY_NAME => 'optional', |
| 1040 | - PCLZIP_OPT_BY_EREG => 'optional', |
|
| 1041 | - PCLZIP_OPT_BY_PREG => 'optional', |
|
| 1042 | - PCLZIP_OPT_BY_INDEX => 'optional' )); |
|
| 1043 | - if ($v_result != 1) { |
|
| 1044 | - return 0; |
|
| 1045 | - } |
|
| 1040 | + PCLZIP_OPT_BY_EREG => 'optional', |
|
| 1041 | + PCLZIP_OPT_BY_PREG => 'optional', |
|
| 1042 | + PCLZIP_OPT_BY_INDEX => 'optional' )); |
|
| 1043 | + if ($v_result != 1) { |
|
| 1044 | + return 0; |
|
| 1045 | + } |
|
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | 1048 | // ----- Magic quotes trick |
@@ -1051,9 +1051,9 @@ discard block |
||
| 1051 | 1051 | // ----- Call the delete fct |
| 1052 | 1052 | $v_list = array(); |
| 1053 | 1053 | if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) { |
| 1054 | - $this->privSwapBackMagicQuotes(); |
|
| 1055 | - unset($v_list); |
|
| 1056 | - return(0); |
|
| 1054 | + $this->privSwapBackMagicQuotes(); |
|
| 1055 | + unset($v_list); |
|
| 1056 | + return(0); |
|
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | 1059 | // ----- Magic quotes trick |
@@ -1061,41 +1061,41 @@ discard block |
||
| 1061 | 1061 | |
| 1062 | 1062 | // ----- Return |
| 1063 | 1063 | return $v_list; |
| 1064 | - } |
|
| 1065 | - // -------------------------------------------------------------------------------- |
|
| 1066 | - |
|
| 1067 | - // -------------------------------------------------------------------------------- |
|
| 1068 | - // Function : deleteByIndex() |
|
| 1069 | - // Description : |
|
| 1070 | - // ***** Deprecated ***** |
|
| 1071 | - // delete(PCLZIP_OPT_BY_INDEX, $p_index) should be prefered. |
|
| 1072 | - // -------------------------------------------------------------------------------- |
|
| 1073 | - function deleteByIndex($p_index) |
|
| 1074 | - { |
|
| 1064 | + } |
|
| 1065 | + // -------------------------------------------------------------------------------- |
|
| 1066 | + |
|
| 1067 | + // -------------------------------------------------------------------------------- |
|
| 1068 | + // Function : deleteByIndex() |
|
| 1069 | + // Description : |
|
| 1070 | + // ***** Deprecated ***** |
|
| 1071 | + // delete(PCLZIP_OPT_BY_INDEX, $p_index) should be prefered. |
|
| 1072 | + // -------------------------------------------------------------------------------- |
|
| 1073 | + function deleteByIndex($p_index) |
|
| 1074 | + { |
|
| 1075 | 1075 | |
| 1076 | 1076 | $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index); |
| 1077 | 1077 | |
| 1078 | 1078 | // ----- Return |
| 1079 | 1079 | return $p_list; |
| 1080 | - } |
|
| 1081 | - // -------------------------------------------------------------------------------- |
|
| 1082 | - |
|
| 1083 | - // -------------------------------------------------------------------------------- |
|
| 1084 | - // Function : properties() |
|
| 1085 | - // Description : |
|
| 1086 | - // This method gives the properties of the archive. |
|
| 1087 | - // The properties are : |
|
| 1088 | - // nb : Number of files in the archive |
|
| 1089 | - // comment : Comment associated with the archive file |
|
| 1090 | - // status : not_exist, ok |
|
| 1091 | - // Parameters : |
|
| 1092 | - // None |
|
| 1093 | - // Return Values : |
|
| 1094 | - // 0 on failure, |
|
| 1095 | - // An array with the archive properties. |
|
| 1096 | - // -------------------------------------------------------------------------------- |
|
| 1097 | - function properties() |
|
| 1098 | - { |
|
| 1080 | + } |
|
| 1081 | + // -------------------------------------------------------------------------------- |
|
| 1082 | + |
|
| 1083 | + // -------------------------------------------------------------------------------- |
|
| 1084 | + // Function : properties() |
|
| 1085 | + // Description : |
|
| 1086 | + // This method gives the properties of the archive. |
|
| 1087 | + // The properties are : |
|
| 1088 | + // nb : Number of files in the archive |
|
| 1089 | + // comment : Comment associated with the archive file |
|
| 1090 | + // status : not_exist, ok |
|
| 1091 | + // Parameters : |
|
| 1092 | + // None |
|
| 1093 | + // Return Values : |
|
| 1094 | + // 0 on failure, |
|
| 1095 | + // An array with the archive properties. |
|
| 1096 | + // -------------------------------------------------------------------------------- |
|
| 1097 | + function properties() |
|
| 1098 | + { |
|
| 1099 | 1099 | |
| 1100 | 1100 | // ----- Reset the error handler |
| 1101 | 1101 | $this->privErrorReset(); |
@@ -1105,8 +1105,8 @@ discard block |
||
| 1105 | 1105 | |
| 1106 | 1106 | // ----- Check archive |
| 1107 | 1107 | if (!$this->privCheckFormat()) { |
| 1108 | - $this->privSwapBackMagicQuotes(); |
|
| 1109 | - return(0); |
|
| 1108 | + $this->privSwapBackMagicQuotes(); |
|
| 1109 | + return(0); |
|
| 1110 | 1110 | } |
| 1111 | 1111 | |
| 1112 | 1112 | // ----- Default properties |
@@ -1118,9 +1118,9 @@ discard block |
||
| 1118 | 1118 | // ----- Look if file exists |
| 1119 | 1119 | if (@is_file($this->zipname)) |
| 1120 | 1120 | { |
| 1121 | - // ----- Open the zip file |
|
| 1122 | - if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) |
|
| 1123 | - { |
|
| 1121 | + // ----- Open the zip file |
|
| 1122 | + if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) |
|
| 1123 | + { |
|
| 1124 | 1124 | $this->privSwapBackMagicQuotes(); |
| 1125 | 1125 | |
| 1126 | 1126 | // ----- Error log |
@@ -1128,23 +1128,23 @@ discard block |
||
| 1128 | 1128 | |
| 1129 | 1129 | // ----- Return |
| 1130 | 1130 | return 0; |
| 1131 | - } |
|
| 1131 | + } |
|
| 1132 | 1132 | |
| 1133 | - // ----- Read the central directory informations |
|
| 1134 | - $v_central_dir = array(); |
|
| 1135 | - if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
|
| 1136 | - { |
|
| 1133 | + // ----- Read the central directory informations |
|
| 1134 | + $v_central_dir = array(); |
|
| 1135 | + if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
|
| 1136 | + { |
|
| 1137 | 1137 | $this->privSwapBackMagicQuotes(); |
| 1138 | 1138 | return 0; |
| 1139 | - } |
|
| 1139 | + } |
|
| 1140 | 1140 | |
| 1141 | - // ----- Close the zip file |
|
| 1142 | - $this->privCloseFd(); |
|
| 1141 | + // ----- Close the zip file |
|
| 1142 | + $this->privCloseFd(); |
|
| 1143 | 1143 | |
| 1144 | - // ----- Set the user attributes |
|
| 1145 | - $v_prop['comment'] = $v_central_dir['comment']; |
|
| 1146 | - $v_prop['nb'] = $v_central_dir['entries']; |
|
| 1147 | - $v_prop['status'] = 'ok'; |
|
| 1144 | + // ----- Set the user attributes |
|
| 1145 | + $v_prop['comment'] = $v_central_dir['comment']; |
|
| 1146 | + $v_prop['nb'] = $v_central_dir['entries']; |
|
| 1147 | + $v_prop['status'] = 'ok'; |
|
| 1148 | 1148 | } |
| 1149 | 1149 | |
| 1150 | 1150 | // ----- Magic quotes trick |
@@ -1152,23 +1152,23 @@ discard block |
||
| 1152 | 1152 | |
| 1153 | 1153 | // ----- Return |
| 1154 | 1154 | return $v_prop; |
| 1155 | - } |
|
| 1156 | - // -------------------------------------------------------------------------------- |
|
| 1157 | - |
|
| 1158 | - // -------------------------------------------------------------------------------- |
|
| 1159 | - // Function : duplicate() |
|
| 1160 | - // Description : |
|
| 1161 | - // This method creates an archive by copying the content of an other one. If |
|
| 1162 | - // the archive already exist, it is replaced by the new one without any warning. |
|
| 1163 | - // Parameters : |
|
| 1164 | - // $p_archive : The filename of a valid archive, or |
|
| 1165 | - // a valid PclZip object. |
|
| 1166 | - // Return Values : |
|
| 1167 | - // 1 on success. |
|
| 1168 | - // 0 or a negative value on error (error code). |
|
| 1169 | - // -------------------------------------------------------------------------------- |
|
| 1170 | - function duplicate($p_archive) |
|
| 1171 | - { |
|
| 1155 | + } |
|
| 1156 | + // -------------------------------------------------------------------------------- |
|
| 1157 | + |
|
| 1158 | + // -------------------------------------------------------------------------------- |
|
| 1159 | + // Function : duplicate() |
|
| 1160 | + // Description : |
|
| 1161 | + // This method creates an archive by copying the content of an other one. If |
|
| 1162 | + // the archive already exist, it is replaced by the new one without any warning. |
|
| 1163 | + // Parameters : |
|
| 1164 | + // $p_archive : The filename of a valid archive, or |
|
| 1165 | + // a valid PclZip object. |
|
| 1166 | + // Return Values : |
|
| 1167 | + // 1 on success. |
|
| 1168 | + // 0 or a negative value on error (error code). |
|
| 1169 | + // -------------------------------------------------------------------------------- |
|
| 1170 | + function duplicate($p_archive) |
|
| 1171 | + { |
|
| 1172 | 1172 | $v_result = 1; |
| 1173 | 1173 | |
| 1174 | 1174 | // ----- Reset the error handler |
@@ -1178,56 +1178,56 @@ discard block |
||
| 1178 | 1178 | if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip')) |
| 1179 | 1179 | { |
| 1180 | 1180 | |
| 1181 | - // ----- Duplicate the archive |
|
| 1182 | - $v_result = $this->privDuplicate($p_archive->zipname); |
|
| 1181 | + // ----- Duplicate the archive |
|
| 1182 | + $v_result = $this->privDuplicate($p_archive->zipname); |
|
| 1183 | 1183 | } |
| 1184 | 1184 | |
| 1185 | 1185 | // ----- Look if the $p_archive is a string (so a filename) |
| 1186 | 1186 | else if (is_string($p_archive)) |
| 1187 | 1187 | { |
| 1188 | 1188 | |
| 1189 | - // ----- Check that $p_archive is a valid zip file |
|
| 1190 | - // TBC : Should also check the archive format |
|
| 1191 | - if (!is_file($p_archive)) { |
|
| 1189 | + // ----- Check that $p_archive is a valid zip file |
|
| 1190 | + // TBC : Should also check the archive format |
|
| 1191 | + if (!is_file($p_archive)) { |
|
| 1192 | 1192 | // ----- Error log |
| 1193 | 1193 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'"); |
| 1194 | 1194 | $v_result = PCLZIP_ERR_MISSING_FILE; |
| 1195 | - } |
|
| 1196 | - else { |
|
| 1195 | + } |
|
| 1196 | + else { |
|
| 1197 | 1197 | // ----- Duplicate the archive |
| 1198 | 1198 | $v_result = $this->privDuplicate($p_archive); |
| 1199 | - } |
|
| 1199 | + } |
|
| 1200 | 1200 | } |
| 1201 | 1201 | |
| 1202 | 1202 | // ----- Invalid variable |
| 1203 | 1203 | else |
| 1204 | 1204 | { |
| 1205 | - // ----- Error log |
|
| 1206 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add"); |
|
| 1207 | - $v_result = PCLZIP_ERR_INVALID_PARAMETER; |
|
| 1205 | + // ----- Error log |
|
| 1206 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add"); |
|
| 1207 | + $v_result = PCLZIP_ERR_INVALID_PARAMETER; |
|
| 1208 | 1208 | } |
| 1209 | 1209 | |
| 1210 | 1210 | // ----- Return |
| 1211 | 1211 | return $v_result; |
| 1212 | - } |
|
| 1213 | - // -------------------------------------------------------------------------------- |
|
| 1214 | - |
|
| 1215 | - // -------------------------------------------------------------------------------- |
|
| 1216 | - // Function : merge() |
|
| 1217 | - // Description : |
|
| 1218 | - // This method merge the $p_archive_to_add archive at the end of the current |
|
| 1219 | - // one ($this). |
|
| 1220 | - // If the archive ($this) does not exist, the merge becomes a duplicate. |
|
| 1221 | - // If the $p_archive_to_add archive does not exist, the merge is a success. |
|
| 1222 | - // Parameters : |
|
| 1223 | - // $p_archive_to_add : It can be directly the filename of a valid zip archive, |
|
| 1224 | - // or a PclZip object archive. |
|
| 1225 | - // Return Values : |
|
| 1226 | - // 1 on success, |
|
| 1227 | - // 0 or negative values on error (see below). |
|
| 1228 | - // -------------------------------------------------------------------------------- |
|
| 1229 | - function merge($p_archive_to_add) |
|
| 1230 | - { |
|
| 1212 | + } |
|
| 1213 | + // -------------------------------------------------------------------------------- |
|
| 1214 | + |
|
| 1215 | + // -------------------------------------------------------------------------------- |
|
| 1216 | + // Function : merge() |
|
| 1217 | + // Description : |
|
| 1218 | + // This method merge the $p_archive_to_add archive at the end of the current |
|
| 1219 | + // one ($this). |
|
| 1220 | + // If the archive ($this) does not exist, the merge becomes a duplicate. |
|
| 1221 | + // If the $p_archive_to_add archive does not exist, the merge is a success. |
|
| 1222 | + // Parameters : |
|
| 1223 | + // $p_archive_to_add : It can be directly the filename of a valid zip archive, |
|
| 1224 | + // or a PclZip object archive. |
|
| 1225 | + // Return Values : |
|
| 1226 | + // 1 on success, |
|
| 1227 | + // 0 or negative values on error (see below). |
|
| 1228 | + // -------------------------------------------------------------------------------- |
|
| 1229 | + function merge($p_archive_to_add) |
|
| 1230 | + { |
|
| 1231 | 1231 | $v_result = 1; |
| 1232 | 1232 | |
| 1233 | 1233 | // ----- Reset the error handler |
@@ -1235,125 +1235,125 @@ discard block |
||
| 1235 | 1235 | |
| 1236 | 1236 | // ----- Check archive |
| 1237 | 1237 | if (!$this->privCheckFormat()) { |
| 1238 | - return(0); |
|
| 1238 | + return(0); |
|
| 1239 | 1239 | } |
| 1240 | 1240 | |
| 1241 | 1241 | // ----- Look if the $p_archive_to_add is a PclZip object |
| 1242 | 1242 | if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip')) |
| 1243 | 1243 | { |
| 1244 | 1244 | |
| 1245 | - // ----- Merge the archive |
|
| 1246 | - $v_result = $this->privMerge($p_archive_to_add); |
|
| 1245 | + // ----- Merge the archive |
|
| 1246 | + $v_result = $this->privMerge($p_archive_to_add); |
|
| 1247 | 1247 | } |
| 1248 | 1248 | |
| 1249 | 1249 | // ----- Look if the $p_archive_to_add is a string (so a filename) |
| 1250 | 1250 | else if (is_string($p_archive_to_add)) |
| 1251 | 1251 | { |
| 1252 | 1252 | |
| 1253 | - // ----- Create a temporary archive |
|
| 1254 | - $v_object_archive = new PclZip($p_archive_to_add); |
|
| 1253 | + // ----- Create a temporary archive |
|
| 1254 | + $v_object_archive = new PclZip($p_archive_to_add); |
|
| 1255 | 1255 | |
| 1256 | - // ----- Merge the archive |
|
| 1257 | - $v_result = $this->privMerge($v_object_archive); |
|
| 1256 | + // ----- Merge the archive |
|
| 1257 | + $v_result = $this->privMerge($v_object_archive); |
|
| 1258 | 1258 | } |
| 1259 | 1259 | |
| 1260 | 1260 | // ----- Invalid variable |
| 1261 | 1261 | else |
| 1262 | 1262 | { |
| 1263 | - // ----- Error log |
|
| 1264 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add"); |
|
| 1265 | - $v_result = PCLZIP_ERR_INVALID_PARAMETER; |
|
| 1263 | + // ----- Error log |
|
| 1264 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add"); |
|
| 1265 | + $v_result = PCLZIP_ERR_INVALID_PARAMETER; |
|
| 1266 | 1266 | } |
| 1267 | 1267 | |
| 1268 | 1268 | // ----- Return |
| 1269 | 1269 | return $v_result; |
| 1270 | - } |
|
| 1271 | - // -------------------------------------------------------------------------------- |
|
| 1270 | + } |
|
| 1271 | + // -------------------------------------------------------------------------------- |
|
| 1272 | 1272 | |
| 1273 | 1273 | |
| 1274 | 1274 | |
| 1275 | - // -------------------------------------------------------------------------------- |
|
| 1276 | - // Function : errorCode() |
|
| 1277 | - // Description : |
|
| 1278 | - // Parameters : |
|
| 1279 | - // -------------------------------------------------------------------------------- |
|
| 1280 | - function errorCode() |
|
| 1281 | - { |
|
| 1275 | + // -------------------------------------------------------------------------------- |
|
| 1276 | + // Function : errorCode() |
|
| 1277 | + // Description : |
|
| 1278 | + // Parameters : |
|
| 1279 | + // -------------------------------------------------------------------------------- |
|
| 1280 | + function errorCode() |
|
| 1281 | + { |
|
| 1282 | 1282 | if (PCLZIP_ERROR_EXTERNAL == 1) { |
| 1283 | - return(PclErrorCode()); |
|
| 1283 | + return(PclErrorCode()); |
|
| 1284 | 1284 | } |
| 1285 | 1285 | else { |
| 1286 | - return($this->error_code); |
|
| 1287 | - } |
|
| 1288 | - } |
|
| 1289 | - // -------------------------------------------------------------------------------- |
|
| 1290 | - |
|
| 1291 | - // -------------------------------------------------------------------------------- |
|
| 1292 | - // Function : errorName() |
|
| 1293 | - // Description : |
|
| 1294 | - // Parameters : |
|
| 1295 | - // -------------------------------------------------------------------------------- |
|
| 1296 | - function errorName($p_with_code=false) |
|
| 1297 | - { |
|
| 1286 | + return($this->error_code); |
|
| 1287 | + } |
|
| 1288 | + } |
|
| 1289 | + // -------------------------------------------------------------------------------- |
|
| 1290 | + |
|
| 1291 | + // -------------------------------------------------------------------------------- |
|
| 1292 | + // Function : errorName() |
|
| 1293 | + // Description : |
|
| 1294 | + // Parameters : |
|
| 1295 | + // -------------------------------------------------------------------------------- |
|
| 1296 | + function errorName($p_with_code=false) |
|
| 1297 | + { |
|
| 1298 | 1298 | $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR', |
| 1299 | - PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL', |
|
| 1300 | - PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL', |
|
| 1301 | - PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER', |
|
| 1302 | - PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE', |
|
| 1303 | - PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG', |
|
| 1304 | - PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP', |
|
| 1305 | - PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE', |
|
| 1306 | - PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL', |
|
| 1307 | - PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION', |
|
| 1308 | - PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT', |
|
| 1309 | - PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL', |
|
| 1310 | - PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL', |
|
| 1311 | - PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM', |
|
| 1312 | - PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', |
|
| 1313 | - PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE', |
|
| 1314 | - PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE', |
|
| 1315 | - PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', |
|
| 1316 | - PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION' |
|
| 1317 | - ,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE' |
|
| 1318 | - ,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION' |
|
| 1299 | + PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL', |
|
| 1300 | + PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL', |
|
| 1301 | + PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER', |
|
| 1302 | + PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE', |
|
| 1303 | + PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG', |
|
| 1304 | + PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP', |
|
| 1305 | + PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE', |
|
| 1306 | + PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL', |
|
| 1307 | + PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION', |
|
| 1308 | + PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT', |
|
| 1309 | + PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL', |
|
| 1310 | + PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL', |
|
| 1311 | + PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM', |
|
| 1312 | + PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', |
|
| 1313 | + PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE', |
|
| 1314 | + PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE', |
|
| 1315 | + PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', |
|
| 1316 | + PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION' |
|
| 1317 | + ,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE' |
|
| 1318 | + ,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION' |
|
| 1319 | 1319 | ); |
| 1320 | 1320 | |
| 1321 | 1321 | if (isset($v_name[$this->error_code])) { |
| 1322 | - $v_value = $v_name[$this->error_code]; |
|
| 1322 | + $v_value = $v_name[$this->error_code]; |
|
| 1323 | 1323 | } |
| 1324 | 1324 | else { |
| 1325 | - $v_value = 'NoName'; |
|
| 1325 | + $v_value = 'NoName'; |
|
| 1326 | 1326 | } |
| 1327 | 1327 | |
| 1328 | 1328 | if ($p_with_code) { |
| 1329 | - return($v_value.' ('.$this->error_code.')'); |
|
| 1329 | + return($v_value.' ('.$this->error_code.')'); |
|
| 1330 | 1330 | } |
| 1331 | 1331 | else { |
| 1332 | - return($v_value); |
|
| 1333 | - } |
|
| 1334 | - } |
|
| 1335 | - // -------------------------------------------------------------------------------- |
|
| 1336 | - |
|
| 1337 | - // -------------------------------------------------------------------------------- |
|
| 1338 | - // Function : errorInfo() |
|
| 1339 | - // Description : |
|
| 1340 | - // Parameters : |
|
| 1341 | - // -------------------------------------------------------------------------------- |
|
| 1342 | - function errorInfo($p_full=false) |
|
| 1343 | - { |
|
| 1332 | + return($v_value); |
|
| 1333 | + } |
|
| 1334 | + } |
|
| 1335 | + // -------------------------------------------------------------------------------- |
|
| 1336 | + |
|
| 1337 | + // -------------------------------------------------------------------------------- |
|
| 1338 | + // Function : errorInfo() |
|
| 1339 | + // Description : |
|
| 1340 | + // Parameters : |
|
| 1341 | + // -------------------------------------------------------------------------------- |
|
| 1342 | + function errorInfo($p_full=false) |
|
| 1343 | + { |
|
| 1344 | 1344 | if (PCLZIP_ERROR_EXTERNAL == 1) { |
| 1345 | - return(PclErrorString()); |
|
| 1345 | + return(PclErrorString()); |
|
| 1346 | 1346 | } |
| 1347 | 1347 | else { |
| 1348 | - if ($p_full) { |
|
| 1348 | + if ($p_full) { |
|
| 1349 | 1349 | return($this->errorName(true)." : ".$this->error_string); |
| 1350 | - } |
|
| 1351 | - else { |
|
| 1350 | + } |
|
| 1351 | + else { |
|
| 1352 | 1352 | return($this->error_string." [code ".$this->error_code."]"); |
| 1353 | - } |
|
| 1353 | + } |
|
| 1354 | 1354 | } |
| 1355 | - } |
|
| 1356 | - // -------------------------------------------------------------------------------- |
|
| 1355 | + } |
|
| 1356 | + // -------------------------------------------------------------------------------- |
|
| 1357 | 1357 | |
| 1358 | 1358 | |
| 1359 | 1359 | // -------------------------------------------------------------------------------- |
@@ -1364,25 +1364,25 @@ discard block |
||
| 1364 | 1364 | |
| 1365 | 1365 | |
| 1366 | 1366 | |
| 1367 | - // -------------------------------------------------------------------------------- |
|
| 1368 | - // Function : privCheckFormat() |
|
| 1369 | - // Description : |
|
| 1370 | - // This method check that the archive exists and is a valid zip archive. |
|
| 1371 | - // Several level of check exists. (futur) |
|
| 1372 | - // Parameters : |
|
| 1373 | - // $p_level : Level of check. Default 0. |
|
| 1374 | - // 0 : Check the first bytes (magic codes) (default value)) |
|
| 1375 | - // 1 : 0 + Check the central directory (futur) |
|
| 1376 | - // 2 : 1 + Check each file header (futur) |
|
| 1377 | - // Return Values : |
|
| 1378 | - // true on success, |
|
| 1379 | - // false on error, the error code is set. |
|
| 1380 | - // -------------------------------------------------------------------------------- |
|
| 1381 | - function privCheckFormat($p_level=0) |
|
| 1382 | - { |
|
| 1367 | + // -------------------------------------------------------------------------------- |
|
| 1368 | + // Function : privCheckFormat() |
|
| 1369 | + // Description : |
|
| 1370 | + // This method check that the archive exists and is a valid zip archive. |
|
| 1371 | + // Several level of check exists. (futur) |
|
| 1372 | + // Parameters : |
|
| 1373 | + // $p_level : Level of check. Default 0. |
|
| 1374 | + // 0 : Check the first bytes (magic codes) (default value)) |
|
| 1375 | + // 1 : 0 + Check the central directory (futur) |
|
| 1376 | + // 2 : 1 + Check each file header (futur) |
|
| 1377 | + // Return Values : |
|
| 1378 | + // true on success, |
|
| 1379 | + // false on error, the error code is set. |
|
| 1380 | + // -------------------------------------------------------------------------------- |
|
| 1381 | + function privCheckFormat($p_level=0) |
|
| 1382 | + { |
|
| 1383 | 1383 | $v_result = true; |
| 1384 | 1384 | |
| 1385 | - // ----- Reset the file system cache |
|
| 1385 | + // ----- Reset the file system cache |
|
| 1386 | 1386 | clearstatcache(); |
| 1387 | 1387 | |
| 1388 | 1388 | // ----- Reset the error handler |
@@ -1390,16 +1390,16 @@ discard block |
||
| 1390 | 1390 | |
| 1391 | 1391 | // ----- Look if the file exits |
| 1392 | 1392 | if (!is_file($this->zipname)) { |
| 1393 | - // ----- Error log |
|
| 1394 | - PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'"); |
|
| 1395 | - return(false); |
|
| 1393 | + // ----- Error log |
|
| 1394 | + PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'"); |
|
| 1395 | + return(false); |
|
| 1396 | 1396 | } |
| 1397 | 1397 | |
| 1398 | 1398 | // ----- Check that the file is readeable |
| 1399 | 1399 | if (!is_readable($this->zipname)) { |
| 1400 | - // ----- Error log |
|
| 1401 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'"); |
|
| 1402 | - return(false); |
|
| 1400 | + // ----- Error log |
|
| 1401 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'"); |
|
| 1402 | + return(false); |
|
| 1403 | 1403 | } |
| 1404 | 1404 | |
| 1405 | 1405 | // ----- Check the magic code |
@@ -1413,43 +1413,43 @@ discard block |
||
| 1413 | 1413 | |
| 1414 | 1414 | // ----- Return |
| 1415 | 1415 | return $v_result; |
| 1416 | - } |
|
| 1417 | - // -------------------------------------------------------------------------------- |
|
| 1418 | - |
|
| 1419 | - // -------------------------------------------------------------------------------- |
|
| 1420 | - // Function : privParseOptions() |
|
| 1421 | - // Description : |
|
| 1422 | - // This internal methods reads the variable list of arguments ($p_options_list, |
|
| 1423 | - // $p_size) and generate an array with the options and values ($v_result_list). |
|
| 1424 | - // $v_requested_options contains the options that can be present and those that |
|
| 1425 | - // must be present. |
|
| 1426 | - // $v_requested_options is an array, with the option value as key, and 'optional', |
|
| 1427 | - // or 'mandatory' as value. |
|
| 1428 | - // Parameters : |
|
| 1429 | - // See above. |
|
| 1430 | - // Return Values : |
|
| 1431 | - // 1 on success. |
|
| 1432 | - // 0 on failure. |
|
| 1433 | - // -------------------------------------------------------------------------------- |
|
| 1434 | - function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false) |
|
| 1435 | - { |
|
| 1416 | + } |
|
| 1417 | + // -------------------------------------------------------------------------------- |
|
| 1418 | + |
|
| 1419 | + // -------------------------------------------------------------------------------- |
|
| 1420 | + // Function : privParseOptions() |
|
| 1421 | + // Description : |
|
| 1422 | + // This internal methods reads the variable list of arguments ($p_options_list, |
|
| 1423 | + // $p_size) and generate an array with the options and values ($v_result_list). |
|
| 1424 | + // $v_requested_options contains the options that can be present and those that |
|
| 1425 | + // must be present. |
|
| 1426 | + // $v_requested_options is an array, with the option value as key, and 'optional', |
|
| 1427 | + // or 'mandatory' as value. |
|
| 1428 | + // Parameters : |
|
| 1429 | + // See above. |
|
| 1430 | + // Return Values : |
|
| 1431 | + // 1 on success. |
|
| 1432 | + // 0 on failure. |
|
| 1433 | + // -------------------------------------------------------------------------------- |
|
| 1434 | + function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false) |
|
| 1435 | + { |
|
| 1436 | 1436 | $v_result=1; |
| 1437 | 1437 | |
| 1438 | 1438 | // ----- Read the options |
| 1439 | 1439 | $i=0; |
| 1440 | 1440 | while ($i<$p_size) { |
| 1441 | 1441 | |
| 1442 | - // ----- Check if the option is supported |
|
| 1443 | - if (!isset($v_requested_options[$p_options_list[$i]])) { |
|
| 1442 | + // ----- Check if the option is supported |
|
| 1443 | + if (!isset($v_requested_options[$p_options_list[$i]])) { |
|
| 1444 | 1444 | // ----- Error log |
| 1445 | 1445 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method"); |
| 1446 | 1446 | |
| 1447 | 1447 | // ----- Return |
| 1448 | 1448 | return PclZip::errorCode(); |
| 1449 | - } |
|
| 1449 | + } |
|
| 1450 | 1450 | |
| 1451 | - // ----- Look for next option |
|
| 1452 | - switch ($p_options_list[$i]) { |
|
| 1451 | + // ----- Look for next option |
|
| 1452 | + switch ($p_options_list[$i]) { |
|
| 1453 | 1453 | // ----- Look for options that request a path value |
| 1454 | 1454 | case PCLZIP_OPT_PATH : |
| 1455 | 1455 | case PCLZIP_OPT_REMOVE_PATH : |
@@ -1461,11 +1461,11 @@ discard block |
||
| 1461 | 1461 | |
| 1462 | 1462 | // ----- Return |
| 1463 | 1463 | return PclZip::errorCode(); |
| 1464 | - } |
|
| 1464 | + } |
|
| 1465 | 1465 | |
| 1466 | - // ----- Get the value |
|
| 1467 | - $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); |
|
| 1468 | - $i++; |
|
| 1466 | + // ----- Get the value |
|
| 1467 | + $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); |
|
| 1468 | + $i++; |
|
| 1469 | 1469 | break; |
| 1470 | 1470 | |
| 1471 | 1471 | case PCLZIP_OPT_TEMP_FILE_THRESHOLD : |
@@ -1473,24 +1473,24 @@ discard block |
||
| 1473 | 1473 | if (($i+1) >= $p_size) { |
| 1474 | 1474 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
| 1475 | 1475 | return PclZip::errorCode(); |
| 1476 | - } |
|
| 1476 | + } |
|
| 1477 | 1477 | |
| 1478 | - // ----- Check for incompatible options |
|
| 1479 | - if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) { |
|
| 1478 | + // ----- Check for incompatible options |
|
| 1479 | + if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) { |
|
| 1480 | 1480 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'"); |
| 1481 | 1481 | return PclZip::errorCode(); |
| 1482 | - } |
|
| 1482 | + } |
|
| 1483 | 1483 | |
| 1484 | - // ----- Check the value |
|
| 1485 | - $v_value = $p_options_list[$i+1]; |
|
| 1486 | - if ((!is_integer($v_value)) || ($v_value<0)) { |
|
| 1484 | + // ----- Check the value |
|
| 1485 | + $v_value = $p_options_list[$i+1]; |
|
| 1486 | + if ((!is_integer($v_value)) || ($v_value<0)) { |
|
| 1487 | 1487 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
| 1488 | 1488 | return PclZip::errorCode(); |
| 1489 | - } |
|
| 1489 | + } |
|
| 1490 | 1490 | |
| 1491 | - // ----- Get the value (and convert it in bytes) |
|
| 1492 | - $v_result_list[$p_options_list[$i]] = $v_value*1048576; |
|
| 1493 | - $i++; |
|
| 1491 | + // ----- Get the value (and convert it in bytes) |
|
| 1492 | + $v_result_list[$p_options_list[$i]] = $v_value*1048576; |
|
| 1493 | + $i++; |
|
| 1494 | 1494 | break; |
| 1495 | 1495 | |
| 1496 | 1496 | case PCLZIP_OPT_TEMP_FILE_ON : |
@@ -1498,9 +1498,9 @@ discard block |
||
| 1498 | 1498 | if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) { |
| 1499 | 1499 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'"); |
| 1500 | 1500 | return PclZip::errorCode(); |
| 1501 | - } |
|
| 1501 | + } |
|
| 1502 | 1502 | |
| 1503 | - $v_result_list[$p_options_list[$i]] = true; |
|
| 1503 | + $v_result_list[$p_options_list[$i]] = true; |
|
| 1504 | 1504 | break; |
| 1505 | 1505 | |
| 1506 | 1506 | case PCLZIP_OPT_TEMP_FILE_OFF : |
@@ -1508,14 +1508,14 @@ discard block |
||
| 1508 | 1508 | if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) { |
| 1509 | 1509 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'"); |
| 1510 | 1510 | return PclZip::errorCode(); |
| 1511 | - } |
|
| 1512 | - // ----- Check for incompatible options |
|
| 1513 | - if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) { |
|
| 1511 | + } |
|
| 1512 | + // ----- Check for incompatible options |
|
| 1513 | + if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) { |
|
| 1514 | 1514 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'"); |
| 1515 | 1515 | return PclZip::errorCode(); |
| 1516 | - } |
|
| 1516 | + } |
|
| 1517 | 1517 | |
| 1518 | - $v_result_list[$p_options_list[$i]] = true; |
|
| 1518 | + $v_result_list[$p_options_list[$i]] = true; |
|
| 1519 | 1519 | break; |
| 1520 | 1520 | |
| 1521 | 1521 | case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION : |
@@ -1526,16 +1526,16 @@ discard block |
||
| 1526 | 1526 | |
| 1527 | 1527 | // ----- Return |
| 1528 | 1528 | return PclZip::errorCode(); |
| 1529 | - } |
|
| 1529 | + } |
|
| 1530 | 1530 | |
| 1531 | - // ----- Get the value |
|
| 1532 | - if ( is_string($p_options_list[$i+1]) |
|
| 1531 | + // ----- Get the value |
|
| 1532 | + if ( is_string($p_options_list[$i+1]) |
|
| 1533 | 1533 | && ($p_options_list[$i+1] != '')) { |
| 1534 | 1534 | $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); |
| 1535 | 1535 | $i++; |
| 1536 | - } |
|
| 1537 | - else { |
|
| 1538 | - } |
|
| 1536 | + } |
|
| 1537 | + else { |
|
| 1538 | + } |
|
| 1539 | 1539 | break; |
| 1540 | 1540 | |
| 1541 | 1541 | // ----- Look for options that request an array of string for value |
@@ -1547,23 +1547,23 @@ discard block |
||
| 1547 | 1547 | |
| 1548 | 1548 | // ----- Return |
| 1549 | 1549 | return PclZip::errorCode(); |
| 1550 | - } |
|
| 1550 | + } |
|
| 1551 | 1551 | |
| 1552 | - // ----- Get the value |
|
| 1553 | - if (is_string($p_options_list[$i+1])) { |
|
| 1554 | - $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1]; |
|
| 1555 | - } |
|
| 1556 | - else if (is_array($p_options_list[$i+1])) { |
|
| 1557 | - $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
|
| 1558 | - } |
|
| 1559 | - else { |
|
| 1552 | + // ----- Get the value |
|
| 1553 | + if (is_string($p_options_list[$i+1])) { |
|
| 1554 | + $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1]; |
|
| 1555 | + } |
|
| 1556 | + else if (is_array($p_options_list[$i+1])) { |
|
| 1557 | + $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
|
| 1558 | + } |
|
| 1559 | + else { |
|
| 1560 | 1560 | // ----- Error log |
| 1561 | 1561 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
| 1562 | 1562 | |
| 1563 | 1563 | // ----- Return |
| 1564 | 1564 | return PclZip::errorCode(); |
| 1565 | - } |
|
| 1566 | - $i++; |
|
| 1565 | + } |
|
| 1566 | + $i++; |
|
| 1567 | 1567 | break; |
| 1568 | 1568 | |
| 1569 | 1569 | // ----- Look for options that request an EREG or PREG expression |
@@ -1580,20 +1580,20 @@ discard block |
||
| 1580 | 1580 | |
| 1581 | 1581 | // ----- Return |
| 1582 | 1582 | return PclZip::errorCode(); |
| 1583 | - } |
|
| 1583 | + } |
|
| 1584 | 1584 | |
| 1585 | - // ----- Get the value |
|
| 1586 | - if (is_string($p_options_list[$i+1])) { |
|
| 1587 | - $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
|
| 1588 | - } |
|
| 1589 | - else { |
|
| 1585 | + // ----- Get the value |
|
| 1586 | + if (is_string($p_options_list[$i+1])) { |
|
| 1587 | + $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
|
| 1588 | + } |
|
| 1589 | + else { |
|
| 1590 | 1590 | // ----- Error log |
| 1591 | 1591 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
| 1592 | 1592 | |
| 1593 | 1593 | // ----- Return |
| 1594 | 1594 | return PclZip::errorCode(); |
| 1595 | - } |
|
| 1596 | - $i++; |
|
| 1595 | + } |
|
| 1596 | + $i++; |
|
| 1597 | 1597 | break; |
| 1598 | 1598 | |
| 1599 | 1599 | // ----- Look for options that takes a string |
@@ -1604,29 +1604,29 @@ discard block |
||
| 1604 | 1604 | if (($i+1) >= $p_size) { |
| 1605 | 1605 | // ----- Error log |
| 1606 | 1606 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, |
| 1607 | - "Missing parameter value for option '" |
|
| 1608 | - .PclZipUtilOptionText($p_options_list[$i]) |
|
| 1609 | - ."'"); |
|
| 1607 | + "Missing parameter value for option '" |
|
| 1608 | + .PclZipUtilOptionText($p_options_list[$i]) |
|
| 1609 | + ."'"); |
|
| 1610 | 1610 | |
| 1611 | 1611 | // ----- Return |
| 1612 | 1612 | return PclZip::errorCode(); |
| 1613 | - } |
|
| 1613 | + } |
|
| 1614 | 1614 | |
| 1615 | - // ----- Get the value |
|
| 1616 | - if (is_string($p_options_list[$i+1])) { |
|
| 1617 | - $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
|
| 1618 | - } |
|
| 1619 | - else { |
|
| 1615 | + // ----- Get the value |
|
| 1616 | + if (is_string($p_options_list[$i+1])) { |
|
| 1617 | + $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
|
| 1618 | + } |
|
| 1619 | + else { |
|
| 1620 | 1620 | // ----- Error log |
| 1621 | 1621 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, |
| 1622 | - "Wrong parameter value for option '" |
|
| 1623 | - .PclZipUtilOptionText($p_options_list[$i]) |
|
| 1624 | - ."'"); |
|
| 1622 | + "Wrong parameter value for option '" |
|
| 1623 | + .PclZipUtilOptionText($p_options_list[$i]) |
|
| 1624 | + ."'"); |
|
| 1625 | 1625 | |
| 1626 | 1626 | // ----- Return |
| 1627 | 1627 | return PclZip::errorCode(); |
| 1628 | - } |
|
| 1629 | - $i++; |
|
| 1628 | + } |
|
| 1629 | + $i++; |
|
| 1630 | 1630 | break; |
| 1631 | 1631 | |
| 1632 | 1632 | // ----- Look for options that request an array of index |
@@ -1638,87 +1638,87 @@ discard block |
||
| 1638 | 1638 | |
| 1639 | 1639 | // ----- Return |
| 1640 | 1640 | return PclZip::errorCode(); |
| 1641 | - } |
|
| 1641 | + } |
|
| 1642 | 1642 | |
| 1643 | - // ----- Get the value |
|
| 1644 | - $v_work_list = array(); |
|
| 1645 | - if (is_string($p_options_list[$i+1])) { |
|
| 1643 | + // ----- Get the value |
|
| 1644 | + $v_work_list = array(); |
|
| 1645 | + if (is_string($p_options_list[$i+1])) { |
|
| 1646 | 1646 | |
| 1647 | - // ----- Remove spaces |
|
| 1648 | - $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', ''); |
|
| 1647 | + // ----- Remove spaces |
|
| 1648 | + $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', ''); |
|
| 1649 | 1649 | |
| 1650 | - // ----- Parse items |
|
| 1651 | - $v_work_list = explode(",", $p_options_list[$i+1]); |
|
| 1652 | - } |
|
| 1653 | - else if (is_integer($p_options_list[$i+1])) { |
|
| 1654 | - $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1]; |
|
| 1655 | - } |
|
| 1656 | - else if (is_array($p_options_list[$i+1])) { |
|
| 1657 | - $v_work_list = $p_options_list[$i+1]; |
|
| 1658 | - } |
|
| 1659 | - else { |
|
| 1650 | + // ----- Parse items |
|
| 1651 | + $v_work_list = explode(",", $p_options_list[$i+1]); |
|
| 1652 | + } |
|
| 1653 | + else if (is_integer($p_options_list[$i+1])) { |
|
| 1654 | + $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1]; |
|
| 1655 | + } |
|
| 1656 | + else if (is_array($p_options_list[$i+1])) { |
|
| 1657 | + $v_work_list = $p_options_list[$i+1]; |
|
| 1658 | + } |
|
| 1659 | + else { |
|
| 1660 | 1660 | // ----- Error log |
| 1661 | 1661 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
| 1662 | 1662 | |
| 1663 | 1663 | // ----- Return |
| 1664 | 1664 | return PclZip::errorCode(); |
| 1665 | - } |
|
| 1665 | + } |
|
| 1666 | 1666 | |
| 1667 | - // ----- Reduce the index list |
|
| 1668 | - // each index item in the list must be a couple with a start and |
|
| 1669 | - // an end value : [0,3], [5-5], [8-10], ... |
|
| 1670 | - // ----- Check the format of each item |
|
| 1671 | - $v_sort_flag=false; |
|
| 1672 | - $v_sort_value=0; |
|
| 1673 | - for ($j=0; $j<sizeof($v_work_list); $j++) { |
|
| 1674 | - // ----- Explode the item |
|
| 1675 | - $v_item_list = explode("-", $v_work_list[$j]); |
|
| 1676 | - $v_size_item_list = sizeof($v_item_list); |
|
| 1667 | + // ----- Reduce the index list |
|
| 1668 | + // each index item in the list must be a couple with a start and |
|
| 1669 | + // an end value : [0,3], [5-5], [8-10], ... |
|
| 1670 | + // ----- Check the format of each item |
|
| 1671 | + $v_sort_flag=false; |
|
| 1672 | + $v_sort_value=0; |
|
| 1673 | + for ($j=0; $j<sizeof($v_work_list); $j++) { |
|
| 1674 | + // ----- Explode the item |
|
| 1675 | + $v_item_list = explode("-", $v_work_list[$j]); |
|
| 1676 | + $v_size_item_list = sizeof($v_item_list); |
|
| 1677 | 1677 | |
| 1678 | - // ----- TBC : Here we might check that each item is a |
|
| 1679 | - // real integer ... |
|
| 1678 | + // ----- TBC : Here we might check that each item is a |
|
| 1679 | + // real integer ... |
|
| 1680 | 1680 | |
| 1681 | - // ----- Look for single value |
|
| 1682 | - if ($v_size_item_list == 1) { |
|
| 1683 | - // ----- Set the option value |
|
| 1684 | - $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; |
|
| 1685 | - $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0]; |
|
| 1686 | - } |
|
| 1687 | - elseif ($v_size_item_list == 2) { |
|
| 1688 | - // ----- Set the option value |
|
| 1689 | - $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; |
|
| 1690 | - $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1]; |
|
| 1691 | - } |
|
| 1692 | - else { |
|
| 1693 | - // ----- Error log |
|
| 1694 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1695 | - |
|
| 1696 | - // ----- Return |
|
| 1697 | - return PclZip::errorCode(); |
|
| 1698 | - } |
|
| 1699 | - |
|
| 1700 | - |
|
| 1701 | - // ----- Look for list sort |
|
| 1702 | - if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) { |
|
| 1703 | - $v_sort_flag=true; |
|
| 1704 | - |
|
| 1705 | - // ----- TBC : An automatic sort should be writen ... |
|
| 1706 | - // ----- Error log |
|
| 1707 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1708 | - |
|
| 1709 | - // ----- Return |
|
| 1710 | - return PclZip::errorCode(); |
|
| 1711 | - } |
|
| 1712 | - $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start']; |
|
| 1713 | - } |
|
| 1681 | + // ----- Look for single value |
|
| 1682 | + if ($v_size_item_list == 1) { |
|
| 1683 | + // ----- Set the option value |
|
| 1684 | + $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; |
|
| 1685 | + $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0]; |
|
| 1686 | + } |
|
| 1687 | + elseif ($v_size_item_list == 2) { |
|
| 1688 | + // ----- Set the option value |
|
| 1689 | + $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; |
|
| 1690 | + $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1]; |
|
| 1691 | + } |
|
| 1692 | + else { |
|
| 1693 | + // ----- Error log |
|
| 1694 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1695 | + |
|
| 1696 | + // ----- Return |
|
| 1697 | + return PclZip::errorCode(); |
|
| 1698 | + } |
|
| 1699 | + |
|
| 1700 | + |
|
| 1701 | + // ----- Look for list sort |
|
| 1702 | + if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) { |
|
| 1703 | + $v_sort_flag=true; |
|
| 1704 | + |
|
| 1705 | + // ----- TBC : An automatic sort should be writen ... |
|
| 1706 | + // ----- Error log |
|
| 1707 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Invalid order of index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
|
| 1708 | + |
|
| 1709 | + // ----- Return |
|
| 1710 | + return PclZip::errorCode(); |
|
| 1711 | + } |
|
| 1712 | + $v_sort_value = $v_result_list[$p_options_list[$i]][$j]['start']; |
|
| 1713 | + } |
|
| 1714 | 1714 | |
| 1715 | - // ----- Sort the items |
|
| 1716 | - if ($v_sort_flag) { |
|
| 1717 | - // TBC : To Be Completed |
|
| 1718 | - } |
|
| 1715 | + // ----- Sort the items |
|
| 1716 | + if ($v_sort_flag) { |
|
| 1717 | + // TBC : To Be Completed |
|
| 1718 | + } |
|
| 1719 | 1719 | |
| 1720 | - // ----- Next option |
|
| 1721 | - $i++; |
|
| 1720 | + // ----- Next option |
|
| 1721 | + $i++; |
|
| 1722 | 1722 | break; |
| 1723 | 1723 | |
| 1724 | 1724 | // ----- Look for options that request no value |
@@ -1740,11 +1740,11 @@ discard block |
||
| 1740 | 1740 | |
| 1741 | 1741 | // ----- Return |
| 1742 | 1742 | return PclZip::errorCode(); |
| 1743 | - } |
|
| 1743 | + } |
|
| 1744 | 1744 | |
| 1745 | - // ----- Get the value |
|
| 1746 | - $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
|
| 1747 | - $i++; |
|
| 1745 | + // ----- Get the value |
|
| 1746 | + $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
|
| 1747 | + $i++; |
|
| 1748 | 1748 | break; |
| 1749 | 1749 | |
| 1750 | 1750 | // ----- Look for options that request a call-back |
@@ -1765,54 +1765,54 @@ discard block |
||
| 1765 | 1765 | |
| 1766 | 1766 | // ----- Return |
| 1767 | 1767 | return PclZip::errorCode(); |
| 1768 | - } |
|
| 1768 | + } |
|
| 1769 | 1769 | |
| 1770 | - // ----- Get the value |
|
| 1771 | - $v_function_name = $p_options_list[$i+1]; |
|
| 1770 | + // ----- Get the value |
|
| 1771 | + $v_function_name = $p_options_list[$i+1]; |
|
| 1772 | 1772 | |
| 1773 | - // ----- Check that the value is a valid existing function |
|
| 1774 | - if (!function_exists($v_function_name)) { |
|
| 1773 | + // ----- Check that the value is a valid existing function |
|
| 1774 | + if (!function_exists($v_function_name)) { |
|
| 1775 | 1775 | // ----- Error log |
| 1776 | 1776 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
| 1777 | 1777 | |
| 1778 | 1778 | // ----- Return |
| 1779 | 1779 | return PclZip::errorCode(); |
| 1780 | - } |
|
| 1780 | + } |
|
| 1781 | 1781 | |
| 1782 | - // ----- Set the attribute |
|
| 1783 | - $v_result_list[$p_options_list[$i]] = $v_function_name; |
|
| 1784 | - $i++; |
|
| 1782 | + // ----- Set the attribute |
|
| 1783 | + $v_result_list[$p_options_list[$i]] = $v_function_name; |
|
| 1784 | + $i++; |
|
| 1785 | 1785 | break; |
| 1786 | 1786 | |
| 1787 | 1787 | default : |
| 1788 | 1788 | // ----- Error log |
| 1789 | 1789 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, |
| 1790 | - "Unknown parameter '" |
|
| 1791 | - .$p_options_list[$i]."'"); |
|
| 1790 | + "Unknown parameter '" |
|
| 1791 | + .$p_options_list[$i]."'"); |
|
| 1792 | 1792 | |
| 1793 | - // ----- Return |
|
| 1794 | - return PclZip::errorCode(); |
|
| 1795 | - } |
|
| 1793 | + // ----- Return |
|
| 1794 | + return PclZip::errorCode(); |
|
| 1795 | + } |
|
| 1796 | 1796 | |
| 1797 | - // ----- Next options |
|
| 1798 | - $i++; |
|
| 1797 | + // ----- Next options |
|
| 1798 | + $i++; |
|
| 1799 | 1799 | } |
| 1800 | 1800 | |
| 1801 | 1801 | // ----- Look for mandatory options |
| 1802 | 1802 | if ($v_requested_options !== false) { |
| 1803 | - for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { |
|
| 1803 | + for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { |
|
| 1804 | 1804 | // ----- Look for mandatory option |
| 1805 | 1805 | if ($v_requested_options[$key] == 'mandatory') { |
| 1806 | - // ----- Look if present |
|
| 1807 | - if (!isset($v_result_list[$key])) { |
|
| 1806 | + // ----- Look if present |
|
| 1807 | + if (!isset($v_result_list[$key])) { |
|
| 1808 | 1808 | // ----- Error log |
| 1809 | 1809 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); |
| 1810 | 1810 | |
| 1811 | 1811 | // ----- Return |
| 1812 | 1812 | return PclZip::errorCode(); |
| 1813 | - } |
|
| 1813 | + } |
|
| 1814 | + } |
|
| 1814 | 1815 | } |
| 1815 | - } |
|
| 1816 | 1816 | } |
| 1817 | 1817 | |
| 1818 | 1818 | // ----- Look for default values |
@@ -1822,22 +1822,22 @@ discard block |
||
| 1822 | 1822 | |
| 1823 | 1823 | // ----- Return |
| 1824 | 1824 | return $v_result; |
| 1825 | - } |
|
| 1826 | - // -------------------------------------------------------------------------------- |
|
| 1827 | - |
|
| 1828 | - // -------------------------------------------------------------------------------- |
|
| 1829 | - // Function : privOptionDefaultThreshold() |
|
| 1830 | - // Description : |
|
| 1831 | - // Parameters : |
|
| 1832 | - // Return Values : |
|
| 1833 | - // -------------------------------------------------------------------------------- |
|
| 1834 | - function privOptionDefaultThreshold(&$p_options) |
|
| 1835 | - { |
|
| 1825 | + } |
|
| 1826 | + // -------------------------------------------------------------------------------- |
|
| 1827 | + |
|
| 1828 | + // -------------------------------------------------------------------------------- |
|
| 1829 | + // Function : privOptionDefaultThreshold() |
|
| 1830 | + // Description : |
|
| 1831 | + // Parameters : |
|
| 1832 | + // Return Values : |
|
| 1833 | + // -------------------------------------------------------------------------------- |
|
| 1834 | + function privOptionDefaultThreshold(&$p_options) |
|
| 1835 | + { |
|
| 1836 | 1836 | $v_result=1; |
| 1837 | 1837 | |
| 1838 | 1838 | if (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) |
| 1839 | 1839 | || isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) { |
| 1840 | - return $v_result; |
|
| 1840 | + return $v_result; |
|
| 1841 | 1841 | } |
| 1842 | 1842 | |
| 1843 | 1843 | // ----- Get 'memory_limit' configuration value |
@@ -1859,52 +1859,52 @@ discard block |
||
| 1859 | 1859 | |
| 1860 | 1860 | // ----- Sanity check : No threshold if value lower than 1M |
| 1861 | 1861 | if ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] < 1048576) { |
| 1862 | - unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]); |
|
| 1862 | + unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]); |
|
| 1863 | 1863 | } |
| 1864 | 1864 | |
| 1865 | 1865 | // ----- Return |
| 1866 | 1866 | return $v_result; |
| 1867 | - } |
|
| 1868 | - // -------------------------------------------------------------------------------- |
|
| 1869 | - |
|
| 1870 | - // -------------------------------------------------------------------------------- |
|
| 1871 | - // Function : privFileDescrParseAtt() |
|
| 1872 | - // Description : |
|
| 1873 | - // Parameters : |
|
| 1874 | - // Return Values : |
|
| 1875 | - // 1 on success. |
|
| 1876 | - // 0 on failure. |
|
| 1877 | - // -------------------------------------------------------------------------------- |
|
| 1878 | - function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false) |
|
| 1879 | - { |
|
| 1867 | + } |
|
| 1868 | + // -------------------------------------------------------------------------------- |
|
| 1869 | + |
|
| 1870 | + // -------------------------------------------------------------------------------- |
|
| 1871 | + // Function : privFileDescrParseAtt() |
|
| 1872 | + // Description : |
|
| 1873 | + // Parameters : |
|
| 1874 | + // Return Values : |
|
| 1875 | + // 1 on success. |
|
| 1876 | + // 0 on failure. |
|
| 1877 | + // -------------------------------------------------------------------------------- |
|
| 1878 | + function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false) |
|
| 1879 | + { |
|
| 1880 | 1880 | $v_result=1; |
| 1881 | 1881 | |
| 1882 | 1882 | // ----- For each file in the list check the attributes |
| 1883 | 1883 | foreach ($p_file_list as $v_key => $v_value) { |
| 1884 | 1884 | |
| 1885 | - // ----- Check if the option is supported |
|
| 1886 | - if (!isset($v_requested_options[$v_key])) { |
|
| 1885 | + // ----- Check if the option is supported |
|
| 1886 | + if (!isset($v_requested_options[$v_key])) { |
|
| 1887 | 1887 | // ----- Error log |
| 1888 | 1888 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file"); |
| 1889 | 1889 | |
| 1890 | 1890 | // ----- Return |
| 1891 | 1891 | return PclZip::errorCode(); |
| 1892 | - } |
|
| 1892 | + } |
|
| 1893 | 1893 | |
| 1894 | - // ----- Look for attribute |
|
| 1895 | - switch ($v_key) { |
|
| 1894 | + // ----- Look for attribute |
|
| 1895 | + switch ($v_key) { |
|
| 1896 | 1896 | case PCLZIP_ATT_FILE_NAME : |
| 1897 | 1897 | if (!is_string($v_value)) { |
| 1898 | 1898 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
| 1899 | 1899 | return PclZip::errorCode(); |
| 1900 | - } |
|
| 1900 | + } |
|
| 1901 | 1901 | |
| 1902 | - $p_filedescr['filename'] = PclZipUtilPathReduction($v_value); |
|
| 1902 | + $p_filedescr['filename'] = PclZipUtilPathReduction($v_value); |
|
| 1903 | 1903 | |
| 1904 | - if ($p_filedescr['filename'] == '') { |
|
| 1904 | + if ($p_filedescr['filename'] == '') { |
|
| 1905 | 1905 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'"); |
| 1906 | 1906 | return PclZip::errorCode(); |
| 1907 | - } |
|
| 1907 | + } |
|
| 1908 | 1908 | |
| 1909 | 1909 | break; |
| 1910 | 1910 | |
@@ -1912,28 +1912,28 @@ discard block |
||
| 1912 | 1912 | if (!is_string($v_value)) { |
| 1913 | 1913 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
| 1914 | 1914 | return PclZip::errorCode(); |
| 1915 | - } |
|
| 1915 | + } |
|
| 1916 | 1916 | |
| 1917 | - $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value); |
|
| 1917 | + $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value); |
|
| 1918 | 1918 | |
| 1919 | - if ($p_filedescr['new_short_name'] == '') { |
|
| 1919 | + if ($p_filedescr['new_short_name'] == '') { |
|
| 1920 | 1920 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'"); |
| 1921 | 1921 | return PclZip::errorCode(); |
| 1922 | - } |
|
| 1922 | + } |
|
| 1923 | 1923 | break; |
| 1924 | 1924 | |
| 1925 | 1925 | case PCLZIP_ATT_FILE_NEW_FULL_NAME : |
| 1926 | 1926 | if (!is_string($v_value)) { |
| 1927 | 1927 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
| 1928 | 1928 | return PclZip::errorCode(); |
| 1929 | - } |
|
| 1929 | + } |
|
| 1930 | 1930 | |
| 1931 | - $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value); |
|
| 1931 | + $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value); |
|
| 1932 | 1932 | |
| 1933 | - if ($p_filedescr['new_full_name'] == '') { |
|
| 1933 | + if ($p_filedescr['new_full_name'] == '') { |
|
| 1934 | 1934 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'"); |
| 1935 | 1935 | return PclZip::errorCode(); |
| 1936 | - } |
|
| 1936 | + } |
|
| 1937 | 1937 | break; |
| 1938 | 1938 | |
| 1939 | 1939 | // ----- Look for options that takes a string |
@@ -1941,18 +1941,18 @@ discard block |
||
| 1941 | 1941 | if (!is_string($v_value)) { |
| 1942 | 1942 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
| 1943 | 1943 | return PclZip::errorCode(); |
| 1944 | - } |
|
| 1944 | + } |
|
| 1945 | 1945 | |
| 1946 | - $p_filedescr['comment'] = $v_value; |
|
| 1946 | + $p_filedescr['comment'] = $v_value; |
|
| 1947 | 1947 | break; |
| 1948 | 1948 | |
| 1949 | 1949 | case PCLZIP_ATT_FILE_MTIME : |
| 1950 | 1950 | if (!is_integer($v_value)) { |
| 1951 | 1951 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'"); |
| 1952 | 1952 | return PclZip::errorCode(); |
| 1953 | - } |
|
| 1953 | + } |
|
| 1954 | 1954 | |
| 1955 | - $p_filedescr['mtime'] = $v_value; |
|
| 1955 | + $p_filedescr['mtime'] = $v_value; |
|
| 1956 | 1956 | break; |
| 1957 | 1957 | |
| 1958 | 1958 | case PCLZIP_ATT_FILE_CONTENT : |
@@ -1962,50 +1962,50 @@ discard block |
||
| 1962 | 1962 | default : |
| 1963 | 1963 | // ----- Error log |
| 1964 | 1964 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, |
| 1965 | - "Unknown parameter '".$v_key."'"); |
|
| 1965 | + "Unknown parameter '".$v_key."'"); |
|
| 1966 | 1966 | |
| 1967 | - // ----- Return |
|
| 1968 | - return PclZip::errorCode(); |
|
| 1969 | - } |
|
| 1967 | + // ----- Return |
|
| 1968 | + return PclZip::errorCode(); |
|
| 1969 | + } |
|
| 1970 | 1970 | |
| 1971 | - // ----- Look for mandatory options |
|
| 1972 | - if ($v_requested_options !== false) { |
|
| 1971 | + // ----- Look for mandatory options |
|
| 1972 | + if ($v_requested_options !== false) { |
|
| 1973 | 1973 | for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { |
| 1974 | - // ----- Look for mandatory option |
|
| 1975 | - if ($v_requested_options[$key] == 'mandatory') { |
|
| 1974 | + // ----- Look for mandatory option |
|
| 1975 | + if ($v_requested_options[$key] == 'mandatory') { |
|
| 1976 | 1976 | // ----- Look if present |
| 1977 | 1977 | if (!isset($p_file_list[$key])) { |
| 1978 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); |
|
| 1979 | - return PclZip::errorCode(); |
|
| 1978 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")"); |
|
| 1979 | + return PclZip::errorCode(); |
|
| 1980 | + } |
|
| 1980 | 1981 | } |
| 1981 | - } |
|
| 1982 | 1982 | } |
| 1983 | - } |
|
| 1983 | + } |
|
| 1984 | 1984 | |
| 1985 | 1985 | // end foreach |
| 1986 | 1986 | } |
| 1987 | 1987 | |
| 1988 | 1988 | // ----- Return |
| 1989 | 1989 | return $v_result; |
| 1990 | - } |
|
| 1991 | - // -------------------------------------------------------------------------------- |
|
| 1992 | - |
|
| 1993 | - // -------------------------------------------------------------------------------- |
|
| 1994 | - // Function : privFileDescrExpand() |
|
| 1995 | - // Description : |
|
| 1996 | - // This method look for each item of the list to see if its a file, a folder |
|
| 1997 | - // or a string to be added as file. For any other type of files (link, other) |
|
| 1998 | - // just ignore the item. |
|
| 1999 | - // Then prepare the information that will be stored for that file. |
|
| 2000 | - // When its a folder, expand the folder with all the files that are in that |
|
| 2001 | - // folder (recursively). |
|
| 2002 | - // Parameters : |
|
| 2003 | - // Return Values : |
|
| 2004 | - // 1 on success. |
|
| 2005 | - // 0 on failure. |
|
| 2006 | - // -------------------------------------------------------------------------------- |
|
| 2007 | - function privFileDescrExpand(&$p_filedescr_list, &$p_options) |
|
| 2008 | - { |
|
| 1990 | + } |
|
| 1991 | + // -------------------------------------------------------------------------------- |
|
| 1992 | + |
|
| 1993 | + // -------------------------------------------------------------------------------- |
|
| 1994 | + // Function : privFileDescrExpand() |
|
| 1995 | + // Description : |
|
| 1996 | + // This method look for each item of the list to see if its a file, a folder |
|
| 1997 | + // or a string to be added as file. For any other type of files (link, other) |
|
| 1998 | + // just ignore the item. |
|
| 1999 | + // Then prepare the information that will be stored for that file. |
|
| 2000 | + // When its a folder, expand the folder with all the files that are in that |
|
| 2001 | + // folder (recursively). |
|
| 2002 | + // Parameters : |
|
| 2003 | + // Return Values : |
|
| 2004 | + // 1 on success. |
|
| 2005 | + // 0 on failure. |
|
| 2006 | + // -------------------------------------------------------------------------------- |
|
| 2007 | + function privFileDescrExpand(&$p_filedescr_list, &$p_options) |
|
| 2008 | + { |
|
| 2009 | 2009 | $v_result=1; |
| 2010 | 2010 | |
| 2011 | 2011 | // ----- Create a result list |
@@ -2014,58 +2014,58 @@ discard block |
||
| 2014 | 2014 | // ----- Look each entry |
| 2015 | 2015 | for ($i=0; $i<sizeof($p_filedescr_list); $i++) { |
| 2016 | 2016 | |
| 2017 | - // ----- Get filedescr |
|
| 2018 | - $v_descr = $p_filedescr_list[$i]; |
|
| 2017 | + // ----- Get filedescr |
|
| 2018 | + $v_descr = $p_filedescr_list[$i]; |
|
| 2019 | 2019 | |
| 2020 | - // ----- Reduce the filename |
|
| 2021 | - $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false); |
|
| 2022 | - $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']); |
|
| 2020 | + // ----- Reduce the filename |
|
| 2021 | + $v_descr['filename'] = PclZipUtilTranslateWinPath($v_descr['filename'], false); |
|
| 2022 | + $v_descr['filename'] = PclZipUtilPathReduction($v_descr['filename']); |
|
| 2023 | 2023 | |
| 2024 | - // ----- Look for real file or folder |
|
| 2025 | - if (file_exists($v_descr['filename'])) { |
|
| 2024 | + // ----- Look for real file or folder |
|
| 2025 | + if (file_exists($v_descr['filename'])) { |
|
| 2026 | 2026 | if (@is_file($v_descr['filename'])) { |
| 2027 | - $v_descr['type'] = 'file'; |
|
| 2027 | + $v_descr['type'] = 'file'; |
|
| 2028 | 2028 | } |
| 2029 | 2029 | else if (@is_dir($v_descr['filename'])) { |
| 2030 | - $v_descr['type'] = 'folder'; |
|
| 2030 | + $v_descr['type'] = 'folder'; |
|
| 2031 | 2031 | } |
| 2032 | 2032 | else if (@is_link($v_descr['filename'])) { |
| 2033 | - // skip |
|
| 2034 | - continue; |
|
| 2033 | + // skip |
|
| 2034 | + continue; |
|
| 2035 | 2035 | } |
| 2036 | 2036 | else { |
| 2037 | - // skip |
|
| 2038 | - continue; |
|
| 2037 | + // skip |
|
| 2038 | + continue; |
|
| 2039 | + } |
|
| 2039 | 2040 | } |
| 2040 | - } |
|
| 2041 | 2041 | |
| 2042 | - // ----- Look for string added as file |
|
| 2043 | - else if (isset($v_descr['content'])) { |
|
| 2042 | + // ----- Look for string added as file |
|
| 2043 | + else if (isset($v_descr['content'])) { |
|
| 2044 | 2044 | $v_descr['type'] = 'virtual_file'; |
| 2045 | - } |
|
| 2045 | + } |
|
| 2046 | 2046 | |
| 2047 | - // ----- Missing file |
|
| 2048 | - else { |
|
| 2047 | + // ----- Missing file |
|
| 2048 | + else { |
|
| 2049 | 2049 | // ----- Error log |
| 2050 | 2050 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$v_descr['filename']."' does not exist"); |
| 2051 | 2051 | |
| 2052 | 2052 | // ----- Return |
| 2053 | 2053 | return PclZip::errorCode(); |
| 2054 | - } |
|
| 2054 | + } |
|
| 2055 | 2055 | |
| 2056 | - // ----- Calculate the stored filename |
|
| 2057 | - $this->privCalculateStoredFilename($v_descr, $p_options); |
|
| 2056 | + // ----- Calculate the stored filename |
|
| 2057 | + $this->privCalculateStoredFilename($v_descr, $p_options); |
|
| 2058 | 2058 | |
| 2059 | - // ----- Add the descriptor in result list |
|
| 2060 | - $v_result_list[sizeof($v_result_list)] = $v_descr; |
|
| 2059 | + // ----- Add the descriptor in result list |
|
| 2060 | + $v_result_list[sizeof($v_result_list)] = $v_descr; |
|
| 2061 | 2061 | |
| 2062 | - // ----- Look for folder |
|
| 2063 | - if ($v_descr['type'] == 'folder') { |
|
| 2062 | + // ----- Look for folder |
|
| 2063 | + if ($v_descr['type'] == 'folder') { |
|
| 2064 | 2064 | // ----- List of items in folder |
| 2065 | 2065 | $v_dirlist_descr = array(); |
| 2066 | 2066 | $v_dirlist_nb = 0; |
| 2067 | 2067 | if ($v_folder_handler = @opendir($v_descr['filename'])) { |
| 2068 | - while (($v_item_handler = @readdir($v_folder_handler)) !== false) { |
|
| 2068 | + while (($v_item_handler = @readdir($v_folder_handler)) !== false) { |
|
| 2069 | 2069 | |
| 2070 | 2070 | // ----- Skip '.' and '..' |
| 2071 | 2071 | if (($v_item_handler == '.') || ($v_item_handler == '..')) { |
@@ -2080,39 +2080,39 @@ discard block |
||
| 2080 | 2080 | // files/sub-folders also change |
| 2081 | 2081 | if (($v_descr['stored_filename'] != $v_descr['filename']) |
| 2082 | 2082 | && (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) { |
| 2083 | - if ($v_descr['stored_filename'] != '') { |
|
| 2083 | + if ($v_descr['stored_filename'] != '') { |
|
| 2084 | 2084 | $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler; |
| 2085 | - } |
|
| 2086 | - else { |
|
| 2085 | + } |
|
| 2086 | + else { |
|
| 2087 | 2087 | $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler; |
| 2088 | - } |
|
| 2088 | + } |
|
| 2089 | 2089 | } |
| 2090 | 2090 | |
| 2091 | 2091 | $v_dirlist_nb++; |
| 2092 | - } |
|
| 2092 | + } |
|
| 2093 | 2093 | |
| 2094 | - @closedir($v_folder_handler); |
|
| 2094 | + @closedir($v_folder_handler); |
|
| 2095 | 2095 | } |
| 2096 | 2096 | else { |
| 2097 | - // TBC : unable to open folder in read mode |
|
| 2097 | + // TBC : unable to open folder in read mode |
|
| 2098 | 2098 | } |
| 2099 | 2099 | |
| 2100 | 2100 | // ----- Expand each element of the list |
| 2101 | 2101 | if ($v_dirlist_nb != 0) { |
| 2102 | - // ----- Expand |
|
| 2103 | - if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) { |
|
| 2102 | + // ----- Expand |
|
| 2103 | + if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) { |
|
| 2104 | 2104 | return $v_result; |
| 2105 | - } |
|
| 2105 | + } |
|
| 2106 | 2106 | |
| 2107 | - // ----- Concat the resulting list |
|
| 2108 | - $v_result_list = array_merge($v_result_list, $v_dirlist_descr); |
|
| 2107 | + // ----- Concat the resulting list |
|
| 2108 | + $v_result_list = array_merge($v_result_list, $v_dirlist_descr); |
|
| 2109 | 2109 | } |
| 2110 | 2110 | else { |
| 2111 | 2111 | } |
| 2112 | 2112 | |
| 2113 | 2113 | // ----- Free local array |
| 2114 | 2114 | unset($v_dirlist_descr); |
| 2115 | - } |
|
| 2115 | + } |
|
| 2116 | 2116 | } |
| 2117 | 2117 | |
| 2118 | 2118 | // ----- Get the result list |
@@ -2120,17 +2120,17 @@ discard block |
||
| 2120 | 2120 | |
| 2121 | 2121 | // ----- Return |
| 2122 | 2122 | return $v_result; |
| 2123 | - } |
|
| 2124 | - // -------------------------------------------------------------------------------- |
|
| 2125 | - |
|
| 2126 | - // -------------------------------------------------------------------------------- |
|
| 2127 | - // Function : privCreate() |
|
| 2128 | - // Description : |
|
| 2129 | - // Parameters : |
|
| 2130 | - // Return Values : |
|
| 2131 | - // -------------------------------------------------------------------------------- |
|
| 2132 | - function privCreate($p_filedescr_list, &$p_result_list, &$p_options) |
|
| 2133 | - { |
|
| 2123 | + } |
|
| 2124 | + // -------------------------------------------------------------------------------- |
|
| 2125 | + |
|
| 2126 | + // -------------------------------------------------------------------------------- |
|
| 2127 | + // Function : privCreate() |
|
| 2128 | + // Description : |
|
| 2129 | + // Parameters : |
|
| 2130 | + // Return Values : |
|
| 2131 | + // -------------------------------------------------------------------------------- |
|
| 2132 | + function privCreate($p_filedescr_list, &$p_result_list, &$p_options) |
|
| 2133 | + { |
|
| 2134 | 2134 | $v_result=1; |
| 2135 | 2135 | $v_list_detail = array(); |
| 2136 | 2136 | |
@@ -2140,8 +2140,8 @@ discard block |
||
| 2140 | 2140 | // ----- Open the file in write mode |
| 2141 | 2141 | if (($v_result = $this->privOpenFd('wb')) != 1) |
| 2142 | 2142 | { |
| 2143 | - // ----- Return |
|
| 2144 | - return $v_result; |
|
| 2143 | + // ----- Return |
|
| 2144 | + return $v_result; |
|
| 2145 | 2145 | } |
| 2146 | 2146 | |
| 2147 | 2147 | // ----- Add the list of files |
@@ -2155,17 +2155,17 @@ discard block |
||
| 2155 | 2155 | |
| 2156 | 2156 | // ----- Return |
| 2157 | 2157 | return $v_result; |
| 2158 | - } |
|
| 2159 | - // -------------------------------------------------------------------------------- |
|
| 2160 | - |
|
| 2161 | - // -------------------------------------------------------------------------------- |
|
| 2162 | - // Function : privAdd() |
|
| 2163 | - // Description : |
|
| 2164 | - // Parameters : |
|
| 2165 | - // Return Values : |
|
| 2166 | - // -------------------------------------------------------------------------------- |
|
| 2167 | - function privAdd($p_filedescr_list, &$p_result_list, &$p_options) |
|
| 2168 | - { |
|
| 2158 | + } |
|
| 2159 | + // -------------------------------------------------------------------------------- |
|
| 2160 | + |
|
| 2161 | + // -------------------------------------------------------------------------------- |
|
| 2162 | + // Function : privAdd() |
|
| 2163 | + // Description : |
|
| 2164 | + // Parameters : |
|
| 2165 | + // Return Values : |
|
| 2166 | + // -------------------------------------------------------------------------------- |
|
| 2167 | + function privAdd($p_filedescr_list, &$p_result_list, &$p_options) |
|
| 2168 | + { |
|
| 2169 | 2169 | $v_result=1; |
| 2170 | 2170 | $v_list_detail = array(); |
| 2171 | 2171 | |
@@ -2173,11 +2173,11 @@ discard block |
||
| 2173 | 2173 | if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0)) |
| 2174 | 2174 | { |
| 2175 | 2175 | |
| 2176 | - // ----- Do a create |
|
| 2177 | - $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options); |
|
| 2176 | + // ----- Do a create |
|
| 2177 | + $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options); |
|
| 2178 | 2178 | |
| 2179 | - // ----- Return |
|
| 2180 | - return $v_result; |
|
| 2179 | + // ----- Return |
|
| 2180 | + return $v_result; |
|
| 2181 | 2181 | } |
| 2182 | 2182 | // ----- Magic quotes trick |
| 2183 | 2183 | $this->privDisableMagicQuotes(); |
@@ -2185,20 +2185,20 @@ discard block |
||
| 2185 | 2185 | // ----- Open the zip file |
| 2186 | 2186 | if (($v_result=$this->privOpenFd('rb')) != 1) |
| 2187 | 2187 | { |
| 2188 | - // ----- Magic quotes trick |
|
| 2189 | - $this->privSwapBackMagicQuotes(); |
|
| 2188 | + // ----- Magic quotes trick |
|
| 2189 | + $this->privSwapBackMagicQuotes(); |
|
| 2190 | 2190 | |
| 2191 | - // ----- Return |
|
| 2192 | - return $v_result; |
|
| 2191 | + // ----- Return |
|
| 2192 | + return $v_result; |
|
| 2193 | 2193 | } |
| 2194 | 2194 | |
| 2195 | 2195 | // ----- Read the central directory informations |
| 2196 | 2196 | $v_central_dir = array(); |
| 2197 | 2197 | if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
| 2198 | 2198 | { |
| 2199 | - $this->privCloseFd(); |
|
| 2200 | - $this->privSwapBackMagicQuotes(); |
|
| 2201 | - return $v_result; |
|
| 2199 | + $this->privCloseFd(); |
|
| 2200 | + $this->privSwapBackMagicQuotes(); |
|
| 2201 | + return $v_result; |
|
| 2202 | 2202 | } |
| 2203 | 2203 | |
| 2204 | 2204 | // ----- Go to beginning of File |
@@ -2210,13 +2210,13 @@ discard block |
||
| 2210 | 2210 | // ----- Open the temporary file in write mode |
| 2211 | 2211 | if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) |
| 2212 | 2212 | { |
| 2213 | - $this->privCloseFd(); |
|
| 2214 | - $this->privSwapBackMagicQuotes(); |
|
| 2213 | + $this->privCloseFd(); |
|
| 2214 | + $this->privSwapBackMagicQuotes(); |
|
| 2215 | 2215 | |
| 2216 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); |
|
| 2216 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); |
|
| 2217 | 2217 | |
| 2218 | - // ----- Return |
|
| 2219 | - return PclZip::errorCode(); |
|
| 2218 | + // ----- Return |
|
| 2219 | + return PclZip::errorCode(); |
|
| 2220 | 2220 | } |
| 2221 | 2221 | |
| 2222 | 2222 | // ----- Copy the files from the archive to the temporary file |
@@ -2224,10 +2224,10 @@ discard block |
||
| 2224 | 2224 | $v_size = $v_central_dir['offset']; |
| 2225 | 2225 | while ($v_size != 0) |
| 2226 | 2226 | { |
| 2227 | - $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 2228 | - $v_buffer = fread($this->zip_fd, $v_read_size); |
|
| 2229 | - @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
|
| 2230 | - $v_size -= $v_read_size; |
|
| 2227 | + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 2228 | + $v_buffer = fread($this->zip_fd, $v_read_size); |
|
| 2229 | + @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
|
| 2230 | + $v_size -= $v_read_size; |
|
| 2231 | 2231 | } |
| 2232 | 2232 | |
| 2233 | 2233 | // ----- Swap the file descriptor |
@@ -2241,13 +2241,13 @@ discard block |
||
| 2241 | 2241 | $v_header_list = array(); |
| 2242 | 2242 | if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) |
| 2243 | 2243 | { |
| 2244 | - fclose($v_zip_temp_fd); |
|
| 2245 | - $this->privCloseFd(); |
|
| 2246 | - @unlink($v_zip_temp_name); |
|
| 2247 | - $this->privSwapBackMagicQuotes(); |
|
| 2244 | + fclose($v_zip_temp_fd); |
|
| 2245 | + $this->privCloseFd(); |
|
| 2246 | + @unlink($v_zip_temp_name); |
|
| 2247 | + $this->privSwapBackMagicQuotes(); |
|
| 2248 | 2248 | |
| 2249 | - // ----- Return |
|
| 2250 | - return $v_result; |
|
| 2249 | + // ----- Return |
|
| 2250 | + return $v_result; |
|
| 2251 | 2251 | } |
| 2252 | 2252 | |
| 2253 | 2253 | // ----- Store the offset of the central dir |
@@ -2257,43 +2257,43 @@ discard block |
||
| 2257 | 2257 | $v_size = $v_central_dir['size']; |
| 2258 | 2258 | while ($v_size != 0) |
| 2259 | 2259 | { |
| 2260 | - $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 2261 | - $v_buffer = @fread($v_zip_temp_fd, $v_read_size); |
|
| 2262 | - @fwrite($this->zip_fd, $v_buffer, $v_read_size); |
|
| 2263 | - $v_size -= $v_read_size; |
|
| 2260 | + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 2261 | + $v_buffer = @fread($v_zip_temp_fd, $v_read_size); |
|
| 2262 | + @fwrite($this->zip_fd, $v_buffer, $v_read_size); |
|
| 2263 | + $v_size -= $v_read_size; |
|
| 2264 | 2264 | } |
| 2265 | 2265 | |
| 2266 | 2266 | // ----- Create the Central Dir files header |
| 2267 | 2267 | for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++) |
| 2268 | 2268 | { |
| 2269 | - // ----- Create the file header |
|
| 2270 | - if ($v_header_list[$i]['status'] == 'ok') { |
|
| 2269 | + // ----- Create the file header |
|
| 2270 | + if ($v_header_list[$i]['status'] == 'ok') { |
|
| 2271 | 2271 | if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) { |
| 2272 | - fclose($v_zip_temp_fd); |
|
| 2273 | - $this->privCloseFd(); |
|
| 2274 | - @unlink($v_zip_temp_name); |
|
| 2275 | - $this->privSwapBackMagicQuotes(); |
|
| 2272 | + fclose($v_zip_temp_fd); |
|
| 2273 | + $this->privCloseFd(); |
|
| 2274 | + @unlink($v_zip_temp_name); |
|
| 2275 | + $this->privSwapBackMagicQuotes(); |
|
| 2276 | 2276 | |
| 2277 | - // ----- Return |
|
| 2278 | - return $v_result; |
|
| 2277 | + // ----- Return |
|
| 2278 | + return $v_result; |
|
| 2279 | 2279 | } |
| 2280 | 2280 | $v_count++; |
| 2281 | - } |
|
| 2281 | + } |
|
| 2282 | 2282 | |
| 2283 | - // ----- Transform the header to a 'usable' info |
|
| 2284 | - $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); |
|
| 2283 | + // ----- Transform the header to a 'usable' info |
|
| 2284 | + $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); |
|
| 2285 | 2285 | } |
| 2286 | 2286 | |
| 2287 | 2287 | // ----- Zip file comment |
| 2288 | 2288 | $v_comment = $v_central_dir['comment']; |
| 2289 | 2289 | if (isset($p_options[PCLZIP_OPT_COMMENT])) { |
| 2290 | - $v_comment = $p_options[PCLZIP_OPT_COMMENT]; |
|
| 2290 | + $v_comment = $p_options[PCLZIP_OPT_COMMENT]; |
|
| 2291 | 2291 | } |
| 2292 | 2292 | if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) { |
| 2293 | - $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT]; |
|
| 2293 | + $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT]; |
|
| 2294 | 2294 | } |
| 2295 | 2295 | if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) { |
| 2296 | - $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment; |
|
| 2296 | + $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment; |
|
| 2297 | 2297 | } |
| 2298 | 2298 | |
| 2299 | 2299 | // ----- Calculate the size of the central header |
@@ -2302,12 +2302,12 @@ discard block |
||
| 2302 | 2302 | // ----- Create the central dir footer |
| 2303 | 2303 | if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1) |
| 2304 | 2304 | { |
| 2305 | - // ----- Reset the file list |
|
| 2306 | - unset($v_header_list); |
|
| 2307 | - $this->privSwapBackMagicQuotes(); |
|
| 2305 | + // ----- Reset the file list |
|
| 2306 | + unset($v_header_list); |
|
| 2307 | + $this->privSwapBackMagicQuotes(); |
|
| 2308 | 2308 | |
| 2309 | - // ----- Return |
|
| 2310 | - return $v_result; |
|
| 2309 | + // ----- Return |
|
| 2310 | + return $v_result; |
|
| 2311 | 2311 | } |
| 2312 | 2312 | |
| 2313 | 2313 | // ----- Swap back the file descriptor |
@@ -2335,85 +2335,85 @@ discard block |
||
| 2335 | 2335 | |
| 2336 | 2336 | // ----- Return |
| 2337 | 2337 | return $v_result; |
| 2338 | - } |
|
| 2339 | - // -------------------------------------------------------------------------------- |
|
| 2340 | - |
|
| 2341 | - // -------------------------------------------------------------------------------- |
|
| 2342 | - // Function : privOpenFd() |
|
| 2343 | - // Description : |
|
| 2344 | - // Parameters : |
|
| 2345 | - // -------------------------------------------------------------------------------- |
|
| 2346 | - function privOpenFd($p_mode) |
|
| 2347 | - { |
|
| 2338 | + } |
|
| 2339 | + // -------------------------------------------------------------------------------- |
|
| 2340 | + |
|
| 2341 | + // -------------------------------------------------------------------------------- |
|
| 2342 | + // Function : privOpenFd() |
|
| 2343 | + // Description : |
|
| 2344 | + // Parameters : |
|
| 2345 | + // -------------------------------------------------------------------------------- |
|
| 2346 | + function privOpenFd($p_mode) |
|
| 2347 | + { |
|
| 2348 | 2348 | $v_result=1; |
| 2349 | 2349 | |
| 2350 | 2350 | // ----- Look if already open |
| 2351 | 2351 | if ($this->zip_fd != 0) |
| 2352 | 2352 | { |
| 2353 | - // ----- Error log |
|
| 2354 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open'); |
|
| 2353 | + // ----- Error log |
|
| 2354 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open'); |
|
| 2355 | 2355 | |
| 2356 | - // ----- Return |
|
| 2357 | - return PclZip::errorCode(); |
|
| 2356 | + // ----- Return |
|
| 2357 | + return PclZip::errorCode(); |
|
| 2358 | 2358 | } |
| 2359 | 2359 | |
| 2360 | 2360 | // ----- Open the zip file |
| 2361 | 2361 | if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0) |
| 2362 | 2362 | { |
| 2363 | - // ----- Error log |
|
| 2364 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode'); |
|
| 2363 | + // ----- Error log |
|
| 2364 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode'); |
|
| 2365 | 2365 | |
| 2366 | - // ----- Return |
|
| 2367 | - return PclZip::errorCode(); |
|
| 2366 | + // ----- Return |
|
| 2367 | + return PclZip::errorCode(); |
|
| 2368 | 2368 | } |
| 2369 | 2369 | |
| 2370 | 2370 | // ----- Return |
| 2371 | 2371 | return $v_result; |
| 2372 | - } |
|
| 2373 | - // -------------------------------------------------------------------------------- |
|
| 2374 | - |
|
| 2375 | - // -------------------------------------------------------------------------------- |
|
| 2376 | - // Function : privCloseFd() |
|
| 2377 | - // Description : |
|
| 2378 | - // Parameters : |
|
| 2379 | - // -------------------------------------------------------------------------------- |
|
| 2380 | - function privCloseFd() |
|
| 2381 | - { |
|
| 2372 | + } |
|
| 2373 | + // -------------------------------------------------------------------------------- |
|
| 2374 | + |
|
| 2375 | + // -------------------------------------------------------------------------------- |
|
| 2376 | + // Function : privCloseFd() |
|
| 2377 | + // Description : |
|
| 2378 | + // Parameters : |
|
| 2379 | + // -------------------------------------------------------------------------------- |
|
| 2380 | + function privCloseFd() |
|
| 2381 | + { |
|
| 2382 | 2382 | $v_result=1; |
| 2383 | 2383 | |
| 2384 | 2384 | if ($this->zip_fd != 0) |
| 2385 | - @fclose($this->zip_fd); |
|
| 2385 | + @fclose($this->zip_fd); |
|
| 2386 | 2386 | $this->zip_fd = 0; |
| 2387 | 2387 | |
| 2388 | 2388 | // ----- Return |
| 2389 | 2389 | return $v_result; |
| 2390 | - } |
|
| 2391 | - // -------------------------------------------------------------------------------- |
|
| 2392 | - |
|
| 2393 | - // -------------------------------------------------------------------------------- |
|
| 2394 | - // Function : privAddList() |
|
| 2395 | - // Description : |
|
| 2396 | - // $p_add_dir and $p_remove_dir will give the ability to memorize a path which is |
|
| 2397 | - // different from the real path of the file. This is usefull if you want to have PclTar |
|
| 2398 | - // running in any directory, and memorize relative path from an other directory. |
|
| 2399 | - // Parameters : |
|
| 2400 | - // $p_list : An array containing the file or directory names to add in the tar |
|
| 2401 | - // $p_result_list : list of added files with their properties (specially the status field) |
|
| 2402 | - // $p_add_dir : Path to add in the filename path archived |
|
| 2403 | - // $p_remove_dir : Path to remove in the filename path archived |
|
| 2404 | - // Return Values : |
|
| 2405 | - // -------------------------------------------------------------------------------- |
|
| 2390 | + } |
|
| 2391 | + // -------------------------------------------------------------------------------- |
|
| 2392 | + |
|
| 2393 | + // -------------------------------------------------------------------------------- |
|
| 2394 | + // Function : privAddList() |
|
| 2395 | + // Description : |
|
| 2396 | + // $p_add_dir and $p_remove_dir will give the ability to memorize a path which is |
|
| 2397 | + // different from the real path of the file. This is usefull if you want to have PclTar |
|
| 2398 | + // running in any directory, and memorize relative path from an other directory. |
|
| 2399 | + // Parameters : |
|
| 2400 | + // $p_list : An array containing the file or directory names to add in the tar |
|
| 2401 | + // $p_result_list : list of added files with their properties (specially the status field) |
|
| 2402 | + // $p_add_dir : Path to add in the filename path archived |
|
| 2403 | + // $p_remove_dir : Path to remove in the filename path archived |
|
| 2404 | + // Return Values : |
|
| 2405 | + // -------------------------------------------------------------------------------- |
|
| 2406 | 2406 | // function privAddList($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options) |
| 2407 | - function privAddList($p_filedescr_list, &$p_result_list, &$p_options) |
|
| 2408 | - { |
|
| 2407 | + function privAddList($p_filedescr_list, &$p_result_list, &$p_options) |
|
| 2408 | + { |
|
| 2409 | 2409 | $v_result=1; |
| 2410 | 2410 | |
| 2411 | 2411 | // ----- Add the files |
| 2412 | 2412 | $v_header_list = array(); |
| 2413 | 2413 | if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1) |
| 2414 | 2414 | { |
| 2415 | - // ----- Return |
|
| 2416 | - return $v_result; |
|
| 2415 | + // ----- Return |
|
| 2416 | + return $v_result; |
|
| 2417 | 2417 | } |
| 2418 | 2418 | |
| 2419 | 2419 | // ----- Store the offset of the central dir |
@@ -2422,23 +2422,23 @@ discard block |
||
| 2422 | 2422 | // ----- Create the Central Dir files header |
| 2423 | 2423 | for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++) |
| 2424 | 2424 | { |
| 2425 | - // ----- Create the file header |
|
| 2426 | - if ($v_header_list[$i]['status'] == 'ok') { |
|
| 2425 | + // ----- Create the file header |
|
| 2426 | + if ($v_header_list[$i]['status'] == 'ok') { |
|
| 2427 | 2427 | if (($v_result = $this->privWriteCentralFileHeader($v_header_list[$i])) != 1) { |
| 2428 | - // ----- Return |
|
| 2429 | - return $v_result; |
|
| 2428 | + // ----- Return |
|
| 2429 | + return $v_result; |
|
| 2430 | 2430 | } |
| 2431 | 2431 | $v_count++; |
| 2432 | - } |
|
| 2432 | + } |
|
| 2433 | 2433 | |
| 2434 | - // ----- Transform the header to a 'usable' info |
|
| 2435 | - $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); |
|
| 2434 | + // ----- Transform the header to a 'usable' info |
|
| 2435 | + $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]); |
|
| 2436 | 2436 | } |
| 2437 | 2437 | |
| 2438 | 2438 | // ----- Zip file comment |
| 2439 | 2439 | $v_comment = ''; |
| 2440 | 2440 | if (isset($p_options[PCLZIP_OPT_COMMENT])) { |
| 2441 | - $v_comment = $p_options[PCLZIP_OPT_COMMENT]; |
|
| 2441 | + $v_comment = $p_options[PCLZIP_OPT_COMMENT]; |
|
| 2442 | 2442 | } |
| 2443 | 2443 | |
| 2444 | 2444 | // ----- Calculate the size of the central header |
@@ -2447,29 +2447,29 @@ discard block |
||
| 2447 | 2447 | // ----- Create the central dir footer |
| 2448 | 2448 | if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1) |
| 2449 | 2449 | { |
| 2450 | - // ----- Reset the file list |
|
| 2451 | - unset($v_header_list); |
|
| 2450 | + // ----- Reset the file list |
|
| 2451 | + unset($v_header_list); |
|
| 2452 | 2452 | |
| 2453 | - // ----- Return |
|
| 2454 | - return $v_result; |
|
| 2453 | + // ----- Return |
|
| 2454 | + return $v_result; |
|
| 2455 | 2455 | } |
| 2456 | 2456 | |
| 2457 | 2457 | // ----- Return |
| 2458 | 2458 | return $v_result; |
| 2459 | - } |
|
| 2460 | - // -------------------------------------------------------------------------------- |
|
| 2461 | - |
|
| 2462 | - // -------------------------------------------------------------------------------- |
|
| 2463 | - // Function : privAddFileList() |
|
| 2464 | - // Description : |
|
| 2465 | - // Parameters : |
|
| 2466 | - // $p_filedescr_list : An array containing the file description |
|
| 2467 | - // or directory names to add in the zip |
|
| 2468 | - // $p_result_list : list of added files with their properties (specially the status field) |
|
| 2469 | - // Return Values : |
|
| 2470 | - // -------------------------------------------------------------------------------- |
|
| 2471 | - function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options) |
|
| 2472 | - { |
|
| 2459 | + } |
|
| 2460 | + // -------------------------------------------------------------------------------- |
|
| 2461 | + |
|
| 2462 | + // -------------------------------------------------------------------------------- |
|
| 2463 | + // Function : privAddFileList() |
|
| 2464 | + // Description : |
|
| 2465 | + // Parameters : |
|
| 2466 | + // $p_filedescr_list : An array containing the file description |
|
| 2467 | + // or directory names to add in the zip |
|
| 2468 | + // $p_result_list : list of added files with their properties (specially the status field) |
|
| 2469 | + // Return Values : |
|
| 2470 | + // -------------------------------------------------------------------------------- |
|
| 2471 | + function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options) |
|
| 2472 | + { |
|
| 2473 | 2473 | $v_result=1; |
| 2474 | 2474 | $v_header = array(); |
| 2475 | 2475 | |
@@ -2478,60 +2478,60 @@ discard block |
||
| 2478 | 2478 | |
| 2479 | 2479 | // ----- Loop on the files |
| 2480 | 2480 | for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) { |
| 2481 | - // ----- Format the filename |
|
| 2482 | - $p_filedescr_list[$j]['filename'] |
|
| 2483 | - = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false); |
|
| 2481 | + // ----- Format the filename |
|
| 2482 | + $p_filedescr_list[$j]['filename'] |
|
| 2483 | + = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false); |
|
| 2484 | 2484 | |
| 2485 | 2485 | |
| 2486 | - // ----- Skip empty file names |
|
| 2487 | - // TBC : Can this be possible ? not checked in DescrParseAtt ? |
|
| 2488 | - if ($p_filedescr_list[$j]['filename'] == "") { |
|
| 2486 | + // ----- Skip empty file names |
|
| 2487 | + // TBC : Can this be possible ? not checked in DescrParseAtt ? |
|
| 2488 | + if ($p_filedescr_list[$j]['filename'] == "") { |
|
| 2489 | 2489 | continue; |
| 2490 | - } |
|
| 2490 | + } |
|
| 2491 | 2491 | |
| 2492 | - // ----- Check the filename |
|
| 2493 | - if ( ($p_filedescr_list[$j]['type'] != 'virtual_file') |
|
| 2492 | + // ----- Check the filename |
|
| 2493 | + if ( ($p_filedescr_list[$j]['type'] != 'virtual_file') |
|
| 2494 | 2494 | && (!file_exists($p_filedescr_list[$j]['filename']))) { |
| 2495 | 2495 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exist"); |
| 2496 | 2496 | return PclZip::errorCode(); |
| 2497 | - } |
|
| 2497 | + } |
|
| 2498 | 2498 | |
| 2499 | - // ----- Look if it is a file or a dir with no all path remove option |
|
| 2500 | - // or a dir with all its path removed |
|
| 2499 | + // ----- Look if it is a file or a dir with no all path remove option |
|
| 2500 | + // or a dir with all its path removed |
|
| 2501 | 2501 | // if ( (is_file($p_filedescr_list[$j]['filename'])) |
| 2502 | 2502 | // || ( is_dir($p_filedescr_list[$j]['filename']) |
| 2503 | - if ( ($p_filedescr_list[$j]['type'] == 'file') |
|
| 2503 | + if ( ($p_filedescr_list[$j]['type'] == 'file') |
|
| 2504 | 2504 | || ($p_filedescr_list[$j]['type'] == 'virtual_file') |
| 2505 | 2505 | || ( ($p_filedescr_list[$j]['type'] == 'folder') |
| 2506 | 2506 | && ( !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]) |
| 2507 | 2507 | || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
| 2508 | - ) { |
|
| 2508 | + ) { |
|
| 2509 | 2509 | |
| 2510 | 2510 | // ----- Add the file |
| 2511 | 2511 | $v_result = $this->privAddFile($p_filedescr_list[$j], $v_header, |
| 2512 | - $p_options); |
|
| 2512 | + $p_options); |
|
| 2513 | 2513 | if ($v_result != 1) { |
| 2514 | - return $v_result; |
|
| 2514 | + return $v_result; |
|
| 2515 | 2515 | } |
| 2516 | 2516 | |
| 2517 | 2517 | // ----- Store the file infos |
| 2518 | 2518 | $p_result_list[$v_nb++] = $v_header; |
| 2519 | - } |
|
| 2519 | + } |
|
| 2520 | 2520 | } |
| 2521 | 2521 | |
| 2522 | 2522 | // ----- Return |
| 2523 | 2523 | return $v_result; |
| 2524 | - } |
|
| 2525 | - // -------------------------------------------------------------------------------- |
|
| 2526 | - |
|
| 2527 | - // -------------------------------------------------------------------------------- |
|
| 2528 | - // Function : privAddFile() |
|
| 2529 | - // Description : |
|
| 2530 | - // Parameters : |
|
| 2531 | - // Return Values : |
|
| 2532 | - // -------------------------------------------------------------------------------- |
|
| 2533 | - function privAddFile($p_filedescr, &$p_header, &$p_options) |
|
| 2534 | - { |
|
| 2524 | + } |
|
| 2525 | + // -------------------------------------------------------------------------------- |
|
| 2526 | + |
|
| 2527 | + // -------------------------------------------------------------------------------- |
|
| 2528 | + // Function : privAddFile() |
|
| 2529 | + // Description : |
|
| 2530 | + // Parameters : |
|
| 2531 | + // Return Values : |
|
| 2532 | + // -------------------------------------------------------------------------------- |
|
| 2533 | + function privAddFile($p_filedescr, &$p_header, &$p_options) |
|
| 2534 | + { |
|
| 2535 | 2535 | $v_result=1; |
| 2536 | 2536 | |
| 2537 | 2537 | // ----- Working variable |
@@ -2539,11 +2539,11 @@ discard block |
||
| 2539 | 2539 | |
| 2540 | 2540 | // TBC : Already done in the fileAtt check ... ? |
| 2541 | 2541 | if ($p_filename == "") { |
| 2542 | - // ----- Error log |
|
| 2543 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)"); |
|
| 2542 | + // ----- Error log |
|
| 2543 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)"); |
|
| 2544 | 2544 | |
| 2545 | - // ----- Return |
|
| 2546 | - return PclZip::errorCode(); |
|
| 2545 | + // ----- Return |
|
| 2546 | + return PclZip::errorCode(); |
|
| 2547 | 2547 | } |
| 2548 | 2548 | |
| 2549 | 2549 | // ----- Look for a stored different filename |
@@ -2578,94 +2578,94 @@ discard block |
||
| 2578 | 2578 | |
| 2579 | 2579 | // ----- Look for regular file |
| 2580 | 2580 | if ($p_filedescr['type']=='file') { |
| 2581 | - $p_header['external'] = 0x00000000; |
|
| 2582 | - $p_header['size'] = filesize($p_filename); |
|
| 2581 | + $p_header['external'] = 0x00000000; |
|
| 2582 | + $p_header['size'] = filesize($p_filename); |
|
| 2583 | 2583 | } |
| 2584 | 2584 | |
| 2585 | 2585 | // ----- Look for regular folder |
| 2586 | 2586 | else if ($p_filedescr['type']=='folder') { |
| 2587 | - $p_header['external'] = 0x00000010; |
|
| 2588 | - $p_header['mtime'] = filemtime($p_filename); |
|
| 2589 | - $p_header['size'] = filesize($p_filename); |
|
| 2587 | + $p_header['external'] = 0x00000010; |
|
| 2588 | + $p_header['mtime'] = filemtime($p_filename); |
|
| 2589 | + $p_header['size'] = filesize($p_filename); |
|
| 2590 | 2590 | } |
| 2591 | 2591 | |
| 2592 | 2592 | // ----- Look for virtual file |
| 2593 | 2593 | else if ($p_filedescr['type'] == 'virtual_file') { |
| 2594 | - $p_header['external'] = 0x00000000; |
|
| 2595 | - $p_header['size'] = strlen($p_filedescr['content']); |
|
| 2594 | + $p_header['external'] = 0x00000000; |
|
| 2595 | + $p_header['size'] = strlen($p_filedescr['content']); |
|
| 2596 | 2596 | } |
| 2597 | 2597 | |
| 2598 | 2598 | |
| 2599 | 2599 | // ----- Look for filetime |
| 2600 | 2600 | if (isset($p_filedescr['mtime'])) { |
| 2601 | - $p_header['mtime'] = $p_filedescr['mtime']; |
|
| 2601 | + $p_header['mtime'] = $p_filedescr['mtime']; |
|
| 2602 | 2602 | } |
| 2603 | 2603 | else if ($p_filedescr['type'] == 'virtual_file') { |
| 2604 | - $p_header['mtime'] = time(); |
|
| 2604 | + $p_header['mtime'] = time(); |
|
| 2605 | 2605 | } |
| 2606 | 2606 | else { |
| 2607 | - $p_header['mtime'] = filemtime($p_filename); |
|
| 2607 | + $p_header['mtime'] = filemtime($p_filename); |
|
| 2608 | 2608 | } |
| 2609 | 2609 | |
| 2610 | 2610 | // ------ Look for file comment |
| 2611 | 2611 | if (isset($p_filedescr['comment'])) { |
| 2612 | - $p_header['comment_len'] = strlen($p_filedescr['comment']); |
|
| 2613 | - $p_header['comment'] = $p_filedescr['comment']; |
|
| 2612 | + $p_header['comment_len'] = strlen($p_filedescr['comment']); |
|
| 2613 | + $p_header['comment'] = $p_filedescr['comment']; |
|
| 2614 | 2614 | } |
| 2615 | 2615 | else { |
| 2616 | - $p_header['comment_len'] = 0; |
|
| 2617 | - $p_header['comment'] = ''; |
|
| 2616 | + $p_header['comment_len'] = 0; |
|
| 2617 | + $p_header['comment'] = ''; |
|
| 2618 | 2618 | } |
| 2619 | 2619 | |
| 2620 | 2620 | // ----- Look for pre-add callback |
| 2621 | 2621 | if (isset($p_options[PCLZIP_CB_PRE_ADD])) { |
| 2622 | 2622 | |
| 2623 | - // ----- Generate a local information |
|
| 2624 | - $v_local_header = array(); |
|
| 2625 | - $this->privConvertHeader2FileInfo($p_header, $v_local_header); |
|
| 2623 | + // ----- Generate a local information |
|
| 2624 | + $v_local_header = array(); |
|
| 2625 | + $this->privConvertHeader2FileInfo($p_header, $v_local_header); |
|
| 2626 | 2626 | |
| 2627 | - // ----- Call the callback |
|
| 2628 | - // Here I do not use call_user_func() because I need to send a reference to the |
|
| 2629 | - // header. |
|
| 2627 | + // ----- Call the callback |
|
| 2628 | + // Here I do not use call_user_func() because I need to send a reference to the |
|
| 2629 | + // header. |
|
| 2630 | 2630 | // eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);'); |
| 2631 | - $v_result = $p_options[PCLZIP_CB_PRE_ADD](PCLZIP_CB_PRE_ADD, $v_local_header); |
|
| 2632 | - if ($v_result == 0) { |
|
| 2631 | + $v_result = $p_options[PCLZIP_CB_PRE_ADD](PCLZIP_CB_PRE_ADD, $v_local_header); |
|
| 2632 | + if ($v_result == 0) { |
|
| 2633 | 2633 | // ----- Change the file status |
| 2634 | 2634 | $p_header['status'] = "skipped"; |
| 2635 | 2635 | $v_result = 1; |
| 2636 | - } |
|
| 2636 | + } |
|
| 2637 | 2637 | |
| 2638 | - // ----- Update the informations |
|
| 2639 | - // Only some fields can be modified |
|
| 2640 | - if ($p_header['stored_filename'] != $v_local_header['stored_filename']) { |
|
| 2638 | + // ----- Update the informations |
|
| 2639 | + // Only some fields can be modified |
|
| 2640 | + if ($p_header['stored_filename'] != $v_local_header['stored_filename']) { |
|
| 2641 | 2641 | $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']); |
| 2642 | - } |
|
| 2642 | + } |
|
| 2643 | 2643 | } |
| 2644 | 2644 | |
| 2645 | 2645 | // ----- Look for empty stored filename |
| 2646 | 2646 | if ($p_header['stored_filename'] == "") { |
| 2647 | - $p_header['status'] = "filtered"; |
|
| 2647 | + $p_header['status'] = "filtered"; |
|
| 2648 | 2648 | } |
| 2649 | 2649 | |
| 2650 | 2650 | // ----- Check the path length |
| 2651 | 2651 | if (strlen($p_header['stored_filename']) > 0xFF) { |
| 2652 | - $p_header['status'] = 'filename_too_long'; |
|
| 2652 | + $p_header['status'] = 'filename_too_long'; |
|
| 2653 | 2653 | } |
| 2654 | 2654 | |
| 2655 | 2655 | // ----- Look if no error, or file not skipped |
| 2656 | 2656 | if ($p_header['status'] == 'ok') { |
| 2657 | 2657 | |
| 2658 | - // ----- Look for a file |
|
| 2659 | - if ($p_filedescr['type'] == 'file') { |
|
| 2658 | + // ----- Look for a file |
|
| 2659 | + if ($p_filedescr['type'] == 'file') { |
|
| 2660 | 2660 | // ----- Look for using temporary file to zip |
| 2661 | 2661 | if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) |
| 2662 | 2662 | && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON]) |
| 2663 | 2663 | || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) |
| 2664 | 2664 | && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) { |
| 2665 | - $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options); |
|
| 2666 | - if ($v_result < PCLZIP_ERR_NO_ERROR) { |
|
| 2665 | + $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options); |
|
| 2666 | + if ($v_result < PCLZIP_ERR_NO_ERROR) { |
|
| 2667 | 2667 | return $v_result; |
| 2668 | - } |
|
| 2668 | + } |
|
| 2669 | 2669 | } |
| 2670 | 2670 | |
| 2671 | 2671 | // ----- Use "in memory" zip algo |
@@ -2673,8 +2673,8 @@ discard block |
||
| 2673 | 2673 | |
| 2674 | 2674 | // ----- Open the source file |
| 2675 | 2675 | if (($v_file = @fopen($p_filename, "rb")) == 0) { |
| 2676 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); |
|
| 2677 | - return PclZip::errorCode(); |
|
| 2676 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); |
|
| 2677 | + return PclZip::errorCode(); |
|
| 2678 | 2678 | } |
| 2679 | 2679 | |
| 2680 | 2680 | // ----- Read the file content |
@@ -2688,25 +2688,25 @@ discard block |
||
| 2688 | 2688 | |
| 2689 | 2689 | // ----- Look for no compression |
| 2690 | 2690 | if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { |
| 2691 | - // ----- Set header parameters |
|
| 2692 | - $p_header['compressed_size'] = $p_header['size']; |
|
| 2693 | - $p_header['compression'] = 0; |
|
| 2691 | + // ----- Set header parameters |
|
| 2692 | + $p_header['compressed_size'] = $p_header['size']; |
|
| 2693 | + $p_header['compression'] = 0; |
|
| 2694 | 2694 | } |
| 2695 | 2695 | |
| 2696 | 2696 | // ----- Look for normal compression |
| 2697 | 2697 | else { |
| 2698 | - // ----- Compress the content |
|
| 2699 | - $v_content = @gzdeflate($v_content); |
|
| 2698 | + // ----- Compress the content |
|
| 2699 | + $v_content = @gzdeflate($v_content); |
|
| 2700 | 2700 | |
| 2701 | - // ----- Set header parameters |
|
| 2702 | - $p_header['compressed_size'] = strlen($v_content); |
|
| 2703 | - $p_header['compression'] = 8; |
|
| 2701 | + // ----- Set header parameters |
|
| 2702 | + $p_header['compressed_size'] = strlen($v_content); |
|
| 2703 | + $p_header['compression'] = 8; |
|
| 2704 | 2704 | } |
| 2705 | 2705 | |
| 2706 | 2706 | // ----- Call the header generation |
| 2707 | 2707 | if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { |
| 2708 | - @fclose($v_file); |
|
| 2709 | - return $v_result; |
|
| 2708 | + @fclose($v_file); |
|
| 2709 | + return $v_result; |
|
| 2710 | 2710 | } |
| 2711 | 2711 | |
| 2712 | 2712 | // ----- Write the compressed (or not) content |
@@ -2714,10 +2714,10 @@ discard block |
||
| 2714 | 2714 | |
| 2715 | 2715 | } |
| 2716 | 2716 | |
| 2717 | - } |
|
| 2717 | + } |
|
| 2718 | 2718 | |
| 2719 | - // ----- Look for a virtual file (a file from string) |
|
| 2720 | - else if ($p_filedescr['type'] == 'virtual_file') { |
|
| 2719 | + // ----- Look for a virtual file (a file from string) |
|
| 2720 | + else if ($p_filedescr['type'] == 'virtual_file') { |
|
| 2721 | 2721 | |
| 2722 | 2722 | $v_content = $p_filedescr['content']; |
| 2723 | 2723 | |
@@ -2726,36 +2726,36 @@ discard block |
||
| 2726 | 2726 | |
| 2727 | 2727 | // ----- Look for no compression |
| 2728 | 2728 | if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) { |
| 2729 | - // ----- Set header parameters |
|
| 2730 | - $p_header['compressed_size'] = $p_header['size']; |
|
| 2731 | - $p_header['compression'] = 0; |
|
| 2729 | + // ----- Set header parameters |
|
| 2730 | + $p_header['compressed_size'] = $p_header['size']; |
|
| 2731 | + $p_header['compression'] = 0; |
|
| 2732 | 2732 | } |
| 2733 | 2733 | |
| 2734 | 2734 | // ----- Look for normal compression |
| 2735 | 2735 | else { |
| 2736 | - // ----- Compress the content |
|
| 2737 | - $v_content = @gzdeflate($v_content); |
|
| 2736 | + // ----- Compress the content |
|
| 2737 | + $v_content = @gzdeflate($v_content); |
|
| 2738 | 2738 | |
| 2739 | - // ----- Set header parameters |
|
| 2740 | - $p_header['compressed_size'] = strlen($v_content); |
|
| 2741 | - $p_header['compression'] = 8; |
|
| 2739 | + // ----- Set header parameters |
|
| 2740 | + $p_header['compressed_size'] = strlen($v_content); |
|
| 2741 | + $p_header['compression'] = 8; |
|
| 2742 | 2742 | } |
| 2743 | 2743 | |
| 2744 | 2744 | // ----- Call the header generation |
| 2745 | 2745 | if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { |
| 2746 | - @fclose($v_file); |
|
| 2747 | - return $v_result; |
|
| 2746 | + @fclose($v_file); |
|
| 2747 | + return $v_result; |
|
| 2748 | 2748 | } |
| 2749 | 2749 | |
| 2750 | 2750 | // ----- Write the compressed (or not) content |
| 2751 | 2751 | @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']); |
| 2752 | - } |
|
| 2752 | + } |
|
| 2753 | 2753 | |
| 2754 | - // ----- Look for a directory |
|
| 2755 | - else if ($p_filedescr['type'] == 'folder') { |
|
| 2754 | + // ----- Look for a directory |
|
| 2755 | + else if ($p_filedescr['type'] == 'folder') { |
|
| 2756 | 2756 | // ----- Look for directory last '/' |
| 2757 | 2757 | if (@substr($p_header['stored_filename'], -1) != '/') { |
| 2758 | - $p_header['stored_filename'] .= '/'; |
|
| 2758 | + $p_header['stored_filename'] .= '/'; |
|
| 2759 | 2759 | } |
| 2760 | 2760 | |
| 2761 | 2761 | // ----- Set the file properties |
@@ -2766,45 +2766,45 @@ discard block |
||
| 2766 | 2766 | // ----- Call the header generation |
| 2767 | 2767 | if (($v_result = $this->privWriteFileHeader($p_header)) != 1) |
| 2768 | 2768 | { |
| 2769 | - return $v_result; |
|
| 2769 | + return $v_result; |
|
| 2770 | + } |
|
| 2770 | 2771 | } |
| 2771 | - } |
|
| 2772 | 2772 | } |
| 2773 | 2773 | |
| 2774 | 2774 | // ----- Look for post-add callback |
| 2775 | 2775 | if (isset($p_options[PCLZIP_CB_POST_ADD])) { |
| 2776 | 2776 | |
| 2777 | - // ----- Generate a local information |
|
| 2778 | - $v_local_header = array(); |
|
| 2779 | - $this->privConvertHeader2FileInfo($p_header, $v_local_header); |
|
| 2777 | + // ----- Generate a local information |
|
| 2778 | + $v_local_header = array(); |
|
| 2779 | + $this->privConvertHeader2FileInfo($p_header, $v_local_header); |
|
| 2780 | 2780 | |
| 2781 | - // ----- Call the callback |
|
| 2782 | - // Here I do not use call_user_func() because I need to send a reference to the |
|
| 2783 | - // header. |
|
| 2781 | + // ----- Call the callback |
|
| 2782 | + // Here I do not use call_user_func() because I need to send a reference to the |
|
| 2783 | + // header. |
|
| 2784 | 2784 | // eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);'); |
| 2785 | - $v_result = $p_options[PCLZIP_CB_POST_ADD](PCLZIP_CB_POST_ADD, $v_local_header); |
|
| 2786 | - if ($v_result == 0) { |
|
| 2785 | + $v_result = $p_options[PCLZIP_CB_POST_ADD](PCLZIP_CB_POST_ADD, $v_local_header); |
|
| 2786 | + if ($v_result == 0) { |
|
| 2787 | 2787 | // ----- Ignored |
| 2788 | 2788 | $v_result = 1; |
| 2789 | - } |
|
| 2789 | + } |
|
| 2790 | 2790 | |
| 2791 | - // ----- Update the informations |
|
| 2792 | - // Nothing can be modified |
|
| 2791 | + // ----- Update the informations |
|
| 2792 | + // Nothing can be modified |
|
| 2793 | 2793 | } |
| 2794 | 2794 | |
| 2795 | 2795 | // ----- Return |
| 2796 | 2796 | return $v_result; |
| 2797 | - } |
|
| 2798 | - // -------------------------------------------------------------------------------- |
|
| 2799 | - |
|
| 2800 | - // -------------------------------------------------------------------------------- |
|
| 2801 | - // Function : privAddFileUsingTempFile() |
|
| 2802 | - // Description : |
|
| 2803 | - // Parameters : |
|
| 2804 | - // Return Values : |
|
| 2805 | - // -------------------------------------------------------------------------------- |
|
| 2806 | - function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options) |
|
| 2807 | - { |
|
| 2797 | + } |
|
| 2798 | + // -------------------------------------------------------------------------------- |
|
| 2799 | + |
|
| 2800 | + // -------------------------------------------------------------------------------- |
|
| 2801 | + // Function : privAddFileUsingTempFile() |
|
| 2802 | + // Description : |
|
| 2803 | + // Parameters : |
|
| 2804 | + // Return Values : |
|
| 2805 | + // -------------------------------------------------------------------------------- |
|
| 2806 | + function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options) |
|
| 2807 | + { |
|
| 2808 | 2808 | $v_result=PCLZIP_ERR_NO_ERROR; |
| 2809 | 2809 | |
| 2810 | 2810 | // ----- Working variable |
@@ -2813,26 +2813,26 @@ discard block |
||
| 2813 | 2813 | |
| 2814 | 2814 | // ----- Open the source file |
| 2815 | 2815 | if (($v_file = @fopen($p_filename, "rb")) == 0) { |
| 2816 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); |
|
| 2817 | - return PclZip::errorCode(); |
|
| 2816 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode"); |
|
| 2817 | + return PclZip::errorCode(); |
|
| 2818 | 2818 | } |
| 2819 | 2819 | |
| 2820 | 2820 | // ----- Creates a compressed temporary file |
| 2821 | 2821 | $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz'; |
| 2822 | 2822 | if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) { |
| 2823 | - fclose($v_file); |
|
| 2824 | - PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode'); |
|
| 2825 | - return PclZip::errorCode(); |
|
| 2823 | + fclose($v_file); |
|
| 2824 | + PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode'); |
|
| 2825 | + return PclZip::errorCode(); |
|
| 2826 | 2826 | } |
| 2827 | 2827 | |
| 2828 | 2828 | // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks |
| 2829 | 2829 | $v_size = filesize($p_filename); |
| 2830 | 2830 | while ($v_size != 0) { |
| 2831 | - $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 2832 | - $v_buffer = @fread($v_file, $v_read_size); |
|
| 2833 | - //$v_binary_data = pack('a'.$v_read_size, $v_buffer); |
|
| 2834 | - @gzputs($v_file_compressed, $v_buffer, $v_read_size); |
|
| 2835 | - $v_size -= $v_read_size; |
|
| 2831 | + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 2832 | + $v_buffer = @fread($v_file, $v_read_size); |
|
| 2833 | + //$v_binary_data = pack('a'.$v_read_size, $v_buffer); |
|
| 2834 | + @gzputs($v_file_compressed, $v_buffer, $v_read_size); |
|
| 2835 | + $v_size -= $v_read_size; |
|
| 2836 | 2836 | } |
| 2837 | 2837 | |
| 2838 | 2838 | // ----- Close the file |
@@ -2841,14 +2841,14 @@ discard block |
||
| 2841 | 2841 | |
| 2842 | 2842 | // ----- Check the minimum file size |
| 2843 | 2843 | if (filesize($v_gzip_temp_name) < 18) { |
| 2844 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes'); |
|
| 2845 | - return PclZip::errorCode(); |
|
| 2844 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes'); |
|
| 2845 | + return PclZip::errorCode(); |
|
| 2846 | 2846 | } |
| 2847 | 2847 | |
| 2848 | 2848 | // ----- Extract the compressed attributes |
| 2849 | 2849 | if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) { |
| 2850 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); |
|
| 2851 | - return PclZip::errorCode(); |
|
| 2850 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); |
|
| 2851 | + return PclZip::errorCode(); |
|
| 2852 | 2852 | } |
| 2853 | 2853 | |
| 2854 | 2854 | // ----- Read the gzip file header |
@@ -2874,14 +2874,14 @@ discard block |
||
| 2874 | 2874 | |
| 2875 | 2875 | // ----- Call the header generation |
| 2876 | 2876 | if (($v_result = $this->privWriteFileHeader($p_header)) != 1) { |
| 2877 | - return $v_result; |
|
| 2877 | + return $v_result; |
|
| 2878 | 2878 | } |
| 2879 | 2879 | |
| 2880 | 2880 | // ----- Add the compressed data |
| 2881 | 2881 | if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) |
| 2882 | 2882 | { |
| 2883 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); |
|
| 2884 | - return PclZip::errorCode(); |
|
| 2883 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); |
|
| 2884 | + return PclZip::errorCode(); |
|
| 2885 | 2885 | } |
| 2886 | 2886 | |
| 2887 | 2887 | // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks |
@@ -2889,11 +2889,11 @@ discard block |
||
| 2889 | 2889 | $v_size = $p_header['compressed_size']; |
| 2890 | 2890 | while ($v_size != 0) |
| 2891 | 2891 | { |
| 2892 | - $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 2893 | - $v_buffer = @fread($v_file_compressed, $v_read_size); |
|
| 2894 | - //$v_binary_data = pack('a'.$v_read_size, $v_buffer); |
|
| 2895 | - @fwrite($this->zip_fd, $v_buffer, $v_read_size); |
|
| 2896 | - $v_size -= $v_read_size; |
|
| 2892 | + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 2893 | + $v_buffer = @fread($v_file_compressed, $v_read_size); |
|
| 2894 | + //$v_binary_data = pack('a'.$v_read_size, $v_buffer); |
|
| 2895 | + @fwrite($this->zip_fd, $v_buffer, $v_read_size); |
|
| 2896 | + $v_size -= $v_read_size; |
|
| 2897 | 2897 | } |
| 2898 | 2898 | |
| 2899 | 2899 | // ----- Close the file |
@@ -2904,112 +2904,112 @@ discard block |
||
| 2904 | 2904 | |
| 2905 | 2905 | // ----- Return |
| 2906 | 2906 | return $v_result; |
| 2907 | - } |
|
| 2908 | - // -------------------------------------------------------------------------------- |
|
| 2909 | - |
|
| 2910 | - // -------------------------------------------------------------------------------- |
|
| 2911 | - // Function : privCalculateStoredFilename() |
|
| 2912 | - // Description : |
|
| 2913 | - // Based on file descriptor properties and global options, this method |
|
| 2914 | - // calculate the filename that will be stored in the archive. |
|
| 2915 | - // Parameters : |
|
| 2916 | - // Return Values : |
|
| 2917 | - // -------------------------------------------------------------------------------- |
|
| 2918 | - function privCalculateStoredFilename(&$p_filedescr, &$p_options) |
|
| 2919 | - { |
|
| 2907 | + } |
|
| 2908 | + // -------------------------------------------------------------------------------- |
|
| 2909 | + |
|
| 2910 | + // -------------------------------------------------------------------------------- |
|
| 2911 | + // Function : privCalculateStoredFilename() |
|
| 2912 | + // Description : |
|
| 2913 | + // Based on file descriptor properties and global options, this method |
|
| 2914 | + // calculate the filename that will be stored in the archive. |
|
| 2915 | + // Parameters : |
|
| 2916 | + // Return Values : |
|
| 2917 | + // -------------------------------------------------------------------------------- |
|
| 2918 | + function privCalculateStoredFilename(&$p_filedescr, &$p_options) |
|
| 2919 | + { |
|
| 2920 | 2920 | $v_result=1; |
| 2921 | 2921 | |
| 2922 | 2922 | // ----- Working variables |
| 2923 | 2923 | $p_filename = $p_filedescr['filename']; |
| 2924 | 2924 | if (isset($p_options[PCLZIP_OPT_ADD_PATH])) { |
| 2925 | - $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH]; |
|
| 2925 | + $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH]; |
|
| 2926 | 2926 | } |
| 2927 | 2927 | else { |
| 2928 | - $p_add_dir = ''; |
|
| 2928 | + $p_add_dir = ''; |
|
| 2929 | 2929 | } |
| 2930 | 2930 | if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) { |
| 2931 | - $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH]; |
|
| 2931 | + $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH]; |
|
| 2932 | 2932 | } |
| 2933 | 2933 | else { |
| 2934 | - $p_remove_dir = ''; |
|
| 2934 | + $p_remove_dir = ''; |
|
| 2935 | 2935 | } |
| 2936 | 2936 | if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
| 2937 | - $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH]; |
|
| 2937 | + $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH]; |
|
| 2938 | 2938 | } |
| 2939 | 2939 | else { |
| 2940 | - $p_remove_all_dir = 0; |
|
| 2940 | + $p_remove_all_dir = 0; |
|
| 2941 | 2941 | } |
| 2942 | 2942 | |
| 2943 | 2943 | |
| 2944 | 2944 | // ----- Look for full name change |
| 2945 | 2945 | if (isset($p_filedescr['new_full_name'])) { |
| 2946 | - // ----- Remove drive letter if any |
|
| 2947 | - $v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']); |
|
| 2946 | + // ----- Remove drive letter if any |
|
| 2947 | + $v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']); |
|
| 2948 | 2948 | } |
| 2949 | 2949 | |
| 2950 | 2950 | // ----- Look for path and/or short name change |
| 2951 | 2951 | else { |
| 2952 | 2952 | |
| 2953 | - // ----- Look for short name change |
|
| 2954 | - // Its when we cahnge just the filename but not the path |
|
| 2955 | - if (isset($p_filedescr['new_short_name'])) { |
|
| 2953 | + // ----- Look for short name change |
|
| 2954 | + // Its when we cahnge just the filename but not the path |
|
| 2955 | + if (isset($p_filedescr['new_short_name'])) { |
|
| 2956 | 2956 | $v_path_info = pathinfo($p_filename); |
| 2957 | 2957 | $v_dir = ''; |
| 2958 | 2958 | if ($v_path_info['dirname'] != '') { |
| 2959 | - $v_dir = $v_path_info['dirname'].'/'; |
|
| 2959 | + $v_dir = $v_path_info['dirname'].'/'; |
|
| 2960 | 2960 | } |
| 2961 | 2961 | $v_stored_filename = $v_dir.$p_filedescr['new_short_name']; |
| 2962 | - } |
|
| 2963 | - else { |
|
| 2962 | + } |
|
| 2963 | + else { |
|
| 2964 | 2964 | // ----- Calculate the stored filename |
| 2965 | 2965 | $v_stored_filename = $p_filename; |
| 2966 | - } |
|
| 2966 | + } |
|
| 2967 | 2967 | |
| 2968 | - // ----- Look for all path to remove |
|
| 2969 | - if ($p_remove_all_dir) { |
|
| 2968 | + // ----- Look for all path to remove |
|
| 2969 | + if ($p_remove_all_dir) { |
|
| 2970 | 2970 | $v_stored_filename = basename($p_filename); |
| 2971 | - } |
|
| 2972 | - // ----- Look for partial path remove |
|
| 2973 | - else if ($p_remove_dir != "") { |
|
| 2971 | + } |
|
| 2972 | + // ----- Look for partial path remove |
|
| 2973 | + else if ($p_remove_dir != "") { |
|
| 2974 | 2974 | if (substr($p_remove_dir, -1) != '/') |
| 2975 | - $p_remove_dir .= "/"; |
|
| 2975 | + $p_remove_dir .= "/"; |
|
| 2976 | 2976 | |
| 2977 | 2977 | if ( (substr($p_filename, 0, 2) == "./") |
| 2978 | 2978 | || (substr($p_remove_dir, 0, 2) == "./")) { |
| 2979 | 2979 | |
| 2980 | - if ( (substr($p_filename, 0, 2) == "./") |
|
| 2980 | + if ( (substr($p_filename, 0, 2) == "./") |
|
| 2981 | 2981 | && (substr($p_remove_dir, 0, 2) != "./")) { |
| 2982 | 2982 | $p_remove_dir = "./".$p_remove_dir; |
| 2983 | - } |
|
| 2984 | - if ( (substr($p_filename, 0, 2) != "./") |
|
| 2983 | + } |
|
| 2984 | + if ( (substr($p_filename, 0, 2) != "./") |
|
| 2985 | 2985 | && (substr($p_remove_dir, 0, 2) == "./")) { |
| 2986 | 2986 | $p_remove_dir = substr($p_remove_dir, 2); |
| 2987 | - } |
|
| 2987 | + } |
|
| 2988 | 2988 | } |
| 2989 | 2989 | |
| 2990 | 2990 | $v_compare = PclZipUtilPathInclusion($p_remove_dir, |
| 2991 | - $v_stored_filename); |
|
| 2991 | + $v_stored_filename); |
|
| 2992 | 2992 | if ($v_compare > 0) { |
| 2993 | - if ($v_compare == 2) { |
|
| 2993 | + if ($v_compare == 2) { |
|
| 2994 | 2994 | $v_stored_filename = ""; |
| 2995 | - } |
|
| 2996 | - else { |
|
| 2995 | + } |
|
| 2996 | + else { |
|
| 2997 | 2997 | $v_stored_filename = substr($v_stored_filename, |
| 2998 | 2998 | strlen($p_remove_dir)); |
| 2999 | - } |
|
| 2999 | + } |
|
| 3000 | + } |
|
| 3000 | 3001 | } |
| 3001 | - } |
|
| 3002 | 3002 | |
| 3003 | - // ----- Remove drive letter if any |
|
| 3004 | - $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename); |
|
| 3003 | + // ----- Remove drive letter if any |
|
| 3004 | + $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename); |
|
| 3005 | 3005 | |
| 3006 | - // ----- Look for path to add |
|
| 3007 | - if ($p_add_dir != "") { |
|
| 3006 | + // ----- Look for path to add |
|
| 3007 | + if ($p_add_dir != "") { |
|
| 3008 | 3008 | if (substr($p_add_dir, -1) == "/") |
| 3009 | - $v_stored_filename = $p_add_dir.$v_stored_filename; |
|
| 3009 | + $v_stored_filename = $p_add_dir.$v_stored_filename; |
|
| 3010 | 3010 | else |
| 3011 | - $v_stored_filename = $p_add_dir."/".$v_stored_filename; |
|
| 3012 | - } |
|
| 3011 | + $v_stored_filename = $p_add_dir."/".$v_stored_filename; |
|
| 3012 | + } |
|
| 3013 | 3013 | } |
| 3014 | 3014 | |
| 3015 | 3015 | // ----- Filename (reduce the path of stored name) |
@@ -3018,17 +3018,17 @@ discard block |
||
| 3018 | 3018 | |
| 3019 | 3019 | // ----- Return |
| 3020 | 3020 | return $v_result; |
| 3021 | - } |
|
| 3022 | - // -------------------------------------------------------------------------------- |
|
| 3023 | - |
|
| 3024 | - // -------------------------------------------------------------------------------- |
|
| 3025 | - // Function : privWriteFileHeader() |
|
| 3026 | - // Description : |
|
| 3027 | - // Parameters : |
|
| 3028 | - // Return Values : |
|
| 3029 | - // -------------------------------------------------------------------------------- |
|
| 3030 | - function privWriteFileHeader(&$p_header) |
|
| 3031 | - { |
|
| 3021 | + } |
|
| 3022 | + // -------------------------------------------------------------------------------- |
|
| 3023 | + |
|
| 3024 | + // -------------------------------------------------------------------------------- |
|
| 3025 | + // Function : privWriteFileHeader() |
|
| 3026 | + // Description : |
|
| 3027 | + // Parameters : |
|
| 3028 | + // Return Values : |
|
| 3029 | + // -------------------------------------------------------------------------------- |
|
| 3030 | + function privWriteFileHeader(&$p_header) |
|
| 3031 | + { |
|
| 3032 | 3032 | $v_result=1; |
| 3033 | 3033 | |
| 3034 | 3034 | // ----- Store the offset position of the file |
@@ -3041,12 +3041,12 @@ discard block |
||
| 3041 | 3041 | |
| 3042 | 3042 | // ----- Packed data |
| 3043 | 3043 | $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50, |
| 3044 | - $p_header['version_extracted'], $p_header['flag'], |
|
| 3045 | - $p_header['compression'], $v_mtime, $v_mdate, |
|
| 3046 | - $p_header['crc'], $p_header['compressed_size'], |
|
| 3047 | - $p_header['size'], |
|
| 3048 | - strlen($p_header['stored_filename']), |
|
| 3049 | - $p_header['extra_len']); |
|
| 3044 | + $p_header['version_extracted'], $p_header['flag'], |
|
| 3045 | + $p_header['compression'], $v_mtime, $v_mdate, |
|
| 3046 | + $p_header['crc'], $p_header['compressed_size'], |
|
| 3047 | + $p_header['size'], |
|
| 3048 | + strlen($p_header['stored_filename']), |
|
| 3049 | + $p_header['extra_len']); |
|
| 3050 | 3050 | |
| 3051 | 3051 | // ----- Write the first 148 bytes of the header in the archive |
| 3052 | 3052 | fputs($this->zip_fd, $v_binary_data, 30); |
@@ -3054,26 +3054,26 @@ discard block |
||
| 3054 | 3054 | // ----- Write the variable fields |
| 3055 | 3055 | if (strlen($p_header['stored_filename']) != 0) |
| 3056 | 3056 | { |
| 3057 | - fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename'])); |
|
| 3057 | + fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename'])); |
|
| 3058 | 3058 | } |
| 3059 | 3059 | if ($p_header['extra_len'] != 0) |
| 3060 | 3060 | { |
| 3061 | - fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']); |
|
| 3061 | + fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']); |
|
| 3062 | 3062 | } |
| 3063 | 3063 | |
| 3064 | 3064 | // ----- Return |
| 3065 | 3065 | return $v_result; |
| 3066 | - } |
|
| 3067 | - // -------------------------------------------------------------------------------- |
|
| 3068 | - |
|
| 3069 | - // -------------------------------------------------------------------------------- |
|
| 3070 | - // Function : privWriteCentralFileHeader() |
|
| 3071 | - // Description : |
|
| 3072 | - // Parameters : |
|
| 3073 | - // Return Values : |
|
| 3074 | - // -------------------------------------------------------------------------------- |
|
| 3075 | - function privWriteCentralFileHeader(&$p_header) |
|
| 3076 | - { |
|
| 3066 | + } |
|
| 3067 | + // -------------------------------------------------------------------------------- |
|
| 3068 | + |
|
| 3069 | + // -------------------------------------------------------------------------------- |
|
| 3070 | + // Function : privWriteCentralFileHeader() |
|
| 3071 | + // Description : |
|
| 3072 | + // Parameters : |
|
| 3073 | + // Return Values : |
|
| 3074 | + // -------------------------------------------------------------------------------- |
|
| 3075 | + function privWriteCentralFileHeader(&$p_header) |
|
| 3076 | + { |
|
| 3077 | 3077 | $v_result=1; |
| 3078 | 3078 | |
| 3079 | 3079 | // TBC |
@@ -3088,14 +3088,14 @@ discard block |
||
| 3088 | 3088 | |
| 3089 | 3089 | // ----- Packed data |
| 3090 | 3090 | $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50, |
| 3091 | - $p_header['version'], $p_header['version_extracted'], |
|
| 3092 | - $p_header['flag'], $p_header['compression'], |
|
| 3093 | - $v_mtime, $v_mdate, $p_header['crc'], |
|
| 3094 | - $p_header['compressed_size'], $p_header['size'], |
|
| 3095 | - strlen($p_header['stored_filename']), |
|
| 3096 | - $p_header['extra_len'], $p_header['comment_len'], |
|
| 3097 | - $p_header['disk'], $p_header['internal'], |
|
| 3098 | - $p_header['external'], $p_header['offset']); |
|
| 3091 | + $p_header['version'], $p_header['version_extracted'], |
|
| 3092 | + $p_header['flag'], $p_header['compression'], |
|
| 3093 | + $v_mtime, $v_mdate, $p_header['crc'], |
|
| 3094 | + $p_header['compressed_size'], $p_header['size'], |
|
| 3095 | + strlen($p_header['stored_filename']), |
|
| 3096 | + $p_header['extra_len'], $p_header['comment_len'], |
|
| 3097 | + $p_header['disk'], $p_header['internal'], |
|
| 3098 | + $p_header['external'], $p_header['offset']); |
|
| 3099 | 3099 | |
| 3100 | 3100 | // ----- Write the 42 bytes of the header in the zip file |
| 3101 | 3101 | fputs($this->zip_fd, $v_binary_data, 46); |
@@ -3103,36 +3103,36 @@ discard block |
||
| 3103 | 3103 | // ----- Write the variable fields |
| 3104 | 3104 | if (strlen($p_header['stored_filename']) != 0) |
| 3105 | 3105 | { |
| 3106 | - fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename'])); |
|
| 3106 | + fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename'])); |
|
| 3107 | 3107 | } |
| 3108 | 3108 | if ($p_header['extra_len'] != 0) |
| 3109 | 3109 | { |
| 3110 | - fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']); |
|
| 3110 | + fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']); |
|
| 3111 | 3111 | } |
| 3112 | 3112 | if ($p_header['comment_len'] != 0) |
| 3113 | 3113 | { |
| 3114 | - fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']); |
|
| 3114 | + fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']); |
|
| 3115 | 3115 | } |
| 3116 | 3116 | |
| 3117 | 3117 | // ----- Return |
| 3118 | 3118 | return $v_result; |
| 3119 | - } |
|
| 3120 | - // -------------------------------------------------------------------------------- |
|
| 3121 | - |
|
| 3122 | - // -------------------------------------------------------------------------------- |
|
| 3123 | - // Function : privWriteCentralHeader() |
|
| 3124 | - // Description : |
|
| 3125 | - // Parameters : |
|
| 3126 | - // Return Values : |
|
| 3127 | - // -------------------------------------------------------------------------------- |
|
| 3128 | - function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment) |
|
| 3129 | - { |
|
| 3119 | + } |
|
| 3120 | + // -------------------------------------------------------------------------------- |
|
| 3121 | + |
|
| 3122 | + // -------------------------------------------------------------------------------- |
|
| 3123 | + // Function : privWriteCentralHeader() |
|
| 3124 | + // Description : |
|
| 3125 | + // Parameters : |
|
| 3126 | + // Return Values : |
|
| 3127 | + // -------------------------------------------------------------------------------- |
|
| 3128 | + function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment) |
|
| 3129 | + { |
|
| 3130 | 3130 | $v_result=1; |
| 3131 | 3131 | |
| 3132 | 3132 | // ----- Packed data |
| 3133 | 3133 | $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries, |
| 3134 | - $p_nb_entries, $p_size, |
|
| 3135 | - $p_offset, strlen($p_comment)); |
|
| 3134 | + $p_nb_entries, $p_size, |
|
| 3135 | + $p_offset, strlen($p_comment)); |
|
| 3136 | 3136 | |
| 3137 | 3137 | // ----- Write the 22 bytes of the header in the zip file |
| 3138 | 3138 | fputs($this->zip_fd, $v_binary_data, 22); |
@@ -3140,22 +3140,22 @@ discard block |
||
| 3140 | 3140 | // ----- Write the variable fields |
| 3141 | 3141 | if (strlen($p_comment) != 0) |
| 3142 | 3142 | { |
| 3143 | - fputs($this->zip_fd, $p_comment, strlen($p_comment)); |
|
| 3143 | + fputs($this->zip_fd, $p_comment, strlen($p_comment)); |
|
| 3144 | 3144 | } |
| 3145 | 3145 | |
| 3146 | 3146 | // ----- Return |
| 3147 | 3147 | return $v_result; |
| 3148 | - } |
|
| 3149 | - // -------------------------------------------------------------------------------- |
|
| 3150 | - |
|
| 3151 | - // -------------------------------------------------------------------------------- |
|
| 3152 | - // Function : privList() |
|
| 3153 | - // Description : |
|
| 3154 | - // Parameters : |
|
| 3155 | - // Return Values : |
|
| 3156 | - // -------------------------------------------------------------------------------- |
|
| 3157 | - function privList(&$p_list) |
|
| 3158 | - { |
|
| 3148 | + } |
|
| 3149 | + // -------------------------------------------------------------------------------- |
|
| 3150 | + |
|
| 3151 | + // -------------------------------------------------------------------------------- |
|
| 3152 | + // Function : privList() |
|
| 3153 | + // Description : |
|
| 3154 | + // Parameters : |
|
| 3155 | + // Return Values : |
|
| 3156 | + // -------------------------------------------------------------------------------- |
|
| 3157 | + function privList(&$p_list) |
|
| 3158 | + { |
|
| 3159 | 3159 | $v_result=1; |
| 3160 | 3160 | |
| 3161 | 3161 | // ----- Magic quotes trick |
@@ -3164,51 +3164,51 @@ discard block |
||
| 3164 | 3164 | // ----- Open the zip file |
| 3165 | 3165 | if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0) |
| 3166 | 3166 | { |
| 3167 | - // ----- Magic quotes trick |
|
| 3168 | - $this->privSwapBackMagicQuotes(); |
|
| 3167 | + // ----- Magic quotes trick |
|
| 3168 | + $this->privSwapBackMagicQuotes(); |
|
| 3169 | 3169 | |
| 3170 | - // ----- Error log |
|
| 3171 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); |
|
| 3170 | + // ----- Error log |
|
| 3171 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode'); |
|
| 3172 | 3172 | |
| 3173 | - // ----- Return |
|
| 3174 | - return PclZip::errorCode(); |
|
| 3173 | + // ----- Return |
|
| 3174 | + return PclZip::errorCode(); |
|
| 3175 | 3175 | } |
| 3176 | 3176 | |
| 3177 | 3177 | // ----- Read the central directory informations |
| 3178 | 3178 | $v_central_dir = array(); |
| 3179 | 3179 | if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
| 3180 | 3180 | { |
| 3181 | - $this->privSwapBackMagicQuotes(); |
|
| 3182 | - return $v_result; |
|
| 3181 | + $this->privSwapBackMagicQuotes(); |
|
| 3182 | + return $v_result; |
|
| 3183 | 3183 | } |
| 3184 | 3184 | |
| 3185 | 3185 | // ----- Go to beginning of Central Dir |
| 3186 | 3186 | @rewind($this->zip_fd); |
| 3187 | 3187 | if (@fseek($this->zip_fd, $v_central_dir['offset'])) |
| 3188 | 3188 | { |
| 3189 | - $this->privSwapBackMagicQuotes(); |
|
| 3189 | + $this->privSwapBackMagicQuotes(); |
|
| 3190 | 3190 | |
| 3191 | - // ----- Error log |
|
| 3192 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
|
| 3191 | + // ----- Error log |
|
| 3192 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
|
| 3193 | 3193 | |
| 3194 | - // ----- Return |
|
| 3195 | - return PclZip::errorCode(); |
|
| 3194 | + // ----- Return |
|
| 3195 | + return PclZip::errorCode(); |
|
| 3196 | 3196 | } |
| 3197 | 3197 | |
| 3198 | 3198 | // ----- Read each entry |
| 3199 | 3199 | for ($i=0; $i<$v_central_dir['entries']; $i++) |
| 3200 | 3200 | { |
| 3201 | - // ----- Read the file header |
|
| 3202 | - if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) |
|
| 3203 | - { |
|
| 3201 | + // ----- Read the file header |
|
| 3202 | + if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) |
|
| 3203 | + { |
|
| 3204 | 3204 | $this->privSwapBackMagicQuotes(); |
| 3205 | 3205 | return $v_result; |
| 3206 | - } |
|
| 3207 | - $v_header['index'] = $i; |
|
| 3206 | + } |
|
| 3207 | + $v_header['index'] = $i; |
|
| 3208 | 3208 | |
| 3209 | - // ----- Get the only interesting attributes |
|
| 3210 | - $this->privConvertHeader2FileInfo($v_header, $p_list[$i]); |
|
| 3211 | - unset($v_header); |
|
| 3209 | + // ----- Get the only interesting attributes |
|
| 3210 | + $this->privConvertHeader2FileInfo($v_header, $p_list[$i]); |
|
| 3211 | + unset($v_header); |
|
| 3212 | 3212 | } |
| 3213 | 3213 | |
| 3214 | 3214 | // ----- Close the zip file |
@@ -3219,30 +3219,30 @@ discard block |
||
| 3219 | 3219 | |
| 3220 | 3220 | // ----- Return |
| 3221 | 3221 | return $v_result; |
| 3222 | - } |
|
| 3223 | - // -------------------------------------------------------------------------------- |
|
| 3224 | - |
|
| 3225 | - // -------------------------------------------------------------------------------- |
|
| 3226 | - // Function : privConvertHeader2FileInfo() |
|
| 3227 | - // Description : |
|
| 3228 | - // This function takes the file informations from the central directory |
|
| 3229 | - // entries and extract the interesting parameters that will be given back. |
|
| 3230 | - // The resulting file infos are set in the array $p_info |
|
| 3231 | - // $p_info['filename'] : Filename with full path. Given by user (add), |
|
| 3232 | - // extracted in the filesystem (extract). |
|
| 3233 | - // $p_info['stored_filename'] : Stored filename in the archive. |
|
| 3234 | - // $p_info['size'] = Size of the file. |
|
| 3235 | - // $p_info['compressed_size'] = Compressed size of the file. |
|
| 3236 | - // $p_info['mtime'] = Last modification date of the file. |
|
| 3237 | - // $p_info['comment'] = Comment associated with the file. |
|
| 3238 | - // $p_info['folder'] = true/false : indicates if the entry is a folder or not. |
|
| 3239 | - // $p_info['status'] = status of the action on the file. |
|
| 3240 | - // $p_info['crc'] = CRC of the file content. |
|
| 3241 | - // Parameters : |
|
| 3242 | - // Return Values : |
|
| 3243 | - // -------------------------------------------------------------------------------- |
|
| 3244 | - function privConvertHeader2FileInfo($p_header, &$p_info) |
|
| 3245 | - { |
|
| 3222 | + } |
|
| 3223 | + // -------------------------------------------------------------------------------- |
|
| 3224 | + |
|
| 3225 | + // -------------------------------------------------------------------------------- |
|
| 3226 | + // Function : privConvertHeader2FileInfo() |
|
| 3227 | + // Description : |
|
| 3228 | + // This function takes the file informations from the central directory |
|
| 3229 | + // entries and extract the interesting parameters that will be given back. |
|
| 3230 | + // The resulting file infos are set in the array $p_info |
|
| 3231 | + // $p_info['filename'] : Filename with full path. Given by user (add), |
|
| 3232 | + // extracted in the filesystem (extract). |
|
| 3233 | + // $p_info['stored_filename'] : Stored filename in the archive. |
|
| 3234 | + // $p_info['size'] = Size of the file. |
|
| 3235 | + // $p_info['compressed_size'] = Compressed size of the file. |
|
| 3236 | + // $p_info['mtime'] = Last modification date of the file. |
|
| 3237 | + // $p_info['comment'] = Comment associated with the file. |
|
| 3238 | + // $p_info['folder'] = true/false : indicates if the entry is a folder or not. |
|
| 3239 | + // $p_info['status'] = status of the action on the file. |
|
| 3240 | + // $p_info['crc'] = CRC of the file content. |
|
| 3241 | + // Parameters : |
|
| 3242 | + // Return Values : |
|
| 3243 | + // -------------------------------------------------------------------------------- |
|
| 3244 | + function privConvertHeader2FileInfo($p_header, &$p_info) |
|
| 3245 | + { |
|
| 3246 | 3246 | $v_result=1; |
| 3247 | 3247 | |
| 3248 | 3248 | // ----- Get the interesting attributes |
@@ -3261,27 +3261,27 @@ discard block |
||
| 3261 | 3261 | |
| 3262 | 3262 | // ----- Return |
| 3263 | 3263 | return $v_result; |
| 3264 | - } |
|
| 3265 | - // -------------------------------------------------------------------------------- |
|
| 3266 | - |
|
| 3267 | - // -------------------------------------------------------------------------------- |
|
| 3268 | - // Function : privExtractByRule() |
|
| 3269 | - // Description : |
|
| 3270 | - // Extract a file or directory depending of rules (by index, by name, ...) |
|
| 3271 | - // Parameters : |
|
| 3272 | - // $p_file_list : An array where will be placed the properties of each |
|
| 3273 | - // extracted file |
|
| 3274 | - // $p_path : Path to add while writing the extracted files |
|
| 3275 | - // $p_remove_path : Path to remove (from the file memorized path) while writing the |
|
| 3276 | - // extracted files. If the path does not match the file path, |
|
| 3277 | - // the file is extracted with its memorized path. |
|
| 3278 | - // $p_remove_path does not apply to 'list' mode. |
|
| 3279 | - // $p_path and $p_remove_path are commulative. |
|
| 3280 | - // Return Values : |
|
| 3281 | - // 1 on success,0 or less on error (see error code list) |
|
| 3282 | - // -------------------------------------------------------------------------------- |
|
| 3283 | - function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) |
|
| 3284 | - { |
|
| 3264 | + } |
|
| 3265 | + // -------------------------------------------------------------------------------- |
|
| 3266 | + |
|
| 3267 | + // -------------------------------------------------------------------------------- |
|
| 3268 | + // Function : privExtractByRule() |
|
| 3269 | + // Description : |
|
| 3270 | + // Extract a file or directory depending of rules (by index, by name, ...) |
|
| 3271 | + // Parameters : |
|
| 3272 | + // $p_file_list : An array where will be placed the properties of each |
|
| 3273 | + // extracted file |
|
| 3274 | + // $p_path : Path to add while writing the extracted files |
|
| 3275 | + // $p_remove_path : Path to remove (from the file memorized path) while writing the |
|
| 3276 | + // extracted files. If the path does not match the file path, |
|
| 3277 | + // the file is extracted with its memorized path. |
|
| 3278 | + // $p_remove_path does not apply to 'list' mode. |
|
| 3279 | + // $p_path and $p_remove_path are commulative. |
|
| 3280 | + // Return Values : |
|
| 3281 | + // 1 on success,0 or less on error (see error code list) |
|
| 3282 | + // -------------------------------------------------------------------------------- |
|
| 3283 | + function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) |
|
| 3284 | + { |
|
| 3285 | 3285 | $v_result=1; |
| 3286 | 3286 | |
| 3287 | 3287 | // ----- Magic quotes trick |
@@ -3289,44 +3289,44 @@ discard block |
||
| 3289 | 3289 | |
| 3290 | 3290 | // ----- Check the path |
| 3291 | 3291 | if ( ($p_path == "") |
| 3292 | - || ( (substr($p_path, 0, 1) != "/") |
|
| 3293 | - && (substr($p_path, 0, 3) != "../") |
|
| 3294 | - && (substr($p_path,1,2)!=":/"))) |
|
| 3295 | - $p_path = "./".$p_path; |
|
| 3292 | + || ( (substr($p_path, 0, 1) != "/") |
|
| 3293 | + && (substr($p_path, 0, 3) != "../") |
|
| 3294 | + && (substr($p_path,1,2)!=":/"))) |
|
| 3295 | + $p_path = "./".$p_path; |
|
| 3296 | 3296 | |
| 3297 | 3297 | // ----- Reduce the path last (and duplicated) '/' |
| 3298 | 3298 | if (($p_path != "./") && ($p_path != "/")) |
| 3299 | 3299 | { |
| 3300 | - // ----- Look for the path end '/' |
|
| 3301 | - while (substr($p_path, -1) == "/") |
|
| 3302 | - { |
|
| 3300 | + // ----- Look for the path end '/' |
|
| 3301 | + while (substr($p_path, -1) == "/") |
|
| 3302 | + { |
|
| 3303 | 3303 | $p_path = substr($p_path, 0, strlen($p_path)-1); |
| 3304 | - } |
|
| 3304 | + } |
|
| 3305 | 3305 | } |
| 3306 | 3306 | |
| 3307 | 3307 | // ----- Look for path to remove format (should end by /) |
| 3308 | 3308 | if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/')) |
| 3309 | 3309 | { |
| 3310 | - $p_remove_path .= '/'; |
|
| 3310 | + $p_remove_path .= '/'; |
|
| 3311 | 3311 | } |
| 3312 | 3312 | $p_remove_path_size = strlen($p_remove_path); |
| 3313 | 3313 | |
| 3314 | 3314 | // ----- Open the zip file |
| 3315 | 3315 | if (($v_result = $this->privOpenFd('rb')) != 1) |
| 3316 | 3316 | { |
| 3317 | - $this->privSwapBackMagicQuotes(); |
|
| 3318 | - return $v_result; |
|
| 3317 | + $this->privSwapBackMagicQuotes(); |
|
| 3318 | + return $v_result; |
|
| 3319 | 3319 | } |
| 3320 | 3320 | |
| 3321 | 3321 | // ----- Read the central directory informations |
| 3322 | 3322 | $v_central_dir = array(); |
| 3323 | 3323 | if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
| 3324 | 3324 | { |
| 3325 | - // ----- Close the zip file |
|
| 3326 | - $this->privCloseFd(); |
|
| 3327 | - $this->privSwapBackMagicQuotes(); |
|
| 3325 | + // ----- Close the zip file |
|
| 3326 | + $this->privCloseFd(); |
|
| 3327 | + $this->privSwapBackMagicQuotes(); |
|
| 3328 | 3328 | |
| 3329 | - return $v_result; |
|
| 3329 | + return $v_result; |
|
| 3330 | 3330 | } |
| 3331 | 3331 | |
| 3332 | 3332 | // ----- Start at beginning of Central Dir |
@@ -3337,10 +3337,10 @@ discard block |
||
| 3337 | 3337 | for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) |
| 3338 | 3338 | { |
| 3339 | 3339 | |
| 3340 | - // ----- Read next Central dir entry |
|
| 3341 | - @rewind($this->zip_fd); |
|
| 3342 | - if (@fseek($this->zip_fd, $v_pos_entry)) |
|
| 3343 | - { |
|
| 3340 | + // ----- Read next Central dir entry |
|
| 3341 | + @rewind($this->zip_fd); |
|
| 3342 | + if (@fseek($this->zip_fd, $v_pos_entry)) |
|
| 3343 | + { |
|
| 3344 | 3344 | // ----- Close the zip file |
| 3345 | 3345 | $this->privCloseFd(); |
| 3346 | 3346 | $this->privSwapBackMagicQuotes(); |
@@ -3350,54 +3350,54 @@ discard block |
||
| 3350 | 3350 | |
| 3351 | 3351 | // ----- Return |
| 3352 | 3352 | return PclZip::errorCode(); |
| 3353 | - } |
|
| 3353 | + } |
|
| 3354 | 3354 | |
| 3355 | - // ----- Read the file header |
|
| 3356 | - $v_header = array(); |
|
| 3357 | - if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) |
|
| 3358 | - { |
|
| 3355 | + // ----- Read the file header |
|
| 3356 | + $v_header = array(); |
|
| 3357 | + if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) |
|
| 3358 | + { |
|
| 3359 | 3359 | // ----- Close the zip file |
| 3360 | 3360 | $this->privCloseFd(); |
| 3361 | 3361 | $this->privSwapBackMagicQuotes(); |
| 3362 | 3362 | |
| 3363 | 3363 | return $v_result; |
| 3364 | - } |
|
| 3364 | + } |
|
| 3365 | 3365 | |
| 3366 | - // ----- Store the index |
|
| 3367 | - $v_header['index'] = $i; |
|
| 3366 | + // ----- Store the index |
|
| 3367 | + $v_header['index'] = $i; |
|
| 3368 | 3368 | |
| 3369 | - // ----- Store the file position |
|
| 3370 | - $v_pos_entry = ftell($this->zip_fd); |
|
| 3369 | + // ----- Store the file position |
|
| 3370 | + $v_pos_entry = ftell($this->zip_fd); |
|
| 3371 | 3371 | |
| 3372 | - // ----- Look for the specific extract rules |
|
| 3373 | - $v_extract = false; |
|
| 3372 | + // ----- Look for the specific extract rules |
|
| 3373 | + $v_extract = false; |
|
| 3374 | 3374 | |
| 3375 | - // ----- Look for extract by name rule |
|
| 3376 | - if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) |
|
| 3375 | + // ----- Look for extract by name rule |
|
| 3376 | + if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) |
|
| 3377 | 3377 | && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { |
| 3378 | 3378 | |
| 3379 | - // ----- Look if the filename is in the list |
|
| 3380 | - for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) { |
|
| 3379 | + // ----- Look if the filename is in the list |
|
| 3380 | + for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) { |
|
| 3381 | 3381 | |
| 3382 | - // ----- Look for a directory |
|
| 3383 | - if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { |
|
| 3382 | + // ----- Look for a directory |
|
| 3383 | + if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { |
|
| 3384 | 3384 | |
| 3385 | - // ----- Look if the directory is in the filename path |
|
| 3386 | - if ( (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) |
|
| 3385 | + // ----- Look if the directory is in the filename path |
|
| 3386 | + if ( (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) |
|
| 3387 | 3387 | && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
| 3388 | - $v_extract = true; |
|
| 3389 | - } |
|
| 3390 | - } |
|
| 3391 | - // ----- Look for a filename |
|
| 3392 | - elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { |
|
| 3393 | - $v_extract = true; |
|
| 3394 | - } |
|
| 3395 | - } |
|
| 3396 | - } |
|
| 3388 | + $v_extract = true; |
|
| 3389 | + } |
|
| 3390 | + } |
|
| 3391 | + // ----- Look for a filename |
|
| 3392 | + elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { |
|
| 3393 | + $v_extract = true; |
|
| 3394 | + } |
|
| 3395 | + } |
|
| 3396 | + } |
|
| 3397 | 3397 | |
| 3398 | - // ----- Look for extract by ereg rule |
|
| 3399 | - // ereg() is deprecated with PHP 5.3 |
|
| 3400 | - /* |
|
| 3398 | + // ----- Look for extract by ereg rule |
|
| 3399 | + // ereg() is deprecated with PHP 5.3 |
|
| 3400 | + /* |
|
| 3401 | 3401 | else if ( (isset($p_options[PCLZIP_OPT_BY_EREG])) |
| 3402 | 3402 | && ($p_options[PCLZIP_OPT_BY_EREG] != "")) { |
| 3403 | 3403 | |
@@ -3407,199 +3407,199 @@ discard block |
||
| 3407 | 3407 | } |
| 3408 | 3408 | */ |
| 3409 | 3409 | |
| 3410 | - // ----- Look for extract by preg rule |
|
| 3411 | - else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) |
|
| 3410 | + // ----- Look for extract by preg rule |
|
| 3411 | + else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) |
|
| 3412 | 3412 | && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { |
| 3413 | 3413 | |
| 3414 | - if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) { |
|
| 3415 | - $v_extract = true; |
|
| 3416 | - } |
|
| 3417 | - } |
|
| 3414 | + if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) { |
|
| 3415 | + $v_extract = true; |
|
| 3416 | + } |
|
| 3417 | + } |
|
| 3418 | 3418 | |
| 3419 | - // ----- Look for extract by index rule |
|
| 3420 | - else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) |
|
| 3419 | + // ----- Look for extract by index rule |
|
| 3420 | + else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) |
|
| 3421 | 3421 | && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { |
| 3422 | 3422 | |
| 3423 | - // ----- Look if the index is in the list |
|
| 3424 | - for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) { |
|
| 3425 | - |
|
| 3426 | - if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { |
|
| 3427 | - $v_extract = true; |
|
| 3428 | - } |
|
| 3429 | - if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { |
|
| 3430 | - $j_start = $j+1; |
|
| 3431 | - } |
|
| 3432 | - |
|
| 3433 | - if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { |
|
| 3434 | - break; |
|
| 3435 | - } |
|
| 3436 | - } |
|
| 3437 | - } |
|
| 3423 | + // ----- Look if the index is in the list |
|
| 3424 | + for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) { |
|
| 3425 | + |
|
| 3426 | + if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { |
|
| 3427 | + $v_extract = true; |
|
| 3428 | + } |
|
| 3429 | + if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { |
|
| 3430 | + $j_start = $j+1; |
|
| 3431 | + } |
|
| 3432 | + |
|
| 3433 | + if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { |
|
| 3434 | + break; |
|
| 3435 | + } |
|
| 3436 | + } |
|
| 3437 | + } |
|
| 3438 | 3438 | |
| 3439 | - // ----- Look for no rule, which means extract all the archive |
|
| 3440 | - else { |
|
| 3441 | - $v_extract = true; |
|
| 3442 | - } |
|
| 3439 | + // ----- Look for no rule, which means extract all the archive |
|
| 3440 | + else { |
|
| 3441 | + $v_extract = true; |
|
| 3442 | + } |
|
| 3443 | 3443 | |
| 3444 | - // ----- Check compression method |
|
| 3445 | - if ( ($v_extract) |
|
| 3446 | - && ( ($v_header['compression'] != 8) |
|
| 3447 | - && ($v_header['compression'] != 0))) { |
|
| 3448 | - $v_header['status'] = 'unsupported_compression'; |
|
| 3444 | + // ----- Check compression method |
|
| 3445 | + if ( ($v_extract) |
|
| 3446 | + && ( ($v_header['compression'] != 8) |
|
| 3447 | + && ($v_header['compression'] != 0))) { |
|
| 3448 | + $v_header['status'] = 'unsupported_compression'; |
|
| 3449 | 3449 | |
| 3450 | - // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
|
| 3451 | - if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3452 | - && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3450 | + // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
|
| 3451 | + if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3452 | + && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3453 | 3453 | |
| 3454 | - $this->privSwapBackMagicQuotes(); |
|
| 3454 | + $this->privSwapBackMagicQuotes(); |
|
| 3455 | 3455 | |
| 3456 | - PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION, |
|
| 3457 | - "Filename '".$v_header['stored_filename']."' is " |
|
| 3458 | - ."compressed by an unsupported compression " |
|
| 3459 | - ."method (".$v_header['compression'].") "); |
|
| 3460 | - |
|
| 3461 | - return PclZip::errorCode(); |
|
| 3462 | - } |
|
| 3463 | - } |
|
| 3456 | + PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION, |
|
| 3457 | + "Filename '".$v_header['stored_filename']."' is " |
|
| 3458 | + ."compressed by an unsupported compression " |
|
| 3459 | + ."method (".$v_header['compression'].") "); |
|
| 3460 | + |
|
| 3461 | + return PclZip::errorCode(); |
|
| 3462 | + } |
|
| 3463 | + } |
|
| 3464 | 3464 | |
| 3465 | - // ----- Check encrypted files |
|
| 3466 | - if (($v_extract) && (($v_header['flag'] & 1) == 1)) { |
|
| 3467 | - $v_header['status'] = 'unsupported_encryption'; |
|
| 3465 | + // ----- Check encrypted files |
|
| 3466 | + if (($v_extract) && (($v_header['flag'] & 1) == 1)) { |
|
| 3467 | + $v_header['status'] = 'unsupported_encryption'; |
|
| 3468 | 3468 | |
| 3469 | - // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
|
| 3470 | - if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3471 | - && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3469 | + // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
|
| 3470 | + if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3471 | + && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3472 | 3472 | |
| 3473 | - $this->privSwapBackMagicQuotes(); |
|
| 3473 | + $this->privSwapBackMagicQuotes(); |
|
| 3474 | 3474 | |
| 3475 | - PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, |
|
| 3476 | - "Unsupported encryption for " |
|
| 3477 | - ." filename '".$v_header['stored_filename'] |
|
| 3478 | - ."'"); |
|
| 3475 | + PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, |
|
| 3476 | + "Unsupported encryption for " |
|
| 3477 | + ." filename '".$v_header['stored_filename'] |
|
| 3478 | + ."'"); |
|
| 3479 | 3479 | |
| 3480 | - return PclZip::errorCode(); |
|
| 3481 | - } |
|
| 3480 | + return PclZip::errorCode(); |
|
| 3481 | + } |
|
| 3482 | 3482 | } |
| 3483 | 3483 | |
| 3484 | - // ----- Look for real extraction |
|
| 3485 | - if (($v_extract) && ($v_header['status'] != 'ok')) { |
|
| 3486 | - $v_result = $this->privConvertHeader2FileInfo($v_header, |
|
| 3487 | - $p_file_list[$v_nb_extracted++]); |
|
| 3488 | - if ($v_result != 1) { |
|
| 3489 | - $this->privCloseFd(); |
|
| 3490 | - $this->privSwapBackMagicQuotes(); |
|
| 3491 | - return $v_result; |
|
| 3492 | - } |
|
| 3484 | + // ----- Look for real extraction |
|
| 3485 | + if (($v_extract) && ($v_header['status'] != 'ok')) { |
|
| 3486 | + $v_result = $this->privConvertHeader2FileInfo($v_header, |
|
| 3487 | + $p_file_list[$v_nb_extracted++]); |
|
| 3488 | + if ($v_result != 1) { |
|
| 3489 | + $this->privCloseFd(); |
|
| 3490 | + $this->privSwapBackMagicQuotes(); |
|
| 3491 | + return $v_result; |
|
| 3492 | + } |
|
| 3493 | 3493 | |
| 3494 | - $v_extract = false; |
|
| 3495 | - } |
|
| 3494 | + $v_extract = false; |
|
| 3495 | + } |
|
| 3496 | 3496 | |
| 3497 | - // ----- Look for real extraction |
|
| 3498 | - if ($v_extract) |
|
| 3499 | - { |
|
| 3497 | + // ----- Look for real extraction |
|
| 3498 | + if ($v_extract) |
|
| 3499 | + { |
|
| 3500 | 3500 | |
| 3501 | 3501 | // ----- Go to the file position |
| 3502 | 3502 | @rewind($this->zip_fd); |
| 3503 | 3503 | if (@fseek($this->zip_fd, $v_header['offset'])) |
| 3504 | 3504 | { |
| 3505 | - // ----- Close the zip file |
|
| 3506 | - $this->privCloseFd(); |
|
| 3505 | + // ----- Close the zip file |
|
| 3506 | + $this->privCloseFd(); |
|
| 3507 | 3507 | |
| 3508 | - $this->privSwapBackMagicQuotes(); |
|
| 3508 | + $this->privSwapBackMagicQuotes(); |
|
| 3509 | 3509 | |
| 3510 | - // ----- Error log |
|
| 3511 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
|
| 3510 | + // ----- Error log |
|
| 3511 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
|
| 3512 | 3512 | |
| 3513 | - // ----- Return |
|
| 3514 | - return PclZip::errorCode(); |
|
| 3513 | + // ----- Return |
|
| 3514 | + return PclZip::errorCode(); |
|
| 3515 | 3515 | } |
| 3516 | 3516 | |
| 3517 | 3517 | // ----- Look for extraction as string |
| 3518 | 3518 | if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) { |
| 3519 | 3519 | |
| 3520 | - $v_string = ''; |
|
| 3520 | + $v_string = ''; |
|
| 3521 | 3521 | |
| 3522 | - // ----- Extracting the file |
|
| 3523 | - $v_result1 = $this->privExtractFileAsString($v_header, $v_string, $p_options); |
|
| 3524 | - if ($v_result1 < 1) { |
|
| 3522 | + // ----- Extracting the file |
|
| 3523 | + $v_result1 = $this->privExtractFileAsString($v_header, $v_string, $p_options); |
|
| 3524 | + if ($v_result1 < 1) { |
|
| 3525 | 3525 | $this->privCloseFd(); |
| 3526 | 3526 | $this->privSwapBackMagicQuotes(); |
| 3527 | 3527 | return $v_result1; |
| 3528 | - } |
|
| 3528 | + } |
|
| 3529 | 3529 | |
| 3530 | - // ----- Get the only interesting attributes |
|
| 3531 | - if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1) |
|
| 3532 | - { |
|
| 3530 | + // ----- Get the only interesting attributes |
|
| 3531 | + if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1) |
|
| 3532 | + { |
|
| 3533 | 3533 | // ----- Close the zip file |
| 3534 | 3534 | $this->privCloseFd(); |
| 3535 | 3535 | $this->privSwapBackMagicQuotes(); |
| 3536 | 3536 | |
| 3537 | 3537 | return $v_result; |
| 3538 | - } |
|
| 3538 | + } |
|
| 3539 | 3539 | |
| 3540 | - // ----- Set the file content |
|
| 3541 | - $p_file_list[$v_nb_extracted]['content'] = $v_string; |
|
| 3540 | + // ----- Set the file content |
|
| 3541 | + $p_file_list[$v_nb_extracted]['content'] = $v_string; |
|
| 3542 | 3542 | |
| 3543 | - // ----- Next extracted file |
|
| 3544 | - $v_nb_extracted++; |
|
| 3543 | + // ----- Next extracted file |
|
| 3544 | + $v_nb_extracted++; |
|
| 3545 | 3545 | |
| 3546 | - // ----- Look for user callback abort |
|
| 3547 | - if ($v_result1 == 2) { |
|
| 3548 | - break; |
|
| 3549 | - } |
|
| 3546 | + // ----- Look for user callback abort |
|
| 3547 | + if ($v_result1 == 2) { |
|
| 3548 | + break; |
|
| 3549 | + } |
|
| 3550 | 3550 | } |
| 3551 | 3551 | // ----- Look for extraction in standard output |
| 3552 | 3552 | elseif ( (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) |
| 3553 | - && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) { |
|
| 3554 | - // ----- Extracting the file in standard output |
|
| 3555 | - $v_result1 = $this->privExtractFileInOutput($v_header, $p_options); |
|
| 3556 | - if ($v_result1 < 1) { |
|
| 3553 | + && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) { |
|
| 3554 | + // ----- Extracting the file in standard output |
|
| 3555 | + $v_result1 = $this->privExtractFileInOutput($v_header, $p_options); |
|
| 3556 | + if ($v_result1 < 1) { |
|
| 3557 | 3557 | $this->privCloseFd(); |
| 3558 | 3558 | $this->privSwapBackMagicQuotes(); |
| 3559 | 3559 | return $v_result1; |
| 3560 | - } |
|
| 3560 | + } |
|
| 3561 | 3561 | |
| 3562 | - // ----- Get the only interesting attributes |
|
| 3563 | - if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) { |
|
| 3562 | + // ----- Get the only interesting attributes |
|
| 3563 | + if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) { |
|
| 3564 | 3564 | $this->privCloseFd(); |
| 3565 | 3565 | $this->privSwapBackMagicQuotes(); |
| 3566 | 3566 | return $v_result; |
| 3567 | - } |
|
| 3567 | + } |
|
| 3568 | 3568 | |
| 3569 | - // ----- Look for user callback abort |
|
| 3570 | - if ($v_result1 == 2) { |
|
| 3571 | - break; |
|
| 3572 | - } |
|
| 3569 | + // ----- Look for user callback abort |
|
| 3570 | + if ($v_result1 == 2) { |
|
| 3571 | + break; |
|
| 3572 | + } |
|
| 3573 | 3573 | } |
| 3574 | 3574 | // ----- Look for normal extraction |
| 3575 | 3575 | else { |
| 3576 | - // ----- Extracting the file |
|
| 3577 | - $v_result1 = $this->privExtractFile($v_header, |
|
| 3578 | - $p_path, $p_remove_path, |
|
| 3579 | - $p_remove_all_path, |
|
| 3580 | - $p_options); |
|
| 3581 | - if ($v_result1 < 1) { |
|
| 3576 | + // ----- Extracting the file |
|
| 3577 | + $v_result1 = $this->privExtractFile($v_header, |
|
| 3578 | + $p_path, $p_remove_path, |
|
| 3579 | + $p_remove_all_path, |
|
| 3580 | + $p_options); |
|
| 3581 | + if ($v_result1 < 1) { |
|
| 3582 | 3582 | $this->privCloseFd(); |
| 3583 | 3583 | $this->privSwapBackMagicQuotes(); |
| 3584 | 3584 | return $v_result1; |
| 3585 | - } |
|
| 3585 | + } |
|
| 3586 | 3586 | |
| 3587 | - // ----- Get the only interesting attributes |
|
| 3588 | - if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) |
|
| 3589 | - { |
|
| 3587 | + // ----- Get the only interesting attributes |
|
| 3588 | + if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) |
|
| 3589 | + { |
|
| 3590 | 3590 | // ----- Close the zip file |
| 3591 | 3591 | $this->privCloseFd(); |
| 3592 | 3592 | $this->privSwapBackMagicQuotes(); |
| 3593 | 3593 | |
| 3594 | 3594 | return $v_result; |
| 3595 | - } |
|
| 3595 | + } |
|
| 3596 | 3596 | |
| 3597 | - // ----- Look for user callback abort |
|
| 3598 | - if ($v_result1 == 2) { |
|
| 3599 | - break; |
|
| 3600 | - } |
|
| 3597 | + // ----- Look for user callback abort |
|
| 3598 | + if ($v_result1 == 2) { |
|
| 3599 | + break; |
|
| 3600 | + } |
|
| 3601 | + } |
|
| 3601 | 3602 | } |
| 3602 | - } |
|
| 3603 | 3603 | } |
| 3604 | 3604 | |
| 3605 | 3605 | // ----- Close the zip file |
@@ -3608,28 +3608,28 @@ discard block |
||
| 3608 | 3608 | |
| 3609 | 3609 | // ----- Return |
| 3610 | 3610 | return $v_result; |
| 3611 | - } |
|
| 3612 | - // -------------------------------------------------------------------------------- |
|
| 3613 | - |
|
| 3614 | - // -------------------------------------------------------------------------------- |
|
| 3615 | - // Function : privExtractFile() |
|
| 3616 | - // Description : |
|
| 3617 | - // Parameters : |
|
| 3618 | - // Return Values : |
|
| 3619 | - // |
|
| 3620 | - // 1 : ... ? |
|
| 3621 | - // PCLZIP_ERR_USER_ABORTED(2) : User ask for extraction stop in callback |
|
| 3622 | - // -------------------------------------------------------------------------------- |
|
| 3623 | - function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) |
|
| 3624 | - { |
|
| 3611 | + } |
|
| 3612 | + // -------------------------------------------------------------------------------- |
|
| 3613 | + |
|
| 3614 | + // -------------------------------------------------------------------------------- |
|
| 3615 | + // Function : privExtractFile() |
|
| 3616 | + // Description : |
|
| 3617 | + // Parameters : |
|
| 3618 | + // Return Values : |
|
| 3619 | + // |
|
| 3620 | + // 1 : ... ? |
|
| 3621 | + // PCLZIP_ERR_USER_ABORTED(2) : User ask for extraction stop in callback |
|
| 3622 | + // -------------------------------------------------------------------------------- |
|
| 3623 | + function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) |
|
| 3624 | + { |
|
| 3625 | 3625 | $v_result=1; |
| 3626 | 3626 | |
| 3627 | 3627 | // ----- Read the file header |
| 3628 | 3628 | if (($v_result = $this->privReadFileHeader($v_header)) != 1) |
| 3629 | 3629 | { |
| 3630 | - // ----- Return |
|
| 3631 | - return $v_result; |
|
| 3632 | - } |
|
| 3630 | + // ----- Return |
|
| 3631 | + return $v_result; |
|
| 3632 | + } |
|
| 3633 | 3633 | |
| 3634 | 3634 | |
| 3635 | 3635 | // ----- Check that the file header is coherent with $p_entry info |
@@ -3654,74 +3654,74 @@ discard block |
||
| 3654 | 3654 | // ----- Look for path to remove |
| 3655 | 3655 | else if ($p_remove_path != "") |
| 3656 | 3656 | { |
| 3657 | - if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2) |
|
| 3658 | - { |
|
| 3657 | + if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2) |
|
| 3658 | + { |
|
| 3659 | 3659 | |
| 3660 | 3660 | // ----- Change the file status |
| 3661 | 3661 | $p_entry['status'] = "filtered"; |
| 3662 | 3662 | |
| 3663 | 3663 | // ----- Return |
| 3664 | 3664 | return $v_result; |
| 3665 | - } |
|
| 3665 | + } |
|
| 3666 | 3666 | |
| 3667 | - $p_remove_path_size = strlen($p_remove_path); |
|
| 3668 | - if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path) |
|
| 3669 | - { |
|
| 3667 | + $p_remove_path_size = strlen($p_remove_path); |
|
| 3668 | + if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path) |
|
| 3669 | + { |
|
| 3670 | 3670 | |
| 3671 | 3671 | // ----- Remove the path |
| 3672 | 3672 | $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size); |
| 3673 | 3673 | |
| 3674 | - } |
|
| 3674 | + } |
|
| 3675 | 3675 | } |
| 3676 | 3676 | |
| 3677 | 3677 | // ----- Add the path |
| 3678 | 3678 | if ($p_path != '') { |
| 3679 | - $p_entry['filename'] = $p_path."/".$p_entry['filename']; |
|
| 3679 | + $p_entry['filename'] = $p_path."/".$p_entry['filename']; |
|
| 3680 | 3680 | } |
| 3681 | 3681 | |
| 3682 | 3682 | // ----- Check a base_dir_restriction |
| 3683 | 3683 | if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) { |
| 3684 | - $v_inclusion |
|
| 3685 | - = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION], |
|
| 3684 | + $v_inclusion |
|
| 3685 | + = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION], |
|
| 3686 | 3686 | $p_entry['filename']); |
| 3687 | - if ($v_inclusion == 0) { |
|
| 3687 | + if ($v_inclusion == 0) { |
|
| 3688 | 3688 | |
| 3689 | 3689 | PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION, |
| 3690 | - "Filename '".$p_entry['filename']."' is " |
|
| 3691 | - ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION"); |
|
| 3690 | + "Filename '".$p_entry['filename']."' is " |
|
| 3691 | + ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION"); |
|
| 3692 | 3692 | |
| 3693 | 3693 | return PclZip::errorCode(); |
| 3694 | - } |
|
| 3694 | + } |
|
| 3695 | 3695 | } |
| 3696 | 3696 | |
| 3697 | 3697 | // ----- Look for pre-extract callback |
| 3698 | 3698 | if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { |
| 3699 | 3699 | |
| 3700 | - // ----- Generate a local information |
|
| 3701 | - $v_local_header = array(); |
|
| 3702 | - $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
|
| 3700 | + // ----- Generate a local information |
|
| 3701 | + $v_local_header = array(); |
|
| 3702 | + $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
|
| 3703 | 3703 | |
| 3704 | - // ----- Call the callback |
|
| 3705 | - // Here I do not use call_user_func() because I need to send a reference to the |
|
| 3706 | - // header. |
|
| 3704 | + // ----- Call the callback |
|
| 3705 | + // Here I do not use call_user_func() because I need to send a reference to the |
|
| 3706 | + // header. |
|
| 3707 | 3707 | // eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);'); |
| 3708 | - $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header); |
|
| 3709 | - if ($v_result == 0) { |
|
| 3708 | + $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header); |
|
| 3709 | + if ($v_result == 0) { |
|
| 3710 | 3710 | // ----- Change the file status |
| 3711 | 3711 | $p_entry['status'] = "skipped"; |
| 3712 | 3712 | $v_result = 1; |
| 3713 | - } |
|
| 3713 | + } |
|
| 3714 | 3714 | |
| 3715 | - // ----- Look for abort result |
|
| 3716 | - if ($v_result == 2) { |
|
| 3715 | + // ----- Look for abort result |
|
| 3716 | + if ($v_result == 2) { |
|
| 3717 | 3717 | // ----- This status is internal and will be changed in 'skipped' |
| 3718 | 3718 | $p_entry['status'] = "aborted"; |
| 3719 | - $v_result = PCLZIP_ERR_USER_ABORTED; |
|
| 3720 | - } |
|
| 3719 | + $v_result = PCLZIP_ERR_USER_ABORTED; |
|
| 3720 | + } |
|
| 3721 | 3721 | |
| 3722 | - // ----- Update the informations |
|
| 3723 | - // Only some fields can be modified |
|
| 3724 | - $p_entry['filename'] = $v_local_header['filename']; |
|
| 3722 | + // ----- Update the informations |
|
| 3723 | + // Only some fields can be modified |
|
| 3724 | + $p_entry['filename'] = $v_local_header['filename']; |
|
| 3725 | 3725 | } |
| 3726 | 3726 | |
| 3727 | 3727 | |
@@ -3732,9 +3732,9 @@ discard block |
||
| 3732 | 3732 | if (file_exists($p_entry['filename'])) |
| 3733 | 3733 | { |
| 3734 | 3734 | |
| 3735 | - // ----- Look if file is a directory |
|
| 3736 | - if (is_dir($p_entry['filename'])) |
|
| 3737 | - { |
|
| 3735 | + // ----- Look if file is a directory |
|
| 3736 | + if (is_dir($p_entry['filename'])) |
|
| 3737 | + { |
|
| 3738 | 3738 | |
| 3739 | 3739 | // ----- Change the file status |
| 3740 | 3740 | $p_entry['status'] = "already_a_directory"; |
@@ -3743,18 +3743,18 @@ discard block |
||
| 3743 | 3743 | // For historical reason first PclZip implementation does not stop |
| 3744 | 3744 | // when this kind of error occurs. |
| 3745 | 3745 | if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
| 3746 | - && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3746 | + && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3747 | 3747 | |
| 3748 | 3748 | PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY, |
| 3749 | - "Filename '".$p_entry['filename']."' is " |
|
| 3750 | - ."already used by an existing directory"); |
|
| 3749 | + "Filename '".$p_entry['filename']."' is " |
|
| 3750 | + ."already used by an existing directory"); |
|
| 3751 | 3751 | |
| 3752 | 3752 | return PclZip::errorCode(); |
| 3753 | - } |
|
| 3754 | - } |
|
| 3755 | - // ----- Look if file is write protected |
|
| 3756 | - else if (!is_writeable($p_entry['filename'])) |
|
| 3757 | - { |
|
| 3753 | + } |
|
| 3754 | + } |
|
| 3755 | + // ----- Look if file is write protected |
|
| 3756 | + else if (!is_writeable($p_entry['filename'])) |
|
| 3757 | + { |
|
| 3758 | 3758 | |
| 3759 | 3759 | // ----- Change the file status |
| 3760 | 3760 | $p_entry['status'] = "write_protected"; |
@@ -3763,90 +3763,90 @@ discard block |
||
| 3763 | 3763 | // For historical reason first PclZip implementation does not stop |
| 3764 | 3764 | // when this kind of error occurs. |
| 3765 | 3765 | if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
| 3766 | - && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3766 | + && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3767 | 3767 | |
| 3768 | 3768 | PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, |
| 3769 | - "Filename '".$p_entry['filename']."' exists " |
|
| 3770 | - ."and is write protected"); |
|
| 3769 | + "Filename '".$p_entry['filename']."' exists " |
|
| 3770 | + ."and is write protected"); |
|
| 3771 | 3771 | |
| 3772 | 3772 | return PclZip::errorCode(); |
| 3773 | - } |
|
| 3774 | - } |
|
| 3773 | + } |
|
| 3774 | + } |
|
| 3775 | 3775 | |
| 3776 | - // ----- Look if the extracted file is older |
|
| 3777 | - else if (filemtime($p_entry['filename']) > $p_entry['mtime']) |
|
| 3778 | - { |
|
| 3776 | + // ----- Look if the extracted file is older |
|
| 3777 | + else if (filemtime($p_entry['filename']) > $p_entry['mtime']) |
|
| 3778 | + { |
|
| 3779 | 3779 | // ----- Change the file status |
| 3780 | 3780 | if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER])) |
| 3781 | - && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) { |
|
| 3782 | - } |
|
| 3783 | - else { |
|
| 3781 | + && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) { |
|
| 3782 | + } |
|
| 3783 | + else { |
|
| 3784 | 3784 | $p_entry['status'] = "newer_exist"; |
| 3785 | 3785 | |
| 3786 | 3786 | // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
| 3787 | 3787 | // For historical reason first PclZip implementation does not stop |
| 3788 | 3788 | // when this kind of error occurs. |
| 3789 | 3789 | if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
| 3790 | - && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3790 | + && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3791 | 3791 | |
| 3792 | 3792 | PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, |
| 3793 | - "Newer version of '".$p_entry['filename']."' exists " |
|
| 3794 | - ."and option PCLZIP_OPT_REPLACE_NEWER is not selected"); |
|
| 3793 | + "Newer version of '".$p_entry['filename']."' exists " |
|
| 3794 | + ."and option PCLZIP_OPT_REPLACE_NEWER is not selected"); |
|
| 3795 | 3795 | |
| 3796 | 3796 | return PclZip::errorCode(); |
| 3797 | - } |
|
| 3798 | - } |
|
| 3799 | - } |
|
| 3800 | - else { |
|
| 3801 | - } |
|
| 3797 | + } |
|
| 3798 | + } |
|
| 3799 | + } |
|
| 3800 | + else { |
|
| 3801 | + } |
|
| 3802 | 3802 | } |
| 3803 | 3803 | |
| 3804 | 3804 | // ----- Check the directory availability and create it if necessary |
| 3805 | 3805 | else { |
| 3806 | - if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/')) |
|
| 3806 | + if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/')) |
|
| 3807 | 3807 | $v_dir_to_check = $p_entry['filename']; |
| 3808 | - else if (!strstr($p_entry['filename'], "/")) |
|
| 3808 | + else if (!strstr($p_entry['filename'], "/")) |
|
| 3809 | 3809 | $v_dir_to_check = ""; |
| 3810 | - else |
|
| 3810 | + else |
|
| 3811 | 3811 | $v_dir_to_check = dirname($p_entry['filename']); |
| 3812 | 3812 | |
| 3813 | 3813 | if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) { |
| 3814 | 3814 | |
| 3815 | - // ----- Change the file status |
|
| 3816 | - $p_entry['status'] = "path_creation_fail"; |
|
| 3815 | + // ----- Change the file status |
|
| 3816 | + $p_entry['status'] = "path_creation_fail"; |
|
| 3817 | 3817 | |
| 3818 | - // ----- Return |
|
| 3819 | - //return $v_result; |
|
| 3820 | - $v_result = 1; |
|
| 3818 | + // ----- Return |
|
| 3819 | + //return $v_result; |
|
| 3820 | + $v_result = 1; |
|
| 3821 | + } |
|
| 3821 | 3822 | } |
| 3822 | - } |
|
| 3823 | 3823 | } |
| 3824 | 3824 | |
| 3825 | 3825 | // ----- Look if extraction should be done |
| 3826 | 3826 | if ($p_entry['status'] == 'ok') { |
| 3827 | 3827 | |
| 3828 | - // ----- Do the extraction (if not a folder) |
|
| 3829 | - if (!(($p_entry['external']&0x00000010)==0x00000010)) |
|
| 3830 | - { |
|
| 3828 | + // ----- Do the extraction (if not a folder) |
|
| 3829 | + if (!(($p_entry['external']&0x00000010)==0x00000010)) |
|
| 3830 | + { |
|
| 3831 | 3831 | // ----- Look for not compressed file |
| 3832 | 3832 | if ($p_entry['compression'] == 0) { |
| 3833 | 3833 | |
| 3834 | - // ----- Opening destination file |
|
| 3835 | - if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) |
|
| 3836 | - { |
|
| 3834 | + // ----- Opening destination file |
|
| 3835 | + if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) |
|
| 3836 | + { |
|
| 3837 | 3837 | |
| 3838 | 3838 | // ----- Change the file status |
| 3839 | 3839 | $p_entry['status'] = "write_error"; |
| 3840 | 3840 | |
| 3841 | 3841 | // ----- Return |
| 3842 | 3842 | return $v_result; |
| 3843 | - } |
|
| 3843 | + } |
|
| 3844 | 3844 | |
| 3845 | 3845 | |
| 3846 | - // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks |
|
| 3847 | - $v_size = $p_entry['compressed_size']; |
|
| 3848 | - while ($v_size != 0) |
|
| 3849 | - { |
|
| 3846 | + // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks |
|
| 3847 | + $v_size = $p_entry['compressed_size']; |
|
| 3848 | + while ($v_size != 0) |
|
| 3849 | + { |
|
| 3850 | 3850 | $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
| 3851 | 3851 | $v_buffer = @fread($this->zip_fd, $v_read_size); |
| 3852 | 3852 | /* Try to speed up the code |
@@ -3855,38 +3855,38 @@ discard block |
||
| 3855 | 3855 | */ |
| 3856 | 3856 | @fwrite($v_dest_file, $v_buffer, $v_read_size); |
| 3857 | 3857 | $v_size -= $v_read_size; |
| 3858 | - } |
|
| 3858 | + } |
|
| 3859 | 3859 | |
| 3860 | - // ----- Closing the destination file |
|
| 3861 | - fclose($v_dest_file); |
|
| 3860 | + // ----- Closing the destination file |
|
| 3861 | + fclose($v_dest_file); |
|
| 3862 | 3862 | |
| 3863 | - // ----- Change the file mtime |
|
| 3864 | - touch($p_entry['filename'], $p_entry['mtime']); |
|
| 3863 | + // ----- Change the file mtime |
|
| 3864 | + touch($p_entry['filename'], $p_entry['mtime']); |
|
| 3865 | 3865 | |
| 3866 | 3866 | |
| 3867 | 3867 | } |
| 3868 | 3868 | else { |
| 3869 | - // ----- TBC |
|
| 3870 | - // Need to be finished |
|
| 3871 | - if (($p_entry['flag'] & 1) == 1) { |
|
| 3869 | + // ----- TBC |
|
| 3870 | + // Need to be finished |
|
| 3871 | + if (($p_entry['flag'] & 1) == 1) { |
|
| 3872 | 3872 | PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'File \''.$p_entry['filename'].'\' is encrypted. Encrypted files are not supported.'); |
| 3873 | 3873 | return PclZip::errorCode(); |
| 3874 | - } |
|
| 3874 | + } |
|
| 3875 | 3875 | |
| 3876 | 3876 | |
| 3877 | - // ----- Look for using temporary file to unzip |
|
| 3878 | - if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) |
|
| 3877 | + // ----- Look for using temporary file to unzip |
|
| 3878 | + if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) |
|
| 3879 | 3879 | && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON]) |
| 3880 | 3880 | || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) |
| 3881 | 3881 | && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])) ) ) { |
| 3882 | 3882 | $v_result = $this->privExtractFileUsingTempFile($p_entry, $p_options); |
| 3883 | 3883 | if ($v_result < PCLZIP_ERR_NO_ERROR) { |
| 3884 | - return $v_result; |
|
| 3884 | + return $v_result; |
|
| 3885 | + } |
|
| 3885 | 3886 | } |
| 3886 | - } |
|
| 3887 | 3887 | |
| 3888 | - // ----- Look for extract in memory |
|
| 3889 | - else { |
|
| 3888 | + // ----- Look for extract in memory |
|
| 3889 | + else { |
|
| 3890 | 3890 | |
| 3891 | 3891 | |
| 3892 | 3892 | // ----- Read the compressed file in a buffer (one shot) |
@@ -3897,20 +3897,20 @@ discard block |
||
| 3897 | 3897 | unset($v_buffer); |
| 3898 | 3898 | if ($v_file_content === FALSE) { |
| 3899 | 3899 | |
| 3900 | - // ----- Change the file status |
|
| 3901 | - // TBC |
|
| 3902 | - $p_entry['status'] = "error"; |
|
| 3900 | + // ----- Change the file status |
|
| 3901 | + // TBC |
|
| 3902 | + $p_entry['status'] = "error"; |
|
| 3903 | 3903 | |
| 3904 | - return $v_result; |
|
| 3904 | + return $v_result; |
|
| 3905 | 3905 | } |
| 3906 | 3906 | |
| 3907 | 3907 | // ----- Opening destination file |
| 3908 | 3908 | if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { |
| 3909 | 3909 | |
| 3910 | - // ----- Change the file status |
|
| 3911 | - $p_entry['status'] = "write_error"; |
|
| 3910 | + // ----- Change the file status |
|
| 3911 | + $p_entry['status'] = "write_error"; |
|
| 3912 | 3912 | |
| 3913 | - return $v_result; |
|
| 3913 | + return $v_result; |
|
| 3914 | 3914 | } |
| 3915 | 3915 | |
| 3916 | 3916 | // ----- Write the uncompressed data |
@@ -3920,67 +3920,67 @@ discard block |
||
| 3920 | 3920 | // ----- Closing the destination file |
| 3921 | 3921 | @fclose($v_dest_file); |
| 3922 | 3922 | |
| 3923 | - } |
|
| 3923 | + } |
|
| 3924 | 3924 | |
| 3925 | - // ----- Change the file mtime |
|
| 3926 | - @touch($p_entry['filename'], $p_entry['mtime']); |
|
| 3925 | + // ----- Change the file mtime |
|
| 3926 | + @touch($p_entry['filename'], $p_entry['mtime']); |
|
| 3927 | 3927 | } |
| 3928 | 3928 | |
| 3929 | 3929 | // ----- Look for chmod option |
| 3930 | 3930 | if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) { |
| 3931 | 3931 | |
| 3932 | - // ----- Change the mode of the file |
|
| 3933 | - @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]); |
|
| 3932 | + // ----- Change the mode of the file |
|
| 3933 | + @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]); |
|
| 3934 | 3934 | } |
| 3935 | 3935 | |
| 3936 | - } |
|
| 3936 | + } |
|
| 3937 | 3937 | } |
| 3938 | 3938 | |
| 3939 | - // ----- Change abort status |
|
| 3940 | - if ($p_entry['status'] == "aborted") { |
|
| 3939 | + // ----- Change abort status |
|
| 3940 | + if ($p_entry['status'] == "aborted") { |
|
| 3941 | 3941 | $p_entry['status'] = "skipped"; |
| 3942 | - } |
|
| 3942 | + } |
|
| 3943 | 3943 | |
| 3944 | 3944 | // ----- Look for post-extract callback |
| 3945 | 3945 | elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { |
| 3946 | 3946 | |
| 3947 | - // ----- Generate a local information |
|
| 3948 | - $v_local_header = array(); |
|
| 3949 | - $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
|
| 3947 | + // ----- Generate a local information |
|
| 3948 | + $v_local_header = array(); |
|
| 3949 | + $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
|
| 3950 | 3950 | |
| 3951 | - // ----- Call the callback |
|
| 3952 | - // Here I do not use call_user_func() because I need to send a reference to the |
|
| 3953 | - // header. |
|
| 3951 | + // ----- Call the callback |
|
| 3952 | + // Here I do not use call_user_func() because I need to send a reference to the |
|
| 3953 | + // header. |
|
| 3954 | 3954 | // eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);'); |
| 3955 | - $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header); |
|
| 3955 | + $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header); |
|
| 3956 | 3956 | |
| 3957 | - // ----- Look for abort result |
|
| 3958 | - if ($v_result == 2) { |
|
| 3959 | - $v_result = PCLZIP_ERR_USER_ABORTED; |
|
| 3960 | - } |
|
| 3957 | + // ----- Look for abort result |
|
| 3958 | + if ($v_result == 2) { |
|
| 3959 | + $v_result = PCLZIP_ERR_USER_ABORTED; |
|
| 3960 | + } |
|
| 3961 | 3961 | } |
| 3962 | 3962 | |
| 3963 | 3963 | // ----- Return |
| 3964 | 3964 | return $v_result; |
| 3965 | - } |
|
| 3966 | - // -------------------------------------------------------------------------------- |
|
| 3967 | - |
|
| 3968 | - // -------------------------------------------------------------------------------- |
|
| 3969 | - // Function : privExtractFileUsingTempFile() |
|
| 3970 | - // Description : |
|
| 3971 | - // Parameters : |
|
| 3972 | - // Return Values : |
|
| 3973 | - // -------------------------------------------------------------------------------- |
|
| 3974 | - function privExtractFileUsingTempFile(&$p_entry, &$p_options) |
|
| 3975 | - { |
|
| 3965 | + } |
|
| 3966 | + // -------------------------------------------------------------------------------- |
|
| 3967 | + |
|
| 3968 | + // -------------------------------------------------------------------------------- |
|
| 3969 | + // Function : privExtractFileUsingTempFile() |
|
| 3970 | + // Description : |
|
| 3971 | + // Parameters : |
|
| 3972 | + // Return Values : |
|
| 3973 | + // -------------------------------------------------------------------------------- |
|
| 3974 | + function privExtractFileUsingTempFile(&$p_entry, &$p_options) |
|
| 3975 | + { |
|
| 3976 | 3976 | $v_result=1; |
| 3977 | 3977 | |
| 3978 | 3978 | // ----- Creates a temporary file |
| 3979 | 3979 | $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz'; |
| 3980 | 3980 | if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) { |
| 3981 | - fclose($v_file); |
|
| 3982 | - PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode'); |
|
| 3983 | - return PclZip::errorCode(); |
|
| 3981 | + fclose($v_file); |
|
| 3982 | + PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode'); |
|
| 3983 | + return PclZip::errorCode(); |
|
| 3984 | 3984 | } |
| 3985 | 3985 | |
| 3986 | 3986 | |
@@ -3992,11 +3992,11 @@ discard block |
||
| 3992 | 3992 | $v_size = $p_entry['compressed_size']; |
| 3993 | 3993 | while ($v_size != 0) |
| 3994 | 3994 | { |
| 3995 | - $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 3996 | - $v_buffer = @fread($this->zip_fd, $v_read_size); |
|
| 3997 | - //$v_binary_data = pack('a'.$v_read_size, $v_buffer); |
|
| 3998 | - @fwrite($v_dest_file, $v_buffer, $v_read_size); |
|
| 3999 | - $v_size -= $v_read_size; |
|
| 3995 | + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 3996 | + $v_buffer = @fread($this->zip_fd, $v_read_size); |
|
| 3997 | + //$v_binary_data = pack('a'.$v_read_size, $v_buffer); |
|
| 3998 | + @fwrite($v_dest_file, $v_buffer, $v_read_size); |
|
| 3999 | + $v_size -= $v_read_size; |
|
| 4000 | 4000 | } |
| 4001 | 4001 | |
| 4002 | 4002 | // ----- Write gz file format footer |
@@ -4008,27 +4008,27 @@ discard block |
||
| 4008 | 4008 | |
| 4009 | 4009 | // ----- Opening destination file |
| 4010 | 4010 | if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { |
| 4011 | - $p_entry['status'] = "write_error"; |
|
| 4012 | - return $v_result; |
|
| 4011 | + $p_entry['status'] = "write_error"; |
|
| 4012 | + return $v_result; |
|
| 4013 | 4013 | } |
| 4014 | 4014 | |
| 4015 | 4015 | // ----- Open the temporary gz file |
| 4016 | 4016 | if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) { |
| 4017 | - @fclose($v_dest_file); |
|
| 4018 | - $p_entry['status'] = "read_error"; |
|
| 4019 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); |
|
| 4020 | - return PclZip::errorCode(); |
|
| 4017 | + @fclose($v_dest_file); |
|
| 4018 | + $p_entry['status'] = "read_error"; |
|
| 4019 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode'); |
|
| 4020 | + return PclZip::errorCode(); |
|
| 4021 | 4021 | } |
| 4022 | 4022 | |
| 4023 | 4023 | |
| 4024 | 4024 | // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks |
| 4025 | 4025 | $v_size = $p_entry['size']; |
| 4026 | 4026 | while ($v_size != 0) { |
| 4027 | - $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 4028 | - $v_buffer = @gzread($v_src_file, $v_read_size); |
|
| 4029 | - //$v_binary_data = pack('a'.$v_read_size, $v_buffer); |
|
| 4030 | - @fwrite($v_dest_file, $v_buffer, $v_read_size); |
|
| 4031 | - $v_size -= $v_read_size; |
|
| 4027 | + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 4028 | + $v_buffer = @gzread($v_src_file, $v_read_size); |
|
| 4029 | + //$v_binary_data = pack('a'.$v_read_size, $v_buffer); |
|
| 4030 | + @fwrite($v_dest_file, $v_buffer, $v_read_size); |
|
| 4031 | + $v_size -= $v_read_size; |
|
| 4032 | 4032 | } |
| 4033 | 4033 | @fclose($v_dest_file); |
| 4034 | 4034 | @gzclose($v_src_file); |
@@ -4038,22 +4038,22 @@ discard block |
||
| 4038 | 4038 | |
| 4039 | 4039 | // ----- Return |
| 4040 | 4040 | return $v_result; |
| 4041 | - } |
|
| 4042 | - // -------------------------------------------------------------------------------- |
|
| 4043 | - |
|
| 4044 | - // -------------------------------------------------------------------------------- |
|
| 4045 | - // Function : privExtractFileInOutput() |
|
| 4046 | - // Description : |
|
| 4047 | - // Parameters : |
|
| 4048 | - // Return Values : |
|
| 4049 | - // -------------------------------------------------------------------------------- |
|
| 4050 | - function privExtractFileInOutput(&$p_entry, &$p_options) |
|
| 4051 | - { |
|
| 4041 | + } |
|
| 4042 | + // -------------------------------------------------------------------------------- |
|
| 4043 | + |
|
| 4044 | + // -------------------------------------------------------------------------------- |
|
| 4045 | + // Function : privExtractFileInOutput() |
|
| 4046 | + // Description : |
|
| 4047 | + // Parameters : |
|
| 4048 | + // Return Values : |
|
| 4049 | + // -------------------------------------------------------------------------------- |
|
| 4050 | + function privExtractFileInOutput(&$p_entry, &$p_options) |
|
| 4051 | + { |
|
| 4052 | 4052 | $v_result=1; |
| 4053 | 4053 | |
| 4054 | 4054 | // ----- Read the file header |
| 4055 | 4055 | if (($v_result = $this->privReadFileHeader($v_header)) != 1) { |
| 4056 | - return $v_result; |
|
| 4056 | + return $v_result; |
|
| 4057 | 4057 | } |
| 4058 | 4058 | |
| 4059 | 4059 | |
@@ -4065,31 +4065,31 @@ discard block |
||
| 4065 | 4065 | // ----- Look for pre-extract callback |
| 4066 | 4066 | if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { |
| 4067 | 4067 | |
| 4068 | - // ----- Generate a local information |
|
| 4069 | - $v_local_header = array(); |
|
| 4070 | - $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
|
| 4068 | + // ----- Generate a local information |
|
| 4069 | + $v_local_header = array(); |
|
| 4070 | + $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
|
| 4071 | 4071 | |
| 4072 | - // ----- Call the callback |
|
| 4073 | - // Here I do not use call_user_func() because I need to send a reference to the |
|
| 4074 | - // header. |
|
| 4072 | + // ----- Call the callback |
|
| 4073 | + // Here I do not use call_user_func() because I need to send a reference to the |
|
| 4074 | + // header. |
|
| 4075 | 4075 | // eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);'); |
| 4076 | - $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header); |
|
| 4077 | - if ($v_result == 0) { |
|
| 4076 | + $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header); |
|
| 4077 | + if ($v_result == 0) { |
|
| 4078 | 4078 | // ----- Change the file status |
| 4079 | 4079 | $p_entry['status'] = "skipped"; |
| 4080 | 4080 | $v_result = 1; |
| 4081 | - } |
|
| 4081 | + } |
|
| 4082 | 4082 | |
| 4083 | - // ----- Look for abort result |
|
| 4084 | - if ($v_result == 2) { |
|
| 4083 | + // ----- Look for abort result |
|
| 4084 | + if ($v_result == 2) { |
|
| 4085 | 4085 | // ----- This status is internal and will be changed in 'skipped' |
| 4086 | 4086 | $p_entry['status'] = "aborted"; |
| 4087 | - $v_result = PCLZIP_ERR_USER_ABORTED; |
|
| 4088 | - } |
|
| 4087 | + $v_result = PCLZIP_ERR_USER_ABORTED; |
|
| 4088 | + } |
|
| 4089 | 4089 | |
| 4090 | - // ----- Update the informations |
|
| 4091 | - // Only some fields can be modified |
|
| 4092 | - $p_entry['filename'] = $v_local_header['filename']; |
|
| 4090 | + // ----- Update the informations |
|
| 4091 | + // Only some fields can be modified |
|
| 4092 | + $p_entry['filename'] = $v_local_header['filename']; |
|
| 4093 | 4093 | } |
| 4094 | 4094 | |
| 4095 | 4095 | // ----- Trace |
@@ -4097,78 +4097,78 @@ discard block |
||
| 4097 | 4097 | // ----- Look if extraction should be done |
| 4098 | 4098 | if ($p_entry['status'] == 'ok') { |
| 4099 | 4099 | |
| 4100 | - // ----- Do the extraction (if not a folder) |
|
| 4101 | - if (!(($p_entry['external']&0x00000010)==0x00000010)) { |
|
| 4100 | + // ----- Do the extraction (if not a folder) |
|
| 4101 | + if (!(($p_entry['external']&0x00000010)==0x00000010)) { |
|
| 4102 | 4102 | // ----- Look for not compressed file |
| 4103 | 4103 | if ($p_entry['compressed_size'] == $p_entry['size']) { |
| 4104 | 4104 | |
| 4105 | - // ----- Read the file in a buffer (one shot) |
|
| 4106 | - $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); |
|
| 4105 | + // ----- Read the file in a buffer (one shot) |
|
| 4106 | + $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); |
|
| 4107 | 4107 | |
| 4108 | - // ----- Send the file to the output |
|
| 4109 | - echo $v_buffer; |
|
| 4110 | - unset($v_buffer); |
|
| 4108 | + // ----- Send the file to the output |
|
| 4109 | + echo $v_buffer; |
|
| 4110 | + unset($v_buffer); |
|
| 4111 | 4111 | } |
| 4112 | 4112 | else { |
| 4113 | 4113 | |
| 4114 | - // ----- Read the compressed file in a buffer (one shot) |
|
| 4115 | - $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); |
|
| 4114 | + // ----- Read the compressed file in a buffer (one shot) |
|
| 4115 | + $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); |
|
| 4116 | 4116 | |
| 4117 | - // ----- Decompress the file |
|
| 4118 | - $v_file_content = gzinflate($v_buffer); |
|
| 4119 | - unset($v_buffer); |
|
| 4117 | + // ----- Decompress the file |
|
| 4118 | + $v_file_content = gzinflate($v_buffer); |
|
| 4119 | + unset($v_buffer); |
|
| 4120 | 4120 | |
| 4121 | - // ----- Send the file to the output |
|
| 4122 | - echo $v_file_content; |
|
| 4123 | - unset($v_file_content); |
|
| 4121 | + // ----- Send the file to the output |
|
| 4122 | + echo $v_file_content; |
|
| 4123 | + unset($v_file_content); |
|
| 4124 | + } |
|
| 4124 | 4125 | } |
| 4125 | - } |
|
| 4126 | 4126 | } |
| 4127 | 4127 | |
| 4128 | - // ----- Change abort status |
|
| 4129 | - if ($p_entry['status'] == "aborted") { |
|
| 4130 | - $p_entry['status'] = "skipped"; |
|
| 4131 | - } |
|
| 4128 | + // ----- Change abort status |
|
| 4129 | + if ($p_entry['status'] == "aborted") { |
|
| 4130 | + $p_entry['status'] = "skipped"; |
|
| 4131 | + } |
|
| 4132 | 4132 | |
| 4133 | 4133 | // ----- Look for post-extract callback |
| 4134 | 4134 | elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { |
| 4135 | 4135 | |
| 4136 | - // ----- Generate a local information |
|
| 4137 | - $v_local_header = array(); |
|
| 4138 | - $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
|
| 4136 | + // ----- Generate a local information |
|
| 4137 | + $v_local_header = array(); |
|
| 4138 | + $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
|
| 4139 | 4139 | |
| 4140 | - // ----- Call the callback |
|
| 4141 | - // Here I do not use call_user_func() because I need to send a reference to the |
|
| 4142 | - // header. |
|
| 4140 | + // ----- Call the callback |
|
| 4141 | + // Here I do not use call_user_func() because I need to send a reference to the |
|
| 4142 | + // header. |
|
| 4143 | 4143 | // eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);'); |
| 4144 | - $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header); |
|
| 4144 | + $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header); |
|
| 4145 | 4145 | |
| 4146 | - // ----- Look for abort result |
|
| 4147 | - if ($v_result == 2) { |
|
| 4148 | - $v_result = PCLZIP_ERR_USER_ABORTED; |
|
| 4149 | - } |
|
| 4146 | + // ----- Look for abort result |
|
| 4147 | + if ($v_result == 2) { |
|
| 4148 | + $v_result = PCLZIP_ERR_USER_ABORTED; |
|
| 4149 | + } |
|
| 4150 | 4150 | } |
| 4151 | 4151 | |
| 4152 | 4152 | return $v_result; |
| 4153 | - } |
|
| 4154 | - // -------------------------------------------------------------------------------- |
|
| 4155 | - |
|
| 4156 | - // -------------------------------------------------------------------------------- |
|
| 4157 | - // Function : privExtractFileAsString() |
|
| 4158 | - // Description : |
|
| 4159 | - // Parameters : |
|
| 4160 | - // Return Values : |
|
| 4161 | - // -------------------------------------------------------------------------------- |
|
| 4162 | - function privExtractFileAsString(&$p_entry, &$p_string, &$p_options) |
|
| 4163 | - { |
|
| 4153 | + } |
|
| 4154 | + // -------------------------------------------------------------------------------- |
|
| 4155 | + |
|
| 4156 | + // -------------------------------------------------------------------------------- |
|
| 4157 | + // Function : privExtractFileAsString() |
|
| 4158 | + // Description : |
|
| 4159 | + // Parameters : |
|
| 4160 | + // Return Values : |
|
| 4161 | + // -------------------------------------------------------------------------------- |
|
| 4162 | + function privExtractFileAsString(&$p_entry, &$p_string, &$p_options) |
|
| 4163 | + { |
|
| 4164 | 4164 | $v_result=1; |
| 4165 | 4165 | |
| 4166 | 4166 | // ----- Read the file header |
| 4167 | 4167 | $v_header = array(); |
| 4168 | 4168 | if (($v_result = $this->privReadFileHeader($v_header)) != 1) |
| 4169 | 4169 | { |
| 4170 | - // ----- Return |
|
| 4171 | - return $v_result; |
|
| 4170 | + // ----- Return |
|
| 4171 | + return $v_result; |
|
| 4172 | 4172 | } |
| 4173 | 4173 | |
| 4174 | 4174 | |
@@ -4180,110 +4180,110 @@ discard block |
||
| 4180 | 4180 | // ----- Look for pre-extract callback |
| 4181 | 4181 | if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) { |
| 4182 | 4182 | |
| 4183 | - // ----- Generate a local information |
|
| 4184 | - $v_local_header = array(); |
|
| 4185 | - $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
|
| 4183 | + // ----- Generate a local information |
|
| 4184 | + $v_local_header = array(); |
|
| 4185 | + $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
|
| 4186 | 4186 | |
| 4187 | - // ----- Call the callback |
|
| 4188 | - // Here I do not use call_user_func() because I need to send a reference to the |
|
| 4189 | - // header. |
|
| 4187 | + // ----- Call the callback |
|
| 4188 | + // Here I do not use call_user_func() because I need to send a reference to the |
|
| 4189 | + // header. |
|
| 4190 | 4190 | // eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);'); |
| 4191 | - $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header); |
|
| 4192 | - if ($v_result == 0) { |
|
| 4191 | + $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header); |
|
| 4192 | + if ($v_result == 0) { |
|
| 4193 | 4193 | // ----- Change the file status |
| 4194 | 4194 | $p_entry['status'] = "skipped"; |
| 4195 | 4195 | $v_result = 1; |
| 4196 | - } |
|
| 4196 | + } |
|
| 4197 | 4197 | |
| 4198 | - // ----- Look for abort result |
|
| 4199 | - if ($v_result == 2) { |
|
| 4198 | + // ----- Look for abort result |
|
| 4199 | + if ($v_result == 2) { |
|
| 4200 | 4200 | // ----- This status is internal and will be changed in 'skipped' |
| 4201 | 4201 | $p_entry['status'] = "aborted"; |
| 4202 | - $v_result = PCLZIP_ERR_USER_ABORTED; |
|
| 4203 | - } |
|
| 4202 | + $v_result = PCLZIP_ERR_USER_ABORTED; |
|
| 4203 | + } |
|
| 4204 | 4204 | |
| 4205 | - // ----- Update the informations |
|
| 4206 | - // Only some fields can be modified |
|
| 4207 | - $p_entry['filename'] = $v_local_header['filename']; |
|
| 4205 | + // ----- Update the informations |
|
| 4206 | + // Only some fields can be modified |
|
| 4207 | + $p_entry['filename'] = $v_local_header['filename']; |
|
| 4208 | 4208 | } |
| 4209 | 4209 | |
| 4210 | 4210 | |
| 4211 | 4211 | // ----- Look if extraction should be done |
| 4212 | 4212 | if ($p_entry['status'] == 'ok') { |
| 4213 | 4213 | |
| 4214 | - // ----- Do the extraction (if not a folder) |
|
| 4215 | - if (!(($p_entry['external']&0x00000010)==0x00000010)) { |
|
| 4214 | + // ----- Do the extraction (if not a folder) |
|
| 4215 | + if (!(($p_entry['external']&0x00000010)==0x00000010)) { |
|
| 4216 | 4216 | // ----- Look for not compressed file |
| 4217 | - // if ($p_entry['compressed_size'] == $p_entry['size']) |
|
| 4217 | + // if ($p_entry['compressed_size'] == $p_entry['size']) |
|
| 4218 | 4218 | if ($p_entry['compression'] == 0) { |
| 4219 | 4219 | |
| 4220 | - // ----- Reading the file |
|
| 4221 | - $p_string = @fread($this->zip_fd, $p_entry['compressed_size']); |
|
| 4220 | + // ----- Reading the file |
|
| 4221 | + $p_string = @fread($this->zip_fd, $p_entry['compressed_size']); |
|
| 4222 | 4222 | } |
| 4223 | 4223 | else { |
| 4224 | 4224 | |
| 4225 | - // ----- Reading the file |
|
| 4226 | - $v_data = @fread($this->zip_fd, $p_entry['compressed_size']); |
|
| 4225 | + // ----- Reading the file |
|
| 4226 | + $v_data = @fread($this->zip_fd, $p_entry['compressed_size']); |
|
| 4227 | 4227 | |
| 4228 | - // ----- Decompress the file |
|
| 4229 | - if (($p_string = @gzinflate($v_data)) === FALSE) { |
|
| 4230 | - // TBC |
|
| 4231 | - } |
|
| 4228 | + // ----- Decompress the file |
|
| 4229 | + if (($p_string = @gzinflate($v_data)) === FALSE) { |
|
| 4230 | + // TBC |
|
| 4231 | + } |
|
| 4232 | 4232 | } |
| 4233 | 4233 | |
| 4234 | 4234 | // ----- Trace |
| 4235 | - } |
|
| 4236 | - else { |
|
| 4237 | - // TBC : error : can not extract a folder in a string |
|
| 4238 | - } |
|
| 4235 | + } |
|
| 4236 | + else { |
|
| 4237 | + // TBC : error : can not extract a folder in a string |
|
| 4238 | + } |
|
| 4239 | 4239 | |
| 4240 | 4240 | } |
| 4241 | 4241 | |
| 4242 | - // ----- Change abort status |
|
| 4243 | - if ($p_entry['status'] == "aborted") { |
|
| 4242 | + // ----- Change abort status |
|
| 4243 | + if ($p_entry['status'] == "aborted") { |
|
| 4244 | 4244 | $p_entry['status'] = "skipped"; |
| 4245 | - } |
|
| 4245 | + } |
|
| 4246 | 4246 | |
| 4247 | 4247 | // ----- Look for post-extract callback |
| 4248 | 4248 | elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) { |
| 4249 | 4249 | |
| 4250 | - // ----- Generate a local information |
|
| 4251 | - $v_local_header = array(); |
|
| 4252 | - $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
|
| 4250 | + // ----- Generate a local information |
|
| 4251 | + $v_local_header = array(); |
|
| 4252 | + $this->privConvertHeader2FileInfo($p_entry, $v_local_header); |
|
| 4253 | 4253 | |
| 4254 | - // ----- Swap the content to header |
|
| 4255 | - $v_local_header['content'] = $p_string; |
|
| 4256 | - $p_string = ''; |
|
| 4254 | + // ----- Swap the content to header |
|
| 4255 | + $v_local_header['content'] = $p_string; |
|
| 4256 | + $p_string = ''; |
|
| 4257 | 4257 | |
| 4258 | - // ----- Call the callback |
|
| 4259 | - // Here I do not use call_user_func() because I need to send a reference to the |
|
| 4260 | - // header. |
|
| 4258 | + // ----- Call the callback |
|
| 4259 | + // Here I do not use call_user_func() because I need to send a reference to the |
|
| 4260 | + // header. |
|
| 4261 | 4261 | // eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);'); |
| 4262 | - $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header); |
|
| 4262 | + $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header); |
|
| 4263 | 4263 | |
| 4264 | - // ----- Swap back the content to header |
|
| 4265 | - $p_string = $v_local_header['content']; |
|
| 4266 | - unset($v_local_header['content']); |
|
| 4264 | + // ----- Swap back the content to header |
|
| 4265 | + $p_string = $v_local_header['content']; |
|
| 4266 | + unset($v_local_header['content']); |
|
| 4267 | 4267 | |
| 4268 | - // ----- Look for abort result |
|
| 4269 | - if ($v_result == 2) { |
|
| 4270 | - $v_result = PCLZIP_ERR_USER_ABORTED; |
|
| 4271 | - } |
|
| 4268 | + // ----- Look for abort result |
|
| 4269 | + if ($v_result == 2) { |
|
| 4270 | + $v_result = PCLZIP_ERR_USER_ABORTED; |
|
| 4271 | + } |
|
| 4272 | 4272 | } |
| 4273 | 4273 | |
| 4274 | 4274 | // ----- Return |
| 4275 | 4275 | return $v_result; |
| 4276 | - } |
|
| 4277 | - // -------------------------------------------------------------------------------- |
|
| 4278 | - |
|
| 4279 | - // -------------------------------------------------------------------------------- |
|
| 4280 | - // Function : privReadFileHeader() |
|
| 4281 | - // Description : |
|
| 4282 | - // Parameters : |
|
| 4283 | - // Return Values : |
|
| 4284 | - // -------------------------------------------------------------------------------- |
|
| 4285 | - function privReadFileHeader(&$p_header) |
|
| 4286 | - { |
|
| 4276 | + } |
|
| 4277 | + // -------------------------------------------------------------------------------- |
|
| 4278 | + |
|
| 4279 | + // -------------------------------------------------------------------------------- |
|
| 4280 | + // Function : privReadFileHeader() |
|
| 4281 | + // Description : |
|
| 4282 | + // Parameters : |
|
| 4283 | + // Return Values : |
|
| 4284 | + // -------------------------------------------------------------------------------- |
|
| 4285 | + function privReadFileHeader(&$p_header) |
|
| 4286 | + { |
|
| 4287 | 4287 | $v_result=1; |
| 4288 | 4288 | |
| 4289 | 4289 | // ----- Read the 4 bytes signature |
@@ -4294,11 +4294,11 @@ discard block |
||
| 4294 | 4294 | if ($v_data['id'] != 0x04034b50) |
| 4295 | 4295 | { |
| 4296 | 4296 | |
| 4297 | - // ----- Error log |
|
| 4298 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); |
|
| 4297 | + // ----- Error log |
|
| 4298 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); |
|
| 4299 | 4299 | |
| 4300 | - // ----- Return |
|
| 4301 | - return PclZip::errorCode(); |
|
| 4300 | + // ----- Return |
|
| 4301 | + return PclZip::errorCode(); |
|
| 4302 | 4302 | } |
| 4303 | 4303 | |
| 4304 | 4304 | // ----- Read the first 42 bytes of the header |
@@ -4307,14 +4307,14 @@ discard block |
||
| 4307 | 4307 | // ----- Look for invalid block size |
| 4308 | 4308 | if (strlen($v_binary_data) != 26) |
| 4309 | 4309 | { |
| 4310 | - $p_header['filename'] = ""; |
|
| 4311 | - $p_header['status'] = "invalid_header"; |
|
| 4310 | + $p_header['filename'] = ""; |
|
| 4311 | + $p_header['status'] = "invalid_header"; |
|
| 4312 | 4312 | |
| 4313 | - // ----- Error log |
|
| 4314 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); |
|
| 4313 | + // ----- Error log |
|
| 4314 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); |
|
| 4315 | 4315 | |
| 4316 | - // ----- Return |
|
| 4317 | - return PclZip::errorCode(); |
|
| 4316 | + // ----- Return |
|
| 4317 | + return PclZip::errorCode(); |
|
| 4318 | 4318 | } |
| 4319 | 4319 | |
| 4320 | 4320 | // ----- Extract the values |
@@ -4325,10 +4325,10 @@ discard block |
||
| 4325 | 4325 | |
| 4326 | 4326 | // ----- Get extra_fields |
| 4327 | 4327 | if ($v_data['extra_len'] != 0) { |
| 4328 | - $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']); |
|
| 4328 | + $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']); |
|
| 4329 | 4329 | } |
| 4330 | 4330 | else { |
| 4331 | - $p_header['extra'] = ''; |
|
| 4331 | + $p_header['extra'] = ''; |
|
| 4332 | 4332 | } |
| 4333 | 4333 | |
| 4334 | 4334 | // ----- Extract properties |
@@ -4345,23 +4345,23 @@ discard block |
||
| 4345 | 4345 | $p_header['mtime'] = $v_data['mtime']; |
| 4346 | 4346 | if ($p_header['mdate'] && $p_header['mtime']) |
| 4347 | 4347 | { |
| 4348 | - // ----- Extract time |
|
| 4349 | - $v_hour = ($p_header['mtime'] & 0xF800) >> 11; |
|
| 4350 | - $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; |
|
| 4351 | - $v_seconde = ($p_header['mtime'] & 0x001F)*2; |
|
| 4348 | + // ----- Extract time |
|
| 4349 | + $v_hour = ($p_header['mtime'] & 0xF800) >> 11; |
|
| 4350 | + $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; |
|
| 4351 | + $v_seconde = ($p_header['mtime'] & 0x001F)*2; |
|
| 4352 | 4352 | |
| 4353 | - // ----- Extract date |
|
| 4354 | - $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; |
|
| 4355 | - $v_month = ($p_header['mdate'] & 0x01E0) >> 5; |
|
| 4356 | - $v_day = $p_header['mdate'] & 0x001F; |
|
| 4353 | + // ----- Extract date |
|
| 4354 | + $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; |
|
| 4355 | + $v_month = ($p_header['mdate'] & 0x01E0) >> 5; |
|
| 4356 | + $v_day = $p_header['mdate'] & 0x001F; |
|
| 4357 | 4357 | |
| 4358 | - // ----- Get UNIX date format |
|
| 4359 | - $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); |
|
| 4358 | + // ----- Get UNIX date format |
|
| 4359 | + $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); |
|
| 4360 | 4360 | |
| 4361 | 4361 | } |
| 4362 | 4362 | else |
| 4363 | 4363 | { |
| 4364 | - $p_header['mtime'] = time(); |
|
| 4364 | + $p_header['mtime'] = time(); |
|
| 4365 | 4365 | } |
| 4366 | 4366 | |
| 4367 | 4367 | // TBC |
@@ -4376,17 +4376,17 @@ discard block |
||
| 4376 | 4376 | |
| 4377 | 4377 | // ----- Return |
| 4378 | 4378 | return $v_result; |
| 4379 | - } |
|
| 4380 | - // -------------------------------------------------------------------------------- |
|
| 4381 | - |
|
| 4382 | - // -------------------------------------------------------------------------------- |
|
| 4383 | - // Function : privReadCentralFileHeader() |
|
| 4384 | - // Description : |
|
| 4385 | - // Parameters : |
|
| 4386 | - // Return Values : |
|
| 4387 | - // -------------------------------------------------------------------------------- |
|
| 4388 | - function privReadCentralFileHeader(&$p_header) |
|
| 4389 | - { |
|
| 4379 | + } |
|
| 4380 | + // -------------------------------------------------------------------------------- |
|
| 4381 | + |
|
| 4382 | + // -------------------------------------------------------------------------------- |
|
| 4383 | + // Function : privReadCentralFileHeader() |
|
| 4384 | + // Description : |
|
| 4385 | + // Parameters : |
|
| 4386 | + // Return Values : |
|
| 4387 | + // -------------------------------------------------------------------------------- |
|
| 4388 | + function privReadCentralFileHeader(&$p_header) |
|
| 4389 | + { |
|
| 4390 | 4390 | $v_result=1; |
| 4391 | 4391 | |
| 4392 | 4392 | // ----- Read the 4 bytes signature |
@@ -4397,11 +4397,11 @@ discard block |
||
| 4397 | 4397 | if ($v_data['id'] != 0x02014b50) |
| 4398 | 4398 | { |
| 4399 | 4399 | |
| 4400 | - // ----- Error log |
|
| 4401 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); |
|
| 4400 | + // ----- Error log |
|
| 4401 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure'); |
|
| 4402 | 4402 | |
| 4403 | - // ----- Return |
|
| 4404 | - return PclZip::errorCode(); |
|
| 4403 | + // ----- Return |
|
| 4404 | + return PclZip::errorCode(); |
|
| 4405 | 4405 | } |
| 4406 | 4406 | |
| 4407 | 4407 | // ----- Read the first 42 bytes of the header |
@@ -4410,14 +4410,14 @@ discard block |
||
| 4410 | 4410 | // ----- Look for invalid block size |
| 4411 | 4411 | if (strlen($v_binary_data) != 42) |
| 4412 | 4412 | { |
| 4413 | - $p_header['filename'] = ""; |
|
| 4414 | - $p_header['status'] = "invalid_header"; |
|
| 4413 | + $p_header['filename'] = ""; |
|
| 4414 | + $p_header['status'] = "invalid_header"; |
|
| 4415 | 4415 | |
| 4416 | - // ----- Error log |
|
| 4417 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); |
|
| 4416 | + // ----- Error log |
|
| 4417 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data)); |
|
| 4418 | 4418 | |
| 4419 | - // ----- Return |
|
| 4420 | - return PclZip::errorCode(); |
|
| 4419 | + // ----- Return |
|
| 4420 | + return PclZip::errorCode(); |
|
| 4421 | 4421 | } |
| 4422 | 4422 | |
| 4423 | 4423 | // ----- Extract the values |
@@ -4425,21 +4425,21 @@ discard block |
||
| 4425 | 4425 | |
| 4426 | 4426 | // ----- Get filename |
| 4427 | 4427 | if ($p_header['filename_len'] != 0) |
| 4428 | - $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']); |
|
| 4428 | + $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']); |
|
| 4429 | 4429 | else |
| 4430 | - $p_header['filename'] = ''; |
|
| 4430 | + $p_header['filename'] = ''; |
|
| 4431 | 4431 | |
| 4432 | 4432 | // ----- Get extra |
| 4433 | 4433 | if ($p_header['extra_len'] != 0) |
| 4434 | - $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']); |
|
| 4434 | + $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']); |
|
| 4435 | 4435 | else |
| 4436 | - $p_header['extra'] = ''; |
|
| 4436 | + $p_header['extra'] = ''; |
|
| 4437 | 4437 | |
| 4438 | 4438 | // ----- Get comment |
| 4439 | 4439 | if ($p_header['comment_len'] != 0) |
| 4440 | - $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']); |
|
| 4440 | + $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']); |
|
| 4441 | 4441 | else |
| 4442 | - $p_header['comment'] = ''; |
|
| 4442 | + $p_header['comment'] = ''; |
|
| 4443 | 4443 | |
| 4444 | 4444 | // ----- Extract properties |
| 4445 | 4445 | |
@@ -4448,23 +4448,23 @@ discard block |
||
| 4448 | 4448 | // TBC : bug : this was ignoring time with 0/0/0 |
| 4449 | 4449 | if (1) |
| 4450 | 4450 | { |
| 4451 | - // ----- Extract time |
|
| 4452 | - $v_hour = ($p_header['mtime'] & 0xF800) >> 11; |
|
| 4453 | - $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; |
|
| 4454 | - $v_seconde = ($p_header['mtime'] & 0x001F)*2; |
|
| 4451 | + // ----- Extract time |
|
| 4452 | + $v_hour = ($p_header['mtime'] & 0xF800) >> 11; |
|
| 4453 | + $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; |
|
| 4454 | + $v_seconde = ($p_header['mtime'] & 0x001F)*2; |
|
| 4455 | 4455 | |
| 4456 | - // ----- Extract date |
|
| 4457 | - $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; |
|
| 4458 | - $v_month = ($p_header['mdate'] & 0x01E0) >> 5; |
|
| 4459 | - $v_day = $p_header['mdate'] & 0x001F; |
|
| 4456 | + // ----- Extract date |
|
| 4457 | + $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; |
|
| 4458 | + $v_month = ($p_header['mdate'] & 0x01E0) >> 5; |
|
| 4459 | + $v_day = $p_header['mdate'] & 0x001F; |
|
| 4460 | 4460 | |
| 4461 | - // ----- Get UNIX date format |
|
| 4462 | - $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); |
|
| 4461 | + // ----- Get UNIX date format |
|
| 4462 | + $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); |
|
| 4463 | 4463 | |
| 4464 | 4464 | } |
| 4465 | 4465 | else |
| 4466 | 4466 | { |
| 4467 | - $p_header['mtime'] = time(); |
|
| 4467 | + $p_header['mtime'] = time(); |
|
| 4468 | 4468 | } |
| 4469 | 4469 | |
| 4470 | 4470 | // ----- Set the stored filename |
@@ -4475,63 +4475,63 @@ discard block |
||
| 4475 | 4475 | |
| 4476 | 4476 | // ----- Look if it is a directory |
| 4477 | 4477 | if (substr($p_header['filename'], -1) == '/') { |
| 4478 | - //$p_header['external'] = 0x41FF0010; |
|
| 4479 | - $p_header['external'] = 0x00000010; |
|
| 4478 | + //$p_header['external'] = 0x41FF0010; |
|
| 4479 | + $p_header['external'] = 0x00000010; |
|
| 4480 | 4480 | } |
| 4481 | 4481 | |
| 4482 | 4482 | |
| 4483 | 4483 | // ----- Return |
| 4484 | 4484 | return $v_result; |
| 4485 | - } |
|
| 4486 | - // -------------------------------------------------------------------------------- |
|
| 4487 | - |
|
| 4488 | - // -------------------------------------------------------------------------------- |
|
| 4489 | - // Function : privCheckFileHeaders() |
|
| 4490 | - // Description : |
|
| 4491 | - // Parameters : |
|
| 4492 | - // Return Values : |
|
| 4493 | - // 1 on success, |
|
| 4494 | - // 0 on error; |
|
| 4495 | - // -------------------------------------------------------------------------------- |
|
| 4496 | - function privCheckFileHeaders(&$p_local_header, &$p_central_header) |
|
| 4497 | - { |
|
| 4485 | + } |
|
| 4486 | + // -------------------------------------------------------------------------------- |
|
| 4487 | + |
|
| 4488 | + // -------------------------------------------------------------------------------- |
|
| 4489 | + // Function : privCheckFileHeaders() |
|
| 4490 | + // Description : |
|
| 4491 | + // Parameters : |
|
| 4492 | + // Return Values : |
|
| 4493 | + // 1 on success, |
|
| 4494 | + // 0 on error; |
|
| 4495 | + // -------------------------------------------------------------------------------- |
|
| 4496 | + function privCheckFileHeaders(&$p_local_header, &$p_central_header) |
|
| 4497 | + { |
|
| 4498 | 4498 | $v_result=1; |
| 4499 | 4499 | |
| 4500 | - // ----- Check the static values |
|
| 4501 | - // TBC |
|
| 4502 | - if ($p_local_header['filename'] != $p_central_header['filename']) { |
|
| 4503 | - } |
|
| 4504 | - if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) { |
|
| 4505 | - } |
|
| 4506 | - if ($p_local_header['flag'] != $p_central_header['flag']) { |
|
| 4507 | - } |
|
| 4508 | - if ($p_local_header['compression'] != $p_central_header['compression']) { |
|
| 4509 | - } |
|
| 4510 | - if ($p_local_header['mtime'] != $p_central_header['mtime']) { |
|
| 4511 | - } |
|
| 4512 | - if ($p_local_header['filename_len'] != $p_central_header['filename_len']) { |
|
| 4513 | - } |
|
| 4500 | + // ----- Check the static values |
|
| 4501 | + // TBC |
|
| 4502 | + if ($p_local_header['filename'] != $p_central_header['filename']) { |
|
| 4503 | + } |
|
| 4504 | + if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) { |
|
| 4505 | + } |
|
| 4506 | + if ($p_local_header['flag'] != $p_central_header['flag']) { |
|
| 4507 | + } |
|
| 4508 | + if ($p_local_header['compression'] != $p_central_header['compression']) { |
|
| 4509 | + } |
|
| 4510 | + if ($p_local_header['mtime'] != $p_central_header['mtime']) { |
|
| 4511 | + } |
|
| 4512 | + if ($p_local_header['filename_len'] != $p_central_header['filename_len']) { |
|
| 4513 | + } |
|
| 4514 | 4514 | |
| 4515 | - // ----- Look for flag bit 3 |
|
| 4516 | - if (($p_local_header['flag'] & 8) == 8) { |
|
| 4517 | - $p_local_header['size'] = $p_central_header['size']; |
|
| 4518 | - $p_local_header['compressed_size'] = $p_central_header['compressed_size']; |
|
| 4519 | - $p_local_header['crc'] = $p_central_header['crc']; |
|
| 4520 | - } |
|
| 4515 | + // ----- Look for flag bit 3 |
|
| 4516 | + if (($p_local_header['flag'] & 8) == 8) { |
|
| 4517 | + $p_local_header['size'] = $p_central_header['size']; |
|
| 4518 | + $p_local_header['compressed_size'] = $p_central_header['compressed_size']; |
|
| 4519 | + $p_local_header['crc'] = $p_central_header['crc']; |
|
| 4520 | + } |
|
| 4521 | 4521 | |
| 4522 | 4522 | // ----- Return |
| 4523 | 4523 | return $v_result; |
| 4524 | - } |
|
| 4525 | - // -------------------------------------------------------------------------------- |
|
| 4526 | - |
|
| 4527 | - // -------------------------------------------------------------------------------- |
|
| 4528 | - // Function : privReadEndCentralDir() |
|
| 4529 | - // Description : |
|
| 4530 | - // Parameters : |
|
| 4531 | - // Return Values : |
|
| 4532 | - // -------------------------------------------------------------------------------- |
|
| 4533 | - function privReadEndCentralDir(&$p_central_dir) |
|
| 4534 | - { |
|
| 4524 | + } |
|
| 4525 | + // -------------------------------------------------------------------------------- |
|
| 4526 | + |
|
| 4527 | + // -------------------------------------------------------------------------------- |
|
| 4528 | + // Function : privReadEndCentralDir() |
|
| 4529 | + // Description : |
|
| 4530 | + // Parameters : |
|
| 4531 | + // Return Values : |
|
| 4532 | + // -------------------------------------------------------------------------------- |
|
| 4533 | + function privReadEndCentralDir(&$p_central_dir) |
|
| 4534 | + { |
|
| 4535 | 4535 | $v_result=1; |
| 4536 | 4536 | |
| 4537 | 4537 | // ----- Go to the end of the zip file |
@@ -4539,59 +4539,59 @@ discard block |
||
| 4539 | 4539 | @fseek($this->zip_fd, $v_size); |
| 4540 | 4540 | if (@ftell($this->zip_fd) != $v_size) |
| 4541 | 4541 | { |
| 4542 | - // ----- Error log |
|
| 4543 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\''); |
|
| 4542 | + // ----- Error log |
|
| 4543 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\''); |
|
| 4544 | 4544 | |
| 4545 | - // ----- Return |
|
| 4546 | - return PclZip::errorCode(); |
|
| 4545 | + // ----- Return |
|
| 4546 | + return PclZip::errorCode(); |
|
| 4547 | 4547 | } |
| 4548 | 4548 | |
| 4549 | 4549 | // ----- First try : look if this is an archive with no commentaries (most of the time) |
| 4550 | 4550 | // in this case the end of central dir is at 22 bytes of the file end |
| 4551 | 4551 | $v_found = 0; |
| 4552 | 4552 | if ($v_size > 26) { |
| 4553 | - @fseek($this->zip_fd, $v_size-22); |
|
| 4554 | - if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22)) |
|
| 4555 | - { |
|
| 4553 | + @fseek($this->zip_fd, $v_size-22); |
|
| 4554 | + if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22)) |
|
| 4555 | + { |
|
| 4556 | 4556 | // ----- Error log |
| 4557 | 4557 | PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); |
| 4558 | 4558 | |
| 4559 | 4559 | // ----- Return |
| 4560 | 4560 | return PclZip::errorCode(); |
| 4561 | - } |
|
| 4561 | + } |
|
| 4562 | 4562 | |
| 4563 | - // ----- Read for bytes |
|
| 4564 | - $v_binary_data = @fread($this->zip_fd, 4); |
|
| 4565 | - $v_data = @unpack('Vid', $v_binary_data); |
|
| 4563 | + // ----- Read for bytes |
|
| 4564 | + $v_binary_data = @fread($this->zip_fd, 4); |
|
| 4565 | + $v_data = @unpack('Vid', $v_binary_data); |
|
| 4566 | 4566 | |
| 4567 | - // ----- Check signature |
|
| 4568 | - if ($v_data['id'] == 0x06054b50) { |
|
| 4567 | + // ----- Check signature |
|
| 4568 | + if ($v_data['id'] == 0x06054b50) { |
|
| 4569 | 4569 | $v_found = 1; |
| 4570 | - } |
|
| 4570 | + } |
|
| 4571 | 4571 | |
| 4572 | - $v_pos = ftell($this->zip_fd); |
|
| 4572 | + $v_pos = ftell($this->zip_fd); |
|
| 4573 | 4573 | } |
| 4574 | 4574 | |
| 4575 | 4575 | // ----- Go back to the maximum possible size of the Central Dir End Record |
| 4576 | 4576 | if (!$v_found) { |
| 4577 | - $v_maximum_size = 65557; // 0xFFFF + 22; |
|
| 4578 | - if ($v_maximum_size > $v_size) |
|
| 4577 | + $v_maximum_size = 65557; // 0xFFFF + 22; |
|
| 4578 | + if ($v_maximum_size > $v_size) |
|
| 4579 | 4579 | $v_maximum_size = $v_size; |
| 4580 | - @fseek($this->zip_fd, $v_size-$v_maximum_size); |
|
| 4581 | - if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size)) |
|
| 4582 | - { |
|
| 4580 | + @fseek($this->zip_fd, $v_size-$v_maximum_size); |
|
| 4581 | + if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size)) |
|
| 4582 | + { |
|
| 4583 | 4583 | // ----- Error log |
| 4584 | 4584 | PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); |
| 4585 | 4585 | |
| 4586 | 4586 | // ----- Return |
| 4587 | 4587 | return PclZip::errorCode(); |
| 4588 | - } |
|
| 4588 | + } |
|
| 4589 | 4589 | |
| 4590 | - // ----- Read byte per byte in order to find the signature |
|
| 4591 | - $v_pos = ftell($this->zip_fd); |
|
| 4592 | - $v_bytes = 0x00000000; |
|
| 4593 | - while ($v_pos < $v_size) |
|
| 4594 | - { |
|
| 4590 | + // ----- Read byte per byte in order to find the signature |
|
| 4591 | + $v_pos = ftell($this->zip_fd); |
|
| 4592 | + $v_bytes = 0x00000000; |
|
| 4593 | + while ($v_pos < $v_size) |
|
| 4594 | + { |
|
| 4595 | 4595 | // ----- Read a byte |
| 4596 | 4596 | $v_byte = @fread($this->zip_fd, 1); |
| 4597 | 4597 | |
@@ -4604,23 +4604,23 @@ discard block |
||
| 4604 | 4604 | // ----- Compare the bytes |
| 4605 | 4605 | if ($v_bytes == 0x504b0506) |
| 4606 | 4606 | { |
| 4607 | - $v_pos++; |
|
| 4608 | - break; |
|
| 4607 | + $v_pos++; |
|
| 4608 | + break; |
|
| 4609 | 4609 | } |
| 4610 | 4610 | |
| 4611 | 4611 | $v_pos++; |
| 4612 | - } |
|
| 4612 | + } |
|
| 4613 | 4613 | |
| 4614 | - // ----- Look if not found end of central dir |
|
| 4615 | - if ($v_pos == $v_size) |
|
| 4616 | - { |
|
| 4614 | + // ----- Look if not found end of central dir |
|
| 4615 | + if ($v_pos == $v_size) |
|
| 4616 | + { |
|
| 4617 | 4617 | |
| 4618 | 4618 | // ----- Error log |
| 4619 | 4619 | PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature"); |
| 4620 | 4620 | |
| 4621 | 4621 | // ----- Return |
| 4622 | 4622 | return PclZip::errorCode(); |
| 4623 | - } |
|
| 4623 | + } |
|
| 4624 | 4624 | } |
| 4625 | 4625 | |
| 4626 | 4626 | // ----- Read the first 18 bytes of the header |
@@ -4630,11 +4630,11 @@ discard block |
||
| 4630 | 4630 | if (strlen($v_binary_data) != 18) |
| 4631 | 4631 | { |
| 4632 | 4632 | |
| 4633 | - // ----- Error log |
|
| 4634 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data)); |
|
| 4633 | + // ----- Error log |
|
| 4634 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data)); |
|
| 4635 | 4635 | |
| 4636 | - // ----- Return |
|
| 4637 | - return PclZip::errorCode(); |
|
| 4636 | + // ----- Return |
|
| 4637 | + return PclZip::errorCode(); |
|
| 4638 | 4638 | } |
| 4639 | 4639 | |
| 4640 | 4640 | // ----- Extract the values |
@@ -4643,27 +4643,27 @@ discard block |
||
| 4643 | 4643 | // ----- Check the global size |
| 4644 | 4644 | if (($v_pos + $v_data['comment_size'] + 18) != $v_size) { |
| 4645 | 4645 | |
| 4646 | - // ----- Removed in release 2.2 see readme file |
|
| 4647 | - // The check of the file size is a little too strict. |
|
| 4648 | - // Some bugs where found when a zip is encrypted/decrypted with 'crypt'. |
|
| 4649 | - // While decrypted, zip has training 0 bytes |
|
| 4650 | - if (0) { |
|
| 4651 | - // ----- Error log |
|
| 4652 | - PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, |
|
| 4653 | - 'The central dir is not at the end of the archive.' |
|
| 4654 | - .' Some trailing bytes exists after the archive.'); |
|
| 4646 | + // ----- Removed in release 2.2 see readme file |
|
| 4647 | + // The check of the file size is a little too strict. |
|
| 4648 | + // Some bugs where found when a zip is encrypted/decrypted with 'crypt'. |
|
| 4649 | + // While decrypted, zip has training 0 bytes |
|
| 4650 | + if (0) { |
|
| 4651 | + // ----- Error log |
|
| 4652 | + PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, |
|
| 4653 | + 'The central dir is not at the end of the archive.' |
|
| 4654 | + .' Some trailing bytes exists after the archive.'); |
|
| 4655 | 4655 | |
| 4656 | - // ----- Return |
|
| 4657 | - return PclZip::errorCode(); |
|
| 4658 | - } |
|
| 4656 | + // ----- Return |
|
| 4657 | + return PclZip::errorCode(); |
|
| 4658 | + } |
|
| 4659 | 4659 | } |
| 4660 | 4660 | |
| 4661 | 4661 | // ----- Get comment |
| 4662 | 4662 | if ($v_data['comment_size'] != 0) { |
| 4663 | - $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']); |
|
| 4663 | + $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']); |
|
| 4664 | 4664 | } |
| 4665 | 4665 | else |
| 4666 | - $p_central_dir['comment'] = ''; |
|
| 4666 | + $p_central_dir['comment'] = ''; |
|
| 4667 | 4667 | |
| 4668 | 4668 | $p_central_dir['entries'] = $v_data['entries']; |
| 4669 | 4669 | $p_central_dir['disk_entries'] = $v_data['disk_entries']; |
@@ -4678,33 +4678,33 @@ discard block |
||
| 4678 | 4678 | |
| 4679 | 4679 | // ----- Return |
| 4680 | 4680 | return $v_result; |
| 4681 | - } |
|
| 4682 | - // -------------------------------------------------------------------------------- |
|
| 4683 | - |
|
| 4684 | - // -------------------------------------------------------------------------------- |
|
| 4685 | - // Function : privDeleteByRule() |
|
| 4686 | - // Description : |
|
| 4687 | - // Parameters : |
|
| 4688 | - // Return Values : |
|
| 4689 | - // -------------------------------------------------------------------------------- |
|
| 4690 | - function privDeleteByRule(&$p_result_list, &$p_options) |
|
| 4691 | - { |
|
| 4681 | + } |
|
| 4682 | + // -------------------------------------------------------------------------------- |
|
| 4683 | + |
|
| 4684 | + // -------------------------------------------------------------------------------- |
|
| 4685 | + // Function : privDeleteByRule() |
|
| 4686 | + // Description : |
|
| 4687 | + // Parameters : |
|
| 4688 | + // Return Values : |
|
| 4689 | + // -------------------------------------------------------------------------------- |
|
| 4690 | + function privDeleteByRule(&$p_result_list, &$p_options) |
|
| 4691 | + { |
|
| 4692 | 4692 | $v_result=1; |
| 4693 | 4693 | $v_list_detail = array(); |
| 4694 | 4694 | |
| 4695 | 4695 | // ----- Open the zip file |
| 4696 | 4696 | if (($v_result=$this->privOpenFd('rb')) != 1) |
| 4697 | 4697 | { |
| 4698 | - // ----- Return |
|
| 4699 | - return $v_result; |
|
| 4698 | + // ----- Return |
|
| 4699 | + return $v_result; |
|
| 4700 | 4700 | } |
| 4701 | 4701 | |
| 4702 | 4702 | // ----- Read the central directory informations |
| 4703 | 4703 | $v_central_dir = array(); |
| 4704 | 4704 | if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
| 4705 | 4705 | { |
| 4706 | - $this->privCloseFd(); |
|
| 4707 | - return $v_result; |
|
| 4706 | + $this->privCloseFd(); |
|
| 4707 | + return $v_result; |
|
| 4708 | 4708 | } |
| 4709 | 4709 | |
| 4710 | 4710 | // ----- Go to beginning of File |
@@ -4716,14 +4716,14 @@ discard block |
||
| 4716 | 4716 | @rewind($this->zip_fd); |
| 4717 | 4717 | if (@fseek($this->zip_fd, $v_pos_entry)) |
| 4718 | 4718 | { |
| 4719 | - // ----- Close the zip file |
|
| 4720 | - $this->privCloseFd(); |
|
| 4719 | + // ----- Close the zip file |
|
| 4720 | + $this->privCloseFd(); |
|
| 4721 | 4721 | |
| 4722 | - // ----- Error log |
|
| 4723 | - PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
|
| 4722 | + // ----- Error log |
|
| 4723 | + PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size'); |
|
| 4724 | 4724 | |
| 4725 | - // ----- Return |
|
| 4726 | - return PclZip::errorCode(); |
|
| 4725 | + // ----- Return |
|
| 4726 | + return PclZip::errorCode(); |
|
| 4727 | 4727 | } |
| 4728 | 4728 | |
| 4729 | 4729 | // ----- Read each entry |
@@ -4732,53 +4732,53 @@ discard block |
||
| 4732 | 4732 | for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) |
| 4733 | 4733 | { |
| 4734 | 4734 | |
| 4735 | - // ----- Read the file header |
|
| 4736 | - $v_header_list[$v_nb_extracted] = array(); |
|
| 4737 | - if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1) |
|
| 4738 | - { |
|
| 4735 | + // ----- Read the file header |
|
| 4736 | + $v_header_list[$v_nb_extracted] = array(); |
|
| 4737 | + if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1) |
|
| 4738 | + { |
|
| 4739 | 4739 | // ----- Close the zip file |
| 4740 | 4740 | $this->privCloseFd(); |
| 4741 | 4741 | |
| 4742 | 4742 | return $v_result; |
| 4743 | - } |
|
| 4743 | + } |
|
| 4744 | 4744 | |
| 4745 | 4745 | |
| 4746 | - // ----- Store the index |
|
| 4747 | - $v_header_list[$v_nb_extracted]['index'] = $i; |
|
| 4746 | + // ----- Store the index |
|
| 4747 | + $v_header_list[$v_nb_extracted]['index'] = $i; |
|
| 4748 | 4748 | |
| 4749 | - // ----- Look for the specific extract rules |
|
| 4750 | - $v_found = false; |
|
| 4749 | + // ----- Look for the specific extract rules |
|
| 4750 | + $v_found = false; |
|
| 4751 | 4751 | |
| 4752 | - // ----- Look for extract by name rule |
|
| 4753 | - if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) |
|
| 4752 | + // ----- Look for extract by name rule |
|
| 4753 | + if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) |
|
| 4754 | 4754 | && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { |
| 4755 | 4755 | |
| 4756 | - // ----- Look if the filename is in the list |
|
| 4757 | - for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) { |
|
| 4756 | + // ----- Look if the filename is in the list |
|
| 4757 | + for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) { |
|
| 4758 | 4758 | |
| 4759 | - // ----- Look for a directory |
|
| 4760 | - if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { |
|
| 4759 | + // ----- Look for a directory |
|
| 4760 | + if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { |
|
| 4761 | 4761 | |
| 4762 | - // ----- Look if the directory is in the filename path |
|
| 4763 | - if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) |
|
| 4762 | + // ----- Look if the directory is in the filename path |
|
| 4763 | + if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) |
|
| 4764 | 4764 | && (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])) { |
| 4765 | - $v_found = true; |
|
| 4766 | - } |
|
| 4767 | - elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */ |
|
| 4765 | + $v_found = true; |
|
| 4766 | + } |
|
| 4767 | + elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */ |
|
| 4768 | 4768 | && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
| 4769 | - $v_found = true; |
|
| 4770 | - } |
|
| 4771 | - } |
|
| 4772 | - // ----- Look for a filename |
|
| 4773 | - elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { |
|
| 4774 | - $v_found = true; |
|
| 4775 | - } |
|
| 4776 | - } |
|
| 4777 | - } |
|
| 4769 | + $v_found = true; |
|
| 4770 | + } |
|
| 4771 | + } |
|
| 4772 | + // ----- Look for a filename |
|
| 4773 | + elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) { |
|
| 4774 | + $v_found = true; |
|
| 4775 | + } |
|
| 4776 | + } |
|
| 4777 | + } |
|
| 4778 | 4778 | |
| 4779 | - // ----- Look for extract by ereg rule |
|
| 4780 | - // ereg() is deprecated with PHP 5.3 |
|
| 4781 | - /* |
|
| 4779 | + // ----- Look for extract by ereg rule |
|
| 4780 | + // ereg() is deprecated with PHP 5.3 |
|
| 4781 | + /* |
|
| 4782 | 4782 | else if ( (isset($p_options[PCLZIP_OPT_BY_EREG])) |
| 4783 | 4783 | && ($p_options[PCLZIP_OPT_BY_EREG] != "")) { |
| 4784 | 4784 | |
@@ -4788,47 +4788,47 @@ discard block |
||
| 4788 | 4788 | } |
| 4789 | 4789 | */ |
| 4790 | 4790 | |
| 4791 | - // ----- Look for extract by preg rule |
|
| 4792 | - else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) |
|
| 4791 | + // ----- Look for extract by preg rule |
|
| 4792 | + else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) |
|
| 4793 | 4793 | && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { |
| 4794 | 4794 | |
| 4795 | - if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { |
|
| 4796 | - $v_found = true; |
|
| 4797 | - } |
|
| 4798 | - } |
|
| 4795 | + if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { |
|
| 4796 | + $v_found = true; |
|
| 4797 | + } |
|
| 4798 | + } |
|
| 4799 | 4799 | |
| 4800 | - // ----- Look for extract by index rule |
|
| 4801 | - else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) |
|
| 4800 | + // ----- Look for extract by index rule |
|
| 4801 | + else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) |
|
| 4802 | 4802 | && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { |
| 4803 | 4803 | |
| 4804 | - // ----- Look if the index is in the list |
|
| 4805 | - for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) { |
|
| 4804 | + // ----- Look if the index is in the list |
|
| 4805 | + for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) { |
|
| 4806 | 4806 | |
| 4807 | - if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { |
|
| 4808 | - $v_found = true; |
|
| 4809 | - } |
|
| 4810 | - if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { |
|
| 4811 | - $j_start = $j+1; |
|
| 4812 | - } |
|
| 4807 | + if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { |
|
| 4808 | + $v_found = true; |
|
| 4809 | + } |
|
| 4810 | + if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { |
|
| 4811 | + $j_start = $j+1; |
|
| 4812 | + } |
|
| 4813 | 4813 | |
| 4814 | - if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { |
|
| 4815 | - break; |
|
| 4816 | - } |
|
| 4817 | - } |
|
| 4818 | - } |
|
| 4819 | - else { |
|
| 4820 | - $v_found = true; |
|
| 4821 | - } |
|
| 4814 | + if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { |
|
| 4815 | + break; |
|
| 4816 | + } |
|
| 4817 | + } |
|
| 4818 | + } |
|
| 4819 | + else { |
|
| 4820 | + $v_found = true; |
|
| 4821 | + } |
|
| 4822 | 4822 | |
| 4823 | - // ----- Look for deletion |
|
| 4824 | - if ($v_found) |
|
| 4825 | - { |
|
| 4823 | + // ----- Look for deletion |
|
| 4824 | + if ($v_found) |
|
| 4825 | + { |
|
| 4826 | 4826 | unset($v_header_list[$v_nb_extracted]); |
| 4827 | - } |
|
| 4828 | - else |
|
| 4829 | - { |
|
| 4827 | + } |
|
| 4828 | + else |
|
| 4829 | + { |
|
| 4830 | 4830 | $v_nb_extracted++; |
| 4831 | - } |
|
| 4831 | + } |
|
| 4832 | 4832 | } |
| 4833 | 4833 | |
| 4834 | 4834 | // ----- Look if something need to be deleted |
@@ -4880,7 +4880,7 @@ discard block |
||
| 4880 | 4880 | |
| 4881 | 4881 | // ----- Check that local file header is same as central file header |
| 4882 | 4882 | if ($this->privCheckFileHeaders($v_local_header, |
| 4883 | - $v_header_list[$i]) != 1) { |
|
| 4883 | + $v_header_list[$i]) != 1) { |
|
| 4884 | 4884 | // TBC |
| 4885 | 4885 | } |
| 4886 | 4886 | unset($v_local_header); |
@@ -4931,7 +4931,7 @@ discard block |
||
| 4931 | 4931 | // ----- Zip file comment |
| 4932 | 4932 | $v_comment = ''; |
| 4933 | 4933 | if (isset($p_options[PCLZIP_OPT_COMMENT])) { |
| 4934 | - $v_comment = $p_options[PCLZIP_OPT_COMMENT]; |
|
| 4934 | + $v_comment = $p_options[PCLZIP_OPT_COMMENT]; |
|
| 4935 | 4935 | } |
| 4936 | 4936 | |
| 4937 | 4937 | // ----- Calculate the size of the central header |
@@ -4971,11 +4971,11 @@ discard block |
||
| 4971 | 4971 | $this->privCloseFd(); |
| 4972 | 4972 | |
| 4973 | 4973 | if (($v_result = $this->privOpenFd('wb')) != 1) { |
| 4974 | - return $v_result; |
|
| 4974 | + return $v_result; |
|
| 4975 | 4975 | } |
| 4976 | 4976 | |
| 4977 | 4977 | if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) { |
| 4978 | - return $v_result; |
|
| 4978 | + return $v_result; |
|
| 4979 | 4979 | } |
| 4980 | 4980 | |
| 4981 | 4981 | $this->privCloseFd(); |
@@ -4983,35 +4983,35 @@ discard block |
||
| 4983 | 4983 | |
| 4984 | 4984 | // ----- Return |
| 4985 | 4985 | return $v_result; |
| 4986 | - } |
|
| 4987 | - // -------------------------------------------------------------------------------- |
|
| 4988 | - |
|
| 4989 | - // -------------------------------------------------------------------------------- |
|
| 4990 | - // Function : privDirCheck() |
|
| 4991 | - // Description : |
|
| 4992 | - // Check if a directory exists, if not it creates it and all the parents directory |
|
| 4993 | - // which may be useful. |
|
| 4994 | - // Parameters : |
|
| 4995 | - // $p_dir : Directory path to check. |
|
| 4996 | - // Return Values : |
|
| 4997 | - // 1 : OK |
|
| 4998 | - // -1 : Unable to create directory |
|
| 4999 | - // -------------------------------------------------------------------------------- |
|
| 5000 | - function privDirCheck($p_dir, $p_is_dir=false) |
|
| 5001 | - { |
|
| 4986 | + } |
|
| 4987 | + // -------------------------------------------------------------------------------- |
|
| 4988 | + |
|
| 4989 | + // -------------------------------------------------------------------------------- |
|
| 4990 | + // Function : privDirCheck() |
|
| 4991 | + // Description : |
|
| 4992 | + // Check if a directory exists, if not it creates it and all the parents directory |
|
| 4993 | + // which may be useful. |
|
| 4994 | + // Parameters : |
|
| 4995 | + // $p_dir : Directory path to check. |
|
| 4996 | + // Return Values : |
|
| 4997 | + // 1 : OK |
|
| 4998 | + // -1 : Unable to create directory |
|
| 4999 | + // -------------------------------------------------------------------------------- |
|
| 5000 | + function privDirCheck($p_dir, $p_is_dir=false) |
|
| 5001 | + { |
|
| 5002 | 5002 | $v_result = 1; |
| 5003 | 5003 | |
| 5004 | 5004 | |
| 5005 | 5005 | // ----- Remove the final '/' |
| 5006 | 5006 | if (($p_is_dir) && (substr($p_dir, -1)=='/')) |
| 5007 | 5007 | { |
| 5008 | - $p_dir = substr($p_dir, 0, strlen($p_dir)-1); |
|
| 5008 | + $p_dir = substr($p_dir, 0, strlen($p_dir)-1); |
|
| 5009 | 5009 | } |
| 5010 | 5010 | |
| 5011 | 5011 | // ----- Check the directory availability |
| 5012 | 5012 | if ((is_dir($p_dir)) || ($p_dir == "")) |
| 5013 | 5013 | { |
| 5014 | - return 1; |
|
| 5014 | + return 1; |
|
| 5015 | 5015 | } |
| 5016 | 5016 | |
| 5017 | 5017 | // ----- Extract parent directory |
@@ -5020,77 +5020,77 @@ discard block |
||
| 5020 | 5020 | // ----- Just a check |
| 5021 | 5021 | if ($p_parent_dir != $p_dir) |
| 5022 | 5022 | { |
| 5023 | - // ----- Look for parent directory |
|
| 5024 | - if ($p_parent_dir != "") |
|
| 5025 | - { |
|
| 5023 | + // ----- Look for parent directory |
|
| 5024 | + if ($p_parent_dir != "") |
|
| 5025 | + { |
|
| 5026 | 5026 | if (($v_result = $this->privDirCheck($p_parent_dir)) != 1) |
| 5027 | 5027 | { |
| 5028 | - return $v_result; |
|
| 5028 | + return $v_result; |
|
| 5029 | + } |
|
| 5029 | 5030 | } |
| 5030 | - } |
|
| 5031 | 5031 | } |
| 5032 | 5032 | |
| 5033 | 5033 | // ----- Create the directory |
| 5034 | 5034 | if (!@mkdir($p_dir, 0777)) |
| 5035 | 5035 | { |
| 5036 | - // ----- Error log |
|
| 5037 | - PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'"); |
|
| 5036 | + // ----- Error log |
|
| 5037 | + PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'"); |
|
| 5038 | 5038 | |
| 5039 | - // ----- Return |
|
| 5040 | - return PclZip::errorCode(); |
|
| 5039 | + // ----- Return |
|
| 5040 | + return PclZip::errorCode(); |
|
| 5041 | 5041 | } |
| 5042 | 5042 | |
| 5043 | 5043 | // ----- Return |
| 5044 | 5044 | return $v_result; |
| 5045 | - } |
|
| 5046 | - // -------------------------------------------------------------------------------- |
|
| 5047 | - |
|
| 5048 | - // -------------------------------------------------------------------------------- |
|
| 5049 | - // Function : privMerge() |
|
| 5050 | - // Description : |
|
| 5051 | - // If $p_archive_to_add does not exist, the function exit with a success result. |
|
| 5052 | - // Parameters : |
|
| 5053 | - // Return Values : |
|
| 5054 | - // -------------------------------------------------------------------------------- |
|
| 5055 | - function privMerge(&$p_archive_to_add) |
|
| 5056 | - { |
|
| 5045 | + } |
|
| 5046 | + // -------------------------------------------------------------------------------- |
|
| 5047 | + |
|
| 5048 | + // -------------------------------------------------------------------------------- |
|
| 5049 | + // Function : privMerge() |
|
| 5050 | + // Description : |
|
| 5051 | + // If $p_archive_to_add does not exist, the function exit with a success result. |
|
| 5052 | + // Parameters : |
|
| 5053 | + // Return Values : |
|
| 5054 | + // -------------------------------------------------------------------------------- |
|
| 5055 | + function privMerge(&$p_archive_to_add) |
|
| 5056 | + { |
|
| 5057 | 5057 | $v_result=1; |
| 5058 | 5058 | |
| 5059 | 5059 | // ----- Look if the archive_to_add exists |
| 5060 | 5060 | if (!is_file($p_archive_to_add->zipname)) |
| 5061 | 5061 | { |
| 5062 | 5062 | |
| 5063 | - // ----- Nothing to merge, so merge is a success |
|
| 5064 | - $v_result = 1; |
|
| 5063 | + // ----- Nothing to merge, so merge is a success |
|
| 5064 | + $v_result = 1; |
|
| 5065 | 5065 | |
| 5066 | - // ----- Return |
|
| 5067 | - return $v_result; |
|
| 5066 | + // ----- Return |
|
| 5067 | + return $v_result; |
|
| 5068 | 5068 | } |
| 5069 | 5069 | |
| 5070 | 5070 | // ----- Look if the archive exists |
| 5071 | 5071 | if (!is_file($this->zipname)) |
| 5072 | 5072 | { |
| 5073 | 5073 | |
| 5074 | - // ----- Do a duplicate |
|
| 5075 | - $v_result = $this->privDuplicate($p_archive_to_add->zipname); |
|
| 5074 | + // ----- Do a duplicate |
|
| 5075 | + $v_result = $this->privDuplicate($p_archive_to_add->zipname); |
|
| 5076 | 5076 | |
| 5077 | - // ----- Return |
|
| 5078 | - return $v_result; |
|
| 5077 | + // ----- Return |
|
| 5078 | + return $v_result; |
|
| 5079 | 5079 | } |
| 5080 | 5080 | |
| 5081 | 5081 | // ----- Open the zip file |
| 5082 | 5082 | if (($v_result=$this->privOpenFd('rb')) != 1) |
| 5083 | 5083 | { |
| 5084 | - // ----- Return |
|
| 5085 | - return $v_result; |
|
| 5084 | + // ----- Return |
|
| 5085 | + return $v_result; |
|
| 5086 | 5086 | } |
| 5087 | 5087 | |
| 5088 | 5088 | // ----- Read the central directory informations |
| 5089 | 5089 | $v_central_dir = array(); |
| 5090 | 5090 | if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1) |
| 5091 | 5091 | { |
| 5092 | - $this->privCloseFd(); |
|
| 5093 | - return $v_result; |
|
| 5092 | + $this->privCloseFd(); |
|
| 5093 | + return $v_result; |
|
| 5094 | 5094 | } |
| 5095 | 5095 | |
| 5096 | 5096 | // ----- Go to beginning of File |
@@ -5099,20 +5099,20 @@ discard block |
||
| 5099 | 5099 | // ----- Open the archive_to_add file |
| 5100 | 5100 | if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1) |
| 5101 | 5101 | { |
| 5102 | - $this->privCloseFd(); |
|
| 5102 | + $this->privCloseFd(); |
|
| 5103 | 5103 | |
| 5104 | - // ----- Return |
|
| 5105 | - return $v_result; |
|
| 5104 | + // ----- Return |
|
| 5105 | + return $v_result; |
|
| 5106 | 5106 | } |
| 5107 | 5107 | |
| 5108 | 5108 | // ----- Read the central directory informations |
| 5109 | 5109 | $v_central_dir_to_add = array(); |
| 5110 | 5110 | if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1) |
| 5111 | 5111 | { |
| 5112 | - $this->privCloseFd(); |
|
| 5113 | - $p_archive_to_add->privCloseFd(); |
|
| 5112 | + $this->privCloseFd(); |
|
| 5113 | + $p_archive_to_add->privCloseFd(); |
|
| 5114 | 5114 | |
| 5115 | - return $v_result; |
|
| 5115 | + return $v_result; |
|
| 5116 | 5116 | } |
| 5117 | 5117 | |
| 5118 | 5118 | // ----- Go to beginning of File |
@@ -5124,13 +5124,13 @@ discard block |
||
| 5124 | 5124 | // ----- Open the temporary file in write mode |
| 5125 | 5125 | if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0) |
| 5126 | 5126 | { |
| 5127 | - $this->privCloseFd(); |
|
| 5128 | - $p_archive_to_add->privCloseFd(); |
|
| 5127 | + $this->privCloseFd(); |
|
| 5128 | + $p_archive_to_add->privCloseFd(); |
|
| 5129 | 5129 | |
| 5130 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); |
|
| 5130 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode'); |
|
| 5131 | 5131 | |
| 5132 | - // ----- Return |
|
| 5133 | - return PclZip::errorCode(); |
|
| 5132 | + // ----- Return |
|
| 5133 | + return PclZip::errorCode(); |
|
| 5134 | 5134 | } |
| 5135 | 5135 | |
| 5136 | 5136 | // ----- Copy the files from the archive to the temporary file |
@@ -5138,20 +5138,20 @@ discard block |
||
| 5138 | 5138 | $v_size = $v_central_dir['offset']; |
| 5139 | 5139 | while ($v_size != 0) |
| 5140 | 5140 | { |
| 5141 | - $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5142 | - $v_buffer = fread($this->zip_fd, $v_read_size); |
|
| 5143 | - @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
|
| 5144 | - $v_size -= $v_read_size; |
|
| 5141 | + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5142 | + $v_buffer = fread($this->zip_fd, $v_read_size); |
|
| 5143 | + @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
|
| 5144 | + $v_size -= $v_read_size; |
|
| 5145 | 5145 | } |
| 5146 | 5146 | |
| 5147 | 5147 | // ----- Copy the files from the archive_to_add into the temporary file |
| 5148 | 5148 | $v_size = $v_central_dir_to_add['offset']; |
| 5149 | 5149 | while ($v_size != 0) |
| 5150 | 5150 | { |
| 5151 | - $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5152 | - $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size); |
|
| 5153 | - @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
|
| 5154 | - $v_size -= $v_read_size; |
|
| 5151 | + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5152 | + $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size); |
|
| 5153 | + @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
|
| 5154 | + $v_size -= $v_read_size; |
|
| 5155 | 5155 | } |
| 5156 | 5156 | |
| 5157 | 5157 | // ----- Store the offset of the central dir |
@@ -5161,20 +5161,20 @@ discard block |
||
| 5161 | 5161 | $v_size = $v_central_dir['size']; |
| 5162 | 5162 | while ($v_size != 0) |
| 5163 | 5163 | { |
| 5164 | - $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5165 | - $v_buffer = @fread($this->zip_fd, $v_read_size); |
|
| 5166 | - @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
|
| 5167 | - $v_size -= $v_read_size; |
|
| 5164 | + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5165 | + $v_buffer = @fread($this->zip_fd, $v_read_size); |
|
| 5166 | + @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
|
| 5167 | + $v_size -= $v_read_size; |
|
| 5168 | 5168 | } |
| 5169 | 5169 | |
| 5170 | 5170 | // ----- Copy the block of file headers from the archive_to_add |
| 5171 | 5171 | $v_size = $v_central_dir_to_add['size']; |
| 5172 | 5172 | while ($v_size != 0) |
| 5173 | 5173 | { |
| 5174 | - $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5175 | - $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size); |
|
| 5176 | - @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
|
| 5177 | - $v_size -= $v_read_size; |
|
| 5174 | + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5175 | + $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size); |
|
| 5176 | + @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size); |
|
| 5177 | + $v_size -= $v_read_size; |
|
| 5178 | 5178 | } |
| 5179 | 5179 | |
| 5180 | 5180 | // ----- Merge the file comments |
@@ -5193,16 +5193,16 @@ discard block |
||
| 5193 | 5193 | // ----- Create the central dir footer |
| 5194 | 5194 | if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1) |
| 5195 | 5195 | { |
| 5196 | - $this->privCloseFd(); |
|
| 5197 | - $p_archive_to_add->privCloseFd(); |
|
| 5198 | - @fclose($v_zip_temp_fd); |
|
| 5199 | - $this->zip_fd = null; |
|
| 5196 | + $this->privCloseFd(); |
|
| 5197 | + $p_archive_to_add->privCloseFd(); |
|
| 5198 | + @fclose($v_zip_temp_fd); |
|
| 5199 | + $this->zip_fd = null; |
|
| 5200 | 5200 | |
| 5201 | - // ----- Reset the file list |
|
| 5202 | - unset($v_header_list); |
|
| 5201 | + // ----- Reset the file list |
|
| 5202 | + unset($v_header_list); |
|
| 5203 | 5203 | |
| 5204 | - // ----- Return |
|
| 5205 | - return $v_result; |
|
| 5204 | + // ----- Return |
|
| 5205 | + return $v_result; |
|
| 5206 | 5206 | } |
| 5207 | 5207 | |
| 5208 | 5208 | // ----- Swap back the file descriptor |
@@ -5228,46 +5228,46 @@ discard block |
||
| 5228 | 5228 | |
| 5229 | 5229 | // ----- Return |
| 5230 | 5230 | return $v_result; |
| 5231 | - } |
|
| 5232 | - // -------------------------------------------------------------------------------- |
|
| 5233 | - |
|
| 5234 | - // -------------------------------------------------------------------------------- |
|
| 5235 | - // Function : privDuplicate() |
|
| 5236 | - // Description : |
|
| 5237 | - // Parameters : |
|
| 5238 | - // Return Values : |
|
| 5239 | - // -------------------------------------------------------------------------------- |
|
| 5240 | - function privDuplicate($p_archive_filename) |
|
| 5241 | - { |
|
| 5231 | + } |
|
| 5232 | + // -------------------------------------------------------------------------------- |
|
| 5233 | + |
|
| 5234 | + // -------------------------------------------------------------------------------- |
|
| 5235 | + // Function : privDuplicate() |
|
| 5236 | + // Description : |
|
| 5237 | + // Parameters : |
|
| 5238 | + // Return Values : |
|
| 5239 | + // -------------------------------------------------------------------------------- |
|
| 5240 | + function privDuplicate($p_archive_filename) |
|
| 5241 | + { |
|
| 5242 | 5242 | $v_result=1; |
| 5243 | 5243 | |
| 5244 | 5244 | // ----- Look if the $p_archive_filename exists |
| 5245 | 5245 | if (!is_file($p_archive_filename)) |
| 5246 | 5246 | { |
| 5247 | 5247 | |
| 5248 | - // ----- Nothing to duplicate, so duplicate is a success. |
|
| 5249 | - $v_result = 1; |
|
| 5248 | + // ----- Nothing to duplicate, so duplicate is a success. |
|
| 5249 | + $v_result = 1; |
|
| 5250 | 5250 | |
| 5251 | - // ----- Return |
|
| 5252 | - return $v_result; |
|
| 5251 | + // ----- Return |
|
| 5252 | + return $v_result; |
|
| 5253 | 5253 | } |
| 5254 | 5254 | |
| 5255 | 5255 | // ----- Open the zip file |
| 5256 | 5256 | if (($v_result=$this->privOpenFd('wb')) != 1) |
| 5257 | 5257 | { |
| 5258 | - // ----- Return |
|
| 5259 | - return $v_result; |
|
| 5258 | + // ----- Return |
|
| 5259 | + return $v_result; |
|
| 5260 | 5260 | } |
| 5261 | 5261 | |
| 5262 | 5262 | // ----- Open the temporary file in write mode |
| 5263 | 5263 | if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0) |
| 5264 | 5264 | { |
| 5265 | - $this->privCloseFd(); |
|
| 5265 | + $this->privCloseFd(); |
|
| 5266 | 5266 | |
| 5267 | - PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode'); |
|
| 5267 | + PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode'); |
|
| 5268 | 5268 | |
| 5269 | - // ----- Return |
|
| 5270 | - return PclZip::errorCode(); |
|
| 5269 | + // ----- Return |
|
| 5270 | + return PclZip::errorCode(); |
|
| 5271 | 5271 | } |
| 5272 | 5272 | |
| 5273 | 5273 | // ----- Copy the files from the archive to the temporary file |
@@ -5275,10 +5275,10 @@ discard block |
||
| 5275 | 5275 | $v_size = filesize($p_archive_filename); |
| 5276 | 5276 | while ($v_size != 0) |
| 5277 | 5277 | { |
| 5278 | - $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5279 | - $v_buffer = fread($v_zip_temp_fd, $v_read_size); |
|
| 5280 | - @fwrite($this->zip_fd, $v_buffer, $v_read_size); |
|
| 5281 | - $v_size -= $v_read_size; |
|
| 5278 | + $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE); |
|
| 5279 | + $v_buffer = fread($v_zip_temp_fd, $v_read_size); |
|
| 5280 | + @fwrite($this->zip_fd, $v_buffer, $v_read_size); |
|
| 5281 | + $v_size -= $v_read_size; |
|
| 5282 | 5282 | } |
| 5283 | 5283 | |
| 5284 | 5284 | // ----- Close |
@@ -5289,211 +5289,211 @@ discard block |
||
| 5289 | 5289 | |
| 5290 | 5290 | // ----- Return |
| 5291 | 5291 | return $v_result; |
| 5292 | - } |
|
| 5293 | - // -------------------------------------------------------------------------------- |
|
| 5294 | - |
|
| 5295 | - // -------------------------------------------------------------------------------- |
|
| 5296 | - // Function : privErrorLog() |
|
| 5297 | - // Description : |
|
| 5298 | - // Parameters : |
|
| 5299 | - // -------------------------------------------------------------------------------- |
|
| 5300 | - function privErrorLog($p_error_code=0, $p_error_string='') |
|
| 5301 | - { |
|
| 5292 | + } |
|
| 5293 | + // -------------------------------------------------------------------------------- |
|
| 5294 | + |
|
| 5295 | + // -------------------------------------------------------------------------------- |
|
| 5296 | + // Function : privErrorLog() |
|
| 5297 | + // Description : |
|
| 5298 | + // Parameters : |
|
| 5299 | + // -------------------------------------------------------------------------------- |
|
| 5300 | + function privErrorLog($p_error_code=0, $p_error_string='') |
|
| 5301 | + { |
|
| 5302 | 5302 | if (PCLZIP_ERROR_EXTERNAL == 1) { |
| 5303 | - PclError($p_error_code, $p_error_string); |
|
| 5303 | + PclError($p_error_code, $p_error_string); |
|
| 5304 | 5304 | } |
| 5305 | 5305 | else { |
| 5306 | - $this->error_code = $p_error_code; |
|
| 5307 | - $this->error_string = $p_error_string; |
|
| 5308 | - } |
|
| 5309 | - } |
|
| 5310 | - // -------------------------------------------------------------------------------- |
|
| 5311 | - |
|
| 5312 | - // -------------------------------------------------------------------------------- |
|
| 5313 | - // Function : privErrorReset() |
|
| 5314 | - // Description : |
|
| 5315 | - // Parameters : |
|
| 5316 | - // -------------------------------------------------------------------------------- |
|
| 5317 | - function privErrorReset() |
|
| 5318 | - { |
|
| 5306 | + $this->error_code = $p_error_code; |
|
| 5307 | + $this->error_string = $p_error_string; |
|
| 5308 | + } |
|
| 5309 | + } |
|
| 5310 | + // -------------------------------------------------------------------------------- |
|
| 5311 | + |
|
| 5312 | + // -------------------------------------------------------------------------------- |
|
| 5313 | + // Function : privErrorReset() |
|
| 5314 | + // Description : |
|
| 5315 | + // Parameters : |
|
| 5316 | + // -------------------------------------------------------------------------------- |
|
| 5317 | + function privErrorReset() |
|
| 5318 | + { |
|
| 5319 | 5319 | if (PCLZIP_ERROR_EXTERNAL == 1) { |
| 5320 | - PclErrorReset(); |
|
| 5320 | + PclErrorReset(); |
|
| 5321 | 5321 | } |
| 5322 | 5322 | else { |
| 5323 | - $this->error_code = 0; |
|
| 5324 | - $this->error_string = ''; |
|
| 5325 | - } |
|
| 5326 | - } |
|
| 5327 | - // -------------------------------------------------------------------------------- |
|
| 5328 | - |
|
| 5329 | - // -------------------------------------------------------------------------------- |
|
| 5330 | - // Function : privDisableMagicQuotes() |
|
| 5331 | - // Description : |
|
| 5332 | - // Parameters : |
|
| 5333 | - // Return Values : |
|
| 5334 | - // -------------------------------------------------------------------------------- |
|
| 5335 | - function privDisableMagicQuotes() |
|
| 5336 | - { |
|
| 5323 | + $this->error_code = 0; |
|
| 5324 | + $this->error_string = ''; |
|
| 5325 | + } |
|
| 5326 | + } |
|
| 5327 | + // -------------------------------------------------------------------------------- |
|
| 5328 | + |
|
| 5329 | + // -------------------------------------------------------------------------------- |
|
| 5330 | + // Function : privDisableMagicQuotes() |
|
| 5331 | + // Description : |
|
| 5332 | + // Parameters : |
|
| 5333 | + // Return Values : |
|
| 5334 | + // -------------------------------------------------------------------------------- |
|
| 5335 | + function privDisableMagicQuotes() |
|
| 5336 | + { |
|
| 5337 | 5337 | $v_result=1; |
| 5338 | 5338 | |
| 5339 | 5339 | // ----- Look if function exists |
| 5340 | 5340 | if ( (!function_exists("get_magic_quotes_runtime")) |
| 5341 | - || (!function_exists("set_magic_quotes_runtime"))) { |
|
| 5342 | - return $v_result; |
|
| 5343 | - } |
|
| 5341 | + || (!function_exists("set_magic_quotes_runtime"))) { |
|
| 5342 | + return $v_result; |
|
| 5343 | + } |
|
| 5344 | 5344 | |
| 5345 | 5345 | // ----- Look if already done |
| 5346 | 5346 | if ($this->magic_quotes_status != -1) { |
| 5347 | - return $v_result; |
|
| 5348 | - } |
|
| 5347 | + return $v_result; |
|
| 5348 | + } |
|
| 5349 | 5349 | |
| 5350 | - // ----- Get and memorize the magic_quote value |
|
| 5351 | - $this->magic_quotes_status = @get_magic_quotes_runtime(); |
|
| 5350 | + // ----- Get and memorize the magic_quote value |
|
| 5351 | + $this->magic_quotes_status = @get_magic_quotes_runtime(); |
|
| 5352 | 5352 | |
| 5353 | - // ----- Disable magic_quotes |
|
| 5354 | - if ($this->magic_quotes_status == 1) { |
|
| 5355 | - @set_magic_quotes_runtime(0); |
|
| 5356 | - } |
|
| 5353 | + // ----- Disable magic_quotes |
|
| 5354 | + if ($this->magic_quotes_status == 1) { |
|
| 5355 | + @set_magic_quotes_runtime(0); |
|
| 5356 | + } |
|
| 5357 | 5357 | |
| 5358 | 5358 | // ----- Return |
| 5359 | 5359 | return $v_result; |
| 5360 | - } |
|
| 5361 | - // -------------------------------------------------------------------------------- |
|
| 5362 | - |
|
| 5363 | - // -------------------------------------------------------------------------------- |
|
| 5364 | - // Function : privSwapBackMagicQuotes() |
|
| 5365 | - // Description : |
|
| 5366 | - // Parameters : |
|
| 5367 | - // Return Values : |
|
| 5368 | - // -------------------------------------------------------------------------------- |
|
| 5369 | - function privSwapBackMagicQuotes() |
|
| 5370 | - { |
|
| 5360 | + } |
|
| 5361 | + // -------------------------------------------------------------------------------- |
|
| 5362 | + |
|
| 5363 | + // -------------------------------------------------------------------------------- |
|
| 5364 | + // Function : privSwapBackMagicQuotes() |
|
| 5365 | + // Description : |
|
| 5366 | + // Parameters : |
|
| 5367 | + // Return Values : |
|
| 5368 | + // -------------------------------------------------------------------------------- |
|
| 5369 | + function privSwapBackMagicQuotes() |
|
| 5370 | + { |
|
| 5371 | 5371 | $v_result=1; |
| 5372 | 5372 | |
| 5373 | 5373 | // ----- Look if function exists |
| 5374 | 5374 | if ( (!function_exists("get_magic_quotes_runtime")) |
| 5375 | - || (!function_exists("set_magic_quotes_runtime"))) { |
|
| 5376 | - return $v_result; |
|
| 5377 | - } |
|
| 5375 | + || (!function_exists("set_magic_quotes_runtime"))) { |
|
| 5376 | + return $v_result; |
|
| 5377 | + } |
|
| 5378 | 5378 | |
| 5379 | 5379 | // ----- Look if something to do |
| 5380 | 5380 | if ($this->magic_quotes_status != -1) { |
| 5381 | - return $v_result; |
|
| 5382 | - } |
|
| 5381 | + return $v_result; |
|
| 5382 | + } |
|
| 5383 | 5383 | |
| 5384 | - // ----- Swap back magic_quotes |
|
| 5385 | - if ($this->magic_quotes_status == 1) { |
|
| 5386 | - @set_magic_quotes_runtime($this->magic_quotes_status); |
|
| 5387 | - } |
|
| 5384 | + // ----- Swap back magic_quotes |
|
| 5385 | + if ($this->magic_quotes_status == 1) { |
|
| 5386 | + @set_magic_quotes_runtime($this->magic_quotes_status); |
|
| 5387 | + } |
|
| 5388 | 5388 | |
| 5389 | 5389 | // ----- Return |
| 5390 | 5390 | return $v_result; |
| 5391 | - } |
|
| 5392 | - // -------------------------------------------------------------------------------- |
|
| 5393 | - |
|
| 5394 | - } |
|
| 5395 | - // End of class |
|
| 5396 | - // -------------------------------------------------------------------------------- |
|
| 5397 | - |
|
| 5398 | - // -------------------------------------------------------------------------------- |
|
| 5399 | - // Function : PclZipUtilPathReduction() |
|
| 5400 | - // Description : |
|
| 5401 | - // Parameters : |
|
| 5402 | - // Return Values : |
|
| 5403 | - // -------------------------------------------------------------------------------- |
|
| 5404 | - function PclZipUtilPathReduction($p_dir) |
|
| 5405 | - { |
|
| 5391 | + } |
|
| 5392 | + // -------------------------------------------------------------------------------- |
|
| 5393 | + |
|
| 5394 | + } |
|
| 5395 | + // End of class |
|
| 5396 | + // -------------------------------------------------------------------------------- |
|
| 5397 | + |
|
| 5398 | + // -------------------------------------------------------------------------------- |
|
| 5399 | + // Function : PclZipUtilPathReduction() |
|
| 5400 | + // Description : |
|
| 5401 | + // Parameters : |
|
| 5402 | + // Return Values : |
|
| 5403 | + // -------------------------------------------------------------------------------- |
|
| 5404 | + function PclZipUtilPathReduction($p_dir) |
|
| 5405 | + { |
|
| 5406 | 5406 | $v_result = ""; |
| 5407 | 5407 | |
| 5408 | 5408 | // ----- Look for not empty path |
| 5409 | 5409 | if ($p_dir != "") { |
| 5410 | - // ----- Explode path by directory names |
|
| 5411 | - $v_list = explode("/", $p_dir); |
|
| 5410 | + // ----- Explode path by directory names |
|
| 5411 | + $v_list = explode("/", $p_dir); |
|
| 5412 | 5412 | |
| 5413 | - // ----- Study directories from last to first |
|
| 5414 | - $v_skip = 0; |
|
| 5415 | - for ($i=sizeof($v_list)-1; $i>=0; $i--) { |
|
| 5413 | + // ----- Study directories from last to first |
|
| 5414 | + $v_skip = 0; |
|
| 5415 | + for ($i=sizeof($v_list)-1; $i>=0; $i--) { |
|
| 5416 | 5416 | // ----- Look for current path |
| 5417 | 5417 | if ($v_list[$i] == ".") { |
| 5418 | - // ----- Ignore this directory |
|
| 5419 | - // Should be the first $i=0, but no check is done |
|
| 5418 | + // ----- Ignore this directory |
|
| 5419 | + // Should be the first $i=0, but no check is done |
|
| 5420 | 5420 | } |
| 5421 | 5421 | else if ($v_list[$i] == "..") { |
| 5422 | - $v_skip++; |
|
| 5422 | + $v_skip++; |
|
| 5423 | 5423 | } |
| 5424 | 5424 | else if ($v_list[$i] == "") { |
| 5425 | - // ----- First '/' i.e. root slash |
|
| 5426 | - if ($i == 0) { |
|
| 5425 | + // ----- First '/' i.e. root slash |
|
| 5426 | + if ($i == 0) { |
|
| 5427 | 5427 | $v_result = "/".$v_result; |
| 5428 | - if ($v_skip > 0) { |
|
| 5429 | - // ----- It is an invalid path, so the path is not modified |
|
| 5430 | - // TBC |
|
| 5431 | - $v_result = $p_dir; |
|
| 5428 | + if ($v_skip > 0) { |
|
| 5429 | + // ----- It is an invalid path, so the path is not modified |
|
| 5430 | + // TBC |
|
| 5431 | + $v_result = $p_dir; |
|
| 5432 | 5432 | $v_skip = 0; |
| 5433 | - } |
|
| 5434 | - } |
|
| 5435 | - // ----- Last '/' i.e. indicates a directory |
|
| 5436 | - else if ($i == (sizeof($v_list)-1)) { |
|
| 5433 | + } |
|
| 5434 | + } |
|
| 5435 | + // ----- Last '/' i.e. indicates a directory |
|
| 5436 | + else if ($i == (sizeof($v_list)-1)) { |
|
| 5437 | 5437 | $v_result = $v_list[$i]; |
| 5438 | - } |
|
| 5439 | - // ----- Double '/' inside the path |
|
| 5440 | - else { |
|
| 5438 | + } |
|
| 5439 | + // ----- Double '/' inside the path |
|
| 5440 | + else { |
|
| 5441 | 5441 | // ----- Ignore only the double '//' in path, |
| 5442 | 5442 | // but not the first and last '/' |
| 5443 | - } |
|
| 5443 | + } |
|
| 5444 | 5444 | } |
| 5445 | 5445 | else { |
| 5446 | - // ----- Look for item to skip |
|
| 5447 | - if ($v_skip > 0) { |
|
| 5448 | - $v_skip--; |
|
| 5449 | - } |
|
| 5450 | - else { |
|
| 5446 | + // ----- Look for item to skip |
|
| 5447 | + if ($v_skip > 0) { |
|
| 5448 | + $v_skip--; |
|
| 5449 | + } |
|
| 5450 | + else { |
|
| 5451 | 5451 | $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:""); |
| 5452 | - } |
|
| 5452 | + } |
|
| 5453 | + } |
|
| 5453 | 5454 | } |
| 5454 | - } |
|
| 5455 | 5455 | |
| 5456 | - // ----- Look for skip |
|
| 5457 | - if ($v_skip > 0) { |
|
| 5456 | + // ----- Look for skip |
|
| 5457 | + if ($v_skip > 0) { |
|
| 5458 | 5458 | while ($v_skip > 0) { |
| 5459 | 5459 | $v_result = '../'.$v_result; |
| 5460 | 5460 | $v_skip--; |
| 5461 | 5461 | } |
| 5462 | - } |
|
| 5462 | + } |
|
| 5463 | 5463 | } |
| 5464 | 5464 | |
| 5465 | 5465 | // ----- Return |
| 5466 | 5466 | return $v_result; |
| 5467 | - } |
|
| 5468 | - // -------------------------------------------------------------------------------- |
|
| 5469 | - |
|
| 5470 | - // -------------------------------------------------------------------------------- |
|
| 5471 | - // Function : PclZipUtilPathInclusion() |
|
| 5472 | - // Description : |
|
| 5473 | - // This function indicates if the path $p_path is under the $p_dir tree. Or, |
|
| 5474 | - // said in an other way, if the file or sub-dir $p_path is inside the dir |
|
| 5475 | - // $p_dir. |
|
| 5476 | - // The function indicates also if the path is exactly the same as the dir. |
|
| 5477 | - // This function supports path with duplicated '/' like '//', but does not |
|
| 5478 | - // support '.' or '..' statements. |
|
| 5479 | - // Parameters : |
|
| 5480 | - // Return Values : |
|
| 5481 | - // 0 if $p_path is not inside directory $p_dir |
|
| 5482 | - // 1 if $p_path is inside directory $p_dir |
|
| 5483 | - // 2 if $p_path is exactly the same as $p_dir |
|
| 5484 | - // -------------------------------------------------------------------------------- |
|
| 5485 | - function PclZipUtilPathInclusion($p_dir, $p_path) |
|
| 5486 | - { |
|
| 5467 | + } |
|
| 5468 | + // -------------------------------------------------------------------------------- |
|
| 5469 | + |
|
| 5470 | + // -------------------------------------------------------------------------------- |
|
| 5471 | + // Function : PclZipUtilPathInclusion() |
|
| 5472 | + // Description : |
|
| 5473 | + // This function indicates if the path $p_path is under the $p_dir tree. Or, |
|
| 5474 | + // said in an other way, if the file or sub-dir $p_path is inside the dir |
|
| 5475 | + // $p_dir. |
|
| 5476 | + // The function indicates also if the path is exactly the same as the dir. |
|
| 5477 | + // This function supports path with duplicated '/' like '//', but does not |
|
| 5478 | + // support '.' or '..' statements. |
|
| 5479 | + // Parameters : |
|
| 5480 | + // Return Values : |
|
| 5481 | + // 0 if $p_path is not inside directory $p_dir |
|
| 5482 | + // 1 if $p_path is inside directory $p_dir |
|
| 5483 | + // 2 if $p_path is exactly the same as $p_dir |
|
| 5484 | + // -------------------------------------------------------------------------------- |
|
| 5485 | + function PclZipUtilPathInclusion($p_dir, $p_path) |
|
| 5486 | + { |
|
| 5487 | 5487 | $v_result = 1; |
| 5488 | 5488 | |
| 5489 | 5489 | // ----- Look for path beginning by ./ |
| 5490 | 5490 | if ( ($p_dir == '.') |
| 5491 | 5491 | || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) { |
| 5492 | - $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1); |
|
| 5492 | + $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1); |
|
| 5493 | 5493 | } |
| 5494 | 5494 | if ( ($p_path == '.') |
| 5495 | 5495 | || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) { |
| 5496 | - $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1); |
|
| 5496 | + $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1); |
|
| 5497 | 5497 | } |
| 5498 | 5498 | |
| 5499 | 5499 | // ----- Explode dir and path by directory separator |
@@ -5507,196 +5507,196 @@ discard block |
||
| 5507 | 5507 | $j = 0; |
| 5508 | 5508 | while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) { |
| 5509 | 5509 | |
| 5510 | - // ----- Look for empty dir (path reduction) |
|
| 5511 | - if ($v_list_dir[$i] == '') { |
|
| 5510 | + // ----- Look for empty dir (path reduction) |
|
| 5511 | + if ($v_list_dir[$i] == '') { |
|
| 5512 | 5512 | $i++; |
| 5513 | 5513 | continue; |
| 5514 | - } |
|
| 5515 | - if ($v_list_path[$j] == '') { |
|
| 5514 | + } |
|
| 5515 | + if ($v_list_path[$j] == '') { |
|
| 5516 | 5516 | $j++; |
| 5517 | 5517 | continue; |
| 5518 | - } |
|
| 5518 | + } |
|
| 5519 | 5519 | |
| 5520 | - // ----- Compare the items |
|
| 5521 | - if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != '')) { |
|
| 5520 | + // ----- Compare the items |
|
| 5521 | + if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != '')) { |
|
| 5522 | 5522 | $v_result = 0; |
| 5523 | - } |
|
| 5523 | + } |
|
| 5524 | 5524 | |
| 5525 | - // ----- Next items |
|
| 5526 | - $i++; |
|
| 5527 | - $j++; |
|
| 5525 | + // ----- Next items |
|
| 5526 | + $i++; |
|
| 5527 | + $j++; |
|
| 5528 | 5528 | } |
| 5529 | 5529 | |
| 5530 | 5530 | // ----- Look if everything seems to be the same |
| 5531 | 5531 | if ($v_result) { |
| 5532 | - // ----- Skip all the empty items |
|
| 5533 | - while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++; |
|
| 5534 | - while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++; |
|
| 5532 | + // ----- Skip all the empty items |
|
| 5533 | + while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++; |
|
| 5534 | + while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++; |
|
| 5535 | 5535 | |
| 5536 | - if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) { |
|
| 5536 | + if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) { |
|
| 5537 | 5537 | // ----- There are exactly the same |
| 5538 | 5538 | $v_result = 2; |
| 5539 | - } |
|
| 5540 | - else if ($i < $v_list_dir_size) { |
|
| 5539 | + } |
|
| 5540 | + else if ($i < $v_list_dir_size) { |
|
| 5541 | 5541 | // ----- The path is shorter than the dir |
| 5542 | 5542 | $v_result = 0; |
| 5543 | - } |
|
| 5543 | + } |
|
| 5544 | 5544 | } |
| 5545 | 5545 | |
| 5546 | 5546 | // ----- Return |
| 5547 | 5547 | return $v_result; |
| 5548 | - } |
|
| 5549 | - // -------------------------------------------------------------------------------- |
|
| 5550 | - |
|
| 5551 | - // -------------------------------------------------------------------------------- |
|
| 5552 | - // Function : PclZipUtilCopyBlock() |
|
| 5553 | - // Description : |
|
| 5554 | - // Parameters : |
|
| 5555 | - // $p_mode : read/write compression mode |
|
| 5556 | - // 0 : src & dest normal |
|
| 5557 | - // 1 : src gzip, dest normal |
|
| 5558 | - // 2 : src normal, dest gzip |
|
| 5559 | - // 3 : src & dest gzip |
|
| 5560 | - // Return Values : |
|
| 5561 | - // -------------------------------------------------------------------------------- |
|
| 5562 | - function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0) |
|
| 5563 | - { |
|
| 5548 | + } |
|
| 5549 | + // -------------------------------------------------------------------------------- |
|
| 5550 | + |
|
| 5551 | + // -------------------------------------------------------------------------------- |
|
| 5552 | + // Function : PclZipUtilCopyBlock() |
|
| 5553 | + // Description : |
|
| 5554 | + // Parameters : |
|
| 5555 | + // $p_mode : read/write compression mode |
|
| 5556 | + // 0 : src & dest normal |
|
| 5557 | + // 1 : src gzip, dest normal |
|
| 5558 | + // 2 : src normal, dest gzip |
|
| 5559 | + // 3 : src & dest gzip |
|
| 5560 | + // Return Values : |
|
| 5561 | + // -------------------------------------------------------------------------------- |
|
| 5562 | + function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0) |
|
| 5563 | + { |
|
| 5564 | 5564 | $v_result = 1; |
| 5565 | 5565 | |
| 5566 | 5566 | if ($p_mode==0) |
| 5567 | 5567 | { |
| 5568 | - while ($p_size != 0) |
|
| 5569 | - { |
|
| 5568 | + while ($p_size != 0) |
|
| 5569 | + { |
|
| 5570 | 5570 | $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); |
| 5571 | 5571 | $v_buffer = @fread($p_src, $v_read_size); |
| 5572 | 5572 | @fwrite($p_dest, $v_buffer, $v_read_size); |
| 5573 | 5573 | $p_size -= $v_read_size; |
| 5574 | - } |
|
| 5574 | + } |
|
| 5575 | 5575 | } |
| 5576 | 5576 | else if ($p_mode==1) |
| 5577 | 5577 | { |
| 5578 | - while ($p_size != 0) |
|
| 5579 | - { |
|
| 5578 | + while ($p_size != 0) |
|
| 5579 | + { |
|
| 5580 | 5580 | $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); |
| 5581 | 5581 | $v_buffer = @gzread($p_src, $v_read_size); |
| 5582 | 5582 | @fwrite($p_dest, $v_buffer, $v_read_size); |
| 5583 | 5583 | $p_size -= $v_read_size; |
| 5584 | - } |
|
| 5584 | + } |
|
| 5585 | 5585 | } |
| 5586 | 5586 | else if ($p_mode==2) |
| 5587 | 5587 | { |
| 5588 | - while ($p_size != 0) |
|
| 5589 | - { |
|
| 5588 | + while ($p_size != 0) |
|
| 5589 | + { |
|
| 5590 | 5590 | $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); |
| 5591 | 5591 | $v_buffer = @fread($p_src, $v_read_size); |
| 5592 | 5592 | @gzwrite($p_dest, $v_buffer, $v_read_size); |
| 5593 | 5593 | $p_size -= $v_read_size; |
| 5594 | - } |
|
| 5594 | + } |
|
| 5595 | 5595 | } |
| 5596 | 5596 | else if ($p_mode==3) |
| 5597 | 5597 | { |
| 5598 | - while ($p_size != 0) |
|
| 5599 | - { |
|
| 5598 | + while ($p_size != 0) |
|
| 5599 | + { |
|
| 5600 | 5600 | $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE); |
| 5601 | 5601 | $v_buffer = @gzread($p_src, $v_read_size); |
| 5602 | 5602 | @gzwrite($p_dest, $v_buffer, $v_read_size); |
| 5603 | 5603 | $p_size -= $v_read_size; |
| 5604 | - } |
|
| 5604 | + } |
|
| 5605 | 5605 | } |
| 5606 | 5606 | |
| 5607 | 5607 | // ----- Return |
| 5608 | 5608 | return $v_result; |
| 5609 | - } |
|
| 5610 | - // -------------------------------------------------------------------------------- |
|
| 5611 | - |
|
| 5612 | - // -------------------------------------------------------------------------------- |
|
| 5613 | - // Function : PclZipUtilRename() |
|
| 5614 | - // Description : |
|
| 5615 | - // This function tries to do a simple rename() function. If it fails, it |
|
| 5616 | - // tries to copy the $p_src file in a new $p_dest file and then unlink the |
|
| 5617 | - // first one. |
|
| 5618 | - // Parameters : |
|
| 5619 | - // $p_src : Old filename |
|
| 5620 | - // $p_dest : New filename |
|
| 5621 | - // Return Values : |
|
| 5622 | - // 1 on success, 0 on failure. |
|
| 5623 | - // -------------------------------------------------------------------------------- |
|
| 5624 | - function PclZipUtilRename($p_src, $p_dest) |
|
| 5625 | - { |
|
| 5609 | + } |
|
| 5610 | + // -------------------------------------------------------------------------------- |
|
| 5611 | + |
|
| 5612 | + // -------------------------------------------------------------------------------- |
|
| 5613 | + // Function : PclZipUtilRename() |
|
| 5614 | + // Description : |
|
| 5615 | + // This function tries to do a simple rename() function. If it fails, it |
|
| 5616 | + // tries to copy the $p_src file in a new $p_dest file and then unlink the |
|
| 5617 | + // first one. |
|
| 5618 | + // Parameters : |
|
| 5619 | + // $p_src : Old filename |
|
| 5620 | + // $p_dest : New filename |
|
| 5621 | + // Return Values : |
|
| 5622 | + // 1 on success, 0 on failure. |
|
| 5623 | + // -------------------------------------------------------------------------------- |
|
| 5624 | + function PclZipUtilRename($p_src, $p_dest) |
|
| 5625 | + { |
|
| 5626 | 5626 | $v_result = 1; |
| 5627 | 5627 | |
| 5628 | 5628 | // ----- Try to rename the files |
| 5629 | 5629 | if (!@rename($p_src, $p_dest)) { |
| 5630 | 5630 | |
| 5631 | - // ----- Try to copy & unlink the src |
|
| 5632 | - if (!@copy($p_src, $p_dest)) { |
|
| 5631 | + // ----- Try to copy & unlink the src |
|
| 5632 | + if (!@copy($p_src, $p_dest)) { |
|
| 5633 | 5633 | $v_result = 0; |
| 5634 | - } |
|
| 5635 | - else if (!@unlink($p_src)) { |
|
| 5634 | + } |
|
| 5635 | + else if (!@unlink($p_src)) { |
|
| 5636 | 5636 | $v_result = 0; |
| 5637 | - } |
|
| 5637 | + } |
|
| 5638 | 5638 | } |
| 5639 | 5639 | |
| 5640 | 5640 | // ----- Return |
| 5641 | 5641 | return $v_result; |
| 5642 | - } |
|
| 5643 | - // -------------------------------------------------------------------------------- |
|
| 5644 | - |
|
| 5645 | - // -------------------------------------------------------------------------------- |
|
| 5646 | - // Function : PclZipUtilOptionText() |
|
| 5647 | - // Description : |
|
| 5648 | - // Translate option value in text. Mainly for debug purpose. |
|
| 5649 | - // Parameters : |
|
| 5650 | - // $p_option : the option value. |
|
| 5651 | - // Return Values : |
|
| 5652 | - // The option text value. |
|
| 5653 | - // -------------------------------------------------------------------------------- |
|
| 5654 | - function PclZipUtilOptionText($p_option) |
|
| 5655 | - { |
|
| 5642 | + } |
|
| 5643 | + // -------------------------------------------------------------------------------- |
|
| 5644 | + |
|
| 5645 | + // -------------------------------------------------------------------------------- |
|
| 5646 | + // Function : PclZipUtilOptionText() |
|
| 5647 | + // Description : |
|
| 5648 | + // Translate option value in text. Mainly for debug purpose. |
|
| 5649 | + // Parameters : |
|
| 5650 | + // $p_option : the option value. |
|
| 5651 | + // Return Values : |
|
| 5652 | + // The option text value. |
|
| 5653 | + // -------------------------------------------------------------------------------- |
|
| 5654 | + function PclZipUtilOptionText($p_option) |
|
| 5655 | + { |
|
| 5656 | 5656 | |
| 5657 | 5657 | $v_list = get_defined_constants(); |
| 5658 | 5658 | for (reset($v_list); $v_key = key($v_list); next($v_list)) { |
| 5659 | - $v_prefix = substr($v_key, 0, 10); |
|
| 5660 | - if (( ($v_prefix == 'PCLZIP_OPT') |
|
| 5659 | + $v_prefix = substr($v_key, 0, 10); |
|
| 5660 | + if (( ($v_prefix == 'PCLZIP_OPT') |
|
| 5661 | 5661 | || ($v_prefix == 'PCLZIP_CB_') |
| 5662 | 5662 | || ($v_prefix == 'PCLZIP_ATT')) |
| 5663 | - && ($v_list[$v_key] == $p_option)) { |
|
| 5663 | + && ($v_list[$v_key] == $p_option)) { |
|
| 5664 | 5664 | return $v_key; |
| 5665 | - } |
|
| 5665 | + } |
|
| 5666 | 5666 | } |
| 5667 | 5667 | |
| 5668 | 5668 | $v_result = 'Unknown'; |
| 5669 | 5669 | |
| 5670 | 5670 | return $v_result; |
| 5671 | - } |
|
| 5672 | - // -------------------------------------------------------------------------------- |
|
| 5673 | - |
|
| 5674 | - // -------------------------------------------------------------------------------- |
|
| 5675 | - // Function : PclZipUtilTranslateWinPath() |
|
| 5676 | - // Description : |
|
| 5677 | - // Translate windows path by replacing '\' by '/' and optionally removing |
|
| 5678 | - // drive letter. |
|
| 5679 | - // Parameters : |
|
| 5680 | - // $p_path : path to translate. |
|
| 5681 | - // $p_remove_disk_letter : true | false |
|
| 5682 | - // Return Values : |
|
| 5683 | - // The path translated. |
|
| 5684 | - // -------------------------------------------------------------------------------- |
|
| 5685 | - function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true) |
|
| 5686 | - { |
|
| 5671 | + } |
|
| 5672 | + // -------------------------------------------------------------------------------- |
|
| 5673 | + |
|
| 5674 | + // -------------------------------------------------------------------------------- |
|
| 5675 | + // Function : PclZipUtilTranslateWinPath() |
|
| 5676 | + // Description : |
|
| 5677 | + // Translate windows path by replacing '\' by '/' and optionally removing |
|
| 5678 | + // drive letter. |
|
| 5679 | + // Parameters : |
|
| 5680 | + // $p_path : path to translate. |
|
| 5681 | + // $p_remove_disk_letter : true | false |
|
| 5682 | + // Return Values : |
|
| 5683 | + // The path translated. |
|
| 5684 | + // -------------------------------------------------------------------------------- |
|
| 5685 | + function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true) |
|
| 5686 | + { |
|
| 5687 | 5687 | if (stristr(php_uname(), 'windows')) { |
| 5688 | - // ----- Look for potential disk letter |
|
| 5689 | - if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) { |
|
| 5690 | - $p_path = substr($p_path, $v_position+1); |
|
| 5691 | - } |
|
| 5692 | - // ----- Change potential windows directory separator |
|
| 5693 | - if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) { |
|
| 5694 | - $p_path = strtr($p_path, '\\', '/'); |
|
| 5695 | - } |
|
| 5688 | + // ----- Look for potential disk letter |
|
| 5689 | + if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) { |
|
| 5690 | + $p_path = substr($p_path, $v_position+1); |
|
| 5691 | + } |
|
| 5692 | + // ----- Change potential windows directory separator |
|
| 5693 | + if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) { |
|
| 5694 | + $p_path = strtr($p_path, '\\', '/'); |
|
| 5695 | + } |
|
| 5696 | 5696 | } |
| 5697 | 5697 | return $p_path; |
| 5698 | - } |
|
| 5699 | - // -------------------------------------------------------------------------------- |
|
| 5698 | + } |
|
| 5699 | + // -------------------------------------------------------------------------------- |
|
| 5700 | 5700 | |
| 5701 | 5701 | |
| 5702 | 5702 | ?> |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | // ----- Constants |
| 37 | 37 | if (!defined('PCLZIP_READ_BLOCK_SIZE')) { |
| 38 | - define( 'PCLZIP_READ_BLOCK_SIZE', 2048 ); |
|
| 38 | + define('PCLZIP_READ_BLOCK_SIZE', 2048); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | // ----- File list separator |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | //define( 'PCLZIP_SEPARATOR', ' ' ); |
| 50 | 50 | // Recommanded values for smart separation of filenames. |
| 51 | 51 | if (!defined('PCLZIP_SEPARATOR')) { |
| 52 | - define( 'PCLZIP_SEPARATOR', ',' ); |
|
| 52 | + define('PCLZIP_SEPARATOR', ','); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | // ----- Error configuration |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | // you must ensure that you have included PclError library. |
| 59 | 59 | // [2,...] : reserved for futur use |
| 60 | 60 | if (!defined('PCLZIP_ERROR_EXTERNAL')) { |
| 61 | - define( 'PCLZIP_ERROR_EXTERNAL', 0 ); |
|
| 61 | + define('PCLZIP_ERROR_EXTERNAL', 0); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | // ----- Optional static temporary directory |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | // define( 'PCLZIP_TEMPORARY_DIR', '/temp/' ); |
| 72 | 72 | // define( 'PCLZIP_TEMPORARY_DIR', 'C:/Temp/' ); |
| 73 | 73 | if (!defined('PCLZIP_TEMPORARY_DIR')) { |
| 74 | - define( 'PCLZIP_TEMPORARY_DIR', '' ); |
|
| 74 | + define('PCLZIP_TEMPORARY_DIR', ''); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | // ----- Optional threshold ratio for use of temporary files |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | // Samples : |
| 84 | 84 | // define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.5 ); |
| 85 | 85 | if (!defined('PCLZIP_TEMPORARY_FILE_RATIO')) { |
| 86 | - define( 'PCLZIP_TEMPORARY_FILE_RATIO', 0.47 ); |
|
| 86 | + define('PCLZIP_TEMPORARY_FILE_RATIO', 0.47); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | // -------------------------------------------------------------------------------- |
@@ -108,72 +108,72 @@ discard block |
||
| 108 | 108 | // -12 : Unable to rename file (rename) |
| 109 | 109 | // -13 : Invalid header checksum |
| 110 | 110 | // -14 : Invalid archive size |
| 111 | - define( 'PCLZIP_ERR_USER_ABORTED', 2 ); |
|
| 112 | - define( 'PCLZIP_ERR_NO_ERROR', 0 ); |
|
| 113 | - define( 'PCLZIP_ERR_WRITE_OPEN_FAIL', -1 ); |
|
| 114 | - define( 'PCLZIP_ERR_READ_OPEN_FAIL', -2 ); |
|
| 115 | - define( 'PCLZIP_ERR_INVALID_PARAMETER', -3 ); |
|
| 116 | - define( 'PCLZIP_ERR_MISSING_FILE', -4 ); |
|
| 117 | - define( 'PCLZIP_ERR_FILENAME_TOO_LONG', -5 ); |
|
| 118 | - define( 'PCLZIP_ERR_INVALID_ZIP', -6 ); |
|
| 119 | - define( 'PCLZIP_ERR_BAD_EXTRACTED_FILE', -7 ); |
|
| 120 | - define( 'PCLZIP_ERR_DIR_CREATE_FAIL', -8 ); |
|
| 121 | - define( 'PCLZIP_ERR_BAD_EXTENSION', -9 ); |
|
| 122 | - define( 'PCLZIP_ERR_BAD_FORMAT', -10 ); |
|
| 123 | - define( 'PCLZIP_ERR_DELETE_FILE_FAIL', -11 ); |
|
| 124 | - define( 'PCLZIP_ERR_RENAME_FILE_FAIL', -12 ); |
|
| 125 | - define( 'PCLZIP_ERR_BAD_CHECKSUM', -13 ); |
|
| 126 | - define( 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14 ); |
|
| 127 | - define( 'PCLZIP_ERR_MISSING_OPTION_VALUE', -15 ); |
|
| 128 | - define( 'PCLZIP_ERR_INVALID_OPTION_VALUE', -16 ); |
|
| 129 | - define( 'PCLZIP_ERR_ALREADY_A_DIRECTORY', -17 ); |
|
| 130 | - define( 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18 ); |
|
| 131 | - define( 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19 ); |
|
| 132 | - define( 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', -20 ); |
|
| 133 | - define( 'PCLZIP_ERR_DIRECTORY_RESTRICTION', -21 ); |
|
| 111 | + define('PCLZIP_ERR_USER_ABORTED', 2); |
|
| 112 | + define('PCLZIP_ERR_NO_ERROR', 0); |
|
| 113 | + define('PCLZIP_ERR_WRITE_OPEN_FAIL', -1); |
|
| 114 | + define('PCLZIP_ERR_READ_OPEN_FAIL', -2); |
|
| 115 | + define('PCLZIP_ERR_INVALID_PARAMETER', -3); |
|
| 116 | + define('PCLZIP_ERR_MISSING_FILE', -4); |
|
| 117 | + define('PCLZIP_ERR_FILENAME_TOO_LONG', -5); |
|
| 118 | + define('PCLZIP_ERR_INVALID_ZIP', -6); |
|
| 119 | + define('PCLZIP_ERR_BAD_EXTRACTED_FILE', -7); |
|
| 120 | + define('PCLZIP_ERR_DIR_CREATE_FAIL', -8); |
|
| 121 | + define('PCLZIP_ERR_BAD_EXTENSION', -9); |
|
| 122 | + define('PCLZIP_ERR_BAD_FORMAT', -10); |
|
| 123 | + define('PCLZIP_ERR_DELETE_FILE_FAIL', -11); |
|
| 124 | + define('PCLZIP_ERR_RENAME_FILE_FAIL', -12); |
|
| 125 | + define('PCLZIP_ERR_BAD_CHECKSUM', -13); |
|
| 126 | + define('PCLZIP_ERR_INVALID_ARCHIVE_ZIP', -14); |
|
| 127 | + define('PCLZIP_ERR_MISSING_OPTION_VALUE', -15); |
|
| 128 | + define('PCLZIP_ERR_INVALID_OPTION_VALUE', -16); |
|
| 129 | + define('PCLZIP_ERR_ALREADY_A_DIRECTORY', -17); |
|
| 130 | + define('PCLZIP_ERR_UNSUPPORTED_COMPRESSION', -18); |
|
| 131 | + define('PCLZIP_ERR_UNSUPPORTED_ENCRYPTION', -19); |
|
| 132 | + define('PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE', -20); |
|
| 133 | + define('PCLZIP_ERR_DIRECTORY_RESTRICTION', -21); |
|
| 134 | 134 | |
| 135 | 135 | // ----- Options values |
| 136 | - define( 'PCLZIP_OPT_PATH', 77001 ); |
|
| 137 | - define( 'PCLZIP_OPT_ADD_PATH', 77002 ); |
|
| 138 | - define( 'PCLZIP_OPT_REMOVE_PATH', 77003 ); |
|
| 139 | - define( 'PCLZIP_OPT_REMOVE_ALL_PATH', 77004 ); |
|
| 140 | - define( 'PCLZIP_OPT_SET_CHMOD', 77005 ); |
|
| 141 | - define( 'PCLZIP_OPT_EXTRACT_AS_STRING', 77006 ); |
|
| 142 | - define( 'PCLZIP_OPT_NO_COMPRESSION', 77007 ); |
|
| 143 | - define( 'PCLZIP_OPT_BY_NAME', 77008 ); |
|
| 144 | - define( 'PCLZIP_OPT_BY_INDEX', 77009 ); |
|
| 145 | - define( 'PCLZIP_OPT_BY_EREG', 77010 ); |
|
| 146 | - define( 'PCLZIP_OPT_BY_PREG', 77011 ); |
|
| 147 | - define( 'PCLZIP_OPT_COMMENT', 77012 ); |
|
| 148 | - define( 'PCLZIP_OPT_ADD_COMMENT', 77013 ); |
|
| 149 | - define( 'PCLZIP_OPT_PREPEND_COMMENT', 77014 ); |
|
| 150 | - define( 'PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015 ); |
|
| 151 | - define( 'PCLZIP_OPT_REPLACE_NEWER', 77016 ); |
|
| 152 | - define( 'PCLZIP_OPT_STOP_ON_ERROR', 77017 ); |
|
| 136 | + define('PCLZIP_OPT_PATH', 77001); |
|
| 137 | + define('PCLZIP_OPT_ADD_PATH', 77002); |
|
| 138 | + define('PCLZIP_OPT_REMOVE_PATH', 77003); |
|
| 139 | + define('PCLZIP_OPT_REMOVE_ALL_PATH', 77004); |
|
| 140 | + define('PCLZIP_OPT_SET_CHMOD', 77005); |
|
| 141 | + define('PCLZIP_OPT_EXTRACT_AS_STRING', 77006); |
|
| 142 | + define('PCLZIP_OPT_NO_COMPRESSION', 77007); |
|
| 143 | + define('PCLZIP_OPT_BY_NAME', 77008); |
|
| 144 | + define('PCLZIP_OPT_BY_INDEX', 77009); |
|
| 145 | + define('PCLZIP_OPT_BY_EREG', 77010); |
|
| 146 | + define('PCLZIP_OPT_BY_PREG', 77011); |
|
| 147 | + define('PCLZIP_OPT_COMMENT', 77012); |
|
| 148 | + define('PCLZIP_OPT_ADD_COMMENT', 77013); |
|
| 149 | + define('PCLZIP_OPT_PREPEND_COMMENT', 77014); |
|
| 150 | + define('PCLZIP_OPT_EXTRACT_IN_OUTPUT', 77015); |
|
| 151 | + define('PCLZIP_OPT_REPLACE_NEWER', 77016); |
|
| 152 | + define('PCLZIP_OPT_STOP_ON_ERROR', 77017); |
|
| 153 | 153 | // Having big trouble with crypt. Need to multiply 2 long int |
| 154 | 154 | // which is not correctly supported by PHP ... |
| 155 | 155 | //define( 'PCLZIP_OPT_CRYPT', 77018 ); |
| 156 | - define( 'PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019 ); |
|
| 157 | - define( 'PCLZIP_OPT_TEMP_FILE_THRESHOLD', 77020 ); |
|
| 158 | - define( 'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD', 77020 ); // alias |
|
| 159 | - define( 'PCLZIP_OPT_TEMP_FILE_ON', 77021 ); |
|
| 160 | - define( 'PCLZIP_OPT_ADD_TEMP_FILE_ON', 77021 ); // alias |
|
| 161 | - define( 'PCLZIP_OPT_TEMP_FILE_OFF', 77022 ); |
|
| 162 | - define( 'PCLZIP_OPT_ADD_TEMP_FILE_OFF', 77022 ); // alias |
|
| 156 | + define('PCLZIP_OPT_EXTRACT_DIR_RESTRICTION', 77019); |
|
| 157 | + define('PCLZIP_OPT_TEMP_FILE_THRESHOLD', 77020); |
|
| 158 | + define('PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD', 77020); // alias |
|
| 159 | + define('PCLZIP_OPT_TEMP_FILE_ON', 77021); |
|
| 160 | + define('PCLZIP_OPT_ADD_TEMP_FILE_ON', 77021); // alias |
|
| 161 | + define('PCLZIP_OPT_TEMP_FILE_OFF', 77022); |
|
| 162 | + define('PCLZIP_OPT_ADD_TEMP_FILE_OFF', 77022); // alias |
|
| 163 | 163 | |
| 164 | 164 | // ----- File description attributes |
| 165 | - define( 'PCLZIP_ATT_FILE_NAME', 79001 ); |
|
| 166 | - define( 'PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002 ); |
|
| 167 | - define( 'PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003 ); |
|
| 168 | - define( 'PCLZIP_ATT_FILE_MTIME', 79004 ); |
|
| 169 | - define( 'PCLZIP_ATT_FILE_CONTENT', 79005 ); |
|
| 170 | - define( 'PCLZIP_ATT_FILE_COMMENT', 79006 ); |
|
| 165 | + define('PCLZIP_ATT_FILE_NAME', 79001); |
|
| 166 | + define('PCLZIP_ATT_FILE_NEW_SHORT_NAME', 79002); |
|
| 167 | + define('PCLZIP_ATT_FILE_NEW_FULL_NAME', 79003); |
|
| 168 | + define('PCLZIP_ATT_FILE_MTIME', 79004); |
|
| 169 | + define('PCLZIP_ATT_FILE_CONTENT', 79005); |
|
| 170 | + define('PCLZIP_ATT_FILE_COMMENT', 79006); |
|
| 171 | 171 | |
| 172 | 172 | // ----- Call backs values |
| 173 | - define( 'PCLZIP_CB_PRE_EXTRACT', 78001 ); |
|
| 174 | - define( 'PCLZIP_CB_POST_EXTRACT', 78002 ); |
|
| 175 | - define( 'PCLZIP_CB_PRE_ADD', 78003 ); |
|
| 176 | - define( 'PCLZIP_CB_POST_ADD', 78004 ); |
|
| 173 | + define('PCLZIP_CB_PRE_EXTRACT', 78001); |
|
| 174 | + define('PCLZIP_CB_POST_EXTRACT', 78002); |
|
| 175 | + define('PCLZIP_CB_PRE_ADD', 78003); |
|
| 176 | + define('PCLZIP_CB_POST_ADD', 78004); |
|
| 177 | 177 | /* For futur use |
| 178 | 178 | define( 'PCLZIP_CB_PRE_LIST', 78005 ); |
| 179 | 179 | define( 'PCLZIP_CB_POST_LIST', 78006 ); |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | // -------------------------------------------------------------------------------- |
| 279 | 279 | function create($p_filelist) |
| 280 | 280 | { |
| 281 | - $v_result=1; |
|
| 281 | + $v_result = 1; |
|
| 282 | 282 | |
| 283 | 283 | // ----- Reset the error handler |
| 284 | 284 | $this->privErrorReset(); |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | |
| 305 | 305 | // ----- Parse the options |
| 306 | 306 | $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
| 307 | - array (PCLZIP_OPT_REMOVE_PATH => 'optional', |
|
| 307 | + array(PCLZIP_OPT_REMOVE_PATH => 'optional', |
|
| 308 | 308 | PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
| 309 | 309 | PCLZIP_OPT_ADD_PATH => 'optional', |
| 310 | 310 | PCLZIP_CB_PRE_ADD => 'optional', |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | |
| 391 | 391 | // ----- For each file in the list check the attributes |
| 392 | 392 | $v_supported_attributes |
| 393 | - = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' |
|
| 393 | + = array(PCLZIP_ATT_FILE_NAME => 'mandatory' |
|
| 394 | 394 | ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' |
| 395 | 395 | ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' |
| 396 | 396 | ,PCLZIP_ATT_FILE_MTIME => 'optional' |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | // -------------------------------------------------------------------------------- |
| 462 | 462 | function add($p_filelist) |
| 463 | 463 | { |
| 464 | - $v_result=1; |
|
| 464 | + $v_result = 1; |
|
| 465 | 465 | |
| 466 | 466 | // ----- Reset the error handler |
| 467 | 467 | $this->privErrorReset(); |
@@ -487,7 +487,7 @@ discard block |
||
| 487 | 487 | |
| 488 | 488 | // ----- Parse the options |
| 489 | 489 | $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
| 490 | - array (PCLZIP_OPT_REMOVE_PATH => 'optional', |
|
| 490 | + array(PCLZIP_OPT_REMOVE_PATH => 'optional', |
|
| 491 | 491 | PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
| 492 | 492 | PCLZIP_OPT_ADD_PATH => 'optional', |
| 493 | 493 | PCLZIP_CB_PRE_ADD => 'optional', |
@@ -573,7 +573,7 @@ discard block |
||
| 573 | 573 | |
| 574 | 574 | // ----- For each file in the list check the attributes |
| 575 | 575 | $v_supported_attributes |
| 576 | - = array ( PCLZIP_ATT_FILE_NAME => 'mandatory' |
|
| 576 | + = array(PCLZIP_ATT_FILE_NAME => 'mandatory' |
|
| 577 | 577 | ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional' |
| 578 | 578 | ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional' |
| 579 | 579 | ,PCLZIP_ATT_FILE_MTIME => 'optional' |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | // -------------------------------------------------------------------------------- |
| 651 | 651 | function listContent() |
| 652 | 652 | { |
| 653 | - $v_result=1; |
|
| 653 | + $v_result = 1; |
|
| 654 | 654 | |
| 655 | 655 | // ----- Reset the error handler |
| 656 | 656 | $this->privErrorReset(); |
@@ -707,7 +707,7 @@ discard block |
||
| 707 | 707 | // -------------------------------------------------------------------------------- |
| 708 | 708 | function extract() |
| 709 | 709 | { |
| 710 | - $v_result=1; |
|
| 710 | + $v_result = 1; |
|
| 711 | 711 | |
| 712 | 712 | // ----- Reset the error handler |
| 713 | 713 | $this->privErrorReset(); |
@@ -740,7 +740,7 @@ discard block |
||
| 740 | 740 | |
| 741 | 741 | // ----- Parse the options |
| 742 | 742 | $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
| 743 | - array (PCLZIP_OPT_PATH => 'optional', |
|
| 743 | + array(PCLZIP_OPT_PATH => 'optional', |
|
| 744 | 744 | PCLZIP_OPT_REMOVE_PATH => 'optional', |
| 745 | 745 | PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
| 746 | 746 | PCLZIP_OPT_ADD_PATH => 'optional', |
@@ -864,7 +864,7 @@ discard block |
||
| 864 | 864 | //function extractByIndex($p_index, options...) |
| 865 | 865 | function extractByIndex($p_index) |
| 866 | 866 | { |
| 867 | - $v_result=1; |
|
| 867 | + $v_result = 1; |
|
| 868 | 868 | |
| 869 | 869 | // ----- Reset the error handler |
| 870 | 870 | $this->privErrorReset(); |
@@ -901,7 +901,7 @@ discard block |
||
| 901 | 901 | |
| 902 | 902 | // ----- Parse the options |
| 903 | 903 | $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
| 904 | - array (PCLZIP_OPT_PATH => 'optional', |
|
| 904 | + array(PCLZIP_OPT_PATH => 'optional', |
|
| 905 | 905 | PCLZIP_OPT_REMOVE_PATH => 'optional', |
| 906 | 906 | PCLZIP_OPT_REMOVE_ALL_PATH => 'optional', |
| 907 | 907 | PCLZIP_OPT_EXTRACT_AS_STRING => 'optional', |
@@ -971,10 +971,10 @@ discard block |
||
| 971 | 971 | // ----- Trick |
| 972 | 972 | // Here I want to reuse extractByRule(), so I need to parse the $p_index |
| 973 | 973 | // with privParseOptions() |
| 974 | - $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index); |
|
| 974 | + $v_arg_trick = array(PCLZIP_OPT_BY_INDEX, $p_index); |
|
| 975 | 975 | $v_options_trick = array(); |
| 976 | 976 | $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick, |
| 977 | - array (PCLZIP_OPT_BY_INDEX => 'optional' )); |
|
| 977 | + array(PCLZIP_OPT_BY_INDEX => 'optional')); |
|
| 978 | 978 | if ($v_result != 1) { |
| 979 | 979 | return 0; |
| 980 | 980 | } |
@@ -1013,7 +1013,7 @@ discard block |
||
| 1013 | 1013 | // -------------------------------------------------------------------------------- |
| 1014 | 1014 | function delete() |
| 1015 | 1015 | { |
| 1016 | - $v_result=1; |
|
| 1016 | + $v_result = 1; |
|
| 1017 | 1017 | |
| 1018 | 1018 | // ----- Reset the error handler |
| 1019 | 1019 | $this->privErrorReset(); |
@@ -1036,10 +1036,10 @@ discard block |
||
| 1036 | 1036 | |
| 1037 | 1037 | // ----- Parse the options |
| 1038 | 1038 | $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options, |
| 1039 | - array (PCLZIP_OPT_BY_NAME => 'optional', |
|
| 1039 | + array(PCLZIP_OPT_BY_NAME => 'optional', |
|
| 1040 | 1040 | PCLZIP_OPT_BY_EREG => 'optional', |
| 1041 | 1041 | PCLZIP_OPT_BY_PREG => 'optional', |
| 1042 | - PCLZIP_OPT_BY_INDEX => 'optional' )); |
|
| 1042 | + PCLZIP_OPT_BY_INDEX => 'optional')); |
|
| 1043 | 1043 | if ($v_result != 1) { |
| 1044 | 1044 | return 0; |
| 1045 | 1045 | } |
@@ -1293,9 +1293,9 @@ discard block |
||
| 1293 | 1293 | // Description : |
| 1294 | 1294 | // Parameters : |
| 1295 | 1295 | // -------------------------------------------------------------------------------- |
| 1296 | - function errorName($p_with_code=false) |
|
| 1296 | + function errorName($p_with_code = false) |
|
| 1297 | 1297 | { |
| 1298 | - $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR', |
|
| 1298 | + $v_name = array(PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR', |
|
| 1299 | 1299 | PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL', |
| 1300 | 1300 | PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL', |
| 1301 | 1301 | PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER', |
@@ -1339,7 +1339,7 @@ discard block |
||
| 1339 | 1339 | // Description : |
| 1340 | 1340 | // Parameters : |
| 1341 | 1341 | // -------------------------------------------------------------------------------- |
| 1342 | - function errorInfo($p_full=false) |
|
| 1342 | + function errorInfo($p_full = false) |
|
| 1343 | 1343 | { |
| 1344 | 1344 | if (PCLZIP_ERROR_EXTERNAL == 1) { |
| 1345 | 1345 | return(PclErrorString()); |
@@ -1378,7 +1378,7 @@ discard block |
||
| 1378 | 1378 | // true on success, |
| 1379 | 1379 | // false on error, the error code is set. |
| 1380 | 1380 | // -------------------------------------------------------------------------------- |
| 1381 | - function privCheckFormat($p_level=0) |
|
| 1381 | + function privCheckFormat($p_level = 0) |
|
| 1382 | 1382 | { |
| 1383 | 1383 | $v_result = true; |
| 1384 | 1384 | |
@@ -1431,13 +1431,13 @@ discard block |
||
| 1431 | 1431 | // 1 on success. |
| 1432 | 1432 | // 0 on failure. |
| 1433 | 1433 | // -------------------------------------------------------------------------------- |
| 1434 | - function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false) |
|
| 1434 | + function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options = false) |
|
| 1435 | 1435 | { |
| 1436 | - $v_result=1; |
|
| 1436 | + $v_result = 1; |
|
| 1437 | 1437 | |
| 1438 | 1438 | // ----- Read the options |
| 1439 | - $i=0; |
|
| 1440 | - while ($i<$p_size) { |
|
| 1439 | + $i = 0; |
|
| 1440 | + while ($i < $p_size) { |
|
| 1441 | 1441 | |
| 1442 | 1442 | // ----- Check if the option is supported |
| 1443 | 1443 | if (!isset($v_requested_options[$p_options_list[$i]])) { |
@@ -1455,7 +1455,7 @@ discard block |
||
| 1455 | 1455 | case PCLZIP_OPT_REMOVE_PATH : |
| 1456 | 1456 | case PCLZIP_OPT_ADD_PATH : |
| 1457 | 1457 | // ----- Check the number of parameters |
| 1458 | - if (($i+1) >= $p_size) { |
|
| 1458 | + if (($i + 1) >= $p_size) { |
|
| 1459 | 1459 | // ----- Error log |
| 1460 | 1460 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
| 1461 | 1461 | |
@@ -1464,13 +1464,13 @@ discard block |
||
| 1464 | 1464 | } |
| 1465 | 1465 | |
| 1466 | 1466 | // ----- Get the value |
| 1467 | - $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); |
|
| 1467 | + $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i + 1], FALSE); |
|
| 1468 | 1468 | $i++; |
| 1469 | 1469 | break; |
| 1470 | 1470 | |
| 1471 | 1471 | case PCLZIP_OPT_TEMP_FILE_THRESHOLD : |
| 1472 | 1472 | // ----- Check the number of parameters |
| 1473 | - if (($i+1) >= $p_size) { |
|
| 1473 | + if (($i + 1) >= $p_size) { |
|
| 1474 | 1474 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
| 1475 | 1475 | return PclZip::errorCode(); |
| 1476 | 1476 | } |
@@ -1482,14 +1482,14 @@ discard block |
||
| 1482 | 1482 | } |
| 1483 | 1483 | |
| 1484 | 1484 | // ----- Check the value |
| 1485 | - $v_value = $p_options_list[$i+1]; |
|
| 1486 | - if ((!is_integer($v_value)) || ($v_value<0)) { |
|
| 1485 | + $v_value = $p_options_list[$i + 1]; |
|
| 1486 | + if ((!is_integer($v_value)) || ($v_value < 0)) { |
|
| 1487 | 1487 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
| 1488 | 1488 | return PclZip::errorCode(); |
| 1489 | 1489 | } |
| 1490 | 1490 | |
| 1491 | 1491 | // ----- Get the value (and convert it in bytes) |
| 1492 | - $v_result_list[$p_options_list[$i]] = $v_value*1048576; |
|
| 1492 | + $v_result_list[$p_options_list[$i]] = $v_value * 1048576; |
|
| 1493 | 1493 | $i++; |
| 1494 | 1494 | break; |
| 1495 | 1495 | |
@@ -1520,7 +1520,7 @@ discard block |
||
| 1520 | 1520 | |
| 1521 | 1521 | case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION : |
| 1522 | 1522 | // ----- Check the number of parameters |
| 1523 | - if (($i+1) >= $p_size) { |
|
| 1523 | + if (($i + 1) >= $p_size) { |
|
| 1524 | 1524 | // ----- Error log |
| 1525 | 1525 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
| 1526 | 1526 | |
@@ -1529,9 +1529,9 @@ discard block |
||
| 1529 | 1529 | } |
| 1530 | 1530 | |
| 1531 | 1531 | // ----- Get the value |
| 1532 | - if ( is_string($p_options_list[$i+1]) |
|
| 1533 | - && ($p_options_list[$i+1] != '')) { |
|
| 1534 | - $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); |
|
| 1532 | + if (is_string($p_options_list[$i + 1]) |
|
| 1533 | + && ($p_options_list[$i + 1] != '')) { |
|
| 1534 | + $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i + 1], FALSE); |
|
| 1535 | 1535 | $i++; |
| 1536 | 1536 | } |
| 1537 | 1537 | else { |
@@ -1541,7 +1541,7 @@ discard block |
||
| 1541 | 1541 | // ----- Look for options that request an array of string for value |
| 1542 | 1542 | case PCLZIP_OPT_BY_NAME : |
| 1543 | 1543 | // ----- Check the number of parameters |
| 1544 | - if (($i+1) >= $p_size) { |
|
| 1544 | + if (($i + 1) >= $p_size) { |
|
| 1545 | 1545 | // ----- Error log |
| 1546 | 1546 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
| 1547 | 1547 | |
@@ -1550,11 +1550,11 @@ discard block |
||
| 1550 | 1550 | } |
| 1551 | 1551 | |
| 1552 | 1552 | // ----- Get the value |
| 1553 | - if (is_string($p_options_list[$i+1])) { |
|
| 1554 | - $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1]; |
|
| 1553 | + if (is_string($p_options_list[$i + 1])) { |
|
| 1554 | + $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i + 1]; |
|
| 1555 | 1555 | } |
| 1556 | - else if (is_array($p_options_list[$i+1])) { |
|
| 1557 | - $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
|
| 1556 | + else if (is_array($p_options_list[$i + 1])) { |
|
| 1557 | + $v_result_list[$p_options_list[$i]] = $p_options_list[$i + 1]; |
|
| 1558 | 1558 | } |
| 1559 | 1559 | else { |
| 1560 | 1560 | // ----- Error log |
@@ -1574,7 +1574,7 @@ discard block |
||
| 1574 | 1574 | case PCLZIP_OPT_BY_PREG : |
| 1575 | 1575 | //case PCLZIP_OPT_CRYPT : |
| 1576 | 1576 | // ----- Check the number of parameters |
| 1577 | - if (($i+1) >= $p_size) { |
|
| 1577 | + if (($i + 1) >= $p_size) { |
|
| 1578 | 1578 | // ----- Error log |
| 1579 | 1579 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
| 1580 | 1580 | |
@@ -1583,8 +1583,8 @@ discard block |
||
| 1583 | 1583 | } |
| 1584 | 1584 | |
| 1585 | 1585 | // ----- Get the value |
| 1586 | - if (is_string($p_options_list[$i+1])) { |
|
| 1587 | - $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
|
| 1586 | + if (is_string($p_options_list[$i + 1])) { |
|
| 1587 | + $v_result_list[$p_options_list[$i]] = $p_options_list[$i + 1]; |
|
| 1588 | 1588 | } |
| 1589 | 1589 | else { |
| 1590 | 1590 | // ----- Error log |
@@ -1601,7 +1601,7 @@ discard block |
||
| 1601 | 1601 | case PCLZIP_OPT_ADD_COMMENT : |
| 1602 | 1602 | case PCLZIP_OPT_PREPEND_COMMENT : |
| 1603 | 1603 | // ----- Check the number of parameters |
| 1604 | - if (($i+1) >= $p_size) { |
|
| 1604 | + if (($i + 1) >= $p_size) { |
|
| 1605 | 1605 | // ----- Error log |
| 1606 | 1606 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, |
| 1607 | 1607 | "Missing parameter value for option '" |
@@ -1613,8 +1613,8 @@ discard block |
||
| 1613 | 1613 | } |
| 1614 | 1614 | |
| 1615 | 1615 | // ----- Get the value |
| 1616 | - if (is_string($p_options_list[$i+1])) { |
|
| 1617 | - $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
|
| 1616 | + if (is_string($p_options_list[$i + 1])) { |
|
| 1617 | + $v_result_list[$p_options_list[$i]] = $p_options_list[$i + 1]; |
|
| 1618 | 1618 | } |
| 1619 | 1619 | else { |
| 1620 | 1620 | // ----- Error log |
@@ -1632,7 +1632,7 @@ discard block |
||
| 1632 | 1632 | // ----- Look for options that request an array of index |
| 1633 | 1633 | case PCLZIP_OPT_BY_INDEX : |
| 1634 | 1634 | // ----- Check the number of parameters |
| 1635 | - if (($i+1) >= $p_size) { |
|
| 1635 | + if (($i + 1) >= $p_size) { |
|
| 1636 | 1636 | // ----- Error log |
| 1637 | 1637 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
| 1638 | 1638 | |
@@ -1642,19 +1642,19 @@ discard block |
||
| 1642 | 1642 | |
| 1643 | 1643 | // ----- Get the value |
| 1644 | 1644 | $v_work_list = array(); |
| 1645 | - if (is_string($p_options_list[$i+1])) { |
|
| 1645 | + if (is_string($p_options_list[$i + 1])) { |
|
| 1646 | 1646 | |
| 1647 | 1647 | // ----- Remove spaces |
| 1648 | - $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', ''); |
|
| 1648 | + $p_options_list[$i + 1] = strtr($p_options_list[$i + 1], ' ', ''); |
|
| 1649 | 1649 | |
| 1650 | 1650 | // ----- Parse items |
| 1651 | - $v_work_list = explode(",", $p_options_list[$i+1]); |
|
| 1651 | + $v_work_list = explode(",", $p_options_list[$i + 1]); |
|
| 1652 | 1652 | } |
| 1653 | - else if (is_integer($p_options_list[$i+1])) { |
|
| 1654 | - $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1]; |
|
| 1653 | + else if (is_integer($p_options_list[$i + 1])) { |
|
| 1654 | + $v_work_list[0] = $p_options_list[$i + 1].'-'.$p_options_list[$i + 1]; |
|
| 1655 | 1655 | } |
| 1656 | - else if (is_array($p_options_list[$i+1])) { |
|
| 1657 | - $v_work_list = $p_options_list[$i+1]; |
|
| 1656 | + else if (is_array($p_options_list[$i + 1])) { |
|
| 1657 | + $v_work_list = $p_options_list[$i + 1]; |
|
| 1658 | 1658 | } |
| 1659 | 1659 | else { |
| 1660 | 1660 | // ----- Error log |
@@ -1668,9 +1668,9 @@ discard block |
||
| 1668 | 1668 | // each index item in the list must be a couple with a start and |
| 1669 | 1669 | // an end value : [0,3], [5-5], [8-10], ... |
| 1670 | 1670 | // ----- Check the format of each item |
| 1671 | - $v_sort_flag=false; |
|
| 1672 | - $v_sort_value=0; |
|
| 1673 | - for ($j=0; $j<sizeof($v_work_list); $j++) { |
|
| 1671 | + $v_sort_flag = false; |
|
| 1672 | + $v_sort_value = 0; |
|
| 1673 | + for ($j = 0; $j < sizeof($v_work_list); $j++) { |
|
| 1674 | 1674 | // ----- Explode the item |
| 1675 | 1675 | $v_item_list = explode("-", $v_work_list[$j]); |
| 1676 | 1676 | $v_size_item_list = sizeof($v_item_list); |
@@ -1700,7 +1700,7 @@ discard block |
||
| 1700 | 1700 | |
| 1701 | 1701 | // ----- Look for list sort |
| 1702 | 1702 | if ($v_result_list[$p_options_list[$i]][$j]['start'] < $v_sort_value) { |
| 1703 | - $v_sort_flag=true; |
|
| 1703 | + $v_sort_flag = true; |
|
| 1704 | 1704 | |
| 1705 | 1705 | // ----- TBC : An automatic sort should be writen ... |
| 1706 | 1706 | // ----- Error log |
@@ -1734,7 +1734,7 @@ discard block |
||
| 1734 | 1734 | // ----- Look for options that request an octal value |
| 1735 | 1735 | case PCLZIP_OPT_SET_CHMOD : |
| 1736 | 1736 | // ----- Check the number of parameters |
| 1737 | - if (($i+1) >= $p_size) { |
|
| 1737 | + if (($i + 1) >= $p_size) { |
|
| 1738 | 1738 | // ----- Error log |
| 1739 | 1739 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
| 1740 | 1740 | |
@@ -1743,7 +1743,7 @@ discard block |
||
| 1743 | 1743 | } |
| 1744 | 1744 | |
| 1745 | 1745 | // ----- Get the value |
| 1746 | - $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
|
| 1746 | + $v_result_list[$p_options_list[$i]] = $p_options_list[$i + 1]; |
|
| 1747 | 1747 | $i++; |
| 1748 | 1748 | break; |
| 1749 | 1749 | |
@@ -1759,7 +1759,7 @@ discard block |
||
| 1759 | 1759 | case PCLZIP_CB_POST_LIST : |
| 1760 | 1760 | */ |
| 1761 | 1761 | // ----- Check the number of parameters |
| 1762 | - if (($i+1) >= $p_size) { |
|
| 1762 | + if (($i + 1) >= $p_size) { |
|
| 1763 | 1763 | // ----- Error log |
| 1764 | 1764 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
| 1765 | 1765 | |
@@ -1768,7 +1768,7 @@ discard block |
||
| 1768 | 1768 | } |
| 1769 | 1769 | |
| 1770 | 1770 | // ----- Get the value |
| 1771 | - $v_function_name = $p_options_list[$i+1]; |
|
| 1771 | + $v_function_name = $p_options_list[$i + 1]; |
|
| 1772 | 1772 | |
| 1773 | 1773 | // ----- Check that the value is a valid existing function |
| 1774 | 1774 | if (!function_exists($v_function_name)) { |
@@ -1800,7 +1800,7 @@ discard block |
||
| 1800 | 1800 | |
| 1801 | 1801 | // ----- Look for mandatory options |
| 1802 | 1802 | if ($v_requested_options !== false) { |
| 1803 | - for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { |
|
| 1803 | + for ($key = reset($v_requested_options); $key = key($v_requested_options); $key = next($v_requested_options)) { |
|
| 1804 | 1804 | // ----- Look for mandatory option |
| 1805 | 1805 | if ($v_requested_options[$key] == 'mandatory') { |
| 1806 | 1806 | // ----- Look if present |
@@ -1833,7 +1833,7 @@ discard block |
||
| 1833 | 1833 | // -------------------------------------------------------------------------------- |
| 1834 | 1834 | function privOptionDefaultThreshold(&$p_options) |
| 1835 | 1835 | { |
| 1836 | - $v_result=1; |
|
| 1836 | + $v_result = 1; |
|
| 1837 | 1837 | |
| 1838 | 1838 | if (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) |
| 1839 | 1839 | || isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) { |
@@ -1845,16 +1845,16 @@ discard block |
||
| 1845 | 1845 | $v_memory_limit = trim($v_memory_limit); |
| 1846 | 1846 | $last = strtolower(substr($v_memory_limit, -1)); |
| 1847 | 1847 | |
| 1848 | - if($last == 'g') |
|
| 1848 | + if ($last == 'g') |
|
| 1849 | 1849 | //$v_memory_limit = $v_memory_limit*1024*1024*1024; |
| 1850 | - $v_memory_limit = $v_memory_limit*1073741824; |
|
| 1851 | - if($last == 'm') |
|
| 1850 | + $v_memory_limit = $v_memory_limit * 1073741824; |
|
| 1851 | + if ($last == 'm') |
|
| 1852 | 1852 | //$v_memory_limit = $v_memory_limit*1024*1024; |
| 1853 | - $v_memory_limit = $v_memory_limit*1048576; |
|
| 1854 | - if($last == 'k') |
|
| 1855 | - $v_memory_limit = $v_memory_limit*1024; |
|
| 1853 | + $v_memory_limit = $v_memory_limit * 1048576; |
|
| 1854 | + if ($last == 'k') |
|
| 1855 | + $v_memory_limit = $v_memory_limit * 1024; |
|
| 1856 | 1856 | |
| 1857 | - $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*PCLZIP_TEMPORARY_FILE_RATIO); |
|
| 1857 | + $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit * PCLZIP_TEMPORARY_FILE_RATIO); |
|
| 1858 | 1858 | |
| 1859 | 1859 | |
| 1860 | 1860 | // ----- Sanity check : No threshold if value lower than 1M |
@@ -1875,9 +1875,9 @@ discard block |
||
| 1875 | 1875 | // 1 on success. |
| 1876 | 1876 | // 0 on failure. |
| 1877 | 1877 | // -------------------------------------------------------------------------------- |
| 1878 | - function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false) |
|
| 1878 | + function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options = false) |
|
| 1879 | 1879 | { |
| 1880 | - $v_result=1; |
|
| 1880 | + $v_result = 1; |
|
| 1881 | 1881 | |
| 1882 | 1882 | // ----- For each file in the list check the attributes |
| 1883 | 1883 | foreach ($p_file_list as $v_key => $v_value) { |
@@ -1970,7 +1970,7 @@ discard block |
||
| 1970 | 1970 | |
| 1971 | 1971 | // ----- Look for mandatory options |
| 1972 | 1972 | if ($v_requested_options !== false) { |
| 1973 | - for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) { |
|
| 1973 | + for ($key = reset($v_requested_options); $key = key($v_requested_options); $key = next($v_requested_options)) { |
|
| 1974 | 1974 | // ----- Look for mandatory option |
| 1975 | 1975 | if ($v_requested_options[$key] == 'mandatory') { |
| 1976 | 1976 | // ----- Look if present |
@@ -2006,13 +2006,13 @@ discard block |
||
| 2006 | 2006 | // -------------------------------------------------------------------------------- |
| 2007 | 2007 | function privFileDescrExpand(&$p_filedescr_list, &$p_options) |
| 2008 | 2008 | { |
| 2009 | - $v_result=1; |
|
| 2009 | + $v_result = 1; |
|
| 2010 | 2010 | |
| 2011 | 2011 | // ----- Create a result list |
| 2012 | 2012 | $v_result_list = array(); |
| 2013 | 2013 | |
| 2014 | 2014 | // ----- Look each entry |
| 2015 | - for ($i=0; $i<sizeof($p_filedescr_list); $i++) { |
|
| 2015 | + for ($i = 0; $i < sizeof($p_filedescr_list); $i++) { |
|
| 2016 | 2016 | |
| 2017 | 2017 | // ----- Get filedescr |
| 2018 | 2018 | $v_descr = $p_filedescr_list[$i]; |
@@ -2131,7 +2131,7 @@ discard block |
||
| 2131 | 2131 | // -------------------------------------------------------------------------------- |
| 2132 | 2132 | function privCreate($p_filedescr_list, &$p_result_list, &$p_options) |
| 2133 | 2133 | { |
| 2134 | - $v_result=1; |
|
| 2134 | + $v_result = 1; |
|
| 2135 | 2135 | $v_list_detail = array(); |
| 2136 | 2136 | |
| 2137 | 2137 | // ----- Magic quotes trick |
@@ -2166,7 +2166,7 @@ discard block |
||
| 2166 | 2166 | // -------------------------------------------------------------------------------- |
| 2167 | 2167 | function privAdd($p_filedescr_list, &$p_result_list, &$p_options) |
| 2168 | 2168 | { |
| 2169 | - $v_result=1; |
|
| 2169 | + $v_result = 1; |
|
| 2170 | 2170 | $v_list_detail = array(); |
| 2171 | 2171 | |
| 2172 | 2172 | // ----- Look if the archive exists or is empty |
@@ -2183,7 +2183,7 @@ discard block |
||
| 2183 | 2183 | $this->privDisableMagicQuotes(); |
| 2184 | 2184 | |
| 2185 | 2185 | // ----- Open the zip file |
| 2186 | - if (($v_result=$this->privOpenFd('rb')) != 1) |
|
| 2186 | + if (($v_result = $this->privOpenFd('rb')) != 1) |
|
| 2187 | 2187 | { |
| 2188 | 2188 | // ----- Magic quotes trick |
| 2189 | 2189 | $this->privSwapBackMagicQuotes(); |
@@ -2264,7 +2264,7 @@ discard block |
||
| 2264 | 2264 | } |
| 2265 | 2265 | |
| 2266 | 2266 | // ----- Create the Central Dir files header |
| 2267 | - for ($i=0, $v_count=0; $i<sizeof($v_header_list); $i++) |
|
| 2267 | + for ($i = 0, $v_count = 0; $i < sizeof($v_header_list); $i++) |
|
| 2268 | 2268 | { |
| 2269 | 2269 | // ----- Create the file header |
| 2270 | 2270 | if ($v_header_list[$i]['status'] == 'ok') { |
@@ -2297,10 +2297,10 @@ discard block |
||
| 2297 | 2297 | } |
| 2298 | 2298 | |
| 2299 | 2299 | // ----- Calculate the size of the central header |
| 2300 | - $v_size = @ftell($this->zip_fd)-$v_offset; |
|
| 2300 | + $v_size = @ftell($this->zip_fd) - $v_offset; |
|
| 2301 | 2301 | |
| 2302 | 2302 | // ----- Create the central dir footer |
| 2303 | - if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1) |
|
| 2303 | + if (($v_result = $this->privWriteCentralHeader($v_count + $v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1) |
|
| 2304 | 2304 | { |
| 2305 | 2305 | // ----- Reset the file list |
| 2306 | 2306 | unset($v_header_list); |
@@ -2345,7 +2345,7 @@ discard block |
||
| 2345 | 2345 | // -------------------------------------------------------------------------------- |
| 2346 | 2346 | function privOpenFd($p_mode) |
| 2347 | 2347 | { |
| 2348 | - $v_result=1; |
|
| 2348 | + $v_result = 1; |
|
| 2349 | 2349 | |
| 2350 | 2350 | // ----- Look if already open |
| 2351 | 2351 | if ($this->zip_fd != 0) |
@@ -2379,7 +2379,7 @@ discard block |
||
| 2379 | 2379 | // -------------------------------------------------------------------------------- |
| 2380 | 2380 | function privCloseFd() |
| 2381 | 2381 | { |
| 2382 | - $v_result=1; |
|
| 2382 | + $v_result = 1; |
|
| 2383 | 2383 | |
| 2384 | 2384 | if ($this->zip_fd != 0) |
| 2385 | 2385 | @fclose($this->zip_fd); |
@@ -2406,7 +2406,7 @@ discard block |
||
| 2406 | 2406 | // function privAddList($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options) |
| 2407 | 2407 | function privAddList($p_filedescr_list, &$p_result_list, &$p_options) |
| 2408 | 2408 | { |
| 2409 | - $v_result=1; |
|
| 2409 | + $v_result = 1; |
|
| 2410 | 2410 | |
| 2411 | 2411 | // ----- Add the files |
| 2412 | 2412 | $v_header_list = array(); |
@@ -2420,7 +2420,7 @@ discard block |
||
| 2420 | 2420 | $v_offset = @ftell($this->zip_fd); |
| 2421 | 2421 | |
| 2422 | 2422 | // ----- Create the Central Dir files header |
| 2423 | - for ($i=0,$v_count=0; $i<sizeof($v_header_list); $i++) |
|
| 2423 | + for ($i = 0, $v_count = 0; $i < sizeof($v_header_list); $i++) |
|
| 2424 | 2424 | { |
| 2425 | 2425 | // ----- Create the file header |
| 2426 | 2426 | if ($v_header_list[$i]['status'] == 'ok') { |
@@ -2442,7 +2442,7 @@ discard block |
||
| 2442 | 2442 | } |
| 2443 | 2443 | |
| 2444 | 2444 | // ----- Calculate the size of the central header |
| 2445 | - $v_size = @ftell($this->zip_fd)-$v_offset; |
|
| 2445 | + $v_size = @ftell($this->zip_fd) - $v_offset; |
|
| 2446 | 2446 | |
| 2447 | 2447 | // ----- Create the central dir footer |
| 2448 | 2448 | if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1) |
@@ -2470,14 +2470,14 @@ discard block |
||
| 2470 | 2470 | // -------------------------------------------------------------------------------- |
| 2471 | 2471 | function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options) |
| 2472 | 2472 | { |
| 2473 | - $v_result=1; |
|
| 2473 | + $v_result = 1; |
|
| 2474 | 2474 | $v_header = array(); |
| 2475 | 2475 | |
| 2476 | 2476 | // ----- Recuperate the current number of elt in list |
| 2477 | 2477 | $v_nb = sizeof($p_result_list); |
| 2478 | 2478 | |
| 2479 | 2479 | // ----- Loop on the files |
| 2480 | - for ($j=0; ($j<sizeof($p_filedescr_list)) && ($v_result==1); $j++) { |
|
| 2480 | + for ($j = 0; ($j < sizeof($p_filedescr_list)) && ($v_result == 1); $j++) { |
|
| 2481 | 2481 | // ----- Format the filename |
| 2482 | 2482 | $p_filedescr_list[$j]['filename'] |
| 2483 | 2483 | = PclZipUtilTranslateWinPath($p_filedescr_list[$j]['filename'], false); |
@@ -2490,7 +2490,7 @@ discard block |
||
| 2490 | 2490 | } |
| 2491 | 2491 | |
| 2492 | 2492 | // ----- Check the filename |
| 2493 | - if ( ($p_filedescr_list[$j]['type'] != 'virtual_file') |
|
| 2493 | + if (($p_filedescr_list[$j]['type'] != 'virtual_file') |
|
| 2494 | 2494 | && (!file_exists($p_filedescr_list[$j]['filename']))) { |
| 2495 | 2495 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "File '".$p_filedescr_list[$j]['filename']."' does not exist"); |
| 2496 | 2496 | return PclZip::errorCode(); |
@@ -2500,10 +2500,10 @@ discard block |
||
| 2500 | 2500 | // or a dir with all its path removed |
| 2501 | 2501 | // if ( (is_file($p_filedescr_list[$j]['filename'])) |
| 2502 | 2502 | // || ( is_dir($p_filedescr_list[$j]['filename']) |
| 2503 | - if ( ($p_filedescr_list[$j]['type'] == 'file') |
|
| 2503 | + if (($p_filedescr_list[$j]['type'] == 'file') |
|
| 2504 | 2504 | || ($p_filedescr_list[$j]['type'] == 'virtual_file') |
| 2505 | - || ( ($p_filedescr_list[$j]['type'] == 'folder') |
|
| 2506 | - && ( !isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]) |
|
| 2505 | + || (($p_filedescr_list[$j]['type'] == 'folder') |
|
| 2506 | + && (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]) |
|
| 2507 | 2507 | || !$p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
| 2508 | 2508 | ) { |
| 2509 | 2509 | |
@@ -2532,7 +2532,7 @@ discard block |
||
| 2532 | 2532 | // -------------------------------------------------------------------------------- |
| 2533 | 2533 | function privAddFile($p_filedescr, &$p_header, &$p_options) |
| 2534 | 2534 | { |
| 2535 | - $v_result=1; |
|
| 2535 | + $v_result = 1; |
|
| 2536 | 2536 | |
| 2537 | 2537 | // ----- Working variable |
| 2538 | 2538 | $p_filename = $p_filedescr['filename']; |
@@ -2577,13 +2577,13 @@ discard block |
||
| 2577 | 2577 | $p_header['index'] = -1; |
| 2578 | 2578 | |
| 2579 | 2579 | // ----- Look for regular file |
| 2580 | - if ($p_filedescr['type']=='file') { |
|
| 2580 | + if ($p_filedescr['type'] == 'file') { |
|
| 2581 | 2581 | $p_header['external'] = 0x00000000; |
| 2582 | 2582 | $p_header['size'] = filesize($p_filename); |
| 2583 | 2583 | } |
| 2584 | 2584 | |
| 2585 | 2585 | // ----- Look for regular folder |
| 2586 | - else if ($p_filedescr['type']=='folder') { |
|
| 2586 | + else if ($p_filedescr['type'] == 'folder') { |
|
| 2587 | 2587 | $p_header['external'] = 0x00000010; |
| 2588 | 2588 | $p_header['mtime'] = filemtime($p_filename); |
| 2589 | 2589 | $p_header['size'] = filesize($p_filename); |
@@ -2658,10 +2658,10 @@ discard block |
||
| 2658 | 2658 | // ----- Look for a file |
| 2659 | 2659 | if ($p_filedescr['type'] == 'file') { |
| 2660 | 2660 | // ----- Look for using temporary file to zip |
| 2661 | - if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) |
|
| 2661 | + if ((!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) |
|
| 2662 | 2662 | && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON]) |
| 2663 | 2663 | || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) |
| 2664 | - && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) { |
|
| 2664 | + && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])))) { |
|
| 2665 | 2665 | $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options); |
| 2666 | 2666 | if ($v_result < PCLZIP_ERR_NO_ERROR) { |
| 2667 | 2667 | return $v_result; |
@@ -2761,7 +2761,7 @@ discard block |
||
| 2761 | 2761 | // ----- Set the file properties |
| 2762 | 2762 | $p_header['size'] = 0; |
| 2763 | 2763 | //$p_header['external'] = 0x41FF0010; // Value for a folder : to be checked |
| 2764 | - $p_header['external'] = 0x00000010; // Value for a folder : to be checked |
|
| 2764 | + $p_header['external'] = 0x00000010; // Value for a folder : to be checked |
|
| 2765 | 2765 | |
| 2766 | 2766 | // ----- Call the header generation |
| 2767 | 2767 | if (($v_result = $this->privWriteFileHeader($p_header)) != 1) |
@@ -2805,7 +2805,7 @@ discard block |
||
| 2805 | 2805 | // -------------------------------------------------------------------------------- |
| 2806 | 2806 | function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options) |
| 2807 | 2807 | { |
| 2808 | - $v_result=PCLZIP_ERR_NO_ERROR; |
|
| 2808 | + $v_result = PCLZIP_ERR_NO_ERROR; |
|
| 2809 | 2809 | |
| 2810 | 2810 | // ----- Working variable |
| 2811 | 2811 | $p_filename = $p_filedescr['filename']; |
@@ -2859,7 +2859,7 @@ discard block |
||
| 2859 | 2859 | $v_data_header['os'] = bin2hex($v_data_header['os']); |
| 2860 | 2860 | |
| 2861 | 2861 | // ----- Read the gzip file footer |
| 2862 | - @fseek($v_file_compressed, filesize($v_gzip_temp_name)-8); |
|
| 2862 | + @fseek($v_file_compressed, filesize($v_gzip_temp_name) - 8); |
|
| 2863 | 2863 | $v_binary_data = @fread($v_file_compressed, 8); |
| 2864 | 2864 | $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data); |
| 2865 | 2865 | |
@@ -2867,7 +2867,7 @@ discard block |
||
| 2867 | 2867 | $p_header['compression'] = ord($v_data_header['cm']); |
| 2868 | 2868 | //$p_header['mtime'] = $v_data_header['mtime']; |
| 2869 | 2869 | $p_header['crc'] = $v_data_footer['crc']; |
| 2870 | - $p_header['compressed_size'] = filesize($v_gzip_temp_name)-18; |
|
| 2870 | + $p_header['compressed_size'] = filesize($v_gzip_temp_name) - 18; |
|
| 2871 | 2871 | |
| 2872 | 2872 | // ----- Close the file |
| 2873 | 2873 | @fclose($v_file_compressed); |
@@ -2917,7 +2917,7 @@ discard block |
||
| 2917 | 2917 | // -------------------------------------------------------------------------------- |
| 2918 | 2918 | function privCalculateStoredFilename(&$p_filedescr, &$p_options) |
| 2919 | 2919 | { |
| 2920 | - $v_result=1; |
|
| 2920 | + $v_result = 1; |
|
| 2921 | 2921 | |
| 2922 | 2922 | // ----- Working variables |
| 2923 | 2923 | $p_filename = $p_filedescr['filename']; |
@@ -2974,14 +2974,14 @@ discard block |
||
| 2974 | 2974 | if (substr($p_remove_dir, -1) != '/') |
| 2975 | 2975 | $p_remove_dir .= "/"; |
| 2976 | 2976 | |
| 2977 | - if ( (substr($p_filename, 0, 2) == "./") |
|
| 2977 | + if ((substr($p_filename, 0, 2) == "./") |
|
| 2978 | 2978 | || (substr($p_remove_dir, 0, 2) == "./")) { |
| 2979 | 2979 | |
| 2980 | - if ( (substr($p_filename, 0, 2) == "./") |
|
| 2980 | + if ((substr($p_filename, 0, 2) == "./") |
|
| 2981 | 2981 | && (substr($p_remove_dir, 0, 2) != "./")) { |
| 2982 | 2982 | $p_remove_dir = "./".$p_remove_dir; |
| 2983 | 2983 | } |
| 2984 | - if ( (substr($p_filename, 0, 2) != "./") |
|
| 2984 | + if ((substr($p_filename, 0, 2) != "./") |
|
| 2985 | 2985 | && (substr($p_remove_dir, 0, 2) == "./")) { |
| 2986 | 2986 | $p_remove_dir = substr($p_remove_dir, 2); |
| 2987 | 2987 | } |
@@ -3029,15 +3029,15 @@ discard block |
||
| 3029 | 3029 | // -------------------------------------------------------------------------------- |
| 3030 | 3030 | function privWriteFileHeader(&$p_header) |
| 3031 | 3031 | { |
| 3032 | - $v_result=1; |
|
| 3032 | + $v_result = 1; |
|
| 3033 | 3033 | |
| 3034 | 3034 | // ----- Store the offset position of the file |
| 3035 | 3035 | $p_header['offset'] = ftell($this->zip_fd); |
| 3036 | 3036 | |
| 3037 | 3037 | // ----- Transform UNIX mtime to DOS format mdate/mtime |
| 3038 | 3038 | $v_date = getdate($p_header['mtime']); |
| 3039 | - $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2; |
|
| 3040 | - $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday']; |
|
| 3039 | + $v_mtime = ($v_date['hours'] << 11) + ($v_date['minutes'] << 5) + $v_date['seconds'] / 2; |
|
| 3040 | + $v_mdate = (($v_date['year'] - 1980) << 9) + ($v_date['mon'] << 5) + $v_date['mday']; |
|
| 3041 | 3041 | |
| 3042 | 3042 | // ----- Packed data |
| 3043 | 3043 | $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50, |
@@ -3074,7 +3074,7 @@ discard block |
||
| 3074 | 3074 | // -------------------------------------------------------------------------------- |
| 3075 | 3075 | function privWriteCentralFileHeader(&$p_header) |
| 3076 | 3076 | { |
| 3077 | - $v_result=1; |
|
| 3077 | + $v_result = 1; |
|
| 3078 | 3078 | |
| 3079 | 3079 | // TBC |
| 3080 | 3080 | //for(reset($p_header); $key = key($p_header); next($p_header)) { |
@@ -3082,8 +3082,8 @@ discard block |
||
| 3082 | 3082 | |
| 3083 | 3083 | // ----- Transform UNIX mtime to DOS format mdate/mtime |
| 3084 | 3084 | $v_date = getdate($p_header['mtime']); |
| 3085 | - $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2; |
|
| 3086 | - $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday']; |
|
| 3085 | + $v_mtime = ($v_date['hours'] << 11) + ($v_date['minutes'] << 5) + $v_date['seconds'] / 2; |
|
| 3086 | + $v_mdate = (($v_date['year'] - 1980) << 9) + ($v_date['mon'] << 5) + $v_date['mday']; |
|
| 3087 | 3087 | |
| 3088 | 3088 | |
| 3089 | 3089 | // ----- Packed data |
@@ -3127,7 +3127,7 @@ discard block |
||
| 3127 | 3127 | // -------------------------------------------------------------------------------- |
| 3128 | 3128 | function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment) |
| 3129 | 3129 | { |
| 3130 | - $v_result=1; |
|
| 3130 | + $v_result = 1; |
|
| 3131 | 3131 | |
| 3132 | 3132 | // ----- Packed data |
| 3133 | 3133 | $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries, |
@@ -3156,7 +3156,7 @@ discard block |
||
| 3156 | 3156 | // -------------------------------------------------------------------------------- |
| 3157 | 3157 | function privList(&$p_list) |
| 3158 | 3158 | { |
| 3159 | - $v_result=1; |
|
| 3159 | + $v_result = 1; |
|
| 3160 | 3160 | |
| 3161 | 3161 | // ----- Magic quotes trick |
| 3162 | 3162 | $this->privDisableMagicQuotes(); |
@@ -3196,7 +3196,7 @@ discard block |
||
| 3196 | 3196 | } |
| 3197 | 3197 | |
| 3198 | 3198 | // ----- Read each entry |
| 3199 | - for ($i=0; $i<$v_central_dir['entries']; $i++) |
|
| 3199 | + for ($i = 0; $i < $v_central_dir['entries']; $i++) |
|
| 3200 | 3200 | { |
| 3201 | 3201 | // ----- Read the file header |
| 3202 | 3202 | if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1) |
@@ -3243,7 +3243,7 @@ discard block |
||
| 3243 | 3243 | // -------------------------------------------------------------------------------- |
| 3244 | 3244 | function privConvertHeader2FileInfo($p_header, &$p_info) |
| 3245 | 3245 | { |
| 3246 | - $v_result=1; |
|
| 3246 | + $v_result = 1; |
|
| 3247 | 3247 | |
| 3248 | 3248 | // ----- Get the interesting attributes |
| 3249 | 3249 | $v_temp_path = PclZipUtilPathReduction($p_header['filename']); |
@@ -3254,7 +3254,7 @@ discard block |
||
| 3254 | 3254 | $p_info['compressed_size'] = $p_header['compressed_size']; |
| 3255 | 3255 | $p_info['mtime'] = $p_header['mtime']; |
| 3256 | 3256 | $p_info['comment'] = $p_header['comment']; |
| 3257 | - $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010); |
|
| 3257 | + $p_info['folder'] = (($p_header['external'] & 0x00000010) == 0x00000010); |
|
| 3258 | 3258 | $p_info['index'] = $p_header['index']; |
| 3259 | 3259 | $p_info['status'] = $p_header['status']; |
| 3260 | 3260 | $p_info['crc'] = $p_header['crc']; |
@@ -3282,16 +3282,16 @@ discard block |
||
| 3282 | 3282 | // -------------------------------------------------------------------------------- |
| 3283 | 3283 | function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) |
| 3284 | 3284 | { |
| 3285 | - $v_result=1; |
|
| 3285 | + $v_result = 1; |
|
| 3286 | 3286 | |
| 3287 | 3287 | // ----- Magic quotes trick |
| 3288 | 3288 | $this->privDisableMagicQuotes(); |
| 3289 | 3289 | |
| 3290 | 3290 | // ----- Check the path |
| 3291 | - if ( ($p_path == "") |
|
| 3292 | - || ( (substr($p_path, 0, 1) != "/") |
|
| 3291 | + if (($p_path == "") |
|
| 3292 | + || ((substr($p_path, 0, 1) != "/") |
|
| 3293 | 3293 | && (substr($p_path, 0, 3) != "../") |
| 3294 | - && (substr($p_path,1,2)!=":/"))) |
|
| 3294 | + && (substr($p_path, 1, 2) != ":/"))) |
|
| 3295 | 3295 | $p_path = "./".$p_path; |
| 3296 | 3296 | |
| 3297 | 3297 | // ----- Reduce the path last (and duplicated) '/' |
@@ -3300,7 +3300,7 @@ discard block |
||
| 3300 | 3300 | // ----- Look for the path end '/' |
| 3301 | 3301 | while (substr($p_path, -1) == "/") |
| 3302 | 3302 | { |
| 3303 | - $p_path = substr($p_path, 0, strlen($p_path)-1); |
|
| 3303 | + $p_path = substr($p_path, 0, strlen($p_path) - 1); |
|
| 3304 | 3304 | } |
| 3305 | 3305 | } |
| 3306 | 3306 | |
@@ -3334,7 +3334,7 @@ discard block |
||
| 3334 | 3334 | |
| 3335 | 3335 | // ----- Read each entry |
| 3336 | 3336 | $j_start = 0; |
| 3337 | - for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) |
|
| 3337 | + for ($i = 0, $v_nb_extracted = 0; $i < $v_central_dir['entries']; $i++) |
|
| 3338 | 3338 | { |
| 3339 | 3339 | |
| 3340 | 3340 | // ----- Read next Central dir entry |
@@ -3373,17 +3373,17 @@ discard block |
||
| 3373 | 3373 | $v_extract = false; |
| 3374 | 3374 | |
| 3375 | 3375 | // ----- Look for extract by name rule |
| 3376 | - if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) |
|
| 3376 | + if ((isset($p_options[PCLZIP_OPT_BY_NAME])) |
|
| 3377 | 3377 | && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { |
| 3378 | 3378 | |
| 3379 | 3379 | // ----- Look if the filename is in the list |
| 3380 | - for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) { |
|
| 3380 | + for ($j = 0; ($j < sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_extract); $j++) { |
|
| 3381 | 3381 | |
| 3382 | 3382 | // ----- Look for a directory |
| 3383 | 3383 | if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { |
| 3384 | 3384 | |
| 3385 | 3385 | // ----- Look if the directory is in the filename path |
| 3386 | - if ( (strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) |
|
| 3386 | + if ((strlen($v_header['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) |
|
| 3387 | 3387 | && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
| 3388 | 3388 | $v_extract = true; |
| 3389 | 3389 | } |
@@ -3408,7 +3408,7 @@ discard block |
||
| 3408 | 3408 | */ |
| 3409 | 3409 | |
| 3410 | 3410 | // ----- Look for extract by preg rule |
| 3411 | - else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) |
|
| 3411 | + else if ((isset($p_options[PCLZIP_OPT_BY_PREG])) |
|
| 3412 | 3412 | && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { |
| 3413 | 3413 | |
| 3414 | 3414 | if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) { |
@@ -3417,20 +3417,20 @@ discard block |
||
| 3417 | 3417 | } |
| 3418 | 3418 | |
| 3419 | 3419 | // ----- Look for extract by index rule |
| 3420 | - else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) |
|
| 3420 | + else if ((isset($p_options[PCLZIP_OPT_BY_INDEX])) |
|
| 3421 | 3421 | && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { |
| 3422 | 3422 | |
| 3423 | 3423 | // ----- Look if the index is in the list |
| 3424 | - for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) { |
|
| 3424 | + for ($j = $j_start; ($j < sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_extract); $j++) { |
|
| 3425 | 3425 | |
| 3426 | - if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { |
|
| 3426 | + if (($i >= $p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i <= $p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { |
|
| 3427 | 3427 | $v_extract = true; |
| 3428 | 3428 | } |
| 3429 | - if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { |
|
| 3430 | - $j_start = $j+1; |
|
| 3429 | + if ($i >= $p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { |
|
| 3430 | + $j_start = $j + 1; |
|
| 3431 | 3431 | } |
| 3432 | 3432 | |
| 3433 | - if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { |
|
| 3433 | + if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start'] > $i) { |
|
| 3434 | 3434 | break; |
| 3435 | 3435 | } |
| 3436 | 3436 | } |
@@ -3442,14 +3442,14 @@ discard block |
||
| 3442 | 3442 | } |
| 3443 | 3443 | |
| 3444 | 3444 | // ----- Check compression method |
| 3445 | - if ( ($v_extract) |
|
| 3446 | - && ( ($v_header['compression'] != 8) |
|
| 3445 | + if (($v_extract) |
|
| 3446 | + && (($v_header['compression'] != 8) |
|
| 3447 | 3447 | && ($v_header['compression'] != 0))) { |
| 3448 | 3448 | $v_header['status'] = 'unsupported_compression'; |
| 3449 | 3449 | |
| 3450 | 3450 | // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
| 3451 | - if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3452 | - && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3451 | + if ((isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3452 | + && ($p_options[PCLZIP_OPT_STOP_ON_ERROR] === true)) { |
|
| 3453 | 3453 | |
| 3454 | 3454 | $this->privSwapBackMagicQuotes(); |
| 3455 | 3455 | |
@@ -3467,8 +3467,8 @@ discard block |
||
| 3467 | 3467 | $v_header['status'] = 'unsupported_encryption'; |
| 3468 | 3468 | |
| 3469 | 3469 | // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
| 3470 | - if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3471 | - && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3470 | + if ((isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3471 | + && ($p_options[PCLZIP_OPT_STOP_ON_ERROR] === true)) { |
|
| 3472 | 3472 | |
| 3473 | 3473 | $this->privSwapBackMagicQuotes(); |
| 3474 | 3474 | |
@@ -3549,7 +3549,7 @@ discard block |
||
| 3549 | 3549 | } |
| 3550 | 3550 | } |
| 3551 | 3551 | // ----- Look for extraction in standard output |
| 3552 | - elseif ( (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) |
|
| 3552 | + elseif ((isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) |
|
| 3553 | 3553 | && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) { |
| 3554 | 3554 | // ----- Extracting the file in standard output |
| 3555 | 3555 | $v_result1 = $this->privExtractFileInOutput($v_header, $p_options); |
@@ -3622,7 +3622,7 @@ discard block |
||
| 3622 | 3622 | // -------------------------------------------------------------------------------- |
| 3623 | 3623 | function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options) |
| 3624 | 3624 | { |
| 3625 | - $v_result=1; |
|
| 3625 | + $v_result = 1; |
|
| 3626 | 3626 | |
| 3627 | 3627 | // ----- Read the file header |
| 3628 | 3628 | if (($v_result = $this->privReadFileHeader($v_header)) != 1) |
@@ -3640,7 +3640,7 @@ discard block |
||
| 3640 | 3640 | // ----- Look for all path to remove |
| 3641 | 3641 | if ($p_remove_all_path == true) { |
| 3642 | 3642 | // ----- Look for folder entry that not need to be extracted |
| 3643 | - if (($p_entry['external']&0x00000010)==0x00000010) { |
|
| 3643 | + if (($p_entry['external'] & 0x00000010) == 0x00000010) { |
|
| 3644 | 3644 | |
| 3645 | 3645 | $p_entry['status'] = "filtered"; |
| 3646 | 3646 | |
@@ -3742,8 +3742,8 @@ discard block |
||
| 3742 | 3742 | // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
| 3743 | 3743 | // For historical reason first PclZip implementation does not stop |
| 3744 | 3744 | // when this kind of error occurs. |
| 3745 | - if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3746 | - && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3745 | + if ((isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3746 | + && ($p_options[PCLZIP_OPT_STOP_ON_ERROR] === true)) { |
|
| 3747 | 3747 | |
| 3748 | 3748 | PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY, |
| 3749 | 3749 | "Filename '".$p_entry['filename']."' is " |
@@ -3762,8 +3762,8 @@ discard block |
||
| 3762 | 3762 | // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
| 3763 | 3763 | // For historical reason first PclZip implementation does not stop |
| 3764 | 3764 | // when this kind of error occurs. |
| 3765 | - if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3766 | - && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3765 | + if ((isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3766 | + && ($p_options[PCLZIP_OPT_STOP_ON_ERROR] === true)) { |
|
| 3767 | 3767 | |
| 3768 | 3768 | PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, |
| 3769 | 3769 | "Filename '".$p_entry['filename']."' exists " |
@@ -3777,8 +3777,8 @@ discard block |
||
| 3777 | 3777 | else if (filemtime($p_entry['filename']) > $p_entry['mtime']) |
| 3778 | 3778 | { |
| 3779 | 3779 | // ----- Change the file status |
| 3780 | - if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER])) |
|
| 3781 | - && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) { |
|
| 3780 | + if ((isset($p_options[PCLZIP_OPT_REPLACE_NEWER])) |
|
| 3781 | + && ($p_options[PCLZIP_OPT_REPLACE_NEWER] === true)) { |
|
| 3782 | 3782 | } |
| 3783 | 3783 | else { |
| 3784 | 3784 | $p_entry['status'] = "newer_exist"; |
@@ -3786,8 +3786,8 @@ discard block |
||
| 3786 | 3786 | // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
| 3787 | 3787 | // For historical reason first PclZip implementation does not stop |
| 3788 | 3788 | // when this kind of error occurs. |
| 3789 | - if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3790 | - && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) { |
|
| 3789 | + if ((isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) |
|
| 3790 | + && ($p_options[PCLZIP_OPT_STOP_ON_ERROR] === true)) { |
|
| 3791 | 3791 | |
| 3792 | 3792 | PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, |
| 3793 | 3793 | "Newer version of '".$p_entry['filename']."' exists " |
@@ -3803,14 +3803,14 @@ discard block |
||
| 3803 | 3803 | |
| 3804 | 3804 | // ----- Check the directory availability and create it if necessary |
| 3805 | 3805 | else { |
| 3806 | - if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/')) |
|
| 3806 | + if ((($p_entry['external'] & 0x00000010) == 0x00000010) || (substr($p_entry['filename'], -1) == '/')) |
|
| 3807 | 3807 | $v_dir_to_check = $p_entry['filename']; |
| 3808 | 3808 | else if (!strstr($p_entry['filename'], "/")) |
| 3809 | 3809 | $v_dir_to_check = ""; |
| 3810 | 3810 | else |
| 3811 | 3811 | $v_dir_to_check = dirname($p_entry['filename']); |
| 3812 | 3812 | |
| 3813 | - if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) { |
|
| 3813 | + if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external'] & 0x00000010) == 0x00000010))) != 1) { |
|
| 3814 | 3814 | |
| 3815 | 3815 | // ----- Change the file status |
| 3816 | 3816 | $p_entry['status'] = "path_creation_fail"; |
@@ -3826,7 +3826,7 @@ discard block |
||
| 3826 | 3826 | if ($p_entry['status'] == 'ok') { |
| 3827 | 3827 | |
| 3828 | 3828 | // ----- Do the extraction (if not a folder) |
| 3829 | - if (!(($p_entry['external']&0x00000010)==0x00000010)) |
|
| 3829 | + if (!(($p_entry['external'] & 0x00000010) == 0x00000010)) |
|
| 3830 | 3830 | { |
| 3831 | 3831 | // ----- Look for not compressed file |
| 3832 | 3832 | if ($p_entry['compression'] == 0) { |
@@ -3875,10 +3875,10 @@ discard block |
||
| 3875 | 3875 | |
| 3876 | 3876 | |
| 3877 | 3877 | // ----- Look for using temporary file to unzip |
| 3878 | - if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) |
|
| 3878 | + if ((!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) |
|
| 3879 | 3879 | && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON]) |
| 3880 | 3880 | || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]) |
| 3881 | - && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])) ) ) { |
|
| 3881 | + && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])))) { |
|
| 3882 | 3882 | $v_result = $this->privExtractFileUsingTempFile($p_entry, $p_options); |
| 3883 | 3883 | if ($v_result < PCLZIP_ERR_NO_ERROR) { |
| 3884 | 3884 | return $v_result; |
@@ -3973,7 +3973,7 @@ discard block |
||
| 3973 | 3973 | // -------------------------------------------------------------------------------- |
| 3974 | 3974 | function privExtractFileUsingTempFile(&$p_entry, &$p_options) |
| 3975 | 3975 | { |
| 3976 | - $v_result=1; |
|
| 3976 | + $v_result = 1; |
|
| 3977 | 3977 | |
| 3978 | 3978 | // ----- Creates a temporary file |
| 3979 | 3979 | $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz'; |
@@ -4049,7 +4049,7 @@ discard block |
||
| 4049 | 4049 | // -------------------------------------------------------------------------------- |
| 4050 | 4050 | function privExtractFileInOutput(&$p_entry, &$p_options) |
| 4051 | 4051 | { |
| 4052 | - $v_result=1; |
|
| 4052 | + $v_result = 1; |
|
| 4053 | 4053 | |
| 4054 | 4054 | // ----- Read the file header |
| 4055 | 4055 | if (($v_result = $this->privReadFileHeader($v_header)) != 1) { |
@@ -4098,7 +4098,7 @@ discard block |
||
| 4098 | 4098 | if ($p_entry['status'] == 'ok') { |
| 4099 | 4099 | |
| 4100 | 4100 | // ----- Do the extraction (if not a folder) |
| 4101 | - if (!(($p_entry['external']&0x00000010)==0x00000010)) { |
|
| 4101 | + if (!(($p_entry['external'] & 0x00000010) == 0x00000010)) { |
|
| 4102 | 4102 | // ----- Look for not compressed file |
| 4103 | 4103 | if ($p_entry['compressed_size'] == $p_entry['size']) { |
| 4104 | 4104 | |
@@ -4161,7 +4161,7 @@ discard block |
||
| 4161 | 4161 | // -------------------------------------------------------------------------------- |
| 4162 | 4162 | function privExtractFileAsString(&$p_entry, &$p_string, &$p_options) |
| 4163 | 4163 | { |
| 4164 | - $v_result=1; |
|
| 4164 | + $v_result = 1; |
|
| 4165 | 4165 | |
| 4166 | 4166 | // ----- Read the file header |
| 4167 | 4167 | $v_header = array(); |
@@ -4212,7 +4212,7 @@ discard block |
||
| 4212 | 4212 | if ($p_entry['status'] == 'ok') { |
| 4213 | 4213 | |
| 4214 | 4214 | // ----- Do the extraction (if not a folder) |
| 4215 | - if (!(($p_entry['external']&0x00000010)==0x00000010)) { |
|
| 4215 | + if (!(($p_entry['external'] & 0x00000010) == 0x00000010)) { |
|
| 4216 | 4216 | // ----- Look for not compressed file |
| 4217 | 4217 | // if ($p_entry['compressed_size'] == $p_entry['size']) |
| 4218 | 4218 | if ($p_entry['compression'] == 0) { |
@@ -4284,7 +4284,7 @@ discard block |
||
| 4284 | 4284 | // -------------------------------------------------------------------------------- |
| 4285 | 4285 | function privReadFileHeader(&$p_header) |
| 4286 | 4286 | { |
| 4287 | - $v_result=1; |
|
| 4287 | + $v_result = 1; |
|
| 4288 | 4288 | |
| 4289 | 4289 | // ----- Read the 4 bytes signature |
| 4290 | 4290 | $v_binary_data = @fread($this->zip_fd, 4); |
@@ -4348,7 +4348,7 @@ discard block |
||
| 4348 | 4348 | // ----- Extract time |
| 4349 | 4349 | $v_hour = ($p_header['mtime'] & 0xF800) >> 11; |
| 4350 | 4350 | $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; |
| 4351 | - $v_seconde = ($p_header['mtime'] & 0x001F)*2; |
|
| 4351 | + $v_seconde = ($p_header['mtime'] & 0x001F) * 2; |
|
| 4352 | 4352 | |
| 4353 | 4353 | // ----- Extract date |
| 4354 | 4354 | $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; |
@@ -4387,7 +4387,7 @@ discard block |
||
| 4387 | 4387 | // -------------------------------------------------------------------------------- |
| 4388 | 4388 | function privReadCentralFileHeader(&$p_header) |
| 4389 | 4389 | { |
| 4390 | - $v_result=1; |
|
| 4390 | + $v_result = 1; |
|
| 4391 | 4391 | |
| 4392 | 4392 | // ----- Read the 4 bytes signature |
| 4393 | 4393 | $v_binary_data = @fread($this->zip_fd, 4); |
@@ -4451,7 +4451,7 @@ discard block |
||
| 4451 | 4451 | // ----- Extract time |
| 4452 | 4452 | $v_hour = ($p_header['mtime'] & 0xF800) >> 11; |
| 4453 | 4453 | $v_minute = ($p_header['mtime'] & 0x07E0) >> 5; |
| 4454 | - $v_seconde = ($p_header['mtime'] & 0x001F)*2; |
|
| 4454 | + $v_seconde = ($p_header['mtime'] & 0x001F) * 2; |
|
| 4455 | 4455 | |
| 4456 | 4456 | // ----- Extract date |
| 4457 | 4457 | $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980; |
@@ -4495,7 +4495,7 @@ discard block |
||
| 4495 | 4495 | // -------------------------------------------------------------------------------- |
| 4496 | 4496 | function privCheckFileHeaders(&$p_local_header, &$p_central_header) |
| 4497 | 4497 | { |
| 4498 | - $v_result=1; |
|
| 4498 | + $v_result = 1; |
|
| 4499 | 4499 | |
| 4500 | 4500 | // ----- Check the static values |
| 4501 | 4501 | // TBC |
@@ -4532,7 +4532,7 @@ discard block |
||
| 4532 | 4532 | // -------------------------------------------------------------------------------- |
| 4533 | 4533 | function privReadEndCentralDir(&$p_central_dir) |
| 4534 | 4534 | { |
| 4535 | - $v_result=1; |
|
| 4535 | + $v_result = 1; |
|
| 4536 | 4536 | |
| 4537 | 4537 | // ----- Go to the end of the zip file |
| 4538 | 4538 | $v_size = filesize($this->zipname); |
@@ -4550,8 +4550,8 @@ discard block |
||
| 4550 | 4550 | // in this case the end of central dir is at 22 bytes of the file end |
| 4551 | 4551 | $v_found = 0; |
| 4552 | 4552 | if ($v_size > 26) { |
| 4553 | - @fseek($this->zip_fd, $v_size-22); |
|
| 4554 | - if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22)) |
|
| 4553 | + @fseek($this->zip_fd, $v_size - 22); |
|
| 4554 | + if (($v_pos = @ftell($this->zip_fd)) != ($v_size - 22)) |
|
| 4555 | 4555 | { |
| 4556 | 4556 | // ----- Error log |
| 4557 | 4557 | PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); |
@@ -4577,8 +4577,8 @@ discard block |
||
| 4577 | 4577 | $v_maximum_size = 65557; // 0xFFFF + 22; |
| 4578 | 4578 | if ($v_maximum_size > $v_size) |
| 4579 | 4579 | $v_maximum_size = $v_size; |
| 4580 | - @fseek($this->zip_fd, $v_size-$v_maximum_size); |
|
| 4581 | - if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size)) |
|
| 4580 | + @fseek($this->zip_fd, $v_size - $v_maximum_size); |
|
| 4581 | + if (@ftell($this->zip_fd) != ($v_size - $v_maximum_size)) |
|
| 4582 | 4582 | { |
| 4583 | 4583 | // ----- Error log |
| 4584 | 4584 | PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\''); |
@@ -4599,7 +4599,7 @@ discard block |
||
| 4599 | 4599 | //$v_bytes = ($v_bytes << 8) | Ord($v_byte); |
| 4600 | 4600 | // Note we mask the old value down such that once shifted we can never end up with more than a 32bit number |
| 4601 | 4601 | // Otherwise on systems where we have 64bit integers the check below for the magic number will fail. |
| 4602 | - $v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte); |
|
| 4602 | + $v_bytes = (($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte); |
|
| 4603 | 4603 | |
| 4604 | 4604 | // ----- Compare the bytes |
| 4605 | 4605 | if ($v_bytes == 0x504b0506) |
@@ -4689,11 +4689,11 @@ discard block |
||
| 4689 | 4689 | // -------------------------------------------------------------------------------- |
| 4690 | 4690 | function privDeleteByRule(&$p_result_list, &$p_options) |
| 4691 | 4691 | { |
| 4692 | - $v_result=1; |
|
| 4692 | + $v_result = 1; |
|
| 4693 | 4693 | $v_list_detail = array(); |
| 4694 | 4694 | |
| 4695 | 4695 | // ----- Open the zip file |
| 4696 | - if (($v_result=$this->privOpenFd('rb')) != 1) |
|
| 4696 | + if (($v_result = $this->privOpenFd('rb')) != 1) |
|
| 4697 | 4697 | { |
| 4698 | 4698 | // ----- Return |
| 4699 | 4699 | return $v_result; |
@@ -4729,7 +4729,7 @@ discard block |
||
| 4729 | 4729 | // ----- Read each entry |
| 4730 | 4730 | $v_header_list = array(); |
| 4731 | 4731 | $j_start = 0; |
| 4732 | - for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++) |
|
| 4732 | + for ($i = 0, $v_nb_extracted = 0; $i < $v_central_dir['entries']; $i++) |
|
| 4733 | 4733 | { |
| 4734 | 4734 | |
| 4735 | 4735 | // ----- Read the file header |
@@ -4750,21 +4750,21 @@ discard block |
||
| 4750 | 4750 | $v_found = false; |
| 4751 | 4751 | |
| 4752 | 4752 | // ----- Look for extract by name rule |
| 4753 | - if ( (isset($p_options[PCLZIP_OPT_BY_NAME])) |
|
| 4753 | + if ((isset($p_options[PCLZIP_OPT_BY_NAME])) |
|
| 4754 | 4754 | && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) { |
| 4755 | 4755 | |
| 4756 | 4756 | // ----- Look if the filename is in the list |
| 4757 | - for ($j=0; ($j<sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) { |
|
| 4757 | + for ($j = 0; ($j < sizeof($p_options[PCLZIP_OPT_BY_NAME])) && (!$v_found); $j++) { |
|
| 4758 | 4758 | |
| 4759 | 4759 | // ----- Look for a directory |
| 4760 | 4760 | if (substr($p_options[PCLZIP_OPT_BY_NAME][$j], -1) == "/") { |
| 4761 | 4761 | |
| 4762 | 4762 | // ----- Look if the directory is in the filename path |
| 4763 | - if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) |
|
| 4763 | + if ((strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) |
|
| 4764 | 4764 | && (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])) { |
| 4765 | 4765 | $v_found = true; |
| 4766 | 4766 | } |
| 4767 | - elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */ |
|
| 4767 | + elseif ((($v_header_list[$v_nb_extracted]['external'] & 0x00000010) == 0x00000010) /* Indicates a folder */ |
|
| 4768 | 4768 | && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
| 4769 | 4769 | $v_found = true; |
| 4770 | 4770 | } |
@@ -4789,7 +4789,7 @@ discard block |
||
| 4789 | 4789 | */ |
| 4790 | 4790 | |
| 4791 | 4791 | // ----- Look for extract by preg rule |
| 4792 | - else if ( (isset($p_options[PCLZIP_OPT_BY_PREG])) |
|
| 4792 | + else if ((isset($p_options[PCLZIP_OPT_BY_PREG])) |
|
| 4793 | 4793 | && ($p_options[PCLZIP_OPT_BY_PREG] != "")) { |
| 4794 | 4794 | |
| 4795 | 4795 | if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { |
@@ -4798,20 +4798,20 @@ discard block |
||
| 4798 | 4798 | } |
| 4799 | 4799 | |
| 4800 | 4800 | // ----- Look for extract by index rule |
| 4801 | - else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX])) |
|
| 4801 | + else if ((isset($p_options[PCLZIP_OPT_BY_INDEX])) |
|
| 4802 | 4802 | && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) { |
| 4803 | 4803 | |
| 4804 | 4804 | // ----- Look if the index is in the list |
| 4805 | - for ($j=$j_start; ($j<sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) { |
|
| 4805 | + for ($j = $j_start; ($j < sizeof($p_options[PCLZIP_OPT_BY_INDEX])) && (!$v_found); $j++) { |
|
| 4806 | 4806 | |
| 4807 | - if (($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { |
|
| 4807 | + if (($i >= $p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i <= $p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) { |
|
| 4808 | 4808 | $v_found = true; |
| 4809 | 4809 | } |
| 4810 | - if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { |
|
| 4811 | - $j_start = $j+1; |
|
| 4810 | + if ($i >= $p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { |
|
| 4811 | + $j_start = $j + 1; |
|
| 4812 | 4812 | } |
| 4813 | 4813 | |
| 4814 | - if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { |
|
| 4814 | + if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start'] > $i) { |
|
| 4815 | 4815 | break; |
| 4816 | 4816 | } |
| 4817 | 4817 | } |
@@ -4849,11 +4849,11 @@ discard block |
||
| 4849 | 4849 | } |
| 4850 | 4850 | |
| 4851 | 4851 | // ----- Look which file need to be kept |
| 4852 | - for ($i=0; $i<sizeof($v_header_list); $i++) { |
|
| 4852 | + for ($i = 0; $i < sizeof($v_header_list); $i++) { |
|
| 4853 | 4853 | |
| 4854 | 4854 | // ----- Calculate the position of the header |
| 4855 | 4855 | @rewind($this->zip_fd); |
| 4856 | - if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) { |
|
| 4856 | + if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) { |
|
| 4857 | 4857 | // ----- Close the zip file |
| 4858 | 4858 | $this->privCloseFd(); |
| 4859 | 4859 | $v_temp_zip->privCloseFd(); |
@@ -4912,7 +4912,7 @@ discard block |
||
| 4912 | 4912 | $v_offset = @ftell($v_temp_zip->zip_fd); |
| 4913 | 4913 | |
| 4914 | 4914 | // ----- Re-Create the Central Dir files header |
| 4915 | - for ($i=0; $i<sizeof($v_header_list); $i++) { |
|
| 4915 | + for ($i = 0; $i < sizeof($v_header_list); $i++) { |
|
| 4916 | 4916 | // ----- Create the file header |
| 4917 | 4917 | if (($v_result = $v_temp_zip->privWriteCentralFileHeader($v_header_list[$i])) != 1) { |
| 4918 | 4918 | $v_temp_zip->privCloseFd(); |
@@ -4935,7 +4935,7 @@ discard block |
||
| 4935 | 4935 | } |
| 4936 | 4936 | |
| 4937 | 4937 | // ----- Calculate the size of the central header |
| 4938 | - $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset; |
|
| 4938 | + $v_size = @ftell($v_temp_zip->zip_fd) - $v_offset; |
|
| 4939 | 4939 | |
| 4940 | 4940 | // ----- Create the central dir footer |
| 4941 | 4941 | if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) { |
@@ -4997,15 +4997,15 @@ discard block |
||
| 4997 | 4997 | // 1 : OK |
| 4998 | 4998 | // -1 : Unable to create directory |
| 4999 | 4999 | // -------------------------------------------------------------------------------- |
| 5000 | - function privDirCheck($p_dir, $p_is_dir=false) |
|
| 5000 | + function privDirCheck($p_dir, $p_is_dir = false) |
|
| 5001 | 5001 | { |
| 5002 | 5002 | $v_result = 1; |
| 5003 | 5003 | |
| 5004 | 5004 | |
| 5005 | 5005 | // ----- Remove the final '/' |
| 5006 | - if (($p_is_dir) && (substr($p_dir, -1)=='/')) |
|
| 5006 | + if (($p_is_dir) && (substr($p_dir, -1) == '/')) |
|
| 5007 | 5007 | { |
| 5008 | - $p_dir = substr($p_dir, 0, strlen($p_dir)-1); |
|
| 5008 | + $p_dir = substr($p_dir, 0, strlen($p_dir) - 1); |
|
| 5009 | 5009 | } |
| 5010 | 5010 | |
| 5011 | 5011 | // ----- Check the directory availability |
@@ -5054,7 +5054,7 @@ discard block |
||
| 5054 | 5054 | // -------------------------------------------------------------------------------- |
| 5055 | 5055 | function privMerge(&$p_archive_to_add) |
| 5056 | 5056 | { |
| 5057 | - $v_result=1; |
|
| 5057 | + $v_result = 1; |
|
| 5058 | 5058 | |
| 5059 | 5059 | // ----- Look if the archive_to_add exists |
| 5060 | 5060 | if (!is_file($p_archive_to_add->zipname)) |
@@ -5079,7 +5079,7 @@ discard block |
||
| 5079 | 5079 | } |
| 5080 | 5080 | |
| 5081 | 5081 | // ----- Open the zip file |
| 5082 | - if (($v_result=$this->privOpenFd('rb')) != 1) |
|
| 5082 | + if (($v_result = $this->privOpenFd('rb')) != 1) |
|
| 5083 | 5083 | { |
| 5084 | 5084 | // ----- Return |
| 5085 | 5085 | return $v_result; |
@@ -5097,7 +5097,7 @@ discard block |
||
| 5097 | 5097 | @rewind($this->zip_fd); |
| 5098 | 5098 | |
| 5099 | 5099 | // ----- Open the archive_to_add file |
| 5100 | - if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1) |
|
| 5100 | + if (($v_result = $p_archive_to_add->privOpenFd('rb')) != 1) |
|
| 5101 | 5101 | { |
| 5102 | 5102 | $this->privCloseFd(); |
| 5103 | 5103 | |
@@ -5181,7 +5181,7 @@ discard block |
||
| 5181 | 5181 | $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment']; |
| 5182 | 5182 | |
| 5183 | 5183 | // ----- Calculate the size of the (new) central header |
| 5184 | - $v_size = @ftell($v_zip_temp_fd)-$v_offset; |
|
| 5184 | + $v_size = @ftell($v_zip_temp_fd) - $v_offset; |
|
| 5185 | 5185 | |
| 5186 | 5186 | // ----- Swap the file descriptor |
| 5187 | 5187 | // Here is a trick : I swap the temporary fd with the zip fd, in order to use |
@@ -5191,7 +5191,7 @@ discard block |
||
| 5191 | 5191 | $v_zip_temp_fd = $v_swap; |
| 5192 | 5192 | |
| 5193 | 5193 | // ----- Create the central dir footer |
| 5194 | - if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1) |
|
| 5194 | + if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries'] + $v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1) |
|
| 5195 | 5195 | { |
| 5196 | 5196 | $this->privCloseFd(); |
| 5197 | 5197 | $p_archive_to_add->privCloseFd(); |
@@ -5239,7 +5239,7 @@ discard block |
||
| 5239 | 5239 | // -------------------------------------------------------------------------------- |
| 5240 | 5240 | function privDuplicate($p_archive_filename) |
| 5241 | 5241 | { |
| 5242 | - $v_result=1; |
|
| 5242 | + $v_result = 1; |
|
| 5243 | 5243 | |
| 5244 | 5244 | // ----- Look if the $p_archive_filename exists |
| 5245 | 5245 | if (!is_file($p_archive_filename)) |
@@ -5253,7 +5253,7 @@ discard block |
||
| 5253 | 5253 | } |
| 5254 | 5254 | |
| 5255 | 5255 | // ----- Open the zip file |
| 5256 | - if (($v_result=$this->privOpenFd('wb')) != 1) |
|
| 5256 | + if (($v_result = $this->privOpenFd('wb')) != 1) |
|
| 5257 | 5257 | { |
| 5258 | 5258 | // ----- Return |
| 5259 | 5259 | return $v_result; |
@@ -5297,7 +5297,7 @@ discard block |
||
| 5297 | 5297 | // Description : |
| 5298 | 5298 | // Parameters : |
| 5299 | 5299 | // -------------------------------------------------------------------------------- |
| 5300 | - function privErrorLog($p_error_code=0, $p_error_string='') |
|
| 5300 | + function privErrorLog($p_error_code = 0, $p_error_string = '') |
|
| 5301 | 5301 | { |
| 5302 | 5302 | if (PCLZIP_ERROR_EXTERNAL == 1) { |
| 5303 | 5303 | PclError($p_error_code, $p_error_string); |
@@ -5334,10 +5334,10 @@ discard block |
||
| 5334 | 5334 | // -------------------------------------------------------------------------------- |
| 5335 | 5335 | function privDisableMagicQuotes() |
| 5336 | 5336 | { |
| 5337 | - $v_result=1; |
|
| 5337 | + $v_result = 1; |
|
| 5338 | 5338 | |
| 5339 | 5339 | // ----- Look if function exists |
| 5340 | - if ( (!function_exists("get_magic_quotes_runtime")) |
|
| 5340 | + if ((!function_exists("get_magic_quotes_runtime")) |
|
| 5341 | 5341 | || (!function_exists("set_magic_quotes_runtime"))) { |
| 5342 | 5342 | return $v_result; |
| 5343 | 5343 | } |
@@ -5368,10 +5368,10 @@ discard block |
||
| 5368 | 5368 | // -------------------------------------------------------------------------------- |
| 5369 | 5369 | function privSwapBackMagicQuotes() |
| 5370 | 5370 | { |
| 5371 | - $v_result=1; |
|
| 5371 | + $v_result = 1; |
|
| 5372 | 5372 | |
| 5373 | 5373 | // ----- Look if function exists |
| 5374 | - if ( (!function_exists("get_magic_quotes_runtime")) |
|
| 5374 | + if ((!function_exists("get_magic_quotes_runtime")) |
|
| 5375 | 5375 | || (!function_exists("set_magic_quotes_runtime"))) { |
| 5376 | 5376 | return $v_result; |
| 5377 | 5377 | } |
@@ -5412,7 +5412,7 @@ discard block |
||
| 5412 | 5412 | |
| 5413 | 5413 | // ----- Study directories from last to first |
| 5414 | 5414 | $v_skip = 0; |
| 5415 | - for ($i=sizeof($v_list)-1; $i>=0; $i--) { |
|
| 5415 | + for ($i = sizeof($v_list) - 1; $i >= 0; $i--) { |
|
| 5416 | 5416 | // ----- Look for current path |
| 5417 | 5417 | if ($v_list[$i] == ".") { |
| 5418 | 5418 | // ----- Ignore this directory |
@@ -5433,7 +5433,7 @@ discard block |
||
| 5433 | 5433 | } |
| 5434 | 5434 | } |
| 5435 | 5435 | // ----- Last '/' i.e. indicates a directory |
| 5436 | - else if ($i == (sizeof($v_list)-1)) { |
|
| 5436 | + else if ($i == (sizeof($v_list) - 1)) { |
|
| 5437 | 5437 | $v_result = $v_list[$i]; |
| 5438 | 5438 | } |
| 5439 | 5439 | // ----- Double '/' inside the path |
@@ -5448,7 +5448,7 @@ discard block |
||
| 5448 | 5448 | $v_skip--; |
| 5449 | 5449 | } |
| 5450 | 5450 | else { |
| 5451 | - $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:""); |
|
| 5451 | + $v_result = $v_list[$i].($i != (sizeof($v_list) - 1) ? "/".$v_result : ""); |
|
| 5452 | 5452 | } |
| 5453 | 5453 | } |
| 5454 | 5454 | } |
@@ -5487,12 +5487,12 @@ discard block |
||
| 5487 | 5487 | $v_result = 1; |
| 5488 | 5488 | |
| 5489 | 5489 | // ----- Look for path beginning by ./ |
| 5490 | - if ( ($p_dir == '.') |
|
| 5491 | - || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) { |
|
| 5490 | + if (($p_dir == '.') |
|
| 5491 | + || ((strlen($p_dir) >= 2) && (substr($p_dir, 0, 2) == './'))) { |
|
| 5492 | 5492 | $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1); |
| 5493 | 5493 | } |
| 5494 | - if ( ($p_path == '.') |
|
| 5495 | - || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) { |
|
| 5494 | + if (($p_path == '.') |
|
| 5495 | + || ((strlen($p_path) >= 2) && (substr($p_path, 0, 2) == './'))) { |
|
| 5496 | 5496 | $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1); |
| 5497 | 5497 | } |
| 5498 | 5498 | |
@@ -5518,7 +5518,7 @@ discard block |
||
| 5518 | 5518 | } |
| 5519 | 5519 | |
| 5520 | 5520 | // ----- Compare the items |
| 5521 | - if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != '')) { |
|
| 5521 | + if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ($v_list_path[$j] != '')) { |
|
| 5522 | 5522 | $v_result = 0; |
| 5523 | 5523 | } |
| 5524 | 5524 | |
@@ -5559,11 +5559,11 @@ discard block |
||
| 5559 | 5559 | // 3 : src & dest gzip |
| 5560 | 5560 | // Return Values : |
| 5561 | 5561 | // -------------------------------------------------------------------------------- |
| 5562 | - function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0) |
|
| 5562 | + function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode = 0) |
|
| 5563 | 5563 | { |
| 5564 | 5564 | $v_result = 1; |
| 5565 | 5565 | |
| 5566 | - if ($p_mode==0) |
|
| 5566 | + if ($p_mode == 0) |
|
| 5567 | 5567 | { |
| 5568 | 5568 | while ($p_size != 0) |
| 5569 | 5569 | { |
@@ -5573,7 +5573,7 @@ discard block |
||
| 5573 | 5573 | $p_size -= $v_read_size; |
| 5574 | 5574 | } |
| 5575 | 5575 | } |
| 5576 | - else if ($p_mode==1) |
|
| 5576 | + else if ($p_mode == 1) |
|
| 5577 | 5577 | { |
| 5578 | 5578 | while ($p_size != 0) |
| 5579 | 5579 | { |
@@ -5583,7 +5583,7 @@ discard block |
||
| 5583 | 5583 | $p_size -= $v_read_size; |
| 5584 | 5584 | } |
| 5585 | 5585 | } |
| 5586 | - else if ($p_mode==2) |
|
| 5586 | + else if ($p_mode == 2) |
|
| 5587 | 5587 | { |
| 5588 | 5588 | while ($p_size != 0) |
| 5589 | 5589 | { |
@@ -5593,7 +5593,7 @@ discard block |
||
| 5593 | 5593 | $p_size -= $v_read_size; |
| 5594 | 5594 | } |
| 5595 | 5595 | } |
| 5596 | - else if ($p_mode==3) |
|
| 5596 | + else if ($p_mode == 3) |
|
| 5597 | 5597 | { |
| 5598 | 5598 | while ($p_size != 0) |
| 5599 | 5599 | { |
@@ -5657,7 +5657,7 @@ discard block |
||
| 5657 | 5657 | $v_list = get_defined_constants(); |
| 5658 | 5658 | for (reset($v_list); $v_key = key($v_list); next($v_list)) { |
| 5659 | 5659 | $v_prefix = substr($v_key, 0, 10); |
| 5660 | - if (( ($v_prefix == 'PCLZIP_OPT') |
|
| 5660 | + if ((($v_prefix == 'PCLZIP_OPT') |
|
| 5661 | 5661 | || ($v_prefix == 'PCLZIP_CB_') |
| 5662 | 5662 | || ($v_prefix == 'PCLZIP_ATT')) |
| 5663 | 5663 | && ($v_list[$v_key] == $p_option)) { |
@@ -5682,15 +5682,15 @@ discard block |
||
| 5682 | 5682 | // Return Values : |
| 5683 | 5683 | // The path translated. |
| 5684 | 5684 | // -------------------------------------------------------------------------------- |
| 5685 | - function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true) |
|
| 5685 | + function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter = true) |
|
| 5686 | 5686 | { |
| 5687 | 5687 | if (stristr(php_uname(), 'windows')) { |
| 5688 | 5688 | // ----- Look for potential disk letter |
| 5689 | 5689 | if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) { |
| 5690 | - $p_path = substr($p_path, $v_position+1); |
|
| 5690 | + $p_path = substr($p_path, $v_position + 1); |
|
| 5691 | 5691 | } |
| 5692 | 5692 | // ----- Change potential windows directory separator |
| 5693 | - if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) { |
|
| 5693 | + if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0, 1) == '\\')) { |
|
| 5694 | 5694 | $p_path = strtr($p_path, '\\', '/'); |
| 5695 | 5695 | } |
| 5696 | 5696 | } |
@@ -332,8 +332,7 @@ discard block |
||
| 332 | 332 | // ----- Look for the optional second argument |
| 333 | 333 | if ($v_size == 2) { |
| 334 | 334 | $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; |
| 335 | - } |
|
| 336 | - else if ($v_size > 2) { |
|
| 335 | + } else if ($v_size > 2) { |
|
| 337 | 336 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, |
| 338 | 337 | "Invalid number / type of arguments"); |
| 339 | 338 | return 0; |
@@ -382,8 +381,7 @@ discard block |
||
| 382 | 381 | foreach ($v_string_list as $v_string) { |
| 383 | 382 | if ($v_string != '') { |
| 384 | 383 | $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string; |
| 385 | - } |
|
| 386 | - else { |
|
| 384 | + } else { |
|
| 387 | 385 | } |
| 388 | 386 | } |
| 389 | 387 | } |
@@ -517,8 +515,7 @@ discard block |
||
| 517 | 515 | // ----- Look for the optional second argument |
| 518 | 516 | if ($v_size == 2) { |
| 519 | 517 | $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1]; |
| 520 | - } |
|
| 521 | - else if ($v_size > 2) { |
|
| 518 | + } else if ($v_size > 2) { |
|
| 522 | 519 | // ----- Error log |
| 523 | 520 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); |
| 524 | 521 | |
@@ -794,8 +791,7 @@ discard block |
||
| 794 | 791 | // ----- Look for the optional second argument |
| 795 | 792 | if ($v_size == 2) { |
| 796 | 793 | $v_remove_path = $v_arg_list[1]; |
| 797 | - } |
|
| 798 | - else if ($v_size > 2) { |
|
| 794 | + } else if ($v_size > 2) { |
|
| 799 | 795 | // ----- Error log |
| 800 | 796 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); |
| 801 | 797 | |
@@ -939,8 +935,7 @@ discard block |
||
| 939 | 935 | } |
| 940 | 936 | if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) { |
| 941 | 937 | $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE; |
| 942 | - } |
|
| 943 | - else { |
|
| 938 | + } else { |
|
| 944 | 939 | } |
| 945 | 940 | } |
| 946 | 941 | |
@@ -955,8 +950,7 @@ discard block |
||
| 955 | 950 | // ----- Look for the optional second argument |
| 956 | 951 | if ($v_size == 2) { |
| 957 | 952 | $v_remove_path = $v_arg_list[1]; |
| 958 | - } |
|
| 959 | - else if ($v_size > 2) { |
|
| 953 | + } else if ($v_size > 2) { |
|
| 960 | 954 | // ----- Error log |
| 961 | 955 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments"); |
| 962 | 956 | |
@@ -1192,8 +1186,7 @@ discard block |
||
| 1192 | 1186 | // ----- Error log |
| 1193 | 1187 | PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'"); |
| 1194 | 1188 | $v_result = PCLZIP_ERR_MISSING_FILE; |
| 1195 | - } |
|
| 1196 | - else { |
|
| 1189 | + } else { |
|
| 1197 | 1190 | // ----- Duplicate the archive |
| 1198 | 1191 | $v_result = $this->privDuplicate($p_archive); |
| 1199 | 1192 | } |
@@ -1281,8 +1274,7 @@ discard block |
||
| 1281 | 1274 | { |
| 1282 | 1275 | if (PCLZIP_ERROR_EXTERNAL == 1) { |
| 1283 | 1276 | return(PclErrorCode()); |
| 1284 | - } |
|
| 1285 | - else { |
|
| 1277 | + } else { |
|
| 1286 | 1278 | return($this->error_code); |
| 1287 | 1279 | } |
| 1288 | 1280 | } |
@@ -1320,15 +1312,13 @@ discard block |
||
| 1320 | 1312 | |
| 1321 | 1313 | if (isset($v_name[$this->error_code])) { |
| 1322 | 1314 | $v_value = $v_name[$this->error_code]; |
| 1323 | - } |
|
| 1324 | - else { |
|
| 1315 | + } else { |
|
| 1325 | 1316 | $v_value = 'NoName'; |
| 1326 | 1317 | } |
| 1327 | 1318 | |
| 1328 | 1319 | if ($p_with_code) { |
| 1329 | 1320 | return($v_value.' ('.$this->error_code.')'); |
| 1330 | - } |
|
| 1331 | - else { |
|
| 1321 | + } else { |
|
| 1332 | 1322 | return($v_value); |
| 1333 | 1323 | } |
| 1334 | 1324 | } |
@@ -1343,12 +1333,10 @@ discard block |
||
| 1343 | 1333 | { |
| 1344 | 1334 | if (PCLZIP_ERROR_EXTERNAL == 1) { |
| 1345 | 1335 | return(PclErrorString()); |
| 1346 | - } |
|
| 1347 | - else { |
|
| 1336 | + } else { |
|
| 1348 | 1337 | if ($p_full) { |
| 1349 | 1338 | return($this->errorName(true)." : ".$this->error_string); |
| 1350 | - } |
|
| 1351 | - else { |
|
| 1339 | + } else { |
|
| 1352 | 1340 | return($this->error_string." [code ".$this->error_code."]"); |
| 1353 | 1341 | } |
| 1354 | 1342 | } |
@@ -1533,8 +1521,7 @@ discard block |
||
| 1533 | 1521 | && ($p_options_list[$i+1] != '')) { |
| 1534 | 1522 | $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE); |
| 1535 | 1523 | $i++; |
| 1536 | - } |
|
| 1537 | - else { |
|
| 1524 | + } else { |
|
| 1538 | 1525 | } |
| 1539 | 1526 | break; |
| 1540 | 1527 | |
@@ -1552,11 +1539,9 @@ discard block |
||
| 1552 | 1539 | // ----- Get the value |
| 1553 | 1540 | if (is_string($p_options_list[$i+1])) { |
| 1554 | 1541 | $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1]; |
| 1555 | - } |
|
| 1556 | - else if (is_array($p_options_list[$i+1])) { |
|
| 1542 | + } else if (is_array($p_options_list[$i+1])) { |
|
| 1557 | 1543 | $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
| 1558 | - } |
|
| 1559 | - else { |
|
| 1544 | + } else { |
|
| 1560 | 1545 | // ----- Error log |
| 1561 | 1546 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
| 1562 | 1547 | |
@@ -1585,8 +1570,7 @@ discard block |
||
| 1585 | 1570 | // ----- Get the value |
| 1586 | 1571 | if (is_string($p_options_list[$i+1])) { |
| 1587 | 1572 | $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
| 1588 | - } |
|
| 1589 | - else { |
|
| 1573 | + } else { |
|
| 1590 | 1574 | // ----- Error log |
| 1591 | 1575 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
| 1592 | 1576 | |
@@ -1615,8 +1599,7 @@ discard block |
||
| 1615 | 1599 | // ----- Get the value |
| 1616 | 1600 | if (is_string($p_options_list[$i+1])) { |
| 1617 | 1601 | $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1]; |
| 1618 | - } |
|
| 1619 | - else { |
|
| 1602 | + } else { |
|
| 1620 | 1603 | // ----- Error log |
| 1621 | 1604 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, |
| 1622 | 1605 | "Wrong parameter value for option '" |
@@ -1649,14 +1632,11 @@ discard block |
||
| 1649 | 1632 | |
| 1650 | 1633 | // ----- Parse items |
| 1651 | 1634 | $v_work_list = explode(",", $p_options_list[$i+1]); |
| 1652 | - } |
|
| 1653 | - else if (is_integer($p_options_list[$i+1])) { |
|
| 1635 | + } else if (is_integer($p_options_list[$i+1])) { |
|
| 1654 | 1636 | $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1]; |
| 1655 | - } |
|
| 1656 | - else if (is_array($p_options_list[$i+1])) { |
|
| 1637 | + } else if (is_array($p_options_list[$i+1])) { |
|
| 1657 | 1638 | $v_work_list = $p_options_list[$i+1]; |
| 1658 | - } |
|
| 1659 | - else { |
|
| 1639 | + } else { |
|
| 1660 | 1640 | // ----- Error log |
| 1661 | 1641 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
| 1662 | 1642 | |
@@ -1683,13 +1663,11 @@ discard block |
||
| 1683 | 1663 | // ----- Set the option value |
| 1684 | 1664 | $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; |
| 1685 | 1665 | $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[0]; |
| 1686 | - } |
|
| 1687 | - elseif ($v_size_item_list == 2) { |
|
| 1666 | + } elseif ($v_size_item_list == 2) { |
|
| 1688 | 1667 | // ----- Set the option value |
| 1689 | 1668 | $v_result_list[$p_options_list[$i]][$j]['start'] = $v_item_list[0]; |
| 1690 | 1669 | $v_result_list[$p_options_list[$i]][$j]['end'] = $v_item_list[1]; |
| 1691 | - } |
|
| 1692 | - else { |
|
| 1670 | + } else { |
|
| 1693 | 1671 | // ----- Error log |
| 1694 | 1672 | PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Too many values in index range for option '".PclZipUtilOptionText($p_options_list[$i])."'"); |
| 1695 | 1673 | |
@@ -1845,14 +1823,17 @@ discard block |
||
| 1845 | 1823 | $v_memory_limit = trim($v_memory_limit); |
| 1846 | 1824 | $last = strtolower(substr($v_memory_limit, -1)); |
| 1847 | 1825 | |
| 1848 | - if($last == 'g') |
|
| 1849 | - //$v_memory_limit = $v_memory_limit*1024*1024*1024; |
|
| 1826 | + if($last == 'g') { |
|
| 1827 | + //$v_memory_limit = $v_memory_limit*1024*1024*1024; |
|
| 1850 | 1828 | $v_memory_limit = $v_memory_limit*1073741824; |
| 1851 | - if($last == 'm') |
|
| 1852 | - //$v_memory_limit = $v_memory_limit*1024*1024; |
|
| 1829 | + } |
|
| 1830 | + if($last == 'm') { |
|
| 1831 | + //$v_memory_limit = $v_memory_limit*1024*1024; |
|
| 1853 | 1832 | $v_memory_limit = $v_memory_limit*1048576; |
| 1854 | - if($last == 'k') |
|
| 1855 | - $v_memory_limit = $v_memory_limit*1024; |
|
| 1833 | + } |
|
| 1834 | + if($last == 'k') { |
|
| 1835 | + $v_memory_limit = $v_memory_limit*1024; |
|
| 1836 | + } |
|
| 1856 | 1837 | |
| 1857 | 1838 | $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*PCLZIP_TEMPORARY_FILE_RATIO); |
| 1858 | 1839 | |
@@ -2025,15 +2006,12 @@ discard block |
||
| 2025 | 2006 | if (file_exists($v_descr['filename'])) { |
| 2026 | 2007 | if (@is_file($v_descr['filename'])) { |
| 2027 | 2008 | $v_descr['type'] = 'file'; |
| 2028 | - } |
|
| 2029 | - else if (@is_dir($v_descr['filename'])) { |
|
| 2009 | + } else if (@is_dir($v_descr['filename'])) { |
|
| 2030 | 2010 | $v_descr['type'] = 'folder'; |
| 2031 | - } |
|
| 2032 | - else if (@is_link($v_descr['filename'])) { |
|
| 2011 | + } else if (@is_link($v_descr['filename'])) { |
|
| 2033 | 2012 | // skip |
| 2034 | 2013 | continue; |
| 2035 | - } |
|
| 2036 | - else { |
|
| 2014 | + } else { |
|
| 2037 | 2015 | // skip |
| 2038 | 2016 | continue; |
| 2039 | 2017 | } |
@@ -2082,8 +2060,7 @@ discard block |
||
| 2082 | 2060 | && (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) { |
| 2083 | 2061 | if ($v_descr['stored_filename'] != '') { |
| 2084 | 2062 | $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler; |
| 2085 | - } |
|
| 2086 | - else { |
|
| 2063 | + } else { |
|
| 2087 | 2064 | $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler; |
| 2088 | 2065 | } |
| 2089 | 2066 | } |
@@ -2092,8 +2069,7 @@ discard block |
||
| 2092 | 2069 | } |
| 2093 | 2070 | |
| 2094 | 2071 | @closedir($v_folder_handler); |
| 2095 | - } |
|
| 2096 | - else { |
|
| 2072 | + } else { |
|
| 2097 | 2073 | // TBC : unable to open folder in read mode |
| 2098 | 2074 | } |
| 2099 | 2075 | |
@@ -2106,8 +2082,7 @@ discard block |
||
| 2106 | 2082 | |
| 2107 | 2083 | // ----- Concat the resulting list |
| 2108 | 2084 | $v_result_list = array_merge($v_result_list, $v_dirlist_descr); |
| 2109 | - } |
|
| 2110 | - else { |
|
| 2085 | + } else { |
|
| 2111 | 2086 | } |
| 2112 | 2087 | |
| 2113 | 2088 | // ----- Free local array |
@@ -2381,8 +2356,9 @@ discard block |
||
| 2381 | 2356 | { |
| 2382 | 2357 | $v_result=1; |
| 2383 | 2358 | |
| 2384 | - if ($this->zip_fd != 0) |
|
| 2385 | - @fclose($this->zip_fd); |
|
| 2359 | + if ($this->zip_fd != 0) { |
|
| 2360 | + @fclose($this->zip_fd); |
|
| 2361 | + } |
|
| 2386 | 2362 | $this->zip_fd = 0; |
| 2387 | 2363 | |
| 2388 | 2364 | // ----- Return |
@@ -2599,11 +2575,9 @@ discard block |
||
| 2599 | 2575 | // ----- Look for filetime |
| 2600 | 2576 | if (isset($p_filedescr['mtime'])) { |
| 2601 | 2577 | $p_header['mtime'] = $p_filedescr['mtime']; |
| 2602 | - } |
|
| 2603 | - else if ($p_filedescr['type'] == 'virtual_file') { |
|
| 2578 | + } else if ($p_filedescr['type'] == 'virtual_file') { |
|
| 2604 | 2579 | $p_header['mtime'] = time(); |
| 2605 | - } |
|
| 2606 | - else { |
|
| 2580 | + } else { |
|
| 2607 | 2581 | $p_header['mtime'] = filemtime($p_filename); |
| 2608 | 2582 | } |
| 2609 | 2583 | |
@@ -2611,8 +2585,7 @@ discard block |
||
| 2611 | 2585 | if (isset($p_filedescr['comment'])) { |
| 2612 | 2586 | $p_header['comment_len'] = strlen($p_filedescr['comment']); |
| 2613 | 2587 | $p_header['comment'] = $p_filedescr['comment']; |
| 2614 | - } |
|
| 2615 | - else { |
|
| 2588 | + } else { |
|
| 2616 | 2589 | $p_header['comment_len'] = 0; |
| 2617 | 2590 | $p_header['comment'] = ''; |
| 2618 | 2591 | } |
@@ -2923,20 +2896,17 @@ discard block |
||
| 2923 | 2896 | $p_filename = $p_filedescr['filename']; |
| 2924 | 2897 | if (isset($p_options[PCLZIP_OPT_ADD_PATH])) { |
| 2925 | 2898 | $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH]; |
| 2926 | - } |
|
| 2927 | - else { |
|
| 2899 | + } else { |
|
| 2928 | 2900 | $p_add_dir = ''; |
| 2929 | 2901 | } |
| 2930 | 2902 | if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) { |
| 2931 | 2903 | $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH]; |
| 2932 | - } |
|
| 2933 | - else { |
|
| 2904 | + } else { |
|
| 2934 | 2905 | $p_remove_dir = ''; |
| 2935 | 2906 | } |
| 2936 | 2907 | if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
| 2937 | 2908 | $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH]; |
| 2938 | - } |
|
| 2939 | - else { |
|
| 2909 | + } else { |
|
| 2940 | 2910 | $p_remove_all_dir = 0; |
| 2941 | 2911 | } |
| 2942 | 2912 | |
@@ -2959,8 +2929,7 @@ discard block |
||
| 2959 | 2929 | $v_dir = $v_path_info['dirname'].'/'; |
| 2960 | 2930 | } |
| 2961 | 2931 | $v_stored_filename = $v_dir.$p_filedescr['new_short_name']; |
| 2962 | - } |
|
| 2963 | - else { |
|
| 2932 | + } else { |
|
| 2964 | 2933 | // ----- Calculate the stored filename |
| 2965 | 2934 | $v_stored_filename = $p_filename; |
| 2966 | 2935 | } |
@@ -2971,8 +2940,9 @@ discard block |
||
| 2971 | 2940 | } |
| 2972 | 2941 | // ----- Look for partial path remove |
| 2973 | 2942 | else if ($p_remove_dir != "") { |
| 2974 | - if (substr($p_remove_dir, -1) != '/') |
|
| 2975 | - $p_remove_dir .= "/"; |
|
| 2943 | + if (substr($p_remove_dir, -1) != '/') { |
|
| 2944 | + $p_remove_dir .= "/"; |
|
| 2945 | + } |
|
| 2976 | 2946 | |
| 2977 | 2947 | if ( (substr($p_filename, 0, 2) == "./") |
| 2978 | 2948 | || (substr($p_remove_dir, 0, 2) == "./")) { |
@@ -2992,8 +2962,7 @@ discard block |
||
| 2992 | 2962 | if ($v_compare > 0) { |
| 2993 | 2963 | if ($v_compare == 2) { |
| 2994 | 2964 | $v_stored_filename = ""; |
| 2995 | - } |
|
| 2996 | - else { |
|
| 2965 | + } else { |
|
| 2997 | 2966 | $v_stored_filename = substr($v_stored_filename, |
| 2998 | 2967 | strlen($p_remove_dir)); |
| 2999 | 2968 | } |
@@ -3005,10 +2974,11 @@ discard block |
||
| 3005 | 2974 | |
| 3006 | 2975 | // ----- Look for path to add |
| 3007 | 2976 | if ($p_add_dir != "") { |
| 3008 | - if (substr($p_add_dir, -1) == "/") |
|
| 3009 | - $v_stored_filename = $p_add_dir.$v_stored_filename; |
|
| 3010 | - else |
|
| 3011 | - $v_stored_filename = $p_add_dir."/".$v_stored_filename; |
|
| 2977 | + if (substr($p_add_dir, -1) == "/") { |
|
| 2978 | + $v_stored_filename = $p_add_dir.$v_stored_filename; |
|
| 2979 | + } else { |
|
| 2980 | + $v_stored_filename = $p_add_dir."/".$v_stored_filename; |
|
| 2981 | + } |
|
| 3012 | 2982 | } |
| 3013 | 2983 | } |
| 3014 | 2984 | |
@@ -3291,8 +3261,9 @@ discard block |
||
| 3291 | 3261 | if ( ($p_path == "") |
| 3292 | 3262 | || ( (substr($p_path, 0, 1) != "/") |
| 3293 | 3263 | && (substr($p_path, 0, 3) != "../") |
| 3294 | - && (substr($p_path,1,2)!=":/"))) |
|
| 3295 | - $p_path = "./".$p_path; |
|
| 3264 | + && (substr($p_path,1,2)!=":/"))) { |
|
| 3265 | + $p_path = "./".$p_path; |
|
| 3266 | + } |
|
| 3296 | 3267 | |
| 3297 | 3268 | // ----- Reduce the path last (and duplicated) '/' |
| 3298 | 3269 | if (($p_path != "./") && ($p_path != "/")) |
@@ -3779,8 +3750,7 @@ discard block |
||
| 3779 | 3750 | // ----- Change the file status |
| 3780 | 3751 | if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER])) |
| 3781 | 3752 | && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) { |
| 3782 | - } |
|
| 3783 | - else { |
|
| 3753 | + } else { |
|
| 3784 | 3754 | $p_entry['status'] = "newer_exist"; |
| 3785 | 3755 | |
| 3786 | 3756 | // ----- Look for PCLZIP_OPT_STOP_ON_ERROR |
@@ -3796,19 +3766,19 @@ discard block |
||
| 3796 | 3766 | return PclZip::errorCode(); |
| 3797 | 3767 | } |
| 3798 | 3768 | } |
| 3799 | - } |
|
| 3800 | - else { |
|
| 3769 | + } else { |
|
| 3801 | 3770 | } |
| 3802 | 3771 | } |
| 3803 | 3772 | |
| 3804 | 3773 | // ----- Check the directory availability and create it if necessary |
| 3805 | 3774 | else { |
| 3806 | - if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/')) |
|
| 3807 | - $v_dir_to_check = $p_entry['filename']; |
|
| 3808 | - else if (!strstr($p_entry['filename'], "/")) |
|
| 3809 | - $v_dir_to_check = ""; |
|
| 3810 | - else |
|
| 3811 | - $v_dir_to_check = dirname($p_entry['filename']); |
|
| 3775 | + if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/')) { |
|
| 3776 | + $v_dir_to_check = $p_entry['filename']; |
|
| 3777 | + } else if (!strstr($p_entry['filename'], "/")) { |
|
| 3778 | + $v_dir_to_check = ""; |
|
| 3779 | + } else { |
|
| 3780 | + $v_dir_to_check = dirname($p_entry['filename']); |
|
| 3781 | + } |
|
| 3812 | 3782 | |
| 3813 | 3783 | if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) { |
| 3814 | 3784 | |
@@ -3864,8 +3834,7 @@ discard block |
||
| 3864 | 3834 | touch($p_entry['filename'], $p_entry['mtime']); |
| 3865 | 3835 | |
| 3866 | 3836 | |
| 3867 | - } |
|
| 3868 | - else { |
|
| 3837 | + } else { |
|
| 3869 | 3838 | // ----- TBC |
| 3870 | 3839 | // Need to be finished |
| 3871 | 3840 | if (($p_entry['flag'] & 1) == 1) { |
@@ -4108,8 +4077,7 @@ discard block |
||
| 4108 | 4077 | // ----- Send the file to the output |
| 4109 | 4078 | echo $v_buffer; |
| 4110 | 4079 | unset($v_buffer); |
| 4111 | - } |
|
| 4112 | - else { |
|
| 4080 | + } else { |
|
| 4113 | 4081 | |
| 4114 | 4082 | // ----- Read the compressed file in a buffer (one shot) |
| 4115 | 4083 | $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); |
@@ -4219,8 +4187,7 @@ discard block |
||
| 4219 | 4187 | |
| 4220 | 4188 | // ----- Reading the file |
| 4221 | 4189 | $p_string = @fread($this->zip_fd, $p_entry['compressed_size']); |
| 4222 | - } |
|
| 4223 | - else { |
|
| 4190 | + } else { |
|
| 4224 | 4191 | |
| 4225 | 4192 | // ----- Reading the file |
| 4226 | 4193 | $v_data = @fread($this->zip_fd, $p_entry['compressed_size']); |
@@ -4232,8 +4199,7 @@ discard block |
||
| 4232 | 4199 | } |
| 4233 | 4200 | |
| 4234 | 4201 | // ----- Trace |
| 4235 | - } |
|
| 4236 | - else { |
|
| 4202 | + } else { |
|
| 4237 | 4203 | // TBC : error : can not extract a folder in a string |
| 4238 | 4204 | } |
| 4239 | 4205 | |
@@ -4326,8 +4292,7 @@ discard block |
||
| 4326 | 4292 | // ----- Get extra_fields |
| 4327 | 4293 | if ($v_data['extra_len'] != 0) { |
| 4328 | 4294 | $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']); |
| 4329 | - } |
|
| 4330 | - else { |
|
| 4295 | + } else { |
|
| 4331 | 4296 | $p_header['extra'] = ''; |
| 4332 | 4297 | } |
| 4333 | 4298 | |
@@ -4358,8 +4323,7 @@ discard block |
||
| 4358 | 4323 | // ----- Get UNIX date format |
| 4359 | 4324 | $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); |
| 4360 | 4325 | |
| 4361 | - } |
|
| 4362 | - else |
|
| 4326 | + } else |
|
| 4363 | 4327 | { |
| 4364 | 4328 | $p_header['mtime'] = time(); |
| 4365 | 4329 | } |
@@ -4424,22 +4388,25 @@ discard block |
||
| 4424 | 4388 | $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); |
| 4425 | 4389 | |
| 4426 | 4390 | // ----- Get filename |
| 4427 | - if ($p_header['filename_len'] != 0) |
|
| 4428 | - $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']); |
|
| 4429 | - else |
|
| 4430 | - $p_header['filename'] = ''; |
|
| 4391 | + if ($p_header['filename_len'] != 0) { |
|
| 4392 | + $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']); |
|
| 4393 | + } else { |
|
| 4394 | + $p_header['filename'] = ''; |
|
| 4395 | + } |
|
| 4431 | 4396 | |
| 4432 | 4397 | // ----- Get extra |
| 4433 | - if ($p_header['extra_len'] != 0) |
|
| 4434 | - $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']); |
|
| 4435 | - else |
|
| 4436 | - $p_header['extra'] = ''; |
|
| 4398 | + if ($p_header['extra_len'] != 0) { |
|
| 4399 | + $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']); |
|
| 4400 | + } else { |
|
| 4401 | + $p_header['extra'] = ''; |
|
| 4402 | + } |
|
| 4437 | 4403 | |
| 4438 | 4404 | // ----- Get comment |
| 4439 | - if ($p_header['comment_len'] != 0) |
|
| 4440 | - $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']); |
|
| 4441 | - else |
|
| 4442 | - $p_header['comment'] = ''; |
|
| 4405 | + if ($p_header['comment_len'] != 0) { |
|
| 4406 | + $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']); |
|
| 4407 | + } else { |
|
| 4408 | + $p_header['comment'] = ''; |
|
| 4409 | + } |
|
| 4443 | 4410 | |
| 4444 | 4411 | // ----- Extract properties |
| 4445 | 4412 | |
@@ -4461,8 +4428,7 @@ discard block |
||
| 4461 | 4428 | // ----- Get UNIX date format |
| 4462 | 4429 | $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year); |
| 4463 | 4430 | |
| 4464 | - } |
|
| 4465 | - else |
|
| 4431 | + } else |
|
| 4466 | 4432 | { |
| 4467 | 4433 | $p_header['mtime'] = time(); |
| 4468 | 4434 | } |
@@ -4575,8 +4541,9 @@ discard block |
||
| 4575 | 4541 | // ----- Go back to the maximum possible size of the Central Dir End Record |
| 4576 | 4542 | if (!$v_found) { |
| 4577 | 4543 | $v_maximum_size = 65557; // 0xFFFF + 22; |
| 4578 | - if ($v_maximum_size > $v_size) |
|
| 4579 | - $v_maximum_size = $v_size; |
|
| 4544 | + if ($v_maximum_size > $v_size) { |
|
| 4545 | + $v_maximum_size = $v_size; |
|
| 4546 | + } |
|
| 4580 | 4547 | @fseek($this->zip_fd, $v_size-$v_maximum_size); |
| 4581 | 4548 | if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size)) |
| 4582 | 4549 | { |
@@ -4661,9 +4628,9 @@ discard block |
||
| 4661 | 4628 | // ----- Get comment |
| 4662 | 4629 | if ($v_data['comment_size'] != 0) { |
| 4663 | 4630 | $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']); |
| 4631 | + } else { |
|
| 4632 | + $p_central_dir['comment'] = ''; |
|
| 4664 | 4633 | } |
| 4665 | - else |
|
| 4666 | - $p_central_dir['comment'] = ''; |
|
| 4667 | 4634 | |
| 4668 | 4635 | $p_central_dir['entries'] = $v_data['entries']; |
| 4669 | 4636 | $p_central_dir['disk_entries'] = $v_data['disk_entries']; |
@@ -4763,8 +4730,7 @@ discard block |
||
| 4763 | 4730 | if ( (strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) |
| 4764 | 4731 | && (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])) { |
| 4765 | 4732 | $v_found = true; |
| 4766 | - } |
|
| 4767 | - elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */ |
|
| 4733 | + } elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */ |
|
| 4768 | 4734 | && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) { |
| 4769 | 4735 | $v_found = true; |
| 4770 | 4736 | } |
@@ -4815,8 +4781,7 @@ discard block |
||
| 4815 | 4781 | break; |
| 4816 | 4782 | } |
| 4817 | 4783 | } |
| 4818 | - } |
|
| 4819 | - else { |
|
| 4784 | + } else { |
|
| 4820 | 4785 | $v_found = true; |
| 4821 | 4786 | } |
| 4822 | 4787 | |
@@ -4824,8 +4789,7 @@ discard block |
||
| 4824 | 4789 | if ($v_found) |
| 4825 | 4790 | { |
| 4826 | 4791 | unset($v_header_list[$v_nb_extracted]); |
| 4827 | - } |
|
| 4828 | - else |
|
| 4792 | + } else |
|
| 4829 | 4793 | { |
| 4830 | 4794 | $v_nb_extracted++; |
| 4831 | 4795 | } |
@@ -5301,8 +5265,7 @@ discard block |
||
| 5301 | 5265 | { |
| 5302 | 5266 | if (PCLZIP_ERROR_EXTERNAL == 1) { |
| 5303 | 5267 | PclError($p_error_code, $p_error_string); |
| 5304 | - } |
|
| 5305 | - else { |
|
| 5268 | + } else { |
|
| 5306 | 5269 | $this->error_code = $p_error_code; |
| 5307 | 5270 | $this->error_string = $p_error_string; |
| 5308 | 5271 | } |
@@ -5318,8 +5281,7 @@ discard block |
||
| 5318 | 5281 | { |
| 5319 | 5282 | if (PCLZIP_ERROR_EXTERNAL == 1) { |
| 5320 | 5283 | PclErrorReset(); |
| 5321 | - } |
|
| 5322 | - else { |
|
| 5284 | + } else { |
|
| 5323 | 5285 | $this->error_code = 0; |
| 5324 | 5286 | $this->error_string = ''; |
| 5325 | 5287 | } |
@@ -5417,11 +5379,9 @@ discard block |
||
| 5417 | 5379 | if ($v_list[$i] == ".") { |
| 5418 | 5380 | // ----- Ignore this directory |
| 5419 | 5381 | // Should be the first $i=0, but no check is done |
| 5420 | - } |
|
| 5421 | - else if ($v_list[$i] == "..") { |
|
| 5382 | + } else if ($v_list[$i] == "..") { |
|
| 5422 | 5383 | $v_skip++; |
| 5423 | - } |
|
| 5424 | - else if ($v_list[$i] == "") { |
|
| 5384 | + } else if ($v_list[$i] == "") { |
|
| 5425 | 5385 | // ----- First '/' i.e. root slash |
| 5426 | 5386 | if ($i == 0) { |
| 5427 | 5387 | $v_result = "/".$v_result; |
@@ -5441,13 +5401,11 @@ discard block |
||
| 5441 | 5401 | // ----- Ignore only the double '//' in path, |
| 5442 | 5402 | // but not the first and last '/' |
| 5443 | 5403 | } |
| 5444 | - } |
|
| 5445 | - else { |
|
| 5404 | + } else { |
|
| 5446 | 5405 | // ----- Look for item to skip |
| 5447 | 5406 | if ($v_skip > 0) { |
| 5448 | 5407 | $v_skip--; |
| 5449 | - } |
|
| 5450 | - else { |
|
| 5408 | + } else { |
|
| 5451 | 5409 | $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:""); |
| 5452 | 5410 | } |
| 5453 | 5411 | } |
@@ -5530,14 +5488,17 @@ discard block |
||
| 5530 | 5488 | // ----- Look if everything seems to be the same |
| 5531 | 5489 | if ($v_result) { |
| 5532 | 5490 | // ----- Skip all the empty items |
| 5533 | - while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++; |
|
| 5534 | - while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++; |
|
| 5491 | + while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) { |
|
| 5492 | + $j++; |
|
| 5493 | + } |
|
| 5494 | + while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) { |
|
| 5495 | + $i++; |
|
| 5496 | + } |
|
| 5535 | 5497 | |
| 5536 | 5498 | if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) { |
| 5537 | 5499 | // ----- There are exactly the same |
| 5538 | 5500 | $v_result = 2; |
| 5539 | - } |
|
| 5540 | - else if ($i < $v_list_dir_size) { |
|
| 5501 | + } else if ($i < $v_list_dir_size) { |
|
| 5541 | 5502 | // ----- The path is shorter than the dir |
| 5542 | 5503 | $v_result = 0; |
| 5543 | 5504 | } |
@@ -5572,8 +5533,7 @@ discard block |
||
| 5572 | 5533 | @fwrite($p_dest, $v_buffer, $v_read_size); |
| 5573 | 5534 | $p_size -= $v_read_size; |
| 5574 | 5535 | } |
| 5575 | - } |
|
| 5576 | - else if ($p_mode==1) |
|
| 5536 | + } else if ($p_mode==1) |
|
| 5577 | 5537 | { |
| 5578 | 5538 | while ($p_size != 0) |
| 5579 | 5539 | { |
@@ -5582,8 +5542,7 @@ discard block |
||
| 5582 | 5542 | @fwrite($p_dest, $v_buffer, $v_read_size); |
| 5583 | 5543 | $p_size -= $v_read_size; |
| 5584 | 5544 | } |
| 5585 | - } |
|
| 5586 | - else if ($p_mode==2) |
|
| 5545 | + } else if ($p_mode==2) |
|
| 5587 | 5546 | { |
| 5588 | 5547 | while ($p_size != 0) |
| 5589 | 5548 | { |
@@ -5592,8 +5551,7 @@ discard block |
||
| 5592 | 5551 | @gzwrite($p_dest, $v_buffer, $v_read_size); |
| 5593 | 5552 | $p_size -= $v_read_size; |
| 5594 | 5553 | } |
| 5595 | - } |
|
| 5596 | - else if ($p_mode==3) |
|
| 5554 | + } else if ($p_mode==3) |
|
| 5597 | 5555 | { |
| 5598 | 5556 | while ($p_size != 0) |
| 5599 | 5557 | { |
@@ -5631,8 +5589,7 @@ discard block |
||
| 5631 | 5589 | // ----- Try to copy & unlink the src |
| 5632 | 5590 | if (!@copy($p_src, $p_dest)) { |
| 5633 | 5591 | $v_result = 0; |
| 5634 | - } |
|
| 5635 | - else if (!@unlink($p_src)) { |
|
| 5592 | + } else if (!@unlink($p_src)) { |
|
| 5636 | 5593 | $v_result = 0; |
| 5637 | 5594 | } |
| 5638 | 5595 | } |
@@ -138,7 +138,7 @@ |
||
| 138 | 138 | * @param string $primary |
| 139 | 139 | * @param array $rows |
| 140 | 140 | * @param string $serveur |
| 141 | - * @return array |
|
| 141 | + * @return string[] |
|
| 142 | 142 | */ |
| 143 | 143 | function generer_select_where_explicites($table, $primary, $rows, $serveur){ |
| 144 | 144 | # calculer le {id_article IN()} et le {... as points} |
@@ -41,87 +41,87 @@ discard block |
||
| 41 | 41 | * @return array |
| 42 | 42 | */ |
| 43 | 43 | function inc_prepare_recherche_dist($recherche, $table='articles', $cond=false, $serveur='', $modificateurs = array(), $primary='') { |
| 44 | - static $cache = array(); |
|
| 45 | - $delai_fraicheur = min(_DELAI_CACHE_resultats,time()-$GLOBALS['meta']['derniere_modif']); |
|
| 44 | + static $cache = array(); |
|
| 45 | + $delai_fraicheur = min(_DELAI_CACHE_resultats,time()-$GLOBALS['meta']['derniere_modif']); |
|
| 46 | 46 | |
| 47 | - // si recherche n'est pas dans le contexte, on va prendre en globals |
|
| 48 | - // ca permet de faire des inclure simple. |
|
| 49 | - if (!isset($recherche) AND isset($GLOBALS['recherche'])) |
|
| 50 | - $recherche = $GLOBALS['recherche']; |
|
| 47 | + // si recherche n'est pas dans le contexte, on va prendre en globals |
|
| 48 | + // ca permet de faire des inclure simple. |
|
| 49 | + if (!isset($recherche) AND isset($GLOBALS['recherche'])) |
|
| 50 | + $recherche = $GLOBALS['recherche']; |
|
| 51 | 51 | |
| 52 | - // traiter le cas {recherche?} |
|
| 53 | - if ($cond AND !strlen($recherche)) |
|
| 54 | - return array("0 as points" /* as points */, /* where */ ''); |
|
| 52 | + // traiter le cas {recherche?} |
|
| 53 | + if ($cond AND !strlen($recherche)) |
|
| 54 | + return array("0 as points" /* as points */, /* where */ ''); |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | - $rechercher = false; |
|
| 58 | - |
|
| 59 | - if (!isset($cache[$serveur][$table][$recherche])){ |
|
| 60 | - $hash_serv = ($serveur?substr(md5($serveur),0,16):''); |
|
| 61 | - $hash = substr(md5($recherche . $table),0,16); |
|
| 62 | - $where = "(resultats.recherche='$hash' AND resultats.table_objet=".sql_quote($table)." AND resultats.serveur='$hash_serv')"; |
|
| 63 | - $row = sql_fetsel('UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(resultats.maj) AS fraicheur','spip_resultats AS resultats',$where,'','fraicheur DESC','0,1'); |
|
| 64 | - if (!$row |
|
| 65 | - OR ($row['fraicheur']>$delai_fraicheur) |
|
| 66 | - OR (defined('_VAR_MODE') AND _VAR_MODE=='recalcul')){ |
|
| 67 | - $rechercher = true; |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - // si on n'a pas encore traite les donnees dans une boucle precedente |
|
| 72 | - if ($rechercher) { |
|
| 73 | - //$tables = liste_des_champs(); |
|
| 74 | - $x = objet_type($table); |
|
| 75 | - $points = recherche_en_base($recherche, |
|
| 76 | - $x, |
|
| 77 | - array( |
|
| 78 | - 'score' => true, |
|
| 79 | - 'toutvoir' => true, |
|
| 80 | - 'jointures' => true |
|
| 81 | - ), |
|
| 82 | - $serveur); |
|
| 83 | - // pas de résultat, pas de point |
|
| 84 | - $points = isset($points[$x]) ? $points[$x] : array(); |
|
| 85 | - |
|
| 86 | - // permettre aux plugins de modifier le resultat |
|
| 87 | - $points = pipeline('prepare_recherche',array( |
|
| 88 | - 'args'=>array('type'=>$x,'recherche'=>$recherche,'serveur'=>$serveur,'modificateurs'=>$modificateurs), |
|
| 89 | - 'data'=>$points |
|
| 90 | - )); |
|
| 91 | - |
|
| 92 | - // supprimer les anciens resultats de cette recherche |
|
| 93 | - // et les resultats trop vieux avec une marge |
|
| 94 | - // pas de AS resultats dans un delete (mysql) |
|
| 95 | - $whered = str_replace(array("resultats.recherche","resultats.table_objet","resultats.serveur"),array("recherche","table_objet","serveur"),$where); |
|
| 96 | - sql_delete('spip_resultats', 'NOT(' .sql_date_proche('maj', (0-($delai_fraicheur+100)), " SECOND") . ") OR ($whered)"); |
|
| 97 | - |
|
| 98 | - // inserer les resultats dans la table de cache des resultats |
|
| 99 | - if (count($points)){ |
|
| 100 | - $tab_couples = array(); |
|
| 101 | - foreach ($points as $id => $p){ |
|
| 102 | - $tab_couples[] = array( |
|
| 103 | - 'recherche' => $hash, |
|
| 104 | - 'id' => $id, |
|
| 105 | - 'points' => $p['score'], |
|
| 106 | - 'table_objet' => $table, |
|
| 107 | - 'serveur' => $hash_serv, |
|
| 108 | - ); |
|
| 109 | - } |
|
| 110 | - sql_insertq_multi('spip_resultats',$tab_couples,array()); |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - if (!isset($cache[$serveur][$table][$recherche])){ |
|
| 115 | - if (!$serveur) |
|
| 116 | - $cache[$serveur][$table][$recherche] = array("resultats.points AS points",$where); |
|
| 117 | - else { |
|
| 118 | - if (sql_countsel('spip_resultats as resultats',$where)) |
|
| 119 | - $rows = sql_allfetsel('resultats.id,resultats.points','spip_resultats as resultats',$where); |
|
| 120 | - $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return $cache[$serveur][$table][$recherche]; |
|
| 57 | + $rechercher = false; |
|
| 58 | + |
|
| 59 | + if (!isset($cache[$serveur][$table][$recherche])){ |
|
| 60 | + $hash_serv = ($serveur?substr(md5($serveur),0,16):''); |
|
| 61 | + $hash = substr(md5($recherche . $table),0,16); |
|
| 62 | + $where = "(resultats.recherche='$hash' AND resultats.table_objet=".sql_quote($table)." AND resultats.serveur='$hash_serv')"; |
|
| 63 | + $row = sql_fetsel('UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(resultats.maj) AS fraicheur','spip_resultats AS resultats',$where,'','fraicheur DESC','0,1'); |
|
| 64 | + if (!$row |
|
| 65 | + OR ($row['fraicheur']>$delai_fraicheur) |
|
| 66 | + OR (defined('_VAR_MODE') AND _VAR_MODE=='recalcul')){ |
|
| 67 | + $rechercher = true; |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + // si on n'a pas encore traite les donnees dans une boucle precedente |
|
| 72 | + if ($rechercher) { |
|
| 73 | + //$tables = liste_des_champs(); |
|
| 74 | + $x = objet_type($table); |
|
| 75 | + $points = recherche_en_base($recherche, |
|
| 76 | + $x, |
|
| 77 | + array( |
|
| 78 | + 'score' => true, |
|
| 79 | + 'toutvoir' => true, |
|
| 80 | + 'jointures' => true |
|
| 81 | + ), |
|
| 82 | + $serveur); |
|
| 83 | + // pas de résultat, pas de point |
|
| 84 | + $points = isset($points[$x]) ? $points[$x] : array(); |
|
| 85 | + |
|
| 86 | + // permettre aux plugins de modifier le resultat |
|
| 87 | + $points = pipeline('prepare_recherche',array( |
|
| 88 | + 'args'=>array('type'=>$x,'recherche'=>$recherche,'serveur'=>$serveur,'modificateurs'=>$modificateurs), |
|
| 89 | + 'data'=>$points |
|
| 90 | + )); |
|
| 91 | + |
|
| 92 | + // supprimer les anciens resultats de cette recherche |
|
| 93 | + // et les resultats trop vieux avec une marge |
|
| 94 | + // pas de AS resultats dans un delete (mysql) |
|
| 95 | + $whered = str_replace(array("resultats.recherche","resultats.table_objet","resultats.serveur"),array("recherche","table_objet","serveur"),$where); |
|
| 96 | + sql_delete('spip_resultats', 'NOT(' .sql_date_proche('maj', (0-($delai_fraicheur+100)), " SECOND") . ") OR ($whered)"); |
|
| 97 | + |
|
| 98 | + // inserer les resultats dans la table de cache des resultats |
|
| 99 | + if (count($points)){ |
|
| 100 | + $tab_couples = array(); |
|
| 101 | + foreach ($points as $id => $p){ |
|
| 102 | + $tab_couples[] = array( |
|
| 103 | + 'recherche' => $hash, |
|
| 104 | + 'id' => $id, |
|
| 105 | + 'points' => $p['score'], |
|
| 106 | + 'table_objet' => $table, |
|
| 107 | + 'serveur' => $hash_serv, |
|
| 108 | + ); |
|
| 109 | + } |
|
| 110 | + sql_insertq_multi('spip_resultats',$tab_couples,array()); |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + if (!isset($cache[$serveur][$table][$recherche])){ |
|
| 115 | + if (!$serveur) |
|
| 116 | + $cache[$serveur][$table][$recherche] = array("resultats.points AS points",$where); |
|
| 117 | + else { |
|
| 118 | + if (sql_countsel('spip_resultats as resultats',$where)) |
|
| 119 | + $rows = sql_allfetsel('resultats.id,resultats.points','spip_resultats as resultats',$where); |
|
| 120 | + $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return $cache[$serveur][$table][$recherche]; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | |
@@ -137,23 +137,23 @@ discard block |
||
| 137 | 137 | * @return array |
| 138 | 138 | */ |
| 139 | 139 | function generer_select_where_explicites($table, $primary, $rows, $serveur){ |
| 140 | - # calculer le {id_article IN()} et le {... as points} |
|
| 141 | - if (!count($rows)){ |
|
| 142 | - return array("''", "0=1"); |
|
| 143 | - } |
|
| 144 | - else { |
|
| 145 | - $listes_ids = array(); |
|
| 146 | - $select = '0'; |
|
| 147 | - foreach ($rows as $r) |
|
| 148 | - $listes_ids[$r['points']][] = $r['id']; |
|
| 149 | - |
|
| 150 | - foreach ($listes_ids as $p => $ids) |
|
| 151 | - $select .= "+$p*(". |
|
| 152 | - sql_in("$table.$primary", $ids,'',$serveur) |
|
| 153 | - .") "; |
|
| 154 | - |
|
| 155 | - return array("$select AS points ",calcul_mysql_in("$table.$primary",array_map('reset',$rows),'',$serveur)); |
|
| 156 | - } |
|
| 140 | + # calculer le {id_article IN()} et le {... as points} |
|
| 141 | + if (!count($rows)){ |
|
| 142 | + return array("''", "0=1"); |
|
| 143 | + } |
|
| 144 | + else { |
|
| 145 | + $listes_ids = array(); |
|
| 146 | + $select = '0'; |
|
| 147 | + foreach ($rows as $r) |
|
| 148 | + $listes_ids[$r['points']][] = $r['id']; |
|
| 149 | + |
|
| 150 | + foreach ($listes_ids as $p => $ids) |
|
| 151 | + $select .= "+$p*(". |
|
| 152 | + sql_in("$table.$primary", $ids,'',$serveur) |
|
| 153 | + .") "; |
|
| 154 | + |
|
| 155 | + return array("$select AS points ",calcul_mysql_in("$table.$primary",array_map('reset',$rows),'',$serveur)); |
|
| 156 | + } |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | |
@@ -11,10 +11,14 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | |
| 14 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 14 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 15 | + return; |
|
| 16 | +} |
|
| 15 | 17 | |
| 16 | 18 | include_spip('inc/rechercher'); |
| 17 | -if (!defined('_DELAI_CACHE_resultats')) define('_DELAI_CACHE_resultats', 600); |
|
| 19 | +if (!defined('_DELAI_CACHE_resultats')) { |
|
| 20 | + define('_DELAI_CACHE_resultats', 600); |
|
| 21 | +} |
|
| 18 | 22 | |
| 19 | 23 | /** |
| 20 | 24 | * Preparer les listes id_article IN (...) pour les parties WHERE |
@@ -46,12 +50,14 @@ discard block |
||
| 46 | 50 | |
| 47 | 51 | // si recherche n'est pas dans le contexte, on va prendre en globals |
| 48 | 52 | // ca permet de faire des inclure simple. |
| 49 | - if (!isset($recherche) AND isset($GLOBALS['recherche'])) |
|
| 50 | - $recherche = $GLOBALS['recherche']; |
|
| 53 | + if (!isset($recherche) AND isset($GLOBALS['recherche'])) { |
|
| 54 | + $recherche = $GLOBALS['recherche']; |
|
| 55 | + } |
|
| 51 | 56 | |
| 52 | 57 | // traiter le cas {recherche?} |
| 53 | - if ($cond AND !strlen($recherche)) |
|
| 54 | - return array("0 as points" /* as points */, /* where */ ''); |
|
| 58 | + if ($cond AND !strlen($recherche)) { |
|
| 59 | + return array("0 as points" /* as points */, /* where */ ''); |
|
| 60 | + } |
|
| 55 | 61 | |
| 56 | 62 | |
| 57 | 63 | $rechercher = false; |
@@ -112,11 +118,12 @@ discard block |
||
| 112 | 118 | } |
| 113 | 119 | |
| 114 | 120 | if (!isset($cache[$serveur][$table][$recherche])){ |
| 115 | - if (!$serveur) |
|
| 116 | - $cache[$serveur][$table][$recherche] = array("resultats.points AS points",$where); |
|
| 117 | - else { |
|
| 118 | - if (sql_countsel('spip_resultats as resultats',$where)) |
|
| 119 | - $rows = sql_allfetsel('resultats.id,resultats.points','spip_resultats as resultats',$where); |
|
| 121 | + if (!$serveur) { |
|
| 122 | + $cache[$serveur][$table][$recherche] = array("resultats.points AS points",$where); |
|
| 123 | + } else { |
|
| 124 | + if (sql_countsel('spip_resultats as resultats',$where)) { |
|
| 125 | + $rows = sql_allfetsel('resultats.id,resultats.points','spip_resultats as resultats',$where); |
|
| 126 | + } |
|
| 120 | 127 | $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur); |
| 121 | 128 | } |
| 122 | 129 | } |
@@ -140,17 +147,18 @@ discard block |
||
| 140 | 147 | # calculer le {id_article IN()} et le {... as points} |
| 141 | 148 | if (!count($rows)){ |
| 142 | 149 | return array("''", "0=1"); |
| 143 | - } |
|
| 144 | - else { |
|
| 150 | + } else { |
|
| 145 | 151 | $listes_ids = array(); |
| 146 | 152 | $select = '0'; |
| 147 | - foreach ($rows as $r) |
|
| 148 | - $listes_ids[$r['points']][] = $r['id']; |
|
| 153 | + foreach ($rows as $r) { |
|
| 154 | + $listes_ids[$r['points']][] = $r['id']; |
|
| 155 | + } |
|
| 149 | 156 | |
| 150 | - foreach ($listes_ids as $p => $ids) |
|
| 151 | - $select .= "+$p*(". |
|
| 157 | + foreach ($listes_ids as $p => $ids) { |
|
| 158 | + $select .= "+$p*(". |
|
| 152 | 159 | sql_in("$table.$primary", $ids,'',$serveur) |
| 153 | 160 | .") "; |
| 161 | + } |
|
| 154 | 162 | |
| 155 | 163 | return array("$select AS points ",calcul_mysql_in("$table.$primary",array_map('reset',$rows),'',$serveur)); |
| 156 | 164 | } |
@@ -40,9 +40,9 @@ discard block |
||
| 40 | 40 | * cle primaire de la table de recherche |
| 41 | 41 | * @return array |
| 42 | 42 | */ |
| 43 | -function inc_prepare_recherche_dist($recherche, $table='articles', $cond=false, $serveur='', $modificateurs = array(), $primary='') { |
|
| 43 | +function inc_prepare_recherche_dist($recherche, $table = 'articles', $cond = false, $serveur = '', $modificateurs = array(), $primary = '') { |
|
| 44 | 44 | static $cache = array(); |
| 45 | - $delai_fraicheur = min(_DELAI_CACHE_resultats,time()-$GLOBALS['meta']['derniere_modif']); |
|
| 45 | + $delai_fraicheur = min(_DELAI_CACHE_resultats, time() - $GLOBALS['meta']['derniere_modif']); |
|
| 46 | 46 | |
| 47 | 47 | // si recherche n'est pas dans le contexte, on va prendre en globals |
| 48 | 48 | // ca permet de faire des inclure simple. |
@@ -56,14 +56,14 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | $rechercher = false; |
| 58 | 58 | |
| 59 | - if (!isset($cache[$serveur][$table][$recherche])){ |
|
| 60 | - $hash_serv = ($serveur?substr(md5($serveur),0,16):''); |
|
| 61 | - $hash = substr(md5($recherche . $table),0,16); |
|
| 59 | + if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 60 | + $hash_serv = ($serveur ?substr(md5($serveur), 0, 16) : ''); |
|
| 61 | + $hash = substr(md5($recherche.$table), 0, 16); |
|
| 62 | 62 | $where = "(resultats.recherche='$hash' AND resultats.table_objet=".sql_quote($table)." AND resultats.serveur='$hash_serv')"; |
| 63 | - $row = sql_fetsel('UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(resultats.maj) AS fraicheur','spip_resultats AS resultats',$where,'','fraicheur DESC','0,1'); |
|
| 63 | + $row = sql_fetsel('UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(resultats.maj) AS fraicheur', 'spip_resultats AS resultats', $where, '', 'fraicheur DESC', '0,1'); |
|
| 64 | 64 | if (!$row |
| 65 | - OR ($row['fraicheur']>$delai_fraicheur) |
|
| 66 | - OR (defined('_VAR_MODE') AND _VAR_MODE=='recalcul')){ |
|
| 65 | + OR ($row['fraicheur'] > $delai_fraicheur) |
|
| 66 | + OR (defined('_VAR_MODE') AND _VAR_MODE == 'recalcul')) { |
|
| 67 | 67 | $rechercher = true; |
| 68 | 68 | } |
| 69 | 69 | } |
@@ -84,21 +84,21 @@ discard block |
||
| 84 | 84 | $points = isset($points[$x]) ? $points[$x] : array(); |
| 85 | 85 | |
| 86 | 86 | // permettre aux plugins de modifier le resultat |
| 87 | - $points = pipeline('prepare_recherche',array( |
|
| 88 | - 'args'=>array('type'=>$x,'recherche'=>$recherche,'serveur'=>$serveur,'modificateurs'=>$modificateurs), |
|
| 87 | + $points = pipeline('prepare_recherche', array( |
|
| 88 | + 'args'=>array('type'=>$x, 'recherche'=>$recherche, 'serveur'=>$serveur, 'modificateurs'=>$modificateurs), |
|
| 89 | 89 | 'data'=>$points |
| 90 | 90 | )); |
| 91 | 91 | |
| 92 | 92 | // supprimer les anciens resultats de cette recherche |
| 93 | 93 | // et les resultats trop vieux avec une marge |
| 94 | 94 | // pas de AS resultats dans un delete (mysql) |
| 95 | - $whered = str_replace(array("resultats.recherche","resultats.table_objet","resultats.serveur"),array("recherche","table_objet","serveur"),$where); |
|
| 96 | - sql_delete('spip_resultats', 'NOT(' .sql_date_proche('maj', (0-($delai_fraicheur+100)), " SECOND") . ") OR ($whered)"); |
|
| 95 | + $whered = str_replace(array("resultats.recherche", "resultats.table_objet", "resultats.serveur"), array("recherche", "table_objet", "serveur"), $where); |
|
| 96 | + sql_delete('spip_resultats', 'NOT('.sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), " SECOND").") OR ($whered)"); |
|
| 97 | 97 | |
| 98 | 98 | // inserer les resultats dans la table de cache des resultats |
| 99 | - if (count($points)){ |
|
| 99 | + if (count($points)) { |
|
| 100 | 100 | $tab_couples = array(); |
| 101 | - foreach ($points as $id => $p){ |
|
| 101 | + foreach ($points as $id => $p) { |
|
| 102 | 102 | $tab_couples[] = array( |
| 103 | 103 | 'recherche' => $hash, |
| 104 | 104 | 'id' => $id, |
@@ -107,16 +107,16 @@ discard block |
||
| 107 | 107 | 'serveur' => $hash_serv, |
| 108 | 108 | ); |
| 109 | 109 | } |
| 110 | - sql_insertq_multi('spip_resultats',$tab_couples,array()); |
|
| 110 | + sql_insertq_multi('spip_resultats', $tab_couples, array()); |
|
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - if (!isset($cache[$serveur][$table][$recherche])){ |
|
| 114 | + if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 115 | 115 | if (!$serveur) |
| 116 | - $cache[$serveur][$table][$recherche] = array("resultats.points AS points",$where); |
|
| 116 | + $cache[$serveur][$table][$recherche] = array("resultats.points AS points", $where); |
|
| 117 | 117 | else { |
| 118 | - if (sql_countsel('spip_resultats as resultats',$where)) |
|
| 119 | - $rows = sql_allfetsel('resultats.id,resultats.points','spip_resultats as resultats',$where); |
|
| 118 | + if (sql_countsel('spip_resultats as resultats', $where)) |
|
| 119 | + $rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where); |
|
| 120 | 120 | $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur); |
| 121 | 121 | } |
| 122 | 122 | } |
@@ -136,9 +136,9 @@ discard block |
||
| 136 | 136 | * @param string $serveur |
| 137 | 137 | * @return array |
| 138 | 138 | */ |
| 139 | -function generer_select_where_explicites($table, $primary, $rows, $serveur){ |
|
| 139 | +function generer_select_where_explicites($table, $primary, $rows, $serveur) { |
|
| 140 | 140 | # calculer le {id_article IN()} et le {... as points} |
| 141 | - if (!count($rows)){ |
|
| 141 | + if (!count($rows)) { |
|
| 142 | 142 | return array("''", "0=1"); |
| 143 | 143 | } |
| 144 | 144 | else { |
@@ -149,10 +149,10 @@ discard block |
||
| 149 | 149 | |
| 150 | 150 | foreach ($listes_ids as $p => $ids) |
| 151 | 151 | $select .= "+$p*(". |
| 152 | - sql_in("$table.$primary", $ids,'',$serveur) |
|
| 152 | + sql_in("$table.$primary", $ids, '', $serveur) |
|
| 153 | 153 | .") "; |
| 154 | 154 | |
| 155 | - return array("$select AS points ",calcul_mysql_in("$table.$primary",array_map('reset',$rows),'',$serveur)); |
|
| 155 | + return array("$select AS points ", calcul_mysql_in("$table.$primary", array_map('reset', $rows), '', $serveur)); |
|
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | 158 | |
@@ -101,6 +101,10 @@ discard block |
||
| 101 | 101 | // checkbox pour activer ou desactiver |
| 102 | 102 | // si ce n'est pas une extension |
| 103 | 103 | |
| 104 | +/** |
|
| 105 | + * @param integer $id_input |
|
| 106 | + * @param string $file |
|
| 107 | + */ |
|
| 104 | 108 | function plugin_checkbox($id_input, $file, $actif) |
| 105 | 109 | { |
| 106 | 110 | $name = substr(md5($file),0,16); |
@@ -162,6 +166,9 @@ discard block |
||
| 162 | 166 | . "</div>"; |
| 163 | 167 | } |
| 164 | 168 | |
| 169 | +/** |
|
| 170 | + * @param string $nom |
|
| 171 | + */ |
|
| 165 | 172 | function plugin_desintalle($plug_file, $nom, $dir_plugins=null){ |
| 166 | 173 | if (!$dir_plugins) |
| 167 | 174 | $dir_plugins = _DIR_PLUGINS; |
@@ -18,77 +18,77 @@ discard block |
||
| 18 | 18 | // http://doc.spip.org/@ligne_plug |
| 19 | 19 | function plugins_afficher_plugin_dist($url_page, $plug_file, $checked, $actif, $expose=false, $class_li="item", $dir_plugins=_DIR_PLUGINS) { |
| 20 | 20 | |
| 21 | - static $id_input = 0; |
|
| 22 | - static $versions = array(); |
|
| 23 | - |
|
| 24 | - $force_reload = (_request('var_mode')=='recalcul'); |
|
| 25 | - $get_infos = charger_fonction('get_infos','plugins'); |
|
| 26 | - $info = $get_infos($plug_file, $force_reload, $dir_plugins); |
|
| 27 | - $prefix = $info['prefix']; |
|
| 28 | - $cfg = ""; |
|
| 29 | - $checkable = ($dir_plugins!==_DIR_PLUGINS_DIST); |
|
| 30 | - $nom = plugin_nom($info,$dir_plugins,$plug_file); |
|
| 31 | - |
|
| 32 | - if (!plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'],'spip')){ |
|
| 33 | - $info['slogan'] = _T('plugin_info_non_compatible_spip'); |
|
| 34 | - $erreur = http_img_pack("plugin-dis-32.png",_T('plugin_info_non_compatible_spip')," class='picto_err'",_T('plugin_info_non_compatible_spip')); |
|
| 35 | - $class_li .= " disabled"; |
|
| 36 | - $checkable = false; |
|
| 37 | - } |
|
| 38 | - elseif (isset($info['erreur'])) { |
|
| 39 | - $class_li .= " error"; |
|
| 40 | - $erreur = http_img_pack("plugin-err-32.png",_T('plugin_info_erreur_xml')," class='picto_err'",_T('plugin_info_erreur_xml')) |
|
| 41 | - . "<div class='erreur'>" . join('<br >', $info['erreur']) . "</div>"; |
|
| 42 | - $checkable = false; |
|
| 43 | - } |
|
| 44 | - elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins.$plug_file])){ |
|
| 45 | - $class_li .= " error"; |
|
| 46 | - $erreur = http_img_pack("plugin-err-32.png",_T('plugin_impossible_activer', array('plugin' => $nom))," class='picto_err'",_T('plugin_impossible_activer', array('plugin' => $nom))) |
|
| 47 | - . "<div class='erreur'>" . implode("<br />",$GLOBALS['erreurs_activation_raw'][$dir_plugins.$plug_file]) . "</div>"; |
|
| 48 | - } |
|
| 49 | - else |
|
| 50 | - $cfg = $actif ? plugin_bouton_config($plug_file,$info,$dir_plugins) : ""; |
|
| 51 | - |
|
| 52 | - // numerotons les occurrences d'un meme prefix |
|
| 53 | - $versions[$prefix] = $id = isset($versions[$prefix]) ? $versions[$prefix] + 1 : ''; |
|
| 54 | - |
|
| 55 | - $class_li .= ($actif?" actif":"") . ($expose?" on":""); |
|
| 56 | - return "<li id='$prefix$id' class='$class_li'>" |
|
| 57 | - . ((!$checkable AND !$checked) |
|
| 58 | - ? '': plugin_checkbox(++$id_input, $dir_plugins.$plug_file, $checked)) |
|
| 59 | - . plugin_resume($info, $dir_plugins, $plug_file, $url_page) |
|
| 60 | - . $cfg |
|
| 61 | - . $erreur |
|
| 62 | - . (($dir_plugins!==_DIR_PLUGINS_DIST AND plugin_est_installe($plug_file)) |
|
| 63 | - ? plugin_desintalle($plug_file,$nom,$dir_plugins) : '') |
|
| 64 | - . "<div class='details'>" // pour l'ajax de exec/info_plugin |
|
| 65 | - . (!$expose ? '' : affiche_bloc_plugin($plug_file, $info, $dir_plugins)) |
|
| 66 | - . "</div>" |
|
| 67 | - ."</li>"; |
|
| 21 | + static $id_input = 0; |
|
| 22 | + static $versions = array(); |
|
| 23 | + |
|
| 24 | + $force_reload = (_request('var_mode')=='recalcul'); |
|
| 25 | + $get_infos = charger_fonction('get_infos','plugins'); |
|
| 26 | + $info = $get_infos($plug_file, $force_reload, $dir_plugins); |
|
| 27 | + $prefix = $info['prefix']; |
|
| 28 | + $cfg = ""; |
|
| 29 | + $checkable = ($dir_plugins!==_DIR_PLUGINS_DIST); |
|
| 30 | + $nom = plugin_nom($info,$dir_plugins,$plug_file); |
|
| 31 | + |
|
| 32 | + if (!plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'],'spip')){ |
|
| 33 | + $info['slogan'] = _T('plugin_info_non_compatible_spip'); |
|
| 34 | + $erreur = http_img_pack("plugin-dis-32.png",_T('plugin_info_non_compatible_spip')," class='picto_err'",_T('plugin_info_non_compatible_spip')); |
|
| 35 | + $class_li .= " disabled"; |
|
| 36 | + $checkable = false; |
|
| 37 | + } |
|
| 38 | + elseif (isset($info['erreur'])) { |
|
| 39 | + $class_li .= " error"; |
|
| 40 | + $erreur = http_img_pack("plugin-err-32.png",_T('plugin_info_erreur_xml')," class='picto_err'",_T('plugin_info_erreur_xml')) |
|
| 41 | + . "<div class='erreur'>" . join('<br >', $info['erreur']) . "</div>"; |
|
| 42 | + $checkable = false; |
|
| 43 | + } |
|
| 44 | + elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins.$plug_file])){ |
|
| 45 | + $class_li .= " error"; |
|
| 46 | + $erreur = http_img_pack("plugin-err-32.png",_T('plugin_impossible_activer', array('plugin' => $nom))," class='picto_err'",_T('plugin_impossible_activer', array('plugin' => $nom))) |
|
| 47 | + . "<div class='erreur'>" . implode("<br />",$GLOBALS['erreurs_activation_raw'][$dir_plugins.$plug_file]) . "</div>"; |
|
| 48 | + } |
|
| 49 | + else |
|
| 50 | + $cfg = $actif ? plugin_bouton_config($plug_file,$info,$dir_plugins) : ""; |
|
| 51 | + |
|
| 52 | + // numerotons les occurrences d'un meme prefix |
|
| 53 | + $versions[$prefix] = $id = isset($versions[$prefix]) ? $versions[$prefix] + 1 : ''; |
|
| 54 | + |
|
| 55 | + $class_li .= ($actif?" actif":"") . ($expose?" on":""); |
|
| 56 | + return "<li id='$prefix$id' class='$class_li'>" |
|
| 57 | + . ((!$checkable AND !$checked) |
|
| 58 | + ? '': plugin_checkbox(++$id_input, $dir_plugins.$plug_file, $checked)) |
|
| 59 | + . plugin_resume($info, $dir_plugins, $plug_file, $url_page) |
|
| 60 | + . $cfg |
|
| 61 | + . $erreur |
|
| 62 | + . (($dir_plugins!==_DIR_PLUGINS_DIST AND plugin_est_installe($plug_file)) |
|
| 63 | + ? plugin_desintalle($plug_file,$nom,$dir_plugins) : '') |
|
| 64 | + . "<div class='details'>" // pour l'ajax de exec/info_plugin |
|
| 65 | + . (!$expose ? '' : affiche_bloc_plugin($plug_file, $info, $dir_plugins)) |
|
| 66 | + . "</div>" |
|
| 67 | + ."</li>"; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | function plugin_bouton_config($nom, $infos, $dir) |
| 71 | 71 | { |
| 72 | - // la verification se base sur le filesystem |
|
| 73 | - // il faut donc n'utiliser que des minuscules, par convention |
|
| 74 | - $prefix = strtolower($infos['prefix']); |
|
| 75 | - // si plugin.xml fournit un squelette, le prendre |
|
| 76 | - if ($infos['config']) |
|
| 77 | - return recuperer_fond("$dir$nom/" . $infos['config'], |
|
| 78 | - array('script' => 'configurer_' . $prefix, |
|
| 79 | - 'nom' => $nom)); |
|
| 80 | - |
|
| 81 | - // si le plugin CFG est la, l'essayer |
|
| 82 | - if (defined('_DIR_PLUGIN_CFG')) { |
|
| 83 | - if (include_spip('inc/cfg')) // test CFG version >= 1.0.5 |
|
| 84 | - if ($cfg = icone_lien_cfg("$dir$nom", "cfg")) |
|
| 85 | - return "<div class='cfg_link'>$cfg</div>"; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - // sinon prendre le squelette std sur le nom std |
|
| 89 | - return recuperer_fond("prive/squelettes/inclure/cfg", |
|
| 90 | - array('script' => 'configurer_' . $prefix, |
|
| 91 | - 'nom' => $nom)); |
|
| 72 | + // la verification se base sur le filesystem |
|
| 73 | + // il faut donc n'utiliser que des minuscules, par convention |
|
| 74 | + $prefix = strtolower($infos['prefix']); |
|
| 75 | + // si plugin.xml fournit un squelette, le prendre |
|
| 76 | + if ($infos['config']) |
|
| 77 | + return recuperer_fond("$dir$nom/" . $infos['config'], |
|
| 78 | + array('script' => 'configurer_' . $prefix, |
|
| 79 | + 'nom' => $nom)); |
|
| 80 | + |
|
| 81 | + // si le plugin CFG est la, l'essayer |
|
| 82 | + if (defined('_DIR_PLUGIN_CFG')) { |
|
| 83 | + if (include_spip('inc/cfg')) // test CFG version >= 1.0.5 |
|
| 84 | + if ($cfg = icone_lien_cfg("$dir$nom", "cfg")) |
|
| 85 | + return "<div class='cfg_link'>$cfg</div>"; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + // sinon prendre le squelette std sur le nom std |
|
| 89 | + return recuperer_fond("prive/squelettes/inclure/cfg", |
|
| 90 | + array('script' => 'configurer_' . $prefix, |
|
| 91 | + 'nom' => $nom)); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | // checkbox pour activer ou desactiver |
@@ -96,193 +96,193 @@ discard block |
||
| 96 | 96 | |
| 97 | 97 | function plugin_checkbox($id_input, $file, $actif) |
| 98 | 98 | { |
| 99 | - $name = substr(md5($file),0,16); |
|
| 100 | - |
|
| 101 | - return "<div class='check'>\n" |
|
| 102 | - . "<input type='checkbox' name='s$name' id='label_$id_input'" |
|
| 103 | - . ($actif?" checked='checked'":"") |
|
| 104 | - . " class='checkbox' value='O' />" |
|
| 105 | - . "\n<label for='label_$id_input'>"._T('activer_plugin')."</label>" |
|
| 106 | - . "</div>"; |
|
| 99 | + $name = substr(md5($file),0,16); |
|
| 100 | + |
|
| 101 | + return "<div class='check'>\n" |
|
| 102 | + . "<input type='checkbox' name='s$name' id='label_$id_input'" |
|
| 103 | + . ($actif?" checked='checked'":"") |
|
| 104 | + . " class='checkbox' value='O' />" |
|
| 105 | + . "\n<label for='label_$id_input'>"._T('activer_plugin')."</label>" |
|
| 106 | + . "</div>"; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | function plugin_nom($info, $dir_plugins, $plug_file){ |
| 110 | - $prefix = $info['prefix']; |
|
| 111 | - $dir = "$dir_plugins$plug_file"; |
|
| 112 | - // Si dtd paquet, on traite le nom soit par son item de langue soit par sa valeur immediate a l'index "nom" |
|
| 113 | - if ($info['dtd'] == "paquet") { |
|
| 114 | - $nom = PtoBR(plugin_propre("{$prefix}_nom", "$dir/lang/paquet-$prefix")); |
|
| 115 | - if (!$nom) |
|
| 116 | - $nom = PtoBR(propre($info['nom'])); |
|
| 117 | - } |
|
| 118 | - else |
|
| 119 | - $nom = typo(attribut_html($info['nom'])); |
|
| 120 | - |
|
| 121 | - return trim($nom); |
|
| 110 | + $prefix = $info['prefix']; |
|
| 111 | + $dir = "$dir_plugins$plug_file"; |
|
| 112 | + // Si dtd paquet, on traite le nom soit par son item de langue soit par sa valeur immediate a l'index "nom" |
|
| 113 | + if ($info['dtd'] == "paquet") { |
|
| 114 | + $nom = PtoBR(plugin_propre("{$prefix}_nom", "$dir/lang/paquet-$prefix")); |
|
| 115 | + if (!$nom) |
|
| 116 | + $nom = PtoBR(propre($info['nom'])); |
|
| 117 | + } |
|
| 118 | + else |
|
| 119 | + $nom = typo(attribut_html($info['nom'])); |
|
| 120 | + |
|
| 121 | + return trim($nom); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | // Cartouche Resume |
| 125 | 125 | function plugin_resume($info, $dir_plugins, $plug_file, $url_page){ |
| 126 | - $prefix = $info['prefix']; |
|
| 127 | - $dir = "$dir_plugins$plug_file"; |
|
| 128 | - $slogan = PtoBR(plugin_propre($info['slogan'], "$dir/lang/paquet-$prefix")); |
|
| 129 | - // une seule ligne dans le slogan : couper si besoin |
|
| 130 | - if (($p=strpos($slogan, "<br />"))!==FALSE) |
|
| 131 | - $slogan = substr($slogan, 0,$p); |
|
| 132 | - // couper par securite |
|
| 133 | - $slogan = couper($slogan, 80); |
|
| 134 | - |
|
| 135 | - $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 136 | - |
|
| 137 | - $url = parametre_url($url_page, "plugin", substr($dir,strlen(_DIR_RACINE))); |
|
| 138 | - |
|
| 139 | - if (isset($info['logo']) and $i = trim($info['logo'])) { |
|
| 140 | - include_spip("inc/filtres_images_mini"); |
|
| 141 | - $i = inserer_attribut(image_reduire("$dir/$i", 32),'alt',''); |
|
| 142 | - $i = "<div class='icon'><a href='$url' rel='info'>$i</a></div>"; |
|
| 143 | - } else $i = ''; |
|
| 144 | - |
|
| 145 | - return "<div class='resume'>" |
|
| 146 | - . "<h3><a href='$url' rel='info'>" |
|
| 147 | - . $nom |
|
| 148 | - . "</a></h3>" |
|
| 149 | - . " <span class='version'>".$info['version']."</span>" |
|
| 150 | - . " <span class='etat'> - " |
|
| 151 | - . plugin_etat_en_clair($info['etat']) |
|
| 152 | - . "</span>" |
|
| 153 | - . "<div class='short'>".$slogan."</div>" |
|
| 154 | - . $i |
|
| 155 | - . "</div>"; |
|
| 126 | + $prefix = $info['prefix']; |
|
| 127 | + $dir = "$dir_plugins$plug_file"; |
|
| 128 | + $slogan = PtoBR(plugin_propre($info['slogan'], "$dir/lang/paquet-$prefix")); |
|
| 129 | + // une seule ligne dans le slogan : couper si besoin |
|
| 130 | + if (($p=strpos($slogan, "<br />"))!==FALSE) |
|
| 131 | + $slogan = substr($slogan, 0,$p); |
|
| 132 | + // couper par securite |
|
| 133 | + $slogan = couper($slogan, 80); |
|
| 134 | + |
|
| 135 | + $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 136 | + |
|
| 137 | + $url = parametre_url($url_page, "plugin", substr($dir,strlen(_DIR_RACINE))); |
|
| 138 | + |
|
| 139 | + if (isset($info['logo']) and $i = trim($info['logo'])) { |
|
| 140 | + include_spip("inc/filtres_images_mini"); |
|
| 141 | + $i = inserer_attribut(image_reduire("$dir/$i", 32),'alt',''); |
|
| 142 | + $i = "<div class='icon'><a href='$url' rel='info'>$i</a></div>"; |
|
| 143 | + } else $i = ''; |
|
| 144 | + |
|
| 145 | + return "<div class='resume'>" |
|
| 146 | + . "<h3><a href='$url' rel='info'>" |
|
| 147 | + . $nom |
|
| 148 | + . "</a></h3>" |
|
| 149 | + . " <span class='version'>".$info['version']."</span>" |
|
| 150 | + . " <span class='etat'> - " |
|
| 151 | + . plugin_etat_en_clair($info['etat']) |
|
| 152 | + . "</span>" |
|
| 153 | + . "<div class='short'>".$slogan."</div>" |
|
| 154 | + . $i |
|
| 155 | + . "</div>"; |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | function plugin_desintalle($plug_file, $nom, $dir_plugins=null){ |
| 159 | - if (!$dir_plugins) |
|
| 160 | - $dir_plugins = _DIR_PLUGINS; |
|
| 159 | + if (!$dir_plugins) |
|
| 160 | + $dir_plugins = _DIR_PLUGINS; |
|
| 161 | 161 | |
| 162 | - $action = redirige_action_auteur('desinstaller_plugin',"$dir_plugins::$plug_file",'admin_plugin'); |
|
| 163 | - $text = _T('bouton_desinstaller'); |
|
| 164 | - $text2 = _T('info_desinstaller_plugin'); |
|
| 165 | - $file = basename($plug_file); |
|
| 162 | + $action = redirige_action_auteur('desinstaller_plugin',"$dir_plugins::$plug_file",'admin_plugin'); |
|
| 163 | + $text = _T('bouton_desinstaller'); |
|
| 164 | + $text2 = _T('info_desinstaller_plugin'); |
|
| 165 | + $file = basename($plug_file); |
|
| 166 | 166 | |
| 167 | - return "<div class='actions'>[". |
|
| 168 | - "<a href='$action' |
|
| 167 | + return "<div class='actions'>[". |
|
| 168 | + "<a href='$action' |
|
| 169 | 169 | onclick='return confirm(\"$text $nom ?\\n$text2\")'>" |
| 170 | - . $text |
|
| 171 | - . "</a>]</div>" ; |
|
| 170 | + . $text |
|
| 171 | + . "</a>]</div>" ; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | function plugin_etat_en_clair($etat){ |
| 175 | - if (!in_array($etat,array('stable','test','experimental'))) |
|
| 176 | - $etat = 'developpement'; |
|
| 177 | - return _T('plugin_etat_'.$etat); |
|
| 175 | + if (!in_array($etat,array('stable','test','experimental'))) |
|
| 176 | + $etat = 'developpement'; |
|
| 177 | + return _T('plugin_etat_'.$etat); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | // http://doc.spip.org/@plugin_propre |
| 181 | 181 | function plugin_propre($texte, $module='') { |
| 182 | - // retirer le retour a la racine du module, car le find_in_path se fait depuis la racine |
|
| 183 | - if (_DIR_RACINE AND strncmp($module,_DIR_RACINE,strlen(_DIR_RACINE))==0) |
|
| 184 | - $module = substr($module,strlen(_DIR_RACINE)); |
|
| 185 | - if (preg_match("|^\w+_[\w_]+$|", $texte)) { |
|
| 186 | - $texte = _T(($module ? "$module:" : '') . $texte, array(), array('force' => false)); |
|
| 187 | - } |
|
| 188 | - return propre($texte); |
|
| 182 | + // retirer le retour a la racine du module, car le find_in_path se fait depuis la racine |
|
| 183 | + if (_DIR_RACINE AND strncmp($module,_DIR_RACINE,strlen(_DIR_RACINE))==0) |
|
| 184 | + $module = substr($module,strlen(_DIR_RACINE)); |
|
| 185 | + if (preg_match("|^\w+_[\w_]+$|", $texte)) { |
|
| 186 | + $texte = _T(($module ? "$module:" : '') . $texte, array(), array('force' => false)); |
|
| 187 | + } |
|
| 188 | + return propre($texte); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | |
| 192 | 192 | |
| 193 | 193 | // http://doc.spip.org/@affiche_bloc_plugin |
| 194 | 194 | function affiche_bloc_plugin($plug_file, $info, $dir_plugins=null) { |
| 195 | - if (!$dir_plugins) |
|
| 196 | - $dir_plugins = _DIR_PLUGINS; |
|
| 197 | - |
|
| 198 | - $prefix = $info['prefix']; |
|
| 199 | - $dir = "$dir_plugins$plug_file/lang/paquet-$prefix"; |
|
| 200 | - |
|
| 201 | - $s = ""; |
|
| 202 | - // TODO: le traiter_multi ici n'est pas beau |
|
| 203 | - // cf. description du plugin/_stable_/ortho/plugin.xml |
|
| 204 | - $description = ""; |
|
| 205 | - if (isset($info['description'])) |
|
| 206 | - $description = plugin_propre($info['description'], $dir); |
|
| 207 | - |
|
| 208 | - if (isset($info['documentation']) |
|
| 209 | - AND $lien = $info['documentation']){ |
|
| 210 | - $description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') .'</a></em></p>'; |
|
| 211 | - } |
|
| 212 | - $s .= "<dd class='desc'>".$description."</dd>\n"; |
|
| 213 | - |
|
| 214 | - if (isset($info['auteur'])){ |
|
| 215 | - if (is_array($info['auteur'])) |
|
| 216 | - $a = formater_credits($info['auteur'], ', '); |
|
| 217 | - // pour compat mais ne doit plus arriver |
|
| 218 | - else |
|
| 219 | - $a = trim($info['auteur']); |
|
| 220 | - if ($a) |
|
| 221 | - $s .= "<dt class='auteurs'>" . _T('public:par_auteur') ."</dt><dd class='auteurs'>". PtoBR(propre($a, $dir)) . "</dd>\n"; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - if (isset($info['credit'])){ |
|
| 225 | - if ($a = formater_credits($info['credit'], ', ')) |
|
| 226 | - $s .= "<dt class='credits'>" . _T('plugin_info_credit') ."</dt><dd class='credits'>". PtoBR(propre($a, $dir)) . "</dd>\n"; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - if (isset($info['licence'])) { |
|
| 230 | - if (is_array($info['licence'])) |
|
| 231 | - $a = formater_credits($info['licence'], ', '); |
|
| 232 | - // pour compat mais ne doit plus arriver |
|
| 233 | - else |
|
| 234 | - $a = trim($info['licence']); |
|
| 235 | - if ($a) |
|
| 236 | - $s .= "<dt class='licence'>" . _T('intitule_licence') ."</dt><dd class='licence'>". PtoBR(propre($a, $dir)) . "</dd>\n"; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - $s = "<dl class='description'>$s</dl>"; |
|
| 240 | - |
|
| 241 | - // |
|
| 242 | - // Ajouter les infos techniques |
|
| 243 | - // |
|
| 244 | - $infotech = array(); |
|
| 245 | - |
|
| 246 | - $version = "<dt>"._T('version')."</dt><dd>".$info['version']; |
|
| 247 | - // Version SVN |
|
| 248 | - if ($svn_revision = version_svn_courante($dir_plugins.$plug_file)) |
|
| 249 | - $version .= ($svn_revision<0 ? ' SVN':'').' ['.abs($svn_revision).']'; |
|
| 250 | - $version .="</dd>"; |
|
| 251 | - $infotech[] = $version; |
|
| 252 | - $infotech[] = "<dt>"._T('repertoire_plugins')."</dt><dd>".joli_repertoire("$dir_plugins$plug_file")."</dd>"; |
|
| 253 | - // source zip le cas echeant |
|
| 254 | - $infotech[] = (lire_fichier($dir_plugins.$plug_file.'/install.log', $log) |
|
| 255 | - AND preg_match(',^source:(.*)$,m', $log, $r)) |
|
| 256 | - ? '<dt>'._T('plugin_source').'</dt><dd>'.trim($r[1])."</dd>" |
|
| 257 | - :''; |
|
| 258 | - |
|
| 259 | - $infotech[] = !$info['necessite'] ? '' : |
|
| 260 | - ('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join(' ', array_map('array_shift', $info['necessite'])) . '</dd>'); |
|
| 261 | - |
|
| 262 | - $s .= "<dl class='tech'>" |
|
| 263 | - . join('', $infotech) |
|
| 264 | - ."</dl>"; |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - return $s; |
|
| 195 | + if (!$dir_plugins) |
|
| 196 | + $dir_plugins = _DIR_PLUGINS; |
|
| 197 | + |
|
| 198 | + $prefix = $info['prefix']; |
|
| 199 | + $dir = "$dir_plugins$plug_file/lang/paquet-$prefix"; |
|
| 200 | + |
|
| 201 | + $s = ""; |
|
| 202 | + // TODO: le traiter_multi ici n'est pas beau |
|
| 203 | + // cf. description du plugin/_stable_/ortho/plugin.xml |
|
| 204 | + $description = ""; |
|
| 205 | + if (isset($info['description'])) |
|
| 206 | + $description = plugin_propre($info['description'], $dir); |
|
| 207 | + |
|
| 208 | + if (isset($info['documentation']) |
|
| 209 | + AND $lien = $info['documentation']){ |
|
| 210 | + $description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') .'</a></em></p>'; |
|
| 211 | + } |
|
| 212 | + $s .= "<dd class='desc'>".$description."</dd>\n"; |
|
| 213 | + |
|
| 214 | + if (isset($info['auteur'])){ |
|
| 215 | + if (is_array($info['auteur'])) |
|
| 216 | + $a = formater_credits($info['auteur'], ', '); |
|
| 217 | + // pour compat mais ne doit plus arriver |
|
| 218 | + else |
|
| 219 | + $a = trim($info['auteur']); |
|
| 220 | + if ($a) |
|
| 221 | + $s .= "<dt class='auteurs'>" . _T('public:par_auteur') ."</dt><dd class='auteurs'>". PtoBR(propre($a, $dir)) . "</dd>\n"; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + if (isset($info['credit'])){ |
|
| 225 | + if ($a = formater_credits($info['credit'], ', ')) |
|
| 226 | + $s .= "<dt class='credits'>" . _T('plugin_info_credit') ."</dt><dd class='credits'>". PtoBR(propre($a, $dir)) . "</dd>\n"; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + if (isset($info['licence'])) { |
|
| 230 | + if (is_array($info['licence'])) |
|
| 231 | + $a = formater_credits($info['licence'], ', '); |
|
| 232 | + // pour compat mais ne doit plus arriver |
|
| 233 | + else |
|
| 234 | + $a = trim($info['licence']); |
|
| 235 | + if ($a) |
|
| 236 | + $s .= "<dt class='licence'>" . _T('intitule_licence') ."</dt><dd class='licence'>". PtoBR(propre($a, $dir)) . "</dd>\n"; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + $s = "<dl class='description'>$s</dl>"; |
|
| 240 | + |
|
| 241 | + // |
|
| 242 | + // Ajouter les infos techniques |
|
| 243 | + // |
|
| 244 | + $infotech = array(); |
|
| 245 | + |
|
| 246 | + $version = "<dt>"._T('version')."</dt><dd>".$info['version']; |
|
| 247 | + // Version SVN |
|
| 248 | + if ($svn_revision = version_svn_courante($dir_plugins.$plug_file)) |
|
| 249 | + $version .= ($svn_revision<0 ? ' SVN':'').' ['.abs($svn_revision).']'; |
|
| 250 | + $version .="</dd>"; |
|
| 251 | + $infotech[] = $version; |
|
| 252 | + $infotech[] = "<dt>"._T('repertoire_plugins')."</dt><dd>".joli_repertoire("$dir_plugins$plug_file")."</dd>"; |
|
| 253 | + // source zip le cas echeant |
|
| 254 | + $infotech[] = (lire_fichier($dir_plugins.$plug_file.'/install.log', $log) |
|
| 255 | + AND preg_match(',^source:(.*)$,m', $log, $r)) |
|
| 256 | + ? '<dt>'._T('plugin_source').'</dt><dd>'.trim($r[1])."</dd>" |
|
| 257 | + :''; |
|
| 258 | + |
|
| 259 | + $infotech[] = !$info['necessite'] ? '' : |
|
| 260 | + ('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join(' ', array_map('array_shift', $info['necessite'])) . '</dd>'); |
|
| 261 | + |
|
| 262 | + $s .= "<dl class='tech'>" |
|
| 263 | + . join('', $infotech) |
|
| 264 | + ."</dl>"; |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + return $s; |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | function formater_credits($infos, $sep=', ') { |
| 271 | - $texte = ''; |
|
| 272 | - |
|
| 273 | - foreach ($infos as $_credit) { |
|
| 274 | - if ($texte) |
|
| 275 | - $texte .= $sep; |
|
| 276 | - // Si le credit en cours n'est pas un array c'est donc un copyright |
|
| 277 | - $texte .= |
|
| 278 | - (!is_array($_credit)) |
|
| 279 | - ? PtoBR(propre($_credit)) |
|
| 280 | - : ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') . |
|
| 281 | - $_credit['nom'] . |
|
| 282 | - ($_credit['url'] ? '</a>' : ''); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - return $texte; |
|
| 271 | + $texte = ''; |
|
| 272 | + |
|
| 273 | + foreach ($infos as $_credit) { |
|
| 274 | + if ($texte) |
|
| 275 | + $texte .= $sep; |
|
| 276 | + // Si le credit en cours n'est pas un array c'est donc un copyright |
|
| 277 | + $texte .= |
|
| 278 | + (!is_array($_credit)) |
|
| 279 | + ? PtoBR(propre($_credit)) |
|
| 280 | + : ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') . |
|
| 281 | + $_credit['nom'] . |
|
| 282 | + ($_credit['url'] ? '</a>' : ''); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + return $texte; |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | ?> |
@@ -16,51 +16,51 @@ discard block |
||
| 16 | 16 | include_spip('inc/plugin'); // pour plugin_est_installe |
| 17 | 17 | |
| 18 | 18 | // http://doc.spip.org/@ligne_plug |
| 19 | -function plugins_afficher_plugin_dist($url_page, $plug_file, $checked, $actif, $expose=false, $class_li="item", $dir_plugins=_DIR_PLUGINS) { |
|
| 19 | +function plugins_afficher_plugin_dist($url_page, $plug_file, $checked, $actif, $expose = false, $class_li = "item", $dir_plugins = _DIR_PLUGINS) { |
|
| 20 | 20 | |
| 21 | 21 | static $id_input = 0; |
| 22 | 22 | static $versions = array(); |
| 23 | 23 | |
| 24 | - $force_reload = (_request('var_mode')=='recalcul'); |
|
| 25 | - $get_infos = charger_fonction('get_infos','plugins'); |
|
| 24 | + $force_reload = (_request('var_mode') == 'recalcul'); |
|
| 25 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 26 | 26 | $info = $get_infos($plug_file, $force_reload, $dir_plugins); |
| 27 | 27 | $prefix = $info['prefix']; |
| 28 | 28 | $cfg = ""; |
| 29 | - $checkable = ($dir_plugins!==_DIR_PLUGINS_DIST); |
|
| 30 | - $nom = plugin_nom($info,$dir_plugins,$plug_file); |
|
| 29 | + $checkable = ($dir_plugins !== _DIR_PLUGINS_DIST); |
|
| 30 | + $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 31 | 31 | |
| 32 | - if (!plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'],'spip')){ |
|
| 32 | + if (!plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 33 | 33 | $info['slogan'] = _T('plugin_info_non_compatible_spip'); |
| 34 | - $erreur = http_img_pack("plugin-dis-32.png",_T('plugin_info_non_compatible_spip')," class='picto_err'",_T('plugin_info_non_compatible_spip')); |
|
| 34 | + $erreur = http_img_pack("plugin-dis-32.png", _T('plugin_info_non_compatible_spip'), " class='picto_err'", _T('plugin_info_non_compatible_spip')); |
|
| 35 | 35 | $class_li .= " disabled"; |
| 36 | 36 | $checkable = false; |
| 37 | 37 | } |
| 38 | 38 | elseif (isset($info['erreur'])) { |
| 39 | 39 | $class_li .= " error"; |
| 40 | - $erreur = http_img_pack("plugin-err-32.png",_T('plugin_info_erreur_xml')," class='picto_err'",_T('plugin_info_erreur_xml')) |
|
| 41 | - . "<div class='erreur'>" . join('<br >', $info['erreur']) . "</div>"; |
|
| 40 | + $erreur = http_img_pack("plugin-err-32.png", _T('plugin_info_erreur_xml'), " class='picto_err'", _T('plugin_info_erreur_xml')) |
|
| 41 | + . "<div class='erreur'>".join('<br >', $info['erreur'])."</div>"; |
|
| 42 | 42 | $checkable = false; |
| 43 | 43 | } |
| 44 | - elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins.$plug_file])){ |
|
| 44 | + elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins.$plug_file])) { |
|
| 45 | 45 | $class_li .= " error"; |
| 46 | - $erreur = http_img_pack("plugin-err-32.png",_T('plugin_impossible_activer', array('plugin' => $nom))," class='picto_err'",_T('plugin_impossible_activer', array('plugin' => $nom))) |
|
| 47 | - . "<div class='erreur'>" . implode("<br />",$GLOBALS['erreurs_activation_raw'][$dir_plugins.$plug_file]) . "</div>"; |
|
| 46 | + $erreur = http_img_pack("plugin-err-32.png", _T('plugin_impossible_activer', array('plugin' => $nom)), " class='picto_err'", _T('plugin_impossible_activer', array('plugin' => $nom))) |
|
| 47 | + . "<div class='erreur'>".implode("<br />", $GLOBALS['erreurs_activation_raw'][$dir_plugins.$plug_file])."</div>"; |
|
| 48 | 48 | } |
| 49 | 49 | else |
| 50 | - $cfg = $actif ? plugin_bouton_config($plug_file,$info,$dir_plugins) : ""; |
|
| 50 | + $cfg = $actif ? plugin_bouton_config($plug_file, $info, $dir_plugins) : ""; |
|
| 51 | 51 | |
| 52 | 52 | // numerotons les occurrences d'un meme prefix |
| 53 | 53 | $versions[$prefix] = $id = isset($versions[$prefix]) ? $versions[$prefix] + 1 : ''; |
| 54 | 54 | |
| 55 | - $class_li .= ($actif?" actif":"") . ($expose?" on":""); |
|
| 55 | + $class_li .= ($actif ? " actif" : "").($expose ? " on" : ""); |
|
| 56 | 56 | return "<li id='$prefix$id' class='$class_li'>" |
| 57 | 57 | . ((!$checkable AND !$checked) |
| 58 | - ? '': plugin_checkbox(++$id_input, $dir_plugins.$plug_file, $checked)) |
|
| 58 | + ? '' : plugin_checkbox(++$id_input, $dir_plugins.$plug_file, $checked)) |
|
| 59 | 59 | . plugin_resume($info, $dir_plugins, $plug_file, $url_page) |
| 60 | 60 | . $cfg |
| 61 | 61 | . $erreur |
| 62 | - . (($dir_plugins!==_DIR_PLUGINS_DIST AND plugin_est_installe($plug_file)) |
|
| 63 | - ? plugin_desintalle($plug_file,$nom,$dir_plugins) : '') |
|
| 62 | + . (($dir_plugins !== _DIR_PLUGINS_DIST AND plugin_est_installe($plug_file)) |
|
| 63 | + ? plugin_desintalle($plug_file, $nom, $dir_plugins) : '') |
|
| 64 | 64 | . "<div class='details'>" // pour l'ajax de exec/info_plugin |
| 65 | 65 | . (!$expose ? '' : affiche_bloc_plugin($plug_file, $info, $dir_plugins)) |
| 66 | 66 | . "</div>" |
@@ -74,12 +74,12 @@ discard block |
||
| 74 | 74 | $prefix = strtolower($infos['prefix']); |
| 75 | 75 | // si plugin.xml fournit un squelette, le prendre |
| 76 | 76 | if ($infos['config']) |
| 77 | - return recuperer_fond("$dir$nom/" . $infos['config'], |
|
| 78 | - array('script' => 'configurer_' . $prefix, |
|
| 77 | + return recuperer_fond("$dir$nom/".$infos['config'], |
|
| 78 | + array('script' => 'configurer_'.$prefix, |
|
| 79 | 79 | 'nom' => $nom)); |
| 80 | 80 | |
| 81 | 81 | // si le plugin CFG est la, l'essayer |
| 82 | - if (defined('_DIR_PLUGIN_CFG')) { |
|
| 82 | + if (defined('_DIR_PLUGIN_CFG')) { |
|
| 83 | 83 | if (include_spip('inc/cfg')) // test CFG version >= 1.0.5 |
| 84 | 84 | if ($cfg = icone_lien_cfg("$dir$nom", "cfg")) |
| 85 | 85 | return "<div class='cfg_link'>$cfg</div>"; |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | |
| 88 | 88 | // sinon prendre le squelette std sur le nom std |
| 89 | 89 | return recuperer_fond("prive/squelettes/inclure/cfg", |
| 90 | - array('script' => 'configurer_' . $prefix, |
|
| 90 | + array('script' => 'configurer_'.$prefix, |
|
| 91 | 91 | 'nom' => $nom)); |
| 92 | 92 | } |
| 93 | 93 | |
@@ -96,17 +96,17 @@ discard block |
||
| 96 | 96 | |
| 97 | 97 | function plugin_checkbox($id_input, $file, $actif) |
| 98 | 98 | { |
| 99 | - $name = substr(md5($file),0,16); |
|
| 99 | + $name = substr(md5($file), 0, 16); |
|
| 100 | 100 | |
| 101 | 101 | return "<div class='check'>\n" |
| 102 | 102 | . "<input type='checkbox' name='s$name' id='label_$id_input'" |
| 103 | - . ($actif?" checked='checked'":"") |
|
| 103 | + . ($actif ? " checked='checked'" : "") |
|
| 104 | 104 | . " class='checkbox' value='O' />" |
| 105 | 105 | . "\n<label for='label_$id_input'>"._T('activer_plugin')."</label>" |
| 106 | 106 | . "</div>"; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | -function plugin_nom($info, $dir_plugins, $plug_file){ |
|
| 109 | +function plugin_nom($info, $dir_plugins, $plug_file) { |
|
| 110 | 110 | $prefix = $info['prefix']; |
| 111 | 111 | $dir = "$dir_plugins$plug_file"; |
| 112 | 112 | // Si dtd paquet, on traite le nom soit par son item de langue soit par sa valeur immediate a l'index "nom" |
@@ -122,23 +122,23 @@ discard block |
||
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | // Cartouche Resume |
| 125 | -function plugin_resume($info, $dir_plugins, $plug_file, $url_page){ |
|
| 125 | +function plugin_resume($info, $dir_plugins, $plug_file, $url_page) { |
|
| 126 | 126 | $prefix = $info['prefix']; |
| 127 | 127 | $dir = "$dir_plugins$plug_file"; |
| 128 | 128 | $slogan = PtoBR(plugin_propre($info['slogan'], "$dir/lang/paquet-$prefix")); |
| 129 | 129 | // une seule ligne dans le slogan : couper si besoin |
| 130 | - if (($p=strpos($slogan, "<br />"))!==FALSE) |
|
| 131 | - $slogan = substr($slogan, 0,$p); |
|
| 130 | + if (($p = strpos($slogan, "<br />")) !== FALSE) |
|
| 131 | + $slogan = substr($slogan, 0, $p); |
|
| 132 | 132 | // couper par securite |
| 133 | 133 | $slogan = couper($slogan, 80); |
| 134 | 134 | |
| 135 | 135 | $nom = plugin_nom($info, $dir_plugins, $plug_file); |
| 136 | 136 | |
| 137 | - $url = parametre_url($url_page, "plugin", substr($dir,strlen(_DIR_RACINE))); |
|
| 137 | + $url = parametre_url($url_page, "plugin", substr($dir, strlen(_DIR_RACINE))); |
|
| 138 | 138 | |
| 139 | 139 | if (isset($info['logo']) and $i = trim($info['logo'])) { |
| 140 | 140 | include_spip("inc/filtres_images_mini"); |
| 141 | - $i = inserer_attribut(image_reduire("$dir/$i", 32),'alt',''); |
|
| 141 | + $i = inserer_attribut(image_reduire("$dir/$i", 32), 'alt', ''); |
|
| 142 | 142 | $i = "<div class='icon'><a href='$url' rel='info'>$i</a></div>"; |
| 143 | 143 | } else $i = ''; |
| 144 | 144 | |
@@ -155,11 +155,11 @@ discard block |
||
| 155 | 155 | . "</div>"; |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | -function plugin_desintalle($plug_file, $nom, $dir_plugins=null){ |
|
| 158 | +function plugin_desintalle($plug_file, $nom, $dir_plugins = null) { |
|
| 159 | 159 | if (!$dir_plugins) |
| 160 | 160 | $dir_plugins = _DIR_PLUGINS; |
| 161 | 161 | |
| 162 | - $action = redirige_action_auteur('desinstaller_plugin',"$dir_plugins::$plug_file",'admin_plugin'); |
|
| 162 | + $action = redirige_action_auteur('desinstaller_plugin', "$dir_plugins::$plug_file", 'admin_plugin'); |
|
| 163 | 163 | $text = _T('bouton_desinstaller'); |
| 164 | 164 | $text2 = _T('info_desinstaller_plugin'); |
| 165 | 165 | $file = basename($plug_file); |
@@ -168,22 +168,22 @@ discard block |
||
| 168 | 168 | "<a href='$action' |
| 169 | 169 | onclick='return confirm(\"$text $nom ?\\n$text2\")'>" |
| 170 | 170 | . $text |
| 171 | - . "</a>]</div>" ; |
|
| 171 | + . "</a>]</div>"; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | -function plugin_etat_en_clair($etat){ |
|
| 175 | - if (!in_array($etat,array('stable','test','experimental'))) |
|
| 174 | +function plugin_etat_en_clair($etat) { |
|
| 175 | + if (!in_array($etat, array('stable', 'test', 'experimental'))) |
|
| 176 | 176 | $etat = 'developpement'; |
| 177 | 177 | return _T('plugin_etat_'.$etat); |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | // http://doc.spip.org/@plugin_propre |
| 181 | -function plugin_propre($texte, $module='') { |
|
| 181 | +function plugin_propre($texte, $module = '') { |
|
| 182 | 182 | // retirer le retour a la racine du module, car le find_in_path se fait depuis la racine |
| 183 | - if (_DIR_RACINE AND strncmp($module,_DIR_RACINE,strlen(_DIR_RACINE))==0) |
|
| 184 | - $module = substr($module,strlen(_DIR_RACINE)); |
|
| 183 | + if (_DIR_RACINE AND strncmp($module, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) |
|
| 184 | + $module = substr($module, strlen(_DIR_RACINE)); |
|
| 185 | 185 | if (preg_match("|^\w+_[\w_]+$|", $texte)) { |
| 186 | - $texte = _T(($module ? "$module:" : '') . $texte, array(), array('force' => false)); |
|
| 186 | + $texte = _T(($module ? "$module:" : '').$texte, array(), array('force' => false)); |
|
| 187 | 187 | } |
| 188 | 188 | return propre($texte); |
| 189 | 189 | } |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | |
| 192 | 192 | |
| 193 | 193 | // http://doc.spip.org/@affiche_bloc_plugin |
| 194 | -function affiche_bloc_plugin($plug_file, $info, $dir_plugins=null) { |
|
| 194 | +function affiche_bloc_plugin($plug_file, $info, $dir_plugins = null) { |
|
| 195 | 195 | if (!$dir_plugins) |
| 196 | 196 | $dir_plugins = _DIR_PLUGINS; |
| 197 | 197 | |
@@ -206,24 +206,24 @@ discard block |
||
| 206 | 206 | $description = plugin_propre($info['description'], $dir); |
| 207 | 207 | |
| 208 | 208 | if (isset($info['documentation']) |
| 209 | - AND $lien = $info['documentation']){ |
|
| 210 | - $description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') .'</a></em></p>'; |
|
| 209 | + AND $lien = $info['documentation']) { |
|
| 210 | + $description .= "<p><em class='site'><a href='$lien' class='spip_out'>"._T('en_savoir_plus').'</a></em></p>'; |
|
| 211 | 211 | } |
| 212 | 212 | $s .= "<dd class='desc'>".$description."</dd>\n"; |
| 213 | 213 | |
| 214 | - if (isset($info['auteur'])){ |
|
| 214 | + if (isset($info['auteur'])) { |
|
| 215 | 215 | if (is_array($info['auteur'])) |
| 216 | 216 | $a = formater_credits($info['auteur'], ', '); |
| 217 | 217 | // pour compat mais ne doit plus arriver |
| 218 | 218 | else |
| 219 | 219 | $a = trim($info['auteur']); |
| 220 | 220 | if ($a) |
| 221 | - $s .= "<dt class='auteurs'>" . _T('public:par_auteur') ."</dt><dd class='auteurs'>". PtoBR(propre($a, $dir)) . "</dd>\n"; |
|
| 221 | + $s .= "<dt class='auteurs'>"._T('public:par_auteur')."</dt><dd class='auteurs'>".PtoBR(propre($a, $dir))."</dd>\n"; |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - if (isset($info['credit'])){ |
|
| 224 | + if (isset($info['credit'])) { |
|
| 225 | 225 | if ($a = formater_credits($info['credit'], ', ')) |
| 226 | - $s .= "<dt class='credits'>" . _T('plugin_info_credit') ."</dt><dd class='credits'>". PtoBR(propre($a, $dir)) . "</dd>\n"; |
|
| 226 | + $s .= "<dt class='credits'>"._T('plugin_info_credit')."</dt><dd class='credits'>".PtoBR(propre($a, $dir))."</dd>\n"; |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | if (isset($info['licence'])) { |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | else |
| 234 | 234 | $a = trim($info['licence']); |
| 235 | 235 | if ($a) |
| 236 | - $s .= "<dt class='licence'>" . _T('intitule_licence') ."</dt><dd class='licence'>". PtoBR(propre($a, $dir)) . "</dd>\n"; |
|
| 236 | + $s .= "<dt class='licence'>"._T('intitule_licence')."</dt><dd class='licence'>".PtoBR(propre($a, $dir))."</dd>\n"; |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | $s = "<dl class='description'>$s</dl>"; |
@@ -246,8 +246,8 @@ discard block |
||
| 246 | 246 | $version = "<dt>"._T('version')."</dt><dd>".$info['version']; |
| 247 | 247 | // Version SVN |
| 248 | 248 | if ($svn_revision = version_svn_courante($dir_plugins.$plug_file)) |
| 249 | - $version .= ($svn_revision<0 ? ' SVN':'').' ['.abs($svn_revision).']'; |
|
| 250 | - $version .="</dd>"; |
|
| 249 | + $version .= ($svn_revision < 0 ? ' SVN' : '').' ['.abs($svn_revision).']'; |
|
| 250 | + $version .= "</dd>"; |
|
| 251 | 251 | $infotech[] = $version; |
| 252 | 252 | $infotech[] = "<dt>"._T('repertoire_plugins')."</dt><dd>".joli_repertoire("$dir_plugins$plug_file")."</dd>"; |
| 253 | 253 | // source zip le cas echeant |
@@ -256,8 +256,7 @@ discard block |
||
| 256 | 256 | ? '<dt>'._T('plugin_source').'</dt><dd>'.trim($r[1])."</dd>" |
| 257 | 257 | :''; |
| 258 | 258 | |
| 259 | - $infotech[] = !$info['necessite'] ? '' : |
|
| 260 | - ('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join(' ', array_map('array_shift', $info['necessite'])) . '</dd>'); |
|
| 259 | + $infotech[] = !$info['necessite'] ? '' : ('<dt>'._T('plugin_info_necessite').'</dt><dd>'.join(' ', array_map('array_shift', $info['necessite'])).'</dd>'); |
|
| 261 | 260 | |
| 262 | 261 | $s .= "<dl class='tech'>" |
| 263 | 262 | . join('', $infotech) |
@@ -267,7 +266,7 @@ discard block |
||
| 267 | 266 | return $s; |
| 268 | 267 | } |
| 269 | 268 | |
| 270 | -function formater_credits($infos, $sep=', ') { |
|
| 269 | +function formater_credits($infos, $sep = ', ') { |
|
| 271 | 270 | $texte = ''; |
| 272 | 271 | |
| 273 | 272 | foreach ($infos as $_credit) { |
@@ -277,8 +276,8 @@ discard block |
||
| 277 | 276 | $texte .= |
| 278 | 277 | (!is_array($_credit)) |
| 279 | 278 | ? PtoBR(propre($_credit)) |
| 280 | - : ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') . |
|
| 281 | - $_credit['nom'] . |
|
| 279 | + : ($_credit['url'] ? '<a href="'.$_credit['url'].'">' : ''). |
|
| 280 | + $_credit['nom']. |
|
| 282 | 281 | ($_credit['url'] ? '</a>' : ''); |
| 283 | 282 | } |
| 284 | 283 | |
@@ -10,7 +10,9 @@ discard block |
||
| 10 | 10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 13 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 14 | + return; |
|
| 15 | +} |
|
| 14 | 16 | include_spip('inc/charsets'); |
| 15 | 17 | include_spip('inc/texte'); |
| 16 | 18 | include_spip('inc/plugin'); // pour plugin_est_installe |
@@ -34,20 +36,18 @@ discard block |
||
| 34 | 36 | $erreur = http_img_pack("plugin-dis-32.png",_T('plugin_info_non_compatible_spip')," class='picto_err'",_T('plugin_info_non_compatible_spip')); |
| 35 | 37 | $class_li .= " disabled"; |
| 36 | 38 | $checkable = false; |
| 37 | - } |
|
| 38 | - elseif (isset($info['erreur'])) { |
|
| 39 | + } elseif (isset($info['erreur'])) { |
|
| 39 | 40 | $class_li .= " error"; |
| 40 | 41 | $erreur = http_img_pack("plugin-err-32.png",_T('plugin_info_erreur_xml')," class='picto_err'",_T('plugin_info_erreur_xml')) |
| 41 | 42 | . "<div class='erreur'>" . join('<br >', $info['erreur']) . "</div>"; |
| 42 | 43 | $checkable = false; |
| 43 | - } |
|
| 44 | - elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins.$plug_file])){ |
|
| 44 | + } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins.$plug_file])){ |
|
| 45 | 45 | $class_li .= " error"; |
| 46 | 46 | $erreur = http_img_pack("plugin-err-32.png",_T('plugin_impossible_activer', array('plugin' => $nom))," class='picto_err'",_T('plugin_impossible_activer', array('plugin' => $nom))) |
| 47 | 47 | . "<div class='erreur'>" . implode("<br />",$GLOBALS['erreurs_activation_raw'][$dir_plugins.$plug_file]) . "</div>"; |
| 48 | + } else { |
|
| 49 | + $cfg = $actif ? plugin_bouton_config($plug_file,$info,$dir_plugins) : ""; |
|
| 48 | 50 | } |
| 49 | - else |
|
| 50 | - $cfg = $actif ? plugin_bouton_config($plug_file,$info,$dir_plugins) : ""; |
|
| 51 | 51 | |
| 52 | 52 | // numerotons les occurrences d'un meme prefix |
| 53 | 53 | $versions[$prefix] = $id = isset($versions[$prefix]) ? $versions[$prefix] + 1 : ''; |
@@ -73,16 +73,19 @@ discard block |
||
| 73 | 73 | // il faut donc n'utiliser que des minuscules, par convention |
| 74 | 74 | $prefix = strtolower($infos['prefix']); |
| 75 | 75 | // si plugin.xml fournit un squelette, le prendre |
| 76 | - if ($infos['config']) |
|
| 77 | - return recuperer_fond("$dir$nom/" . $infos['config'], |
|
| 76 | + if ($infos['config']) { |
|
| 77 | + return recuperer_fond("$dir$nom/" . $infos['config'], |
|
| 78 | 78 | array('script' => 'configurer_' . $prefix, |
| 79 | 79 | 'nom' => $nom)); |
| 80 | + } |
|
| 80 | 81 | |
| 81 | 82 | // si le plugin CFG est la, l'essayer |
| 82 | 83 | if (defined('_DIR_PLUGIN_CFG')) { |
| 83 | - if (include_spip('inc/cfg')) // test CFG version >= 1.0.5 |
|
| 84 | + if (include_spip('inc/cfg')) { |
|
| 85 | + // test CFG version >= 1.0.5 |
|
| 84 | 86 | if ($cfg = icone_lien_cfg("$dir$nom", "cfg")) |
| 85 | 87 | return "<div class='cfg_link'>$cfg</div>"; |
| 88 | + } |
|
| 86 | 89 | } |
| 87 | 90 | |
| 88 | 91 | // sinon prendre le squelette std sur le nom std |
@@ -112,11 +115,12 @@ discard block |
||
| 112 | 115 | // Si dtd paquet, on traite le nom soit par son item de langue soit par sa valeur immediate a l'index "nom" |
| 113 | 116 | if ($info['dtd'] == "paquet") { |
| 114 | 117 | $nom = PtoBR(plugin_propre("{$prefix}_nom", "$dir/lang/paquet-$prefix")); |
| 115 | - if (!$nom) |
|
| 116 | - $nom = PtoBR(propre($info['nom'])); |
|
| 118 | + if (!$nom) { |
|
| 119 | + $nom = PtoBR(propre($info['nom'])); |
|
| 120 | + } |
|
| 121 | + } else { |
|
| 122 | + $nom = typo(attribut_html($info['nom'])); |
|
| 117 | 123 | } |
| 118 | - else |
|
| 119 | - $nom = typo(attribut_html($info['nom'])); |
|
| 120 | 124 | |
| 121 | 125 | return trim($nom); |
| 122 | 126 | } |
@@ -127,8 +131,9 @@ discard block |
||
| 127 | 131 | $dir = "$dir_plugins$plug_file"; |
| 128 | 132 | $slogan = PtoBR(plugin_propre($info['slogan'], "$dir/lang/paquet-$prefix")); |
| 129 | 133 | // une seule ligne dans le slogan : couper si besoin |
| 130 | - if (($p=strpos($slogan, "<br />"))!==FALSE) |
|
| 131 | - $slogan = substr($slogan, 0,$p); |
|
| 134 | + if (($p=strpos($slogan, "<br />"))!==FALSE) { |
|
| 135 | + $slogan = substr($slogan, 0,$p); |
|
| 136 | + } |
|
| 132 | 137 | // couper par securite |
| 133 | 138 | $slogan = couper($slogan, 80); |
| 134 | 139 | |
@@ -140,7 +145,9 @@ discard block |
||
| 140 | 145 | include_spip("inc/filtres_images_mini"); |
| 141 | 146 | $i = inserer_attribut(image_reduire("$dir/$i", 32),'alt',''); |
| 142 | 147 | $i = "<div class='icon'><a href='$url' rel='info'>$i</a></div>"; |
| 143 | - } else $i = ''; |
|
| 148 | + } else { |
|
| 149 | + $i = ''; |
|
| 150 | + } |
|
| 144 | 151 | |
| 145 | 152 | return "<div class='resume'>" |
| 146 | 153 | . "<h3><a href='$url' rel='info'>" |
@@ -156,8 +163,9 @@ discard block |
||
| 156 | 163 | } |
| 157 | 164 | |
| 158 | 165 | function plugin_desintalle($plug_file, $nom, $dir_plugins=null){ |
| 159 | - if (!$dir_plugins) |
|
| 160 | - $dir_plugins = _DIR_PLUGINS; |
|
| 166 | + if (!$dir_plugins) { |
|
| 167 | + $dir_plugins = _DIR_PLUGINS; |
|
| 168 | + } |
|
| 161 | 169 | |
| 162 | 170 | $action = redirige_action_auteur('desinstaller_plugin',"$dir_plugins::$plug_file",'admin_plugin'); |
| 163 | 171 | $text = _T('bouton_desinstaller'); |
@@ -172,16 +180,18 @@ discard block |
||
| 172 | 180 | } |
| 173 | 181 | |
| 174 | 182 | function plugin_etat_en_clair($etat){ |
| 175 | - if (!in_array($etat,array('stable','test','experimental'))) |
|
| 176 | - $etat = 'developpement'; |
|
| 183 | + if (!in_array($etat,array('stable','test','experimental'))) { |
|
| 184 | + $etat = 'developpement'; |
|
| 185 | + } |
|
| 177 | 186 | return _T('plugin_etat_'.$etat); |
| 178 | 187 | } |
| 179 | 188 | |
| 180 | 189 | // http://doc.spip.org/@plugin_propre |
| 181 | 190 | function plugin_propre($texte, $module='') { |
| 182 | 191 | // retirer le retour a la racine du module, car le find_in_path se fait depuis la racine |
| 183 | - if (_DIR_RACINE AND strncmp($module,_DIR_RACINE,strlen(_DIR_RACINE))==0) |
|
| 184 | - $module = substr($module,strlen(_DIR_RACINE)); |
|
| 192 | + if (_DIR_RACINE AND strncmp($module,_DIR_RACINE,strlen(_DIR_RACINE))==0) { |
|
| 193 | + $module = substr($module,strlen(_DIR_RACINE)); |
|
| 194 | + } |
|
| 185 | 195 | if (preg_match("|^\w+_[\w_]+$|", $texte)) { |
| 186 | 196 | $texte = _T(($module ? "$module:" : '') . $texte, array(), array('force' => false)); |
| 187 | 197 | } |
@@ -192,8 +202,9 @@ discard block |
||
| 192 | 202 | |
| 193 | 203 | // http://doc.spip.org/@affiche_bloc_plugin |
| 194 | 204 | function affiche_bloc_plugin($plug_file, $info, $dir_plugins=null) { |
| 195 | - if (!$dir_plugins) |
|
| 196 | - $dir_plugins = _DIR_PLUGINS; |
|
| 205 | + if (!$dir_plugins) { |
|
| 206 | + $dir_plugins = _DIR_PLUGINS; |
|
| 207 | + } |
|
| 197 | 208 | |
| 198 | 209 | $prefix = $info['prefix']; |
| 199 | 210 | $dir = "$dir_plugins$plug_file/lang/paquet-$prefix"; |
@@ -202,8 +213,9 @@ discard block |
||
| 202 | 213 | // TODO: le traiter_multi ici n'est pas beau |
| 203 | 214 | // cf. description du plugin/_stable_/ortho/plugin.xml |
| 204 | 215 | $description = ""; |
| 205 | - if (isset($info['description'])) |
|
| 206 | - $description = plugin_propre($info['description'], $dir); |
|
| 216 | + if (isset($info['description'])) { |
|
| 217 | + $description = plugin_propre($info['description'], $dir); |
|
| 218 | + } |
|
| 207 | 219 | |
| 208 | 220 | if (isset($info['documentation']) |
| 209 | 221 | AND $lien = $info['documentation']){ |
@@ -212,28 +224,35 @@ discard block |
||
| 212 | 224 | $s .= "<dd class='desc'>".$description."</dd>\n"; |
| 213 | 225 | |
| 214 | 226 | if (isset($info['auteur'])){ |
| 215 | - if (is_array($info['auteur'])) |
|
| 216 | - $a = formater_credits($info['auteur'], ', '); |
|
| 227 | + if (is_array($info['auteur'])) { |
|
| 228 | + $a = formater_credits($info['auteur'], ', '); |
|
| 229 | + } |
|
| 217 | 230 | // pour compat mais ne doit plus arriver |
| 218 | - else |
|
| 219 | - $a = trim($info['auteur']); |
|
| 220 | - if ($a) |
|
| 221 | - $s .= "<dt class='auteurs'>" . _T('public:par_auteur') ."</dt><dd class='auteurs'>". PtoBR(propre($a, $dir)) . "</dd>\n"; |
|
| 231 | + else { |
|
| 232 | + $a = trim($info['auteur']); |
|
| 233 | + } |
|
| 234 | + if ($a) { |
|
| 235 | + $s .= "<dt class='auteurs'>" . _T('public:par_auteur') ."</dt><dd class='auteurs'>". PtoBR(propre($a, $dir)) . "</dd>\n"; |
|
| 236 | + } |
|
| 222 | 237 | } |
| 223 | 238 | |
| 224 | 239 | if (isset($info['credit'])){ |
| 225 | - if ($a = formater_credits($info['credit'], ', ')) |
|
| 226 | - $s .= "<dt class='credits'>" . _T('plugin_info_credit') ."</dt><dd class='credits'>". PtoBR(propre($a, $dir)) . "</dd>\n"; |
|
| 240 | + if ($a = formater_credits($info['credit'], ', ')) { |
|
| 241 | + $s .= "<dt class='credits'>" . _T('plugin_info_credit') ."</dt><dd class='credits'>". PtoBR(propre($a, $dir)) . "</dd>\n"; |
|
| 242 | + } |
|
| 227 | 243 | } |
| 228 | 244 | |
| 229 | 245 | if (isset($info['licence'])) { |
| 230 | - if (is_array($info['licence'])) |
|
| 231 | - $a = formater_credits($info['licence'], ', '); |
|
| 246 | + if (is_array($info['licence'])) { |
|
| 247 | + $a = formater_credits($info['licence'], ', '); |
|
| 248 | + } |
|
| 232 | 249 | // pour compat mais ne doit plus arriver |
| 233 | - else |
|
| 234 | - $a = trim($info['licence']); |
|
| 235 | - if ($a) |
|
| 236 | - $s .= "<dt class='licence'>" . _T('intitule_licence') ."</dt><dd class='licence'>". PtoBR(propre($a, $dir)) . "</dd>\n"; |
|
| 250 | + else { |
|
| 251 | + $a = trim($info['licence']); |
|
| 252 | + } |
|
| 253 | + if ($a) { |
|
| 254 | + $s .= "<dt class='licence'>" . _T('intitule_licence') ."</dt><dd class='licence'>". PtoBR(propre($a, $dir)) . "</dd>\n"; |
|
| 255 | + } |
|
| 237 | 256 | } |
| 238 | 257 | |
| 239 | 258 | $s = "<dl class='description'>$s</dl>"; |
@@ -245,8 +264,9 @@ discard block |
||
| 245 | 264 | |
| 246 | 265 | $version = "<dt>"._T('version')."</dt><dd>".$info['version']; |
| 247 | 266 | // Version SVN |
| 248 | - if ($svn_revision = version_svn_courante($dir_plugins.$plug_file)) |
|
| 249 | - $version .= ($svn_revision<0 ? ' SVN':'').' ['.abs($svn_revision).']'; |
|
| 267 | + if ($svn_revision = version_svn_courante($dir_plugins.$plug_file)) { |
|
| 268 | + $version .= ($svn_revision<0 ? ' SVN':'').' ['.abs($svn_revision).']'; |
|
| 269 | + } |
|
| 250 | 270 | $version .="</dd>"; |
| 251 | 271 | $infotech[] = $version; |
| 252 | 272 | $infotech[] = "<dt>"._T('repertoire_plugins')."</dt><dd>".joli_repertoire("$dir_plugins$plug_file")."</dd>"; |
@@ -271,8 +291,9 @@ discard block |
||
| 271 | 291 | $texte = ''; |
| 272 | 292 | |
| 273 | 293 | foreach ($infos as $_credit) { |
| 274 | - if ($texte) |
|
| 275 | - $texte .= $sep; |
|
| 294 | + if ($texte) { |
|
| 295 | + $texte .= $sep; |
|
| 296 | + } |
|
| 276 | 297 | // Si le credit en cours n'est pas un array c'est donc un copyright |
| 277 | 298 | $texte .= |
| 278 | 299 | (!is_array($_credit)) |
@@ -412,6 +412,10 @@ |
||
| 412 | 412 | * aller a la position $n en parcourant |
| 413 | 413 | * un par un tous les elements |
| 414 | 414 | */ |
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * @param integer $n |
|
| 418 | + */ |
|
| 415 | 419 | private function seek_loop($n) { |
| 416 | 420 | if ($this->pos > $n) |
| 417 | 421 | $this->rewind(); |
@@ -20,537 +20,537 @@ |
||
| 20 | 20 | * |
| 21 | 21 | */ |
| 22 | 22 | class IterFactory{ |
| 23 | - public static function create($iterateur, $command, $info=null){ |
|
| 24 | - |
|
| 25 | - // cas des SI {si expression} analises tres tot |
|
| 26 | - // pour eviter le chargement de tout iterateur |
|
| 27 | - if (isset($command['si'])) { |
|
| 28 | - foreach ($command['si'] as $si) { |
|
| 29 | - if (!$si) { |
|
| 30 | - // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 31 | - // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 32 | - return new IterDecorator(new EmptyIterator(), array(), $info); |
|
| 33 | - } |
|
| 34 | - } |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 38 | - // (il faudrait passer l'argument ->sql_serveur |
|
| 39 | - // pour etre certain qu'on est sur un "php:") |
|
| 40 | - if (class_exists($iterateur)) { |
|
| 41 | - $a = isset($command['args']) ? $command['args'] : array() ; |
|
| 42 | - |
|
| 43 | - // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 44 | - // si on recoit deja un iterateur en argument, on l'utilise |
|
| 45 | - if (count($a)==1 and is_object($a[0]) and is_subclass_of($a[0], 'Iterator')) { |
|
| 46 | - $iter = $a[0]; |
|
| 47 | - |
|
| 48 | - // sinon, on cree un iterateur du type donne |
|
| 49 | - } else { |
|
| 50 | - // arguments de creation de l'iterateur... |
|
| 51 | - // (pas glop) |
|
| 52 | - try { |
|
| 53 | - switch (count($a)) { |
|
| 54 | - case 0: $iter = new $iterateur(); break; |
|
| 55 | - case 1: $iter = new $iterateur($a[0]); break; |
|
| 56 | - case 2: $iter = new $iterateur($a[0], $a[1]); break; |
|
| 57 | - case 3: $iter = new $iterateur($a[0], $a[1], $a[2]); break; |
|
| 58 | - case 4: $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); break; |
|
| 59 | - } |
|
| 60 | - } catch (Exception $e) { |
|
| 61 | - spip_log("Erreur de chargement de l'iterateur $iterateur"); |
|
| 62 | - spip_log($e->getMessage()); |
|
| 63 | - $iter = new EmptyIterator(); |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - } else { |
|
| 67 | - // chercher la classe d'iterateur |
|
| 68 | - // IterateurXXX |
|
| 69 | - // definie dans le fichier iterateurs/xxx.php |
|
| 70 | - $class = "Iterateur".$iterateur; |
|
| 71 | - if (!class_exists($class)){ |
|
| 72 | - if (!include_spip("iterateur/" . strtolower($iterateur)) |
|
| 73 | - OR !class_exists($class)) { |
|
| 74 | - die("Iterateur $iterateur non trouvé"); |
|
| 75 | - // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 76 | - # $iter = new EmptyIterator(); |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - $iter = new $class($command, $info); |
|
| 80 | - } |
|
| 81 | - return new IterDecorator($iter, $command, $info); |
|
| 82 | - } |
|
| 23 | + public static function create($iterateur, $command, $info=null){ |
|
| 24 | + |
|
| 25 | + // cas des SI {si expression} analises tres tot |
|
| 26 | + // pour eviter le chargement de tout iterateur |
|
| 27 | + if (isset($command['si'])) { |
|
| 28 | + foreach ($command['si'] as $si) { |
|
| 29 | + if (!$si) { |
|
| 30 | + // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 31 | + // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 32 | + return new IterDecorator(new EmptyIterator(), array(), $info); |
|
| 33 | + } |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 38 | + // (il faudrait passer l'argument ->sql_serveur |
|
| 39 | + // pour etre certain qu'on est sur un "php:") |
|
| 40 | + if (class_exists($iterateur)) { |
|
| 41 | + $a = isset($command['args']) ? $command['args'] : array() ; |
|
| 42 | + |
|
| 43 | + // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 44 | + // si on recoit deja un iterateur en argument, on l'utilise |
|
| 45 | + if (count($a)==1 and is_object($a[0]) and is_subclass_of($a[0], 'Iterator')) { |
|
| 46 | + $iter = $a[0]; |
|
| 47 | + |
|
| 48 | + // sinon, on cree un iterateur du type donne |
|
| 49 | + } else { |
|
| 50 | + // arguments de creation de l'iterateur... |
|
| 51 | + // (pas glop) |
|
| 52 | + try { |
|
| 53 | + switch (count($a)) { |
|
| 54 | + case 0: $iter = new $iterateur(); break; |
|
| 55 | + case 1: $iter = new $iterateur($a[0]); break; |
|
| 56 | + case 2: $iter = new $iterateur($a[0], $a[1]); break; |
|
| 57 | + case 3: $iter = new $iterateur($a[0], $a[1], $a[2]); break; |
|
| 58 | + case 4: $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); break; |
|
| 59 | + } |
|
| 60 | + } catch (Exception $e) { |
|
| 61 | + spip_log("Erreur de chargement de l'iterateur $iterateur"); |
|
| 62 | + spip_log($e->getMessage()); |
|
| 63 | + $iter = new EmptyIterator(); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + } else { |
|
| 67 | + // chercher la classe d'iterateur |
|
| 68 | + // IterateurXXX |
|
| 69 | + // definie dans le fichier iterateurs/xxx.php |
|
| 70 | + $class = "Iterateur".$iterateur; |
|
| 71 | + if (!class_exists($class)){ |
|
| 72 | + if (!include_spip("iterateur/" . strtolower($iterateur)) |
|
| 73 | + OR !class_exists($class)) { |
|
| 74 | + die("Iterateur $iterateur non trouvé"); |
|
| 75 | + // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 76 | + # $iter = new EmptyIterator(); |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + $iter = new $class($command, $info); |
|
| 80 | + } |
|
| 81 | + return new IterDecorator($iter, $command, $info); |
|
| 82 | + } |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | |
| 86 | 86 | |
| 87 | 87 | |
| 88 | 88 | class IterDecorator extends FilterIterator { |
| 89 | - private $iter; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Conditions de filtrage |
|
| 93 | - * ie criteres de selection |
|
| 94 | - * @var array |
|
| 95 | - */ |
|
| 96 | - protected $filtre = array(); |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 100 | - * @var string |
|
| 101 | - */ |
|
| 102 | - protected $func_filtre = null; |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Critere {offset, limit} |
|
| 106 | - * @var int |
|
| 107 | - * @var int |
|
| 108 | - */ |
|
| 109 | - protected $offset = null; |
|
| 110 | - protected $limit = null; |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * nombre d'elements recuperes depuis la position 0, |
|
| 114 | - * en tenant compte des filtres |
|
| 115 | - * @var int |
|
| 116 | - */ |
|
| 117 | - protected $fetched=0; |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Y a t'il une erreur ? |
|
| 121 | - * |
|
| 122 | - * @var bool |
|
| 123 | - **/ |
|
| 124 | - protected $err = false; |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Drapeau a activer en cas d'echec |
|
| 128 | - * (select SQL errone, non chargement des DATA, etc) |
|
| 129 | - */ |
|
| 130 | - public function err() { |
|
| 131 | - if (method_exists($this->iter, 'err')) |
|
| 132 | - return $this->iter->err(); |
|
| 133 | - if (property_exists($this->iter, 'err')) |
|
| 134 | - return $this->iter->err; |
|
| 135 | - return false; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - public function __construct(Iterator $iter, $command, $info){ |
|
| 139 | - parent::__construct($iter); |
|
| 140 | - parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 89 | + private $iter; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Conditions de filtrage |
|
| 93 | + * ie criteres de selection |
|
| 94 | + * @var array |
|
| 95 | + */ |
|
| 96 | + protected $filtre = array(); |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 100 | + * @var string |
|
| 101 | + */ |
|
| 102 | + protected $func_filtre = null; |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Critere {offset, limit} |
|
| 106 | + * @var int |
|
| 107 | + * @var int |
|
| 108 | + */ |
|
| 109 | + protected $offset = null; |
|
| 110 | + protected $limit = null; |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * nombre d'elements recuperes depuis la position 0, |
|
| 114 | + * en tenant compte des filtres |
|
| 115 | + * @var int |
|
| 116 | + */ |
|
| 117 | + protected $fetched=0; |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Y a t'il une erreur ? |
|
| 121 | + * |
|
| 122 | + * @var bool |
|
| 123 | + **/ |
|
| 124 | + protected $err = false; |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Drapeau a activer en cas d'echec |
|
| 128 | + * (select SQL errone, non chargement des DATA, etc) |
|
| 129 | + */ |
|
| 130 | + public function err() { |
|
| 131 | + if (method_exists($this->iter, 'err')) |
|
| 132 | + return $this->iter->err(); |
|
| 133 | + if (property_exists($this->iter, 'err')) |
|
| 134 | + return $this->iter->err; |
|
| 135 | + return false; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + public function __construct(Iterator $iter, $command, $info){ |
|
| 139 | + parent::__construct($iter); |
|
| 140 | + parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 141 | 141 | |
| 142 | - // recuperer l'iterateur transmis |
|
| 143 | - $this->iter = $this->getInnerIterator(); |
|
| 144 | - $this->command = $command; |
|
| 145 | - $this->info = $info; |
|
| 146 | - $this->pos = 0; |
|
| 147 | - $this->fetched = 0; |
|
| 148 | - |
|
| 149 | - // chercher la liste des champs a retourner par |
|
| 150 | - // fetch si l'objet ne les calcule pas tout seul |
|
| 151 | - if (!method_exists($this->iter, 'fetch')) { |
|
| 152 | - $this->calculer_select(); |
|
| 153 | - $this->calculer_filtres(); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 157 | - if (isset($this->iter->err)) { |
|
| 158 | - $this->err = $this->iter->err; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 162 | - //$this->total = $this->count(); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - // calcule les elements a retournes par fetch() |
|
| 167 | - // enleve les elements inutiles du select() |
|
| 168 | - // |
|
| 169 | - private function calculer_select() { |
|
| 170 | - if ($select = &$this->command['select']) { |
|
| 171 | - foreach($select as $s) { |
|
| 172 | - // /!\ $s = '.nom' |
|
| 173 | - if ($s[0] == '.') { |
|
| 174 | - $s = substr($s, 1); |
|
| 175 | - } |
|
| 176 | - $this->select[] = $s; |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // recuperer la valeur d'une balise #X |
|
| 182 | - // en fonction des methodes |
|
| 183 | - // et proprietes disponibles |
|
| 184 | - public function get_select($nom) { |
|
| 185 | - if (is_object($this->iter) |
|
| 186 | - AND method_exists($this->iter, $nom)) { |
|
| 187 | - try { |
|
| 188 | - return $this->iter->$nom(); |
|
| 189 | - } catch(Exception $e) { |
|
| 190 | - // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 191 | - spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 192 | - spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 193 | - return ''; |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - /* |
|
| 142 | + // recuperer l'iterateur transmis |
|
| 143 | + $this->iter = $this->getInnerIterator(); |
|
| 144 | + $this->command = $command; |
|
| 145 | + $this->info = $info; |
|
| 146 | + $this->pos = 0; |
|
| 147 | + $this->fetched = 0; |
|
| 148 | + |
|
| 149 | + // chercher la liste des champs a retourner par |
|
| 150 | + // fetch si l'objet ne les calcule pas tout seul |
|
| 151 | + if (!method_exists($this->iter, 'fetch')) { |
|
| 152 | + $this->calculer_select(); |
|
| 153 | + $this->calculer_filtres(); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 157 | + if (isset($this->iter->err)) { |
|
| 158 | + $this->err = $this->iter->err; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 162 | + //$this->total = $this->count(); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + // calcule les elements a retournes par fetch() |
|
| 167 | + // enleve les elements inutiles du select() |
|
| 168 | + // |
|
| 169 | + private function calculer_select() { |
|
| 170 | + if ($select = &$this->command['select']) { |
|
| 171 | + foreach($select as $s) { |
|
| 172 | + // /!\ $s = '.nom' |
|
| 173 | + if ($s[0] == '.') { |
|
| 174 | + $s = substr($s, 1); |
|
| 175 | + } |
|
| 176 | + $this->select[] = $s; |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // recuperer la valeur d'une balise #X |
|
| 182 | + // en fonction des methodes |
|
| 183 | + // et proprietes disponibles |
|
| 184 | + public function get_select($nom) { |
|
| 185 | + if (is_object($this->iter) |
|
| 186 | + AND method_exists($this->iter, $nom)) { |
|
| 187 | + try { |
|
| 188 | + return $this->iter->$nom(); |
|
| 189 | + } catch(Exception $e) { |
|
| 190 | + // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 191 | + spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 192 | + spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 193 | + return ''; |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + /* |
|
| 197 | 197 | if (property_exists($this->iter, $nom)) { |
| 198 | 198 | return $this->iter->$nom; |
| 199 | 199 | }*/ |
| 200 | - // cle et valeur par defaut |
|
| 201 | - // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 202 | - if (in_array($nom, array('cle', 'valeur')) |
|
| 203 | - AND method_exists($this, $nom)) { |
|
| 204 | - return $this->$nom(); |
|
| 205 | - } |
|
| 200 | + // cle et valeur par defaut |
|
| 201 | + // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 202 | + if (in_array($nom, array('cle', 'valeur')) |
|
| 203 | + AND method_exists($this, $nom)) { |
|
| 204 | + return $this->$nom(); |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - // Par defaut chercher en xpath dans la valeur() |
|
| 208 | - return table_valeur($this->valeur(), $nom, null); |
|
| 209 | - } |
|
| 207 | + // Par defaut chercher en xpath dans la valeur() |
|
| 208 | + return table_valeur($this->valeur(), $nom, null); |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | 211 | |
| 212 | - private function calculer_filtres() { |
|
| 212 | + private function calculer_filtres() { |
|
| 213 | 213 | |
| 214 | - // Issu de calculer_select() de public/composer L.519 |
|
| 215 | - // TODO: externaliser... |
|
| 216 | - // |
|
| 217 | - // retirer les criteres vides: |
|
| 218 | - // {X ?} avec X absent de l'URL |
|
| 219 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 220 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 221 | - if ($where = &$this->command['where']) { |
|
| 222 | - $menage = false; |
|
| 223 | - foreach($where as $k => $v) { |
|
| 224 | - if (is_array($v)){ |
|
| 225 | - if ((count($v)>=2) && ($v[0]=='REGEXP') && ($v[2]=="'.*'")) $op= false; |
|
| 226 | - elseif ((count($v)>=2) && ($v[0]=='LIKE') && ($v[2]=="'%'")) $op= false; |
|
| 227 | - else $op = $v[0] ? $v[0] : $v; |
|
| 228 | - } else $op = $v; |
|
| 229 | - if ((!$op) OR ($op==1) OR ($op=='0=0')) { |
|
| 230 | - unset($where[$k]); |
|
| 231 | - $menage = true; |
|
| 232 | - } |
|
| 233 | - // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 234 | - // prendre en compte le cas particulier de sous-requetes |
|
| 235 | - // produites par sql_in quand plus de 255 valeurs passees a IN |
|
| 236 | - if (preg_match_all(',\s+IN\s+(\(.*\)),', $op, $s_req)) { |
|
| 237 | - $req = ''; |
|
| 238 | - foreach($s_req[1] as $key => $val) { |
|
| 239 | - $req .= trim($val, '(,)') . ','; |
|
| 240 | - } |
|
| 241 | - $req = '(' . rtrim($req, ',') . ')'; |
|
| 242 | - } |
|
| 243 | - if (preg_match(',^\(\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)(?:\s+(AND|OR)\s+\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\))*\)$,', $op, $regs)) { |
|
| 244 | - $this->ajouter_filtre($regs[1], 'IN', strlen($req) ? $req : $regs[3], $regs[2]); |
|
| 245 | - unset($op); |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - foreach($where as $k => $v) { |
|
| 249 | - // 3 possibilites : count($v) = |
|
| 250 | - // * 1 : {x y} ; on recoit $v[0] = y |
|
| 251 | - // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 252 | - // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 253 | - |
|
| 254 | - // 1 : forcement traite par un critere, on passe |
|
| 255 | - if (count($v) == 1) { |
|
| 256 | - continue; |
|
| 257 | - } |
|
| 258 | - if (count($v) == 2 and is_array($v[1])) { |
|
| 259 | - $this->ajouter_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 260 | - } |
|
| 261 | - if (count($v) == 3) { |
|
| 262 | - $this->ajouter_filtre($v[1], $v[0], $v[2]); |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - // critere {2,7} |
|
| 268 | - if (isset($this->command['limit']) AND $this->command['limit']) { |
|
| 269 | - $limit = explode(',',$this->command['limit']); |
|
| 270 | - $this->offset = $limit[0]; |
|
| 271 | - $this->limit = $limit[1]; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - // Creer la fonction de filtrage sur $this |
|
| 275 | - if ($this->filtre) { |
|
| 276 | - $this->func_filtre = create_function('$me', $b = 'return ('.join(') AND (', $this->filtre).');'); |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - |
|
| 282 | - protected function ajouter_filtre($cle, $op, $valeur, $not=false) { |
|
| 283 | - if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 284 | - if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 285 | - return; |
|
| 286 | - } |
|
| 287 | - } |
|
| 288 | - // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 289 | - # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 290 | - # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 291 | - # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 292 | - # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 214 | + // Issu de calculer_select() de public/composer L.519 |
|
| 215 | + // TODO: externaliser... |
|
| 216 | + // |
|
| 217 | + // retirer les criteres vides: |
|
| 218 | + // {X ?} avec X absent de l'URL |
|
| 219 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 220 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 221 | + if ($where = &$this->command['where']) { |
|
| 222 | + $menage = false; |
|
| 223 | + foreach($where as $k => $v) { |
|
| 224 | + if (is_array($v)){ |
|
| 225 | + if ((count($v)>=2) && ($v[0]=='REGEXP') && ($v[2]=="'.*'")) $op= false; |
|
| 226 | + elseif ((count($v)>=2) && ($v[0]=='LIKE') && ($v[2]=="'%'")) $op= false; |
|
| 227 | + else $op = $v[0] ? $v[0] : $v; |
|
| 228 | + } else $op = $v; |
|
| 229 | + if ((!$op) OR ($op==1) OR ($op=='0=0')) { |
|
| 230 | + unset($where[$k]); |
|
| 231 | + $menage = true; |
|
| 232 | + } |
|
| 233 | + // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 234 | + // prendre en compte le cas particulier de sous-requetes |
|
| 235 | + // produites par sql_in quand plus de 255 valeurs passees a IN |
|
| 236 | + if (preg_match_all(',\s+IN\s+(\(.*\)),', $op, $s_req)) { |
|
| 237 | + $req = ''; |
|
| 238 | + foreach($s_req[1] as $key => $val) { |
|
| 239 | + $req .= trim($val, '(,)') . ','; |
|
| 240 | + } |
|
| 241 | + $req = '(' . rtrim($req, ',') . ')'; |
|
| 242 | + } |
|
| 243 | + if (preg_match(',^\(\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)(?:\s+(AND|OR)\s+\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\))*\)$,', $op, $regs)) { |
|
| 244 | + $this->ajouter_filtre($regs[1], 'IN', strlen($req) ? $req : $regs[3], $regs[2]); |
|
| 245 | + unset($op); |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + foreach($where as $k => $v) { |
|
| 249 | + // 3 possibilites : count($v) = |
|
| 250 | + // * 1 : {x y} ; on recoit $v[0] = y |
|
| 251 | + // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 252 | + // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 253 | + |
|
| 254 | + // 1 : forcement traite par un critere, on passe |
|
| 255 | + if (count($v) == 1) { |
|
| 256 | + continue; |
|
| 257 | + } |
|
| 258 | + if (count($v) == 2 and is_array($v[1])) { |
|
| 259 | + $this->ajouter_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 260 | + } |
|
| 261 | + if (count($v) == 3) { |
|
| 262 | + $this->ajouter_filtre($v[1], $v[0], $v[2]); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + // critere {2,7} |
|
| 268 | + if (isset($this->command['limit']) AND $this->command['limit']) { |
|
| 269 | + $limit = explode(',',$this->command['limit']); |
|
| 270 | + $this->offset = $limit[0]; |
|
| 271 | + $this->limit = $limit[1]; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + // Creer la fonction de filtrage sur $this |
|
| 275 | + if ($this->filtre) { |
|
| 276 | + $this->func_filtre = create_function('$me', $b = 'return ('.join(') AND (', $this->filtre).');'); |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + protected function ajouter_filtre($cle, $op, $valeur, $not=false) { |
|
| 283 | + if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 284 | + if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 285 | + return; |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | + // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 289 | + # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 290 | + # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 291 | + # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 292 | + # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 293 | 293 | |
| 294 | - # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 295 | - # return; |
|
| 294 | + # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 295 | + # return; |
|
| 296 | 296 | |
| 297 | - $a = '$me->get_select(\''.$cle.'\')'; |
|
| 297 | + $a = '$me->get_select(\''.$cle.'\')'; |
|
| 298 | 298 | |
| 299 | - $filtre = ''; |
|
| 299 | + $filtre = ''; |
|
| 300 | 300 | |
| 301 | - if ($op == 'REGEXP') { |
|
| 302 | - $filtre = 'match('.$a.', '.str_replace('\"', '"', $valeur).')'; |
|
| 303 | - $op = ''; |
|
| 304 | - } else if ($op == 'LIKE') { |
|
| 305 | - $valeur = str_replace(array('\"', '_', '%'), array('"', '.', '.*'), preg_quote($valeur)); |
|
| 306 | - $filtre = 'match('.$a.', '.$valeur.')'; |
|
| 307 | - $op = ''; |
|
| 308 | - } else if ($op == '=') { |
|
| 309 | - $op = '=='; |
|
| 310 | - } else if ($op == 'IN') { |
|
| 311 | - $filtre = 'in_array('.$a.', array'.$valeur.')'; |
|
| 312 | - $op = ''; |
|
| 313 | - } else if (!in_array($op, array('<','<=', '>', '>='))) { |
|
| 314 | - spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 315 | - $op = ''; |
|
| 316 | - } |
|
| 301 | + if ($op == 'REGEXP') { |
|
| 302 | + $filtre = 'match('.$a.', '.str_replace('\"', '"', $valeur).')'; |
|
| 303 | + $op = ''; |
|
| 304 | + } else if ($op == 'LIKE') { |
|
| 305 | + $valeur = str_replace(array('\"', '_', '%'), array('"', '.', '.*'), preg_quote($valeur)); |
|
| 306 | + $filtre = 'match('.$a.', '.$valeur.')'; |
|
| 307 | + $op = ''; |
|
| 308 | + } else if ($op == '=') { |
|
| 309 | + $op = '=='; |
|
| 310 | + } else if ($op == 'IN') { |
|
| 311 | + $filtre = 'in_array('.$a.', array'.$valeur.')'; |
|
| 312 | + $op = ''; |
|
| 313 | + } else if (!in_array($op, array('<','<=', '>', '>='))) { |
|
| 314 | + spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 315 | + $op = ''; |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | - if ($op) |
|
| 319 | - $filtre = $a.$op.str_replace('\"', '"', $valeur); |
|
| 318 | + if ($op) |
|
| 319 | + $filtre = $a.$op.str_replace('\"', '"', $valeur); |
|
| 320 | 320 | |
| 321 | - if ($not) |
|
| 322 | - $filtre = "!($filtre)"; |
|
| 321 | + if ($not) |
|
| 322 | + $filtre = "!($filtre)"; |
|
| 323 | 323 | |
| 324 | - if ($filtre) { |
|
| 325 | - $this->filtre[] = $filtre; |
|
| 326 | - } |
|
| 327 | - } |
|
| 324 | + if ($filtre) { |
|
| 325 | + $this->filtre[] = $filtre; |
|
| 326 | + } |
|
| 327 | + } |
|
| 328 | 328 | |
| 329 | 329 | |
| 330 | - public function next(){ |
|
| 331 | - $this->pos++; |
|
| 332 | - parent::next(); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * revient au depart |
|
| 337 | - * @return void |
|
| 338 | - */ |
|
| 339 | - public function rewind() { |
|
| 340 | - $this->pos = 0; |
|
| 341 | - $this->fetched = 0; |
|
| 342 | - parent::rewind(); |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - # Extension SPIP des iterateurs PHP |
|
| 347 | - /** |
|
| 348 | - * type de l'iterateur |
|
| 349 | - * @var string |
|
| 350 | - */ |
|
| 351 | - protected $type; |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * parametres de l'iterateur |
|
| 355 | - * @var array |
|
| 356 | - */ |
|
| 357 | - protected $command; |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * infos de compilateur |
|
| 361 | - * @var array |
|
| 362 | - */ |
|
| 363 | - protected $info; |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * position courante de l'iterateur |
|
| 367 | - * @var int |
|
| 368 | - */ |
|
| 369 | - protected $pos=null; |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * nombre total resultats dans l'iterateur |
|
| 373 | - * @var int |
|
| 374 | - */ |
|
| 375 | - protected $total=null; |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * nombre maximal de recherche pour $total |
|
| 379 | - * si l'iterateur n'implemente pas de fonction specifique |
|
| 380 | - */ |
|
| 381 | - protected $max=100000; |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * Liste des champs a inserer dans les $row |
|
| 386 | - * retournes par ->fetch() |
|
| 387 | - */ |
|
| 388 | - protected $select=array(); |
|
| 330 | + public function next(){ |
|
| 331 | + $this->pos++; |
|
| 332 | + parent::next(); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * revient au depart |
|
| 337 | + * @return void |
|
| 338 | + */ |
|
| 339 | + public function rewind() { |
|
| 340 | + $this->pos = 0; |
|
| 341 | + $this->fetched = 0; |
|
| 342 | + parent::rewind(); |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + # Extension SPIP des iterateurs PHP |
|
| 347 | + /** |
|
| 348 | + * type de l'iterateur |
|
| 349 | + * @var string |
|
| 350 | + */ |
|
| 351 | + protected $type; |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * parametres de l'iterateur |
|
| 355 | + * @var array |
|
| 356 | + */ |
|
| 357 | + protected $command; |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * infos de compilateur |
|
| 361 | + * @var array |
|
| 362 | + */ |
|
| 363 | + protected $info; |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * position courante de l'iterateur |
|
| 367 | + * @var int |
|
| 368 | + */ |
|
| 369 | + protected $pos=null; |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * nombre total resultats dans l'iterateur |
|
| 373 | + * @var int |
|
| 374 | + */ |
|
| 375 | + protected $total=null; |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * nombre maximal de recherche pour $total |
|
| 379 | + * si l'iterateur n'implemente pas de fonction specifique |
|
| 380 | + */ |
|
| 381 | + protected $max=100000; |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * Liste des champs a inserer dans les $row |
|
| 386 | + * retournes par ->fetch() |
|
| 387 | + */ |
|
| 388 | + protected $select=array(); |
|
| 389 | 389 | |
| 390 | 390 | |
| 391 | - /** |
|
| 392 | - * aller a la position absolue n, |
|
| 393 | - * comptee depuis le debut |
|
| 394 | - * |
|
| 395 | - * @param int $n |
|
| 396 | - * absolute pos |
|
| 397 | - * @param string $continue |
|
| 398 | - * param for sql_ api |
|
| 399 | - * @return bool |
|
| 400 | - * success or fail if not implemented |
|
| 401 | - */ |
|
| 402 | - public function seek($n=0, $continue=null) { |
|
| 403 | - if ($this->func_filtre OR !method_exists($this->iter, 'seek') OR !$this->iter->seek($n)) { |
|
| 404 | - $this->seek_loop($n); |
|
| 405 | - } |
|
| 406 | - $this->pos = $n; |
|
| 407 | - $this->fetched = $n; |
|
| 408 | - return true; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - /* |
|
| 391 | + /** |
|
| 392 | + * aller a la position absolue n, |
|
| 393 | + * comptee depuis le debut |
|
| 394 | + * |
|
| 395 | + * @param int $n |
|
| 396 | + * absolute pos |
|
| 397 | + * @param string $continue |
|
| 398 | + * param for sql_ api |
|
| 399 | + * @return bool |
|
| 400 | + * success or fail if not implemented |
|
| 401 | + */ |
|
| 402 | + public function seek($n=0, $continue=null) { |
|
| 403 | + if ($this->func_filtre OR !method_exists($this->iter, 'seek') OR !$this->iter->seek($n)) { |
|
| 404 | + $this->seek_loop($n); |
|
| 405 | + } |
|
| 406 | + $this->pos = $n; |
|
| 407 | + $this->fetched = $n; |
|
| 408 | + return true; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + /* |
|
| 412 | 412 | * aller a la position $n en parcourant |
| 413 | 413 | * un par un tous les elements |
| 414 | 414 | */ |
| 415 | - private function seek_loop($n) { |
|
| 416 | - if ($this->pos > $n) |
|
| 417 | - $this->rewind(); |
|
| 418 | - |
|
| 419 | - while ($this->pos < $n AND $this->valid()) { |
|
| 420 | - $this->next(); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - return true; |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * Avancer de $saut pas |
|
| 428 | - * @param $saut |
|
| 429 | - * @param $max |
|
| 430 | - * @return int |
|
| 431 | - */ |
|
| 432 | - public function skip($saut, $max=null){ |
|
| 433 | - // pas de saut en arriere autorise pour cette fonction |
|
| 434 | - if (($saut=intval($saut))<=0) return $this->pos; |
|
| 435 | - $seek = $this->pos + $saut; |
|
| 436 | - // si le saut fait depasser le maxi, on libere la resource |
|
| 437 | - // et on sort |
|
| 438 | - if (is_null($max)) |
|
| 439 | - $max = $this->count(); |
|
| 440 | - |
|
| 441 | - if ($seek>=$max OR $seek>=$this->count()) { |
|
| 442 | - // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 443 | - $this->free(); |
|
| 444 | - return $max; |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - $this->seek($seek); |
|
| 448 | - return $this->pos; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * Renvoyer un tableau des donnees correspondantes |
|
| 453 | - * a la position courante de l'iterateur |
|
| 454 | - * en controlant si on respecte le filtre |
|
| 455 | - * Appliquer aussi le critere {offset,limit} |
|
| 456 | - * |
|
| 457 | - * @return array|bool |
|
| 458 | - */ |
|
| 459 | - public function fetch() { |
|
| 460 | - if (method_exists($this->iter, 'fetch')) { |
|
| 461 | - return $this->iter->fetch(); |
|
| 462 | - } else { |
|
| 463 | - |
|
| 464 | - while ($this->valid() |
|
| 465 | - AND ( |
|
| 466 | - !$this->accept() |
|
| 467 | - OR (isset($this->offset) AND $this->fetched++ < $this->offset) |
|
| 468 | - )) |
|
| 469 | - $this->next(); |
|
| 470 | - |
|
| 471 | - if (!$this->valid()) |
|
| 472 | - return false; |
|
| 473 | - |
|
| 474 | - if (isset($this->limit) |
|
| 475 | - AND $this->fetched > $this->offset + $this->limit) |
|
| 476 | - return false; |
|
| 477 | - |
|
| 478 | - $r = array(); |
|
| 479 | - foreach ($this->select as $nom) { |
|
| 480 | - $r[$nom] = $this->get_select($nom); |
|
| 481 | - } |
|
| 482 | - $this->next(); |
|
| 483 | - return $r; |
|
| 484 | - } |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - // retourner la cle pour #CLE |
|
| 488 | - public function cle() { |
|
| 489 | - return $this->key(); |
|
| 490 | - } |
|
| 415 | + private function seek_loop($n) { |
|
| 416 | + if ($this->pos > $n) |
|
| 417 | + $this->rewind(); |
|
| 418 | + |
|
| 419 | + while ($this->pos < $n AND $this->valid()) { |
|
| 420 | + $this->next(); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + return true; |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * Avancer de $saut pas |
|
| 428 | + * @param $saut |
|
| 429 | + * @param $max |
|
| 430 | + * @return int |
|
| 431 | + */ |
|
| 432 | + public function skip($saut, $max=null){ |
|
| 433 | + // pas de saut en arriere autorise pour cette fonction |
|
| 434 | + if (($saut=intval($saut))<=0) return $this->pos; |
|
| 435 | + $seek = $this->pos + $saut; |
|
| 436 | + // si le saut fait depasser le maxi, on libere la resource |
|
| 437 | + // et on sort |
|
| 438 | + if (is_null($max)) |
|
| 439 | + $max = $this->count(); |
|
| 440 | + |
|
| 441 | + if ($seek>=$max OR $seek>=$this->count()) { |
|
| 442 | + // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 443 | + $this->free(); |
|
| 444 | + return $max; |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + $this->seek($seek); |
|
| 448 | + return $this->pos; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * Renvoyer un tableau des donnees correspondantes |
|
| 453 | + * a la position courante de l'iterateur |
|
| 454 | + * en controlant si on respecte le filtre |
|
| 455 | + * Appliquer aussi le critere {offset,limit} |
|
| 456 | + * |
|
| 457 | + * @return array|bool |
|
| 458 | + */ |
|
| 459 | + public function fetch() { |
|
| 460 | + if (method_exists($this->iter, 'fetch')) { |
|
| 461 | + return $this->iter->fetch(); |
|
| 462 | + } else { |
|
| 463 | + |
|
| 464 | + while ($this->valid() |
|
| 465 | + AND ( |
|
| 466 | + !$this->accept() |
|
| 467 | + OR (isset($this->offset) AND $this->fetched++ < $this->offset) |
|
| 468 | + )) |
|
| 469 | + $this->next(); |
|
| 470 | + |
|
| 471 | + if (!$this->valid()) |
|
| 472 | + return false; |
|
| 473 | + |
|
| 474 | + if (isset($this->limit) |
|
| 475 | + AND $this->fetched > $this->offset + $this->limit) |
|
| 476 | + return false; |
|
| 477 | + |
|
| 478 | + $r = array(); |
|
| 479 | + foreach ($this->select as $nom) { |
|
| 480 | + $r[$nom] = $this->get_select($nom); |
|
| 481 | + } |
|
| 482 | + $this->next(); |
|
| 483 | + return $r; |
|
| 484 | + } |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + // retourner la cle pour #CLE |
|
| 488 | + public function cle() { |
|
| 489 | + return $this->key(); |
|
| 490 | + } |
|
| 491 | 491 | |
| 492 | - // retourner la valeur pour #VALEUR |
|
| 493 | - public function valeur() { |
|
| 494 | - # attention PHP est mechant avec les objets, parfois il ne les |
|
| 495 | - # clone pas proprement (directoryiterator sous php 5.2.2) |
|
| 496 | - # on se rabat sur la version __toString() |
|
| 497 | - if (is_object($v = $this->current())) { |
|
| 498 | - if (method_exists($v, '__toString')) |
|
| 499 | - $v = $v->__toString(); |
|
| 500 | - else |
|
| 501 | - $v = (array) $v; |
|
| 502 | - } |
|
| 503 | - return $v; |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * Accepte-t-on l'entree courante lue ? |
|
| 508 | - * On execute les filtres pour le savoir. |
|
| 509 | - **/ |
|
| 510 | - public function accept() { |
|
| 511 | - if ($f = $this->func_filtre) { |
|
| 512 | - return $f($this); |
|
| 513 | - } |
|
| 514 | - return true; |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * liberer la ressource |
|
| 519 | - * @return bool |
|
| 520 | - */ |
|
| 521 | - public function free() { |
|
| 522 | - if (method_exists($this->iter, 'free')) { |
|
| 523 | - $this->iter->free(); |
|
| 524 | - } |
|
| 525 | - $this->pos = $this->total = 0; |
|
| 526 | - return true; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * Compter le nombre total de resultats |
|
| 531 | - * pour #TOTAL_BOUCLE |
|
| 532 | - * @return int |
|
| 533 | - */ |
|
| 534 | - public function count() { |
|
| 535 | - if (is_null($this->total)) { |
|
| 536 | - if (method_exists($this->iter, 'count') |
|
| 537 | - AND !$this->func_filtre) { |
|
| 538 | - return $this->total = $this->iter->count(); |
|
| 539 | - } else { |
|
| 540 | - // compter les lignes et rembobiner |
|
| 541 | - $total = 0; |
|
| 542 | - $pos = $this->pos; // sauver la position |
|
| 543 | - $this->rewind(); |
|
| 544 | - while ($this->fetch() and $total < $this->max) { |
|
| 545 | - $total++; |
|
| 546 | - } |
|
| 547 | - $this->seek($pos); |
|
| 548 | - $this->total = $total; |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - return $this->total; |
|
| 553 | - } |
|
| 492 | + // retourner la valeur pour #VALEUR |
|
| 493 | + public function valeur() { |
|
| 494 | + # attention PHP est mechant avec les objets, parfois il ne les |
|
| 495 | + # clone pas proprement (directoryiterator sous php 5.2.2) |
|
| 496 | + # on se rabat sur la version __toString() |
|
| 497 | + if (is_object($v = $this->current())) { |
|
| 498 | + if (method_exists($v, '__toString')) |
|
| 499 | + $v = $v->__toString(); |
|
| 500 | + else |
|
| 501 | + $v = (array) $v; |
|
| 502 | + } |
|
| 503 | + return $v; |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * Accepte-t-on l'entree courante lue ? |
|
| 508 | + * On execute les filtres pour le savoir. |
|
| 509 | + **/ |
|
| 510 | + public function accept() { |
|
| 511 | + if ($f = $this->func_filtre) { |
|
| 512 | + return $f($this); |
|
| 513 | + } |
|
| 514 | + return true; |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * liberer la ressource |
|
| 519 | + * @return bool |
|
| 520 | + */ |
|
| 521 | + public function free() { |
|
| 522 | + if (method_exists($this->iter, 'free')) { |
|
| 523 | + $this->iter->free(); |
|
| 524 | + } |
|
| 525 | + $this->pos = $this->total = 0; |
|
| 526 | + return true; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * Compter le nombre total de resultats |
|
| 531 | + * pour #TOTAL_BOUCLE |
|
| 532 | + * @return int |
|
| 533 | + */ |
|
| 534 | + public function count() { |
|
| 535 | + if (is_null($this->total)) { |
|
| 536 | + if (method_exists($this->iter, 'count') |
|
| 537 | + AND !$this->func_filtre) { |
|
| 538 | + return $this->total = $this->iter->count(); |
|
| 539 | + } else { |
|
| 540 | + // compter les lignes et rembobiner |
|
| 541 | + $total = 0; |
|
| 542 | + $pos = $this->pos; // sauver la position |
|
| 543 | + $this->rewind(); |
|
| 544 | + while ($this->fetch() and $total < $this->max) { |
|
| 545 | + $total++; |
|
| 546 | + } |
|
| 547 | + $this->seek($pos); |
|
| 548 | + $this->total = $total; |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + return $this->total; |
|
| 553 | + } |
|
| 554 | 554 | |
| 555 | 555 | } |
| 556 | 556 | |
@@ -19,8 +19,8 @@ discard block |
||
| 19 | 19 | * fourni dans le fichier iterateurs/xxx.php |
| 20 | 20 | * |
| 21 | 21 | */ |
| 22 | -class IterFactory{ |
|
| 23 | - public static function create($iterateur, $command, $info=null){ |
|
| 22 | +class IterFactory { |
|
| 23 | + public static function create($iterateur, $command, $info = null) { |
|
| 24 | 24 | |
| 25 | 25 | // cas des SI {si expression} analises tres tot |
| 26 | 26 | // pour eviter le chargement de tout iterateur |
@@ -38,11 +38,11 @@ discard block |
||
| 38 | 38 | // (il faudrait passer l'argument ->sql_serveur |
| 39 | 39 | // pour etre certain qu'on est sur un "php:") |
| 40 | 40 | if (class_exists($iterateur)) { |
| 41 | - $a = isset($command['args']) ? $command['args'] : array() ; |
|
| 41 | + $a = isset($command['args']) ? $command['args'] : array(); |
|
| 42 | 42 | |
| 43 | 43 | // permettre de passer un Iterateur directement {args #ITERATEUR} : |
| 44 | 44 | // si on recoit deja un iterateur en argument, on l'utilise |
| 45 | - if (count($a)==1 and is_object($a[0]) and is_subclass_of($a[0], 'Iterator')) { |
|
| 45 | + if (count($a) == 1 and is_object($a[0]) and is_subclass_of($a[0], 'Iterator')) { |
|
| 46 | 46 | $iter = $a[0]; |
| 47 | 47 | |
| 48 | 48 | // sinon, on cree un iterateur du type donne |
@@ -51,11 +51,11 @@ discard block |
||
| 51 | 51 | // (pas glop) |
| 52 | 52 | try { |
| 53 | 53 | switch (count($a)) { |
| 54 | - case 0: $iter = new $iterateur(); break; |
|
| 55 | - case 1: $iter = new $iterateur($a[0]); break; |
|
| 56 | - case 2: $iter = new $iterateur($a[0], $a[1]); break; |
|
| 57 | - case 3: $iter = new $iterateur($a[0], $a[1], $a[2]); break; |
|
| 58 | - case 4: $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); break; |
|
| 54 | + case 0: $iter = new $iterateur(); break; |
|
| 55 | + case 1: $iter = new $iterateur($a[0]); break; |
|
| 56 | + case 2: $iter = new $iterateur($a[0], $a[1]); break; |
|
| 57 | + case 3: $iter = new $iterateur($a[0], $a[1], $a[2]); break; |
|
| 58 | + case 4: $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); break; |
|
| 59 | 59 | } |
| 60 | 60 | } catch (Exception $e) { |
| 61 | 61 | spip_log("Erreur de chargement de l'iterateur $iterateur"); |
@@ -68,8 +68,8 @@ discard block |
||
| 68 | 68 | // IterateurXXX |
| 69 | 69 | // definie dans le fichier iterateurs/xxx.php |
| 70 | 70 | $class = "Iterateur".$iterateur; |
| 71 | - if (!class_exists($class)){ |
|
| 72 | - if (!include_spip("iterateur/" . strtolower($iterateur)) |
|
| 71 | + if (!class_exists($class)) { |
|
| 72 | + if (!include_spip("iterateur/".strtolower($iterateur)) |
|
| 73 | 73 | OR !class_exists($class)) { |
| 74 | 74 | die("Iterateur $iterateur non trouvé"); |
| 75 | 75 | // si l'iterateur n'existe pas, on se rabat sur le generique |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | * en tenant compte des filtres |
| 115 | 115 | * @var int |
| 116 | 116 | */ |
| 117 | - protected $fetched=0; |
|
| 117 | + protected $fetched = 0; |
|
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | 120 | * Y a t'il une erreur ? |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | return false; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - public function __construct(Iterator $iter, $command, $info){ |
|
| 138 | + public function __construct(Iterator $iter, $command, $info) { |
|
| 139 | 139 | parent::__construct($iter); |
| 140 | 140 | parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
| 141 | 141 | |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | // |
| 169 | 169 | private function calculer_select() { |
| 170 | 170 | if ($select = &$this->command['select']) { |
| 171 | - foreach($select as $s) { |
|
| 171 | + foreach ($select as $s) { |
|
| 172 | 172 | // /!\ $s = '.nom' |
| 173 | 173 | if ($s[0] == '.') { |
| 174 | 174 | $s = substr($s, 1); |
@@ -186,9 +186,9 @@ discard block |
||
| 186 | 186 | AND method_exists($this->iter, $nom)) { |
| 187 | 187 | try { |
| 188 | 188 | return $this->iter->$nom(); |
| 189 | - } catch(Exception $e) { |
|
| 189 | + } catch (Exception $e) { |
|
| 190 | 190 | // #GETCHILDREN sur un fichier de DirectoryIterator ... |
| 191 | - spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 191 | + spip_log("Methode $nom en echec sur ".get_class($this->iter)); |
|
| 192 | 192 | spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
| 193 | 193 | return ''; |
| 194 | 194 | } |
@@ -220,13 +220,13 @@ discard block |
||
| 220 | 220 | // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
| 221 | 221 | if ($where = &$this->command['where']) { |
| 222 | 222 | $menage = false; |
| 223 | - foreach($where as $k => $v) { |
|
| 224 | - if (is_array($v)){ |
|
| 225 | - if ((count($v)>=2) && ($v[0]=='REGEXP') && ($v[2]=="'.*'")) $op= false; |
|
| 226 | - elseif ((count($v)>=2) && ($v[0]=='LIKE') && ($v[2]=="'%'")) $op= false; |
|
| 223 | + foreach ($where as $k => $v) { |
|
| 224 | + if (is_array($v)) { |
|
| 225 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) $op = false; |
|
| 226 | + elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) $op = false; |
|
| 227 | 227 | else $op = $v[0] ? $v[0] : $v; |
| 228 | 228 | } else $op = $v; |
| 229 | - if ((!$op) OR ($op==1) OR ($op=='0=0')) { |
|
| 229 | + if ((!$op) OR ($op == 1) OR ($op == '0=0')) { |
|
| 230 | 230 | unset($where[$k]); |
| 231 | 231 | $menage = true; |
| 232 | 232 | } |
@@ -235,17 +235,17 @@ discard block |
||
| 235 | 235 | // produites par sql_in quand plus de 255 valeurs passees a IN |
| 236 | 236 | if (preg_match_all(',\s+IN\s+(\(.*\)),', $op, $s_req)) { |
| 237 | 237 | $req = ''; |
| 238 | - foreach($s_req[1] as $key => $val) { |
|
| 239 | - $req .= trim($val, '(,)') . ','; |
|
| 238 | + foreach ($s_req[1] as $key => $val) { |
|
| 239 | + $req .= trim($val, '(,)').','; |
|
| 240 | 240 | } |
| 241 | - $req = '(' . rtrim($req, ',') . ')'; |
|
| 241 | + $req = '('.rtrim($req, ',').')'; |
|
| 242 | 242 | } |
| 243 | 243 | if (preg_match(',^\(\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)(?:\s+(AND|OR)\s+\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\))*\)$,', $op, $regs)) { |
| 244 | 244 | $this->ajouter_filtre($regs[1], 'IN', strlen($req) ? $req : $regs[3], $regs[2]); |
| 245 | 245 | unset($op); |
| 246 | 246 | } |
| 247 | 247 | } |
| 248 | - foreach($where as $k => $v) { |
|
| 248 | + foreach ($where as $k => $v) { |
|
| 249 | 249 | // 3 possibilites : count($v) = |
| 250 | 250 | // * 1 : {x y} ; on recoit $v[0] = y |
| 251 | 251 | // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | |
| 267 | 267 | // critere {2,7} |
| 268 | 268 | if (isset($this->command['limit']) AND $this->command['limit']) { |
| 269 | - $limit = explode(',',$this->command['limit']); |
|
| 269 | + $limit = explode(',', $this->command['limit']); |
|
| 270 | 270 | $this->offset = $limit[0]; |
| 271 | 271 | $this->limit = $limit[1]; |
| 272 | 272 | } |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | |
| 280 | 280 | |
| 281 | 281 | |
| 282 | - protected function ajouter_filtre($cle, $op, $valeur, $not=false) { |
|
| 282 | + protected function ajouter_filtre($cle, $op, $valeur, $not = false) { |
|
| 283 | 283 | if (method_exists($this->iter, 'exception_des_criteres')) { |
| 284 | 284 | if (in_array($cle, $this->iter->exception_des_criteres())) { |
| 285 | 285 | return; |
@@ -310,8 +310,8 @@ discard block |
||
| 310 | 310 | } else if ($op == 'IN') { |
| 311 | 311 | $filtre = 'in_array('.$a.', array'.$valeur.')'; |
| 312 | 312 | $op = ''; |
| 313 | - } else if (!in_array($op, array('<','<=', '>', '>='))) { |
|
| 314 | - spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 313 | + } else if (!in_array($op, array('<', '<=', '>', '>='))) { |
|
| 314 | + spip_log('operateur non reconnu '.$op); // [todo] mettre une erreur de squelette |
|
| 315 | 315 | $op = ''; |
| 316 | 316 | } |
| 317 | 317 | |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | |
| 330 | - public function next(){ |
|
| 330 | + public function next() { |
|
| 331 | 331 | $this->pos++; |
| 332 | 332 | parent::next(); |
| 333 | 333 | } |
@@ -366,26 +366,26 @@ discard block |
||
| 366 | 366 | * position courante de l'iterateur |
| 367 | 367 | * @var int |
| 368 | 368 | */ |
| 369 | - protected $pos=null; |
|
| 369 | + protected $pos = null; |
|
| 370 | 370 | |
| 371 | 371 | /** |
| 372 | 372 | * nombre total resultats dans l'iterateur |
| 373 | 373 | * @var int |
| 374 | 374 | */ |
| 375 | - protected $total=null; |
|
| 375 | + protected $total = null; |
|
| 376 | 376 | |
| 377 | 377 | /** |
| 378 | 378 | * nombre maximal de recherche pour $total |
| 379 | 379 | * si l'iterateur n'implemente pas de fonction specifique |
| 380 | 380 | */ |
| 381 | - protected $max=100000; |
|
| 381 | + protected $max = 100000; |
|
| 382 | 382 | |
| 383 | 383 | |
| 384 | 384 | /** |
| 385 | 385 | * Liste des champs a inserer dans les $row |
| 386 | 386 | * retournes par ->fetch() |
| 387 | 387 | */ |
| 388 | - protected $select=array(); |
|
| 388 | + protected $select = array(); |
|
| 389 | 389 | |
| 390 | 390 | |
| 391 | 391 | /** |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | * @return bool |
| 400 | 400 | * success or fail if not implemented |
| 401 | 401 | */ |
| 402 | - public function seek($n=0, $continue=null) { |
|
| 402 | + public function seek($n = 0, $continue = null) { |
|
| 403 | 403 | if ($this->func_filtre OR !method_exists($this->iter, 'seek') OR !$this->iter->seek($n)) { |
| 404 | 404 | $this->seek_loop($n); |
| 405 | 405 | } |
@@ -429,16 +429,16 @@ discard block |
||
| 429 | 429 | * @param $max |
| 430 | 430 | * @return int |
| 431 | 431 | */ |
| 432 | - public function skip($saut, $max=null){ |
|
| 432 | + public function skip($saut, $max = null) { |
|
| 433 | 433 | // pas de saut en arriere autorise pour cette fonction |
| 434 | - if (($saut=intval($saut))<=0) return $this->pos; |
|
| 434 | + if (($saut = intval($saut)) <= 0) return $this->pos; |
|
| 435 | 435 | $seek = $this->pos + $saut; |
| 436 | 436 | // si le saut fait depasser le maxi, on libere la resource |
| 437 | 437 | // et on sort |
| 438 | 438 | if (is_null($max)) |
| 439 | 439 | $max = $this->count(); |
| 440 | 440 | |
| 441 | - if ($seek>=$max OR $seek>=$this->count()) { |
|
| 441 | + if ($seek >= $max OR $seek >= $this->count()) { |
|
| 442 | 442 | // sortie plus rapide que de faire next() jusqu'a la fin ! |
| 443 | 443 | $this->free(); |
| 444 | 444 | return $max; |
@@ -11,7 +11,9 @@ discard block |
||
| 11 | 11 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 12 | 12 | \***************************************************************************/ |
| 13 | 13 | |
| 14 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 14 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 15 | + return; |
|
| 16 | +} |
|
| 15 | 17 | |
| 16 | 18 | /** |
| 17 | 19 | * Fabrique d'iterateur |
@@ -128,10 +130,12 @@ discard block |
||
| 128 | 130 | * (select SQL errone, non chargement des DATA, etc) |
| 129 | 131 | */ |
| 130 | 132 | public function err() { |
| 131 | - if (method_exists($this->iter, 'err')) |
|
| 132 | - return $this->iter->err(); |
|
| 133 | - if (property_exists($this->iter, 'err')) |
|
| 134 | - return $this->iter->err; |
|
| 133 | + if (method_exists($this->iter, 'err')) { |
|
| 134 | + return $this->iter->err(); |
|
| 135 | + } |
|
| 136 | + if (property_exists($this->iter, 'err')) { |
|
| 137 | + return $this->iter->err; |
|
| 138 | + } |
|
| 135 | 139 | return false; |
| 136 | 140 | } |
| 137 | 141 | |
@@ -222,10 +226,16 @@ discard block |
||
| 222 | 226 | $menage = false; |
| 223 | 227 | foreach($where as $k => $v) { |
| 224 | 228 | if (is_array($v)){ |
| 225 | - if ((count($v)>=2) && ($v[0]=='REGEXP') && ($v[2]=="'.*'")) $op= false; |
|
| 226 | - elseif ((count($v)>=2) && ($v[0]=='LIKE') && ($v[2]=="'%'")) $op= false; |
|
| 227 | - else $op = $v[0] ? $v[0] : $v; |
|
| 228 | - } else $op = $v; |
|
| 229 | + if ((count($v)>=2) && ($v[0]=='REGEXP') && ($v[2]=="'.*'")) { |
|
| 230 | + $op= false; |
|
| 231 | + } elseif ((count($v)>=2) && ($v[0]=='LIKE') && ($v[2]=="'%'")) { |
|
| 232 | + $op= false; |
|
| 233 | + } else { |
|
| 234 | + $op = $v[0] ? $v[0] : $v; |
|
| 235 | + } |
|
| 236 | + } else { |
|
| 237 | + $op = $v; |
|
| 238 | + } |
|
| 229 | 239 | if ((!$op) OR ($op==1) OR ($op=='0=0')) { |
| 230 | 240 | unset($where[$k]); |
| 231 | 241 | $menage = true; |
@@ -315,11 +325,13 @@ discard block |
||
| 315 | 325 | $op = ''; |
| 316 | 326 | } |
| 317 | 327 | |
| 318 | - if ($op) |
|
| 319 | - $filtre = $a.$op.str_replace('\"', '"', $valeur); |
|
| 328 | + if ($op) { |
|
| 329 | + $filtre = $a.$op.str_replace('\"', '"', $valeur); |
|
| 330 | + } |
|
| 320 | 331 | |
| 321 | - if ($not) |
|
| 322 | - $filtre = "!($filtre)"; |
|
| 332 | + if ($not) { |
|
| 333 | + $filtre = "!($filtre)"; |
|
| 334 | + } |
|
| 323 | 335 | |
| 324 | 336 | if ($filtre) { |
| 325 | 337 | $this->filtre[] = $filtre; |
@@ -413,8 +425,9 @@ discard block |
||
| 413 | 425 | * un par un tous les elements |
| 414 | 426 | */ |
| 415 | 427 | private function seek_loop($n) { |
| 416 | - if ($this->pos > $n) |
|
| 417 | - $this->rewind(); |
|
| 428 | + if ($this->pos > $n) { |
|
| 429 | + $this->rewind(); |
|
| 430 | + } |
|
| 418 | 431 | |
| 419 | 432 | while ($this->pos < $n AND $this->valid()) { |
| 420 | 433 | $this->next(); |
@@ -431,12 +444,15 @@ discard block |
||
| 431 | 444 | */ |
| 432 | 445 | public function skip($saut, $max=null){ |
| 433 | 446 | // pas de saut en arriere autorise pour cette fonction |
| 434 | - if (($saut=intval($saut))<=0) return $this->pos; |
|
| 447 | + if (($saut=intval($saut))<=0) { |
|
| 448 | + return $this->pos; |
|
| 449 | + } |
|
| 435 | 450 | $seek = $this->pos + $saut; |
| 436 | 451 | // si le saut fait depasser le maxi, on libere la resource |
| 437 | 452 | // et on sort |
| 438 | - if (is_null($max)) |
|
| 439 | - $max = $this->count(); |
|
| 453 | + if (is_null($max)) { |
|
| 454 | + $max = $this->count(); |
|
| 455 | + } |
|
| 440 | 456 | |
| 441 | 457 | if ($seek>=$max OR $seek>=$this->count()) { |
| 442 | 458 | // sortie plus rapide que de faire next() jusqu'a la fin ! |
@@ -465,15 +481,18 @@ discard block |
||
| 465 | 481 | AND ( |
| 466 | 482 | !$this->accept() |
| 467 | 483 | OR (isset($this->offset) AND $this->fetched++ < $this->offset) |
| 468 | - )) |
|
| 469 | - $this->next(); |
|
| 484 | + )) { |
|
| 485 | + $this->next(); |
|
| 486 | + } |
|
| 470 | 487 | |
| 471 | - if (!$this->valid()) |
|
| 472 | - return false; |
|
| 488 | + if (!$this->valid()) { |
|
| 489 | + return false; |
|
| 490 | + } |
|
| 473 | 491 | |
| 474 | 492 | if (isset($this->limit) |
| 475 | - AND $this->fetched > $this->offset + $this->limit) |
|
| 476 | - return false; |
|
| 493 | + AND $this->fetched > $this->offset + $this->limit) { |
|
| 494 | + return false; |
|
| 495 | + } |
|
| 477 | 496 | |
| 478 | 497 | $r = array(); |
| 479 | 498 | foreach ($this->select as $nom) { |
@@ -495,10 +514,11 @@ discard block |
||
| 495 | 514 | # clone pas proprement (directoryiterator sous php 5.2.2) |
| 496 | 515 | # on se rabat sur la version __toString() |
| 497 | 516 | if (is_object($v = $this->current())) { |
| 498 | - if (method_exists($v, '__toString')) |
|
| 499 | - $v = $v->__toString(); |
|
| 500 | - else |
|
| 501 | - $v = (array) $v; |
|
| 517 | + if (method_exists($v, '__toString')) { |
|
| 518 | + $v = $v->__toString(); |
|
| 519 | + } else { |
|
| 520 | + $v = (array) $v; |
|
| 521 | + } |
|
| 502 | 522 | } |
| 503 | 523 | return $v; |
| 504 | 524 | } |
@@ -211,7 +211,7 @@ |
||
| 211 | 211 | * |
| 212 | 212 | * @param array $depart |
| 213 | 213 | * @param array $arrivee |
| 214 | - * @param string|array $col |
|
| 214 | + * @param string $col |
|
| 215 | 215 | * @return bool |
| 216 | 216 | */ |
| 217 | 217 | function nogroupby_if($depart, $arrivee, $col){ |
@@ -30,10 +30,10 @@ discard block |
||
| 30 | 30 | * @return array |
| 31 | 31 | */ |
| 32 | 32 | function decompose_champ_id_objet($champ){ |
| 33 | - if (($champ!=='id_objet') AND preg_match(',^id_([a-z_]+)$,', $champ, $regs)){ |
|
| 34 | - return array('id_objet', 'objet', objet_type($regs[1])); |
|
| 35 | - } |
|
| 36 | - return $champ; |
|
| 33 | + if (($champ!=='id_objet') AND preg_match(',^id_([a-z_]+)$,', $champ, $regs)){ |
|
| 34 | + return array('id_objet', 'objet', objet_type($regs[1])); |
|
| 35 | + } |
|
| 36 | + return $champ; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -46,16 +46,16 @@ discard block |
||
| 46 | 46 | * @return array |
| 47 | 47 | */ |
| 48 | 48 | function trouver_champs_decomposes($champ, $desc){ |
| 49 | - if (!is_array($desc) // on ne se risque pas en conjectures si on ne connait pas la table |
|
| 50 | - OR array_key_exists($champ, $desc['field']) |
|
| 51 | - ) |
|
| 52 | - return array($champ); |
|
| 53 | - if (is_array($decompose = decompose_champ_id_objet($champ))){ |
|
| 54 | - array_pop($decompose); |
|
| 55 | - if (count(array_intersect($decompose, array_keys($desc['field'])))==count($decompose)) |
|
| 56 | - return $decompose; |
|
| 57 | - } |
|
| 58 | - return array($champ); |
|
| 49 | + if (!is_array($desc) // on ne se risque pas en conjectures si on ne connait pas la table |
|
| 50 | + OR array_key_exists($champ, $desc['field']) |
|
| 51 | + ) |
|
| 52 | + return array($champ); |
|
| 53 | + if (is_array($decompose = decompose_champ_id_objet($champ))){ |
|
| 54 | + array_pop($decompose); |
|
| 55 | + if (count(array_intersect($decompose, array_keys($desc['field'])))==count($decompose)) |
|
| 56 | + return $decompose; |
|
| 57 | + } |
|
| 58 | + return array($champ); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | |
@@ -79,21 +79,21 @@ discard block |
||
| 79 | 79 | * @return string |
| 80 | 80 | */ |
| 81 | 81 | function calculer_jointure(&$boucle, $depart, $arrivee, $col = '', $cond = false, $max_liens=5){ |
| 82 | - // les jointures minimales sont optimales : |
|
| 83 | - // on contraint le nombre d'etapes en l'augmentant |
|
| 84 | - // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 85 | - $max = 1; |
|
| 86 | - $res = false; |
|
| 87 | - $milieu_exclus = ($col?$col:array()); |
|
| 88 | - while ($max<=$max_liens AND !$res){ |
|
| 89 | - $res = calculer_chaine_jointures($boucle, $depart, $arrivee, array(), $milieu_exclus, $max); |
|
| 90 | - $max++; |
|
| 91 | - } |
|
| 92 | - if (!$res) return ""; |
|
| 93 | - |
|
| 94 | - list($nom, $desc) = $depart; |
|
| 95 | - |
|
| 96 | - return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 82 | + // les jointures minimales sont optimales : |
|
| 83 | + // on contraint le nombre d'etapes en l'augmentant |
|
| 84 | + // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 85 | + $max = 1; |
|
| 86 | + $res = false; |
|
| 87 | + $milieu_exclus = ($col?$col:array()); |
|
| 88 | + while ($max<=$max_liens AND !$res){ |
|
| 89 | + $res = calculer_chaine_jointures($boucle, $depart, $arrivee, array(), $milieu_exclus, $max); |
|
| 90 | + $max++; |
|
| 91 | + } |
|
| 92 | + if (!$res) return ""; |
|
| 93 | + |
|
| 94 | + list($nom, $desc) = $depart; |
|
| 95 | + |
|
| 96 | + return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
@@ -125,66 +125,66 @@ discard block |
||
| 125 | 125 | * @return string |
| 126 | 126 | */ |
| 127 | 127 | function fabrique_jointures(&$boucle, $res, $cond = false, $desc = array(), $nom = '', $col = '', $echap = true){ |
| 128 | - static $num = array(); |
|
| 129 | - $id_table = ""; |
|
| 130 | - $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 131 | - foreach ($res as $cle => $r){ |
|
| 132 | - list($d, $a, $j) = $r; |
|
| 133 | - if (!$id_table) $id_table = $d; |
|
| 134 | - $n = ++$cpt; |
|
| 135 | - if (is_array($j)){ // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 136 | - list($j1, $j2, $obj, $type) = $j; |
|
| 137 | - // trouver de quel cote est (id_objet,objet) |
|
| 138 | - if ($j1=="id_$obj") |
|
| 139 | - $obj = "$id_table.$obj"; |
|
| 140 | - else |
|
| 141 | - $obj = "L$n.$obj"; |
|
| 142 | - // le where complementaire est envoye dans la jointure pour pouvoir etre elimine avec la jointure |
|
| 143 | - // en cas d'optimisation |
|
| 144 | - //$boucle->where[] = array("'='","'$obj'","sql_quote('$type')"); |
|
| 145 | - $boucle->join["L$n"] = |
|
| 146 | - $echap ? |
|
| 147 | - array("'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')") |
|
| 148 | - : |
|
| 149 | - array($id_table, $j2, $j1, "$obj=".sql_quote($type)); |
|
| 150 | - } |
|
| 151 | - else |
|
| 152 | - $boucle->join["L$n"] = $echap ? array("'$id_table'", "'$j'") : array($id_table, $j); |
|
| 153 | - $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - // pas besoin de group by |
|
| 158 | - // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 159 | - // si une seule jointure et sur une table avec primary key formee |
|
| 160 | - // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 161 | - // et operateur d'egalite (http://trac.rezo.net/trac/spip/ticket/477) |
|
| 162 | - |
|
| 163 | - if ($pk = (isset($a[1]) && (count($boucle->from)==2) && !$cond)){ |
|
| 164 | - $pk = nogroupby_if($desc, $a[1], $col); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - // pas de group by |
|
| 168 | - // si une seule jointure |
|
| 169 | - // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 170 | - if (!$pk |
|
| 171 | - AND (count($boucle->from)==2) |
|
| 172 | - AND isset($a[1]['key']['PRIMARY KEY']) |
|
| 173 | - AND ($j==$a[1]['key']['PRIMARY KEY']) |
|
| 174 | - ) |
|
| 175 | - $pk = true; |
|
| 176 | - |
|
| 177 | - // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 178 | - $groups = liste_champs_jointures($nom, $desc, true); |
|
| 179 | - if (!$pk) foreach ($groups as $id_prim){ |
|
| 180 | - $id_field = $nom.'.'.$id_prim; |
|
| 181 | - if (!in_array($id_field, $boucle->group)){ |
|
| 182 | - $boucle->group[] = $id_field; |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - $boucle->modificateur['lien'] = true; |
|
| 187 | - return "L$n"; |
|
| 128 | + static $num = array(); |
|
| 129 | + $id_table = ""; |
|
| 130 | + $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 131 | + foreach ($res as $cle => $r){ |
|
| 132 | + list($d, $a, $j) = $r; |
|
| 133 | + if (!$id_table) $id_table = $d; |
|
| 134 | + $n = ++$cpt; |
|
| 135 | + if (is_array($j)){ // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 136 | + list($j1, $j2, $obj, $type) = $j; |
|
| 137 | + // trouver de quel cote est (id_objet,objet) |
|
| 138 | + if ($j1=="id_$obj") |
|
| 139 | + $obj = "$id_table.$obj"; |
|
| 140 | + else |
|
| 141 | + $obj = "L$n.$obj"; |
|
| 142 | + // le where complementaire est envoye dans la jointure pour pouvoir etre elimine avec la jointure |
|
| 143 | + // en cas d'optimisation |
|
| 144 | + //$boucle->where[] = array("'='","'$obj'","sql_quote('$type')"); |
|
| 145 | + $boucle->join["L$n"] = |
|
| 146 | + $echap ? |
|
| 147 | + array("'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')") |
|
| 148 | + : |
|
| 149 | + array($id_table, $j2, $j1, "$obj=".sql_quote($type)); |
|
| 150 | + } |
|
| 151 | + else |
|
| 152 | + $boucle->join["L$n"] = $echap ? array("'$id_table'", "'$j'") : array($id_table, $j); |
|
| 153 | + $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + // pas besoin de group by |
|
| 158 | + // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 159 | + // si une seule jointure et sur une table avec primary key formee |
|
| 160 | + // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 161 | + // et operateur d'egalite (http://trac.rezo.net/trac/spip/ticket/477) |
|
| 162 | + |
|
| 163 | + if ($pk = (isset($a[1]) && (count($boucle->from)==2) && !$cond)){ |
|
| 164 | + $pk = nogroupby_if($desc, $a[1], $col); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + // pas de group by |
|
| 168 | + // si une seule jointure |
|
| 169 | + // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 170 | + if (!$pk |
|
| 171 | + AND (count($boucle->from)==2) |
|
| 172 | + AND isset($a[1]['key']['PRIMARY KEY']) |
|
| 173 | + AND ($j==$a[1]['key']['PRIMARY KEY']) |
|
| 174 | + ) |
|
| 175 | + $pk = true; |
|
| 176 | + |
|
| 177 | + // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 178 | + $groups = liste_champs_jointures($nom, $desc, true); |
|
| 179 | + if (!$pk) foreach ($groups as $id_prim){ |
|
| 180 | + $id_field = $nom.'.'.$id_prim; |
|
| 181 | + if (!in_array($id_field, $boucle->group)){ |
|
| 182 | + $boucle->group[] = $id_field; |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + $boucle->modificateur['lien'] = true; |
|
| 187 | + return "L$n"; |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
@@ -200,12 +200,12 @@ discard block |
||
| 200 | 200 | * @return bool |
| 201 | 201 | */ |
| 202 | 202 | function nogroupby_if($depart, $arrivee, $col){ |
| 203 | - $pk = $arrivee['key']['PRIMARY KEY']; |
|
| 204 | - if (!$pk) return false; |
|
| 205 | - $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 206 | - if (is_array($col)) $col = implode(', *', $col); // cas id_objet, objet |
|
| 207 | - return (preg_match("/^$id_primary, *$col$/", $pk) OR |
|
| 208 | - preg_match("/^$col, *$id_primary$/", $pk)); |
|
| 203 | + $pk = $arrivee['key']['PRIMARY KEY']; |
|
| 204 | + if (!$pk) return false; |
|
| 205 | + $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 206 | + if (is_array($col)) $col = implode(', *', $col); // cas id_objet, objet |
|
| 207 | + return (preg_match("/^$id_primary, *$col$/", $pk) OR |
|
| 208 | + preg_match("/^$col, *$id_primary$/", $pk)); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
@@ -224,33 +224,33 @@ discard block |
||
| 224 | 224 | */ |
| 225 | 225 | function liste_champs_jointures($nom, $desc, $primary = false){ |
| 226 | 226 | |
| 227 | - static $nojoin = array('idx', 'maj', 'date', 'statut'); |
|
| 227 | + static $nojoin = array('idx', 'maj', 'date', 'statut'); |
|
| 228 | 228 | |
| 229 | - // si cle primaire demandee, la privilegier |
|
| 230 | - if ($primary && isset($desc['key']['PRIMARY KEY'])) |
|
| 231 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 229 | + // si cle primaire demandee, la privilegier |
|
| 230 | + if ($primary && isset($desc['key']['PRIMARY KEY'])) |
|
| 231 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 232 | 232 | |
| 233 | - // les champs declares explicitement pour les jointures |
|
| 234 | - if (isset($desc['join'])) return $desc['join']; |
|
| 235 | - /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 233 | + // les champs declares explicitement pour les jointures |
|
| 234 | + if (isset($desc['join'])) return $desc['join']; |
|
| 235 | + /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 236 | 236 | elseif (isset($GLOBALS['tables_auxiliaires'][$nom]['join'])) return $GLOBALS['tables_auxiliaires'][$nom]['join'];*/ |
| 237 | 237 | |
| 238 | - // si pas de cle, c'est fichu |
|
| 239 | - if (!isset($desc['key'])) return array(); |
|
| 238 | + // si pas de cle, c'est fichu |
|
| 239 | + if (!isset($desc['key'])) return array(); |
|
| 240 | 240 | |
| 241 | - // si cle primaire |
|
| 242 | - if (isset($desc['key']['PRIMARY KEY'])) |
|
| 243 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 241 | + // si cle primaire |
|
| 242 | + if (isset($desc['key']['PRIMARY KEY'])) |
|
| 243 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 244 | 244 | |
| 245 | - // ici on se rabat sur les cles secondaires, |
|
| 246 | - // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 247 | - // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 248 | - // il faut declarer explicitement le champ 'join' de sa description |
|
| 245 | + // ici on se rabat sur les cles secondaires, |
|
| 246 | + // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 247 | + // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 248 | + // il faut declarer explicitement le champ 'join' de sa description |
|
| 249 | 249 | |
| 250 | - $join = array(); |
|
| 251 | - foreach ($desc['key'] as $v) $join = split_key($v, $join); |
|
| 252 | - foreach ($join as $k) if (in_array($k, $nojoin)) unset($join[$k]); |
|
| 253 | - return $join; |
|
| 250 | + $join = array(); |
|
| 251 | + foreach ($desc['key'] as $v) $join = split_key($v, $join); |
|
| 252 | + foreach ($join as $k) if (in_array($k, $nojoin)) unset($join[$k]); |
|
| 253 | + return $join; |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | /** |
@@ -263,8 +263,8 @@ discard block |
||
| 263 | 263 | * @return array |
| 264 | 264 | */ |
| 265 | 265 | function split_key($v, $join = array()){ |
| 266 | - foreach (preg_split('/,\s*/', $v) as $k) $join[$k] = $k; |
|
| 267 | - return $join; |
|
| 266 | + foreach (preg_split('/,\s*/', $v) as $k) $join[$k] = $k; |
|
| 267 | + return $join; |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
@@ -286,112 +286,112 @@ discard block |
||
| 286 | 286 | * @return array |
| 287 | 287 | */ |
| 288 | 288 | function calculer_chaine_jointures(&$boucle, $depart, $arrivee, $vu = array(), $milieu_exclus = array(), $max_liens = 5){ |
| 289 | - static $trouver_table; |
|
| 290 | - if (!$trouver_table) |
|
| 291 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 292 | - |
|
| 293 | - if (is_string($milieu_exclus)) |
|
| 294 | - $milieu_exclus = array($milieu_exclus); |
|
| 295 | - // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 296 | - // faire une jointure sur objet tout seul n'a pas de sens |
|
| 297 | - if (in_array('id_objet',$milieu_exclus) AND !in_array('objet',$milieu_exclus)) |
|
| 298 | - $milieu_exclus[] = 'objet'; |
|
| 299 | - |
|
| 300 | - list($dnom, $ddesc) = $depart; |
|
| 301 | - list($anom, $adesc) = $arrivee; |
|
| 302 | - if (!count($vu)){ |
|
| 303 | - $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 304 | - $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - $akeys = array(); |
|
| 308 | - foreach ($adesc['key'] as $k) { |
|
| 309 | - // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 310 | - $akeys = array_merge($akeys, preg_split('/,\s*/', $k)); |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - // enlever les cles d'arrivee exclues par l'appel |
|
| 314 | - $akeys = array_diff($akeys, $milieu_exclus); |
|
| 315 | - |
|
| 316 | - // cles candidates au depart |
|
| 317 | - $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 318 | - // enlever les cles dde depart exclues par l'appel |
|
| 319 | - $keys = array_diff($keys, $milieu_exclus); |
|
| 320 | - |
|
| 321 | - $v = !$keys ? false : array_intersect(array_values($keys), $akeys); |
|
| 322 | - |
|
| 323 | - if ($v) |
|
| 324 | - return array(array($dnom, array($adesc['table'], $adesc), array_shift($v))); |
|
| 325 | - |
|
| 326 | - // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 327 | - if (count(array_intersect(array('id_objet', 'objet'), $keys))==2){ |
|
| 328 | - // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 329 | - // id_objet,objet |
|
| 330 | - // si oui on la prend |
|
| 331 | - foreach ($akeys as $key){ |
|
| 332 | - $v = decompose_champ_id_objet($key); |
|
| 333 | - if (is_array($v)){ |
|
| 334 | - $objet = array_shift($v); // objet,'article' |
|
| 335 | - array_unshift($v, $key); // id_article,objet,'article' |
|
| 336 | - array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 337 | - return array(array($dnom, array($adesc['table'], $adesc), $v)); |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - else { |
|
| 342 | - // regarder si l'une des cles de depart peut se decomposer en |
|
| 343 | - // id_objet,objet a l'arrivee |
|
| 344 | - // si oui on la prend |
|
| 345 | - foreach ($keys as $key){ |
|
| 346 | - if (count($v = trouver_champs_decomposes($key, $adesc))>1){ |
|
| 347 | - if (count($v)==count(array_intersect($v, $akeys))){ |
|
| 348 | - $v = decompose_champ_id_objet($key); // id_objet,objet,'article' |
|
| 349 | - array_unshift($v, $key); // id_article,id_objet,objet,'article' |
|
| 350 | - return array(array($dnom, array($adesc['table'], $adesc), $v)); |
|
| 351 | - } |
|
| 352 | - } |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - // si l'on voulait une jointure direct, c'est rate ! |
|
| 356 | - if ($max_liens<=1) return array(); |
|
| 357 | - |
|
| 358 | - // sinon essayer de passer par une autre table |
|
| 359 | - $new = $vu; |
|
| 360 | - foreach ($boucle->jointures as $v){ |
|
| 361 | - if ($v |
|
| 362 | - AND !in_array($v, $vu) |
|
| 363 | - AND $def = $trouver_table($v, $boucle->sql_serveur) |
|
| 364 | - AND !in_array($def['table_sql'], $vu) |
|
| 365 | - ){ |
|
| 366 | - // ne pas tester les cles qui sont exclues a l'appel |
|
| 367 | - // ie la cle de la jointure precedente |
|
| 368 | - $test_cles = $milieu_exclus; |
|
| 369 | - $new[] = $v; |
|
| 370 | - $max_iter = 50; // securite |
|
| 371 | - while (count($jointure_directe_possible = calculer_chaine_jointures($boucle, $depart, array($v, $def), $vu, $test_cles, 1)) |
|
| 372 | - AND $max_iter--){ |
|
| 373 | - $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 374 | - $milieu = end($jointure_directe_possible); |
|
| 375 | - $exclure_fin = $milieu_exclus; |
|
| 376 | - if (is_string($milieu)){ |
|
| 377 | - $exclure_fin[] = $milieu; |
|
| 378 | - $test_cles[] = $milieu; |
|
| 379 | - } |
|
| 380 | - else{ |
|
| 381 | - $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 382 | - $test_cles = array_merge($test_cles, $milieu); |
|
| 383 | - } |
|
| 384 | - // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 385 | - // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 386 | - $r = calculer_chaine_jointures($boucle, array($v, $def), $arrivee, $new, $exclure_fin, $max_liens-1); |
|
| 387 | - if ($r){ |
|
| 388 | - array_unshift($r, $jointure_directe_possible); |
|
| 389 | - return $r; |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - } |
|
| 394 | - return array(); |
|
| 289 | + static $trouver_table; |
|
| 290 | + if (!$trouver_table) |
|
| 291 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 292 | + |
|
| 293 | + if (is_string($milieu_exclus)) |
|
| 294 | + $milieu_exclus = array($milieu_exclus); |
|
| 295 | + // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 296 | + // faire une jointure sur objet tout seul n'a pas de sens |
|
| 297 | + if (in_array('id_objet',$milieu_exclus) AND !in_array('objet',$milieu_exclus)) |
|
| 298 | + $milieu_exclus[] = 'objet'; |
|
| 299 | + |
|
| 300 | + list($dnom, $ddesc) = $depart; |
|
| 301 | + list($anom, $adesc) = $arrivee; |
|
| 302 | + if (!count($vu)){ |
|
| 303 | + $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 304 | + $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + $akeys = array(); |
|
| 308 | + foreach ($adesc['key'] as $k) { |
|
| 309 | + // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 310 | + $akeys = array_merge($akeys, preg_split('/,\s*/', $k)); |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + // enlever les cles d'arrivee exclues par l'appel |
|
| 314 | + $akeys = array_diff($akeys, $milieu_exclus); |
|
| 315 | + |
|
| 316 | + // cles candidates au depart |
|
| 317 | + $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 318 | + // enlever les cles dde depart exclues par l'appel |
|
| 319 | + $keys = array_diff($keys, $milieu_exclus); |
|
| 320 | + |
|
| 321 | + $v = !$keys ? false : array_intersect(array_values($keys), $akeys); |
|
| 322 | + |
|
| 323 | + if ($v) |
|
| 324 | + return array(array($dnom, array($adesc['table'], $adesc), array_shift($v))); |
|
| 325 | + |
|
| 326 | + // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 327 | + if (count(array_intersect(array('id_objet', 'objet'), $keys))==2){ |
|
| 328 | + // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 329 | + // id_objet,objet |
|
| 330 | + // si oui on la prend |
|
| 331 | + foreach ($akeys as $key){ |
|
| 332 | + $v = decompose_champ_id_objet($key); |
|
| 333 | + if (is_array($v)){ |
|
| 334 | + $objet = array_shift($v); // objet,'article' |
|
| 335 | + array_unshift($v, $key); // id_article,objet,'article' |
|
| 336 | + array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 337 | + return array(array($dnom, array($adesc['table'], $adesc), $v)); |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + else { |
|
| 342 | + // regarder si l'une des cles de depart peut se decomposer en |
|
| 343 | + // id_objet,objet a l'arrivee |
|
| 344 | + // si oui on la prend |
|
| 345 | + foreach ($keys as $key){ |
|
| 346 | + if (count($v = trouver_champs_decomposes($key, $adesc))>1){ |
|
| 347 | + if (count($v)==count(array_intersect($v, $akeys))){ |
|
| 348 | + $v = decompose_champ_id_objet($key); // id_objet,objet,'article' |
|
| 349 | + array_unshift($v, $key); // id_article,id_objet,objet,'article' |
|
| 350 | + return array(array($dnom, array($adesc['table'], $adesc), $v)); |
|
| 351 | + } |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + // si l'on voulait une jointure direct, c'est rate ! |
|
| 356 | + if ($max_liens<=1) return array(); |
|
| 357 | + |
|
| 358 | + // sinon essayer de passer par une autre table |
|
| 359 | + $new = $vu; |
|
| 360 | + foreach ($boucle->jointures as $v){ |
|
| 361 | + if ($v |
|
| 362 | + AND !in_array($v, $vu) |
|
| 363 | + AND $def = $trouver_table($v, $boucle->sql_serveur) |
|
| 364 | + AND !in_array($def['table_sql'], $vu) |
|
| 365 | + ){ |
|
| 366 | + // ne pas tester les cles qui sont exclues a l'appel |
|
| 367 | + // ie la cle de la jointure precedente |
|
| 368 | + $test_cles = $milieu_exclus; |
|
| 369 | + $new[] = $v; |
|
| 370 | + $max_iter = 50; // securite |
|
| 371 | + while (count($jointure_directe_possible = calculer_chaine_jointures($boucle, $depart, array($v, $def), $vu, $test_cles, 1)) |
|
| 372 | + AND $max_iter--){ |
|
| 373 | + $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 374 | + $milieu = end($jointure_directe_possible); |
|
| 375 | + $exclure_fin = $milieu_exclus; |
|
| 376 | + if (is_string($milieu)){ |
|
| 377 | + $exclure_fin[] = $milieu; |
|
| 378 | + $test_cles[] = $milieu; |
|
| 379 | + } |
|
| 380 | + else{ |
|
| 381 | + $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 382 | + $test_cles = array_merge($test_cles, $milieu); |
|
| 383 | + } |
|
| 384 | + // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 385 | + // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 386 | + $r = calculer_chaine_jointures($boucle, array($v, $def), $arrivee, $new, $exclure_fin, $max_liens-1); |
|
| 387 | + if ($r){ |
|
| 388 | + array_unshift($r, $jointure_directe_possible); |
|
| 389 | + return $r; |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | + return array(); |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | /** |
@@ -404,17 +404,17 @@ discard block |
||
| 404 | 404 | * @return array |
| 405 | 405 | */ |
| 406 | 406 | function trouver_cles_table($keys){ |
| 407 | - $res = array(); |
|
| 408 | - foreach ($keys as $v){ |
|
| 409 | - if (!strpos($v, ",")) |
|
| 410 | - $res[$v] = 1; |
|
| 411 | - else { |
|
| 412 | - foreach (preg_split("/\s*,\s*/", $v) as $k){ |
|
| 413 | - $res[$k] = 1; |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - } |
|
| 417 | - return array_keys($res); |
|
| 407 | + $res = array(); |
|
| 408 | + foreach ($keys as $v){ |
|
| 409 | + if (!strpos($v, ",")) |
|
| 410 | + $res[$v] = 1; |
|
| 411 | + else { |
|
| 412 | + foreach (preg_split("/\s*,\s*/", $v) as $k){ |
|
| 413 | + $res[$k] = 1; |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + } |
|
| 417 | + return array_keys($res); |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | /** |
@@ -427,60 +427,60 @@ discard block |
||
| 427 | 427 | * @return array|string |
| 428 | 428 | */ |
| 429 | 429 | function trouver_champ_exterieur($cle, $joints, &$boucle, $checkarrivee = false){ |
| 430 | - static $trouver_table = ''; |
|
| 431 | - if (!$trouver_table) |
|
| 432 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 433 | - |
|
| 434 | - // support de la recherche multi champ : |
|
| 435 | - // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 436 | - // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 437 | - // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 438 | - if (!is_array($cle)) |
|
| 439 | - $cle = array($cle); |
|
| 440 | - |
|
| 441 | - foreach ($joints as $k => $join){ |
|
| 442 | - if ($join && $table = $trouver_table($join, $boucle->sql_serveur)){ |
|
| 443 | - if (isset($table['field']) |
|
| 444 | - // verifier que toutes les cles cherchees sont la |
|
| 445 | - AND (count(array_intersect($cle, array_keys($table['field'])))==count($cle)) |
|
| 446 | - // si on sait ou on veut arriver, il faut que ca colle |
|
| 447 | - AND ($checkarrivee==false || $checkarrivee==$table['table']) |
|
| 448 | - ) |
|
| 449 | - return array($table['table'], $table); |
|
| 450 | - } |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - // au premier coup, on essaye de decomposer, si possible |
|
| 454 | - if (count($cle)==1 |
|
| 455 | - AND $c = reset($cle) |
|
| 456 | - AND is_array($decompose = decompose_champ_id_objet($c)) |
|
| 457 | - ){ |
|
| 458 | - |
|
| 459 | - $desc = $boucle->show; |
|
| 460 | - // cas 1 : la cle id_xx est dans la table de depart |
|
| 461 | - // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 462 | - if (isset($desc['field'][$c])){ |
|
| 463 | - $cle = array(); |
|
| 464 | - $cle[] = array_shift($decompose); // id_objet |
|
| 465 | - $cle[] = array_shift($decompose); // objet |
|
| 466 | - return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 467 | - } |
|
| 468 | - // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 469 | - // -> il faut trouver une cle de depart zzz telle que |
|
| 470 | - // id_objet,objet,zzz soit a l'arrivee |
|
| 471 | - else { |
|
| 472 | - $depart = liste_champs_jointures($desc['table'], $desc); |
|
| 473 | - foreach ($depart as $d){ |
|
| 474 | - $cle = array(); |
|
| 475 | - $cle[] = array_shift($decompose); // id_objet |
|
| 476 | - $cle[] = array_shift($decompose); // objet |
|
| 477 | - $cle[] = $d; |
|
| 478 | - if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) |
|
| 479 | - return $ext; |
|
| 480 | - } |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - return ""; |
|
| 430 | + static $trouver_table = ''; |
|
| 431 | + if (!$trouver_table) |
|
| 432 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 433 | + |
|
| 434 | + // support de la recherche multi champ : |
|
| 435 | + // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 436 | + // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 437 | + // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 438 | + if (!is_array($cle)) |
|
| 439 | + $cle = array($cle); |
|
| 440 | + |
|
| 441 | + foreach ($joints as $k => $join){ |
|
| 442 | + if ($join && $table = $trouver_table($join, $boucle->sql_serveur)){ |
|
| 443 | + if (isset($table['field']) |
|
| 444 | + // verifier que toutes les cles cherchees sont la |
|
| 445 | + AND (count(array_intersect($cle, array_keys($table['field'])))==count($cle)) |
|
| 446 | + // si on sait ou on veut arriver, il faut que ca colle |
|
| 447 | + AND ($checkarrivee==false || $checkarrivee==$table['table']) |
|
| 448 | + ) |
|
| 449 | + return array($table['table'], $table); |
|
| 450 | + } |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + // au premier coup, on essaye de decomposer, si possible |
|
| 454 | + if (count($cle)==1 |
|
| 455 | + AND $c = reset($cle) |
|
| 456 | + AND is_array($decompose = decompose_champ_id_objet($c)) |
|
| 457 | + ){ |
|
| 458 | + |
|
| 459 | + $desc = $boucle->show; |
|
| 460 | + // cas 1 : la cle id_xx est dans la table de depart |
|
| 461 | + // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 462 | + if (isset($desc['field'][$c])){ |
|
| 463 | + $cle = array(); |
|
| 464 | + $cle[] = array_shift($decompose); // id_objet |
|
| 465 | + $cle[] = array_shift($decompose); // objet |
|
| 466 | + return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 467 | + } |
|
| 468 | + // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 469 | + // -> il faut trouver une cle de depart zzz telle que |
|
| 470 | + // id_objet,objet,zzz soit a l'arrivee |
|
| 471 | + else { |
|
| 472 | + $depart = liste_champs_jointures($desc['table'], $desc); |
|
| 473 | + foreach ($depart as $d){ |
|
| 474 | + $cle = array(); |
|
| 475 | + $cle[] = array_shift($decompose); // id_objet |
|
| 476 | + $cle[] = array_shift($decompose); // objet |
|
| 477 | + $cle[] = $d; |
|
| 478 | + if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) |
|
| 479 | + return $ext; |
|
| 480 | + } |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + return ""; |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | /** |
@@ -506,17 +506,17 @@ discard block |
||
| 506 | 506 | * @return string |
| 507 | 507 | */ |
| 508 | 508 | function trouver_jointure_champ($champ, &$boucle, $jointures = false, $cond = false) { |
| 509 | - if ($jointures === false) { |
|
| 510 | - $jointures = $boucle->jointures; |
|
| 511 | - } |
|
| 512 | - $cle = trouver_champ_exterieur($champ, $jointures, $boucle); |
|
| 513 | - if ($cle){ |
|
| 514 | - $desc = $boucle->show; |
|
| 515 | - $cle = calculer_jointure($boucle, array($desc['id_table'], $desc), $cle, '', $cond); |
|
| 516 | - } |
|
| 517 | - if ($cle) return $cle; |
|
| 518 | - spip_log("trouver_jointure_champ: $champ inconnu"); |
|
| 519 | - return ''; |
|
| 509 | + if ($jointures === false) { |
|
| 510 | + $jointures = $boucle->jointures; |
|
| 511 | + } |
|
| 512 | + $cle = trouver_champ_exterieur($champ, $jointures, $boucle); |
|
| 513 | + if ($cle){ |
|
| 514 | + $desc = $boucle->show; |
|
| 515 | + $cle = calculer_jointure($boucle, array($desc['id_table'], $desc), $cle, '', $cond); |
|
| 516 | + } |
|
| 517 | + if ($cle) return $cle; |
|
| 518 | + spip_log("trouver_jointure_champ: $champ inconnu"); |
|
| 519 | + return ''; |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | ?> |
@@ -29,8 +29,8 @@ discard block |
||
| 29 | 29 | * @param string $champ |
| 30 | 30 | * @return array |
| 31 | 31 | */ |
| 32 | -function decompose_champ_id_objet($champ){ |
|
| 33 | - if (($champ!=='id_objet') AND preg_match(',^id_([a-z_]+)$,', $champ, $regs)){ |
|
| 32 | +function decompose_champ_id_objet($champ) { |
|
| 33 | + if (($champ !== 'id_objet') AND preg_match(',^id_([a-z_]+)$,', $champ, $regs)) { |
|
| 34 | 34 | return array('id_objet', 'objet', objet_type($regs[1])); |
| 35 | 35 | } |
| 36 | 36 | return $champ; |
@@ -45,14 +45,14 @@ discard block |
||
| 45 | 45 | * @param array $desc |
| 46 | 46 | * @return array |
| 47 | 47 | */ |
| 48 | -function trouver_champs_decomposes($champ, $desc){ |
|
| 48 | +function trouver_champs_decomposes($champ, $desc) { |
|
| 49 | 49 | if (!is_array($desc) // on ne se risque pas en conjectures si on ne connait pas la table |
| 50 | 50 | OR array_key_exists($champ, $desc['field']) |
| 51 | 51 | ) |
| 52 | 52 | return array($champ); |
| 53 | - if (is_array($decompose = decompose_champ_id_objet($champ))){ |
|
| 53 | + if (is_array($decompose = decompose_champ_id_objet($champ))) { |
|
| 54 | 54 | array_pop($decompose); |
| 55 | - if (count(array_intersect($decompose, array_keys($desc['field'])))==count($decompose)) |
|
| 55 | + if (count(array_intersect($decompose, array_keys($desc['field']))) == count($decompose)) |
|
| 56 | 56 | return $decompose; |
| 57 | 57 | } |
| 58 | 58 | return array($champ); |
@@ -78,14 +78,14 @@ discard block |
||
| 78 | 78 | * flag pour savoir si le critere est conditionnel ou non |
| 79 | 79 | * @return string |
| 80 | 80 | */ |
| 81 | -function calculer_jointure(&$boucle, $depart, $arrivee, $col = '', $cond = false, $max_liens=5){ |
|
| 81 | +function calculer_jointure(&$boucle, $depart, $arrivee, $col = '', $cond = false, $max_liens = 5) { |
|
| 82 | 82 | // les jointures minimales sont optimales : |
| 83 | 83 | // on contraint le nombre d'etapes en l'augmentant |
| 84 | 84 | // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
| 85 | 85 | $max = 1; |
| 86 | 86 | $res = false; |
| 87 | - $milieu_exclus = ($col?$col:array()); |
|
| 88 | - while ($max<=$max_liens AND !$res){ |
|
| 87 | + $milieu_exclus = ($col ? $col : array()); |
|
| 88 | + while ($max <= $max_liens AND !$res) { |
|
| 89 | 89 | $res = calculer_chaine_jointures($boucle, $depart, $arrivee, array(), $milieu_exclus, $max); |
| 90 | 90 | $max++; |
| 91 | 91 | } |
@@ -124,18 +124,18 @@ discard block |
||
| 124 | 124 | * @param bool $echap |
| 125 | 125 | * @return string |
| 126 | 126 | */ |
| 127 | -function fabrique_jointures(&$boucle, $res, $cond = false, $desc = array(), $nom = '', $col = '', $echap = true){ |
|
| 127 | +function fabrique_jointures(&$boucle, $res, $cond = false, $desc = array(), $nom = '', $col = '', $echap = true) { |
|
| 128 | 128 | static $num = array(); |
| 129 | 129 | $id_table = ""; |
| 130 | 130 | $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
| 131 | - foreach ($res as $cle => $r){ |
|
| 131 | + foreach ($res as $cle => $r) { |
|
| 132 | 132 | list($d, $a, $j) = $r; |
| 133 | 133 | if (!$id_table) $id_table = $d; |
| 134 | 134 | $n = ++$cpt; |
| 135 | - if (is_array($j)){ // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 135 | + if (is_array($j)) { // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 136 | 136 | list($j1, $j2, $obj, $type) = $j; |
| 137 | 137 | // trouver de quel cote est (id_objet,objet) |
| 138 | - if ($j1=="id_$obj") |
|
| 138 | + if ($j1 == "id_$obj") |
|
| 139 | 139 | $obj = "$id_table.$obj"; |
| 140 | 140 | else |
| 141 | 141 | $obj = "L$n.$obj"; |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
| 161 | 161 | // et operateur d'egalite (http://trac.rezo.net/trac/spip/ticket/477) |
| 162 | 162 | |
| 163 | - if ($pk = (isset($a[1]) && (count($boucle->from)==2) && !$cond)){ |
|
| 163 | + if ($pk = (isset($a[1]) && (count($boucle->from) == 2) && !$cond)) { |
|
| 164 | 164 | $pk = nogroupby_if($desc, $a[1], $col); |
| 165 | 165 | } |
| 166 | 166 | |
@@ -168,17 +168,17 @@ discard block |
||
| 168 | 168 | // si une seule jointure |
| 169 | 169 | // et si l'index de jointure est une primary key a l'arrivee ! |
| 170 | 170 | if (!$pk |
| 171 | - AND (count($boucle->from)==2) |
|
| 171 | + AND (count($boucle->from) == 2) |
|
| 172 | 172 | AND isset($a[1]['key']['PRIMARY KEY']) |
| 173 | - AND ($j==$a[1]['key']['PRIMARY KEY']) |
|
| 173 | + AND ($j == $a[1]['key']['PRIMARY KEY']) |
|
| 174 | 174 | ) |
| 175 | 175 | $pk = true; |
| 176 | 176 | |
| 177 | 177 | // la clause Group by est en conflit avec ORDER BY, a completer |
| 178 | 178 | $groups = liste_champs_jointures($nom, $desc, true); |
| 179 | - if (!$pk) foreach ($groups as $id_prim){ |
|
| 179 | + if (!$pk) foreach ($groups as $id_prim) { |
|
| 180 | 180 | $id_field = $nom.'.'.$id_prim; |
| 181 | - if (!in_array($id_field, $boucle->group)){ |
|
| 181 | + if (!in_array($id_field, $boucle->group)) { |
|
| 182 | 182 | $boucle->group[] = $id_field; |
| 183 | 183 | } |
| 184 | 184 | } |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | * @param string|array $col |
| 200 | 200 | * @return bool |
| 201 | 201 | */ |
| 202 | -function nogroupby_if($depart, $arrivee, $col){ |
|
| 202 | +function nogroupby_if($depart, $arrivee, $col) { |
|
| 203 | 203 | $pk = $arrivee['key']['PRIMARY KEY']; |
| 204 | 204 | if (!$pk) return false; |
| 205 | 205 | $id_primary = $depart['key']['PRIMARY KEY']; |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | * @param bool $primary |
| 223 | 223 | * @return array |
| 224 | 224 | */ |
| 225 | -function liste_champs_jointures($nom, $desc, $primary = false){ |
|
| 225 | +function liste_champs_jointures($nom, $desc, $primary = false) { |
|
| 226 | 226 | |
| 227 | 227 | static $nojoin = array('idx', 'maj', 'date', 'statut'); |
| 228 | 228 | |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | * @param array $join |
| 263 | 263 | * @return array |
| 264 | 264 | */ |
| 265 | -function split_key($v, $join = array()){ |
|
| 265 | +function split_key($v, $join = array()) { |
|
| 266 | 266 | foreach (preg_split('/,\s*/', $v) as $k) $join[$k] = $k; |
| 267 | 267 | return $join; |
| 268 | 268 | } |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | * nombre maxi d'etapes |
| 286 | 286 | * @return array |
| 287 | 287 | */ |
| 288 | -function calculer_chaine_jointures(&$boucle, $depart, $arrivee, $vu = array(), $milieu_exclus = array(), $max_liens = 5){ |
|
| 288 | +function calculer_chaine_jointures(&$boucle, $depart, $arrivee, $vu = array(), $milieu_exclus = array(), $max_liens = 5) { |
|
| 289 | 289 | static $trouver_table; |
| 290 | 290 | if (!$trouver_table) |
| 291 | 291 | $trouver_table = charger_fonction('trouver_table', 'base'); |
@@ -294,12 +294,12 @@ discard block |
||
| 294 | 294 | $milieu_exclus = array($milieu_exclus); |
| 295 | 295 | // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
| 296 | 296 | // faire une jointure sur objet tout seul n'a pas de sens |
| 297 | - if (in_array('id_objet',$milieu_exclus) AND !in_array('objet',$milieu_exclus)) |
|
| 297 | + if (in_array('id_objet', $milieu_exclus) AND !in_array('objet', $milieu_exclus)) |
|
| 298 | 298 | $milieu_exclus[] = 'objet'; |
| 299 | 299 | |
| 300 | 300 | list($dnom, $ddesc) = $depart; |
| 301 | 301 | list($anom, $adesc) = $arrivee; |
| 302 | - if (!count($vu)){ |
|
| 302 | + if (!count($vu)) { |
|
| 303 | 303 | $vu[] = $dnom; // ne pas oublier la table de depart |
| 304 | 304 | $vu[] = $anom; // ne pas oublier la table d'arrivee |
| 305 | 305 | } |
@@ -324,13 +324,13 @@ discard block |
||
| 324 | 324 | return array(array($dnom, array($adesc['table'], $adesc), array_shift($v))); |
| 325 | 325 | |
| 326 | 326 | // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
| 327 | - if (count(array_intersect(array('id_objet', 'objet'), $keys))==2){ |
|
| 327 | + if (count(array_intersect(array('id_objet', 'objet'), $keys)) == 2) { |
|
| 328 | 328 | // regarder si l'une des cles d'arrivee peut se decomposer en |
| 329 | 329 | // id_objet,objet |
| 330 | 330 | // si oui on la prend |
| 331 | - foreach ($akeys as $key){ |
|
| 331 | + foreach ($akeys as $key) { |
|
| 332 | 332 | $v = decompose_champ_id_objet($key); |
| 333 | - if (is_array($v)){ |
|
| 333 | + if (is_array($v)) { |
|
| 334 | 334 | $objet = array_shift($v); // objet,'article' |
| 335 | 335 | array_unshift($v, $key); // id_article,objet,'article' |
| 336 | 336 | array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
@@ -342,9 +342,9 @@ discard block |
||
| 342 | 342 | // regarder si l'une des cles de depart peut se decomposer en |
| 343 | 343 | // id_objet,objet a l'arrivee |
| 344 | 344 | // si oui on la prend |
| 345 | - foreach ($keys as $key){ |
|
| 346 | - if (count($v = trouver_champs_decomposes($key, $adesc))>1){ |
|
| 347 | - if (count($v)==count(array_intersect($v, $akeys))){ |
|
| 345 | + foreach ($keys as $key) { |
|
| 346 | + if (count($v = trouver_champs_decomposes($key, $adesc)) > 1) { |
|
| 347 | + if (count($v) == count(array_intersect($v, $akeys))) { |
|
| 348 | 348 | $v = decompose_champ_id_objet($key); // id_objet,objet,'article' |
| 349 | 349 | array_unshift($v, $key); // id_article,id_objet,objet,'article' |
| 350 | 350 | return array(array($dnom, array($adesc['table'], $adesc), $v)); |
@@ -353,38 +353,38 @@ discard block |
||
| 353 | 353 | } |
| 354 | 354 | } |
| 355 | 355 | // si l'on voulait une jointure direct, c'est rate ! |
| 356 | - if ($max_liens<=1) return array(); |
|
| 356 | + if ($max_liens <= 1) return array(); |
|
| 357 | 357 | |
| 358 | 358 | // sinon essayer de passer par une autre table |
| 359 | 359 | $new = $vu; |
| 360 | - foreach ($boucle->jointures as $v){ |
|
| 360 | + foreach ($boucle->jointures as $v) { |
|
| 361 | 361 | if ($v |
| 362 | 362 | AND !in_array($v, $vu) |
| 363 | 363 | AND $def = $trouver_table($v, $boucle->sql_serveur) |
| 364 | 364 | AND !in_array($def['table_sql'], $vu) |
| 365 | - ){ |
|
| 365 | + ) { |
|
| 366 | 366 | // ne pas tester les cles qui sont exclues a l'appel |
| 367 | 367 | // ie la cle de la jointure precedente |
| 368 | 368 | $test_cles = $milieu_exclus; |
| 369 | 369 | $new[] = $v; |
| 370 | 370 | $max_iter = 50; // securite |
| 371 | 371 | while (count($jointure_directe_possible = calculer_chaine_jointures($boucle, $depart, array($v, $def), $vu, $test_cles, 1)) |
| 372 | - AND $max_iter--){ |
|
| 372 | + AND $max_iter--) { |
|
| 373 | 373 | $jointure_directe_possible = reset($jointure_directe_possible); |
| 374 | 374 | $milieu = end($jointure_directe_possible); |
| 375 | 375 | $exclure_fin = $milieu_exclus; |
| 376 | - if (is_string($milieu)){ |
|
| 376 | + if (is_string($milieu)) { |
|
| 377 | 377 | $exclure_fin[] = $milieu; |
| 378 | 378 | $test_cles[] = $milieu; |
| 379 | 379 | } |
| 380 | - else{ |
|
| 380 | + else { |
|
| 381 | 381 | $exclure_fin = array_merge($exclure_fin, $milieu); |
| 382 | 382 | $test_cles = array_merge($test_cles, $milieu); |
| 383 | 383 | } |
| 384 | 384 | // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
| 385 | 385 | // sans repasser par la meme cle milieu, ni une cle deja vue ! |
| 386 | - $r = calculer_chaine_jointures($boucle, array($v, $def), $arrivee, $new, $exclure_fin, $max_liens-1); |
|
| 387 | - if ($r){ |
|
| 386 | + $r = calculer_chaine_jointures($boucle, array($v, $def), $arrivee, $new, $exclure_fin, $max_liens - 1); |
|
| 387 | + if ($r) { |
|
| 388 | 388 | array_unshift($r, $jointure_directe_possible); |
| 389 | 389 | return $r; |
| 390 | 390 | } |
@@ -403,13 +403,13 @@ discard block |
||
| 403 | 403 | * @param $keys |
| 404 | 404 | * @return array |
| 405 | 405 | */ |
| 406 | -function trouver_cles_table($keys){ |
|
| 406 | +function trouver_cles_table($keys) { |
|
| 407 | 407 | $res = array(); |
| 408 | - foreach ($keys as $v){ |
|
| 408 | + foreach ($keys as $v) { |
|
| 409 | 409 | if (!strpos($v, ",")) |
| 410 | 410 | $res[$v] = 1; |
| 411 | 411 | else { |
| 412 | - foreach (preg_split("/\s*,\s*/", $v) as $k){ |
|
| 412 | + foreach (preg_split("/\s*,\s*/", $v) as $k) { |
|
| 413 | 413 | $res[$k] = 1; |
| 414 | 414 | } |
| 415 | 415 | } |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | * @param bool $checkarrivee |
| 427 | 427 | * @return array|string |
| 428 | 428 | */ |
| 429 | -function trouver_champ_exterieur($cle, $joints, &$boucle, $checkarrivee = false){ |
|
| 429 | +function trouver_champ_exterieur($cle, $joints, &$boucle, $checkarrivee = false) { |
|
| 430 | 430 | static $trouver_table = ''; |
| 431 | 431 | if (!$trouver_table) |
| 432 | 432 | $trouver_table = charger_fonction('trouver_table', 'base'); |
@@ -438,28 +438,28 @@ discard block |
||
| 438 | 438 | if (!is_array($cle)) |
| 439 | 439 | $cle = array($cle); |
| 440 | 440 | |
| 441 | - foreach ($joints as $k => $join){ |
|
| 442 | - if ($join && $table = $trouver_table($join, $boucle->sql_serveur)){ |
|
| 441 | + foreach ($joints as $k => $join) { |
|
| 442 | + if ($join && $table = $trouver_table($join, $boucle->sql_serveur)) { |
|
| 443 | 443 | if (isset($table['field']) |
| 444 | 444 | // verifier que toutes les cles cherchees sont la |
| 445 | - AND (count(array_intersect($cle, array_keys($table['field'])))==count($cle)) |
|
| 445 | + AND (count(array_intersect($cle, array_keys($table['field']))) == count($cle)) |
|
| 446 | 446 | // si on sait ou on veut arriver, il faut que ca colle |
| 447 | - AND ($checkarrivee==false || $checkarrivee==$table['table']) |
|
| 447 | + AND ($checkarrivee == false || $checkarrivee == $table['table']) |
|
| 448 | 448 | ) |
| 449 | 449 | return array($table['table'], $table); |
| 450 | 450 | } |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | // au premier coup, on essaye de decomposer, si possible |
| 454 | - if (count($cle)==1 |
|
| 454 | + if (count($cle) == 1 |
|
| 455 | 455 | AND $c = reset($cle) |
| 456 | 456 | AND is_array($decompose = decompose_champ_id_objet($c)) |
| 457 | - ){ |
|
| 457 | + ) { |
|
| 458 | 458 | |
| 459 | 459 | $desc = $boucle->show; |
| 460 | 460 | // cas 1 : la cle id_xx est dans la table de depart |
| 461 | 461 | // -> on cherche uniquement id_objet,objet a l'arrivee |
| 462 | - if (isset($desc['field'][$c])){ |
|
| 462 | + if (isset($desc['field'][$c])) { |
|
| 463 | 463 | $cle = array(); |
| 464 | 464 | $cle[] = array_shift($decompose); // id_objet |
| 465 | 465 | $cle[] = array_shift($decompose); // objet |
@@ -470,7 +470,7 @@ discard block |
||
| 470 | 470 | // id_objet,objet,zzz soit a l'arrivee |
| 471 | 471 | else { |
| 472 | 472 | $depart = liste_champs_jointures($desc['table'], $desc); |
| 473 | - foreach ($depart as $d){ |
|
| 473 | + foreach ($depart as $d) { |
|
| 474 | 474 | $cle = array(); |
| 475 | 475 | $cle[] = array_shift($decompose); // id_objet |
| 476 | 476 | $cle[] = array_shift($decompose); // objet |
@@ -510,7 +510,7 @@ discard block |
||
| 510 | 510 | $jointures = $boucle->jointures; |
| 511 | 511 | } |
| 512 | 512 | $cle = trouver_champ_exterieur($champ, $jointures, $boucle); |
| 513 | - if ($cle){ |
|
| 513 | + if ($cle) { |
|
| 514 | 514 | $desc = $boucle->show; |
| 515 | 515 | $cle = calculer_jointure($boucle, array($desc['id_table'], $desc), $cle, '', $cond); |
| 516 | 516 | } |
@@ -10,7 +10,9 @@ discard block |
||
| 10 | 10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 13 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 14 | + return; |
|
| 15 | +} |
|
| 14 | 16 | |
| 15 | 17 | // deduction automatique d'une chaine de jointures |
| 16 | 18 | |
@@ -48,12 +50,14 @@ discard block |
||
| 48 | 50 | function trouver_champs_decomposes($champ, $desc){ |
| 49 | 51 | if (!is_array($desc) // on ne se risque pas en conjectures si on ne connait pas la table |
| 50 | 52 | OR array_key_exists($champ, $desc['field']) |
| 51 | - ) |
|
| 52 | - return array($champ); |
|
| 53 | + ) { |
|
| 54 | + return array($champ); |
|
| 55 | + } |
|
| 53 | 56 | if (is_array($decompose = decompose_champ_id_objet($champ))){ |
| 54 | 57 | array_pop($decompose); |
| 55 | - if (count(array_intersect($decompose, array_keys($desc['field'])))==count($decompose)) |
|
| 56 | - return $decompose; |
|
| 58 | + if (count(array_intersect($decompose, array_keys($desc['field'])))==count($decompose)) { |
|
| 59 | + return $decompose; |
|
| 60 | + } |
|
| 57 | 61 | } |
| 58 | 62 | return array($champ); |
| 59 | 63 | } |
@@ -89,7 +93,9 @@ discard block |
||
| 89 | 93 | $res = calculer_chaine_jointures($boucle, $depart, $arrivee, array(), $milieu_exclus, $max); |
| 90 | 94 | $max++; |
| 91 | 95 | } |
| 92 | - if (!$res) return ""; |
|
| 96 | + if (!$res) { |
|
| 97 | + return ""; |
|
| 98 | + } |
|
| 93 | 99 | |
| 94 | 100 | list($nom, $desc) = $depart; |
| 95 | 101 | |
@@ -130,15 +136,18 @@ discard block |
||
| 130 | 136 | $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
| 131 | 137 | foreach ($res as $cle => $r){ |
| 132 | 138 | list($d, $a, $j) = $r; |
| 133 | - if (!$id_table) $id_table = $d; |
|
| 139 | + if (!$id_table) { |
|
| 140 | + $id_table = $d; |
|
| 141 | + } |
|
| 134 | 142 | $n = ++$cpt; |
| 135 | 143 | if (is_array($j)){ // c'est un lien sur un champ du type id_objet,objet,'article' |
| 136 | 144 | list($j1, $j2, $obj, $type) = $j; |
| 137 | 145 | // trouver de quel cote est (id_objet,objet) |
| 138 | - if ($j1=="id_$obj") |
|
| 139 | - $obj = "$id_table.$obj"; |
|
| 140 | - else |
|
| 141 | - $obj = "L$n.$obj"; |
|
| 146 | + if ($j1=="id_$obj") { |
|
| 147 | + $obj = "$id_table.$obj"; |
|
| 148 | + } else { |
|
| 149 | + $obj = "L$n.$obj"; |
|
| 150 | + } |
|
| 142 | 151 | // le where complementaire est envoye dans la jointure pour pouvoir etre elimine avec la jointure |
| 143 | 152 | // en cas d'optimisation |
| 144 | 153 | //$boucle->where[] = array("'='","'$obj'","sql_quote('$type')"); |
@@ -147,9 +156,9 @@ discard block |
||
| 147 | 156 | array("'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')") |
| 148 | 157 | : |
| 149 | 158 | array($id_table, $j2, $j1, "$obj=".sql_quote($type)); |
| 159 | + } else { |
|
| 160 | + $boucle->join["L$n"] = $echap ? array("'$id_table'", "'$j'") : array($id_table, $j); |
|
| 150 | 161 | } |
| 151 | - else |
|
| 152 | - $boucle->join["L$n"] = $echap ? array("'$id_table'", "'$j'") : array($id_table, $j); |
|
| 153 | 162 | $boucle->from[$id_table = "L$n"] = $a[0]; |
| 154 | 163 | } |
| 155 | 164 | |
@@ -171,13 +180,16 @@ discard block |
||
| 171 | 180 | AND (count($boucle->from)==2) |
| 172 | 181 | AND isset($a[1]['key']['PRIMARY KEY']) |
| 173 | 182 | AND ($j==$a[1]['key']['PRIMARY KEY']) |
| 174 | - ) |
|
| 175 | - $pk = true; |
|
| 183 | + ) { |
|
| 184 | + $pk = true; |
|
| 185 | + } |
|
| 176 | 186 | |
| 177 | 187 | // la clause Group by est en conflit avec ORDER BY, a completer |
| 178 | 188 | $groups = liste_champs_jointures($nom, $desc, true); |
| 179 | - if (!$pk) foreach ($groups as $id_prim){ |
|
| 189 | + if (!$pk) { |
|
| 190 | + foreach ($groups as $id_prim){ |
|
| 180 | 191 | $id_field = $nom.'.'.$id_prim; |
| 192 | + } |
|
| 181 | 193 | if (!in_array($id_field, $boucle->group)){ |
| 182 | 194 | $boucle->group[] = $id_field; |
| 183 | 195 | } |
@@ -201,9 +213,14 @@ discard block |
||
| 201 | 213 | */ |
| 202 | 214 | function nogroupby_if($depart, $arrivee, $col){ |
| 203 | 215 | $pk = $arrivee['key']['PRIMARY KEY']; |
| 204 | - if (!$pk) return false; |
|
| 216 | + if (!$pk) { |
|
| 217 | + return false; |
|
| 218 | + } |
|
| 205 | 219 | $id_primary = $depart['key']['PRIMARY KEY']; |
| 206 | - if (is_array($col)) $col = implode(', *', $col); // cas id_objet, objet |
|
| 220 | + if (is_array($col)) { |
|
| 221 | + $col = implode(', *', $col); |
|
| 222 | + } |
|
| 223 | + // cas id_objet, objet |
|
| 207 | 224 | return (preg_match("/^$id_primary, *$col$/", $pk) OR |
| 208 | 225 | preg_match("/^$col, *$id_primary$/", $pk)); |
| 209 | 226 | } |
@@ -227,20 +244,26 @@ discard block |
||
| 227 | 244 | static $nojoin = array('idx', 'maj', 'date', 'statut'); |
| 228 | 245 | |
| 229 | 246 | // si cle primaire demandee, la privilegier |
| 230 | - if ($primary && isset($desc['key']['PRIMARY KEY'])) |
|
| 231 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 247 | + if ($primary && isset($desc['key']['PRIMARY KEY'])) { |
|
| 248 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 249 | + } |
|
| 232 | 250 | |
| 233 | 251 | // les champs declares explicitement pour les jointures |
| 234 | - if (isset($desc['join'])) return $desc['join']; |
|
| 252 | + if (isset($desc['join'])) { |
|
| 253 | + return $desc['join']; |
|
| 254 | + } |
|
| 235 | 255 | /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
| 236 | 256 | elseif (isset($GLOBALS['tables_auxiliaires'][$nom]['join'])) return $GLOBALS['tables_auxiliaires'][$nom]['join'];*/ |
| 237 | 257 | |
| 238 | 258 | // si pas de cle, c'est fichu |
| 239 | - if (!isset($desc['key'])) return array(); |
|
| 259 | + if (!isset($desc['key'])) { |
|
| 260 | + return array(); |
|
| 261 | + } |
|
| 240 | 262 | |
| 241 | 263 | // si cle primaire |
| 242 | - if (isset($desc['key']['PRIMARY KEY'])) |
|
| 243 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 264 | + if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 265 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 266 | + } |
|
| 244 | 267 | |
| 245 | 268 | // ici on se rabat sur les cles secondaires, |
| 246 | 269 | // en eliminant celles qui sont pas pertinentes (idx, maj) |
@@ -248,8 +271,12 @@ discard block |
||
| 248 | 271 | // il faut declarer explicitement le champ 'join' de sa description |
| 249 | 272 | |
| 250 | 273 | $join = array(); |
| 251 | - foreach ($desc['key'] as $v) $join = split_key($v, $join); |
|
| 252 | - foreach ($join as $k) if (in_array($k, $nojoin)) unset($join[$k]); |
|
| 274 | + foreach ($desc['key'] as $v) { |
|
| 275 | + $join = split_key($v, $join); |
|
| 276 | + } |
|
| 277 | + foreach ($join as $k) { |
|
| 278 | + if (in_array($k, $nojoin)) unset($join[$k]); |
|
| 279 | + } |
|
| 253 | 280 | return $join; |
| 254 | 281 | } |
| 255 | 282 | |
@@ -263,7 +290,9 @@ discard block |
||
| 263 | 290 | * @return array |
| 264 | 291 | */ |
| 265 | 292 | function split_key($v, $join = array()){ |
| 266 | - foreach (preg_split('/,\s*/', $v) as $k) $join[$k] = $k; |
|
| 293 | + foreach (preg_split('/,\s*/', $v) as $k) { |
|
| 294 | + $join[$k] = $k; |
|
| 295 | + } |
|
| 267 | 296 | return $join; |
| 268 | 297 | } |
| 269 | 298 | |
@@ -287,15 +316,18 @@ discard block |
||
| 287 | 316 | */ |
| 288 | 317 | function calculer_chaine_jointures(&$boucle, $depart, $arrivee, $vu = array(), $milieu_exclus = array(), $max_liens = 5){ |
| 289 | 318 | static $trouver_table; |
| 290 | - if (!$trouver_table) |
|
| 291 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 319 | + if (!$trouver_table) { |
|
| 320 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 321 | + } |
|
| 292 | 322 | |
| 293 | - if (is_string($milieu_exclus)) |
|
| 294 | - $milieu_exclus = array($milieu_exclus); |
|
| 323 | + if (is_string($milieu_exclus)) { |
|
| 324 | + $milieu_exclus = array($milieu_exclus); |
|
| 325 | + } |
|
| 295 | 326 | // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
| 296 | 327 | // faire une jointure sur objet tout seul n'a pas de sens |
| 297 | - if (in_array('id_objet',$milieu_exclus) AND !in_array('objet',$milieu_exclus)) |
|
| 298 | - $milieu_exclus[] = 'objet'; |
|
| 328 | + if (in_array('id_objet',$milieu_exclus) AND !in_array('objet',$milieu_exclus)) { |
|
| 329 | + $milieu_exclus[] = 'objet'; |
|
| 330 | + } |
|
| 299 | 331 | |
| 300 | 332 | list($dnom, $ddesc) = $depart; |
| 301 | 333 | list($anom, $adesc) = $arrivee; |
@@ -320,8 +352,9 @@ discard block |
||
| 320 | 352 | |
| 321 | 353 | $v = !$keys ? false : array_intersect(array_values($keys), $akeys); |
| 322 | 354 | |
| 323 | - if ($v) |
|
| 324 | - return array(array($dnom, array($adesc['table'], $adesc), array_shift($v))); |
|
| 355 | + if ($v) { |
|
| 356 | + return array(array($dnom, array($adesc['table'], $adesc), array_shift($v))); |
|
| 357 | + } |
|
| 325 | 358 | |
| 326 | 359 | // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
| 327 | 360 | if (count(array_intersect(array('id_objet', 'objet'), $keys))==2){ |
@@ -337,8 +370,7 @@ discard block |
||
| 337 | 370 | return array(array($dnom, array($adesc['table'], $adesc), $v)); |
| 338 | 371 | } |
| 339 | 372 | } |
| 340 | - } |
|
| 341 | - else { |
|
| 373 | + } else { |
|
| 342 | 374 | // regarder si l'une des cles de depart peut se decomposer en |
| 343 | 375 | // id_objet,objet a l'arrivee |
| 344 | 376 | // si oui on la prend |
@@ -353,7 +385,9 @@ discard block |
||
| 353 | 385 | } |
| 354 | 386 | } |
| 355 | 387 | // si l'on voulait une jointure direct, c'est rate ! |
| 356 | - if ($max_liens<=1) return array(); |
|
| 388 | + if ($max_liens<=1) { |
|
| 389 | + return array(); |
|
| 390 | + } |
|
| 357 | 391 | |
| 358 | 392 | // sinon essayer de passer par une autre table |
| 359 | 393 | $new = $vu; |
@@ -376,8 +410,7 @@ discard block |
||
| 376 | 410 | if (is_string($milieu)){ |
| 377 | 411 | $exclure_fin[] = $milieu; |
| 378 | 412 | $test_cles[] = $milieu; |
| 379 | - } |
|
| 380 | - else{ |
|
| 413 | + } else{ |
|
| 381 | 414 | $exclure_fin = array_merge($exclure_fin, $milieu); |
| 382 | 415 | $test_cles = array_merge($test_cles, $milieu); |
| 383 | 416 | } |
@@ -406,9 +439,9 @@ discard block |
||
| 406 | 439 | function trouver_cles_table($keys){ |
| 407 | 440 | $res = array(); |
| 408 | 441 | foreach ($keys as $v){ |
| 409 | - if (!strpos($v, ",")) |
|
| 410 | - $res[$v] = 1; |
|
| 411 | - else { |
|
| 442 | + if (!strpos($v, ",")) { |
|
| 443 | + $res[$v] = 1; |
|
| 444 | + } else { |
|
| 412 | 445 | foreach (preg_split("/\s*,\s*/", $v) as $k){ |
| 413 | 446 | $res[$k] = 1; |
| 414 | 447 | } |
@@ -428,15 +461,17 @@ discard block |
||
| 428 | 461 | */ |
| 429 | 462 | function trouver_champ_exterieur($cle, $joints, &$boucle, $checkarrivee = false){ |
| 430 | 463 | static $trouver_table = ''; |
| 431 | - if (!$trouver_table) |
|
| 432 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 464 | + if (!$trouver_table) { |
|
| 465 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 466 | + } |
|
| 433 | 467 | |
| 434 | 468 | // support de la recherche multi champ : |
| 435 | 469 | // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
| 436 | 470 | // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
| 437 | 471 | // soit une table avec les 3 champs id_xx, id_objet, objet |
| 438 | - if (!is_array($cle)) |
|
| 439 | - $cle = array($cle); |
|
| 472 | + if (!is_array($cle)) { |
|
| 473 | + $cle = array($cle); |
|
| 474 | + } |
|
| 440 | 475 | |
| 441 | 476 | foreach ($joints as $k => $join){ |
| 442 | 477 | if ($join && $table = $trouver_table($join, $boucle->sql_serveur)){ |
@@ -445,8 +480,9 @@ discard block |
||
| 445 | 480 | AND (count(array_intersect($cle, array_keys($table['field'])))==count($cle)) |
| 446 | 481 | // si on sait ou on veut arriver, il faut que ca colle |
| 447 | 482 | AND ($checkarrivee==false || $checkarrivee==$table['table']) |
| 448 | - ) |
|
| 449 | - return array($table['table'], $table); |
|
| 483 | + ) { |
|
| 484 | + return array($table['table'], $table); |
|
| 485 | + } |
|
| 450 | 486 | } |
| 451 | 487 | } |
| 452 | 488 | |
@@ -475,8 +511,9 @@ discard block |
||
| 475 | 511 | $cle[] = array_shift($decompose); // id_objet |
| 476 | 512 | $cle[] = array_shift($decompose); // objet |
| 477 | 513 | $cle[] = $d; |
| 478 | - if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) |
|
| 479 | - return $ext; |
|
| 514 | + if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) { |
|
| 515 | + return $ext; |
|
| 516 | + } |
|
| 480 | 517 | } |
| 481 | 518 | } |
| 482 | 519 | } |
@@ -514,7 +551,9 @@ discard block |
||
| 514 | 551 | $desc = $boucle->show; |
| 515 | 552 | $cle = calculer_jointure($boucle, array($desc['id_table'], $desc), $cle, '', $cond); |
| 516 | 553 | } |
| 517 | - if ($cle) return $cle; |
|
| 554 | + if ($cle) { |
|
| 555 | + return $cle; |
|
| 556 | + } |
|
| 518 | 557 | spip_log("trouver_jointure_champ: $champ inconnu"); |
| 519 | 558 | return ''; |
| 520 | 559 | } |
@@ -66,7 +66,7 @@ |
||
| 66 | 66 | * |
| 67 | 67 | * http://doc.spip.org/@calculer_taille_dossier |
| 68 | 68 | * |
| 69 | - * @param $dir |
|
| 69 | + * @param string|null $dir |
|
| 70 | 70 | * @return int |
| 71 | 71 | */ |
| 72 | 72 | function calculer_taille_dossier ($dir) { |
@@ -20,44 +20,44 @@ discard block |
||
| 20 | 20 | * @param string|null $arg |
| 21 | 21 | */ |
| 22 | 22 | function action_calculer_taille_cache_dist($arg=null){ |
| 23 | - if (is_null($arg)){ |
|
| 24 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 25 | - $arg = $securiser_action(); |
|
| 26 | - } |
|
| 27 | - include_spip('inc/filtres'); |
|
| 23 | + if (is_null($arg)){ |
|
| 24 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 25 | + $arg = $securiser_action(); |
|
| 26 | + } |
|
| 27 | + include_spip('inc/filtres'); |
|
| 28 | 28 | |
| 29 | - if ($arg=='images'){ |
|
| 30 | - $taille = calculer_taille_dossier(_DIR_VAR); |
|
| 31 | - $res = _T('ecrire:taille_cache_image', |
|
| 32 | - array( |
|
| 33 | - 'dir' => joli_repertoire(_DIR_VAR), |
|
| 34 | - 'taille' => "<b>".(taille_en_octets($taille) > 0 ? taille_en_octets($taille) : "0 octet")."</b>" |
|
| 35 | - ) |
|
| 36 | - ); |
|
| 37 | - } |
|
| 38 | - else { |
|
| 39 | - include_spip('inc/invalideur'); |
|
| 40 | - $taille = |
|
| 41 | - calculer_taille_dossier(_DIR_CACHE_XML) |
|
| 42 | - +calculer_taille_dossier(_DIR_CACHE.'skel/') |
|
| 43 | - +calculer_taille_dossier(_DIR_CACHE.'wheels/') |
|
| 44 | - +calculer_taille_dossier(_DIR_CACHE.'contextes/') |
|
| 45 | - ; |
|
| 46 | - $taille += intval(taille_du_cache()); |
|
| 47 | - if ($taille<=150000){ |
|
| 48 | - $res = _T('taille_cache_vide'); |
|
| 49 | - } |
|
| 50 | - elseif ($taille<=1024*1024){ |
|
| 51 | - $res = _T('taille_cache_moins_de',array('octets'=>taille_en_octets(1024*1024))); |
|
| 52 | - } |
|
| 53 | - else { |
|
| 54 | - $res = _T('taille_cache_octets',array('octets'=>taille_en_octets($taille))); |
|
| 55 | - } |
|
| 56 | - $res = "<b>$res</b>"; |
|
| 57 | - } |
|
| 29 | + if ($arg=='images'){ |
|
| 30 | + $taille = calculer_taille_dossier(_DIR_VAR); |
|
| 31 | + $res = _T('ecrire:taille_cache_image', |
|
| 32 | + array( |
|
| 33 | + 'dir' => joli_repertoire(_DIR_VAR), |
|
| 34 | + 'taille' => "<b>".(taille_en_octets($taille) > 0 ? taille_en_octets($taille) : "0 octet")."</b>" |
|
| 35 | + ) |
|
| 36 | + ); |
|
| 37 | + } |
|
| 38 | + else { |
|
| 39 | + include_spip('inc/invalideur'); |
|
| 40 | + $taille = |
|
| 41 | + calculer_taille_dossier(_DIR_CACHE_XML) |
|
| 42 | + +calculer_taille_dossier(_DIR_CACHE.'skel/') |
|
| 43 | + +calculer_taille_dossier(_DIR_CACHE.'wheels/') |
|
| 44 | + +calculer_taille_dossier(_DIR_CACHE.'contextes/') |
|
| 45 | + ; |
|
| 46 | + $taille += intval(taille_du_cache()); |
|
| 47 | + if ($taille<=150000){ |
|
| 48 | + $res = _T('taille_cache_vide'); |
|
| 49 | + } |
|
| 50 | + elseif ($taille<=1024*1024){ |
|
| 51 | + $res = _T('taille_cache_moins_de',array('octets'=>taille_en_octets(1024*1024))); |
|
| 52 | + } |
|
| 53 | + else { |
|
| 54 | + $res = _T('taille_cache_octets',array('octets'=>taille_en_octets($taille))); |
|
| 55 | + } |
|
| 56 | + $res = "<b>$res</b>"; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - $res = "<p>$res</p>"; |
|
| 60 | - ajax_retour($res); |
|
| 59 | + $res = "<p>$res</p>"; |
|
| 60 | + ajax_retour($res); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | |
@@ -70,20 +70,20 @@ discard block |
||
| 70 | 70 | * @return int |
| 71 | 71 | */ |
| 72 | 72 | function calculer_taille_dossier ($dir) { |
| 73 | - $handle = @opendir($dir); |
|
| 74 | - if (!$handle) return 0; |
|
| 75 | - $taille = 0; |
|
| 76 | - while (($fichier = @readdir($handle)) !== false) { |
|
| 77 | - // Eviter ".", "..", ".htaccess", etc. |
|
| 78 | - if ($fichier[0] == '.') continue; |
|
| 79 | - if (is_file($d = "$dir/$fichier")) { |
|
| 80 | - $taille += filesize($d); |
|
| 81 | - } |
|
| 82 | - else if (is_dir($d)) |
|
| 83 | - $taille += calculer_taille_dossier($d); |
|
| 84 | - } |
|
| 85 | - closedir($handle); |
|
| 86 | - return $taille; |
|
| 73 | + $handle = @opendir($dir); |
|
| 74 | + if (!$handle) return 0; |
|
| 75 | + $taille = 0; |
|
| 76 | + while (($fichier = @readdir($handle)) !== false) { |
|
| 77 | + // Eviter ".", "..", ".htaccess", etc. |
|
| 78 | + if ($fichier[0] == '.') continue; |
|
| 79 | + if (is_file($d = "$dir/$fichier")) { |
|
| 80 | + $taille += filesize($d); |
|
| 81 | + } |
|
| 82 | + else if (is_dir($d)) |
|
| 83 | + $taille += calculer_taille_dossier($d); |
|
| 84 | + } |
|
| 85 | + closedir($handle); |
|
| 86 | + return $taille; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | ?> |
| 90 | 90 | \ No newline at end of file |
@@ -19,14 +19,14 @@ discard block |
||
| 19 | 19 | * |
| 20 | 20 | * @param string|null $arg |
| 21 | 21 | */ |
| 22 | -function action_calculer_taille_cache_dist($arg=null){ |
|
| 23 | - if (is_null($arg)){ |
|
| 22 | +function action_calculer_taille_cache_dist($arg = null) { |
|
| 23 | + if (is_null($arg)) { |
|
| 24 | 24 | $securiser_action = charger_fonction('securiser_action', 'inc'); |
| 25 | 25 | $arg = $securiser_action(); |
| 26 | 26 | } |
| 27 | 27 | include_spip('inc/filtres'); |
| 28 | 28 | |
| 29 | - if ($arg=='images'){ |
|
| 29 | + if ($arg == 'images') { |
|
| 30 | 30 | $taille = calculer_taille_dossier(_DIR_VAR); |
| 31 | 31 | $res = _T('ecrire:taille_cache_image', |
| 32 | 32 | array( |
@@ -44,14 +44,14 @@ discard block |
||
| 44 | 44 | +calculer_taille_dossier(_DIR_CACHE.'contextes/') |
| 45 | 45 | ; |
| 46 | 46 | $taille += intval(taille_du_cache()); |
| 47 | - if ($taille<=150000){ |
|
| 47 | + if ($taille <= 150000) { |
|
| 48 | 48 | $res = _T('taille_cache_vide'); |
| 49 | 49 | } |
| 50 | - elseif ($taille<=1024*1024){ |
|
| 51 | - $res = _T('taille_cache_moins_de',array('octets'=>taille_en_octets(1024*1024))); |
|
| 50 | + elseif ($taille <= 1024 * 1024) { |
|
| 51 | + $res = _T('taille_cache_moins_de', array('octets'=>taille_en_octets(1024 * 1024))); |
|
| 52 | 52 | } |
| 53 | 53 | else { |
| 54 | - $res = _T('taille_cache_octets',array('octets'=>taille_en_octets($taille))); |
|
| 54 | + $res = _T('taille_cache_octets', array('octets'=>taille_en_octets($taille))); |
|
| 55 | 55 | } |
| 56 | 56 | $res = "<b>$res</b>"; |
| 57 | 57 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @param $dir |
| 70 | 70 | * @return int |
| 71 | 71 | */ |
| 72 | -function calculer_taille_dossier ($dir) { |
|
| 72 | +function calculer_taille_dossier($dir) { |
|
| 73 | 73 | $handle = @opendir($dir); |
| 74 | 74 | if (!$handle) return 0; |
| 75 | 75 | $taille = 0; |
@@ -10,7 +10,9 @@ discard block |
||
| 10 | 10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 13 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 14 | + return; |
|
| 15 | +} |
|
| 14 | 16 | |
| 15 | 17 | |
| 16 | 18 | |
@@ -34,8 +36,7 @@ discard block |
||
| 34 | 36 | 'taille' => "<b>".(taille_en_octets($taille) > 0 ? taille_en_octets($taille) : "0 octet")."</b>" |
| 35 | 37 | ) |
| 36 | 38 | ); |
| 37 | - } |
|
| 38 | - else { |
|
| 39 | + } else { |
|
| 39 | 40 | include_spip('inc/invalideur'); |
| 40 | 41 | $taille = |
| 41 | 42 | calculer_taille_dossier(_DIR_CACHE_XML) |
@@ -46,11 +47,9 @@ discard block |
||
| 46 | 47 | $taille += intval(taille_du_cache()); |
| 47 | 48 | if ($taille<=150000){ |
| 48 | 49 | $res = _T('taille_cache_vide'); |
| 49 | - } |
|
| 50 | - elseif ($taille<=1024*1024){ |
|
| 50 | + } elseif ($taille<=1024*1024){ |
|
| 51 | 51 | $res = _T('taille_cache_moins_de',array('octets'=>taille_en_octets(1024*1024))); |
| 52 | - } |
|
| 53 | - else { |
|
| 52 | + } else { |
|
| 54 | 53 | $res = _T('taille_cache_octets',array('octets'=>taille_en_octets($taille))); |
| 55 | 54 | } |
| 56 | 55 | $res = "<b>$res</b>"; |
@@ -71,16 +70,20 @@ discard block |
||
| 71 | 70 | */ |
| 72 | 71 | function calculer_taille_dossier ($dir) { |
| 73 | 72 | $handle = @opendir($dir); |
| 74 | - if (!$handle) return 0; |
|
| 73 | + if (!$handle) { |
|
| 74 | + return 0; |
|
| 75 | + } |
|
| 75 | 76 | $taille = 0; |
| 76 | 77 | while (($fichier = @readdir($handle)) !== false) { |
| 77 | 78 | // Eviter ".", "..", ".htaccess", etc. |
| 78 | - if ($fichier[0] == '.') continue; |
|
| 79 | + if ($fichier[0] == '.') { |
|
| 80 | + continue; |
|
| 81 | + } |
|
| 79 | 82 | if (is_file($d = "$dir/$fichier")) { |
| 80 | 83 | $taille += filesize($d); |
| 84 | + } else if (is_dir($d)) { |
|
| 85 | + $taille += calculer_taille_dossier($d); |
|
| 81 | 86 | } |
| 82 | - else if (is_dir($d)) |
|
| 83 | - $taille += calculer_taille_dossier($d); |
|
| 84 | 87 | } |
| 85 | 88 | closedir($handle); |
| 86 | 89 | return $taille; |
@@ -35,6 +35,9 @@ |
||
| 35 | 35 | redirige_par_entete($redirect, true); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | +/** |
|
| 39 | + * @param boolean $update_session |
|
| 40 | + */ |
|
| 38 | 41 | function action_converser_changer_langue($update_session){ |
| 39 | 42 | if ($lang = _request('var_lang')) |
| 40 | 43 | action_converser_post($lang); |
@@ -20,52 +20,52 @@ |
||
| 20 | 20 | // http://doc.spip.org/@action_converser_dist |
| 21 | 21 | function action_converser_dist() |
| 22 | 22 | { |
| 23 | - $update_session = false; |
|
| 24 | - if ( _request('arg') AND spip_connect()) { |
|
| 25 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 26 | - $securiser_action(); |
|
| 27 | - $update_session = true; |
|
| 28 | - } |
|
| 23 | + $update_session = false; |
|
| 24 | + if ( _request('arg') AND spip_connect()) { |
|
| 25 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 26 | + $securiser_action(); |
|
| 27 | + $update_session = true; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - $lang = action_converser_changer_langue($update_session); |
|
| 31 | - $redirect = rawurldecode(_request('redirect')); |
|
| 30 | + $lang = action_converser_changer_langue($update_session); |
|
| 31 | + $redirect = rawurldecode(_request('redirect')); |
|
| 32 | 32 | |
| 33 | - if (!$redirect) $redirect = _DIR_RESTREINT_ABS; |
|
| 34 | - $redirect = parametre_url($redirect,'lang',$lang,'&'); |
|
| 35 | - redirige_par_entete($redirect, true); |
|
| 33 | + if (!$redirect) $redirect = _DIR_RESTREINT_ABS; |
|
| 34 | + $redirect = parametre_url($redirect,'lang',$lang,'&'); |
|
| 35 | + redirige_par_entete($redirect, true); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | function action_converser_changer_langue($update_session){ |
| 39 | - if ($lang = _request('var_lang')) |
|
| 40 | - action_converser_post($lang); |
|
| 41 | - elseif ($lang = _request('var_lang_ecrire')) { |
|
| 42 | - if ($update_session) { |
|
| 43 | - sql_updateq("spip_auteurs", array("lang" => $lang), "id_auteur = " . $GLOBALS['visiteur_session']['id_auteur']); |
|
| 44 | - $GLOBALS['visiteur_session']['lang'] = $lang; |
|
| 45 | - $session = charger_fonction('session', 'inc'); |
|
| 46 | - if ($spip_session = $session($GLOBALS['visiteur_session'])) { |
|
| 47 | - spip_setcookie( |
|
| 48 | - 'spip_session', |
|
| 49 | - $spip_session, |
|
| 50 | - time() + 3600 * 24 * 14 |
|
| 51 | - ); |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - action_converser_post($lang, 'spip_lang_ecrire'); |
|
| 55 | - } |
|
| 56 | - return $lang; |
|
| 39 | + if ($lang = _request('var_lang')) |
|
| 40 | + action_converser_post($lang); |
|
| 41 | + elseif ($lang = _request('var_lang_ecrire')) { |
|
| 42 | + if ($update_session) { |
|
| 43 | + sql_updateq("spip_auteurs", array("lang" => $lang), "id_auteur = " . $GLOBALS['visiteur_session']['id_auteur']); |
|
| 44 | + $GLOBALS['visiteur_session']['lang'] = $lang; |
|
| 45 | + $session = charger_fonction('session', 'inc'); |
|
| 46 | + if ($spip_session = $session($GLOBALS['visiteur_session'])) { |
|
| 47 | + spip_setcookie( |
|
| 48 | + 'spip_session', |
|
| 49 | + $spip_session, |
|
| 50 | + time() + 3600 * 24 * 14 |
|
| 51 | + ); |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + action_converser_post($lang, 'spip_lang_ecrire'); |
|
| 55 | + } |
|
| 56 | + return $lang; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | // http://doc.spip.org/@action_converser_post |
| 60 | 60 | function action_converser_post($lang, $ecrire=false) |
| 61 | 61 | { |
| 62 | - if ($lang) { |
|
| 63 | - include_spip('inc/lang'); |
|
| 64 | - if (changer_langue($lang)) { |
|
| 65 | - spip_setcookie('spip_lang', $_COOKIE['spip_lang'] = $lang, time() + 365 * 24 * 3600); |
|
| 66 | - if ($ecrire) |
|
| 67 | - spip_setcookie('spip_lang_ecrire', $_COOKIE['spip_lang_ecrire'] = $lang, time() + 365 * 24 * 3600); |
|
| 68 | - } |
|
| 69 | - } |
|
| 62 | + if ($lang) { |
|
| 63 | + include_spip('inc/lang'); |
|
| 64 | + if (changer_langue($lang)) { |
|
| 65 | + spip_setcookie('spip_lang', $_COOKIE['spip_lang'] = $lang, time() + 365 * 24 * 3600); |
|
| 66 | + if ($ecrire) |
|
| 67 | + spip_setcookie('spip_lang_ecrire', $_COOKIE['spip_lang_ecrire'] = $lang, time() + 365 * 24 * 3600); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | 70 | } |
| 71 | 71 | ?> |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | function action_converser_dist() |
| 22 | 22 | { |
| 23 | 23 | $update_session = false; |
| 24 | - if ( _request('arg') AND spip_connect()) { |
|
| 24 | + if (_request('arg') AND spip_connect()) { |
|
| 25 | 25 | $securiser_action = charger_fonction('securiser_action', 'inc'); |
| 26 | 26 | $securiser_action(); |
| 27 | 27 | $update_session = true; |
@@ -31,16 +31,16 @@ discard block |
||
| 31 | 31 | $redirect = rawurldecode(_request('redirect')); |
| 32 | 32 | |
| 33 | 33 | if (!$redirect) $redirect = _DIR_RESTREINT_ABS; |
| 34 | - $redirect = parametre_url($redirect,'lang',$lang,'&'); |
|
| 34 | + $redirect = parametre_url($redirect, 'lang', $lang, '&'); |
|
| 35 | 35 | redirige_par_entete($redirect, true); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | -function action_converser_changer_langue($update_session){ |
|
| 38 | +function action_converser_changer_langue($update_session) { |
|
| 39 | 39 | if ($lang = _request('var_lang')) |
| 40 | 40 | action_converser_post($lang); |
| 41 | 41 | elseif ($lang = _request('var_lang_ecrire')) { |
| 42 | 42 | if ($update_session) { |
| 43 | - sql_updateq("spip_auteurs", array("lang" => $lang), "id_auteur = " . $GLOBALS['visiteur_session']['id_auteur']); |
|
| 43 | + sql_updateq("spip_auteurs", array("lang" => $lang), "id_auteur = ".$GLOBALS['visiteur_session']['id_auteur']); |
|
| 44 | 44 | $GLOBALS['visiteur_session']['lang'] = $lang; |
| 45 | 45 | $session = charger_fonction('session', 'inc'); |
| 46 | 46 | if ($spip_session = $session($GLOBALS['visiteur_session'])) { |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | // http://doc.spip.org/@action_converser_post |
| 60 | -function action_converser_post($lang, $ecrire=false) |
|
| 60 | +function action_converser_post($lang, $ecrire = false) |
|
| 61 | 61 | { |
| 62 | 62 | if ($lang) { |
| 63 | 63 | include_spip('inc/lang'); |
@@ -10,7 +10,9 @@ discard block |
||
| 10 | 10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 13 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 14 | + return; |
|
| 15 | +} |
|
| 14 | 16 | |
| 15 | 17 | include_spip('inc/cookie'); |
| 16 | 18 | |
@@ -30,15 +32,17 @@ discard block |
||
| 30 | 32 | $lang = action_converser_changer_langue($update_session); |
| 31 | 33 | $redirect = rawurldecode(_request('redirect')); |
| 32 | 34 | |
| 33 | - if (!$redirect) $redirect = _DIR_RESTREINT_ABS; |
|
| 35 | + if (!$redirect) { |
|
| 36 | + $redirect = _DIR_RESTREINT_ABS; |
|
| 37 | + } |
|
| 34 | 38 | $redirect = parametre_url($redirect,'lang',$lang,'&'); |
| 35 | 39 | redirige_par_entete($redirect, true); |
| 36 | 40 | } |
| 37 | 41 | |
| 38 | 42 | function action_converser_changer_langue($update_session){ |
| 39 | - if ($lang = _request('var_lang')) |
|
| 40 | - action_converser_post($lang); |
|
| 41 | - elseif ($lang = _request('var_lang_ecrire')) { |
|
| 43 | + if ($lang = _request('var_lang')) { |
|
| 44 | + action_converser_post($lang); |
|
| 45 | + } elseif ($lang = _request('var_lang_ecrire')) { |
|
| 42 | 46 | if ($update_session) { |
| 43 | 47 | sql_updateq("spip_auteurs", array("lang" => $lang), "id_auteur = " . $GLOBALS['visiteur_session']['id_auteur']); |
| 44 | 48 | $GLOBALS['visiteur_session']['lang'] = $lang; |
@@ -63,8 +67,9 @@ discard block |
||
| 63 | 67 | include_spip('inc/lang'); |
| 64 | 68 | if (changer_langue($lang)) { |
| 65 | 69 | spip_setcookie('spip_lang', $_COOKIE['spip_lang'] = $lang, time() + 365 * 24 * 3600); |
| 66 | - if ($ecrire) |
|
| 67 | - spip_setcookie('spip_lang_ecrire', $_COOKIE['spip_lang_ecrire'] = $lang, time() + 365 * 24 * 3600); |
|
| 70 | + if ($ecrire) { |
|
| 71 | + spip_setcookie('spip_lang_ecrire', $_COOKIE['spip_lang_ecrire'] = $lang, time() + 365 * 24 * 3600); |
|
| 72 | + } |
|
| 68 | 73 | } |
| 69 | 74 | } |
| 70 | 75 | } |
@@ -221,7 +221,7 @@ |
||
| 221 | 221 | * @param $id_auteur |
| 222 | 222 | * @param $c |
| 223 | 223 | * @param bool $force_webmestre |
| 224 | - * @return bool|string |
|
| 224 | + * @return false|string |
|
| 225 | 225 | */ |
| 226 | 226 | function auteur_instituer($id_auteur, $c, $force_webmestre = false) { |
| 227 | 227 | if (!$id_auteur=intval($id_auteur)) |
@@ -15,38 +15,38 @@ discard block |
||
| 15 | 15 | // http://doc.spip.org/@action_editer_auteur_dist |
| 16 | 16 | function action_editer_auteur_dist($arg=null) { |
| 17 | 17 | |
| 18 | - if (is_null($arg)){ |
|
| 19 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 20 | - $arg = $securiser_action(); |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - |
|
| 24 | - // si id_auteur n'est pas un nombre, c'est une creation |
|
| 25 | - if (!$id_auteur = intval($arg)) { |
|
| 26 | - |
|
| 27 | - if (($id_auteur = auteur_inserer()) > 0){ |
|
| 28 | - |
|
| 29 | - # cf. GROS HACK |
|
| 30 | - # recuperer l'eventuel logo charge avant la creation |
|
| 31 | - # ils ont un id = 0-id_auteur de la session |
|
| 32 | - $id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur']; |
|
| 33 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 34 | - if (list($logo) = $chercher_logo($id_hack, 'id_auteur', 'on')) |
|
| 35 | - rename($logo, str_replace($id_hack, $id_auteur, $logo)); |
|
| 36 | - if (list($logo) = $chercher_logo($id_hack, 'id_auteur', 'off')) |
|
| 37 | - rename($logo, str_replace($id_hack, $id_auteur, $logo)); |
|
| 38 | - } |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - // Enregistre l'envoi dans la BD |
|
| 42 | - $err = ""; |
|
| 43 | - if ($id_auteur > 0) |
|
| 44 | - $err = auteur_modifier($id_auteur); |
|
| 45 | - |
|
| 46 | - if ($err) |
|
| 47 | - spip_log("echec editeur auteur: $err",_LOG_ERREUR); |
|
| 48 | - |
|
| 49 | - return array($id_auteur,$err); |
|
| 18 | + if (is_null($arg)){ |
|
| 19 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 20 | + $arg = $securiser_action(); |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + |
|
| 24 | + // si id_auteur n'est pas un nombre, c'est une creation |
|
| 25 | + if (!$id_auteur = intval($arg)) { |
|
| 26 | + |
|
| 27 | + if (($id_auteur = auteur_inserer()) > 0){ |
|
| 28 | + |
|
| 29 | + # cf. GROS HACK |
|
| 30 | + # recuperer l'eventuel logo charge avant la creation |
|
| 31 | + # ils ont un id = 0-id_auteur de la session |
|
| 32 | + $id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur']; |
|
| 33 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 34 | + if (list($logo) = $chercher_logo($id_hack, 'id_auteur', 'on')) |
|
| 35 | + rename($logo, str_replace($id_hack, $id_auteur, $logo)); |
|
| 36 | + if (list($logo) = $chercher_logo($id_hack, 'id_auteur', 'off')) |
|
| 37 | + rename($logo, str_replace($id_hack, $id_auteur, $logo)); |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + // Enregistre l'envoi dans la BD |
|
| 42 | + $err = ""; |
|
| 43 | + if ($id_auteur > 0) |
|
| 44 | + $err = auteur_modifier($id_auteur); |
|
| 45 | + |
|
| 46 | + if ($err) |
|
| 47 | + spip_log("echec editeur auteur: $err",_LOG_ERREUR); |
|
| 48 | + |
|
| 49 | + return array($id_auteur,$err); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -56,34 +56,34 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | function auteur_inserer($source=null) { |
| 58 | 58 | |
| 59 | - // Ce qu'on va demander comme modifications |
|
| 60 | - $champs = array(); |
|
| 61 | - $champs['source'] = $source?$source:'spip'; |
|
| 62 | - |
|
| 63 | - $champs['login'] = ''; |
|
| 64 | - $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 65 | - $champs['webmestre'] = 'non'; |
|
| 66 | - |
|
| 67 | - // Envoyer aux plugins |
|
| 68 | - $champs = pipeline('pre_insertion', |
|
| 69 | - array( |
|
| 70 | - 'args' => array( |
|
| 71 | - 'table' => 'spip_auteurs', |
|
| 72 | - ), |
|
| 73 | - 'data' => $champs |
|
| 74 | - ) |
|
| 75 | - ); |
|
| 76 | - $id_auteur = sql_insertq("spip_auteurs", $champs); |
|
| 77 | - pipeline('post_insertion', |
|
| 78 | - array( |
|
| 79 | - 'args' => array( |
|
| 80 | - 'table' => 'spip_auteurs', |
|
| 81 | - 'id_objet' => $id_auteur |
|
| 82 | - ), |
|
| 83 | - 'data' => $champs |
|
| 84 | - ) |
|
| 85 | - ); |
|
| 86 | - return $id_auteur; |
|
| 59 | + // Ce qu'on va demander comme modifications |
|
| 60 | + $champs = array(); |
|
| 61 | + $champs['source'] = $source?$source:'spip'; |
|
| 62 | + |
|
| 63 | + $champs['login'] = ''; |
|
| 64 | + $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 65 | + $champs['webmestre'] = 'non'; |
|
| 66 | + |
|
| 67 | + // Envoyer aux plugins |
|
| 68 | + $champs = pipeline('pre_insertion', |
|
| 69 | + array( |
|
| 70 | + 'args' => array( |
|
| 71 | + 'table' => 'spip_auteurs', |
|
| 72 | + ), |
|
| 73 | + 'data' => $champs |
|
| 74 | + ) |
|
| 75 | + ); |
|
| 76 | + $id_auteur = sql_insertq("spip_auteurs", $champs); |
|
| 77 | + pipeline('post_insertion', |
|
| 78 | + array( |
|
| 79 | + 'args' => array( |
|
| 80 | + 'table' => 'spip_auteurs', |
|
| 81 | + 'id_objet' => $id_auteur |
|
| 82 | + ), |
|
| 83 | + 'data' => $champs |
|
| 84 | + ) |
|
| 85 | + ); |
|
| 86 | + return $id_auteur; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | |
@@ -99,55 +99,55 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | function auteur_modifier($id_auteur, $set = null, $force_update=false) { |
| 101 | 101 | |
| 102 | - include_spip('inc/modifier'); |
|
| 103 | - include_spip('inc/filtres'); |
|
| 104 | - $c = collecter_requests( |
|
| 105 | - // white list |
|
| 106 | - objet_info('auteur','champs_editables'), |
|
| 107 | - // black list |
|
| 108 | - $force_update?array():array('webmestre','pass','login'), |
|
| 109 | - // donnees eventuellement fournies |
|
| 110 | - $set |
|
| 111 | - ); |
|
| 112 | - |
|
| 113 | - if ($err = objet_modifier_champs('auteur', $id_auteur, |
|
| 114 | - array( |
|
| 115 | - 'data' => $set, |
|
| 116 | - 'nonvide' => array('nom' => _T('ecrire:item_nouvel_auteur')) |
|
| 117 | - ), |
|
| 118 | - $c)) |
|
| 119 | - return $err; |
|
| 120 | - $session = $c; |
|
| 121 | - |
|
| 122 | - $err = ''; |
|
| 123 | - if (!$force_update){ |
|
| 124 | - // Modification de statut, changement de rubrique ? |
|
| 125 | - $c = collecter_requests( |
|
| 126 | - // white list |
|
| 127 | - array( |
|
| 128 | - 'statut', 'new_login','new_pass','login','pass','webmestre','restreintes','id_parent' |
|
| 129 | - ), |
|
| 130 | - // black list |
|
| 131 | - array(), |
|
| 132 | - // donnees eventuellement fournies |
|
| 133 | - $set |
|
| 134 | - ); |
|
| 135 | - if (isset($c['new_login']) AND !isset($c['login'])) |
|
| 136 | - $c['login'] = $c['new_login']; |
|
| 137 | - if (isset($c['new_pass']) AND !isset($c['pass'])) |
|
| 138 | - $c['pass'] = $c['new_pass']; |
|
| 139 | - $err = auteur_instituer($id_auteur, $c); |
|
| 140 | - $session = array_merge($session,$c); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - // .. mettre a jour les sessions de cet auteur |
|
| 144 | - include_spip('inc/session'); |
|
| 145 | - $session['id_auteur'] = $id_auteur; |
|
| 146 | - unset($session['new_login']); |
|
| 147 | - unset($session['new_pass']); |
|
| 148 | - actualiser_sessions($session); |
|
| 149 | - |
|
| 150 | - return $err; |
|
| 102 | + include_spip('inc/modifier'); |
|
| 103 | + include_spip('inc/filtres'); |
|
| 104 | + $c = collecter_requests( |
|
| 105 | + // white list |
|
| 106 | + objet_info('auteur','champs_editables'), |
|
| 107 | + // black list |
|
| 108 | + $force_update?array():array('webmestre','pass','login'), |
|
| 109 | + // donnees eventuellement fournies |
|
| 110 | + $set |
|
| 111 | + ); |
|
| 112 | + |
|
| 113 | + if ($err = objet_modifier_champs('auteur', $id_auteur, |
|
| 114 | + array( |
|
| 115 | + 'data' => $set, |
|
| 116 | + 'nonvide' => array('nom' => _T('ecrire:item_nouvel_auteur')) |
|
| 117 | + ), |
|
| 118 | + $c)) |
|
| 119 | + return $err; |
|
| 120 | + $session = $c; |
|
| 121 | + |
|
| 122 | + $err = ''; |
|
| 123 | + if (!$force_update){ |
|
| 124 | + // Modification de statut, changement de rubrique ? |
|
| 125 | + $c = collecter_requests( |
|
| 126 | + // white list |
|
| 127 | + array( |
|
| 128 | + 'statut', 'new_login','new_pass','login','pass','webmestre','restreintes','id_parent' |
|
| 129 | + ), |
|
| 130 | + // black list |
|
| 131 | + array(), |
|
| 132 | + // donnees eventuellement fournies |
|
| 133 | + $set |
|
| 134 | + ); |
|
| 135 | + if (isset($c['new_login']) AND !isset($c['login'])) |
|
| 136 | + $c['login'] = $c['new_login']; |
|
| 137 | + if (isset($c['new_pass']) AND !isset($c['pass'])) |
|
| 138 | + $c['pass'] = $c['new_pass']; |
|
| 139 | + $err = auteur_instituer($id_auteur, $c); |
|
| 140 | + $session = array_merge($session,$c); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + // .. mettre a jour les sessions de cet auteur |
|
| 144 | + include_spip('inc/session'); |
|
| 145 | + $session['id_auteur'] = $id_auteur; |
|
| 146 | + unset($session['new_login']); |
|
| 147 | + unset($session['new_pass']); |
|
| 148 | + actualiser_sessions($session); |
|
| 149 | + |
|
| 150 | + return $err; |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -165,8 +165,8 @@ discard block |
||
| 165 | 165 | * @return string |
| 166 | 166 | */ |
| 167 | 167 | function auteur_associer($id_auteur,$objets, $qualif = null){ |
| 168 | - include_spip('action/editer_liens'); |
|
| 169 | - return objet_associer(array('auteur'=>$id_auteur), $objets, $qualif); |
|
| 168 | + include_spip('action/editer_liens'); |
|
| 169 | + return objet_associer(array('auteur'=>$id_auteur), $objets, $qualif); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * @return string |
| 178 | 178 | */ |
| 179 | 179 | function auteur_referent($id_auteur,$c){ |
| 180 | - return auteur_associer($id_auteur,$c); |
|
| 180 | + return auteur_associer($id_auteur,$c); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
@@ -192,8 +192,8 @@ discard block |
||
| 192 | 192 | * @return string |
| 193 | 193 | */ |
| 194 | 194 | function auteur_dissocier($id_auteur,$objets){ |
| 195 | - include_spip('action/editer_liens'); |
|
| 196 | - return objet_dissocier(array('auteur'=>$id_auteur), $objets); |
|
| 195 | + include_spip('action/editer_liens'); |
|
| 196 | + return objet_dissocier(array('auteur'=>$id_auteur), $objets); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | /** |
@@ -210,8 +210,8 @@ discard block |
||
| 210 | 210 | * @return bool|int |
| 211 | 211 | */ |
| 212 | 212 | function auteur_qualifier($id_auteur,$objets,$qualif){ |
| 213 | - include_spip('action/editer_liens'); |
|
| 214 | - return objet_qualifier_liens(array('auteur'=>$id_auteur), $objets, $qualif); |
|
| 213 | + include_spip('action/editer_liens'); |
|
| 214 | + return objet_qualifier_liens(array('auteur'=>$id_auteur), $objets, $qualif); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | |
@@ -224,114 +224,114 @@ discard block |
||
| 224 | 224 | * @return bool|string |
| 225 | 225 | */ |
| 226 | 226 | function auteur_instituer($id_auteur, $c, $force_webmestre = false) { |
| 227 | - if (!$id_auteur=intval($id_auteur)) |
|
| 228 | - return false; |
|
| 229 | - $erreurs = array(); // contiendra les differentes erreurs a traduire par _T() |
|
| 230 | - $champs = array(); |
|
| 231 | - |
|
| 232 | - // les memoriser pour les faire passer dans le pipeline pre_edition |
|
| 233 | - if (isset($c['login']) AND strlen($c['login'])) |
|
| 234 | - $champs['login'] = $c['login']; |
|
| 235 | - if (isset($c['pass']) AND strlen($c['pass'])) |
|
| 236 | - $champs['pass'] = $c['pass']; |
|
| 237 | - |
|
| 238 | - $statut = $statut_ancien = sql_getfetsel('statut','spip_auteurs','id_auteur='.intval($id_auteur)); |
|
| 227 | + if (!$id_auteur=intval($id_auteur)) |
|
| 228 | + return false; |
|
| 229 | + $erreurs = array(); // contiendra les differentes erreurs a traduire par _T() |
|
| 230 | + $champs = array(); |
|
| 231 | + |
|
| 232 | + // les memoriser pour les faire passer dans le pipeline pre_edition |
|
| 233 | + if (isset($c['login']) AND strlen($c['login'])) |
|
| 234 | + $champs['login'] = $c['login']; |
|
| 235 | + if (isset($c['pass']) AND strlen($c['pass'])) |
|
| 236 | + $champs['pass'] = $c['pass']; |
|
| 237 | + |
|
| 238 | + $statut = $statut_ancien = sql_getfetsel('statut','spip_auteurs','id_auteur='.intval($id_auteur)); |
|
| 239 | 239 | |
| 240 | - if (isset($c['statut']) |
|
| 241 | - AND (autoriser('modifier', 'auteur', $id_auteur,null, array('statut' => $c['statut'])))) |
|
| 242 | - $statut = $champs['statut'] = $c['statut']; |
|
| 243 | - |
|
| 244 | - // Restreindre avant de declarer l'auteur |
|
| 245 | - // (section critique sur les droits) |
|
| 246 | - if ($c['id_parent']) { |
|
| 247 | - if (is_array($c['restreintes'])) |
|
| 248 | - $c['restreintes'][] = $c['id_parent']; |
|
| 249 | - else |
|
| 250 | - $c['restreintes'] = array($c['id_parent']); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - if (isset($c['webmestre']) |
|
| 254 | - AND ($force_webmestre OR autoriser('modifier', 'auteur', $id_auteur,null, array('webmestre' => '?')))) |
|
| 255 | - $champs['webmestre'] = $c['webmestre']=='oui'?'oui':'non'; |
|
| 240 | + if (isset($c['statut']) |
|
| 241 | + AND (autoriser('modifier', 'auteur', $id_auteur,null, array('statut' => $c['statut'])))) |
|
| 242 | + $statut = $champs['statut'] = $c['statut']; |
|
| 243 | + |
|
| 244 | + // Restreindre avant de declarer l'auteur |
|
| 245 | + // (section critique sur les droits) |
|
| 246 | + if ($c['id_parent']) { |
|
| 247 | + if (is_array($c['restreintes'])) |
|
| 248 | + $c['restreintes'][] = $c['id_parent']; |
|
| 249 | + else |
|
| 250 | + $c['restreintes'] = array($c['id_parent']); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + if (isset($c['webmestre']) |
|
| 254 | + AND ($force_webmestre OR autoriser('modifier', 'auteur', $id_auteur,null, array('webmestre' => '?')))) |
|
| 255 | + $champs['webmestre'] = $c['webmestre']=='oui'?'oui':'non'; |
|
| 256 | 256 | |
| 257 | - // Envoyer aux plugins |
|
| 258 | - $champs = pipeline('pre_edition', |
|
| 259 | - array( |
|
| 260 | - 'args' => array( |
|
| 261 | - 'table' => 'spip_auteurs', |
|
| 262 | - 'id_objet' => $id_auteur, |
|
| 263 | - 'action' => 'instituer', |
|
| 264 | - 'statut_ancien' => $statut_ancien, |
|
| 265 | - ), |
|
| 266 | - 'data' => $champs |
|
| 267 | - ) |
|
| 268 | - ); |
|
| 257 | + // Envoyer aux plugins |
|
| 258 | + $champs = pipeline('pre_edition', |
|
| 259 | + array( |
|
| 260 | + 'args' => array( |
|
| 261 | + 'table' => 'spip_auteurs', |
|
| 262 | + 'id_objet' => $id_auteur, |
|
| 263 | + 'action' => 'instituer', |
|
| 264 | + 'statut_ancien' => $statut_ancien, |
|
| 265 | + ), |
|
| 266 | + 'data' => $champs |
|
| 267 | + ) |
|
| 268 | + ); |
|
| 269 | 269 | |
| 270 | - if (is_array($c['restreintes']) |
|
| 271 | - AND autoriser('modifier', 'auteur', $id_auteur, NULL, array('restreint'=>$c['restreintes']))) { |
|
| 272 | - $rubriques = array_map('intval',$c['restreintes']); |
|
| 273 | - $rubriques = array_unique($rubriques); |
|
| 274 | - $rubriques = array_diff($rubriques,array(0)); |
|
| 275 | - auteur_dissocier($id_auteur, array('rubrique'=>'*')); |
|
| 276 | - auteur_associer($id_auteur,array('rubrique'=>$rubriques)); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - $flag_ecrire_acces = false; |
|
| 280 | - // commencer par traiter les cas particuliers des logins et pass |
|
| 281 | - // avant les autres ecritures en base |
|
| 282 | - if (isset($champs['login']) OR isset($champs['pass'])){ |
|
| 283 | - $auth_methode = sql_getfetsel('source','spip_auteurs','id_auteur='.intval($id_auteur)); |
|
| 284 | - include_spip('inc/auth'); |
|
| 285 | - if (isset($champs['login']) AND strlen($champs['login'])) |
|
| 286 | - if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) |
|
| 287 | - $erreurs[] = 'ecrire:impossible_modifier_login_auteur'; |
|
| 288 | - if (isset($champs['pass']) AND strlen($champs['pass'])){ |
|
| 289 | - $champs['login'] = sql_getfetsel('login','spip_auteurs','id_auteur='.intval($id_auteur)); |
|
| 290 | - if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) |
|
| 291 | - $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
|
| 292 | - } |
|
| 293 | - unset($champs['login']); |
|
| 294 | - unset($champs['pass']); |
|
| 295 | - $flag_ecrire_acces = true; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - if (!count($champs)) return implode(' ', array_map('_T', $erreurs)); |
|
| 299 | - sql_updateq('spip_auteurs', $champs , 'id_auteur='.$id_auteur); |
|
| 300 | - |
|
| 301 | - // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
|
| 302 | - if ($flag_ecrire_acces |
|
| 303 | - OR isset($champs['statut']) |
|
| 304 | - ) { |
|
| 305 | - include_spip('inc/acces'); |
|
| 306 | - ecrire_acces(); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - // Invalider les caches |
|
| 310 | - include_spip('inc/invalideur'); |
|
| 311 | - suivre_invalideur("id='auteur/$id_auteur'"); |
|
| 270 | + if (is_array($c['restreintes']) |
|
| 271 | + AND autoriser('modifier', 'auteur', $id_auteur, NULL, array('restreint'=>$c['restreintes']))) { |
|
| 272 | + $rubriques = array_map('intval',$c['restreintes']); |
|
| 273 | + $rubriques = array_unique($rubriques); |
|
| 274 | + $rubriques = array_diff($rubriques,array(0)); |
|
| 275 | + auteur_dissocier($id_auteur, array('rubrique'=>'*')); |
|
| 276 | + auteur_associer($id_auteur,array('rubrique'=>$rubriques)); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + $flag_ecrire_acces = false; |
|
| 280 | + // commencer par traiter les cas particuliers des logins et pass |
|
| 281 | + // avant les autres ecritures en base |
|
| 282 | + if (isset($champs['login']) OR isset($champs['pass'])){ |
|
| 283 | + $auth_methode = sql_getfetsel('source','spip_auteurs','id_auteur='.intval($id_auteur)); |
|
| 284 | + include_spip('inc/auth'); |
|
| 285 | + if (isset($champs['login']) AND strlen($champs['login'])) |
|
| 286 | + if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) |
|
| 287 | + $erreurs[] = 'ecrire:impossible_modifier_login_auteur'; |
|
| 288 | + if (isset($champs['pass']) AND strlen($champs['pass'])){ |
|
| 289 | + $champs['login'] = sql_getfetsel('login','spip_auteurs','id_auteur='.intval($id_auteur)); |
|
| 290 | + if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) |
|
| 291 | + $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
|
| 292 | + } |
|
| 293 | + unset($champs['login']); |
|
| 294 | + unset($champs['pass']); |
|
| 295 | + $flag_ecrire_acces = true; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + if (!count($champs)) return implode(' ', array_map('_T', $erreurs)); |
|
| 299 | + sql_updateq('spip_auteurs', $champs , 'id_auteur='.$id_auteur); |
|
| 300 | + |
|
| 301 | + // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
|
| 302 | + if ($flag_ecrire_acces |
|
| 303 | + OR isset($champs['statut']) |
|
| 304 | + ) { |
|
| 305 | + include_spip('inc/acces'); |
|
| 306 | + ecrire_acces(); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + // Invalider les caches |
|
| 310 | + include_spip('inc/invalideur'); |
|
| 311 | + suivre_invalideur("id='auteur/$id_auteur'"); |
|
| 312 | 312 | |
| 313 | - // Pipeline |
|
| 314 | - pipeline('post_edition', |
|
| 315 | - array( |
|
| 316 | - 'args' => array( |
|
| 317 | - 'table' => 'spip_auteurs', |
|
| 318 | - 'id_objet' => $id_auteur, |
|
| 319 | - 'action' => 'instituer', |
|
| 320 | - 'statut_ancien' => $statut_ancien, |
|
| 321 | - ), |
|
| 322 | - 'data' => $champs |
|
| 323 | - ) |
|
| 324 | - ); |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - // Notifications |
|
| 328 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 329 | - $notifications('instituerauteur', $id_auteur, |
|
| 330 | - array('statut' => $statut, 'statut_ancien' => $statut_ancien) |
|
| 331 | - ); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - return implode(' ', array_map('_T', $erreurs)); |
|
| 313 | + // Pipeline |
|
| 314 | + pipeline('post_edition', |
|
| 315 | + array( |
|
| 316 | + 'args' => array( |
|
| 317 | + 'table' => 'spip_auteurs', |
|
| 318 | + 'id_objet' => $id_auteur, |
|
| 319 | + 'action' => 'instituer', |
|
| 320 | + 'statut_ancien' => $statut_ancien, |
|
| 321 | + ), |
|
| 322 | + 'data' => $champs |
|
| 323 | + ) |
|
| 324 | + ); |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + // Notifications |
|
| 328 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 329 | + $notifications('instituerauteur', $id_auteur, |
|
| 330 | + array('statut' => $statut, 'statut_ancien' => $statut_ancien) |
|
| 331 | + ); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + return implode(' ', array_map('_T', $erreurs)); |
|
| 335 | 335 | |
| 336 | 336 | } |
| 337 | 337 | |
@@ -339,17 +339,17 @@ discard block |
||
| 339 | 339 | |
| 340 | 340 | |
| 341 | 341 | function insert_auteur($source=null) { |
| 342 | - return auteur_inserer($source); |
|
| 342 | + return auteur_inserer($source); |
|
| 343 | 343 | } |
| 344 | 344 | function auteurs_set($id_auteur, $set = null) { |
| 345 | - return auteur_modifier($id_auteur,$set); |
|
| 345 | + return auteur_modifier($id_auteur,$set); |
|
| 346 | 346 | } |
| 347 | 347 | function instituer_auteur($id_auteur, $c, $force_webmestre = false) { |
| 348 | - return auteur_instituer($id_auteur,$c,$force_webmestre); |
|
| 348 | + return auteur_instituer($id_auteur,$c,$force_webmestre); |
|
| 349 | 349 | } |
| 350 | 350 | // http://doc.spip.org/@revision_auteur |
| 351 | 351 | function revision_auteur($id_auteur, $c=false) { |
| 352 | - return auteur_modifier($id_auteur,$c); |
|
| 352 | + return auteur_modifier($id_auteur,$c); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | ?> |
@@ -13,9 +13,9 @@ discard block |
||
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) return; |
| 14 | 14 | |
| 15 | 15 | // http://doc.spip.org/@action_editer_auteur_dist |
| 16 | -function action_editer_auteur_dist($arg=null) { |
|
| 16 | +function action_editer_auteur_dist($arg = null) { |
|
| 17 | 17 | |
| 18 | - if (is_null($arg)){ |
|
| 18 | + if (is_null($arg)) { |
|
| 19 | 19 | $securiser_action = charger_fonction('securiser_action', 'inc'); |
| 20 | 20 | $arg = $securiser_action(); |
| 21 | 21 | } |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | // si id_auteur n'est pas un nombre, c'est une creation |
| 25 | 25 | if (!$id_auteur = intval($arg)) { |
| 26 | 26 | |
| 27 | - if (($id_auteur = auteur_inserer()) > 0){ |
|
| 27 | + if (($id_auteur = auteur_inserer()) > 0) { |
|
| 28 | 28 | |
| 29 | 29 | # cf. GROS HACK |
| 30 | 30 | # recuperer l'eventuel logo charge avant la creation |
@@ -44,9 +44,9 @@ discard block |
||
| 44 | 44 | $err = auteur_modifier($id_auteur); |
| 45 | 45 | |
| 46 | 46 | if ($err) |
| 47 | - spip_log("echec editeur auteur: $err",_LOG_ERREUR); |
|
| 47 | + spip_log("echec editeur auteur: $err", _LOG_ERREUR); |
|
| 48 | 48 | |
| 49 | - return array($id_auteur,$err); |
|
| 49 | + return array($id_auteur, $err); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -54,14 +54,14 @@ discard block |
||
| 54 | 54 | * @param string $source |
| 55 | 55 | * @return int |
| 56 | 56 | */ |
| 57 | -function auteur_inserer($source=null) { |
|
| 57 | +function auteur_inserer($source = null) { |
|
| 58 | 58 | |
| 59 | 59 | // Ce qu'on va demander comme modifications |
| 60 | 60 | $champs = array(); |
| 61 | - $champs['source'] = $source?$source:'spip'; |
|
| 61 | + $champs['source'] = $source ? $source : 'spip'; |
|
| 62 | 62 | |
| 63 | 63 | $champs['login'] = ''; |
| 64 | - $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 64 | + $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 65 | 65 | $champs['webmestre'] = 'non'; |
| 66 | 66 | |
| 67 | 67 | // Envoyer aux plugins |
@@ -97,15 +97,15 @@ discard block |
||
| 97 | 97 | * utilise par auth/spip |
| 98 | 98 | * @return string |
| 99 | 99 | */ |
| 100 | -function auteur_modifier($id_auteur, $set = null, $force_update=false) { |
|
| 100 | +function auteur_modifier($id_auteur, $set = null, $force_update = false) { |
|
| 101 | 101 | |
| 102 | 102 | include_spip('inc/modifier'); |
| 103 | 103 | include_spip('inc/filtres'); |
| 104 | 104 | $c = collecter_requests( |
| 105 | 105 | // white list |
| 106 | - objet_info('auteur','champs_editables'), |
|
| 106 | + objet_info('auteur', 'champs_editables'), |
|
| 107 | 107 | // black list |
| 108 | - $force_update?array():array('webmestre','pass','login'), |
|
| 108 | + $force_update ? array() : array('webmestre', 'pass', 'login'), |
|
| 109 | 109 | // donnees eventuellement fournies |
| 110 | 110 | $set |
| 111 | 111 | ); |
@@ -120,12 +120,12 @@ discard block |
||
| 120 | 120 | $session = $c; |
| 121 | 121 | |
| 122 | 122 | $err = ''; |
| 123 | - if (!$force_update){ |
|
| 123 | + if (!$force_update) { |
|
| 124 | 124 | // Modification de statut, changement de rubrique ? |
| 125 | 125 | $c = collecter_requests( |
| 126 | 126 | // white list |
| 127 | 127 | array( |
| 128 | - 'statut', 'new_login','new_pass','login','pass','webmestre','restreintes','id_parent' |
|
| 128 | + 'statut', 'new_login', 'new_pass', 'login', 'pass', 'webmestre', 'restreintes', 'id_parent' |
|
| 129 | 129 | ), |
| 130 | 130 | // black list |
| 131 | 131 | array(), |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | if (isset($c['new_pass']) AND !isset($c['pass'])) |
| 138 | 138 | $c['pass'] = $c['new_pass']; |
| 139 | 139 | $err = auteur_instituer($id_auteur, $c); |
| 140 | - $session = array_merge($session,$c); |
|
| 140 | + $session = array_merge($session, $c); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | // .. mettre a jour les sessions de cet auteur |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | * @param array $qualif |
| 165 | 165 | * @return string |
| 166 | 166 | */ |
| 167 | -function auteur_associer($id_auteur,$objets, $qualif = null){ |
|
| 167 | +function auteur_associer($id_auteur, $objets, $qualif = null) { |
|
| 168 | 168 | include_spip('action/editer_liens'); |
| 169 | 169 | return objet_associer(array('auteur'=>$id_auteur), $objets, $qualif); |
| 170 | 170 | } |
@@ -176,8 +176,8 @@ discard block |
||
| 176 | 176 | * @param array $c |
| 177 | 177 | * @return string |
| 178 | 178 | */ |
| 179 | -function auteur_referent($id_auteur,$c){ |
|
| 180 | - return auteur_associer($id_auteur,$c); |
|
| 179 | +function auteur_referent($id_auteur, $c) { |
|
| 180 | + return auteur_associer($id_auteur, $c); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | * @param array $objets |
| 192 | 192 | * @return string |
| 193 | 193 | */ |
| 194 | -function auteur_dissocier($id_auteur,$objets){ |
|
| 194 | +function auteur_dissocier($id_auteur, $objets) { |
|
| 195 | 195 | include_spip('action/editer_liens'); |
| 196 | 196 | return objet_dissocier(array('auteur'=>$id_auteur), $objets); |
| 197 | 197 | } |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | * @param array $qualif |
| 210 | 210 | * @return bool|int |
| 211 | 211 | */ |
| 212 | -function auteur_qualifier($id_auteur,$objets,$qualif){ |
|
| 212 | +function auteur_qualifier($id_auteur, $objets, $qualif) { |
|
| 213 | 213 | include_spip('action/editer_liens'); |
| 214 | 214 | return objet_qualifier_liens(array('auteur'=>$id_auteur), $objets, $qualif); |
| 215 | 215 | } |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * @return bool|string |
| 225 | 225 | */ |
| 226 | 226 | function auteur_instituer($id_auteur, $c, $force_webmestre = false) { |
| 227 | - if (!$id_auteur=intval($id_auteur)) |
|
| 227 | + if (!$id_auteur = intval($id_auteur)) |
|
| 228 | 228 | return false; |
| 229 | 229 | $erreurs = array(); // contiendra les differentes erreurs a traduire par _T() |
| 230 | 230 | $champs = array(); |
@@ -235,10 +235,10 @@ discard block |
||
| 235 | 235 | if (isset($c['pass']) AND strlen($c['pass'])) |
| 236 | 236 | $champs['pass'] = $c['pass']; |
| 237 | 237 | |
| 238 | - $statut = $statut_ancien = sql_getfetsel('statut','spip_auteurs','id_auteur='.intval($id_auteur)); |
|
| 238 | + $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur='.intval($id_auteur)); |
|
| 239 | 239 | |
| 240 | 240 | if (isset($c['statut']) |
| 241 | - AND (autoriser('modifier', 'auteur', $id_auteur,null, array('statut' => $c['statut'])))) |
|
| 241 | + AND (autoriser('modifier', 'auteur', $id_auteur, null, array('statut' => $c['statut'])))) |
|
| 242 | 242 | $statut = $champs['statut'] = $c['statut']; |
| 243 | 243 | |
| 244 | 244 | // Restreindre avant de declarer l'auteur |
@@ -251,8 +251,8 @@ discard block |
||
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | if (isset($c['webmestre']) |
| 254 | - AND ($force_webmestre OR autoriser('modifier', 'auteur', $id_auteur,null, array('webmestre' => '?')))) |
|
| 255 | - $champs['webmestre'] = $c['webmestre']=='oui'?'oui':'non'; |
|
| 254 | + AND ($force_webmestre OR autoriser('modifier', 'auteur', $id_auteur, null, array('webmestre' => '?')))) |
|
| 255 | + $champs['webmestre'] = $c['webmestre'] == 'oui' ? 'oui' : 'non'; |
|
| 256 | 256 | |
| 257 | 257 | // Envoyer aux plugins |
| 258 | 258 | $champs = pipeline('pre_edition', |
@@ -269,24 +269,24 @@ discard block |
||
| 269 | 269 | |
| 270 | 270 | if (is_array($c['restreintes']) |
| 271 | 271 | AND autoriser('modifier', 'auteur', $id_auteur, NULL, array('restreint'=>$c['restreintes']))) { |
| 272 | - $rubriques = array_map('intval',$c['restreintes']); |
|
| 272 | + $rubriques = array_map('intval', $c['restreintes']); |
|
| 273 | 273 | $rubriques = array_unique($rubriques); |
| 274 | - $rubriques = array_diff($rubriques,array(0)); |
|
| 274 | + $rubriques = array_diff($rubriques, array(0)); |
|
| 275 | 275 | auteur_dissocier($id_auteur, array('rubrique'=>'*')); |
| 276 | - auteur_associer($id_auteur,array('rubrique'=>$rubriques)); |
|
| 276 | + auteur_associer($id_auteur, array('rubrique'=>$rubriques)); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | $flag_ecrire_acces = false; |
| 280 | 280 | // commencer par traiter les cas particuliers des logins et pass |
| 281 | 281 | // avant les autres ecritures en base |
| 282 | - if (isset($champs['login']) OR isset($champs['pass'])){ |
|
| 283 | - $auth_methode = sql_getfetsel('source','spip_auteurs','id_auteur='.intval($id_auteur)); |
|
| 282 | + if (isset($champs['login']) OR isset($champs['pass'])) { |
|
| 283 | + $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur='.intval($id_auteur)); |
|
| 284 | 284 | include_spip('inc/auth'); |
| 285 | 285 | if (isset($champs['login']) AND strlen($champs['login'])) |
| 286 | 286 | if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) |
| 287 | 287 | $erreurs[] = 'ecrire:impossible_modifier_login_auteur'; |
| 288 | - if (isset($champs['pass']) AND strlen($champs['pass'])){ |
|
| 289 | - $champs['login'] = sql_getfetsel('login','spip_auteurs','id_auteur='.intval($id_auteur)); |
|
| 288 | + if (isset($champs['pass']) AND strlen($champs['pass'])) { |
|
| 289 | + $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur='.intval($id_auteur)); |
|
| 290 | 290 | if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) |
| 291 | 291 | $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
| 292 | 292 | } |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | if (!count($champs)) return implode(' ', array_map('_T', $erreurs)); |
| 299 | - sql_updateq('spip_auteurs', $champs , 'id_auteur='.$id_auteur); |
|
| 299 | + sql_updateq('spip_auteurs', $champs, 'id_auteur='.$id_auteur); |
|
| 300 | 300 | |
| 301 | 301 | // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
| 302 | 302 | if ($flag_ecrire_acces |
@@ -338,18 +338,18 @@ discard block |
||
| 338 | 338 | |
| 339 | 339 | |
| 340 | 340 | |
| 341 | -function insert_auteur($source=null) { |
|
| 341 | +function insert_auteur($source = null) { |
|
| 342 | 342 | return auteur_inserer($source); |
| 343 | 343 | } |
| 344 | 344 | function auteurs_set($id_auteur, $set = null) { |
| 345 | - return auteur_modifier($id_auteur,$set); |
|
| 345 | + return auteur_modifier($id_auteur, $set); |
|
| 346 | 346 | } |
| 347 | 347 | function instituer_auteur($id_auteur, $c, $force_webmestre = false) { |
| 348 | - return auteur_instituer($id_auteur,$c,$force_webmestre); |
|
| 348 | + return auteur_instituer($id_auteur, $c, $force_webmestre); |
|
| 349 | 349 | } |
| 350 | 350 | // http://doc.spip.org/@revision_auteur |
| 351 | -function revision_auteur($id_auteur, $c=false) { |
|
| 352 | - return auteur_modifier($id_auteur,$c); |
|
| 351 | +function revision_auteur($id_auteur, $c = false) { |
|
| 352 | + return auteur_modifier($id_auteur, $c); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | ?> |
@@ -10,7 +10,9 @@ discard block |
||
| 10 | 10 | * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 13 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 14 | + return; |
|
| 15 | +} |
|
| 14 | 16 | |
| 15 | 17 | // http://doc.spip.org/@action_editer_auteur_dist |
| 16 | 18 | function action_editer_auteur_dist($arg=null) { |
@@ -31,20 +33,24 @@ discard block |
||
| 31 | 33 | # ils ont un id = 0-id_auteur de la session |
| 32 | 34 | $id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur']; |
| 33 | 35 | $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
| 34 | - if (list($logo) = $chercher_logo($id_hack, 'id_auteur', 'on')) |
|
| 35 | - rename($logo, str_replace($id_hack, $id_auteur, $logo)); |
|
| 36 | - if (list($logo) = $chercher_logo($id_hack, 'id_auteur', 'off')) |
|
| 37 | - rename($logo, str_replace($id_hack, $id_auteur, $logo)); |
|
| 36 | + if (list($logo) = $chercher_logo($id_hack, 'id_auteur', 'on')) { |
|
| 37 | + rename($logo, str_replace($id_hack, $id_auteur, $logo)); |
|
| 38 | + } |
|
| 39 | + if (list($logo) = $chercher_logo($id_hack, 'id_auteur', 'off')) { |
|
| 40 | + rename($logo, str_replace($id_hack, $id_auteur, $logo)); |
|
| 41 | + } |
|
| 38 | 42 | } |
| 39 | 43 | } |
| 40 | 44 | |
| 41 | 45 | // Enregistre l'envoi dans la BD |
| 42 | 46 | $err = ""; |
| 43 | - if ($id_auteur > 0) |
|
| 44 | - $err = auteur_modifier($id_auteur); |
|
| 47 | + if ($id_auteur > 0) { |
|
| 48 | + $err = auteur_modifier($id_auteur); |
|
| 49 | + } |
|
| 45 | 50 | |
| 46 | - if ($err) |
|
| 47 | - spip_log("echec editeur auteur: $err",_LOG_ERREUR); |
|
| 51 | + if ($err) { |
|
| 52 | + spip_log("echec editeur auteur: $err",_LOG_ERREUR); |
|
| 53 | + } |
|
| 48 | 54 | |
| 49 | 55 | return array($id_auteur,$err); |
| 50 | 56 | } |
@@ -115,8 +121,9 @@ discard block |
||
| 115 | 121 | 'data' => $set, |
| 116 | 122 | 'nonvide' => array('nom' => _T('ecrire:item_nouvel_auteur')) |
| 117 | 123 | ), |
| 118 | - $c)) |
|
| 119 | - return $err; |
|
| 124 | + $c)) { |
|
| 125 | + return $err; |
|
| 126 | + } |
|
| 120 | 127 | $session = $c; |
| 121 | 128 | |
| 122 | 129 | $err = ''; |
@@ -132,10 +139,12 @@ discard block |
||
| 132 | 139 | // donnees eventuellement fournies |
| 133 | 140 | $set |
| 134 | 141 | ); |
| 135 | - if (isset($c['new_login']) AND !isset($c['login'])) |
|
| 136 | - $c['login'] = $c['new_login']; |
|
| 137 | - if (isset($c['new_pass']) AND !isset($c['pass'])) |
|
| 138 | - $c['pass'] = $c['new_pass']; |
|
| 142 | + if (isset($c['new_login']) AND !isset($c['login'])) { |
|
| 143 | + $c['login'] = $c['new_login']; |
|
| 144 | + } |
|
| 145 | + if (isset($c['new_pass']) AND !isset($c['pass'])) { |
|
| 146 | + $c['pass'] = $c['new_pass']; |
|
| 147 | + } |
|
| 139 | 148 | $err = auteur_instituer($id_auteur, $c); |
| 140 | 149 | $session = array_merge($session,$c); |
| 141 | 150 | } |
@@ -224,35 +233,41 @@ discard block |
||
| 224 | 233 | * @return bool|string |
| 225 | 234 | */ |
| 226 | 235 | function auteur_instituer($id_auteur, $c, $force_webmestre = false) { |
| 227 | - if (!$id_auteur=intval($id_auteur)) |
|
| 228 | - return false; |
|
| 236 | + if (!$id_auteur=intval($id_auteur)) { |
|
| 237 | + return false; |
|
| 238 | + } |
|
| 229 | 239 | $erreurs = array(); // contiendra les differentes erreurs a traduire par _T() |
| 230 | 240 | $champs = array(); |
| 231 | 241 | |
| 232 | 242 | // les memoriser pour les faire passer dans le pipeline pre_edition |
| 233 | - if (isset($c['login']) AND strlen($c['login'])) |
|
| 234 | - $champs['login'] = $c['login']; |
|
| 235 | - if (isset($c['pass']) AND strlen($c['pass'])) |
|
| 236 | - $champs['pass'] = $c['pass']; |
|
| 243 | + if (isset($c['login']) AND strlen($c['login'])) { |
|
| 244 | + $champs['login'] = $c['login']; |
|
| 245 | + } |
|
| 246 | + if (isset($c['pass']) AND strlen($c['pass'])) { |
|
| 247 | + $champs['pass'] = $c['pass']; |
|
| 248 | + } |
|
| 237 | 249 | |
| 238 | 250 | $statut = $statut_ancien = sql_getfetsel('statut','spip_auteurs','id_auteur='.intval($id_auteur)); |
| 239 | 251 | |
| 240 | 252 | if (isset($c['statut']) |
| 241 | - AND (autoriser('modifier', 'auteur', $id_auteur,null, array('statut' => $c['statut'])))) |
|
| 242 | - $statut = $champs['statut'] = $c['statut']; |
|
| 253 | + AND (autoriser('modifier', 'auteur', $id_auteur,null, array('statut' => $c['statut'])))) { |
|
| 254 | + $statut = $champs['statut'] = $c['statut']; |
|
| 255 | + } |
|
| 243 | 256 | |
| 244 | 257 | // Restreindre avant de declarer l'auteur |
| 245 | 258 | // (section critique sur les droits) |
| 246 | 259 | if ($c['id_parent']) { |
| 247 | - if (is_array($c['restreintes'])) |
|
| 248 | - $c['restreintes'][] = $c['id_parent']; |
|
| 249 | - else |
|
| 250 | - $c['restreintes'] = array($c['id_parent']); |
|
| 260 | + if (is_array($c['restreintes'])) { |
|
| 261 | + $c['restreintes'][] = $c['id_parent']; |
|
| 262 | + } else { |
|
| 263 | + $c['restreintes'] = array($c['id_parent']); |
|
| 264 | + } |
|
| 251 | 265 | } |
| 252 | 266 | |
| 253 | 267 | if (isset($c['webmestre']) |
| 254 | - AND ($force_webmestre OR autoriser('modifier', 'auteur', $id_auteur,null, array('webmestre' => '?')))) |
|
| 255 | - $champs['webmestre'] = $c['webmestre']=='oui'?'oui':'non'; |
|
| 268 | + AND ($force_webmestre OR autoriser('modifier', 'auteur', $id_auteur,null, array('webmestre' => '?')))) { |
|
| 269 | + $champs['webmestre'] = $c['webmestre']=='oui'?'oui':'non'; |
|
| 270 | + } |
|
| 256 | 271 | |
| 257 | 272 | // Envoyer aux plugins |
| 258 | 273 | $champs = pipeline('pre_edition', |
@@ -282,20 +297,24 @@ discard block |
||
| 282 | 297 | if (isset($champs['login']) OR isset($champs['pass'])){ |
| 283 | 298 | $auth_methode = sql_getfetsel('source','spip_auteurs','id_auteur='.intval($id_auteur)); |
| 284 | 299 | include_spip('inc/auth'); |
| 285 | - if (isset($champs['login']) AND strlen($champs['login'])) |
|
| 286 | - if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) |
|
| 300 | + if (isset($champs['login']) AND strlen($champs['login'])) { |
|
| 301 | + if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) |
|
| 287 | 302 | $erreurs[] = 'ecrire:impossible_modifier_login_auteur'; |
| 303 | + } |
|
| 288 | 304 | if (isset($champs['pass']) AND strlen($champs['pass'])){ |
| 289 | 305 | $champs['login'] = sql_getfetsel('login','spip_auteurs','id_auteur='.intval($id_auteur)); |
| 290 | - if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) |
|
| 291 | - $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
|
| 306 | + if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) { |
|
| 307 | + $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
|
| 308 | + } |
|
| 292 | 309 | } |
| 293 | 310 | unset($champs['login']); |
| 294 | 311 | unset($champs['pass']); |
| 295 | 312 | $flag_ecrire_acces = true; |
| 296 | 313 | } |
| 297 | 314 | |
| 298 | - if (!count($champs)) return implode(' ', array_map('_T', $erreurs)); |
|
| 315 | + if (!count($champs)) { |
|
| 316 | + return implode(' ', array_map('_T', $erreurs)); |
|
| 317 | + } |
|
| 299 | 318 | sql_updateq('spip_auteurs', $champs , 'id_auteur='.$id_auteur); |
| 300 | 319 | |
| 301 | 320 | // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
@@ -208,19 +208,19 @@ discard block |
||
| 208 | 208 | * @api |
| 209 | 209 | * @uses sql_select() |
| 210 | 210 | * |
| 211 | - * @param array|string $select |
|
| 211 | + * @param string $select |
|
| 212 | 212 | * Liste des champs a recuperer (Select) |
| 213 | - * @param array|string $from |
|
| 213 | + * @param string $from |
|
| 214 | 214 | * Tables a consulter (From) |
| 215 | - * @param array|string $where |
|
| 215 | + * @param string $where |
|
| 216 | 216 | * Conditions a remplir (Where) |
| 217 | - * @param array|string $groupby |
|
| 217 | + * @param string $groupby |
|
| 218 | 218 | * Critere de regroupement (Group by) |
| 219 | - * @param array|string $orderby |
|
| 219 | + * @param string $orderby |
|
| 220 | 220 | * Tableau de classement (Order By) |
| 221 | 221 | * @param string $limit |
| 222 | 222 | * Critere de limite (Limit) |
| 223 | - * @param array $having |
|
| 223 | + * @param string $having |
|
| 224 | 224 | * Tableau des des post-conditions a remplir (Having) |
| 225 | 225 | * @param string $serveur |
| 226 | 226 | * Le serveur sollicite (pour retrouver la connexion) |
@@ -249,9 +249,9 @@ discard block |
||
| 249 | 249 | * Tables a consulter (From) |
| 250 | 250 | * @param array|string $where |
| 251 | 251 | * Conditions a remplir (Where) |
| 252 | - * @param array|string $groupby |
|
| 252 | + * @param string $groupby |
|
| 253 | 253 | * Critere de regroupement (Group by) |
| 254 | - * @param array $having |
|
| 254 | + * @param string $having |
|
| 255 | 255 | * Tableau des des post-conditions a remplir (Having) |
| 256 | 256 | * @param string $serveur |
| 257 | 257 | * Le serveur sollicite (pour retrouver la connexion) |
@@ -507,6 +507,9 @@ discard block |
||
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | // http://doc.spip.org/@sql_update |
| 510 | +/** |
|
| 511 | + * @param string $table |
|
| 512 | + */ |
|
| 510 | 513 | function sql_update($table, $exp, $where='', $desc=array(), $serveur='', $option=true) |
| 511 | 514 | { |
| 512 | 515 | $f = sql_serveur('update', $serveur, $option==='continue' OR $option===false); |
@@ -540,6 +543,9 @@ discard block |
||
| 540 | 543 | } |
| 541 | 544 | |
| 542 | 545 | // http://doc.spip.org/@sql_replace |
| 546 | +/** |
|
| 547 | + * @param string $table |
|
| 548 | + */ |
|
| 543 | 549 | function sql_replace($table, $couples, $desc=array(), $serveur='', $option=true) |
| 544 | 550 | { |
| 545 | 551 | $f = sql_serveur('replace', $serveur, $option==='continue' OR $option===false); |
@@ -663,6 +669,9 @@ discard block |
||
| 663 | 669 | } |
| 664 | 670 | |
| 665 | 671 | // http://doc.spip.org/@sql_create |
| 672 | +/** |
|
| 673 | + * @param string $nom |
|
| 674 | + */ |
|
| 666 | 675 | function sql_create($nom, $champs, $cles=array(), $autoinc=false, $temporary=false, $serveur='', $option=true) { |
| 667 | 676 | $f = sql_serveur('create', $serveur, $option==='continue' OR $option===false); |
| 668 | 677 | if (!is_string($f) OR !$f) return false; |
@@ -694,6 +703,9 @@ discard block |
||
| 694 | 703 | } |
| 695 | 704 | |
| 696 | 705 | // http://doc.spip.org/@sql_multi |
| 706 | +/** |
|
| 707 | + * @param string $sel |
|
| 708 | + */ |
|
| 697 | 709 | function sql_multi($sel, $lang, $serveur='', $option=true) |
| 698 | 710 | { |
| 699 | 711 | $f = sql_serveur('multi', $serveur, $option==='continue' OR $option===false); |
@@ -753,6 +765,9 @@ discard block |
||
| 753 | 765 | } |
| 754 | 766 | |
| 755 | 767 | // http://doc.spip.org/@sql_repair |
| 768 | +/** |
|
| 769 | + * @return string |
|
| 770 | + */ |
|
| 756 | 771 | function sql_repair($table, $serveur='', $option=true) { |
| 757 | 772 | $f = sql_serveur('repair', $serveur, $option==='continue' OR $option===false); |
| 758 | 773 | if (!is_string($f) OR !$f) return false; |
@@ -765,6 +780,9 @@ discard block |
||
| 765 | 780 | // A n'utiliser qu'en derniere extremite |
| 766 | 781 | |
| 767 | 782 | // http://doc.spip.org/@sql_query |
| 783 | +/** |
|
| 784 | + * @param string $ins |
|
| 785 | + */ |
|
| 768 | 786 | function sql_query($ins, $serveur='', $option=true) { |
| 769 | 787 | $f = sql_serveur('query', $serveur, $option==='continue' OR $option===false); |
| 770 | 788 | if (!is_string($f) OR !$f) return false; |
@@ -852,13 +870,13 @@ discard block |
||
| 852 | 870 | * Tables a consulter (From) |
| 853 | 871 | * @param array|string $where |
| 854 | 872 | * Conditions a remplir (Where) |
| 855 | - * @param array|string $groupby |
|
| 873 | + * @param string $groupby |
|
| 856 | 874 | * Critere de regroupement (Group by) |
| 857 | - * @param array|string $orderby |
|
| 875 | + * @param string $orderby |
|
| 858 | 876 | * Tableau de classement (Order By) |
| 859 | 877 | * @param string $limit |
| 860 | 878 | * Critere de limite (Limit) |
| 861 | - * @param array $having |
|
| 879 | + * @param string $having |
|
| 862 | 880 | * Tableau des des post-conditions a remplir (Having) |
| 863 | 881 | * @param string $serveur |
| 864 | 882 | * Le serveur sollicite (pour retrouver la connexion) |
@@ -1107,6 +1125,11 @@ discard block |
||
| 1107 | 1125 | return $f($val, $type); |
| 1108 | 1126 | } |
| 1109 | 1127 | |
| 1128 | +/** |
|
| 1129 | + * @param string $champ |
|
| 1130 | + * @param double $interval |
|
| 1131 | + * @param string $unite |
|
| 1132 | + */ |
|
| 1110 | 1133 | function sql_date_proche($champ, $interval, $unite, $serveur='', $option=true) |
| 1111 | 1134 | { |
| 1112 | 1135 | $f = sql_serveur('date_proche', $serveur, true); |
@@ -1159,6 +1182,10 @@ discard block |
||
| 1159 | 1182 | // s'il accepte les requetes imbriquees afin d'optimiser ca |
| 1160 | 1183 | |
| 1161 | 1184 | // http://doc.spip.org/@sql_in_select |
| 1185 | +/** |
|
| 1186 | + * @param string $in |
|
| 1187 | + * @param string $select |
|
| 1188 | + */ |
|
| 1162 | 1189 | function sql_in_select($in, $select, $from = array(), $where = array(), |
| 1163 | 1190 | $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur='') |
| 1164 | 1191 | { |
@@ -53,13 +53,13 @@ discard block |
||
| 53 | 53 | * |
| 54 | 54 | **/ |
| 55 | 55 | function sql_serveur($ins_sql='', $serveur='', $continue=false) { |
| 56 | - static $sql_serveur = array(); |
|
| 57 | - if (!isset($sql_serveur[$serveur][$ins_sql])){ |
|
| 58 | - $f = spip_connect_sql(sql_ABSTRACT_VERSION, $ins_sql, $serveur, $continue); |
|
| 59 | - if (!is_string($f) OR !$f) return $f; |
|
| 60 | - $sql_serveur[$serveur][$ins_sql] = $f; |
|
| 61 | - } |
|
| 62 | - return $sql_serveur[$serveur][$ins_sql]; |
|
| 56 | + static $sql_serveur = array(); |
|
| 57 | + if (!isset($sql_serveur[$serveur][$ins_sql])){ |
|
| 58 | + $f = spip_connect_sql(sql_ABSTRACT_VERSION, $ins_sql, $serveur, $continue); |
|
| 59 | + if (!is_string($f) OR !$f) return $f; |
|
| 60 | + $sql_serveur[$serveur][$ins_sql] = $f; |
|
| 61 | + } |
|
| 62 | + return $sql_serveur[$serveur][$ins_sql]; |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -81,16 +81,16 @@ discard block |
||
| 81 | 81 | * Retourne le nom du charset si effectivement trouve, sinon false. |
| 82 | 82 | **/ |
| 83 | 83 | function sql_get_charset($charset, $serveur='', $option=true){ |
| 84 | - // le nom http du charset differe parfois du nom SQL utf-8 ==> utf8 etc. |
|
| 85 | - $desc = sql_serveur('', $serveur, true,true); |
|
| 86 | - $desc = $desc[sql_ABSTRACT_VERSION]; |
|
| 87 | - $c = $desc['charsets'][$charset]; |
|
| 88 | - if ($c) { |
|
| 89 | - if (function_exists($f=@$desc['get_charset'])) |
|
| 90 | - if ($f($c, $serveur, $option!==false)) return $c; |
|
| 91 | - } |
|
| 92 | - spip_log( "SPIP ne connait pas les Charsets disponibles sur le serveur $serveur. Le serveur choisira seul.", _LOG_AVERTISSEMENT); |
|
| 93 | - return false; |
|
| 84 | + // le nom http du charset differe parfois du nom SQL utf-8 ==> utf8 etc. |
|
| 85 | + $desc = sql_serveur('', $serveur, true,true); |
|
| 86 | + $desc = $desc[sql_ABSTRACT_VERSION]; |
|
| 87 | + $c = $desc['charsets'][$charset]; |
|
| 88 | + if ($c) { |
|
| 89 | + if (function_exists($f=@$desc['get_charset'])) |
|
| 90 | + if ($f($c, $serveur, $option!==false)) return $c; |
|
| 91 | + } |
|
| 92 | + spip_log( "SPIP ne connait pas les Charsets disponibles sur le serveur $serveur. Le serveur choisira seul.", _LOG_AVERTISSEMENT); |
|
| 93 | + return false; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | |
@@ -116,9 +116,9 @@ discard block |
||
| 116 | 116 | * Retourne true si elle reussie. |
| 117 | 117 | **/ |
| 118 | 118 | function sql_set_charset($charset,$serveur='', $option=true){ |
| 119 | - $f = sql_serveur('set_charset', $serveur, $option==='continue' OR $option===false); |
|
| 120 | - if (!is_string($f) OR !$f) return false; |
|
| 121 | - return $f($charset, $serveur, $option!==false); |
|
| 119 | + $f = sql_serveur('set_charset', $serveur, $option==='continue' OR $option===false); |
|
| 120 | + if (!is_string($f) OR !$f) return false; |
|
| 121 | + return $f($charset, $serveur, $option!==false); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | |
@@ -168,33 +168,33 @@ discard block |
||
| 168 | 168 | * |
| 169 | 169 | **/ |
| 170 | 170 | function sql_select ($select = array(), $from = array(), $where = array(), |
| 171 | - $groupby = array(), $orderby = array(), $limit = '', $having = array(), |
|
| 172 | - $serveur='', $option=true) { |
|
| 173 | - $f = sql_serveur('select', $serveur, $option==='continue' OR $option===false); |
|
| 174 | - if (!is_string($f) OR !$f) return false; |
|
| 175 | - |
|
| 176 | - $debug = (defined('_VAR_MODE') AND _VAR_MODE == 'debug'); |
|
| 177 | - if (($option !== false) AND !$debug) { |
|
| 178 | - $res = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, is_array($option) ? true : $option); |
|
| 179 | - } else { |
|
| 180 | - $query = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 181 | - if (!$option) return $query; |
|
| 182 | - // le debug, c'est pour ce qui a ete produit par le compilateur |
|
| 183 | - if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 184 | - list($table, $id,) = $GLOBALS['debug']['aucasou']; |
|
| 185 | - $nom = $GLOBALS['debug_objets']['courant'] . $id; |
|
| 186 | - $GLOBALS['debug_objets']['requete'][$nom] = $query; |
|
| 187 | - } |
|
| 188 | - $res = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, true); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - // en cas d'erreur |
|
| 192 | - if (!is_string($res)) return $res; |
|
| 193 | - // denoncer l'erreur SQL dans sa version brute |
|
| 194 | - spip_sql_erreur($serveur); |
|
| 195 | - // idem dans sa version squelette (prefixe des tables non substitue) |
|
| 196 | - erreur_squelette(array(sql_errno($serveur), sql_error($serveur), $res), $option); |
|
| 197 | - return false; |
|
| 171 | + $groupby = array(), $orderby = array(), $limit = '', $having = array(), |
|
| 172 | + $serveur='', $option=true) { |
|
| 173 | + $f = sql_serveur('select', $serveur, $option==='continue' OR $option===false); |
|
| 174 | + if (!is_string($f) OR !$f) return false; |
|
| 175 | + |
|
| 176 | + $debug = (defined('_VAR_MODE') AND _VAR_MODE == 'debug'); |
|
| 177 | + if (($option !== false) AND !$debug) { |
|
| 178 | + $res = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, is_array($option) ? true : $option); |
|
| 179 | + } else { |
|
| 180 | + $query = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 181 | + if (!$option) return $query; |
|
| 182 | + // le debug, c'est pour ce qui a ete produit par le compilateur |
|
| 183 | + if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 184 | + list($table, $id,) = $GLOBALS['debug']['aucasou']; |
|
| 185 | + $nom = $GLOBALS['debug_objets']['courant'] . $id; |
|
| 186 | + $GLOBALS['debug_objets']['requete'][$nom] = $query; |
|
| 187 | + } |
|
| 188 | + $res = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, true); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + // en cas d'erreur |
|
| 192 | + if (!is_string($res)) return $res; |
|
| 193 | + // denoncer l'erreur SQL dans sa version brute |
|
| 194 | + spip_sql_erreur($serveur); |
|
| 195 | + // idem dans sa version squelette (prefixe des tables non substitue) |
|
| 196 | + erreur_squelette(array(sql_errno($serveur), sql_error($serveur), $res), $option); |
|
| 197 | + return false; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | |
@@ -231,9 +231,9 @@ discard block |
||
| 231 | 231 | * |
| 232 | 232 | **/ |
| 233 | 233 | function sql_get_select($select = array(), $from = array(), $where = array(), |
| 234 | - $groupby = array(), $orderby = array(), $limit = '', $having = array(), |
|
| 235 | - $serveur='') { |
|
| 236 | - return sql_select ($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 234 | + $groupby = array(), $orderby = array(), $limit = '', $having = array(), |
|
| 235 | + $serveur='') { |
|
| 236 | + return sql_select ($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | |
@@ -267,13 +267,13 @@ discard block |
||
| 267 | 267 | * |
| 268 | 268 | **/ |
| 269 | 269 | function sql_countsel($from = array(), $where = array(), |
| 270 | - $groupby = array(), $having = array(), |
|
| 271 | - $serveur='', $option=true) { |
|
| 272 | - $f = sql_serveur('countsel', $serveur, $option==='continue' OR $option===false); |
|
| 273 | - if (!is_string($f) OR !$f) return false; |
|
| 274 | - $r = $f($from, $where, $groupby, $having, $serveur, $option!==false); |
|
| 275 | - if ($r===false) spip_sql_erreur($serveur); |
|
| 276 | - return $r; |
|
| 270 | + $groupby = array(), $having = array(), |
|
| 271 | + $serveur='', $option=true) { |
|
| 272 | + $f = sql_serveur('countsel', $serveur, $option==='continue' OR $option===false); |
|
| 273 | + if (!is_string($f) OR !$f) return false; |
|
| 274 | + $r = $f($from, $where, $groupby, $having, $serveur, $option!==false); |
|
| 275 | + if ($r===false) spip_sql_erreur($serveur); |
|
| 276 | + return $r; |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | /** |
@@ -300,11 +300,11 @@ discard block |
||
| 300 | 300 | * Ce retour n'est pas pertinent pour savoir si l'operation est correctement realisee. |
| 301 | 301 | **/ |
| 302 | 302 | function sql_alter($q, $serveur='', $option=true) { |
| 303 | - $f = sql_serveur('alter', $serveur, $option==='continue' OR $option===false); |
|
| 304 | - if (!is_string($f) OR !$f) return false; |
|
| 305 | - $r = $f($q, $serveur, $option!==false); |
|
| 306 | - if ($r===false) spip_sql_erreur($serveur); |
|
| 307 | - return $r; |
|
| 303 | + $f = sql_serveur('alter', $serveur, $option==='continue' OR $option===false); |
|
| 304 | + if (!is_string($f) OR !$f) return false; |
|
| 305 | + $r = $f($q, $serveur, $option!==false); |
|
| 306 | + if ($r===false) spip_sql_erreur($serveur); |
|
| 307 | + return $r; |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | /** |
@@ -327,9 +327,9 @@ discard block |
||
| 327 | 327 | * presentant une ligne de resultat d'une selection |
| 328 | 328 | */ |
| 329 | 329 | function sql_fetch($res, $serveur='', $option=true) { |
| 330 | - $f = sql_serveur('fetch', $serveur, $option==='continue' OR $option===false); |
|
| 331 | - if (!is_string($f) OR !$f) return false; |
|
| 332 | - return $f($res, NULL, $serveur, $option!==false); |
|
| 330 | + $f = sql_serveur('fetch', $serveur, $option==='continue' OR $option===false); |
|
| 331 | + if (!is_string($f) OR !$f) return false; |
|
| 332 | + return $f($res, NULL, $serveur, $option!==false); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | |
@@ -356,14 +356,14 @@ discard block |
||
| 356 | 356 | * presentant une ligne de resultat d'une selection |
| 357 | 357 | */ |
| 358 | 358 | function sql_fetch_all($res, $serveur='', $option=true){ |
| 359 | - $rows = array(); |
|
| 360 | - if (!$res) return $rows; |
|
| 361 | - $f = sql_serveur('fetch', $serveur, $option==='continue' OR $option===false); |
|
| 362 | - if (!is_string($f) OR !$f) return array(); |
|
| 363 | - while ($r = $f($res, NULL, $serveur, $option!==false)) |
|
| 364 | - $rows[] = $r; |
|
| 365 | - sql_free($res, $serveur); |
|
| 366 | - return $rows; |
|
| 359 | + $rows = array(); |
|
| 360 | + if (!$res) return $rows; |
|
| 361 | + $f = sql_serveur('fetch', $serveur, $option==='continue' OR $option===false); |
|
| 362 | + if (!is_string($f) OR !$f) return array(); |
|
| 363 | + while ($r = $f($res, NULL, $serveur, $option!==false)) |
|
| 364 | + $rows[] = $r; |
|
| 365 | + sql_free($res, $serveur); |
|
| 366 | + return $rows; |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | /** |
@@ -391,11 +391,11 @@ discard block |
||
| 391 | 391 | * Operation effectuee (true), sinon false. |
| 392 | 392 | **/ |
| 393 | 393 | function sql_seek($res, $row_number, $serveur='', $option=true) { |
| 394 | - $f = sql_serveur('seek', $serveur, $option==='continue' OR $option===false); |
|
| 395 | - if (!is_string($f) OR !$f) return false; |
|
| 396 | - $r = $f($res, $row_number, $serveur, $option!==false); |
|
| 397 | - if ($r===false) spip_sql_erreur($serveur); |
|
| 398 | - return $r; |
|
| 394 | + $f = sql_serveur('seek', $serveur, $option==='continue' OR $option===false); |
|
| 395 | + if (!is_string($f) OR !$f) return false; |
|
| 396 | + $r = $f($res, $row_number, $serveur, $option!==false); |
|
| 397 | + if ($r===false) spip_sql_erreur($serveur); |
|
| 398 | + return $r; |
|
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | |
@@ -420,11 +420,11 @@ discard block |
||
| 420 | 420 | * False en cas d'erreur. |
| 421 | 421 | **/ |
| 422 | 422 | function sql_listdbs($serveur='', $option=true) { |
| 423 | - $f = sql_serveur('listdbs', $serveur, $option==='continue' OR $option===false); |
|
| 424 | - if (!is_string($f) OR !$f) return false; |
|
| 425 | - $r = $f($serveur); |
|
| 426 | - if ($r===false) spip_sql_erreur($serveur); |
|
| 427 | - return $r; |
|
| 423 | + $f = sql_serveur('listdbs', $serveur, $option==='continue' OR $option===false); |
|
| 424 | + if (!is_string($f) OR !$f) return false; |
|
| 425 | + $r = $f($serveur); |
|
| 426 | + if ($r===false) spip_sql_erreur($serveur); |
|
| 427 | + return $r; |
|
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | |
@@ -447,29 +447,29 @@ discard block |
||
| 447 | 447 | **/ |
| 448 | 448 | function sql_selectdb($nom, $serveur='', $option=true) |
| 449 | 449 | { |
| 450 | - $f = sql_serveur('selectdb', $serveur, $option==='continue' OR $option===false); |
|
| 451 | - if (!is_string($f) OR !$f) return false; |
|
| 452 | - $r = $f($nom, $serveur, $option!==false); |
|
| 453 | - if ($r===false) spip_sql_erreur($serveur); |
|
| 454 | - return $r; |
|
| 450 | + $f = sql_serveur('selectdb', $serveur, $option==='continue' OR $option===false); |
|
| 451 | + if (!is_string($f) OR !$f) return false; |
|
| 452 | + $r = $f($nom, $serveur, $option!==false); |
|
| 453 | + if ($r===false) spip_sql_erreur($serveur); |
|
| 454 | + return $r; |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | // http://doc.spip.org/@sql_count |
| 458 | 458 | function sql_count($res, $serveur='', $option=true) |
| 459 | 459 | { |
| 460 | - $f = sql_serveur('count', $serveur, $option==='continue' OR $option===false); |
|
| 461 | - if (!is_string($f) OR !$f) return false; |
|
| 462 | - $r = $f($res, $serveur, $option!==false); |
|
| 463 | - if ($r===false) spip_sql_erreur($serveur); |
|
| 464 | - return $r; |
|
| 460 | + $f = sql_serveur('count', $serveur, $option==='continue' OR $option===false); |
|
| 461 | + if (!is_string($f) OR !$f) return false; |
|
| 462 | + $r = $f($res, $serveur, $option!==false); |
|
| 463 | + if ($r===false) spip_sql_erreur($serveur); |
|
| 464 | + return $r; |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | // http://doc.spip.org/@sql_free |
| 468 | 468 | function sql_free($res, $serveur='', $option=true) |
| 469 | 469 | { |
| 470 | - $f = sql_serveur('free', $serveur, $option==='continue' OR $option===false); |
|
| 471 | - if (!is_string($f) OR !$f) return false; |
|
| 472 | - return $f($res); |
|
| 470 | + $f = sql_serveur('free', $serveur, $option==='continue' OR $option===false); |
|
| 471 | + if (!is_string($f) OR !$f) return false; |
|
| 472 | + return $f($res); |
|
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | // Cette fonction ne garantit pas une portabilite totale |
@@ -479,41 +479,41 @@ discard block |
||
| 479 | 479 | // http://doc.spip.org/@sql_insert |
| 480 | 480 | function sql_insert($table, $noms, $valeurs, $desc=array(), $serveur='', $option=true) |
| 481 | 481 | { |
| 482 | - $f = sql_serveur('insert', $serveur, $option==='continue' OR $option===false); |
|
| 483 | - if (!is_string($f) OR !$f) return false; |
|
| 484 | - $r = $f($table, $noms, $valeurs, $desc, $serveur, $option!==false); |
|
| 485 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 486 | - return $r; |
|
| 482 | + $f = sql_serveur('insert', $serveur, $option==='continue' OR $option===false); |
|
| 483 | + if (!is_string($f) OR !$f) return false; |
|
| 484 | + $r = $f($table, $noms, $valeurs, $desc, $serveur, $option!==false); |
|
| 485 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 486 | + return $r; |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | // http://doc.spip.org/@sql_insertq |
| 490 | 490 | function sql_insertq($table, $couples=array(), $desc=array(), $serveur='', $option=true) |
| 491 | 491 | { |
| 492 | - $f = sql_serveur('insertq', $serveur, $option==='continue' OR $option===false); |
|
| 493 | - if (!is_string($f) OR !$f) return false; |
|
| 494 | - $r = $f($table, $couples, $desc, $serveur, $option!==false); |
|
| 495 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 496 | - return $r; |
|
| 492 | + $f = sql_serveur('insertq', $serveur, $option==='continue' OR $option===false); |
|
| 493 | + if (!is_string($f) OR !$f) return false; |
|
| 494 | + $r = $f($table, $couples, $desc, $serveur, $option!==false); |
|
| 495 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 496 | + return $r; |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | // http://doc.spip.org/@sql_insertq_multi |
| 500 | 500 | function sql_insertq_multi($table, $couples=array(), $desc=array(), $serveur='', $option=true) |
| 501 | 501 | { |
| 502 | - $f = sql_serveur('insertq_multi', $serveur, $option==='continue' OR $option===false); |
|
| 503 | - if (!is_string($f) OR !$f) return false; |
|
| 504 | - $r = $f($table, $couples, $desc, $serveur, $option!==false); |
|
| 505 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 506 | - return $r; |
|
| 502 | + $f = sql_serveur('insertq_multi', $serveur, $option==='continue' OR $option===false); |
|
| 503 | + if (!is_string($f) OR !$f) return false; |
|
| 504 | + $r = $f($table, $couples, $desc, $serveur, $option!==false); |
|
| 505 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 506 | + return $r; |
|
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | // http://doc.spip.org/@sql_update |
| 510 | 510 | function sql_update($table, $exp, $where='', $desc=array(), $serveur='', $option=true) |
| 511 | 511 | { |
| 512 | - $f = sql_serveur('update', $serveur, $option==='continue' OR $option===false); |
|
| 513 | - if (!is_string($f) OR !$f) return false; |
|
| 514 | - $r = $f($table, $exp, $where, $desc, $serveur, $option!==false); |
|
| 515 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 516 | - return $r; |
|
| 512 | + $f = sql_serveur('update', $serveur, $option==='continue' OR $option===false); |
|
| 513 | + if (!is_string($f) OR !$f) return false; |
|
| 514 | + $r = $f($table, $exp, $where, $desc, $serveur, $option!==false); |
|
| 515 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 516 | + return $r; |
|
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | // Update est presque toujours appelee sur des constantes ou des dates |
@@ -522,63 +522,63 @@ discard block |
||
| 522 | 522 | // http://doc.spip.org/@sql_updateq |
| 523 | 523 | function sql_updateq($table, $exp, $where='', $desc=array(), $serveur='', $option=true) |
| 524 | 524 | { |
| 525 | - $f = sql_serveur('updateq', $serveur, $option==='continue' OR $option===false); |
|
| 526 | - if (!is_string($f) OR !$f) return false; |
|
| 527 | - $r = $f($table, $exp, $where, $desc, $serveur, $option!==false); |
|
| 528 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 529 | - return $r; |
|
| 525 | + $f = sql_serveur('updateq', $serveur, $option==='continue' OR $option===false); |
|
| 526 | + if (!is_string($f) OR !$f) return false; |
|
| 527 | + $r = $f($table, $exp, $where, $desc, $serveur, $option!==false); |
|
| 528 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 529 | + return $r; |
|
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | // http://doc.spip.org/@sql_delete |
| 533 | 533 | function sql_delete($table, $where='', $serveur='', $option=true) |
| 534 | 534 | { |
| 535 | - $f = sql_serveur('delete', $serveur, $option==='continue' OR $option===false); |
|
| 536 | - if (!is_string($f) OR !$f) return false; |
|
| 537 | - $r = $f($table, $where, $serveur, $option!==false); |
|
| 538 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 539 | - return $r; |
|
| 535 | + $f = sql_serveur('delete', $serveur, $option==='continue' OR $option===false); |
|
| 536 | + if (!is_string($f) OR !$f) return false; |
|
| 537 | + $r = $f($table, $where, $serveur, $option!==false); |
|
| 538 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 539 | + return $r; |
|
| 540 | 540 | } |
| 541 | 541 | |
| 542 | 542 | // http://doc.spip.org/@sql_replace |
| 543 | 543 | function sql_replace($table, $couples, $desc=array(), $serveur='', $option=true) |
| 544 | 544 | { |
| 545 | - $f = sql_serveur('replace', $serveur, $option==='continue' OR $option===false); |
|
| 546 | - if (!is_string($f) OR !$f) return false; |
|
| 547 | - $r = $f($table, $couples, $desc, $serveur, $option!==false); |
|
| 548 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 549 | - return $r; |
|
| 545 | + $f = sql_serveur('replace', $serveur, $option==='continue' OR $option===false); |
|
| 546 | + if (!is_string($f) OR !$f) return false; |
|
| 547 | + $r = $f($table, $couples, $desc, $serveur, $option!==false); |
|
| 548 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 549 | + return $r; |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | |
| 553 | 553 | // http://doc.spip.org/@sql_replace_multi |
| 554 | 554 | function sql_replace_multi($table, $tab_couples, $desc=array(), $serveur='', $option=true) |
| 555 | 555 | { |
| 556 | - $f = sql_serveur('replace_multi', $serveur, $option==='continue' OR $option===false); |
|
| 557 | - if (!is_string($f) OR !$f) return false; |
|
| 558 | - $r = $f($table, $tab_couples, $desc, $serveur, $option!==false); |
|
| 559 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 560 | - return $r; |
|
| 556 | + $f = sql_serveur('replace_multi', $serveur, $option==='continue' OR $option===false); |
|
| 557 | + if (!is_string($f) OR !$f) return false; |
|
| 558 | + $r = $f($table, $tab_couples, $desc, $serveur, $option!==false); |
|
| 559 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 560 | + return $r; |
|
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | // http://doc.spip.org/@sql_drop_table |
| 564 | 564 | function sql_drop_table($table, $exist='', $serveur='', $option=true) |
| 565 | 565 | { |
| 566 | - $f = sql_serveur('drop_table', $serveur, $option==='continue' OR $option===false); |
|
| 567 | - if (!is_string($f) OR !$f) return false; |
|
| 568 | - $r = $f($table, $exist, $serveur, $option!==false); |
|
| 569 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 570 | - return $r; |
|
| 566 | + $f = sql_serveur('drop_table', $serveur, $option==='continue' OR $option===false); |
|
| 567 | + if (!is_string($f) OR !$f) return false; |
|
| 568 | + $r = $f($table, $exist, $serveur, $option!==false); |
|
| 569 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 570 | + return $r; |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | // supprimer une vue sql |
| 574 | 574 | // http://doc.spip.org/@sql_drop_view |
| 575 | 575 | function sql_drop_view($table, $exist='', $serveur='', $option=true) |
| 576 | 576 | { |
| 577 | - $f = sql_serveur('drop_view', $serveur, $option==='continue' OR $option===false); |
|
| 578 | - if (!is_string($f) OR !$f) return false; |
|
| 579 | - $r = $f($table, $exist, $serveur, $option!==false); |
|
| 580 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 581 | - return $r; |
|
| 577 | + $f = sql_serveur('drop_view', $serveur, $option==='continue' OR $option===false); |
|
| 578 | + if (!is_string($f) OR !$f) return false; |
|
| 579 | + $r = $f($table, $exist, $serveur, $option!==false); |
|
| 580 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 581 | + return $r; |
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | /** |
@@ -601,16 +601,16 @@ discard block |
||
| 601 | 601 | **/ |
| 602 | 602 | function sql_showbase($spip=NULL, $serveur='', $option=true) |
| 603 | 603 | { |
| 604 | - $f = sql_serveur('showbase', $serveur, $option==='continue' OR $option===false); |
|
| 605 | - if (!is_string($f) OR !$f) return false; |
|
| 604 | + $f = sql_serveur('showbase', $serveur, $option==='continue' OR $option===false); |
|
| 605 | + if (!is_string($f) OR !$f) return false; |
|
| 606 | 606 | |
| 607 | - // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 608 | - if ($spip == NULL){ |
|
| 609 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 610 | - $spip = $connexion['prefixe'] . '\_%'; |
|
| 611 | - } |
|
| 607 | + // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 608 | + if ($spip == NULL){ |
|
| 609 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 610 | + $spip = $connexion['prefixe'] . '\_%'; |
|
| 611 | + } |
|
| 612 | 612 | |
| 613 | - return $f($spip, $serveur, $option!==false); |
|
| 613 | + return $f($spip, $serveur, $option!==false); |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | /** |
@@ -634,50 +634,50 @@ discard block |
||
| 634 | 634 | **/ |
| 635 | 635 | function sql_alltable($spip=NULL, $serveur='', $option=true) |
| 636 | 636 | { |
| 637 | - $q = sql_showbase($spip, $serveur, $option); |
|
| 638 | - $r = array(); |
|
| 639 | - if ($q) while ($t = sql_fetch($q, $serveur)) { $r[] = array_shift($t);} |
|
| 640 | - return $r; |
|
| 637 | + $q = sql_showbase($spip, $serveur, $option); |
|
| 638 | + $r = array(); |
|
| 639 | + if ($q) while ($t = sql_fetch($q, $serveur)) { $r[] = array_shift($t);} |
|
| 640 | + return $r; |
|
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | // http://doc.spip.org/@sql_showtable |
| 644 | 644 | function sql_showtable($table, $table_spip = false, $serveur='', $option=true) |
| 645 | 645 | { |
| 646 | - $f = sql_serveur('showtable', $serveur, $option==='continue' OR $option===false); |
|
| 647 | - if (!is_string($f) OR !$f) return false; |
|
| 648 | - |
|
| 649 | - // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 650 | - if ($table_spip){ |
|
| 651 | - $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 652 | - $prefixe = $connexion['prefixe']; |
|
| 653 | - $vraie_table = preg_replace('/^spip/', $prefixe, $table); |
|
| 654 | - } else $vraie_table = $table; |
|
| 655 | - |
|
| 656 | - $f = $f($vraie_table, $serveur, $option!==false); |
|
| 657 | - if (!$f) return array(); |
|
| 658 | - if (isset($GLOBALS['tables_principales'][$table]['join'])) |
|
| 659 | - $f['join'] = $GLOBALS['tables_principales'][$table]['join']; |
|
| 660 | - elseif (isset($GLOBALS['tables_auxiliaires'][$table]['join'])) |
|
| 661 | - $f['join'] = $GLOBALS['tables_auxiliaires'][$table]['join']; |
|
| 662 | - return $f; |
|
| 646 | + $f = sql_serveur('showtable', $serveur, $option==='continue' OR $option===false); |
|
| 647 | + if (!is_string($f) OR !$f) return false; |
|
| 648 | + |
|
| 649 | + // la globale n'est remplie qu'apres l'appel de sql_serveur. |
|
| 650 | + if ($table_spip){ |
|
| 651 | + $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 652 | + $prefixe = $connexion['prefixe']; |
|
| 653 | + $vraie_table = preg_replace('/^spip/', $prefixe, $table); |
|
| 654 | + } else $vraie_table = $table; |
|
| 655 | + |
|
| 656 | + $f = $f($vraie_table, $serveur, $option!==false); |
|
| 657 | + if (!$f) return array(); |
|
| 658 | + if (isset($GLOBALS['tables_principales'][$table]['join'])) |
|
| 659 | + $f['join'] = $GLOBALS['tables_principales'][$table]['join']; |
|
| 660 | + elseif (isset($GLOBALS['tables_auxiliaires'][$table]['join'])) |
|
| 661 | + $f['join'] = $GLOBALS['tables_auxiliaires'][$table]['join']; |
|
| 662 | + return $f; |
|
| 663 | 663 | } |
| 664 | 664 | |
| 665 | 665 | // http://doc.spip.org/@sql_create |
| 666 | 666 | function sql_create($nom, $champs, $cles=array(), $autoinc=false, $temporary=false, $serveur='', $option=true) { |
| 667 | - $f = sql_serveur('create', $serveur, $option==='continue' OR $option===false); |
|
| 668 | - if (!is_string($f) OR !$f) return false; |
|
| 669 | - $r = $f($nom, $champs, $cles, $autoinc, $temporary, $serveur, $option!==false); |
|
| 670 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 671 | - return $r; |
|
| 667 | + $f = sql_serveur('create', $serveur, $option==='continue' OR $option===false); |
|
| 668 | + if (!is_string($f) OR !$f) return false; |
|
| 669 | + $r = $f($nom, $champs, $cles, $autoinc, $temporary, $serveur, $option!==false); |
|
| 670 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 671 | + return $r; |
|
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | function sql_create_base($nom, $serveur='', $option=true) |
| 675 | 675 | { |
| 676 | - $f = sql_serveur('create_base', $serveur, $option==='continue' OR $option===false); |
|
| 677 | - if (!is_string($f) OR !$f) return false; |
|
| 678 | - $r = $f($nom, $serveur, $option!==false); |
|
| 679 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 680 | - return $r; |
|
| 676 | + $f = sql_serveur('create_base', $serveur, $option==='continue' OR $option===false); |
|
| 677 | + if (!is_string($f) OR !$f) return false; |
|
| 678 | + $r = $f($nom, $serveur, $option!==false); |
|
| 679 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 680 | + return $r; |
|
| 681 | 681 | } |
| 682 | 682 | |
| 683 | 683 | // Fonction pour creer une vue |
@@ -686,19 +686,19 @@ discard block |
||
| 686 | 686 | // (en mettant $option du sql_select a false pour recuperer la requete) |
| 687 | 687 | // http://doc.spip.org/@sql_create_view |
| 688 | 688 | function sql_create_view($nom, $select_query, $serveur='', $option=true) { |
| 689 | - $f = sql_serveur('create_view', $serveur, $option==='continue' OR $option===false); |
|
| 690 | - if (!is_string($f) OR !$f) return false; |
|
| 691 | - $r = $f($nom, $select_query, $serveur, $option!==false); |
|
| 692 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 693 | - return $r; |
|
| 689 | + $f = sql_serveur('create_view', $serveur, $option==='continue' OR $option===false); |
|
| 690 | + if (!is_string($f) OR !$f) return false; |
|
| 691 | + $r = $f($nom, $select_query, $serveur, $option!==false); |
|
| 692 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 693 | + return $r; |
|
| 694 | 694 | } |
| 695 | 695 | |
| 696 | 696 | // http://doc.spip.org/@sql_multi |
| 697 | 697 | function sql_multi($sel, $lang, $serveur='', $option=true) |
| 698 | 698 | { |
| 699 | - $f = sql_serveur('multi', $serveur, $option==='continue' OR $option===false); |
|
| 700 | - if (!is_string($f) OR !$f) return false; |
|
| 701 | - return $f($sel, $lang); |
|
| 699 | + $f = sql_serveur('multi', $serveur, $option==='continue' OR $option===false); |
|
| 700 | + if (!is_string($f) OR !$f) return false; |
|
| 701 | + return $f($sel, $lang); |
|
| 702 | 702 | } |
| 703 | 703 | |
| 704 | 704 | |
@@ -713,9 +713,9 @@ discard block |
||
| 713 | 713 | * False si le serveur est indisponible |
| 714 | 714 | */ |
| 715 | 715 | function sql_error($serveur='') { |
| 716 | - $f = sql_serveur('error', $serveur, 'continue'); |
|
| 717 | - if (!is_string($f) OR !$f) return false; |
|
| 718 | - return $f('query inconnue', $serveur); |
|
| 716 | + $f = sql_serveur('error', $serveur, 'continue'); |
|
| 717 | + if (!is_string($f) OR !$f) return false; |
|
| 718 | + return $f('query inconnue', $serveur); |
|
| 719 | 719 | } |
| 720 | 720 | |
| 721 | 721 | /** |
@@ -729,36 +729,36 @@ discard block |
||
| 729 | 729 | * False si le serveur est indisponible |
| 730 | 730 | */ |
| 731 | 731 | function sql_errno($serveur='') { |
| 732 | - $f = sql_serveur('errno', $serveur, 'continue'); |
|
| 733 | - if (!is_string($f) OR !$f) return false; |
|
| 734 | - return $f($serveur); |
|
| 732 | + $f = sql_serveur('errno', $serveur, 'continue'); |
|
| 733 | + if (!is_string($f) OR !$f) return false; |
|
| 734 | + return $f($serveur); |
|
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | // http://doc.spip.org/@sql_explain |
| 738 | 738 | function sql_explain($q, $serveur='', $option=true) { |
| 739 | - $f = sql_serveur('explain', $serveur, 'continue'); |
|
| 740 | - if (!is_string($f) OR !$f) return false; |
|
| 741 | - $r = $f($q, $serveur, $option!==false); |
|
| 742 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 743 | - return $r; |
|
| 739 | + $f = sql_serveur('explain', $serveur, 'continue'); |
|
| 740 | + if (!is_string($f) OR !$f) return false; |
|
| 741 | + $r = $f($q, $serveur, $option!==false); |
|
| 742 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 743 | + return $r; |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | // http://doc.spip.org/@sql_optimize |
| 747 | 747 | function sql_optimize($table, $serveur='', $option=true) { |
| 748 | - $f = sql_serveur('optimize', $serveur, $option==='continue' OR $option===false); |
|
| 749 | - if (!is_string($f) OR !$f) return false; |
|
| 750 | - $r = $f($table, $serveur, $option!==false); |
|
| 751 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 752 | - return $r; |
|
| 748 | + $f = sql_serveur('optimize', $serveur, $option==='continue' OR $option===false); |
|
| 749 | + if (!is_string($f) OR !$f) return false; |
|
| 750 | + $r = $f($table, $serveur, $option!==false); |
|
| 751 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 752 | + return $r; |
|
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | // http://doc.spip.org/@sql_repair |
| 756 | 756 | function sql_repair($table, $serveur='', $option=true) { |
| 757 | - $f = sql_serveur('repair', $serveur, $option==='continue' OR $option===false); |
|
| 758 | - if (!is_string($f) OR !$f) return false; |
|
| 759 | - $r = $f($table, $serveur, $option!==false); |
|
| 760 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 761 | - return $r; |
|
| 757 | + $f = sql_serveur('repair', $serveur, $option==='continue' OR $option===false); |
|
| 758 | + if (!is_string($f) OR !$f) return false; |
|
| 759 | + $r = $f($table, $serveur, $option!==false); |
|
| 760 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 761 | + return $r; |
|
| 762 | 762 | } |
| 763 | 763 | |
| 764 | 764 | // Fonction la plus generale ... et la moins portable |
@@ -766,11 +766,11 @@ discard block |
||
| 766 | 766 | |
| 767 | 767 | // http://doc.spip.org/@sql_query |
| 768 | 768 | function sql_query($ins, $serveur='', $option=true) { |
| 769 | - $f = sql_serveur('query', $serveur, $option==='continue' OR $option===false); |
|
| 770 | - if (!is_string($f) OR !$f) return false; |
|
| 771 | - $r = $f($ins, $serveur, $option!==false); |
|
| 772 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 773 | - return $r; |
|
| 769 | + $f = sql_serveur('query', $serveur, $option==='continue' OR $option===false); |
|
| 770 | + if (!is_string($f) OR !$f) return false; |
|
| 771 | + $r = $f($ins, $serveur, $option!==false); |
|
| 772 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 773 | + return $r; |
|
| 774 | 774 | } |
| 775 | 775 | |
| 776 | 776 | /** |
@@ -819,14 +819,14 @@ discard block |
||
| 819 | 819 | * |
| 820 | 820 | **/ |
| 821 | 821 | function sql_fetsel($select = array(), $from = array(), $where = array(), |
| 822 | - $groupby = array(), $orderby = array(), $limit = '', |
|
| 823 | - $having = array(), $serveur='', $option=true) { |
|
| 824 | - $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 825 | - if ($option===false) return $q; |
|
| 826 | - if (!$q) return array(); |
|
| 827 | - $r = sql_fetch($q, $serveur, $option); |
|
| 828 | - sql_free($q, $serveur, $option); |
|
| 829 | - return $r; |
|
| 822 | + $groupby = array(), $orderby = array(), $limit = '', |
|
| 823 | + $having = array(), $serveur='', $option=true) { |
|
| 824 | + $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 825 | + if ($option===false) return $q; |
|
| 826 | + if (!$q) return array(); |
|
| 827 | + $r = sql_fetch($q, $serveur, $option); |
|
| 828 | + sql_free($q, $serveur, $option); |
|
| 829 | + return $r; |
|
| 830 | 830 | } |
| 831 | 831 | |
| 832 | 832 | |
@@ -883,11 +883,11 @@ discard block |
||
| 883 | 883 | * |
| 884 | 884 | **/ |
| 885 | 885 | function sql_allfetsel($select = array(), $from = array(), $where = array(), |
| 886 | - $groupby = array(), $orderby = array(), $limit = '', |
|
| 887 | - $having = array(), $serveur='', $option=true) { |
|
| 888 | - $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 889 | - if ($option===false) return $q; |
|
| 890 | - return sql_fetch_all($q, $serveur, $option); |
|
| 886 | + $groupby = array(), $orderby = array(), $limit = '', |
|
| 887 | + $having = array(), $serveur='', $option=true) { |
|
| 888 | + $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 889 | + if ($option===false) return $q; |
|
| 890 | + return sql_fetch_all($q, $serveur, $option); |
|
| 891 | 891 | } |
| 892 | 892 | |
| 893 | 893 | |
@@ -932,14 +932,14 @@ discard block |
||
| 932 | 932 | * |
| 933 | 933 | **/ |
| 934 | 934 | function sql_getfetsel($select, $from = array(), $where = array(), $groupby = array(), |
| 935 | - $orderby = array(), $limit = '', $having = array(), $serveur='', $option=true) { |
|
| 936 | - if (preg_match('/\s+as\s+(\w+)$/i', $select, $c)) $id = $c[1]; |
|
| 937 | - elseif (!preg_match('/\W/', $select)) $id = $select; |
|
| 938 | - else {$id = 'n'; $select .= ' AS n';} |
|
| 939 | - $r = sql_fetsel($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 940 | - if ($option===false) return $r; |
|
| 941 | - if (!$r) return NULL; |
|
| 942 | - return $r[$id]; |
|
| 935 | + $orderby = array(), $limit = '', $having = array(), $serveur='', $option=true) { |
|
| 936 | + if (preg_match('/\s+as\s+(\w+)$/i', $select, $c)) $id = $c[1]; |
|
| 937 | + elseif (!preg_match('/\W/', $select)) $id = $select; |
|
| 938 | + else {$id = 'n'; $select .= ' AS n';} |
|
| 939 | + $r = sql_fetsel($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 940 | + if ($option===false) return $r; |
|
| 941 | + if (!$r) return NULL; |
|
| 942 | + return $r[$id]; |
|
| 943 | 943 | } |
| 944 | 944 | |
| 945 | 945 | /** |
@@ -957,8 +957,8 @@ discard block |
||
| 957 | 957 | * Numero de version du serveur SQL |
| 958 | 958 | **/ |
| 959 | 959 | function sql_version($serveur='', $option=true) { |
| 960 | - $row = sql_fetsel("version() AS n", '','','','','','',$serveur); |
|
| 961 | - return ($row['n']); |
|
| 960 | + $row = sql_fetsel("version() AS n", '','','','','','',$serveur); |
|
| 961 | + return ($row['n']); |
|
| 962 | 962 | } |
| 963 | 963 | |
| 964 | 964 | /** |
@@ -994,11 +994,11 @@ discard block |
||
| 994 | 994 | * Le serveur SQL prefere t'il des transactions pour les insertions multiples ? |
| 995 | 995 | **/ |
| 996 | 996 | function sql_preferer_transaction($serveur='', $option=true) { |
| 997 | - $f = sql_serveur('preferer_transaction', $serveur, 'continue'); |
|
| 998 | - if (!is_string($f) OR !$f) return false; |
|
| 999 | - $r = $f($serveur, $option!==false); |
|
| 1000 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 1001 | - return $r; |
|
| 997 | + $f = sql_serveur('preferer_transaction', $serveur, 'continue'); |
|
| 998 | + if (!is_string($f) OR !$f) return false; |
|
| 999 | + $r = $f($serveur, $option!==false); |
|
| 1000 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 1001 | + return $r; |
|
| 1002 | 1002 | }; |
| 1003 | 1003 | |
| 1004 | 1004 | /** |
@@ -1020,11 +1020,11 @@ discard block |
||
| 1020 | 1020 | * false en cas d'erreur |
| 1021 | 1021 | **/ |
| 1022 | 1022 | function sql_demarrer_transaction($serveur='', $option=true) { |
| 1023 | - $f = sql_serveur('demarrer_transaction', $serveur, 'continue'); |
|
| 1024 | - if (!is_string($f) OR !$f) return false; |
|
| 1025 | - $r = $f($serveur, $option!==false); |
|
| 1026 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 1027 | - return $r; |
|
| 1023 | + $f = sql_serveur('demarrer_transaction', $serveur, 'continue'); |
|
| 1024 | + if (!is_string($f) OR !$f) return false; |
|
| 1025 | + $r = $f($serveur, $option!==false); |
|
| 1026 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 1027 | + return $r; |
|
| 1028 | 1028 | }; |
| 1029 | 1029 | |
| 1030 | 1030 | /** |
@@ -1046,11 +1046,11 @@ discard block |
||
| 1046 | 1046 | * false en cas d'erreur |
| 1047 | 1047 | **/ |
| 1048 | 1048 | function sql_terminer_transaction($serveur='', $option=true) { |
| 1049 | - $f = sql_serveur('terminer_transaction', $serveur, 'continue'); |
|
| 1050 | - if (!is_string($f) OR !$f) return false; |
|
| 1051 | - $r = $f($serveur, $option!==false); |
|
| 1052 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 1053 | - return $r; |
|
| 1049 | + $f = sql_serveur('terminer_transaction', $serveur, 'continue'); |
|
| 1050 | + if (!is_string($f) OR !$f) return false; |
|
| 1051 | + $r = $f($serveur, $option!==false); |
|
| 1052 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 1053 | + return $r; |
|
| 1054 | 1054 | }; |
| 1055 | 1055 | |
| 1056 | 1056 | |
@@ -1075,9 +1075,9 @@ discard block |
||
| 1075 | 1075 | **/ |
| 1076 | 1076 | function sql_hex($val, $serveur='', $option=true) |
| 1077 | 1077 | { |
| 1078 | - $f = sql_serveur('hex', $serveur, $option==='continue' OR $option===false); |
|
| 1079 | - if (!is_string($f) OR !$f) return false; |
|
| 1080 | - return $f($val); |
|
| 1078 | + $f = sql_serveur('hex', $serveur, $option==='continue' OR $option===false); |
|
| 1079 | + if (!is_string($f) OR !$f) return false; |
|
| 1080 | + return $f($val); |
|
| 1081 | 1081 | } |
| 1082 | 1082 | |
| 1083 | 1083 | /** |
@@ -1102,16 +1102,16 @@ discard block |
||
| 1102 | 1102 | **/ |
| 1103 | 1103 | function sql_quote($val, $serveur='', $type='') |
| 1104 | 1104 | { |
| 1105 | - $f = sql_serveur('quote', $serveur, true); |
|
| 1106 | - if (!is_string($f) OR !$f) $f = '_q'; |
|
| 1107 | - return $f($val, $type); |
|
| 1105 | + $f = sql_serveur('quote', $serveur, true); |
|
| 1106 | + if (!is_string($f) OR !$f) $f = '_q'; |
|
| 1107 | + return $f($val, $type); |
|
| 1108 | 1108 | } |
| 1109 | 1109 | |
| 1110 | 1110 | function sql_date_proche($champ, $interval, $unite, $serveur='', $option=true) |
| 1111 | 1111 | { |
| 1112 | - $f = sql_serveur('date_proche', $serveur, true); |
|
| 1113 | - if (!is_string($f) OR !$f) return false; |
|
| 1114 | - return $f($champ, $interval, $unite); |
|
| 1112 | + $f = sql_serveur('date_proche', $serveur, true); |
|
| 1113 | + if (!is_string($f) OR !$f) return false; |
|
| 1114 | + return $f($champ, $interval, $unite); |
|
| 1115 | 1115 | } |
| 1116 | 1116 | |
| 1117 | 1117 | /** |
@@ -1143,16 +1143,16 @@ discard block |
||
| 1143 | 1143 | * Expression de requête SQL |
| 1144 | 1144 | **/ |
| 1145 | 1145 | function sql_in($val, $valeurs, $not='', $serveur='', $option=true) { |
| 1146 | - if (is_array($valeurs)) { |
|
| 1147 | - $f = sql_serveur('quote', $serveur, true); |
|
| 1148 | - if (!is_string($f) OR !$f) return false; |
|
| 1149 | - $valeurs = join(',', array_map($f, array_unique($valeurs))); |
|
| 1150 | - } elseif (isset($valeurs[0]) AND $valeurs[0]===',') $valeurs = substr($valeurs,1); |
|
| 1151 | - if (!strlen(trim($valeurs))) return ($not ? "0=0" : '0=1'); |
|
| 1152 | - |
|
| 1153 | - $f = sql_serveur('in', $serveur, $option==='continue' OR $option===false); |
|
| 1154 | - if (!is_string($f) OR !$f) return false; |
|
| 1155 | - return $f($val, $valeurs, $not, $serveur, $option!==false); |
|
| 1146 | + if (is_array($valeurs)) { |
|
| 1147 | + $f = sql_serveur('quote', $serveur, true); |
|
| 1148 | + if (!is_string($f) OR !$f) return false; |
|
| 1149 | + $valeurs = join(',', array_map($f, array_unique($valeurs))); |
|
| 1150 | + } elseif (isset($valeurs[0]) AND $valeurs[0]===',') $valeurs = substr($valeurs,1); |
|
| 1151 | + if (!strlen(trim($valeurs))) return ($not ? "0=0" : '0=1'); |
|
| 1152 | + |
|
| 1153 | + $f = sql_serveur('in', $serveur, $option==='continue' OR $option===false); |
|
| 1154 | + if (!is_string($f) OR !$f) return false; |
|
| 1155 | + return $f($val, $valeurs, $not, $serveur, $option!==false); |
|
| 1156 | 1156 | } |
| 1157 | 1157 | |
| 1158 | 1158 | // Penser a dire dans la description du serveur |
@@ -1160,13 +1160,13 @@ discard block |
||
| 1160 | 1160 | |
| 1161 | 1161 | // http://doc.spip.org/@sql_in_select |
| 1162 | 1162 | function sql_in_select($in, $select, $from = array(), $where = array(), |
| 1163 | - $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur='') |
|
| 1163 | + $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur='') |
|
| 1164 | 1164 | { |
| 1165 | - $liste = array(); |
|
| 1166 | - $res = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur); |
|
| 1167 | - while ($r = sql_fetch($res)) {$liste[] = array_shift($r);} |
|
| 1168 | - sql_free($res); |
|
| 1169 | - return sql_in($in, $liste); |
|
| 1165 | + $liste = array(); |
|
| 1166 | + $res = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur); |
|
| 1167 | + while ($r = sql_fetch($res)) {$liste[] = array_shift($r);} |
|
| 1168 | + sql_free($res); |
|
| 1169 | + return sql_in($in, $liste); |
|
| 1170 | 1170 | } |
| 1171 | 1171 | |
| 1172 | 1172 | /** |
@@ -1197,32 +1197,32 @@ discard block |
||
| 1197 | 1197 | * Position apres le saut. |
| 1198 | 1198 | */ |
| 1199 | 1199 | function sql_skip($res, $pos, $saut, $count, $serveur='', $option=true){ |
| 1200 | - // pas de saut en arriere qu'on ne sait pas faire sans sql_seek |
|
| 1201 | - if (($saut=intval($saut))<=0) return $pos; |
|
| 1202 | - |
|
| 1203 | - $seek = $pos + $saut; |
|
| 1204 | - // si le saut fait depasser le maxi, on libere la resource |
|
| 1205 | - // et on sort |
|
| 1206 | - if ($seek>=$count) {sql_free($res, $serveur, $option); return $count;} |
|
| 1207 | - |
|
| 1208 | - if (sql_seek($res, $seek)) |
|
| 1209 | - $pos = $seek; |
|
| 1210 | - else |
|
| 1211 | - while ($pos<$seek AND sql_fetch($res, $serveur, $option)) |
|
| 1212 | - $pos++; |
|
| 1213 | - return $pos; |
|
| 1200 | + // pas de saut en arriere qu'on ne sait pas faire sans sql_seek |
|
| 1201 | + if (($saut=intval($saut))<=0) return $pos; |
|
| 1202 | + |
|
| 1203 | + $seek = $pos + $saut; |
|
| 1204 | + // si le saut fait depasser le maxi, on libere la resource |
|
| 1205 | + // et on sort |
|
| 1206 | + if ($seek>=$count) {sql_free($res, $serveur, $option); return $count;} |
|
| 1207 | + |
|
| 1208 | + if (sql_seek($res, $seek)) |
|
| 1209 | + $pos = $seek; |
|
| 1210 | + else |
|
| 1211 | + while ($pos<$seek AND sql_fetch($res, $serveur, $option)) |
|
| 1212 | + $pos++; |
|
| 1213 | + return $pos; |
|
| 1214 | 1214 | } |
| 1215 | 1215 | |
| 1216 | 1216 | // http://doc.spip.org/@sql_test_int |
| 1217 | 1217 | function sql_test_int($type, $serveur='', $option=true) |
| 1218 | 1218 | { |
| 1219 | - return preg_match('/^(TINYINT|SMALLINT|MEDIUMINT|INT|INTEGER|BIGINT)/i',trim($type)); |
|
| 1219 | + return preg_match('/^(TINYINT|SMALLINT|MEDIUMINT|INT|INTEGER|BIGINT)/i',trim($type)); |
|
| 1220 | 1220 | } |
| 1221 | 1221 | |
| 1222 | 1222 | // http://doc.spip.org/@sql_test_date |
| 1223 | 1223 | function sql_test_date($type, $serveur='', $option=true) |
| 1224 | 1224 | { |
| 1225 | - return preg_match('/^(DATE|DATETIME|TIMESTAMP|TIME)/i',trim($type)); |
|
| 1225 | + return preg_match('/^(DATE|DATETIME|TIMESTAMP|TIME)/i',trim($type)); |
|
| 1226 | 1226 | } |
| 1227 | 1227 | |
| 1228 | 1228 | /** |
@@ -1245,15 +1245,15 @@ discard block |
||
| 1245 | 1245 | * La date formatee |
| 1246 | 1246 | */ |
| 1247 | 1247 | function sql_format_date($annee=0, $mois=0, $jour=0, $h=0, $m=0, $s=0, $serveur=''){ |
| 1248 | - $annee = sprintf("%04s",$annee); |
|
| 1249 | - $mois = sprintf("%02s",$mois); |
|
| 1248 | + $annee = sprintf("%04s",$annee); |
|
| 1249 | + $mois = sprintf("%02s",$mois); |
|
| 1250 | 1250 | |
| 1251 | - if ($annee == "0000") $mois = 0; |
|
| 1252 | - if ($mois == "00") $jour = 0; |
|
| 1251 | + if ($annee == "0000") $mois = 0; |
|
| 1252 | + if ($mois == "00") $jour = 0; |
|
| 1253 | 1253 | |
| 1254 | - return sprintf("%04u",$annee) . '-' . sprintf("%02u",$mois) . '-' |
|
| 1255 | - . sprintf("%02u",$jour) . ' ' . sprintf("%02u",$h) . ':' |
|
| 1256 | - . sprintf("%02u",$m) . ':' . sprintf("%02u",$s); |
|
| 1254 | + return sprintf("%04u",$annee) . '-' . sprintf("%02u",$mois) . '-' |
|
| 1255 | + . sprintf("%02u",$jour) . ' ' . sprintf("%02u",$h) . ':' |
|
| 1256 | + . sprintf("%02u",$m) . ':' . sprintf("%02u",$s); |
|
| 1257 | 1257 | } |
| 1258 | 1258 | |
| 1259 | 1259 | |
@@ -1277,28 +1277,28 @@ discard block |
||
| 1277 | 1277 | **/ |
| 1278 | 1278 | function description_table($nom, $serveur=''){ |
| 1279 | 1279 | |
| 1280 | - global $tables_principales, $tables_auxiliaires; |
|
| 1281 | - static $trouver_table; |
|
| 1280 | + global $tables_principales, $tables_auxiliaires; |
|
| 1281 | + static $trouver_table; |
|
| 1282 | 1282 | |
| 1283 | - /* toujours utiliser trouver_table |
|
| 1283 | + /* toujours utiliser trouver_table |
|
| 1284 | 1284 | qui renverra la description theorique |
| 1285 | 1285 | car sinon on va se comporter differement selon que la table est declaree |
| 1286 | 1286 | ou non |
| 1287 | 1287 | */ |
| 1288 | - if (!$trouver_table) $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1289 | - if ($desc = $trouver_table($nom, $serveur)) |
|
| 1290 | - return $desc; |
|
| 1288 | + if (!$trouver_table) $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1289 | + if ($desc = $trouver_table($nom, $serveur)) |
|
| 1290 | + return $desc; |
|
| 1291 | 1291 | |
| 1292 | - // sauf a l'installation : |
|
| 1293 | - include_spip('base/serial'); |
|
| 1294 | - if (isset($tables_principales[$nom])) |
|
| 1295 | - return $tables_principales[$nom]; |
|
| 1292 | + // sauf a l'installation : |
|
| 1293 | + include_spip('base/serial'); |
|
| 1294 | + if (isset($tables_principales[$nom])) |
|
| 1295 | + return $tables_principales[$nom]; |
|
| 1296 | 1296 | |
| 1297 | - include_spip('base/auxiliaires'); |
|
| 1298 | - if (isset($tables_auxiliaires[$nom])) |
|
| 1299 | - return $tables_auxiliaires[$nom]; |
|
| 1297 | + include_spip('base/auxiliaires'); |
|
| 1298 | + if (isset($tables_auxiliaires[$nom])) |
|
| 1299 | + return $tables_auxiliaires[$nom]; |
|
| 1300 | 1300 | |
| 1301 | - return false; |
|
| 1301 | + return false; |
|
| 1302 | 1302 | } |
| 1303 | 1303 | |
| 1304 | 1304 | |
@@ -52,9 +52,9 @@ discard block |
||
| 52 | 52 | * Si l'instruction demandee n'existe pas, retourne la liste de toutes les instructions du serveur SQL avec $continue a true. |
| 53 | 53 | * |
| 54 | 54 | **/ |
| 55 | -function sql_serveur($ins_sql='', $serveur='', $continue=false) { |
|
| 55 | +function sql_serveur($ins_sql = '', $serveur = '', $continue = false) { |
|
| 56 | 56 | static $sql_serveur = array(); |
| 57 | - if (!isset($sql_serveur[$serveur][$ins_sql])){ |
|
| 57 | + if (!isset($sql_serveur[$serveur][$ins_sql])) { |
|
| 58 | 58 | $f = spip_connect_sql(sql_ABSTRACT_VERSION, $ins_sql, $serveur, $continue); |
| 59 | 59 | if (!is_string($f) OR !$f) return $f; |
| 60 | 60 | $sql_serveur[$serveur][$ins_sql] = $f; |
@@ -80,16 +80,16 @@ discard block |
||
| 80 | 80 | * @return string|bool |
| 81 | 81 | * Retourne le nom du charset si effectivement trouve, sinon false. |
| 82 | 82 | **/ |
| 83 | -function sql_get_charset($charset, $serveur='', $option=true){ |
|
| 83 | +function sql_get_charset($charset, $serveur = '', $option = true) { |
|
| 84 | 84 | // le nom http du charset differe parfois du nom SQL utf-8 ==> utf8 etc. |
| 85 | - $desc = sql_serveur('', $serveur, true,true); |
|
| 85 | + $desc = sql_serveur('', $serveur, true, true); |
|
| 86 | 86 | $desc = $desc[sql_ABSTRACT_VERSION]; |
| 87 | 87 | $c = $desc['charsets'][$charset]; |
| 88 | 88 | if ($c) { |
| 89 | - if (function_exists($f=@$desc['get_charset'])) |
|
| 90 | - if ($f($c, $serveur, $option!==false)) return $c; |
|
| 89 | + if (function_exists($f = @$desc['get_charset'])) |
|
| 90 | + if ($f($c, $serveur, $option !== false)) return $c; |
|
| 91 | 91 | } |
| 92 | - spip_log( "SPIP ne connait pas les Charsets disponibles sur le serveur $serveur. Le serveur choisira seul.", _LOG_AVERTISSEMENT); |
|
| 92 | + spip_log("SPIP ne connait pas les Charsets disponibles sur le serveur $serveur. Le serveur choisira seul.", _LOG_AVERTISSEMENT); |
|
| 93 | 93 | return false; |
| 94 | 94 | } |
| 95 | 95 | |
@@ -115,10 +115,10 @@ discard block |
||
| 115 | 115 | * @return bool |
| 116 | 116 | * Retourne true si elle reussie. |
| 117 | 117 | **/ |
| 118 | -function sql_set_charset($charset,$serveur='', $option=true){ |
|
| 119 | - $f = sql_serveur('set_charset', $serveur, $option==='continue' OR $option===false); |
|
| 118 | +function sql_set_charset($charset, $serveur = '', $option = true) { |
|
| 119 | + $f = sql_serveur('set_charset', $serveur, $option === 'continue' OR $option === false); |
|
| 120 | 120 | if (!is_string($f) OR !$f) return false; |
| 121 | - return $f($charset, $serveur, $option!==false); |
|
| 121 | + return $f($charset, $serveur, $option !== false); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | |
@@ -167,10 +167,10 @@ discard block |
||
| 167 | 167 | * afin de disposer du texte brut. |
| 168 | 168 | * |
| 169 | 169 | **/ |
| 170 | -function sql_select ($select = array(), $from = array(), $where = array(), |
|
| 170 | +function sql_select($select = array(), $from = array(), $where = array(), |
|
| 171 | 171 | $groupby = array(), $orderby = array(), $limit = '', $having = array(), |
| 172 | - $serveur='', $option=true) { |
|
| 173 | - $f = sql_serveur('select', $serveur, $option==='continue' OR $option===false); |
|
| 172 | + $serveur = '', $option = true) { |
|
| 173 | + $f = sql_serveur('select', $serveur, $option === 'continue' OR $option === false); |
|
| 174 | 174 | if (!is_string($f) OR !$f) return false; |
| 175 | 175 | |
| 176 | 176 | $debug = (defined('_VAR_MODE') AND _VAR_MODE == 'debug'); |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | // le debug, c'est pour ce qui a ete produit par le compilateur |
| 183 | 183 | if (isset($GLOBALS['debug']['aucasou'])) { |
| 184 | 184 | list($table, $id,) = $GLOBALS['debug']['aucasou']; |
| 185 | - $nom = $GLOBALS['debug_objets']['courant'] . $id; |
|
| 185 | + $nom = $GLOBALS['debug_objets']['courant'].$id; |
|
| 186 | 186 | $GLOBALS['debug_objets']['requete'][$nom] = $query; |
| 187 | 187 | } |
| 188 | 188 | $res = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, true); |
@@ -232,8 +232,8 @@ discard block |
||
| 232 | 232 | **/ |
| 233 | 233 | function sql_get_select($select = array(), $from = array(), $where = array(), |
| 234 | 234 | $groupby = array(), $orderby = array(), $limit = '', $having = array(), |
| 235 | - $serveur='') { |
|
| 236 | - return sql_select ($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 235 | + $serveur = '') { |
|
| 236 | + return sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | |
@@ -268,11 +268,11 @@ discard block |
||
| 268 | 268 | **/ |
| 269 | 269 | function sql_countsel($from = array(), $where = array(), |
| 270 | 270 | $groupby = array(), $having = array(), |
| 271 | - $serveur='', $option=true) { |
|
| 272 | - $f = sql_serveur('countsel', $serveur, $option==='continue' OR $option===false); |
|
| 271 | + $serveur = '', $option = true) { |
|
| 272 | + $f = sql_serveur('countsel', $serveur, $option === 'continue' OR $option === false); |
|
| 273 | 273 | if (!is_string($f) OR !$f) return false; |
| 274 | - $r = $f($from, $where, $groupby, $having, $serveur, $option!==false); |
|
| 275 | - if ($r===false) spip_sql_erreur($serveur); |
|
| 274 | + $r = $f($from, $where, $groupby, $having, $serveur, $option !== false); |
|
| 275 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 276 | 276 | return $r; |
| 277 | 277 | } |
| 278 | 278 | |
@@ -299,11 +299,11 @@ discard block |
||
| 299 | 299 | * - false en cas de serveur indiponible ou d'erreur |
| 300 | 300 | * Ce retour n'est pas pertinent pour savoir si l'operation est correctement realisee. |
| 301 | 301 | **/ |
| 302 | -function sql_alter($q, $serveur='', $option=true) { |
|
| 303 | - $f = sql_serveur('alter', $serveur, $option==='continue' OR $option===false); |
|
| 302 | +function sql_alter($q, $serveur = '', $option = true) { |
|
| 303 | + $f = sql_serveur('alter', $serveur, $option === 'continue' OR $option === false); |
|
| 304 | 304 | if (!is_string($f) OR !$f) return false; |
| 305 | - $r = $f($q, $serveur, $option!==false); |
|
| 306 | - if ($r===false) spip_sql_erreur($serveur); |
|
| 305 | + $r = $f($q, $serveur, $option !== false); |
|
| 306 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 307 | 307 | return $r; |
| 308 | 308 | } |
| 309 | 309 | |
@@ -326,10 +326,10 @@ discard block |
||
| 326 | 326 | * Tableau de cles (colonnes SQL ou alias) / valeurs (valeurs dans la colonne de la table ou calculee) |
| 327 | 327 | * presentant une ligne de resultat d'une selection |
| 328 | 328 | */ |
| 329 | -function sql_fetch($res, $serveur='', $option=true) { |
|
| 330 | - $f = sql_serveur('fetch', $serveur, $option==='continue' OR $option===false); |
|
| 329 | +function sql_fetch($res, $serveur = '', $option = true) { |
|
| 330 | + $f = sql_serveur('fetch', $serveur, $option === 'continue' OR $option === false); |
|
| 331 | 331 | if (!is_string($f) OR !$f) return false; |
| 332 | - return $f($res, NULL, $serveur, $option!==false); |
|
| 332 | + return $f($res, NULL, $serveur, $option !== false); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | |
@@ -355,12 +355,12 @@ discard block |
||
| 355 | 355 | * de cles (colonnes SQL ou alias) / valeurs (valeurs dans la colonne de la table ou calculee) |
| 356 | 356 | * presentant une ligne de resultat d'une selection |
| 357 | 357 | */ |
| 358 | -function sql_fetch_all($res, $serveur='', $option=true){ |
|
| 358 | +function sql_fetch_all($res, $serveur = '', $option = true) { |
|
| 359 | 359 | $rows = array(); |
| 360 | 360 | if (!$res) return $rows; |
| 361 | - $f = sql_serveur('fetch', $serveur, $option==='continue' OR $option===false); |
|
| 361 | + $f = sql_serveur('fetch', $serveur, $option === 'continue' OR $option === false); |
|
| 362 | 362 | if (!is_string($f) OR !$f) return array(); |
| 363 | - while ($r = $f($res, NULL, $serveur, $option!==false)) |
|
| 363 | + while ($r = $f($res, NULL, $serveur, $option !== false)) |
|
| 364 | 364 | $rows[] = $r; |
| 365 | 365 | sql_free($res, $serveur); |
| 366 | 366 | return $rows; |
@@ -390,11 +390,11 @@ discard block |
||
| 390 | 390 | * @return bool |
| 391 | 391 | * Operation effectuee (true), sinon false. |
| 392 | 392 | **/ |
| 393 | -function sql_seek($res, $row_number, $serveur='', $option=true) { |
|
| 394 | - $f = sql_serveur('seek', $serveur, $option==='continue' OR $option===false); |
|
| 393 | +function sql_seek($res, $row_number, $serveur = '', $option = true) { |
|
| 394 | + $f = sql_serveur('seek', $serveur, $option === 'continue' OR $option === false); |
|
| 395 | 395 | if (!is_string($f) OR !$f) return false; |
| 396 | - $r = $f($res, $row_number, $serveur, $option!==false); |
|
| 397 | - if ($r===false) spip_sql_erreur($serveur); |
|
| 396 | + $r = $f($res, $row_number, $serveur, $option !== false); |
|
| 397 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 398 | 398 | return $r; |
| 399 | 399 | } |
| 400 | 400 | |
@@ -419,11 +419,11 @@ discard block |
||
| 419 | 419 | * Tableau contenant chaque nom de base de donnees. |
| 420 | 420 | * False en cas d'erreur. |
| 421 | 421 | **/ |
| 422 | -function sql_listdbs($serveur='', $option=true) { |
|
| 423 | - $f = sql_serveur('listdbs', $serveur, $option==='continue' OR $option===false); |
|
| 422 | +function sql_listdbs($serveur = '', $option = true) { |
|
| 423 | + $f = sql_serveur('listdbs', $serveur, $option === 'continue' OR $option === false); |
|
| 424 | 424 | if (!is_string($f) OR !$f) return false; |
| 425 | 425 | $r = $f($serveur); |
| 426 | - if ($r===false) spip_sql_erreur($serveur); |
|
| 426 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 427 | 427 | return $r; |
| 428 | 428 | } |
| 429 | 429 | |
@@ -445,29 +445,29 @@ discard block |
||
| 445 | 445 | * True ou nom de la base en cas de success. |
| 446 | 446 | * False en cas d'erreur. |
| 447 | 447 | **/ |
| 448 | -function sql_selectdb($nom, $serveur='', $option=true) |
|
| 448 | +function sql_selectdb($nom, $serveur = '', $option = true) |
|
| 449 | 449 | { |
| 450 | - $f = sql_serveur('selectdb', $serveur, $option==='continue' OR $option===false); |
|
| 450 | + $f = sql_serveur('selectdb', $serveur, $option === 'continue' OR $option === false); |
|
| 451 | 451 | if (!is_string($f) OR !$f) return false; |
| 452 | - $r = $f($nom, $serveur, $option!==false); |
|
| 453 | - if ($r===false) spip_sql_erreur($serveur); |
|
| 452 | + $r = $f($nom, $serveur, $option !== false); |
|
| 453 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 454 | 454 | return $r; |
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | // http://doc.spip.org/@sql_count |
| 458 | -function sql_count($res, $serveur='', $option=true) |
|
| 458 | +function sql_count($res, $serveur = '', $option = true) |
|
| 459 | 459 | { |
| 460 | - $f = sql_serveur('count', $serveur, $option==='continue' OR $option===false); |
|
| 460 | + $f = sql_serveur('count', $serveur, $option === 'continue' OR $option === false); |
|
| 461 | 461 | if (!is_string($f) OR !$f) return false; |
| 462 | - $r = $f($res, $serveur, $option!==false); |
|
| 463 | - if ($r===false) spip_sql_erreur($serveur); |
|
| 462 | + $r = $f($res, $serveur, $option !== false); |
|
| 463 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 464 | 464 | return $r; |
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | // http://doc.spip.org/@sql_free |
| 468 | -function sql_free($res, $serveur='', $option=true) |
|
| 468 | +function sql_free($res, $serveur = '', $option = true) |
|
| 469 | 469 | { |
| 470 | - $f = sql_serveur('free', $serveur, $option==='continue' OR $option===false); |
|
| 470 | + $f = sql_serveur('free', $serveur, $option === 'continue' OR $option === false); |
|
| 471 | 471 | if (!is_string($f) OR !$f) return false; |
| 472 | 472 | return $f($res); |
| 473 | 473 | } |
@@ -477,41 +477,41 @@ discard block |
||
| 477 | 477 | // Elle est fournie pour permettre l'actualisation de vieux codes |
| 478 | 478 | // par un Sed brutal qui peut donner des resultats provisoirement acceptables |
| 479 | 479 | // http://doc.spip.org/@sql_insert |
| 480 | -function sql_insert($table, $noms, $valeurs, $desc=array(), $serveur='', $option=true) |
|
| 480 | +function sql_insert($table, $noms, $valeurs, $desc = array(), $serveur = '', $option = true) |
|
| 481 | 481 | { |
| 482 | - $f = sql_serveur('insert', $serveur, $option==='continue' OR $option===false); |
|
| 482 | + $f = sql_serveur('insert', $serveur, $option === 'continue' OR $option === false); |
|
| 483 | 483 | if (!is_string($f) OR !$f) return false; |
| 484 | - $r = $f($table, $noms, $valeurs, $desc, $serveur, $option!==false); |
|
| 484 | + $r = $f($table, $noms, $valeurs, $desc, $serveur, $option !== false); |
|
| 485 | 485 | if ($r === false) spip_sql_erreur($serveur); |
| 486 | 486 | return $r; |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | // http://doc.spip.org/@sql_insertq |
| 490 | -function sql_insertq($table, $couples=array(), $desc=array(), $serveur='', $option=true) |
|
| 490 | +function sql_insertq($table, $couples = array(), $desc = array(), $serveur = '', $option = true) |
|
| 491 | 491 | { |
| 492 | - $f = sql_serveur('insertq', $serveur, $option==='continue' OR $option===false); |
|
| 492 | + $f = sql_serveur('insertq', $serveur, $option === 'continue' OR $option === false); |
|
| 493 | 493 | if (!is_string($f) OR !$f) return false; |
| 494 | - $r = $f($table, $couples, $desc, $serveur, $option!==false); |
|
| 494 | + $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 495 | 495 | if ($r === false) spip_sql_erreur($serveur); |
| 496 | 496 | return $r; |
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | // http://doc.spip.org/@sql_insertq_multi |
| 500 | -function sql_insertq_multi($table, $couples=array(), $desc=array(), $serveur='', $option=true) |
|
| 500 | +function sql_insertq_multi($table, $couples = array(), $desc = array(), $serveur = '', $option = true) |
|
| 501 | 501 | { |
| 502 | - $f = sql_serveur('insertq_multi', $serveur, $option==='continue' OR $option===false); |
|
| 502 | + $f = sql_serveur('insertq_multi', $serveur, $option === 'continue' OR $option === false); |
|
| 503 | 503 | if (!is_string($f) OR !$f) return false; |
| 504 | - $r = $f($table, $couples, $desc, $serveur, $option!==false); |
|
| 504 | + $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 505 | 505 | if ($r === false) spip_sql_erreur($serveur); |
| 506 | 506 | return $r; |
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | // http://doc.spip.org/@sql_update |
| 510 | -function sql_update($table, $exp, $where='', $desc=array(), $serveur='', $option=true) |
|
| 510 | +function sql_update($table, $exp, $where = '', $desc = array(), $serveur = '', $option = true) |
|
| 511 | 511 | { |
| 512 | - $f = sql_serveur('update', $serveur, $option==='continue' OR $option===false); |
|
| 512 | + $f = sql_serveur('update', $serveur, $option === 'continue' OR $option === false); |
|
| 513 | 513 | if (!is_string($f) OR !$f) return false; |
| 514 | - $r = $f($table, $exp, $where, $desc, $serveur, $option!==false); |
|
| 514 | + $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 515 | 515 | if ($r === false) spip_sql_erreur($serveur); |
| 516 | 516 | return $r; |
| 517 | 517 | } |
@@ -520,63 +520,63 @@ discard block |
||
| 520 | 520 | // Cette fonction est donc plus utile que la precedente,d'autant qu'elle |
| 521 | 521 | // permet de gerer les differences de representation des constantes. |
| 522 | 522 | // http://doc.spip.org/@sql_updateq |
| 523 | -function sql_updateq($table, $exp, $where='', $desc=array(), $serveur='', $option=true) |
|
| 523 | +function sql_updateq($table, $exp, $where = '', $desc = array(), $serveur = '', $option = true) |
|
| 524 | 524 | { |
| 525 | - $f = sql_serveur('updateq', $serveur, $option==='continue' OR $option===false); |
|
| 525 | + $f = sql_serveur('updateq', $serveur, $option === 'continue' OR $option === false); |
|
| 526 | 526 | if (!is_string($f) OR !$f) return false; |
| 527 | - $r = $f($table, $exp, $where, $desc, $serveur, $option!==false); |
|
| 527 | + $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 528 | 528 | if ($r === false) spip_sql_erreur($serveur); |
| 529 | 529 | return $r; |
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | // http://doc.spip.org/@sql_delete |
| 533 | -function sql_delete($table, $where='', $serveur='', $option=true) |
|
| 533 | +function sql_delete($table, $where = '', $serveur = '', $option = true) |
|
| 534 | 534 | { |
| 535 | - $f = sql_serveur('delete', $serveur, $option==='continue' OR $option===false); |
|
| 535 | + $f = sql_serveur('delete', $serveur, $option === 'continue' OR $option === false); |
|
| 536 | 536 | if (!is_string($f) OR !$f) return false; |
| 537 | - $r = $f($table, $where, $serveur, $option!==false); |
|
| 537 | + $r = $f($table, $where, $serveur, $option !== false); |
|
| 538 | 538 | if ($r === false) spip_sql_erreur($serveur); |
| 539 | 539 | return $r; |
| 540 | 540 | } |
| 541 | 541 | |
| 542 | 542 | // http://doc.spip.org/@sql_replace |
| 543 | -function sql_replace($table, $couples, $desc=array(), $serveur='', $option=true) |
|
| 543 | +function sql_replace($table, $couples, $desc = array(), $serveur = '', $option = true) |
|
| 544 | 544 | { |
| 545 | - $f = sql_serveur('replace', $serveur, $option==='continue' OR $option===false); |
|
| 545 | + $f = sql_serveur('replace', $serveur, $option === 'continue' OR $option === false); |
|
| 546 | 546 | if (!is_string($f) OR !$f) return false; |
| 547 | - $r = $f($table, $couples, $desc, $serveur, $option!==false); |
|
| 547 | + $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 548 | 548 | if ($r === false) spip_sql_erreur($serveur); |
| 549 | 549 | return $r; |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | |
| 553 | 553 | // http://doc.spip.org/@sql_replace_multi |
| 554 | -function sql_replace_multi($table, $tab_couples, $desc=array(), $serveur='', $option=true) |
|
| 554 | +function sql_replace_multi($table, $tab_couples, $desc = array(), $serveur = '', $option = true) |
|
| 555 | 555 | { |
| 556 | - $f = sql_serveur('replace_multi', $serveur, $option==='continue' OR $option===false); |
|
| 556 | + $f = sql_serveur('replace_multi', $serveur, $option === 'continue' OR $option === false); |
|
| 557 | 557 | if (!is_string($f) OR !$f) return false; |
| 558 | - $r = $f($table, $tab_couples, $desc, $serveur, $option!==false); |
|
| 558 | + $r = $f($table, $tab_couples, $desc, $serveur, $option !== false); |
|
| 559 | 559 | if ($r === false) spip_sql_erreur($serveur); |
| 560 | 560 | return $r; |
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | // http://doc.spip.org/@sql_drop_table |
| 564 | -function sql_drop_table($table, $exist='', $serveur='', $option=true) |
|
| 564 | +function sql_drop_table($table, $exist = '', $serveur = '', $option = true) |
|
| 565 | 565 | { |
| 566 | - $f = sql_serveur('drop_table', $serveur, $option==='continue' OR $option===false); |
|
| 566 | + $f = sql_serveur('drop_table', $serveur, $option === 'continue' OR $option === false); |
|
| 567 | 567 | if (!is_string($f) OR !$f) return false; |
| 568 | - $r = $f($table, $exist, $serveur, $option!==false); |
|
| 568 | + $r = $f($table, $exist, $serveur, $option !== false); |
|
| 569 | 569 | if ($r === false) spip_sql_erreur($serveur); |
| 570 | 570 | return $r; |
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | // supprimer une vue sql |
| 574 | 574 | // http://doc.spip.org/@sql_drop_view |
| 575 | -function sql_drop_view($table, $exist='', $serveur='', $option=true) |
|
| 575 | +function sql_drop_view($table, $exist = '', $serveur = '', $option = true) |
|
| 576 | 576 | { |
| 577 | - $f = sql_serveur('drop_view', $serveur, $option==='continue' OR $option===false); |
|
| 577 | + $f = sql_serveur('drop_view', $serveur, $option === 'continue' OR $option === false); |
|
| 578 | 578 | if (!is_string($f) OR !$f) return false; |
| 579 | - $r = $f($table, $exist, $serveur, $option!==false); |
|
| 579 | + $r = $f($table, $exist, $serveur, $option !== false); |
|
| 580 | 580 | if ($r === false) spip_sql_erreur($serveur); |
| 581 | 581 | return $r; |
| 582 | 582 | } |
@@ -599,18 +599,18 @@ discard block |
||
| 599 | 599 | * @return ressource |
| 600 | 600 | * Ressource à utiliser avec sql_fetch() |
| 601 | 601 | **/ |
| 602 | -function sql_showbase($spip=NULL, $serveur='', $option=true) |
|
| 602 | +function sql_showbase($spip = NULL, $serveur = '', $option = true) |
|
| 603 | 603 | { |
| 604 | - $f = sql_serveur('showbase', $serveur, $option==='continue' OR $option===false); |
|
| 604 | + $f = sql_serveur('showbase', $serveur, $option === 'continue' OR $option === false); |
|
| 605 | 605 | if (!is_string($f) OR !$f) return false; |
| 606 | 606 | |
| 607 | 607 | // la globale n'est remplie qu'apres l'appel de sql_serveur. |
| 608 | - if ($spip == NULL){ |
|
| 608 | + if ($spip == NULL) { |
|
| 609 | 609 | $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 610 | - $spip = $connexion['prefixe'] . '\_%'; |
|
| 610 | + $spip = $connexion['prefixe'].'\_%'; |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | - return $f($spip, $serveur, $option!==false); |
|
| 613 | + return $f($spip, $serveur, $option !== false); |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | /** |
@@ -632,28 +632,28 @@ discard block |
||
| 632 | 632 | * @return array |
| 633 | 633 | * Liste des tables SQL |
| 634 | 634 | **/ |
| 635 | -function sql_alltable($spip=NULL, $serveur='', $option=true) |
|
| 635 | +function sql_alltable($spip = NULL, $serveur = '', $option = true) |
|
| 636 | 636 | { |
| 637 | 637 | $q = sql_showbase($spip, $serveur, $option); |
| 638 | 638 | $r = array(); |
| 639 | - if ($q) while ($t = sql_fetch($q, $serveur)) { $r[] = array_shift($t);} |
|
| 639 | + if ($q) while ($t = sql_fetch($q, $serveur)) { $r[] = array_shift($t); } |
|
| 640 | 640 | return $r; |
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | // http://doc.spip.org/@sql_showtable |
| 644 | -function sql_showtable($table, $table_spip = false, $serveur='', $option=true) |
|
| 644 | +function sql_showtable($table, $table_spip = false, $serveur = '', $option = true) |
|
| 645 | 645 | { |
| 646 | - $f = sql_serveur('showtable', $serveur, $option==='continue' OR $option===false); |
|
| 646 | + $f = sql_serveur('showtable', $serveur, $option === 'continue' OR $option === false); |
|
| 647 | 647 | if (!is_string($f) OR !$f) return false; |
| 648 | 648 | |
| 649 | 649 | // la globale n'est remplie qu'apres l'appel de sql_serveur. |
| 650 | - if ($table_spip){ |
|
| 650 | + if ($table_spip) { |
|
| 651 | 651 | $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 652 | 652 | $prefixe = $connexion['prefixe']; |
| 653 | 653 | $vraie_table = preg_replace('/^spip/', $prefixe, $table); |
| 654 | 654 | } else $vraie_table = $table; |
| 655 | 655 | |
| 656 | - $f = $f($vraie_table, $serveur, $option!==false); |
|
| 656 | + $f = $f($vraie_table, $serveur, $option !== false); |
|
| 657 | 657 | if (!$f) return array(); |
| 658 | 658 | if (isset($GLOBALS['tables_principales'][$table]['join'])) |
| 659 | 659 | $f['join'] = $GLOBALS['tables_principales'][$table]['join']; |
@@ -663,19 +663,19 @@ discard block |
||
| 663 | 663 | } |
| 664 | 664 | |
| 665 | 665 | // http://doc.spip.org/@sql_create |
| 666 | -function sql_create($nom, $champs, $cles=array(), $autoinc=false, $temporary=false, $serveur='', $option=true) { |
|
| 667 | - $f = sql_serveur('create', $serveur, $option==='continue' OR $option===false); |
|
| 666 | +function sql_create($nom, $champs, $cles = array(), $autoinc = false, $temporary = false, $serveur = '', $option = true) { |
|
| 667 | + $f = sql_serveur('create', $serveur, $option === 'continue' OR $option === false); |
|
| 668 | 668 | if (!is_string($f) OR !$f) return false; |
| 669 | - $r = $f($nom, $champs, $cles, $autoinc, $temporary, $serveur, $option!==false); |
|
| 669 | + $r = $f($nom, $champs, $cles, $autoinc, $temporary, $serveur, $option !== false); |
|
| 670 | 670 | if ($r === false) spip_sql_erreur($serveur); |
| 671 | 671 | return $r; |
| 672 | 672 | } |
| 673 | 673 | |
| 674 | -function sql_create_base($nom, $serveur='', $option=true) |
|
| 674 | +function sql_create_base($nom, $serveur = '', $option = true) |
|
| 675 | 675 | { |
| 676 | - $f = sql_serveur('create_base', $serveur, $option==='continue' OR $option===false); |
|
| 676 | + $f = sql_serveur('create_base', $serveur, $option === 'continue' OR $option === false); |
|
| 677 | 677 | if (!is_string($f) OR !$f) return false; |
| 678 | - $r = $f($nom, $serveur, $option!==false); |
|
| 678 | + $r = $f($nom, $serveur, $option !== false); |
|
| 679 | 679 | if ($r === false) spip_sql_erreur($serveur); |
| 680 | 680 | return $r; |
| 681 | 681 | } |
@@ -685,18 +685,18 @@ discard block |
||
| 685 | 685 | // select_query : une requete select, idealement cree avec $req = sql_select() |
| 686 | 686 | // (en mettant $option du sql_select a false pour recuperer la requete) |
| 687 | 687 | // http://doc.spip.org/@sql_create_view |
| 688 | -function sql_create_view($nom, $select_query, $serveur='', $option=true) { |
|
| 689 | - $f = sql_serveur('create_view', $serveur, $option==='continue' OR $option===false); |
|
| 688 | +function sql_create_view($nom, $select_query, $serveur = '', $option = true) { |
|
| 689 | + $f = sql_serveur('create_view', $serveur, $option === 'continue' OR $option === false); |
|
| 690 | 690 | if (!is_string($f) OR !$f) return false; |
| 691 | - $r = $f($nom, $select_query, $serveur, $option!==false); |
|
| 691 | + $r = $f($nom, $select_query, $serveur, $option !== false); |
|
| 692 | 692 | if ($r === false) spip_sql_erreur($serveur); |
| 693 | 693 | return $r; |
| 694 | 694 | } |
| 695 | 695 | |
| 696 | 696 | // http://doc.spip.org/@sql_multi |
| 697 | -function sql_multi($sel, $lang, $serveur='', $option=true) |
|
| 697 | +function sql_multi($sel, $lang, $serveur = '', $option = true) |
|
| 698 | 698 | { |
| 699 | - $f = sql_serveur('multi', $serveur, $option==='continue' OR $option===false); |
|
| 699 | + $f = sql_serveur('multi', $serveur, $option === 'continue' OR $option === false); |
|
| 700 | 700 | if (!is_string($f) OR !$f) return false; |
| 701 | 701 | return $f($sel, $lang); |
| 702 | 702 | } |
@@ -712,7 +712,7 @@ discard block |
||
| 712 | 712 | * Description de l'erreur |
| 713 | 713 | * False si le serveur est indisponible |
| 714 | 714 | */ |
| 715 | -function sql_error($serveur='') { |
|
| 715 | +function sql_error($serveur = '') { |
|
| 716 | 716 | $f = sql_serveur('error', $serveur, 'continue'); |
| 717 | 717 | if (!is_string($f) OR !$f) return false; |
| 718 | 718 | return $f('query inconnue', $serveur); |
@@ -728,35 +728,35 @@ discard block |
||
| 728 | 728 | * Numéro de l'erreur |
| 729 | 729 | * False si le serveur est indisponible |
| 730 | 730 | */ |
| 731 | -function sql_errno($serveur='') { |
|
| 731 | +function sql_errno($serveur = '') { |
|
| 732 | 732 | $f = sql_serveur('errno', $serveur, 'continue'); |
| 733 | 733 | if (!is_string($f) OR !$f) return false; |
| 734 | 734 | return $f($serveur); |
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | // http://doc.spip.org/@sql_explain |
| 738 | -function sql_explain($q, $serveur='', $option=true) { |
|
| 739 | - $f = sql_serveur('explain', $serveur, 'continue'); |
|
| 738 | +function sql_explain($q, $serveur = '', $option = true) { |
|
| 739 | + $f = sql_serveur('explain', $serveur, 'continue'); |
|
| 740 | 740 | if (!is_string($f) OR !$f) return false; |
| 741 | - $r = $f($q, $serveur, $option!==false); |
|
| 741 | + $r = $f($q, $serveur, $option !== false); |
|
| 742 | 742 | if ($r === false) spip_sql_erreur($serveur); |
| 743 | 743 | return $r; |
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | // http://doc.spip.org/@sql_optimize |
| 747 | -function sql_optimize($table, $serveur='', $option=true) { |
|
| 748 | - $f = sql_serveur('optimize', $serveur, $option==='continue' OR $option===false); |
|
| 747 | +function sql_optimize($table, $serveur = '', $option = true) { |
|
| 748 | + $f = sql_serveur('optimize', $serveur, $option === 'continue' OR $option === false); |
|
| 749 | 749 | if (!is_string($f) OR !$f) return false; |
| 750 | - $r = $f($table, $serveur, $option!==false); |
|
| 750 | + $r = $f($table, $serveur, $option !== false); |
|
| 751 | 751 | if ($r === false) spip_sql_erreur($serveur); |
| 752 | 752 | return $r; |
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | // http://doc.spip.org/@sql_repair |
| 756 | -function sql_repair($table, $serveur='', $option=true) { |
|
| 757 | - $f = sql_serveur('repair', $serveur, $option==='continue' OR $option===false); |
|
| 756 | +function sql_repair($table, $serveur = '', $option = true) { |
|
| 757 | + $f = sql_serveur('repair', $serveur, $option === 'continue' OR $option === false); |
|
| 758 | 758 | if (!is_string($f) OR !$f) return false; |
| 759 | - $r = $f($table, $serveur, $option!==false); |
|
| 759 | + $r = $f($table, $serveur, $option !== false); |
|
| 760 | 760 | if ($r === false) spip_sql_erreur($serveur); |
| 761 | 761 | return $r; |
| 762 | 762 | } |
@@ -765,10 +765,10 @@ discard block |
||
| 765 | 765 | // A n'utiliser qu'en derniere extremite |
| 766 | 766 | |
| 767 | 767 | // http://doc.spip.org/@sql_query |
| 768 | -function sql_query($ins, $serveur='', $option=true) { |
|
| 769 | - $f = sql_serveur('query', $serveur, $option==='continue' OR $option===false); |
|
| 768 | +function sql_query($ins, $serveur = '', $option = true) { |
|
| 769 | + $f = sql_serveur('query', $serveur, $option === 'continue' OR $option === false); |
|
| 770 | 770 | if (!is_string($f) OR !$f) return false; |
| 771 | - $r = $f($ins, $serveur, $option!==false); |
|
| 771 | + $r = $f($ins, $serveur, $option !== false); |
|
| 772 | 772 | if ($r === false) spip_sql_erreur($serveur); |
| 773 | 773 | return $r; |
| 774 | 774 | } |
@@ -820,9 +820,9 @@ discard block |
||
| 820 | 820 | **/ |
| 821 | 821 | function sql_fetsel($select = array(), $from = array(), $where = array(), |
| 822 | 822 | $groupby = array(), $orderby = array(), $limit = '', |
| 823 | - $having = array(), $serveur='', $option=true) { |
|
| 824 | - $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 825 | - if ($option===false) return $q; |
|
| 823 | + $having = array(), $serveur = '', $option = true) { |
|
| 824 | + $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 825 | + if ($option === false) return $q; |
|
| 826 | 826 | if (!$q) return array(); |
| 827 | 827 | $r = sql_fetch($q, $serveur, $option); |
| 828 | 828 | sql_free($q, $serveur, $option); |
@@ -884,9 +884,9 @@ discard block |
||
| 884 | 884 | **/ |
| 885 | 885 | function sql_allfetsel($select = array(), $from = array(), $where = array(), |
| 886 | 886 | $groupby = array(), $orderby = array(), $limit = '', |
| 887 | - $having = array(), $serveur='', $option=true) { |
|
| 888 | - $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 889 | - if ($option===false) return $q; |
|
| 887 | + $having = array(), $serveur = '', $option = true) { |
|
| 888 | + $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 889 | + if ($option === false) return $q; |
|
| 890 | 890 | return sql_fetch_all($q, $serveur, $option); |
| 891 | 891 | } |
| 892 | 892 | |
@@ -932,12 +932,12 @@ discard block |
||
| 932 | 932 | * |
| 933 | 933 | **/ |
| 934 | 934 | function sql_getfetsel($select, $from = array(), $where = array(), $groupby = array(), |
| 935 | - $orderby = array(), $limit = '', $having = array(), $serveur='', $option=true) { |
|
| 935 | + $orderby = array(), $limit = '', $having = array(), $serveur = '', $option = true) { |
|
| 936 | 936 | if (preg_match('/\s+as\s+(\w+)$/i', $select, $c)) $id = $c[1]; |
| 937 | 937 | elseif (!preg_match('/\W/', $select)) $id = $select; |
| 938 | - else {$id = 'n'; $select .= ' AS n';} |
|
| 939 | - $r = sql_fetsel($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 940 | - if ($option===false) return $r; |
|
| 938 | + else {$id = 'n'; $select .= ' AS n'; } |
|
| 939 | + $r = sql_fetsel($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 940 | + if ($option === false) return $r; |
|
| 941 | 941 | if (!$r) return NULL; |
| 942 | 942 | return $r[$id]; |
| 943 | 943 | } |
@@ -956,8 +956,8 @@ discard block |
||
| 956 | 956 | * @return string |
| 957 | 957 | * Numero de version du serveur SQL |
| 958 | 958 | **/ |
| 959 | -function sql_version($serveur='', $option=true) { |
|
| 960 | - $row = sql_fetsel("version() AS n", '','','','','','',$serveur); |
|
| 959 | +function sql_version($serveur = '', $option = true) { |
|
| 960 | + $row = sql_fetsel("version() AS n", '', '', '', '', '', '', $serveur); |
|
| 961 | 961 | return ($row['n']); |
| 962 | 962 | } |
| 963 | 963 | |
@@ -993,10 +993,10 @@ discard block |
||
| 993 | 993 | * @return bool |
| 994 | 994 | * Le serveur SQL prefere t'il des transactions pour les insertions multiples ? |
| 995 | 995 | **/ |
| 996 | -function sql_preferer_transaction($serveur='', $option=true) { |
|
| 997 | - $f = sql_serveur('preferer_transaction', $serveur, 'continue'); |
|
| 996 | +function sql_preferer_transaction($serveur = '', $option = true) { |
|
| 997 | + $f = sql_serveur('preferer_transaction', $serveur, 'continue'); |
|
| 998 | 998 | if (!is_string($f) OR !$f) return false; |
| 999 | - $r = $f($serveur, $option!==false); |
|
| 999 | + $r = $f($serveur, $option !== false); |
|
| 1000 | 1000 | if ($r === false) spip_sql_erreur($serveur); |
| 1001 | 1001 | return $r; |
| 1002 | 1002 | }; |
@@ -1019,10 +1019,10 @@ discard block |
||
| 1019 | 1019 | * true si la transaction est demarree |
| 1020 | 1020 | * false en cas d'erreur |
| 1021 | 1021 | **/ |
| 1022 | -function sql_demarrer_transaction($serveur='', $option=true) { |
|
| 1023 | - $f = sql_serveur('demarrer_transaction', $serveur, 'continue'); |
|
| 1022 | +function sql_demarrer_transaction($serveur = '', $option = true) { |
|
| 1023 | + $f = sql_serveur('demarrer_transaction', $serveur, 'continue'); |
|
| 1024 | 1024 | if (!is_string($f) OR !$f) return false; |
| 1025 | - $r = $f($serveur, $option!==false); |
|
| 1025 | + $r = $f($serveur, $option !== false); |
|
| 1026 | 1026 | if ($r === false) spip_sql_erreur($serveur); |
| 1027 | 1027 | return $r; |
| 1028 | 1028 | }; |
@@ -1045,10 +1045,10 @@ discard block |
||
| 1045 | 1045 | * true si la transaction est demarree |
| 1046 | 1046 | * false en cas d'erreur |
| 1047 | 1047 | **/ |
| 1048 | -function sql_terminer_transaction($serveur='', $option=true) { |
|
| 1049 | - $f = sql_serveur('terminer_transaction', $serveur, 'continue'); |
|
| 1048 | +function sql_terminer_transaction($serveur = '', $option = true) { |
|
| 1049 | + $f = sql_serveur('terminer_transaction', $serveur, 'continue'); |
|
| 1050 | 1050 | if (!is_string($f) OR !$f) return false; |
| 1051 | - $r = $f($serveur, $option!==false); |
|
| 1051 | + $r = $f($serveur, $option !== false); |
|
| 1052 | 1052 | if ($r === false) spip_sql_erreur($serveur); |
| 1053 | 1053 | return $r; |
| 1054 | 1054 | }; |
@@ -1073,9 +1073,9 @@ discard block |
||
| 1073 | 1073 | * @return string |
| 1074 | 1074 | * Retourne la valeur hexadecimale attendue par le serveur SQL |
| 1075 | 1075 | **/ |
| 1076 | -function sql_hex($val, $serveur='', $option=true) |
|
| 1076 | +function sql_hex($val, $serveur = '', $option = true) |
|
| 1077 | 1077 | { |
| 1078 | - $f = sql_serveur('hex', $serveur, $option==='continue' OR $option===false); |
|
| 1078 | + $f = sql_serveur('hex', $serveur, $option === 'continue' OR $option === false); |
|
| 1079 | 1079 | if (!is_string($f) OR !$f) return false; |
| 1080 | 1080 | return $f($val); |
| 1081 | 1081 | } |
@@ -1100,14 +1100,14 @@ discard block |
||
| 1100 | 1100 | * @return string |
| 1101 | 1101 | * La chaine echappee |
| 1102 | 1102 | **/ |
| 1103 | -function sql_quote($val, $serveur='', $type='') |
|
| 1103 | +function sql_quote($val, $serveur = '', $type = '') |
|
| 1104 | 1104 | { |
| 1105 | 1105 | $f = sql_serveur('quote', $serveur, true); |
| 1106 | 1106 | if (!is_string($f) OR !$f) $f = '_q'; |
| 1107 | 1107 | return $f($val, $type); |
| 1108 | 1108 | } |
| 1109 | 1109 | |
| 1110 | -function sql_date_proche($champ, $interval, $unite, $serveur='', $option=true) |
|
| 1110 | +function sql_date_proche($champ, $interval, $unite, $serveur = '', $option = true) |
|
| 1111 | 1111 | { |
| 1112 | 1112 | $f = sql_serveur('date_proche', $serveur, true); |
| 1113 | 1113 | if (!is_string($f) OR !$f) return false; |
@@ -1142,17 +1142,17 @@ discard block |
||
| 1142 | 1142 | * @return string |
| 1143 | 1143 | * Expression de requête SQL |
| 1144 | 1144 | **/ |
| 1145 | -function sql_in($val, $valeurs, $not='', $serveur='', $option=true) { |
|
| 1145 | +function sql_in($val, $valeurs, $not = '', $serveur = '', $option = true) { |
|
| 1146 | 1146 | if (is_array($valeurs)) { |
| 1147 | 1147 | $f = sql_serveur('quote', $serveur, true); |
| 1148 | 1148 | if (!is_string($f) OR !$f) return false; |
| 1149 | 1149 | $valeurs = join(',', array_map($f, array_unique($valeurs))); |
| 1150 | - } elseif (isset($valeurs[0]) AND $valeurs[0]===',') $valeurs = substr($valeurs,1); |
|
| 1150 | + } elseif (isset($valeurs[0]) AND $valeurs[0] === ',') $valeurs = substr($valeurs, 1); |
|
| 1151 | 1151 | if (!strlen(trim($valeurs))) return ($not ? "0=0" : '0=1'); |
| 1152 | 1152 | |
| 1153 | - $f = sql_serveur('in', $serveur, $option==='continue' OR $option===false); |
|
| 1153 | + $f = sql_serveur('in', $serveur, $option === 'continue' OR $option === false); |
|
| 1154 | 1154 | if (!is_string($f) OR !$f) return false; |
| 1155 | - return $f($val, $valeurs, $not, $serveur, $option!==false); |
|
| 1155 | + return $f($val, $valeurs, $not, $serveur, $option !== false); |
|
| 1156 | 1156 | } |
| 1157 | 1157 | |
| 1158 | 1158 | // Penser a dire dans la description du serveur |
@@ -1160,11 +1160,11 @@ discard block |
||
| 1160 | 1160 | |
| 1161 | 1161 | // http://doc.spip.org/@sql_in_select |
| 1162 | 1162 | function sql_in_select($in, $select, $from = array(), $where = array(), |
| 1163 | - $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur='') |
|
| 1163 | + $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur = '') |
|
| 1164 | 1164 | { |
| 1165 | 1165 | $liste = array(); |
| 1166 | 1166 | $res = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur); |
| 1167 | - while ($r = sql_fetch($res)) {$liste[] = array_shift($r);} |
|
| 1167 | + while ($r = sql_fetch($res)) {$liste[] = array_shift($r); } |
|
| 1168 | 1168 | sql_free($res); |
| 1169 | 1169 | return sql_in($in, $liste); |
| 1170 | 1170 | } |
@@ -1196,33 +1196,33 @@ discard block |
||
| 1196 | 1196 | * @return int |
| 1197 | 1197 | * Position apres le saut. |
| 1198 | 1198 | */ |
| 1199 | -function sql_skip($res, $pos, $saut, $count, $serveur='', $option=true){ |
|
| 1199 | +function sql_skip($res, $pos, $saut, $count, $serveur = '', $option = true) { |
|
| 1200 | 1200 | // pas de saut en arriere qu'on ne sait pas faire sans sql_seek |
| 1201 | - if (($saut=intval($saut))<=0) return $pos; |
|
| 1201 | + if (($saut = intval($saut)) <= 0) return $pos; |
|
| 1202 | 1202 | |
| 1203 | 1203 | $seek = $pos + $saut; |
| 1204 | 1204 | // si le saut fait depasser le maxi, on libere la resource |
| 1205 | 1205 | // et on sort |
| 1206 | - if ($seek>=$count) {sql_free($res, $serveur, $option); return $count;} |
|
| 1206 | + if ($seek >= $count) {sql_free($res, $serveur, $option); return $count; } |
|
| 1207 | 1207 | |
| 1208 | 1208 | if (sql_seek($res, $seek)) |
| 1209 | 1209 | $pos = $seek; |
| 1210 | 1210 | else |
| 1211 | - while ($pos<$seek AND sql_fetch($res, $serveur, $option)) |
|
| 1211 | + while ($pos < $seek AND sql_fetch($res, $serveur, $option)) |
|
| 1212 | 1212 | $pos++; |
| 1213 | 1213 | return $pos; |
| 1214 | 1214 | } |
| 1215 | 1215 | |
| 1216 | 1216 | // http://doc.spip.org/@sql_test_int |
| 1217 | -function sql_test_int($type, $serveur='', $option=true) |
|
| 1217 | +function sql_test_int($type, $serveur = '', $option = true) |
|
| 1218 | 1218 | { |
| 1219 | - return preg_match('/^(TINYINT|SMALLINT|MEDIUMINT|INT|INTEGER|BIGINT)/i',trim($type)); |
|
| 1219 | + return preg_match('/^(TINYINT|SMALLINT|MEDIUMINT|INT|INTEGER|BIGINT)/i', trim($type)); |
|
| 1220 | 1220 | } |
| 1221 | 1221 | |
| 1222 | 1222 | // http://doc.spip.org/@sql_test_date |
| 1223 | -function sql_test_date($type, $serveur='', $option=true) |
|
| 1223 | +function sql_test_date($type, $serveur = '', $option = true) |
|
| 1224 | 1224 | { |
| 1225 | - return preg_match('/^(DATE|DATETIME|TIMESTAMP|TIME)/i',trim($type)); |
|
| 1225 | + return preg_match('/^(DATE|DATETIME|TIMESTAMP|TIME)/i', trim($type)); |
|
| 1226 | 1226 | } |
| 1227 | 1227 | |
| 1228 | 1228 | /** |
@@ -1244,16 +1244,16 @@ discard block |
||
| 1244 | 1244 | * @return string |
| 1245 | 1245 | * La date formatee |
| 1246 | 1246 | */ |
| 1247 | -function sql_format_date($annee=0, $mois=0, $jour=0, $h=0, $m=0, $s=0, $serveur=''){ |
|
| 1248 | - $annee = sprintf("%04s",$annee); |
|
| 1249 | - $mois = sprintf("%02s",$mois); |
|
| 1247 | +function sql_format_date($annee = 0, $mois = 0, $jour = 0, $h = 0, $m = 0, $s = 0, $serveur = '') { |
|
| 1248 | + $annee = sprintf("%04s", $annee); |
|
| 1249 | + $mois = sprintf("%02s", $mois); |
|
| 1250 | 1250 | |
| 1251 | 1251 | if ($annee == "0000") $mois = 0; |
| 1252 | 1252 | if ($mois == "00") $jour = 0; |
| 1253 | 1253 | |
| 1254 | - return sprintf("%04u",$annee) . '-' . sprintf("%02u",$mois) . '-' |
|
| 1255 | - . sprintf("%02u",$jour) . ' ' . sprintf("%02u",$h) . ':' |
|
| 1256 | - . sprintf("%02u",$m) . ':' . sprintf("%02u",$s); |
|
| 1254 | + return sprintf("%04u", $annee).'-'.sprintf("%02u", $mois).'-' |
|
| 1255 | + . sprintf("%02u", $jour).' '.sprintf("%02u", $h).':' |
|
| 1256 | + . sprintf("%02u", $m).':'.sprintf("%02u", $s); |
|
| 1257 | 1257 | } |
| 1258 | 1258 | |
| 1259 | 1259 | |
@@ -1275,7 +1275,7 @@ discard block |
||
| 1275 | 1275 | * @return array|bool |
| 1276 | 1276 | * Description de la table ou false si elle n'est pas trouvee ou declaree. |
| 1277 | 1277 | **/ |
| 1278 | -function description_table($nom, $serveur=''){ |
|
| 1278 | +function description_table($nom, $serveur = '') { |
|
| 1279 | 1279 | |
| 1280 | 1280 | global $tables_principales, $tables_auxiliaires; |
| 1281 | 1281 | static $trouver_table; |
@@ -24,7 +24,9 @@ discard block |
||
| 24 | 24 | * @version 1 |
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | -if (!defined('_ECRIRE_INC_VERSION')) return; |
|
| 27 | +if (!defined('_ECRIRE_INC_VERSION')) { |
|
| 28 | + return; |
|
| 29 | +} |
|
| 28 | 30 | |
| 29 | 31 | /** Version de l'API SQL */ |
| 30 | 32 | define('sql_ABSTRACT_VERSION', 1); |
@@ -56,7 +58,9 @@ discard block |
||
| 56 | 58 | static $sql_serveur = array(); |
| 57 | 59 | if (!isset($sql_serveur[$serveur][$ins_sql])){ |
| 58 | 60 | $f = spip_connect_sql(sql_ABSTRACT_VERSION, $ins_sql, $serveur, $continue); |
| 59 | - if (!is_string($f) OR !$f) return $f; |
|
| 61 | + if (!is_string($f) OR !$f) { |
|
| 62 | + return $f; |
|
| 63 | + } |
|
| 60 | 64 | $sql_serveur[$serveur][$ins_sql] = $f; |
| 61 | 65 | } |
| 62 | 66 | return $sql_serveur[$serveur][$ins_sql]; |
@@ -86,8 +90,9 @@ discard block |
||
| 86 | 90 | $desc = $desc[sql_ABSTRACT_VERSION]; |
| 87 | 91 | $c = $desc['charsets'][$charset]; |
| 88 | 92 | if ($c) { |
| 89 | - if (function_exists($f=@$desc['get_charset'])) |
|
| 90 | - if ($f($c, $serveur, $option!==false)) return $c; |
|
| 93 | + if (function_exists($f=@$desc['get_charset'])) { |
|
| 94 | + if ($f($c, $serveur, $option!==false)) return $c; |
|
| 95 | + } |
|
| 91 | 96 | } |
| 92 | 97 | spip_log( "SPIP ne connait pas les Charsets disponibles sur le serveur $serveur. Le serveur choisira seul.", _LOG_AVERTISSEMENT); |
| 93 | 98 | return false; |
@@ -117,7 +122,9 @@ discard block |
||
| 117 | 122 | **/ |
| 118 | 123 | function sql_set_charset($charset,$serveur='', $option=true){ |
| 119 | 124 | $f = sql_serveur('set_charset', $serveur, $option==='continue' OR $option===false); |
| 120 | - if (!is_string($f) OR !$f) return false; |
|
| 125 | + if (!is_string($f) OR !$f) { |
|
| 126 | + return false; |
|
| 127 | + } |
|
| 121 | 128 | return $f($charset, $serveur, $option!==false); |
| 122 | 129 | } |
| 123 | 130 | |
@@ -171,14 +178,18 @@ discard block |
||
| 171 | 178 | $groupby = array(), $orderby = array(), $limit = '', $having = array(), |
| 172 | 179 | $serveur='', $option=true) { |
| 173 | 180 | $f = sql_serveur('select', $serveur, $option==='continue' OR $option===false); |
| 174 | - if (!is_string($f) OR !$f) return false; |
|
| 181 | + if (!is_string($f) OR !$f) { |
|
| 182 | + return false; |
|
| 183 | + } |
|
| 175 | 184 | |
| 176 | 185 | $debug = (defined('_VAR_MODE') AND _VAR_MODE == 'debug'); |
| 177 | 186 | if (($option !== false) AND !$debug) { |
| 178 | 187 | $res = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, is_array($option) ? true : $option); |
| 179 | 188 | } else { |
| 180 | 189 | $query = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
| 181 | - if (!$option) return $query; |
|
| 190 | + if (!$option) { |
|
| 191 | + return $query; |
|
| 192 | + } |
|
| 182 | 193 | // le debug, c'est pour ce qui a ete produit par le compilateur |
| 183 | 194 | if (isset($GLOBALS['debug']['aucasou'])) { |
| 184 | 195 | list($table, $id,) = $GLOBALS['debug']['aucasou']; |
@@ -189,7 +200,9 @@ discard block |
||
| 189 | 200 | } |
| 190 | 201 | |
| 191 | 202 | // en cas d'erreur |
| 192 | - if (!is_string($res)) return $res; |
|
| 203 | + if (!is_string($res)) { |
|
| 204 | + return $res; |
|
| 205 | + } |
|
| 193 | 206 | // denoncer l'erreur SQL dans sa version brute |
| 194 | 207 | spip_sql_erreur($serveur); |
| 195 | 208 | // idem dans sa version squelette (prefixe des tables non substitue) |
@@ -270,9 +283,13 @@ discard block |
||
| 270 | 283 | $groupby = array(), $having = array(), |
| 271 | 284 | $serveur='', $option=true) { |
| 272 | 285 | $f = sql_serveur('countsel', $serveur, $option==='continue' OR $option===false); |
| 273 | - if (!is_string($f) OR !$f) return false; |
|
| 286 | + if (!is_string($f) OR !$f) { |
|
| 287 | + return false; |
|
| 288 | + } |
|
| 274 | 289 | $r = $f($from, $where, $groupby, $having, $serveur, $option!==false); |
| 275 | - if ($r===false) spip_sql_erreur($serveur); |
|
| 290 | + if ($r===false) { |
|
| 291 | + spip_sql_erreur($serveur); |
|
| 292 | + } |
|
| 276 | 293 | return $r; |
| 277 | 294 | } |
| 278 | 295 | |
@@ -301,9 +318,13 @@ discard block |
||
| 301 | 318 | **/ |
| 302 | 319 | function sql_alter($q, $serveur='', $option=true) { |
| 303 | 320 | $f = sql_serveur('alter', $serveur, $option==='continue' OR $option===false); |
| 304 | - if (!is_string($f) OR !$f) return false; |
|
| 321 | + if (!is_string($f) OR !$f) { |
|
| 322 | + return false; |
|
| 323 | + } |
|
| 305 | 324 | $r = $f($q, $serveur, $option!==false); |
| 306 | - if ($r===false) spip_sql_erreur($serveur); |
|
| 325 | + if ($r===false) { |
|
| 326 | + spip_sql_erreur($serveur); |
|
| 327 | + } |
|
| 307 | 328 | return $r; |
| 308 | 329 | } |
| 309 | 330 | |
@@ -328,7 +349,9 @@ discard block |
||
| 328 | 349 | */ |
| 329 | 350 | function sql_fetch($res, $serveur='', $option=true) { |
| 330 | 351 | $f = sql_serveur('fetch', $serveur, $option==='continue' OR $option===false); |
| 331 | - if (!is_string($f) OR !$f) return false; |
|
| 352 | + if (!is_string($f) OR !$f) { |
|
| 353 | + return false; |
|
| 354 | + } |
|
| 332 | 355 | return $f($res, NULL, $serveur, $option!==false); |
| 333 | 356 | } |
| 334 | 357 | |
@@ -357,11 +380,16 @@ discard block |
||
| 357 | 380 | */ |
| 358 | 381 | function sql_fetch_all($res, $serveur='', $option=true){ |
| 359 | 382 | $rows = array(); |
| 360 | - if (!$res) return $rows; |
|
| 383 | + if (!$res) { |
|
| 384 | + return $rows; |
|
| 385 | + } |
|
| 361 | 386 | $f = sql_serveur('fetch', $serveur, $option==='continue' OR $option===false); |
| 362 | - if (!is_string($f) OR !$f) return array(); |
|
| 363 | - while ($r = $f($res, NULL, $serveur, $option!==false)) |
|
| 364 | - $rows[] = $r; |
|
| 387 | + if (!is_string($f) OR !$f) { |
|
| 388 | + return array(); |
|
| 389 | + } |
|
| 390 | + while ($r = $f($res, NULL, $serveur, $option!==false)) { |
|
| 391 | + $rows[] = $r; |
|
| 392 | + } |
|
| 365 | 393 | sql_free($res, $serveur); |
| 366 | 394 | return $rows; |
| 367 | 395 | } |
@@ -392,9 +420,13 @@ discard block |
||
| 392 | 420 | **/ |
| 393 | 421 | function sql_seek($res, $row_number, $serveur='', $option=true) { |
| 394 | 422 | $f = sql_serveur('seek', $serveur, $option==='continue' OR $option===false); |
| 395 | - if (!is_string($f) OR !$f) return false; |
|
| 423 | + if (!is_string($f) OR !$f) { |
|
| 424 | + return false; |
|
| 425 | + } |
|
| 396 | 426 | $r = $f($res, $row_number, $serveur, $option!==false); |
| 397 | - if ($r===false) spip_sql_erreur($serveur); |
|
| 427 | + if ($r===false) { |
|
| 428 | + spip_sql_erreur($serveur); |
|
| 429 | + } |
|
| 398 | 430 | return $r; |
| 399 | 431 | } |
| 400 | 432 | |
@@ -421,9 +453,13 @@ discard block |
||
| 421 | 453 | **/ |
| 422 | 454 | function sql_listdbs($serveur='', $option=true) { |
| 423 | 455 | $f = sql_serveur('listdbs', $serveur, $option==='continue' OR $option===false); |
| 424 | - if (!is_string($f) OR !$f) return false; |
|
| 456 | + if (!is_string($f) OR !$f) { |
|
| 457 | + return false; |
|
| 458 | + } |
|
| 425 | 459 | $r = $f($serveur); |
| 426 | - if ($r===false) spip_sql_erreur($serveur); |
|
| 460 | + if ($r===false) { |
|
| 461 | + spip_sql_erreur($serveur); |
|
| 462 | + } |
|
| 427 | 463 | return $r; |
| 428 | 464 | } |
| 429 | 465 | |
@@ -448,9 +484,13 @@ discard block |
||
| 448 | 484 | function sql_selectdb($nom, $serveur='', $option=true) |
| 449 | 485 | { |
| 450 | 486 | $f = sql_serveur('selectdb', $serveur, $option==='continue' OR $option===false); |
| 451 | - if (!is_string($f) OR !$f) return false; |
|
| 487 | + if (!is_string($f) OR !$f) { |
|
| 488 | + return false; |
|
| 489 | + } |
|
| 452 | 490 | $r = $f($nom, $serveur, $option!==false); |
| 453 | - if ($r===false) spip_sql_erreur($serveur); |
|
| 491 | + if ($r===false) { |
|
| 492 | + spip_sql_erreur($serveur); |
|
| 493 | + } |
|
| 454 | 494 | return $r; |
| 455 | 495 | } |
| 456 | 496 | |
@@ -458,9 +498,13 @@ discard block |
||
| 458 | 498 | function sql_count($res, $serveur='', $option=true) |
| 459 | 499 | { |
| 460 | 500 | $f = sql_serveur('count', $serveur, $option==='continue' OR $option===false); |
| 461 | - if (!is_string($f) OR !$f) return false; |
|
| 501 | + if (!is_string($f) OR !$f) { |
|
| 502 | + return false; |
|
| 503 | + } |
|
| 462 | 504 | $r = $f($res, $serveur, $option!==false); |
| 463 | - if ($r===false) spip_sql_erreur($serveur); |
|
| 505 | + if ($r===false) { |
|
| 506 | + spip_sql_erreur($serveur); |
|
| 507 | + } |
|
| 464 | 508 | return $r; |
| 465 | 509 | } |
| 466 | 510 | |
@@ -468,7 +512,9 @@ discard block |
||
| 468 | 512 | function sql_free($res, $serveur='', $option=true) |
| 469 | 513 | { |
| 470 | 514 | $f = sql_serveur('free', $serveur, $option==='continue' OR $option===false); |
| 471 | - if (!is_string($f) OR !$f) return false; |
|
| 515 | + if (!is_string($f) OR !$f) { |
|
| 516 | + return false; |
|
| 517 | + } |
|
| 472 | 518 | return $f($res); |
| 473 | 519 | } |
| 474 | 520 | |
@@ -480,9 +526,13 @@ discard block |
||
| 480 | 526 | function sql_insert($table, $noms, $valeurs, $desc=array(), $serveur='', $option=true) |
| 481 | 527 | { |
| 482 | 528 | $f = sql_serveur('insert', $serveur, $option==='continue' OR $option===false); |
| 483 | - if (!is_string($f) OR !$f) return false; |
|
| 529 | + if (!is_string($f) OR !$f) { |
|
| 530 | + return false; |
|
| 531 | + } |
|
| 484 | 532 | $r = $f($table, $noms, $valeurs, $desc, $serveur, $option!==false); |
| 485 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 533 | + if ($r === false) { |
|
| 534 | + spip_sql_erreur($serveur); |
|
| 535 | + } |
|
| 486 | 536 | return $r; |
| 487 | 537 | } |
| 488 | 538 | |
@@ -490,9 +540,13 @@ discard block |
||
| 490 | 540 | function sql_insertq($table, $couples=array(), $desc=array(), $serveur='', $option=true) |
| 491 | 541 | { |
| 492 | 542 | $f = sql_serveur('insertq', $serveur, $option==='continue' OR $option===false); |
| 493 | - if (!is_string($f) OR !$f) return false; |
|
| 543 | + if (!is_string($f) OR !$f) { |
|
| 544 | + return false; |
|
| 545 | + } |
|
| 494 | 546 | $r = $f($table, $couples, $desc, $serveur, $option!==false); |
| 495 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 547 | + if ($r === false) { |
|
| 548 | + spip_sql_erreur($serveur); |
|
| 549 | + } |
|
| 496 | 550 | return $r; |
| 497 | 551 | } |
| 498 | 552 | |
@@ -500,9 +554,13 @@ discard block |
||
| 500 | 554 | function sql_insertq_multi($table, $couples=array(), $desc=array(), $serveur='', $option=true) |
| 501 | 555 | { |
| 502 | 556 | $f = sql_serveur('insertq_multi', $serveur, $option==='continue' OR $option===false); |
| 503 | - if (!is_string($f) OR !$f) return false; |
|
| 557 | + if (!is_string($f) OR !$f) { |
|
| 558 | + return false; |
|
| 559 | + } |
|
| 504 | 560 | $r = $f($table, $couples, $desc, $serveur, $option!==false); |
| 505 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 561 | + if ($r === false) { |
|
| 562 | + spip_sql_erreur($serveur); |
|
| 563 | + } |
|
| 506 | 564 | return $r; |
| 507 | 565 | } |
| 508 | 566 | |
@@ -510,9 +568,13 @@ discard block |
||
| 510 | 568 | function sql_update($table, $exp, $where='', $desc=array(), $serveur='', $option=true) |
| 511 | 569 | { |
| 512 | 570 | $f = sql_serveur('update', $serveur, $option==='continue' OR $option===false); |
| 513 | - if (!is_string($f) OR !$f) return false; |
|
| 571 | + if (!is_string($f) OR !$f) { |
|
| 572 | + return false; |
|
| 573 | + } |
|
| 514 | 574 | $r = $f($table, $exp, $where, $desc, $serveur, $option!==false); |
| 515 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 575 | + if ($r === false) { |
|
| 576 | + spip_sql_erreur($serveur); |
|
| 577 | + } |
|
| 516 | 578 | return $r; |
| 517 | 579 | } |
| 518 | 580 | |
@@ -523,9 +585,13 @@ discard block |
||
| 523 | 585 | function sql_updateq($table, $exp, $where='', $desc=array(), $serveur='', $option=true) |
| 524 | 586 | { |
| 525 | 587 | $f = sql_serveur('updateq', $serveur, $option==='continue' OR $option===false); |
| 526 | - if (!is_string($f) OR !$f) return false; |
|
| 588 | + if (!is_string($f) OR !$f) { |
|
| 589 | + return false; |
|
| 590 | + } |
|
| 527 | 591 | $r = $f($table, $exp, $where, $desc, $serveur, $option!==false); |
| 528 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 592 | + if ($r === false) { |
|
| 593 | + spip_sql_erreur($serveur); |
|
| 594 | + } |
|
| 529 | 595 | return $r; |
| 530 | 596 | } |
| 531 | 597 | |
@@ -533,9 +599,13 @@ discard block |
||
| 533 | 599 | function sql_delete($table, $where='', $serveur='', $option=true) |
| 534 | 600 | { |
| 535 | 601 | $f = sql_serveur('delete', $serveur, $option==='continue' OR $option===false); |
| 536 | - if (!is_string($f) OR !$f) return false; |
|
| 602 | + if (!is_string($f) OR !$f) { |
|
| 603 | + return false; |
|
| 604 | + } |
|
| 537 | 605 | $r = $f($table, $where, $serveur, $option!==false); |
| 538 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 606 | + if ($r === false) { |
|
| 607 | + spip_sql_erreur($serveur); |
|
| 608 | + } |
|
| 539 | 609 | return $r; |
| 540 | 610 | } |
| 541 | 611 | |
@@ -543,9 +613,13 @@ discard block |
||
| 543 | 613 | function sql_replace($table, $couples, $desc=array(), $serveur='', $option=true) |
| 544 | 614 | { |
| 545 | 615 | $f = sql_serveur('replace', $serveur, $option==='continue' OR $option===false); |
| 546 | - if (!is_string($f) OR !$f) return false; |
|
| 616 | + if (!is_string($f) OR !$f) { |
|
| 617 | + return false; |
|
| 618 | + } |
|
| 547 | 619 | $r = $f($table, $couples, $desc, $serveur, $option!==false); |
| 548 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 620 | + if ($r === false) { |
|
| 621 | + spip_sql_erreur($serveur); |
|
| 622 | + } |
|
| 549 | 623 | return $r; |
| 550 | 624 | } |
| 551 | 625 | |
@@ -554,9 +628,13 @@ discard block |
||
| 554 | 628 | function sql_replace_multi($table, $tab_couples, $desc=array(), $serveur='', $option=true) |
| 555 | 629 | { |
| 556 | 630 | $f = sql_serveur('replace_multi', $serveur, $option==='continue' OR $option===false); |
| 557 | - if (!is_string($f) OR !$f) return false; |
|
| 631 | + if (!is_string($f) OR !$f) { |
|
| 632 | + return false; |
|
| 633 | + } |
|
| 558 | 634 | $r = $f($table, $tab_couples, $desc, $serveur, $option!==false); |
| 559 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 635 | + if ($r === false) { |
|
| 636 | + spip_sql_erreur($serveur); |
|
| 637 | + } |
|
| 560 | 638 | return $r; |
| 561 | 639 | } |
| 562 | 640 | |
@@ -564,9 +642,13 @@ discard block |
||
| 564 | 642 | function sql_drop_table($table, $exist='', $serveur='', $option=true) |
| 565 | 643 | { |
| 566 | 644 | $f = sql_serveur('drop_table', $serveur, $option==='continue' OR $option===false); |
| 567 | - if (!is_string($f) OR !$f) return false; |
|
| 645 | + if (!is_string($f) OR !$f) { |
|
| 646 | + return false; |
|
| 647 | + } |
|
| 568 | 648 | $r = $f($table, $exist, $serveur, $option!==false); |
| 569 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 649 | + if ($r === false) { |
|
| 650 | + spip_sql_erreur($serveur); |
|
| 651 | + } |
|
| 570 | 652 | return $r; |
| 571 | 653 | } |
| 572 | 654 | |
@@ -575,9 +657,13 @@ discard block |
||
| 575 | 657 | function sql_drop_view($table, $exist='', $serveur='', $option=true) |
| 576 | 658 | { |
| 577 | 659 | $f = sql_serveur('drop_view', $serveur, $option==='continue' OR $option===false); |
| 578 | - if (!is_string($f) OR !$f) return false; |
|
| 660 | + if (!is_string($f) OR !$f) { |
|
| 661 | + return false; |
|
| 662 | + } |
|
| 579 | 663 | $r = $f($table, $exist, $serveur, $option!==false); |
| 580 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 664 | + if ($r === false) { |
|
| 665 | + spip_sql_erreur($serveur); |
|
| 666 | + } |
|
| 581 | 667 | return $r; |
| 582 | 668 | } |
| 583 | 669 | |
@@ -602,7 +688,9 @@ discard block |
||
| 602 | 688 | function sql_showbase($spip=NULL, $serveur='', $option=true) |
| 603 | 689 | { |
| 604 | 690 | $f = sql_serveur('showbase', $serveur, $option==='continue' OR $option===false); |
| 605 | - if (!is_string($f) OR !$f) return false; |
|
| 691 | + if (!is_string($f) OR !$f) { |
|
| 692 | + return false; |
|
| 693 | + } |
|
| 606 | 694 | |
| 607 | 695 | // la globale n'est remplie qu'apres l'appel de sql_serveur. |
| 608 | 696 | if ($spip == NULL){ |
@@ -636,7 +724,10 @@ discard block |
||
| 636 | 724 | { |
| 637 | 725 | $q = sql_showbase($spip, $serveur, $option); |
| 638 | 726 | $r = array(); |
| 639 | - if ($q) while ($t = sql_fetch($q, $serveur)) { $r[] = array_shift($t);} |
|
| 727 | + if ($q) { |
|
| 728 | + while ($t = sql_fetch($q, $serveur)) { $r[] = array_shift($t); |
|
| 729 | + } |
|
| 730 | + } |
|
| 640 | 731 | return $r; |
| 641 | 732 | } |
| 642 | 733 | |
@@ -644,39 +735,54 @@ discard block |
||
| 644 | 735 | function sql_showtable($table, $table_spip = false, $serveur='', $option=true) |
| 645 | 736 | { |
| 646 | 737 | $f = sql_serveur('showtable', $serveur, $option==='continue' OR $option===false); |
| 647 | - if (!is_string($f) OR !$f) return false; |
|
| 738 | + if (!is_string($f) OR !$f) { |
|
| 739 | + return false; |
|
| 740 | + } |
|
| 648 | 741 | |
| 649 | 742 | // la globale n'est remplie qu'apres l'appel de sql_serveur. |
| 650 | 743 | if ($table_spip){ |
| 651 | 744 | $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 652 | 745 | $prefixe = $connexion['prefixe']; |
| 653 | 746 | $vraie_table = preg_replace('/^spip/', $prefixe, $table); |
| 654 | - } else $vraie_table = $table; |
|
| 747 | + } else { |
|
| 748 | + $vraie_table = $table; |
|
| 749 | + } |
|
| 655 | 750 | |
| 656 | 751 | $f = $f($vraie_table, $serveur, $option!==false); |
| 657 | - if (!$f) return array(); |
|
| 658 | - if (isset($GLOBALS['tables_principales'][$table]['join'])) |
|
| 659 | - $f['join'] = $GLOBALS['tables_principales'][$table]['join']; |
|
| 660 | - elseif (isset($GLOBALS['tables_auxiliaires'][$table]['join'])) |
|
| 661 | - $f['join'] = $GLOBALS['tables_auxiliaires'][$table]['join']; |
|
| 752 | + if (!$f) { |
|
| 753 | + return array(); |
|
| 754 | + } |
|
| 755 | + if (isset($GLOBALS['tables_principales'][$table]['join'])) { |
|
| 756 | + $f['join'] = $GLOBALS['tables_principales'][$table]['join']; |
|
| 757 | + } elseif (isset($GLOBALS['tables_auxiliaires'][$table]['join'])) { |
|
| 758 | + $f['join'] = $GLOBALS['tables_auxiliaires'][$table]['join']; |
|
| 759 | + } |
|
| 662 | 760 | return $f; |
| 663 | 761 | } |
| 664 | 762 | |
| 665 | 763 | // http://doc.spip.org/@sql_create |
| 666 | 764 | function sql_create($nom, $champs, $cles=array(), $autoinc=false, $temporary=false, $serveur='', $option=true) { |
| 667 | 765 | $f = sql_serveur('create', $serveur, $option==='continue' OR $option===false); |
| 668 | - if (!is_string($f) OR !$f) return false; |
|
| 766 | + if (!is_string($f) OR !$f) { |
|
| 767 | + return false; |
|
| 768 | + } |
|
| 669 | 769 | $r = $f($nom, $champs, $cles, $autoinc, $temporary, $serveur, $option!==false); |
| 670 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 770 | + if ($r === false) { |
|
| 771 | + spip_sql_erreur($serveur); |
|
| 772 | + } |
|
| 671 | 773 | return $r; |
| 672 | 774 | } |
| 673 | 775 | |
| 674 | 776 | function sql_create_base($nom, $serveur='', $option=true) |
| 675 | 777 | { |
| 676 | 778 | $f = sql_serveur('create_base', $serveur, $option==='continue' OR $option===false); |
| 677 | - if (!is_string($f) OR !$f) return false; |
|
| 779 | + if (!is_string($f) OR !$f) { |
|
| 780 | + return false; |
|
| 781 | + } |
|
| 678 | 782 | $r = $f($nom, $serveur, $option!==false); |
| 679 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 783 | + if ($r === false) { |
|
| 784 | + spip_sql_erreur($serveur); |
|
| 785 | + } |
|
| 680 | 786 | return $r; |
| 681 | 787 | } |
| 682 | 788 | |
@@ -687,9 +793,13 @@ discard block |
||
| 687 | 793 | // http://doc.spip.org/@sql_create_view |
| 688 | 794 | function sql_create_view($nom, $select_query, $serveur='', $option=true) { |
| 689 | 795 | $f = sql_serveur('create_view', $serveur, $option==='continue' OR $option===false); |
| 690 | - if (!is_string($f) OR !$f) return false; |
|
| 796 | + if (!is_string($f) OR !$f) { |
|
| 797 | + return false; |
|
| 798 | + } |
|
| 691 | 799 | $r = $f($nom, $select_query, $serveur, $option!==false); |
| 692 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 800 | + if ($r === false) { |
|
| 801 | + spip_sql_erreur($serveur); |
|
| 802 | + } |
|
| 693 | 803 | return $r; |
| 694 | 804 | } |
| 695 | 805 | |
@@ -697,7 +807,9 @@ discard block |
||
| 697 | 807 | function sql_multi($sel, $lang, $serveur='', $option=true) |
| 698 | 808 | { |
| 699 | 809 | $f = sql_serveur('multi', $serveur, $option==='continue' OR $option===false); |
| 700 | - if (!is_string($f) OR !$f) return false; |
|
| 810 | + if (!is_string($f) OR !$f) { |
|
| 811 | + return false; |
|
| 812 | + } |
|
| 701 | 813 | return $f($sel, $lang); |
| 702 | 814 | } |
| 703 | 815 | |
@@ -714,7 +826,9 @@ discard block |
||
| 714 | 826 | */ |
| 715 | 827 | function sql_error($serveur='') { |
| 716 | 828 | $f = sql_serveur('error', $serveur, 'continue'); |
| 717 | - if (!is_string($f) OR !$f) return false; |
|
| 829 | + if (!is_string($f) OR !$f) { |
|
| 830 | + return false; |
|
| 831 | + } |
|
| 718 | 832 | return $f('query inconnue', $serveur); |
| 719 | 833 | } |
| 720 | 834 | |
@@ -730,34 +844,48 @@ discard block |
||
| 730 | 844 | */ |
| 731 | 845 | function sql_errno($serveur='') { |
| 732 | 846 | $f = sql_serveur('errno', $serveur, 'continue'); |
| 733 | - if (!is_string($f) OR !$f) return false; |
|
| 847 | + if (!is_string($f) OR !$f) { |
|
| 848 | + return false; |
|
| 849 | + } |
|
| 734 | 850 | return $f($serveur); |
| 735 | 851 | } |
| 736 | 852 | |
| 737 | 853 | // http://doc.spip.org/@sql_explain |
| 738 | 854 | function sql_explain($q, $serveur='', $option=true) { |
| 739 | 855 | $f = sql_serveur('explain', $serveur, 'continue'); |
| 740 | - if (!is_string($f) OR !$f) return false; |
|
| 856 | + if (!is_string($f) OR !$f) { |
|
| 857 | + return false; |
|
| 858 | + } |
|
| 741 | 859 | $r = $f($q, $serveur, $option!==false); |
| 742 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 860 | + if ($r === false) { |
|
| 861 | + spip_sql_erreur($serveur); |
|
| 862 | + } |
|
| 743 | 863 | return $r; |
| 744 | 864 | } |
| 745 | 865 | |
| 746 | 866 | // http://doc.spip.org/@sql_optimize |
| 747 | 867 | function sql_optimize($table, $serveur='', $option=true) { |
| 748 | 868 | $f = sql_serveur('optimize', $serveur, $option==='continue' OR $option===false); |
| 749 | - if (!is_string($f) OR !$f) return false; |
|
| 869 | + if (!is_string($f) OR !$f) { |
|
| 870 | + return false; |
|
| 871 | + } |
|
| 750 | 872 | $r = $f($table, $serveur, $option!==false); |
| 751 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 873 | + if ($r === false) { |
|
| 874 | + spip_sql_erreur($serveur); |
|
| 875 | + } |
|
| 752 | 876 | return $r; |
| 753 | 877 | } |
| 754 | 878 | |
| 755 | 879 | // http://doc.spip.org/@sql_repair |
| 756 | 880 | function sql_repair($table, $serveur='', $option=true) { |
| 757 | 881 | $f = sql_serveur('repair', $serveur, $option==='continue' OR $option===false); |
| 758 | - if (!is_string($f) OR !$f) return false; |
|
| 882 | + if (!is_string($f) OR !$f) { |
|
| 883 | + return false; |
|
| 884 | + } |
|
| 759 | 885 | $r = $f($table, $serveur, $option!==false); |
| 760 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 886 | + if ($r === false) { |
|
| 887 | + spip_sql_erreur($serveur); |
|
| 888 | + } |
|
| 761 | 889 | return $r; |
| 762 | 890 | } |
| 763 | 891 | |
@@ -767,9 +895,13 @@ discard block |
||
| 767 | 895 | // http://doc.spip.org/@sql_query |
| 768 | 896 | function sql_query($ins, $serveur='', $option=true) { |
| 769 | 897 | $f = sql_serveur('query', $serveur, $option==='continue' OR $option===false); |
| 770 | - if (!is_string($f) OR !$f) return false; |
|
| 898 | + if (!is_string($f) OR !$f) { |
|
| 899 | + return false; |
|
| 900 | + } |
|
| 771 | 901 | $r = $f($ins, $serveur, $option!==false); |
| 772 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 902 | + if ($r === false) { |
|
| 903 | + spip_sql_erreur($serveur); |
|
| 904 | + } |
|
| 773 | 905 | return $r; |
| 774 | 906 | } |
| 775 | 907 | |
@@ -822,8 +954,12 @@ discard block |
||
| 822 | 954 | $groupby = array(), $orderby = array(), $limit = '', |
| 823 | 955 | $having = array(), $serveur='', $option=true) { |
| 824 | 956 | $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
| 825 | - if ($option===false) return $q; |
|
| 826 | - if (!$q) return array(); |
|
| 957 | + if ($option===false) { |
|
| 958 | + return $q; |
|
| 959 | + } |
|
| 960 | + if (!$q) { |
|
| 961 | + return array(); |
|
| 962 | + } |
|
| 827 | 963 | $r = sql_fetch($q, $serveur, $option); |
| 828 | 964 | sql_free($q, $serveur, $option); |
| 829 | 965 | return $r; |
@@ -886,7 +1022,9 @@ discard block |
||
| 886 | 1022 | $groupby = array(), $orderby = array(), $limit = '', |
| 887 | 1023 | $having = array(), $serveur='', $option=true) { |
| 888 | 1024 | $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
| 889 | - if ($option===false) return $q; |
|
| 1025 | + if ($option===false) { |
|
| 1026 | + return $q; |
|
| 1027 | + } |
|
| 890 | 1028 | return sql_fetch_all($q, $serveur, $option); |
| 891 | 1029 | } |
| 892 | 1030 | |
@@ -933,12 +1071,18 @@ discard block |
||
| 933 | 1071 | **/ |
| 934 | 1072 | function sql_getfetsel($select, $from = array(), $where = array(), $groupby = array(), |
| 935 | 1073 | $orderby = array(), $limit = '', $having = array(), $serveur='', $option=true) { |
| 936 | - if (preg_match('/\s+as\s+(\w+)$/i', $select, $c)) $id = $c[1]; |
|
| 937 | - elseif (!preg_match('/\W/', $select)) $id = $select; |
|
| 938 | - else {$id = 'n'; $select .= ' AS n';} |
|
| 1074 | + if (preg_match('/\s+as\s+(\w+)$/i', $select, $c)) { |
|
| 1075 | + $id = $c[1]; |
|
| 1076 | + } elseif (!preg_match('/\W/', $select)) { |
|
| 1077 | + $id = $select; |
|
| 1078 | + } else {$id = 'n'; $select .= ' AS n';} |
|
| 939 | 1079 | $r = sql_fetsel($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
| 940 | - if ($option===false) return $r; |
|
| 941 | - if (!$r) return NULL; |
|
| 1080 | + if ($option===false) { |
|
| 1081 | + return $r; |
|
| 1082 | + } |
|
| 1083 | + if (!$r) { |
|
| 1084 | + return NULL; |
|
| 1085 | + } |
|
| 942 | 1086 | return $r[$id]; |
| 943 | 1087 | } |
| 944 | 1088 | |
@@ -995,9 +1139,13 @@ discard block |
||
| 995 | 1139 | **/ |
| 996 | 1140 | function sql_preferer_transaction($serveur='', $option=true) { |
| 997 | 1141 | $f = sql_serveur('preferer_transaction', $serveur, 'continue'); |
| 998 | - if (!is_string($f) OR !$f) return false; |
|
| 1142 | + if (!is_string($f) OR !$f) { |
|
| 1143 | + return false; |
|
| 1144 | + } |
|
| 999 | 1145 | $r = $f($serveur, $option!==false); |
| 1000 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 1146 | + if ($r === false) { |
|
| 1147 | + spip_sql_erreur($serveur); |
|
| 1148 | + } |
|
| 1001 | 1149 | return $r; |
| 1002 | 1150 | }; |
| 1003 | 1151 | |
@@ -1021,9 +1169,13 @@ discard block |
||
| 1021 | 1169 | **/ |
| 1022 | 1170 | function sql_demarrer_transaction($serveur='', $option=true) { |
| 1023 | 1171 | $f = sql_serveur('demarrer_transaction', $serveur, 'continue'); |
| 1024 | - if (!is_string($f) OR !$f) return false; |
|
| 1172 | + if (!is_string($f) OR !$f) { |
|
| 1173 | + return false; |
|
| 1174 | + } |
|
| 1025 | 1175 | $r = $f($serveur, $option!==false); |
| 1026 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 1176 | + if ($r === false) { |
|
| 1177 | + spip_sql_erreur($serveur); |
|
| 1178 | + } |
|
| 1027 | 1179 | return $r; |
| 1028 | 1180 | }; |
| 1029 | 1181 | |
@@ -1047,9 +1199,13 @@ discard block |
||
| 1047 | 1199 | **/ |
| 1048 | 1200 | function sql_terminer_transaction($serveur='', $option=true) { |
| 1049 | 1201 | $f = sql_serveur('terminer_transaction', $serveur, 'continue'); |
| 1050 | - if (!is_string($f) OR !$f) return false; |
|
| 1202 | + if (!is_string($f) OR !$f) { |
|
| 1203 | + return false; |
|
| 1204 | + } |
|
| 1051 | 1205 | $r = $f($serveur, $option!==false); |
| 1052 | - if ($r === false) spip_sql_erreur($serveur); |
|
| 1206 | + if ($r === false) { |
|
| 1207 | + spip_sql_erreur($serveur); |
|
| 1208 | + } |
|
| 1053 | 1209 | return $r; |
| 1054 | 1210 | }; |
| 1055 | 1211 | |
@@ -1076,7 +1232,9 @@ discard block |
||
| 1076 | 1232 | function sql_hex($val, $serveur='', $option=true) |
| 1077 | 1233 | { |
| 1078 | 1234 | $f = sql_serveur('hex', $serveur, $option==='continue' OR $option===false); |
| 1079 | - if (!is_string($f) OR !$f) return false; |
|
| 1235 | + if (!is_string($f) OR !$f) { |
|
| 1236 | + return false; |
|
| 1237 | + } |
|
| 1080 | 1238 | return $f($val); |
| 1081 | 1239 | } |
| 1082 | 1240 | |
@@ -1103,14 +1261,18 @@ discard block |
||
| 1103 | 1261 | function sql_quote($val, $serveur='', $type='') |
| 1104 | 1262 | { |
| 1105 | 1263 | $f = sql_serveur('quote', $serveur, true); |
| 1106 | - if (!is_string($f) OR !$f) $f = '_q'; |
|
| 1264 | + if (!is_string($f) OR !$f) { |
|
| 1265 | + $f = '_q'; |
|
| 1266 | + } |
|
| 1107 | 1267 | return $f($val, $type); |
| 1108 | 1268 | } |
| 1109 | 1269 | |
| 1110 | 1270 | function sql_date_proche($champ, $interval, $unite, $serveur='', $option=true) |
| 1111 | 1271 | { |
| 1112 | 1272 | $f = sql_serveur('date_proche', $serveur, true); |
| 1113 | - if (!is_string($f) OR !$f) return false; |
|
| 1273 | + if (!is_string($f) OR !$f) { |
|
| 1274 | + return false; |
|
| 1275 | + } |
|
| 1114 | 1276 | return $f($champ, $interval, $unite); |
| 1115 | 1277 | } |
| 1116 | 1278 | |
@@ -1145,13 +1307,21 @@ discard block |
||
| 1145 | 1307 | function sql_in($val, $valeurs, $not='', $serveur='', $option=true) { |
| 1146 | 1308 | if (is_array($valeurs)) { |
| 1147 | 1309 | $f = sql_serveur('quote', $serveur, true); |
| 1148 | - if (!is_string($f) OR !$f) return false; |
|
| 1310 | + if (!is_string($f) OR !$f) { |
|
| 1311 | + return false; |
|
| 1312 | + } |
|
| 1149 | 1313 | $valeurs = join(',', array_map($f, array_unique($valeurs))); |
| 1150 | - } elseif (isset($valeurs[0]) AND $valeurs[0]===',') $valeurs = substr($valeurs,1); |
|
| 1151 | - if (!strlen(trim($valeurs))) return ($not ? "0=0" : '0=1'); |
|
| 1314 | + } elseif (isset($valeurs[0]) AND $valeurs[0]===',') { |
|
| 1315 | + $valeurs = substr($valeurs,1); |
|
| 1316 | + } |
|
| 1317 | + if (!strlen(trim($valeurs))) { |
|
| 1318 | + return ($not ? "0=0" : '0=1'); |
|
| 1319 | + } |
|
| 1152 | 1320 | |
| 1153 | 1321 | $f = sql_serveur('in', $serveur, $option==='continue' OR $option===false); |
| 1154 | - if (!is_string($f) OR !$f) return false; |
|
| 1322 | + if (!is_string($f) OR !$f) { |
|
| 1323 | + return false; |
|
| 1324 | + } |
|
| 1155 | 1325 | return $f($val, $valeurs, $not, $serveur, $option!==false); |
| 1156 | 1326 | } |
| 1157 | 1327 | |
@@ -1198,18 +1368,21 @@ discard block |
||
| 1198 | 1368 | */ |
| 1199 | 1369 | function sql_skip($res, $pos, $saut, $count, $serveur='', $option=true){ |
| 1200 | 1370 | // pas de saut en arriere qu'on ne sait pas faire sans sql_seek |
| 1201 | - if (($saut=intval($saut))<=0) return $pos; |
|
| 1371 | + if (($saut=intval($saut))<=0) { |
|
| 1372 | + return $pos; |
|
| 1373 | + } |
|
| 1202 | 1374 | |
| 1203 | 1375 | $seek = $pos + $saut; |
| 1204 | 1376 | // si le saut fait depasser le maxi, on libere la resource |
| 1205 | 1377 | // et on sort |
| 1206 | 1378 | if ($seek>=$count) {sql_free($res, $serveur, $option); return $count;} |
| 1207 | 1379 | |
| 1208 | - if (sql_seek($res, $seek)) |
|
| 1209 | - $pos = $seek; |
|
| 1210 | - else |
|
| 1211 | - while ($pos<$seek AND sql_fetch($res, $serveur, $option)) |
|
| 1380 | + if (sql_seek($res, $seek)) { |
|
| 1381 | + $pos = $seek; |
|
| 1382 | + } else { |
|
| 1383 | + while ($pos<$seek AND sql_fetch($res, $serveur, $option)) |
|
| 1212 | 1384 | $pos++; |
| 1385 | + } |
|
| 1213 | 1386 | return $pos; |
| 1214 | 1387 | } |
| 1215 | 1388 | |
@@ -1248,8 +1421,12 @@ discard block |
||
| 1248 | 1421 | $annee = sprintf("%04s",$annee); |
| 1249 | 1422 | $mois = sprintf("%02s",$mois); |
| 1250 | 1423 | |
| 1251 | - if ($annee == "0000") $mois = 0; |
|
| 1252 | - if ($mois == "00") $jour = 0; |
|
| 1424 | + if ($annee == "0000") { |
|
| 1425 | + $mois = 0; |
|
| 1426 | + } |
|
| 1427 | + if ($mois == "00") { |
|
| 1428 | + $jour = 0; |
|
| 1429 | + } |
|
| 1253 | 1430 | |
| 1254 | 1431 | return sprintf("%04u",$annee) . '-' . sprintf("%02u",$mois) . '-' |
| 1255 | 1432 | . sprintf("%02u",$jour) . ' ' . sprintf("%02u",$h) . ':' |
@@ -1285,18 +1462,23 @@ discard block |
||
| 1285 | 1462 | car sinon on va se comporter differement selon que la table est declaree |
| 1286 | 1463 | ou non |
| 1287 | 1464 | */ |
| 1288 | - if (!$trouver_table) $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1289 | - if ($desc = $trouver_table($nom, $serveur)) |
|
| 1290 | - return $desc; |
|
| 1465 | + if (!$trouver_table) { |
|
| 1466 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1467 | + } |
|
| 1468 | + if ($desc = $trouver_table($nom, $serveur)) { |
|
| 1469 | + return $desc; |
|
| 1470 | + } |
|
| 1291 | 1471 | |
| 1292 | 1472 | // sauf a l'installation : |
| 1293 | 1473 | include_spip('base/serial'); |
| 1294 | - if (isset($tables_principales[$nom])) |
|
| 1295 | - return $tables_principales[$nom]; |
|
| 1474 | + if (isset($tables_principales[$nom])) { |
|
| 1475 | + return $tables_principales[$nom]; |
|
| 1476 | + } |
|
| 1296 | 1477 | |
| 1297 | 1478 | include_spip('base/auxiliaires'); |
| 1298 | - if (isset($tables_auxiliaires[$nom])) |
|
| 1299 | - return $tables_auxiliaires[$nom]; |
|
| 1479 | + if (isset($tables_auxiliaires[$nom])) { |
|
| 1480 | + return $tables_auxiliaires[$nom]; |
|
| 1481 | + } |
|
| 1300 | 1482 | |
| 1301 | 1483 | return false; |
| 1302 | 1484 | } |