/** * [f 论坛版块显示帖子列表] * @param [type] $id [版块ID] * @return [type] [无] */ public function f($id) { $id = I('get.id'); $p = A('Public'); $common = $p->common(); $d_topic = D('Topic'); $num = 10; //每页显示几条 $page_count = ceil($d_topic->getTopicNum('forum', $id) / $num); //总页数 $page_now = empty(I('get.page')) ? 1 : I('get.page'); //当前页 $action = 'Forum/' . $id . '/page'; $page = $p->pageShow($page_count, $page_now, $action); //分页列表变量 $arr = $d_topic->getTopicList(($page_now - 1) * $num, $num, $id); $c_topic = A('Topic'); $topic = $c_topic->regroup($arr, 2, 'forum'); //数组重组 $d_forum = D('Forum'); $forum = $d_forum->getForumMsg($id); //版块详细信息 foreach ($forum as $key => $value) { switch ($key) { case 'time': $forum[$key] = date_rewrite(strtotime($value)); break; default: $forum[$key] = $value; break; } } //var_dump($arr); //var_dump($forum); $t = empty($_GET['page']) ? '' : "第 " . $page_now . " 页 - "; $title = $t . $forum['name'] . " - " . $common['website']['site_title'] . ""; $this->assign('title', $title); $this->assign('common', $common); $this->assign('topic', $topic); $this->assign('forum', $forum); $this->assign('page', $page); C('TOKEN_ON', false); $this->display(); }
/** * 消息数组重组 * @param array $arr 传入数组 * @param string $type 1 => 一维数组 2 => 二维数组 * @return Ambigous <multitype:, unknown> */ private function regroup($arr, $type, $list) { $res_arr = array(); if ($type == 1) { foreach ($arr as $key => $value) { switch ($key) { case 'read_on': if ($value == 0) { $res_arr[$key] = "【主题内容】(对方未阅读)"; } else { if ($value == 1) { $res_arr[$key] = "【主题内容】[对方于 " . $arr['read_time'] . " 已读]"; } } break; case 'time': $res_arr[$key] = date_rewrite(strtotime($value)); break; case "avatar": if ($value == 0) { $res_arr['avatar'] = "http://" . SLBBS_ROOT . "/Public/icon/avatar/default.png"; } else { $res_arr['avatar'] = "http://" . SLBBS_ROOT . "/Public/icon/avatar/" . $value . ""; } break; case 'send_id': if ($value == session('user_id') && $arr['read_on'] == 0) { D('Message')->upReadMessage($arr['id']); //标记已读 } $res_arr[$key] = $value; break; default: $res_arr[$key] = $value; break; } } } else { if ($type == 2) { foreach ($arr as $key => $value) { foreach ($value as $_key => $_value) { switch ($_key) { case 'send_id': if ($_value == session('user_id') && $value['read_on'] == 0) { D('Message')->upReadMessage($value['id']); //标记已读 } break; case 'read_on': if ($_value == 0) { if ($list == 'list') { $res_arr[$key][$_key] = "<font color='red'>[有新动态]</font>"; } else { $res_arr[$key][$_key] = "<font color='red'>[对方未读]</font>"; } } elseif ($_value == 1) { if ($list == 'list') { $res_arr[$key][$_key] = ""; } else { $res_arr[$key][$_key] = " [对方于 " . $value['read_time'] . " 已读]"; } } break; case 'time': $res_arr[$key][$_key] = date_rewrite(strtotime($_value)); break; case "avatar": if ($_value == 0) { $res_arr[$key]['avatar'] = "http://" . SLBBS_ROOT . "/Public/icon/avatar/default.png"; } else { $res_arr[$key]['avatar'] = "http://" . SLBBS_ROOT . "/Public/icon/avatar/" . $_value . ""; } break; default: $res_arr[$key][$_key] = $_value; break; } } } } } return $res_arr; }
/** * [regroup 帖子数组重组] * @param [array] $topicArr [传入帖子数组] * @param [int] $type [1 =>一维数组 2=>二维数组] * @param [string] $page [用于判断首页或者论坛页面] * @return [array] [数组] */ public function regroup($topicArr, $type, $page = '') { $arr = array(); if ($type == 1) { foreach ($topicArr as $key => $value) { switch ($key) { case "user_id": $arr['user_url'] = U("/Member/" . $value . ""); $arr['user_id'] = $value; break; case "date": $arr['date'] = date_rewrite(strtotime($value)); break; case "last_date": if ($value == 0) { $arr['last_date'] = "暂无回复"; } else { $arr['last_date'] = date_rewrite(strtotime($value)); } break; case "forum_id": $arr['forum_url'] = U("/Forum/" . $value . ""); break; case "name": $arr['forum_name'] = $value; break; case 'views': $arr[$key] = $value + 1; break; case 'best': if ($value == 1) { $arr['topic_title'] = "【精华】" . $topicArr['title'] . ""; } $arr['best'] = $value; break; case "title": $arr['topic_title'] = $value; break; case "avatar": if ($value == 0) { $arr['avatar_url'] = "http://" . SLBBS_ROOT . "/Public/icon/avatar/default.png"; } else { $arr['avatar_url'] = "http://" . SLBBS_ROOT . "/Public/icon/avatar/" . $value . ""; } break; case 'content': $arr['content'] = xss_clean(htmlspecialchars_decode($value)); break; default: $arr[$key] = $value; } $arr['forum_id'] = $topicArr['forum_id']; } if ($arr['hide'] == 0) { $arr['content'] = "<font color='red'>【帖子审核中。。。】</font>"; } } elseif ($type == 2) { foreach ($topicArr as $key => $value) { foreach ($value as $_key => $_value) { //数组重新赋值 switch ($_key) { case "user_id": $arr[$key]['user_url'] = U("/Member/" . $_value . ""); break; case "date": $arr[$key]['date'] = date_rewrite(strtotime($_value)); break; case "last_date": $arr[$key]['last_date'] = date_rewrite(strtotime($_value)); break; case "forum_id": $arr[$key]['forum_url'] = U("/Forum/" . $_value . ""); break; case "name": $arr[$key]['forum_name'] = $_value; break; case 'best': if ($_value == 1) { $arr[$key]['topic_title'] = "<font color='red'>" . $topicArr[$key]['title'] . "</font>"; } break; case 'top': if ($page == 'forum') { if ($_value == 1) { $arr[$key]['topic_title'] = "<font color='#dd1a00'>" . $topicArr[$key]['title'] . "</font> <img src='http://" . SLBBS_ROOT . "/Public/images/top.png'>"; } } break; case 'home_top': if ($_value == 1) { $arr[$key]['topic_title'] = "<font color='#dd1a00'>【首页置顶】" . $topicArr[$key]['title'] . "</font> <img src='http://" . SLBBS_ROOT . "/Public/images/top.png'>"; } break; case "title": $arr[$key]['topic_title'] = $_value; break; case "avatar": if ($_value == 0) { $arr[$key]['avatar_url'] = "http://" . SLBBS_ROOT . "/Public/icon/avatar/default.png"; } else { $arr[$key]['avatar_url'] = "http://" . SLBBS_ROOT . "/Public/icon/avatar/" . $_value . ""; } break; case "id": $arr[$key]['topic_url'] = U("/Topic/" . $_value . ""); break; default: $arr[$key][$_key] = $_value; } } } } return $arr; }