当前位置: 首页>>代码示例>>PHP>>正文


PHP Files\Helper类代码示例

本文整理汇总了PHP中OCA\Files\Helper的典型用法代码示例。如果您正苦于以下问题:PHP Helper类的具体用法?PHP Helper怎么用?PHP Helper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Helper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: rename

 /**
  * rename a file
  *
  * @param string $dir
  * @param string $oldname
  * @param string $newname
  * @return array
  */
 public function rename($dir, $oldname, $newname)
 {
     $result = array('success' => false, 'data' => NULL);
     // rename to non-existing folder is denied
     if (!$this->view->file_exists($dir)) {
         $result['data'] = array('message' => (string) $this->l10n->t('The target folder has been moved or deleted.', array($dir)), 'code' => 'targetnotfound');
         // rename to existing file is denied
     } else {
         if ($this->view->file_exists($dir . '/' . $newname)) {
             $result['data'] = array('message' => $this->l10n->t("The name %s is already used in the folder %s. Please choose a different name.", array($newname, $dir)));
         } else {
             if ($newname !== '.' and $this->view->rename($dir . '/' . $oldname, $dir . '/' . $newname)) {
                 // successful rename
                 $meta = $this->view->getFileInfo($dir . '/' . $newname);
                 $fileinfo = \OCA\Files\Helper::formatFileInfo($meta);
                 $result['success'] = true;
                 $result['data'] = $fileinfo;
             } else {
                 // rename failed
                 $result['data'] = array('message' => $this->l10n->t('%s could not be renamed', array($oldname)));
             }
         }
     }
     return $result;
 }
开发者ID:olucao,项目名称:owncloud-core,代码行数:33,代码来源:app.php

示例2: rename

 /**
  * rename a file
  *
  * @param string $dir
  * @param string $oldname
  * @param string $newname
  * @return array
  */
 public function rename($dir, $oldname, $newname)
 {
     $result = array('success' => false, 'data' => NULL);
     // rename to "/Shared" is denied
     if ($dir === '/' and $newname === 'Shared') {
         $result['data'] = array('message' => $this->l10n->t("Invalid folder name. Usage of 'Shared' is reserved."));
         // rename to existing file is denied
     } else {
         if ($this->view->file_exists($dir . '/' . $newname)) {
             $result['data'] = array('message' => $this->l10n->t("The name %s is already used in the folder %s. Please choose a different name.", array($newname, $dir)));
         } else {
             if ($newname !== '.' and !($dir === '/' and $oldname === 'Shared') and $this->view->rename($dir . '/' . $oldname, $dir . '/' . $newname)) {
                 // successful rename
                 $meta = $this->view->getFileInfo($dir . '/' . $newname);
                 if ($meta['mimetype'] === 'httpd/unix-directory') {
                     $meta['type'] = 'dir';
                 } else {
                     $meta['type'] = 'file';
                 }
                 $fileinfo = array('id' => $meta['fileid'], 'mime' => $meta['mimetype'], 'size' => $meta['size'], 'etag' => $meta['etag'], 'directory' => $dir, 'name' => $newname, 'isPreviewAvailable' => \OC::$server->getPreviewManager()->isMimeSupported($meta['mimetype']), 'icon' => \OCA\Files\Helper::determineIcon($meta));
                 $result['success'] = true;
                 $result['data'] = $fileinfo;
             } else {
                 // rename failed
                 $result['data'] = array('message' => $this->l10n->t('%s could not be renamed', array($oldname)));
             }
         }
     }
     return $result;
 }
开发者ID:omusico,项目名称:isle-web-framework,代码行数:38,代码来源:app.php

示例3: testGetFilesByTagMultiple

 public function testGetFilesByTagMultiple()
 {
     $tagName = 'MyTagName';
     $fileInfo1 = new FileInfo('/root.txt', $this->getMockBuilder('\\OC\\Files\\Storage\\Storage')->disableOriginalConstructor()->getMock(), '/var/www/root.txt', ['mtime' => 55, 'mimetype' => 'application/pdf', 'size' => 1234, 'etag' => 'MyEtag'], $this->getMockBuilder('\\OCP\\Files\\Mount\\IMountPoint')->disableOriginalConstructor()->getMock());
     $fileInfo2 = new FileInfo('/root.txt', $this->getMockBuilder('\\OC\\Files\\Storage\\Storage')->disableOriginalConstructor()->getMock(), '/var/www/some/sub.txt', ['mtime' => 999, 'mimetype' => 'application/binary', 'size' => 9876, 'etag' => 'SubEtag'], $this->getMockBuilder('\\OCP\\Files\\Mount\\IMountPoint')->disableOriginalConstructor()->getMock());
     $this->tagService->expects($this->once())->method('getFilesByTag')->with($this->equalTo([$tagName]))->will($this->returnValue([$fileInfo1, $fileInfo2]));
     $expected = new DataResponse(['files' => [['id' => null, 'parentId' => null, 'date' => \OCP\Util::formatDate(55), 'mtime' => 55000, 'icon' => \OCA\Files\Helper::determineIcon($fileInfo1), 'name' => 'root.txt', 'permissions' => null, 'mimetype' => 'application/pdf', 'size' => 1234, 'type' => 'file', 'etag' => 'MyEtag', 'path' => '/', 'tags' => [['MyTagName']]], ['id' => null, 'parentId' => null, 'date' => \OCP\Util::formatDate(999), 'mtime' => 999000, 'icon' => \OCA\Files\Helper::determineIcon($fileInfo2), 'name' => 'root.txt', 'permissions' => null, 'mimetype' => 'application/binary', 'size' => 9876, 'type' => 'file', 'etag' => 'SubEtag', 'path' => '/', 'tags' => [['MyTagName']]]]]);
     $this->assertEquals($expected, $this->apiController->getFilesByTag([$tagName]));
 }
开发者ID:samj1912,项目名称:repo,代码行数:9,代码来源:apicontrollertest.php

示例4: testSortByName

 /**
  * @dataProvider sortDataProvider
  */
 public function testSortByName($sort, $sortDescending, $expectedOrder)
 {
     $files = self::getTestFileList();
     $files = \OCA\Files\Helper::sortFiles($files, $sort, $sortDescending);
     $fileNames = array();
     foreach ($files as $fileInfo) {
         $fileNames[] = $fileInfo->getName();
     }
     $this->assertEquals($expectedOrder, $fileNames);
 }
开发者ID:Kevin-ZK,项目名称:vaneDisk,代码行数:13,代码来源:helper.php

示例5: getTrashFiles

 /**
  * Retrieves the contents of a trash bin directory.
  * @param string $dir path to the directory inside the trashbin
  * or empty to retrieve the root of the trashbin
  * @return array of files
  */
 public static function getTrashFiles($dir)
 {
     $result = array();
     $user = \OCP\User::getUser();
     if ($dir && $dir !== '/') {
         $view = new \OC_Filesystemview('/' . $user . '/files_trashbin/files');
         $dirContent = $view->opendir($dir);
         if ($dirContent === false) {
             return null;
         }
         if (is_resource($dirContent)) {
             while (($entryName = readdir($dirContent)) !== false) {
                 if (!\OC\Files\Filesystem::isIgnoredDir($entryName)) {
                     $pos = strpos($dir . '/', '/', 1);
                     $tmp = substr($dir, 0, $pos);
                     $pos = strrpos($tmp, '.d');
                     $timestamp = substr($tmp, $pos + 2);
                     $result[] = array('id' => $entryName, 'timestamp' => $timestamp, 'mime' => $view->getMimeType($dir . '/' . $entryName), 'type' => $view->is_dir($dir . '/' . $entryName) ? 'dir' : 'file', 'location' => $dir);
                 }
             }
             closedir($dirContent);
         }
     } else {
         $query = \OC_DB::prepare('SELECT `id`,`location`,`timestamp`,`type`,`mime` FROM `*PREFIX*files_trash` WHERE `user` = ?');
         $result = $query->execute(array($user))->fetchAll();
     }
     $files = array();
     $id = 0;
     foreach ($result as $r) {
         $i = array();
         $i['id'] = $id++;
         $i['name'] = $r['id'];
         $i['date'] = \OCP\Util::formatDate($r['timestamp']);
         $i['timestamp'] = $r['timestamp'];
         $i['etag'] = $i['timestamp'];
         // dummy etag
         $i['mimetype'] = $r['mime'];
         $i['type'] = $r['type'];
         if ($i['type'] === 'file') {
             $fileinfo = pathinfo($r['id']);
             $i['basename'] = $fileinfo['filename'];
             $i['extension'] = isset($fileinfo['extension']) ? '.' . $fileinfo['extension'] : '';
         }
         $i['directory'] = $r['location'];
         if ($i['directory'] === '/') {
             $i['directory'] = '';
         }
         $i['permissions'] = \OCP\PERMISSION_READ;
         $i['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($r['mime']);
         $i['icon'] = \OCA\Files\Helper::determineIcon($i);
         $files[] = $i;
     }
     usort($files, array('\\OCA\\Files\\Helper', 'fileCmp'));
     return $files;
 }
开发者ID:hjimmy,项目名称:owncloud,代码行数:61,代码来源:helper.php

示例6: determineIcon

function determineIcon($file, $sharingRoot, $sharingToken)
{
    // for folders we simply reuse the files logic
    if ($file['type'] == 'dir') {
        return \OCA\Files\Helper::determineIcon($file);
    }
    $relativePath = substr($file['path'], 6);
    $relativePath = substr($relativePath, strlen($sharingRoot));
    if ($file['isPreviewAvailable']) {
        return OCP\publicPreview_icon($relativePath, $sharingToken) . '&c=' . $file['etag'];
    }
    return OCP\mimetype_icon($file['mimetype']);
}
开发者ID:hjimmy,项目名称:owncloud,代码行数:13,代码来源:public.php

示例7: getChildInfo

/**
 * @param \OCP\Files\FileInfo $dir
 * @param \OC\Files\View $view
 * @return array
 */
function getChildInfo($dir, $view)
{
    $children = $view->getDirectoryContent($dir->getPath());
    $result = array();
    foreach ($children as $child) {
        $formated = \OCA\Files\Helper::formatFileInfo($child);
        if ($child->getType() === 'dir') {
            $formated['children'] = getChildInfo($child, $view);
        }
        $formated['mtime'] = $formated['mtime'] / 1000;
        $result[] = $formated;
    }
    return $result;
}
开发者ID:samj1912,项目名称:repo,代码行数:19,代码来源:shareinfo.php

示例8: formatFileInfos

 /**
  * Format file infos for JSON
  * @param \OCP\Files\FileInfo[] $fileInfos file infos
  */
 public static function formatFileInfos($fileInfos)
 {
     $files = array();
     $id = 0;
     foreach ($fileInfos as $i) {
         $entry = \OCA\Files\Helper::formatFileInfo($i);
         $entry['id'] = $id++;
         $entry['etag'] = $entry['mtime'];
         // add fake etag, it is only needed to identify the preview image
         $entry['permissions'] = \OCP\Constants::PERMISSION_READ;
         $files[] = $entry;
     }
     return $files;
 }
开发者ID:Kevin-ZK,项目名称:vaneDisk,代码行数:18,代码来源:helper.php

示例9: formatFileInfos

 /**
  * Format file infos for JSON
  * @param \OCP\Files\FileInfo[] $fileInfos file infos
  */
 public static function formatFileInfos($fileInfos)
 {
     $files = array();
     $id = 0;
     foreach ($fileInfos as $i) {
         $entry = \OCA\Files\Helper::formatFileInfo($i);
         $entry['id'] = $id++;
         $entry['etag'] = $entry['mtime'];
         // add fake etag, it is only needed to identify the preview image
         $entry['permissions'] = \OCP\Constants::PERMISSION_READ;
         if (\OCP\App::isEnabled('files_encryption')) {
             $entry['isPreviewAvailable'] = false;
         }
         $files[] = $entry;
     }
     return $files;
 }
开发者ID:heldernl,项目名称:owncloud8-extended,代码行数:21,代码来源:helper.php

示例10: rename

 /**
  * rename a file
  *
  * @param string $dir
  * @param string $oldname
  * @param string $newname
  * @return array
  */
 public function rename($dir, $oldname, $newname)
 {
     $result = array('success' => false, 'data' => NULL);
     try {
         // check if the new name is conform to file name restrictions
         $this->view->verifyPath($dir, $newname);
     } catch (\OCP\Files\InvalidPathException $ex) {
         $result['data'] = array('message' => $this->l10n->t($ex->getMessage()), 'code' => 'invalidname');
         return $result;
     }
     $normalizedOldPath = \OC\Files\Filesystem::normalizePath($dir . '/' . $oldname);
     $normalizedNewPath = \OC\Files\Filesystem::normalizePath($dir . '/' . $newname);
     // rename to non-existing folder is denied
     if (!$this->view->file_exists($normalizedOldPath)) {
         $result['data'] = array('message' => $this->l10n->t('%s could not be renamed as it has been deleted', array($oldname)), 'code' => 'sourcenotfound', 'oldname' => $oldname, 'newname' => $newname);
     } else {
         if (!$this->view->file_exists($dir)) {
             $result['data'] = array('message' => (string) $this->l10n->t('The target folder has been moved or deleted.', array($dir)), 'code' => 'targetnotfound');
             // rename to existing file is denied
         } else {
             if ($this->view->file_exists($normalizedNewPath)) {
                 $result['data'] = array('message' => $this->l10n->t("The name %s is already used in the folder %s. Please choose a different name.", array($newname, $dir)));
             } else {
                 if ($newname !== '.' and $this->view->rename($normalizedOldPath, $normalizedNewPath)) {
                     // successful rename
                     $meta = $this->view->getFileInfo($normalizedNewPath);
                     $meta = \OCA\Files\Helper::populateTags(array($meta));
                     $fileInfo = \OCA\Files\Helper::formatFileInfo(current($meta));
                     $fileInfo['path'] = dirname($normalizedNewPath);
                     $result['success'] = true;
                     $result['data'] = $fileInfo;
                 } else {
                     // rename failed
                     $result['data'] = array('message' => $this->l10n->t('%s could not be renamed', array($oldname)));
                 }
             }
         }
     }
     return $result;
 }
开发者ID:Kevin-ZK,项目名称:vaneDisk,代码行数:48,代码来源:app.php

示例11: getFiles

 /**
  * Retrieves the contents of the given directory and
  * returns it as a sorted array.
  * @param string $dir path to the directory
  * @return array of files
  */
 public static function getFiles($dir)
 {
     $content = \OC\Files\Filesystem::getDirectoryContent($dir);
     $files = array();
     foreach ($content as $i) {
         $i['date'] = \OCP\Util::formatDate($i['mtime']);
         if ($i['type'] === 'file') {
             $fileinfo = pathinfo($i['name']);
             $i['basename'] = $fileinfo['filename'];
             if (!empty($fileinfo['extension'])) {
                 $i['extension'] = '.' . $fileinfo['extension'];
             } else {
                 $i['extension'] = '';
             }
         }
         $i['directory'] = $dir;
         $i['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($i['mimetype']);
         $i['icon'] = \OCA\Files\Helper::determineIcon($i);
         $files[] = $i;
     }
     usort($files, array('\\OCA\\Files\\Helper', 'fileCmp'));
     return $files;
 }
开发者ID:hjimmy,项目名称:owncloud,代码行数:29,代码来源:helper.php

示例12: manipulateDeleteTime

 /**
  * @param OCP\Files\FileInfo[] $files
  * @param string $trashRoot
  * @param integer $expireDate
  */
 private function manipulateDeleteTime($files, $trashRoot, $expireDate)
 {
     $counter = 0;
     foreach ($files as &$file) {
         // modify every second file
         $counter = ($counter + 1) % 2;
         if ($counter === 1) {
             $source = $trashRoot . '/files/' . $file['name'] . '.d' . $file['mtime'];
             $target = \OC\Files\Filesystem::normalizePath($trashRoot . '/files/' . $file['name'] . '.d' . $expireDate);
             $this->rootView->rename($source, $target);
             $file['mtime'] = $expireDate;
         }
     }
     return \OCA\Files\Helper::sortFiles($files, 'mtime');
 }
开发者ID:loulancn,项目名称:core,代码行数:20,代码来源:trashbin.php

示例13: create

 /**
  * @NoAdminRequired
  */
 public function create()
 {
     $mimetype = $this->request->post['mimetype'];
     $filename = $this->request->post['filename'];
     $dir = $this->request->post['dir'];
     $view = new View('/' . $this->uid . '/files');
     if (!$dir) {
         $dir = '/';
     }
     $basename = $this->l10n->t('New Document.odt');
     switch ($mimetype) {
         case 'application/vnd.oasis.opendocument.spreadsheet':
             $basename = $this->l10n->t('New Spreadsheet.ods');
             break;
         case 'application/vnd.oasis.opendocument.presentation':
             $basename = $this->l10n->t('New Presentation.odp');
             break;
         default:
             // to be safe
             $mimetype = 'application/vnd.oasis.opendocument.text';
             break;
     }
     if (!$filename) {
         $path = Helper::getNewFileName($view, $dir . '/' . $basename);
     } else {
         $path = $dir . '/' . $filename;
     }
     $content = '';
     if (class_exists('\\OC\\Files\\Type\\TemplateManager')) {
         $manager = \OC_Helper::getFileTemplateManager();
         $content = $manager->getTemplate($mimetype);
     }
     if (!$content) {
         $content = file_get_contents(dirname(__DIR__) . self::ODT_TEMPLATE_PATH);
     }
     $discovery_parsed = null;
     try {
         $discovery = $this->getDiscovery();
         $loadEntities = libxml_disable_entity_loader(true);
         $discovery_parsed = simplexml_load_string($discovery);
         libxml_disable_entity_loader($loadEntities);
         if ($discovery_parsed === false) {
             $this->cache->remove('discovery.xml');
             $wopiRemote = $this->appConfig->getAppValue('wopi_url');
             return array('status' => 'error', 'message' => $this->l10n->t('Collabora Online: discovery.xml from "%s" is not a well-formed XML string.', array($wopiRemote)), 'hint' => $this->l10n->t('Please contact the "%s" administrator.', array($wopiRemote)));
         }
     } catch (ResponseException $e) {
         return array('status' => 'error', 'message' => $e->getMessage(), 'hint' => $e->getHint());
     }
     if ($content && $view->file_put_contents($path, $content)) {
         $info = $view->getFileInfo($path);
         $ret = $this->getWopiSrcUrl($discovery_parsed, $mimetype);
         $response = array('status' => 'success', 'fileid' => $info['fileid'], 'urlsrc' => $ret['urlsrc'], 'action' => $ret['action'], 'lolang' => $this->settings->getUserValue($this->uid, 'core', 'lang', 'en'), 'data' => \OCA\Files\Helper::formatFileInfo($info));
     } else {
         $response = array('status' => 'error', 'message' => (string) $this->l10n->t('Can\'t create document'));
     }
     return $response;
 }
开发者ID:owncloud,项目名称:richdocuments,代码行数:61,代码来源:documentcontroller.php

示例14: catch

                        $data['directory'] = $returnedDir;
                        $result[] = $data;
                    }
                } else {
                    $error = $l->t('Upload failed. Could not find uploaded file');
                }
            } catch (Exception $ex) {
                $error = $ex->getMessage();
            }
        } else {
            // file already exists
            $meta = \OC\Files\Filesystem::getFileInfo($target);
            if ($meta === false) {
                $error = $l->t('Upload failed. Could not get file info.');
            } else {
                $data = \OCA\Files\Helper::formatFileInfo($meta);
                $data['permissions'] = $data['permissions'] & $allowedPermissions;
                $data['status'] = 'existserror';
                $data['originalname'] = $files['tmp_name'][$i];
                $data['uploadMaxFilesize'] = $maxUploadFileSize;
                $data['maxHumanFilesize'] = $maxHumanFileSize;
                $data['permissions'] = $meta['permissions'] & $allowedPermissions;
                $data['directory'] = $returnedDir;
                $result[] = $data;
            }
        }
    }
} else {
    $error = $l->t('Invalid directory.');
}
if ($error === false) {
开发者ID:WYSAC,项目名称:oregon-owncloud,代码行数:31,代码来源:upload.php

示例15: formatFileInfo

 /**
  * Formats the file info to be returned as JSON to the client.
  *
  * @param \OCP\Files\FileInfo $i
  * @return array formatted file info
  */
 public static function formatFileInfo(FileInfo $i)
 {
     $entry = array();
     $entry['id'] = $i['fileid'];
     $entry['parentId'] = $i['parent'];
     $entry['date'] = \OCP\Util::formatDate($i['mtime']);
     $entry['mtime'] = $i['mtime'] * 1000;
     // only pick out the needed attributes
     $entry['icon'] = \OCA\Files\Helper::determineIcon($i);
     if (\OC::$server->getPreviewManager()->isAvailable($i)) {
         $entry['isPreviewAvailable'] = true;
     }
     $entry['name'] = $i->getName();
     $entry['permissions'] = $i['permissions'];
     $entry['mimetype'] = $i['mimetype'];
     $entry['size'] = $i['size'];
     $entry['type'] = $i['type'];
     $entry['etag'] = $i['etag'];
     if (isset($i['tags'])) {
         $entry['tags'] = $i['tags'];
     }
     if (isset($i['displayname_owner'])) {
         $entry['shareOwner'] = $i['displayname_owner'];
     }
     if (isset($i['is_share_mount_point'])) {
         $entry['isShareMountPoint'] = $i['is_share_mount_point'];
     }
     $mountType = null;
     if ($i->isShared()) {
         $mountType = 'shared';
     } else {
         if ($i->isMounted()) {
             $mountType = 'external';
         }
     }
     if ($mountType !== null) {
         if ($i->getInternalPath() === '') {
             $mountType .= '-root';
         }
         $entry['mountType'] = $mountType;
     }
     if (isset($i['extraData'])) {
         $entry['extraData'] = $i['extraData'];
     }
     return $entry;
 }
开发者ID:riso,项目名称:owncloud-core,代码行数:52,代码来源:helper.php


注:本文中的OCA\Files\Helper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。