public function formatItems($items, $format, $parameters = null) { if ($format == self::FORMAT_SHARED_STORAGE) { // Only 1 item should come through for this format call return array('path' => $items[key($items)]['path'], 'permissions' => $items[key($items)]['permissions']); } else { if ($format == self::FORMAT_FILE_APP && isset($parameters['folder'])) { // Only 1 item should come through for this format call $folder = $items[key($items)]; if (isset($parameters['mimetype_filter'])) { $mimetype_filter = $parameters['mimetype_filter']; } else { $mimetype_filter = ''; } $path = $folder['path'] . substr($parameters['folder'], 7 + strlen($folder['file_target'])); $files = OC_FileCache::getFolderContent($path, '', $mimetype_filter); foreach ($files as &$file) { $file['directory'] = $parameters['folder']; $file['type'] = $file['mimetype'] == 'httpd/unix-directory' ? 'dir' : 'file'; $file['permissions'] = $folder['permissions']; if ($file['type'] == 'file') { // Remove Create permission if type is file $file['permissions'] &= ~OCP\Share::PERMISSION_CREATE; } } return $files; } } return array(); }
function search($query) { $files = OC_FileCache::search($query, true); $results = array(); foreach ($files as $fileData) { $file = $fileData['path']; $mime = $fileData['mimetype']; if ($mime == 'httpd/unix-directory') { $results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('files', 'index.php') . '?dir=' . $file, 'Files'); } else { $mimeBase = $fileData['mimepart']; switch ($mimeBase) { case 'audio': break; case 'text': $results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('files', 'download.php') . '?file=' . $file, 'Text'); break; case 'image': $results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('files', 'download.php') . '?file=' . $file, 'Images'); break; default: if ($mime == 'application/xml') { $results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('files', 'download.php') . '?file=' . $file, 'Text'); } else { $results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('files', 'download.php') . '?file=' . $file, 'Files'); } } } } return $results; }
public function isValidSource($itemSource, $uidOwner) { $path = OC_FileCache::getPath($itemSource, $uidOwner); if ($path) { $this->path = $path; return true; } return false; }
/** * get the free space in the users home folder * @return int */ private function getFreeSpace() { $rootInfo = OC_FileCache::get(''); $usedSpace = $rootInfo['size']; $totalSpace = $this->getQuota(); if ($totalSpace == 0) { return 0; } return $totalSpace - $usedSpace; }
public function preFile_put_contents($path, &$data) { if (self::shouldEncrypt($path)) { if (!is_resource($data)) { //stream put contents should have been converter to fopen $data = OC_Crypt::blockEncrypt($data); OC_FileCache::put($path, array('encrypted' => true)); } } }
public static function setupFS($user = '') { // configure the initial filesystem based on the configuration if (self::$fsSetup) { //setting up the filesystem twice can only lead to trouble return false; } // If we are not forced to load a specific user we load the one that is logged in if ($user == "" && OC_User::isLoggedIn()) { $user = OC_User::getUser(); } // the filesystem will finish when $user is not empty, // mark fs setup here to avoid doing the setup from loading // OC_Filesystem if ($user != '') { self::$fsSetup = true; } $CONFIG_DATADIRECTORY = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data"); //first set up the local "root" storage if (!self::$rootMounted) { OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => $CONFIG_DATADIRECTORY), '/'); self::$rootMounted = true; } if ($user != "") { //if we aren't logged in, there is no use to set up the filesystem $user_dir = '/' . $user . '/files'; $user_root = OC_User::getHome($user); $userdirectory = $user_root . '/files'; if (!is_dir($userdirectory)) { mkdir($userdirectory, 0755, true); } //jail the user into his "home" directory OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => $user_root), $user); OC_Filesystem::init($user_dir); $quotaProxy = new OC_FileProxy_Quota(); OC_FileProxy::register($quotaProxy); // Load personal mount config if (is_file($user_root . '/mount.php')) { $mountConfig = (include $user_root . '/mount.php'); if (isset($mountConfig['user'][$user])) { foreach ($mountConfig['user'][$user] as $mountPoint => $options) { OC_Filesystem::mount($options['class'], $options['options'], $mountPoint); } } $mtime = filemtime($user_root . '/mount.php'); $previousMTime = OC_Preferences::getValue($user, 'files', 'mountconfigmtime', 0); if ($mtime > $previousMTime) { //mount config has changed, filecache needs to be updated OC_FileCache::triggerUpdate($user); OC_Preferences::setValue($user, 'files', 'mountconfigmtime', $mtime); } } OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $user_dir)); } }
public static function getPresentations() { $presentations = array(); $list = \OC_FileCache::searchByMime('application', 'zip'); foreach ($list as $l) { $info = pathinfo($l); $size = \OC_Filesystem::filesize($l); $mtime = \OC_Filesystem::filemtime($l); $entry = array('url' => $l, 'name' => $info['filename'], 'size' => $size, 'mtime' => $mtime); $presentations[] = $entry; } return $presentations; }
function search($query) { $files = OC_FileCache::search($query, true); $results = array(); foreach ($files as $fileData) { $file = $fileData['path']; $mime = $fileData['mimetype']; if ($mime == 'application/pdf') { $results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('reader', 'results.php') . '?file=' . $file, 'eBook'); } } return $results; }
/** * get the content of a directory * @param dir $directory path under datadirectory */ public static function getDirectoryContent($directory, $mimetype_filter = '') { $directory = OC_Filesystem::normalizePath($directory); if ($directory == '/') { $directory = ''; } $files = array(); if (($directory == '/Shared' || substr($directory, 0, 8) == '/Shared/') && OC_App::isEnabled('files_sharing')) { if ($directory == '/Shared') { $files = OCP\Share::getItemsSharedWith('file', OC_Share_Backend_File::FORMAT_FILE_APP, array('folder' => $directory, 'mimetype_filter' => $mimetype_filter)); } else { $pos = strpos($directory, '/', 8); // Get shared folder name if ($pos !== false) { $itemTarget = substr($directory, 7, $pos - 7); } else { $itemTarget = substr($directory, 7); } $files = OCP\Share::getItemSharedWith('folder', $itemTarget, OC_Share_Backend_File::FORMAT_FILE_APP, array('folder' => $directory, 'mimetype_filter' => $mimetype_filter)); } } else { $files = OC_FileCache::getFolderContent($directory, false, $mimetype_filter); foreach ($files as &$file) { $file['directory'] = $directory; $file['type'] = $file['mimetype'] == 'httpd/unix-directory' ? 'dir' : 'file'; $permissions = OCP\Share::PERMISSION_READ; // NOTE: Remove check when new encryption is merged if (!$file['encrypted']) { $permissions |= OCP\Share::PERMISSION_SHARE; } if ($file['type'] == 'dir' && $file['writable']) { $permissions |= OCP\Share::PERMISSION_CREATE; } if ($file['writable']) { $permissions |= OCP\Share::PERMISSION_UPDATE | OCP\Share::PERMISSION_DELETE; } $file['permissions'] = $permissions; } if ($directory == '' && OC_App::isEnabled('files_sharing')) { // Add 'Shared' folder $files = array_merge($files, OCP\Share::getItemsSharedWith('file', OC_Share_Backend_File::FORMAT_FILE_APP_ROOT)); } } usort($files, "fileCmp"); //TODO: remove this once ajax is merged return $files; }
/** * get the free space in the users home folder * @return int */ private function getFreeSpace() { $rootInfo = OC_FileCache::get(''); // TODO Remove after merge of share_api if (OC_FileCache::inCache('/Shared')) { $sharedInfo = OC_FileCache::get('/Shared'); } else { $sharedInfo = null; } $usedSpace = isset($rootInfo['size']) ? $rootInfo['size'] : 0; $usedSpace = isset($sharedInfo['size']) ? $usedSpace - $sharedInfo['size'] : $usedSpace; $totalSpace = $this->getQuota(); if ($totalSpace == 0) { return 0; } return $totalSpace - $usedSpace; }
/** * get all files and folders in a folder * @param string path * @param string root (optional) * @return array * * returns an array of assiciative arrays with the following keys: * - path * - name * - size * - mtime * - ctime * - mimetype * - encrypted * - versioned */ public static function getFolderContent($path, $root = false, $mimetype_filter = '') { if ($root === false) { $root = OC_Filesystem::getRoot(); } $parent = OC_FileCache::getId($path, $root); if ($parent == -1) { return array(); } $query = OC_DB::prepare('SELECT `id`,`path`,`name`,`ctime`,`mtime`,`mimetype`,`size`,`encrypted`,`versioned`,`writable` FROM `*PREFIX*fscache` WHERE `parent`=? AND (`mimetype` LIKE ? OR `mimetype` = ?)'); $result = $query->execute(array($parent, $mimetype_filter . '%', 'httpd/unix-directory'))->fetchAll(); if (is_array($result)) { return $result; } else { OC_Log::write('files', 'getFolderContent(): file not found in cache (' . $path . ')', OC_Log::DEBUG); return false; } }
function explore($current_dir, $sub_dirs, $num_of_results) { $return = array(); // Search for pdfs in sub directories. foreach ($sub_dirs as $dir) { $pdfs = \OC_FileCache::searchByMime('application', 'pdf', '/' . \OCP\USER::getUser() . '/files' . $current_dir . $dir . '/'); sort($pdfs); $max_count = min(count($pdfs), $num_of_results); $thumbs = array(); for ($i = $max_count - 1; $i >= 0; $i--) { if (!in_array($pdfs[$i], $thumbs)) { $thumbs[] = $pdfs[$i]; } } $return[] = array($dir, $thumbs); } return $return; }
/** * get the free space in the path's owner home folder * @param path * @return int */ private function getFreeSpace($path) { $storage = OC_Filesystem::getStorage($path); $owner = $storage->getOwner($path); $totalSpace = $this->getQuota($owner); if ($totalSpace == -1) { return -1; } $rootInfo = OC_FileCache::get('', "/" . $owner . "/files"); // TODO Remove after merge of share_api if (OC_FileCache::inCache('/Shared', "/" . $owner . "/files")) { $sharedInfo = OC_FileCache::get('/Shared', "/" . $owner . "/files"); } else { $sharedInfo = null; } $usedSpace = isset($rootInfo['size']) ? $rootInfo['size'] : 0; $usedSpace = isset($sharedInfo['size']) ? $usedSpace - $sharedInfo['size'] : $usedSpace; return $totalSpace - $usedSpace; }
/** * scan a folder for music * @param OC_EventSource eventSource (optional) * @return int the number of songs found */ public static function scanCollection($eventSource = null) { $music = OC_FileCache::searchByMime('audio'); $ogg = OC_FileCache::searchByMime('application', 'ogg'); $music = array_merge($music, $ogg); $eventSource->send('count', count($music)); $songs = 0; foreach ($music as $file) { self::scanFile($file); $songs++; if ($eventSource) { $eventSource->send('scanned', array('file' => $file, 'count' => $songs)); } } if ($eventSource) { $eventSource->send('done', $songs); } return $songs; }
function search($query) { $files = OC_FileCache::search($query, true); $results = array(); $l = OC_L10N::get('lib'); foreach ($files as $fileData) { $path = $fileData['path']; $mime = $fileData['mimetype']; $name = basename($path); $text = ''; $skip = false; if ($mime == 'httpd/unix-directory') { $link = OC_Helper::linkTo('files', 'index.php', array('dir' => $path)); $type = (string) $l->t('Files'); } else { $link = OC_Helper::linkToRoute('download', array('file' => $path)); $mimeBase = $fileData['mimepart']; switch ($mimeBase) { case 'audio': $skip = true; break; case 'text': $type = (string) $l->t('Text'); break; case 'image': $type = (string) $l->t('Images'); break; default: if ($mime == 'application/xml') { $type = (string) $l->t('Text'); } else { $type = (string) $l->t('Files'); } } } if (!$skip) { $results[] = new OC_Search_Result($name, $text, $link, $type); } } return $results; }
public static function loadUserMountPoints($user) { $user_dir = '/' . $user . '/files'; $user_root = OC_User::getHome($user); $userdirectory = $user_root . '/files'; if (is_file($user_root . '/mount.php')) { $mountConfig = (include $user_root . '/mount.php'); if (isset($mountConfig['user'][$user])) { foreach ($mountConfig['user'][$user] as $mountPoint => $options) { OC_Filesystem::mount($options['class'], $options['options'], $mountPoint); } } $mtime = filemtime($user_root . '/mount.php'); $previousMTime = OC_Preferences::getValue($user, 'files', 'mountconfigmtime', 0); if ($mtime > $previousMTime) { //mount config has changed, filecache needs to be updated OC_FileCache::triggerUpdate($user); OC_Preferences::setValue($user, 'files', 'mountconfigmtime', $mtime); } } }
function explore($current_dir, $sub_dirs) { $return = array(); // Search for pdfs in sub directories. foreach ($sub_dirs as $dir) { $pdfs = \OC_FileCache::searchByMime('application', 'pdf', '/' . \OCP\USER::getUser() . '/files' . $current_dir . $dir . '/'); sort($pdfs); $thumbs = array(); $count = 1; foreach ($pdfs as $pdf) { // We need only 3 pdf pages to create thumbnails for folders. if ($count <= 3) { // Store the urls in an array. $thumbs[] = $pdf; $count++; } } // Return the directory and contained pdfs(any 3). $return[] = array($dir, $thumbs); } return $return; }
<?php require_once OC::$APPSROOT . '/apps/files_sharing/lib_share.php'; OCP\JSON::checkAppEnabled('files_sharing'); OCP\JSON::checkLoggedIn(); $userDirectory = '/' . OCP\USER::getUser() . '/files'; $sources = explode(';', $_POST['sources']); $uid_shared_with = $_POST['uid_shared_with']; $permissions = $_POST['permissions']; foreach ($sources as $source) { $file = OC_FileCache::get($source); $path = ltrim($source, '/'); $source = $userDirectory . $source; // Check if the file exists or if the file is being reshared if ($source && $file['encrypted'] == false && (OC_FILESYSTEM::file_exists($path) && OC_FILESYSTEM::is_readable($path) || OC_Share::getSource($source))) { try { $shared = new OC_Share($source, $uid_shared_with, $permissions); // If this is a private link, return the token if ($uid_shared_with == OC_Share::PUBLICLINK) { OCP\JSON::success(array('data' => $shared->getToken())); } else { OCP\JSON::success(); } } catch (Exception $exception) { OCP\Util::writeLog('files_sharing', 'Unexpected Error : ' . $exception->getMessage(), OCP\Util::ERROR); OCP\JSON::error(array('data' => array('message' => $exception->getMessage()))); } } else { if ($file['encrypted'] == true) { OCP\JSON::error(array('data' => array('message' => 'Encrypted files cannot be shared'))); } else {
public static function search($query) { return OC_FileCache::search($query); }
/** * Copyright (c) 2011, Robin Appelman <*****@*****.**> * This file is licensed under the Affero General Public License version 3 or later. * See the COPYING-README file. */ require_once '../lib/base.php'; OC_Util::checkLoggedIn(); // Highlight navigation entry OC_Util::addScript('settings', 'personal'); OC_Util::addStyle('settings', 'settings'); OC_Util::addScript('3rdparty', 'chosen/chosen.jquery.min'); OC_Util::addStyle('3rdparty', 'chosen'); OC_App::setActiveNavigationEntry('personal'); // calculate the disc space $rootInfo = OC_FileCache::get(''); $used = $rootInfo['size']; $free = OC_Filesystem::free_space(); $total = $free + $used; if ($total == 0) { $total = 1; } // prevent division by zero $relative = round($used / $total * 10000) / 100; $email = OC_Preferences::getValue(OC_User::getUser(), 'settings', 'email', ''); $lang = OC_Preferences::getValue(OC_User::getUser(), 'core', 'lang', OC_L10N::findLanguage()); $languageCodes = OC_L10N::findAvailableLanguages(); sort($languageCodes); //put the current language in the front unset($languageCodes[array_search($lang, $languageCodes)]); array_unshift($languageCodes, $lang);
/** * return the content of a file or return a zip file containning multiply files * * @param dir $dir * @param file $file ; seperated list of files to download * @param boolean $only_header ; boolean to only send header of the request */ public static function get($dir, $files, $only_header = false) { if (strpos($files, ';')) { $files = explode(';', $files); } if (is_array($files)) { self::validateZipDownload($dir, $files); $executionTime = intval(ini_get('max_execution_time')); set_time_limit(0); $zip = new ZipArchive(); $filename = OC_Helper::tmpFile('.zip'); if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== TRUE) { exit("cannot open <{$filename}>\n"); } foreach ($files as $file) { $file = $dir . '/' . $file; if (OC_Filesystem::is_file($file)) { $tmpFile = OC_Filesystem::toTmpFile($file); self::$tmpFiles[] = $tmpFile; $zip->addFile($tmpFile, basename($file)); } elseif (OC_Filesystem::is_dir($file)) { self::zipAddDir($file, $zip); } } $zip->close(); set_time_limit($executionTime); } elseif (OC_Filesystem::is_dir($dir . '/' . $files)) { self::validateZipDownload($dir, $files); $executionTime = intval(ini_get('max_execution_time')); set_time_limit(0); $zip = new ZipArchive(); $filename = OC_Helper::tmpFile('.zip'); if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== TRUE) { exit("cannot open <{$filename}>\n"); } $file = $dir . '/' . $files; self::zipAddDir($file, $zip); $zip->close(); set_time_limit($executionTime); } else { $zip = false; $filename = $dir . '/' . $files; } @ob_end_clean(); if ($zip or OC_Filesystem::is_readable($filename)) { header('Content-Disposition: attachment; filename="' . basename($filename) . '"'); header('Content-Transfer-Encoding: binary'); OC_Response::disableCaching(); if ($zip) { ini_set('zlib.output_compression', 'off'); header('Content-Type: application/zip'); header('Content-Length: ' . filesize($filename)); } else { $fileData = OC_FileCache::get($filename); header('Content-Type: ' . $fileData['mimetype']); } } elseif ($zip or !OC_Filesystem::file_exists($filename)) { header("HTTP/1.0 404 Not Found"); $tmpl = new OC_Template('', '404', 'guest'); $tmpl->assign('file', $filename); $tmpl->printPage(); } else { header("HTTP/1.0 403 Forbidden"); die('403 Forbidden'); } if ($only_header) { if (!$zip) { header("Content-Length: " . OC_Filesystem::filesize($filename)); } return; } if ($zip) { $handle = fopen($filename, 'r'); if ($handle) { $chunkSize = 8 * 1024; // 1 MB chunks while (!feof($handle)) { echo fread($handle, $chunkSize); flush(); } } unlink($filename); } else { OC_Filesystem::readfile($filename); } foreach (self::$tmpFiles as $tmpFile) { if (file_exists($tmpFile) and is_file($tmpFile)) { unlink($tmpFile); } } }
exit; } } $files = $_FILES['files']; $dir = $_POST['dir']; $error = ''; $totalSize = 0; foreach ($files['size'] as $size) { $totalSize += $size; } if ($totalSize > OC_Filesystem::free_space('/')) { OCP\JSON::error(array("data" => array("message" => "Not enough space available"))); exit; } $result = array(); if (strpos($dir, '..') === false) { $fileCount = count($files['name']); for ($i = 0; $i < $fileCount; $i++) { $target = OCP\Files::buildNotExistingFileName(stripslashes($dir), $files['name'][$i]); if (is_uploaded_file($files['tmp_name'][$i]) and OC_Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) { $meta = OC_FileCache::get($target); $id = OC_FileCache::getId($target); $result[] = array("status" => "success", 'mime' => $meta['mimetype'], 'size' => $meta['size'], 'id' => $id, 'name' => basename($target)); } } OCP\JSON::encodedPrint($result); exit; } else { $error = 'invalid dir'; } OCP\JSON::error(array('data' => array('error' => $error, "file" => $fileName)));
<?php set_time_limit(0); //scanning can take ages $force = isset($_GET['force']) and $_GET['force'] == 'true'; $dir = isset($_GET['dir']) ? $_GET['dir'] : ''; $checkOnly = isset($_GET['checkonly']) and $_GET['checkonly'] == 'true'; if (!$checkOnly) { $eventSource = new OC_EventSource(); } //create the file cache if necesary if ($force or !OC_FileCache::inCache('')) { if (!$checkOnly) { OCP\DB::beginTransaction(); OC_FileCache::scan($dir, $eventSource); OC_FileCache::clean(); OCP\DB::commit(); $eventSource->send('success', true); } else { OCP\JSON::success(array('data' => array('done' => true))); exit; } } else { if ($checkOnly) { OCP\JSON::success(array('data' => array('done' => false))); exit; } if (isset($eventSource)) { $eventSource->send('success', false); } else { exit;
public function stream_close() { $this->flush(); if ($this->meta['mode'] != 'r' and $this->meta['mode'] != 'rb') { OC_FileCache::put($this->path, array('encrypted' => true)); } return fclose($this->source); }
/** * update the filesystem after a rename has been detected * @param string oldPath * @param string newPath * @param string root (optional) */ public static function rename($oldPath, $newPath, $root = false) { if (!OC_FileCache::inCache($oldPath, $root)) { return; } if ($root === false) { $view = OC_Filesystem::getView(); } else { $view = new OC_FilesystemView($root); } $cached = OC_FileCache_Cached::get($oldPath, $root); $oldSize = $cached['size']; OC_FileCache::increaseSize(dirname($oldPath), -$oldSize, $root); OC_FileCache::increaseSize(dirname($newPath), $oldSize, $root); OC_FileCache::move($oldPath, $newPath); }
if ($(elem).hasClass('title')) { $(elem).removeClass('visible'); } else { $(elem).css('margin-top', Math.floor(5-(Math.random()*10)) + 'px') .css('margin-left', Math.floor(5-(Math.random()*10))+ 'px') .css('z-index', '3'); } }); } </script> <?php include 'apps/gallery/lib/tiles.php'; $root = empty($_GET['root']) ? '/' : $_GET['root']; $images = \OC_FileCache::searchByMime('image', null, '/bartek/files' . $root); sort($images); $arr = array(); $tl = new \OC\Pictures\TilesLine(); $ts = new \OC\Pictures\TileStack(array(), ''); $previous_element = $images[0]; for ($i = 0; $i < count($images); $i++) { error_log($images[$i]); $prev_dir_arr = explode('/', $previous_element); $dir_arr = explode('/', $images[$i]); if (count($dir_arr) == 1) { $tl->addTile(new \OC\Pictures\TileSingle($images[$i])); continue; } if (strcmp($prev_dir_arr[0], $dir_arr[0]) != 0) { $tl->addTile(new \OC\Pictures\TileStack($arr, $prev_dir_arr[0]));
/** * get the quota of a user * @param string $format * @param string $user * @return string xml/json */ private static function quotaGet($format, $user) { $login = OC_OCS::checkpassword(); if (OC_Group::inGroup($login, 'admin') or $login == $user) { if (OC_User::userExists($user)) { // calculate the disc space $user_dir = '/' . $user . '/files'; OC_Filesystem::init($user_dir); $rootInfo = OC_FileCache::get(''); $sharedInfo = OC_FileCache::get('/Shared'); $used = $rootInfo['size'] - $sharedInfo['size']; $free = OC_Filesystem::free_space(); $total = $free + $used; if ($total == 0) { $total = 1; } // prevent division by zero $relative = round($used / $total * 10000) / 100; $xml = array(); $xml['quota'] = $total; $xml['free'] = $free; $xml['used'] = $used; $xml['relative'] = $relative; $txt = OC_OCS::generatexml($format, 'ok', 100, '', $xml, 'cloud', '', 1, 0, 0); echo $txt; } else { echo self::generateXml('', 'fail', 300, 'User does not exist'); } } else { echo self::generateXml('', 'fail', 300, 'You don´t have permission to access this ressource.'); } }
/** * @brief Generate a unique target for the item * @param string Item type * @param string Item source * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK * @param string User or group the item is being shared with * @param string The suggested target originating from a reshare (optional) * @param int The id of the parent group share (optional) * @return string Item target */ private static function generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $suggestedTarget = null, $groupParent = null) { $backend = self::getBackend($itemType); if ($shareType == self::SHARE_TYPE_LINK) { if (isset($suggestedTarget)) { return $suggestedTarget; } return $backend->generateTarget($itemSource, false); } else { if ($itemType == 'file' || $itemType == 'folder') { $column = 'file_target'; $columnSource = 'file_source'; } else { $column = 'item_target'; $columnSource = 'item_source'; } if ($shareType == self::SHARE_TYPE_USER) { // Share with is a user, so set share type to user and groups $shareType = self::$shareTypeUserAndGroups; $userAndGroups = array_merge(array($shareWith), \OC_Group::getUserGroups($shareWith)); } else { $userAndGroups = false; } $exclude = null; // Backend has 3 opportunities to generate a unique target for ($i = 0; $i < 2; $i++) { // Check if suggested target exists first if ($i == 0 && isset($suggestedTarget)) { $target = $suggestedTarget; } else { if ($shareType == self::SHARE_TYPE_GROUP) { $target = $backend->generateTarget($itemSource, false, $exclude); } else { $target = $backend->generateTarget($itemSource, $shareWith, $exclude); } if (is_array($exclude) && in_array($target, $exclude)) { break; } } // Check if target already exists $checkTarget = self::getItems($itemType, $target, $shareType, $shareWith); if (!empty($checkTarget)) { foreach ($checkTarget as $item) { // Skip item if it is the group parent row if (isset($groupParent) && $item['id'] == $groupParent) { if (count($checkTarget) == 1) { return $target; } else { continue; } } if ($item['uid_owner'] == $uidOwner) { if ($itemType == 'file' || $itemType == 'folder') { if ($item['file_source'] == \OC_FileCache::getId($itemSource)) { return $target; } } else { if ($item['item_source'] == $itemSource) { return $target; } } } } if (!isset($exclude)) { $exclude = array(); } // Find similar targets to improve backend's chances to generate a unqiue target if ($userAndGroups) { if ($column == 'file_target') { $checkTargets = \OC_DB::prepare('SELECT `' . $column . '` FROM `*PREFIX*share` WHERE `item_type` IN (\'file\', \'folder\') AND `share_type` IN (?,?,?) AND `share_with` IN (\'' . implode('\',\'', $userAndGroups) . '\')'); $result = $checkTargets->execute(array(self::SHARE_TYPE_USER, self::SHARE_TYPE_GROUP, self::$shareTypeGroupUserUnique)); } else { $checkTargets = \OC_DB::prepare('SELECT `' . $column . '` FROM `*PREFIX*share` WHERE `item_type` = ? AND `share_type` IN (?,?,?) AND `share_with` IN (\'' . implode('\',\'', $userAndGroups) . '\')'); $result = $checkTargets->execute(array($itemType, self::SHARE_TYPE_USER, self::SHARE_TYPE_GROUP, self::$shareTypeGroupUserUnique)); } } else { if ($column == 'file_target') { $checkTargets = \OC_DB::prepare('SELECT `' . $column . '` FROM `*PREFIX*share` WHERE `item_type` IN (\'file\', \'folder\') AND `share_type` = ? AND `share_with` = ?'); $result = $checkTargets->execute(array(self::SHARE_TYPE_GROUP, $shareWith)); } else { $checkTargets = \OC_DB::prepare('SELECT `' . $column . '` FROM `*PREFIX*share` WHERE `item_type` = ? AND `share_type` = ? AND `share_with` = ?'); $result = $checkTargets->execute(array($itemType, self::SHARE_TYPE_GROUP, $shareWith)); } } while ($row = $result->fetchRow()) { $exclude[] = $row[$column]; } } else { return $target; } } } $message = 'Sharing backend registered for ' . $itemType . ' did not generate a unique target for ' . $itemSource; \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR); throw new \Exception($message); }
public static function findPaths() { $images = OC_FileCache::searchByMime('image', '', self::getScanningRoot()); $paths = array(); foreach ($images as $image) { $path = dirname($image); $path = self::getGalleryRoot() . ($path == '.' ? '' : $path); if ($path !== '/') { $path = rtrim($path, '/'); } if (array_search($path, $paths) === false) { $paths[] = $path; } // add sub path also if they don't contain images while (($path = dirname($path)) != '/') { if (array_search($path, $paths) === false) { $paths[] = $path; } } } sort($paths); return $paths; }
/** * delete files owned by user from the cache * @param string $parameters$parameters["uid"]) */ public static function deleteFromUser($parameters) { OC_FileCache::clear($parameters["uid"]); }