论坛新鲜事其实就是微博功能,允许注册用户发布,转发,评论信息。通过关注可以使别人的信息显示在自己的版面上。
新鲜事的的程序控制及模板全部放在apps/weibo/目录下面,由根目录apps.php路由请求到apps/weibo/index.php由其提供统一的操作入口。前台请求由apps/weibo/action下面的my.php及view.php来处理。
登录后该用户的操作由apps/weibo/action/my.php来完成。View.php负责浏览其他用户的新鲜事。
而模板位于apps/weibo/template
以下是新鲜事相关表
pw_weibo_bind 新鲜事评论关系表
pw_weibo_cmrelations 新鲜事评论关系表
pw_weibo_cnrelations 群组与新鲜事关联表
pw_weibo_comment 新鲜事评论表
pw_weibo_content 新鲜事内容表
pw_weibo_login_session 账号通登录会话表
pw_weibo_login_user 账号通注册用户表
pw_weibo_referto 新鲜事@我的 关联表
pw_weibo_relations 新鲜事“我关注的新鲜事”关系表
内详细字段请见http://wiki.phpwind.me/doc/V87_dataStruct/index.htm,pw8.7数据结构
下面我们分别对新鲜事基本的发布,转发,评论及展示进行说明
新鲜事的所有前台操作由apps/weibo/action/my.php来完成。代码如下
if ($do == 'post') {
//提交hash进行校验,函数见global.php
PostCheck();
//接收新鲜事内容
S::gp(array('atc_content'),'GP');
S::gp(array('uploadPic', 'ismessage','type'), 'GP');
$type != 'sendweibo' && $type = 'weibo';
//如果后台设置为不允许连接,则不许发布
if ($o_weibourl != 1) {
preg_match('/http:\/\//i', $atc_content) && Showmsg('weibo_link_close');
}
//加载用户相关service,见lib/user/userservice.class.php, L::loadClass函数见 require/common.php
$userService = L::loadClass('UserService', 'user');
if ($db_tcheck ){
require_once(R_P.'require/postfunc.php');
$userInfo
= $userService->get($winduid,false,true);
$userInfo['postcheck'] = unserialize($userInfo['postcheck']);
$userInfo['postcheck']['weibo'] == tcheck($atc_content) && Showmsg('weibo_content_same'); //内容验证
}
//匹配转发
preg_match_all('/@([^\\&\'"\/\*,<>\r\t\n\s#%?@::]+)\s?/i', $atc_content, $matchs);
if($matchs[1]){
$atUids
= array();
foreach($matchs[1] as $v){
if(!$v) continue;
$atUids[]
= $userService->getUserIdByUserName($v);
}
//加载朋友相关serivce 见lib/friend/attention.class.php, 内class PW_Attention
$attentionService
= L::loadClass('Attention', 'friend');/* @var $attentionService PW_Attention */
$blackList
= $attentionService->getBlackListToMe($winduid, $atUids);
if($blackList) Showmsg('weibo_cannot_at');
}
//微博内容检检测 lib/sns/weibo.class.php sendCheck()函数
if (($return = $weiboService->sendCheck($atc_content, $groupid)) !== true) {
Showmsg($return);
}
if ($ismessage) {
require_once(A_P . 'weibo/require/sendmessage.php');
}
$extra = array();
//处理上传图片
if ($uploadPic && is_array($uploadPic)) {
$array = array();
$query = $db->query("SELECT p.*
FROM pw_cnphoto p LEFT JOIN pw_cnalbum
a ON p.aid=a.aid WHERE p.pid IN (" . S::sqlImplode($uploadPic) . ")");
while ($rt = $db->fetch_array($query)) {
$array[$rt['pid']] = $rt;
}
$extra['photos'] = $array;
}
//发送微博 见lib/sns/weibo.class.php send()函数
if ($weiboService->send($winduid, $atc_content, $type, 0,
$extra)) {
if ($db_tcheck) {
$userInfo['postcheck']['weibo'] = tcheck($atc_content);
$userService->update($winduid, array(), array('postcheck' => serialize($userInfo['postcheck'])));
}
weibocredit('weibo_Post');
Showmsg('mode_o_write_success');
} else {
Showmsg('undefined_action');
}
以上是发布的功能代码
我们看到 apps/weibo/action/my.php 转发操作:
} elseif ($do == 'transmit') {
S::gp(array('mid'), 'GP', 2);
//判断评论的新鲜是是否存在
if (!$weibo = $weiboService->getWeibosByMid($mid)) {
Showmsg('您转发的新鲜事不存在,或已被删除!');
}
$transmits = array();
//得到微博类型,转发或原创 见lib/sns/weibo.class.php
getType()函数
$type = $weiboService->getType($weibo['type']);
if ($type == 'transmit' && $weibo['objectid']) {
$transmits = $weiboService->getWeibosByMid($weibo['objectid']);
}
$attentionService = L::loadClass('Attention', 'friend');/* @var $attentionService
PW_Attention */
//获得被屏蔽默认的列表 见 见lib/friend/attention.class.php getBlackListToMe()函数
$blackList = $attentionService->getBlackListToMe($winduid, array($weibo['uid']));
//如果未接收到step参数则获取转发信息
if (empty($_POST['step'])) {
S::gp(array('istopic','topicname'), 'GP');
$uids
= array($weibo['uid']);
if ($transmits) {
$uids[] =
$transmits['uid'];
}
$userService
= L::loadClass('UserService', 'user');
$uInfo
= $userService->getByUserIds($uids);
$weibo
= array_merge($weibo, $uInfo[$weibo['uid']]);
if ($transmits) {
$showInfo = array_merge($transmits, $uInfo[$transmits['uid']]);
$dString = ' ||@' . $weibo['username'] . ':' . $weibo['content'];
} else {
$showInfo = $weibo;
$dString = '';
}
if (strpos($showInfo['content'],'[s:') !== false && strpos($showInfo['content'],']') !== false) {
$sParse = L::loadClass('smileparser', 'smile');
//得到之前被转发的内容
$showInfo['content'] = $sParse->parse($showInfo['content']);
}
$showInfo['extra'] = $showInfo['extra'] ? unserialize($showInfo['extra']) : array();
$id = 'transmit_' . $id;
} else { //进行转发操作
S::gp(array('atc_content','ifcomment'), 'P');
$tmid
= $transmits ? $weibo['objectid'] : $mid;
//检测查转发内容
if (($return = $weiboService->sendCheck($atc_content, $groupid,true))
!== true) {
Showmsg($return);
}
//转发新鲜事
if ($weiboService->send($winduid, $atc_content, 'transmit', $tmid)) {
//pw_weibo_content原创信息转发次数加1
$weiboService->updateCountNum(array('transmit' => 1), $tmid);
//如果转发已被转发的内容,则被转发微博转发次数内容加1
if($transmits){
$weiboService->updateCountNum(array('transmit' => 1), $mid);
}
//如果作为回复发送
if ($ifcomment) {
$commentService = L::loadClass("comment","sns");
//作为被转发微博评论
if($commentService->comment($winduid,$mid,$atc_content)){
//同时评论加1
$weiboService->updateCountNum(array('replies' => 1), $mid);
}
}
echo "success";
ajax_footer();
} else {
Showmsg('undefined_action');
}
}
我们看到 apps/weibo/action/my.php 评论操作:
} elseif ($do == 'postcomment') {
S::gp(array('mid','ifsendweibo','writeContent','identify','tid','ifReplyThread'), 'GP');
//将换行符\n转换成<br>
$writeContent = nl2br($writeContent);
//加载评论service 见lib/sns/comment.class.php
$commentService = L::loadClass("comment","sns");
//检测评论信息 见lib/sns/comment.class.php commentCheck()函数
if (($status = $commentService->commentCheck($writeContent)) !== true) {
Showmsg($status);
}
//发表评论
$result = $commentService->comment($winduid,$mid,$writeContent);
//如果发布成功
if ($result) {
//评论数加1
$weiboService->updateCountNum(array('replies' => 1), $mid);
//如果转发到自己的新鲜事
if ($ifsendweibo) {
if (($weiboStatus = $weiboService->sendCheck($writeContent, $groupid)) !== true) {
Showmsg($weiboStatus);
}
//作为新鲜事发布
$weiboService->send($winduid, $writeContent, 'transmit',$mid, array());
$weiboService->updateCountNum(array('transmit' => 1), $mid);
}
//如果评论的是帖子
if ($ifReplyThread) {
//检测该贴是否为可评论的正常帖
if (($weiboService->checkReplyRight($tid)) !== true) {
Showmsg('您不能对该贴进行回复');
}
$pingService = L::loadClass('ping', 'forum');
$atc_content = $writeContent."\r\n\r\n[size=2][color=#a5a5a5]内容来自[新鲜事][/color] [/size]";
//对帖子进行评论
$pingService->addPost($tid, $atc_content);
}
echo 'ok';
} else {
Showmsg("weibo_cannot_at");
}
$id = $identify ? $mid.'_'.$identify : $mid;
新鲜事的三大功能已经介绍完毕,当然还有前台其他的收藏,删除功能也都在apps/weibo/action/my.php里面完成
后台新鲜事管理
后台为管理员提供的新鲜事的管理功能,包括新鲜事及其转发的评论,查找删除等。
我们看到后台的管理地址为admin.php?adminjob=apps&admintype=weibo_manage其实是定位到了apps/weibo/admin/manage.php那里面的操作不在多说,前面讲的只是抛砖引玉的作用,希望对大家有帮助!