westdc-zf1/application/default/controllers/NewsController.php

143 lines
3.9 KiB
PHP
Raw Normal View History

<?php
class NewsController extends Zend_Controller_Action
{
private $limit=10;
function preDispatch()
{
$this->view->config = Zend_Registry::get('config');
$this->db=Zend_Registry::get('db');
$this->messenger=$this->_helper->getHelper('FlashMessenger');
$this->view->messages = $this->messenger->getMessages();
}
function indexAction()
{
2012-04-03 15:57:59 +00:00
$sql="select * from news_category order by displayorder asc";
$re = $this->db->query($sql);
$types = $re->fetchAll();
$this->view->types=$types;
$time = date("Y-m-d H:i:s",time());
2012-04-03 15:57:59 +00:00
$sql = "SELECT a.*,t.title as typetitle FROM news_archives a
left join news_catelogs cl on a.id=cl.aid
LEFT JOIN news_category t ON cl.cid=t.id
WHERE a.ts_published<'$time' AND is_pub>=1 ORDER BY ts_published DESC";
$rs = $this->db->query($sql);
$rows = $rs->fetchAll();
$page = $this->_request->getParam('page');
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($page);
$paginator->setItemCountPerPage($this->view->config->page->max);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
}
function listAction()
{
$type = strtolower($this->_request->getParam('type'));
$page = $this->_request->getParam('page');
if(preg_match("/archive\-(\d+)\.html/",$page,$matches))
{
$this->_forward('archive', 'news', null, array('archive' => $matches['1'] , 'type'=> $type));
}
else
{
if(preg_match("/[^a-z0-9]/",$type) || preg_match("/[^0-9]/",$page))
{
$this->_forward('error', 'error', null, null);
}
2012-04-03 15:57:59 +00:00
$sql = "SELECT a.id,a.title FROM news_category c
left join news_catelogs cl on c.id=cl.cid
left join news_archives a on cl.aid=a.id WHERE c.id='$type' ";
$rs = $this->db->query($sql);
$row = $rs->fetch();
if(empty($row['id']))
{
$this->_forward('error', 'error', null, null);
}
else{
$this->view->url = $row['url'];
$this->view->title = $row['title'];
$sql="select * from news_catlog order by displayorder asc";
$re = $this->db->query($sql);
$types = $re->fetchAll();
$this->view->types=$types;
$time = date("Y-m-d H:i:s",time());
$sql = "SELECT arc.*,c.url FROM news_archives arc
left join news_catlog c ON arc.typeid=c.id
WHERE arc.typeid='{$row['id']}' AND arc.ts_published<'".$time."' AND arc.pub>=1
ORDER BY arc.ts_published DESC";
$rs = $this->db->query($sql);
$rows = $rs->fetchAll();
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($page);
$paginator->setItemCountPerPage($this->view->config->page->max);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
}
}
}
function archiveAction()
{
$type = $this->_request->getParam('type');
$archive = $this->_request->getParam('archive');
$this->view->type = $type;
if(preg_match("/[^a-z0-9]/",$type) || preg_match("/[^0-9]/",$archive))
{
$this->_forward('error', 'error', null, null);
}
$sql="select * from news_catlog order by displayorder asc";
$re = $this->db->query($sql);
$types = $re->fetchAll();
$this->view->types=$types;
$time = date("Y-m-d H:i:s",time());
$sql = "SELECT arc.*,addon.* FROM news_archives arc";
$sql .= " LEFT JOIN news_catlog type ON arc.typeid=type.id";
$sql .= " LEFT JOIN news_archivesaddon addon ON arc.id=addon.id";
$sql .= " WHERE arc.pub>0 AND ts_published<'$time' AND arc.id=$archive";
$rs = $this->db->query($sql);
$row = $rs->fetch();
if(empty($row['id']))
{
$this->_forward('error', 'error', null, null);
}
$this->view->infos = $row;
}
function searchAction()
{
}
}