設為首頁收藏本站

 取回密碼
 註冊
搜尋
熱搜: Redump discuz
檢視: 388|回覆: 0

【轉貼】 Discuz!發送系統通知notification_add

[複製連結]
匿名
匿名  發表於 2021年4月23日 14:41:54 |閱讀模式
方法定義位置:source\function\function_core.php

function notification_add($touid, $type, $note, $notevars = array(), $system = 0) {
         return helper_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);
                }
        }
懶得打字嗎?讓本助手協助你 【使用進階編輯器請點選右方進階模式】
您需要登入後才可以回覆 登入 | 註冊

本版積分規則

手機版|Archiver|漁家小舖

GMT+8, 2024年4月20日 09:51 , Processed in 0.404351 second(s), 15 queries , Gzip On, Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回覆 返回頂端 返回清單