added elfinder module

This commit is contained in:
2018-12-04 20:35:06 +01:00
parent 1b53514906
commit ccab226e12
223 changed files with 97254 additions and 0 deletions

View File

@@ -0,0 +1,112 @@
<?php
class elFinderEditorOnlineConvert extends elFinderEditor
{
protected $allowed = array('init', 'api');
public function enabled()
{
return !defined('ELFINDER_DISABLE_ONLINE_CONVERT') || !ELFINDER_DISABLE_ONLINE_CONVERT;
}
public function init()
{
return array('api' => defined('ELFINDER_ONLINE_CONVERT_APIKEY') && ELFINDER_ONLINE_CONVERT_APIKEY && function_exists('curl_init'));
}
public function api()
{
// return array('apires' => array('message' => 'Currently disabled for developping...'));
$endpoint = 'https://api2.online-convert.com/jobs';
$category = $this->argValue('category');
$convert = $this->argValue('convert');
$options = $this->argValue('options');
$source = $this->argValue('source');
$filename = $this->argValue('filename');
$mime = $this->argValue('mime');
$jobid = $this->argValue('jobid');
$string_method = '';
$options = array();
// Currently these converts are make error with API call. I don't know why.
$nonApi = array('android','blackberry','dpg','ipad','iphone','ipod','nintendo-3ds','nintendo-ds','ps3','psp','wii','xbox');
if (in_array($convert, $nonApi)) {
return array('apires' => array());
}
$ch = null;
if ($convert && $source) {
$request = array(
'input' => array(array(
'type' => 'remote',
'source' => $source
)),
'conversion' => array(array(
'target' => $convert
))
);
if ($filename !== '') {
$request['input'][0]['filename'] = $filename;
}
if ($mime !== '') {
$request['input'][0]['content_type'] = $mime;
}
if ($category) {
$request['conversion'][0]['category'] = $category;
}
if ($options && $options !== 'null') {
$options = json_decode($options, true);
}
if (!is_array($options)) {
$options = array();
}
if ($options) {
$request['conversion'][0]['options'] = $options;
}
$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($request));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-Oc-Api-Key: ' . ELFINDER_ONLINE_CONVERT_APIKEY,
'Content-Type: application/json',
'cache-control: no-cache'
));
} else if ($jobid) {
$ch = curl_init($endpoint . '/' . $jobid);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-Oc-Api-Key: ' . ELFINDER_ONLINE_CONVERT_APIKEY,
'cache-control: no-cache'
));
}
if ($ch) {
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$error = curl_error($ch);
curl_close($ch);
if (! empty($error)) {
$res = array('error' => $error);
} else {
$data = json_decode($response, true);
if (isset($data['status']) && isset($data['status']['code']) && $data['status']['code'] === 'completed') {
$session = $this->elfinder->getSession();
$urlContentSaveIds = $session->get('urlContentSaveIds', array());
$urlContentSaveIds['OnlineConvert-'.$data['id']] = true;
$session->set('urlContentSaveIds', $urlContentSaveIds);
}
$res = array('apires' => $data);
}
return $res;
} else {
return array('error' => array('errCmdParams', 'editor.OnlineConvert.api'));
}
}
}

View File

@@ -0,0 +1,12 @@
<?php
class elFinderEditorZipArchive extends elFinderEditor
{
public function enabled()
{
return (!defined('ELFINDER_DISABLE_ZIPEDITOR') || !ELFINDER_DISABLE_ZIPEDITOR) &&
class_exists('Barryvdh\elFinderFlysystemDriver\Driver') &&
class_exists('League\Flysystem\Filesystem') &&
class_exists('League\Flysystem\ZipArchive\ZipArchiveAdapter');
}
}

View File

@@ -0,0 +1,136 @@
<?php
class elFinderEditorZohoOffice extends elFinderEditor
{
private static $curlTimeout = 20;
protected $allowed = array('init', 'save');
private $urls = array(
'writer' => 'https://writer.zoho.com/writer/remotedoc.im',
'sheet' => 'https://sheet.zoho.com/sheet/remotedoc.im',
'show' => 'https://show.zoho.com/show/remotedoc.im',
);
private $srvs = array(
'application/msword' => 'writer',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'writer',
'application/pdf' => 'writer',
'application/vnd.oasis.opendocument.text' => 'writer',
'application/rtf' => 'writer',
'text/html' => 'writer',
'application/vnd.ms-excel' => 'sheet',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'sheet',
'application/vnd.oasis.opendocument.spreadsheet' => 'sheet',
'application/vnd.sun.xml.calc' => 'sheet',
'text/csv' => 'sheet',
'text/tab-separated-values' => 'sheet',
'application/vnd.ms-powerpoint' => 'show',
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'show',
'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'show',
'application/vnd.oasis.opendocument.presentation' => 'show',
'application/vnd.sun.xml.impress' => 'show',
);
public function enabled()
{
return defined('ELFINDER_ZOHO_OFFICE_APIKEY') && ELFINDER_ZOHO_OFFICE_APIKEY && function_exists('curl_init');
}
public function init()
{
if (!defined('ELFINDER_ZOHO_OFFICE_APIKEY') || !function_exists('curl_init')) {
return array('error', array(elFinder::ERROR_CONF, '`ELFINDER_ZOHO_OFFICE_APIKEY` or curl extension'));
}
if (!empty($this->args['target'])) {
$fp = $cfile = null;
$hash = $this->args['target'];
if (($srcVol = $this->elfinder->getVolume($hash)) && ($file = $srcVol->file($hash))) {
if ($size = $file['size']) {
$src = $srcVol->open($hash);
$fp = tmpfile();
stream_copy_to_stream($src, $fp);
$srcVol->close($src, $hash);
$info = stream_get_meta_data($fp);
if ($info && !empty($info['uri'])) {
$srcFile = $info['uri'];
if (class_exists('CURLFile')) {
$cfile = new CURLFile($srcFile);
$cfile->setPostFilename($file['name']);
$cfile->setMimeType($file['mime']);
} else {
$cfile = '@'.$srcFile;
}
}
}
//$srv = $this->args['service'];
$format = $srcVol->getExtentionByMime($file['mime']);
if (!$format) {
$format = substr($file['name'], strrpos($file['name'], '.') * -1);
}
$cdata = empty($this->args['cdata']) ? '' : $this->args['cdata'];
$lang = $this->args['lang'];
if ($lang === 'jp') {
$lang = 'ja';
}
$srvsName = $this->srvs[$file['mime']];
$data = array(
'apikey' => ELFINDER_ZOHO_OFFICE_APIKEY,
'output' => 'url',
'mode' => 'normaledit',
'filename' => $file['name'],
'id' => $hash,
'format' => $format,
'lang' => $lang,
'saveurl' => elFinder::getConnectorUrl().'?cmd=editor&name=ZohoOffice&method=save'.$cdata,
);
if ($cfile) {
$data['content'] = $cfile;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->urls[$srvsName]);
curl_setopt($ch, CURLOPT_TIMEOUT, self::$curlTimeout);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$res = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
$fp && fclose($fp);
if ($res) {
if (strpos($res, 'RESULT=TRUE') !== false) {
list(, $url) = explode('URL=', $res);
preg_match('/URL=([^\s]+)/', $res, $m);
return array('zohourl' => $m[1]);
} else {
$error = $res;
}
}
if ($error) {
return array('error' => preg_split('/[\r\n]+/', $error));
}
}
}
return array('error' => array('errCmdParams', 'editor.ZohoOffice.init'));
}
public function save()
{
if (isset($_POST) && ! empty($_POST['id'])) {
$hash = $_POST['id'];
if ($volume = $this->elfinder->getVolume($hash)) {
$content = file_get_contents($_FILES['content']['tmp_name']);
if ($volume->putContents($hash, $content)) {
return array('raw' => true, 'error' => '', 'header' => 'HTTP/1.1 200 OK');
}
}
}
return array('raw' => true, 'error' => '', 'header' => 'HTTP/1.1 500 Internal Server Error');
}
}

View File

@@ -0,0 +1,64 @@
<?php
/**
* Abstract class of editor plugins.
*
* @author Naoki Sawada
*/
class elFinderEditor
{
/**
* Array of allowed method by request from client side.
*
* @var array
*/
protected $allowed = array();
/**
* Constructor.
*
* @param object $elfinder
* @param array $args
*/
public function __construct($elfinder, $args)
{
$this->elfinder = $elfinder;
$this->args = $args;
}
/**
* Return boolean that this plugin is enabled.
*
* @return bool
*/
public function enabled()
{
return true;
}
/**
* Return boolean that $name method is allowed.
*
* @param string $name
*
* @return bool
*/
public function isAllowedMethod($name)
{
$checker = array_flip($this->allowed);
return isset($checker[$name]);
}
/**
* Return $this->args value of the key
*
* @param string $key target key
* @param string $empty empty value
*
* @return mixed
*/
public function argValue($key, $empty = '')
{
return isset($this->args[$key])? $this->args[$key] : $empty;
}
}