discuz广告调用修改:
修改文件source/function/function_core.php 的adshow函数,增加了广告调用数量的控制
function adshow($parameter) {
global $_G;
if($_G['inajax'] || $_G['group']['closead']) {
return;
}
if(isset($_G['config']['plugindeveloper']) && $_G['config']['plugindeveloper'] == 2) {
return '<hook>[ad '.$parameter.']</hook>';
}
$params = explode('/', $parameter);
$customid = 0;
$customc = explode('_', $params[0]);
if($customc[0] == 'custom') {
$params[0] = $customc[0];
$customid = $customc[1];
}
// 增加调用数量
if ($customc[2]) {
$num = $customc[2];
}
$adcontent = null;
if(empty($_G['setting']['advtype']) || !in_array($params[0], $_G['setting']['advtype'])) {
$adcontent = '';
}
if($adcontent === null) {
loadcache('advs');
$adids = array();
$evalcode = &$_G['cache']['advs']['evalcode'][$params[0]];
$parameters = &$_G['cache']['advs']['parameters'][$params[0]];
$codes = &$_G['cache']['advs']['code'][$_G['basescript']][$params[0]];
if(!empty($codes)) {
foreach($codes as $adid => $code) {
$parameter = &$parameters[$adid];
$checked = true;
@eval($evalcode['check']);
if($checked) {
$adids[] = $adid;
}
}
if(!empty($adids)) {
$adcode = $extra = '';
@eval($evalcode['create']);
if(empty($notag)) {
// $adcontent = '<div'.($params[1] != '' ? ' class="'.$params[1].'"' : '').$extra.'>'.$adcode.'</div>'; discuz默认代码
// 修改为以下代码,增加了广告数量控制和随机显示
if($num>1){
$adcontent ='';
shuffle($adids);
foreach($adids as $adKey => $adID)
{
if($adKey == $num) break;
$adcode=$codes[$adID];
$adcontent .= '<div'.($params[1] != '' ? ' class="'.$params[1].'"' : '').$extra.'>'.$adcode.'</div>';
}
}else{
$adcontent = '<div'.($params[1] != '' ? ' class="'.$params[1].'"' : '').$extra.'>'.$adcode.'</div>';
}
} else {
$adcontent = $adcode;
}
}
}
}
$adfunc = 'ad_'.$params[0];
$_G['setting']['pluginhooks'][$adfunc] = null;
hookscript('ad', 'global', 'funcs', array('params' => $params, 'content' => $adcontent), $adfunc);
if(!$_G['setting']['hookscript']['global']['ad']['funcs'][$adfunc]) {
hookscript('ad', $_G['basescript'], 'funcs', array('params' => $params, 'content' => $adcontent), $adfunc);
}
return $_G['setting']['pluginhooks'][$adfunc] === null ? $adcontent : $_G['setting']['pluginhooks'][$adfunc];
}
模板调用代码:
discuz默认调用代码为 <!--{ad/custom_2}-->
新的控制广告显示数量代码为 <!--{ad/custom_2_3}--> 红色为调用数量