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) { $this->_helper->viewRenderer('category-add'); $this->view->categories = $this->getAllcategory(); if(empty($submit)){ //$this->_helper->viewRenderer('category-add'); }else{ $data = array(); $data['title'] = $this->_request->getParam('ctitle'); $data['url'] = $this->_request->getParam('url'); $data['keywords'] = $this->_request->getParam('keyword'); $data['description'] = $this->_request->getParam('description'); $data['fid'] = $this->_request->getParam('fid'); $data['display'] = 1; $this->view->info = $data; if(empty($data['title'])) { $this->view->error = "请输入标题"; return true; } if(empty($data['url'])) { $this->view->error = "请输入栏目连接,如http://westdc.westgis.ac.cn/news/notice,则只需要输入notice"; return true; } if(!preg_match("/^[a-z]+$/",$data['url'])) { $this->view->error = "url格式不正确,仅允许26个小写字母"; return true; } if($this->db->insert("news_category",$data)) { $this->view->msg = '提示信息:栏目添加成功!'; $this->view->jump_url = '/admin/news/catlog'; return true; }else{ $this->view->error = "添加失败,请重试"; return true; } } }//栏目添加 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) { $submit = $this->_getParam('submit'); if(empty($submit)) { $this->_helper->viewRenderer('category-edit'); $this->view->info = $this->getCategory($edit); $this->view->categories = $this->getAllcategory($edit); }else{ $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'); $display = (int)$this->_request->getParam('display'); $fid = $this->_request->getParam('fid'); if(empty($displayorder)) { $displayorder = 0; } $sql="update news_category set title='$title',keywords='$keyword',description='$description',displayorder=$displayorder,url='$url',fid=$fid,display=$display where id=$edit"; if($this->db->exec($sql)>0) { $this->messenger->addMessage('提示信息:栏目编辑成功!'); $this->_redirect('/admin/news/catlog'); } } }//栏目编辑 else { include_once("news.php"); $news = new news($this->db); $catlogs = $news->getAllCategory(-1); /* $sql="select * from news_category WHERE fid=0 order by displayorder asc"; $re=$this->db->query($sql); $catlogs=$re->fetchAll(); foreach($catlogs as $k=>$v) { $catlogs[$k]['sub'] = $this->getSubCategory($v['id']); } */ $this->view->catlogs=$catlogs; }//栏目列表 }//栏目管理 function getSubCategory($fid) { $sql = "SELECT * FROM news_category WHERE fid=?"; $sth = $this->db->prepare($sql); $sth->execute(array($fid)); $rows = $sth->fetchAll(); if(empty($rows) || count($rows)<1) { return 0; }else{ return $rows; } } function getCategory($id) { $sql = "SELECT * FROM news_category WHERE id=?"; $sth = $this->db->prepare($sql); $sth->execute(array($id)); $rows = $sth->fetch(); return $rows; } function getAllcategory($id=0) { $_addon = ''; if(!empty($id)) { $_addon = "WHERE id not in ($id)"; } $sql = "SELECT * FROM news_category $_addon ORDER BY id DESC"; $sth = $this->db->prepare($sql); $sth->execute(); return $sth->fetchAll(); } 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 '
发布失败:
    '; foreach ($msg as $v) { echo '
  1. '.$v.'
  2. '; } echo'
'; } else { if(!empty($pubtimer)) { $pubtime = date("Y-m-d H:i:s",strtotime($pubtime)); } else { $pubtime = date("Y-m-d H:i:s",time()); } $date=array( 'title' => $this->db->quote($this->replacehtml($title)), 'writer' => $uid, 'keyword' => $this->db->quote($this->replacehtml($keyword)), 'description'=> $this->db->quote($this->replacehtml($description)), 'image' => $image, 'pubtime' => $pubtime, 'source' => $source, 'typeid' => $typeid, 'pub' => $pub, 'body' => $this->db->quote($body) ); $sql = "INSERT INTO news_archives (title,userid,keywords,description,image,ts_published,source,typeid,is_pub,body) VALUES ( ".$date['title'].", ".$date['writer'].", ".$date['keyword'].", ".$date['description'].", '{$date['image']}', '{$date['pubtime']}', '{$date['source']}', '{$date['typeid']}', '{$date['pub']}', ".$date['body']." ) RETURNING id "; try{ $sth = $this->db->prepare($sql); if($sth->execute()) { $temp = $sth->fetch(PDO::FETCH_ASSOC); echo '
发布成功!
'; }else{ echo '
发布失败!请重试
'; } }catch(Exception $e){ echo '
文章发布失败:
  1. '.$e->getMessage().'
'; } } }// 文章发布 function newseditAction() { $id = $this->_request->getParam('id'); $sql = "select * from news_archives arc where arc.id=$id"; $rs = $this->db->query($sql); $row = $rs->fetch(); $this->view->ev = $row; if(!empty($row['image'])) { $sql = "SELECT * FROM attachments WHERE filename='".str_replace("/upload/",'',$row['image'])."'"; $rs = $this->db->query($sql); $row = $rs->fetch(); $this->view->att = $row; } $sql="select * from news_category 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 '
发布失败:
    '; echo '
  1. 参数错误
  2. '. '
'; } $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 '
发布失败:
    '; foreach ($msg as $v) { echo '
  1. '.$v.'
  2. '; } echo'
'; } 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 '
发布成功!
'; }else{ echo '
发布失败!写入附加表出错,请联系管理员
'; } }catch(Exception $e){ echo '
文章发布失败:
  1. '.$e->getMessage().'
'; } } }// 文章编辑 function deleteAction(){ $id = $this->_request->getParam('id'); $sql = "DELETE FROM news_archives WHERE id='$id'"; $this->db->exec($sql); $this->messenger->addMessage('提示信息:文章删除成功!'); $this->_redirect('/admin/news/newslist'); }//文章删除 function uploadAction(){ try{ $auth = Zend_Auth::getInstance(); if($auth->hasIdentity()) { $user = $auth->getIdentity(); $userid = $user->id; } include_once('files.php'); $files=new files(); $msg = $files -> upload('../htdocs/upload/',$_FILES['Filedata'],'image'); if(empty($msg['error'])) { $msg['error']=""; $filename = $msg['db_path']; $filesize = $msg['file_size']; $filedesc = $this->_request->getParam('filedesc'); $filetype = 'thumb'; $realname = $msg['realname']; $fileurl = $msg['file_url']; $sql = "insert into attachments (filename,filetype,filedesc,userid,filesize,realname) values ('$filename','$filetype','$filedesc','$userid','$filesize','$realname') RETURNING id"; $sth = $this->db->prepare($sql); $sth->execute(); $att = $sth->fetch(PDO::FETCH_ASSOC); $msg['attid'] = $attid = $att['id']; $imgct = files::getImageType('../htdocs/upload/'.$filename); if(!isset($imgct['error'])) $preview = ''; else $preview = ""; $msg['html'] = $preview.$realname.'[已完成]
'; $msg['preview'] = "/images/".$attid; echo Zend_Json::encode($msg); exit(); }else{ $msg['error'] = '附件上传失败:'.$msg['error']; @unlink($filename); echo Zend_Json::encode($msg); exit(); } }catch(Exception $e){ $msg['error'] = "错误:".$e->getMessage(); echo Zend_Json::encode($msg); exit(); } } function getattsAction(){ $this->_helper->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $id = $this->_request->getParam('id'); if($id!='') { $auth = Zend_Auth::getInstance(); if($auth->hasIdentity()) { $sql = "select att.realname,att.id,att.filename from attachments att left join archives_att ratt on att.id=ratt.attid where ratt.arcid=$id"; $rs = $this->db->query($sql); $atts = $rs->fetchAll(); include_once('files/files.php'); foreach($atts as $k=>$v) { $imgct = files::getImageType('../htdocs/upload/'.$v['filename']); if(!isset($imgct['error'])) $preview = ''; else $preview = ""; $atts[$k]['html']= $preview.$v['realname'].'[已完成]
'; } echo Zend_Json::encode($atts); exit(); }else { exit(); } }else{ exit(); } } function delattAction(){ $this->_helper->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $id = $this->_request->getParam('id'); $aid = $this->_getParam('aid'); $basepath = '../htdocs/upload/'; $info = $this->getFileinfo($id); $filepath = $basepath.$info['filename']; try{ if(empty($aid)) { $sql = "DELETE FROM attachments WHERE id=$id"; if($this->db->exec($sql)>0) { @unlink($filepath); } }else{ $sql = "delete from archives_att where attid='$id' and arcid='$aid'"; if($this->db->exec($sql)>0) { $sql = "DELETE FROM attachments WHERE id=$id"; if($this->db->exec($sql)>0){@unlink($filepath);} } } } catch(Exception $e){} } public function getFileinfo($id){ $sql = "select * from attachments where id='$id'"; $re= $this->db->query($sql); $row= $re->fetch(); return $row; } public function jsonexit($data){ $this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data)); return true; } }