First commit

This commit is contained in:
2025-06-18 10:24:27 +08:00
commit ebc39cd5dd
3873 changed files with 412712 additions and 0 deletions

235
uc_server/lib/dbi.class.php Normal file
View File

@@ -0,0 +1,235 @@
<?php
/*
[UCenter] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: db.class.php 980 2009-12-22 03:12:49Z zhaoxiongfei $
*/
class ucserver_db {
var $querynum = 0;
var $link;
var $histories;
var $stmtcache = array();
var $dbhost;
var $dbuser;
var $dbpw;
var $dbcharset;
var $pconnect;
var $tablepre;
var $time;
var $goneaway = 5;
function connect($dbhost, $dbuser, $dbpw, $dbname = '', $dbcharset = '', $pconnect = 0, $tablepre='', $time = 0) {
if (intval($pconnect) === 1) $dbhost = 'p:' . $dbhost;
$this->dbhost = $dbhost;
$this->dbuser = $dbuser;
$this->dbpw = $dbpw;
$this->dbname = $dbname;
$this->dbcharset = $dbcharset;
$this->pconnect = $pconnect;
$this->tablepre = $tablepre;
$this->time = $time;
mysqli_report(MYSQLI_REPORT_OFF);
if(!$this->link = new mysqli($dbhost, $dbuser, $dbpw, $dbname)) {
$this->halt('Can not connect to MySQL server');
}
$this->link->options(MYSQLI_OPT_LOCAL_INFILE, false);
if($dbcharset) {
$this->link->set_charset($dbcharset);
}
$this->link->query("SET sql_mode=''");
$this->link->query("SET character_set_client=binary");
}
function fetch_array($query, $result_type = MYSQLI_ASSOC) {
return $query ? $query->fetch_array($result_type) : null;
}
function result_first($sql) {
$query = $this->query($sql);
return $this->result($query, 0);
}
function fetch_first($sql) {
$query = $this->query($sql);
return $this->fetch_array($query);
}
function fetch_all($sql, $id = '') {
$arr = array();
$query = $this->query($sql);
while($data = $this->fetch_array($query)) {
$id ? $arr[$data[$id]] = $data : $arr[] = $data;
}
return $arr;
}
function result_first_stmt($sql, $key = array(), $value = array()) {
$query = $this->query_stmt($sql, $key, $value);
return $this->result($query, 0);
}
function fetch_first_stmt($sql, $key = array(), $value = array()) {
$query = $this->query_stmt($sql, $key, $value);
return $this->fetch_array($query);
}
function fetch_all_stmt($sql, $key = array(), $value = array(), $id = '') {
$arr = array();
$query = $this->query_stmt($sql, $key, $value);
while($data = $this->fetch_array($query)) {
$id ? $arr[$data[$id]] = $data : $arr[] = $data;
}
return $arr;
}
function cache_gc() {
$this->query("DELETE FROM {$this->tablepre}sqlcaches WHERE expiry<$this->time");
}
function query($sql, $type = '', $cachetime = FALSE) {
$resultmode = $type == 'UNBUFFERED' ? MYSQLI_USE_RESULT : MYSQLI_STORE_RESULT;
if(!($query = $this->link->query($sql, $resultmode)) && $type != 'SILENT') {
$this->halt('MySQL Query Error', $sql);
}
$this->querynum++;
$this->histories[] = $sql;
return $query;
}
function query_stmt($sql, $key = array(), $value = array(), $type = '', $saveprep = FALSE, $cachetime = FALSE) {
$parse = $this->parse_query($sql, $key, $value);
if($saveprep && array_key_exists(hash("sha256", $parse[0]), $this->stmtcache)) {
$stmt = & $this->stmtcache[hash("sha256", $parse[0])];
} else {
$stmt = $this->link->prepare($parse[0]);
$saveprep && $this->stmtcache[hash("sha256", $parse[0])] = & $stmt;
}
if(!empty($key)) {
$stmt->bind_param(...$parse[1]);
}
if(!($query = $stmt->execute()) && $type != 'SILENT') {
$this->halt('MySQL Query Error', $parse[0]);
}
$this->querynum++;
$this->histories[] = $parse[0];
return strncasecmp("SELECT", $sql, 6) ? $query : $stmt->get_result();
}
function affected_rows() {
return $this->link->affected_rows;
}
function error() {
return $this->link->error;
}
function errno() {
return $this->link->errno;
}
function result($query, $row) {
if(!$query || $query->num_rows == 0) {
return null;
}
$query->data_seek($row);
$assocs = $query->fetch_row();
return $assocs[0];
}
function num_rows($query) {
$query = $query ? $query->num_rows : 0;
return $query;
}
function num_fields($query) {
return $query ? $query->field_count : 0;
}
function free_result($query) {
return $query ? $query->free() : false;
}
function insert_id() {
return ($id = $this->link->insert_id) >= 0 ? $id : $this->result($this->query("SELECT last_insert_id()"), 0);
}
function fetch_row($query) {
$query = $query ? $query->fetch_row() : null;
return $query;
}
function fetch_fields($query) {
return $query ? $query->fetch_field() : null;
}
function version() {
return $this->link->server_info;
}
function escape_string($str) {
return $this->link->escape_string($str);
}
function close() {
return $this->link->close();
}
function parse_query($sql, $key = array(), $value = array()) {
$list = '';
$array = array();
if(strpos($sql, '?')) {
foreach ($key as $k => $v) {
if(in_array($v, array('i', 'd', 's', 'b'))) {
$list .= $v;
$array = array_merge($array, (array)$value[$k]);
}
}
} else {
preg_match_all("/:([A-Za-z0-9]*?)( |$)/", $sql, $matches);
foreach ($matches[1] as $match) {
if(in_array($key[$match], array('i', 'd', 's', 'b'))) {
$list .= $key[$match];
$array = array_merge($array, (array)$value[$match]);
$sql = str_replace(":".$match, "?", $sql);
}
}
}
return array($sql, array_merge((array)$list, $array));
}
function halt($message = '', $sql = '') {
$error = $this->error();
$errorno = $this->errno();
if($errorno == 2006 && $this->goneaway-- > 0) {
$this->connect($this->dbhost, $this->dbuser, $this->dbpw, $this->dbname, $this->dbcharset, $this->pconnect, $this->tablepre, $this->time);
$this->query($sql);
} else {
$s = '';
if($message) {
$s = "<b>UCenter info:</b> $message<br />";
}
if($sql) {
$s .= '<b>SQL:</b>'.htmlspecialchars($sql).'<br />';
}
$s .= '<b>Error:</b>'.$error.'<br />';
$s .= '<b>Errno:</b>'.$errorno.'<br />';
$s = str_replace(UC_DBTABLEPRE, '[Table]', $s);
exit($s);
}
}
}
?>

1
uc_server/lib/index.htm Normal file
View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,443 @@
<?php
/*
[Discuz!] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: seccode.class.php 1164 2014-10-31 06:58:24Z hypowang $
*/
class seccode {
var $code; //100000-999999 <20><>Χ<EFBFBD><CEA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
var $type = 0; //0 Ӣ<><D3A2>ͼƬ<CDBC><C6AC>֤<EFBFBD><D6A4> 1 <20><><EFBFBD><EFBFBD>ͼƬ<CDBC><C6AC>֤<EFBFBD><D6A4> 2 Flash <20><>֤<EFBFBD><D6A4> 3 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><D6A4>
var $width = 0;
var $height = 0;
var $background = 1;
var $adulterate = 1;
var $ttf = 0;
var $angle = 0;
var $color = 1;
var $size = 0;
var $shadow = 1;
var $animator = 0; //GIF <20><><EFBFBD><EFBFBD>
var $fontpath = ''; //TTF <20>ֿ<EFBFBD>Ŀ¼
var $datapath = '';
var $includepath= '';
var $fontcolor;
var $im;
static function seccode_check($code, $input) {
if ($code == '' || $input == '') {
return false;
}
self::seccodeconvert($code);
return $input === $code;
}
static function seccodeconvert(&$seccode) {
$s = sprintf('%04s', base_convert($seccode, 10, 20));
$seccodeunits = 'CEFHKLMNOPQRSTUVWXYZ';
$seccode = '';
for($i = 0; $i < 4; $i++) {
$unit = ord($s[$i]);
$seccode .= ($unit >= 0x30 && $unit <= 0x39) ? $seccodeunits[$unit - 0x30] : $seccodeunits[$unit - 0x57];
}
}
function display() {
$this->type == 2 && !extension_loaded('ming') && $this->type = 0;
$this->width = $this->width >= 0 && $this->width <= 200 ? $this->width : 150;
$this->height = $this->height >= 0 && $this->height <= 80 ? $this->height : 60;
self::seccodeconvert($this->code);
if($this->type < 2 && function_exists('imagecreate') && function_exists('imagecolorset') && function_exists('imagecopyresized') &&
function_exists('imagecolorallocate') && function_exists('imagechar') && function_exists('imagecolorsforindex') &&
function_exists('imageline') && function_exists('imagecreatefromstring') && (function_exists('imagegif') || function_exists('imagepng') || function_exists('imagejpeg'))) {
$this->image();
} elseif($this->type == 2 && extension_loaded('ming')) {
$this->flash();
} elseif($this->type == 3) {
$this->audio();
} else {
$this->bitmap();
}
}
function fileext($filename) {
return trim(substr(strrchr($filename, '.'), 1, 10));
}
function image() {
$bgcontent = $this->background();
if($this->animator == 1 && function_exists('imagegif')) {
include_once $this->includepath.'gifmerge.class.php';
$trueframe = mt_rand(1, 9);
for($i = 0; $i <= 9; $i++) {
$this->im = imagecreatefromstring($bgcontent);
$x[$i] = $y[$i] = 0;
$this->adulterate && $this->adulterate();
if($i == $trueframe) {
$this->ttf && function_exists('imagettftext') || $this->type == 1 ? $this->ttffont() : $this->giffont();
$d[$i] = mt_rand(250, 400);
} else {
$this->adulteratefont();
$d[$i] = mt_rand(5, 15);
}
ob_start();
imagegif($this->im);
imagedestroy($this->im);
$frame[$i] = ob_get_contents();
ob_end_clean();
}
$anim = new GifMerge($frame, 255, 255, 255, 0, $d, $x, $y, 'C_MEMORY');
header('Content-type: image/gif');
echo $anim->getAnimation();
} else {
$this->im = imagecreatefromstring($bgcontent);
$this->adulterate && $this->adulterate();
$this->ttf && function_exists('imagettftext') || $this->type == 1 ? $this->ttffont() : $this->giffont();
if(function_exists('imagepng')) {
header('Content-type: image/png');
imagepng($this->im);
} else {
header('Content-type: image/jpeg');
imagejpeg($this->im, '', 100);
}
imagedestroy($this->im);
}
}
function background() {
$this->im = imagecreatetruecolor($this->width, $this->height);
$backgroundcolor = imagecolorallocate($this->im, 255, 255, 255);
$backgrounds = $c = array();
if($this->background && function_exists('imagecreatefromjpeg') && function_exists('imagecolorat') && function_exists('imagecopymerge') &&
function_exists('imagesetpixel') && function_exists('imageSX') && function_exists('imageSY')) {
if($handle = @opendir($this->datapath.'background/')) {
while($bgfile = @readdir($handle)) {
if(preg_match('/\.jpg$/i', $bgfile)) {
$backgrounds[] = $this->datapath.'background/'.$bgfile;
}
}
@closedir($handle);
}
if($backgrounds) {
$imwm = imagecreatefromjpeg($backgrounds[array_rand($backgrounds)]);
$colorindex = imagecolorat($imwm, 0, 0);
$this->c = imagecolorsforindex($imwm, $colorindex);
$colorindex = imagecolorat($imwm, 1, 0);
imagesetpixel($imwm, 0, 0, $colorindex);
$c[0] = $c['red'];$c[1] = $c['green'];$c[2] = $c['blue'];
imagecopymerge($this->im, $imwm, 0, 0, mt_rand(0, 200 - $this->width), mt_rand(0, 80 - $this->height), imageSX($imwm), imageSY($imwm), 100);
imagedestroy($imwm);
}
}
if(!$this->background || !$backgrounds) {
for($i = 0;$i < 3;$i++) {
$start[$i] = mt_rand(200, 255);$end[$i] = mt_rand(100, 150);$step[$i] = ($end[$i] - $start[$i]) / $this->width;$c[$i] = $start[$i];
}
for($i = 0;$i < $this->width;$i++) {
$color = imagecolorallocate($this->im, $c[0], $c[1], $c[2]);
imageline($this->im, $i, 0, $i-(isset($angle) ? $angle : 0), $this->height, $color);
$c[0] += $step[0];$c[1] += $step[1];$c[2] += $step[2];
}
$c[0] -= 20;$c[1] -= 20;$c[2] -= 20;
}
ob_start();
if(function_exists('imagepng')) {
imagepng($this->im);
} else {
imagejpeg($this->im, '', 100);
}
imagedestroy($this->im);
$bgcontent = ob_get_contents();
ob_end_clean();
$this->fontcolor = $c;
return $bgcontent;
}
function adulterate() {
$linenums = $this->height / 10;
for($i=0; $i <= $linenums; $i++) {
$color = $this->color ? imagecolorallocate($this->im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)) : imagecolorallocate($this->im, $this->fontcolor[0], $this->fontcolor[1], $this->fontcolor[2]);
$x = mt_rand(0, $this->width);
$y = mt_rand(0, $this->height);
if(mt_rand(0, 1)) {
imagearc($this->im, $x, $y, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, 360), mt_rand(0, 360), $color);
} else {
$linemaxlong = isset($linemaxlong) ? $linemaxlong : 0;
$linex = isset($linex) ? $linex : 0;
$liney = isset($liney) ? $liney : 0;
imageline($this->im, $x, $y, $linex + mt_rand(0, $linemaxlong), $liney + mt_rand(0, mt_rand($this->height, $this->width)), $color);
}
}
}
function adulteratefont() {
$seccodeunits = 'BCEFGHJKMPQRTVWXY2346789';
$x = $this->width / 4;
$y = $this->height / 10;
$text_color = imagecolorallocate($this->im, $this->fontcolor[0], $this->fontcolor[1], $this->fontcolor[2]);
for($i = 0; $i <= 3; $i++) {
$adulteratecode = $seccodeunits[mt_rand(0, 23)];
imagechar($this->im, 5, $x * $i + mt_rand(0, $x - 10), mt_rand($y, $this->height - 10 - $y), $adulteratecode, $text_color);
}
}
function ttffont() {
$seccode = $this->code;
$charset = isset($GLOBALS['charset']) ? $GLOBALS['charset'] : '';
$seccoderoot = $this->type ? $this->fontpath.'ch/' : $this->fontpath.'en/';
$dirs = opendir($seccoderoot);
$seccodettf = array();
while($entry = readdir($dirs)) {
if($entry != '.' && $entry != '..' && in_array(strtolower($this->fileext($entry)), array('ttf', 'ttc'))) {
$seccodettf[] = $entry;
}
}
if(empty($seccodettf)) {
$this->giffont();
return;
}
$seccodelength = 4;
if($this->type && !empty($seccodettf)) {
if(strtoupper($charset) != 'UTF-8') {
include $this->includepath.'chinese.class.php';
$cvt = new Chinese($charset, 'utf8');
$seccode = $cvt->Convert($seccode);
}
$seccode = array(substr($seccode, 0, 3), substr($seccode, 3, 3));
$seccodelength = 2;
}
$widthtotal = 0;
for($i = 0; $i < $seccodelength; $i++) {
$font[$i]['font'] = $seccoderoot.$seccodettf[array_rand($seccodettf)];
$font[$i]['angle'] = $this->angle ? mt_rand(-30, 30) : 0;
$font[$i]['size'] = $this->type ? $this->width / 7 : $this->width / 6;
$this->size && $font[$i]['size'] = mt_rand($font[$i]['size'] - $this->width / 40, $font[$i]['size'] + $this->width / 20);
$box = imagettfbbox($font[$i]['size'], 0, $font[$i]['font'], $seccode[$i]);
$font[$i]['zheight'] = max($box[1], $box[3]) - min($box[5], $box[7]);
$box = imagettfbbox($font[$i]['size'], $font[$i]['angle'], $font[$i]['font'], $seccode[$i]);
$font[$i]['height'] = max($box[1], $box[3]) - min($box[5], $box[7]);
$font[$i]['hd'] = $font[$i]['height'] - $font[$i]['zheight'];
$font[$i]['width'] = (max($box[2], $box[4]) - min($box[0], $box[6])) + mt_rand(0, $this->width / 8);
$font[$i]['width'] = $font[$i]['width'] > $this->width / $seccodelength ? $this->width / $seccodelength : $font[$i]['width'];
$widthtotal += $font[$i]['width'];
}
$x = mt_rand($font[0]['angle'] > 0 ? cos(deg2rad(90 - $font[0]['angle'])) * $font[0]['zheight'] : 1, $this->width - $widthtotal > 2 ? $this->width - $widthtotal : 2);
!$this->color && $text_color = imagecolorallocate($this->im, $this->fontcolor[0], $this->fontcolor[1], $this->fontcolor[2]);
for($i = 0; $i < $seccodelength; $i++) {
if($this->color) {
$this->fontcolor = array(mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
$this->shadow && $text_shadowcolor = imagecolorallocate($this->im, 255 - $this->fontcolor[0], 255 - $this->fontcolor[1], 255 - $this->fontcolor[2]);
$text_color = imagecolorallocate($this->im, $this->fontcolor[0], $this->fontcolor[1], $this->fontcolor[2]);
} elseif($this->shadow) {
$text_shadowcolor = imagecolorallocate($this->im, 255 - $this->fontcolor[0], 255 - $this->fontcolor[1], 255 - $this->fontcolor[2]);
}
$y = $font[0]['angle'] > 0 ? mt_rand($font[$i]['height'], $this->height) : mt_rand($font[$i]['height'] - $font[$i]['hd'], $this->height - $font[$i]['hd']);
$this->shadow && imagettftext($this->im, $font[$i]['size'], $font[$i]['angle'], $x + 1, $y + 1, $text_shadowcolor, $font[$i]['font'], $seccode[$i]);
imagettftext($this->im, $font[$i]['size'], $font[$i]['angle'], $x, $y, $text_color, $font[$i]['font'], $seccode[$i]);
$x += $font[$i]['width'];
}
}
function giffont() {
$seccode = $this->code;
$seccodedir = array();
if(function_exists('imagecreatefromgif')) {
$seccoderoot = $this->datapath.'gif/';
$dirs = opendir($seccoderoot);
while($dir = readdir($dirs)) {
if($dir != '.' && $dir != '..' && file_exists($seccoderoot.$dir.'/9.gif')) {
$seccodedir[] = $dir;
}
}
}
$widthtotal = 0;
for($i = 0; $i <= 3; $i++) {
$this->imcodefile = $seccodedir ? $seccoderoot.$seccodedir[array_rand($seccodedir)].'/'.strtolower($seccode[$i]).'.gif' : '';
if(!empty($this->imcodefile) && file_exists($this->imcodefile)) {
$font[$i]['file'] = $this->imcodefile;
$font[$i]['data'] = getimagesize($this->imcodefile);
$font[$i]['width'] = $font[$i]['data'][0] + mt_rand(0, 6) - 4;
$font[$i]['height'] = $font[$i]['data'][1] + mt_rand(0, 6) - 4;
$font[$i]['width'] += mt_rand(0, $this->width / 5 - $font[$i]['width']);
$widthtotal += $font[$i]['width'];
} else {
$font[$i]['file'] = '';
$font[$i]['width'] = 8 + mt_rand(0, $this->width / 5 - 5);
$widthtotal += $font[$i]['width'];
}
}
$x = mt_rand(1, $this->width - $widthtotal);
for($i = 0; $i <= 3; $i++) {
$this->color && $this->fontcolor = array(mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
if($font[$i]['file']) {
$this->imcode = imagecreatefromgif($font[$i]['file']);
if($this->size) {
$font[$i]['width'] = mt_rand($font[$i]['width'] - $this->width / 20, $font[$i]['width'] + $this->width / 20);
$font[$i]['height'] = mt_rand($font[$i]['height'] - $this->width / 20, $font[$i]['height'] + $this->width / 20);
}
$y = mt_rand(0, $this->height - $font[$i]['height']);
if($this->shadow) {
$this->imcodeshadow = $this->imcode;
imagecolorset($this->imcodeshadow, 0 , 255 - $this->fontcolor[0], 255 - $this->fontcolor[1], 255 - $this->fontcolor[2]);
imagecopyresized($this->im, $this->imcodeshadow, $x + 1, $y + 1, 0, 0, $font[$i]['width'], $font[$i]['height'], $font[$i]['data'][0], $font[$i]['data'][1]);
}
imagecolorset($this->imcode, 0 , $this->fontcolor[0], $this->fontcolor[1], $this->fontcolor[2]);
imagecopyresized($this->im, $this->imcode, $x, $y, 0, 0, $font[$i]['width'], $font[$i]['height'], $font[$i]['data'][0], $font[$i]['data'][1]);
} else {
$y = mt_rand(0, $this->height - 20);
if($this->shadow) {
$text_shadowcolor = imagecolorallocate($this->im, 255 - $this->fontcolor[0], 255 - $this->fontcolor[1], 255 - $this->fontcolor[2]);
imagechar($this->im, 5, $x + 1, $y + 1, $seccode[$i], $text_shadowcolor);
}
$text_color = imagecolorallocate($this->im, $this->fontcolor[0], $this->fontcolor[1], $this->fontcolor[2]);
imagechar($this->im, 5, $x, $y, $seccode[$i], $text_color);
}
$x += $font[$i]['width'];
}
}
function flash() {
$spacing = 5;
$codewidth = ($this->width - $spacing * 5) / 4;
$strforswdaction = '';
for($i = 0; $i <= 3; $i++) {
$strforswdaction .= $this->swfcode($codewidth, $spacing, $this->code[$i], $i+1);
}
ming_setScale(20.00000000);
ming_useswfversion(6);
$movie = new SWFMovie();
$movie->setDimension($this->width, $this->height);
$movie->setBackground(255, 255, 255);
$movie->setRate(31);
$fontcolor = '0x'.(sprintf('%02s', dechex (mt_rand(0, 255)))).(sprintf('%02s', dechex (mt_rand(0, 128)))).(sprintf('%02s', dechex (mt_rand(0, 255))));
$strAction = "
_root.createEmptyMovieClip ( 'triangle', 1 );
with ( _root.triangle ) {
lineStyle( 3, $fontcolor, 100 );
$strforswdaction
}
";
$movie->add(new SWFAction( str_replace("\r", "", $strAction) ));
header('Content-type: application/x-shockwave-flash');
$movie->output();
}
function swfcode($width, $d, $code, $order) {
$str = '';
$height = $this->height - $d * 2;
$x_0 = ($order * ($width + $d) - $width);
$x_1 = $x_0 + $width / 2;
$x_2 = $x_0 + $width;
$y_0 = $d;
$y_2 = $y_0 + $height;
$y_1 = $y_2 / 2;
$y_0_5 = $y_2 / 4;
$y_1_5 = $y_1 + $y_0_5;
switch($code) {
case 'B':$str .= 'moveTo('.$x_1.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_1.', '.$y_2.');lineTo('.$x_2.', '.$y_1_5.');lineTo('.$x_1.', '.$y_1.');lineTo('.$x_2.', '.$y_0_5.');lineTo('.$x_1.', '.$y_0.');moveTo('.$x_0.', '.$y_1.');lineTo('.$x_1.', '.$y_1.');';break;
case 'C':$str .= 'moveTo('.$x_2.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_2.', '.$y_2.');';break;
case 'E':$str .= 'moveTo('.$x_2.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_2.', '.$y_2.');moveTo('.$x_0.', '.$y_1.');lineTo('.$x_1.', '.$y_1.');';break;
case 'F':$str .= 'moveTo('.$x_2.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');moveTo('.$x_0.', '.$y_1.');lineTo('.$x_1.', '.$y_1.');';break;
case 'G':$str .= 'moveTo('.$x_2.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_2.', '.$y_2.');lineTo('.$x_2.', '.$y_1.');lineTo('.$x_1.', '.$y_1.');';break;
case 'H':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');moveTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');moveTo('.$x_0.', '.$y_1.');lineTo('.$x_2.', '.$y_1.');';break;
case 'J':$str .= 'moveTo('.$x_1.', '.$y_0.');lineTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_0.', '.$y_1_5.');';break;
case 'K':$str .= 'moveTo('.$x_2.', '.$y_0.');lineTo('.$x_1.', '.$y_1.');lineTo('.$x_0.', '.$y_1.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');moveTo('.$x_1.', '.$y_1.');lineTo('.$x_2.', '.$y_2.');';break;
case 'M':$str .= 'moveTo('.$x_0.', '.$y_2.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_1.', '.$y_1.');lineTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');';break;
case 'P':$str .= 'moveTo('.$x_0.', '.$y_1.');lineTo('.$x_1.', '.$y_1.');lineTo('.$x_2.', '.$y_0_5.');lineTo('.$x_1.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');';break;
case 'Q':$str .= 'moveTo('.$x_2.', '.$y_2.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');lineTo('.$x_1.', '.$y_1.');';break;
case 'R':$str .= 'moveTo('.$x_0.', '.$y_1.');lineTo('.$x_1.', '.$y_1.');lineTo('.$x_2.', '.$y_0_5.');lineTo('.$x_1.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');moveTo('.$x_1.', '.$y_1.');lineTo('.$x_2.', '.$y_2.');';break;
case 'T':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_2.', '.$y_0.');moveTo('.$x_1.', '.$y_0.');lineTo('.$x_1.', '.$y_2.');';break;
case 'V':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_1.', '.$y_2.');lineTo('.$x_2.', '.$y_0.');';break;
case 'W':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_1.', '.$y_1.');lineTo('.$x_2.', '.$y_2.');lineTo('.$x_2.', '.$y_0.');';break;
case 'X':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');moveTo('.$x_2.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');';break;
case 'Y':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_1.', '.$y_1.');lineTo('.$x_2.', '.$y_0.');moveTo('.$x_1.', '.$y_1.');lineTo('.$x_1.', '.$y_2.');';break;
case '2':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_1.');lineTo('.$x_0.', '.$y_1.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_2.', '.$y_2.');';break;
case '3':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');lineTo('.$x_0.', '.$y_2.');moveTo('.$x_0.', '.$y_1.');lineTo('.$x_2.', '.$y_1.');';break;
case '4':$str .= 'moveTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');moveTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_1.');lineTo('.$x_2.', '.$y_1.');';break;
case '6':$str .= 'moveTo('.$x_2.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_2.', '.$y_2.');lineTo('.$x_2.', '.$y_1.');lineTo('.$x_0.', '.$y_1.');';break;
case '7':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');';break;
case '8':$str .= 'moveTo('.$x_0.', '.$y_0.');lineTo('.$x_0.', '.$y_2.');lineTo('.$x_2.', '.$y_2.');lineTo('.$x_2.', '.$y_0.');lineTo('.$x_0.', '.$y_0.');moveTo('.$x_0.', '.$y_1.');lineTo('.$x_2.', '.$y_1.');';break;
case '9':$str .= 'moveTo('.$x_2.', '.$y_1.');lineTo('.$x_0.', '.$y_1.');lineTo('.$x_0.', '.$y_0.');lineTo('.$x_2.', '.$y_0.');lineTo('.$x_2.', '.$y_2.');lineTo('.$x_0.', '.$y_2.');';break;
}
return $str;
}
function audio() {
header('Content-type: audio/mpeg');
for($i = 0;$i <= 3; $i++) {
readfile($this->datapath.'sound/'.strtolower($this->code[$i]).'.mp3');
}
}
function bitmap() {
$numbers = array
(
'B' => array('00','fc','66','66','66','7c','66','66','fc','00'),
'C' => array('00','38','64','c0','c0','c0','c4','64','3c','00'),
'E' => array('00','fe','62','62','68','78','6a','62','fe','00'),
'F' => array('00','f8','60','60','68','78','6a','62','fe','00'),
'G' => array('00','78','cc','cc','de','c0','c4','c4','7c','00'),
'H' => array('00','e7','66','66','66','7e','66','66','e7','00'),
'J' => array('00','f8','cc','cc','cc','0c','0c','0c','7f','00'),
'K' => array('00','f3','66','66','7c','78','6c','66','f7','00'),
'M' => array('00','f7','63','6b','6b','77','77','77','e3','00'),
'P' => array('00','f8','60','60','7c','66','66','66','fc','00'),
'Q' => array('00','78','cc','cc','cc','cc','cc','cc','78','00'),
'R' => array('00','f3','66','6c','7c','66','66','66','fc','00'),
'T' => array('00','78','30','30','30','30','b4','b4','fc','00'),
'V' => array('00','1c','1c','36','36','36','63','63','f7','00'),
'W' => array('00','36','36','36','77','7f','6b','63','f7','00'),
'X' => array('00','f7','66','3c','18','18','3c','66','ef','00'),
'Y' => array('00','7e','18','18','18','3c','24','66','ef','00'),
'2' => array('fc','c0','60','30','18','0c','cc','cc','78','00'),
'3' => array('78','8c','0c','0c','38','0c','0c','8c','78','00'),
'4' => array('00','3e','0c','fe','4c','6c','2c','3c','1c','1c'),
'6' => array('78','cc','cc','cc','ec','d8','c0','60','3c','00'),
'7' => array('30','30','38','18','18','18','1c','8c','fc','00'),
'8' => array('78','cc','cc','cc','78','cc','cc','cc','78','00'),
'9' => array('f0','18','0c','6c','dc','cc','cc','cc','78','00')
);
foreach($numbers as $i => $number) {
for($j = 0; $j < 6; $j++) {
$a1 = substr('012', mt_rand(0, 2), 1).substr('012345', mt_rand(0, 5), 1);
$a2 = substr('012345', mt_rand(0, 5), 1).substr('0123', mt_rand(0, 3), 1);
mt_rand(0, 1) == 1 ? array_push($numbers[$i], $a1) : array_unshift($numbers[$i], $a1);
mt_rand(0, 1) == 0 ? array_push($numbers[$i], $a1) : array_unshift($numbers[$i], $a2);
}
}
$bitmap = array();
for($i = 0; $i < 20; $i++) {
for($j = 0; $j <= 3; $j++) {
$bytes = $numbers[$this->code[$j]][$i];
$a = mt_rand(0, 14);
array_push($bitmap, $bytes);
}
}
for($i = 0; $i < 8; $i++) {
$a = substr('012345', mt_rand(0, 2), 1) . substr('012345', mt_rand(0, 5), 1);
array_unshift($bitmap, $a);
array_push($bitmap, $a);
}
$image = pack('H*', '424d9e000000000000003e000000280000002000000018000000010001000000'.
'0000600000000000000000000000000000000000000000000000FFFFFF00'.implode('', $bitmap));
header('Content-Type: image/bmp');
echo $image;
}
}
?>

View File

@@ -0,0 +1,146 @@
<?php
/*
[UCenter] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: sendmail.inc.php 1124 2011-12-06 11:03:23Z svn_project_zhangjie $
*/
!defined('IN_UC') && exit('Access Denied');
if($mail_setting['mailsilent']) {
error_reporting(0);
}
$maildelimiter = $mail_setting['maildelimiter'] == 1 ? "\r\n" : ($mail_setting['maildelimiter'] == 2 ? "\r" : "\n");
$mailusername = isset($mail_setting['mailusername']) ? $mail_setting['mailusername'] : 1;
$appname = $this->base->cache['apps'][$mail['appid']]['name'];
$mail['subject'] = '=?'.$mail['charset'].'?B?'.base64_encode(str_replace("\r", '', str_replace("\n", '', '['.$appname.'] '.$mail['subject']))).'?=';
$mail['message'] = chunk_split(base64_encode(str_replace("\r\n.", " \r\n..", str_replace("\n", "\r\n", str_replace("\r", "\n", str_replace("\r\n", "\n", str_replace("\n\r", "\r", $mail['message'])))))));
$email_from = $mail['frommail'] == '' ? '=?'.$mail['charset'].'?B?'.base64_encode($appname)."?= <{$mail_setting['maildefault']}>" : (preg_match('/^(.+?) \<(.+?)\>$/',$email_from, $from) ? '=?'.$mail['charset'].'?B?'.base64_encode($from[1])."?= <$from[2]>" : $mail['frommail']);
foreach(explode(',', $mail['email_to']) as $touser) {
$tousers[] = preg_match('/^(.+?) \<(.+?)\>$/',$touser, $to) ? ($mailusername ? '=?'.$mail['charset'].'?B?'.base64_encode($to[1])."?= <$to[2]>" : $to[2]) : $touser;
}
$tousers = is_array($tousers) ? $tousers : array($tousers);
$mail['email_to'] = implode(',', $tousers);
$headers = "From: $email_from{$maildelimiter}X-Priority: 3{$maildelimiter}X-Mailer: Discuz! $version{$maildelimiter}MIME-Version: 1.0{$maildelimiter}Content-type: text/".($mail['htmlon'] ? 'html' : 'plain')."; charset={$mail['charset']}{$maildelimiter}Content-Transfer-Encoding: base64{$maildelimiter}";
$mail_setting['mailport'] = $mail_setting['mailport'] ? $mail_setting['mailport'] : 25;
$mail_setting['mailtimeout'] = isset($mail_setting['mailtimeout']) && strlen($mail_setting['mailtimeout']) ? intval($mail_setting['mailtimeout']) : 30;
if($mail_setting['mailsend'] == 1 && function_exists('mail')) {
return @mail($mail['email_to'], $mail['subject'], $mail['message'], $headers);
} elseif($mail_setting['mailsend'] == 2) {
if(!$fp = fsocketopen($mail_setting['mailserver'], $mail_setting['mailport'], $errno, $errstr, $mail_setting['mailtimeout'])) {
return false;
}
stream_set_blocking($fp, true);
stream_set_timeout($fp, $mail_setting['mailtimeout']);
$lastmessage = fgets($fp, 512);
if(substr($lastmessage, 0, 3) != '220') {
return false;
}
fputs($fp, ($mail_setting['mailauth'] ? 'EHLO' : 'HELO')." discuz\r\n");
$lastmessage = fgets($fp, 512);
if(substr($lastmessage, 0, 3) != 220 && substr($lastmessage, 0, 3) != 250) {
return false;
}
while(1) {
if(substr($lastmessage, 3, 1) != '-' || empty($lastmessage)) {
break;
}
$lastmessage = fgets($fp, 512);
}
if($mail_setting['mailauth']) {
fputs($fp, "AUTH LOGIN\r\n");
$lastmessage = fgets($fp, 512);
if(substr($lastmessage, 0, 3) != 334) {
return false;
}
fputs($fp, base64_encode($mail_setting['mailauth_username'])."\r\n");
$lastmessage = fgets($fp, 512);
if(substr($lastmessage, 0, 3) != 334) {
return false;
}
fputs($fp, base64_encode($mail_setting['mailauth_password'])."\r\n");
$lastmessage = fgets($fp, 512);
if(substr($lastmessage, 0, 3) != 235) {
return false;
}
$email_from = $mail_setting['mailfrom'];
}
fputs($fp, "MAIL FROM: <".preg_replace("/.*\<(.+?)\>.*/", "\\1", $email_from).">\r\n");
$lastmessage = fgets($fp, 512);
if(substr($lastmessage, 0, 3) != 250) {
fputs($fp, "MAIL FROM: <".preg_replace("/.*\<(.+?)\>.*/", "\\1", $email_from).">\r\n");
$lastmessage = fgets($fp, 512);
if(substr($lastmessage, 0, 3) != 250) {
return false;
}
}
$email_tos = array();
foreach(explode(',', $mail['email_to']) as $touser) {
$touser = trim($touser);
if($touser) {
fputs($fp, "RCPT TO: <".preg_replace("/.*\<(.+?)\>.*/", "\\1", $touser).">\r\n");
$lastmessage = fgets($fp, 512);
if(substr($lastmessage, 0, 3) != 250) {
fputs($fp, "RCPT TO: <".preg_replace("/.*\<(.+?)\>.*/", "\\1", $touser).">\r\n");
$lastmessage = fgets($fp, 512);
return false;
}
}
}
fputs($fp, "DATA\r\n");
$lastmessage = fgets($fp, 512);
if(substr($lastmessage, 0, 3) != 354) {
return false;
}
$headers .= 'Message-ID: <'.gmdate('YmdHs').'.'.substr(md5($mail['message'].microtime()), 0, 6).rand(100000, 999999).'@'.$_SERVER['HTTP_HOST'].">{$maildelimiter}";
fputs($fp, "Date: ".gmdate('r')."\r\n");
fputs($fp, "To: ".$mail['email_to']."\r\n");
fputs($fp, "Subject: ".$mail['subject']."\r\n");
fputs($fp, $headers."\r\n");
fputs($fp, "\r\n\r\n");
fputs($fp, "{$mail['message']}\r\n.\r\n");
$lastmessage = fgets($fp, 512);
if(substr($lastmessage, 0, 3) != 250) {
return false;
}
fputs($fp, "QUIT\r\n");
return true;
} elseif($mail_setting['mailsend'] == 3) {
ini_set('SMTP', $mail_setting['mailserver']);
ini_set('smtp_port', $mail_setting['mailport']);
ini_set('sendmail_from', $email_from);
return @mail($mail['email_to'], $mail['subject'], $mail['message'], $headers);
}
?>

View File

@@ -0,0 +1,199 @@
<?php
/*
[UCenter] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: template.class.php 1167 2014-11-03 03:06:21Z hypowang $
*/
class template {
var $tpldir;
var $objdir;
var $tplfile;
var $objfile;
var $langfile;
var $vars;
var $force = 0;
var $var_regexp = "\@?\\\$[a-zA-Z_]\w*(?:\[[\w\.\"\'\[\]\$]+\])*";
var $vtag_regexp = "\<\?=(\@?\\\$[a-zA-Z_]\w*(?:\[[\w\.\"\'\[\]\$]+\])*)\?\>";
var $const_regexp = "\{([\w]+)\}";
var $languages = array();
var $sid;
function __construct() {
$this->template();
}
function template() {
ob_start();
$this->defaulttpldir = UC_ROOT.'./view/default';
$this->tpldir = UC_ROOT.'./view/default';
$this->objdir = UC_DATADIR.'./view';
$this->langfile = UC_ROOT.'./view/default/templates.lang.php';
if (version_compare(PHP_VERSION, '5') == -1) {
register_shutdown_function(array(&$this, '__destruct'));
}
}
function assign($k, $v) {
$this->vars[$k] = $v;
}
function display($file) {
extract($this->vars, EXTR_SKIP);
include $this->gettpl($file);
}
function gettpl($file) {
isset($_REQUEST['inajax']) && ($file == 'header' || $file == 'footer') && $file = $file.'_ajax';
isset($_REQUEST['inajax']) && ($file == 'admin_header' || $file == 'admin_footer') && $file = substr($file, 6).'_ajax';
$this->tplfile = $this->tpldir.'/'.$file.'.htm';
$this->objfile = $this->objdir.'/'.$file.'.php';
$tplfilemtime = @filemtime($this->tplfile);
if($tplfilemtime === FALSE) {
$this->tplfile = $this->defaulttpldir.'/'.$file.'.htm';
}
if($this->force || !file_exists($this->objfile) || @filemtime($this->objfile) < filemtime($this->tplfile)) {
if(empty($this->language)) {
@include $this->langfile;
if(is_array($languages)) {
$this->languages += $languages;
}
}
$this->complie();
}
return $this->objfile;
}
function complie() {
$template = file_get_contents($this->tplfile);
$template = preg_replace("/\<\!\-\-\{(.+?)\}\-\-\>/s", "{\\1}", $template);
$template = preg_replace_callback("/\{lang\s+(\w+?)\}/is", array($this, 'complie_callback_lang_1'), $template);
$template = preg_replace("/\{($this->var_regexp)\}/", "<?=\\1?>", $template);
$template = preg_replace("/\{($this->const_regexp)\}/", "<?=\\1?>", $template);
$template = preg_replace("/(?<!\<\?\=|\\\\)$this->var_regexp/", "<?=\\0?>", $template);
$template = preg_replace_callback("/\<\?=(\@?\\\$[a-zA-Z_]\w*)((\[[\\$\[\]\w]+\])+)\?\>/is", array($this, 'complie_callback_arrayindex_12'), $template);
$template = preg_replace_callback("/\{\{eval (.*?)\}\}/is", array($this, 'complie_callback_stripvtag_1'), $template);
$template = preg_replace_callback("/\{eval (.*?)\}/is", array($this, 'complie_callback_stripvtag_1'), $template);
$template = preg_replace_callback("/\{for (.*?)\}/is", array($this, 'complie_callback_stripvtag_for1'), $template);
$template = preg_replace_callback("/\{elseif\s+(.+?)\}/is", array($this, 'complie_callback_stripvtag_elseif1'), $template);
for($i=0; $i<2; $i++) {
$template = preg_replace_callback("/\{loop\s+$this->vtag_regexp\s+$this->vtag_regexp\s+$this->vtag_regexp\}(.+?)\{\/loop\}/is", array($this, 'complie_callback_loopsection_1234'), $template);
$template = preg_replace_callback("/\{loop\s+$this->vtag_regexp\s+$this->vtag_regexp\}(.+?)\{\/loop\}/is", array($this, 'complie_callback_loopsection_123'), $template);
}
$template = preg_replace_callback("/\{if\s+(.+?)\}/is", array($this, 'complie_callback_stripvtag_if1'), $template);
$template = preg_replace("/\{template\s+(\w+?)\}/is", "<? include \$this->gettpl('\\1');?>", $template);
$template = preg_replace_callback("/\{template\s+(.+?)\}/is", array($this, 'complie_callback_stripvtag_template1'), $template);
$template = preg_replace("/\{else\}/is", "<? } else { ?>", $template);
$template = preg_replace("/\{\/if\}/is", "<? } ?>", $template);
$template = preg_replace("/\{\/for\}/is", "<? } ?>", $template);
$template = preg_replace("/$this->const_regexp/", "<?=\\1?>", $template);
$template = "<? if(!defined('UC_ROOT')) exit('Access Denied');?>\r\n$template";
$template = preg_replace("/(\\\$[a-zA-Z_]\w+\[)([a-zA-Z_]\w+)\]/i", "\\1'\\2']", $template);
$template = preg_replace("/\<\?(\s{1})/is", "<?php\\1", $template);
$template = preg_replace("/\<\?\=(.+?)\?\>/is", "<?php echo \\1;?>", $template);
file_put_contents($this->objfile, $template, LOCK_EX);
}
function complie_callback_lang_1($matches) {
return $this->lang($matches[1]);
}
function complie_callback_arrayindex_12($matches) {
return $this->arrayindex($matches[1], $matches[2]);
}
function complie_callback_stripvtag_1($matches) {
return $this->stripvtag('<? '.$matches[1].'?>');
}
function complie_callback_stripvtag_for1($matches) {
return $this->stripvtag('<? for('.$matches[1].') {?>');
}
function complie_callback_stripvtag_elseif1($matches) {
return $this->stripvtag('<? } elseif('.$matches[1].') { ?>');
}
function complie_callback_loopsection_1234($matches) {
return $this->loopsection($matches[1], $matches[2], $matches[3], $matches[4]);
}
function complie_callback_loopsection_123($matches) {
return $this->loopsection($matches[1], '', $matches[2], $matches[3]);
}
function complie_callback_stripvtag_if1($matches) {
return $this->stripvtag('<? if('.$matches[1].') { ?>');
}
function complie_callback_stripvtag_template1($matches) {
return $this->stripvtag('<? include $this->gettpl('.$matches[1].'); ?>');
}
function arrayindex($name, $items) {
$items = preg_replace("/\[([a-zA-Z_]\w*)\]/is", "['\\1']", $items);
return "<?=$name$items?>";
}
function stripvtag($s) {
return preg_replace("/$this->vtag_regexp/is", "\\1", str_replace("\\\"", '"', $s));
}
function loopsection($arr, $k, $v, $statement) {
$arr = $this->stripvtag($arr);
$k = $this->stripvtag($k);
$v = $this->stripvtag($v);
$statement = str_replace("\\\"", '"', $statement);
return $k ? "<? foreach((array)$arr as $k => $v) {?>$statement<? }?>" : "<? foreach((array)$arr as $v) {?>$statement<? } ?>";
}
function lang($k) {
return !empty($this->languages[$k]) ? $this->languages[$k] : "{ $k }";
}
function _transsid($url, $tag = '', $wml = 0) {
$sid = $this->sid;
$tag = stripslashes($tag);
if(!$tag || (!preg_match("/^(https?:\/\/|mailto:|#|javascript)/i", $url) && !strpos($url, 'sid='))) {
if($pos = strpos($url, '#')) {
$urlret = substr($url, $pos);
$url = substr($url, 0, $pos);
} else {
$urlret = '';
}
$url .= (strpos($url, '?') ? ($wml ? '&amp;' : '&') : '?').'sid='.$sid.$urlret;
}
return $tag.$url;
}
function __destruct() {
$sid = rawurlencode($this->sid);
$content = preg_replace_callback("/\<a(\s*[^\>]+\s*)href\=([\"|\']?)([^\"\'\s]+)/is", array($this, 'destruct_callback_transsid_312'), ob_get_contents());
$content = preg_replace("/(\<form.+?\>)/is", "\\1\n<input type=\"hidden\" name=\"sid\" value=\"".rawurldecode(rawurldecode(rawurldecode($sid)))."\" />", $content);
ob_end_clean();
echo $content;
}
function destruct_callback_transsid_312($matches) {
return $this->_transsid($matches[3],'<a'.$matches[1].'href='.$matches[2]);
}
}

View File

@@ -0,0 +1,148 @@
<?php
/*
[UCenter] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: uccode.class.php 1139 2012-05-08 09:02:11Z liulanbo $
*/
class uccode {
var $uccodes;
function __construct() {
$this->uccode();
}
function uccode() {
$this->uccode = array(
'pcodecount' => -1,
'codecount' => 0,
'codehtml' => array()
);
}
function codedisp($code) {
$this->uccode['pcodecount']++;
$code = str_replace('\\"', '"', preg_replace("/^[\n\r]*(.+?)[\n\r]*$/is", "\\1", $code));
$this->uccode['codehtml'][$this->uccode['pcodecount']] = $this->tpl_codedisp($code);
$this->uccode['codecount']++;
return "[\tUCENTER_CODE_".$this->uccode['pcodecount']."\t]";
}
function complie($message) {
$message = dhtmlspecialchars($message);
if(strpos($message, '[/code]') !== FALSE) {
$message = preg_replace_callback("/\s*\[code\](.+?)\[\/code\]\s*/is", array($this, 'complie_callback_codedisp_1'), $message);
}
if(strpos($message, '[/url]') !== FALSE) {
$message = preg_replace_callback("/\[url(=((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|ed2k|thunder|synacast){1}:\/\/|www\.)([^\[\"']+?))?\](.+?)\[\/url\]/is", array($this, 'complie_callback_parseurl_15'), $message);
}
if(strpos($message, '[/email]') !== FALSE) {
$message = preg_replace_callback("/\[email(=([A-Za-z0-9\-_.+]+)@([A-Za-z0-9\-_]+[.][A-Za-z0-9\-_.]+))?\](.+?)\[\/email\]/is", array($this, 'complie_callback_parseemail_14'), $message);
}
$message = str_replace(array(
'[/color]', '[/size]', '[/font]', '[/align]', '[b]', '[/b]',
'[i]', '[/i]', '[u]', '[/u]', '[list]', '[list=1]', '[list=a]',
'[list=A]', '[*]', '[/list]', '[indent]', '[/indent]', '[/float]'
), array(
'</font>', '</font>', '</font>', '</p>', '<strong>', '</strong>', '<i>',
'</i>', '<u>', '</u>', '<ul>', '<ul type="1">', '<ul type="a">',
'<ul type="A">', '<li>', '</ul>', '<blockquote>', '</blockquote>', '</span>'
), preg_replace(array(
"/\[color=([#\w]+?)\]/i",
"/\[size=(\d+?)\]/i",
"/\[size=(\d+(\.\d+)?(px|pt|in|cm|mm|pc|em|ex|%)+?)\]/i",
"/\[font=([^\[\<]+?)\]/i",
"/\[align=(left|center|right)\]/i",
"/\[float=(left|right)\]/i"
), array(
"<font color=\"\\1\">",
"<font size=\"\\1\">",
"<font style=\"font-size: \\1\">",
"<font face=\"\\1 \">",
"<p align=\"\\1\">",
"<span style=\"float: \\1;\">"
), $message));
if(strpos($message, '[/quote]') !== FALSE) {
$message = preg_replace("/\s*\[quote\][\n\r]*(.+?)[\n\r]*\[\/quote\]\s*/is", $this->tpl_quote(), $message);
}
if(strpos($message, '[/img]') !== FALSE) {
$message = preg_replace_callback("/\[img\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/is", array($this, 'complie_callback_bbcodeurl_1'), $message);
$message = preg_replace_callback("/\[img=(\d{1,4})[x|\,](\d{1,4})\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/is", array($this, 'complie_callback_bbcodeurl_312'), $message);
}
for($i = 0; $i <= $this->uccode['pcodecount']; $i++) {
$message = str_replace("[\tUCENTER_CODE_$i\t]", $this->uccode['codehtml'][$i], $message);
}
return nl2br(str_replace(array("\t", ' ', ' '), array('&nbsp; &nbsp; &nbsp; &nbsp; ', '&nbsp; &nbsp;', '&nbsp;&nbsp;'), $message));
}
function complie_callback_codedisp_1($matches) {
return $this->codedisp($matches[1]);
}
function complie_callback_parseurl_15($matches) {
return $this->parseurl($matches[1], $matches[5]);
}
function complie_callback_parseemail_14($matches) {
return $this->parseemail($matches[1], $matches[4]);
}
function complie_callback_bbcodeurl_1($matches) {
return $this->bbcodeurl($matches[1], '<img src="%s" border="0" alt="" />');
}
function complie_callback_bbcodeurl_312($matches) {
return $this->bbcodeurl($matches[3], '<img width="'.$matches[1].'" height="'.$matches[2].'" src="%s" border="0" alt="" />');
}
function parseurl($url, $text) {
if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|ed2k|thunder|synacast){1}:\/\/|www\.)[^\[\"']+/i", trim($text), $matches)) {
$url = $matches[0];
$length = 65;
if(strlen($url) > $length) {
$text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));
}
return '<a href="'.(substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url).'" target="_blank">'.$text.'</a>';
} else {
$url = substr($url, 1);
if(substr(strtolower($url), 0, 4) == 'www.') {
$url = 'http://'.$url;
}
return '<a href="'.$url.'" target="_blank">'.$text.'</a>';
}
}
function parseemail($email, $text) {
$text = str_replace('\"', '"', $text);
if(!$email && preg_match("/\s*([A-Za-z0-9\-_.+]+)@([A-Za-z0-9\-_]+[.][A-Za-z0-9\-_.]+)\s*/i", $text, $matches)) {
$email = trim($matches[0]);
return '<a href="mailto:'.$email.'">'.$email.'</a>';
} else {
return '<a href="mailto:'.substr($email, 1).'">'.$text.'</a>';
}
}
function bbcodeurl($url, $tags) {
if(!preg_match("/<.+?>/s", $url)) {
if(!in_array(strtolower(substr($url, 0, 6)), array('http:/', 'https:', 'ftp://', 'rtsp:/', 'mms://'))) {
$url = 'http://'.$url;
}
return str_replace(array('submit', 'logging.php'), array('', ''), sprintf($tags, $url, addslashes($url)));
} else {
return '&nbsp;'.$url;
}
}
function tpl_codedisp($code) {
return '<div class="blockcode"><code id="code'.$this->uccodes['codecount'].'">'.$code.'</code></div>';
}
function tpl_quote() {
return '<div class="quote"><blockquote>\\1</blockquote></div>';
}
}
?>

View File

@@ -0,0 +1,88 @@
<?php
/*
[UCenter] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: ucip.class.php 803 2019-12-19 12:00:00Z community $
*/
class ucip {
function __construct() {
}
public static function validate_ip($ip) {
return filter_var($ip, FILTER_VALIDATE_IP) !== false;
}
public static function check_ip($requestIp, $ips)
{
if (!self::validate_ip($requestIp)) {
return false;
}
if (!\is_array($ips)) {
$ips = [$ips];
}
$method = substr_count($requestIp, ':') > 1 ? 'check_ip6' : 'check_ip4';
foreach ($ips as $ip) {
if (self::$method($requestIp, $ip)) {
return true;
}
}
return false;
}
public static function check_ip6($requestIp, $ip)
{
if (false !== strpos($ip, '/')) {
list($address, $netmask) = explode('/', $ip, 2);
if ('0' === $netmask) {
return (bool) unpack('n*', @inet_pton($address));
}
if ($netmask < 1 || $netmask > 128) {
return false;
}
} else {
$address = $ip;
$netmask = 128;
}
$bytesAddr = unpack('n*', @inet_pton($address));
$bytesTest = unpack('n*', @inet_pton($requestIp));
if (!$bytesAddr || !$bytesTest) {
return false;
}
for ($i = 1, $ceil = ceil($netmask / 16); $i <= $ceil; ++$i) {
$left = $netmask - 16 * ($i - 1);
$left = ($left <= 16) ? $left : 16;
$mask = ~(0xffff >> $left) & 0xffff;
if (($bytesAddr[$i] & $mask) != ($bytesTest[$i] & $mask)) {
return false;
}
}
return true;
}
public static function check_ip4($requestIp, $ip)
{
if (false !== strpos($ip, '/')) {
list($address, $netmask) = explode('/', $ip, 2);
if ('0' === $netmask) {
return false;
}
if ($netmask < 0 || $netmask > 32) {
return false;
}
} else {
$address = $ip;
$netmask = 32;
}
if (false === ip2long($address)) {
return false;
}
return 0 === substr_compare(sprintf('%032b', ip2long($requestIp)), sprintf('%032b', ip2long($address)), 0, $netmask);
}
}
?>

View File

@@ -0,0 +1,35 @@
<?php
/*
[UCenter] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: ucip_getter_dnslist.class.php 969 2019-12-19 12:00:00Z community $
*/
class ucip_getter_dnslist {
public static function get($s) {
if (empty($s['header']) || empty($s['list'])) {
return $_SERVER['REMOTE_ADDR'];
}
$ip = $_SERVER['REMOTE_ADDR'];
$rdns = gethostbyaddr($ip);
foreach($s['list'] as $host) {
if (preg_match('/'.$host.'$/i', $rdns)) {
if ($s['header'] != 'HTTP_X_FORWARDED_FOR') {
$ip = ucip::validate_ip($_SERVER[$s['header']]) ? $_SERVER[$s['header']] : $ip;
} else {
if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ",") > 0) {
$exp = explode(",", $_SERVER['HTTP_X_FORWARDED_FOR']);
$ip = ucip::validate_ip(trim($exp[0])) ? $exp[0] : $ip;
} else {
$ip = ucip::validate_ip($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $ip;
}
}
}
}
return $ip;
}
}

View File

@@ -0,0 +1,30 @@
<?php
/*
[UCenter] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: ucip_getter_header.class.php 809 2019-12-19 12:00:00Z community $
*/
class ucip_getter_header {
public static function get($s) {
if (empty($s['header'])) {
return $_SERVER['REMOTE_ADDR'];
}
$ip = $_SERVER['REMOTE_ADDR'];
if ($s['header'] != 'HTTP_X_FORWARDED_FOR') {
$ip = ucip::validate_ip($_SERVER[$s['header']]) ? $_SERVER[$s['header']] : $ip;
} else {
if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ",") > 0) {
$exp = explode(",", $_SERVER['HTTP_X_FORWARDED_FOR']);
$ip = ucip::validate_ip(trim($exp[0])) ? $exp[0] : $ip;
} else {
$ip = ucip::validate_ip($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $ip;
}
}
return $ip;
}
}

View File

@@ -0,0 +1,35 @@
<?php
/*
[UCenter] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: ucip_getter_iplist.class.php 959 2019-12-19 12:00:00Z community $
*/
class ucip_getter_iplist {
public static function get($s) {
if (empty($s['header']) || empty($s['list'])) {
return $_SERVER['REMOTE_ADDR'];
}
$ip = $_SERVER['REMOTE_ADDR'];
$rdns = gethostbyaddr($ip);
foreach($s['list'] as $host) {
if (ucip::check_ip($ip, $host)) {
if ($s['header'] != 'HTTP_X_FORWARDED_FOR') {
$ip = ucip::validate_ip($_SERVER[$s['header']]) ? $_SERVER[$s['header']] : $ip;
} else {
if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ",") > 0) {
$exp = explode(",", $_SERVER['HTTP_X_FORWARDED_FOR']);
$ip = ucip::validate_ip(trim($exp[0])) ? $exp[0] : $ip;
} else {
$ip = ucip::validate_ip($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $ip;
}
}
}
}
return $ip;
}
}

View File

@@ -0,0 +1,313 @@
<?php
/*
[UCenter] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: upload.class.php 1059 2011-03-01 07:25:09Z monkey $
*/
Class upload{
var $dir;
var $thumb_width;
var $thumb_height;
var $thumb_ext;
var $watermark_file;
var $watermark_pos;
var $watermark_alpha;
var $time;
var $filetypedata = array();
var $filetypeids = array();
var $filetypes = array();
function __construct($time = 0) {
$this->time = $time ? $time : time();
$this->filetypedata = array(
'av' => array('av', 'wmv', 'wav'),
'real' => array('rm', 'rmvb'),
'binary' => array('dat'),
'flash' => array('swf'),
'html' => array('html', 'htm'),
'image' => array('gif', 'jpg', 'jpeg', 'png', 'bmp', 'webp'),
'office' => array('doc', 'xls', 'ppt'),
'pdf' => array('pdf'),
'rar' => array('rar', 'zip'),
'text' => array('txt'),
'bt' => array('bt'),
'zip' => array('tar', 'rar', 'zip', 'gz'),
);
$this->filetypeids = array_keys($this->filetypedata);
foreach($this->filetypedata as $data) {
$this->filetypes = array_merge($this->filetypes, $data);
}
}
function set_dir($dir) {
$this->dir = $dir;
}
function set_thumb($width, $height, $ext = '') {
$this->thumb_width = $width;
$this->thumb_height = $height;
$this->thumb_ext = $ext;
}
function set_watermark($file, $pos = 9, $alpha = 100) {
$this->watermark_file = $file;
$this->watermark_pos = $pos;
$this->watermark_alpha = $alpha;
}
function execute() {
$arr = array();
$keys = array_keys($_FILES['attach']['name']);
foreach($keys as $key) {
if(!$_FILES['attach']['name'][$key]) {
continue;
}
$file = array(
'name' => $_FILES['attach']['name'][$key],
'tmp_name' => $_FILES['attach']['tmp_name'][$key]
);
$fileext = $this->fileext($file['name']);
if(!in_array($fileext, $this->filetypes)) {
$fileext = '_'.$fileext;
}
$tfilename = $this->time.rand(100, 999);
$filename = '1'.$tfilename.'.'.$fileext;
$filethumb = '0'.$tfilename.'.'.($this->thumb_ext ? $this->thumb_ext : $fileext);
$this->copy($file['tmp_name'], $this->dir.'/'.$filename);
$arr[$key]['file'] = $filename;
if(in_array($fileext, array('jpg', 'gif', 'png', 'webp'))) {
if($this->thumb_width) {
if($this->thumb($this->thumb_width, $this->thumb_height, $this->dir.'/'.$filename, $this->dir.'/'.$filethumb, ($this->thumb_ext ? $this->thumb_ext : $fileext))) {
$arr[$key]['thumb'] = $filethumb;
}
}
if($this->watermark_file) {
$this->waterfile($this->dir.'/'.$filename, $this->watermark_file, $fileext, $this->watermark_pos, $this->watermark_alpha);
}
}
}
return $arr;
}
function mkdir_by_date($date, $dir = '.') {
list($y, $m, $d) = explode('-', date('Y-m-d', $date));
!is_dir("$dir/$y") && mkdir("$dir/$y", 0777);
!is_dir("$dir/$y/$m$d") && mkdir("$dir/$y/$m$d", 0777);
return "$y/$m$d";
}
function mkdir_by_hash($s, $dir = '.') {
$s = md5($s);
!is_dir($dir.'/'.$s[0]) && mkdir($dir.'/'.$s[0], 0777);
!is_dir($dir.'/'.$s[0].'/'.$s[1]) && mkdir($dir.'/'.$s[0].'/'.$s[1], 0777);
!is_dir($dir.'/'.$s[0].'/'.$s[1].'/'.$s[2]) && mkdir($dir.'/'.$s[0].'/'.$s[1].'/'.$s[2], 0777);
return $s[0].'/'.$s[1].'/'.$s[2];
}
function mkdir_by_uid($uid, $dir = '.') {
$uid = sprintf("%09d", $uid);
$dir1 = substr($uid, 0, 3);
$dir2 = substr($uid, 3, 2);
$dir3 = substr($uid, 5, 2);
!is_dir($dir.'/'.$dir1) && mkdir($dir.'/'.$dir1, 0777);
!is_dir($dir.'/'.$dir1.'/'.$dir2) && mkdir($dir.'/'.$dir1.'/'.$dir2, 0777);
!is_dir($dir.'/'.$dir1.'/'.$dir2.'/'.$dir3) && mkdir($dir.'/'.$dir1.'/'.$dir2.'/'.$dir3, 0777);
return $dir1.'/'.$dir2.'/'.$dir3;
}
function copy($sourcefile, $destfile) {
move_uploaded_file($sourcefile, $destfile);
@unlink($sourcefile);
}
function watermark($target, $watermark_file, $ext, $watermarkstatus=9, $watermarktrans=50) {
$gdsurporttype = array();
if(function_exists('imageAlphaBlending') && function_exists('getimagesize')) {
if(function_exists('imageGIF')) $gdsurporttype[]='gif';
if(function_exists('imagePNG')) $gdsurporttype[]='png';
if(function_exists('imageWEBP')) $gdsurporttype[]='webp';
if(function_exists('imageJPEG')) {
$gdsurporttype[]='jpg';
$gdsurporttype[]='jpeg';
}
}
if($gdsurporttype && in_array($ext, $gdsurporttype) ) {
$attachinfo = getimagesize($target);
$watermark_logo = imageCreateFromGIF($watermark_file);
$logo_w = imageSX($watermark_logo);
$logo_h = imageSY($watermark_logo);
$img_w = $attachinfo[0];
$img_h = $attachinfo[1];
$wmwidth = $img_w - $logo_w;
$wmheight = $img_h - $logo_h;
$animatedgif = 0;
if($attachinfo['mime'] == 'image/gif') {
$fp = fopen($target, 'rb');
$targetcontent = fread($fp, 9999999);
fclose($fp);
$animatedgif = strpos($targetcontent, 'NETSCAPE2.0') === FALSE ? 0 : 1;
}
$animatedwebp = 0;
if($attachinfo['mime'] == 'image/webp') {
$fp = fopen($target, 'rb');
$targetcontent = fread($fp, 40);
fclose($fp);
if (stripos($targetcontent, 'WEBPVP8X') !== FALSE || stripos($targetcontent, 'ANIM') !== FALSE) {
$animatedwebp = 1;
}else{
$animatedwebp = 0;
}
}
if($watermark_logo && $wmwidth > 10 && $wmheight > 10 && !$animatedgif && !$animatedwebp) {
switch ($attachinfo['mime']) {
case 'image/jpeg':
$dst_photo = imageCreateFromJPEG($target);
break;
case 'image/gif':
$dst_photo = imageCreateFromGIF($target);
break;
case 'image/png':
$dst_photo = imageCreateFromPNG($target);
break;
case 'image/webp':
$dst_photo = imageCreateFromWEBP($target);
break;
}
switch($watermarkstatus) {
case 1:
$x = +5;
$y = +5;
break;
case 2:
$x = ($logo_w + $img_w) / 2;
$y = +5;
break;
case 3:
$x = $img_w - $logo_w-5;
$y = +5;
break;
case 4:
$x = +5;
$y = ($logo_h + $img_h) / 2;
break;
case 5:
$x = ($logo_w + $img_w) / 2;
$y = ($logo_h + $img_h) / 2;
break;
case 6:
$x = $img_w - $logo_w;
$y = ($logo_h + $img_h) / 2;
break;
case 7:
$x = +5;
$y = $img_h - $logo_h-5;
break;
case 8:
$x = ($logo_w + $img_w) / 2;
$y = $img_h - $logo_h;
break;
case 9:
$x = $img_w - $logo_w-5;
$y = $img_h - $logo_h-5;
break;
}
imageAlphaBlending($watermark_logo, FALSE);
imagesavealpha($watermark_logo,TRUE);
imageCopyMerge($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h, $watermarktrans);
switch($attachinfo['mime']) {
case 'image/jpeg':
imageJPEG($dst_photo, $target);
break;
case 'image/gif':
imageGIF($dst_photo, $target);
break;
case 'image/png':
imagePNG($dst_photo, $target);
break;
case 'image/webp':
imageWEBP($dst_photo, $target);
break;
}
}
}
}
function thumb($forcedwidth, $forcedheight, $sourcefile, $destfile, $destext, $imgcomp = 0) {
$g_imgcomp=100-$imgcomp;
$g_srcfile=$sourcefile;
$g_dstfile=$destfile;
$g_fw=$forcedwidth;
$g_fh=$forcedheight;
$ext = strtolower(substr(strrchr($sourcefile, '.'), 1, 10));
if(file_exists($g_srcfile)) {
$g_is = getimagesize($g_srcfile);
if($g_is[0] < $forcedwidth && $g_is[1] < $forcedheight) {
copy($sourcefile, $destfile);
return filesize($destfile);;
}
if (($g_is[0] - $g_fw) >= ($g_is[1] - $g_fh)){
$g_iw=$g_fw;
$g_ih=($g_fw/$g_is[0])*$g_is[1];
} else {
$g_ih=$g_fh;
$g_iw=($g_ih/$g_is[1])*$g_is[0];
}
switch ($ext) {
case 'jpg':
$img_src = @imagecreatefromjpeg($g_srcfile);
!$img_src && $img_src = imagecreatefromgif($g_srcfile);
break;
case 'gif':
$img_src = imagecreatefromgif($g_srcfile);
break;
case 'png':
$img_src = imagecreatefrompng($g_srcfile);
break;
case 'webp':
$img_src = imagecreatefromwebp($g_srcfile);
break;
}
$img_dst = imagecreatetruecolor($g_iw, $g_ih);
imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $g_iw, $g_ih, $g_is[0], $g_is[1]);
switch($destext) {
case 'jpg':
imagejpeg($img_dst, $g_dstfile, $g_imgcomp);
break;
case 'gif':
imagegif($img_dst, $g_dstfile);
break;
}
imagedestroy($img_dst);
return filesize($destfile);
} else {
return false;
}
}
function fileext($filename) {
return substr(strrchr($filename, '.'), 1, 10);
}
function get_filetype($ext) {
foreach($this->filetypedata as $k => $v) {
if(in_array($ext, $v)) {
return $k;
}
}
return 'common';
}
}
?>

105
uc_server/lib/xml.class.php Normal file
View File

@@ -0,0 +1,105 @@
<?php
/*
[UCenter] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: xml.class.php 1059 2011-03-01 07:25:09Z monkey $
*/
function xml_unserialize(&$xml, $isnormal = FALSE) {
$xml_parser = new XML($isnormal);
$data = $xml_parser->parse($xml);
$xml_parser->destruct();
return $data;
}
function xml_serialize($arr, $htmlon = FALSE, $isnormal = FALSE, $level = 1) {
$s = $level == 1 ? "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n<root>\r\n" : '';
$space = str_repeat("\t", $level);
foreach($arr as $k => $v) {
if(!is_array($v)) {
$s .= $space."<item id=\"$k\">".($htmlon ? '<![CDATA[' : '').$v.($htmlon ? ']]>' : '')."</item>\r\n";
} else {
$s .= $space."<item id=\"$k\">\r\n".xml_serialize($v, $htmlon, $isnormal, $level + 1).$space."</item>\r\n";
}
}
$s = preg_replace("/([\x01-\x08\x0b-\x0c\x0e-\x1f])+/", ' ', $s);
return $level == 1 ? $s."</root>" : $s;
}
class XML {
var $parser;
var $document;
var $stack;
var $data;
var $last_opened_tag;
var $isnormal;
var $attrs = array();
var $failed = FALSE;
function __construct($isnormal) {
$this->XML($isnormal);
}
function XML($isnormal) {
$this->isnormal = $isnormal;
$this->parser = xml_parser_create('ISO-8859-1');
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false);
xml_set_object($this->parser, $this);
xml_set_element_handler($this->parser, 'open','close');
xml_set_character_data_handler($this->parser, 'data');
}
function destruct() {
xml_parser_free($this->parser);
}
function parse(&$data) {
$this->document = array();
$this->stack = array();
return xml_parse($this->parser, $data, true) && !$this->failed ? $this->document : '';
}
function open($parser, $tag, $attributes) {
$this->data = '';
$this->failed = FALSE;
if(!$this->isnormal) {
if(isset($attributes['id']) && !(isset($this->document[$attributes['id']]) && is_string($this->document[$attributes['id']]))) {
$this->document = &$this->document[$attributes['id']];
} else {
$this->failed = TRUE;
}
} else {
if(!isset($this->document[$tag]) || !is_string($this->document[$tag])) {
$this->document = &$this->document[$tag];
} else {
$this->failed = TRUE;
}
}
$this->stack[] = &$this->document;
$this->last_opened_tag = $tag;
$this->attrs = $attributes;
}
function data($parser, $data) {
if($this->last_opened_tag != NULL) {
$this->data .= $data;
}
}
function close($parser, $tag) {
if($this->last_opened_tag == $tag) {
$this->document = $this->data;
$this->last_opened_tag = NULL;
}
array_pop($this->stack);
if($this->stack) {
$this->document = &$this->stack[count($this->stack)-1];
}
}
}
?>