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


PHP Helper::formatFileInfo方法代码示例

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


在下文中一共展示了Helper::formatFileInfo方法的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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 = parent::formatFileInfo($i);
     preg_match('/(?<container>project-\\d+)/', $i->getPath(), $container);
     preg_match('/(?<target>task-(?<targetId>\\d+))/', $i->getPath(), $task);
     preg_match('/(?<target>issue-(?<targetId>\\d+))/', $i->getPath(), $issue);
     if (!is_null($container)) {
         if (isset($_SESSION['targetType'])) {
             $entry['container'] = $_SESSION['targetType'];
         }
         $entry['path'] .= PageController::PROJECTKIT_PREFIX . DIRECTORY_SEPARATOR . $container[0] . DIRECTORY_SEPARATOR;
         if (!empty($task)) {
             $entry['path'] .= $task['target'];
             $entry['targetType'] = TargetType::TASK;
             $entry['targetId'] = $task['targetId'];
         }
         if (!empty($issue)) {
             $entry['path'] .= $issue['target'];
             $entry['targetType'] = TargetType::ISSUE;
             $entry['targetId'] = $issue['targetId'];
         }
     }
     return $entry;
 }
开发者ID:fproject,项目名称:apps,代码行数:30,代码来源:helper.php

示例7: array

    $result['data'] = array('message' => (string) $l10n->t('The target folder has been moved or deleted.'), 'code' => 'targetnotfound');
    OCP\JSON::error($result);
    exit;
}
$target = $dir . '/' . $fileName;
if (\OC\Files\Filesystem::file_exists($target)) {
    $result['data'] = array('message' => (string) $l10n->t('The name %s is already used in the folder %s. Please choose a different name.', array($fileName, $dir)));
    OCP\JSON::error($result);
    exit;
}
$success = false;
$templateManager = OC_Helper::getFileTemplateManager();
$mimeType = OC_Helper::getMimetypeDetector()->detectPath($target);
$content = $templateManager->getTemplate($mimeType);
try {
    if ($content) {
        $success = \OC\Files\Filesystem::file_put_contents($target, $content);
    } else {
        $success = \OC\Files\Filesystem::touch($target);
    }
} catch (\Exception $e) {
    $result = ['success' => false, 'data' => ['message' => $e->getMessage()]];
    OCP\JSON::error($result);
    exit;
}
if ($success) {
    $meta = \OC\Files\Filesystem::getFileInfo($target);
    OCP\JSON::success(array('data' => \OCA\Files\Helper::formatFileInfo($meta)));
    return;
}
OCP\JSON::error(array('data' => array('message' => $l10n->t('Error when creating the file'))));
开发者ID:samj1912,项目名称:repo,代码行数:31,代码来源:newfile.php

示例8: 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

示例9: getFilesByTag

 /**
  * Returns a list of all files tagged with the given tag.
  *
  * @NoAdminRequired
  *
  * @param array|string $tagName tag name to filter by
  * @return DataResponse
  */
 public function getFilesByTag($tagName)
 {
     $files = array();
     $fileInfos = $this->tagService->getFilesByTag($tagName);
     foreach ($fileInfos as &$fileInfo) {
         $file = \OCA\Files\Helper::formatFileInfo($fileInfo);
         $parts = explode('/', dirname($fileInfo->getPath()), 4);
         if (isset($parts[3])) {
             $file['path'] = '/' . $parts[3];
         } else {
             $file['path'] = '/';
         }
         $file['tags'] = [$tagName];
         $files[] = $file;
     }
     return new DataResponse(['files' => $files]);
 }
开发者ID:rosarion,项目名称:core,代码行数:25,代码来源:apicontroller.php

示例10: getlogo

 public function getlogo()
 {
     $userfiles = \OCA\Files\Helper::getFiles('ProjectLogo');
     foreach ($userfiles as $f => $file) {
         $userfiles[$f] = \OCA\Files\Helper::formatFileInfo($file);
         $userfiles[$f]['mtime'] = $userfiles[$f]['mtime'] / 1000;
     }
     $params = ['user' => $this->userId, 'files' => $userfiles, 'error' => null, 'errorinfo' => ''];
     return new DataResponse($params);
 }
开发者ID:raceface2nd,项目名称:owncollab,代码行数:10,代码来源:apicontroller.php

示例11: createFileListTree

 public function createFileListTree($path = '/')
 {
     $files = \OCA\Files\Helper::getFiles($path);
     if (is_array($files)) {
         foreach ($files as $f => $file) {
             if ($file['type'] == 'dir') {
                 $this->createFileListTree(substr($file['path'], 6));
             } else {
                 $fdata = \OCA\Files\Helper::formatFileInfo($file);
                 $fdata['mtime'] = $file['mtime'] / 1000;
                 $fdata['path'] = substr($file['path'], 6);
                 array_push($this->listtree, $fdata);
             }
         }
     }
     return $this->listtree;
 }
开发者ID:raceface2nd,项目名称:owncollab,代码行数:17,代码来源:apicontroller.php

示例12: getfolderfiles

 public function getfolderfiles($folderid)
 {
     $files = $this->connect->files();
     $path = $files->getFolderPath($folderid, $this->userId);
     //$userfiles = \OCA\Files\Helper::getFiles('../'.$path);
     $userfiles = \OCA\Files\Helper::getFiles('/' . $path);
     foreach ($userfiles as $f => $file) {
         $userfiles[$f] = \OCA\Files\Helper::formatFileInfo($file);
         $userfiles[$f]['mtime'] = $userfiles[$f]['mtime'] / 1000;
     }
     $params = array('files' => $userfiles, 'folder' => $userfiles, 'requesttoken' => !\OC_Util::isCallRegistered() ? '' : \OC_Util::callRegister());
     $view = Helper::renderPartial($this->appName, 'api.folderfiles', $params);
     //$view = "User files!";
     $params = array('user' => $this->userId, 'files' => $userfiles, 'view' => $view, 'requesttoken' => !\OC_Util::isCallRegistered() ? '' : \OC_Util::callRegister());
     return new DataResponse($params);
 }
开发者ID:bogolubov,项目名称:owncollab_talks-1,代码行数:16,代码来源:apicontroller.php

示例13: read

 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  * @return TemplateResponse
  */
 public function read($id)
 {
     $attachements_info = [];
     $message = $this->connect->messages()->getById((int) $id);
     $parent = $this->connect->messages()->getById((int) $message['rid']);
     if (!empty($message['attachements'])) {
         $attach = [];
         try {
             $attach = json_decode($message['attachements'], true);
         } catch (\Exception $e) {
             var_dump('Exception: ' . $e->getMessage());
         }
         foreach ($attach as $at) {
             $file = $this->connect->files()->getInfoById($at);
             $fileInfo = false;
             $filePath = str_replace('files/', '', $file['path']);
             try {
                 $fileInfo = \OC\Files\Filesystem::getFileInfo($filePath);
             } catch (\Exception $e) {
             }
             //var_dump($file);
             if (!$fileInfo) {
                 $itemSource = \OCP\Share::getItemSharedWithBySource('file', $at);
                 if (is_array($itemSource) && !empty($itemSource)) {
                     $fileInfo = \OC\Files\Filesystem::getFileInfo($itemSource['file_target']);
                     $filePath = $itemSource['file_target'];
                 }
             }
             if (!$fileInfo) {
                 continue;
             }
             $icon = '/core/img/filetypes/image.svg';
             // \OCA\Files\Helper::determineIcon($fileInfo);
             $attachements_info[] = ['preview' => $icon, 'link' => "/remote.php/webdav/{$filePath}", 'file' => $file, 'info' => \OCA\Files\Helper::formatFileInfo($fileInfo)];
         }
     }
     Helper::cookies('goto_message', $message['rid'] == 0 ? $message['id'] : $parent['id'], 0, '/');
     $data = ['menu' => 'all', 'content' => 'read', 'message' => $message, 'parent' => $parent, 'attachements_info' => $attachements_info];
     return new TemplateResponse($this->appName, 'main', $data);
 }
开发者ID:raceface2nd,项目名称:owncollab,代码行数:45,代码来源:maincontroller.php

示例14: upload

 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  * @SSOCORS
  */
 public function upload($dir = '/')
 {
     \OC::$server->getSession()->close();
     // Firefox and Konqueror tries to download application/json for me.  --Arthur
     \OCP\JSON::setContentTypeHeader('text/plain');
     // If a directory token is sent along check if public upload is permitted.
     // If not, check the login.
     // If no token is sent along, rely on login only
     $allowedPermissions = \OCP\Constants::PERMISSION_ALL;
     $errorCode = null;
     if (\OC\Files\Filesystem::file_exists($dir) === false) {
         return new DataResponse(array('data' => array_merge(array('message' => 'Invalid directory.')), 'status' => 'error'));
     }
     // get array with current storage stats (e.g. max file size)
     $storageStats = \OCA\Files\Helper::buildFileStorageStatistics($dir);
     $files = $this->request->getUploadedFile('files');
     if (!isset($files)) {
         return new DataResponse(array('data' => array_merge(array('message' => 'No file was uploaded. Unknown error'), $storageStats), 'status' => 'error'));
     }
     foreach ($files['error'] as $error) {
         if ($error != 0) {
             $errors = array(UPLOAD_ERR_OK => 'There is no error, the file uploaded with success', UPLOAD_ERR_INI_SIZE => 'The uploaded file exceeds the upload_max_filesize directive in php.ini: ' . ini_get('upload_max_filesize'), UPLOAD_ERR_FORM_SIZE => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form', UPLOAD_ERR_PARTIAL => 'The uploaded file was only partially uploaded', UPLOAD_ERR_NO_FILE => 'No file was uploaded', UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder', UPLOAD_ERR_CANT_WRITE => 'Failed to write to disk');
             $errorMessage = $errors[$error];
             \OC::$server->getLogger()->alert("Upload error: {$error} - {$errorMessage}", array('app' => 'files'));
             return new DataResponse(array('data' => array_merge(array('message' => $errorMessage), $storageStats), 'status' => 'error'));
         }
     }
     $error = false;
     $maxUploadFileSize = $storageStats['uploadMaxFilesize'];
     $maxHumanFileSize = \OCP\Util::humanFileSize($maxUploadFileSize);
     $totalSize = 0;
     foreach ($files['size'] as $size) {
         $totalSize += $size;
     }
     if ($maxUploadFileSize >= 0 and $totalSize > $maxUploadFileSize) {
         return new DataResponse(array('data' => array('message' => 'Not enough storage available', 'uploadMaxFilesize' => $maxUploadFileSize, '   maxHumanFilesize' => $maxHumanFileSize), 'status' => 'error'));
     }
     $result = array();
     $fileCount = count($files['name']);
     for ($i = 0; $i < $fileCount; $i++) {
         // target directory for when uploading folders
         $relativePath = '';
         $target = \OC\Files\Filesystem::normalizePath($dir . $relativePath . '/' . $files['name'][$i]);
         // relative dir to return to the client
         if (isset($publicDirectory)) {
             // path relative to the public root
             $returnedDir = $publicDirectory . $relativePath;
         } else {
             // full path
             $returnedDir = $dir . $relativePath;
         }
         $returnedDir = \OC\Files\Filesystem::normalizePath($returnedDir);
         $exists = \OC\Files\Filesystem::file_exists($target);
         if ($exists) {
             $target = \OCP\Files::buildNotExistingFileName($dir . $relativePath, $files['name'][$i]);
         }
         try {
             if (is_uploaded_file($files['tmp_name'][$i]) and \OC\Files\Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) {
                 // updated max file size after upload
                 $storageStats = \OCA\Files\Helper::buildFileStorageStatistics($dir);
                 $meta = \OC\Files\Filesystem::getFileInfo($target);
                 if ($meta === false) {
                     $error = 'The target folder has been moved or deleted.';
                     $errorCode = 'targetnotfound';
                 } else {
                     $data = \OCA\Files\Helper::formatFileInfo($meta);
                     $data['originalname'] = $files['name'][$i];
                     $data['uploadMaxFilesize'] = $maxUploadFileSize;
                     $data['maxHumanFilesize'] = $maxHumanFileSize;
                     $data['permissions'] = $meta['permissions'] & $allowedPermissions;
                     $data['directory'] = $returnedDir;
                     $result[] = $data;
                 }
             } else {
                 $error = 'Upload failed. Could not find uploaded file';
             }
         } catch (Exception $ex) {
             $error = $ex->getMessage();
         }
     }
     if ($error === false) {
         $result = \OCP\JSON::encode($result);
         return new DataResponse(array('data' => $result, 'status' => 'success'));
     } else {
         return new DataResponse(array('data' => array_merge(array('message' => $error, 'code' => $errorCode), $storageStats), 'status' => 'error'));
     }
 }
开发者ID:inwinstack,项目名称:owncloud-singlesignon,代码行数:92,代码来源:collaborationapicontroller.php

示例15: 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


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