提交 d78575eb 编写于 作者: huangxuan258's avatar huangxuan258

修复上次提交新增url栏目自定义功能覆盖错误,修复编辑问题出现html问题

上级 eb1a8638
<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );
class Admin_category extends ADMIN_Controller {
function __construct() {
parent::__construct ();
$this->load->model ( 'category_model' );
}
function index($_message = '') {
$message = $_message;
$category ['grade'] = $pid = 0;
$tcategorylist = $this->category_model->list_by_pid ( $pid );
$categorylist = array ();
foreach ( $tcategorylist as $cat ) {
if ($cat ['isshowindex'] == null || $cat ['isshowindex'] == 0) {
$cat ['isshowindex'] = "首页显示";
} else {
$cat ['isshowindex'] = "首页不显示";
}
if ($cat ['isusearticle'] == null || $cat ['isusearticle'] == 0) {
$cat ['isusearticle'] = "不应用到文章发布";
} else {
$cat ['isusearticle'] = "应用到文章发布";
}
if ($cat ['isuseask'] == null || $cat ['isuseask'] == 0) {
$cat ['isuseask'] = "不应用到问答发布";
} else {
$cat ['isuseask'] = "应用到问答发布";
}
if (! isset ( $cat ['onlybackground'] ) || $cat ['onlybackground'] == 0) {
$cat ['onlybackground'] = "前端可发布";
} else {
$cat ['onlybackground'] = "只后台发布";
}
$categorylist [] = $cat;
}
include template ( 'categorylist', 'admin' );
}
function updateCatTmplate() {
// $tmpname='catlist_topic';//htmlspecialchars( $this->input->post ('tmpname'));
$id = intval ( htmlspecialchars ( $this->input->post ( 'id' ) ) );
$tmpname = htmlspecialchars ( $this->input->post ( 'tmpname' ) );
$cat = $this->category_model->get ( $id );
if ($cat ['template'] != null && $cat ['template'] != '') {
$tmpname = '';
}
$this->category_model->update_by_id_tmplate ( $id, $tmpname );
cleardir ( FCPATH . '/data/cache' ); // 清除缓存文件
echo "1";
}
// 更新首页是否显示分类
function updatecatbyindex() {
if (null !== $this->input->post ( 'cid' )) {
$cids = implode ( ",", $this->input->post ( 'cid' ) );
$pid = intval ( $this->input->post ( 'hiddencid' ) );
foreach ( $this->input->post ( 'cid' ) as $val ) {
$type = 'isshowindex';
$category = $this->category [$val];
// 状态值
$typevalue = $category ['isshowindex'] == 1 ? 0 : 1;
$this->category_model->update_by_type ( $val, $type, $typevalue );
}
cleardir ( FCPATH . '/data/cache' ); // 清除缓存文件
$this->index ( "设置成功" );
}
}
// 更新问答是否显示分类
function updatecatbywenda() {
if (null !== $this->input->post ( 'cid' )) {
$cids = implode ( ",", $this->input->post ( 'cid' ) );
$pid = intval ( $this->input->post ( 'hiddencid' ) );
foreach ( $this->input->post ( 'cid' ) as $val ) {
$type = 'isuseask';
$category = $this->category [$val];
// 状态值
$typevalue = $category ['isuseask'] == 1 ? 0 : 1;
$this->category_model->update_by_type ( $val, $type, $typevalue );
}
cleardir ( FCPATH . '/data/cache' ); // 清除缓存文件
$this->index ( "设置成功" );
}
}
function updatecatbyorder() {
if (null !== $this->input->post ( 'cid' )) {
$cids = implode ( ",", $this->input->post ( 'cid' ) );
$pid = intval ( $this->input->post ( 'hiddencid' ) );
$orders = $this->input->post ( 'corder' );
// var_dump($orders);exit();
foreach ( $this->input->post ( 'cid' ) as $val ) {
// echo $val.'--'.$orders[$i].'--'.$i."<br>";
$orderval = $this->input->post ( 'corder' . $val );
$this->category_model->order_category ( intval ( $val ), intval ( $orderval ) );
}
// exit();
cleardir ( FCPATH . '/data/cache' ); // 清除缓存文件
$this->message ( "设置成功" );
}
}
// 更新问答是否显示分类
function updatecatbywenzhang() {
if (null !== $this->input->post ( 'cid' )) {
$cids = implode ( ",", $this->input->post ( 'cid' ) );
$pid = intval ( $this->input->post ( 'hiddencid' ) );
foreach ( $this->input->post ( 'cid' ) as $val ) {
$type = 'isusearticle';
$category = $this->category [$val];
// 状态值
$typevalue = $category ['isusearticle'] == 1 ? 0 : 1;
$this->category_model->update_by_type ( $val, $type, $typevalue );
}
cleardir ( FCPATH . '/data/cache' ); // 清除缓存文件
$this->message ( "设置成功" );
}
}
// 更新问答是否只在后台发布分类
function updatecatbybackground() {
if (null !== $this->input->post ( 'cid' )) {
$cids = implode ( ",", $this->input->post ( 'cid' ) );
$pid = intval ( $this->input->post ( 'hiddencid' ) );
foreach ( $this->input->post ( 'cid' ) as $val ) {
$type = 'onlybackground';
$category = $this->category [$val];
// 状态值
$typevalue = $category ['onlybackground'] == 1 ? 0 : 1;
$this->category_model->update_by_type ( $val, $type, $typevalue );
}
cleardir ( FCPATH . '/data/cache' ); // 清除缓存文件
$this->message ( "设置成功" );
}
}
function updatecatbytype() {
$cid = intval ( $this->input->post ( 'cid' ) );
// type 1:是否首页显示,2:是否应用问答,3:是否应用文章
$type = intval ( $this->input->post ( 'type' ) );
// 状态值
$typevalue = intval ( $this->input->post ( 'typevalue' ) );
$typevalue = $typevalue == 1 ? 0 : 1;
switch ($type) {
case 1 :
$type = 'isshowindex';
break;
case 2 :
$type = 'isuseask';
break;
case 3 :
$type = 'isusearticle';
break;
}
$this->category_model->update_by_type ( $cid, $type, $typevalue );
cleardir ( FCPATH . '/data/cache' ); // 清除缓存文件
echo "1";
}
function postadd() {
if (null !== $this->input->post ( 'submit' )) {
$pid = 0;
$category1 = $this->input->post ( 'category1' );
$category2 = $this->input->post ( 'category2' );
if (isset ( $category2 ) && trim ( $category2 ) != '') {
$pid = $category2;
} else if (isset ( $category1 ) && trim ( $category1 ) != '') {
$pid = $category1;
}
$lines = explode ( "\n", $this->input->post ( 'categorys' ) );
$this->category_model->add ( $lines, $pid );
cleardir ( FCPATH . '/data/cache' ); // 清除缓存文件
exit ( '1' );
} else {
exit ( '0' );
}
}
function add() {
$id = intval ( $this->uri->segment ( 3 ) );
$selectedarray = array ();
if ($id) {
$category = $this->category [$id];
$item = $category;
for($grade = $category ['grade']; $grade > 0; $grade --) {
$selectedarray [] = $item ['id'];
$item ['pid'] && $item = $this->category [$item ['pid']];
}
}
if (isset ( $selectedarray ) && count ( $selectedarray ) > 0) {
switch (count ( $selectedarray )) {
case 1 :
list ( $category1 ) = array_reverse ( $selectedarray );
break;
case 2 :
list ( $category1, $category2 ) = array_reverse ( $selectedarray );
break;
case 3 :
list ( $category1, $category2, $category3 ) = array_reverse ( $selectedarray );
break;
}
}
$categoryjs = $this->category_model->get_js ();
include template ( 'addcategory', 'admin' );
}
// 获取分类描述
function getmiaosu() {
$id = intval ( htmlspecialchars ( $this->input->post ( 'id' ) ) );
$category = $this->category [$id];
echo $category ['miaosu'];
exit ();
}
function editalias() {
$alias = htmlspecialchars ( $this->input->post ( 'alias' ) );
$id = intval ( htmlspecialchars ( $this->input->post ( 'id' ) ) );
$this->category_model->update_by_id_alias ( $id, $alias );
cleardir ( FCPATH . '/data/cache' ); // 清除缓存文件
echo "更新成功";
}
function editmiaosu() {
$miaosu = $this->input->post ( 'miaosu' );
$id = intval ( $this->input->post ( 'id' ) );
// runlog('miaosu.txt', $id.'----.'.$miaosu);
$this->category_model->update_by_id_miaosu ( $id, $miaosu );
cleardir ( FCPATH . '/data/cache' ); // 清除缓存文件
echo "更新成功";
}
function edit() {
$id = intval ( $this->uri->segment ( 3 ) ) == 0 ? intval ( $this->input->post ( 'id' ) ) : intval ( $this->uri->segment ( 3 ) );
if (null !== $this->input->post ( 'submit' )) {
$name = trim ( $this->input->post ( 'name' ) ); // 分类名称
$aliasname = trim ( $this->input->post ( 'aliasname' ) ); // 分类别名
$edit_miaosu = trim ( $this->input->post ( 'edit_miaosu' ) ); // 分类描述
$s_tmplist = trim ( $this->input->post ( 's_tmplist' ) ); // 文章分类模板名字
$s_articletmplist = trim ( $this->input->post ( 's_articletmplist' ) ); // 文章详情模板名字
$dir= trim ( $this->input->post ( 'dir' ) ); // 分类目录名称
$categorydir = '';
$categorydir = empty($dir) ? '':$dir;
$cid = 0;
$category1 = $this->input->post ( 'category1' );
$category2 = $this->input->post ( 'category2' );
$category3 = $this->input->post ( 'category3' );
if ($category3) {
$cid = $category3;
} else if ($category2) {
$cid = $category2;
} else if ($category1) {
$cid = $category1;
}
if ($cid > 0) {
$category = $this->category [$cid]; // 得到分类信息
} else {
$category = $this->category [$id]; // 得到分类信息
}
if ($_FILES ["catimage"] ['name'] != '') {
$uid = $id;
$avatardir = "/data/category/";
$extname = extname ( $_FILES ["catimage"] ["name"] );
if (! isimage ( $extname ))
$this->message ( "图片扩展名不正确!", 'admin_category/editimg' );
$upload_tmp_file = FCPATH . '/data/tmp/cat_' . $uid . '.' . $extname;
$uid = abs ( $uid );
$uid = sprintf ( "%09d", $uid );
$dir1 = $avatardir . substr ( $uid, 0, 3 );
$dir2 = $dir1 . '/' . substr ( $uid, 3, 2 );
$dir3 = $dir2 . '/' . substr ( $uid, 5, 2 );
(! is_dir ( FCPATH . $dir1 )) && forcemkdir ( FCPATH . $dir1 );
(! is_dir ( FCPATH . $dir2 )) && forcemkdir ( FCPATH . $dir2 );
(! is_dir ( FCPATH . $dir3 )) && forcemkdir ( FCPATH . $dir3 );
$bigimg = $dir3 . "/big_" . $uid . '.' . $extname;
$smallimg = $dir3 . "/small_" . $uid . '.' . $extname;
unlink ( FCPATH . $dir3 . "/big_" . $uid . '.jpg' );
unlink ( FCPATH . $dir3 . "/big_" . $uid . '.png' );
unlink ( FCPATH . "/small_" . $uid . '.png' );
unlink ( FCPATH . "/small_" . $uid . '.jpg' );
if (move_uploaded_file ( $_FILES ["catimage"] ["tmp_name"], $upload_tmp_file )) {
$avatar_dir = glob ( FCPATH . $dir3 . "/small_{$uid}.*" );
foreach ( $avatar_dir as $imgfile ) {
if (strtolower ( $extname ) != extname ( $imgfile ))
unlink ( $imgfile );
}
image_resize ( $upload_tmp_file, FCPATH . $bigimg, 195, 195, 1 );
image_resize ( $upload_tmp_file, FCPATH . $smallimg, 32, 32, 1 );
}
}
$data=array(
'name'=>$name,
'dir'=>$categorydir,
'alias'=>$aliasname,
'miaosu'=>$edit_miaosu,
'template'=>$s_tmplist,
'articletemplate'=>$s_articletmplist,
);
$this->db->where(array('id'=>$id))->update('category',$data);
//$this->category_model->update_by_id ( $id, $name, $categorydir, $category ['pid'], $aliasname, $edit_miaosu, $s_tmplist );
cleardir ( FCPATH . '/data/cache' ); // 清除缓存文件
$pid = $category ['pid'];
if ($pid != 0) {
$this->input->post ( 'cid' ) ? $this->myview ( $this->input->post ( 'cid' ) ) : $this->message ( "操作成功", "admin_category/myview/$pid" );
} else {
$this->input->post ( 'cid' ) ? $this->myview ( $this->input->post ( 'cid' ) ) : $this->message ( "操作成功", "admin_category" );
}
} else {
$category = $this->category_model->get ( $id );
$item = $category;
$selectedarray = array ();
for($grade = $category ['grade']; $grade > 1; $grade --) {
$selectedarray [] = $item ['pid'];
$item = $this->category [$item ['pid']];
}
if (isset ( $selectedarray ) && count ( $selectedarray ) > 0) {
switch (count ( $selectedarray )) {
case 1 :
list ( $category1 ) = array_reverse ( $selectedarray );
break;
case 2 :
list ( $category1, $category2 ) = array_reverse ( $selectedarray );
break;
case 3 :
list ( $category1, $category2, $category3 ) = array_reverse ( $selectedarray );
break;
}
}
$categoryjs = $this->category_model->get_js ();
$file_dir = APPPATH . "views/" . $this->setting ['tpl_dir'];
$files = scandir ( $file_dir );
$catlistfiles = array ();
$articlelistfiles = array ();
foreach ( $files as $file ) {
if (strstr ( $file, 'catlist' )) {
array_push ( $catlistfiles, $file );
}
if (strstr ( $file, 'topicone' )) {
array_push ( $articlelistfiles, $file );
}
}
include template ( 'editcategory', 'admin' );
}
}
// 后台分类管理查看一个分类
function myview($cid = 0, $msg = '') {
$cid = $cid ? $cid : intval ( $this->uri->segment ( 3 ) );
$navlist = $this->category_model->get_navigation ( $cid ); // 获取导航
if (isset ( $this->category [$cid] )) {
$category = $this->category [$cid];
} else {
$category = null;
}
$categorylist = $this->category_model->list_by_cid ( $cid, $category ['pid'] ); // 获取子分类
$pid = $cid;
$msg && $message = $msg;
include template ( 'categorylist', 'admin' );
}
// 删除分类
function remove() {
if (null !== $this->input->post ( 'cid' )) {
$cids = implode ( ",", $this->input->post ( 'cid' ) );
$pid = intval ( $this->input->post ( 'hiddencid' ) );
$this->category_model->remove ( $cids );
$this->message ( '分类删除成功!' );
}
}
/* 后台分类排序 */
function reorder() {
$orders = explode ( ",", $this->input->post ( 'order' ) );
foreach ( $orders as $order => $cid ) {
$this->category_model->order_category ( intval ( $cid ), $order );
}
$this->cache->remove ( 'category' );
}
// 修改封面图
function editimg() {
if (isset ( $_FILES ["catimage"] )) {
$uid = intval ( $this->input->post ( 'catid' ) );
$avatardir = "/data/category/";
$extname = extname ( $_FILES ["catimage"] ["name"] );
if (! isimage ( $extname ))
$this->message ( "图片扩展名不正确!", 'admin_category/editimg' );
$upload_tmp_file = FCPATH . '/data/tmp/cat_' . $uid . '.' . $extname;
$uid = abs ( $uid );
$uid = sprintf ( "%09d", $uid );
$dir1 = $avatardir . substr ( $uid, 0, 3 );
$dir2 = $dir1 . '/' . substr ( $uid, 3, 2 );
$dir3 = $dir2 . '/' . substr ( $uid, 5, 2 );
(! is_dir ( FCPATH . $dir1 )) && forcemkdir ( FCPATH . $dir1 );
(! is_dir ( FCPATH . $dir2 )) && forcemkdir ( FCPATH . $dir2 );
(! is_dir ( FCPATH . $dir3 )) && forcemkdir ( FCPATH . $dir3 );
$bigimg = $dir3 . "/big_" . $uid . '.' . $extname;
$smallimg = $dir3 . "/small_" . $uid . '.' . $extname;
if (move_uploaded_file ( $_FILES ["catimage"] ["tmp_name"], $upload_tmp_file )) {
$avatar_dir = glob ( FCPATH . $dir3 . "/small_{$uid}.*" );
foreach ( $avatar_dir as $imgfile ) {
if (strtolower ( $extname ) != extname ( $imgfile ))
unlink ( $imgfile );
}
image_resize ( $upload_tmp_file, FCPATH . $bigimg, 195, 195, 1 );
image_resize ( $upload_tmp_file, FCPATH . $smallimg, 32, 32, 1 );
}
}
header ( "Location:" . SITE_URL . 'index.php?admin_category.html' );
}
}
?>
\ No newline at end of file
<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );
class Category extends CI_Controller {
var $whitelist;
function __construct() {
$this->whitelist = "attentto,search,viewtopic,clist";
parent::__construct ();
$this->load->model ( 'category_model' );
$this->load->model ( 'question_model' );
$this->load->model ( "topic_model" );
}
function viewtopic() {
$navtitle = "热门专题";
$status = null!== $this->uri->segment ( 3 ) ? $this->uri->segment ( 3 ) : 'hot';
@$page = max ( 1, intval ( $this->uri->segment ( 4 ) ) );
$pagesize = 21;
$startindex = ($page - 1) * $pagesize;
$where = "and grade=1 ";
switch ($status) {
case 'question' :
$where=$where." and isuseask=1 ";
break;
}
$rownum = returnarraynum ( $this->db->query ( getwheresql ( 'category', " 1=1 $where ", $this->db->dbprefix ) )->row_array () );
//$userarticle = $this->topic_model->get_user_articles ( 0, 5 );
$catlist = $this->category_model->listtopic ( $status, $startindex, $pagesize );
$departstr = page ( $rownum, $pagesize, $page, "category/viewtopic/$status" );
include template ( 'category_all' );
}
function view() {
$this->load->model ( "expert_model" );
if(intval ( $this->uri->rsegments[3] )==0){
$catdir=addslashes(strip_tags($this->uri->rsegments[3]));//获取目录
$_cat=$this->db->get_where('category',array('dir'=>$catdir))->row_array();
if($_cat){
$cid=$_cat['id'];
}else{
show_404();
}
}else{
$cid = intval ( $this->uri->rsegments[3] ) ? intval ( $this->uri->rsegments[3]) : 'all';
}
$status = null!== $this->uri->rsegments[4] ? $this->uri->rsegments[4]: 'all';
@$page = max ( 1, intval ( $this->uri->rsegments[5]) );
$pagesize = $this->setting ['list_default'];
$startindex = ($page - 1) * $pagesize; //每页面显示$pagesize条
if ($cid != 'all') {
$category = $this->category [$cid]; //得到分类信息
$navtitle = $category ['name'];
$cfield = 'cid' . $category ['grade'];
} else {
$category = $this->category;
$navtitle = '全部分类';
$cfield = '';
$category ['pid'] = 0;
}
if ($category ['name'] == '') {
header ( 'HTTP/1.1 404 Not Found' );
header ( "status: 404 Not Found" );
echo '<!DOCTYPE html><html><head><meta charset=utf-8 /><title>404-您访问的页面不存在</title>';
echo "<style>body { background-color: #ECECEC; font-family: 'Open Sans', sans-serif;font-size: 14px; color: #3c3c3c;}";
echo ".nullpage p:first-child {text-align: center; font-size: 150px; font-weight: bold; line-height: 100px; letter-spacing: 5px; color: #fff;}";
echo ".nullpage p:not(:first-child) {text-align: center;color: #666;";
echo "font-family: cursive;font-size: 20px;text-shadow: 0 1px 0 #fff; letter-spacing: 1px;line-height: 2em;margin-top: -50px;}";
echo ".nullpage p a{margin-left:10px;font-size:20px;}";
echo '</style></head><body> <div class="nullpage"><p><span>4</span><span>0</span><span>4</span></p><p>抱歉,话题不存在!⊂((δ⊥δ))⊃<a href="/">返回主页</a></p></div></body></html>';
exit ();
}
$statusword = "";
switch ($status) {
case '1' :
$statusword = '待解决';
break;
case '2' :
$statusword = '已解决';
break;
case '4' :
$statusword = '高悬赏';
break;
case '6' :
$statusword = '推荐';
break;
case 'all' :
$statusword = '全部';
break;
}
$is_followed = $this->category_model->is_followed ( $cid, $this->user ['uid'] );
$rownum = $this->question_model->rownum_by_cfield_cvalue_status ( $cfield, $cid, $status ); //获取总的记录数
$questionlist = $this->question_model->list_by_cfield_cvalue_status ( $cfield, $cid, $status, $startindex, $pagesize ); //问题列表数据
$topiclist = $this->topic_model->get_bycatid ( $cid, 0, 8 );
$followerlist = $this->category_model->get_followers ( $cid, 0, 8 ); //获取导航
if($catdir){
$departstr = page ( $rownum, $pagesize, $page, "category/view/$catdir/$status" ); //得到分页字符串
}else{
$departstr = page ( $rownum, $pagesize, $page, "category/view/$cid/$status" ); //得到分页字符串
}
$navlist = $this->category_model->get_navigation ( $cid ); //获取导航
$sublist = $this->category_model->list_by_cid_pid ( $cid, $category ['pid'] ); //获取子分类
$expertlist = $this->expert_model->get_by_cid ( $cid ); //分类专家
$cids = array ();
//如果这是顶级分类
if ($category ['pid'] == 0) {
//获取当前分类下的子分类--二级分类
$catlist = $this->category_model->list_by_pid ( $cid );
//把顶级分类id写入数组
array_push ( $cids, $cid );
//循环获取顶级分类下的子分类
foreach ( $catlist as $key => $val ) {
//子分类写入数组
array_push ( $cids, $val ['id'] );
//获取子分类下的三级分类
$catlist1 = $this->category_model->list_by_pid ( $val ['id'] );
foreach ( $catlist1 as $key1 => $val1 ) {
array_push ( $cids, $val1 ['id'] );
}
}
} else {
//如果不是顶级分类,先将分类id写入数组
array_push ( $cids, $cid );
//获取该分类下的父亲级别的分类
// $catlist=$this->category_model->list_by_pid($catmodel['pid']);
//获取该分类下的子分类
$catlist = $this->category_model->list_by_pid ( $cid );
if ($catlist) {
//遍历子分类写入数组
foreach ( $catlist as $key => $val ) {
array_push ( $cids, $val ['id'] );
}
}
// var_dump($catmodel);exit();
}
$cidsp = implode ( ',', $cids );
$trownum = returnarraynum ( $this->db->query ( getwheresql ( 'topic', " articleclassid in($cidsp) ", $this->db->dbprefix ) )->row_array () );
/* SEO */
if ($category ['alias']) {
$navtitle = $category ['alias'];
}
$seo_keywords = $navtitle;
$seo_description = $this->setting ['site_name'] . $navtitle . '频道,提供' . $navtitle . '相关问题及答案,' . $statusword . '问题,第' . $page . "页。";
;
/* SEO */
if ($category ['miaosu']) {
$seo_description =strip_tags( $category ['miaosu']);
}
if ($this->setting ['seo_category_title']) {
$seo_title = str_replace ( "{wzmc}", $this->setting ['site_name'], $this->setting ['seo_category_title'] );
$seo_title = str_replace ( "{flmc}", $navtitle, $seo_title );
$seo_title = $seo_title . '_' . $statusword . '_第' . $page . "页";
} else {
$navtitle = $navtitle . '_' . $statusword . '_第' . $page . "页";
}
if ($this->setting ['seo_category_description']) {
$seo_description = str_replace ( "{wzmc}", $this->setting ['site_name'], $this->setting ['seo_category_description'] );
$seo_description = str_replace ( "{flmc}", $navtitle, $seo_description );
}
if ($this->setting ['seo_category_keywords']) {
$seo_keywords = str_replace ( "{wzmc}", $this->setting ['site_name'], $this->setting ['seo_category_keywords'] );
$seo_keywords = str_replace ( "{flmc}", $navtitle, $seo_keywords );
}
$category['bigimage'] = get_cid_dir ( $category['id'], 'big' );
//相关分类标签
$this->load->model ( "tag_model" );
$relativetags = $this->tag_model->gettaglistbycid ( $cid );
include template ( 'category' );
}
function search() {
$hidefooter = 'hidefooter';
$type = "category";
$this->load->helper ( 'security' );
if ($_GET ['word']) {
$word = xss_clean ( $_GET ['word'] );
} else {
$word = xss_clean ( $_GET [0] );
}
$word = str_replace ( array ("\\", "'", " ", "/", "&" ), "", $word );
$word = strip_tags ( $word );
$word = htmlspecialchars ( $word );
if (isset ( $_SERVER ['HTTP_X_REWRITE_URL'] )&&$_GET ['word']==null) {
if (function_exists ( "iconv" ) && $this->uri->rsegments [3] != null) {
$word = iconv ( "GB2312", "UTF-8//IGNORE",$this->uri->rsegments [3] );
}
}else if(isset($_SERVER['ORIG_PATH_INFO'])&&$_GET ['word']==null) {
$word = iconv ( "GB2312", "UTF-8//IGNORE",$this->uri->rsegments [3] );
}
$word = taddslashes ( $word, 1 );
(! $word) && $this->message ( "搜索关键词不能为空!", 'BACK' );
$navtitle = $word;
@$page = max ( 1, intval ( $this->uri->rsegments [4] ) );
$pagesize = $this->setting ['list_default'];
$startindex = ($page - 1) * $pagesize;
$seo_description = $word;
$seo_keywords = $word;
$word=addslashes($word);
$rownum = returnarraynum ( $this->db->query ( getwheresql ( 'category', " `name` like '%$word%' ", $this->db->dbprefix ) )->row_array () );
$catlist = $this->category_model->list_by_name ( $word, $startindex, $pagesize );
$departstr = page ( $rownum, $pagesize, $page, "category/search/$word" );
include template ( 'serach_category' );
}
function clist() {
$status = null!== $this->uri->segment ( 3 ) ? $this->uri->segment ( 3 ) : 'all';
$navtitle = $statustitle = $this->statusarray [$status];
@$page = max ( 1, intval ( $this->uri->segment ( 4 ) ) );
$pagesize = $this->setting ['list_default'];
$startindex = ($page - 1) * $pagesize; //每页面显示$pagesize条
$rownum = $this->question_model->rownum_by_cfield_cvalue_status ( '', 0, $status ); //获取总的记录数
$questionlist = $this->question_model->list_by_cfield_cvalue_status ( '', 0, $status, $startindex, $pagesize ); //问题列表数据
$departstr = page ( $rownum, $pagesize, $page, "category/list/$status" ); //得到分页字符串
$metakeywords = $navtitle;
$metadescription = '问题列表' . $navtitle;
include template ( 'list' );
}
function recommend() {
$this->load ( 'topic' );
$navtitle = '专题列表';
@$page = max ( 1, intval ( $this->uri->segment ( 3 ) ) );
$pagesize = $this->setting ['list_default'];
$startindex = ($page - 1) * $pagesize;
$rownum = returnarraynum ( $this->db->query ( getwheresql ( 'topic', ' 1=1 ', $this->db->dbprefix ) )->row_array () );
;
$topiclist = $this->topic_model->get_list ( 2, $startindex, $pagesize );
$departstr = page ( $rownum, $pagesize, $page, "category/recommend" );
$metakeywords = $navtitle;
$metadescription = '精彩推荐列表';
include template ( 'recommendlist' );
}
function attentto() {
$cid = intval ( $this->input->post ( 'cid' ) );
if (! $cid) {
exit ( 'error' );
}
if ($this->user ['uid'] == 0) {
exit ( "-1" );
}
$is_followed = $this->category_model->is_followed ( $cid, $this->user ['uid'] );
if ($is_followed) {
$this->category_model->unfollow ( $cid, $this->user ['uid'] );
$this->load->model ( "doing_model" );
$this->doing_model->deletedoing ( $this->user ['uid'], 10, $cid );
} else {
$this->load->model ( "doing_model" );
$category = $this->category [$cid]; //得到分类信息
$this->doing_model->add ( $this->user ['uid'], $this->user ['username'], 10, $cid, $category ['name'] );
$this->category_model->follow ( $cid, $this->user ['uid'] );
}
exit ( 'ok' );
}
}
?>
\ No newline at end of file
此差异已折叠。
......@@ -230,8 +230,9 @@ class Admin_category extends ADMIN_Controller {
$edit_miaosu = trim ( $this->input->post ( 'edit_miaosu' ) ); // 分类描述
$s_tmplist = trim ( $this->input->post ( 's_tmplist' ) ); // 文章分类模板名字
$s_articletmplist = trim ( $this->input->post ( 's_articletmplist' ) ); // 文章详情模板名字
$dir= trim ( $this->input->post ( 'dir' ) ); // 分类目录名称
$categorydir = '';
$categorydir = empty($dir) ? '':$dir;
$cid = 0;
$category1 = $this->input->post ( 'category1' );
$category2 = $this->input->post ( 'category2' );
......
......@@ -10,7 +10,6 @@ class Category extends CI_Controller {
$this->load->model ( 'category_model' );
$this->load->model ( 'question_model' );
$this->load->model ( "topic_model" );
}
function viewtopic() {
......@@ -34,11 +33,22 @@ class Category extends CI_Controller {
$departstr = page ( $rownum, $pagesize, $page, "category/viewtopic/$status" );
include template ( 'category_all' );
}
//category/view/1/2/10
//cid,status,第几页?
function view() {
function view() {
$this->load->model ( "expert_model" );
$cid = intval ( $this->uri->rsegments[3] ) ? intval ( $this->uri->rsegments[3]) : 'all';
if(intval ( $this->uri->rsegments[3] )==0){
$catdir=addslashes(strip_tags($this->uri->rsegments[3]));//获取目录
$_cat=$this->db->get_where('category',array('dir'=>$catdir))->row_array();
if($_cat){
$cid=$_cat['id'];
}else{
show_404();
}
}else{
$cid = intval ( $this->uri->rsegments[3] ) ? intval ( $this->uri->rsegments[3]) : 'all';
}
$status = null!== $this->uri->rsegments[4] ? $this->uri->rsegments[4]: 'all';
@$page = max ( 1, intval ( $this->uri->rsegments[5]) );
$pagesize = $this->setting ['list_default'];
......@@ -90,7 +100,12 @@ class Category extends CI_Controller {
$questionlist = $this->question_model->list_by_cfield_cvalue_status ( $cfield, $cid, $status, $startindex, $pagesize ); //问题列表数据
$topiclist = $this->topic_model->get_bycatid ( $cid, 0, 8 );
$followerlist = $this->category_model->get_followers ( $cid, 0, 8 ); //获取导航
$departstr = page ( $rownum, $pagesize, $page, "category/view/$cid/$status" ); //得到分页字符串
if($catdir){
$departstr = page ( $rownum, $pagesize, $page, "category/view/$catdir/$status" ); //得到分页字符串
}else{
$departstr = page ( $rownum, $pagesize, $page, "category/view/$cid/$status" ); //得到分页字符串
}
$navlist = $this->category_model->get_navigation ( $cid ); //获取导航
$sublist = $this->category_model->list_by_cid_pid ( $cid, $category ['pid'] ); //获取子分类
$expertlist = $this->expert_model->get_by_cid ( $cid ); //分类专家
......
......@@ -2922,7 +2922,7 @@ class Question extends CI_Controller {
echo json_encode ( $message );
exit ();
}
$content = $this->input->post ( 'content', FALSE );
$content = $this->input->post ( 'content' );
// 更新问题详情
$tags = trim ( $this->input->post ( 'tags' ), ',' );
......@@ -2941,7 +2941,7 @@ class Question extends CI_Controller {
'cid1' => $cid1,
'cid2' => $cid2,
'cid3' => $cid3,
'description' => htmlspecialchars ( $content )
'description' => $content
);
$this->db->where ( array (
......
......@@ -696,7 +696,18 @@ exit();
include template ( 'topic' );
}
function catlist() {
$catid = intval ( $this->uri->rsegments [3] );
if(intval ( $this->uri->rsegments[3] )==0){
$catdir=addslashes(strip_tags($this->uri->rsegments[3]));//获取目录
$_cat=$this->db->get_where('category',array('dir'=>$catdir))->row_array();
if($_cat){
$catid=$_cat['id'];
}else{
show_404();
}
}else{
$catid = intval ( $this->uri->rsegments [3] );
}
//相关分类标签
$this->load->model ( "tag_model" );
$relativetags = $this->tag_model->gettaglistbycid ( $catid );
......@@ -735,7 +746,8 @@ exit();
// 获取该分类下的父亲级别的分类
// $catlist=$this->category_model->list_by_pid($catmodel['pid']);
if ($catmodel ['grade'] == 3) {
//$catlist = $this->category_model->list_by_pid ( $catmodel ['pid'] );
......@@ -752,9 +764,7 @@ exit();
array_push ( $cids, $val ['id'] );
}
}
}
// var_dump($catmodel);exit();
}
......@@ -773,7 +783,12 @@ exit();
$topiclist [$key] ['tags'] = $taglist;
}
$departstr = page ( $rownum, $pagesize, $page, "topic/catlist/$catid" );
if($catdir){
$departstr = page ( $rownum, $pagesize, $page, "topic/catlist/$catdir" );
}else{
$departstr = page ( $rownum, $pagesize, $page, "topic/catlist/$catid" );
}
/* SEO */
$seo_keywords = $navtitle;
......@@ -800,7 +815,7 @@ exit();
$seo_keywords = str_replace ( "{wzmc}", $this->setting ['site_name'], $this->setting ['seo_category_keywords'] );
$seo_keywords = str_replace ( "{flmc}", $navtitle, $seo_keywords );
}
// 如果分类模板没有为空,就应用新模板
if ($catmodel ['template'] == null || trim ( $catmodel ['template'] ) == '') {
include template ( 'catlist' );
......@@ -809,6 +824,7 @@ exit();
}
}
function convertUrlQuery($query) {
$queryParts = explode ( '&', $query );
$params = array ();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册