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`).

controller
i18n
static
app.php
wget 'https://sme10.lists2.roe3.org/kodbox/plugins/officeViewer/app.php'
View Content
<?php

/**
 * office文件预览整合
 */
class officeViewerPlugin extends PluginBase{
	function __construct(){
		parent::__construct();
		$this->appList = array(
			'wb' => 'webOffice',
			'lb' => 'libreOffice',
			'ol' => 'officeLive',
			'yz' => 'yzOffice',
		);
	}
	public function regist(){
		$this->hookRegist(array(
			'user.commonJs.insert'	=> 'officeViewerPlugin.echoJs'
		));
	}
	public function echoJs(){
		$this->echoFile('static/app/main.js');
	}

	// 重置支持的文件格式
	public function onChangeStatus($status){
		if($status != '1') return;
		$config = $this->getConfig();
		if ($config['openType'] != 'js') return;

		$update = array(
			'openType' => 'wb',
			'fileExt' => 'doc,docx,xls,xlsx,ppt,pptx,csv',
		);
		$this->setConfig($update);
	}
	public function onSetConfig($config) {
		$openType = $config['openType'];
		if ($openType == 'js') {	// 兼容旧版
			$openType = 'wb';
			$config['openType'] = $openType;
		}
		$ext = 'doc,docx,xls,xlsx,ppt,pptx,csv';
		if (isset($config[$openType . 'FileExt'])) {
			$ext = $config[$openType . 'FileExt'];
		}
		$config['fileExt'] = $ext;
		return $config;
	}

	// 入口
	public function index(){
		// $path   = $this->filePath($this->in['path'],true,true);
		$path   = $this->filePathGet($this->in['path'],true);	// filePath和加载模板方式都会触发plugin.fileView,为免重复,不使用filePath获取
		if (!empty($this->fileInfo['fileID'])) {
			$info = Model('File')->fileInfo($this->fileInfo['fileID']);
			if(!$info || !IO::exist($info['path'])){
				$msg = LNG('common.pathNotExists').LNG('common.phyFileNotExists');
				show_tips($msg);
			}
		}
		if (!$this->fileInfo['size']) show_tips(LNG('officeViewer.main.fileSizeErr'));

		$config = $this->getConfig();
		$openType = isset($config['openType']) ? $config['openType'] : '';
		if ($openType == 'js') $openType = 'wb';	// 兼容旧版
		$types	= $openType == 'wb' ? array_keys($this->appList) : array($openType);
		// 过滤关闭的服务
		foreach ($types as $i => $type) {
			$open = $type.'Open';
			if (isset($config[$open]) && $config[$open] == '0') unset($types[$i]);
		}
		// 按顺序依次调用
		$skip 	= (isset($this->in['skip']) && $this->in['skip'] == 'wb') ? true : false;
		foreach ($this->appList as $type => $app) {
			if ($type == 'wb' && $skip) continue;
			if (!in_array($type, $types) || !$this->allowExt($type,true)) continue;
			if ($type == 'lb' && !$this->action($app)->getSoffice()) continue;
			if ($type == 'ol' && !$this->isNetwork()) continue;	// officelive,文件需为域名地址
			return $this->fileOut($app);
		}
		show_tips(LNG('officeViewer.main.invalidType'));
	}

	// 用不同的方式预览office文件
	public function fileOut($app){
		return $this->action($app)->index();
	}
	public function action($app){
		return Action($this->pluginName . "Plugin.{$app}.index");
	}

	// 获取各应用的配置参数
	public function _appConfig($type){
		$config = $this->getConfig();
		$data = array();
		foreach($config as $key => $value) {
			if(strpos($key, $type) === 0) {
				$k = lcfirst(substr($key, strlen($type)));
				$data[$k] = $value;
			}
		}
		return $data;
	}
	// 各打开方式支持的文件格式
	public function allowExt($type,$inlet=false){
		$ext = $this->in['ext'];
		$config = $this->getConfig();
		$extAll = explode(',', $config[$type.'FileExt']);
		if (!in_array($ext, $extAll)) return false;
		// 某些文件可能只是命名为旧格式,根据前2个字符(PK)区分
		if ($type == 'wb' && $inlet && in_array($ext, array('doc', 'ppt'))) {
			// 使用解析后的文件路径;打开压缩包内的doc文件直接用path会报错
			$prfx = IO::fileSubstr($this->fileInfo['path'], 0, 2); 
			return strtolower($prfx) == 'pk' ? true : false;
		}
		return true;
	}
	// 各打开方式错误提示
	public function showTips($msg, $title){
		$title = '<span style="font-size:20px;">'.LNG('officeViewer.meta.name')
				.'</span><span style="font-size:14px;margin-left:5px;"> - '.$title.'</span>';
		show_tips($msg, '', '', $title);
	}

	/**
	 * 可通过互联网访问
	 * @param boolean $domain	要求是域名
	 * @return void
	 */
	public function isNetwork($domain = true){
		// 1. 判断是否为域名
		$host = get_url_domain(APP_HOST);
		if($host == 'localhost') return false;
		if($domain && !is_domain($host)) return false;

		$key = md5($this->pluginName . '_kodbox_server_network_' . intval($domain) . '_' . $host);
		$check = Cache::get($key);
		if($check !== false) return (boolean) $check;
		$time = ($check ? 30 : 3) * 3600 * 24;	// 可访问保存30天,否则3天

		// 2. 判断外网能否访问
		$data = array('type' => 'network', 'url' => APP_HOST);
		$url = $GLOBALS['config']['settings']['kodApiServer'] . 'plugin/platform/';
		$res = url_request($url, 'POST', $data, false, false, false, 3);
		if(!$res || $res['code'] != 200 || !isset($res['data'])) {
			Cache::set($key, 0, $time);
			return false;
		}
		$res = json_decode($res['data'], true);

		$check = (boolean) $res['code'];
		Cache::set($key, (int) $check, $time);
		return $check;
	}

	/**
	 * 加载模板文件
	 */
	public function showWebOffice($app, $link=''){
		$path   = $this->in['path'];
		$assign = array(
			"fileUrl"	=> '',
			'filePath'	=> $path,
			'canWrite'	=> false,
			'fileName'	=> $this->in['name'],
			'fileApp'	=> $app, 
			'fileExt'	=> $this->in['ext']
		);
		if($path){
			if(substr($path,0,4) == 'http'){
				$assign['fileUrl'] = $path;
			}else{
				$assign['fileUrl']  = $this->filePathLink($path);
				if(ActionCall('explorer.auth.fileCanWrite',$path)){
					$assign['canWrite'] = true;
				}
			}
			$assign['fileUrl'] .= "&disable_name=1&name=/".$assign['fileName'];
		}
		if ($link) $assign['fileUrl'] = $link;
		$assign['LNG'] = $this->initLang();
		$this->assign($assign);
		$this->display($this->pluginPath.'static/weboffice/template.html');
	}

	/**
	 * 引入模板文件
	 * @param [type] $template
	 * @return void
	 */
	public function includeTpl($template){
		$LNG = $this->initLang();
		include($this->pluginPath.$template);
	}

	// 编辑方式
	public function editApp() {
		$data = Input::getArray(array(
			'path' => array('check' => 'require'),
			'name' => array('check' => 'require'),
			'ext'  => array('check' => 'require'),
		));

		$list = array();
		$appList = Model('Plugin')->loadList();
		$apps = array('wpsOffice','onlyoffice','officeOnline');	// 新页面打开,排除client方式
		foreach ($apps as $app) {
			if (!isset($appList[$app]) || !$appList[$app]['status']) continue;
			$config = $appList[$app]['config'];
			if (!$config['pluginAuth']) continue;
			$auth = ActionCall('user.authPlugin.checkAuthValue',$config['pluginAuth']);
			if (!$auth) continue;

			$fileExt  = $config['fileExt'];
			$fileSort = $config['fileSort'];
			$fileExt = explode(',', $fileExt);
			if (!in_array($data['ext'], $fileExt)) continue;

			$list[$app] = intval($fileSort);
		}
		if (!$list) show_json(LNG('officeViewer.main.typeErr'), false);
		arsort($list, SORT_NUMERIC);
		$app = key($list);	// 从当前指针位置返回键名(排序会重置指针)

		$link = urlApi('plugin/'.$app,'path='.$data['path']);
		$link .= '&ext='.rawurlencode($data['ext']).'&name='.rawurlencode($data['name']);
		show_json($link, true, $app);
	}
}

package.json
wget 'https://sme10.lists2.roe3.org/kodbox/plugins/officeViewer/package.json'
View Content
{
	"id":"officeViewer",
	"name":"{{LNG['officeViewer.meta.name']}}",
	"title":"{{LNG['officeViewer.meta.title']}}",
	"version":"1.34",
	"category":"file",
	"source":{
		"icon":"{{pluginHost}}static/images/icon.png"
	},
	"description":"{{LNG['officeViewer.meta.desc']}}",
	"auther":{
		"copyright":"kodcloud",
		"homePage":"http://kodcloud.com"
	},
	"networkDesc": "{{LNG['officeViewer.meta.netwrokDesc']}}",
	"configItem":{
		"formStyle":{
			"className":"form-box-title-left",
			"tabs":{
				"{{LNG['admin.setting.base']}}":"pluginAuth,sep001,openWith,fileSort,fileExt",
				"{{LNG['officeViewer.meta.service']}}":"openType,sep002,wbDesc,wbFileExt,lbOpen,lbSoffice,lbFileExt,olOpen,olApiServer,olFileExt,yzOpen,yzFileExt"
			},
			"loadFile":"{{pluginHost}}static/libreoffice/check.js"
		},
		"pluginAuth":{
			"type":"userSelect",
			"value":{"all":1},
			"display":"{{LNG['admin.plugin.auth']}}",
			"desc":"{{LNG['admin.plugin.authDesc']}}",
			"require":1
		},
		"sep001":"<hr/>",
		"openWith":{
			"type":"radio",
			"value":"dialog",
			"display":"{{LNG['admin.plugin.openWith']}}",
			"info":{
				"dialog":"{{LNG['admin.plugin.openWithDilog']}}",
				"window":"{{LNG['admin.plugin.openWithWindow']}}"
			}
		},
		"fileSort":{
			"type":"number",
			"display":"{{LNG['admin.plugin.fileSort']}}",
			"desc":"{{LNG['admin.plugin.fileSortDesc']}}",
			"value":1000
		},
		"fileExt":{
			"type":"tags",
			"display":"{{LNG['admin.plugin.fileExt']}}",
			"desc":"{{LNG['admin.plugin.fileExtDesc']}}",
			"className": "hidden",
			"value":"docx,doc,xlsx,xls,csv,pptx,ppt"
		},

		"openType":{
			"type":"segment",
			"value":"wb",
			"display":"{{LNG['officeViewer.meta.openType']}}",
			"info":{
				"wb":"{{LNG['officeViewer.webOffice.name']}}",	// WebOffice->自动解析
				"lb":"LibreOffice",
				"ol":"OfficeLive",
				"yz":"{{LNG['officeViewer.yzOffice.name']}}"
			},
			"switchItem":{
				"wb":"wbDesc,wbFileExt",
				"lb":"lbOpen,lbSoffice,lbFileExt",
				"ol":"olOpen,olApiServer,olFileExt",
				"yz":"yzOpen,yzFileExt"
			}
		},
		"sep002":"<hr/>",

		"wbDesc":{
			"type":"html",
			"display":"{{LNG['officeViewer.meta.instruction']}}",
			"desc":"{{LNG['officeViewer.webOffice.desc']}}"
		},
		"wbFileExt":{
			"type":"tags",
			"display":"{{LNG['admin.plugin.fileExt']}}",
			"desc":"{{LNG['admin.plugin.fileExtDesc']}}",
			"value":"docx,doc,xlsx,xls,csv,pptx,ppt"
		},

		"lbOpen":{
			"type":"switch",
			"value":1,
			"display":"{{LNG['officeViewer.meta.svcOpen']}}",
			"desc":"{{LNG['officeViewer.libreOffice.desc']}}",
			"switchItem":{"0":"","1":"lbSoffice,lbFileExt"}
		},
		"lbSoffice":{
			"type":"input",
			// "value":"/opt/libreoffice7.5/program/soffice",
			"value":"",
			"display":"{{LNG['officeViewer.libreOffice.path']}}",
			"desc":"{{LNG['officeViewer.libreOffice.pathDesc']}}"
		},
		"lbFileExt":{
			"type":"tags",
			"display":"{{LNG['admin.plugin.fileExt']}}",
			"desc":"{{LNG['admin.plugin.fileExtDesc']}}",
			"value":"doc,docx,ods,xls,xlsx,odt,ppt,pps,pptx,odp,rtf,csv,tsv"
		},

		"olOpen":{
			"type":"switch",
			"value":1,
			"display":"{{LNG['officeViewer.meta.svcOpen']}}",
			"desc":"{{LNG['officeViewer.officeLive.desc']}}",
			"switchItem":{"0":"","1":"olApiServer,olFileExt"}
		},
		"olApiServer":{
			"type":"input",
			"value":"https://view.officeapps.live.com/op/embed.aspx?src=",
			"display":"{{LNG['officeViewer.officeLive.apiServer']}}",
			"desc":"{{LNG['officeViewer.officeLive.apiServerDesc']}}",
			"require":1
		},
		"olFileExt":{
			"type":"tags",
			"display":"{{LNG['admin.plugin.fileExt']}}",
			"desc":"{{LNG['admin.plugin.fileExtDesc']}}",
			"value":"doc,docx,docm,dot,dotx,dotm,rtf,xls,xlsx,xlt,xlsb,xlsm,csv,ppt,pptx,pps,ppsx,pptm,potm,ppam,potx,ppsm,odt,ods,odp,ott,ots,otp,wps,wpt"
		},

		"yzOpen":{
			"type":"switch",
			"value":1,
			"display":"{{LNG['officeViewer.meta.svcOpen']}}",
			"desc":"{{LNG['officeViewer.yzOffice.desc']}}",
			"switchItem":{"0":"","1":"yzFileExt"}
		},
		"yzFileExt":{
			"type":"tags",
			"display":"{{LNG['admin.plugin.fileExt']}}",
			"desc":"{{LNG['admin.plugin.fileExtDesc']}}",
			"value":"doc,docx,docm,dot,dotx,dotm,rtf,wps,wpt,xls,xlsx,xlt,xlsm,csv,ppt,pptx,pps,ppsx"
		}
	}
}
readme.md
wget 'https://sme10.lists2.roe3.org/kodbox/plugins/officeViewer/readme.md'
View Content
##### 1.32 更新内容
- 功能调整
    - 增加前端解析提示;表格指定格式显示异常调整。

##### 1.31 更新内容
- 功能调整
    - 修改LibreOffice默认路径,适配TeamOS系统环境。