Rev 130 Rev 139
1 <?php 1 <?php
2 // +----------------------------------------------------------------------+ 2 // +----------------------------------------------------------------------+
3 // | PHP Version 4 | 3 // | PHP Version 4 |
4 // +----------------------------------------------------------------------+ 4 // +----------------------------------------------------------------------+
5 // | Copyright (c) 1997-2004 The PHP Group | 5 // | Copyright (c) 1997-2004 The PHP Group |
6 // +----------------------------------------------------------------------+ 6 // +----------------------------------------------------------------------+
7 // | This source file is subject to version 3.0 of the PHP license, | 7 // | This source file is subject to version 3.0 of the PHP license, |
8 // | that is bundled with this package in the file LICENSE, and is | 8 // | that is bundled with this package in the file LICENSE, and is |
9 // | available at through the world-wide-web at | 9 // | available at through the world-wide-web at |
10 // | http://www.php.net/license/3_0.txt. | 10 // | http://www.php.net/license/3_0.txt. |
11 // | If you did not receive a copy of the PHP license and are unable to | 11 // | If you did not receive a copy of the PHP license and are unable to |
12 // | obtain it through the world-wide-web, please send a note to | 12 // | obtain it through the world-wide-web, please send a note to |
13 // | license@php.net so we can mail you a copy immediately. | 13 // | license@php.net so we can mail you a copy immediately. |
14 // +----------------------------------------------------------------------+ 14 // +----------------------------------------------------------------------+
15 // | Authors: Michael Wallner <mike@php.net> | 15 // | Authors: Michael Wallner <mike@php.net> |
16 // | Aidan Lister <aidan@php.net> | 16 // | Aidan Lister <aidan@php.net> |
17 // +----------------------------------------------------------------------+ 17 // +----------------------------------------------------------------------+
18 // 18 //
19 // $Id: convert_uudecode.php,v 1.8 2005/01/26 04:55:13 aidan Exp $ 19 // $Id: convert_uudecode.php,v 1.8 2005/01/26 04:55:13 aidan Exp $
20   20  
21   21  
22 /** 22 /**
23 * Replace convert_uudecode() 23 * Replace convert_uudecode()
24 * 24 *
25 * @category PHP 25 * @category PHP
26 * @package PHP_Compat 26 * @package PHP_Compat
27 * @link http://php.net/function.convert_uudecode 27 * @link http://php.net/function.convert_uudecode
28 * @author Michael Wallner <mike@php.net> 28 * @author Michael Wallner <mike@php.net>
29 * @author Aidan Lister <aidan@php.net> 29 * @author Aidan Lister <aidan@php.net>
30 * @version $Revision: 1.8 $ 30 * @version $Revision: 1.8 $
31 * @since PHP 5 31 * @since PHP 5
32 * @require PHP 4.0.0 (user_error) 32 * @require PHP 4.0.0 (user_error)
33 */ 33 */
34 if (!function_exists('convert_uudecode')) { 34 if (!function_exists('convert_uudecode')) {
35 function convert_uudecode($string) 35 function convert_uudecode($string)
36 { 36 {
37 // Sanity check 37 // Sanity check
38 if (!is_scalar($string)) { 38 if (!is_scalar($string)) {
39 user_error('convert_uuencode() expects parameter 1 to be string, ' . 39 user_error('convert_uuencode() expects parameter 1 to be string, ' .
40 gettype($string) . ' given', E_USER_WARNING); 40 gettype($string) . ' given', E_USER_WARNING);
41 return false; 41 return false;
42 } 42 }
43   43  
44 if (strlen($string) < 8) { 44 if (strlen($string) < 8) {
45 user_error('convert_uuencode() The given parameter is not a valid uuencoded string', E_USER_WARNING); 45 user_error('convert_uuencode() The given parameter is not a valid uuencoded string', E_USER_WARNING);
46 return false; 46 return false;
47 } 47 }
48   48  
49 $decoded = ''; 49 $decoded = '';
50 foreach (explode("\n", $string) as $line) { 50 foreach (explode("\n", $string) as $line) {
51   51  
52 $c = count($bytes = unpack('c*', substr(trim($line), 1))); 52 $c = count($bytes = unpack('c*', substr(trim($line), 1)));
53   53  
54 while ($c % 4) { 54 while ($c % 4) {
55 $bytes[++$c] = 0; 55 $bytes[++$c] = 0;
56 } 56 }
57   57  
58 foreach (array_chunk($bytes, 4) as $b) { 58 foreach (array_chunk($bytes, 4) as $b) {
59 $b0 = $b[0] == 0x60 ? 0 : $b[0] - 0x20; 59 $b0 = $b[0] == 0x60 ? 0 : $b[0] - 0x20;
60 $b1 = $b[1] == 0x60 ? 0 : $b[1] - 0x20; 60 $b1 = $b[1] == 0x60 ? 0 : $b[1] - 0x20;
61 $b2 = $b[2] == 0x60 ? 0 : $b[2] - 0x20; 61 $b2 = $b[2] == 0x60 ? 0 : $b[2] - 0x20;
62 $b3 = $b[3] == 0x60 ? 0 : $b[3] - 0x20; 62 $b3 = $b[3] == 0x60 ? 0 : $b[3] - 0x20;
63 63
64 $b0 <<= 2; 64 $b0 <<= 2;
65 $b0 |= ($b1 >> 4) & 0x03; 65 $b0 |= ($b1 >> 4) & 0x03;
66 $b1 <<= 4; 66 $b1 <<= 4;
67 $b1 |= ($b2 >> 2) & 0x0F; 67 $b1 |= ($b2 >> 2) & 0x0F;
68 $b2 <<= 6; 68 $b2 <<= 6;
69 $b2 |= $b3 & 0x3F; 69 $b2 |= $b3 & 0x3F;
70 70
71 $decoded .= pack('c*', $b0, $b1, $b2); 71 $decoded .= pack('c*', $b0, $b1, $b2);
72 } 72 }
73 } 73 }
74   74  
75 return rtrim($decoded, "\0"); 75 return rtrim($decoded, "\0");
76 } 76 }
77 } 77 }
78   78  
79 ?> 79 ?>
80 80