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

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

日志

Discuz功能改进:如何用@来发通知

热度 8已有 11480 次阅读2014-11-20 11:30 PM |个人分类:Discuz|系统分类:社交网理论与实践

在一些论坛里,用户可以在贴子里写上另一个用户的用户名,并加一个@前缀,这样对方就会收到通知来看这个帖子。

下面是虎扑论坛里的一个例子:






下面我们尝试在Discuz系统的记录里加上这个功能。

1。 在source/language/lang_notification.php加入: 'doing_mention' => '{actor} 在 < a href="{url}" target="_blank">记录</a> 中提到了您', 2。 在source/include/spacecp/spacecp_doing.php里下面一段: if($updo['uid'] != $_G['uid']) { notification_add($updo['uid'], 'doing', 'doing_reply', array( 'url'=>"home.php?mod=space&uid=$updo[uid]&do=doing&view=me&doid=$updo[doid]&highlight=$newid", 'from_id'=>$updo['doid'], 'from_idtype'=>'doid')); updatecreditbyaction('comment', 0, array(), 'doing'.$updo['doid']); } 之后加入: if (preg_match_all("/(&nbsp;|\s|^)@(\S+)(&nbsp;|\s|$)/", $message, $matches)) { $result = array_unique($matches[2]); foreach($result as $ausername) { if(($auid = C::t('common_member')->fetch_uid_by_username($ausername))) { if (($auid != $_G['uid']) && ($auid != $updo['uid'])) { if (!isblacklist($auid)) notification_add($auid, 'comment', 'doing_mention', array( 'url'=>"home.php?mod=space&uid=$auid&do=doing&view=me&doid=$updo[doid]&highlight=$newid", 'from_id'=>$updo['doid'], 'from_idtype'=>'doid')); } } } } 下面是效果图:





以上只是讨论下做法,不足为据。 类似的可以将这个功能引入日志及其评论中,在这里就不讨论了。

注:本文中的代码里的某些<符号后人为加了一个不应该有的空格,以避免Discuz在保存日志时自动改变日志内容。

5/1/2016补充:经网友sesemule提醒,发现原来的代码只处理了记录里的回复部分,没处理记录本身。要支持记录本身的话,还要做下面的改动:
3。 在source/include/spacecp/spacecp_doing.php里下面一句: C::t('common_member_field_home')->update($_G['uid'], $setarr); 之后加入: if (preg_match_all("/(&nbsp;|\s|^)@(\S+)(&nbsp;|\s|$)/", $message, $matches)) { $result = array_unique($matches[2]); foreach($result as $ausername) { if(($auid = C::t('common_member')->fetch_uid_by_username($ausername))) { if ($auid != $_G['uid']) { if (!isblacklist($auid)) notification_add($auid, 'comment', 'doing_mention', array( 'url'=>"home.php?mod=space&uid=$auid&do=doing&view=me&doid=$newdoid&highlightdoing=$newdoid", 'from_id'=>$updo['doid'], 'from_idtype'=>'doid')); } } } } 4。 在source/include/space/space_doing.php里将下面这句 $uids = $_GET['highlight'] ? array() : array($space['uid']); 改成: $uids = ($_GET['highlight'] || $_GET['highlightdoing']) ? array() : array($space['uid']); 5。 在source/include/space/space_doing.php里下面这段: $query = C::t('home_doing')->fetch_all_search($start, $perpage, 1, $uids, '', $searchkey, '', '' ,'', 1, $doid, $f_index); foreach($query as $value) { 之后加入: if($_GET['highlightdoing'] && $value['doid'] == $_GET['highlightdoing']) { $value['style'] .= 'color:#F60;'; } 6。在template/default/home/space_doing.htm里将下面这句 <dd class="{if empty($diymode)}ptm{else}ptw{/if} xs2"> 改成: <dd class="{if empty($diymode)}ptm{else}ptw{/if} xs2" style="$dv[style]">
相关代码下载: http://www.bian-wang.com/upload/txgz_doing_at_notification_160502a.zip

5/16/2016补充:应网友sesemule的要求,把这个功能扩展到日志及其评论:
1)加汉字:在文件 source/language/lang_notification.php 中加入:
'blog_mention' => '{actor} 在 < a href="{url}" target="_blank">日志</a> 中提到了您', 'blogcomment_mention' => '{actor} 在 < a href="{url}" target="_blank">日志评论</a> 中提到了您', 2)日志的通知:在文件 source/include/spacecp/spacecp_blog.php 里的下面这段
if($newblog = blog_post($_POST, $blog)) { if(empty($blog) && $newblog['topicid']) { $url = 'home.php?mod=space&uid='.$_G['uid'].'&do=topic&topicid='.$newblog['topicid'].'&view=blog&quickforward=1'; } else { $url = 'home.php?mod=space&uid='.$newblog['uid'].'&do=blog&quickforward=1&id='.$newblog['blogid']; } 后加入 if (preg_match_all("/(&nbsp;|\s|^)@(\S+)(&nbsp;|\s|$)/", $_POST['message'], $matches)) { $n_url = 'home.php?mod=space&uid='.$newblog['uid'].'&do=blog&id='.$newblog['blogid']; $result = array_unique($matches[2]); foreach($result as $ausername) { if(($auid = C::t('common_member')->fetch_uid_by_username($ausername))) { if ($auid != $_G['uid']) { if (!isblacklist($auid)) notification_add($auid, 'comment', 'blog_mention', array('url'=>$n_url)); } } } } 3)日志评论的通知:
3a)新评论:在文件 source/include/spacecp/spacecp_comment.php 里的下面这段
$cidarr = add_comment($message, $id, $idtype, $cid); 后加入 if ($idtype == 'blogid') { if (preg_match_all("/(&nbsp;|\s|^)@(\S+)(&nbsp;|\s|$)/", $message, $matches)) { if($cidarr['cid'] != 0 && $comment = C::t('home_comment')->fetch($cidarr['cid'], $_G['uid'])) { $n_url = "home.php?mod=space&uid=$comment[uid]&do=blog&id=$id&cid=$cidarr[cid]"; $result = array_unique($matches[2]); foreach($result as $ausername) { if(($auid = C::t('common_member')->fetch_uid_by_username($ausername))) { if ($auid != $_G['uid']) { if (!isblacklist($auid)) notification_add($auid, 'comment', 'blogcomment_mention', array('url'=>$n_url)); } } } } } } 3b)修改评论: 在文件 source/include/spacecp/spacecp_comment.php 里的下面这段
C::t('home_comment')->update($comment['cid'], array('message'=>$message, 'status'=>$comment_status)); 后加入 if ($comment['idtype'] == 'blogid') { if (preg_match_all("/(&nbsp;|\s|^)@(\S+)(&nbsp;|\s|$)/", $message, $matches)) { $n_url = "home.php?mod=space&uid=$comment[uid]&do=blog&id=$comment[id]&cid=$cid"; $result = array_unique($matches[2]); foreach($result as $ausername) { if(($auid = C::t('common_member')->fetch_uid_by_username($ausername))) { if ($auid != $_G['uid']) { if (!isblacklist($auid)) notification_add($auid, 'comment', 'blogcomment_mention', array('url'=>$n_url)); } } } } }

发表评论 评论 (174 个评论)

回复 天香公主 2017-4-14 11:42 PM
sesemule: 天香,discuz有一个“登录安全提醒”功能,如果本次登录与上次登录的IP地址不同,就会在右下角弹窗提醒用户,大概是这个样子:
[img]http://www.bian-wang.com/d ...
嗯,这个主意不错。我想可以这样做,你试试吧:
1)修改语言包文件 source/language/lang_notification.php,在末端加入

    'ipnotice' => '<div class="bm"><h2>安全提醒</h2><div class="bm_c" style="width: 400px;">
<dl class="xld cl bbda">
<dd>本次登录位置 {nowip} {nowipConvert}<br />上次登录位置 {lastip} {lastipConvert}<br />上次登录时间 {lastipDate}</dd>
</dl>
<p class="ptn cl"><a href="home.php?mod=spacecp&ac=profile&op=password" onclick="setcookie(\'lip\', \'\', -1);" class="xi2 y">登录地点异常,建议立即更改密码 &raquo;</a></p>
</div>',

2)修改函数库文件 source/function/function_misc.php,在末端加入

function ipnotice() {
    global $_G;
    if (!$_G['setting']['bbclosed'] && !$_G['member']['freeze'] && !$_G['member']['groupexpiry'] && $_G['setting']['disableipnotice'] != 1 && $_G['uid'] && !empty($_G['cookie']['lip']) && $_G['cookie']['lip'] != ',')
    {
        $status = C::t('common_member_status')->fetch($_G['uid']);
                $lip = explode(',', $_G['cookie']['lip']);

                $lastipConvert = convertip($lip[0]);
        $lastipDate = dgmdate($lip[1]);

                $nowipConvert = convertip($status['lastip']);

        $lastipConvert = process_ipnotice($lastipConvert);
                $nowipConvert = process_ipnotice($nowipConvert);

                if($lastipConvert != $nowipConvert && stripos($lastipConvert, $nowipConvert) == false && stripos($nowipConvert, $lastipConvert) == false) {
                        notification_add($_G['uid'], 'system', 'ipnotice', array(
                'nowip' => $status['lastip'],
                'nowipConvert' => $nowipConvert,
                'lastip' => $lip[0],
                'lastipConvert' => $lastipConvert,
                'lastipDate' => $lastipDate
            ),1);
                }
    }
}

3)修改类文件 source/class/class_member.php,在函数 on_login 的定义里的下面一句

C::t('common_member_status')->update($_G['uid'], array('lastip' => $_G['clientip'], 'port' => $_G['remoteport'], 'lastvisit' =>TIMESTAMP, 'lastactivity' => TIMESTAMP));

后添加:

require_once libfile('function/misc');
ipnotice();
回复 sesemule 2017-4-13 11:23 PM
天香,discuz有一个“登录安全提醒”功能,如果本次登录与上次登录的IP地址不同,就会在右下角弹窗提醒用户,大概是这个样子:


(开启这个功能的方法是:后台→全局→站点功能→其他→“关闭登录安全提醒”选择否)

天香能否帮忙把这个功能集成到系统提醒里面?就是如果本次登录与上次登录的IP地址不同,就会给用户发送一条系统提醒,告知用户本次的登录IP、上次的登录IP以及登录时间等信息。

我觉得系统提醒比右下角弹窗提醒显得更正式,毕竟是涉及到安全的比较重要的问题;而弹窗提醒有可能被某些浏览器当成广告给拦截掉,或者直接被用户习惯性忽略掉。
回复 天香公主 2017-4-8 08:56 AM
东风: 我有折腾了https, 才注意到,将来用远程附件, 就没法一致了,不过那也得用远程附件。
嗯,用https好。远程附件那也用https,应该不会有问题吧
回复 东风 2017-4-8 04:31 AM
天香公主: "基本设置"tab下原来是
    本地附件保存位置: ./data/attachment
    本地附件 URL 地址: data/attachment
你把它们改成了URL估计不行吧,似乎应该改在"远程 ...
我有折腾了https, 才注意到,将来用远程附件, 就没法一致了,不过那也得用远程附件。
回复 东风 2017-4-8 04:29 AM
carry0987: 好吧.....
你改好了,我以后向您取经~
回复 carry0987 2017-4-6 06:20 PM
天香公主: "基本设置"tab下原来是
    本地附件保存位置: ./data/attachment
    本地附件 URL 地址: data/attachment
你把它们改成了URL估计不行吧,似乎应该改在"远程 ...
好吧.....
回复 天香公主 2017-4-6 11:53 AM
carry0987:
http://i.imgur.com/A4pFeWN.png
目前我只改了這個..
"基本设置"tab下原来是
    本地附件保存位置: ./data/attachment
    本地附件 URL 地址: data/attachment
你把它们改成了URL估计不行吧,似乎应该改在"远程附件"tab里
回复 carry0987 2017-4-5 07:35 AM

目前我只改了這個..
回复 天香公主 2017-4-5 06:40 AM
carry0987: 天香,我將論壇的附件完全移動到qbnehs.besv.net這個遠程空間(意思是將attachment整個資料夾移至遠程空間並且刪除本地的attachment),結果圖片就無法上傳了..... ...
是这个远程空间设置有问题吧?
回复 天香公主 2017-4-5 06:38 AM
sesemule: 赞!
  
回复 carry0987 2017-4-5 05:24 AM
天香,我將論壇的附件完全移動到qbnehs.besv.net這個遠程空間(意思是將attachment整個資料夾移至遠程空間並且刪除本地的attachment),結果圖片就無法上傳了......出現圖片上傳失敗...
回复 sesemule 2017-4-5 12:25 AM
天香公主: 同意。可以在我加的代码
   notification_add($auid, ...
前加个条件,改成
   if (!isblacklist($auid)) notification_add($auid, ...
我在文中都加了。 ...
赞!
回复 天香公主 2017-4-4 08:25 PM
sesemule: 天香,我觉得@功能需要辅以可屏蔽功能,也就是“被我拉进黑名单的人不能@我”,否则会被某些居心不良的人用来骚扰他人。

在别处看到一个帖子,是完善论坛黑名单 ...
同意。可以在我加的代码
   notification_add($auid, ...
前加个条件,改成
   if (!isblacklist($auid)) notification_add($auid, ...
我在文中都加了。
回复 sesemule 2017-4-4 07:09 AM
天香,我觉得@功能需要辅以可屏蔽功能,也就是“被我拉进黑名单的人不能@我”,否则会被某些居心不良的人用来骚扰他人。

在别处看到一个帖子,是完善论坛黑名单的功能的,天香看下能否借鉴来给咱们的@功能加上拉黑的功能?链接在这里:http://gedong.net/forum.php?mod=viewthread&tid=447
回复 carry0987 2017-3-8 11:26 PM
天香公主: 嗯,之所以问题只出在手机上,而在电脑和iPad上没问题是因为文件source/function/function_blog.php 里的函数 blog_post 里有下面这段:
if($_G['mobile']) {
    ...
在後面多加一個 0 後就解決問題了,我提交到git上吧....
測試結果:https://www.fucknehs.com/home.php?mod=space&uid=1&do=blog&quickforward=1&id=27
回复 carry0987 2017-3-8 11:20 PM
天香公主: 嗯,之所以问题只出在电话上,而在电脑和iPad上没问题是因为文件source/function/function_blog.php 里的函数 blog_post 里有下面这段:
if($_G['mobile']) {
    ...
屬於特殊情況.....
但是,你也知道,Dz的手機版功能實在是太少了,連BBcode都不能用,也因為現在的手機屏幕越來越大,所以在手機上使用電腦版的情況其實不在少數
回复 天香公主 2017-3-8 11:04 PM
carry0987: 官方在Git上表示無法修復,因為編輯器很容易在修正一個錯誤後同時新增更多的錯誤....他們表示當初Dz的js堅持自己寫,所以產生了這個大坑 ...
嗯,之所以问题只出在手机上,而在电脑和iPad上没问题是因为文件source/function/function_blog.php 里的函数 blog_post 里有下面这段:
if($_G['mobile']) {
    $POST['message'] = getstr($POST['message'], 0, 0, 0, 1);
    $POST['message'] = censor($POST['message']);
} else {
    $POST['message'] = getstr($POST['message'], 0, 0, 0, 0, 1);
    $POST['message'] = censor($POST['message']);
    ....
如果在电话上提交日志,$_G['mobile']非空,所以执行的是前一部分代码,而电脑和iPad上提交日志,则执行后半部分的代码。所以结果就不同了。如果把这判断和前半部分去掉,估计就解决了你的问题,但这样做会产生新问题吗?我不敢断言。

估计这个问题只有在手机上用Discuz的电脑版才出现吧。大多数人在手机上应该是用手机版或APP吧?
回复 carry0987 2017-3-8 10:49 PM
天香公主: 哦,qbnehs.com是3.2, 我想在那试下,但上次开的账号不能用了,你可以自己试试。我刚在3.1彼岸网上试了试,也有同样问题。又在我的测试站里把各个版本都试过了, ...
官方在Git上表示無法修復,因為編輯器很容易在修正一個錯誤後同時新增更多的錯誤....他們表示當初Dz的js堅持自己寫,所以產生了這個大坑
回复 天香公主 2017-3-8 10:30 PM
carry0987: 重灌回3.2也可以,www.qbnehs.com這個是測試用的
哦,qbnehs.com是3.2, 我想在那试下,但上次开的账号不能用了,你可以自己试试。我刚在3.1彼岸网上试了试,也有同样问题。又在我的测试站里把各个版本都试过了,可以确信这不是新版带来的新问题。你也可以去那里试试 https://ngcorner.com
回复 carry0987 2017-3-8 01:25 AM
天香公主: 我在安卓手机上做了些测试。觉得这不是个Discuz3.3/PHP7的新问题。Discuz3.2/PHP5.6同样也有这个问题,即发新日志添加相册图片提交后图片显示成代码了。 ...
重灌回3.2也可以,www.qbnehs.com這個是測試用的

facelist doodle 涂鸦板

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

小黑屋|Archiver|彼岸网  

Powered by Discuz! X3.1 © 2001-2014 Comsenz Inc.
GMT-4, 2024-3-28 09:18 AM , Processed in 0.020930 second(s), 11 queries. ,ApcOn

返回顶部