php 廣告調用類代碼(支援Flash調用)_PHP教程

來源:互聯網
上載者:User
調用方式如下:其中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 '';    

類如下:
複製代碼 代碼如下:
/**
* 說明:廣告類,方便廣告列表、內容的調用。
* 需要:資料庫類
* 支援:僅支援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 = '



'; $ReturnContent.= ' '; $ReturnContent.= ' '; $ReturnContent.= ' '; $ReturnContent.= '
';
$ReturnContent.= '



'; $ReturnContent.= ' '; $ReturnContent.= ' '; $ReturnContent.= ' '; $ReturnContent.= '
';
$ReturnContent.= '';
$ReturnContent.= '';
$ReturnContent.= '



'; $ReturnContent.= ' '; $ReturnContent.= ' '; $ReturnContent.= ' '; $ReturnContent.= '
';
$ReturnContent.= '';
$ReturnContent.= '';
$ReturnContent.= '';
$ReturnContent.= '';
$ReturnContent.= '';
$ReturnContent.= '';
$ReturnContent.= '';
$ReturnContent.= '
';
$ReturnContent.= '
';
}else{
//圖片廣告
$ReturnContent = '';
}
//如果為調用JS方式
if(self::$JS){
$ReturnContent = 'document.write("'.addslashes($ReturnContent).'");';
}
//重設預設值,這裡還是採用單件模式
self::$Id = 0;
self::$Order = 0;
self::$JS = 0;
return $ReturnContent;
}
}
?>

http://www.bkjia.com/PHPjc/324181.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/324181.htmlTechArticle調用方式如下:其中DebugStr這個函數就是類似一個echo。 複製代碼 代碼如下: DebugStr('$Adv-getContentById($id); $id為廣告編號, 僅調用一條,返回內...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.