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/app.php b/appinfo/app.php index 82a380ed..4155214e 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -36,8 +36,8 @@ $navigationEntry = function () use ($c) { return [ 'id' => 'documents_index', 'order' => 2, - 'href' => \OCP\Util::linkTo('documents/', 'index.php'), - 'icon' => \OCP\Util::imagePath('documents', 'documents.svg'), + 'href' => $c->query('ServerContainer')->getURLGenerator()->linkToRoute('documents.document.index'), + 'icon' => $c->query('ServerContainer')->getURLGenerator()->imagePath('documents', 'documents.svg'), 'name' => $c->query('L10N')->t('Documents') ]; }; diff --git a/appinfo/application.php b/appinfo/application.php index f44fd803..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') ); @@ -73,8 +72,8 @@ class Application extends App { $container->registerService('L10N', function($c) { return $c->query('ServerContainer')->getL10N($c->query('AppName')); }); - $container->registerService('UserId', function() { - return \OCP\User::getUser(); + $container->registerService('UserId', function($c) { + return $c->query('ServerContainer')->getUserSession()->getUser()->getUID(); }); } } diff --git a/appinfo/routes.php b/appinfo/routes.php index 016c1864..c765fea6 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -12,37 +12,28 @@ namespace OCA\Documents; $application = new \OCA\Documents\AppInfo\Application(); -$application->registerRoutes($this, array( - 'routes' => array( +$application->registerRoutes($this, [ + 'routes' => [ //users - array('name' => 'user#rename', 'url' => 'ajax/user/rename', 'verb' => 'POST'), - array('name' => 'user#disconnectUser', 'url' => 'ajax/user/disconnect', 'verb' => 'POST'), - array('name' => 'user#disconnectGuest', 'url' => 'ajax/user/disconnectGuest', 'verb' => 'POST'), + ['name' => 'user#rename', 'url' => 'ajax/user/rename', 'verb' => 'POST'], + ['name' => 'user#disconnectUser', 'url' => 'ajax/user/disconnect', 'verb' => 'POST'], + ['name' => 'user#disconnectGuest', 'url' => 'ajax/user/disconnectGuest', 'verb' => 'POST'], //session - array('name' => 'session#joinAsUser', 'url' => 'ajax/session/joinasuser/{fileId}', 'verb' => 'POST'), - array('name' => 'session#joinAsGuest', 'url' => 'ajax/session/joinasguest/{token}', 'verb' => 'POST'), - array('name' => 'session#save', 'url' => 'ajax/session/save', 'verb' => 'POST'), - array('name' => 'session#poll', 'url' => 'ajax/otpoll.php', 'verb' => 'POST'), + ['name' => 'session#joinAsUser', 'url' => 'ajax/session/joinasuser/{fileId}', 'verb' => 'POST'], + ['name' => 'session#joinAsGuest', 'url' => 'ajax/session/joinasguest/{token}', 'verb' => 'POST'], + ['name' => 'session#save', 'url' => 'ajax/session/save', 'verb' => 'POST'], + ['name' => 'session#poll', 'url' => 'ajax/otpoll.php', 'verb' => 'POST'], //documents - array('name' => 'document#create', 'url' => 'ajax/documents/create', 'verb' => 'POST'), - array('name' => 'document#serve', 'url' => 'ajax/genesis/{esId}', 'verb' => 'GET'), - array('name' => 'document#rename', 'url' => 'ajax/documents/rename/{fileId}', 'verb' => 'POST'), - array('name' => 'document#listAll', 'url' => 'ajax/documents/list', 'verb' => 'GET'), - array('name' => 'document#download', 'url' => 'ajax/download.php', 'verb' => 'GET'), + ['name' => 'document#index', 'url' => 'index', 'verb' => 'GET'], + ['name' => 'document#create', 'url' => 'ajax/documents/create', 'verb' => 'POST'], + ['name' => 'document#serve', 'url' => 'ajax/genesis/{esId}', 'verb' => 'GET'], + ['name' => 'document#rename', 'url' => 'ajax/documents/rename/{fileId}', 'verb' => 'POST'], + ['name' => 'document#listAll', 'url' => 'ajax/documents/list', 'verb' => 'GET'], + ['name' => 'document#download', 'url' => 'ajax/download.php', 'verb' => 'GET'], //settings - array('name' => 'settings#savePersonal', 'url' => 'ajax/personal.php', 'verb' => 'POST'), - array('name' => 'settings#setUnstable', 'url' => 'ajax/config/unstable', 'verb' => 'POST'), - array('name' => 'settings#setConverter', 'url' => 'ajax/admin.php', 'verb' => 'POST'), - array('name' => 'settings#getSupportedMimes', 'url' => 'ajax/mimes.php', 'verb' => 'GET'), - ) -)); - -/** - * Document routes - */ - -/** @var $this \OC\Route\Router */ - -$this->create('documents_index', '') - ->get() - ->actionInclude('documents/index.php'); + ['name' => 'settings#savePersonal', 'url' => 'ajax/personal.php', 'verb' => 'POST'], + ['name' => 'settings#setUnstable', 'url' => 'ajax/config/unstable', 'verb' => 'POST'], + ['name' => 'settings#setConverter', 'url' => 'ajax/admin.php', 'verb' => 'POST'], + ['name' => 'settings#getSupportedMimes', 'url' => 'ajax/mimes.php', 'verb' => 'GET'], + ] +]); diff --git a/appinfo/update.php b/appinfo/update.php index 9a7e2b03..8406ae51 100644 --- a/appinfo/update.php +++ b/appinfo/update.php @@ -9,16 +9,18 @@ * later. */ -$installedVersion = \OCP\Config::getAppValue('documents', 'installed_version'); +$config = \OC::$server->getConfig(); +$dbConnection = \OC::$server->getDatabaseConnection(); +$installedVersion = $config->getAppValue('documents', 'installed_version'); -$cleanup = \OC_DB::prepare('DELETE FROM `*PREFIX*documents_member` WHERE `last_activity`=0 or `last_activity` is NULL'); +$cleanup = $dbConnection->prepare('DELETE FROM `*PREFIX*documents_member` WHERE `last_activity`=0 or `last_activity` is NULL'); $cleanup->execute(); if (version_compare($installedVersion, '0.7', '<=')) { - \OCP\Config::setAppValue('documents', 'unstable', 'false'); + $config->setAppValue('documents', 'unstable', 'false'); $session = new \OCA\Documents\Db\Session(); - $query = \OC_DB::prepare('UPDATE `*PREFIX*documents_session` SET `genesis_url`=? WHERE `es_id`=?'); + $query = $dbConnection->prepare('UPDATE `*PREFIX*documents_session` SET `genesis_url`=? WHERE `es_id`=?'); foreach ($session->getCollection() as $sessionData){ $sessionData['genesis_url'] = \OCA\Documents\Genesis::DOCUMENTS_DIRNAME . $sessionData['genesis_url']; @@ -30,12 +32,12 @@ if (version_compare($installedVersion, '0.7', '<=')) { } } if (version_compare($installedVersion, '0.8', '<')) { - $query = \OC_DB::prepare('UPDATE `*PREFIX*documents_member` SET `is_guest`=1 WHERE `uid` LIKE \'%(guest)\' '); + $query = $dbConnection->prepare('UPDATE `*PREFIX*documents_member` SET `is_guest`=1 WHERE `uid` LIKE \'%(guest)\' '); $query->execute(array()); } if (version_compare($installedVersion, '0.9', '<')) { - $query = \OC_DB::prepare('UPDATE `*PREFIX*documents_op` SET `optype`=? WHERE `seq`=?'); + $query = $dbConnection->prepare('UPDATE `*PREFIX*documents_op` SET `optype`=? WHERE `seq`=?'); $ops = new \OCA\Documents\Db\Op(); foreach ($ops->getCollection() as $opData){ $opSpec = json_decode($opData['opspec'], true); diff --git a/controller/documentcontroller.php b/controller/documentcontroller.php index 62dd9f39..c1137b7d 100644 --- a/controller/documentcontroller.php +++ b/controller/documentcontroller.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\Db; use \OCA\Documents\Helper; @@ -41,6 +42,23 @@ class DocumentController extends Controller{ $this->settings = $settings; } + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function index(){ + \OC::$server->getNavigationManager()->setActiveEntry( 'documents_index' ); + $maxUploadFilesize = \OCP\Util::maxUploadFilesize("/"); + return new TemplateResponse('documents', 'documents', [ + 'enable_previews' => $this->settings->getSystemValue('enable_previews', true), + 'useUnstable' => $this->settings->getAppValue('documents', 'unstable', 'false'), + 'savePath' => $this->settings->getUserValue($this->uid, 'documents', 'save_path', '/'), + 'uploadMaxFilesize' => $maxUploadFilesize, + 'uploadMaxHumanFilesize' => \OCP\Util::humanFileSize($maxUploadFilesize), + 'allowShareWithLink' => $this->settings->getAppValue('core', 'shareapi_allow_links', 'yes'), + ]); + } + /** * @NoAdminRequired */ diff --git a/controller/sessioncontroller.php b/controller/sessioncontroller.php index 1a4103ff..2c806e17 100644 --- a/controller/sessioncontroller.php +++ b/controller/sessioncontroller.php @@ -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/index.php b/index.php deleted file mode 100644 index b9eda8b5..00000000 --- a/index.php +++ /dev/null @@ -1,55 +0,0 @@ -. - * - */ - - -namespace OCA\Documents; - -\OCP\User::checkLoggedIn(); -\OCP\JSON::checkAppEnabled('documents'); -\OCP\App::setActiveNavigationEntry( 'documents_index' ); - -\OCP\Util::addStyle( 'documents', 'style' ); -\OCP\Util::addStyle( 'documents', '3rdparty/webodf/dojo-app' ); - -\OCP\Util::addScript('documents', 'documents'); - -\OCP\Util::addScript('files', 'file-upload'); -\OCP\Util::addScript('files', 'jquery.iframe-transport'); -\OCP\Util::addScript('files', 'jquery.fileupload'); - - -$tmpl = new \OCP\Template('documents', 'documents', 'user'); - -$previewsEnabled = \OC::$server->getConfig()->getSystemValue('enable_previews', true); -$unstable = \OCP\Config::getAppValue('documents', 'unstable', 'false'); -$maxUploadFilesize = \OCP\Util::maxUploadFilesize("/"); -$savePath = \OCP\Config::getUserValue(\OCP\User::getUser(), 'documents', 'save_path', '/'); - -$tmpl->assign('enable_previews', $previewsEnabled); -$tmpl->assign('useUnstable', $unstable); -$tmpl->assign('uploadMaxFilesize', $maxUploadFilesize); -$tmpl->assign('uploadMaxHumanFilesize', \OCP\Util::humanFileSize($maxUploadFilesize)); -$tmpl->assign('savePath', $savePath); -$tmpl->assign("allowShareWithLink", \OC::$server->getAppConfig()->getValue('core', 'shareapi_allow_links', 'yes')); - -$tmpl->printPage(); diff --git a/lib/config.php b/lib/config.php index 4d6f182f..b4e59067 100644 --- a/lib/config.php +++ b/lib/config.php @@ -20,8 +20,8 @@ class Config { $targetFilter = 'odt:writer8'; $targetExtension = 'odt'; $input = file_get_contents(dirname(__DIR__) . self::TEST_DOC_PATH); - $infile = \OCP\Files::tmpFile(); - $outdir = \OCP\Files::tmpFolder(); + $infile = \OC::$server->getTempManager()->getTemporaryFile(); + $outdir = \OC::$server->getTempManager()->getTemporaryFolder(); $outfile = $outdir . '/' . basename($infile) . '.' . $targetExtension; $cmd = Helper::findOpenOffice(); @@ -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.php b/lib/db.php index b4bdac40..918ec7b8 100644 --- a/lib/db.php +++ b/lib/db.php @@ -43,7 +43,7 @@ abstract class Db { * @return mixed */ public function getLastInsertId(){ - return \OCP\DB::insertid($this->tableName); + return \OC::$server->getDatabaseConnection()->lastInsertId($this->tableName); } /** diff --git a/lib/db/session.php b/lib/db/session.php index 04bdbe84..b8de3c1c 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; /** @@ -88,6 +90,7 @@ class Session extends \OCA\Documents\Db { if (!$member->insert()){ throw new \Exception('Failed to add member into database'); } + $sessionData['member_id'] = (string) $member->getLastInsertId(); // Do we have OC_Avatar in out disposal? if (\OC_Config::getValue('enable_avatars', true) !== true){ @@ -96,10 +99,11 @@ class Session extends \OCA\Documents\Db { $imageUrl = $uid; } - $displayName = $file->isPublicShare() ? $uid . ' ' . \OCA\Documents\Db\Member::getGuestPostfix() : \OCP\User::getDisplayName($uid); - $userId = $file->isPublicShare() ? $displayName : \OCP\User::getUser(); - - $sessionData['member_id'] = (string) $member->getLastInsertId(); + $displayName = $file->isPublicShare() + ? $uid . ' ' . \OCA\Documents\Db\Member::getGuestPostfix() + : \OC::$server->getUserSession()->getUser()->getDisplayName($uid) + ; + $userId = $file->isPublicShare() ? $displayName : \OC::$server->getUserSession()->getUser()->getUID(); $op = new \OCA\Documents\Db\Op(); $op->addMember( $sessionData['es_id'], @@ -188,10 +192,10 @@ class Session extends \OCA\Documents\Db { WHERE `s`.`es_id` = ? GROUP BY `m`.`es_id` ', - array( - \OCP\User::getUser(), + [ + \OC::$server->getUserSession()->getUser()->getUID(), $esId - ) + ] ); $info = $result->fetchRow(); @@ -204,7 +208,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/lib/file.php b/lib/file.php index 74c8964e..ed4acf99 100644 --- a/lib/file.php +++ b/lib/file.php @@ -147,7 +147,10 @@ class File { if ($this->isPublicShare()){ if (isset($this->sharing['uid_owner'])){ $owner = $this->sharing['uid_owner']; - \OCP\JSON::checkUserExists($this->sharing['uid_owner']); + if (!\OC::$server->getUserManager()->userExists($this->sharing['uid_owner'])) { + throw new \Exception('Share owner' . $this->sharing['uid_owner'] . ' does not exist '); + } + \OC_Util::tearDownFS(); \OC_Util::setupFS($this->sharing['uid_owner']); } else { @@ -155,7 +158,7 @@ class File { } $view = new View('/' . $owner . '/files'); } else { - $owner = \OCP\User::getUser(); + $owner = \OC::$server->getUserSession()->getUser()->getUID(); $root = '/' . $owner; if ($useDefaultRoot){ $root .= '/' . 'files'; diff --git a/lib/helper.php b/lib/helper.php index a351672f..e6ffaee5 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -161,9 +161,10 @@ class Helper { } public static function findOpenOffice(){ + $config = \OC::$server->getConfig(); $cmd = ''; - if (is_string(\OC_Config::getValue('preview_libreoffice_path', null))){ - $cmd = \OC_Config::getValue('preview_libreoffice_path', null); + if (is_string($config->getSystemValue('preview_libreoffice_path', null))){ + $cmd = $config->getSystemValue('preview_libreoffice_path', null); } $whichLibreOffice = shell_exec('which libreoffice'); 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('MS Word support (requires openOffice/libreOffice)')) ?>
diff --git a/templates/documents.php b/templates/documents.php index 07b1bb06..20e0bef4 100644 --- a/templates/documents.php +++ b/templates/documents.php @@ -1,3 +1,11 @@ +