T1646: Get list of supported document types for file creation dialog from Chwala API
This commit is contained in:
parent
90eea059e2
commit
7fe3910a73
2 changed files with 47 additions and 19 deletions
|
@ -445,16 +445,11 @@ class kolab_files_engine
|
||||||
$select_type = new html_select(array('id' => 'file-create-type', 'name' => 'type'));
|
$select_type = new html_select(array('id' => 'file-create-type', 'name' => 'type'));
|
||||||
$table = new html_table(array('cols' => 2, 'class' => 'propform'));
|
$table = new html_table(array('cols' => 2, 'class' => 'propform'));
|
||||||
|
|
||||||
// @TODO: get this list from Chwala API
|
$types = array();
|
||||||
$types = array(
|
|
||||||
'application/vnd.oasis.opendocument.text' => 'odt',
|
foreach ($this->get_mimetypes('edit') as $type => $mimetype) {
|
||||||
'text/plain' => 'txt',
|
$types[$type] = $mimetype['ext'];
|
||||||
'text/html' => 'html',
|
$select_type->add($mimetype['label'], $type);
|
||||||
);
|
|
||||||
foreach (array_keys($types) as $type) {
|
|
||||||
list ($app, $label) = explode('/', $type);
|
|
||||||
$label = preg_replace('/[^a-z]/', '', $label);
|
|
||||||
$select_type->add($this->plugin->gettext('type.' . $label), $type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$table->add('title', html::label('file-create-name', rcube::Q($this->plugin->gettext('filename'))));
|
$table->add('title', html::label('file-create-name', rcube::Q($this->plugin->gettext('filename'))));
|
||||||
|
@ -1383,24 +1378,54 @@ class kolab_files_engine
|
||||||
/**
|
/**
|
||||||
* Returns mimetypes supported by File API viewers
|
* Returns mimetypes supported by File API viewers
|
||||||
*/
|
*/
|
||||||
protected function get_mimetypes()
|
protected function get_mimetypes($type = 'view')
|
||||||
{
|
{
|
||||||
$token = $this->get_api_token();
|
$mimetypes = array();
|
||||||
$request = $this->get_request(array('method' => 'mimetypes'), $token);
|
|
||||||
|
|
||||||
// send request to the API
|
// send request to the API
|
||||||
try {
|
try {
|
||||||
|
if ($this->mimetypes === null) {
|
||||||
|
$this->mimetypes = false;
|
||||||
|
|
||||||
|
$token = $this->get_api_token();
|
||||||
|
$request = $this->get_request(array('method' => 'mimetypes'), $token);
|
||||||
$response = $request->send();
|
$response = $request->send();
|
||||||
$status = $response->getStatus();
|
$status = $response->getStatus();
|
||||||
$body = @json_decode($response->getBody(), true);
|
$body = @json_decode($response->getBody(), true);
|
||||||
|
|
||||||
if ($status == 200 && $body['status'] == 'OK') {
|
if ($status == 200 && $body['status'] == 'OK') {
|
||||||
$mimetypes = $body['result'];
|
$this->mimetypes = $body['result'];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new Exception($body['reason'] ?: "Failed to get mimetypes. Status: $status");
|
throw new Exception($body['reason'] ?: "Failed to get mimetypes. Status: $status");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_array($this->mimetypes) && array_key_exists($type, $this->mimetypes)) {
|
||||||
|
$mimetypes = $this->mimetypes[$type];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$mimetypes = (array) $this->mimetypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
// fallback to static definition if old Chwala is used
|
||||||
|
if ($type == 'edit' && empty($mimetypes)) {
|
||||||
|
$mimetypes = array(
|
||||||
|
'application/vnd.oasis.opendocument.text' => 'odt',
|
||||||
|
'text/plain' => 'txt',
|
||||||
|
'text/html' => 'html',
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach (array_keys($mimetypes) as $type) {
|
||||||
|
list ($app, $label) = explode('/', $type);
|
||||||
|
$label = preg_replace('/[^a-z]/', '', $label);
|
||||||
|
$mimetypes[$type] = array(
|
||||||
|
'ext' => $mimetypes[$type],
|
||||||
|
'label' => $this->plugin->gettext('type.' . $label),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
catch (Exception $e) {
|
catch (Exception $e) {
|
||||||
rcube::raise_error(array(
|
rcube::raise_error(array(
|
||||||
'code' => 500, 'type' => 'php', 'line' => __LINE__, 'file' => __FILE__,
|
'code' => 500, 'type' => 'php', 'line' => __LINE__, 'file' => __FILE__,
|
||||||
|
|
|
@ -168,6 +168,9 @@ $labels['arialabelfilesavedialog'] = 'File(s) saving dialog';
|
||||||
$labels['arialabelfileprops'] = 'File properties';
|
$labels['arialabelfileprops'] = 'File properties';
|
||||||
$labels['arialabelfilecontent'] = 'File content';
|
$labels['arialabelfilecontent'] = 'File content';
|
||||||
$labels['arialabelfileeditdialog'] = 'File editing dialog';
|
$labels['arialabelfileeditdialog'] = 'File editing dialog';
|
||||||
|
$labels['arialabeldoceditorsdialog'] = 'Document session management dialog';
|
||||||
|
$labels['arialabelexportoptions'] = 'Document export options';
|
||||||
|
$labels['arialabelcollaborators'] = 'List of document editors';
|
||||||
|
|
||||||
$labels['type.plain'] = 'Plain Text Document';
|
$labels['type.plain'] = 'Plain Text Document';
|
||||||
$labels['type.vndoasisopendocumenttext'] = 'Text Document (ODF)';
|
$labels['type.vndoasisopendocumenttext'] = 'Text Document (ODF)';
|
||||||
|
|
Loading…
Add table
Reference in a new issue