168 lines
5.3 KiB
PHP
168 lines
5.3 KiB
PHP
<?php
|
|
namespace Legu\Controller;
|
|
|
|
use Common\Controller\AdminbaseController;
|
|
|
|
class AdminController extends AdminbaseController {
|
|
|
|
protected $posts_model;
|
|
|
|
function _initialize() {
|
|
parent::_initialize();
|
|
$this->posts_model = D("Legu/News");
|
|
}
|
|
|
|
// 后台文章管理列表
|
|
public function index(){
|
|
$this->_lists(array("status"=>array('neq',3)));
|
|
$this->display();
|
|
}
|
|
|
|
|
|
/**
|
|
* 文章列表处理方法,根据不同条件显示不同的列表
|
|
* @param array $where 查询条件
|
|
*/
|
|
private function _lists($where=array()){
|
|
|
|
$type=I('request.type');
|
|
if(!empty($type)){
|
|
$where['type']=$type;
|
|
}
|
|
$start_time=I('request.start_time');
|
|
if(!empty($start_time)){
|
|
$where['date']=array(
|
|
array('EGT',$start_time)
|
|
);
|
|
}
|
|
|
|
$end_time=I('request.end_time');
|
|
if(!empty($end_time)){
|
|
if(empty($where['date'])){
|
|
$where['date']=array();
|
|
}
|
|
array_push($where['date'], array('ELT',$end_time));
|
|
}
|
|
$count=$this->posts_model->where($where)->count();
|
|
$page = $this->page($count, 20);
|
|
$lists=$this->posts_model->where($where)->select();
|
|
$this->assign("page", $page->show('Admin'));
|
|
$this->assign("formget",array_merge($_GET,$_POST));
|
|
$this->assign("posts",$lists);
|
|
}
|
|
|
|
// 文章添加
|
|
public function add(){
|
|
$this->display();
|
|
}
|
|
|
|
// 文章添加提交
|
|
public function add_post(){
|
|
if (IS_POST) {
|
|
if(!empty($_POST['photos_alt']) && !empty($_POST['photos_url'])){
|
|
foreach ($_POST['photos_url'] as $key=>$url){
|
|
$photourl=sp_asset_relative_url($url);
|
|
$_POST['smeta']['photo'][]=array("url"=>$photourl,"alt"=>$_POST['photos_alt'][$key]);
|
|
}
|
|
}
|
|
$_POST['smeta']['thumb'] = sp_asset_relative_url($_POST['smeta']['thumb']);
|
|
|
|
$article=I("post.post");
|
|
$article['smeta']=json_encode($_POST['smeta']);
|
|
$article['content']=htmlspecialchars_decode($article['content']);
|
|
$result=$this->posts_model->add($article);
|
|
if ($result) {
|
|
|
|
$this->success("添加成功!");
|
|
} else {
|
|
$this->error("添加失败!");
|
|
}
|
|
}
|
|
}
|
|
|
|
// 文章编辑
|
|
public function edit(){
|
|
$id= I("get.id",0,'intval');
|
|
$post=$this->posts_model->where("id=$id")->find();
|
|
$this->assign("post",$post);
|
|
$this->assign("smeta",json_decode($post['smeta'],true));
|
|
$this->display();
|
|
}
|
|
|
|
// 文章编辑提交
|
|
public function edit_post(){
|
|
if (IS_POST) {
|
|
if(!empty($_POST['photos_alt']) && !empty($_POST['photos_url'])){
|
|
foreach ($_POST['photos_url'] as $key=>$url){
|
|
$photourl=sp_asset_relative_url($url);
|
|
$_POST['smeta']['photo'][]=array("url"=>$photourl,"alt"=>$_POST['photos_alt'][$key]);
|
|
}
|
|
}
|
|
$_POST['smeta']['thumb'] = sp_asset_relative_url($_POST['smeta']['thumb']);
|
|
|
|
$article=I("post.post");
|
|
$article['smeta']=json_encode($_POST['smeta']);
|
|
$article['content']=htmlspecialchars_decode($article['content']);
|
|
$result=$this->posts_model->save($article);
|
|
if ($result!==false) {
|
|
$this->success("保存成功!");
|
|
} else {
|
|
$this->error("保存失败!");
|
|
}
|
|
}
|
|
}
|
|
|
|
// 文章删除
|
|
public function delete(){
|
|
if(isset($_GET['id'])){
|
|
$id = I("get.id",0,'intval');
|
|
if ($this->posts_model->where(array('id'=>$id))->save(array('status'=>3)) !==false) {
|
|
$this->success("删除成功!");
|
|
} else {
|
|
$this->error("删除失败!");
|
|
}
|
|
}
|
|
|
|
if(isset($_POST['ids'])){
|
|
$ids = I('post.ids/a');
|
|
|
|
if ($this->posts_model->where(array('id'=>array('in',$ids)))->save(array('post_status'=>3))!==false) {
|
|
$this->success("删除成功!");
|
|
} else {
|
|
$this->error("删除失败!");
|
|
}
|
|
}
|
|
}
|
|
|
|
// 文章置顶
|
|
public function top(){
|
|
if(isset($_POST['ids']) && $_GET["top"]){
|
|
$ids = I('post.ids/a');
|
|
|
|
if ( $this->posts_model->where(array('id'=>array('in',$ids)))->save(array('istop'=>1))!==false) {
|
|
$this->success("置顶成功!");
|
|
} else {
|
|
$this->error("置顶失败!");
|
|
}
|
|
}
|
|
if(isset($_POST['ids']) && $_GET["untop"]){
|
|
$ids = I('post.ids/a');
|
|
|
|
if ( $this->posts_model->where(array('id'=>array('in',$ids)))->save(array('istop'=>0))!==false) {
|
|
$this->success("取消置顶成功!");
|
|
} else {
|
|
$this->error("取消置顶失败!");
|
|
}
|
|
}
|
|
}
|
|
|
|
// 文章排序
|
|
public function listorders() {
|
|
$status = parent::_listorders($this->term_relationships_model);
|
|
if ($status) {
|
|
$this->success("排序更新成功!");
|
|
} else {
|
|
$this->error("排序更新失败!");
|
|
}
|
|
}
|
|
} |