1.修改函数getad:
进入function/common.func.php文件,找到函数getad,将它替换为以下函数:- //$value为频道或者广告ID, style为广告投放位置, pagetype广告投放页面
- function getad($type, $value, $pagetype='') {
- global $_SGLOBAL, $_SCONFIG;
- $adarr = $paramarr = $advlist = $adresult = array();
- $advhtml = $adpageout = '';
- $advcount = 0;
- if($type == 'system') {
- if($value == 'space') {
- @include_once S_ROOT .'./data/system/adspace.cache.php';
- }else{
- @include_once S_ROOT .'./data/system/adsystem.cache.php';
- }
- //判断此频道是否有广告
- if(!empty($_SGLOBAL['ad'][$value]) || !empty($_SGLOBAL['ad']['all'])){
- if(!empty($_SGLOBAL['ad']['all']) && !empty($_SGLOBAL['ad'][$value])) {
- $adarr = array_merge($_SGLOBAL['ad']['all'],$_SGLOBAL['ad'][$value]);
- }elseif(!empty($_SGLOBAL['ad'][$value])){
- $adarr = $_SGLOBAL['ad'][$value];
- }else{
- $adarr = $_SGLOBAL['ad']['all'];
- }
- foreach($adarr as $key=>$advalue) {
- $paramarr = $advalue['parameters'];
- if(!empty($paramarr['endtime']) && (strtotime($paramarr['startime']) > ($_SGLOBAL['timestamp']+$_SCONFIG['timeoffset']*3600) || (strtotime($paramarr['endtime']) < $_SGLOBAL['timestamp']+$_SCONFIG['timeoffset']*3600))) {
- continue;
- } else {
- //获取广告代码
- switch($advalue['adtype']) {
- case 'text':
- $advhtml = '<a href="'.$paramarr['texturl'].'" target="_blank" style="font-size: '.$paramarr['fontsize'].'px;">'.stripslashes($paramarr['textcontent']).'</a>';
- break;
- case 'code':
- $advhtml = stripslashes($paramarr['adcodecontent']);
- break;
- case 'image':
- $advhtml = '<a href="'.$paramarr['imageurl'].'" target="_blank"><img src="'.$paramarr['imagesrc'].'" width="'.$paramarr['imagewidth'].'px" height="'.$paramarr['imageheight'].'px" alt="'.$paramarr['imagetext'].'" /></a>';
- break;
- case 'flash':
- $advhtml = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" adcodebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0" width="'.$paramarr['flashwidth'].'px" height="'.$paramarr['flashheight'].'px">';
- $advhtml .= '<param name="movie" value="'.stripslashes($paramarr['flashsrc']).'" />';
- $advhtml .= '<param name="quality" value="high" />';
- $advhtml .= '<embed src="'.stripslashes($paramarr['flashsrc']).'" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'.$paramarr['flashwidth'].'px" height="'.$paramarr['flashheight'].'px"></embed>';
- $advhtml .= '</object>';
- }
- if(!empty($pagetype) && in_array($pagetype, explode("\t", $advalue['pagetype'])) || in_array('all', explode("\t", $advalue['pagetype']))) {
- if($advalue['style'] == 'pageoutindex' || $advalue['style'] == 'all') {
- $adpageout = addcslashes($advhtml , '/"\\');
- $adpageout = str_replace("\n", '<br />',$adpageout);
- $adpageout = str_replace("\r", '',$adpageout);
- $adpageout = <<<EOF
- <script type="text/javascript">
- function openwin() {
- OpenWindow=window.open("", (window.name!="newwin")?"newwin":"", "height={$paramarr[outwidth]}px, width={$paramarr[outheight]}px,toolbar=no ,scrollbars=no,menubar=no");
- OpenWindow.document.write("$adpageout");
- OpenWindow.document.close();
- }
- openwin();
- </script>
- EOF;
- }
- } else {
- continue;
- }
- switch($advalue['style']) {
- case 'pageoutindex' :
- $advlist['pageoutindex'][] = $adpageout;
- break;
- case 'all' :
- $advlist['pageheadad'][] = $advhtml;
- $advlist['pagecenterad'][] = $advhtml;
- $advlist['pagefootad'][] = $advhtml;
- $advlist['pagemovead'][] = $advhtml;
- $advlist['pageoutad'][] = $advhtml;
- $advlist['siderad'][] = $advhtml;
- $advlist['viewinad'][] = $advhtml;
- $advlist['pageoutindex'][] = $adpageout;
- break;
- default :
- $advlist[$advalue['style']][] = $advhtml;
- }
- }
- }
- foreach($advlist as $key=>$value) {
- $advcount = count($value);
- if($key=='pageheadad'){ //显示多个顶部广告
- $adresult['pageheadad'] = $value;
- }elseif($key=='pagefootad'){ //显示多个底部广告
- $adresult['pagefootad'] = $value;
- }elseif($key=='pagecenterad'){ //显示多个中央横幅广告
- $adresult['pagecenterad'] = $value;
- }else{
- if($advcount>0) {
- $adresult[$key] = $advcount > 1 ? $value[mt_rand(0, $advcount -1)] : $value[0];
- }
- }
- }
-
- if(!empty($adresult)) {
- return $adresult;
- } elseif(empty($adresult)){
- return '';
- }
- } else {
- return '';
- }
- } elseif($type == 'user') {
- @include_once S_ROOT .'./data/system/aduser.cache.php';
- $adid = intval($value);
- $adarr = $_SGLOBAL['ad'][$adid];
- $paramarr = $adarr['parameters'];
- if(!empty($paramarr['endtime']) && (strtotime($paramarr['startime']) > ($_SGLOBAL['timestamp']+$_SCONFIG['timeoffset']*3600) || (strtotime($paramarr['endtime']) < $_SGLOBAL['timestamp']+$_SCONFIG['timeoffset']*3600))) {
- return '';
- } else {
- return $paramarr['adechocontent'];
- }
- }
- }
复制代码 2、这样在页面上接收到的返回值中头部和尾部广告就是一个数组,而不是单一的值,然后就可以在页面上循环显示了。
在每个页面中都有这样一句代码:- <!--{eval $ads = getad('system', 'indexad', '1'); }-->
复制代码 它是将所有要显示的广告取出来放在变量$ads里面,这个代码基本上在每个页面上都会有,不用管它,我们要修改的是显示代码。
广告的显示代码都是形如这个样子的:- <!--{if !empty($ads['pageheadad']) }-->
- <div class="ad_header">$ads[pageheadad]</div>
- <!--{/if}-->
复制代码 $ads的key值决定了要显示哪种广告,修改为形如下面这样的:- <!--{if !empty($ads['pageheadad']) }-->
- <!--{loop $ads['pageheadad'] $ad}-->
- <div class="ad_header">$ad</div>
- <!--{/loop}-->
- <!--{/if}-->
复制代码 显示广告的代码在在每个模块文件中都有,要正常显示,需要全部修改才行。
注意:上面修改过的函数只对应中央横幅广告(pagecenterad)、顶部广告(pageheadad)、底部广告(pagefootad)。
上面给出的修改方法,只是显示,不保证美观。 |