概述
调用方式如下:其中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;
}
}
?>
最后
以上就是跳跃大地为你收集整理的php 广告调用类代码(支持Flash调用)的全部内容,希望文章能够帮你解决php 广告调用类代码(支持Flash调用)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复