<?php
/***
*
*@package binzcms
*@version $id:FrontAdClass.php, v 1.0
*@author 斌子
*@Sun Sep 12 16:39:22 GMT 2010
*@copyright (c) 2009-2010 binzcms
*
*/
if(!defined("BINZCMS")) {
	die("hacking");
}
/**
 *
 * FrontAdClass
 * 广告控制类
 * 
 */
include(MOD_PATH."/ModFrontAdClass.php");
class FrontAdClass extends ModFrontAdClass {
	/**
	 * __construct
	 *
	 * 构造函数
	 * @access  public（权限）
	 */
	public function __construct($act) {
		/*获取方法*/
		if(empty($act)) {
			$act	= "index_show";
		}

		/*合法action*/
		$this->allow_action	= array(
		'index_show',				//首页显示
		'front_ad'
		);

		parent::__construct($act);

		/*非法action，$act从新赋值*/
		if(!$this->action_state) {
			$act	= "index_show";
		}

		$this->$act();
	}
	/**
	 * front_ad
	 *
	 * 广告显示
	 * @access  public（权限）
	 * 
	 * 
	 */
	private function front_ad() {
		/* 编码转换 */
		if (empty($_GET['charset'])){
			$_GET['charset'] = 'utf8';
		}
		header('Content-type: application/x-javascript; charset=' . ($_GET['charset'] == 'utf8' ? 'utf-8' : $_GET['charset']));

		$ad_info		= array();
		$ad_info		= $this->mod_front_ad_show();

		include(ROOT_PATH.'/include/CharsetClass.php');
		$charset_change	= new CharsetClass();
		if($_GET['charset'] != 'utf8') {
			$ad_info['ad_name'] = $charset_change->change_charset($ad_info['ad_name'],'utf8_to_'.$_GET['charset']);
			$ad_info['ad_body'] = $charset_change->change_charset($ad_info['ad_body'],'utf8_to_'.$_GET['charset']);
		}

		$ad_str			= '';
		switch ($ad_info['ad_type']) {
			case 'ad_flash':		//flash广告
			$src	= WEB_HOST."/".$ad_info['ad_body'];
			$ad_str	= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" <param name="movie" value="'.$src.'"><param name="quality" value="high"><embed src="'.$src.'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed></object>';
			break;
			case 'ad_image':		//图片广告
			$src	= '<img src="'.WEB_HOST."/".$ad_info['ad_body'].'" border="0" alt="'.$ad_info['ad_name'].'">';
			$ad_str	= '<a href="'.$ad_info['ad_url'].'" target="_blank">'.$src.'</a>';
			break;
			case 'ad_text':			//文字广告
			$ad_str = '<a href="'.$ad_info['ad_url'].'" target="_blank">' . nl2br(htmlspecialchars(addslashes($ad_info['ad_body']))). '</a>';
			break;
			case 'ad_code':			//代码广告
			$ad_str	= $ad_info['ad_body'];
			break;
		}
		echo "document.writeln('$ad_str');";
	}
	/**
	 * __destruct
	 *
	 * 析构函数
	 * @access  public（权限）
	 */
	public function __destruct() {

	}
}
?>