diff --git a/admin.php b/admin.php index 8890c1f3..9816fa76 100644 --- a/admin.php +++ b/admin.php @@ -2,10 +2,9 @@ namespace OCA\Documents; -\OCP\Util::addScript('documents', 'admin'); +use \OCA\Documents\AppInfo\Application; -$tmpl = new \OCP\Template('documents', 'admin'); -$tmpl->assign('converter', Config::getConverter()); -$tmpl->assign('converter_url', Config::getConverterUrl()); +$app = new Application(); +$response = $app->getContainer()->query('\OCA\Documents\Controller\SettingsController')->adminIndex(); +return $response->render(); -return $tmpl->fetchPage(); diff --git a/appinfo/application.php b/appinfo/application.php index d270daf0..7d2dc9da 100644 --- a/appinfo/application.php +++ b/appinfo/application.php @@ -55,7 +55,6 @@ class Application extends App { $c->query('AppName'), $c->query('Request'), $c->query('CoreConfig'), - $c->query('Logger'), $c->query('L10N'), $c->query('UserId') ); diff --git a/controller/sessioncontroller.php b/controller/sessioncontroller.php index 1a4103ff..3675489c 100644 --- a/controller/sessioncontroller.php +++ b/controller/sessioncontroller.php @@ -123,8 +123,8 @@ class SessionController extends Controller{ $member = new Db\Member(); $member->load($memberId); - if (!$member->getIsGuest()){ - \OCP\JSON::checkLoggedIn(); + if (!$member->getIsGuest() && !\OCP\User::checkLoggedIn()){ + exit(); } try { @@ -236,7 +236,7 @@ class SessionController extends Controller{ if ($this->uid){ $view = new View('/' . $this->uid . '/files'); - $dir = \OCP\Config::getUserValue($this->uid, 'documents', 'save_path', ''); + $dir = \OC::$server->getConfig()->getUserValue($this->uid, 'documents', 'save_path', ''); $path = Helper::getNewFileName($view, $dir . 'New Document.odt'); } else { throw $e; diff --git a/controller/settingscontroller.php b/controller/settingscontroller.php index 201f8646..fdd3e097 100644 --- a/controller/settingscontroller.php +++ b/controller/settingscontroller.php @@ -16,6 +16,7 @@ use \OCP\IRequest; use \OCP\IConfig; use \OCP\IL10N; use \OCP\AppFramework\Http\JSONResponse; +use OCP\AppFramework\Http\TemplateResponse; use OCA\Documents\Converter; use OCA\Documents\Config; @@ -23,16 +24,14 @@ use OCA\Documents\Filter; class SettingsController extends Controller{ - private $uid; + private $userId; private $settings; - private $logger; private $l10n; - public function __construct($appName, IRequest $request, IConfig $settings, $logger, IL10N $l10n, $uid){ + public function __construct($appName, IRequest $request, IConfig $settings, IL10N $l10n, $userId){ parent::__construct($appName, $request); - $this->uid = $uid; + $this->userId = $userId; $this->settings = $settings; - $this->logger = $logger; $this->l10n = $l10n; } @@ -46,6 +45,45 @@ class SettingsController extends Controller{ ); } + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function personalIndex(){ + return new TemplateResponse( + 'documents', + 'personal', + [ 'save_path' => $this->settings->getUserValue($this->userId, 'documents', 'save_path', '/') ], + 'blank' + ); + } + + /** + * @NoCSRFRequired + */ + public function settingsIndex(){ + return new TemplateResponse( + 'documents', + 'settings', + [ 'unstable' => $this->settings->getAppValue('documents', 'unstable', 'false') ], + 'blank' + ); + } + + /** + * @NoCSRFRequired + */ + public function adminIndex(){ + return new TemplateResponse( + 'documents', + 'admin', + [ + 'converter' => Config::getConverter(), + 'converter_url' => Config::getConverterUrl(), + ], + 'blank' + ); + } /** * @NoAdminRequired @@ -60,7 +98,7 @@ class SettingsController extends Controller{ } if ($status){ - $this->settings->setUserValue($this->uid, $this->appName, 'save_path', $savePath); + $this->settings->setUserValue($this->userId, $this->appName, 'save_path', $savePath); $response = array( 'status' => 'success', 'data' => array('message'=> $this->l10n->t('Directory saved successfully.')) @@ -100,7 +138,10 @@ class SettingsController extends Controller{ $currentConverter = $this->settings->getAppValue($this->appName, 'converter', 'off'); if ($currentConverter == 'external'){ if (!Converter::checkConnection()){ - $this->logger->warning('Bad response from Format Filter Server', array('app' => $this->appName)); + \OC::$server->getLogger()->warning( + 'Bad response from Format Filter Server', + ['app' => $this->appName] + ); $response = array( 'status' => 'error', 'data'=> diff --git a/lib/config.php b/lib/config.php index 4d6f182f..d718511b 100644 --- a/lib/config.php +++ b/lib/config.php @@ -66,11 +66,11 @@ class Config { } protected static function getAppValue($key, $default){ - return \OCP\Config::getAppValue(self::APP_NAME, $key, $default); + return \OC::$server->getConfig()->getAppValue(self::APP_NAME, $key, $default); } protected static function setAppValue($key, $value){ - return \OCP\Config::setAppValue(self::APP_NAME, $key, $value); + return \OC::$server->getConfig()->setAppValue(self::APP_NAME, $key, $value); } } diff --git a/lib/converter.php b/lib/converter.php index 1667d528..5dbe2007 100644 --- a/lib/converter.php +++ b/lib/converter.php @@ -43,8 +43,8 @@ class Converter { * @return string */ protected static function convertLocal($input, $targetFilter, $targetExtension){ - $infile = \OCP\Files::tmpFile(); - $outdir = \OCP\Files::tmpFolder(); + $infile = \OC::$server->getTempManager()->getTemporaryFile(); + $outdir = \OC::$server->getTempManager()->getTemporaryFolder(); $cmd = Helper::findOpenOffice(); $params = ' --headless --convert-to ' . $targetFilter . ' --outdir ' . escapeshellarg($outdir) diff --git a/lib/db/session.php b/lib/db/session.php index 04bdbe84..69d96118 100644 --- a/lib/db/session.php +++ b/lib/db/session.php @@ -12,6 +12,8 @@ namespace OCA\Documents\Db; +use OCP\Security\ISecureRandom; + use OCA\Documents\Filter; /** @@ -204,7 +206,9 @@ class Session extends \OCA\Documents\Db { protected function getUniqueSessionId(){ $testSession = new Session(); do{ - $id = \OC_Util::generateRandomBytes(30); + $id = \OC::$server->getSecureRandom() + ->getMediumStrengthGenerator() + ->generate(30, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS); } while ($testSession->load($id)->hasData()); return $id; diff --git a/personal.php b/personal.php index 80669767..b5af9798 100644 --- a/personal.php +++ b/personal.php @@ -12,10 +12,8 @@ namespace OCA\Documents; -\OCP\Util::addScript('documents', 'personal'); +use \OCA\Documents\AppInfo\Application; -$tmpl = new \OCP\Template('documents', 'personal'); -$savePath = \OCP\Config::getUserValue(\OCP\User::getUser(), 'documents', 'save_path', '/'); -$tmpl->assign('savePath', $savePath); - -return $tmpl->fetchPage(); +$app = new Application(); +$response = $app->getContainer()->query('\OCA\Documents\Controller\SettingsController')->personalIndex(); +return $response->render(); diff --git a/public.php b/public.php index 57cbfde9..bb3c9971 100644 --- a/public.php +++ b/public.php @@ -15,8 +15,6 @@ namespace OCA\Documents; \OCP\JSON::checkAppEnabled('documents'); -\OCP\Util::addStyle( 'documents', 'style' ); - if (\OC_Appconfig::getValue('core', 'shareapi_allow_links', 'yes') !== 'yes') { header('HTTP/1.0 404 Not Found'); $tmpl = new OCP\Template('', '404', 'guest'); diff --git a/settings.php b/settings.php index a03e6051..7a36b929 100644 --- a/settings.php +++ b/settings.php @@ -12,10 +12,8 @@ namespace OCA\Documents; -\OCP\Util::addScript('documents', 'settings'); +use \OCA\Documents\AppInfo\Application; -$tmpl = new \OCP\Template('documents', 'settings'); -$unstable = \OCP\Config::getAppValue('documents', 'unstable', 'false'); -$tmpl->assign('unstable', $unstable); - -return $tmpl->fetchPage(); +$app = new Application(); +$response = $app->getContainer()->query('\OCA\Documents\Controller\SettingsController')->settingsIndex(); +return $response->render(); diff --git a/templates/admin.php b/templates/admin.php index e4eaccdd..6b088eed 100644 --- a/templates/admin.php +++ b/templates/admin.php @@ -1,3 +1,6 @@ +

t('Documents')) ?>

t('MS Word support (requires openOffice/libreOffice)')) ?>

diff --git a/templates/personal.php b/templates/personal.php index b51a922a..0c881812 100644 --- a/templates/personal.php +++ b/templates/personal.php @@ -1,7 +1,10 @@ +

t('Documents')); ?>

- +
diff --git a/templates/public.php b/templates/public.php index 6f018e88..cd34217e 100644 --- a/templates/public.php +++ b/templates/public.php @@ -1,3 +1,6 @@ +
diff --git a/templates/settings.php b/templates/settings.php index 8e165f1f..c835bb44 100644 --- a/templates/settings.php +++ b/templates/settings.php @@ -1,3 +1,6 @@ +

t('Documents')) ?>