コード例 #1
0
ファイル: function.php プロジェクト: kennyhonghui/zhuoxi
/**
 * 内容页SEO信息
 * @param int $data
 * @param int $page
 * @return array
 */
function showSeo($data, $page = 1)
{
    $cats = get_category_data();
    $cat = $cats[$data['catid']];
    $listseo = listSeo($cat);
    $meta_title = $meta_keywords = $meta_description = '';
    $meta_title = (isset($data['stitle']) && $data['stitle'] ? $data['stitle'] . '-' . $data['title'] . '-' : $data['title'] . '-' . ($page > 1 ? lang('fun-1', array('1' => $page)) . '-' : '')) . $listseo['meta_title'];
    $meta_keywords = empty($data['keywords']) ? $listseo['meta_keywords'] : $data['keywords'] . ',' . $listseo['meta_keywords'];
    $meta_description = empty($data['description']) ? $listseo['meta_description'] : $data['description'];
    return array('meta_title' => $meta_title, 'meta_keywords' => $meta_keywords, 'meta_description' => $meta_description);
}
コード例 #2
0
ファイル: Common.php プロジェクト: kennyhonghui/zhuoxi
 /**
  * 生成栏目html
  */
 protected function createCat($cat, $page = 1)
 {
     if ($cat['typeid'] == 3) {
         return false;
     }
     if ($cat['setting']['url']['use'] == 0 || $cat['setting']['url']['tohtml'] == 0 || $cat['setting']['url']['list'] == '') {
         return false;
     }
     $url = substr($this->getCaturl($cat, $page), strlen(self::get_base_url()));
     //去掉域名部分
     if (substr($url, -5) != '.html') {
         $file = 'index.html';
         //文件名
         $dir = $url;
         //目录
     } else {
         $file = basename($url);
         $dir = str_replace($file, '', $url);
     }
     $this->mkdirs($dir);
     $dir = substr($dir, -1) == '/' ? substr($dir, 0, -1) : $dir;
     $htmlfile = $dir ? $dir . '/' . $file : $file;
     ob_start();
     $catid = $cat['catid'];
     $cat = $this->cats[$catid];
     if (empty($cat)) {
         return;
     }
     $this->view->setTheme(true);
     if ($cat['typeid'] == 1) {
         //内部栏目
         $this->view->assign($cat);
         $this->view->assign(listSeo($cat, $page));
         $this->view->assign(array('page' => $page, 'catid' => $catid, 'pageurl' => urlencode($this->getCaturl($cat, '{page}'))));
         $this->view->display(substr($cat['child'] == 1 ? $cat['categorytpl'] : $cat['listtpl'], 0, -5));
     } elseif ($cat['typeid'] == 2) {
         //单网页
         $cat = $this->get_content_page($cat, 0, $page);
         $cat['content'] = relatedlink($cat['content']);
         $this->view->assign($cat);
         $this->view->assign(listSeo($cat, $page));
         $this->view->display(substr($cat['showtpl'], 0, -5));
     }
     $this->view->setTheme(false);
     if (!file_put_contents($htmlfile, ob_get_clean(), LOCK_EX)) {
         $this->adminMsg(lang('a-com-11', array('1' => $htmlfile)));
     }
     $htmlfiles = $this->cache->get('html_files');
     $htmlfiles[] = $htmlfile;
     if (empty($page) || $page == 1) {
         $onefile = str_replace('{page}', 1, substr($this->getCaturl($cat, '{page}'), strlen(self::get_base_url())));
         @copy($htmlfile, $onefile);
         $htmlfiles[] = $onefile;
     }
     $this->cache->set('html_files', $htmlfiles);
     if (strpos($cat['content'], '{-page-}') !== false) {
         $content = explode('{-page-}', $cat['content']);
         $pageid = count($content) >= $page ? $page - 1 : count($content) - 1;
         $page_id = 1;
         $pagelist = array();
         $cat['content'] = $content[$pageid];
         foreach ($content as $t) {
             $pagelist[$page_id] = getCaturl($cat, $page_id);
             $page_id++;
         }
         if (isset($pagelist[$page + 1])) {
             $this->createCat($cat, $page + 1);
         }
     }
     return true;
 }
コード例 #3
0
 /**
  * 内容搜索
  */
 public function searchAction()
 {
     $kw = $this->get('kw');
     $kw = urldecode($kw);
     $sql = null;
     $page = (int) $this->get('page') > 0 ? (int) $this->get('page') : 1;
     $param = $this->getParam();
     if ($this->site['SITE_SEARCH_TYPE'] == 2) {
         //Sphinx
         if (empty($kw)) {
             $this->msg(lang('con-5'));
         }
         App::auto_load('sphinxapi');
         $cl = new SphinxClient();
         $host = $this->site['SITE_SEARCH_SPHINX_HOST'];
         $prot = $this->site['SITE_SEARCH_SPHINX_PORT'];
         $name = $this->site['SITE_SEARCH_SPHINX_NAME'];
         $start = ($page - 1) * (int) $this->site['SITE_SEARCH_PAGE'];
         $limit = (int) $this->site['SITE_SEARCH_PAGE'];
         $cl->SetServer($host, 9312);
         $cl->SetMatchMode(SPH_MATCH_ALL);
         $cl->SetSortMode(SPH_SORT_EXTENDED, 'updatetime DESC');
         $cl->SetLimits($start, $limit);
         $res = $cl->Query($kw, $this->site['SITE_SEARCH_SPHINX_NAME']);
         if ($res['total']) {
             $ids = '';
             foreach ($res['matches'] as $cid => $val) {
                 $ids .= $cid . ',';
             }
             $ids = substr($ids, -1) == ',' ? substr($ids, 0, -1) : $ids;
             $total = $res['total'];
             $pageurl = $this->site['SITE_SEARCH_URLRULE'] ? str_replace('{id}', urlencode($kw), $this->site['SITE_SEARCH_URLRULE']) : url('content/search', array('kw' => urlencode($kw), 'page' => '{page}'));
             $sql = 'SELECT id,modelid,catid,url,thumb,title,keywords,description,username,updatetime,inputtime from ' . $this->content->prefix . 'content_' . $this->siteid . ' WHERE id IN (' . $ids . ') ORDER BY updatetime DESC LIMIT ' . $limit;
         }
     } else {
         //普通搜索
         $search = $this->model('search');
         $start = ($page - 1) * (int) $this->site['SITE_SEARCH_PAGE'];
         $limit = $this->site['SITE_SEARCH_PAGE'] ? (int) $this->site['SITE_SEARCH_PAGE'] : 10;
         $cache = (int) $this->site['SITE_SEARCH_INDEX_CACHE'];
         $result = $search->getData((int) $this->get('id'), $cache, $param, $start, $limit, $this->site['SITE_SEARCH_KW_FIELDS'], $this->site['SITE_SEARCH_KW_OR']);
         $kw = $result['keywords'];
         $sql = $result['sql'];
         $total = $result['total'];
         $catid = $result['catid'];
         $modelid = $result['modelid'];
         $pageurl = $this->site['SITE_SEARCH_URLRULE'] ? str_replace('{id}', $result['id'], $this->site['SITE_SEARCH_URLRULE']) : url('content/search', array('id' => $result['id'], 'page' => '{page}'));
     }
     if ($sql) {
         $pagelist = $this->instance('pagelist');
         $pagelist->loadconfig();
         $data = $this->content->execute($sql, true, $this->site['SITE_SEARCH_DATA_CACHE']);
         $pagelist = $pagelist->total($total)->url($pageurl)->num($this->site['SITE_SEARCH_PAGE'])->page($page)->output();
     } else {
         $data = array();
         $total = 0;
         $pagelist = '';
     }
     $this->view->assign(listSeo($cat, $page, $kw));
     $this->view->assign(array('id' => $id, 'kw' => $kw, 'model' => $this->get_model(), 'catid' => $catid, 'modelid' => $modelid, 'searchpage' => $pagelist, 'searchdata' => $data, 'searchnums' => $total));
     $this->view->display('search');
 }