PHPIndex

This page lists files in the current directory. You can view content, get download/execute commands for Wget, Curl, or PowerShell, or filter the list using wildcards (e.g., `*.sh`).

index.class.php
wget 'https://sme10.lists2.roe3.org/kodbox/plugins/officeViewer/controller/yzOffice/index.class.php'
View Content
<?php 
class officeViewerYzOfficeIndex extends Controller {
	public function __construct() {
		parent::__construct();
		$this->pluginName = 'officeViewerPlugin';
		$this->plugin = Action($this->pluginName);
        $this->_dir = __DIR__ . '/';
        $this->filePath = '';   // 解析后的文件路径
        $this->appName = LNG('officeViewer.yzOffice.name');
    }

    public function index(){
        if(!$this->plugin->allowExt('yz')) {
            $this->plugin->showTips(LNG('officeViewer.main.invalidExt'), $this->appName);
		}
        // 改地址需和yzOffice.class.php保持一致
        $header = url_header('https://www.yozodcs.com/');
        if(!$header || !$header['status']) {
        // if(!check_url('https://www.yozodcs.com/')) {
            $this->plugin->showTips(LNG('officeViewer.main.notNetwork'), $this->appName);
        }
        $app = $this->getObj();
		if(!$app->task['success'] ){
            if($link = $this->fileLink()) {
                $this->fileOutLink($app, $link);
            }
			include_once($this->_dir.'template.php');
			return;
		}
		//获取预览url
		$step     = count($app->task['steps']) - 1;
		$infoData = $app->task['steps'][$step]['result'];
		if($infoData['errorcode'] || !is_array($infoData['data']) ){
			$app->clearCache();
			$this->plugin->showTips($infoData['message'], $this->appName);
		}
        if(empty($infoData['data']['viewUrl'])) {
            $app->clearCache();
            $this->plugin->showTips(LNG('officeViewer.main.invalidUrl'), $this->appName);
        }
		$link = $infoData['data']['viewUrl'];
        $link = $this->fileLink($link);
        $this->fileOutLink($app, $link);
    }
    /**
     * viewUrl读取、更新和删除
     * @param boolean $link
     * @param boolean $del
     * @return void
     */
    private function fileLink($link = false, $del = false){
        $key = md5($this->pluginName . '.yzOffice.viewUrls');
        $data = Cache::get($key);
        if(!$data) $data = array();
        $info = IO::info($this->filePath);
        // $name = md5($info['path'] . (isset($info['fileID']) ? '_'.$info['fileID'] : ''));
        $name = md5(isset($info['fileID']) ? $info['fileID'] : $info['path'].'_'.$info['size']);
        if(!$link) {
            return isset($data[$name]) ? $data[$name] : false;
        }
        if($del) {
            unset($data[$name]);
        }else{
            $data[$name] = $link;
        }
        Cache::set($key, $data);
        return $link;

        $path = $this->_dir . 'data/';
		if(!is_dir($path)) mk_dir($path);
        $file = $path . 'viewurls.txt';
        if(@!file_exists($file) && !$link) return false;
        $data = file_get_contents($file);
        $data = json_decode($data, true);

        $info = IO::info($this->filePath);
        $name = md5($info['path'] . (isset($info['fileID']) ? '_'.$info['fileID'] : ''));
        if(!$link) {
            return isset($data[$name]) ? $data[$name] : false;
        }
        if($del) {
            unset($data[$name]);
        }else{
            $data[$name] = $link;
        }
        // 可能要加锁
        file_put_contents($file, json_encode_force($data));
        return $link;
    }
    // 链接可能已失效,输出前先判断
    private function fileOutLink($app, $link){
        $res = url_request($link);
		$data = json_decode($res['data'], true);

        // 没有错误(字符串decode结果为null),且set-cookie不为空(正常为viewpath=xxx,过期的为空),直接输出;否则删除缓存重新加载
        if(!$data && (!empty($res['header']['Set-Cookie']) || !empty($res['header']['set-cookie']))) {
            // header('Location:' . $link);
        } else {
            $app->clearCache();
            $this->fileLink($link, true);
            $link = this_url();
            // 最多重复运行3s,避免意外死循环
            $key = md5($link);
            $time = Cache::get($key);
            if ($time && (timeFloat() - $time) > 3) {
                Cache::remove($key);
                $msg = isset($data['message']) ? $data['message'] : LNG('officeViewer.yzOffice.linkExpired');
                $this->plugin->showTips($msg.LNG('officeViewer.main.tryAgain'), $this->appName);
            }
            Cache::get($key, timeFloat());
        }
        Action($this->pluginName)->showWebOffice('yz', $link);
        // header('Location:' . $link);
    }

	public function task(){
		$app = $this->getObj();
		$app->runTask();
	}
	public function getFile(){
		$app = $this->getObj();
		$app->getFile($this->in['file']);
	}
	private function getObj(){
        $path = $this->plugin->filePath($this->in['path']);
        $this->filePath = $path;
		require_once($this->_dir.'yzOffice.class.php');
		return new yzOffice($this->plugin, $path);
	}

	public function restart(){
		$app = $this->getObj();
		$res = $app->clearCache();
        $this->fileLink(true, true);
		show_json('success');
	}

}
template.php
wget 'https://sme10.lists2.roe3.org/kodbox/plugins/officeViewer/controller/yzOffice/template.php'
View Content
<!doctype html>
<head>
	<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=no" />
	<meta charset="utf-8">
	<?php $this->plugin->link();?>
	<title><?php echo clear_html($fileName);?></title>
	<style>
		body {margin: 0;font-family: "Helvetica Neue Light", "Segoe UI Semilight", sans-serif;}
		.infoButtonPrint{
			cursor: pointer;font-size:20px;right:60px;text-align:center;
			background:none;color: #666;line-height:27px;
		}
		.load-content{    
			position: fixed;
			overflow: hidden;z-index: 100;top:0;left:0;right:0;bottom:0;
			font-size:13px;color:#666;
		}
		.app-icon{text-align: center;position: absolute;left: 50%; top: 50%; transform: translate(-50%,-50%);}
		.app-icon img{max-height: 150px; width: 96px;}
		.app-icon .app-name{font-size:16px;color:#222;margin-top:5px;}
		.load-status{margin: 20px auto;}
		.load-status .progress{
			width:300px;height:30px;margin: 10px auto;position: relative;
			background-image: linear-gradient(to right,#ddd, #f6f6f6, #ddd);
		}
		.progress-loading{font-size:30px;margin-top: 20px;}
		.progress-slider .content{position: absolute;width: 100%;color:#29792c;font-size:12px;line-height:30px;}
		.progress-slider .left{float:left;padding-left: 10px;}
		.progress-slider .right{float:right;padding-right: 10px;}
		.progress-bar{opacity: 0.7;}
		.clear{clear:both;}
		.progress-text{text-align: center;display: block;width:300px;margin: 0 auto;padding: 10px;word-wrap: break-word;}
		@page {
			margin-left: 0px;
			margin-right: 0px;
			margin-top: 0px;
			margin-bottom: 0px;
			margin: 0;
			-webkit-print-color-adjust: exact;
		}

		body{background:#f0f0f0 !important;}
		div.word-body, div.ppt-body{background:#ff0;}
		div.word-page{box-shadow: 0 1px 6px #ccc;}
	</style> 
</head>
<body>
	<div class="load-content display">
		<div class="app-icon">
			<img src="<?php echo "{$this->plugin->pluginHost}/static/images/icon.png";?>" />
			<div class="app-name"><?php echo LNG('officeViewer.meta.name');?></div>
			<div class="load-status">
				<div class="progress-text alert"><?php echo LNG('officeViewer.yzOffice.transfer');?></div>
				<div class="progress-slider progress progress-striped active hidden">
					<div class="progress-bar progress-bar-success" role="progressbar" style="width:0%;"></div>	
					<div class="content">
						<span class="left"></span>
						<span class="right"></span>
						<div class="clear"></div>
					</div>
				</div>
				<div class="progress-loading hidden">
					<div class="moveCircleRight"><i class="ri-loader-line"></i></div>
				</div>
			</div>
		</div>
	</div>
	<div id="MyViewerDiv"></div>
</body>
	<script type="text/javascript">
		var LNG = {
			"error":"<?php echo LNG('explorer.error');?>",
			"success":"<?php echo LNG('explorer.success');?>",
			"officeViewer.yzOffice.transfer":"<?php echo LNG('officeViewer.yzOffice.transfer');?>",
			"officeViewer.yzOffice.converting":"<?php echo LNG('officeViewer.yzOffice.converting');?>",
			"officeViewer.yzOffice.uploadError":"<?php echo LNG('officeViewer.yzOffice.uploadError');?>",
			"officeViewer.yzOffice.convert":"<?php echo LNG('officeViewer.yzOffice.convert');?>",
			"officeViewer.yzOffice.transferAgain":"<?php echo LNG('officeViewer.yzOffice.transferAgain');?>"
		};
		var path     = '<?php echo clear_quote($this->plugin->in["path"]);?>';
		var apiBase  = "<?php echo $this->plugin->pluginApi;?>";//不能含有index.php
		var selfHost = '<?php echo $this->plugin->pluginHost;?>';
		var cacheFile= '<?php echo $config["cacheFile"];?>';
		var apiUrl = {
			task:apiBase+'yzOffice/index/task&path='+urlEncode(path),
			restart:apiBase+'yzOffice/index/restart&path='+urlEncode(path),
			getFile:apiBase+'yzOffice/index/getFile&path='+urlEncode(path)+'&file='
		}
		var request = function(){
			$('.load-content').fadeIn(100);
			$('.progress-text').removeClass('alert-danger').html(LNG['officeViewer.yzOffice.transfer']);
			$('.progress-bar').css('width',"0%");
			var repeatTimer;
			var taskStatus = function(){
				$.ajax({
					url:apiUrl.task+"&time"+UUID(),
					dataType:'json',
					success:function(data){
						statusUpdate(data);
					}
				});
			}
			var statusUpdate = function(data){
				if(!data) return;
				if(!data.code){
					var error = data.data;
					if(!_.isString(error)){
						error = LNG['error'];
					}
					clearInterval(repeatTimer);
					error += '&nbsp;&nbsp;<a class="load_repeat" href="javascript:void(0);">'
                			     + LNG['officeViewer.yzOffice.transferAgain']+'</a>';
					$('.progress-text').addClass('alert-danger').html(error);
					$('.progress-slider,.progress-loading').hide();
					return;
				}

				if(!data.data) return;
				if(data.data.success == 1){
					clearInterval(repeatTimer);
					var item = data.data.steps[data.data.steps.length-1];
					// $('.progress-text').html(LNG['success']+LNG['officeViewer.yzOffice.convert']);
					$('.progress-text').html(LNG['officeViewer.yzOffice.convert']);
					loadSuccess(data);
				}else{
					var step = data.data.steps[data.data.currentStep];
					var stepInfo = step.result;
					if(!_.isObject(stepInfo)){
						return;
					}
					$('.progress-text').removeClass('alert-danger');
					$('.progress-slider,.progress-loading').removeClass('hidden');
					if(step.name == 'upload'){
						$('.progress-text').html(LNG['officeViewer.yzOffice.transfer']);
						if(stepInfo === false){
							clearInterval(repeatTimer);
							loadError(LNG['officeViewer.yzOffice.uploadError']);
						}

						var sizeTotal = pathTools.fileSize(stepInfo.taskTotal);
						var sizeSuccess = pathTools.fileSize(stepInfo.taskFinished);
						var speed = pathTools.fileSize(stepInfo.taskSpeed)+'/s';
						$('.progress-slider .left').html(sizeSuccess+'/'+sizeTotal+' ('+speed+')');//12.6M/25.3M (1.2M/s)
						$('.progress-slider .right').html(_.floor((stepInfo.taskPercent*100),1)+"%");
						$('.progress-bar').css('width',(stepInfo.taskPercent*100)+"%");
					}else if(step.name == 'convertProcess'){
						$('.progress-slider').addClass('hidden');
						$('.progress-text').html(LNG['officeViewer.yzOffice.convert']);
					}
				}
			}
			clearInterval(repeatTimer);
			taskStatus();
			repeatTimer = setInterval(taskStatus,600);
		};
		var loadSuccess = function(data){
			window.location.reload();
		}
		var loadError = function(error){
			$('.progress-slider,.progress-loading').hide();
			error += '&nbsp;&nbsp;<a class="load_repeat" href="javascript:void(0);">'+
			LNG['officeViewer.yzOffice.transferAgain']+'</a>';
			$('.progress-text').addClass('alert-danger').html(error).css('text-align','left');
		}
		$(window).ready(function(){
			request();
			$('.load_repeat').live('click',function(){
				$.ajax({
					url:apiUrl.restart+"&time"+UUID(),
					dataType:'json',
					success:function(data){
						if(data.code){
							request();
						}
					}
				});
			});
		});
	</script>
</head>

yzOffice.class.php
wget 'https://sme10.lists2.roe3.org/kodbox/plugins/officeViewer/controller/yzOffice/yzOffice.class.php'
View Content
<?php
/*
* @link http://kodcloud.com/
* @author warlee | e-mail:kodcloud@qq.com
* @copyright warlee 2014.(Shanghai)Co.,Ltd
* @license http://kodcloud.com/tools/license/license.txt
*/
//官网用户demo
//https://www.yozodcs.com/page/example.html
class yzOffice{
	public $plugin;
	public $filePath;
	public $task;
	public $taskFile;
	public $api;

	public $cachePath;	// 缓存文件目录
	public $cacheTask;	// 任务信息缓存名称
	public function __construct($plugin,$filePath){
		$this->plugin = $plugin;
		$this->filePath = $filePath;

		$this->api = array(
			'upload'	=> "https://www.yozodcs.com/fcscloud/file/upload",
			'convert'	=> "https://www.yozodcs.com/fcscloud/composite/convert",
		);
		$this->cachePath = $this->plugin->cachePath;
		$this->cacheTask = md5($this->cachePath . IO::hashSimple($this->filePath));

		// 任务信息,如有缓存直接读取;否则读任务文件内容,存入缓存
		$this->taskFile = $this->cachePath.'info.json';
		if($this->task = Cache::get($this->cacheTask)) return;
		if($info = IO::infoFull($this->taskFile)){
			$this->taskFile = $info['path'];
			$taskHas = json_decode(IO::getContent($this->taskFile),true);
			$this->task = $taskHas;
			return Cache::set($this->cacheTask, $taskHas);
		}
		return $this->task = false;
	}
	public function runTask(){
		$task = array(
			'currentStep'	=> 0,
			'success'     	=> 0,
			'taskUuid'		=> md5($this->filePath.rand_string(20)),
			'hideData'		=> array(),
			'steps'	=> array(
				array('name'=>'upload','process'=>'uploadProcess','status'=>0,'result'=>''),
				array('name'=>'convert','process'=>'convert','status'=>0,'result'=>''),
			)
		);
		if(is_array($this->task)){
			$task = &$this->task;
		}else{
			$this->task = &$task;
		}

		$item  = &$task['steps'][$task['currentStep']];
		// write_log(array('永中任务----', $item));
		if($item['status'] == 0){
			$item['status'] = 1;
			if(!$item['process'] || 
				$item['name'] == $item['process']){ //单步没有定时检测;相等则自我查询进度;0=>2之间跳转
				$item['status'] = 0;
			}
			$this->saveData();
			$function = $item['name'];
			$result = $this->$function();
			if(isset($result['data'])){
				$item['result'] = $result['data'];
				$item['status'] = 2;
				$task['currentStep'] += 1;

				//最后一步完成
				if( $item['status'] == 2 &&  $task['currentStep'] > count($task['steps'])-1 ){
					$task['success'] = 1;
				}
				if($task['currentStep'] >= count($task['steps'])-1 ){
					$task['currentStep'] = count($task['steps'])-1;
				}
				$this->saveData();
			}else{
				$error = LNG('explorer.error');
				if(is_array($result) && $result['code'] == 100){
					$error = LNG('explorer.upload.error');
				}else if(is_array($result) && is_string($result['data']) ){
					$error = $result['data'];
				}
				show_json($error,false,$result);
			}
		}else if($item['status'] == 1){
			$function = $item['process'];
			if($function){
				$item['result'] = $this->$function();
				if($item['name'] == 'upload' && !$item['result']){
					show_json($item['result'],false);
				}
				$this->saveData();
			}
		}
		unset($task['hideData']);
		show_json($task);
	}
	public function saveData(){
		Cache::set($this->cacheTask, $this->task);
		if($this->taskSuccess($this->task)){
			$data = json_encode_force($this->task);
			return $this->plugin->pluginCacheFileSet($this->taskFile, $data);
		}
	}
	// 是否转换成功
	public function taskSuccess($taskHas){
		if(!is_array($taskHas)) return false;
		$lastStep = end($taskHas['steps']);
		return $lastStep['status'] == 2 ? $taskHas : false;
	}

	//非高清预览【返回上传后直接转换过的文件】
	public function upload(){
		ignore_timeout();
		// 上传文件至office服务器,先下载至本地,地址入缓存(进度和重启需要)
		// $path = IO::tempLocalFile($this->filePath);
		$path = $this->plugin->pluginLocalFile($this->filePath);
		$post = array(
			"file"			=> "@".$path,
		);
		$task = new TaskHttp($this->task['taskUuid'],'plugin.yzOffice.upload',filesize($path));
		$result = url_request($this->api['upload'],'POST',$post,false,false,true,3600);
		// write_log(array('永中上传----', $this->api['upload'], $result, $path));
		return is_array($result) && $result['data'] ? $result : false;
	}
	public function convert($tempFile=false){
		$headers = array("Content-Type: application/x-www-form-urlencoded; charset=UTF-8");
		$tempFile = $tempFile?$tempFile:$this->task['steps'][0]['result']['data']['data'];
		$postArr = array(
			'srcRelativePath'	=> $tempFile,
			'convertType'		=> 61,
			'isDccAsync'		=> 1,
			'isCopy'			=> 1,
			// 'time'				=> 1800
			'isShowTitle'		=> 0,	// 显示文件名
			'isDelSrc'			=> 1,	// 删除源文件
		);
		$post = http_build_query($postArr);//post默认用array发送;content-type为x-www-form-urlencoded时用key=1&key=2的形式
		$result = url_request($this->api['convert'],'POST',$post,$headers,false,true,3600);
		// write_log(array('永中转换----', $this->api['convert'], $result, $postArr));
		if(is_array($result) && is_array($result['data'])){
			return $result;
		}
		return false;
	}

	public function clearCache(){
		Cache::remove($this->cacheTask);
		Task::kill($this->task['taskUuid']);
		IO::remove($this->cachePath, false);
	}

	public function uploadProcess(){
		return Task::get($this->task['taskUuid']);
	}
	public function getFile($file){
		ignore_timeout();
		$ext = unzip_filter_ext(get_path_ext($file));
		$cacheFile = $this->cachePath.md5($file.'file').'.'.$ext;
		if($info = IO::infoFull($cacheFile)){
			return IO::fileOut($info['path']);
		}
		$step     = count($this->task['steps']) - 1;
		$infoData = $this->task['steps'][$step]['result'];
		$link = $infoData['data'][0];
		$linkFile = get_path_father($link) . str_replace('./','',$file);
		$result = url_request($linkFile,'GET',false);
		if($result['code'] == 200){
			$cacheFile = $this->plugin->pluginCacheFileSet($cacheFile, $result['data']);
			IO::fileOut($cacheFile);
		}
	}
}