本文整理汇总了PHP中OC\Files\View类的典型用法代码示例。如果您正苦于以下问题:PHP View类的具体用法?PHP View怎么用?PHP View使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了View类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
parent::setUp();
//clear all proxies and hooks so we can do clean testing
\OC_Hook::clear('OC_Filesystem');
//set up temporary storage
$this->storage = \OC\Files\Filesystem::getStorage('/');
\OC\Files\Filesystem::clearMounts();
$storage = new \OC\Files\Storage\Temporary(array());
\OC\Files\Filesystem::mount($storage, array(), '/');
$datadir = str_replace('local::', '', $storage->getId());
$config = \OC::$server->getConfig();
$this->datadir = $config->getSystemValue('cachedirectory', \OC::$SERVERROOT . '/data/cache');
$config->setSystemValue('cachedirectory', $datadir);
\OC_User::clearBackends();
\OC_User::useBackend(new \Test\Util\User\Dummy());
//login
\OC_User::createUser('test', 'test');
$this->user = \OC_User::getUser();
\OC_User::setUserId('test');
//set up the users dir
$this->rootView = new \OC\Files\View('');
$this->rootView->mkdir('/test');
$this->instance = new \OC\Cache\File();
// forces creation of cache folder for subsequent tests
$this->instance->set('hack', 'hack');
}
示例2: getAllVersions
/**
* Gets all versions of a note
*
* @NoAdminRequired
* @NoCSRFRequired
* @CORS
*
* @return array
*/
public function getAllVersions()
{
$source = $this->request->getParam("file_name", "");
list($uid, $filename) = Storage::getUidAndFilename($source);
$versions = Storage::getVersions($uid, $filename, $source);
$versionsResults = array();
if (is_array($versions) && count($versions) > 0) {
require_once __DIR__ . '/../3rdparty/finediff/finediff.php';
$users_view = new View('/' . $uid);
$currentData = $users_view->file_get_contents('files/' . $filename);
// $previousData = $currentData;
// $versions = array_reverse( $versions, true );
foreach ($versions as $versionData) {
// get timestamp of version
$mtime = (int) $versionData["version"];
// get filename of note version
$versionFileName = 'files_versions/' . $filename . '.v' . $mtime;
// load the data from the file
$data = $users_view->file_get_contents($versionFileName);
// calculate diff between versions
$opcodes = \FineDiff::getDiffOpcodes($currentData, $data);
$html = \FineDiff::renderDiffToHTMLFromOpcodes($currentData, $opcodes);
$versionsResults[] = array("timestamp" => $mtime, "humanReadableTimestamp" => $versionData["humanReadableTimestamp"], "diffHtml" => $html, "data" => $data);
// $previousData = $data;
}
// $versionsResults = array_reverse( $versionsResults );
}
return array("file_name" => $source, "versions" => $versionsResults);
}
示例3: getMaximumStorageUsage
/**
* @param string $userName
* @return integer
*/
public function getMaximumStorageUsage($userName)
{
$view = new FilesView('/' . $userName . '/files');
$freeSpace = (int) $view->free_space();
$usedSpace = $view->getFileInfo('/')->getSize();
return $freeSpace + $usedSpace;
}
示例4: setUp
protected function setUp()
{
$app = new Application();
$this->container = $app->getContainer();
$this->container['Config'] = $this->getMockBuilder('\\OCP\\IConfig')->disableOriginalConstructor()->getMock();
$this->container['AppName'] = 'files_sharing';
$this->container['UserSession'] = $this->getMockBuilder('\\OC\\User\\Session')->disableOriginalConstructor()->getMock();
$this->container['URLGenerator'] = $this->getMockBuilder('\\OC\\URLGenerator')->disableOriginalConstructor()->getMock();
$this->urlGenerator = $this->container['URLGenerator'];
$this->shareController = $this->container['ShareController'];
// Store current user
$this->oldUser = \OC_User::getUser();
// Create a dummy user
$this->user = \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate(12, ISecureRandom::CHAR_LOWER);
\OC_User::createUser($this->user, $this->user);
\OC_Util::tearDownFS();
\OC_User::setUserId('');
Filesystem::tearDown();
\OC_User::setUserId($this->user);
\OC_Util::setupFS($this->user);
// Create a dummy shared file
$view = new View('/' . $this->user . '/files');
$view->file_put_contents('file1.txt', 'I am such an awesome shared file!');
$this->token = \OCP\Share::shareItem(Filesystem::getFileInfo('file1.txt')->getType(), Filesystem::getFileInfo('file1.txt')->getId(), \OCP\Share::SHARE_TYPE_LINK, 'IAmPasswordProtected!', 1);
}
示例5: show
/**
* Get the template for a specific activity-event in the activities
*
* @param array $activity An array with all the activity data in it
* @return string
*/
public static function show($activity)
{
$tmpl = new Template('activity', 'activity.box');
$tmpl->assign('formattedDate', Util::formatDate($activity['timestamp']));
$tmpl->assign('formattedTimestamp', \OCP\relative_modified_date($activity['timestamp']));
$tmpl->assign('user', $activity['user']);
$tmpl->assign('displayName', User::getDisplayName($activity['user']));
if ($activity['app'] === 'files') {
// We do not link the subject as we create links for the parameters instead
$activity['link'] = '';
}
$tmpl->assign('event', $activity);
if ($activity['file']) {
$rootView = new View('/' . $activity['affecteduser'] . '/files');
$exist = $rootView->file_exists($activity['file']);
$is_dir = $rootView->is_dir($activity['file']);
unset($rootView);
// show a preview image if the file still exists
$mimetype = \OC_Helper::getFileNameMimeType($activity['file']);
if (!$is_dir && \OC::$server->getPreviewManager()->isMimeSupported($mimetype) && $exist) {
$tmpl->assign('previewLink', Util::linkTo('files', 'index.php', array('dir' => dirname($activity['file']))));
$tmpl->assign('previewImageLink', Util::linkToRoute('core_ajax_preview', array('file' => $activity['file'], 'x' => 150, 'y' => 150)));
} else {
$tmpl->assign('previewLink', Util::linkTo('files', 'index.php', array('dir' => $activity['file'])));
$tmpl->assign('previewImageLink', \OC_Helper::mimetypeIcon($is_dir ? 'dir' : $mimetype));
$tmpl->assign('previewLinkIsDir', true);
}
}
return $tmpl->fetchPage();
}
示例6: getThumbnail
/**
* @param string $path
* @param int $maxX
* @param int $maxY
* @param boolean $scalingup
* @param \OC\Files\View $fileview
* @return bool|\OC_Image
*/
public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview)
{
$content = $fileview->fopen($path, 'r');
$content = stream_get_contents($content);
//don't create previews of empty text files
if (trim($content) === '') {
return false;
}
$lines = preg_split("/\r\n|\n|\r/", $content);
$fontSize = 5;
//5px
$lineSize = ceil($fontSize * 1.25);
$image = imagecreate($maxX, $maxY);
imagecolorallocate($image, 255, 255, 255);
$textColor = imagecolorallocate($image, 0, 0, 0);
foreach ($lines as $index => $line) {
$index = $index + 1;
$x = (int) 1;
$y = (int) ($index * $lineSize) - $fontSize;
imagestring($image, 1, $x, $y, $line, $textColor);
if ($index * $lineSize >= $maxY) {
break;
}
}
$image = new \OC_Image($image);
return $image->valid() ? $image : false;
}
示例7: byUsername
/**
* @param string $userName
* @return integer
*/
public function byUsername($userName)
{
$view = new FilesView('/' . $userName . '/files');
$freeSpace = (int) $view->free_space();
$fileInfo = $view->getFileInfo('/');
Assertion::notEmpty($fileInfo);
$usedSpace = $fileInfo->getSize();
return KiloBytes::allocateUnits($freeSpace + $usedSpace)->units();
}
示例8: getFreeSpace
/**
* @param $parentUri
* @return mixed
*/
public function getFreeSpace($parentUri)
{
if (is_null($this->fileView)) {
// initialize fileView
$this->fileView = \OC\Files\Filesystem::getView();
}
$freeSpace = $this->fileView->free_space($parentUri);
return $freeSpace;
}
示例9: testChangeLock
public function testChangeLock()
{
Filesystem::initMountPoints($this->recipientUid);
$recipientView = new View('/' . $this->recipientUid . '/files');
$recipientView->lockFile('bar.txt', ILockingProvider::LOCK_SHARED);
$recipientView->changeLock('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
$recipientView->unlockFile('bar.txt', ILockingProvider::LOCK_EXCLUSIVE);
$this->assertTrue(true);
}
示例10: validate
/**
* Check if genesis is valid
* @param \OC\Files\View $view
* @param string $path relative to the view
* @throws \Exception
*/
protected function validate($view, $path)
{
if (!$view->file_exists($path)) {
throw new \Exception('Document not found ' . $path);
}
if (!$view->is_file($path)) {
throw new \Exception('Object ' . $path . ' is not a file.');
}
//TODO check if it is a valid odt
}
示例11: getPrivateKey
/**
* @brief retrieve the ENCRYPTED private key from a user
*
* @param \OC\Files\View $view
* @param string $user
* @return string private key or false (hopefully)
* @note the key returned by this method must be decrypted before use
*/
public static function getPrivateKey($view, $user)
{
$path = '/' . $user . '/' . 'files_encryption' . '/' . $user . '.private.key';
$key = false;
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
if ($view->file_exists($path)) {
$key = $view->file_get_contents($path);
}
\OC_FileProxy::$enabled = $proxyStatus;
return $key;
}
示例12: propagateForOwner
/**
* @param array $share
* @param string $internalPath
* @param \OC\Files\Cache\ChangePropagator $propagator
*/
private function propagateForOwner($share, $internalPath, ChangePropagator $propagator)
{
// note that we have already set up the filesystem for the owner when mounting the share
$view = new View('/' . $share['uid_owner'] . '/files');
$shareRootPath = $view->getPath($share['item_source']);
if (!is_null($shareRootPath)) {
$path = $shareRootPath . '/' . $internalPath;
$path = Filesystem::normalizePath($path);
$propagator->addChange($path);
$propagator->propagateChanges();
}
}
示例13: run
public function run()
{
$view = new View('/');
$children = $view->getDirectoryContent('/');
foreach ($children as $child) {
if ($view->is_dir($child->getPath())) {
$thumbnailsFolder = $child->getPath() . '/thumbnails';
if ($view->is_dir($thumbnailsFolder)) {
$view->rmdir($thumbnailsFolder);
}
}
}
}
示例14: 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;
}
示例15: testPrepareParameters
/**
* @dataProvider prepareParametersData
*/
public function testPrepareParameters($params, $filePosition, $stripPath, $highlightParams, $expected, $createFolder = '')
{
if ($createFolder !== '') {
$this->view->mkdir('/' . \OCP\User::getUser() . '/files/' . $createFolder);
}
$this->assertEquals($expected, $this->parameterHelper->prepareParameters($params, $filePosition, $stripPath, $highlightParams));
}