<?php
namespace application\home\controller;
class index extends auth {
public $config;
public function __construct() {
parent::__construct();
$this->config = get_config();
$this->assign('config', $this->config);
}
public function index() {
$this->assign('config', $this->config);
$this->display('index');
}
public function lists() {
$catid = isset($_GET['catid']) ? intval($_GET['catid']) : 0;
if (!$catid)
showmsg(L('missing_parameter'), 'stop');
$catinfo = get_category($catid);
if (!$catinfo) {
showmsg(L('category_not_existent'), 'stop');
}
if ($catinfo['type'] == 2) {
showmsg(L('is_jump'), $catinfo['pclink'], 1);
}
$template = $catid == $catinfo['arrchildid'] ? $catinfo['list_template'] : $catinfo['category_template'];
if ($catinfo['type'] == 1) {
$r = db('page')->where(array('catid' => $catid))->find();
$this->assign('item', $r);
$template = $catinfo['category_template'];
}
$ret = db('content')->field('title,catid,inputtime,url,thumb,status,description')->where(['catid' => $catid])->newpage();
foreach ($ret['items'] as $row) {
$thumb = $row['thumb'];
if (empty($thumb)) {
$thumb = "/static/home/nophoto.gif";
}
$row['thumb'] = $thumb;
$row['description'] = cutstr($row['description'], 310);
$data[] = $row;
}
$this->assign('page', $ret['page']);
$this->assign('items', $data);
$this->assign('catid', $catid);
$this->assign('catinfo', $catinfo);
$this->assign('template', $template);
$this->assign('config', $this->config);
$this->display($template);
}
public function show() {
$catid = isset($_GET['catid']) ? intval($_GET['catid']) : 0;
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if (!$catid || !$id) {
showmsg(L('missing_parameter'), 'stop');
}
$catinfo = get_category($catid);
if (!$catinfo) {
showmsg(L('category_not_existent'), 'stop');
}
$modelid = $catinfo['modelid'];
$template = $catinfo['show_template'];
$modelinfo = get_modelinfo();
if (!isset($modelinfo[$modelid])) {
showmsg(L('model_not_existent'), 'stop');
}
$table = $modelinfo[$modelid]['tablename'];
$where = ['a.contentid' => $id];
$data = db('content a')
->field('*')
->join(db()->prefix . '' . $table . " g on a.contentid=g.contentid")
->where($where)
->find();
if (!$data || $data['status'] != 1) {
showmsg(L('content_not_existent'), 'stop');
}
db('content')->where(['contentid' => $id])->update('views = views + 1');
$this->assign('item', $data);
$this->assign('catid', $catid);
$this->assign('config', $this->config);
$this->assign('template', $template);
$this->display($template);
}
}