欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

php 广告调用类代码(支持Flash调用)

程序员文章站 2024-01-19 18:46:10
调用方式如下:其中debugstr这个函数就是类似一个echo。 复制代码 代码如下: debugstr('$adv->getcontentbyid($id); $i...
调用方式如下:其中debugstr这个函数就是类似一个echo。
复制代码 代码如下:

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 '<hr>';    

类如下:
复制代码 代码如下:

<?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://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" target=_blank><img style="float: none; margin: 1px; vertical-align: middle; width: 18px; border-top-style: none; border-right-style: none; border-left-style: none; height: 18px; border-bottom-style: none" src="data:image/png;base64,ivborw0kggoaaaansuheugaaabiaaaascayaaabwzo5xaaaabhncsvqicagifahkiaaaaalwsflzaaapkgaad5ibbkh+oaaaabl0rvh0u29mdhdhcmuad3d3lmlua3njyxbllm9yz5vupboaaanfsurbvdinlzjlanxvfie/+3/ozjjmokmzxqtjoj2kmkybtbcxossc0nin0l11auxcdunkkf0otbbcuxxhqlckohutsivasdbvqyevjw3txdwmk2smmf/jplwkmzxfldxw+chhnu+c+ztxggmygnrlmcf7jrydakp38t8icqurt25ojxz8yqefoutls6nnnxv+snbz6behbi7damdy8gz79hv2fqqh+xtxlrzstz3xlesbmp3rele9slz25ocrl87m/ferm5tfwloewhjwpqflsiaegefremt8co0rcrkncbwbpttjznqfnbidc6io8m3bvq+zypznyxtytze1/so+30cptm4lqyexlivpqss0pznks30a2i7nwnu9p44ijahhbutw4wh8xhazumkeiuqduos6ylyt7sxp8tuny9ytlof6hkkazdtmz1wnkfabygs60ezw+9bylpaduao06439phr7iyvg+i64+4ezi2fm8sovhk0zsdcavwroefrlagebslyc0pzy74fsrqa77dtpxttmgo3mjmeodth2y0c83oju87v7nhcowg+dpfvgo7snr0wdb9pa2kpukalkc7s1dak1ivyaktwhvmra4fxn9b9nfbajrailv/lp/clvqitbfohstkcqkumsqwm9n2hs7bjslvlzwcn1xv597rstk7p09uy5d+5d8gco0pe7gem2e8z7gktstdzqsa4bllwyovwumzg4ymdaaeeqcpbso8zpz/pn1tky2ceijfdashuk1eiliawm9cedjf//nppn3ymialzxrsmf1ppstg1jnoul30mmc0i1m1e1umtk1ce1lzzc8vkcxhjcmeqphzqsprtpdjow2edr7rvbikluyyrvmplwtlz2vdidji6oeqqbyrgshifxhcolzgjikmrtd/2rwo0dhcurxwjc2zlutnlhuy09xpr6o4igiagcoigiiikklhx7zzzwzeg00krbzuuui8xm02+nfjerdb2n1bbruun6yhf+/jjnbzvxfq/pdxe9g8e2+ftindrzj1m8fwmuu/90rzdg8pqzlca/f+nnl9hcf/8gtzjwggwmtvaw1tkuaskz3njtb7oh/ft7px2nnv4bjlsknxlrx2yaaaaasuvork5cyii="></a></span>#version=7,0,19,0" width="'.$width.'" height="'.$height.'">';
$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.macromedia.com/go/getflashplayer" target=_blank><img style="float: none; margin: 1px; vertical-align: middle; width: 18px; border-top-style: none; border-right-style: none; border-left-style: none; height: 18px; border-bottom-style: none" src="data:image/png;base64,ivborw0kggoaaaansuheugaaabiaaaascayaaabwzo5xaaaabhncsvqicagifahkiaaaaalwsflzaaapkgaad5ibbkh+oaaaabl0rvh0u29mdhdhcmuad3d3lmlua3njyxbllm9yz5vupboaaanfsurbvdinlzjlanxvfie/+3/ozjjmokmzxqtjoj2kmkybtbcxossc0nin0l11auxcdunkkf0otbbcuxxhqlckohutsivasdbvqyevjw3txdwmk2smmf/jplwkmzxfldxw+chhnu+c+ztxggmygnrlmcf7jrydakp38t8icqurt25ojxz8yqefoutls6nnnxv+snbz6behbi7damdy8gz79hv2fqqh+xtxlrzstz3xlesbmp3rele9slz25ocrl87m/ferm5tfwloewhjwpqflsiaegefremt8co0rcrkncbwbpttjznqfnbidc6io8m3bvq+zypznyxtytze1/so+30cptm4lqyexlivpqss0pznks30a2i7nwnu9p44ijahhbutw4wh8xhazumkeiuqduos6ylyt7sxp8tuny9ytlof6hkkazdtmz1wnkfabygs60ezw+9bylpaduao06439phr7iyvg+i64+4ezi2fm8sovhk0zsdcavwroefrlagebslyc0pzy74fsrqa77dtpxttmgo3mjmeodth2y0c83oju87v7nhcowg+dpfvgo7snr0wdb9pa2kpukalkc7s1dak1ivyaktwhvmra4fxn9b9nfbajrailv/lp/clvqitbfohstkcqkumsqwm9n2hs7bjslvlzwcn1xv597rstk7p09uy5d+5d8gco0pe7gem2e8z7gktstdzqsa4bllwyovwumzg4ymdaaeeqcpbso8zpz/pn1tky2ceijfdashuk1eiliawm9cedjf//nppn3ymialzxrsmf1ppstg1jnoul30mmc0i1m1e1umtk1ce1lzzc8vkcxhjcmeqphzqsprtpdjow2edr7rvbikluyyrvmplwtlz2vdidji6oeqqbyrgshifxhcolzgjikmrtd/2rwo0dhcurxwjc2zlutnlhuy09xpr6o4igiagcoigiiikklhx7zzzwzeg00krbzuuui8xm02+nfjerdb2n1bbruun6yhf+/jjnbzvxfq/pdxe9g8e2+ftindrzj1m8fwmuu/90rzdg8pqzlca/f+nnl9hcf/8gtzjwggwmtvaw1tkuaskz3njtb7oh/ft7px2nnv4bjlsknxlrx2yaaaaasuvork5cyii="></a></span>" type="application/x-shockwave-flash" width="'.$width.'" height="'.$height.'"></embed></object>';
$returncontent.= '</td>';
$returncontent.= '</tr>';
$returncontent.= '</table>';
$returncontent.= '</td>';
$returncontent.= '</tr>';
$returncontent.= '</table>';
}else{
//图片广告
$returncontent = '<a target="_blank" href="'.$url.'"><img src="'.$filename.'" width="'.$width.'" height="'.$height.'" border="0" /></a>';
}
//如果为调用js方式
if(self::$js){
$returncontent = 'document.write("'.addslashes($returncontent).'");';
}
//重置默认值,这里还是采用单件模式
self::$id = 0;
self::$order = 0;
self::$js = 0;
return $returncontent;
}
}
?>