/** * 个人站首页 */ public function doDefault(LJL_Request $input, LJL_Response $output) { LJL_Http::setExpires(3600); #设置缓存时间 $page = $input->get('page') ? intval($input->get('page')) : 1; //文章列表 $articleList = Helper_Blog::getArticleList(array('page' => $page, 'pageSize' => $this->pageSize, 'fields' => array('id', 'firstImgId', 'title', 'descript'))); $articleCount = Helper_Blog::getArticleList(array('isCount' => 1)); //分页相关 $totalPage = ceil($articleCount / $this->pageSize); $pageStr = Libs_Global_Page::getPageString(array('page' => $page, 'pageTotal' => $totalPage, 'urlClass' => 'Blog_Plugin_Urls', 'urlFunc' => 'getIndexUrl', 'args' => array('page' => $page))); $cateList = LJL_Config::get('Blog_' . ucfirst(APP_BLOG_NAME) . '_Cate', 'CATE'); //面包屑导航 $nav[0]['title'] = '首页'; $pageTitle = $page > 1 ? '-第' . $page . '页' : ''; //首页展示图片 $showImgs = ''; $imgStrFile = '/tmp/' . APP_BLOG_NAME . '.php'; if (file_exists($imgStrFile) && $page < 2) { $imgStr = file_get_contents($imgStrFile); $imgArr = json_decode($imgStr); $showImgs = '<div id="img-scroll">'; foreach ((array) $imgArr as $key => $urlsrc) { $active = $key === 0 ? 'class="active"' : ''; $us = explode('#', $urlsrc); $showImgs .= '<a target="_blank" href="' . $us[0] . '"><img ' . $active . ' src="' . $us[1] . '"></a>'; } $showImgs .= '</div>'; } //seo $output->seoArr = array('title' => BLOG_SEO_TITTLE . $pageTitle . ' | 最红博 '); $output->nav = $nav; $output->cate = ''; $output->tag = ''; $output->cateList = $cateList; $output->pageStr = $pageStr; $output->articleList = $articleList; $output->showImgs = $showImgs; $output->header = $output->fetchCol("Part/Main/Header"); $output->footer = $output->fetchCol("Part/Main/Footer"); $output->navbarTpl = $output->fetchCol("Part/Navbar"); $output->leftsideCate = $output->fetchCol("Part/LeftsideCate"); $output->navGuideTpl = $output->fetchCol("Part/Navguide"); $output->newArticleTpl = $output->fetchCol("Part/NewArticle"); $output->searchTpl = $output->fetchCol("Part/Search"); $output->setTemplate('List'); }
/** * 获得数据列表 */ public static function getList($paramArr) { $options = array('dbName' => self::$initDbName, 'tblName' => self::$initTblName, 'cols' => '*', 'pageSize' => 20, 'page' => 1, 'pageUrl' => '', 'whereSql' => '', 'orderSql' => '', 'iswrite' => false, 'getAll' => false, 'pageTpl' => 9, 'jsOnclick' => '', 'limit' => '', 'groupbySql' => '', 'debug' => 0); if (is_array($paramArr)) { $options = array_merge($options, $paramArr); } extract($options); $db = API_DbAdv::instance($dbName); if ($iswrite) { $db->forceReadMaster(); } #强制用主库,防止 读写分离导致数据不同步 if ($limit) { $limit = ' limit ' . $limit; #获得数量信息 $sql = "select {$cols} from {$tblName} where 1 {$whereSql} {$groupbySql} {$limit}"; $allCnt = count($db->getAll($sql)); } else { #获得数量信息 $sql = "select count('x') cnt from {$tblName} where 1 {$whereSql} {$groupbySql} {$limit}"; if ($groupbySql) { $allCnt = count($db->getAll($sql)); } else { $allCnt = $db->getOne($sql); } } #获得分页信息 $pageCfg = array('page' => $page, 'rownum' => $pageSize, 'target' => '_self', 'total' => $allCnt, 'url' => $pageUrl, 'jsOnclick' => $jsOnclick); $pageObj = new Libs_Global_Page($pageCfg); $pageBar = $pageObj->display($pageTpl); $offset = ($page - 1) * $pageSize; $limitSql = $getAll ? "" : " limit {$offset},{$pageSize}"; $sql = "select {$cols} from {$tblName} where 1 {$whereSql} {$groupbySql} {$orderSql} {$limitSql} "; $data = $db->getAll($sql); if ($debug) { echo $sql; } return array('allCnt' => $allCnt, 'pageBar' => $pageBar, 'data' => $data); }
public function DoList(LJL_Request $input, LJL_Response $output) { $page = $input->get('page'); $articleId = $input->get('articleid'); if ($page <= 1) { $page = 1; } $articleList = Helper_Blog::getArticleList(array('page' => $page, 'pageSize' => $this->pageSize, 'fields' => array(), 'isPublished' => 0, 'articleid' => $articleId)); $articleCount = Helper_Blog::getArticleList(array('isCount' => 1, 'isPublished' => 0, 'articleid' => $articleId)); //分页相关 $totalPage = ceil($articleCount / $this->pageSize); $pageStr = Libs_Global_Page::getPageString(array('page' => $page, 'pageTotal' => $totalPage, 'urlClass' => 'Blog_Plugin_Urls', 'urlFunc' => 'getAdminListUrl', 'args' => array('page' => $page))); //默认showimg $putDir = '/tmp/' . APP_BLOG_NAME . '.php'; $outimg = ''; if (file_exists($putDir)) { $imgArr = json_decode(file_get_contents($putDir)); foreach ((array) $imgArr as $img) { $outimg .= "\n" . $img; } } $output->imgStr = $outimg; $output->articleid = $articleId; $output->pageStr = $pageStr; $output->articleList = $articleList; $output->setTemplate('AdminList'); }
private function _fulltextSearch($input, $output) { LJL_Http::setExpires(3600); #设置缓存时间 $tag = $keyword = trim($input->get('keyword')); $page = $input->get('page') ? intval($input->get('page')) : 1; $start = ($page - 1) * $this->pageSize; $query = array('q' => $keyword ? $keyword : '*', 'wt' => 'json', 'rows' => $this->pageSize, 'start' => $start, 'hl' => 'true', 'hl.fl' => 'title,descript', "hl.simple.pre" => '<font color="red">', "hl.simple.post" => '</font>'); $solrServer = LJL_Config::get('Blog_Solr', 'SOLR'); $url = $solrServer['url'] . '/select?' . http_build_query($query); //echo $url;die; $solrRes = LJL_Http::curlPage(array('url' => $url, 'timeout' => 5)); $searchRes = json_decode($solrRes, true); //var_dump($searchRes); $cateList = LJL_Config::get('Blog_' . ucfirst(APP_BLOG_NAME) . '_Cate', 'CATE'); //文章列表 $articleList = $searchRes['response']['docs']; $articleCount = $searchRes['response']['numFound']; $articleHl = $searchRes['highlighting']; unset($searchRes); //组织高亮部分 //var_dump($articleHl);die; foreach ((array) $articleList as $akey => $aval) { if (key_exists($aval['id'], $articleHl)) { if (isset($articleHl[$aval['id']]['title'])) { $articleList[$akey]['title'] = $articleHl[$aval['id']]['title'][0]; } if (isset($articleHl[$aval['id']]['descript'])) { $articleList[$akey]['descript'] = $articleHl[$aval['id']]['descript'][0]; } } } //分页相关 $totalPage = ceil($articleCount / $this->pageSize); $pageStr = Libs_Global_Page::getPageString(array('page' => $page, 'pageTotal' => $totalPage, 'urlClass' => 'Blog_Plugin_Urls', 'urlFunc' => 'getSearchUrl', 'args' => array('type' => $input->get('type'), 'keyword' => $keyword, 'page' => $page))); //获取各分类下tag标签 if ($cateList) { $tagsArr = []; foreach ($cateList as $cateKey => $cateV) { $tagsArr[$cateKey] = Helper_Blog::getTags(array('cate' => $cateKey)); } } //面包屑导航 $nav[0]['title'] = '首页'; $nav[0]['url'] = WWW_WEB; $nav[1]['title'] = $keyword; //seo $output->seoArr = array('title' => $keyword . '搜索-第' . $page . '页 - ' . BLOG_SEO_TITTLE . ' | 最红博 '); $output->tagsArr = $tagsArr; $output->tag = $keyword; $output->cate = ''; $output->nav = $nav; $output->cateList = $cateList; $output->pageStr = $pageStr; $output->articleList = $articleList; $output->header = $output->fetchCol("Part/Main/Header"); $output->footer = $output->fetchCol("Part/Main/Footer"); $output->navbarTpl = $output->fetchCol("Part/Navbar"); $output->leftsideCate = $output->fetchCol("Part/LeftsideCate"); $output->navGuideTpl = $output->fetchCol("Part/Navguide"); $output->newArticleTpl = $output->fetchCol("Part/NewArticle"); $output->searchTpl = $output->fetchCol("Part/Search"); $output->setTemplate('List'); }