#308 增加了数据新闻发布功能

This commit is contained in:
Li Jianxuan 2012-03-23 07:39:52 +00:00
parent f43f91275f
commit 66cee6c625
1 changed files with 113 additions and 87 deletions

View File

@ -1191,6 +1191,12 @@ class AuthorController extends Zend_Controller_Action
$u_id = $user->id; $u_id = $user->id;
} }
//新闻列表
if(empty($ac) || $ac=="list")
{
}
//新闻发布 //新闻发布
if($ac == "add") if($ac == "add")
{ {
@ -1200,6 +1206,7 @@ class AuthorController extends Zend_Controller_Action
//新闻发布的ajax动作 //新闻发布的ajax动作
if($ac =="addnews") if($ac =="addnews")
{ {
try{
$this->_helper->layout->disableLayout(); $this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender(); $this->_helper->viewRenderer->setNoRender();
@ -1222,7 +1229,7 @@ class AuthorController extends Zend_Controller_Action
$msg = array(); $msg = array();
// 合法性判断 // 合法性判断
if(mb_strlen($data['title'],"utf-8")<=6) if(mb_strlen($data['title'],"utf-8")<3)
{ {
$msg['status'] = 0; $msg['status'] = 0;
$msg['error'] = '标题太短,请重新填写'; $msg['error'] = '标题太短,请重新填写';
@ -1230,7 +1237,7 @@ class AuthorController extends Zend_Controller_Action
return true; return true;
} }
if(mb_strlen($data['title'],"utf-8")>=60) if(mb_strlen($data['title'],"utf-8")>60)
{ {
$msg['status'] = 0; $msg['status'] = 0;
$msg['error'] = '标题太长,请重新填写'; $msg['error'] = '标题太长,请重新填写';
@ -1238,7 +1245,7 @@ class AuthorController extends Zend_Controller_Action
return true; return true;
} }
if(mb_strlen($data['keyword'],"utf-8")<=4) if(mb_strlen($data['keyword'],"utf-8")<4)
{ {
$msg['status'] = 0; $msg['status'] = 0;
$msg['error'] = '关键词太短,请重新填写'; $msg['error'] = '关键词太短,请重新填写';
@ -1246,7 +1253,7 @@ class AuthorController extends Zend_Controller_Action
return true; return true;
} }
if(mb_strlen($data['keyword'],"utf-8")>=40) if(mb_strlen($data['keyword'],"utf-8")>40)
{ {
$msg['status'] = 0; $msg['status'] = 0;
$msg['error'] = '关键词太长,请重新填写'; $msg['error'] = '关键词太长,请重新填写';
@ -1263,7 +1270,8 @@ class AuthorController extends Zend_Controller_Action
} }
//获得描述 //获得描述
$data['description'] = mb_substr(preg_replace("/<(.*)>.*<\/\1>|<(.*) \/>/","",$data['body']),0,450,"UTF-8"); //删除段落及html标记
$data['description'] = mb_substr(preg_replace(array("/<(.*)>|<(.*) \/>/i","/\s/i"),array(""," "),$data['body']),0,450,"UTF-8");
//默认填充数据 //默认填充数据
$data['source'] = "西部数据中心"; $data['source'] = "西部数据中心";
@ -1274,20 +1282,38 @@ class AuthorController extends Zend_Controller_Action
(userid,title,keywords,description,image,source,ts_publish,is_pub,body) (userid,title,keywords,description,image,source,ts_publish,is_pub,body)
VALUES VALUES
(?,?,?,?,?,?,?,?,?) (?,?,?,?,?,?,?,?,?)
"; ";
$sth = $this->db->prepare($sql); $sth = $this->db->prepare($sql);
$sth -> execute(array($data['userid'],$data['title'],$data['keyword'],$data['description'],'',$data['source'],'now()',1,$data['body'])); $ex = $sth -> execute(array($data['userid'],$data['title'],$data['keyword'],$data['description'],'',$data['source'],'now()',1,$data['body']));
if($ex)
{
$msg['status'] = 1; $msg['status'] = 1;
$msg['outstring'] = "新闻添加成功"; $msg['outstring'] = "新闻添加成功";
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg)); $this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true; return true;
}else{
$msg['status'] = 0;
$msg['error'] = "新闻添加失败,请重试";
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
}catch(Exception $e){
if($this->debug==0)
{
$msg['status'] = 0;
$msg['error'] = "新闻添加失败,请重试";
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}else{
$msg['status'] = 0;
$msg['error'] = "新闻添加失败,请重试:".$e->getMessage();
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
}
} }