<?php
//==================================================================
//=================include/common.inc.php===========================
//==================================================================
//dirname(__FILE__),返回路径%root%/ads/include
//substr(dirname("file"),0,-8);取得文件的上一级目录,返回%root%/ads,因为/include为8个字符
//定义常量MOD_ROOT,指向模块根目录
define('MOD_ROOT', substr(dirname(__FILE__), 0, -8));
//定义变量$mod为模块根目录名称
$mod = 'ads';
//引入文件/include/common.inc.php
require substr(MOD_ROOT, 0, -strlen($mod)).'include/common.inc.php';
//定义变量数组,存放文件头信息,爬虫的食物:标题、关键字、描述
$head['title'] = $MOD['name'];
$head['keywords'] = $MOD['name'];
$head['description'] = $MOD['name'];
?>
<?php
//=====================================================================
//=================include/global.inc.php==============================
//====================================================================
defined('IN_PHPCMS') or exit('Access Denied');
/**
* 返回广告的类型
*/
function get_type($type) {
global $LANG;
if($type=='image') return $LANG['image'];
elseif($type=='flash') return 'FLASH';
elseif($type=='text') return $LANG['text'];
elseif($type=='code') return $LANG['code'];
else return $LANG['unkown'];
}
/**
* 根据广告的类型,对其进行转换,返回相对应的html格式的内容
*
* @param $ads 原始内容
* @param $isjs 默认为1,表示默认为js,对其进行转换
* @return 转换后的html内容
*/
function ads_content($ads, $isjs = 1)
{
if (!is_array($ads)) return "";
@extract($ads);
switch ($type)
{
case 'image':
$imageurl = imgurl($imageurl, 1);
$content = ads_image($adsid, $linkurl, $imageurl, $width, $height, $alt);
break;
case 'flash':
$flashurl = imgurl($flashurl, 1);
$content = ads_flash($adsid, $flashurl, $width, $height, $wmode = 'transparent');
break;
case 'text':
$content = ads_text($adsid, $text);
break;
case 'code':
$content = ads_code($adsid, $code);
break;
}
return $isjs ? strip_js($content) : $content;
}
/**
* 对图片格式的内容进行转换
*
* @param $id
* @param $linkurl 点击图片的链接地址
* @param $imageurl 图片来源地址
* @param $width 图片的显示宽度
* @param $height 图片的显示高度
* @param $alt 鼠标悬停在图片上时的提示信息,默认为空,可选属性
* @return 转换后的html
*/
function ads_image($id, $linkurl, $imageurl, $width, $height, $alt = '')
{
global $PHP_SITEURL,$MOD;
$url = $MOD['enableadsclick'] ? $PHP_SITEURL.'ads/clickads.php?id='.$id : $linkurl;
return "<a href='".$url."' target='_blank'><img src='".$imageurl."' border='0' width='".$width."' height='".$height."' alt='".$alt."'></a>";
}
/**
* 对flash格式内容进行转换
*
* @param $id
* @param $flashurl flash文件的来源
* @param $width flash的显示宽度
* @param $height flash的显示高度
* @param $wmode 设定flash的窗口模式
* @return 转换后的html
*/
function ads_flash($id, $flashurl, $width, $height, $wmode = 'transparent')
{
return "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='".$width."' height='".$height."'>
<param name='movie' value='".$flashurl."' /><param name='quality' value='high' />
".($wmode ? "<param name='wmode' value='transparent' />" : "") ."
<embed src='".$flashurl."' width='".$width."' height='".$height."' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash'>
</embed>
</object>";
}
//对文本格式的广告,返回其内容
function ads_text($id, $text)
{
return $text;
}
//对代码格式的广告信息,返回其代码
function ads_code($id, $code)
{
return $code;
}
?>
<?php
//======================================================================
//=================include/createhtml/common.inc.php===================
//=====================================================================
//检查用户是否具有访问权限
defined('IN_PHPCMS') or exit('Access Denied');
//选择出第一条符合条件的广告
$ads = $db->get_one("SELECT * FROM ".TABLE_ADS." a, ".TABLE_ADS_PLACE." p WHERE a.placeid=p.placeid AND p.placeid=$placeid AND a.fromdate<=UNIX_TIMESTAMP() AND a.todate>=UNIX_TIMESTAMP() AND a.passed=1 AND a.checked=1 LIMIT 1");
//根据广告的类型,对其进行转换,返回相对应的html格式的内容
$content = ads_content($ads, $isjs);
$templateid = $ads['templateid'] ? $ads['templateid'] : 'ads';
//打开输出缓冲区
ob_start();
//加载模板文件
include template('ads', $templateid);
//返回内部缓冲区的内容
$data = ob_get_contents();
//这个比较重要,只有使用了这个函数后,缓冲区里的内容才会读取出来
ob_clean();
//设定文件路径
$filename = $isjs ? PHPCMS_ROOT.'/data/'.$MOD['htmldir'].'/'.$placeid.'.js' : PHPCMS_ROOT.'/data/'.$MOD['htmldir'].'/'.$placeid.'.html';
//添加文件
file_put_contents($filename, $data);
//尝试将 filename 所指定文件的模式改成 mode 所给定的
@chmod($filename, 0777);
?>
PHPCMS模块分析之广告模块详解----北冥神功破解法(二)
最新推荐文章于 2022-09-01 14:16:52 发布