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

前端之家收集整理的这篇文章主要介绍了php 广告调用类代码(支持Flash调用)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

调用方式如下:其中DebugStr这个函数就是类似一个echo。
<div class="codetitle"><a style="CURSOR: pointer" data="39422" class="copybut" id="copybut39422" onclick="doCopy('code39422')"> 代码如下:

<div class="codebody" id="code39422">
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 '
';    

类如下:
<div class="codetitle"><a style="CURSOR: pointer" data="31136" class="copybut" id="copybut31136" onclick="doCopy('code31136')"> 代码如下:
<div class="codebody" id="code31136">
<?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.= '
';
$ReturnContent.= '
';
$ReturnContent.= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab<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=">#version=7,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://www.macromedia.com/go/getflashplayer<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=">" type="application/x-shockwave-flash" width="'.$Width.'" height="'.$Height.'">';
$ReturnContent.= '</td>';
$ReturnContent.= '</tr>';
$ReturnContent.= '</table>';
$ReturnContent.= '</td>';
$ReturnContent.= '</tr>';
$ReturnContent.= '</table>';
}else{
//图片广告
$ReturnContent = '<a target="_blank" href="'.$Url.'">';
}
//如果为调用JS方式
if(self::$JS){
$ReturnContent = 'document.write("'.addslashes($ReturnContent).'");';
}
//重置默认值,这里还是采用单件模式
self::$Id = 0;
self::$Order = 0;
self::$JS = 0;
return $ReturnContent;
}
}
?>

原文链接:https://www.f2er.com/php/27674.html
广告调用类

猜你在找的PHP相关文章