Subversion-Projekte lars-tiefland.ci

Revision

Revision 68 | Revision 2049 | Zur aktuellen Revision | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 68 Revision 1257
Zeile 104... Zeile 104...
104
	 * @var	int
104
	 * @var	int
105
	 */
105
	 */
106
	public $compression_level = 2;
106
	public $compression_level = 2;
Zeile 107... Zeile 107...
107
 
107
 
-
 
108
	/**
-
 
109
	 * mbstring.func_override flag
-
 
110
	 *
-
 
111
	 * @var	bool
-
 
112
	 */
-
 
113
	protected static $func_override;
-
 
114
 
108
	/**
115
	/**
109
	 * Initialize zip compression class
116
	 * Initialize zip compression class
110
	 *
117
	 *
111
	 * @return	void
118
	 * @return	void
112
	 */
119
	 */
113
	public function __construct()
120
	public function __construct()
-
 
121
	{
-
 
122
		isset(self::$func_override) OR self::$func_override = (extension_loaded('mbstring') && ini_get('mbstring.func_override'));
114
	{
123
 
115
		$this->now = time();
124
		$this->now = time();
116
		log_message('info', 'Zip Compression Class Initialized');
125
		log_message('info', 'Zip Compression Class Initialized');
Zeile 117... Zeile 126...
117
	}
126
	}
Zeile 180... Zeile 189...
180
			.pack('v', $file_mtime)
189
			.pack('v', $file_mtime)
181
			.pack('v', $file_mdate)
190
			.pack('v', $file_mdate)
182
			.pack('V', 0) // crc32
191
			.pack('V', 0) // crc32
183
			.pack('V', 0) // compressed filesize
192
			.pack('V', 0) // compressed filesize
184
			.pack('V', 0) // uncompressed filesize
193
			.pack('V', 0) // uncompressed filesize
185
			.pack('v', strlen($dir)) // length of pathname
194
			.pack('v', self::strlen($dir)) // length of pathname
186
			.pack('v', 0) // extra field length
195
			.pack('v', 0) // extra field length
187
			.$dir
196
			.$dir
188
			// below is "data descriptor" segment
197
			// below is "data descriptor" segment
189
			.pack('V', 0) // crc32
198
			.pack('V', 0) // crc32
190
			.pack('V', 0) // compressed filesize
199
			.pack('V', 0) // compressed filesize
Zeile 195... Zeile 204...
195
			.pack('v', $file_mtime)
204
			.pack('v', $file_mtime)
196
			.pack('v', $file_mdate)
205
			.pack('v', $file_mdate)
197
			.pack('V',0) // crc32
206
			.pack('V',0) // crc32
198
			.pack('V',0) // compressed filesize
207
			.pack('V',0) // compressed filesize
199
			.pack('V',0) // uncompressed filesize
208
			.pack('V',0) // uncompressed filesize
200
			.pack('v', strlen($dir)) // length of pathname
209
			.pack('v', self::strlen($dir)) // length of pathname
201
			.pack('v', 0) // extra field length
210
			.pack('v', 0) // extra field length
202
			.pack('v', 0) // file comment length
211
			.pack('v', 0) // file comment length
203
			.pack('v', 0) // disk number start
212
			.pack('v', 0) // disk number start
204
			.pack('v', 0) // internal file attributes
213
			.pack('v', 0) // internal file attributes
205
			.pack('V', 16) // external file attributes - 'directory' bit set
214
			.pack('V', 16) // external file attributes - 'directory' bit set
206
			.pack('V', $this->offset) // relative offset of local header
215
			.pack('V', $this->offset) // relative offset of local header
207
			.$dir;
216
			.$dir;
Zeile 208... Zeile 217...
208
 
217
 
209
		$this->offset = strlen($this->zipdata);
218
		$this->offset = self::strlen($this->zipdata);
210
		$this->entries++;
219
		$this->entries++;
Zeile 211... Zeile 220...
211
	}
220
	}
Zeile 253... Zeile 262...
253
	 */
262
	 */
254
	protected function _add_data($filepath, $data, $file_mtime, $file_mdate)
263
	protected function _add_data($filepath, $data, $file_mtime, $file_mdate)
255
	{
264
	{
256
		$filepath = str_replace('\\', '/', $filepath);
265
		$filepath = str_replace('\\', '/', $filepath);
Zeile 257... Zeile 266...
257
 
266
 
258
		$uncompressed_size = strlen($data);
267
		$uncompressed_size = self::strlen($data);
259
		$crc32  = crc32($data);
268
		$crc32  = crc32($data);
260
		$gzdata = substr(gzcompress($data, $this->compression_level), 2, -4);
269
		$gzdata = self::substr(gzcompress($data, $this->compression_level), 2, -4);
Zeile 261... Zeile 270...
261
		$compressed_size = strlen($gzdata);
270
		$compressed_size = self::strlen($gzdata);
262
 
271
 
263
		$this->zipdata .=
272
		$this->zipdata .=
264
			"\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00"
273
			"\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00"
265
			.pack('v', $file_mtime)
274
			.pack('v', $file_mtime)
266
			.pack('v', $file_mdate)
275
			.pack('v', $file_mdate)
267
			.pack('V', $crc32)
276
			.pack('V', $crc32)
268
			.pack('V', $compressed_size)
277
			.pack('V', $compressed_size)
269
			.pack('V', $uncompressed_size)
278
			.pack('V', $uncompressed_size)
270
			.pack('v', strlen($filepath)) // length of filename
279
			.pack('v', self::strlen($filepath)) // length of filename
271
			.pack('v', 0) // extra field length
280
			.pack('v', 0) // extra field length
Zeile 272... Zeile 281...
272
			.$filepath
281
			.$filepath
Zeile 277... Zeile 286...
277
			.pack('v', $file_mtime)
286
			.pack('v', $file_mtime)
278
			.pack('v', $file_mdate)
287
			.pack('v', $file_mdate)
279
			.pack('V', $crc32)
288
			.pack('V', $crc32)
280
			.pack('V', $compressed_size)
289
			.pack('V', $compressed_size)
281
			.pack('V', $uncompressed_size)
290
			.pack('V', $uncompressed_size)
282
			.pack('v', strlen($filepath)) // length of filename
291
			.pack('v', self::strlen($filepath)) // length of filename
283
			.pack('v', 0) // extra field length
292
			.pack('v', 0) // extra field length
284
			.pack('v', 0) // file comment length
293
			.pack('v', 0) // file comment length
285
			.pack('v', 0) // disk number start
294
			.pack('v', 0) // disk number start
286
			.pack('v', 0) // internal file attributes
295
			.pack('v', 0) // internal file attributes
287
			.pack('V', 32) // external file attributes - 'archive' bit set
296
			.pack('V', 32) // external file attributes - 'archive' bit set
288
			.pack('V', $this->offset) // relative offset of local header
297
			.pack('V', $this->offset) // relative offset of local header
289
			.$filepath;
298
			.$filepath;
Zeile 290... Zeile 299...
290
 
299
 
291
		$this->offset = strlen($this->zipdata);
300
		$this->offset = self::strlen($this->zipdata);
292
		$this->entries++;
301
		$this->entries++;
293
		$this->file_num++;
302
		$this->file_num++;
Zeile 294... Zeile 303...
294
	}
303
	}
Zeile 399... Zeile 408...
399
 
408
 
400
		return $this->zipdata
409
		return $this->zipdata
401
			.$this->directory."\x50\x4b\x05\x06\x00\x00\x00\x00"
410
			.$this->directory."\x50\x4b\x05\x06\x00\x00\x00\x00"
402
			.pack('v', $this->entries) // total # of entries "on this disk"
411
			.pack('v', $this->entries) // total # of entries "on this disk"
403
			.pack('v', $this->entries) // total # of entries overall
412
			.pack('v', $this->entries) // total # of entries overall
404
			.pack('V', strlen($this->directory)) // size of central dir
413
			.pack('V', self::strlen($this->directory)) // size of central dir
405
			.pack('V', strlen($this->zipdata)) // offset to start of central dir
414
			.pack('V', self::strlen($this->zipdata)) // offset to start of central dir
406
			."\x00\x00"; // .zip file comment length
415
			."\x00\x00"; // .zip file comment length
Zeile 407... Zeile 416...
407
	}
416
	}
Zeile 423... Zeile 432...
423
			return FALSE;
432
			return FALSE;
424
		}
433
		}
Zeile 425... Zeile 434...
425
 
434
 
Zeile 426... Zeile 435...
426
		flock($fp, LOCK_EX);
435
		flock($fp, LOCK_EX);
427
 
436
 
428
		for ($result = $written = 0, $data = $this->get_zip(), $length = strlen($data); $written < $length; $written += $result)
437
		for ($result = $written = 0, $data = $this->get_zip(), $length = self::strlen($data); $written < $length; $written += $result)
429
		{
438
		{
430
			if (($result = fwrite($fp, substr($data, $written))) === FALSE)
439
			if (($result = fwrite($fp, self::substr($data, $written))) === FALSE)
431
			{
440
			{
432
				break;
441
				break;
Zeile 479... Zeile 488...
479
		$this->file_num = 0;
488
		$this->file_num = 0;
480
		$this->offset = 0;
489
		$this->offset = 0;
481
		return $this;
490
		return $this;
482
	}
491
	}
Zeile -... Zeile 492...
-
 
492
 
-
 
493
	// --------------------------------------------------------------------
-
 
494
 
-
 
495
	/**
-
 
496
	 * Byte-safe strlen()
-
 
497
	 *
-
 
498
	 * @param	string	$str
-
 
499
	 * @return	int
-
 
500
	 */
-
 
501
	protected static function strlen($str)
-
 
502
	{
-
 
503
		return (self::$func_override)
-
 
504
			? mb_strlen($str, '8bit')
-
 
505
			: strlen($str);
-
 
506
	}
-
 
507
 
-
 
508
	// --------------------------------------------------------------------
-
 
509
 
-
 
510
	/**
-
 
511
	 * Byte-safe substr()
-
 
512
	 *
-
 
513
	 * @param	string	$str
-
 
514
	 * @param	int	$start
-
 
515
	 * @param	int	$length
-
 
516
	 * @return	string
-
 
517
	 */
-
 
518
	protected static function substr($str, $start, $length = NULL)
-
 
519
	{
-
 
520
		if (self::$func_override)
-
 
521
		{
-
 
522
			// mb_substr($str, $start, null, '8bit') returns an empty
-
 
523
			// string on PHP 5.3
-
 
524
			isset($length) OR $length = ($start >= 0 ? self::strlen($str) - $start : -$start);
-
 
525
			return mb_substr($str, $start, $length, '8bit');
-
 
526
		}
-
 
527
 
-
 
528
		return isset($length)
-
 
529
			? substr($str, $start, $length)
-
 
530
			: substr($str, $start);
483
 
531
	}