richdocuments/lib/Controller/SettingsController.php

88 lines
2.0 KiB
PHP
Raw Normal View History

<?php
/**
2015-12-16 17:57:44 +03:00
* ownCloud - Richdocuments App
*
* @author Victor Dubiniuk
* @copyright 2014 Victor Dubiniuk victor.dubiniuk@gmail.com
*
* This file is licensed under the Affero General Public License version 3 or
* later.
*/
2015-12-16 17:57:44 +03:00
namespace OCA\Richdocuments\Controller;
use \OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use \OCP\IRequest;
use \OCP\IL10N;
2015-12-16 17:57:44 +03:00
use OCA\Richdocuments\AppConfig;
use OCA\Richdocuments\Filter;
class SettingsController extends Controller{
/** @var IL10N */
private $l10n;
/** @var AppConfig */
2015-09-18 22:10:27 +03:00
private $appConfig;
2016-03-05 17:40:47 -04:00
/**
* @param string $appName
* @param IRequest $request
* @param IL10N $l10n
* @param AppConfig $appConfig
* @param string $userId
*/
public function __construct($appName,
IRequest $request,
IL10N $l10n,
AppConfig $appConfig,
$userId) {
parent::__construct($appName, $request);
$this->l10n = $l10n;
2015-09-18 22:10:27 +03:00
$this->appConfig = $appConfig;
}
2016-03-05 17:40:47 -04:00
/**
* @NoAdminRequired
*/
public function getSupportedMimes(){
return array(
'status' => 'success',
'mimes' => Filter::getAll()
);
}
2016-03-05 17:40:47 -04:00
/**
* @param string $wopi_url
* @param string $doc_format
* @return JSONResponse
*/
public function setSettings($wopi_url,
$doc_format){
$message = $this->l10n->t('Saved');
if ($wopi_url !== null){
2016-03-05 17:40:47 -04:00
$this->appConfig->setAppValue('wopi_url', $wopi_url);
$colon = strpos($wopi_url, ':', 0);
if (\OC::$server->getRequest()->getServerProtocol() !== substr($wopi_url, 0, $colon)){
$message = $this->l10n->t('Saved with error: Collabora Online should use the same protocol as the server installation.');
}
2016-03-05 17:40:47 -04:00
}
if ($doc_format !== null) {
$this->appConfig->setAppValue('doc_format', $doc_format);
}
2016-03-17 10:00:46 -04:00
$richMemCache = \OC::$server->getMemCacheFactory()->create('richdocuments');
$richMemCache->clear('discovery.xml');
$response = array(
'status' => 'success',
'data' => array('message' => (string) $message)
);
2016-03-05 17:40:47 -04:00
return new JSONResponse($response);
}
}