Changeset View
Changeset View
Standalone View
Standalone View
plugins/kolab_files/lib/kolab_files_engine.php
Show All 22 Lines | |||||
*/ | */ | ||||
class kolab_files_engine | class kolab_files_engine | ||||
{ | { | ||||
private $plugin; | private $plugin; | ||||
private $rc; | private $rc; | ||||
private $url; | private $url; | ||||
private $url_srv; | private $url_srv; | ||||
private $filetypes_style; | |||||
private $timeout = 600; | private $timeout = 600; | ||||
private $files_sort_cols = array('name', 'mtime', 'size'); | private $files_sort_cols = array('name', 'mtime', 'size'); | ||||
private $sessions_sort_cols = array('name'); | private $sessions_sort_cols = array('name'); | ||||
private $mimetypes = null; | private $mimetypes = null; | ||||
const API_VERSION = 4; | const API_VERSION = 4; | ||||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | public function ui() | ||||
$this->plugin->include_script('kolab_files.js'); | $this->plugin->include_script('kolab_files.js'); | ||||
$this->rc->output->set_env('files_url', $this->url . '/api/'); | $this->rc->output->set_env('files_url', $this->url . '/api/'); | ||||
$this->rc->output->set_env('files_token', $this->get_api_token()); | $this->rc->output->set_env('files_token', $this->get_api_token()); | ||||
$this->rc->output->set_env('files_caps', $caps); | $this->rc->output->set_env('files_caps', $caps); | ||||
$this->rc->output->set_env('files_api_version', $caps['VERSION'] ?? 3); | $this->rc->output->set_env('files_api_version', $caps['VERSION'] ?? 3); | ||||
$this->rc->output->set_env('files_user', $this->rc->get_user_name()); | $this->rc->output->set_env('files_user', $this->rc->get_user_name()); | ||||
if ($caps['DOCEDIT']) { | if ($caps['DOCEDIT'] ?? false) { | ||||
$this->plugin->add_label('declinednotice', 'invitednotice', 'acceptedownernotice', | $this->plugin->add_label('declinednotice', 'invitednotice', 'acceptedownernotice', | ||||
'declinedownernotice', 'requestednotice', 'acceptednotice', 'declinednotice', | 'declinedownernotice', 'requestednotice', 'acceptednotice', 'declinednotice', | ||||
'more', 'accept', 'decline', 'join', 'status', 'when', 'file', 'comment', | 'more', 'accept', 'decline', 'join', 'status', 'when', 'file', 'comment', | ||||
'statusaccepted', 'statusinvited', 'statusdeclined', 'statusrequested', | 'statusaccepted', 'statusinvited', 'statusdeclined', 'statusrequested', | ||||
'invitationaccepting', 'invitationdeclining', 'invitationrequesting', | 'invitationaccepting', 'invitationdeclining', 'invitationrequesting', | ||||
'close', 'invitationtitle', 'sessions', 'saving'); | 'close', 'invitationtitle', 'sessions', 'saving'); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 567 Lines • ▼ Show 20 Lines | class kolab_files_engine | ||||
/** | /** | ||||
* Creates <THEAD> for message list table | * Creates <THEAD> for message list table | ||||
*/ | */ | ||||
protected function list_head($attrib, $a_show_cols, $type = 'files') | protected function list_head($attrib, $a_show_cols, $type = 'files') | ||||
{ | { | ||||
$prefix = 'kolab_' . $type . '_'; | $prefix = 'kolab_' . $type . '_'; | ||||
$c_prefix = 'kolab_files_' . ($type != 'files' ? $type : '') . '_'; | $c_prefix = 'kolab_files_' . ($type != 'files' ? $type : '') . '_'; | ||||
$skin_path = $_SESSION['skin_path']; | $skin_path = $_SESSION['skin_path'] ?? null; | ||||
// check to see if we have some settings for sorting | // check to see if we have some settings for sorting | ||||
$sort_col = $_SESSION[$prefix . 'sort_col']; | $sort_col = $_SESSION[$prefix . 'sort_col']; | ||||
$sort_order = $_SESSION[$prefix . 'sort_order']; | $sort_order = $_SESSION[$prefix . 'sort_order']; | ||||
$dont_override = (array)$this->rc->config->get('dont_override'); | $dont_override = (array)$this->rc->config->get('dont_override'); | ||||
$disabled_sort = in_array($c_prefix . 'sort_col', $dont_override); | $disabled_sort = in_array($c_prefix . 'sort_col', $dont_override); | ||||
$disabled_order = in_array($c_prefix . 'sort_order', $dont_override); | $disabled_order = in_array($c_prefix . 'sort_order', $dont_override); | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | protected function list_head($attrib, $a_show_cols, $type = 'files') | ||||
// make sort links | // make sort links | ||||
if (in_array($col, $a_sort_cols)) { | if (in_array($col, $a_sort_cols)) { | ||||
$col_name = html::a(array( | $col_name = html::a(array( | ||||
'href' => "#sort", | 'href' => "#sort", | ||||
'onclick' => 'return ' . rcmail_output::JS_OBJECT_NAME . ".command('$type-sort','$col',this)", | 'onclick' => 'return ' . rcmail_output::JS_OBJECT_NAME . ".command('$type-sort','$col',this)", | ||||
'title' => $this->plugin->gettext('sortby') | 'title' => $this->plugin->gettext('sortby') | ||||
), $col_name); | ), $col_name); | ||||
} | } | ||||
else if ($col_name[0] != '<') { | else if (empty($col_name) || $col_name[0] != '<') { | ||||
$col_name = '<span class="' . $col .'">' . $col_name . '</span>'; | $col_name = '<span class="' . $col .'">' . $col_name . '</span>'; | ||||
} | } | ||||
$sort_class = $col == $sort_col && !$disabled_order ? " sorted$sort_order" : ''; | $sort_class = $col == $sort_col && !$disabled_order ? " sorted$sort_order" : ''; | ||||
$class_name = $col.$sort_class; | $class_name = $col.$sort_class; | ||||
// put it all together | // put it all together | ||||
$cells[] = array('className' => $class_name, 'id' => "rcm$col", 'html' => $col_name); | $cells[] = array('className' => $class_name, 'id' => "rcm$col", 'html' => $col_name); | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | class kolab_files_engine | ||||
* Template object for file preview frame | * Template object for file preview frame | ||||
*/ | */ | ||||
public function file_preview_frame($attrib) | public function file_preview_frame($attrib) | ||||
{ | { | ||||
if (empty($attrib['id'])) { | if (empty($attrib['id'])) { | ||||
$attrib['id'] = 'filepreviewframe'; | $attrib['id'] = 'filepreviewframe'; | ||||
} | } | ||||
if ($frame = $this->file_data['viewer']['frame']) { | if ($frame = ($this->file_data['viewer']['frame'] ?? null)) { | ||||
return $frame; | return $frame; | ||||
} | } | ||||
if ($href = $this->file_data['viewer']['href']) { | if ($href = $this->file_data['viewer']['href']) { | ||||
// file href attribute must be an absolute URL (Bug #2063) | // file href attribute must be an absolute URL (Bug #2063) | ||||
if (!empty($href)) { | if (!empty($href)) { | ||||
if (!preg_match('|^https?://|', $href)) { | if (!preg_match('|^https?://|', $href)) { | ||||
$href = $this->url . '/api/' . $href; | $href = $this->url . '/api/' . $href; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
else { | else { | ||||
$token = $this->get_api_token(); | $token = $this->get_api_token(); | ||||
$href = $this->url . '/api/?method=file_get' | $href = $this->url . '/api/?method=file_get' | ||||
. '&file=' . urlencode($this->file_data['filename']) | . '&file=' . urlencode($this->file_data['filename']) | ||||
. '&token=' . urlencode($token); | . '&token=' . urlencode($token); | ||||
} | } | ||||
$this->rc->output->add_gui_object('preview_frame', $attrib['id']); | $this->rc->output->add_gui_object('preview_frame', $attrib['id']); | ||||
$attrib['allowfullscreen'] = true; | $attrib['allowfullscreen'] = true; | ||||
$attrib['src'] = $href; | $attrib['src'] = $href; | ||||
$attrib['onload'] = 'kolab_files_frame_load(this)'; | $attrib['onload'] = 'kolab_files_frame_load(this)'; | ||||
$form = null; | |||||
// editor requires additional arguments via POST | // editor requires additional arguments via POST | ||||
if (!empty($this->file_data['viewer']['post'])) { | if (!empty($this->file_data['viewer']['post'])) { | ||||
$attrib['src'] = 'program/resources/blank.gif'; | $attrib['src'] = 'program/resources/blank.gif'; | ||||
$form_content = new html_hiddenfield(); | $form_content = new html_hiddenfield(); | ||||
$form_attrib = array( | $form_attrib = array( | ||||
'action' => $href, | 'action' => $href, | ||||
'id' => $attrib['id'] . '-form', | 'id' => $attrib['id'] . '-form', | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | public function quota_display($attrib) | ||||
return html::span($attrib, ''); | return html::span($attrib, ''); | ||||
} | } | ||||
/** | /** | ||||
* Get API token for current user session, authenticate if needed | * Get API token for current user session, authenticate if needed | ||||
*/ | */ | ||||
public function get_api_token($configure = true) | public function get_api_token($configure = true) | ||||
{ | { | ||||
$token = $_SESSION['kolab_files_token']; | $token = $_SESSION['kolab_files_token'] ?? null; | ||||
$time = $_SESSION['kolab_files_time']; | $time = $_SESSION['kolab_files_time'] ?? null; | ||||
if ($token && time() - $this->timeout < $time) { | if ($token && time() - $this->timeout < $time) { | ||||
if (time() - $time <= $this->timeout / 2) { | if (time() - $time <= $this->timeout / 2) { | ||||
return $token; | return $token; | ||||
} | } | ||||
} | } | ||||
$request = $this->get_request(array('method' => 'ping'), $token); | $request = $this->get_request(array('method' => 'ping'), $token); | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | protected function capabilities() | ||||
} | } | ||||
catch (Exception $e) { | catch (Exception $e) { | ||||
rcube::raise_error($e, true, false); | rcube::raise_error($e, true, false); | ||||
return array(); | return array(); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if ($_SESSION['kolab_files_caps']['MANTICORE'] || $_SESSION['kolab_files_caps']['WOPI']) { | if (($_SESSION['kolab_files_caps']['MANTICORE'] ?? false) || ($_SESSION['kolab_files_caps']['WOPI'] ?? false)) { | ||||
$_SESSION['kolab_files_caps']['DOCEDIT'] = true; | $_SESSION['kolab_files_caps']['DOCEDIT'] = true; | ||||
$_SESSION['kolab_files_caps']['DOCTYPE'] = $_SESSION['kolab_files_caps']['MANTICORE'] ? 'manticore' : 'wopi'; | $_SESSION['kolab_files_caps']['DOCTYPE'] = $_SESSION['kolab_files_caps']['MANTICORE'] ? 'manticore' : 'wopi'; | ||||
} | } | ||||
if (!empty($_SESSION['kolab_files_caps']) && !isset($_SESSION['kolab_files_caps']['MOUNTPOINTS'])) { | if (!empty($_SESSION['kolab_files_caps']) && !isset($_SESSION['kolab_files_caps']['MOUNTPOINTS'])) { | ||||
$_SESSION['kolab_files_caps']['MOUNTPOINTS'] = array(); | $_SESSION['kolab_files_caps']['MOUNTPOINTS'] = array(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | public function configure($token = null, $prefs = array()) | ||||
if (!$token) { | if (!$token) { | ||||
$token = $this->get_api_token(false); | $token = $this->get_api_token(false); | ||||
} | } | ||||
try { | try { | ||||
// Configure session | // Configure session | ||||
$query = array( | $query = array( | ||||
'method' => 'configure', | 'method' => 'configure', | ||||
'timezone' => $prefs['timezone'] ?: $this->rc->config->get('timezone'), | 'timezone' => $prefs['timezone'] ?? $this->rc->config->get('timezone'), | ||||
'date_format' => $prefs['date_long'] ?: $this->rc->config->get('date_long', 'Y-m-d H:i'), | 'date_format' => $prefs['date_long'] ?? $this->rc->config->get('date_long', 'Y-m-d H:i'), | ||||
); | ); | ||||
$request = $this->get_request($query, $token); | $request = $this->get_request($query, $token); | ||||
$response = $request->send(); | $response = $request->send(); | ||||
$status = $response->getStatus(); | $status = $response->getStatus(); | ||||
if ($status != 200) { | if ($status != 200) { | ||||
throw new Exception(sprintf("Failed to configure chwala session (Status: %d)", $status)); | throw new Exception(sprintf("Failed to configure chwala session (Status: %d)", $status)); | ||||
▲ Show 20 Lines • Show All 490 Lines • ▼ Show 20 Lines | protected function file_opener($viewer) | ||||
// register template objects for dialogs (and main interface) | // register template objects for dialogs (and main interface) | ||||
$this->rc->output->add_handlers(array( | $this->rc->output->add_handlers(array( | ||||
'fileinfobox' => array($this, 'file_info_box'), | 'fileinfobox' => array($this, 'file_info_box'), | ||||
'filepreviewframe' => array($this, 'file_preview_frame'), | 'filepreviewframe' => array($this, 'file_preview_frame'), | ||||
)); | )); | ||||
$placeholder = $this->rc->output->asset_url('program/resources/blank.gif'); | $placeholder = $this->rc->output->asset_url('program/resources/blank.gif'); | ||||
if ($this->file_data['viewer']['wopi']) { | $editor_type = null; | ||||
$got_editor = null; | |||||
if ($this->file_data['viewer']['wopi'] ?? false) { | |||||
$editor_type = 'wopi'; | $editor_type = 'wopi'; | ||||
$got_editor = ($viewer & 4); | $got_editor = ($viewer & 4); | ||||
} | } | ||||
else if ($this->file_data['viewer']['manticore']) { | else if ($this->file_data['viewer']['manticore'] ?? false) { | ||||
$editor_type = 'manticore'; | $editor_type = 'manticore'; | ||||
$got_editor = ($viewer & 4); | $got_editor = ($viewer & 4); | ||||
} | } | ||||
// this one is for styling purpose | // this one is for styling purpose | ||||
$this->rc->output->set_env('extwin', true); | $this->rc->output->set_env('extwin', true); | ||||
$this->rc->output->set_env('file', $file); | $this->rc->output->set_env('file', $file); | ||||
$this->rc->output->set_env('file_data', $this->file_data); | $this->rc->output->set_env('file_data', $this->file_data); | ||||
▲ Show 20 Lines • Show All 152 Lines • Show Last 20 Lines |