首页 > CMS > Discuz > 正文

Discuz论坛教程之notification_add发送系统通知方法

2024-08-30 19:07:26
字体:
来源:转载
供稿:网友

Discuz!论坛如何发送系统通知呢,怎么样让用户收到系统发送的通知呢?Discuz!发送系统通知方法notification_add解析,想要知道Discuz!论坛怎么样发送通知就来看看吧

方法定义位置:

source/function/function_core.php

代码如下:

view plaincopy

functionnotification_add($touid, $type, $note, $notevars= array(), $system= 0) { returnhelper_notification::notification_add($touid, $type, $note, $notevars, $system);  

}  

参数说明:

$touid:接收通知的uid,即发给谁;

$type:通知类型,如system为系统通知,这里$type参数稍微复制一点,下面我们把type参数的各种意义罗列出来供大家参考:

appId(数字)         漫游应用 
myapp                应用邀请或请求 
credit                积分充值 
goods                商品 
mod_member        用户审核 
system                系统消息 
group                群组审核通过 
report                举报 
verify                认证 
manage_                管理通知 
magic                道具 
poke                打招呼 
friend                好友 
task                任务 
wall                留言 
piccomment        图片评论 
blogcomment        日志评论 
sharecomment        分享评论 
follow                关注 
pusearticle        推送 
at                        @功能 
pcomment        点评 
post                回帖引用 
show                排行榜 
clickblog        日志顶操作 
clickarticle 文章顶操作 
clickpic        图片顶操作 
doing                记录 
pmreport        消息举报 
sharenotice        分享通知 
group                群组 
reward                悬赏 
activity        活动 
thread                主题 
blog                日志 
article                文章 

$note:通知内容,支持html代码;

$notevars:附加参数,如:actor、from_num、from_id、from_idtype

$system:是否系统通知,默认0,强制转为系统通知;

详细代码逻辑参考helper_notification类代码

helper类所在位置:

/source/class/helper/helper_notification.php

相关代码如下:

public static function notification_add($touid, $type, $note, $notevars = array(), $system = 0, $category = -1) {  

global $_G;  

if(!($tospace = getuserbyuid($touid))) {  

return false;  

}  

space_merge($tospace, 'field_home');  

$filter = empty($tospace['privacy']['filter_note'])?array():array_keys($tospace['privacy']['filter_note']);  

if($filter && (in_array($type.'|0', $filter) || in_array($type.'|'.$_G['uid'], $filter))) {  

return false;  

}  

if($category == -1) {  

$category = 0;  

$categoryname = '';  

if($type == 'follow' || $type == 'follower') {  

switch ($type) {  

case 'follow' : $category = 5; break;  

case 'follower' : $category = 6; break;  

}  

$categoryname = $type;  

} else {  

foreach($_G['notice_structure'] as $key => $val) {  

if(in_array($type, $val)) {  

switch ($key) {  

case 'mypost' : $category = 1; break;  

case 'interactive' : $category = 2; break;  

case 'system' : $category = 3; break;  

case 'manage' : $category = 4; break;  

default :  $category = 0;  

}  

$categoryname = $key;  

break;  

}  

}  

}  

} else {  

switch ($category) {  

case 1 : $categoryname = 'mypost'; break;  

case 2 : $categoryname = 'interactive'; break;  

case 3 : $categoryname = 'system'; break;  

case 4 : $categoryname = 'manage'; break;  

case 5 : $categoryname = 'follow'; break;  

case 6 : $categoryname = 'follower'; break;  

default :  $categoryname = 'app';  

}  

}  

if($category == 0) {  

$categoryname = 'app';  

} elseif($category == 1 || $category == 2) {  

$categoryname = $type;  

}  

$notevars['actor'] = "<a href=/"home.php?mod=space&uid=$_G[uid]/">".$_G['member']['username']."</a>";  

if(!is_numeric($type)) {  

$vars = explode(':', $note);  

if(count($vars) == 2) {  

$notestring = lang('plugin/'.$vars[0], $vars[1], $notevars);  

} else {  

$notestring = lang('notification', $note, $notevars);  

}  

$frommyapp = false;  

} else {  

$frommyapp = true;  

$notestring = $note;  

}  

$oldnote = array();  

if($notevars['from_id'] && $notevars['from_idtype']) {  

$oldnote = C::t('home_notification')->fetch_by_fromid_uid($notevars['from_id'], $notevars['from_idtype'], $touid);  

}  

if(empty($oldnote['from_num'])) $oldnote['from_num'] = 0;  

$notevars['from_num'] = $notevars['from_num'] ? $notevars['from_num'] : 1;  

$setarr = array(  

'uid' => $touid,  

'type' => $type,  

'new' => 1,  

'authorid' => $_G['uid'],  

'author' => $_G['username'],  

'note' => $notestring,  

'dateline' => $_G['timestamp'],  

'from_id' => $notevars['from_id'],  

'from_idtype' => $notevars['from_idtype'],  

'from_num' => ($oldnote['from_num']+$notevars['from_num']),  

'category' => $category  

);  

if($system) {  

$setarr['authorid'] = 0;  

$setarr['author'] = '';  

}  

$pkId = 0;  

if($oldnote['id']) {  

C::t('home_notification')->update($oldnote['id'], $setarr);  

$pkId = $oldnote['id'];  

} else {  

$oldnote['new'] = 0;  

$pkId = C::t('home_notification')->insert($setarr, true);  

}  

$banType = array('task');  

if($_G['setting']['cloud_status'] && !in_array($type, $banType)) {  

$noticeService = Cloud::loadClass('Service_Client_Notification');  

if($oldnote['id']) {  

$noticeService->update($touid, $pkId, $setarr['from_num'], $setarr['dateline'], $note);  

} else {  

$extra = $type == 'post' ? array('pId' => $notevars['pid']) : array();  

$extra['notekey'] = $note;  

$noticeService->add($touid, $pkId, $type, $setarr['authorid'], $setarr['author'], $setarr['from_id'], $setarr['from_idtype'], $setarr['note'], $setarr['from_num'], $setarr['dateline'], $extra);  

}  

}  

if(empty($oldnote['new'])) {  

C::t('common_member')->increase($touid, array('newprompt' => 1));  

$newprompt = C::t('common_member_newprompt')->fetch($touid);  

if($newprompt) {  

$newprompt['data'] = unserialize($newprompt['data']);  

if(!empty($newprompt['data'][$categoryname])) {  

$newprompt['data'][$categoryname] = intval($newprompt['data'][$categoryname]) + 1;  

} else {  

$newprompt['data'][$categoryname] = 1;  

}  

C::t('common_member_newprompt')->update($touid, array('data' => serialize($newprompt['data'])));  

} else {  

C::t('common_member_newprompt')->insert($touid, array($categoryname => 1));  

}  

require_once libfile('function/mail');  

$mail_subject = lang('notification', 'mail_to_user');  

sendmail_touser($touid, $mail_subject, $notestring, $frommyapp ? 'myapp' : $type);  

}  

if(!$system && $_G['uid'] && $touid != $_G['uid']) {  

C::t('home_friend')->update_num_by_uid_fuid(1, $_G['uid'], $touid);  

}  

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表