db=Zend_Registry::get('db'); $this->view->config = Zend_Registry::get('config'); $this->messenger=$this->_helper->getHelper('FlashMessenger'); $this->view->messages = $this->messenger->getMessages(); } function postDispatch() { $this->view->messages = $this->messenger->getMessages(); } function indexAction() { $sql = "select n.*,c.title as catlog,u.realname as author from news_archives n left join news_category c on n.typeid=c.id LEFT JOIN users u ON n.userid=u.id order by n.ts_created desc limit 10"; $rs = $this->db->query($sql); $rows = $rs->fetchAll(); $this->view->news = $rows; $sql = "SELECT count(id) as c FROM news_archives"; $rs = $this->db->query($sql); $row = $rs->fetch(); $this->view->totle = $row; $sql = "SELECT count(id) as c FROM news_category"; $rs = $this->db->query($sql); $row = $rs->fetch(); $this->view->typec = $row; }//indexAction 首页 function newslistAction(){ $type = $this->_request->getParam('type'); if(!empty($type)) { $sql = "select n.*,c.title as catlog,c.url,u.realname as author from news_archives n left join news_category c on n.typeid=c.id LEFT JOIN users u ON n.userid=u.id WHERE n.typeid='$type' order by n.ts_created desc"; }else { $sql = "select n.*,c.title as catlog,c.url,u.realname as author from news_archives n left join news_category c on n.typeid=c.id LEFT JOIN users u ON n.userid=u.id order by n.ts_created desc"; } $rs = $this->db->query($sql); $rows = $rs->fetchAll(); $paginator = Zend_Paginator::factory($rows); $paginator->setCurrentPageNumber($this->_getParam('page')); $paginator->setItemCountPerPage($this->view->config->page->max); $paginator->setView($this->view); Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); $this->view->paginator=$paginator; $sql="select * from news_category order by displayorder desc"; $re = $this->db->query($sql); $types = $re->fetchAll(); $this->view->types=$types; $this->view->type = $type; }//newslistAction 新闻列表 function catlogAction() { $add = $this->_request->getParam('add'); $submit = $this->_request->getParam('submit'); $delete = $this->_request->getParam('delete'); $edit = $this->_request->getParam('edit'); if($add) { if(empty($submit)) $this->_helper->viewRenderer('category-add'); else{ $title = $this->_request->getParam('ctitle'); $url = $this->_request->getParam('url'); $keyword = $this->_request->getParam('keyword'); $description = $this->_request->getParam('description'); $sql="insert into news_category (title,keywords,description,url) values ('$title','$keyword','$description','$url')"; if($this->db->exec($sql) > 0) { $this->messenger->addMessage('提示信息:栏目添加成功!'); $this->_redirect('/admin/news/catlog'); } } }//栏目添加 if($delete>0) { $sql = "delete from news_category where id='$delete'"; if($this->db->exec($sql)>0) { $this->messenger->addMessage('提示信息:栏目删除成功!'); $this->_redirect('/admin/news/catlog'); } }//栏目删除 if($edit>0) { $title = $this->_request->getParam('ctitle'); $url = $this->_request->getParam('url'); $keyword = $this->_request->getParam('keyword'); $description = $this->_request->getParam('description'); $displayorder = $this->_request->getParam('displayorder'); $sql="update news_category set title='$title',keywords='$keyword',description='$description',displayorder='$displayorder',url='$url' where id='$edit'"; if($this->db->exec($sql)>0) { $this->messenger->addMessage('提示信息:栏目编辑成功!'); $this->_redirect('/admin/news/catlog'); } }//栏目编辑 else { $sql="select * from news_category order by displayorder asc"; $re=$this->db->query($sql); $catlogs=$re->fetchAll(); $this->view->catlogs=$catlogs; }//栏目列表 }//栏目管理 function newsaddAction() { $id = $this->_request->getParam('id'); if($id>0) { $sql = "SELECT arc.id,arc.title,arc.ts_published,arc.typeid,cat.url,cat.id as typeid from news_archives arc LEFT JOIN news_category cat ON arc.typeid=cat.id WHERE arc.id=$id"; $rs = $this->db->query($sql); $rows = $rs->fetch(); if($rows['ts_published']>time()) { $title = "《{$rows['title']}》将在".date('Y-m-d H:i',$rows['ts_published'])."发布"; } else { $title = "《{$rows['title']}》发布成功!"; } $this->view->title = $title; $this->view->infos = $rows; $this->_helper->viewRenderer('newsaddok'); } $sql="select * from news_category order by displayorder desc"; $re = $this->db->query($sql); $types = $re->fetchAll(); $this->view->types=$types; }//newsadd 新闻添加 function replacehtml($html) { $newString = htmlentities($html, ENT_QUOTES, "UTF-8"); return $newString; } function archivesaddAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $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[] = "内容描述不能超过200个字符,现在输入了".strlen($description)."个字符"; if(empty($body)) $msg[]="请填写内容"; if($typeid==0) $msg[]="请选择栏目"; if(count($msg)>0) { echo '