require_once '../../../lib/base.php';
OC_JSON::checkAppEnabled('files_sharing');
require_once '../lib_share.php';
$userDirectory = "/" . OC_User::getUser() . "/files";
$source = $userDirectory . $_GET['source'];
$path = $source;
if ($users = OC_Share::getMySharedItem($source)) {
    for ($i = 0; $i < count($users); $i++) {
        if ($users[$i]['uid_shared_with'] == OC_Share::PUBLICLINK) {
            $users[$i]['token'] = OC_Share::getTokenFromSource($source);
        }
    }
}
$source = dirname($source);
while ($source != "" && $source != "/" && $source != "." && $source != $userDirectory) {
    if ($values = OC_Share::getMySharedItem($source)) {
        $values = array_values($values);
        $parentUsers = array();
        for ($i = 0; $i < count($values); $i++) {
            if ($values[$i]['uid_shared_with'] == OC_Share::PUBLICLINK) {
                $values[$i]['token'] = OC_Share::getTokenFromSource($source) . "&path=" . substr($path, strlen($source));
            }
            $parentUsers[basename($source) . "-" . $i] = $values[$i];
        }
        $users = array_merge($users, $parentUsers);
    }
    $source = dirname($source);
}
if (!empty($users)) {
    OC_JSON::encodedPrint($users);
}
예제 #2
0
<?php

require_once OC::$APPSROOT . '/apps/files_sharing/lib_share.php';
OCP\JSON::checkAppEnabled('files_sharing');
OCP\JSON::checkLoggedIn();
$item = array();
$userDirectory = '/' . OCP\USER::getUser() . '/files';
$source = $userDirectory . $_GET['item'];
$path = $source;
// Search for item and shared parent folders
while ($path != $userDirectory) {
    if ($rows = OC_Share::getMySharedItem($path)) {
        for ($i = 0; $i < count($rows); $i++) {
            $uid_shared_with = $rows[$i]['uid_shared_with'];
            if ($uid_shared_with == OC_Share::PUBLICLINK && !isset($item['privateLink'])) {
                $token = OC_Share::getTokenFromSource($path);
                if ($path == $source) {
                    $item['privateLink'] = $token;
                } else {
                    // If in parent folder, include a path parameter to get direct access to file
                    $item['privateLink'] = $token . '&path=' . str_replace('%2F', '/', str_replace('+', '%20', urlencode(substr($source, strlen($path)))));
                }
            } else {
                // Check if uid_shared_with is a group
                if (($pos = strpos($uid_shared_with, '@')) !== false) {
                    $gid = substr($uid_shared_with, $pos + 1);
                    // Include users in the group so the users can be removed from the list of people to share with
                    if ($path == $source) {
                        $group = array(array('gid' => $gid, 'permissions' => $rows[$i]['permissions'], 'users' => OC_Group::usersInGroup($gid), 'parentFolder' => false));
                    } else {
                        $group = array(array('gid' => $gid, 'permissions' => $rows[$i]['permissions'], 'users' => OC_Group::usersInGroup($gid), 'parentFolder' => basename($path)));