立即注册 登录
彼岸网 返回首页

天香公主的个人空间 http://www.bian-wang.com/discuz/?10005 [收藏] [复制] [分享] [RSS] https://github.com/txgz999/discuz/wiki

日志

Discuz功能改进:最新点评日志榜(续)

已有 2501 次阅读2014-11-20 12:36 AM |个人分类:Discuz|系统分类:社交网理论与实践

新评日志榜和热评日志榜(续)

上次我们讨论了最新点评日志榜和热门评论日志榜(链接)。当我们将最新点评日志榜放上彼岸网的门户页后发现一个缺点,就是当我们阅读了这个榜上的一篇博文后,过一会再来到门户页的时候,从这个榜上看不出那篇博文是否有新评论。经过讨论我们觉得应该加个mouseover的功能,当mouseover一条博文时显示最新的一条评论。这既解决了前述问题,又能是用户在门户页上就了解了最新评论。下面是效果图。


我们在上次的最新点评日志榜的基础上,还是在上次修改和添加的四个文件上继续增加些代码。

1。 在source/language/lang_blockclass.php加入:
'blockclass_blog_field_lastcommentauthor' => '最新评论作者',
'blockclass_blog_field_lastcomment' => '最新评论',
'blockclass_blog_field_lastcommentdateline' => '最新评论时间',

2。在source/language/block/lang_bloglist.php加入:
'bloglist_lastcommentlength' => '最新评论长度',

3。在source/class/block/space/block_blog.php里做下述三个修改:
3a)增加一个显示最新评论的长度的上限的设置,这个值可以在DIY模块里设置。在函数block_blog里的$this->setting = array(...);句加
'lastcommentlength'	=> array(
   'title' => 'bloglist_lastcommentlength',
   'type' => 'text',
   'default' => 200
),
3b) 在输出的数据中加三个与最新评论有关的变量。在函数fields的return array(...);句里加
'lastcommentauthor' => array('name' => lang('blockclass', 'blockclass_blog_field_lastcommentauthor'), 'formtype' => 'text', 'datatype' => 'string'),
'lastcomment' => array('name' => lang('blockclass', 'blockclass_blog_field_lastcomment'), 'formtype' => 'text', 'datatype' => 'string'),
'lastcommentdateline' => array('name' => lang('blockclass', 'blockclass_blog_field_lastcommentdateline'), 'formtype' => 'date', 'datatype' => 'date'),
3c)在函数getdata里需要做些修改,一是
$lastcommentlength = $parameter['lastcommentlength'] ? intval($parameter['lastcommentlength']) : 200;
二是下面这个while循环需要做些改动,加入对新加的三个与最新评论有关的变量的赋值。 为完整起见,下面是这个代码的全部:
while($data = DB::fetch($query)) {
    if(empty($data['pic'])) {
        $data['pic'] = STATICURL.'image/common/nophoto.gif';
        $data['picflag'] = '0';
    } else {
        $data['pic'] = preg_replace('/\.thumb\.jpg$/', '', $data['pic']);
        $data['pic'] = 'album/'.$data['pic'];
        $data['picflag'] = $data['remote'] == '1' ? '2' : '1';
    }
    $lastcomment = '';
    $lastcommentauthor = '';   
    if ($data['lastcommentdateline']) {
        $csql = "SELECT c.* FROM ".DB::table('home_comment')." c WHERE c.id=".$data['blogid']." AND c.dateline=".$data['lastcommentdateline']." AND c.status=0 LIMIT 0,1;";   
        if($cdata = DB::fetch_first($csql)) {
            $lastcomment = $cdata['message'];
            $lastcommentauthor = $cdata['author'];   
        }
    }
    $list[] = array(
        'id' => $data['blogid'],
        'idtype' => 'blogid',
        'title' => cutstr($data['subject'], $titlelength, ''),
        'url' => 'home.php?mod=space&uid='.$data[uid].'&do=blog&id='.$data['blogid'],
        'pic' => $data['pic'],
        'picflag' => $data['picflag'],
        'summary' => $data['message'] ? preg_replace("/&[a-z]+\;/i", '', cutstr(strip_tags($data['message']), $summarylength, '')) : '',
        'fields' => array(
            'fulltitle' => $data['subject'],
            'dateline'=>$data['dateline'],
            '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']),
            'replynum'=>$data['replynum'],
            'viewnum'=>$data['viewnum'],
            'click1'=>$data['click1'],
            'click2'=>$data['click2'],
            'click3'=>$data['click3'],
            'click4'=>$data['click4'],
            'click5'=>$data['click5'],
            'click6'=>$data['click6'],
            'click7'=>$data['click7'],
            'click8'=>$data['click8'],
            'lastcommentauthor' => $lastcommentauthor, 
            'lastcomment' => $lastcomment ? preg_replace("/&[a-z]+\;/i", '', cutstr(strip_tags($lastcomment), $lastcommentlength, '')) : '',
            'lastcommentdateline'=>$data['lastcommentdateline'],
        )
    );
}

4。在source/class/block/space/block_blogcommentnew.php内,在函数block_blog里的$this->setting = array(...);句加
'lastcommentlength'	=> array(
   'title' => 'bloglist_lastcommentlength',
   'type' => 'text',
   'default' => 200
),


在管理中心的工具页上更新缓存后,我们就可以在门户页进入DIY高级模式里去编辑那个最新点评日志榜。注意在模块的设置窗口出现了我们新加的设置项和数组值:



将它的模块模板改为: <div class="module cl xl xl1"> <ul> [loop] <li><a href="{url}" tip="最新评论: <strong>{lastcommentauthor}</strong> ({lastcommentdateline})<br/>{lastcomment}" onmouseover="showTip(this);" {target}>{title}</a></li> [/loop] </ul> </div>  
模板里用到的函数showTip是Discuz提供的,可以很方便的将HTML代码显示在弹出框里。Discuz提供的多个功能都用了这个函数,如个人资料页里的链接和论坛首页四格里的贴子链接:




评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 立即注册

小黑屋|Archiver|彼岸网  

Powered by Discuz! X3.1 © 2001-2014 Comsenz Inc.
GMT-4, 2024-3-29 01:15 AM , Processed in 0.015280 second(s), 8 queries. ,ApcOn

返回顶部