<?php
class PluginsController extends Easy_Controller_Action {
	public function xunleiAction(){
		$server = new ServerModel();
		$xunlei = new Xunlei();
		$this->_View->stime = @file_get_contents(ROOT.'xunlei.log');
		$etime = strtotime($this->_View->stime) ? time() : (strtotime($this->_View->stime)+86400);
		$this->_View->etime = date('Y-m-d', $etime);
		if ($this->_Request->getParams('etime')){
			if (strtotime($this->_Request->getParams('etime')) > time()){
				$this->_View->message = _('结束日期不能大于当前日期!');
				exit($this->_View->render('message'));
			}else{
				if ($xunlei->import() === true ){
					$total = $this->_Request->getParam('num');
					$this->_View->subject = _('导入第一步成功');
					$this->_View->message = _('导入成功!共导入'.$total);
					$this->_View->button = _('点击进入分类转换');
					$this->_View->jumpurl = $this->_View->installdir.'plugins/changecategory/';
					exit($this->_View->render('message'));
				}
			}
		}elseif ($this->_Request->getParam('uri')){
			$this->_View->subject = _('迅雷资源入口');
			
			$uri = base64_decode($this->_Request->getParam('uri'));
			$stime = preg_replace('/(.+)\/stime\/([\d\-]+)\/(.+)/is','$2', $uri);
			$this->_View->message = _('正在导入!'.$stime.'号影片。3秒后自动导入下一天影片');
			$this->_View->button = _('点击导入下一天影片');
			$this->_View->jumpurl = $uri;
			$this->_View->meta = '<meta http-equiv="Refresh" content="3;URL='.$uri.'" />';
			exit($this->_View->render('message'));
		}
		$this->_View->serverOption = $server->CreateOption();
	}
	public function changecategoryAction(){
		$this->_View->cate = new  CategoryModel();
		if ($this->_Request->getPost('do') == 'next'){
			$num = $this->_View->cate->catergoryMerge($this->_Request->getPost('old'),$this->_Request->getPost('new') );
			$this->_View->message = _('合并成功!更改了'.$num.'条记录!');
			if (file_exists(ROOT.'Cache/xunlei/category.log')){
				@unlink(ROOT.'Cache/xunlei/category.log');
			}
			exit($this->_View->render('message'));
		}else{
			$this->_View->CategoryOption = $this->_View->cate->CreateOption(0,0);
			$contents = trim(@file_get_contents(ROOT.'Cache/xunlei/category.log'));
			$this->_View->Category = array_unique(explode("\n", $contents));
		}
	}
	public function caijiAction(){
		$caiji = new CaijiModel();
		$caiji->get();
	}
}
?>