discuz! X3.2 自定义后台门户模块模板里的标签

这里只提供对源码的修改, 至于插件, 暂不考虑...

想在首页里展示一些自定义字段的内容, 奈何dz无此功能, 无奈去扒源码.

首先切到 source 文件夹下

1. 在 class/block/portal/block_article.php 此文件里, 找到 getdata 方法, 在大约 305 行, 找到 $list 数组, 对 'fields' 元素添加字段

$list[] = array(
>--->--->--->---'id' => $data['aid'],
>--->--->--->---'idtype' => 'aid',
>--->--->--->---'title' => cutstr($data['title'], $titlelength, ''),
>--->--->--->---'url' => fetch_article_url($data),
>--->--->--->---'pic' => $data['pic'],
>--->--->--->---'picflag' => $data['picflag'],
>--->--->--->---'summary' => cutstr(strip_tags($data['summary']), $summarylength, ''),
>--->--->--->---'fields' => array(
// add by debmzhang at 2014-12-17 16:59 --start
'download_url' => $data['download_url'],
'download_size' => $data['download_size'],
'download_type' => $data['download_type'],
'download_official_website' => $data['download_official_website'],
'newgame_url' => $data['newgame_url'],
'newgame_web' => $data['newgame_web'],
'newgame_status' => $data['newgame_status'],
'newgame_f' => $data['newgame_f'],
'newgame_kfs' => $data['newgame_kfs'],
'newgame_yys' => $data['newgame_yys'],
'newgame_ce_time' => $data['newgame_ce_time'],
// add by debmzhang at 2014-12-17 16:59 --end
>--->--->--->--->---'uid'=>$data['uid'],
>--->--->--->--->---'username'=>$data['username'],
>--->--->--->--->---'avatar' => avatar($data['uid'], 'small', true, false, false, $_G['setting']['ucenterurl']),
>--->--->--->--->---'avatar_middle' => avatar($data['uid'], 'middle', true, false, false, $_G['setting']['ucenterurl']),
>--->--->--->--->---'avatar_big' => avatar($data['uid'], 'big', true, false, false, $_G['setting']['ucenterurl']),
>--->--->--->--->---'fulltitle' => $data['title'],
>--->--->--->--->---'dateline'=>$data['dateline'],
>--->--->--->--->---'caturl'=> $_G['cache']['portalcategory'][$data['catid']]['caturl'],
>--->--->--->--->---'catname' => $_G['cache']['portalcategory'][$data['catid']]['catname'],
>--->--->--->--->---'articles' => $_G['cache']['portalcategory'][$data['catid']]['articles'],
>--->--->--->--->---'viewnum' => intval($data['viewnum']),
>--->--->--->--->---'commentnum' => intval($data['commentnum'])
>--->--->--->---)
>--->--->---);

2. 修改文件 function/function_block.php

1> 找到 block_template 方法,  在大约293行, 即在 $fields 下, 再添加一些内容, 与原来的 $fields 进行 array_merge 操作

// add by debmzhang at 2014-12-18 14:34  --start
$fieldsForExtra = array(
'download_url' => array('name' => '下载频道--下载地址', 'formtype' => 'download_url', 'datatype' => 'download_url'),
'download_size' => array('name' => '下载频道--下载大小', 'formtype' => 'download_size', 'datatype' => 'download_size'),
'download_type' => array('name' => '下载频道--下载类型', 'formtype' => 'download_type', 'datatype' => 'download_type'),
'download_official_website' => array('name' => '下载频道--下载官网', 'formtype' => 'download_official_website', 'datatype' => 'download_official_website'),
'newgame_url' => array('name' => '新游频道--下载地址', 'formtype' => 'newgame_url', 'datatype' => 'newgame_url'),
'newgame_web' => array('name' => '新游频道--下载官网', 'formtype' => 'newgame_web', 'datatype' => 'newgame_web'),
'newgame_status' => array('name' => '新游频道--下载状态', 'formtype' => 'newgame_status', 'datatype' => 'newgame_status'),
'newgame_f' => array('name' => '新游频道--下载激活码', 'formtype' => 'newgame_f', 'datatype' => 'newgame_f'),
'newgame_kfs' => array('name' => '新游频道--开发商', 'formtype' => 'newgame_kfs', 'datatype' => 'newgame_kfs'),
'newgame_yys' => array('name' => '新游频道--运营商', 'formtype' => 'newgame_yys', 'datatype' => 'newgame_yys'),
'newgame_ce_time' => array('name' => '新游频道--测试时间', 'formtype' => 'newgame_ce_time', 'datatype' => 'newgame_ce_time'),
);
$fields = array_merge($fields, $fieldsForExtra);
// add by debmzhang at 2014-12-18 14:34 --end

2> 继续往下找, $fields 数组进行 foreach 操作时, 添加自己的逻辑, 也就是在这里进行了数据的替换操作

foreach($fields as $key=>$field) {
>--->--->--->---$replacevalue = $blockitem[$key];
>--->--->--->---$field['datatype'] = !empty($field['datatype']) ? $field['datatype'] : '';
>--->--->--->---if($field['datatype'] == 'int') {// int
>--->--->--->--->---$replacevalue = intval($replacevalue);
>--->--->--->---} elseif($field['datatype'] == 'string') {
>--->--->--->--->---$replacevalue = preg_quote($replacevalue);
>--->--->--->---} elseif($field['datatype'] == 'date') {
>--->--->--->--->---$replacevalue = dgmdate($replacevalue, $block['dateuformat'] ? 'u' : $block['dateformat'], '9999', $block['dateuformat'] ? $block['dateformat'] : '');
>--->--->--->---} elseif($field['datatype'] == 'title') {//title
>--->--->--->--->---$searcharr[] = '{title-title}';
>--->--->--->--->---$replacearr[] = preg_quote(!empty($blockitem['fields']['fulltitle']) ? $blockitem['fields']['fulltitle'] : dhtmlspecialchars($replacevalue));
>--->--->--->--->---$searcharr[] = '{alt-title}';
>--->--->--->--->---$replacearr[] = preg_quote(!empty($blockitem['fields']['fulltitle']) ? $blockitem['fields']['fulltitle'] : dhtmlspecialchars($replacevalue));
>--->--->--->--->---$replacevalue = preg_quote($replacevalue);
>--->--->--->--->---if($blockitem['showstyle'] && ($style = block_showstyle($blockitem['showstyle'], 'title'))) {
>--->--->--->--->--->---$replacevalue = '<font style="'.$style.'">'.$replacevalue.'</font>';
>--->--->--->--->---}
// add by debmzhang at 2014-12-17 18:25 --start
} elseif ($field['datatype'] == 'download_url') {
$searcharr[] = '{download_url}';
$replacearr[] = preg_quote(!empty($blockitem['fields']['download_url']) ? $blockitem['fields']['download_url'] : dhtmlspecialchars($replacevalue));
$replacevalue = preg_quote($replacevalue);
} elseif ($field['datatype'] == 'download_size') {
$searcharr[] = '{download_size}';
$replacearr[] = preg_quote(!empty($blockitem['fields']['download_size']) ? $blockitem['fields']['download_size'] : dhtmlspecialchars($replacevalue));
$replacevalue = preg_quote($replacevalue);
} elseif ($field['datatype'] == 'download_type') {
$searcharr[] = '{download_type}';
$replacearr[] = preg_quote(!empty($blockitem['fields']['download_type']) ? $blockitem['fields']['download_type'] : dhtmlspecialchars($replacevalue));
$replacevalue = preg_quote($replacevalue);
} elseif ($field['datatype'] == 'download_official_website') {
$searcharr[] = '{download_official_website}';
$replacearr[] = preg_quote(!empty($blockitem['fields']['download_official_website']) ? $blockitem['fields']['download_official_website'] : dhtmlspecialchars($replacevalue));
$replacevalue = preg_quote($replacevalue);
} elseif ($field['datatype'] == 'newgame_url') {
$searcharr[] = '{newgame_url}';
$replacearr[] = preg_quote(!empty($blockitem['fields']['newgame_url']) ? $blockitem['fields']['newgame_url'] : dhtmlspecialchars($replacevalue));
$replacevalue = preg_quote($replacevalue);
} elseif ($field['datatype'] == 'newgame_web') {
$searcharr[] = '{newgame_web}';
$replacearr[] = preg_quote(!empty($blockitem['fields']['newgame_web']) ? $blockitem['fields']['newgame_web'] : dhtmlspecialchars($replacevalue));
$replacevalue = preg_quote($replacevalue);
} elseif ($field['datatype'] == 'newgame_status') {
$searcharr[] = '{newgame_status}';
$replacearr[] = preg_quote(!empty($blockitem['fields']['newgame_status']) ? $blockitem['fields']['newgame_status'] : dhtmlspecialchars($replacevalue));
$replacevalue = preg_quote($replacevalue);
} elseif ($field['datatype'] == 'newgame_ce_time') {
$searcharr[] = '{newgame_ce_time}';
$replacearr[] = preg_quote(!empty($blockitem['fields']['newgame_ce_time']) ? $blockitem['fields']['newgame_ce_time'] : dhtmlspecialchars($replacevalue));
$replacevalue = preg_quote($replacevalue);
// add by debmzhang at 2014-12-17 18:25 --end
>--->--->--->---} elseif($field['datatype'] == 'summary') {//summary
>--->--->--->--->---$replacevalue = preg_quote($replacevalue);
>--->--->--->--->---if($blockitem['showstyle'] && ($style = block_showstyle($blockitem['showstyle'], 'summary'))) {
>--->--->--->--->--->---$replacevalue = '<font style="'.$style.'">'.$replacevalue.'</font>';
>--->--->--->--->---}
>--->--->--->---}

3. 在后台 门户--模块模板  添加新的 模块模板的时候, 就可以使用自己定义的标签了, 这里最好都写成数据库里的字段, 当然, 上面的一些描述里都是使用的我在数据库里添加的字段名.

到此, 前台自定义diy时使用这个模块模板的时候, 数据就会被替换为数据库里的内容了...

上一篇:12.2备库rman使用delete删除归档日志报错RMAN-08137: WARNING: archived log not deleted, needed for standby or upstream capture process


下一篇:RMAN数据库恢复之恢复表空间和数据文件