コード例 #1
0
 public function Query()
 {
     $Length = StrLen($this->ServerIP);
     $Data = Pack('cccca*', HexDec($Length), 0, 0x4, $Length, $this->ServerIP) . Pack('nc', $this->ServerPort, 0x1);
     Socket_Send($this->Socket, $Data, StrLen($Data), 0);
     // handshake
     Socket_Send($this->Socket, "", 2, 0);
     // status ping
     $Length = $this->ReadVarInt();
     // full packet length
     if ($Length < 10) {
         return FALSE;
     }
     Socket_Read($this->Socket, 1);
     // packet type, in server ping it's 0
     $Length = $this->ReadVarInt();
     // string length
     $Data = Socket_Read($this->Socket, $Length, PHP_NORMAL_READ);
     // and finally the json string
     if ($Data === FALSE) {
         throw new MinecraftPingException('Server didn\'t return any data');
     }
     $Data = JSON_Decode($Data, true);
     if (JSON_Last_Error() !== JSON_ERROR_NONE) {
         if (Function_Exists('json_last_error_msg')) {
             throw new MinecraftPingException(JSON_Last_Error_Msg());
         } else {
             throw new MinecraftPingException('JSON parsing failed');
         }
         return FALSE;
     }
     return $Data;
 }
コード例 #2
0
ファイル: Bytes.php プロジェクト: carriercomm/jbs
function Bytes_Trim($String)
{
    /****************************************************************************/
    $__args_types = array('string');
    #-----------------------------------------------------------------------------
    $__args__ = Func_Get_Args();
    eval(FUNCTION_INIT);
    /****************************************************************************/
    return DecHex(HexDec($String));
}
コード例 #3
0
ファイル: Captcha.class.php プロジェクト: joly/web2project
 function Captcha($text, $font, $color)
 {
     $C = HexDec($color);
     $R = floor($C / pow(256, 2));
     $G = floor($C % pow(256, 2) / pow(256, 1));
     $B = floor($C % pow(256, 2) % pow(256, 1) / pow(256, 0));
     $fsize = 32;
     $bound = array();
     $bound = imageTTFBbox($fsize, 0, $font, $text);
     $this->image = imageCreateTrueColor($bound[4] + 5, abs($bound[5]) + 15);
     imageFill($this->image, 0, 0, ImageColorAllocate($this->image, 255, 255, 255));
     imagettftext($this->image, $fsize, 0, 2, abs($bound[5]) + 5, ImageColorAllocate($this->image, $R, $G, $B), $font, $text);
 }
コード例 #4
0
ファイル: SNAC.php プロジェクト: carriercomm/jbs
function SNAC_Create($FamilyID, $SubTypeID, $Data = '')
{
    /****************************************************************************/
    $__args_types = array('integer', 'integer', 'string');
    #-----------------------------------------------------------------------------
    $__args__ = Func_Get_Args();
    eval(FUNCTION_INIT);
    /****************************************************************************/
    $Result = Bytes_I2B(WORD, HexDec($FamilyID)) . Bytes_I2B(WORD, HexDec($SubTypeID)) . Bytes_I2B(BUTE, 0) . Bytes_I2B(BUTE, 0) . Bytes_I2B(DWORD, Rand(1, 65025));
    # Номер запроса
    #-----------------------------------------------------------------------------
    $Result .= $Data;
    # Сам пакет
    #-----------------------------------------------------------------------------
    return $Result;
}
コード例 #5
0
ファイル: form_layout_paged.php プロジェクト: wycus/darmedic
 function ColorChangeIntensity($color, $intensity_offset)
 {
     if (eregi('^#([[:xdigit:]]{2})([[:xdigit:]]{2})([[:xdigit:]]{2})$', $color, $components) != 7) {
         return $color;
     }
     if (($red = intval(HexDec($components[1]) * (100 + $intensity_offset) / 100)) > 255) {
         $red = 255;
     }
     if (($green = intval(HexDec($components[2]) * (100 + $intensity_offset) / 100)) > 255) {
         $green = 255;
     }
     if (($blue = intval(HexDec($components[3]) * (100 + $intensity_offset) / 100)) > 255) {
         $blue = 255;
     }
     return sprintf('#%02X%02X%02X', $red, $green, $blue);
 }
コード例 #6
0
ファイル: cal_sem.php プロジェクト: akwawa/RipMeal-v2
function couleur_inverse($c_orig)
{
    $a = substr($c_orig, 0, 1);
    $b = substr($c_orig, 1, 1);
    $c = substr($c_orig, 2, 1);
    $d = substr($c_orig, 3, 1);
    $e = substr($c_orig, 4, 1);
    $f = substr($c_orig, 5, 1);
    $ai = DecHex(15 - HexDec($a));
    $bi = DecHex(15 - HexDec($b));
    $ci = DecHex(15 - HexDec($c));
    $di = DecHex(15 - HexDec($d));
    $ei = DecHex(15 - HexDec($e));
    $fi = DecHex(15 - HexDec($f));
    $c_inv = $ai . $bi . $ci . $di . $ei . $fi;
    return $c_inv;
}
コード例 #7
0
ファイル: mediafire_com.php プロジェクト: proma66/filegir
function mf_str_conv($str_or)
{
    $str_or = stripslashes($str_or);
    if (!preg_match("/unescape\\(\\W([0-9a-f]+)\\W\\);\\w+=([0-9]+);[^\\^]+\\)([0-9\\^]+)?\\)\\);eval/", $str_or, $match)) {
        return $str_or;
    }
    $match[3] = $match[3] ? $match[3] : "";
    for ($i = 0; $i < $match[2]; $i++) {
        $c = HexDec(substr($match[1], $i * 2, 2));
        eval("\$c = \$c" . $match[3] . ";");
        $str_re .= chr($c);
    }
    $str_re = str_replace($match[0], stripslashes($str_re), $str_or);
    if (preg_match("/unescape\\(\\W([0-9a-f]+)\\W\\);\\w+=([0-9]+);[^\\^]+\\)([0-9\\^]+)?\\)\\);eval/", $str_re, $dummy)) {
        $str_re = mf_str_conv($str_re);
    }
    return $str_re;
}
コード例 #8
0
ファイル: TVL.php プロジェクト: carriercomm/jbs
function TVL_Explode($String, &$Array = array())
{
    /****************************************************************************/
    $__args_types = array('string', 'array');
    #-----------------------------------------------------------------------------
    $__args__ = Func_Get_Args();
    eval(FUNCTION_INIT);
    /****************************************************************************/
    $Length = HexDec(Bytes_Get($String, 02, WORD));
    #-----------------------------------------------------------------------------
    $Array[Bytes_Get($String, 00, WORD)] = SubStr($String, 04, $Length);
    #-----------------------------------------------------------------------------
    if (StrLen($String = SubStr($String, 04 + $Length)) > 0) {
        TVL_Explode($String, $Array);
    }
    #-----------------------------------------------------------------------------
    return $Array;
}
コード例 #9
0
ファイル: NtpClient.php プロジェクト: rafni/NtpClient
 /**
  * Make a new query to the NTP server
  * @param string $timeserver
  * @param integer $port
  * @param integer $timeout
  * @return object
  */
 public static function query($timeserver, $port, $timeout = 2)
 {
     $err = null;
     $errstr = null;
     $fp = @fsockopen($timeserver, $port, $err, $errstr, $timeout);
     if ($fp) {
         fputs($fp, "\n");
         $timeread = fread($fp, 49);
         $timevalue = bin2hex($timeread);
         $timevalue = abs(HexDec('7fffffff') - HexDec($timevalue) - HexDec('7fffffff'));
         $timestamp = $timevalue - 2208988800.0;
         # convert to UNIX epoch timestamp
         fclose($fp);
         $result = (object) array('timezone' => date_default_timezone_get(), 'timestamp' => $timestamp, 'datetime' => date('Y-m-d H:i:s', $timestamp));
     } else {
         $result = null;
     }
     return (object) array('result' => $result, 'error-code' => $err, 'error-text' => $errstr);
 }
コード例 #10
0
ファイル: setupItemdesc.php プロジェクト: polserver/poltools
function BuildItemDesc($file)
{
    print " * Loading multis config file...\n";
    $cfg_file = ReadConfigFile($file);
    if ($cfg_file == FALSE) {
        print "Cant open {$file} ({$php_errormsg}). Blame Stephen Donald.\n";
        exit;
    }
    print " * Purging itemdesc.cfg for new write...\n";
    $handle = FOpen("itemdesc.cfg", "w");
    FClose($handle);
    $handle = FOpen("itemdesc.cfg", "a");
    print " * Finding elem names...";
    $elem_names = GetConfigStringKeys($cfg_file, CLASS_LABELS_ON);
    print "(" . Count($elem_names) . ")\n";
    foreach ($elem_names as $elem_name) {
        if (!Preg_Match("/^House\\s+/i", $elem_name)) {
            continue;
        }
        $multi_id = Preg_Replace("/^House\\s+/i", "", $elem_name);
        $objtype = HexDec($multi_id);
        $objtype += 16384;
        // 0x4000
        $objtype = "0x" . DecHex($objtype);
        FWrite($handle, "House {$objtype}\n");
        FWrite($handle, "{\n");
        FWrite($handle, "\t// Main Stuff\n");
        FWrite($handle, "\tName\t\tHouse{$objtype}\n");
        FWrite($handle, "\tGraphic\t\t{$objtype}\n");
        FWrite($handle, "\n");
        FWrite($handle, "\t// Multi Info\n");
        FWrite($handle, "\tMultiID\t\t{$multi_id}\n");
        FWrite($handle, "}\n\n");
    }
    FClose($handle);
    return 1;
}
コード例 #11
0
ファイル: Palette.comp.php プロジェクト: carriercomm/jbs
#-------------------------------------------------------------------------------
$Table = new Tag('TABLE', array('class' => 'Standard', 'cellspacing' => 0, 'cellpadding' => 0));
#-------------------------------------------------------------------------------
$Gradetion = $Palette['Gradetion'];
#-------------------------------------------------------------------------------
foreach ($Palette['Colors'] as $Color) {
    #-----------------------------------------------------------------------------
    $Tr = new Tag('TR');
    #-----------------------------------------------------------------------------
    for ($i = 1; $i < ($Count = $Gradetion['Count']) * 2; $i++) {
        #---------------------------------------------------------------------------
        $IsLeft = $i >= $Count;
        #---------------------------------------------------------------------------
        $Shift = ($IsLeft ? $i - $Count : $Count - $i) * $Gradetion['Step'];
        #---------------------------------------------------------------------------
        $Shifted = Color_Shift(HexDec($Color), $IsLeft ? 0xffffff : 0x0, $Shift);
        #---------------------------------------------------------------------------
        $Colors[] = $Shifted;
        #---------------------------------------------------------------------------
        $Td = new Tag('TD', array('align' => 'center', 'bgcolor' => $Shifted, 'height' => 50, 'width' => 50), $Shifted);
        #---------------------------------------------------------------------------
        if ($i == $Count) {
            $Td->AddAttribs(array('style' => 'border:1px solid #DCDCDC;'));
        }
        #---------------------------------------------------------------------------
        $Tr->AddChild($Td);
    }
    #-----------------------------------------------------------------------------
    $Table->AddChild($Tr);
}
#-------------------------------------------------------------------------------
コード例 #12
0
 public function watermark($file, $desfile)
 {
     $suffx = substr($file, strlen($file) - 4, 4);
     if ($suffx == ".jpg" || $suffx == "jpeg" || $suffx == ".png") {
         $text = str_replace("[date]", date($this->_wmdatfmt), $this->_wmtext);
         if ($suffx == ".jpg" || $suffx == "jpeg") {
             $image = imagecreatefromjpeg($file);
         } elseif ($suffx == ".png") {
             $image = imagecreatefrompng($file);
         } else {
             return false;
         }
         $rgbtext = HexDec($this->_wmrgbtext);
         $txtr = floor($rgbtext / pow(256, 2));
         $txtg = floor($rgbtext % pow(256, 2) / pow(256, 1));
         $txtb = floor($rgbtext % pow(256, 2) % pow(256, 1) / pow(256, 0));
         $rgbtsdw = HexDec($this->_wmrgbtsdw);
         $tsdr = floor($rgbtsdw / pow(256, 2));
         $tsdg = floor($rgbtsdw % pow(256, 2) / pow(256, 1));
         $tsdb = floor($rgbtsdw % pow(256, 2) % pow(256, 1) / pow(256, 0));
         $coltext = imagecolorallocate($image, $txtr, $txtg, $txtb);
         $coltsdw = imagecolorallocate($image, $tsdr, $tsdg, $tsdb);
         if ($this->_wmhotspot != 0) {
             $ix = imagesx($image);
             $iy = imagesy($image);
             $tsw = strlen($text) * $this->_wmfont_size / imagefontwidth($this->_wmfont) * 3;
             $tsh = $this->_wmfont_size / imagefontheight($this->_wmfont);
             switch ($this->_wmhotspot) {
                 case 1:
                     $txp = $this->_wmtxp;
                     $typ = $tsh * $tsh + imagefontheight($this->_wmfont) * 2 + $this->_wmtyp;
                     break;
                 case 2:
                     $txp = floor(($ix - $tsw) / 2);
                     $typ = $tsh * $tsh + imagefontheight($this->_wmfont) * 2 + $this->_wmtyp;
                     break;
                 case 3:
                     $txp = $ix - $tsw - $this->_wmtxp;
                     $typ = $tsh * $tsh + imagefontheight($this->_wmfont) * 2 + $this->_wmtyp;
                     break;
                 case 4:
                     $txp = $this->_wmtxp;
                     $typ = floor(($iy - $tsh) / 2);
                     break;
                 case 5:
                     $txp = floor(($ix - $tsw) / 2);
                     $typ = floor(($iy - $tsh) / 2);
                     break;
                 case 6:
                     $txp = $ix - $tsw - $this->_wmtxp;
                     $typ = floor(($iy - $tsh) / 2);
                     break;
                 case 7:
                     $txp = $this->_wmtxp;
                     $typ = $iy - $tsh - $this->_wmtyp;
                     break;
                 case 8:
                     $txp = floor(($ix - $tsw) / 2);
                     $typ = $iy - $tsh - $this->_wmtyp;
                     break;
                 case 9:
                     $txp = $ix - $tsw - $this->_wmtxp;
                     $typ = $iy - $tsh - $this->_wmtyp;
                     break;
                 default:
                     return false;
             }
         } else {
             $txp = 0;
             $typ = 0;
         }
         imagettftext($image, $this->_wmfont_size, 0, $txp + 1, $typ + 1, $coltsdw, $this->_wmfont, $text);
         imagettftext($image, $this->_wmfont_size, 0, $txp, $typ, $coltext, $this->_wmfont, $text);
         if ($suffx == ".jpg" || $suffx == "jpeg") {
             imagejpeg($image, $desfile, $this->_JPEGquality);
         } elseif ($suffx == ".png") {
             imagepng($image, $desfile);
         }
         imagedestroy($image);
         return true;
     } else {
         return false;
     }
 }
コード例 #13
0
 function Mark53($AccountNo, $BLZ)
 {
     $Significance = '4216379A5842';
     if (strlen($AccountNo) == 10) {
         if (substr($AccountNo, 0, 1) == '9') {
             $Correct = $this->Mark20($AccountNo);
         }
     } else {
         $Help = 0;
         $Rest = 0;
         $AltKonto = substr($BLZ, -4, 2) . substr($AccountNo, 1, 1) . substr($BLZ, -1) . substr($AccountNo, 0, 1) . substr($AccountNo, 2, 1);
         $AccountNo = Substr($AccountNo, 3);
         while (substr($AccountNo, 0, 1) == '0') {
             $AccountNo = Substr($AccountNo, 1);
         }
         $AltKonto = $AltKonto . $AccountNo;
         while (strlen($AltKonto) < 12) {
             $AltKonto = "0" . $AltKonto;
         }
         $Checksum = substr($AltKonto, 5, 1);
         $AltKonto = substr($AltKonto, 0, 5) . '0' . substr($AltKonto, 6);
         $Laenge = strlen($AltKonto);
         for ($Run = 0; $Run < $Laenge; $Run++) {
             $Help += substr($AltKonto, $Run, 1) * HexDec(substr($Significance, $Run, 1));
         }
         $Rest = $Help % 11;
         $Gewicht = HexDec(substr($Significance, 5, 1));
         $PZ = -1;
         do {
             $PZ++;
             $Help2 = $Rest + $PZ * $Gewicht;
         } while ($Help2 % 11 != 10 or $PZ > 9);
         if ($Help2 % 11 == 10) {
             if ($PZ == $Checksum) {
                 $Correct = 0;
             } else {
                 $Correct = 1;
             }
         } else {
             $Correct = 1;
         }
     }
     return $Correct;
 }
コード例 #14
0
ファイル: DSA.php プロジェクト: orangeal2o3/pukiwiki-plugin
 /**
  * hex decode using bcmath extension
  */
 function _hexdecBcmath($hex)
 {
     $dec = '0';
     for ($i = 0; $i < strlen($hex); $i += 4) {
         $dec = bcadd(bcmul($dec, 65536), HexDec(substr($hex, $i, 4)));
     }
     return $dec;
 }
コード例 #15
0
ファイル: common.php プロジェクト: nouphet/rata
 /**
  * mod_ktai コードをデコード (サブ関数) by nao-pon
  *
  * @param string $match
  * @return string
  */
 function _decodeModKtai($match)
 {
     if ($match[1]) {
         if ($this->to !== 'COMMON' && strtolower(substr($match[1], 0, 9)) === '<textarea') {
             $carrier = '';
             switch ($this->to) {
                 case MPC_TO_FOMA:
                     $carrier = MPC_FROM_FOMA;
                     break;
                 case MPC_TO_EZWEB:
                     $carrier = MPC_FROM_EZWEB;
                     break;
                 case MPC_TO_SOFTBANK:
                     $carrier = MPC_FROM_SOFTBANK;
                     break;
             }
             if ($carrier) {
                 $mpc = MobilePictogramConverter::factory($match[1], $carrier, $this->from_charset, MPC_FROM_OPTION_MODKTAI);
                 return $mpc->autoConvert();
             }
         }
         return $match[0];
     }
     if (isset($match[4])) {
         $emj_table = 'emj2i_table';
         $match[2] = 'i';
         if (!empty($match[5])) {
             switch (strtolower($match[5])) {
                 case 'sb':
                     $emj_table = 'emj2s_table';
                     $match[2] = 's';
                     break;
                 case 'ez':
                     $emj_table = 'e2icon_table';
                     $match[2] = 'e';
                     break;
                 default:
                     $emj_table = 'emj2i_table';
                     $match[2] = 'i';
             }
         }
         if (empty($this->{$emj_table})) {
             require 'map/' . $emj_table . '.php';
         }
         $_table = $this->{$emj_table};
         if (!isset($_table[$match[4]])) {
             return $match[0];
         }
         $match[3] = $match[2] === 'e' ? dechex($_table[$match[4]]) : $_table[$match[4]];
         /*
         	    	if ($this->emj_to === 's') {
         		    	if (empty($this->i2s_table)) {
         		require 'map/i2s_table.php';
             }
             $match[2] = 's';
             $match[3] = dechex($this->i2s_table[hexdec($match[3])]);
         } else if ($this->emj_to === 'e') {
         		    	if (empty($this->i2e_table)) {
         		require 'map/i2e_table.php';
             }
         	            if (empty($this->e2icon_table)) {
         	                require 'map/e2icon_table.php';
         	            }
             $match[2] = 'e';
             $match[3] = dechex($this->e2icon_table[$this->i2e_table[hexdec($match[3])]]);
         }
         */
     }
     $mode = strtolower($match[2]);
     if ($mode === 'v') {
         $mode = 's';
     }
     // ezweb convert to icon number
     $dec = HexDec($match[3]);
     if ($mode === 'e') {
         if (empty($this->e2icon_table)) {
             require 'map/e2icon_table.php';
         }
         $dec = intval(array_search($dec, $this->e2icon_table));
     }
     $_dec = $dec;
     //exists check
     switch ($mode) {
         case 'i':
             $table = $mode . '2e_table';
             break;
         case 's':
             $table = $mode . '2e_table';
             break;
         case 'e':
             $table = $mode . '2s_table';
             break;
     }
     if (empty($this->{$table})) {
         require 'map/' . $table . '.php';
     }
     $table_array =& $this->{$table};
     if (!isset($table_array[$dec])) {
         return $match[0];
     }
     // set convert table
     $table = '';
     switch ($this->to) {
         case MPC_TO_FOMA:
             if ($mode !== 'i') {
                 $table = $mode . '2i_table';
             }
             $decode_func = 'i_options_encode';
             break;
         case MPC_TO_SOFTBANK:
             if ($mode !== 's') {
                 $table = $mode . '2s_table';
             }
             $decode_func = 's_options_encode';
             break;
         case MPC_TO_EZWEB:
             if ($mode !== 'e') {
                 $table = $mode . '2e_table';
             }
             $decode_func = 'e_options_encode';
             break;
         default:
             $decode_func = $mode . '_options_encode';
     }
     // convert
     if ($table) {
         if (empty($this->{$table})) {
             require 'map/' . $table . '.php';
         }
         $table_array =& $this->{$table};
         $dec = isset($table_array[$dec]) ? $table_array[$dec] : FALSE;
     }
     // show image if nonexist
     $_option = '';
     if (!is_numeric($dec)) {
         $dec = $_dec;
         $_option = $this->getOption();
         $this->setOption(MPC_TO_OPTION_IMG);
         $decode_func = $mode . '_options_encode';
     }
     // decode
     $ret = $this->{$decode_func}($dec);
     if ($_option) {
         $this->setOption($_option);
     }
     return $ret;
 }
コード例 #16
0
 private function decodeAddress($value)
 {
     $charset = null;
     $s = 0;
     $decoded = '';
     $l = strlen($value);
     while ($s < $l) {
         if (GetType($q = strpos($value, '=?', $s)) != 'integer') {
             if ($s == 0) {
                 return $value;
             }
             if ($s < $l) {
                 $decoded .= substr($value, $s);
             }
             break;
         }
         if ($s < $q) {
             $decoded .= substr($value, $s, $q - $s);
         }
         $q += 2;
         if (GetType($c = strpos($value, '?', $q)) != 'integer' || $q == $c) {
             return $value;
         }
         if (isset($charset)) {
             $another_charset = strtolower(substr($value, $q, $c - $q));
             if (strcmp($charset, $another_charset) && strcmp($another_charset, 'ascii')) {
                 return $value;
             }
         } else {
             $charset = strtolower(substr($value, $q, $c - $q));
             if (!strcmp($charset, 'ascii')) {
                 $charset = null;
             }
         }
         ++$c;
         if (GetType($t = strpos($value, '?', $c)) != 'integer' || $c == $t) {
             return $value;
         }
         $type = strtolower(substr($value, $c, $t - $c));
         ++$t;
         if (GetType($e = strpos($value, '?=', $t)) != 'integer') {
             return $this->SetPositionedWarning('invalid Q-encoding encoded data', $p + $e);
         }
         switch ($type) {
             case 'q':
                 for ($s = $t; $s < $e;) {
                     switch ($b = $value[$s]) {
                         case '=':
                             $h = HexDec($hex = strtolower(substr($value, $s + 1, 2)));
                             if ($s + 3 > $e || strcmp(sprintf('%02x', $h), $hex)) {
                                 return $value;
                             }
                             $decoded .= chr($h);
                             $s += 3;
                             break;
                         case '_':
                             $decoded .= ' ';
                             ++$s;
                             break;
                         default:
                             $decoded .= $b;
                             ++$s;
                     }
                 }
                 break;
             case 'b':
                 if ($e <= $t || strlen($binary = base64_decode($data = substr($value, $t, $e - $t))) == 0 || GetType($binary) != 'string') {
                     return $value;
                 }
                 $decoded .= $binary;
                 $s = $e;
                 break;
             default:
                 return $value;
         }
         $s += 2;
         $s += strspn($value, " \t", $s);
     }
     $value = $decoded;
     return $value;
 }
コード例 #17
0
ファイル: form_captcha.php プロジェクト: wycus/darmedic
 function DrawText($image, $text, $color)
 {
     $rgb = strlen($color) ? $color : "#000000";
     if (($text_color = imagecolorallocate($image, HexDec(substr($rgb, 1, 2)), HexDec(substr($rgb, 3, 2)), HexDec(substr($rgb, 5, 2)))) == -1) {
         return "could not allocate the text color";
     }
     if (strlen($color) == 0) {
         $text_color = imagecolortransparent($image, $text_color);
     }
     $text_width = strlen($text) * imagefontwidth($this->font);
     $text_height = imagefontheight($this->font);
     imagestring($image, $this->font, rand(0, $this->image_width - $text_width), rand(0, $this->image_height - $text_height), $text, $text_color);
     return "";
 }
コード例 #18
0
ファイル: rfc822.php プロジェクト: sukhjeet81/capuchn
 function QDecode($p, &$value, &$encoding)
 {
     $encoding = $charset = null;
     $s = 0;
     $decoded = '';
     $l = strlen($value);
     while ($s < $l) {
         if (GetType($q = strpos($value, '=?', $s)) != 'integer') {
             if ($s == 0) {
                 return 1;
             }
             if ($s < $l) {
                 $decoded .= substr($value, $s);
             }
             break;
         }
         if ($s < $q) {
             $decoded .= substr($value, $s, $q - $s);
         }
         $q += 2;
         if (GetType($c = strpos($value, '?', $q)) != 'integer' || $q == $c) {
             return $this->SetPositionedWarning('invalid Q-encoding character set', $p + $q);
         }
         if (isset($charset)) {
             $another_charset = strtolower(substr($value, $q, $c - $q));
             if (strcmp($charset, $another_charset) && strcmp($another_charset, 'ascii')) {
                 return $this->SetWarning('it is not possible to decode an encoded value using mixed character sets into a single value', $p + $q);
             }
         } else {
             $charset = strtolower(substr($value, $q, $c - $q));
             if (!strcmp($charset, 'ascii')) {
                 $charset = null;
             }
         }
         ++$c;
         if (GetType($t = strpos($value, '?', $c)) != 'integer' || $c == $t) {
             return $this->SetPositionedWarning('invalid Q-encoding type', $p + $c);
         }
         $type = strtolower(substr($value, $c, $t - $c));
         ++$t;
         if (GetType($e = strpos($value, '?=', $t)) != 'integer') {
             return $this->SetPositionedWarning('invalid Q-encoding encoded data', $p + $e);
         }
         switch ($type) {
             case 'q':
                 for ($s = $t; $s < $e;) {
                     switch ($b = $value[$s]) {
                         case '=':
                             $h = HexDec($hex = strtolower(substr($value, $s + 1, 2)));
                             if ($s + 3 > $e || strcmp(sprintf('%02x', $h), $hex)) {
                                 return $this->SetPositionedWarning('invalid Q-encoding q encoded data', $p + $s);
                             }
                             $decoded .= chr($h);
                             $s += 3;
                             break;
                         case '_':
                             $decoded .= ' ';
                             ++$s;
                             break;
                         default:
                             $decoded .= $b;
                             ++$s;
                     }
                 }
                 break;
             case 'b':
                 if ($e <= $t || strlen($binary = base64_decode($data = substr($value, $t, $e - $t))) == 0 || GetType($binary) != 'string') {
                     return $this->SetPositionedWarning('invalid Q-encoding b encoded data', $p + $t);
                 }
                 $decoded .= $binary;
                 $s = $e;
                 break;
             default:
                 return $this->SetPositionedWarning('Q-encoding ' . $type . ' is not yet supported', $p + $c);
         }
         $s += 2;
     }
     $value = $decoded;
     $encoding = $charset;
     return 1;
 }
コード例 #19
0
 function _bc_hexdec($hex)
 {
     $dec = "0";
     while (strlen($hex)) {
         $i = HexDec(substr($hex, 0, 4));
         $dec = bcadd(bcmul($dec, 65536), $i);
         $hex = substr($hex, 4);
     }
     return $dec;
 }
コード例 #20
0
 /**
  * Converts a "HTML-color" TypoScript datatype to RGB-values.
  * Default is 0,0,0
  *
  * @param string $string "HTML-color" data type string, eg. 'red', '#ffeedd' or '255,0,255'. You can also add a modifying operator afterwards. There are two options: "255,0,255 : 20" - will add 20 to values, result is "255,20,255". Or "255,0,255 : *1.23" which will multiply all RGB values with 1.23
  * @return array RGB values in key 0/1/2 of the array
  */
 public function convertColor($string)
 {
     $col = array();
     $cParts = explode(':', $string, 2);
     // Finding the RGB definitions of the color:
     $string = $cParts[0];
     if (strstr($string, '#')) {
         $string = preg_replace('/[^A-Fa-f0-9]*/', '', $string);
         $col[] = HexDec(substr($string, 0, 2));
         $col[] = HexDec(substr($string, 2, 2));
         $col[] = HexDec(substr($string, 4, 2));
     } elseif (strstr($string, ',')) {
         $string = preg_replace('/[^,0-9]*/', '', $string);
         $strArr = explode(',', $string);
         $col[] = (int) $strArr[0];
         $col[] = (int) $strArr[1];
         $col[] = (int) $strArr[2];
     } else {
         $string = strtolower(trim($string));
         if ($this->colMap[$string]) {
             $col = $this->colMap[$string];
         } else {
             $col = array(0, 0, 0);
         }
     }
     // ... and possibly recalculating the value
     if (trim($cParts[1])) {
         $cParts[1] = trim($cParts[1]);
         if ($cParts[1][0] === '*') {
             $val = doubleval(substr($cParts[1], 1));
             $col[0] = MathUtility::forceIntegerInRange($col[0] * $val, 0, 255);
             $col[1] = MathUtility::forceIntegerInRange($col[1] * $val, 0, 255);
             $col[2] = MathUtility::forceIntegerInRange($col[2] * $val, 0, 255);
         } else {
             $val = (int) $cParts[1];
             $col[0] = MathUtility::forceIntegerInRange($col[0] + $val, 0, 255);
             $col[1] = MathUtility::forceIntegerInRange($col[1] + $val, 0, 255);
             $col[2] = MathUtility::forceIntegerInRange($col[2] + $val, 0, 255);
         }
     }
     return $col;
 }
コード例 #21
0
 /**
  * [Describe function...]
  *
  * @param	[type]		$http_post_vars: ...
  * @param	[type]		$http_post_files: ...
  * @param	[type]		$theConstants: ...
  * @param	[type]		$tplRow: ...
  * @return	[type]		...
  */
 function ext_procesInput($http_post_vars, $http_post_files, $theConstants, $tplRow)
 {
     $data = $http_post_vars['data'];
     $check = $http_post_vars['check'];
     $copyResource = $http_post_vars['_copyResource'];
     $Wdata = $http_post_vars['Wdata'];
     $W2data = $http_post_vars['W2data'];
     $W3data = $http_post_vars['W3data'];
     $W4data = $http_post_vars['W4data'];
     $W5data = $http_post_vars['W5data'];
     if (is_array($data)) {
         foreach ($data as $key => $var) {
             if (isset($theConstants[$key])) {
                 if ($this->ext_dontCheckIssetValues || isset($check[$key])) {
                     // If checkbox is set, update the value
                     list($var) = explode(LF, $var);
                     // exploding with linebreak, just to make sure that no multiline input is given!
                     $typeDat = $this->ext_getTypeData($theConstants[$key]['type']);
                     switch ($typeDat['type']) {
                         case 'int':
                             if ($typeDat['paramstr']) {
                                 $var = t3lib_div::intInRange($var, $typeDat['params'][0], $typeDat['params'][1]);
                             } else {
                                 $var = intval($var);
                             }
                             break;
                         case 'int+':
                             $var = max(0, intval($var));
                             break;
                         case 'color':
                             $col = array();
                             if ($var && !t3lib_div::inList($this->HTMLcolorList, strtolower($var))) {
                                 $var = preg_replace('/[^A-Fa-f0-9]*/', '', $var);
                                 $useFullHex = strlen($var) > 3;
                                 $col[] = HexDec(substr($var, 0, 1));
                                 $col[] = HexDec(substr($var, 1, 1));
                                 $col[] = HexDec(substr($var, 2, 1));
                                 if ($useFullHex) {
                                     $col[] = HexDec(substr($var, 3, 1));
                                     $col[] = HexDec(substr($var, 4, 1));
                                     $col[] = HexDec(substr($var, 5, 1));
                                 }
                                 $var = substr('0' . DecHex($col[0]), -1) . substr('0' . DecHex($col[1]), -1) . substr('0' . DecHex($col[2]), -1);
                                 if ($useFullHex) {
                                     $var .= substr('0' . DecHex($col[3]), -1) . substr('0' . DecHex($col[4]), -1) . substr('0' . DecHex($col[5]), -1);
                                 }
                                 $var = '#' . strtoupper($var);
                             }
                             break;
                         case 'comment':
                             if ($var) {
                                 $var = '#';
                             } else {
                                 $var = '';
                             }
                             break;
                         case 'wrap':
                             if (isset($Wdata[$key])) {
                                 $var .= '|' . $Wdata[$key];
                             }
                             break;
                         case 'offset':
                             if (isset($Wdata[$key])) {
                                 $var = intval($var) . ',' . intval($Wdata[$key]);
                                 if (isset($W2data[$key])) {
                                     $var .= ',' . intval($W2data[$key]);
                                     if (isset($W3data[$key])) {
                                         $var .= ',' . intval($W3data[$key]);
                                         if (isset($W4data[$key])) {
                                             $var .= ',' . intval($W4data[$key]);
                                             if (isset($W5data[$key])) {
                                                 $var .= ',' . intval($W5data[$key]);
                                             }
                                         }
                                     }
                                 }
                             }
                             break;
                         case 'boolean':
                             if ($var) {
                                 $var = $typeDat['paramstr'] ? $typeDat['paramstr'] : 1;
                             }
                             break;
                         case 'file':
                             if (!$this->ext_noCEUploadAndCopying) {
                                 if ($http_post_files['upload_data']['name'][$key] && $http_post_files['upload_data']['tmp_name'][$key] != 'none') {
                                     $var = $this->upload_copy_file($typeDat, $tplRow, trim($http_post_files['upload_data']['name'][$key]), $http_post_files['upload_data']['tmp_name'][$key]);
                                 }
                                 if ($copyResource[$key]) {
                                     $var = $this->upload_copy_file($typeDat, $tplRow, basename($copyResource[$key]), $copyResource[$key]);
                                 }
                             }
                             break;
                     }
                     if ($this->ext_printAll || strcmp($theConstants[$key]['value'], $var)) {
                         $this->ext_putValueInConf($key, $var);
                         // Put value in, if changed.
                     }
                     unset($check[$key]);
                     // Remove the entry because it has been "used"
                 } else {
                     $this->ext_removeValueInConf($key);
                 }
             }
         }
     }
     // Remaining keys in $check indicates fields that are just clicked "on" to be edited. Therefore we get the default value and puts that in the template as a start...
     if (!$this->ext_dontCheckIssetValues && is_array($check)) {
         foreach ($check as $key => $var) {
             if (isset($theConstants[$key])) {
                 $dValue = $theConstants[$key]['default_value'];
                 $this->ext_putValueInConf($key, $dValue);
             }
         }
     }
 }
コード例 #22
0
 /**
  * [Describe function...]
  *
  * @param 	[type]		$http_post_vars: ...
  * @param 	array (not used anymore)
  * @param 	[type]		$theConstants: ...
  * @param 	[type]		$tplRow: ...
  * @return 	[type]		...
  * @todo Define visibility
  */
 public function ext_procesInput($http_post_vars, $http_post_files, $theConstants, $tplRow)
 {
     $data = $http_post_vars['data'];
     $check = $http_post_vars['check'];
     $Wdata = $http_post_vars['Wdata'];
     $W2data = $http_post_vars['W2data'];
     $W3data = $http_post_vars['W3data'];
     $W4data = $http_post_vars['W4data'];
     $W5data = $http_post_vars['W5data'];
     if (is_array($data)) {
         foreach ($data as $key => $var) {
             if (isset($theConstants[$key])) {
                 // If checkbox is set, update the value
                 if ($this->ext_dontCheckIssetValues || isset($check[$key])) {
                     // Exploding with linebreak, just to make sure that no multiline input is given!
                     list($var) = explode(LF, $var);
                     $typeDat = $this->ext_getTypeData($theConstants[$key]['type']);
                     switch ($typeDat['type']) {
                         case 'int':
                             if ($typeDat['paramstr']) {
                                 $var = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($var, $typeDat['params'][0], $typeDat['params'][1]);
                             } else {
                                 $var = (int) $var;
                             }
                             break;
                         case 'int+':
                             $var = max(0, (int) $var);
                             break;
                         case 'color':
                             $col = array();
                             if ($var && !GeneralUtility::inList($this->HTMLcolorList, strtolower($var))) {
                                 $var = preg_replace('/[^A-Fa-f0-9]*/', '', $var);
                                 $useFulHex = strlen($var) > 3;
                                 $col[] = HexDec($var[0]);
                                 $col[] = HexDec($var[1]);
                                 $col[] = HexDec($var[2]);
                                 if ($useFulHex) {
                                     $col[] = HexDec($var[3]);
                                     $col[] = HexDec($var[4]);
                                     $col[] = HexDec($var[5]);
                                 }
                                 $var = substr('0' . DecHex($col[0]), -1) . substr('0' . DecHex($col[1]), -1) . substr('0' . DecHex($col[2]), -1);
                                 if ($useFulHex) {
                                     $var .= substr('0' . DecHex($col[3]), -1) . substr('0' . DecHex($col[4]), -1) . substr('0' . DecHex($col[5]), -1);
                                 }
                                 $var = '#' . strtoupper($var);
                             }
                             break;
                         case 'comment':
                             if ($var) {
                                 $var = '#';
                             } else {
                                 $var = '';
                             }
                             break;
                         case 'wrap':
                             if (isset($Wdata[$key])) {
                                 $var .= '|' . $Wdata[$key];
                             }
                             break;
                         case 'offset':
                             if (isset($Wdata[$key])) {
                                 $var = (int) $var . ',' . (int) $Wdata[$key];
                                 if (isset($W2data[$key])) {
                                     $var .= ',' . (int) $W2data[$key];
                                     if (isset($W3data[$key])) {
                                         $var .= ',' . (int) $W3data[$key];
                                         if (isset($W4data[$key])) {
                                             $var .= ',' . (int) $W4data[$key];
                                             if (isset($W5data[$key])) {
                                                 $var .= ',' . (int) $W5data[$key];
                                             }
                                         }
                                     }
                                 }
                             }
                             break;
                         case 'boolean':
                             if ($var) {
                                 $var = $typeDat['paramstr'] ? $typeDat['paramstr'] : 1;
                             }
                             break;
                     }
                     if ($this->ext_printAll || (string) $theConstants[$key]['value'] !== (string) $var) {
                         // Put value in, if changed.
                         $this->ext_putValueInConf($key, $var);
                     }
                     // Remove the entry because it has been "used"
                     unset($check[$key]);
                 } else {
                     $this->ext_removeValueInConf($key);
                 }
             }
         }
     }
     // Remaining keys in $check indicates fields that are just clicked "on" to be edited. Therefore we get the default value and puts that in the template as a start...
     if (!$this->ext_dontCheckIssetValues && is_array($check)) {
         foreach ($check as $key => $var) {
             if (isset($theConstants[$key])) {
                 $dValue = $theConstants[$key]['default_value'];
                 $this->ext_putValueInConf($key, $dValue);
             }
         }
     }
 }
コード例 #23
0
ファイル: functions_chn.php プロジェクト: dalinhuang/cameras
function GBunspace($text)
{
    $news = "";
    $l = strlen($text);
    $a = 0;
    $last_space = 1;
    while ($a < $l) {
        $ch = substr($text, $a, 1);
        $ch2 = substr($text, $a + 1, 1);
        $ch3 = substr($text, $a + 2, 1);
        if ($a + 1 == $l) {
            $last_space = 1;
        }
        if ($ch == " ") {
            if ($last_space == 0) {
                if (ord($ch2) >= HexDec("0x81") && ord($ch3) >= HexDec("0x40")) {
                    if ($chi == 0) {
                        $news .= " ";
                        $last_space = 1;
                    }
                    $chi = 1;
                } elseif ($ch2 != " ") {
                    $news .= " ";
                    $chi = 0;
                    $last_space = 1;
                }
            }
        } else {
            if (ord($ch) >= HexDec("0x81") && ord($ch2) >= HexDec("0x40")) {
                $chi = 1;
                $a++;
                $news .= $ch . $ch2;
                $last_space = 0;
            } else {
                $chi = 0;
                $news .= $ch;
                $last_space = 0;
            }
        }
        $a++;
    }
    // Chk 1 & last is space
    $l = strlen($news);
    if (substr($news, 0, 1) == " ") {
        $news = substr($news, 1);
    }
    $l = strlen($news);
    if (substr($news, $l - 1, 1) == " ") {
        $news = substr($news, 0, $l - 1);
    }
    return $news;
}
コード例 #24
0
ファイル: mime_parser.php プロジェクト: sgh1986915/php-crm
 function DecodePart($part)
 {
     switch ($part['Type']) {
         case 'MessageStart':
             $this->headers = array();
             break;
         case 'HeaderName':
             if ($this->decode_bodies) {
                 $this->current_header = strtolower($part['Name']);
             }
             break;
         case 'HeaderValue':
             if ($this->decode_headers) {
                 $value = $part['Value'];
                 $error = '';
                 for ($decoded_header = array(), $position = 0; $position < strlen($value);) {
                     if (GetType($encoded = strpos($value, '=?', $position)) != 'integer') {
                         if ($position < strlen($value)) {
                             if (count($decoded_header)) {
                                 $decoded_header[count($decoded_header) - 1]['Value'] .= substr($value, $position);
                             } else {
                                 $decoded_header[] = array('Value' => substr($value, $position), 'Encoding' => 'ASCII');
                             }
                         }
                         break;
                     }
                     $set = $encoded + 2;
                     if (GetType($method = strpos($value, '?', $set)) != 'integer') {
                         $error = 'invalid header encoding syntax ' . $part['Value'];
                         $error_position = $part['Position'] + $set;
                         break;
                     }
                     $encoding = strtoupper(substr($value, $set, $method - $set));
                     $method += 1;
                     if (GetType($data = strpos($value, '?', $method)) != 'integer') {
                         $error = 'invalid header encoding syntax ' . $part['Value'];
                         $error_position = $part['Position'] + $set;
                         break;
                     }
                     $start = $data + 1;
                     if (GetType($end = strpos($value, '?=', $start)) != 'integer') {
                         $error = 'invalid header encoding syntax ' . $part['Value'];
                         $error_position = $part['Position'] + $start;
                         break;
                     }
                     if ($encoded > $position) {
                         if (count($decoded_header)) {
                             $decoded_header[count($decoded_header) - 1]['Value'] .= substr($value, $position, $encoded - $position);
                         } else {
                             $decoded_header[] = array('Value' => substr($value, $position, $encoded - $position), 'Encoding' => 'ASCII');
                         }
                     }
                     switch (strtolower(substr($value, $method, $data - $method))) {
                         case 'q':
                             if ($end > $start) {
                                 for ($decoded = '', $position = $start; $position < $end;) {
                                     switch ($value[$position]) {
                                         case '=':
                                             $h = HexDec($hex = strtolower(substr($value, $position + 1, 2)));
                                             if ($end - $position < 3 || strcmp(sprintf('%02x', $h), $hex)) {
                                                 $warning = 'the header specified an invalid encoded character';
                                                 $warning_position = $part['Position'] + $position + 1;
                                                 if ($this->ignore_syntax_errors) {
                                                     $this->SetPositionedWarning($warning, $warning_position);
                                                     $decoded .= '=';
                                                     $position++;
                                                 } else {
                                                     $error = $warning;
                                                     $error_position = $warning_position;
                                                     break 4;
                                                 }
                                             } else {
                                                 $decoded .= Chr($h);
                                                 $position += 3;
                                             }
                                             break;
                                         case '_':
                                             $decoded .= ' ';
                                             $position++;
                                             break;
                                         default:
                                             $decoded .= $value[$position];
                                             $position++;
                                             break;
                                     }
                                 }
                                 if (count($decoded_header) && !strcmp($decoded_header[$last = count($decoded_header) - 1]['Encoding'], 'ASCII') || !strcmp($decoded_header[$last]['Encoding'], $encoding)) {
                                     $decoded_header[$last]['Value'] .= $decoded;
                                     $decoded_header[$last]['Encoding'] = $encoding;
                                 } else {
                                     $decoded_header[] = array('Value' => $decoded, 'Encoding' => $encoding);
                                 }
                             }
                             break;
                         case 'b':
                             $decoded = base64_decode(substr($value, $start, $end - $start));
                             if ($end <= $start || GetType($decoded) != 'string' || strlen($decoded) == 0) {
                                 $warning = 'the header specified an invalid base64 encoded text';
                                 $warning_position = $part['Position'] + $start;
                                 if ($this->ignore_syntax_errors) {
                                     $this->SetPositionedWarning($warning, $warning_position);
                                 } else {
                                     $error = $warning;
                                     $error_position = $warning_position;
                                     break 2;
                                 }
                             }
                             if (count($decoded_header) && !strcmp($decoded_header[$last = count($decoded_header) - 1]['Encoding'], 'ASCII') || !strcmp($decoded_header[$last]['Encoding'], $encoding)) {
                                 $decoded_header[$last]['Value'] .= $decoded;
                                 $decoded_header[$last]['Encoding'] = $encoding;
                             } else {
                                 $decoded_header[] = array('Value' => $decoded, 'Encoding' => $encoding);
                             }
                             break;
                         default:
                             $error = 'the header specified an unsupported encoding method';
                             $error_position = $part['Position'] + $method;
                             break 2;
                     }
                     $position = $end + 2;
                 }
                 if (strlen($error) == 0 && count($decoded_header)) {
                     $part['Decoded'] = $decoded_header;
                 }
             }
             if ($this->decode_bodies || $this->decode_headers) {
                 switch ($this->current_header) {
                     case 'content-type:':
                         $boundary = $this->ParseParameters($part['Value'], $type, $parameters, 'boundary');
                         $this->headers['Type'] = $type;
                         if ($this->decode_headers) {
                             $part['MainValue'] = $type;
                             $part['Parameters'] = $parameters;
                         }
                         if (!strcmp(strtok($type, '/'), 'multipart')) {
                             $this->headers['Multipart'] = 1;
                             if (strlen($boundary)) {
                                 $this->headers['Boundary'] = $boundary;
                             } else {
                                 return $this->SetPositionedError('multipart content-type header does not specify the boundary parameter', $part['Position']);
                             }
                         }
                         break;
                     case 'content-transfer-encoding:':
                         switch ($this->headers['Encoding'] = strtolower(trim($part['Value']))) {
                             case 'quoted-printable':
                                 $this->headers['QuotedPrintable'] = 1;
                                 break;
                             case '7 bit':
                             case '8 bit':
                                 if (!$this->SetPositionedWarning('"' . $this->headers['Encoding'] . '" is an incorrect content transfer encoding type', $part['Position'])) {
                                     return 0;
                                 }
                             case '7bit':
                             case '8bit':
                             case 'binary':
                                 break;
                             case 'base64':
                                 $this->headers['Base64'] = 1;
                                 break;
                             default:
                                 if (!$this->SetPositionedWarning('decoding ' . $this->headers['Encoding'] . ' encoded bodies is not yet supported', $part['Position'])) {
                                     return 0;
                                 }
                         }
                         break;
                 }
             }
             break;
         case 'BodyStart':
             if ($this->decode_bodies && isset($this->headers['Multipart'])) {
                 $this->body_parser_state = MIME_PARSER_BODY_START;
                 $this->body_buffer = '';
                 $this->body_buffer_position = 0;
             }
             break;
         case 'MessageEnd':
             if ($this->decode_bodies && isset($this->headers['Multipart']) && $this->body_parser_state != MIME_PARSER_BODY_DONE) {
                 if ($this->body_parser_state != MIME_PARSER_BODY_DATA) {
                     return $this->SetPositionedError('incomplete message body part', $part['Position']);
                 }
                 if (!$this->SetPositionedWarning('truncated message body part', $part['Position'])) {
                     return 0;
                 }
             }
             break;
         case 'BodyData':
             if ($this->decode_bodies) {
                 if (strlen($this->body_buffer) == 0) {
                     $this->body_buffer = $part['Data'];
                     $this->body_offset = $part['Position'];
                 } else {
                     $this->body_buffer .= $part['Data'];
                 }
                 if (isset($this->headers['Multipart'])) {
                     $boundary = '--' . $this->headers['Boundary'];
                     switch ($this->body_parser_state) {
                         case MIME_PARSER_BODY_START:
                             for ($position = $this->body_buffer_position;;) {
                                 if (!$this->FindBodyLineBreak($position, $break, $line_break)) {
                                     return 1;
                                 }
                                 $next = $line_break + strlen($break);
                                 if (!strcmp(rtrim(substr($this->body_buffer, $position, $line_break - $position)), $boundary)) {
                                     $part = array('Type' => 'StartPart', 'Part' => $this->headers['Boundary'], 'Position' => $this->body_offset + $next);
                                     $this->parts[] = $part;
                                     unset($this->body_parser);
                                     $this->body_parser = new mime_parser_class();
                                     $this->body_parser->decode_bodies = 1;
                                     $this->body_parser->decode_headers = $this->decode_headers;
                                     $this->body_parser->mbox = 0;
                                     $this->body_parser_state = MIME_PARSER_BODY_DATA;
                                     $this->body_buffer = substr($this->body_buffer, $next);
                                     $this->body_offset += $next;
                                     $this->body_buffer_position = 0;
                                     break;
                                 } else {
                                     $position = $next;
                                 }
                             }
                         case MIME_PARSER_BODY_DATA:
                             for ($position = $this->body_buffer_position;;) {
                                 if (!$this->FindBodyLineBreak($position, $break, $line_break)) {
                                     if ($position > 0) {
                                         if (!$this->body_parser->Parse(substr($this->body_buffer, 0, $position), 0)) {
                                             return $this->SetError($this->body_parser->error);
                                         }
                                         if (!$this->QueueBodyParts()) {
                                             return 0;
                                         }
                                     }
                                     $this->body_buffer = substr($this->body_buffer, $position);
                                     $this->body_buffer_position = 0;
                                     $this->body_offset += $position;
                                     return 1;
                                 }
                                 $next = $line_break + strlen($break);
                                 $line = substr($this->body_buffer, $position, $line_break - $position);
                                 if (!strcmp(rtrim($line), $boundary)) {
                                     if (!$this->body_parser->Parse(substr($this->body_buffer, 0, $position), 1)) {
                                         return $this->SetError($this->body_parser->error);
                                     }
                                     if (!$this->QueueBodyParts()) {
                                         return 0;
                                     }
                                     $part = array('Type' => 'EndPart', 'Part' => $this->headers['Boundary'], 'Position' => $this->body_offset + $position);
                                     $this->parts[] = $part;
                                     $part = array('Type' => 'StartPart', 'Part' => $this->headers['Boundary'], 'Position' => $this->body_offset + $next);
                                     $this->parts[] = $part;
                                     unset($this->body_parser);
                                     $this->body_parser = new mime_parser_class();
                                     $this->body_parser->decode_bodies = 1;
                                     $this->body_parser->decode_headers = $this->decode_headers;
                                     $this->body_parser->mbox = 0;
                                     $this->body_buffer = substr($this->body_buffer, $next);
                                     $this->body_buffer_position = 0;
                                     $this->body_offset += $next;
                                     $position = 0;
                                     continue;
                                 } elseif (!strcmp($r = rtrim($line), $boundary . '--')) {
                                     if (!$this->body_parser->Parse(substr($this->body_buffer, 0, $position), 1)) {
                                         return $this->SetError($this->body_parser->error);
                                     }
                                     if (!$this->QueueBodyParts()) {
                                         return 0;
                                     }
                                     $part = array('Type' => 'EndPart', 'Part' => $this->headers['Boundary'], 'Position' => $this->body_offset + $position);
                                     $this->body_buffer = substr($this->body_buffer, $next);
                                     $this->body_buffer_position = 0;
                                     $this->body_offset += $next;
                                     $this->body_parser_state = MIME_PARSER_BODY_DONE;
                                     break 2;
                                 }
                                 $position = $next;
                             }
                             break;
                         case MIME_PARSER_BODY_DONE:
                             return 1;
                         default:
                             return $this->SetPositionedError($this->state . ' is not a valid body parser state', $this->body_buffer_position);
                     }
                 } elseif (isset($this->headers['QuotedPrintable'])) {
                     for ($end = strlen($this->body_buffer), $decoded = '', $position = $this->body_buffer_position; $position < $end;) {
                         if (GetType($equal = strpos($this->body_buffer, '=', $position)) != 'integer') {
                             $decoded .= substr($this->body_buffer, $position);
                             $position = $end;
                             break;
                         }
                         $next = $equal + 1;
                         switch ($end - $equal) {
                             case 1:
                                 $decoded .= substr($this->body_buffer, $position, $equal - $position);
                                 $position = $equal;
                                 break 2;
                             case 2:
                                 $decoded .= substr($this->body_buffer, $position, $equal - $position);
                                 if (!strcmp($this->body_buffer[$next], "\n")) {
                                     $position = $end;
                                 } else {
                                     $position = $equal;
                                 }
                                 break 2;
                         }
                         if (!strcmp(substr($this->body_buffer, $next, 2), $break = "\r\n") || !strcmp($this->body_buffer[$next], $break = "\n") || !strcmp($this->body_buffer[$next], $break = "\r")) {
                             $decoded .= substr($this->body_buffer, $position, $equal - $position);
                             $position = $next + strlen($break);
                             continue;
                         }
                         $decoded .= substr($this->body_buffer, $position, $equal - $position);
                         $h = HexDec($hex = strtolower(substr($this->body_buffer, $next, 2)));
                         if (strcmp(sprintf('%02x', $h), $hex)) {
                             if (!$this->SetPositionedWarning('the body specified an invalid quoted-printable encoded character', $this->body_offset + $next)) {
                                 return 0;
                             }
                             $decoded .= '=';
                             $position = $next;
                         } else {
                             $decoded .= Chr($h);
                             $position = $equal + 3;
                         }
                     }
                     if (strlen($decoded) == 0) {
                         $this->body_buffer_position = $position;
                         return 1;
                     }
                     $part['Data'] = $decoded;
                     $this->body_buffer = substr($this->body_buffer, $position);
                     $this->body_buffer_position = 0;
                     $this->body_offset += $position;
                 } elseif (isset($this->headers['Base64'])) {
                     $part['Data'] = base64_decode($this->body_buffer_position ? substr($this->body_buffer, $this->body_buffer_position) : $this->body_buffer);
                     $this->body_offset += strlen($this->body_buffer) - $this->body_buffer_position;
                     $this->body_buffer_position = 0;
                     $this->body_buffer = '';
                 } else {
                     $part['Data'] = substr($this->body_buffer, $this->body_buffer_position);
                     $this->body_buffer_position = 0;
                     $this->body_buffer = '';
                 }
             }
             break;
     }
     $this->parts[] = $part;
     return 1;
 }
コード例 #25
0
ファイル: library.php プロジェクト: BackupTheBerlios/verlihub
FUNCTION DecodeStr($hex, $key) {
	$hex = EregI_Replace("([a-f0-9]{".$key[8]."})([a-f0-9]{".$key[6]."})([a-f0-9]*)([a-f0-9]{".$key[7]."})([a-f0-9]{".$key[9]."})", "\\5\\4\\3\\2\\1", $hex);

	FOR($i = 0; $i < StrLen($hex); $i++) {
		$str .= Chr(HexDec($hex[$i++].$hex[$i]));
		}

	RETURN Explode(Chr(30), $str);
	}