diff --git a/ajax/controller.php b/ajax/controller.php new file mode 100644 index 00000000..93f47fa1 --- /dev/null +++ b/ajax/controller.php @@ -0,0 +1,65 @@ +sendResponse(); + } + + public static function startSession($args){ + $path = @$_POST['path']; + + \OCP\JSON::checkLoggedIn(); + $uid = \OCP\User::getUser(); + $officeView = View::initOfficeView($uid); + + if (!$officeView->file_exists($path)){ + $genesisPath = View::storeDocument($uid, $path); + } else { + $genesisPath = $path; + } + + if ($genesisPath){ + $session = Session::getSessionByPath($uid, $genesisPath); + if (!$session){ + $hash = View::getHashByGenesis($uid, $genesisPath); + $session = Session::addSession($genesisPath, $hash); + } + \OCP\JSON::success($session); + exit(); + } + \OCP\JSON::error(); + } + + public static function joinSession($args){ + $esId = @$args['es_id']; + + \OCP\JSON::checkLoggedIn(); + + if ($esId){ + $session = Session::getSession($esId); + \OCP\JSON::success($session); + exit(); + } + \OCP\JSON::error(); + } + +} \ No newline at end of file diff --git a/appinfo/app.php b/appinfo/app.php index c57024a1..5f4702a7 100755 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -33,6 +33,6 @@ OCP\App::addNavigationEntry(array( 'name' => 'Office') ); -OC::$CLASSPATH['OCA\Office\Genesis'] = 'office/lib/genesis.php'; +OC::$CLASSPATH['OCA\Office\Controller'] = 'office/ajax/controller.php'; OC::$CLASSPATH['OCA\Office\Download\Simple'] = 'office/lib/download/simple.php'; OC::$CLASSPATH['OCA\Office\Download\Range'] = 'office/lib/download/range.php'; diff --git a/appinfo/routes.php b/appinfo/routes.php index a2572474..85727fc7 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -11,9 +11,27 @@ $this->create('office_genesis', 'ajax/genesis/{es_id}') ->post() - ->action('\OCA\Office\Genesis', 'serve') + ->action('\OCA\Office\Controller', 'serve') ; $this->create('office_genesis', 'ajax/genesis/{es_id}') ->get() - ->action('\OCA\Office\Genesis', 'serve') + ->action('\OCA\Office\Controller', 'serve') ; + +$this->create('office_session_start', 'ajax/session/start') + ->get() + ->action('\OCA\Office\Controller', 'startSession') +; +$this->create('office_session_start', 'ajax/session/start') + ->post() + ->action('\OCA\Office\Controller', 'startSession') +; + +$this->create('office_session_join', 'ajax/session/join/{es_id}') + ->get() + ->action('\OCA\Office\Controller', 'joinSession') +; +$this->create('office_session_join', 'ajax/session/join/{es_id}') + ->post() + ->action('\OCA\Office\Controller', 'joinSession') +; \ No newline at end of file diff --git a/js/office.js b/js/office.js index 3b0bb898..99851261 100644 --- a/js/office.js +++ b/js/office.js @@ -89,8 +89,8 @@ var officeMain = { return; } - $.post(OC.filePath('office', 'ajax', 'session.php'), - { 'genesis' : filepath }, + $.post(OC.Router.generate('office_session_start'), + { 'path' : filepath }, officeMain.onView ); }, diff --git a/lib/genesis.php b/lib/genesis.php deleted file mode 100644 index 143a4463..00000000 --- a/lib/genesis.php +++ /dev/null @@ -1,29 +0,0 @@ -sendResponse(); - } - -} \ No newline at end of file diff --git a/lib/session.php b/lib/session.php index 0e461c8a..71fbec77 100644 --- a/lib/session.php +++ b/lib/session.php @@ -25,9 +25,9 @@ class Session { return $result->fetchRow(); } - public static function getSessionByPath($url){ - $query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*office_session` WHERE `genesis_url`= ?'); - $result = $query->execute(array($url)); + public static function getSessionByPath($uid, $url){ + $query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*office_session` WHERE `genesis_url`= ? AND `owner`= ? '); + $result = $query->execute(array($url, $uid)); return $result->fetchRow(); }