Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Rework Inbox Driver
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Mar 9, 2016
1 parent 359e514 commit 7d9478c
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 236 deletions.
8 changes: 4 additions & 4 deletions core/src/plugins/access.inbox/Gruntfile.js
Expand Up @@ -7,9 +7,9 @@ module.exports = function(grunt) {
files: [
{
expand: true,
cwd: 'res/react/',
src: ['**/*.js'],
dest: 'res/build/',
cwd: 'res/',
src: ['**/*.es6'],
dest: 'res/',
ext: '.js'
}
]
Expand All @@ -18,7 +18,7 @@ module.exports = function(grunt) {
watch: {
js: {
files: [
"res/react/**/*"
"res/*.es6"
],
tasks: ['babel'],
options: {
Expand Down
279 changes: 109 additions & 170 deletions core/src/plugins/access.inbox/class.inboxAccessDriver.php
Expand Up @@ -26,165 +26,26 @@
class inboxAccessDriver extends fsAccessDriver
{
private static $output;
private static $stats;

public function initRepository()
{
$this->detectStreamWrapper(true);
$this->urlBase = "pydio://".$this->repository->getId();
}

/**
*
* Main callback for all share- actions.
* @param string $action
* @param array $httpVars
* @param array $fileVars
* @return null
* @throws Exception
*/
public function switchAction($action, $httpVars, $fileVars) {

switch ($action) {
//------------------------------------
// SHARING FILE OR FOLDER
//------------------------------------
case "load_shares":

$nodes = static::getNodes();

header("Content-type:application/json");

$data = [];
$data["shares"] = [];

foreach ($nodes as $key => $node) {

$n = new AJXP_Node($node['url']);

$remoteShare = $node['remote_share'];

$repositoryId = $n->getRepositoryId();
$n->getRepository()->driverInstance = null;

try {
ConfService::loadDriverForRepository($n->getRepository());
} catch (\Exception $e) {
continue;
}

$repository = $n->getRepository();

$currentData = [
"repositoryId" => $repositoryId
];

if (!empty($remoteShare)) {
$currentData += [
"label" => $remoteShare->getDocumentName(),
"owner" => $remoteShare->getSender() . ' (remote)',
"cr_date" => $remoteShare->getReceptionDate(),
"status" => $remoteShare->getStatus()
];

if ($remoteShare->getStatus() == 1) {
// Adding the actions button
$currentData += [
"actions" => [[
"id" => "accept",
"message" => "Accepter",
"options" => [
"get_action" => "accept_invitation",
"remote_share_id" => $remoteShare->getId(),
"statusOnSuccess" => OCS_INVITATION_STATUS_ACCEPTED
]
],
[
"id" => "decline",
"message" => "Refuser",
"options" => [
"get_action" => "reject_invitation",
"remote_share_id" => $remoteShare->getId(),
"statusOnSuccess" => OCS_INVITATION_STATUS_REJECTED
]
]]
];
}
} else {
$currentData += [
"label" => $n->getLabel(),
"owner" => $repository->getOwner(),
"cr_date" => $repository->getOption('CREATION_TIME'),
];
}

// Ensuring that mandatory options are set
$currentData += [
"status" => 0,
"actions" => [[
"id" => "view",
"message" => "View",
"options" => [
"get_action" => "switch_repository",
"repository_id" => $repositoryId
]
]]
];

$data["shares"][] = $currentData;
}

echo json_encode($data);

break;

default:
parent::switchAction($action, $httpVars, $fileVars);

break;
}
}

public function loadNodeInfo(&$ajxpNode, $parentNode = false, $details = false)
{
$mess = ConfService::getMessages();

parent::loadNodeInfo($ajxpNode, $parentNode, $details);

if(!$ajxpNode->isRoot()){
$targetUrl = inboxAccessWrapper::translateURL($ajxpNode->getUrl());
$repoId = parse_url($targetUrl, PHP_URL_HOST);
$r = ConfService::getRepositoryById($repoId);
if(!is_null($r)){
$owner = $r->getOwner();
$creationTime = $r->getOption("CREATION_TIME");
$label = $r->getDisplay();
}else{
$owner = "http://".parse_url($targetUrl, PHP_URL_HOST);
$creationTime = time();
$label = "";
}
$leaf = $ajxpNode->isLeaf();
$meta = array(
"shared_repository_id" => $repoId,
"ajxp_description" => ($leaf?"File":"Folder")." shared by ".$owner. " ". AJXP_Utils::relativeDate($creationTime, $mess)
);
if(!$leaf){
$meta["ajxp_mime"] = "shared_folder";
}

// Retrieving stored details
$originalNode = self::$output[$repoId];
$remoteShare = $originalNode['remote_share'];
$originalNode = self::$output[$ajxpNode->getLabel()];
$meta = $originalNode["meta"];
$label = $originalNode["label"];

if (!empty($remoteShare)) {
$meta["remote_share_id"] = $remoteShare->getId();
if ($remoteShare->getStatus() == 1) {
$label .= " (pending)";
$meta["ajxp_mime"] = "invitation";
} else {
$label .= " (accepted)";
$meta["remote_share_accepted"] = "true";
}
if(!$ajxpNode->isLeaf()){
$meta["icon"] = "mime_empty.png";
}

// Overriding display name with repository name
Expand All @@ -193,53 +54,131 @@ public function loadNodeInfo(&$ajxpNode, $parentNode = false, $details = false)
}
}

public static function getNodes(){
public static function getNodeData($nodePath){
$basename = basename(parse_url($nodePath, PHP_URL_PATH));
if(empty($basename)){
return ['stat' => stat(AJXP_Utils::getAjxpTmpDir())];
}
$allNodes = self::getNodes(false);
$nodeData = $allNodes[$basename];
if(!isSet($nodeData["stat"])){
if(in_array(pathinfo($basename, PATHINFO_EXTENSION), array("error", "invitation"))){
$stat = stat(AJXP_Utils::getAjxpTmpDir());
}else{
$url = $nodeData["url"];
$node = new AJXP_Node($nodeData["url"]);
$node->getRepository()->driverInstance = null;
try{
ConfService::loadDriverForRepository($node->getRepository());
$node->getRepository()->detectStreamWrapper(true);
$stat = stat($url);
self::$output[$basename]["stat"] = $stat;
}catch (Exception $e){
$stat = stat(AJXP_Utils::getAjxpTmpDir());
}
}
$nodeData["stat"] = $stat;
}
return $nodeData;
}

public static function getNodes($checkStats = false){

if(isSet(self::$output)){
return self::$output;
}

$mess = ConfService::getMessages();
$repos = ConfService::getAccessibleRepositories();

self::$output = array();
$output = array();
foreach($repos as $repo) {
if (!$repo->hasOwner()) {
if (!$repo->hasOwner() || !$repo->hasContentFilter()) {
continue;
}

$cFilter = $filter = $label = null;

$repoId = $repo->getId();
$url = "pydio://" . $repoId . "/";
$meta = array(
"shared_repository_id" => $repoId,
"ajxp_description" => "File shared by ".$repo->getOwner(). " ". AJXP_Utils::relativeDate($repo->getOption("CREATION_TIME"), $mess),
"share_meta_type" => 1
);

$cFilter = $repo->getContentFilter();
$filter = ($cFilter instanceof ContentFilter) ? array_keys($cFilter->filters)[0] : $cFilter;
if (!is_array($filter)) {
$label = basename($filter);
}else{
$label = $repo->getDisplay();
}
$url .= $label;

if ($repo->hasContentFilter()) {
$cFilter = $repo->getContentFilter();
$filter = ($cFilter instanceof ContentFilter) ? array_keys($cFilter->filters)[0] : $cFilter;
$status = null;
$remoteShare = null;
$name = pathinfo($label, PATHINFO_FILENAME);
$ext = pathinfo($label, PATHINFO_EXTENSION);

if (!is_array($filter)) {
$label = basename($filter);
}
}
$node = new AJXP_Node($url);
$node->setLabel($label);

if (empty($label)) {
$label = $repo->getDisplay();
}
if($checkStats){

$url .= $label;
if(strpos($repoId, "ocs_remote_share_") === 0){
// Check Status
$linkId = str_replace("ocs_remote_share_", "", $repoId);
$node->getRepository()->driverInstance = null;
try{
ConfService::loadDriverForRepository($node->getRepository());
}catch (Exception $e){
$ext = "error";
$meta["ajxp_mime"] = "error";
}
$node->getRepository()->detectStreamWrapper(true);

$stat = @stat($url);
if($stat === false){
$ext = "error";
$meta["ajxp_mime"] = "error";
$meta["share_meta_type"] = 2;
}else if(strpos($repoId, "ocs_remote_share_") === 0){
// Check Status
$linkId = str_replace("ocs_remote_share_", "", $repoId);
$ocsStore = new \Pydio\OCS\Model\SQLStore();
$remoteShare = $ocsStore->remoteShareById($linkId);
$status = $remoteShare->getStatus();
if($status == OCS_INVITATION_STATUS_PENDING){
$stat = stat(AJXP_Utils::getAjxpTmpDir());
$ext = "invitation";
$meta["ajxp_mime"] = "invitation";
$meta["share_meta_type"] = 0;
} else {
$meta["remote_share_accepted"] = "true";
}
$meta["remote_share_id"] = $remoteShare->getId();
}
if($ext == "invitation"){
$label .= " (pending)";
}else if($ext == "error"){
$label .= " (error)";
}

$ocsStore = new \Pydio\OCS\Model\SQLStore();
$remoteShare = $ocsStore->remoteShareById($linkId);
}

self::$output[$repoId] = [
$index = 0;$suffix = "";
while(isSet($output[$name.$suffix.".".$ext])){
$index ++;
$suffix = " ($index)";
}
$output[$name.$suffix.".".$ext] = [
"label" => $label,
"url" => $url,
"remote_share" => $remoteShare
"remote_share" => $remoteShare,
"meta" => $meta
];
if(isset($stat)){
$output[$name.$suffix.".".$ext]['stat'] = $stat;
}
}

return self::$output;
ConfService::loadDriverForRepository(ConfService::getRepository());
self::$output = $output;
return $output;
}
}
16 changes: 11 additions & 5 deletions core/src/plugins/access.inbox/class.inboxAccessWrapper.php
Expand Up @@ -47,7 +47,12 @@ class inboxAccessWrapper implements AjxpWrapper
*/
public function dir_opendir($path, $options)
{
$this->nodesIterator = new ArrayIterator(inboxAccessDriver::getNodes());
if(trim(parse_url($path, PHP_URL_PATH), "/") == ""){
$this->nodesIterator = new ArrayIterator(inboxAccessDriver::getNodes(true));
}else{
$this->nodesIterator = new ArrayIterator([]);
}


return true;
}
Expand Down Expand Up @@ -103,10 +108,8 @@ public static function translateURL($path){
$pydioScheme = false;
self::$linkNode = null;

$nodes = inboxAccessDriver::getNodes();

$nodes = inboxAccessDriver::getNodes(false);
$nodePath = basename(parse_url($path, PHP_URL_PATH));

$node = $nodes[ltrim($nodePath, '/')];

if (empty($node) || ! isset($node['url'])) {
Expand Down Expand Up @@ -402,14 +405,17 @@ public function unlink($path)
*/
public function url_stat($path, $flags)
{
$nodeData = inboxAccessDriver::getNodeData($path);
return $nodeData["stat"];

$url = self::translateURL($path);
if(strpos($url, "invitation") === 0){
return stat(__FILE__);
}
if($url == null){
return false;
}
$stat = @stat($url);
$stat = stat($url);
if($stat === false){
return false;
}
Expand Down

0 comments on commit 7d9478c

Please sign in to comment.