📄 makecontroller.php
字号:
<?php
/*
秀影EasyFramework框架
qq:24498936
msn:jdzcn_net@hotmail.com
website:http://www.vodcms.com
*/
class MakeController extends Easy_Controller_Action {
public function init(){
$this->path = $this->_View->getViewRoot();
$this->_View->skin = $this->config['template'];
$this->_View->moviearea = $this->mconf['area'];
$this->_View->config = $this->config;
$this->_View->Template = new Template(); //
}
public function indexAction(){
if ($this->_Request->getPost('makeindex')){
$this->_View->setViewRoot( 'templates' );
$this->_View->location = _('站点首页');
$this->_View->installdir = $this->config['basedir'].'index.php';
$GLOBALS['config']['rewrite'] = 'html';
$content = $this->_View->render($this->_View->skin.'/index');
$IO = new Easy_Filesystem();
if ( $IO->wFile(ROOT.'index.htm', $content)===false){
$this->_View->subject = _('首页生成失败!');
$this->_View->message = $IO->error;
}else{
$this->_View->message = _('首页生成成功!');
}
unset($content);
$this->_View->setViewRoot($this->path);
exit($this->_View->render('message'));
}elseif($this->_Request->getPost('delete')){
@unlink(ROOT.'index.htm');
$this->_View->setViewRoot($this->path);
$this->_View->message = _('首页删除成功!');
exit($this->_View->render('message'));
}
$this->_View->setViewRoot($this->path);
}
public function categoryAction(){
$category = new CategoryModel();
$movie = new MovieModel();
$make = new MakeModel();
$IO = new Easy_Filesystem();
$make->view = &$this->_View;
$this->_View->category = $category->CreateOption(0,0);
if( $this->_Request->getParam('do') == 'yes' ){
$GLOBALS['config']['rewrite'] = 'html';
$categoryid = intval($this->_Request->getParams('id'));
$total = intval($this->_Request->getParams('total'));
$subid = intval($this->_Request->getParams('subid'));
$all = $this->_Request->getParam('all');
$make->view->installdir = $this->config['basedir'].'index.php';
$make->view->config['rewrite'] = 'html'; //临时生成伪静态
if ($categoryid > 0 || $all == 'yes') { //如果用户提交的分类ID存在
if ($all == 'yes'){ //生成全部页面时
$rows = $category->getChilds(0);
}else{
$rows = $category->getChilds($categoryid);
}
if ($subid){
$index = array_search($subid, $rows);
$id = $subid;
}else{
$index = 0 ;
$id = $rows[0];
}
if ($id){
$this->_View->setViewRoot('templates');
$allrows = $movie->search(array('category'=> $id), false, 0, 'a.movid');
$totals = count($allrows); //分类总影片数
$pagesize = ceil($totals / $this->config['pagesize']);
$page = 1;
$loading = $pingjun;
while( $page <= $pagesize){
@set_time_limit(999);
$contents = $make->makeCategory($id, $page);
$path = str_replace('{id}', $id, $this->config['crewrite']);
$path = str_replace('{page}', $page, $path);
$IO->makedir(dirname($path));
$filename = ROOT.$path;
if ($IO->wfile($filename, $contents)===false){
echo '生成文件'.$filename.' 失败<br />';
echo $IO->error;
exit;
}
unset($contents, $filename, $path);
$total ++;
$page++;
}
$nextid = $rows[$index+1];
if ($nextid){
$this->_View->setViewRoot($this->path);
$row = $category->getRow( array('id'=> $nextid));
$this->_View->subject = _('分类静态页面生成');
$this->_View->message = _('正在生成分类名:'.$row['category'].'ID:'.$nextid.'的页面文件!');
$this->_View->button = _('点击这里手动继续!');
$this->_View->meta = '<meta http-equiv="refresh" content="1;URL='.INSTALLDIR.'?mod=make&action=category&do=yes&id='.$categoryid.'&subid='.$nextid.'&total='.$total.'&all='.$all.'" />';
$this->_View->jumpurl = INSTALLDIR.'?mod=make&action=category&do=yes&id='.$categoryid.'&subid='.$nextid.'&total='.$total.'&all='.$all;
exit($this->_View->render('message'));
}
}
$this->_View->setViewRoot($this->path);
$this->_View->subject = _('分类静态页面生成');
$this->_View->message = _('页面生成成功!共生成'.$total.'个文件');
$this->_View->jumpurl = INSTALLDIR.'?mod=make&action=category';
exit($this->_View->render('message'));
}
echo 'd';
exit;
}
$this->_View->setViewRoot($this->path);
}
/*影片页面生成*/
public function viewAction(){
$cate = new CategoryModel();
$movie = new MovieModel();
$make = new MakeModel();
$IO = new Easy_Filesystem();
$make->view = &$this->_View;
$GLOBALS['config']['rewrite'] = 'html';
$make->view->installdir = $this->config['basedir'].'index.php';
$this->_View->category = $cate->CreateOption(0,0);
if ($this->_Request->getParam('do') == 'yes'){
$where = array();
$maxpage = 30; //每生成100个页面就刷新一次页面防止超时
$max = intval($this->_Request->getParams('max'));
$total = (int)$this->_Request->getParams('total');
$pagesize = $this->_Request->getParams('pagesize') ? intval($this->_Request->getParams('pagesize')) : 1;
$where['looked'] = 0;
$limit = ($pagesize-1)*$maxpage.','.$maxpage;
$categoryid = (int)$this->_Request->getParams('category');
if ( $categoryid > 0 ){
$where['category'] = $categoryid;
$allrows = $movie->Search($where, false,$limit,'a.movid as movid, a.addtime as addtime');
}elseif ( (int)$this->_Request->getParams('max')>0 ){
$allrows = $movie->Search($where,false, (int)$this->_Request->getPost('max') ,'a.movid as movid, a.addtime as addtime');
}else{
$allrows = $movie->Search($where,false, $limit ,'a.movid as movid, a.addtime as addtime');
}
foreach ($allrows as $row){
$total++;
$contents = $make->makeMovie($row['movid']);
$path = str_replace('{movid}', $row['movid'], $this->config['mrewrite']);
$path = str_replace('{date}', date('Ymd', $row['addtime']), $path);
$IO->makedir(dirname($path));
$filename = ROOT.$path;
if ($IO->wfile($filename, $contents)===false){
echo '生成文件'.$filename.' 失败<br />';
echo $IO->error;
exit;
}
}
if ( count($allrows) < $maxpage){ //如果记录数小于50
$this->_View->setViewRoot($this->path);
$this->_View->subject = _('影片静态页面生成');
$this->_View->message = _('页面生成成功!共生成'.$total.'个文件');
$this->_View->jumpurl = INSTALLDIR.'?mod=make&action=view';
exit($this->_View->render('message'));
}else{
$this->_View->setViewRoot($this->path);
$this->_View->subject = _('影片静态页面生成');
$this->_View->message = _('正在生成下'.$maxpage.'个影片页面文件!');
$this->_View->button = _('点击这里手动继续!');
$this->_View->meta = '<meta http-equiv="refresh" content="1;URL='.$this->config['basedir'].'admin.php?mod=make&action=view&do=yes&category='.(int)$categoryid.'&max='.$max.'&total='.$total.'&pagesize='.($pagesize+1).' />';
$this->_View->jumpurl = $this->config['basedir'].'admin.php?mod=make&action=view&do=yes&category='.(int)$categoryid.'&max='.$max.'&total='.$total.'&pagesize='.($pagesize+1);
exit($this->_View->render('message'));
}
}
$make->view->installdir = $this->config['basedir'].'admin.php';
$this->_View->setViewRoot($this->path);
}
/*公告生成*/
public function noteAction(){
$this->_View->setViewRoot($this->path);
if ($this->_Request->isPost()){
$note = new AfficheModel();
$data = null;
foreach($note->getAll() as $row){
$data.='<li>·<a href=\"javascript:vote(\''.$this->config['basedir'].'index.php\', '.$row['id'].')\">'.$row['title'].' / '.date('Y-m-d', $row['addtime']).'</a></li>';
}
$IO = new Easy_Filesystem(ROOT);
$data = 'document.write("<div id=\"scrollDiv\"><ul>'.$data.'</ul></div>");';
if ($IO->wFile(ROOT.'js/note.js', $data) === false){
$this->_View->subject = _('生成公告失败!');
$this->_View->message = $IO->error;
}else{
$this->_View->message = _('生成公告生成!');
}
exit($this->_View->render('message'));
}
}
/*站点地图生成*/
public function sitemapAction(){
if ($this->_Request->isPost()){
@set_time_limit(999);
$category = new CategoryModel();
$movie = new MovieModel();
$IO = new Easy_Filesystem();
$IO->delete(ROOT.'sitemap.xml'); //删除老的sitemap
$urlnum = 0;
$xml = '<?xml version="1.0" encoding="UTF-8"?>'."\n\r";
$xml.= '<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
'."\n\r";
$xml.= '<url>';
$xml.= '<loc>'.$this->config['domain'].$this->config['basedir'].'index.php</loc>';
$xml.= '<lastmod>'.date('Y-m-d').'</lastmod>';
$xml.= '<changefreq>daily</changefreq>';
$xml.= '<priority>0.8</priority>';
$xml.= '</url>';
foreach($category->getAll(array('locked'=>0)) as $row){
$allrows = $movie->Search(array('category'=> $id), false, 0, 'a.movid');
$total = count($allrows);
$pagesize = ceil($total / $this->config['pagesize']);
$page = 1;
while($page <= $pagesize){
$xml.= '<url>'."\n\r";
$xml.= '<loc>'.$this->config['domain'].htmlentities(clink($row['id'], $page)).'</loc>'."\n\r";
$xml.= '<lastmod>'.date('Y-m-d').'</lastmod>'."\n\r";
$xml.= '<changefreq>weekly</changefreq>'."\n\r";
$xml.= '<priority>0.7</priority>'."\n\r";
$xml.= '</url>'."\n\r";
$IO->wFile(ROOT.'sitemap.xml', $xml, 'a'); //追加模式写入
unset($xml);
$page++;
++$urlnum;
}
}
unset($row);
$where = array();
$where['locked'] = 0;
$allrows = $movie->Search($where,0,0, 'a.movid as movid,a.addtime as addtime,a.modifytime as modifytime');
foreach ($allrows as $row){
$modifytime = $row['modifytime'] ? $row['modifytime'] : $row['addtime'];
$xml.= '<url>'."\n\r";
$xml.= '<loc>'.$this->config['domain'].htmlentities(mlink($row['movid'], $row['addtime'])).'</loc>'."\n\r";
$xml.= '<lastmod>'.date('Y-m-d',$modifytime).'</lastmod>'."\n\r";
$xml.= '<changefreq>weekly</changefreq>'."\n\r";
$xml.= '<priority>0.8</priority>'."\n\r";
$xml.= '</url>'."\n\r";
$IO->wFile(ROOT.'sitemap.xml', $xml, 'a'); //追加模式写入
unset($xml);
++$urlnum;
}
unset($row, $allrows);
if ($IO->wFile(ROOT.'sitemap.xml', '</urlset>', 'a')===false){ //追加模式写入
$this->_View->subject = _('生成sitemap失败');
$this->_View->message = $IO->error;
}else{
$this->_View->message = _('站点地图生成成功!共有连接'.$urlnum);
}
exit($this->_View->render('message'));
}
}
}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -