完善新闻中心功能

This commit is contained in:
Li Jianxuan 2012-11-27 03:57:27 +00:00
parent 01293cc0cc
commit 21bd8bf9b6
7 changed files with 218 additions and 198 deletions

View File

@ -43,13 +43,14 @@ class Admin_NewsController extends Zend_Controller_Action
if(!empty($type))
{
$sql = "select n.*,c.title as catlog,c.code as author from ".$News->tbl_archives." n
left join ".$News->tbl_categorys." c on n.typeid=c.id
$sql = "select n.*,c.id as typeid,c.title as catlog,c.code from ".$News->tbl_archives." n
left join ".$News->tbl_catalog." ct on ct.aid=n.id
left join ".$News->tbl_categorys." c on c.id = ct.cid
LEFT JOIN users u ON n.userid=u.id
WHERE n.typeid='$type' order by n.ts_created desc";
WHERE c.id='$type' order by n.ts_created desc";
}else
{
$sql = "select n.*,c.title as catlog,c.code from ".$News->tbl_archives." n
$sql = "select n.*,c.id as typeid,c.title as catlog,c.code from ".$News->tbl_archives." n
left join ".$News->tbl_catalog." ct on ct.aid=n.id
left join ".$News->tbl_categorys." c on c.id = ct.cid
LEFT JOIN users u ON n.userid=u.id
@ -254,7 +255,7 @@ class Admin_NewsController extends Zend_Controller_Action
{
$_addon = "WHERE id not in ($id)";
}
$sql = "SELECT * FROM news_category $_addon ORDER BY id DESC";
$sql = "SELECT * FROM ar_category $_addon ORDER BY id DESC";
$sth = $this->db->prepare($sql);
$sth->execute();
return $sth->fetchAll();
@ -349,51 +350,76 @@ class Admin_NewsController extends Zend_Controller_Action
'body' => $this->db->quote($body)
);
$update = $this->_getParam('update');
$aid = $this->_getParam('aid');
$sql = "INSERT INTO ".$News->tbl_archives." (userid,title,description,image,source,ts_published,is_pub,body)
VALUES (
".$data['userid'].",
".$data['title'].",
".$data['description'].",
".$data['image'].",
".$data['source'].",
".$data['ts_published'].",
".$data['is_pub'].",
".$data['body']."
)
RETURNING id
";
try{
$sth = $this->db->prepare($sql);
if($sth->execute())
if(is_numeric($update) && !empty($update) && !empty($aid))
{
if($this->db->update($News->tbl_archives,$data[],"id=$aid"))
{
$temp = $sth->fetch(PDO::FETCH_ASSOC);
$News->ToCatalog($temp['id'],$typeid);
echo '<div class="box box-success">发布成功!</div><script>
$News->ChangeCatalog($aid,$typeid);
$News->DeleteTags($aid);
$News->MakeTags($aid,$keyword);
echo '<div class="box box-success">修改成功!</div><script>
setTimeout("self.location=\'/admin/news/newslist\'",500);
</script>';
return true;
}else{
echo '<div class="box box-success">发布失败!请重试</div>';
echo '<div class="box box-success">修改失败!请重试</div>';
return true;
}
}else{
$sql = "INSERT INTO ".$News->tbl_archives." (userid,title,description,image,source,ts_published,is_pub,body)
VALUES (
".$data['userid'].",
".$data['title'].",
".$data['description'].",
".$data['image'].",
".$data['source'].",
".$data['ts_published'].",
".$data['is_pub'].",
".$data['body']."
)
RETURNING id
";
try{
$sth = $this->db->prepare($sql);
if($sth->execute())
{
$temp = $sth->fetch(PDO::FETCH_ASSOC);
$News->ToCatalog($temp['id'],$typeid);
$News->MakeTags($temp['id'],$keyword);
echo '<div class="box box-success">发布成功!</div><script>
setTimeout("self.location=\'/admin/news/newslist\'",500);
</script>';
return true;
}else{
echo '<div class="box box-error">发布失败!请重试</div>';
return true;
}
}catch(Exception $e){
echo '<div class="box box-error">文章发布失败:</div>
<div class="box box-error-msg">
<ol>
<li>'.$e->getMessage().'</li>
</ol>
</div>';
return true;
}
}catch(Exception $e){
echo '<div class="box box-error">文章发布失败:</div>
<div class="box box-error-msg">
<ol>
<li>'.$e->getMessage().'</li>
</ol>
</div>';
}
}// 文章发布
//文档编辑
function newseditAction()
{
include_once("news.php");
$News = new news($this->db);
$id = $this->_request->getParam('id');
$sql = "select * from news_archives arc where arc.id=$id";
$sql = "select * from ".$News->tbl_archives." arc where arc.id=$id";
$rs = $this->db->query($sql);
$row = $rs->fetch();
@ -407,127 +433,15 @@ class Admin_NewsController extends Zend_Controller_Action
$this->view->att = $row;
}
$sql="select * from news_category order by displayorder desc";
$this->view->keywords = join(",",$News->GetTags($id));
$sql="select * from ".$News->tbl_categorys." order by displayorder desc";
$re = $this->db->query($sql);
$types = $re->fetchAll();
$this->view->types=$types;
}
function archiveseditAction()
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$id = $this->_request->getParam('id');
if(empty($id))
{
echo '<div class="box box-error">发布失败:</div>
<div class="box box-error-msg">
<ol>';
echo '<li>参数错误</li>'.
'</ol>
</div>
';
}
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$user = $auth->getIdentity();
$uid = $user->id;
}
$datavar = array(
'title','source','image','body','typeid','pub','pubtimer','pubtime','description','keyword'
);
foreach($_POST as $k=>$v)
{
if(in_array($k,$datavar))
{
$$k=$v;
}
}
$msg=array();
if(empty($title)) $msg[]="标题不能为空";
if(strlen($title)>200) $msg[]="标题长度不能超过200个字符";
if(strlen($keyword)>200) $msg[] = "关键词长度不能超过200个字符现在输入了".strlen($keyword)."个字符";
if(strlen($description)>500) $msg[] = "内容描述不能超过500个字符现在输入了".strlen($description)."个字符";
if(empty($body)) $msg[]="请填写内容";
if($typeid==0) $msg[]="请选择栏目";
if(count($msg)>0)
{
echo '<div class="box box-error">发布失败:</div>
<div class="box box-error-msg">
<ol>';
foreach ($msg as $v)
{
echo '<li>'.$v.'</li>';
}
echo'</ol>
</div>
';
}
else
{
$pubtime = date("Y-m-d H:i:s",strtotime($pubtime));
$date=array(
'title' => $this->replacehtml($title),
'writer' => $uid,
'keyword' => $this->replacehtml($keyword),
'description'=> $this->replacehtml($description),
'image' => $image,
'pubtime' => $pubtime,
'source' => $this->replacehtml($source),
'typeid' => $typeid,
'pub' => $pub,
'body' => $this->db->quote($body)
);
$sql = "UPDATE news_archives SET
title='{$date['title']}',
userid='{$date['writer']}',
keywords='{$date['keyword']}',
description='{$date['description']}',
image='{$date['image']}',
ts_published='{$date['pubtime']}',
source='{$date['source']}',
typeid='{$date['typeid']}',
is_pub='{$date['pub']}',
body=".$date['body']."
WHERE id='$id'
";
try{
$sth = $this->db->prepare($sql);
if($sth->execute())
{
echo '<div class="box box-success">发布成功!</div><script>
setTimeout("self.location=\'/admin/news/newsadd/id/'.$id.'\'",500);
</script>';
}else{
echo '<div class="box box-success">发布失败!写入附加表出错,请联系管理员</div>';
}
}catch(Exception $e){
echo '<div class="box box-error">文章发布失败:</div>
<div class="box box-error-msg">
<ol>
<li>'.$e->getMessage().'</li>
</ol>
</div>';
}
}
}// 文章编辑
function deleteAction(){
$id = $this->_request->getParam('id');

View File

@ -77,7 +77,7 @@
}else{
$deep = 1;
}
if($vv['fid']==$v['id'])
if($vv['tid']==$top)
{
echo '
<tr>

View File

@ -165,7 +165,7 @@ $(document).ready(function(){
</header>
<section>
输入Tag标签多个用半角逗号 " , "隔开每个Tag标签长度小于6个汉字
<p><textarea id="keyword" class="small full" name="keyword"><?php echo $this->ev['keywords']; ?></textarea></p>
<p><textarea id="keyword" class="small full" name="keyword"><?php echo $this->keywords; ?></textarea></p>
</section>
</div>
<div id="return"></div>

View File

@ -6,7 +6,7 @@
$this->headLink()->appendStylesheet('/css/admin.css');
$this->headScript()->appendFile('/js/jquery.colorbox-min.js');
$this->headLink()->appendStylesheet('/css/author.css');
$this->headLink()->appendStylesheet('/css/colorbox.css');
$this->headLink()->appendStylesheet('/css/colorbox.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/admin">后台首页</a>');
$this->breadcrumb('<a href="/admin/news">新闻中心</a>');
@ -70,20 +70,7 @@ $('#divFooter').css('position','absolute');
$list .= '
<tr>
<td>
<div id="paddiv'.$v['id'].'">
<a id="titlebtn'.$v['id'].'" class="title"><b>'.$v['title'].'</b></a>
<div class="listingDetails">
<div class="pad">
<b>详细信息</b>
<p>作者:'.$v['author'].'</p>
<p>关键词:'.$v['keywords'].'</p>
<p>描述:'.$v['description'].'</p>
<p>添加时间:'.date("Y-m-d H:i",strtotime($v['ts_created'])).'</p>
<p>发布时间:'.date("Y-m-d H:i",strtotime($v['ts_published'])).'</p>
<p>来源:'.$v['source'].'</p>
<p>点击:'.$v['click'].'</p>
</div>
</div></div>
</td>
<td><a href="/admin/news/newslist/type/'.$v['typeid'].'">'.$v['catlog'].'</a></td>
<td>';
@ -105,7 +92,7 @@ $('#divFooter').css('position','absolute');
}
$list .= '</td>
<td>
<a href="/news/'.$v['url'].'/archive-'.$v['id'].'.html" target="_blank"><b>预览</b></a>
<a href="/news/'.$v['code'].'/archive-'.$v['id'].'.html" target="_blank"><b>预览</b></a>
<a href="/admin/news/newsedit/id/'.$v['id'].'"><b>编辑</b></a>
<a href="/admin/news/delete/id/'.$v['id'].'" onclick="return confirm(\'是否确定删除该文章\')">删除</a></td>
</tr>

View File

@ -13,14 +13,14 @@ class NewsController extends Zend_Controller_Action
function indexAction()
{
include_once("news.php");
$news = new news($this->db);
$types = $news->getAllCategory();
$News = new news($this->db);
$types = $News->getAllCategory();
$this->view->types=$types;
$time = date("Y-m-d H:i:s",time());
$sql = "SELECT id,title,url FROM news_category WHERE fid=0";
$sql = "SELECT id,title,code FROM ".$News->tbl_categorys." WHERE fid=0";
$sth = $this->db->query($sql);
$rows = $sth->fetchAll();
@ -28,16 +28,17 @@ class NewsController extends Zend_Controller_Action
foreach($rows as $v)
{
$sql = "SELECT arc.*,t.title as typetitle,t.url FROM news_archives arc
LEFT JOIN news_category t ON arc.typeid=t.id
WHERE arc.ts_published<'$time' AND arc.typeid={$v['id']}
ORDER BY ts_published DESC
LIMIT 10";
$sql = "SELECT n.*,c.title as typetitle,c.code FROM ".$News->tbl_archives." n
left join ".$News->tbl_catalog." ct on ct.aid=n.id
left join ".$News->tbl_categorys." c on c.id = ct.cid
WHERE n.ts_published<'$time' AND ct.cid={$v['id']}
ORDER BY ts_published DESC
LIMIT 10";
$rs = $this->db->query($sql);
$archives = $rs->fetchAll();
$newslist[$v['id']] = array("title"=>$v['title'],"url"=>$v['url'],"id"=>$v['id'],"list"=>$archives);
$newslist[$v['id']] = array("title"=>$v['title'],"url"=>$v['code'],"id"=>$v['id'],"list"=>$archives);
}
$this->view->lists = $newslist;
@ -60,7 +61,11 @@ class NewsController extends Zend_Controller_Action
$this->_forward('error', 'error', null, null);
}
$sql = "SELECT id,url,title FROM news_category WHERE url='$type' AND display>0 ";
include_once("news.php");
$News = new news($this->db);
$sql = "SELECT id,code,title FROM ".$News->tbl_categorys." WHERE code='$type' AND is_pub=true ";
$rs = $this->db->query($sql);
$row = $rs->fetch();
@ -71,7 +76,7 @@ class NewsController extends Zend_Controller_Action
else{
$this->view->url = $row['url'];
$this->view->url = $row['code'];
$this->view->title = $row['title'];
include_once("news.php");
@ -82,10 +87,11 @@ class NewsController extends Zend_Controller_Action
$time = date("Y-m-d H:i:s",time());
$sql = "SELECT arc.*,c.url FROM news_archives arc
left join news_category c ON arc.typeid=c.id
WHERE arc.typeid='{$row['id']}' AND arc.ts_published<'".$time."' AND arc.is_pub>=1
ORDER BY arc.ts_published DESC";
$sql = "SELECT n.*,c.code FROM ".$News->tbl_archives." n
left join ".$News->tbl_catalog." ct on ct.aid=n.id
left join ".$News->tbl_categorys." c ON ct.cid=c.id
WHERE c.id='{$row['id']}' AND n.ts_published<'".$time."' AND n.is_pub=true
ORDER BY n.ts_published DESC";
$rs = $this->db->query($sql);
$rows = $rs->fetchAll();
@ -115,15 +121,19 @@ class NewsController extends Zend_Controller_Action
}
include_once("news.php");
$news = new news($this->db);
$types = $news->getAllCategory();
$News = new news($this->db);
$types = $News->getAllCategory();
$this->view->types=$types;
$sql = "SELECT arc.*,type.url,type.title as typename,u.realname as author FROM news_archives arc";
$sql .= " LEFT JOIN news_category type ON arc.typeid=type.id";
$sql .= " LEFT JOIN users u ON arc.userid=u.id";
$sql .= " WHERE arc.is_pub>0 AND arc.ts_published<'now()' AND arc.id=$archive";
$time = date("Y-m-d H:i:s",time());
$sql = "SELECT n.*,c.title as typename,c.code,u.realname as author FROM ".$News->tbl_archives." n
left join ".$News->tbl_catalog." ct on ct.aid=n.id
left join ".$News->tbl_categorys." c ON ct.cid=c.id
LEFT JOIN users u ON n.userid=u.id
WHERE c.code='".$type."' AND n.ts_published<'".$time."' AND n.is_pub=true AND n.id=".$archive."
ORDER BY n.ts_published DESC";
$rs = $this->db->query($sql);
$row = $rs->fetch();

View File

@ -22,13 +22,13 @@ $this->breadcrumb()->setSeparator(' > ');
{
if($v['fid']==0)
{
echo '<li><a href="/news/'.$v['url'].'">'.$v['title'].'</a></li>';
echo '<li><a href="/news/'.$v['code'].'">'.$v['title'].'</a></li>';
}
foreach($this->types as $vd)
{
if($vd['fid']==$v['id'])
{
echo '<li> - <a href="/news/'.$vd['url'].'">'.$vd['title'].'</a></li>';
echo '<li> - <a href="/news/'.$vd['code'].'">'.$vd['title'].'</a></li>';
}
}
}
@ -52,7 +52,7 @@ $this->breadcrumb()->setSeparator(' > ');
$description = "No description";
}else if (mb_strlen($v['description'])>160)
{
$description = mb_substr($v['description'],0,160,'utf-8').'...<a href="/news/'.$v['url'].'/archive-'.$v['id'].'.html" class="more">(more)</a>';
$description = mb_substr($v['description'],0,160,'utf-8').'...<a href="/news/'.$v['code'].'/archive-'.$v['id'].'.html" class="more">(more)</a>';
}else{
$description = $v['description'];
}
@ -61,7 +61,7 @@ $this->breadcrumb()->setSeparator(' > ');
{
echo '<img src="'.$v['image'].'" style="max-height:200px;float:left;" />';
}
echo '<a href="/news/'.$v['url'].'/archive-'.$v['id'].'.html" class="title">'.$v['title'].'</a><br />
echo '<a href="/news/'.$v['code'].'/archive-'.$v['id'].'.html" class="title">'.$v['title'].'</a><br />
<small>TIME&nbsp;:&nbsp;'.date("Y-m-d H:i",strtotime( $v['ts_published'] )).'</small>
<p>'.$description.'</p>
</li>';

View File

@ -106,12 +106,42 @@ class news
}//ToCatalog()
//写入标签关系
function MakeTags(){
/*
* 更改栏目 ChangeCatalog()
*
*
*
*/
function ChangeCatalog($aid,$cid,$uuid='',$status=0){
return true;
if(empty($aid) || !is_numeric($aid))
{
return false;
}
}//MakeTags
if(empty($cid) && empty($uuid))
{
return false;
}
$data = array(
"cid" => $cid,
"status" => $status
);
if(!empty($uuid))
{
$data['uuid'] = $uuid;
}
if($this->db->update($this->tbl_catalog,$data,"id=$aid"))
{
return true;
}else{
return false;
}
}//ChangeCatalog
//修改文档状态
function ChangeStatus($aid,$pub){
@ -146,12 +176,91 @@ class news
return false;
}
$this->DeleteTags($aid);
$sql = "DELETE FROM ".$this->tbl_archives." WHERE id=$aid";
@$this->db->exec($sql);
$sql = "DELETE FROM ".$this->tbl_catalog." WHERE aid=$aid";
@$this->db->exec($sql);
return true;
}//DeleteArchives
//写入标签关系
function MakeTags($aid,$keywords){
$keywords = trim($keywords);
if(empty($aid) || !is_numeric($aid))
{
return false;
}
if(preg_match("/,/",$keywords))
{
$tag = explode(",",$keywords);
}else{
if($this->db->insert($this->tbl_tag,array("id"=>$aid,"tag"=>$tag)))
{
return true;
}else{
return true;
}
}
if(is_array($tag))
{
foreach($tag as $v)
{
$v = trim($v);
if($v!='')
{
$this->db->insert($this->tbl_tag,array("id"=>$aid,"tag"=>$v));
}
}
}
return true;
}//MakeTags
//读取标签
function GetTags($aid,$limit=0){
if(empty($aid) || !is_numeric($aid))
{
return false;
}
$sql = "SELECT * FROM ".$this->tbl_tag." WHERE id=$aid";
if(!empty($limit))
{
$sql .= " LIMIT $limit";
}
$sth = $this->db->query($sql);
$rows = $sth->fetchAll();
$keywords = array();
foreach($rows as $k=>$v)
{
$keywords[] = $v['tag'];
}
return $keywords;
}//GetTags
//删除标签
function DeleteTags($aid){
if(empty($aid) || !is_numeric($aid))
{
return false;
}
$sql = "DELETE FROM ".$this->tbl_tag." WHERE id=$aid";
@$this->db->exec($sql);
return true;
}
}