#308 添加了数据新闻功能

This commit is contained in:
Li Jianxuan 2012-03-23 09:53:07 +00:00
parent 9b946a9275
commit 68e9fbfa04
5 changed files with 435 additions and 22 deletions

View File

@ -1199,6 +1199,63 @@ class AuthorController extends Zend_Controller_Action
//新闻列表 //新闻列表
if(empty($ac) || $ac=="list") if(empty($ac) || $ac=="list")
{ {
$keyword = $this->_request->getParam('q');
$wheresql = "";
if(!empty($keyword))
{
$this->view->q = $keyword;
$search = new Search($keyword);
$wheresql = $search->sql_expr(array("arc.title","arc.description"));
}
if(!empty($wheresql))
{
$wheresql = " WHERE ".$wheresql;
}
$sql = "SELECT arc.id,arc.title,arc.ts_publish,arc.description,u.realname FROM news_archives arc
LEFT JOIN users u ON arc.userid=u.id
$wheresql
ORDER BY arc.ts_publish";
$sth = $this->db->prepare($sql);
$sth->execute();
$rows = $sth->fetchAll();
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(10);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
}
if($ac == "view")
{
$this->_helper->viewRenderer('news-view');
$aid = (int)$this->_request->getParam('aid');
if(empty($aid) || !is_numeric($aid))
{
$this->_redirect('/error/error');
}
else
{
$this->db->exec("UPDATE news_archives arc SET click=click+1 WHERE arc.id=$aid");
$sql = "SELECT arc.*,u.realname FROM news_archives arc
LEFT JOIN users u ON u.id=arc.userid
WHERE arc.id=?";
$sth = $this->db->prepare($sql);
$sth -> execute(array($aid));
$row = $sth->fetch();
$this->view->info = $row;
}
} }
@ -1208,6 +1265,27 @@ class AuthorController extends Zend_Controller_Action
$this->_helper->viewRenderer('news-add'); $this->_helper->viewRenderer('news-add');
}// $ac == add }// $ac == add
//新闻编辑
if($ac == "edit")
{
$this->_helper->viewRenderer('news-edit');
$aid = (int)$this->_request->getParam('aid');
if(empty($aid) || !is_numeric($aid))
{
$this->_redirect('/error/error');
}
$sql = "SELECT * FROM news_archives WHERE id=?";
$sth = $this->db->prepare($sql);
$sth->execute(array($aid));
$row = $sth->fetch();
$this->view->info = $row;
}
//新闻发布的ajax动作 //新闻发布的ajax动作
if($ac =="addnews") if($ac =="addnews")
{ {
@ -1217,9 +1295,10 @@ class AuthorController extends Zend_Controller_Action
$data = array(); $data = array();
$data['title'] = $this->_request->getParam('title'); $aid = $this->_request->getParam('aid');
$data['keyword'] = $this->_request->getParam('keyword'); $data['title'] = trim($this->_request->getParam('title'));
$data['body'] = $this->_request->getParam('body'); $data['keyword'] = trim($this->_request->getParam('keyword'));
$data['body'] = trim($this->_request->getParam('body'));
//对参数进行预处理 //对参数进行预处理
foreach($data as $k=>$v) foreach($data as $k=>$v)
@ -1282,25 +1361,42 @@ class AuthorController extends Zend_Controller_Action
$data['source'] = "西部数据中心"; $data['source'] = "西部数据中心";
$data['typeid'] = 0; $data['typeid'] = 0;
$data['userid'] = $u_id; $data['userid'] = $u_id;
$data['keyword'] = str_replace("",",",$data['keyword']);
if(empty($aid))
{
$sql = "INSERT INTO news_archives $sql = "INSERT INTO news_archives
(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);
$ex = $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']));
}
else
{
$sql = "UPDATE news_archives SET title=?,keywords=?,description=?,body=? WHERE id=? AND userid=?";
$sth = $this->db->prepare($sql);
$ex = $sth -> execute(array($data['title'],$data['keyword'],$data['description'],$data['body'],$aid,$data['userid']));
}
if($ex) if($ex)
{ {
$msg['status'] = 1; $msg['status'] = 1;
$msg['outstring'] = "新闻添加成功"; if(empty($aid))
{$msg['outstring'] = "新闻添加成功";}
else
{$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{ }else{
$msg['status'] = 0; $msg['status'] = 0;
$msg['error'] = "新闻添加失败,请重试"; if(empty($aid))
{$msg['error'] = "新闻添加失败,请重试";}
else
{$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;
} }
@ -1308,12 +1404,15 @@ class AuthorController extends Zend_Controller_Action
if($this->debug==0) if($this->debug==0)
{ {
$msg['status'] = 0; $msg['status'] = 0;
$msg['error'] = "新闻添加失败,请重试"; if(empty($aid))
{$msg['error'] = "新闻添加失败,请重试";}
else
{$msg['error'] = "新闻编辑失败,请重试";}
$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{ }else{
$msg['status'] = 0; $msg['status'] = 0;
$msg['error'] = "新闻添加失败,请重试:".$e->getMessage(); $msg['error'] = "新闻添加/编辑失败,请重试:".$e->getMessage();
$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;
} }

View File

@ -0,0 +1,109 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle($this->config->title->author);
$this->headTitle()->setSeparator(' - ');
$this->headScript()->appendFile('/js/jquery-1.7.min.js');
$this->headScript()->appendFile('/static/js/kindeditor-min.js');
$this->headScript()->appendFile('/static/js/kindlang/zh_CN.js');
$this->headLink()->appendStylesheet('/css/author.css');
$this->headLink()->appendStylesheet('/static/css/kindskin/default/default.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/author">数据作者</a>');
$this->breadcrumb('数据新闻');
$this->breadcrumb()->setSeparator(' > ');
?>
<!-- 左侧导航 -->
<div id='sidebar'>
<div id='leftnavi'>
<?= $this->partial('author/navi.phtml'); ?>
</div>
</div>
<!-- //左侧导航 -->
<!-- 页面内容 -->
<div id="wapper">
<!-- 按钮 -->
<div id="tabs-controller">
<ul>
<li class="box-shadow"><a class="text-shadow" href="/author/news">数据新闻</a></li>
<li class="box-shadow active"><a class="text-shadow" href="/author/news/ac/add">新闻发布</a></li>
</ul>
</div>
<!-- 新闻表单 -->
<div class="form" id="form">
<form name="form" id="newsadd" method="post" action="#">
<fieldset>
<legend>新闻信息</legend>
<input type="hidden" id="image" class="half title" value="" name="image"/>
<p>
<label class="required" for="producttitle">标题</label><br/>
<input type="text" id="producttitle" class="half" value="" name="title" maxlength="100"/>
<small>请准确概况新闻内容</small>
</p>
<p>
<label class="required" for="producttitle">标签</label><br/>
<input type="text" id="keyword" class="half" value="" name="keyword"/>
<small>使用半角逗号“,”隔开,如 (冻土,冰川)</small>
</p>
<p>
<label for="body">新闻内容</label><br/>
<textarea id="body" class="large full" name="body"></textarea>
</p>
<p class="box"><input type="button" onclick="addon();" id="submit" class="btn btn-green big" value="提交"/> or <input type="reset" class="btn" value="重置" onclick="return confirm('确实要抛弃已经填写内容?');"/></p>
<div id="return"></div>
</fieldset>
</form>
</div>
</div>
<!-- //页面内容 -->
<script>
$(document).ready(function(){
$('#wapper').width($('body').width()-300);
KindEditor.ready(function(K) {
editor=K.create('textarea[name="body"]', {
cssPath : '/static/js/plugins/code/prettify.css',
uploadJson : '/plugins/upload_json.php',
allowFileManager : true
});
});
});
function addon(){
editor.sync();
$.ajax({
'type': "POST",
'url': "/author/news/ac/addnews",
'data': $("#newsadd").serialize(),
'success': function(data){
if (typeof(data)=='object')
{
if(typeof(data.error)!='undefined'){
alert(data.error);
}else{
if(data.status==1)
{
$('#form').html('<div class="box box-success">新闻添加成功!<a href="/author/news">进入新闻列表</a></div>');
setTimeout("top.location='/author/news'",5000);
}
}
}else{
alert('出现错误,请稍候');
$('#return').html('');
}
},
'beforeSend':function(){
$('#submit').val('正在提交...');
$('#submit').attr("disabled","disabled");
},
'complete':function(){
$('#submit').val('提交');
$('#submit').removeAttr('disabled');
},
'timeout': 20000,
'error': function(){
alert('处理中出现问题,请重试');
$('#return').html('');
}
});
}
</script>

View File

@ -0,0 +1,106 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle($this->config->title->author);
$this->headTitle()->setSeparator(' - ');
$this->headScript()->appendFile('/js/jquery-1.7.min.js');
$this->headScript()->appendFile('/static/js/kindeditor-min.js');
$this->headScript()->appendFile('/static/js/kindlang/zh_CN.js');
$this->headLink()->appendStylesheet('/css/author.css');
$this->headLink()->appendStylesheet('/static/css/kindskin/default/default.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/author">数据作者</a>');
$this->breadcrumb('数据新闻');
$this->breadcrumb()->setSeparator(' > ');
?>
<!-- 左侧导航 -->
<div id='sidebar'>
<div id='leftnavi'>
<?= $this->partial('author/navi.phtml'); ?>
</div>
</div>
<!-- //左侧导航 -->
<!-- 页面内容 -->
<div id="wapper">
<div id="tabs-controller">
<ul>
<li class="box-shadow"><a class="text-shadow" href="/author/news">数据新闻</a></li>
<li class="box-shadow"><a class="text-shadow" href="/author/news/ac/add">新闻发布</a></li>
</ul>
</div>
<!-- 新闻表单 -->
<div class="form" id="form">
<form name="form" id="newsadd" method="post" action="#">
<fieldset>
<legend>新闻信息</legend>
<p>
<label class="required" for="producttitle">标题</label><br/>
<input type="text" id="producttitle" class="half" value="<?php echo $this->info['title'];?>" name="title" maxlength="100"/>
<small>请准确概况新闻内容</small>
</p>
<p>
<label class="required" for="producttitle">标签</label><br/>
<input type="text" id="keyword" class="half" value="<?php echo $this->info['keywords'];?>" name="keyword"/>
<small>使用半角逗号","隔开,如 (冻土,冰川)</small>
</p>
<p>
<label for="body">新闻内容</label><br/>
<textarea id="body" class="large full" name="body"><?php echo $this->info['body'];?></textarea>
</p>
<input type="hidden" name="aid" value="<?php echo $this->info['id'];?>" />
<p class="box"><input type="button" onclick="addon();" id="submit" class="btn btn-green big" value="提交"/> or <input type="reset" class="btn" value="重置" onclick="return confirm('确实要抛弃已经填写内容?');"/></p>
<div id="return"></div>
</fieldset>
</form>
</div>
<!-- //页面内容 -->
<script>
$(document).ready(function(){
$('#wapper').width($('body').width()-300);
KindEditor.ready(function(K) {
editor=K.create('textarea[name="body"]', {
cssPath : '/static/js/plugins/code/prettify.css',
uploadJson : '/plugins/upload_json.php',
allowFileManager : true
});
});
});
function addon(){
editor.sync();
$.ajax({
'type': "POST",
'url': "/author/news/ac/addnews",
'data': $("#newsadd").serialize(),
'success': function(data){
if (typeof(data)=='object')
{
if(typeof(data.error)!='undefined'){
alert(data.error);
}else{
if(data.status==1)
{
$('#form').html('<div class="box box-success">新闻编辑成功!<a href="/author/news">进入新闻列表</a></div>');
setTimeout("top.location='/author/news'",5000);
}
}
}else{
alert('出现错误,请稍候');
$('#return').html('');
}
},
'beforeSend':function(){
$('#submit').val('正在提交...');
$('#submit').attr("disabled","disabled");
},
'complete':function(){
$('#submit').val('提交');
$('#submit').removeAttr('disabled');
},
'timeout': 20000,
'error': function(){
alert('处理中出现问题,请重试');
$('#return').html('');
}
});
}
</script>

View File

@ -0,0 +1,43 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle($this->config->title->author);
$this->headTitle()->setSeparator(' - ');
$this->headScript()->appendFile('/js/jquery-1.7.min.js');
$this->headLink()->appendStylesheet('/css/author.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/author">数据作者</a>');
$this->breadcrumb('数据新闻');
$this->breadcrumb()->setSeparator(' > ');
?>
<!-- 左侧导航 -->
<div id='sidebar'>
<div id='leftnavi'>
<?= $this->partial('author/navi.phtml'); ?>
</div>
</div>
<!-- //左侧导航 -->
<!-- 页面内容 -->
<div id="wapper">
<div id="tabs-controller">
<ul>
<li class="box-shadow active"><a class="text-shadow" href="/author/news">数据新闻</a></li>
<li class="box-shadow"><a class="text-shadow" href="/author/news/ac/add">新闻发布</a></li>
</ul>
</div>
<form id="datasearch" class="search_form" action="/author/news/">
<input type="text" id="keyword" name="q" value="<?php if(!empty($this->q)) echo $this->q; ?>" />
<button type="submit" class="btn" id="search_btn">搜索</button>
</form>
<div id="archives_view">
<div class="title"><?php echo $this->info['title'];?></div>
<div class="info">作者:<?php echo $this->info['realname'];?> 发布时间:<?php echo date("Y-m-d",strtotime($this->info['ts_publish']));?> 阅读次数:<?php echo $this->info['click'];?></div>
<div class="content">
<?php echo $this->info['body'];?>
</div>
</div>
</div>
<!-- //页面内容 -->
<script>
$('#wapper').width($('body').width()-300);
</script>

View File

@ -0,0 +1,56 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle($this->config->title->author);
$this->headTitle()->setSeparator(' - ');
$this->headScript()->appendFile('/js/jquery-1.7.min.js');
$this->headLink()->appendStylesheet('/css/author.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/author">数据作者</a>');
$this->breadcrumb('数据新闻');
$this->breadcrumb()->setSeparator(' > ');
?>
<!-- 左侧导航 -->
<div id='sidebar'>
<div id='leftnavi'>
<?= $this->partial('author/navi.phtml'); ?>
</div>
</div>
<!-- //左侧导航 -->
<!-- 页面内容 -->
<div id="wapper">
<div id="tabs-controller">
<ul>
<li class="box-shadow active"><a class="text-shadow" href="/author/news">数据新闻</a></li>
<li class="box-shadow"><a class="text-shadow" href="/author/news/ac/add">新闻发布</a></li>
</ul>
</div>
<form id="datasearch" class="search_form" action="/author/news/">
<input type="text" id="keyword" name="q" value="<?php if(!empty($this->q)) echo $this->q; ?>" />
<button type="submit" class="btn" id="search_btn">搜索</button>
</form>
<div id="datalist">
<?php
if (count($this->paginator)):
echo "<ul>";
$autoindex=0;
foreach ($this->paginator as $item):
$autoindex++;
?>
<li>
<p><a href="/author/news/ac/view/aid/<?php echo $item['id'];?>" class="title"><?php echo $item['title'];?></a></p>
<p>作者:<?php echo $item['realname'];?> 发布时间:<?php echo date("Y-m-d",strtotime($item['ts_publish']));?></p>
<p><?php echo $item['description'];?></p>
</li>
<?php
endforeach;
echo "</ul>";
endif; ?>
</div>
<div class="pagenavi"><?= $this->paginator; ?></div>
</div>
<!-- //页面内容 -->
<script>
$('#wapper').width($('body').width()-300);
</script>