代码:
<?PHP
/*******************************************
Avatar Class
Version 1.0
Author: duketang
Msn: tangxl@gi310.com
QQ: 8339544
Date: 2005/12/22
********************************************/
class xshow_class
{
var $db;
var $conf;
var $user_path;
var $temp_path;
var $user_id;
var $default_layer;
var $out_suit_layer;
var $default_boy_module;
var $default_girl_module;
function xshow_class()
{
global $db,$conf;
$this->db = $db;
$this->conf = $conf;
$this->user_id = phone_user_id();
$this->user_path = "/test_system/test.cn/data/xshow/user_profile/".ceil($this->user_id/3000)."/".$this->user_id."/";
$this->temp_path = "/test_system/test.cn/data/xshow/user_temp/";
//必选层
$this->default_layer = array(5,6,7,8,10,11,13);
//套装互斥层
$this->out_suit_layer = array(3,6,7,9,10,11);
//默认结构
$this->default_boy_module = array(
5 => array(7,0,11,'N',12,''),
6 => array(1,0,0,'N',1,''),
7 => array(2,0,0,'N',3,''),
8 => array(3,0,0,'Y',5,''),
10 => array(4,0,0,'N',7,''),
11 => array(5,0,0,'N',9,''),
13 => array(6,0,12,'N',11,'')
);
$this->default_girl_module = array(
5 => array(7,0,13,'N',14,''),
6 => array(1,0,0,'N',2,''),
7 => array(2,0,0,'N',4,''),
8 => array(3,0,0,'Y',6,''),
10 => array(4,0,0,'N',8,''),
11 => array(5,0,0,'N',10,''),
13 => array(6,0,14,'N',13,'')
);
}
/**
* 检测性别
*/
function check_sex($show_user_id)
{
$user_path = "/test_system/test.cn/data/xshow/user_profile/".ceil($show_user_id/3000)."/".$show_user_id."/";
if(!file_exists($this->user_path."main.xml") and $_GET['code'] != "new_xshow")
{
$wml_data .= "<card id='my_space' title='我的空间'>";
$wml_data .= "<p align='left'>n";
$wml_data .= "请确定你的性别(注意:本次选定以后将不能再做修改!)<br/>";
$wml_data .= "<select name='sex'><option value='1'>男</option><option value='2'>女</option></select><br/>";
if($_GET['action']=="camer" and $_GET['camer_id'] != "")
{
$wml_data .= "<anchor title='Click'>进入我的形象<go href='./../../page.php?action=xshow&code=new_xshow&testSESSID=".$_GET['testSESSID']."&up_url=".urlencode("/page.php?action='./../../&'quot;.$_GET['action']."&code=".$_GET['code']."&camer_id=".$_GET['camer_id'])."' method='post'><postfield name='sex' value='$(sex)'/></go></anchor><br/>";
}else{
$wml_data .= "<anchor title='Click'>进入我的形象<go href='./../../page.php?action=xshow&code=new_xshow&testSESSID=".$_GET['testSESSID']."' method='post'><postfield name='sex' value='$(sex)'/></go></anchor><br/>";
}
$wml_data .= "--------------<br/>";
$wml_data .= "<a href='./../../index2.wml'>回门户首页</a></p>n";
$this->wml_data = $wml_data;
$this->out_page();
include_once($this->conf['WAP_INCLUDE_PATH']."/foot.inc.php");
exit();
}
}
/**
* 生成主形象
*
* @param int $show_user_id 用户ID
* @param char $xml_file 所使用数据名
* @param char $res_file 生成文件名
* @param int $start_layer 所使用层集合
*/
function xshow_process($show_user_id,$xml_file="main",$res_file="main",$layer_array="")
{
$show_user_path = "/test_system/test.cn/data/xshow/user_profile/".ceil($show_user_id/3000)."/".$show_user_id."/";
$xml_data = new XMLParser($show_user_path.$xml_file.".xml");
$main_data = $xml_data->result->profile_data;
$ani = false;
$for_i = 1;
$last_layer = "";
$layer_count = sizeof($main_data->layer);
$s_img_path = "/test_system/test.cn/data/xshow/";
if($layer_array==""){
for ($i=1;$i<=100;$i++){
$layer_array[] = $i;
}
}
//print_r($layer_array);
foreach ($main_data->layer as $layer_data)
{
if(in_array($layer_data->ln,$layer_array))
{
if($layer_data->ani == "Y") $ani = true;
//echo $for_i."<br>";
if($for_i == 1) $last_layer = $layer_data;
if(!$ani and $for_i == 1)
{
copy($s_img_path.$last_layer->ln."/".$last_layer->type."/".$last_layer->img.".gif",$this->temp_path.$show_user_id."_user.gif");
}elseif($ani and $for_i == 1){
for ($ani_for_i = 0;$ani_for_i<4;$ani_for_i++)
{
copy($s_img_path.$last_layer->ln."/".$last_layer->type."/".$last_layer->img."_f_0".$ani_for_i.".gif",$this->temp_path.$show_user_id."_user_f_0".$ani_for_i.".gif");
}
}
if(!$ani)
{
if($for_i > 1)
{
$last_img =imagecreatefromgif($this->temp_path.$show_user_id."_user".".gif");
$last_img_size=getimagesize($this->temp_path.$show_user_id."_user".".gif",$last_img_info);
$layer_img =imagecreatefromgif($s_img_path.$layer_data->ln."/".$layer_data->type."/".$layer_data->img.".gif");
$layer_img_size = getimagesize($s_img_path.$layer_data->ln."/".$layer_data->type."/".$layer_data->img.".gif");
imagecopy ($last_img,$layer_img,0,0,0,0,$layer_img_size[0],$layer_img_size[1]);
imagedestroy($layer_img);
imagegif($last_img, $this->temp_path.$show_user_id."_user.gif");
imagedestroy($last_img);
}
}else{
if($for_i > 1)
{
if(!file_exists($this->temp_path.$show_user_id."_user_f_00.gif"))
{
copy($this->temp_path.$show_user_id."_user.gif",$this->temp_path.$show_user_id."_user_f_00.gif");
copy($this->temp_path.$show_user_id."_user.gif",$this->temp_path.$show_user_id."_user_f_01.gif");
copy($this->temp_path.$show_user_id."_user.gif",$this->temp_path.$show_user_id."_user_f_02.gif");
copy($this->temp_path.$show_user_id."_user.gif",$this->temp_path.$show_user_id."_user_f_03.gif");
}
if($layer_data->ani == "Y")
{
for ($ani_for_i=0;$ani_for_i<4;$ani_for_i++)
{
//echo $this->temp_path.$this->user_id."_user_f_0".$ani_for_i.".gif"."<br/>";
//echo $s_img_path.$layer_data->ln."/".$layer_data->type."/".$layer_data->img.".gif"."<br/>";
$last_img =imagecreatefromgif($this->temp_path.$show_user_id."_user_f_0".$ani_for_i.".gif");
$last_img_size=getimagesize($this->temp_path.$show_user_id."_user_f_0".$ani_for_i.".gif",$last_img_info);
$layer_img =imagecreatefromgif($s_img_path.$layer_data->ln."/".$layer_data->type."/".$layer_data->img."_f_0".$ani_for_i.".gif");
$layer_img_size = getimagesize($s_img_path.$layer_data->ln."/".$layer_data->type."/".$layer_data->img."_f_0".$ani_for_i.".gif");
imagecopy ($last_img,$layer_img,0,0,0,0,$layer_img_size[0],$layer_img_size[1]);
imagedestroy($layer_img);
imagegif($last_img, $this->temp_path.$show_user_id."_user_f_0".$ani_for_i.".gif");
imagedestroy($last_img);
}
}else{
for ($ani_for_i=0;$ani_for_i<4;$ani_for_i++)
{
//echo $this->temp_path.$this->user_id."_user_f_0".$ani_for_i.".gif"."<br/>";
//echo $s_img_path.$layer_data->ln."/".$layer_data->type."/".$layer_data->img.".gif"."<br/>";
$last_img =imagecreatefromgif($this->temp_path.$show_user_id."_user_f_0".$ani_for_i.".gif");
$last_img_size=getimagesize($this->temp_path.$show_user_id."_user_f_0".$ani_for_i.".gif",$last_img_info);
$layer_img =imagecreatefromgif($s_img_path.$layer_data->ln."/".$layer_data->type."/".$layer_data->img.".gif");
$layer_img_size = getimagesize($s_img_path.$layer_data->ln."/".$layer_data->type."/".$layer_data->img.".gif");
&nb
里面所使用的xml读取类
代码:
class XMLParser
{
var $path;
var $result;
function cleanString($string)
{
$tmp = trim(str_replace("'", "'", $string));
return $tmp;
}
function XMLParser($filename)
{
$this->path = "$this->result";
$this->index = 0;
$data_array = file($filename);
$data = implode("n",$data_array);
$xml_parser = xml_parser_create();
xml_set_object($xml_parser, &$this);
xml_set_element_handler($xml_parser, 'startElement', 'endElement');
xml_set_character_data_handler($xml_parser, 'characterData');
xml_parser_set_option($xml_parser,XML_OPTION_CASE_FOLDING,0);
xml_parse($xml_parser, $data, true);
xml_parser_free($xml_parser);
}
function startElement($parser, $tag, $attributeList)
{
$this->path .= "->".$tag;
eval("$data = ".$this->path.";");
if (is_array($data))
{
$index = sizeof($data);
$this->path .= "[".$index."]";
}
else if (is_object($data))
{
eval($this->path." = array(".$this->path.");");
$this->path .= "[1]";
}
foreach($attributeList as $name => $value)
eval($this->path."->".$name. " = '".XMLParser::cleanString($value)."';");
}
function endElement($parser, $tag)
{
$this->path = substr($this->path, 0, strrpos($this->path, "->"));
}
function characterData($parser, $data)
{
if ($data = XMLParser::cleanString($data))
{
//eval($this->path." = '$data';");
eval("$this->path .= $data;");
}
}
}