Example #1
0
 /**
  * 前台获取文章列表
  *
  * @param string $condition
  * @param int $page
  * @param int $perPageNum
  * @return array
  */
 function getLogsForHome($condition = '', $page = 1, $perPageNum)
 {
     $start_limit = !empty($page) ? ($page - 1) * $perPageNum : 0;
     $limit = $perPageNum ? "LIMIT {$start_limit}, {$perPageNum}" : '';
     $sql = "SELECT * FROM " . DB_PREFIX . "blog WHERE type='blog' and hide='n' and checked='y' {$condition} {$limit}";
     $res = $this->db->query($sql);
     $logs = array();
     while ($row = $this->db->fetch_array($res)) {
         $row['log_title'] = htmlspecialchars(trim($row['title']));
         $row['log_url'] = Url::log($row['gid']);
         $row['logid'] = $row['gid'];
         $cookiePassword = isset($_COOKIE['em_logpwd_' . $row['gid']]) ? addslashes(trim($_COOKIE['em_logpwd_' . $row['gid']])) : '';
         if (!empty($row['password']) && $cookiePassword != $row['password']) {
             $row['excerpt'] = '<p>[该文章已设置加密,请点击标题输入密码访问]</p>';
         } else {
             if (!empty($row['excerpt'])) {
                 $row['excerpt'] .= '<p class="readmore"><a href="' . Url::log($row['logid']) . '">阅读全文&gt;&gt;</a></p>';
             }
         }
         $row['log_description'] = empty($row['excerpt']) ? breakLog($row['content'], $row['gid']) : $row['excerpt'];
         $row['attachment'] = '';
         $row['tag'] = '';
         $row['tbcount'] = 0;
         //兼容未删除引用的模板
         $logs[] = $row;
     }
     return $logs;
 }
Example #2
0
 public function indexAction()
 {
     //获取相关用于检索的参数
     //分类
     $category = get("category", "txt") ? trim(get("category", "txt")) : "";
     //归档
     $archive = get("archive", "txt") ? trim(get("archive", "txt")) : "";
     //标签
     $tag = get("tag", "txt") ? trim(get("tag", "txt")) : "";
     //获取文章列表
     $where = $logList = array();
     $where['status'] = \Admin\Article\Type\Status::STATUS_ENABLE;
     $where['member_id'] = 1;
     //检索
     if (!empty($category)) {
         $where['category'] = $category;
     }
     if (!empty($archive)) {
         preg_match("/^(\\d{4})年(\\d{1,2})月\$/", $archive, $result);
         $where['time?>='] = "{$result['1']}-{$result['2']}-01 00:00:00";
         $where['time?<'] = "{$result['1']}-" . ($result[2] + 1) . "-01 00:00:00";
     }
     if (!empty($tag)) {
         $tagRow = db()->Table('article_tag')->getRow(array('tagname' => $tag))->done();
         //getRow
         if ($tagRow) {
             $where['id'] = explode(",", $tagRow['gid']);
         }
     }
     $count = db()->Table('article')->getAll($where)->order("istop desc")->count()->done();
     //getAll
     $page = new \System\Library\Page($count);
     if ($page->isShow) {
         $showPage = $page->show();
         // 分页显示输出
     } else {
         $showPage = "";
     }
     // 进行分页数据查询
     $all = db()->Table('article')->getAll($where)->limit($page->firstRow, $page->listRows)->order("istop desc")->done();
     foreach ($all as $k => $v) {
         $logList[$k]['title'] = htmlspecialchars(trim($v['title']));
         $logList[$k]['id'] = $v['id'];
         $logList[$k]['url'] = $this->getView()->log($v['id']);
         $cookiePassword = cookie('xtt_logpwd_' . $v['id']) ? addslashes(trim(cookie('xtt_logpwd_' . $v['id']))) : '';
         $excerpt = empty($v['excerpt']) ? breakLog($v['content'], $v['id']) : $v['excerpt'];
         $excerpt = mb_substr(strip_tags($excerpt), 0, 60);
         $logList[$k]['excerpt'] = $v['excerpt'] = $excerpt;
         if (!empty($v['password']) && $cookiePassword != $v['password']) {
             $logList[$k]['excerpt'] = '<p>[该日志已设置加密,请点击标题输入密码访问]</p>';
         } else {
             if (!empty($v['excerpt'])) {
                 $logList[$k]['excerpt'] .= '<p class="readmore"><a href="' . $this->getView()->log($v['id']) . '">阅读全文&gt;&gt;</a></p>';
             }
         }
         $logList[$k]['thumbnail'] = $v['thumbnail'];
         $logList[$k]['time'] = $v['time'];
         $logList[$k]['author'] = member($v['member_id']);
         $model = new \Home\Model\homeModel();
         $logList[$k]['category'] = $model->getArticleCategory($v['category']);
         $tag = new \Admin\Model\articleModel();
         //获取该文章标签
         $tags = $tag->getTags($v['id'], true);
         if ($tags) {
             $logList[$k]['tags'] = explode(",", $tags);
         }
         $logList[$k]['comment_num'] = $v['comment_num'];
         $logList[$k]['view_num'] = $v['view_num'];
         $logList[$k]['istop'] = $v['istop'];
         $logList[$k]['content'] = handleContent($v['content']);
     }
     $this->getView()->assign(array('articleAll' => $logList, 'show' => $showPage));
     $this->getView()->display();
 }