Exemplo n.º 1
0
 protected function _initialize()
 {
     /* 读取站点配置 */
     $config = api('Config/lists');
     C($config);
     //添加配置
     if (!C('WEB_SITE_CLOSE') && $_SESSION[C('USER_AUTH_KEY')] != 1) {
         $this->error('站点已经关闭,请稍后访问~', '', 1000);
     }
     $a = D('Member')->need_login();
     $field = array('uid', 'username', 'nickname', 'name', 'email', 'space_url', 'reg_time', 'last_login_time', 'signature', 'avatar32', 'avatar64', 'avatar128', 'avatar256');
     $userinfo = query_user($field, $_SESSION['cs_home']['user_auth']['uid']);
     $roleauth = getmroleauth();
     checkscore($_SESSION['cs_home']['user_auth']['uid']);
     $mymail['status'] = 1;
     $mymail['is_read'] = 0;
     $mymail['to_uid'] = $_SESSION['cs_home']['user_auth']['uid'];
     $mymailcount = M('Message')->where($mymail)->count();
     $userinfo['mymailcount'] = empty($mymailcount) ? '' : $mymailcount;
     $isadmin = is_admin($_SESSION['cs_home']['user_auth']['uid']);
     $this->assign('isadmin', $isadmin);
     $this->assign('user_auth', session('user_auth'));
     $this->assign('uid', getnowUid());
     $this->assign('userinfo', $userinfo);
     $this->assign('roleauth', $roleauth);
     //得到会员组权限
     $cname = strtolower(CONTROLLER_NAME);
     $aname = strtolower(ACTION_NAME);
     $this->assign('aname', $aname);
     $this->assign('cname', $cname);
     $cate = new CategoryApi();
     $clist = $cate->get_catelist(0);
     $clistnum = $cate->get_editcnum();
     $this->assign('clist', $clist);
     $nosigncate = M('Cate')->where(array('status' => 1, 'type' => 1))->select();
     $m = D('cate');
     $catelist = $m->field('*,CONCAT(spid,id) as path2')->where(array('type' => 1, 'status' => 1))->order('path2')->select();
     $t = new tree();
     $catelistarr = $t->unlimitCategoryFormat($catelist);
     $catehtml = $t->treeFormat($catelistarr);
     $this->assign('catehtml', $catehtml);
     $this->assign('nosigncate', $nosigncate);
     $this->assign('clistnum', $clistnum);
     $nav = D('nav')->where(array('status' => 1))->order('sort desc')->select();
     foreach ($nav as $key => $vo) {
         $nav[$key]['url'] = navurl($vo['id'], $vo['type']);
         $nav[$key]['active'] = navactive($vo['id'], $vo['type']);
         if ($vo['win']) {
             $nav[$key]['target'] = '_blank';
         } else {
             $nav[$key]['target'] = '_self';
         }
     }
     $this->assign('nav', $nav);
 }
Exemplo n.º 2
0
 public function addComment()
 {
     $config = get_addon_config('LocalComment');
     $can_guest_comment = $config['can_guest_comment'];
     if (!$can_guest_comment) {
         //不允许游客评论
         if (!is_login()) {
             $this->error('请登录后评论。');
         }
     }
     //获取参数
     $app = strval($_REQUEST['app']);
     $mod = strval($_REQUEST['con']);
     $row_id = intval($_REQUEST['row_id']);
     $content = strval($_REQUEST['content']);
     $uid = intval($_REQUEST['uid']);
     $pid = intval($_REQUEST['pid']);
     if (M($mod)->where(array('id' => $row_id))->getField('status') != 1) {
         $this->error('该文章尚未审核通过!');
     }
     $data = array('app' => $app, 'con' => $mod, 'row_id' => $row_id, 'content' => $content, 'uid' => is_login(), 'pid' => $pid);
     $commentModel = D('Addons://LocalComment/LocalComment');
     $data = $commentModel->create($data);
     if (!$data) {
         $this->error('评论失败:' . $commentModel->getError());
     } else {
         D($app . '/' . $mod)->where(array('id' => $row_id))->setInc('reply_count');
         $rowinfo = D($app . '/' . $mod)->where(array('id' => $row_id))->find();
         $data['content'] = op_h($data['content'], 'font');
         $commentModel->add($data);
         if (!is_login()) {
             if ($uid) {
                 $title = '游客' . '评论了您';
                 $message = '评论内容:' . $content;
                 $url = $_SERVER['HTTP_REFERER'];
                 if (strtolower($mod) == 'article') {
                     $rowurl = U('Home/Index/artc', array('id' => $row_id));
                 }
                 if (strtolower($mod) == 'music') {
                     $rowurl = U('Home/Index/musicc', array('id' => $row_id));
                 }
                 if (strtolower($mod) == 'group') {
                     $rowurl = U('Home/Index/groupc', array('id' => $row_id));
                 }
                 sendMessage($rowinfo['uid'], '0', $title, $message . ',链接地址:<a href="' . $rowurl . '">' . $rowinfo['title'] . '</a>', 0);
             }
             //返回结果
             $this->success('评论成功', 'refresh');
         } else {
             //给评论对象发送消息
             if ($uid) {
                 $user = D('Member')->find(getnowUid());
                 $title = $user['nickname'] . '评论了您';
                 $message = '评论内容:' . $content;
                 $url = $_SERVER['HTTP_REFERER'];
                 if ($rowinfo['uid'] != getnowUid()) {
                     if (strtolower($mod) == 'article') {
                         $rowurl = U('Home/Index/artc', array('id' => $row_id));
                     }
                     if (strtolower($mod) == 'music') {
                         $rowurl = U('Home/Index/musicc', array('id' => $row_id));
                     }
                     if (strtolower($mod) == 'group') {
                         $rowurl = U('Home/Index/groupc', array('id' => $row_id));
                     }
                     sendMessage($rowinfo['uid'], getnowUid(), $title, $message . ',链接地址:<a href="' . $rowurl . '">' . $rowinfo['title'] . '</a>', 0);
                 }
             }
         }
         //通知被@到的人
         $uids = get_at_uids($content);
         $uids = array_unique($uids);
         $uids = array_subtract($uids, array($uid));
         foreach ($uids as $uid) {
             $user = D('Member')->find(getnowUid());
             $title = $user['nickname'] . '@了您';
             $message = '评论内容:' . $content;
             $url = $_SERVER['HTTP_REFERER'];
             sendMessage($uid, getnowUid(), $title, $message . ',链接地址:<a href="' . U('Index/artc', array('id' => $row_id)) . '">' . $rowinfo['title'] . '</a>', 0);
         }
         //返回结果
         $this->success('评论成功');
     }
 }