OC_Files::get("", $path, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false); } } else { OCP\Util::addStyle('files_sharing', 'public'); OCP\Util::addScript('files_sharing', 'public'); OCP\Util::addScript('files', 'fileactions'); $tmpl = new OCP\Template('files_sharing', 'public', 'base'); $tmpl->assign('owner', $uidOwner); // Show file list if (OC_Filesystem::is_dir($path)) { OCP\Util::addStyle('files', 'files'); OCP\Util::addScript('files', 'files'); OCP\Util::addScript('files', 'filelist'); $files = array(); $rootLength = strlen($baseDir) + 1; foreach (OC_Files::getDirectoryContent($path) as $i) { $i['date'] = OCP\Util::formatDate($i['mtime']); if ($i['type'] == 'file') { $fileinfo = pathinfo($i['name']); $i['basename'] = $fileinfo['filename']; $i['extension'] = isset($fileinfo['extension']) ? '.' . $fileinfo['extension'] : ''; } $i['directory'] = '/' . substr('/' . $uidOwner . '/files' . $i['directory'], $rootLength); if ($i['directory'] == '/') { $i['directory'] = ''; } $i['permissions'] = OCP\Share::PERMISSION_READ; $files[] = $i; } // Make breadcrumb $breadcrumb = array();
public static function zipAddDir($dir, $zip, $internalDir = '') { $dirname = basename($dir); $zip->addEmptyDir($internalDir . $dirname); $internalDir .= $dirname .= '/'; $files = OC_Files::getDirectoryContent($dir); foreach ($files as $file) { $filename = $file['name']; $file = $dir . '/' . $filename; if (OC_Filesystem::is_file($file)) { $tmpFile = OC_Filesystem::toTmpFile($file); OC_Files::$tmpFiles[] = $tmpFile; $zip->addFile($tmpFile, $internalDir . $filename); } elseif (OC_Filesystem::is_dir($file)) { self::zipAddDir($file, $zip, $internalDir); } } }
/** * @brief Share an item with a user, group, or via private link * @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 int CRUDS permissions * @return bool Returns true on success or false on failure */ public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions) { $uidOwner = \OC_User::getUser(); $sharingPolicy = \OC_Appconfig::getValue('core', 'shareapi_share_policy', 'global'); // Verify share type and sharing conditions are met if ($shareType === self::SHARE_TYPE_USER) { if ($shareWith == $uidOwner) { $message = 'Sharing ' . $itemSource . ' failed, because the user ' . $shareWith . ' is the item owner'; \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } if (!\OC_User::userExists($shareWith)) { $message = 'Sharing ' . $itemSource . ' failed, because the user ' . $shareWith . ' does not exist'; \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } if ($sharingPolicy == 'groups_only') { $inGroup = array_intersect(\OC_Group::getUserGroups($uidOwner), \OC_Group::getUserGroups($shareWith)); if (empty($inGroup)) { $message = 'Sharing ' . $itemSource . ' failed, because the user ' . $shareWith . ' is not a member of any groups that ' . $uidOwner . ' is a member of'; \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } } // Check if the item source is already shared with the user, either from the same owner or a different user if ($checkExists = self::getItems($itemType, $itemSource, self::$shareTypeUserAndGroups, $shareWith, null, self::FORMAT_NONE, null, 1, true, true)) { // Only allow the same share to occur again if it is the same owner and is not a user share, this use case is for increasing permissions for a specific user if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) { $message = 'Sharing ' . $itemSource . ' failed, because this item is already shared with ' . $shareWith; \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } } } else { if ($shareType === self::SHARE_TYPE_GROUP) { if (!\OC_Group::groupExists($shareWith)) { $message = 'Sharing ' . $itemSource . ' failed, because the group ' . $shareWith . ' does not exist'; \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } if ($sharingPolicy == 'groups_only' && !\OC_Group::inGroup($uidOwner, $shareWith)) { $message = 'Sharing ' . $itemSource . ' failed, because ' . $uidOwner . ' is not a member of the group ' . $shareWith; \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } // Check if the item source is already shared with the group, either from the same owner or a different user // The check for each user in the group is done inside the put() function if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_GROUP, $shareWith, null, self::FORMAT_NONE, null, 1, true, true)) { // Only allow the same share to occur again if it is the same owner and is not a group share, this use case is for increasing permissions for a specific user if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) { $message = 'Sharing ' . $itemSource . ' failed, because this item is already shared with ' . $shareWith; \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } } // Convert share with into an array with the keys group and users $group = $shareWith; $shareWith = array(); $shareWith['group'] = $group; $shareWith['users'] = array_diff(\OC_Group::usersInGroup($group), array($uidOwner)); } else { if ($shareType === self::SHARE_TYPE_LINK) { if (\OC_Appconfig::getValue('core', 'shareapi_allow_links', 'yes') == 'yes') { if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_LINK, null, $uidOwner, self::FORMAT_NONE, null, 1)) { // If password is set delete the old link if (isset($shareWith)) { self::delete($checkExists['id']); } else { $message = 'Sharing ' . $itemSource . ' failed, because this item is already shared with a link'; \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } } // Generate hash of password - same method as user passwords if (isset($shareWith)) { $forcePortable = CRYPT_BLOWFISH != 1; $hasher = new \PasswordHash(8, $forcePortable); $shareWith = $hasher->HashPassword($shareWith . \OC_Config::getValue('passwordsalt', '')); } return self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions); } $message = 'Sharing ' . $itemSource . ' failed, because sharing with links is not allowed'; \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR); throw new \Exception($message); return false; // } else if ($shareType === self::SHARE_TYPE_CONTACT) { // if (!\OC_App::isEnabled('contacts')) { // $message = 'Sharing '.$itemSource.' failed, because the contacts app is not enabled'; // \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); // return false; // } // $vcard = \OC_Contacts_App::getContactVCard($shareWith); // if (!isset($vcard)) { // $message = 'Sharing '.$itemSource.' failed, because the contact does not exist'; // \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); // throw new \Exception($message); // } // $details = \OC_Contacts_VCard::structureContact($vcard); // // TODO Add ownCloud user to contacts vcard // if (!isset($details['EMAIL'])) { // $message = 'Sharing '.$itemSource.' failed, because no email address is associated with the contact'; // \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); // throw new \Exception($message); // } // return self::shareItem($itemType, $itemSource, self::SHARE_TYPE_EMAIL, $details['EMAIL'], $permissions); } else { // Future share types need to include their own conditions $message = 'Share type ' . $shareType . ' is not valid for ' . $itemSource; \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } } } // If the item is a folder, scan through the folder looking for equivalent item types if ($itemType == 'folder') { $parentFolder = self::put('folder', $itemSource, $shareType, $shareWith, $uidOwner, $permissions, true); if ($parentFolder && ($files = \OC_Files::getDirectoryContent($itemSource))) { for ($i = 0; $i < count($files); $i++) { $name = substr($files[$i]['name'], strpos($files[$i]['name'], $itemSource) - strlen($itemSource)); if ($files[$i]['mimetype'] == 'httpd/unix-directory' && ($children = \OC_Files::getDirectoryContent($name, '/'))) { // Continue scanning into child folders array_push($files, $children); } else { // Check file extension for an equivalent item type to convert to $extension = strtolower(substr($itemSource, strrpos($itemSource, '.') + 1)); foreach (self::$backends as $type => $backend) { if (isset($backend->dependsOn) && $backend->dependsOn == 'file' && isset($backend->supportedFileExtensions) && in_array($extension, $backend->supportedFileExtensions)) { $itemType = $type; break; } } // Pass on to put() to check if this item should be converted, the item won't be inserted into the database unless it can be converted self::put($itemType, $name, $shareType, $shareWith, $uidOwner, $permissions, $parentFolder); } } return true; } return false; } else { // Put the item into the database return self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions); } }
* This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE * License as published by the Free Software Foundation; either * version 3 of the License, or any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU AFFERO GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see <http://www.gnu.org/licenses/>. * */ OCP\User::checkLoggedIn(); OCP\App::checkAppEnabled('facefinder'); OCP\App::setActiveNavigationEntry('facefinder'); OCP\Util::addStyle('facefinder', 'styles'); OCP\Util::addScript('facefinder', 'new_1'); if (!OCP\App::isEnabled('files_imageviewer')) { OCP\Template::printUserPage('facefinder', 'no-image-app'); exit; } $root = !empty($_GET['root']) ? $_GET['root'] : '/'; $files = \OC_Files::getDirectoryContent($root, 'image'); $tl = new \OC\Pictures\TilesLine(); $ts = new \OC\Pictures\TileStack(array(), ''); $tmpl = new OCP\Template('facefinder', 'index', 'user'); $tmpl->assign('root', $root, false); $tmpl->assign('tl', $tl, false); $tmpl->printPage();
/** * Returns an array with all the child nodes * * @return Sabre_DAV_INode[] */ public function getChildren() { $folder_content = OC_Files::getDirectoryContent($this->path); $paths = array(); foreach ($folder_content as $info) { $paths[] = $this->path . '/' . $info['name']; } $properties = array_fill_keys($paths, array()); if (count($paths) > 0) { // // the number of arguments within IN conditions are limited in most databases // we chunk $paths into arrays of 200 items each to meet this criteria // $chunks = array_chunk($paths, 200, false); foreach ($chunks as $pack) { $placeholders = join(',', array_fill(0, count($pack), '?')); $query = OC_DB::prepare('SELECT * FROM `*PREFIX*properties` WHERE `userid` = ?' . ' AND `propertypath` IN (' . $placeholders . ')'); array_unshift($pack, OC_User::getUser()); // prepend userid $result = $query->execute($pack); while ($row = $result->fetchRow()) { $propertypath = $row['propertypath']; $propertyname = $row['propertyname']; $propertyvalue = $row['propertyvalue']; $properties[$propertypath][$propertyname] = $propertyvalue; } } } $nodes = array(); foreach ($folder_content as $info) { $node = $this->getChild($info['name'], $info); $node->setPropertyCache($properties[$this->path . '/' . $info['name']]); $nodes[] = $node; } return $nodes; }
/** * Returns an array with all the child nodes * * @return Sabre_DAV_INode[] */ public function getChildren() { $folder_content = OC_Files::getDirectoryContent($this->path); $paths = array(); foreach ($folder_content as $info) { $paths[] = $this->path . '/' . $info['name']; } $properties = array_fill_keys($paths, array()); if (count($paths) > 0) { $placeholders = join(',', array_fill(0, count($paths), '?')); $query = OC_DB::prepare('SELECT * FROM `*PREFIX*properties` WHERE `userid` = ?' . ' AND `propertypath` IN (' . $placeholders . ')'); array_unshift($paths, OC_User::getUser()); // prepend userid $result = $query->execute($paths); while ($row = $result->fetchRow()) { $propertypath = $row['propertypath']; $propertyname = $row['propertyname']; $propertyvalue = $row['propertyvalue']; $properties[$propertypath][$propertyname] = $propertyvalue; } } $nodes = array(); foreach ($folder_content as $info) { $node = $this->getChild($info['name'], $info); $node->setPropertyCache($properties[$this->path . '/' . $info['name']]); $nodes[] = $node; } return $nodes; }
$ts = new \OC\Pictures\TileStack(array(), ''); $root_images = array(); foreach ($files as $file) { $filename = $root . $file['name']; if ($file['type'] == 'file') { $root_images[] = $filename; } else { // it is a dir, look for images in subdirs. We keep trying till // we find some images or there are no subdirs anymore to check. $name = $file['name']; $second_level_images = array(); $dirs_to_check = array($filename); while (!empty($dirs_to_check)) { // get next subdir to check $subdir = array_pop($dirs_to_check); $subdir_files = \OC_Files::getDirectoryContent($subdir, 'image'); foreach ($subdir_files as $file) { if ($file['type'] == 'file') { $second_level_images[] = $subdir . '/' . $file['name']; } else { $dirs_to_check[] = $subdir . '/' . $file['name']; } } if (count($second_level_images) != 0) { // if we collected images for this directory $tl->addTile(new \OC\Pictures\TileStack($second_level_images, $name)); break; } } } }
/** * recursive copy to copy a whole directory * * @param $source source path, relative to the users files directory * @param $destination destination path relative to the users root directoy * @param $view file view for the users root directory */ private static function copy_recursive($source, $destination, $view) { $size = 0; if ($view->is_dir('files' . $source)) { $view->mkdir($destination); $view->touch($destination, $view->filemtime('files' . $source)); foreach (\OC_Files::getDirectoryContent($source) as $i) { $pathDir = $source . '/' . $i['name']; if ($view->is_dir('files' . $pathDir)) { $size += self::copy_recursive($pathDir, $destination . '/' . $i['name'], $view); } else { $size += $view->filesize('files' . $pathDir); $view->copy('files' . $pathDir, $destination . '/' . $i['name']); $view->touch($destination . '/' . $i['name'], $view->filemtime('files' . $pathDir)); } } } else { $size += $view->filesize('files' . $source); $view->copy('files' . $source, $destination); $view->touch($destination, $view->filemtime('files' . $source)); } return $size; }
/** * Retrieves a list of jobs launched for a specln ific case study * @param type $study */ function get_jobs_for_study($study) { $jobids = array(); $directory = $study . "/results"; $content = OC_Files::getDirectoryContent($directory); foreach ($content as $c) { if (\OC\Files\Filesystem::is_dir($directory . "/" . $c["name"])) { $jobids[] = $c["name"]; } } array_multisort($jobids, SORT_DESC); return $jobids; }