开源CMS \ discuz \ 【discuz x3】space_notice.php分析

【discuz x3】space_notice.php分析

总点击132
简介:<?php /** *[Discuz!](C)2001-2099ComsenzInc. *ThisisNOTafreeware,useissubjecttolicenseterms * *$Id:space_notice.php340472013-09-2504:41:45Znemohou$

<?php

/**

* [Discuz!] (C)2001-2099 Comsenz Inc.

* This is NOT a freeware,use is subject to license terms

*

* $Id: space_notice.php 34047 2013-09-25 04:41:45Z nemohou $

*/

if(!defined('IN_DISCUZ')) {

exit('Access Denied');

}

$perpage = 30;

$perpage = mob_perpage($perpage);

$page = empty($_GET['page'])?0:intval($_GET['page']);//页码

if($page<1) $page = 1;

$start = ($page-1)*$perpage;//开始记录

ckstart($start,$perpage);//分页判断

$list = array();//定义了一个list数组

$mynotice = $count = 0;//应用提醒变量

$multi = '';//分页变量

if(empty($_G['member']['category_num']['manage']) && !in_array($_G['adminid'],array(1,2,3))) {

unset($_G['notice_structure']['manage']);

}

/*

* $_GET[view]的值有以下几种

* $_G['notice_structure']:

* mypost-我的帖子

* interactive-坛友互动

* system-系统提醒

* app-应用提醒

*/

$view = (!empty($_GET['view']) && (isset($_G['notice_structure'][$_GET[view]]) || in_array($_GET['view'],array('userapp'))))?$_GET['view']:'mypost';

$actives = array($view=>' class="a"');

$opactives[$view] = 'class="a"';//当前选中项添加class="a"样式

$categorynum = $newprompt = array();//定义一个分类变量和新提醒数变量

if($view == 'userapp') {//@提到我 页面中默认不执行

space_merge($space,'status');

if($_GET['op'] == 'del') {

$appid = intval($_GET['appid']);

C::t('common_myinvite')->delete_by_appid_touid($appid,$_G['uid']);

showmessage('do_success',"home.php?mod=space&do=notice&view=userapp&quickforward=1");

}

$filtrate = 0;

$count = 0;

$apparr = array();

$type = intval($_GET['type']);

foreach(C::t('common_myinvite')->fetch_all_by_touid($_G['uid']) as $value) {

$count++;

$key = md5($value['typename'].$value['type']);

$apparr[$key][] = $value;

if($filtrate) {

$filtrate--;

} else {

if($count < $perpage) {

if($type && $value['appid'] == $type) {

$list[$key][] = $value;

} elseif(!$type) {

$list[$key][] = $value;

}

}

}

}

$mynotice = $count;

} else {//@提到我 页面中默认执行

if(!empty($_GET['ignore'])) {//忽略

//通知表

C::t('home_notification')->ignore($_G['uid']);

}

foreach (array('wall','piccomment','blogcomment','clickblog','clickpic','sharecomment','doing','friend','credit','bbs','system','thread','task','group') as $key) {

//key的值:'wall','group'

$noticetypes[$key] = lang('notification',"type_$key");//提醒类型

}

$isread = in_array($_GET['isread'],array(0,1)) ? intval($_GET['isread']) : 0;//是否已读

$category = $type = '';//定义$category、$type变量

/*

* 1、$view值:mypost-我的帖子 interactive-坛友互动

* 第一:$view值为mypost的情况

* Array (

* [0] => post //帖子

* [1] => pcomment //点评

* [2] => activity //活动

* [3] => reward //悬赏

* [4] => goods //商品

* [5] => at //@提到我的

* )

*/

if(isset($_G['notice_structure'][$view])) {

if(!in_array($view,array('mypost','interactive'))) {//非我的帖子、坛友互动的情况

$category = $view;

} else {//我的帖子和坛友互动的情况

$deftype = $_G['notice_structure'][$view][0];//post

if($_G['member']['newprompt_num']) {//我的帖子或坛友互动新提醒总数量

//各个新提醒数量,如:帖子新提醒数量、点评新提醒数量、活动新提醒数量、悬赏新提醒数量、商品新提醒数量、提到我的新提醒数量

foreach($_G['notice_structure'][$view] as $subtype) {

if($_G['member']['newprompt_num'][$subtype]) {

$deftype = $subtype;

break;

}

}

}

//当前选项类型,默认值为post:可能值为 post-帖子、pcomment-点评、activity-活动、reward-悬赏、goods-商品、at-提到我的 等等

$type = in_array($_GET['type'],$_G['notice_structure'][$view]) ? trim($_GET['type']) : $deftype;

}

}

$wherearr = array();//定义一个where条件数组,用于sql查询

$new = -1;//如果$new等于-1的话,在sql语句中会将new字段的值重新设置为空

if(!empty($type)) {

$wherearr[] = "`type`='$type'";//如果当前选项类型不为空,则加入到条件数组中

}

$sql = ' AND '.implode(' AND ',$wherearr);//拼接的sql语句

$newnotify = false;//新通知标识,false-非新通知 true-新通知

/*

* 通知表

* $type:通知类型:"doing"记录,"friend"好友请求,"sharenotice"好友分享,"post"话题回复,"at"提到我的 等等

* $category不为空的情况:提醒分类 1-我的帖子 2-坛友互动 3-系统消息 4-管理工作 0-应用消息

* $new:通知是否为新:"1"为新通知,"0"为通知已读

* $uid:通知用户的id

* note字段:通知内容,这个是我们关心的

*

* $count:帖子数量、点评数量、活动数量、悬赏数量、商品数量、提到我的数量,如,提到我的-数量7,代表总共有7个提到我的信息(包括已读和未读的信息)

*/

$count = C::t('home_notification')->count_by_uid($_G['uid'],$new,$type,$category);//当前登录用户当前分类下当前选中项信息总数量条数

if($count) {//如果当前选中项信息总数量不为空

if($new == 1 && $perpage == 30) {

$perpage = 200;

}

/*

* 当前登录用户当前选中类型所有信息组成的数组,如:帖子类型中所有帖子的回复内容

* $category不为空的情况:提醒分类 1-我的帖子 2-坛友互动 3-系统消息 4-管理工作 0-应用消息 5-收听 6-听众

* $new:如果$new的值等于-1的话,那么会将$new的值重新设置为空

*/

foreach(C::t('home_notification')->fetch_all_by_uid($_G['uid'],$start,$perpage,$category) as $value) {

if($value['new']) {//通知是否为新:"1"为新通知,"0"为通知已读

$newnotify = true;//新通知

$value['style'] = 'color:#000;font-weight:bold;';//新通知的样式

} else {

$value['style'] = '';//非新通知的样式

}

$value['rowid'] = '';

//打招呼、好友的情况下才执行

if(in_array($value['type'],array('friend','poke'))) {//坛友互动:打招呼-id="pokeQuery_1" 、好友-id="pendingFriend_1" id="pendingFriend_3"

$value['rowid'] = ' id="'.($value['type'] == 'friend' ? 'pendingFriend_' : 'pokeQuery_').$value['authorid'].'" ';

}

//来源量

if($value['from_num'] > 0) $value['from_num'] = $value['from_num'] - 1;

$list[$value['id']] = $value;//$list数组的值

}

$multi = '';

$multi = multi($count,$page,"home.php?mod=space&do=$do&isread=1");

}

if($newnotify) {//新通知不为空的情况

/*

* 作用:将新通知更新为已读,将来源量更新为0

* 第四个参数为$new参数,默认值为true,在$new为true的情况下会自动将其重置为0,0-通知更新为已读

* 第五个参数为$from_num参数,默认值为true,在$from_num为true的情况下会自动将其重置为0,0-来源量更新为0

* $category不为空的情况:提醒分类 1-我的帖子 2-坛友互动 3-系统消息 4-管理工作 0-应用消息

*/

C::t('home_notification')->ignore($_G['uid'],$category,true,true);//忽略意义:将新通知更新为已读,将来源量更新为0

//云状态的情况

if($_G['setting']['cloud_status']) {

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

$noticeService->setNoticeFlag($_G['uid'],TIMESTAMP);

}

}

//更新common_member_newprompt及common_member表中的新提醒数目

helper_notification::update_newprompt($_G['uid'],($type ? $type : $category));

//我的app应用状态,默认不执行

if($_G['setting']['my_app_status']) {

//用户邀请表

$mynotice = C::t('common_myinvite')->count_by_touid($_G['uid']);

}

//新提醒数目

if($_G['member']['newprompt']) {

$recountprompt = 0;//重新统计新提醒数目标识

/*

* 分类下新提醒数目,即:左侧显示的新提醒数目

* 如:通知左侧

* 消息

* 我的帖子(11)

* 坛友互动(9)

* 系统消息(1)

* 应用提醒

*/

foreach($_G['member']['category_num'] as $promptnum) {//分类下新提醒总数目

$recountprompt += $promptnum;//新提醒数目累加:1+9+11

}

$recountprompt += $mynotice;//将应用提醒也累加进来

if($recountprompt == 0) {//如果新提醒为0

//更新用户主表中当前登录用户的新提醒数目为0

C::t('common_member')->update($_G['uid'],array('newprompt' => 0));

}

}

$readtag = array($type => ' class="a"');//给当前选中标签项添加样式:<li class="a">提到我的</li>

}

//将$newprompt新提醒数保存到cookie中

dsetcookie('promptstate_'.$_G['uid'],$newprompt,31536000);

include_once template("diy:home/space_notice");

?>


意见反馈 常见问题 官方微信 返回顶部