Changeset View
Changeset View
Standalone View
Standalone View
lib/drivers/kolab/kolab_file_storage.php
Show First 20 Lines • Show All 173 Lines • ▼ Show 20 Lines | private function login($username, $password, $host, &$error = null) | ||||
return false; | return false; | ||||
} | } | ||||
$login_lc = $this->rc->config->get('login_lc'); | $login_lc = $this->rc->config->get('login_lc'); | ||||
$default_port = $this->rc->config->get('default_port', 143); | $default_port = $this->rc->config->get('default_port', 143); | ||||
// parse $host | // parse $host | ||||
$a_host = parse_url($host); | $a_host = parse_url($host); | ||||
$port = null; | |||||
if ($a_host['host']) { | if ($a_host['host']) { | ||||
$host = $a_host['host']; | $host = $a_host['host']; | ||||
$ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'))) ? $a_host['scheme'] : null; | $ssl = (isset($a_host['scheme']) && in_array($a_host['scheme'], array('ssl','imaps','tls'))) ? $a_host['scheme'] : null; | ||||
if (!empty($a_host['port'])) { | if (!empty($a_host['port'])) { | ||||
$port = $a_host['port']; | $port = $a_host['port']; | ||||
} | } | ||||
else if ($ssl && $ssl != 'tls' && (!$default_port || $default_port == 143)) { | else if ($ssl && $ssl != 'tls' && (!$default_port || $default_port == 143)) { | ||||
$port = 993; | $port = 993; | ||||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | private function login($username, $password, $host, &$error = null) | ||||
return true; | return true; | ||||
} | } | ||||
protected function init($user = null) | protected function init($user = null) | ||||
{ | { | ||||
$this->rc->plugins->exec_hook('startup'); | $this->rc->plugins->exec_hook('startup'); | ||||
if ($_SESSION['user_id'] || $user) { | if ($_SESSION['user_id'] ?? false || $user) { | ||||
// overwrite config with user preferences | // overwrite config with user preferences | ||||
$this->rc->user = $user ? $user : new rcube_user($_SESSION['user_id']); | $this->rc->user = $user ? $user : new rcube_user($_SESSION['user_id']); | ||||
$this->rc->config->set_user_prefs((array)$this->rc->user->get_prefs()); | $this->rc->config->set_user_prefs((array)$this->rc->user->get_prefs()); | ||||
$storage = $this->rc->get_storage(); | $storage = $this->rc->get_storage(); | ||||
$storage->set_charset($this->rc->config->get('default_charset', RCUBE_CHARSET)); | $storage->set_charset($this->rc->config->get('default_charset', RCUBE_CHARSET)); | ||||
setlocale(LC_ALL, 'en_US.utf8', 'en_US.UTF-8'); | setlocale(LC_ALL, 'en_US.utf8', 'en_US.UTF-8'); | ||||
▲ Show 20 Lines • Show All 367 Lines • ▼ Show 20 Lines | public function file_info($file_name) | ||||
if (empty($file)) { | if (empty($file)) { | ||||
throw new Exception("Storage error. File not found.", file_storage::ERROR); | throw new Exception("Storage error. File not found.", file_storage::ERROR); | ||||
} | } | ||||
$file = $this->from_file_object($file); | $file = $this->from_file_object($file); | ||||
return array( | return array( | ||||
'name' => $file['name'], | 'name' => $file['name'], | ||||
'size' => (int) $file['size'], | 'size' => (int) ($file['size'] ?? null), | ||||
'type' => (string) $file['type'], | 'type' => (string) $file['type'], | ||||
'mtime' => file_utils::date_format($file['changed'], $this->config['date_format'], $this->config['timezone']), | 'mtime' => file_utils::date_format($file['changed'], $this->config['date_format'], $this->config['timezone']), | ||||
'ctime' => file_utils::date_format($file['created'], $this->config['date_format'], $this->config['timezone']), | 'ctime' => file_utils::date_format($file['created'], $this->config['date_format'], $this->config['timezone']), | ||||
'modified' => $file['changed'] ? $file['changed']->format('U') : 0, | 'modified' => $file['changed'] ? $file['changed']->format('U') : 0, | ||||
'created' => $file['created'] ? $file['created']->format('U') : 0, | 'created' => $file['created'] ? $file['created']->format('U') : 0, | ||||
); | ); | ||||
} | } | ||||
Show All 33 Lines | public function file_list($folder_name, $params = array()) | ||||
// convert to kolab_storage files list data format | // convert to kolab_storage files list data format | ||||
foreach ($files as $idx => $file) { | foreach ($files as $idx => $file) { | ||||
$file = $this->from_file_object($file); | $file = $this->from_file_object($file); | ||||
if (!isset($file['name'])) { | if (!isset($file['name'])) { | ||||
continue; | continue; | ||||
} | } | ||||
$filename = $params['prefix'] . $folder_name . file_storage::SEPARATOR . $file['name']; | $filename = ($params['prefix'] ?? null) . $folder_name . file_storage::SEPARATOR . ($file['name'] ?? null); | ||||
$result[$filename] = array( | $result[$filename] = array( | ||||
'name' => $file['name'], | 'name' => $file['name'], | ||||
'size' => (int) $file['size'], | 'size' => (int) ($file['size'] ?? null), | ||||
'type' => (string) $file['type'], | 'type' => (string) $file['type'], | ||||
'mtime' => file_utils::date_format($file['changed'], $this->config['date_format'], $this->config['timezone']), | 'mtime' => file_utils::date_format($file['changed'], $this->config['date_format'], $this->config['timezone']), | ||||
'ctime' => file_utils::date_format($file['created'], $this->config['date_format'], $this->config['timezone']), | 'ctime' => file_utils::date_format($file['created'], $this->config['date_format'], $this->config['timezone']), | ||||
'modified' => $file['changed'] ? $file['changed']->format('U') : 0, | 'modified' => $file['changed'] ? $file['changed']->format('U') : 0, | ||||
'created' => $file['created'] ? $file['created']->format('U') : 0, | 'created' => $file['created'] ? $file['created']->format('U') : 0, | ||||
); | ); | ||||
unset($files[$idx]); | unset($files[$idx]); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 280 Lines • ▼ Show 20 Lines | public function folder_list($params = array()) | ||||
} | } | ||||
$folders = array_map(array($this, 'folder_out'), $folders); | $folders = array_map(array($this, 'folder_out'), $folders); | ||||
} | } | ||||
// This could probably be optimized by doing a direct | // This could probably be optimized by doing a direct | ||||
// IMAP LIST command with prepared second argument, but | // IMAP LIST command with prepared second argument, but | ||||
// it would make caching not optimal | // it would make caching not optimal | ||||
if ($params['level'] > 0) { | if (($params['level'] ?? 0) > 0) { | ||||
$offset = isset($params['path']) && strlen($params['path']) ? strlen($params['path']) + 1 : 0; | $offset = isset($params['path']) && strlen($params['path']) ? strlen($params['path']) + 1 : 0; | ||||
foreach ($folders as $idx => $folder) { | foreach ($folders as $idx => $folder) { | ||||
if (substr_count($folder, $separator, $offset) >= $params['level']) { | if (substr_count($folder, $separator, $offset) >= $params['level']) { | ||||
unset($folders[$idx]); | unset($folders[$idx]); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 572 Lines • ▼ Show 20 Lines | protected function get_folder_object($folder_name) | ||||
return $this->folders[$folder_name]; | return $this->folders[$folder_name]; | ||||
} | } | ||||
/** | /** | ||||
* Simplify internal structure of the file object | * Simplify internal structure of the file object | ||||
*/ | */ | ||||
protected function from_file_object($file) | protected function from_file_object($file) | ||||
{ | { | ||||
if (isset($file['filename']) && !$file['name']) { | if (isset($file['filename']) && !($file['name'] ?? false)) { | ||||
$file['name'] = $file['filename']; | $file['name'] = $file['filename']; | ||||
} | } | ||||
if (empty($file['_attachments'])) { | if (empty($file['_attachments'])) { | ||||
return $file; | return $file; | ||||
} | } | ||||
$attachment = array_shift($file['_attachments']); | $attachment = array_shift($file['_attachments']); | ||||
Show All 17 Lines | protected function to_file_object($file) | ||||
// get attachment body and save it in path | // get attachment body and save it in path | ||||
$file['_attachments'] = array( | $file['_attachments'] = array( | ||||
0 => array( | 0 => array( | ||||
'name' => $file['name'], | 'name' => $file['name'], | ||||
'path' => $file['path'], | 'path' => $file['path'], | ||||
'content' => $file['content'], | 'content' => $file['content'], | ||||
'mimetype' => $file['type'], | 'mimetype' => $file['type'], | ||||
'size' => $file['size'], | 'size' => $file['size'] ?? null, | ||||
)); | )); | ||||
unset($file['name']); | unset($file['name']); | ||||
unset($file['size']); | unset($file['size']); | ||||
unset($file['type']); | unset($file['type']); | ||||
unset($file['path']); | unset($file['path']); | ||||
unset($file['fileid']); | unset($file['fileid']); | ||||
▲ Show 20 Lines • Show All 44 Lines • Show Last 20 Lines |