复制代码 代码如下:
debugstr('$adv->getcontentbyid($id); $id为广告编号, 仅调用一条,返回内容为字符串');
echo adv::getcontentbyid(35);
debugstr('$adv->getcontentbyidjs($id); $id为广告编号, 仅调用一条,返回内容为js字符串');
echo adv::getcontentbyidjs(35);
debugstr('$adv->getcontentbyorder($id); $id为广告编号, 仅调用id倒序一条,返回内容为字符串');
echo adv::getcontentbyorder(4);
debugstr('$adv->getcontentbyorderjs($id); $id为广告编号, 仅调用id倒序一条,返回内容为js字符串');
echo adv::getcontentbyorderjs(4);
echo 'f32b48428a809b51f04d3228cdf461fa';
类如下:
复制代码 代码如下:
<?php /** * 说明:广告类,方便广告列表、内容的调用。 * 需要:数据库类 * 支持:仅支持php5,单件模式 * * @author zerolone * @version 2011-1-6 11:32:06 * 调用方法 * adv::getcontentbyid($id); $id为广告编号, 仅调用一条,返回内容为字符串 * adv::getcontentbyidjs($id); $id为广告编号, 仅调用一条,返回内容为js字符串 * adv::getcontentbyorder($order); $order为对应, 仅调用id倒序一条,返回内容为字符串 * adv::getcontentbyorderjs($order); $order对应顺序, 仅调用id倒序一条,返回内容为js字符串 */ class adv { static $id = 0; //编号 static $order = 0; //顺序 static $js = 0; //是否使用js, 0为不使用 /** * 根据id, 返回广告内容,仅调用一条 * * @param 编号 $id * */ public static function getcontentbyid($id){ self::$id = $id; return self::getcontent(); } /** * 根据id, 返回广告内容js,仅调用一条 * * @param 编号 $id * */ public static function getcontentbyidjs($id){ self::$id = $id; self::$js = 1; return self::getcontent(); } /** * 根据order, 返回广告内容,仅调用一条 * * @param 编号 $order * */ public static function getcontentbyorder($order){ self::$order = $order; return self::getcontent(); } /** * 根据order, 返回广告内容js,仅调用一条 * * @param 编号 $order * */ public static function getcontentbyorderjs($order){ self::$order = $order; self::$js = 1; return self::getcontent(); } /** * 生成一个广告内容,只调用一条 * * @return 广告内容 */ private function getcontent(){ $returncontent=''; //------------------0-------1--------2--------3 $sqlstr = 'select `pic`, `width`, `height`, `url` from '.table_adv; if(self::$id){ $sqlstr.= ' where `id`=' . self::$id; }else{ $sqlstr.= ' where `order`=' . self::$order; $sqlstr.= ' order by `id` desc '; } $sqlstr.= ' limit 1'; $mydatabase=database::get(); $mydatabase->sqlstr = $sqlstr; if ($mydatabase->query ()) { $db_record = $mydatabase->resultarr [0]; $filename = $db_record[0]; $width = $db_record[1]; $height = $db_record[2]; $url = $db_record[3]; } //判断类型 $filename_ext=strtoupper(pathinfo($filename, pathinfo_extension)); if ($filename_ext=='swf'){ //flash广告 $returncontent = '<table width="' . $width .'" border="0" cellspacing="0" cellpadding="0">'; $returncontent.= '<tr>'; $returncontent.= '<td height="' . $height . '">'; $returncontent.= '<table width="100%" border="0" cellpadding="0" cellspacing="0">'; $returncontent.= '<tr>'; $returncontent.= '<td>'; $returncontent.= '<div style="position:absolute; width:0px; height:0px; z-index:1">'; $returncontent.= '<div style="position:absolute; left:0px; top:0px; width:' . $width . 'px; height:' . $height . 'px; z-index:2; filter:alpha(opacity=0)">'; $returncontent.= '<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">'; $returncontent.= '<tr>'; $returncontent.= '<td style="cursor:hand" onclick=window.open("'. $url . '");> </td>'; $returncontent.= '</tr>'; $returncontent.= '</table>'; $returncontent.= '</div>'; $returncontent.= '</div>'; $returncontent.= '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http<span class=makelinks_urlspan>://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab<!--makelinks--><a class=makelinks_url title=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab style="margin: 1px; vertical-align: middle" href="http://www.php1.cn/">$returncontent.= '<param name="movie" value="'.$filename.'">'; $returncontent.= '<param name="quality" value="high">'; $returncontent.= '<param name="wmode" value="transparent">'; $returncontent.= '<embed src="'.$filename.'" quality="high" wmode="transparent" pluginspage="http<span class=makelinks_urlspan>://www.macromedia.com/go/getflashplayer<!--makelinks--><a class=makelinks_url title=http://www.macromedia.com/go/getflashplayer style="margin: 1px; vertical-align: middle" href="http://www.php1.cn/">$returncontent.= '</td>'; $returncontent.= '</tr>'; $returncontent.= '</table>'; $returncontent.= '</td>'; $returncontent.= '</tr>'; $returncontent.= '</table>'; }else{ //图片广告 $returncontent = '<a target="_blank" href="http://www.php1.cn/">} //如果为调用js方式 if(self::$js){ $returncontent = 'document.write("'.addslashes($returncontent).'");'; } //重置默认值,这里还是采用单件模式 self::$id = 0; self::$order = 0; self::$js = 0; return $returncontent; } } ?>
