#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,94 +1206,114 @@ class AuthorController extends Zend_Controller_Action
//新闻发布的ajax动作 //新闻发布的ajax动作
if($ac =="addnews") if($ac =="addnews")
{ {
$this->_helper->layout->disableLayout(); try{
$this->_helper->viewRenderer->setNoRender(); $this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$data = array(); $data = array();
$data['title'] = $this->_request->getParam('title'); $data['title'] = $this->_request->getParam('title');
$data['keyword'] = $this->_request->getParam('keyword'); $data['keyword'] = $this->_request->getParam('keyword');
$data['body'] = $this->_request->getParam('body'); $data['body'] = $this->_request->getParam('body');
//对参数进行预处理 //对参数进行预处理
foreach($data as $k=>$v) foreach($data as $k=>$v)
{ {
$data[$k]=preg_replace("#<a([^>]*)>(.*)</a>#i","",$v); $data[$k]=preg_replace("#<a([^>]*)>(.*)</a>#i","",$v);
$data[$k]=preg_replace("#<script([^>]*)>(.*)</script>#i","",$v); $data[$k]=preg_replace("#<script([^>]*)>(.*)</script>#i","",$v);
$data[$k]=preg_replace("#<iframe([^>]*)>(.*)</iframe>#i","",$v); $data[$k]=preg_replace("#<iframe([^>]*)>(.*)</iframe>#i","",$v);
$data[$k]=str_replace("\"","",$v); $data[$k]=str_replace("\"","",$v);
$data[$k]=str_replace("\'","",$v); $data[$k]=str_replace("\'","",$v);
}
$msg = array();
// 合法性判断
if(mb_strlen($data['title'],"utf-8")<3)
{
$msg['status'] = 0;
$msg['error'] = '标题太短,请重新填写';
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
if(mb_strlen($data['title'],"utf-8")>60)
{
$msg['status'] = 0;
$msg['error'] = '标题太长,请重新填写';
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
if(mb_strlen($data['keyword'],"utf-8")<4)
{
$msg['status'] = 0;
$msg['error'] = '关键词太短,请重新填写';
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
if(mb_strlen($data['keyword'],"utf-8")>40)
{
$msg['status'] = 0;
$msg['error'] = '关键词太长,请重新填写';
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
if(mb_strlen($data['body'],"utf-8")<40)
{
$msg['status'] = 0;
$msg['error'] = '新闻内容太短,请重新填写';
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
//获得描述
//删除段落及html标记
$data['description'] = mb_substr(preg_replace(array("/<(.*)>|<(.*) \/>/i","/\s/i"),array(""," "),$data['body']),0,450,"UTF-8");
//默认填充数据
$data['source'] = "西部数据中心";
$data['typeid'] = 0;
$data['userid'] = $u_id;
$sql = "INSERT INTO news_archives
(userid,title,keywords,description,image,source,ts_publish,is_pub,body)
VALUES
(?,?,?,?,?,?,?,?,?)
";
$sth = $this->db->prepare($sql);
$ex = $sth -> execute(array($data['userid'],$data['title'],$data['keyword'],$data['description'],'',$data['source'],'now()',1,$data['body']));
if($ex)
{
$msg['status'] = 1;
$msg['outstring'] = "新闻添加成功";
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
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;
}
} }
$msg = array();
// 合法性判断
if(mb_strlen($data['title'],"utf-8")<=6)
{
$msg['status'] = 0;
$msg['error'] = '标题太短,请重新填写';
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
if(mb_strlen($data['title'],"utf-8")>=60)
{
$msg['status'] = 0;
$msg['error'] = '标题太长,请重新填写';
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
if(mb_strlen($data['keyword'],"utf-8")<=4)
{
$msg['status'] = 0;
$msg['error'] = '关键词太短,请重新填写';
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
if(mb_strlen($data['keyword'],"utf-8")>=40)
{
$msg['status'] = 0;
$msg['error'] = '关键词太长,请重新填写';
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
if(mb_strlen($data['body'],"utf-8")<40)
{
$msg['status'] = 0;
$msg['error'] = '新闻内容太短,请重新填写';
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
}
//获得描述
$data['description'] = mb_substr(preg_replace("/<(.*)>.*<\/\1>|<(.*) \/>/","",$data['body']),0,450,"UTF-8");
//默认填充数据
$data['source'] = "西部数据中心";
$data['typeid'] = 0;
$data['userid'] = $u_id;
$sql = "INSERT INTO news_archives
(userid,title,keywords,description,image,source,ts_publish,is_pub,body)
VALUES
(?,?,?,?,?,?,?,?,?)
";
$sth = $this->db->prepare($sql);
$sth -> execute(array($data['userid'],$data['title'],$data['keyword'],$data['description'],'',$data['source'],'now()',1,$data['body']));
$msg['status'] = 1;
$msg['outstring'] = "新闻添加成功";
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
return true;
} }