/** * 文章列表 * @author Saki <*****@*****.**> * @date 2014-5-13上午10:30:51 * @version v1.0.0 */ public function listinfo() { $model = new \Admin\Model\ArticleListModel(); //计算分类总数 $sql = "select count(ctm) as count from (select date_format(ctm,'%Y-%m') as ctm from __PREFIX__article_list group by date_format(ctm,'%Y-%m')) a"; $count = $model->query($sql); //分页显示设置 $Page = new \Think\Page($count[0]['count'], 10); $Page->setConfig('prev', '上一页'); $Page->setConfig('next', '下一页'); $Page->setConfig('theme', '%FIRST% %LINK_PAGE% %END%'); $show = $Page->show(); //分页数据处理 $list = $model->getArticleList_Mon($Page); $this->assign('list', $list); $this->assign('page', $show); $this->display(); }
/** * @todo: 删除评论 * @author Saki <*****@*****.**> * @date 2014-12-26 下午5:45:28 * @version V1.0 */ public function deleteComment($id, $aid) { $model = D('Admin/ArticleComment'); try { $map['id'] = $id; $map['_logic'] = 'OR'; $map['pid'] = $id; $count = $model->where($map)->count(); $isdelete = $model->where($map)->delete(); if ($isdelete) { //评论数-n $article_list_model = new \Admin\Model\ArticleListModel(); $article_list_model->minusComment($aid, $count); } $errcode = $isdelete ? 0 : 500; $msg = $isdelete ? '删除成功' : '删除失败'; } catch (Exception $e) { $errcode = 500; $msg = $e->getMessage(); } $res['errcode'] = $errcode; $res['msg'] = $msg; return $res; }
/** * @todo: 前台点击【文章标签】操作控制器 * @author Saki <*****@*****.**> * @date 2015-1-7 下午3:12:21 * @version V1.0 */ public function Tagslog() { $model = new \Admin\Model\ArticleListModel(); $type_model = D('Admin/ArticleType'); //查询条件判断 $map['admin_id'] = 1; if (isset($_GET['code'])) { $condition['id'] = $_GET['code']; $ishas_type = D('Admin/ArticleType')->where($condition)->limit(1)->find(); if ($ishas_type) { $map['type_id'] = $_GET['code']; } } $count = $model->where($map)->count(); //分页显示设置 $Page = new \Think\Page($count, 7); $Page->setConfig('prev', '上一页'); $Page->setConfig('next', '下一页'); $Page->setConfig('theme', '%FIRST% %LINK_PAGE% %END%'); $show = $Page->show(); //分页数据处理 $Parsedown = new \Org\Markdown\Parsedown(); $list = $model->relation(true)->where($map)->order('ctm desc')->limit($Page->firstRow . ',' . $Page->listRows)->select(); foreach ($list as $k => $article) { //内容的截取 $content = $article['content']; $new_content = strip_tags($Parsedown->text($content)); $list[$k]['content'] = mb_substr($new_content, 0, 200, 'utf-8') . '...'; //时间的处理 $list[$k]['ctm_M'] = date('M', strtotime($article['ctm'])); //月份简写 $ctm_F = date('F', strtotime($article['ctm'])); //月份全写 $len_M = strlen($list[$k]['ctm_M']); //缩写字符串的长度 $ctm_F = mb_substr($ctm_F, $len_M); //截取剩余字符串 $list[$k]['ctm_F'] = $ctm_F; //月份全写截取后的剩余字符串 $list[$k]['ctm_Y'] = date('Y', strtotime($article['ctm'])); //年份 $list[$k]['ctm_D'] = date('d', strtotime($article['ctm'])); //日期 } $this->assign('list', $list); $this->assign('page', $show); $this->display('tags'); }
/** * @todo: 日历插件 * @author Saki <*****@*****.**> * @date 2014-12-17 上午11:21:33 * @version V1.0 */ public function calendar() { $str = ''; $Y = date('Y', time()); //当前年份 $m = date('m', time()); //当前月份 $w = date('w', time()); //当前星期几,0-6,0代表星期天 $d = date('d', time()); $beginDate = date('Y-m-01', strtotime(date("Y-m-d"))); //当前月的第一天 $beginTime = strtotime($beginDate); //当前月的第一天的时间戳 $w_first = date('w', $beginTime); //当前月第一天是星期几 $day_count = cal_days_in_month(CAL_GREGORIAN, $m, $Y); //当前月总共天数 //计算总行数等数值 $row_num = ($day_count + $w_first) % 7 == 0 ? floor(($day_count + $w_first) / 7) : floor(($day_count + $w_first) / 7 + 1); $data = array(); //每行的具体信息 for ($i = 1; $i <= $row_num; $i++) { if ($i == 1) { //第一行 $temp['type'] = 'top'; $temp['colspan'] = $w_first; //开头空格数 $temp['start'] = 1; $temp['end'] = 7 - $w_first + 1; $temp['day_num'] = 7 - $w_first; } elseif ($i == $row_num) { $temp['type'] = 'end'; $temp['colspan'] = 7 - ($day_count + $w_first) % 7; $temp['start'] = 7 * ($i - 1) + 1 - $w_first; $temp['end'] = $day_count + 1; $temp['day_num'] = ($day_count + $w_first) % 7; } else { $temp['type'] = 'center'; $temp['colspan'] = 0; $temp['start'] = 7 * ($i - 1) + 1 - $w_first; $temp['end'] = 7 * ($i - 1) + 1 - $w_first + 6 + 1; $temp['day_num'] = 7; } //加入到总数组中 array_push($data, $temp); } //当前月发表过文章的列表信息 $model = new \Admin\Model\ArticleListModel(); $sql = "select group_concat(date_format(ctm,'%d')) as ctm FROM __PREFIX__article_list where date_format(ctm,'%Y-%m')=date_format(now(),'%Y-%m') and status=1"; $has_ctm = $model->query($sql); $this->assign('calendar', $data); $this->assign('has_ctm', $has_ctm[0]['ctm']); $this->assign('d', $d); }
/** * @todo: 预览文章 * @author Saki <*****@*****.**> * @date 2014-12-16 上午9:21:57 * @version V1.0 */ public function view() { $p = isset($_GET['p']) ? $_GET['p'] : 0; //评论分页标志 //文章详细信息 $model = new \Admin\Model\ArticleListModel(); $info = $model->getArticleInfo($_GET['id']); $tags = explode(",", $info['tags']); //查询评论列表 $comments_model = new \Admin\Model\ArticleCommentModel(); //统计总条数 $condition['aid'] = $_GET['id']; $condition['pid'] = 0; $count = $comments_model->where($condition)->count(); //分页显示设置 $Page = new \Think\Page($count, 3); $Page->setConfig('prev', '上一页'); $Page->setConfig('next', '下一页'); $Page->setConfig('theme', '%FIRST% %LINK_PAGE% %END%'); $show = $Page->show(); $comments_list = $comments_model->getComments_First($Page, $condition); //输出 $this->assign('info', $info); $this->assign('tags', $tags); $this->assign('comments_list', $comments_list); $this->assign('page', $show); $this->assign('p', $p); $this->display(); }