/** * 关闭这个主题 * @param: NULL * @return: NULL * @access: public */ public function run() { //取回用户需要设置帖子id $id = $this->getParameterFromGET('id'); if (!$id) { $this->AlertAndBack(CR_ID_IS_EMPTY); return; } //验证主题是否存在 if (!TopicUtil::replyIsExists($this->db, $id)) { $this->AlertAndBack(CR_ID_IS_NOT_EXISTS); return; } //验证用户的身份 $sql = 'select id, group_dep from base_user_info where lower(user_name) =?'; $sth = $this->db->prepare($sql); $res = $this->db->Execute($sth, array(strtolower($_SESSION['user']['name']))); $rows = $res->FetchRow(); $user_id = $rows['id']; $user_group = $rows['group_dep']; if ($user_group != 1 && $user_group != 2 && $user_group != 3) { //用户没有权限锁定回复 $this->AlertAndBack(CR_USER_HAVE_NO_PRIVILEGES); return; } if ($user_group == 3) { //如果用户是版主 //则查看用户是否是本版的版主 $layout_id = TopicUtil::getLayoutFromReplyId($this->db, $id); $temp_array = array(); LayoutUtil::getParentId($this->db, $layout_id, $temp_array); array_push($temp_array, $layout_id); $sql = 'select count(*) as num from bbs_layout_manager where user_id=? and ' . ' layout_id in (' . implode(',', $temp_array) . ')'; $sth = $this->db->prepare($sql); $res = $this->db->Execute($sth, array($user_id)); $rows = $res->FetchRow(); if (!$rows['num']) { $this->AlertAndBack(CR_USER_HAVE_NO_PRIVILEGES); return; } } //其他的情况中用户是可以解锁这个回复的 //用户是这个版块的版主 //用户是超级版主 //用户是系统管理员 $sql = 'update bbs_reply set reply_status=1 where id=?'; $sth = $this->db->Prepare($sql); $this->db->Execute($sth, array($id)); //成功后,则转向 //求这个回帖的位置所在的位置 $sql = 'select subject_id from bbs_reply where id=?'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($id)); $rows = $res->FetchRow(); $topic_id = $rows['subject_id']; $sort_number = TopicUtil::getSortNumber($this->db, $topic_id, $id); $page = ceil($sort_number / 10); //这里还有很多的工作需要做 $this->forward('index.php?module=bbs&action=viewtopic&id=' . $topic_id . '&page=' . $page . '#topic' . $sort_number); }
/** * run this action * @param: NULL * @return: NULL * @access: public */ public function run() { //取得参数 $id = $this->getParameterFromGET('id'); if (!$id) { return; } //取得所有的子版块 $sql = 'select parent_id from bbs_layout where id=?'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($id)); $rows = $res->FetchRow(); $parent_id = $rows['parent_id']; $all_id = array(); LayoutUtil::getChildId($this->db, $id, $all_id); array_push($all_id, $id); $sql = 'delete from bbs_layout where id in (' . implode(',', $all_id) . ')'; $this->db->Execute($sql); //删除所有的帖子 $sql = 'delete from bbs_subject where layout_id in (' . implode(',', $all_id) . ')'; $this->db->Execute($sql); //删除所有的回复 $sql = 'delete from bbs_reply where layout_id in (' . implode(',', $all_id) . ')'; $this->db->Execute($sql); //求父版块 $this->forward('index.php?action=layout&parent=' . $parent_id); return; }
/** * run this action * @param: NULL * @return: NULL * @access: public */ public function run() { $smarty = $this->getSmarty(); //取得传入的版块的id $layout_id = $this->getParameterFromGET('id'); $smarty->assign('id', $layout_id); //检查版块时候存在 $sql = 'select count(*) as num from bbs_layout where id=?'; $sth = $this->db->prepare($sql); $res = $this->db->Execute($sth, array($layout_id)); $rows = $res->FetchRow(); if (!$rows['num']) { $this->AlertAndBack(LAYOUT_IS_NOT_EXISTS); return; } $sql = 'select parent_id from bbs_layout where id=?'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($layout_id)); $rows = $res->FetchRow(); $parent_id = $rows['parent_id']; $smarty->assign('parent_id', $parent_id); //求现有的版主列表 $manager_list_array = LayoutUtil::getManagerList($this->db, $layout_id); $manager_str = ""; foreach ($manager_list_array as $temp_rows) { $manager_str .= "<input type=\"checkbox\" name=\"user_id[]\" value=" . $temp_rows['user_id'] . ">"; $manager_str .= $temp_rows['user_name'] . "<br>\n"; } $smarty->assign('manager_list', $manager_str); $smarty->display('adminshowdelmanager.tmpl'); return; }
/** * 关闭这个主题 * @param: NULL * @return: NULL * @access: public */ public function run() { //取回用户需要关闭的帖子id $id = $this->getParameterFromGET('id'); if (!$id) { $this->AlertAndBack(CT_ID_IS_EMPTY); return; } //验证主题是否存在 if (!TopicUtil::isExists($this->db, $id)) { $this->AlertAndBack(CT_ID_IS_NOT_EXISTS); return; } //验证用户的身份 $sql = 'select id, group_dep from base_user_info where lower(user_name) =?'; $sth = $this->db->prepare($sql); $res = $this->db->Execute($sth, array(strtolower($_SESSION['user']['name']))); $rows = $res->FetchRow(); $user_id = $rows['id']; $user_group = $rows['group_dep']; if ($user_group != 1 && $user_group != 2 && $user_group != 3) { //用户就没有权限关闭主题 $this->AlertAndBack(CT_USER_HAVE_NO_PRIVILEGES); return; } if ($user_group == 3) { //如果用户是版主 //则查看用户是否是本版的版主 //或者是其父版版主 $layout_id = TopicUtil::getLayoutId($this->db, $id); $temp_array = array(); LayoutUtil::getParentId($this->db, $layout_id, $temp_array); array_push($temp_array, $layout_id); $sql = 'select count(*) as num from bbs_layout_manager where user_id=? and ' . ' layout_id in (' . implode(',', $temp_array) . ')'; $sth = $this->db->prepare($sql); $res = $this->db->Execute($sth, array($user_id)); $rows = $res->FetchRow(); if (!$rows['num']) { $this->AlertAndBack(CT_USER_HAVE_NO_PRIVILEGES); return; } } //其他的情况中用户是可以关闭这个主题的。 //用户是这个版块的版主 //用户是超级版主 //用户是系统管理员 $sql = 'update bbs_subject set subject_status=2 where id=?'; $sth = $this->db->prepare($sql); $this->db->Execute($sth, array($id)); if ($this->db->ErrorNo()) { $this->AlertAndBack($this->db->ErrorMsg()); return; } $this->TipsAndForward(TAF_CLOSE_TOPIC_SUCCESS, 'index.php?module=bbs&action=viewtopic&id=' . $id); return; }
/** * 关闭这个主题 * @param: NULL * @return: NULL * @access: public */ public function run() { //取回用户需要删除的帖子id $id = $this->getParameterFromGET('id'); if (!$id) { $this->AlertAndBack(ST_ID_IS_EMPTY); return; } //验证主题是否存在 if (!TopicUtil::isExists($this->db, $id)) { $this->AlertAndBack(ST_ID_IS_NOT_EXISTS); return; } //验证用户的身份 $sql = 'select id, group_dep from base_user_info where lower(user_name) =?'; $sth = $this->db->prepare($sql); $res = $this->db->Execute($sth, array(strtolower($_SESSION['user']['name']))); $rows = $res->FetchRow(); $user_id = $rows['id']; $user_group = $rows['group_dep']; if ($user_group != 1 && $user_group != 2 && $user_group != 3) { //用户就没有权限打开主题 $this->AlertAndBack(ST_USER_HAVE_NO_PRIVILEGES); return; } if ($user_group == 3) { //如果用户是版主 //则查看用户是否是本版的版主 $layout_id = TopicUtil::getLayoutId($this->db, $id); $temp_array = array(); LayoutUtil::getParentId($this->db, $layout_id, $temp_array); array_push($temp_array, $layout_id); $sql = 'select count(*) as num from bbs_layout_manager where user_id=? and ' . ' layout_id in (' . implode(',', $temp_array) . ')'; $sth = $this->db->prepare($sql); $res = $this->db->Execute($sth, array($user_id)); $rows = $res->FetchRow(); if (!$rows['num']) { $this->AlertAndBack(ST_USER_HAVE_NO_PRIVILEGES); return; } } //其他的情况中用户是可以关闭这个主题的。 //用户是这个版块的版主 //用户是超级版主 //用户是系统管理员 $smarty = $this->getSmarty(); $smarty->assign('clone_title', ST_DELETE_TOPIC); $smarty->assign('id', $id); $smarty->display('deltopic.tmpl'); }
public function run() { $smarty = $this->getSmarty(); $layout_array = array(); $i = 0; LayoutUtil::getAllLayout($this->db, $layout_array, $i); $layout_option = ''; foreach ($layout_array as $layout) { $layout_option .= "<option value=\"" . $layout['id'] . "\">"; $layout_option .= $layout['name'] . "</option>\n"; } $smarty->assign('layout_information', $layout_option); $smarty->display('bbssearch.tmpl'); return; }
/** * run this action * @param: NULL * @return: NULL * @access: public */ public function run() { $id = $this->getParameterFromGET('id'); if (!$id) { $this->AlertAndBack(USER_IS_EMPTY); return; } $sql = 'select count(*) as num from base_user_info where id=?'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($id)); $rows = $res->FetchRow(); if (!$rows['num']) { $this->AlertAndBack(USER_IS_NOT_EXISTS); return; } $sql = 'select group_dep from base_user_info where id=?'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($id)); $rows = $res->FetchRow(); $smarty = $this->getSmarty(); $smarty->assign('id', $id); $smarty->assign('group_id', $rows['group_dep']); $sql = 'select * from sys_group order by id asc '; $res = $this->db->Execute($sql); $temp = array(); while ($rows = $res->FetchRow()) { $temp[] = array('id' => $rows['id'], 'name' => $rows['group_name'], 'description' => $rows['description']); } $layout_array = array(); $i = 0; LayoutUtil::getAllLayout($this->db, $layout_array, $i); $layout_option = ''; foreach ($layout_array as $layout) { $layout_option .= "<option value=\"" . $layout['id'] . "\">"; $layout_option .= $layout['name'] . "</option>\n"; } $smarty->assign('layout_string', $layout_option); $smarty->assign('sysarray', $temp); $smarty->assign('page', $this->getParameterFromGET('page')); $smarty->assign('t', $this->getParameterFromGET('t')); $smarty->assign('m', $this->getParameterFromGET('m')); $smarty->display('adminsetgroup.tmpl'); return; }
/** * 显示用户的控制面板 */ public function run() { //求得用户的id $user_id = UserUtil::getUserId($this->db, $_SESSION['user']['name']); $smarty = $this->getSmarty(); $user_name = $_SESSION['user']['name']; $smarty->assign('view_user_name', $user_name); //用户的所在组 $sql = 'select b.group_name from base_user_info as a join sys_group as b on ' . ' a.group_dep = b.id where a.id=?'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($user_id)); $rows = $res->FetchRow(); $smarty->assign('user_roles', $rows['group_name']); $user_header = UserUtil::getUserHeader($this->db, $user_id); $smarty->assign('head_url', $user_header); //查询新的短消息的数量 $sql = 'select count(*) as num from message_inbox where user_id=? and is_read = 0 '; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($user_id)); $rows = $res->FetchRow(); $smarty->assign('new_message_label', $rows['num']); //共有短消息数 $sql = 'select count(*) as num from message_inbox where user_id=? '; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($user_id)); $rows = $res->FetchRow(); $smarty->assign('total_message_number', $rows['num']); //取得用户注册时间 $sql = 'select register_date from base_user_info where id=?'; $stmt = $this->db->prepare($sql); $res = $this->db->CacheExecute(60 * 60, $stmt, array($user_id)); $rows = $res->FetchRow(); $smarty->assign('user_register_date', $rows['register_date']); //取得用户最后的登录时间 $sql = 'SELECT from_unixtime(last_time) as lastlogout FROM `user_last_time_logout` where user_id=?'; $stmt = $this->db->prepare($sql); $res = $this->db->CacheExecute(60 * 60, $stmt, array($user_id)); $rows = $res->FetchRow(); $smarty->assign('user_last_logout', $rows['lastlogout']); //发表的主题数 $sql = 'select count(*) as num from bbs_subject where author = ?'; $stmt = $this->db->Prepare($sql); $res = $this->db->CacheExecute(10, $stmt, array($user_name)); $rows = $res->FetchRow(); $smarty->assign('all_topic_number', $rows['num']); //参与的帖子数 $sql = 'select count(*) as num from bbs_reply where author=?'; $stmt = $this->db->Prepare($sql); $res = $this->db->CacheExecute(10, $stmt, array($user_name)); $rows = $res->FetchRow(); $smarty->assign('all_reply_number', $rows['num']); ///拥有的短消息的数量 $sql = 'select count(*) as num from message_inbox where user_id=?'; $stmt = $this->db->prepare($sql); $res = $this->db->CacheExecute(20, $stmt, array($user_id)); $rows = $res->FetchRow(); $number_inbox = $rows['num']; $sql = 'select count(*) as num from message_outbox where user_id=?'; $stmt = $this->db->prepare($sql); $res = $this->db->CacheExecute(20, $stmt, array($user_id)); $rows = $res->FetchRow(); $smarty->assign('message_all_number', $number_inbox + $rows['num']); //拥有的收藏数 $sql = 'select count(*) as num from favor where user_id=?'; $stmt = $this->db->prepare($sql); $res = $this->db->CacheExecute(10, $stmt, array($user_id)); $rows = $res->FetchRow(); $smarty->assign('favor_amount', $rows['num']); $show_best = $this->getParameter('best'); if ($show_best) { $show_best = 1; } else { $show_best = 0; } //取得导航栏菜单 //开始检查帖子。 $total_number = LayoutUtil::getTotalNumberTopicByUser($this->db, $user_name, $show_best); //求总公的页面 $total_page = ceil($total_number / $this->page_number); //取得当前的页面 $page = $this->getParameter('page'); if (!$page || $page < 0) { $page = 1; } if ($page > $total_page && $total_page > 0) { $page = $total_page; } $begin_page = 1; $end_page = $total_page; if ($page <= 10 && $total_page >= 10) { $end_page = 10; } else { if ($page > 10) { if ($page % 10 == 0) { //向前翻 $end_page = $page; $begin_page = $end_page - 9; } else { if ($page % 10 == 1) { //向后翻 //确定开始的页数 $begin_page = $page; if ($begin_page > $total_page) { $begin_page = $page - 9; } if ($begin_page + 9 > $total_page) { $end_page = $total_page; } else { $end_page = $begin_page + 9; } } else { $num = $page % 10; $pre_num = floor($page / 10); $begin_page = $pre_num * 10 + 1; $end_page = $begin_page + 9; } } } } if ($end_page > $total_page) { $end_page = $total_page; } $nav_page_array = array(); for ($i = $begin_page; $i <= $end_page; $i++) { array_push($nav_page_array, $i); } //帖子导航栏 $smarty->assign('nav_page', $nav_page_array); //当前的页面 $smarty->assign('now_page', $page); //共有的页面 $smarty->assign('total_page', $total_page); //最新5条发表的主题 $subject_array = LayoutUtil::getSubjectInfoByUser($this->db, $user_name, $this->page_number, ($page - 1) * $this->page_number, $show_best); $smarty->assign('subject', $subject_array); $smarty->assign('view_my_best_topic', $show_best); $smarty->display('listmytopic.tmpl'); }
/** * 保存新帖 * @param: NULL * @return: NULL * @access: public */ public function run() { //取得版块的id $bbs_id = $this->getParameter('id'); if (!$bbs_id) { $this->forward('index.php'); } //验证论坛是否存在 if (!LayoutUtil::isExists($this->db, $bbs_id)) { //论坛不存在,则转向首页 $this->forward('index.php'); } //更新用户在本版的信息 LayoutUtil::updateOnlineUser($this->db, $bbs_id); $bbs_status = LayoutUtil::getLayoutStatus($this->db, $bbs_id); if ($bbs_status == 1 && !isset($_SESSION['user'])) { $this->AlertAndForward(SNT_NEED_LOGIN, 'index.php?module=user&action=showlogin'); return; } else { if ($bbs_status == 2) { $this->AlertAndForward(SNT_LAYOUT_WAS_CLOSED, 'index.php'); return; } else { if ($bbs_status == 3) { //等于三不允许发帖 $this->AlertAndBack(SNT_NOW_ALLOW_NEW_TOPIC); return; } else { if (LayoutUtil::isClosedByParent($this->db, $bbs_id)) { $this->AlertAndForward(SNT_LAYOUT_WAS_CLOSED, 'index.php'); return; } } } } //取得各种参数 //帖子的表情 $express = $this->getParameterFromPost('express'); //上传的帖子标题 $title = $this->getParameterFromPost('title'); //上传的内容 $content = $this->getParameterFromPost('content'); //记录在Session里 $_SESSION['temp_title'] = $title; $_SESSION['temp_content'] = $content; $_SESSION['temp_express'] = $express; //看文件是否有文件上传 if ($_FILES['attach']['tmp_name']) { //用户有上传文件 if ($_FILES['attach']['type'] != 'image/gif' && $_FILES['attach']['type'] != 'image/jpeg' && $_FILES['attach']['type'] != 'image/jpg' && $_FILES['attach']['type'] != 'image/pjpeg' && $_FILES['attach']['type'] != 'image/png') { $this->AlertandBack(ST_PHONE_FILE_LIMIT); } //判断上传的文件大小是否合乎要求 if ($_FILES['attach']['size'] > 1048576) { $this->AlertAndBack(ST_PHONE_FILE_SIZE_LIMIT); return; } } if (!$title || strlen($title) <= 0) { $this->AlertAndBack(ST_TITLE_IS_EMPTY); return; } /* if ( strlen($title) > 140 ) { $this->AlertAndBack(ST_TITLE_TOO_LONG); return; }*/ if (!$content || strlen($content) <= 0) { $this->AlertAndBack(ST_CONTENT_IS_EMPTY); return; } //插入新帖子 $ip_temp = getIp(); $ip = $ip_temp['ip']; $user_name = $_SESSION['user']['name']; $now = time(); $sql = 'insert into bbs_subject ( layout_id, title, author, content, post_ip, ' . 'post_date, express, last_access_date ) values (?, ?, ?, ?, ?, ?, ?, ?) '; $sth = $this->{'db'}->Prepare($sql); $this->{'db'}->Execute($sth, array($bbs_id, $title, $user_name, $content, $ip, $now, $express, $now)); if ($this->{'db'}->ErrorNo()) { $this->AerltAndBack($this->{'db'}->ErrorMsg()); return; } //得到最后的id $insert_id = $this->{'db'}->Insert_id(); if ($_FILES['attach']['tmp_name']) { //取得文件的大小 list($image_width, $image_height, $image_type, $image_attr) = getimagesize($_FILES['attach']['tmp_name']); //判断文件的类型 switch ($image_type) { case 1: $image_left_type = '.gif'; break; case 2: $image_left_type = '.jpg'; break; case 3: $image_left_type = '.png'; break; } //存储的文件名 $file_name = ROOT_PATH . 'upload/attach/' . $insert_id . $image_left_type; if (!move_uploaded_file($_FILES['attach']['tmp_name'], $file_name)) { $sql = 'delete from bbs_subject where id=?'; $sth = $this->{'db'}->Prepare($sql); $this->{'db'}->Execute($sth, array($insert_id)); $this->AlertAndBack(ST_UPLOAD_ERROR); return; } else { $sql = 'insert into bbs_subject_attach (subject_id, file_type) ' . ' values (?, ?)'; $sth = $this->{'db'}->Prepare($sql); $this->{'db'}->Execute($sth, array($insert_id, $image_left_type)); } } unset($_SESSION['temp_title']); unset($_SESSION['temp_content']); unset($_SESSION['temp_express']); $this->TipsAndForward(ST_SEND_TOPIC_SUCCESS, 'index.php?module=bbs&action=viewtopic&id=' . $insert_id); }
/** * 保存新回复 * @param: NULL * @return: NULL * @access: public */ public function run() { //取得主题的id $topic_id = $this->getParameterFromPOST('id'); //验证帖子的是否存在 if (!TopicUtil::isExists($this->db, $topic_id)) { $this->AlertAndBack(TOPIC_IS_NOT_EXISTS); return; } //验证帖子的状态 $status = TopicUtil::getTopicStatus($this->db, $topic_id); //注意状态为3,则为帖子被锁定,不能回复了。 if ($status == 2) { $this->AlertAndBack(TOPIC_HAD_BE_CLOSED); return; } else { if ($status == 3) { $this->AlertAndBack(TOPIC_HAD_BE_LOCK); return; } } //取得版块的id $bbs_id = TopicUtil::getLayoutId($this->db, $topic_id); if (!$bbs_id) { $this->forward('index.php'); } //验证论坛是否存在 if (!LayoutUtil::isExists($this->db, $bbs_id)) { //论坛不存在,则转向首页 $this->forward('index.php'); } //更新用户在本版的信息 LayoutUtil::updateOnlineUser($this->db, $bbs_id); $bbs_status = LayoutUtil::getLayoutStatus($this->db, $bbs_id); if ($bbs_status == 1 && !isset($_SESSION['user'])) { $this->AlertAndForward(SNT_NEED_LOGIN, 'index.php?module=user&action=showlogin'); return; } else { if ($bbs_status == 2) { $this->AlertAndForward(SNT_LAYOUT_WAS_CLOSED, 'index.php'); return; } else { if ($bbs_status == 3) { //等于三不允许发帖 $this->AlertAndBack(SNT_NOW_ALLOW_NEW_TOPIC); return; } else { if (LayoutUtil::isClosedByParent($this->db, $bbs_id)) { $this->AlertAndForward(SNT_LAYOUT_WAS_CLOSED, 'index.php'); return; } } } } //取得各种参数 //帖子的表情 $express = $this->getParameterFromPost('express'); //上传的帖子标题 $title = $this->getParameterFromPost('title'); //上传的内容 $content = $this->getParameterFromPost('content'); //记录在Session里 $_SESSION['temp_title'] = $title; $_SESSION['temp_content'] = $content; $_SESSION['temp_express'] = $express; //看文件是否有文件上传 if ($_FILES['attach']['tmp_name']) { //用户有上传文件 if ($_FILES['attach']['type'] != 'image/gif' && $_FILES['attach']['type'] != 'image/jpeg' && $_FILES['attach']['type'] != 'image/jpg' && $_FILES['attach']['type'] != 'image/pjpeg' && $_FILES['attach']['type'] != 'image/png') { $this->AlertandBack(ST_PHONE_FILE_LIMIT); } //判断上传的文件大小是否合乎要求 if ($_FILES['attach']['size'] > 1048576) { $this->AlertAndBack(ST_PHONE_FILE_SIZE_LIMIT); return; } } //回复标题可以为空 //如果标题为空,则自动生成一个标题 if (!$title || strlen($title) <= 0) { $sql = 'select title from bbs_subject where id=?'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($topic_id)); $rows = $res->FetchRow(); $title = "Re:" . $rows['title']; } /* if ( strlen($title) > 143 ) { $this->AlertAndBack(ST_TITLE_TOO_LONG); return; }*/ if (!$content || strlen($content) <= 0) { $this->AlertAndBack(ST_CONTENT_IS_EMPTY); return; } //插入新回复 $ip_temp = getIp(); $ip = $ip_temp['ip']; $user_name = $_SESSION['user']['name']; $now = time(); $sql = 'insert into bbs_reply ( layout_id, title, author, content, post_ip, ' . 'post_date, express, subject_id ) values (?, ?, ?, ?, ?, ?, ?, ?) '; $sth = $this->{'db'}->Prepare($sql); $this->{'db'}->Execute($sth, array($bbs_id, $title, $user_name, $content, $ip, $now, $express, $topic_id)); if ($this->{'db'}->ErrorNo()) { $this->AlertAndBack($this->{'db'}->ErrorMsg()); return; } //得到最后的id $insert_id = $this->{'db'}->Insert_id(); if ($_FILES['attach']['tmp_name']) { //取得文件的大小 list($image_width, $image_height, $image_type, $image_attr) = getimagesize($_FILES['attach']['tmp_name']); //判断文件的类型 switch ($image_type) { case 1: $image_left_type = '.gif'; break; case 2: $image_left_type = '.jpg'; break; case 3: $image_left_type = '.png'; break; } //存储的文件名 $file_name = ROOT_PATH . 'upload/attach/reply/' . $insert_id . $image_left_type; if (!move_uploaded_file($_FILES['attach']['tmp_name'], $file_name)) { $sql = 'delete from bbs_reply where id=?'; $sth = $this->{'db'}->Prepare($sql); $this->{'db'}->Execute($sth, array($insert_id)); $this->AlertAndBack(ST_UPLOAD_ERROR); return; } else { $sql = 'insert into bbs_reply_attach (reply_id, file_type) ' . ' values (?, ?)'; $sth = $this->{'db'}->Prepare($sql); $this->{'db'}->Execute($sth, array($insert_id, $image_left_type)); } } unset($_SESSION['temp_title']); unset($_SESSION['temp_content']); unset($_SESSION['temp_express']); //发送短信,通知各个用户有回复了你的帖子 //发送邮件,通知各个用户有回复了你的帖子 $mail_user = array(); $message_user = array(); $sql = 'select a.author, b.user_email, b.id from bbs_subject a join ' . ' base_user_info b on a.author = b.user_name ' . ' join user_setting c on b.id=c.user_id where a.id=? and c.user_whether_receive_email=1'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($topic_id)); $rows = $res->FetchRow(); if ($rows['id']) { $mail_user[] = $rows['user_email']; } $sql = 'select distinct a.author, b.user_email, b.id from bbs_reply a join base_user_info b ' . ' on a.author = b.user_name join user_setting c on b.id=c.user_id ' . ' where a.subject_id=? and c.user_whether_receive_email=1'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($topic_id)); while ($rows = $res->FetchRow()) { if ($rows['id']) { $mail_user[] = $rows['user_email']; } } $mail_user = array_unique($mail_user); //计算发送短信的用户数组 $sql = 'select a.author, b.id from bbs_subject a join ' . ' base_user_info b on a.author = b.user_name ' . ' join user_setting c on b.id=c.user_id where a.id=? and c.receive_system_message=1'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($topic_id)); $rows = $res->FetchRow(); if ($rows['id']) { $message_user[] = $rows['id']; } $sql = 'select distinct a.author, b.id from bbs_reply a join base_user_info b ' . ' on a.author = b.user_name join user_setting c on b.id=c.user_id ' . ' where a.subject_id=? and c.receive_system_message=1'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($topic_id)); while ($rows = $res->FetchRow()) { if ($rows['id']) { $message_user[] = $rows['id']; } } $message_user = array_unique($message_user); //开始发送邮件 $to_address = implode(',', $mail_user); $mail_content = ST_MAIL_CONTENT . "\n\n"; $mail_content .= ROOT_URL . 'index.php?module=bbs&action=viewtopic&id=' . $topic_id . "\n\n"; $headers = "To:" . $to_address . "\r\n"; $headers .= "From:" . WEBSITE_EMAIL . "\r\n"; //发送邮件: @mail($to_address, ST_MAIL_SUBJECT, $mail_content, $headers); //发送短消息 //发件人 $sender = '0'; $message_content = ST_MESSAGE_CONTENT . "\n"; $now = getNoFormateCurrentDate(); $message_content .= "[url=" . 'index.php?module=bbs&action=viewtopic&id=' . $topic_id . "][color=red]" . ST_CLICK_HERE . "[/color]" . "[/url]"; $sql = 'insert into message_inbox ( user_id, send_user_id, title, receive_time, content ) ' . ' values ( ?, ?, ?, ?, ?) '; $sth = $this->db->Prepare($sql); foreach ($message_user as $user) { $this->db->Execute($sth, array($user, $sender, ST_MAIL_SUBJECT, $now, $message_content)); } $now = time(); //更新主题的最后更新时间 $update_sql = 'update bbs_subject set last_access_date=?,reply_number=reply_number+1 where id=?'; $sth = $this->db->Prepare($update_sql); $this->db->Execute($sth, array($now, $topic_id)); //求这个回帖的位置所在的位置 $sort_number = TopicUtil::getSortNumber($this->db, $topic_id, $insert_id); $page = ceil($sort_number / $this->pre_page); //这里还有很多的工作需要做 $this->TipsAndForward(ST_SAVE_REPLY_SUCCESS, 'index.php?module=bbs&action=viewtopic&id=' . $topic_id . '&page=' . $page . '#topic' . $sort_number); }
/** * 返回子论坛的信息 * @param: $id, 论坛ID * @param: $db, 数据库的连接 * @reurn: Array * @access; public */ public static function &getSubBBS(&$db, $id) { /*{{{*/ //查询所有下级子论坛 $sub_bbs_layout_id = LayoutUtil::getLayoutInfoByParentId($db, $id); $sub_array = array(); foreach ($sub_bbs_layout_id as $sub_rows) { $sub_id = $sub_rows['id']; //注意:$sub_bbs_id是一个数组 $sub_bbs_id = array(); LayoutUtil::getChildId($db, $sub_id, $sub_bbs_id); array_push($sub_bbs_id, $sub_id); /** * 如果已经将论坛锁住,则不判断是否有新帖 */ /** * $layout_status == 0 || $layout_status is null 则为开放 * $layout_status == 1 则需要验证 * $layout_status == 2 则为关闭 */ $layout_status = LayoutUtil::getLayoutStatus($db, $sub_id); /** * 判断是否有新帖子 * 判断有新帖子的流程是: * 如果用户已经登录,则找出用户的作后动作的时间 * 如果用户没有登录,则显示没有新帖子 */ $image = 'nonewtopic.gif'; if ($layout_status == 2) { $image = 'lock.gif'; } else { if (isset($_SESSION['user'])) { if (LayoutUtil::haveNewTopic($db, $_SESSION['user']['name'], $sub_bbs_id)) { /** * 求出最后时间后,需要我们找出当前子论坛下各个子论坛的id */ $image = 'havenewtopic.gif'; } } } //求出论坛及子论坛下面的查看的人数 $view_number = LayoutUtil::getViewNumber($db, $sub_bbs_id); //求出论坛和子论坛下的所有的主题 $topic_number = LayoutUtil::getTopicNumber($db, $sub_bbs_id); //求出论坛下所有的回复数 $reply_number = LayoutUtil::getReplyNumber($db, $sub_bbs_id); //求论坛里最后发表的帖子 $temp_rows = LayoutUtil::getLastPostTopic($db, $sub_id); $last_id = $temp_rows['id']; $last_title = $temp_rows['title']; $last_time = $temp_rows['last_access_date']; $last_time = set_locale_time($last_time); $short_title = utf8_substr($last_title, 0, 10); //求版主列表的字符串 $manager_list_array = LayoutUtil::getManagerList($db, $sub_id); $manager_str = ""; foreach ($manager_list_array as $temp_rows) { $manager_str .= "<option value=" . $temp_rows['user_id'] . ">"; $manager_str .= $temp_rows['user_name'] . "</option>\n"; } $sub_array[] = array('id' => $sub_rows['id'], 'title' => $sub_rows['title'], 'content' => ConvertString(stripslashes($sub_rows['description']), ROOT_URL, IMAGE_URL . 'express/'), 'image' => $image, 'viewnumber' => $view_number, 'topic_number' => $topic_number, 'reply_number' => $reply_number, 'topicid' => $last_id, 'topic_title' => $last_title, 'short_title' => $short_title, 'last_time' => $last_time, 'managerlist' => $manager_str); } return $sub_array; }
/** * 运行本类 * @param: NULL * @return: NULL * @access: public */ public function run() { /*{{{*/ $smarty = $this->getSmarty(); $smarty->assign('clone_title', CREATE_NEW_REPLY); //取得主题的id $topic_id = $this->getParameterFromGET('id'); //验证帖子的是否存在 if (!TopicUtil::isExists($this->db, $topic_id)) { $this->AlertAndBack(TOPIC_IS_NOT_EXISTS); return; } //验证帖子的状态 $status = TopicUtil::getTopicStatus($this->db, $topic_id); //注意状态为3,则为帖子被锁定,不能回复了。 if ($status == 2) { $this->AlertAndBack(TOPIC_HAD_BE_CLOSED); return; } else { if ($status == 3) { $this->AlertAndBack(TOPIC_HAD_BE_LOCK); return; } } //取得该帖子所在的版块 $layout_id = TopicUtil::getLayoutId($this->db, $topic_id); if (!LayoutUtil::isExists($this->db, $layout_id)) { //论坛不存在,则转向首页 $this->forward('index.php'); } //更新用户在本版的信息 LayoutUtil::updateOnlineUser($this->db, $layout_id); $bbs_status = LayoutUtil::getLayoutStatus($this->db, $layout_id); if ($bbs_status == 1 && !isset($_SESSION['user'])) { $this->AlertAndForward(SRY_NEED_LOGIN, 'index.php?module=user&action=showlogin'); return; } else { if ($bbs_status == 2) { $this->AlertAndForward(SRY_LAYOUT_WAS_CLOSED, 'index.php'); return; } else { if ($bbs_status == 3) { //等于三不允许发帖 $this->AlertAndBack(SRY_NOW_ALLOW_NEW_TOPIC); return; } else { if (LayoutUtil::isClosedByParent($this->db, $bbs_id)) { $this->AlertAndForward(SRY_LAYOUT_WAS_CLOSED, 'index.php'); return; } } } } //返回论坛上面的导行栏。 $nav_array = LayoutUtil::getParentLayoutInfo($this->db, $layout_id); //导航栏 $smarty->assign('nav_array', $nav_array); //先删除已经不存在的用户 LayoutUtil::delNotExistsUser($this->db); //从Session里读出数据 $temp_title = $_SESSION['temp_title']; if (strlen($temp_title) <= 0) { $smarty->assign('temp_title', $temp_title); } //看看是否是引用 $quote = $this->getParameterFromGET('quote'); $reply_id = $this->getParameterFromGET('replyid'); $temp_content = $_SESSION['temp_content']; $fck = new FCKeditor("content"); $fck->BasePath = FCKEDITOR_BASEPATH; if ($temp_content) { if (get_magic_quotes_gpc()) { $fck->Value = stripslashes($temp_content); } else { $fck->Value = $temp_content; } } else { if ($quote == 1) { if ($reply_id == 0) { $sql = 'select content from bbs_subject where id=?'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($topic_id)); $rows = $res->FetchRow(); if (get_magic_quotes_gpc()) { $temp_content1 = stripslashes($rows['content']); } else { $temp_content1 = $rows['content']; } $fck->Value = '[quote]' . $temp_content1 . '[/quote]'; } else { $sql = 'select content from bbs_reply where id=?'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($reply_id)); $rows = $res->FetchRow(); if (get_magic_quotes_gpc()) { $temp_content1 = stripslashes($rows['content']); } else { $temp_content1 = $rows['content']; } $fck->Value = '[quote]' . $temp_content1 . '[/quote]'; } } } $smarty->assign('fck', $fck); $temp_express = $_SESSION['temp_express']; $smarty->assign('temp_express', $temp_express); $smarty->assign('is_new_topic', 0); $smarty->assign('is_new_reply', 1); $smarty->assign('bbsid', $topic_id); $smarty->display('topic.tmpl'); }
/** * 显示版面的情况 * @param: NULL * @return: NULL * @access: public */ public function run() { //取得用户的id $user_id = UserUtil::getUserId($this->db, $_SESSION['user']['name']); $smarty = $this->getSmarty(); //取得站点的公告,并显示在页面上 $is_have_post = false; $post_str = ''; if (PostUtil::haveNotExpirePost($this->getDB())) { $is_have_post = true; $post_array = PostUtil::getPost($this->getDB(), 3); foreach ($post_array as $post_rows) { $post_str .= '<a href=\'index.php?module=post&action=view&id=' . $post_rows['id'] . '\' title=\'' . $post_rows['title'] . '\'>' . utf8_substr($post_rows['title'], 0, 35) . '</a>' . ' '; } } $smarty->assign('have_system_post', $is_have_post); $smarty->assign('post_str', $post_str); //公告显示结束 $q = $this->getParameterFromGET('q'); $encode_q = $q; //取得查询字符串 if (!$q) { //取得用户最后一次的动作时间 $last_time = UserUtil::getUserLastLogoutTime($this->db, $user_id); //生成一个where语句 $q = " where last_access_date >='" . $last_time . "'"; $encode_q = base64_encode($q); } else { $q = base64_decode($q); } $smarty->assign('encode_q', $encode_q); //生成所有的记录数 $sql = 'select count(*) as num from bbs_subject ' . $q; $res = $this->db->Execute($sql); $rows = $res->FetchRow(); $total_number = $rows['num']; //求总公的页面 $total_page = ceil($total_number / $this->page_number); //取得当前的页面 $page = $this->getParameter('page'); if (!$page || $page < 0) { $page = 1; } if ($page > $total_page && $total_page > 0) { $page = $total_page; } $begin_page = 1; $end_page = $total_page; if ($page <= 10 && $total_page >= 10) { $end_page = 10; } else { if ($page > 10) { if ($page % 10 == 0) { //向前翻 $end_page = $page; $begin_page = $end_page - 9; } else { if ($page % 10 == 1) { //向后翻 //确定开始的页数 $begin_page = $page; if ($begin_page > $total_page) { $begin_page = $page - 9; } if ($begin_page + 9 > $total_page) { $end_page = $total_page; } else { $end_page = $begin_page + 9; } } else { $num = $page % 10; $pre_num = floor($page / 10); $begin_page = $pre_num * 10 + 1; $end_page = $begin_page + 9; } } } } if ($end_page > $total_page) { $end_page = $total_page; } $nav_page_array = array(); for ($i = $begin_page; $i <= $end_page; $i++) { array_push($nav_page_array, $i); } //帖子导航栏 $smarty->assign('nav_page', $nav_page_array); //当前的页面 $smarty->assign('now_page', $page); //共有的页面 $smarty->assign('total_page', $total_page); //显示搜索结果 //求出偏移 $offset_number = ($page - 1) * $this->page_number; $subject_array = LayoutUtil::getCacheSubjectInfo($this->db, $this->page_number, $offset_number, $q); if ($total_page > 0) { $smarty->assign('subject', $subject_array); $smarty->assign('have_subject', 1); } $smarty->display('viewnew.tmpl'); }
/** * 查看帖子 * @param: NULL * @return: NULL * @access: public */ public function run() { //取得帖子的id $topic_id = $this->getParameterFromGET('id'); $topic_id = (int) $topic_id; if (!$topic_id || $topic_id < 1) { $this->AlertAndBack(VT_TOPIC_ID_IS_NOT_VALID); return; } //验证帖子的id是否存在 if (!TopicUtil::isExists($this->db, $topic_id)) { $this->AlertAndBack(VT_TOPIC_ID_IS_NOT_EXISTS); return; } //查询帖子的版块id $layout_id = TopicUtil::getLayoutId($this->db, $topic_id); //验证论坛的版块 if (!LayoutUtil::isExists($this->db, $layout_id)) { $this->AlertAndBack(VT_LAYOUT_IS_NOT_EXISTS); return; } //得出论坛版块的状态 $layout_status = LayoutUtil::getLayoutStatus($this->db, $layout_id); //状态为0则为全部开放 //状态为1则为需要验证 //状态为2则为关闭 //如果为2 if ($layout_status == 2) { $this->AlertAndBack(VT_LAYOUT_IS_CLOSED); return; } else { if ($layout_status == 1) { if (!$_SESSION['user']['name']) { $this->AlertAndBack(VT_LAYOUT_NEED_AUTHOR); return; } } } //取得帖子的状态 $topic_status = TopicUtil::getTopicStatus($this->db, $topic_id); /** * 为0, 则开放 * 为1, 则需要认证 * 为2,则关闭 */ if ($topic_status == 1) { if (!$_SESSION['user']['name']) { $this->AlertAndBack(VT_TOPIC_NEED_AUTHOR); return; } } //增加帖子的浏览次数 TopicUtil::updateViewNumber($this->db, $topic_id); //取得Smarty的对象 $smarty = $this->getSmarty(); //先删除已经不存在的用户 LayoutUtil::delNotExistsUser($this->db); //取得站点的公告,并显示在页面上 $is_have_post = false; $post_str = ''; if (PostUtil::haveNotExpirePost($this->getDB())) { $is_have_post = true; $post_array = PostUtil::getPost($this->getDB(), 3); foreach ($post_array as $post_rows) { $post_str .= '<a href=\'index.php?module=post&action=view&id=' . $post_rows['id'] . '\' title=\'' . $post_rows['title'] . '\'>' . utf8_substr($post_rows['title'], 0, 35) . '</a>' . ' '; } } $smarty->assign('have_system_post', $is_have_post); $smarty->assign('post_str', $post_str); //求帖子的访问的导航菜单 $nav_array = LayoutUtil::getParentLayoutInfo($this->db, $layout_id); //导航栏 $smarty->assign('nav_array', $nav_array); //求帖子的标题 $title = TopicUtil::getTitle($this->db, $topic_id); $smarty->assign('topic_title', $title); $smarty->assign('clone_title', ' -> ' . $title); //取得页面 $page = $this->getParameterFromGET('page'); if (!$page || $page <= 0) { $page = 1; } //求总的页面 $total_page = TopicUtil::getTotalPage($this->db, $topic_id, $this->pre_page); if ($page > $total_page && $total_page > 0) { $page = $total_page; } //帖子的id和版块的id $smarty->assign('topic_id', $topic_id); $smarty->assign('bbs_id', $layout_id); //页面 $smarty->assign('now_page', $page); $smarty->assign('total_page', $total_page); $begin_page = 1; $end_page = $total_page; if ($page <= 10 && $total_page >= 10) { $end_page = 10; } else { if ($page > 10) { if ($page % 10 == 0) { //向前翻 $end_page = $page; $begin_page = $end_page - 9; } else { if ($page % 10 == 1) { //向后翻 //确定开始的页数 $begin_page = $page; if ($begin_page > $total_page) { $begin_page = $page - 9; } if ($begin_page + 9 > $total_page) { $end_page = $total_page; } else { $end_page = $begin_page + 9; } } else { $num = $page % 10; $pre_num = floor($page / 10); $begin_page = $pre_num * 10 + 1; $end_page = $begin_page + 9; } } } } if ($end_page > $total_page) { $end_page = $total_page; } $nav_page_array = array(); for ($i = $begin_page; $i <= $end_page; $i++) { array_push($nav_page_array, $i); } //帖子导航栏 $smarty->assign('nav_page', $nav_page_array); $offset_page = ($page - 1) * $this->pre_page; $topic_array = TopicUtil::getTopicInfo($this->db, $topic_id, $this->pre_page, $offset_page); $smarty->assign('topic', $topic_array); //取得当前用户的身份 $user_name = $_SESSION['user']['name']; $user_id = UserUtil::getUserId($this->db, $user_name); if (strlen($user_name)) { //验证用户的身份 $sql = 'select group_dep from base_user_info where lower(user_name) =?'; $sth = $this->db->prepare($sql); $res = $this->db->Execute($sth, array(strtolower($user_name))); $rows = $res->FetchRow(); $user_group = $rows['group_dep']; if ($user_group == 1 || $user_group == 2) { $smarty->assign('can_be_close', 1); } else { if ($user_group == 3) { $layout_id = TopicUtil::getLayoutId($this->db, $topic_id); $sql = 'select count(*) as num from bbs_layout_manager where user_id=? and ' . ' layout_id=?'; $sth = $this->db->prepare($sql); $res = $this->db->Execute($sth, array($user_id, $layout_id)); $rows = $res->FetchRow(); if (!$rows['num']) { $smarty->assign('can_be_close', 0); } else { $smarty->assign('can_be_close', 1); } } } } else { $smarty->assign('can_be_close', 0); } //加密一个返回的url $backurl = 'index.php?module=bbs&action=viewtopic&id=' . $topic_id . '&page=' . $page; $backurl = base64_encode($backurl); $smarty->assign('backurl', $backurl); $smarty->display('viewtopic.tmpl'); }
/** * 运行本类 */ public function run() { /*{{{*/ $id = $this->getParameterFromGET('id'); $is_topic = $this->getParameterFromGET('topic'); $bbs_id = 0; //判断$id是否存在。 if ($is_topic == 1) { //如果等于1,则为主题 if (!TopicUtil::isExists($this->db, $id)) { $this->AlertAndBack(SE_TOPIC_ID_IS_NOT_EXISTS); return; } else { //如果存在,则判断用户是否有权利修改 $sql = 'select author, layout_id from bbs_subject where id=?'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($id)); $rows = $res->FetchRow(); $user_name = $rows['author']; $bbs_id = $rows['layout_id']; $user_can_be_edit = 0; if (strtolower($_SESSION['user']['name']) == strtolower($user_name)) { $user_can_be_edit = 1; } else { if (strtolower($_SESSION['user']['name']) != strtolower($user_name)) { //判断用户是否是这个版块的版主。 $dep = UserUtil::getUserDep($this->db, $_SESSION['user']['name']); if ($dep == 1 || $dep == 2) { $user_can_be_edit = 1; } else { if ($dep == 3) { $user_can_be_edit = UserUtil::isThisLayoutAdmin($this->db, $id, $bbs_id, $_SESSION['user']['name']); } } } } if (!$user_can_be_edit) { $this->AlertAndBack(SE_YOU_HAVE_NO_PRIVIATE); return; } } } else { //$topic 为其他值,那么就是回帖,而不是主题 $sql = 'select author, subject_id, layout_id from bbs_reply where id=?'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($id)); $rows = $res->FetchRow(); if (!$rows['author']) { $this->AlertAndBack(SE_TOPIC_ID_IS_NOT_EXISTS); return; } //如果存在, //则判断用户是否有权限 $user_name = $rows['author']; $subject_id = $rows['subject_id']; $bbs_id = $rows['layout_id']; $user_can_be_edit = 0; if (strtolower($_SESSION['user']['name']) == strtolower($user_name)) { $user_can_be_edit = 1; } else { if (strtolower($_SESSION['user']['name']) != strtolower($user_name)) { //判断用户是否是这个版块的版主。 $dep = UserUtil::getUserDep($this->db, $_SESSION['user']['name']); if ($dep == 1 || $dep == 2) { $user_can_be_edit = 1; } else { if ($dep == 3) { $user_can_be_edit = UserUtil::isThisLayoutAdmin($this->db, $subject_id, $bbs_id, $_SESSION['user']['name']); } } } } if (!$user_can_be_edit) { $this->AlertAndBack(SE_YOU_HAVE_NO_PRIVIATE); return; } } $smarty = $this->getSmarty(); if ($is_topic) { $smarty->assign('clone_title', SE_EDIT_TOPIC); } else { $smarty->assign('clone_title', SE_EDIT_REPLY); } //更新用户在本版的信息 LayoutUtil::updateOnlineUser($this->db, $bbs_id); //返回论坛上面的导行栏。 $nav_array = LayoutUtil::getParentLayoutInfo($this->db, $bbs_id); //导航栏 $smarty->assign('nav_array', $nav_array); //先删除已经不存在的用户 LayoutUtil::delNotExistsUser($this->db); //用户有权限了。 //则可以开始显示用户帖子的内容 $smarty->assign('id_edit', 1); $smarty->assign('is_topic', $is_topic); $smarty->assign('is_edit', 1); $smarty->assign('bbsid', $id); if ($is_topic == 1) { //如果$is_topic 等于1, 则为主题 $sql = 'select title, content, express from bbs_subject where id=?'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sql, array($id)); $rows = $res->FetchRow(); $smarty->assign('temp_title', $rows['title']); $fck = new FCKeditor("content"); $fck->BasePath = FCKEDITOR_BASEPATH; if (get_magic_quotes_gpc()) { $fck->Value = stripslashes($rows['content']); } else { $fck->Value = $rows['content']; } $smarty->assign('fck', $fck); $smarty->assign('temp_express', $rows['express']); //查询是否有附件 $sql = 'select subject_id, file_type from bbs_subject_attach where subject_id=?'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($id)); $rows = $res->FetchRow(); if ($rows['subject_id']) { $filename = ROOT_URL . 'upload/attach/' . $rows['subject_id'] . $rows['file_type']; $smarty->assign('image_name', $filename); } } else { $sql = 'select title, content, express from bbs_reply where id=?'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sql, array($id)); $rows = $res->FetchRow(); $smarty->assign('temp_title', $rows['title']); $fck = new FCKeditor("content"); $fck->BasePath = FCKEDITOR_BASEPATH; // $fck->Value = $rows['content']; if (get_magic_quotes_gpc()) { $fck->Value = stripslashes($rows['content']); } else { $fck->Value = $rows['content']; } $smarty->assign('fck', $fck); $smarty->assign('temp_express', $rows['express']); //查询是否有附件 $sql = 'select reply_id, file_type from bbs_reply_attach where reply_id=?'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($id)); $rows = $res->FetchRow(); if ($rows['reply_id']) { $filename = ROOT_URL . 'upload/attach/reply/' . $rows['reply_id'] . $rows['file_type']; $smarty->assign('image_name', $filename); } } $smarty->display('topic.tmpl'); return; }
/** * 显示版面的情况 * @param: NULL * @return: NULL * @access: public */ public function run() { //收集论坛的ID $bbs_id = $this->getParameter("id"); if (!$bbs_id) { $this->forward('index.php'); } //验证论坛是否存在 if (!LayoutUtil::isExists($this->db, $bbs_id)) { //论坛不存在,则转向首页 $this->forward('index.php'); } //更新用户在本版的信息 LayoutUtil::updateOnlineUser($this->db, $bbs_id); //如果论坛存在,则返回论坛的状态 $bbs_status = LayoutUtil::getLayoutStatus($this->db, $bbs_id); if ($bbs_status == 1 && !isset($_SESSION['user'])) { $this->AlertAndForward(VL_NEED_LOGIN, 'index.php?module=user&action=showlogin'); return; } else { if ($bbs_status == 2) { $this->AlertAndForward(VL_LAYOUT_WAS_CLOSED, 'index.php'); return; } else { if (LayoutUtil::isClosedByParent($this->db, $bbs_id)) { $this->AlertAndForward(VL_LAYOUT_WAS_CLOSED, 'index.php'); return; } } } //取回smarty的实例 $smarty = $this->getSmarty(); //返回论坛上面的导行栏。 $nav_array = LayoutUtil::getParentLayoutInfo($this->db, $bbs_id); //导航栏 $smarty->assign('nav_array', $nav_array); //先删除已经不存在的用户 LayoutUtil::delNotExistsUser($this->db); //取得站点的公告,并显示在页面上 $is_have_post = false; $post_str = ''; if (PostUtil::haveNotExpirePost($this->getDB())) { $is_have_post = true; $post_array = PostUtil::getPost($this->getDB(), 3); foreach ($post_array as $post_rows) { $post_str .= '<a href=\'index.php?module=post&action=view&id=' . $post_rows['id'] . '\' title=\'' . $post_rows['title'] . '\'>' . utf8_substr($post_rows['title'], 0, 35) . '</a>' . ' '; } } $smarty->assign('have_system_post', $is_have_post); $smarty->assign('post_str', $post_str); //状态确认了。开始检查论坛是否有子论坛 $bbs_title = LayoutUtil::getTitle($this->db, $bbs_id); $bbs_sub_info = LayoutUtil::getSubBBS($this->db, $bbs_id); //论坛的ID $smarty->assign('bbs_id', $bbs_id); //子论坛的信息 $smarty->assign('bbs_title', $bbs_title); $smarty->assign('have_sub_bbs', isset($bbs_sub_info[0]) ? 1 : 0); $smarty->assign('info', $bbs_sub_info); //如果状态为3,则不允许发帖,就不显示帖子 $smarty->assign('not_allow_new_topic', $bbs_status == 3 ? 1 : 0); //如果状态为3,则不允许发帖, //如果不为3,则表示可以发帖子, //就应该显示帖子的数据 if ($bbs_status != 3) { //开始检查帖子。 $total_number = LayoutUtil::getTotalNumberTopicByParentId($this->db, $bbs_id); //求总公的页面 $total_page = ceil($total_number / $this->page_number); //取得当前的页面 $page = $this->getParameter('page'); if (!$page || $page < 0) { $page = 1; } if ($page > $total_page && $total_page > 0) { $page = $total_page; } $begin_page = 1; $end_page = $total_page; if ($page <= 10 && $total_page >= 10) { $end_page = 10; } else { if ($page > 10) { if ($page % 10 == 0) { //向前翻 $end_page = $page; $begin_page = $end_page - 9; } else { if ($page % 10 == 1) { //向后翻 //确定开始的页数 $begin_page = $page; if ($begin_page > $total_page) { $begin_page = $page - 9; } if ($begin_page + 9 > $total_page) { $end_page = $total_page; } else { $end_page = $begin_page + 9; } } else { $num = $page % 10; $pre_num = floor($page / 10); $begin_page = $pre_num * 10 + 1; $end_page = $begin_page + 9; } } } } if ($end_page > $total_page) { $end_page = $total_page; } $nav_page_array = array(); for ($i = $begin_page; $i <= $end_page; $i++) { array_push($nav_page_array, $i); } //帖子导航栏 $smarty->assign('nav_page', $nav_page_array); //当前的页面 $smarty->assign('now_page', $page); //共有的页面 $smarty->assign('total_page', $total_page); //如果是$page =1 就显示置顶贴,要不然不显示。 //呵呵。 //先看看是否要显示精华 $show_best = $this->getParameterFromGET('showbest'); $top_number = $this->page_number; if ($page == 1) { $top_subject_array = LayoutUtil::getTopicSubjectInfo($this->db, $bbs_id, $this->page_number, $show_best); $temp_number = count($top_subject_array); $top_number = $this->page_number - $temp_number; if ($temp_number >= 1) { $smarty->assign('have_top_subject', 1); $smarty->assign('top_subject', $top_subject_array); } } //求出偏移 $offset_number = ($page - 1) * $top_number; $subject_array = LayoutUtil::getSubjectInfo($this->db, $bbs_id, $this->page_number, $top_number, $offset_number, $show_best); if (count($subject_array) >= 1) { $smarty->assign('subject', $subject_array); $smarty->assign('have_subject', 1); } $smarty->assign('show_best', $show_best); } //记录用户到本版中 //还是应该记录一下用户在本版待的时间 //然后需要计算一下在本版,和本版的子版中正在浏览的人数 //删除超时用户 //取回本版和子版的ID的数组 $sub_id_array = array(); LayoutUtil::getChildId($this->db, $bbs_id, $sub_id_array); array_push($sub_id_array, $bbs_id); LayoutUtil::delExpiresUser($this->db, $sub_id_array); //统计在本版浏览的用户数 $online_user = LayoutUtil::getViewNumber($this->db, $sub_id_array); //返回本版浏览的用户的信息 $user_info = UserUtil::getUserInfoArray($this->db, $sub_id_array); $online_user_number = count($user_info); $vistor_number = $online_user - $online_user_number; $smarty->assign('online_user_number', $online_user_number); $smarty->assign('online_vistor_number', $vistor_number); $smarty->assign('user_info', $user_info); $smarty->display('viewlayout.tmpl'); }
/** * 显示版面的情况 * @param: NULL * @return: NULL * @access: public */ public function run() { //取得用户的id $user_id = UserUtil::getUserId($this->db, $_SESSION['user']['name']); $smarty = $this->getSmarty(); //取得站点的公告,并显示在页面上 $is_have_post = false; $post_str = ''; if (PostUtil::haveNotExpirePost($this->getDB())) { $is_have_post = true; $post_array = PostUtil::getPost($this->getDB(), 3); foreach ($post_array as $post_rows) { $post_str .= '<a href=\'index.php?module=post&action=view&id=' . $post_rows['id'] . '\' title=\'' . $post_rows['title'] . '\'>' . utf8_substr($post_rows['title'], 0, 35) . '</a>' . ' '; } } $smarty->assign('have_system_post', $is_have_post); $smarty->assign('post_str', $post_str); //公告显示结束 $q = $this->getParameterFromGET('q'); $encode_q = urlencode($q); //取得查询字符串 if (!$q) { $where_sql = ''; //收集查询的变量 //按关键字查询 $word = $this->getParameter('word'); //按用户名来查询 $find_user = $this->getParameter('user'); if (!$find_user && !$word) { $this->AlertAndBack(SR_NO_FIND_KEYWORD); return; } $word = ltrim($word); $word = rtrim($word); //按空格拆分关键字 $word_array = preg_split("/[\\s,]+/", $word); //看用户的搜索是按关键字,还是按帖子的内容 $is_topic = $this->getParameter('wordtarget'); if ($is_topic != 1 && $is_topic != 2) { $is_topic = 1; } $i = 0; if (count($word_array) > 1) { $where_sql .= " and ( "; foreach ($word_array as $value) { if ($is_topic == 1) { $where_sql .= " title like '%" . $value . "%' "; if ($i < count($word_array) - 1) { $where_sql .= " or "; } } else { if ($is_topic == 2) { $where_sql .= " MATCH(content) AGAINST('" . $value . "') "; if ($i < count($word_array) - 1) { $where_sql .= " or "; } } } $i = $i + 1; } $where_sql .= " ) "; } else { if (count($word_array) == 1 && $word) { if ($is_topic == 1) { $where_sql .= " and title like '%" . $word . "%' "; } else { if ($is_topic == 2) { $where_sql .= " and match(content) against('" . $word . "')"; } } } } //是按用户名来搜索的 //收集用户名 $find_user = ltrim($find_user); $find_user = rtrim($find_user); $find_user_array = preg_split("/[\\s,]+/", $find_user); $is_match = $this->getParameter('usermatch'); $i = 0; if (count($find_user_array) > 1) { $where_sql .= " and ( "; foreach ($find_user_array as $value) { if ($is_match) { $where_sql .= " author='" . $value . "' "; if ($i < count($find_user_array) - 1) { $where_sql .= " or "; } } else { $where_sql .= " author like '%" . $value . "%' "; if ($i < count($find_user_array) - 1) { $where_sql .= " or "; } } $i = $i + 1; } $where_sql .= " ) "; } else { if (count($find_user_array) == 1 && $find_user) { if ($is_match) { $where_sql .= " and author ='" . $find_user . "' "; } else { $where_sql .= " and author like '%" . $find_user . "%' "; } } } //再收集用户是否选择了论坛进行搜索。 $layout = $this->getParameterFromPOST('layout'); if ($layout && !is_array($layout)) { $this->AlertAndBack(SR_SYSTEM_REQUEST_ERROR); return; } $i = 0; if (count($layout) > 1) { $where_sql .= " and ( "; foreach ($layout as $value) { $where_sql .= " layout_id='" . $value . "' "; if ($i < count($layout) - 1) { $where_sql .= " or "; } $i = $i + 1; } $where_sql .= " ) "; } else { if (count($layout) == 1) { $where_sql .= " and layout_id='" . $layout . "' "; } } $q = ' where 1 ' . $where_sql; $encode_q = base64_encode($q); $encode_q = urlencode($encode_q); } else { // $q = urldecode($q); $q = base64_decode($q); } //求总的total number $smarty->assign('encode_q', $encode_q); //生成所有的记录数 $sql = 'select count(*) as num from bbs_subject ' . $q; $res = $this->db->Execute($sql); $rows = $res->FetchRow(); $total_number = $rows['num']; //求总公的页面 $total_page = ceil($total_number / $this->page_number); //取得当前的页面 $page = $this->getParameter('page'); if (!$page || $page < 0) { $page = 1; } if ($page > $total_page && $total_page > 0) { $page = $total_page; } $begin_page = 1; $end_page = $total_page; if ($page <= 10 && $total_page >= 10) { $end_page = 10; } else { if ($page > 10) { if ($page % 10 == 0) { //向前翻 $end_page = $page; $begin_page = $end_page - 9; } else { if ($page % 10 == 1) { //向后翻 //确定开始的页数 $begin_page = $page; if ($begin_page > $total_page) { $begin_page = $page - 9; } if ($begin_page + 9 > $total_page) { $end_page = $total_page; } else { $end_page = $begin_page + 9; } } else { $num = $page % 10; $pre_num = floor($page / 10); $begin_page = $pre_num * 10 + 1; $end_page = $begin_page + 9; } } } } if ($end_page > $total_page) { $end_page = $total_page; } $nav_page_array = array(); for ($i = $begin_page; $i <= $end_page; $i++) { array_push($nav_page_array, $i); } //帖子导航栏 $smarty->assign('nav_page', $nav_page_array); //当前的页面 $smarty->assign('now_page', $page); //共有的页面 $smarty->assign('total_page', $total_page); //显示搜索结果 //求出偏移 $offset_number = ($page - 1) * $this->page_number; $subject_array = LayoutUtil::getCacheSubjectInfo($this->db, $this->page_number, $offset_number, $q); if ($total_page > 0) { $smarty->assign('subject', $subject_array); $smarty->assign('have_subject', 1); } $smarty->display('bbssearchresult.tmpl'); }
/** * run this action * @param: NULL * @return: NULL * @access: public */ public function run() { $parent_id = $this->getParameter('parent'); if (!$parent_id) { $parent_id = 0; } $smarty = $this->getSmarty(); $sql = 'select id, title, description, status from bbs_layout where parent_id=? order by id asc'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($parent_id)); $temp = array(); while ($rows = $res->FetchRow()) { $status = SL_OPEN_STATUS; if ($rows['status'] == 0) { $status = SL_OPEN_STATUS; } else { if ($rows['status'] == 1) { $status = SL_NEED_LOGIN; } else { if ($rows['status'] == 2) { $status = SL_CLOSE; } else { if ($rows['status'] == 3) { $status = SL_ONLY_SPLIT_CATEGORY; } else { $status = SL_OPEN_STATUS; } } } } //求现有的版主列表 $manager_list_array = LayoutUtil::getManagerList($this->db, $rows['id']); $manager_str = ""; foreach ($manager_list_array as $temp_rows) { $manager_str .= "<option value=" . $temp_rows['user_id'] . ">"; $manager_str .= $temp_rows['user_name'] . "</option>\n"; } $temp[] = array('name' => $rows['title'], 'desc' => $rows['description'], 'status' => $status, 'id' => $rows['id'], 'ma' => $manager_str); } //返回论坛上面的导行栏。 $nav_array = LayoutUtil::getParentLayoutInfo($this->db, $parent_id); //导航栏 $smarty->assign('menu', $nav_array); $smarty->assign('parent_id', $parent_id); $smarty->assign('layout', $temp); $smarty->display('adminlayout.tmpl'); return; }
/** * 显示用户的控制面板 */ public function run() { //求得用户的id $user_id = UserUtil::getUserId($this->db, $_SESSION['user']['name']); $smarty = $this->getSmarty(); $user_name = $_SESSION['user']['name']; $smarty->assign('view_user_name', $user_name); //用户的所在组 $sql = 'select b.group_name from base_user_info as a join sys_group as b on ' . ' a.group_dep = b.id where a.id=?'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($user_id)); $rows = $res->FetchRow(); $smarty->assign('user_roles', $rows['group_name']); $user_header = UserUtil::getUserHeader($this->db, $user_id); $smarty->assign('head_url', $user_header); //查询新的短消息的数量 $sql = 'select count(*) as num from message_inbox where user_id=? and is_read = 0 '; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($user_id)); $rows = $res->FetchRow(); $smarty->assign('new_message_label', $rows['num']); //共有短消息数 $sql = 'select count(*) as num from message_inbox where user_id=? '; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($user_id)); $rows = $res->FetchRow(); $smarty->assign('total_message_number', $rows['num']); //取得用户注册时间 $sql = 'select register_date from base_user_info where id=?'; $stmt = $this->db->prepare($sql); $res = $this->db->CacheExecute(60 * 60, $stmt, array($user_id)); $rows = $res->FetchRow(); $smarty->assign('user_register_date', $rows['register_date']); //取得用户最后的登录时间 $sql = 'SELECT from_unixtime(last_time) as lastlogout FROM `user_last_time_logout` where user_id=?'; $stmt = $this->db->prepare($sql); $res = $this->db->CacheExecute(60 * 60, $stmt, array($user_id)); $rows = $res->FetchRow(); $smarty->assign('user_last_logout', $rows['lastlogout']); //发表的主题数 $sql = 'select count(*) as num from bbs_subject where author = ?'; $stmt = $this->db->Prepare($sql); $res = $this->db->CacheExecute(10, $stmt, array($user_name)); $rows = $res->FetchRow(); $smarty->assign('all_topic_number', $rows['num']); //参与的帖子数 $sql = 'select count(*) as num from bbs_reply where author=?'; $stmt = $this->db->Prepare($sql); $res = $this->db->CacheExecute(10, $stmt, array($user_name)); $rows = $res->FetchRow(); $smarty->assign('all_reply_number', $rows['num']); //拥有的收藏数 $sql = 'select count(*) as num from favor where user_id=?'; $stmt = $this->db->prepare($sql); $res = $this->db->CacheExecute(10, $stmt, array($user_id)); $rows = $res->FetchRow(); $smarty->assign('favor_amount', $rows['num']); ///拥有的短消息的数量 $sql = 'select count(*) as num from message_inbox where user_id=?'; $stmt = $this->db->prepare($sql); $res = $this->db->CacheExecute(20, $stmt, array($user_id)); $rows = $res->FetchRow(); $number_inbox = $rows['num']; $sql = 'select count(*) as num from message_outbox where user_id=?'; $stmt = $this->db->prepare($sql); $res = $this->db->CacheExecute(20, $stmt, array($user_id)); $rows = $res->FetchRow(); $smarty->assign('message_all_number', $number_inbox + $rows['num']); //最新的5条短消息 $sql = 'select a.id, a.user_id, b.user_name,a.send_user_id, ' . 'a.title, a.receive_time, a.is_read ' . ' from message_inbox as a, base_user_info as b where a.send_user_id = b.id and a.user_id=? ' . ' order by a.id desc'; $stmt = $this->db->prepare($sql); $res = $this->db->CacheSelectLimit(20, $stmt, 5, 1, array($user_id)); $rows = $res->GetArray(); $smarty->assign('msg', $rows); //最新5条发表的主题 $subject_array = LayoutUtil::getSubjectInfoByUser($this->db, $user_name); $smarty->assign('subject', $subject_array); //最新参与的5条主题 $reply_array = LayoutUtil::getReplyInfoByUser($this->db, $user_name); $smarty->assign('reply', $reply_array); //最新的5条收藏 $favor_array = LayoutUtil::getSubjectInfoByFavor($this->db, $user_id); $smarty->assign('favor', $favor_array); $smarty->display('usercontrol.tmpl'); }
/** * 判断用户是否是本版的版主 * @param: &$db, * @param: $id 帖子的id * @param: $user_name 用户的名字 * @return: $is_admin boolean * @access: pulic * @static */ public static function isThisLayoutAdmin(&$db, $id, $layout_id, $user_name) { /*{{{*/ //取得帖子的版块 $user_id = self::getUserId($db, $user_name); $temp_array = array(); LayoutUtil::getParentId($db, $layout_id, $temp_array); array_push($temp_array, $layout_id); $sql = 'select count(*) as num from bbs_layout_manager where user_id=? and ' . ' layout_id in (' . implode(',', $temp_array) . ')'; $sth = $db->prepare($sql); $res = $db->Execute($sth, array($user_id)); $rows = $res->FetchRow(); if ($rows['num']) { return 1; } else { return 0; } }
/** * 运行本类 * @param: NULL * @return: NULL * @access: public */ public function run() { $smarty = $this->getSmarty(); $smarty->assign('clone_title', CREATE_NEW_TOPIC); //取得版块的id $bbs_id = $this->getParameter('id'); if (!$bbs_id) { $this->forward('index.php'); } //验证论坛是否存在 if (!LayoutUtil::isExists($this->db, $bbs_id)) { //论坛不存在,则转向首页 $this->forward('index.php'); } //更新用户在本版的信息 LayoutUtil::updateOnlineUser($this->db, $bbs_id); $bbs_status = LayoutUtil::getLayoutStatus($this->db, $bbs_id); if ($bbs_status == 1 && !isset($_SESSION['user'])) { $this->AlertAndForward(SNT_NEED_LOGIN, 'index.php?module=user&action=showlogin'); return; } else { if ($bbs_status == 2) { $this->AlertAndForward(SNT_LAYOUT_WAS_CLOSED, 'index.php'); return; } else { if ($bbs_status == 3) { //等于三不允许发帖 $this->AlertAndBack(SNT_NOW_ALLOW_NEW_TOPIC); return; } else { if (LayoutUtil::isClosedByParent($this->db, $bbs_id)) { $this->AlertAndForward(SNT_LAYOUT_WAS_CLOSED, 'index.php'); return; } } } } //返回论坛上面的导行栏。 $nav_array = LayoutUtil::getParentLayoutInfo($this->db, $bbs_id); //导航栏 $smarty->assign('nav_array', $nav_array); //先删除已经不存在的用户 LayoutUtil::delNotExistsUser($this->db); //从Session里读出数据 $temp_title = $_SESSION['temp_title']; $smarty->assign('temp_title', $temp_title); $temp_express = $_SESSION['temp_express']; $smarty->assign('temp_express', $temp_express); //附件临时 $smarty->assign('is_new_topic', 1); $smarty->assign('bbsid', $bbs_id); $temp_content = $_SESSION['temp_content']; $fck = new FCKeditor("content"); $fck->BasePath = FCKEDITOR_BASEPATH; $fck->Value = $temp_content; $smarty->assign('fck', $fck); $smarty->display('topic.tmpl'); }