<?php
/*
 * 愚子方提供解码
 * 联系QQ: 179210540
 * 仅提供学习使用
 */

class AliziTags {
	
	public static function alizi($item){
		preg_match_all("/(\{\[(Alizi([\w\d\-]+))\]\})/",$item['content'],$matches);
		if(!in_array('AliziWeixin',$matches[2])){
			array_push($matches[2],'AliziWeixin');
		}
		if(!empty($matches[2])){
			foreach($matches[2] as $tags){
				$tag = explode('-',$tags);
				$action = $tag[0];
				if(method_exists('AliziTags',$action)){
					$argv = isset($tag[1])?$tag[1]:'';
					$item['content'] = self::$action($item,$argv);
				}	
			}
			
		}
		return $item;
	}
	
	
	//订单标签
	private function AliziOrder(&$item,$num){
		return str_replace('{[AliziOrder]}',R('Widgets/form',array('request'=>$_GET)),$item['content']);
	}
	
	//评论标签
	private function AliziComment(&$item,$num){
		return str_replace('{[AliziComment-'.$num.']}',R('Widgets/comment',array('request'=>$_GET,'num'=>$num)),$item['content']);
	}
	
	//滚动标签
	private function AliziScroll(&$item,$num){
		return str_replace('{[AliziScroll-'.$num.']}',R('Widgets/scroll',array('request'=>$_GET,'num'=>$num)),$item['content']);
	}
	
	//微信客服标签
	private function AliziWeixin(&$item,$num){
		
		$weixin = explode(';',$item['weixin']);
		if(!empty($weixin)){
			$index = array_rand($weixin);
			$arr = explode('|',$weixin[$index]);
			$wx = array('name'=>$arr[0],'img'=>isset($arr[1])?$arr[1]:'');
		}else{
			$wx = array('name'=>'','img'=>'');
		}
		$item['weixin'] = $wx;
		return str_replace('{[AliziWeixin]}',$wx['name'],$item['content']);
	}
	

}