本文整理汇总了PHP中OC\Files\View::opendir方法的典型用法代码示例。如果您正苦于以下问题:PHP View::opendir方法的具体用法?PHP View::opendir怎么用?PHP View::opendir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC\Files\View
的用法示例。
在下文中一共展示了View::opendir方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: listCertificates
/**
* Returns all certificates trusted by the user
*
* @return \OCP\ICertificate[]
*/
public function listCertificates()
{
if (!$this->config->getSystemValue('installed', false)) {
return array();
}
$path = $this->getPathToCertificates() . 'uploads/';
if (!$this->view->is_dir($path)) {
return array();
}
$result = array();
$handle = $this->view->opendir($path);
if (!is_resource($handle)) {
return array();
}
while (false !== ($file = readdir($handle))) {
if ($file != '.' && $file != '..') {
try {
$result[] = new Certificate($this->view->file_get_contents($path . $file), $file);
} catch (\Exception $e) {
}
}
}
closedir($handle);
return $result;
}
示例2: copy
/**
* Copies a file or directory.
*
* This method must work recursively and delete the destination
* if it exists
*
* @param string $source
* @param string $destination
* @throws \Sabre\DAV\Exception\ServiceUnavailable
* @return void
*/
public function copy($source, $destination)
{
if (!$this->fileView) {
throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup');
}
try {
if ($this->fileView->is_file($source)) {
$this->fileView->copy($source, $destination);
} else {
$this->fileView->mkdir($destination);
$dh = $this->fileView->opendir($source);
if (is_resource($dh)) {
while (($subNode = readdir($dh)) !== false) {
if ($subNode == '.' || $subNode == '..') {
continue;
}
$this->copy($source . '/' . $subNode, $destination . '/' . $subNode);
}
}
}
} catch (\OCP\Files\StorageNotAvailableException $e) {
throw new \Sabre\DAV\Exception\ServiceUnavailable($e->getMessage());
}
list($destinationDir, ) = \Sabre\DAV\URLUtil::splitPath($destination);
$this->markDirty($destinationDir);
}
示例3: renameFileKeys
/**
* rename file keys
*
* @param string $user
* @param string $path
* @param bool $trash
*/
private function renameFileKeys($user, $path, $trash = false)
{
if ($this->view->is_dir($user . '/' . $path) === false) {
$this->logger->info('Skip dir /' . $user . '/' . $path . ': does not exist');
return;
}
$dh = $this->view->opendir($user . '/' . $path);
if (is_resource($dh)) {
while (($file = readdir($dh)) !== false) {
if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
if ($this->view->is_dir($user . '/' . $path . '/' . $file)) {
$this->renameFileKeys($user, $path . '/' . $file, $trash);
} else {
$target = $this->getTargetDir($user, $path, $file, $trash);
if ($target) {
$this->createPathForKeys(dirname($target));
$this->view->rename($user . '/' . $path . '/' . $file, $target);
} else {
$this->logger->warning('did not move key "' . $file . '" could not find the corresponding file in /data/' . $user . '/files.' . 'Most likely the key was already moved in a previous migration run and is already on the right place.');
}
}
}
}
closedir($dh);
}
}
示例4: findEncFiles
/**
* Find all files and their encryption status within a directory
* @param string $directory The path of the parent directory to search
* @param bool $found the founded files if called again
* @return array keys: plain, encrypted, broken
* @note $directory needs to be a path relative to OC data dir. e.g.
* /admin/files NOT /backup OR /home/www/oc/data/admin/files
*/
public function findEncFiles($directory, &$found = false)
{
// Disable proxy - we don't want files to be decrypted before
// we handle them
\OC_FileProxy::$enabled = false;
if ($found === false) {
$found = array('plain' => array(), 'encrypted' => array(), 'broken' => array());
}
if ($this->view->is_dir($directory) && ($handle = $this->view->opendir($directory))) {
if (is_resource($handle)) {
while (false !== ($file = readdir($handle))) {
if ($file !== "." && $file !== "..") {
// skip stray part files
if (Helper::isPartialFilePath($file)) {
continue;
}
$filePath = $directory . '/' . $this->view->getRelativePath('/' . $file);
$relPath = Helper::stripUserFilesPath($filePath);
// If the path is a directory, search
// its contents
if ($this->view->is_dir($filePath)) {
$this->findEncFiles($filePath, $found);
// If the path is a file, determine
// its encryption status
} elseif ($this->view->is_file($filePath)) {
// Disable proxies again, some-
// where they got re-enabled :/
\OC_FileProxy::$enabled = false;
$isEncryptedPath = $this->isEncryptedPath($filePath);
// If the file is encrypted
// NOTE: If the userId is
// empty or not set, file will
// detected as plain
// NOTE: This is inefficient;
// scanning every file like this
// will eat server resources :(
if ($isEncryptedPath) {
$fileKey = Keymanager::getFileKey($this->view, $this, $relPath);
$shareKey = Keymanager::getShareKey($this->view, $this->userId, $this, $relPath);
// if file is encrypted but now file key is available, throw exception
if ($fileKey === false || $shareKey === false) {
\OCP\Util::writeLog('encryption library', 'No keys available to decrypt the file: ' . $filePath, \OCP\Util::ERROR);
$found['broken'][] = array('name' => $file, 'path' => $filePath);
} else {
$found['encrypted'][] = array('name' => $file, 'path' => $filePath);
}
// If the file is not encrypted
} else {
$found['plain'][] = array('name' => $file, 'path' => $relPath);
}
}
}
}
}
}
\OC_FileProxy::$enabled = true;
return $found;
}
示例5: dir_opendir
public function dir_opendir($path, $options)
{
$this->setup();
$path = substr($path, strlen('oc://'));
$this->path = $path;
$this->dirSource = self::$rootView->opendir($path);
if (is_resource($this->dirSource)) {
$this->meta = stream_get_meta_data($this->dirSource);
}
return is_resource($this->dirSource);
}
示例6: renameFileKeys
/**
* rename file keys
*
* @param string $user
* @param string $path
* @param bool $trash
*/
private function renameFileKeys($user, $path, $trash = false)
{
$dh = $this->view->opendir($user . '/' . $path);
if (is_resource($dh)) {
while (($file = readdir($dh)) !== false) {
if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
if ($this->view->is_dir($user . '/' . $path . '/' . $file)) {
$this->renameFileKeys($user, $path . '/' . $file, $trash);
} else {
$target = $this->getTargetDir($user, $path, $file, $trash);
$this->createPathForKeys(dirname($target));
$this->view->rename($user . '/' . $path . '/' . $file, $target);
}
}
}
closedir($dh);
}
}
示例7: renameShareKeys
private function renameShareKeys($user, $filePath, $filename, $target, $trash)
{
$oldShareKeyPath = $this->getOldShareKeyPath($user, $filePath, $trash);
$dh = $this->view->opendir($oldShareKeyPath);
if (is_resource($dh)) {
while (($file = readdir($dh)) !== false) {
if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
if ($this->view->is_dir($oldShareKeyPath . '/' . $file)) {
continue;
} else {
if (substr($file, 0, strlen($filename) + 1) === $filename . '.') {
$uid = $this->getUidFromShareKey($file, $filename, $trash);
$this->view->copy($oldShareKeyPath . '/' . $file, $target . '/' . $uid . '.shareKey');
}
}
}
}
closedir($dh);
}
}
示例8: recursiveDelShareKeys
/**
* recursively delete share keys from given users
*
* @param string $dir directory
* @param array $userIds user ids for which the share keys should be deleted
* @param string $owner owner of the file
* @param \OC\Files\View $view view relative to data/
*/
private static function recursiveDelShareKeys($dir, $userIds, $owner, $view)
{
$dirContent = $view->opendir($dir);
$dirSlices = explode('/', ltrim($dir, '/'));
$realFileDir = '/' . $owner . '/files/' . implode('/', array_slice($dirSlices, 3)) . '/';
if (is_resource($dirContent)) {
while (($file = readdir($dirContent)) !== false) {
if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
if ($view->is_dir($dir . '/' . $file)) {
self::recursiveDelShareKeys($dir . '/' . $file, $userIds, $owner, $view);
} else {
$realFile = $realFileDir . self::getFilenameFromShareKey($file);
foreach ($userIds as $userId) {
if (preg_match("/(.*)." . $userId . ".shareKey/", $file)) {
if ($userId === $owner && $view->file_exists($realFile)) {
\OCP\Util::writeLog('files_encryption', 'original file still exists, keep owners share key!', \OCP\Util::ERROR);
continue;
}
\OCP\Util::writeLog('files_encryption', 'recursiveDelShareKey: delete share key: ' . $file, \OCP\Util::DEBUG);
$view->unlink($dir . '/' . $file);
}
}
}
}
}
closedir($dirContent);
}
}
示例9: isEmpty
/**
* check if trash bin is empty for a given user
*
* @param string $user
* @return bool
*/
public static function isEmpty($user)
{
$view = new \OC\Files\View('/' . $user . '/files_trashbin');
if ($view->is_dir('/files') && ($dh = $view->opendir('/files'))) {
while ($file = readdir($dh)) {
if ($file !== '.' and $file !== '..') {
return false;
}
}
}
return true;
}
示例10: getVersions
/**
* get a list of all available versions of a file in descending chronological order
* @param string $uid user id from the owner of the file
* @param string $filename file to find versions of, relative to the user files dir
* @param string $userFullPath
* @return array versions newest version first
*/
public static function getVersions($uid, $filename, $userFullPath = '')
{
$versions = array();
if (empty($filename)) {
return $versions;
}
// fetch for old versions
$view = new View('/' . $uid . '/');
$pathinfo = pathinfo($filename);
$versionedFile = $pathinfo['basename'];
$dir = Filesystem::normalizePath(self::VERSIONS_ROOT . '/' . $pathinfo['dirname']);
$dirContent = false;
if ($view->is_dir($dir)) {
$dirContent = $view->opendir($dir);
}
if ($dirContent === false) {
return $versions;
}
if (is_resource($dirContent)) {
while (($entryName = readdir($dirContent)) !== false) {
if (!Filesystem::isIgnoredDir($entryName)) {
$pathparts = pathinfo($entryName);
$filename = $pathparts['filename'];
if ($filename === $versionedFile) {
$pathparts = pathinfo($entryName);
$timestamp = substr($pathparts['extension'], 1);
$filename = $pathparts['filename'];
$key = $timestamp . '#' . $filename;
$versions[$key]['version'] = $timestamp;
$versions[$key]['humanReadableTimestamp'] = self::getHumanReadableTimestamp($timestamp);
if (empty($userFullPath)) {
$versions[$key]['preview'] = '';
} else {
$versions[$key]['preview'] = \OCP\Util::linkToRoute('core_ajax_versions_preview', array('file' => $userFullPath, 'version' => $timestamp));
}
$versions[$key]['path'] = Filesystem::normalizePath($pathinfo['dirname'] . '/' . $filename);
$versions[$key]['name'] = $versionedFile;
$versions[$key]['size'] = $view->filesize($dir . '/' . $entryName);
}
}
}
closedir($dirContent);
}
// sort with newest version first
krsort($versions);
return $versions;
}
示例11: opendir
public static function opendir($path)
{
return self::$defaultInstance->opendir($path);
}
示例12: isEmpty
/**
* check if trash bin is empty for a given user
*
* @param string $user
* @return bool
*/
public static function isEmpty($user)
{
$view = new View('/' . $user . '/files_trashbin');
if ($view->is_dir('/files') && ($dh = $view->opendir('/files'))) {
while ($file = readdir($dh)) {
if (!Filesystem::isIgnoredDir($file)) {
return false;
}
}
}
return true;
}
示例13: recursiveDelShareKeys
/**
* recursively delete share keys from given users
*
* @param string $dir directory
* @param array $userIds user ids for which the share keys should be deleted
* @param \OC\Files\View $view view relative to data/
*/
private static function recursiveDelShareKeys($dir, $userIds, $view)
{
$dirContent = $view->opendir($dir);
if (is_resource($dirContent)) {
while (($file = readdir($dirContent)) !== false) {
if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
if ($view->is_dir($dir . '/' . $file)) {
self::recursiveDelShareKeys($dir . '/' . $file, $userIds, $view);
} else {
foreach ($userIds as $userId) {
if ($userId . '.shareKey' === $file) {
\OCP\Util::writeLog('files_encryption', 'recursiveDelShareKey: delete share key: ' . $file, \OCP\Util::DEBUG);
self::deleteKey($view, $dir . '/' . $file);
}
}
}
}
}
closedir($dirContent);
}
}
示例14: findShareKeys
/**
* find all share keys for a given file
* @param string $path to the file
* @param \OC\Files\View $view view, relative to data/
* @return array list of files, path relative to data/
*/
public static function findShareKeys($path, $view)
{
$result = array();
$pathinfo = pathinfo($path);
$dirContent = $view->opendir($pathinfo['dirname']);
if (is_resource($dirContent)) {
while (($file = readdir($dirContent)) !== false) {
if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
if (preg_match("/" . $pathinfo['filename'] . ".(.*).shareKey/", $file)) {
$result[] = $pathinfo['dirname'] . '/' . $file;
}
}
}
closedir($dirContent);
}
return $result;
}