: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
class elFinderEditorZohoOffice extends elFinderEditor
private static $curlTimeout = 20;
protected $allowed = array('init', 'save', 'chk');
protected $editor_settings = array(
'writer' => 'https://api.office-integrator.com/writer/officeapi/v1/document',
'sheet' => 'https://api.office-integrator.com/sheet/officeapi/v1/spreadsheet',
'show' => 'https://api.office-integrator.com/show/officeapi/v1/presentation',
'application/msword' => 'writer',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'writer',
'application/pdf' => 'writer',
'application/vnd.oasis.opendocument.text' => 'writer',
'application/rtf' => '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/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',
protected function extentionNormrize($extention, $srvsName) {
if (!in_array($extention, array('zdoc', 'docx', 'rtf', 'odt', 'html', 'txt'))) {
if (!in_array($extention, array('zsheet', 'xls', 'xlsx', 'ods', 'csv', 'tsv'))) {
if (!in_array($extention, array('zslides', 'pptx', 'pps', 'ppsx', 'odp', 'sxi'))) {
public function __construct($elfinder, $args)
parent::__construct($elfinder, $args);
$this->myName = preg_replace('/^elFinderEditor/i', '', get_class($this));
public function enabled()
return defined('ELFINDER_ZOHO_OFFICE_APIKEY') && ELFINDER_ZOHO_OFFICE_APIKEY && function_exists('curl_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'])) {
$hash = $this->args['target'];
/** @var elFinderVolumeDriver $srcVol */
if (($srcVol = $this->elfinder->getVolume($hash)) && ($file = $srcVol->file($hash))) {
$cdata = empty($this->args['cdata']) ? '' : $this->args['cdata'];
$cookie = $this->elfinder->getFetchCookieFile();
$conUrl = elFinder::getConnectorUrl();
curl_setopt($ch, CURLOPT_URL, $conUrl . (strpos($conUrl, '?') !== false? '&' : '?') . 'cmd=editor&name=' . $this->myName . '&method=chk&args[target]=' . rawurlencode($hash) . $cdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
if ($data = json_decode($res, true)) {
$save = !empty($data['cansave']);
if ($size = $file['size']) {
$src = $srcVol->open($hash);
stream_copy_to_stream($src, $fp);
$srcVol->close($src, $hash);
$info = stream_get_meta_data($fp);
if ($info && !empty($info['uri'])) {
if (class_exists('CURLFile')) {
$cfile = new CURLFile($srcFile);
$cfile->setPostFilename($file['name']);
$cfile->setMimeType($file['mime']);
//$srv = $this->args['service'];
$srvsName = $this->srvs[$file['mime']];
$format = $this->extentionNormrize($srcVol->getExtentionByMime($file['mime']), $srvsName);
$format = substr($file['name'], strrpos($file['name'], '.') * -1);
$lang = $this->args['lang'];
'apikey' => ELFINDER_ZOHO_OFFICE_APIKEY,
'callback_settings' => array(
'save_format' => $format,
'save_url_params' => array(
'editor_settings' => $this->editor_settings[$srvsName],
'document_info' => array(
'document_name' => substr($file['name'], 0, strlen($file['name']) - strlen($format)- 1)
$data['editor_settings']['language'] = $lang;
$conUrl = elFinder::getConnectorUrl();
$data['callback_settings']['save_url'] = $conUrl . (strpos($conUrl, '?') !== false? '&' : '?') . 'cmd=editor&name=' . $this->myName . '&method=save' . $cdata;
foreach($data as $_k => $_v) {
$data[$_k] = json_encode($_v);
$data['document'] = $cfile;
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);
$error = curl_error($ch);
if ($res && $res = @json_decode($res, true)) {
if (!empty($res['document_url'])) {
$ret = array('zohourl' => $res['document_url']);
$ret['warning'] = 'exportToSave';
return array('error' => is_string($error)? preg_split('/[\r\n]+/', $error) : 'Error code: ' . $error);
return array('error' => array('errCmdParams', 'editor.' . $this->myName . '.init'));
if (!empty($_POST) && !empty($_POST['hash']) && !empty($_FILES) && !empty($_FILES['content'])) {
/** @var elFinderVolumeDriver $volume */
if ($volume = $this->elfinder->getVolume($hash)) {
if ($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');
$hash = $this->args['target'];
/** @var elFinderVolumeDriver $volume */
if ($volume = $this->elfinder->getVolume($hash)) {
if ($file = $volume->file($hash)) {
$res = (bool)$file['write'];
return array('cansave' => $res);