Merge pull request #236 from owncloud/get-path-refactoring
Get path refactoring
This commit is contained in:
commit
3788512dff
@ -5,8 +5,6 @@ namespace OCA\Documents;
|
|||||||
\OCP\JSON::callCheck();
|
\OCP\JSON::callCheck();
|
||||||
\OCP\JSON::checkAdminUser();
|
\OCP\JSON::checkAdminUser();
|
||||||
|
|
||||||
$l10n = \OCP\Util::getL10N('documents');
|
|
||||||
|
|
||||||
$converter = isset($_POST['converter']) ? $_POST['converter'] : null;
|
$converter = isset($_POST['converter']) ? $_POST['converter'] : null;
|
||||||
$url = isset($_POST['url']) ? $_POST['url'] : null;
|
$url = isset($_POST['url']) ? $_POST['url'] : null;
|
||||||
try {
|
try {
|
||||||
@ -21,7 +19,7 @@ try {
|
|||||||
if (Config::getConverter()!='local'){
|
if (Config::getConverter()!='local'){
|
||||||
if (!Converter::checkConnection()){
|
if (!Converter::checkConnection()){
|
||||||
Helper::warnLog('Bad response from Format Filter Server');
|
Helper::warnLog('Bad response from Format Filter Server');
|
||||||
\OCP\JSON::error(array('message' => $l10n->t('Format filter server is down or misconfigured') ));
|
\OCP\JSON::error(array('message' => Config::getL10n()->t('Format filter server is down or misconfigured') ));
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,6 @@ class Controller {
|
|||||||
\OCP\JSON::callCheck();
|
\OCP\JSON::callCheck();
|
||||||
}
|
}
|
||||||
\OCP\JSON::checkAppEnabled('documents');
|
\OCP\JSON::checkAppEnabled('documents');
|
||||||
return '(guest)';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
@ -32,35 +32,38 @@ try{
|
|||||||
$esId = $request->getParam('args/es_id');
|
$esId = $request->getParam('args/es_id');
|
||||||
|
|
||||||
$session = new Db_Session();
|
$session = new Db_Session();
|
||||||
$sessionData = $session->load($esId)->getData();
|
$session->load($esId);
|
||||||
|
|
||||||
|
$memberId = $request->getParam('args/member_id');
|
||||||
|
$member = new Db_Member();
|
||||||
|
$member->load($memberId);
|
||||||
|
|
||||||
|
if ($member->getIsGuest() || is_null($member->getIsGuest())){
|
||||||
|
Controller::preDispatchGuest(false);
|
||||||
|
} else {
|
||||||
|
Controller::preDispatch(false);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$file = new File(@$sessionData['file_id']);
|
$file = new File($session->getFileId());
|
||||||
} catch (\Exception $e){
|
} catch (\Exception $e){
|
||||||
Helper::warnLog('Error. Session no longer exists. ' . $e->getMessage());
|
Helper::warnLog('Error. Session no longer exists. ' . $e->getMessage());
|
||||||
$ex = new BadRequestException();
|
$ex = new BadRequestException();
|
||||||
$ex->setBody($request->getRawRequest());
|
$ex->setBody($request->getRawRequest());
|
||||||
throw $ex;
|
throw $ex;
|
||||||
}
|
}
|
||||||
if (!$file->isPublicShare()){
|
|
||||||
Controller::preDispatch(false);
|
|
||||||
} else {
|
|
||||||
Controller::preDispatchGuest(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
$command = $request->getParam('command');
|
$command = $request->getParam('command');
|
||||||
switch ($command){
|
switch ($command){
|
||||||
case 'sync_ops':
|
case 'sync_ops':
|
||||||
$seqHead = (string) $request->getParam('args/seq_head');
|
$seqHead = (string) $request->getParam('args/seq_head');
|
||||||
if (!is_null($seqHead)){
|
if (!is_null($seqHead)){
|
||||||
$memberId = $request->getParam('args/member_id');
|
|
||||||
$ops = $request->getParam('args/client_ops');
|
$ops = $request->getParam('args/client_ops');
|
||||||
$hasOps = is_array($ops) && count($ops)>0;
|
$hasOps = is_array($ops) && count($ops)>0;
|
||||||
|
|
||||||
$op = new Db_Op();
|
$op = new Db_Op();
|
||||||
$currentHead = $op->getHeadSeq($esId);
|
$currentHead = $op->getHeadSeq($esId);
|
||||||
|
|
||||||
$member = new Db_Member();
|
|
||||||
try {
|
try {
|
||||||
$member->updateActivity($memberId);
|
$member->updateActivity($memberId);
|
||||||
} catch (\Exception $e){
|
} catch (\Exception $e){
|
||||||
|
@ -15,12 +15,16 @@ namespace OCA\Documents;
|
|||||||
class SessionController extends Controller{
|
class SessionController extends Controller{
|
||||||
|
|
||||||
public static function joinAsGuest($args){
|
public static function joinAsGuest($args){
|
||||||
$uid = self::preDispatchGuest();
|
self::preDispatchGuest();
|
||||||
$uid = substr(@$_POST['name'], 0, 16) .' '. $uid;
|
|
||||||
$token = @$args['token'];
|
$uid = Helper::getArrayValueByKey($_POST, 'name');
|
||||||
|
$guestUid = substr($uid, 0, 16);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
$token = Helper::getArrayValueByKey($args, 'token');
|
||||||
$file = File::getByShareToken($token);
|
$file = File::getByShareToken($token);
|
||||||
self::join($uid, $file);
|
$session = Db_Session::start($uid, $file, true);
|
||||||
|
\OCP\JSON::success($session);
|
||||||
} catch (\Exception $e){
|
} catch (\Exception $e){
|
||||||
Helper::warnLog('Starting a session failed. Reason: ' . $e->getMessage());
|
Helper::warnLog('Starting a session failed. Reason: ' . $e->getMessage());
|
||||||
\OCP\JSON::error();
|
\OCP\JSON::error();
|
||||||
@ -30,16 +34,20 @@ class SessionController extends Controller{
|
|||||||
|
|
||||||
public static function joinAsUser($args){
|
public static function joinAsUser($args){
|
||||||
$uid = self::preDispatch();
|
$uid = self::preDispatch();
|
||||||
$fileId = intval(@$args['file_id']);
|
$fileId = Helper::getArrayValueByKey($args, 'file_id');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$file = new File($fileId);
|
$view = \OC\Files\Filesystem::getView();
|
||||||
|
$path = $view->getPath($fileId);
|
||||||
|
|
||||||
if ($file->getPermissions() & \OCP\PERMISSION_UPDATE) {
|
if ($view->isUpdatable($path)) {
|
||||||
self::join($uid, $file);
|
$file = new File($fileId);
|
||||||
|
$session = Db_Session::start($uid, $file);
|
||||||
|
\OCP\JSON::success($session);
|
||||||
} else {
|
} else {
|
||||||
|
$info = $view->getFileInfo();
|
||||||
\OCP\JSON::success(array(
|
\OCP\JSON::success(array(
|
||||||
'permissions' => $file->getPermissions(),
|
'permissions' => $info['permissions'],
|
||||||
'id' => $fileId
|
'id' => $fileId
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -51,11 +59,6 @@ class SessionController extends Controller{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function join($uid, $file){
|
|
||||||
$session = Db_Session::start($uid, $file);
|
|
||||||
\OCP\JSON::success($session);
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store the document content to its origin
|
* Store the document content to its origin
|
||||||
@ -68,6 +71,19 @@ class SessionController extends Controller{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$memberId = @$_SERVER['HTTP_WEBODF_MEMBER_ID'];
|
$memberId = @$_SERVER['HTTP_WEBODF_MEMBER_ID'];
|
||||||
|
$currentMember = new Db_Member();
|
||||||
|
$currentMember->load($memberId);
|
||||||
|
if (is_null($currentMember->getIsGuest()) || $currentMember->getIsGuest()){
|
||||||
|
$uid = self::preDispatchGuest();
|
||||||
|
} else {
|
||||||
|
self::preDispatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
//check if member belongs to the session
|
||||||
|
if ($esId != $currentMember->getEsId()){
|
||||||
|
throw new \Exception($memberId . ' does not belong to session ' . $esId);
|
||||||
|
}
|
||||||
|
|
||||||
$sessionRevision = @$_SERVER['HTTP_WEBODF_SESSION_REVISION'];
|
$sessionRevision = @$_SERVER['HTTP_WEBODF_SESSION_REVISION'];
|
||||||
|
|
||||||
$stream = fopen('php://input','r');
|
$stream = fopen('php://input','r');
|
||||||
@ -79,22 +95,21 @@ class SessionController extends Controller{
|
|||||||
$session = new Db_Session();
|
$session = new Db_Session();
|
||||||
$session->load($esId);
|
$session->load($esId);
|
||||||
|
|
||||||
if (!$session->hasData()){
|
if (!$session->getEsId()){
|
||||||
throw new \Exception('Session does not exist');
|
throw new \Exception('Session does not exist');
|
||||||
}
|
}
|
||||||
$sessionData = $session->getData();
|
|
||||||
try {
|
try {
|
||||||
$file = new File($sessionData['file_id']);
|
if ($currentMember->getIsGuest()){
|
||||||
if (!$file->isPublicShare()){
|
$file = File::getByShareToken($currentMember->getToken());
|
||||||
self::preDispatch();
|
|
||||||
} else {
|
} else {
|
||||||
self::preDispatchGuest();
|
$file = new File($session->getFileId());
|
||||||
}
|
}
|
||||||
|
|
||||||
list($view, $path) = $file->getOwnerViewAndPath();
|
list($view, $path) = $file->getOwnerViewAndPath();
|
||||||
} catch (\Exception $e){
|
} catch (\Exception $e){
|
||||||
//File was deleted or unshared. We need to save content as new file anyway
|
//File was deleted or unshared. We need to save content as new file anyway
|
||||||
//Sorry, but for guests it would be lost :(
|
//Sorry, but for guests it would be lost :(
|
||||||
$uid = self::preDispatch();
|
|
||||||
$view = new \OC\Files\View('/' . $uid . '/files');
|
$view = new \OC\Files\View('/' . $uid . '/files');
|
||||||
|
|
||||||
$dir = \OCP\Config::getUserValue(\OCP\User::getUser(), 'documents', 'save_path', '');
|
$dir = \OCP\Config::getUserValue(\OCP\User::getUser(), 'documents', 'save_path', '');
|
||||||
@ -110,22 +125,16 @@ class SessionController extends Controller{
|
|||||||
$members
|
$members
|
||||||
);
|
);
|
||||||
|
|
||||||
//check if member belongs to the session
|
|
||||||
if (!in_array($memberId, $memberIds)){
|
|
||||||
throw new \Exception($memberId . ' does not belong to session ' . $esId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Active users except current user
|
// Active users except current user
|
||||||
$memberCount = count($memberIds) - 1;
|
$memberCount = count($memberIds) - 1;
|
||||||
|
|
||||||
if ($view->file_exists($path)){
|
if ($view->file_exists($path)){
|
||||||
|
|
||||||
$proxyStatus = \OC_FileProxy::$enabled;
|
$proxyStatus = \OC_FileProxy::$enabled;
|
||||||
\OC_FileProxy::$enabled = false;
|
\OC_FileProxy::$enabled = false;
|
||||||
$currentHash = sha1($view->file_get_contents($path));
|
$currentHash = sha1($view->file_get_contents($path));
|
||||||
\OC_FileProxy::$enabled = $proxyStatus;
|
\OC_FileProxy::$enabled = $proxyStatus;
|
||||||
|
|
||||||
if (!Helper::isVersionsEnabled() && $currentHash !== $sessionData['genesis_hash']){
|
if (!Helper::isVersionsEnabled() && $currentHash !== $session->getGenesisHash()){
|
||||||
// Original file was modified externally. Save to a new one
|
// Original file was modified externally. Save to a new one
|
||||||
$path = Helper::getNewFileName($view, $path, '-conflict');
|
$path = Helper::getNewFileName($view, $path, '-conflict');
|
||||||
}
|
}
|
||||||
@ -142,7 +151,6 @@ class SessionController extends Controller{
|
|||||||
if ($memberCount>0){
|
if ($memberCount>0){
|
||||||
// Update genesis hash to prevent conflicts
|
// Update genesis hash to prevent conflicts
|
||||||
Helper::debugLog('Update hash');
|
Helper::debugLog('Update hash');
|
||||||
|
|
||||||
$session->updateGenesisHash($esId, sha1($data['content']));
|
$session->updateGenesisHash($esId, sha1($data['content']));
|
||||||
} else {
|
} else {
|
||||||
// Last user. Kill session data
|
// Last user. Kill session data
|
||||||
|
@ -29,8 +29,7 @@ class UserController extends Controller{
|
|||||||
$member = new Db_Member();
|
$member = new Db_Member();
|
||||||
$member->loadBy('member_id', $args['member_id']);
|
$member->loadBy('member_id', $args['member_id']);
|
||||||
if ($esId && $member->hasData()){
|
if ($esId && $member->hasData()){
|
||||||
$memberData = $member->getData();
|
if ($member->getEsId() === $esId && $member->getStatus() == Db_Member::MEMBER_STATUS_ACTIVE){
|
||||||
if ($memberData['es_id']===$esId && $memberData['status']==Db_Member::MEMBER_STATUS_ACTIVE){
|
|
||||||
$member->deactivate(array($args['member_id']));
|
$member->deactivate(array($args['member_id']));
|
||||||
$op = new Db_Op();
|
$op = new Db_Op();
|
||||||
$op->removeMember($esId, $args['member_id']);
|
$op->removeMember($esId, $args['member_id']);
|
||||||
@ -40,19 +39,24 @@ class UserController extends Controller{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function rename($args){
|
public static function rename($args){
|
||||||
|
self::preDispatchGuest();
|
||||||
|
|
||||||
$memberId = Helper::getArrayValueByKey($args, 'member_id');
|
$memberId = Helper::getArrayValueByKey($args, 'member_id');
|
||||||
$name = Helper::getArrayValueByKey($_POST, 'name');
|
$name = Helper::getArrayValueByKey($_POST, 'name');
|
||||||
$member = new Db_Member();
|
$member = new Db_Member();
|
||||||
$member->load($memberId);
|
$member->load($memberId);
|
||||||
$memberData = $member->getData();
|
|
||||||
if (count($memberData) && $memberData['status']==Db_Member::MEMBER_STATUS_ACTIVE
|
if ($member->getEsId()
|
||||||
&& preg_match('/.* \(guest\)$/', $memberData['uid'])
|
&& $member->getStatus() == Db_Member::MEMBER_STATUS_ACTIVE
|
||||||
|
&& $member->getIsGuest()
|
||||||
){
|
){
|
||||||
if (!preg_match('/.* \(guest\)$/', $name)){
|
$guestMark = Db_Member::getGuestPostfix();
|
||||||
$name .= ' (guest)';
|
if (substr($name, -strlen($guestMark)) !== $guestMark){
|
||||||
|
$name = $name . ' ' . $guestMark;
|
||||||
}
|
}
|
||||||
|
|
||||||
$op = new Db_Op();
|
$op = new Db_Op();
|
||||||
$op->changeNick($memberData['es_id'], $memberId, $name);
|
$op->changeNick($member->getEsId(), $memberId, $name);
|
||||||
}
|
}
|
||||||
\OCP\JSON::success();
|
\OCP\JSON::success();
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* ownCloud - Documents App
|
* ownCloud - Documents App
|
||||||
*
|
*
|
||||||
* @author Frank Karlitschek
|
* @author Frank Karlitschek
|
||||||
* @copyright 2011 Frank Karlitschek karlitschek@kde.org
|
* @copyright 2013-2014 Frank Karlitschek karlitschek@kde.org
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
@ -26,14 +26,12 @@ OCP\App::register(array('order' => 70, 'id' => 'documents', 'name' => 'Documents
|
|||||||
\OCP\App::registerAdmin('documents', 'admin');
|
\OCP\App::registerAdmin('documents', 'admin');
|
||||||
OCP\App::registerPersonal('documents', 'personal');
|
OCP\App::registerPersonal('documents', 'personal');
|
||||||
|
|
||||||
$l10n = \OCP\Util::getL10N('documents');
|
|
||||||
|
|
||||||
OCP\App::addNavigationEntry(array(
|
OCP\App::addNavigationEntry(array(
|
||||||
'id' => 'documents_index',
|
'id' => 'documents_index',
|
||||||
'order' => 2,
|
'order' => 2,
|
||||||
'href' => OCP\Util::linkTo('documents', 'index.php'),
|
'href' => OCP\Util::linkTo('documents', 'index.php'),
|
||||||
'icon' => OCP\Util::imagePath('documents', 'documents.svg'),
|
'icon' => OCP\Util::imagePath('documents', 'documents.svg'),
|
||||||
'name' => $l10n->t('Documents'))
|
'name' => OCA\Documents\Config::getL10n()->t('Documents'))
|
||||||
);
|
);
|
||||||
|
|
||||||
OC::$CLASSPATH['OCA\Documents\Controller'] = 'documents/ajax/controller.php';
|
OC::$CLASSPATH['OCA\Documents\Controller'] = 'documents/ajax/controller.php';
|
||||||
|
@ -91,6 +91,21 @@
|
|||||||
<unsigned>true</unsigned>
|
<unsigned>true</unsigned>
|
||||||
<length>4</length>
|
<length>4</length>
|
||||||
</field>
|
</field>
|
||||||
|
<field>
|
||||||
|
<name>is_guest</name>
|
||||||
|
<type>integer</type>
|
||||||
|
<default>0</default>
|
||||||
|
<notnull>true</notnull>
|
||||||
|
<unsigned>true</unsigned>
|
||||||
|
<length>1</length>
|
||||||
|
</field>
|
||||||
|
<field>
|
||||||
|
<name>token</name>
|
||||||
|
<type>text</type>
|
||||||
|
<default></default>
|
||||||
|
<notnull>false</notnull>
|
||||||
|
<length>32</length>
|
||||||
|
</field>
|
||||||
<field>
|
<field>
|
||||||
<name>status</name>
|
<name>status</name>
|
||||||
<type>integer</type>
|
<type>integer</type>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<description>An ownCloud app to work with office documents</description>
|
<description>An ownCloud app to work with office documents</description>
|
||||||
<licence>AGPL</licence>
|
<licence>AGPL</licence>
|
||||||
<author>Frank Karlitschek</author>
|
<author>Frank Karlitschek</author>
|
||||||
<require>5.0.19</require>
|
<require>6.0</require>
|
||||||
<shipped>true</shipped>
|
<shipped>true</shipped>
|
||||||
<default_enable/>
|
<default_enable/>
|
||||||
<public>
|
<public>
|
||||||
|
@ -29,3 +29,7 @@ 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->execute(array());
|
||||||
|
}
|
@ -1 +1 @@
|
|||||||
0.7.2
|
0.8.1
|
@ -4,7 +4,7 @@
|
|||||||
* ownCloud - Documents App
|
* ownCloud - Documents App
|
||||||
*
|
*
|
||||||
* @author Frank Karlitschek
|
* @author Frank Karlitschek
|
||||||
* @copyright 2011 Frank Karlitschek karlitschek@kde.org
|
* @copyright 2013-2014 Frank Karlitschek karlitschek@kde.org
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
@ -714,9 +714,9 @@ var Files = Files || {
|
|||||||
|
|
||||||
if ( $('#isPublic').length ) {
|
if ( $('#isPublic').length ) {
|
||||||
urlSpec.t = $('#dirToken').val();
|
urlSpec.t = $('#dirToken').val();
|
||||||
previewURL = OC.Router.generate('core_ajax_public_preview', urlSpec);
|
previewURL = OC.generateUrl('core_ajax_public_preview/{url_spec}', {url_spec : urlSpec});
|
||||||
} else {
|
} else {
|
||||||
previewURL = OC.Router.generate('core_ajax_preview', urlSpec);
|
previewURL = OC.generateUrl('core_ajax_preview/{url_spec}', {url_spec : urlSpec});
|
||||||
}
|
}
|
||||||
previewURL = previewURL.replace('(', '%28');
|
previewURL = previewURL.replace('(', '%28');
|
||||||
previewURL = previewURL.replace(')', '%29');
|
previewURL = previewURL.replace(')', '%29');
|
||||||
|
@ -15,6 +15,10 @@ namespace OCA\Documents;
|
|||||||
class Config {
|
class Config {
|
||||||
const APP_NAME = 'documents';
|
const APP_NAME = 'documents';
|
||||||
|
|
||||||
|
public static function getL10n(){
|
||||||
|
return \OCP\Util::getL10N(self::APP_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
public static function getConverter(){
|
public static function getConverter(){
|
||||||
return self::getAppValue('converter', 'local');
|
return self::getAppValue('converter', 'local');
|
||||||
}
|
}
|
||||||
|
11
lib/db.php
11
lib/db.php
@ -206,4 +206,15 @@ abstract class Db {
|
|||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function __call($name, $arguments){
|
||||||
|
if (substr($name, 0, 3) === 'get'){
|
||||||
|
$requestedProperty = substr($name, 3);
|
||||||
|
$property = strtolower(preg_replace('/(.)([A-Z])/', "$1_$2", $requestedProperty));
|
||||||
|
if (isset($this->data[$property])){
|
||||||
|
return $this->data[$property];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,11 +23,16 @@ class Db_Member extends Db{
|
|||||||
|
|
||||||
protected $tableName = '`*PREFIX*documents_member`';
|
protected $tableName = '`*PREFIX*documents_member`';
|
||||||
|
|
||||||
protected $insertStatement = 'INSERT INTO `*PREFIX*documents_member` (`es_id`, `uid`, `color`, `last_activity`)
|
protected $insertStatement = 'INSERT INTO `*PREFIX*documents_member` (`es_id`, `uid`, `color`, `last_activity`, `is_guest`, `token`)
|
||||||
VALUES (?, ?, ?, ?)';
|
VALUES (?, ?, ?, ?, ?, ?)';
|
||||||
|
|
||||||
protected $loadStatement = 'SELECT * FROM `*PREFIX*documents_member` WHERE `member_id`= ?';
|
protected $loadStatement = 'SELECT * FROM `*PREFIX*documents_member` WHERE `member_id`= ?';
|
||||||
|
|
||||||
|
public static function getGuestPostfix(){
|
||||||
|
return '(' . Config::getL10n()->t('guest') . ')';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function updateActivity($memberId){
|
public function updateActivity($memberId){
|
||||||
return $this->execute(
|
return $this->execute(
|
||||||
'UPDATE ' . $this->tableName . ' SET `last_activity`=?, `status`=? WHERE `member_id`=?',
|
'UPDATE ' . $this->tableName . ' SET `last_activity`=?, `status`=? WHERE `member_id`=?',
|
||||||
|
@ -35,13 +35,11 @@ class Db_Session extends \OCA\Documents\Db {
|
|||||||
* @return array
|
* @return array
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function start($uid, File $file){
|
public static function start($uid, $file){
|
||||||
list($ownerView, $path) = $file->getOwnerViewAndPath();
|
|
||||||
|
|
||||||
// Create a directory to store genesis
|
// Create a directory to store genesis
|
||||||
|
$genesis = new Genesis($file);
|
||||||
|
|
||||||
$genesis = new Genesis($ownerView, $path, $file->getOwner());
|
list($ownerView, $path) = $file->getOwnerViewAndPath();
|
||||||
|
|
||||||
$oldSession = new Db_Session();
|
$oldSession = new Db_Session();
|
||||||
$oldSession->loadBy('file_id', $file->getFileId());
|
$oldSession->loadBy('file_id', $file->getFileId());
|
||||||
|
|
||||||
@ -59,55 +57,37 @@ class Db_Session extends \OCA\Documents\Db {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$session = $oldSession
|
$sessionData = $oldSession
|
||||||
->loadBy('file_id', $file->getFileId())
|
->loadBy('file_id', $file->getFileId())
|
||||||
->getData()
|
->getData()
|
||||||
;
|
;
|
||||||
$session['title'] = basename($path);
|
|
||||||
|
|
||||||
$memberColor = Helper::getMemberColor($uid);
|
$memberColor = Helper::getMemberColor($uid);
|
||||||
|
|
||||||
$member = new Db_Member(array(
|
$member = new Db_Member(array(
|
||||||
$session['es_id'],
|
$sessionData['es_id'],
|
||||||
$uid,
|
$uid,
|
||||||
$memberColor,
|
$memberColor,
|
||||||
time()
|
time(),
|
||||||
|
intval($file->isPublicShare()),
|
||||||
|
$file->getToken()
|
||||||
));
|
));
|
||||||
|
|
||||||
if ($member->insert()){
|
if ($member->insert()){
|
||||||
// Do we have OC_Avatar in out disposal?
|
// Do we have OC_Avatar in out disposal?
|
||||||
if (!class_exists('\OC_Avatar') || \OC_Config::getValue('enable_avatars', true) !== true){
|
if (!class_exists('\OC_Avatar') || \OC_Config::getValue('enable_avatars', true) !== true){
|
||||||
//$x['avatar_url'] = \OCP\Util::linkToRoute('documents_user_avatar');
|
|
||||||
$imageUrl = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw==';
|
$imageUrl = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw==';
|
||||||
} else {
|
} else {
|
||||||
// https://github.com/owncloud/documents/issues/51
|
|
||||||
// Temporary stub
|
|
||||||
$imageUrl = $uid;
|
$imageUrl = $uid;
|
||||||
|
|
||||||
/*
|
|
||||||
$avatar = new \OC_Avatar($uid);
|
|
||||||
$image = $avatar->get(64);
|
|
||||||
// User has an avatar
|
|
||||||
if ($image instanceof \OC_Image) {
|
|
||||||
$imageUrl = \OC_Helper::linkToRoute(
|
|
||||||
'core_avatar_get',
|
|
||||||
array( 'user' => $uid, 'size' => 64)
|
|
||||||
) . '?requesttoken=' . \OC::$session->get('requesttoken');
|
|
||||||
} else {
|
|
||||||
//shortcircuit if it's not an image
|
|
||||||
$imageUrl = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw==';
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$displayName = $file->isPublicShare() ? $uid . ' ' . Db_Member::getGuestPostfix() : \OCP\User::getDisplayName($uid);
|
||||||
|
|
||||||
$session['member_id'] = (string) $member->getLastInsertId();
|
$sessionData['member_id'] = (string) $member->getLastInsertId();
|
||||||
$op = new Db_Op();
|
$op = new Db_Op();
|
||||||
$op->addMember(
|
$op->addMember(
|
||||||
$session['es_id'],
|
$sessionData['es_id'],
|
||||||
$session['member_id'],
|
$sessionData['member_id'],
|
||||||
\OCP\User::getDisplayName($uid),
|
$displayName,
|
||||||
$memberColor,
|
$memberColor,
|
||||||
$imageUrl
|
$imageUrl
|
||||||
);
|
);
|
||||||
@ -115,9 +95,10 @@ class Db_Session extends \OCA\Documents\Db {
|
|||||||
throw new \Exception('Failed to add member into database');
|
throw new \Exception('Failed to add member into database');
|
||||||
}
|
}
|
||||||
|
|
||||||
$session['permissions'] = $ownerView->getFilePermissions($path);
|
$sessionData['title'] = basename($path);
|
||||||
|
$sessionData['permissions'] = $ownerView->getFilePermissions($path);
|
||||||
|
|
||||||
return $session;
|
return $sessionData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function cleanUp($esId){
|
public static function cleanUp($esId){
|
||||||
@ -196,14 +177,8 @@ class Db_Session extends \OCA\Documents\Db {
|
|||||||
protected function getUniqueSessionId(){
|
protected function getUniqueSessionId(){
|
||||||
$testSession = new Db_Session();
|
$testSession = new Db_Session();
|
||||||
do{
|
do{
|
||||||
// this prevents branching for stable5 for now:
|
$id = \OC_Util::generateRandomBytes(30);
|
||||||
// OC_Util::generate_random_bytes was camelCased
|
} while ($testSession->load($id)->hasData());
|
||||||
if (method_exists('\OC_Util', 'generate_random_bytes')){
|
|
||||||
$id = \OC_Util::generate_random_bytes(30);
|
|
||||||
} else {
|
|
||||||
$id = \OC_Util::generateRandomBytes(30);
|
|
||||||
}
|
|
||||||
}while ($testSession->load($id)->hasData());
|
|
||||||
|
|
||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
|
85
lib/file.php
85
lib/file.php
@ -28,6 +28,7 @@ class File {
|
|||||||
protected $owner;
|
protected $owner;
|
||||||
protected $path;
|
protected $path;
|
||||||
protected $sharing;
|
protected $sharing;
|
||||||
|
protected $token ='';
|
||||||
protected $passwordProtected = false;
|
protected $passwordProtected = false;
|
||||||
|
|
||||||
|
|
||||||
@ -47,28 +48,18 @@ class File {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function getByShareToken($token){
|
public static function getByShareToken($token){
|
||||||
$linkItem = \OCP\Share::getShareByToken($token, false);
|
$linkItem = \OCP\Share::getShareByToken($token, false);
|
||||||
if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
|
if (is_array($linkItem) && isset($linkItem['uid_owner'])) {
|
||||||
// seems to be a valid share
|
// seems to be a valid share
|
||||||
$rootLinkItem = \OCP\Share::resolveReShare($linkItem);
|
$rootLinkItem = \OCP\Share::resolveReShare($linkItem);
|
||||||
$fileOwner = $rootLinkItem['uid_owner'];
|
|
||||||
} else {
|
} else {
|
||||||
throw new \Exception('This file was probably unshared');
|
throw new \Exception('This file was probably unshared');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($rootLinkItem['path']) && isset($rootLinkItem['file_target'])){
|
|
||||||
$rootLinkItem['path'] = $rootLinkItem['file_target'];
|
|
||||||
}
|
|
||||||
$file = new File($rootLinkItem['file_source'], array($rootLinkItem));
|
$file = new File($rootLinkItem['file_source'], array($rootLinkItem));
|
||||||
|
$file->setToken($token);
|
||||||
|
|
||||||
if (isset($rootLinkItem['uid_owner'])){
|
|
||||||
\OC_Util::tearDownFS();
|
|
||||||
\OC_Util::setupFS($rootLinkItem['uid_owner']);
|
|
||||||
$file->setOwner($rootLinkItem['uid_owner']);
|
|
||||||
$file->setPath(\OC\Files\Filesystem::getPath($linkItem['file_source']));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($linkItem['share_with']) && !empty($linkItem['share_with'])){
|
if (isset($linkItem['share_with']) && !empty($linkItem['share_with'])){
|
||||||
$file->setPasswordProtected(true);
|
$file->setPasswordProtected(true);
|
||||||
@ -77,6 +68,10 @@ class File {
|
|||||||
return $file;
|
return $file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getToken($token){
|
||||||
|
return $this->token;
|
||||||
|
}
|
||||||
|
|
||||||
public function getFileId(){
|
public function getFileId(){
|
||||||
return $this->fileId;
|
return $this->fileId;
|
||||||
}
|
}
|
||||||
@ -89,16 +84,12 @@ class File {
|
|||||||
$this->path = $path;
|
$this->path = $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setToken($token){
|
||||||
|
$this->token = $token;
|
||||||
|
}
|
||||||
|
|
||||||
public function isPublicShare(){
|
public function isPublicShare(){
|
||||||
foreach ($this->sharing as $share){
|
return !empty($this->token);
|
||||||
if (
|
|
||||||
$share['share_type'] == \OCP\Share::SHARE_TYPE_LINK
|
|
||||||
|| $share['share_type'] == \OCP\Share::SHARE_TYPE_EMAIL
|
|
||||||
){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isPasswordProtected(){
|
public function isPasswordProtected(){
|
||||||
@ -158,22 +149,27 @@ class File {
|
|||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function getOwnerViewAndPath(){
|
public function getOwnerViewAndPath(){
|
||||||
if (!$this->owner || !$this->path){
|
if ($this->isPublicShare()){
|
||||||
if ($this->isPublicShare()){
|
$rootLinkItem = \OCP\Share::resolveReShare($this->sharing[0]);
|
||||||
list($owner, $path) = $this->getSharedFileOwnerAndPath();
|
if (isset($rootLinkItem['uid_owner'])){
|
||||||
|
$owner = $rootLinkItem['uid_owner'];
|
||||||
} else {
|
} else {
|
||||||
$owner = \OCP\User::getUser();
|
throw new \Exception($this->fileId . ' is a broken share');
|
||||||
$path = Storage::resolvePath($this->fileId);
|
|
||||||
if (!$path){
|
|
||||||
throw new \Exception($this->fileId . ' can not be resolved');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
$view = new View('/' . $owner . '/files');
|
||||||
$this->path = $path;
|
$path = $rootLinkItem['file_target'];
|
||||||
$this->owner = $owner;
|
} else {
|
||||||
|
$owner = \OCP\User::getUser();
|
||||||
|
$view = new View('/' . $this->owner);
|
||||||
|
$path = $view->getPath($this->fileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
$view = new View('/' . $this->owner . '/files');
|
if (!$path){
|
||||||
|
throw new \Exception($this->fileId . ' can not be resolved');
|
||||||
|
}
|
||||||
|
$this->path = $path;
|
||||||
|
$this->owner = $owner;
|
||||||
|
|
||||||
if (!$view->file_exists($this->path)){
|
if (!$view->file_exists($this->path)){
|
||||||
throw new \Exception($this->path . ' doesn\'t exist');
|
throw new \Exception($this->path . ' doesn\'t exist');
|
||||||
}
|
}
|
||||||
@ -181,6 +177,7 @@ class File {
|
|||||||
return array($view, $this->path);
|
return array($view, $this->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getOwner(){
|
public function getOwner(){
|
||||||
if (!$this->owner){
|
if (!$this->owner){
|
||||||
$this->getOwnerViewAndPath();
|
$this->getOwnerViewAndPath();
|
||||||
@ -188,28 +185,6 @@ class File {
|
|||||||
return $this->owner;
|
return $this->owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* public links only
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function getSharedFileOwnerAndPath(){
|
|
||||||
foreach ($this->sharing as $share){
|
|
||||||
$rootLinkItem = \OCP\Share::resolveReShare($share);
|
|
||||||
if (isset($rootLinkItem['uid_owner'])){
|
|
||||||
$owner = $rootLinkItem['uid_owner'];
|
|
||||||
} else {
|
|
||||||
$owner = false;
|
|
||||||
}
|
|
||||||
\OC_Util::tearDownFS();
|
|
||||||
\OC_Util::setupFS($owner);
|
|
||||||
return array(
|
|
||||||
$owner,
|
|
||||||
\OC\Files\Filesystem::getPath($rootLinkItem['file_source'])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getPassword(){
|
protected function getPassword(){
|
||||||
return $this->sharing[0]['share_with'];
|
return $this->sharing[0]['share_with'];
|
||||||
|
@ -15,8 +15,8 @@ namespace OCA\Documents;
|
|||||||
class Filter_Office {
|
class Filter_Office {
|
||||||
const NATIVE_MIMETYPE = 'application/vnd.oasis.opendocument.text';
|
const NATIVE_MIMETYPE = 'application/vnd.oasis.opendocument.text';
|
||||||
|
|
||||||
private static $readSpec;
|
private $readSpec;
|
||||||
private static $writeSpec;
|
private $writeSpec;
|
||||||
|
|
||||||
/* sample mimespec
|
/* sample mimespec
|
||||||
array (
|
array (
|
||||||
|
@ -35,11 +35,12 @@ class Genesis {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new genesis document
|
* Create new genesis document
|
||||||
* @param OCA\Documents\View $view Filesystem view with root '/user/files'
|
* @param OCA\Documents\File $file
|
||||||
* @param string $path relative path
|
|
||||||
* @param string $owner file owner
|
|
||||||
* */
|
* */
|
||||||
public function __construct(\OCA\Documents\View $view, $path, $owner){
|
public function __construct(\OCA\Documents\File $file){
|
||||||
|
list($view, $path) = $file->getOwnerViewAndPath();
|
||||||
|
$owner = $file->getOwner();
|
||||||
|
|
||||||
$this->view = new View('/' . $owner);
|
$this->view = new View('/' . $owner);
|
||||||
|
|
||||||
if (!$this->view->file_exists(self::DOCUMENTS_DIRNAME)){
|
if (!$this->view->file_exists(self::DOCUMENTS_DIRNAME)){
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* ownCloud - Documents App
|
* ownCloud - Documents App
|
||||||
*
|
*
|
||||||
* @author Frank Karlitschek
|
* @author Frank Karlitschek
|
||||||
* @copyright 2012 Frank Karlitschek frank@owncloud.org
|
* @copyright 2013-2014 Frank Karlitschek frank@owncloud.org
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
@ -71,25 +71,22 @@ class Storage {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sessionObj = new Db_Session();
|
$session = new Db_Session();
|
||||||
$session = $sessionObj
|
$session->loadBy('file_id', $fileId);
|
||||||
->loadBy('file_id', $fileId)
|
|
||||||
->getData()
|
|
||||||
;
|
|
||||||
|
|
||||||
if (!is_array($session) || !isset($session['es_id'])){
|
if (!$session->getEsId()){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$member = new Db_Member();
|
$member = new Db_Member();
|
||||||
$sessionMembers = $member->getCollectionBy('es_id', $session['es_id']);
|
$sessionMembers = $member->getCollectionBy('es_id', $session->getEsId());
|
||||||
foreach ($sessionMembers as $memberData){
|
foreach ($sessionMembers as $memberData){
|
||||||
if (intval($memberData['status'])===Db_Member::MEMBER_STATUS_ACTIVE){
|
if (intval($memberData['status'])===Db_Member::MEMBER_STATUS_ACTIVE){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Db_Session::cleanUp($session['es_id']);
|
Db_Session::cleanUp($session->getEsId());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function searchDocuments(){
|
protected static function searchDocuments(){
|
||||||
|
11
public.php
11
public.php
@ -40,9 +40,14 @@ if (isset($_GET['t'])) {
|
|||||||
\OCP\Util::addScript('documents', 'documents');
|
\OCP\Util::addScript('documents', 'documents');
|
||||||
if ($file->getFileId()){
|
if ($file->getFileId()){
|
||||||
$session = new Db_Session();
|
$session = new Db_Session();
|
||||||
$sessionData = $session->loadBy('file_id', $file->getFileId())->getData();
|
$session->loadBy('file_id', $file->getFileId());
|
||||||
$member = new Db_Member();
|
|
||||||
$members = $member->getCollectionBy('es_id', $sessionData['es_id']);
|
if ($session->getEsId()){
|
||||||
|
$member = new Db_Member();
|
||||||
|
$members = $member->getCollectionBy('es_id', $session->getEsId());
|
||||||
|
} else {
|
||||||
|
$members = 0;
|
||||||
|
}
|
||||||
$tmpl->assign('total', count($members)+1);
|
$tmpl->assign('total', count($members)+1);
|
||||||
} else {
|
} else {
|
||||||
$tmpl->assign('total', 1);
|
$tmpl->assign('total', 1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user