本文整理汇总了PHP中OCP\Files::getStorage方法的典型用法代码示例。如果您正苦于以下问题:PHP Files::getStorage方法的具体用法?PHP Files::getStorage怎么用?PHP Files::getStorage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OCP\Files
的用法示例。
在下文中一共展示了Files::getStorage方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($params)
{
$host = $params['host'];
//remove leading http[s], will be generated in createBaseUri()
if (substr($host, 0, 8) == "https://") {
$host = substr($host, 8);
} else {
if (substr($host, 0, 7) == "http://") {
$host = substr($host, 7);
}
}
$this->host = $host;
$this->user = $params['user'];
$this->password = $params['password'];
$this->secure = isset($params['secure']) && $params['secure'] == 'true' ? true : false;
$this->root = isset($params['root']) ? $params['root'] : '/';
if (!$this->root || $this->root[0] != '/') {
$this->root = '/' . $this->root;
}
if (substr($this->root, -1, 1) != '/') {
$this->root .= '/';
}
$settings = array('baseUri' => $this->createBaseUri(), 'userName' => $this->user, 'password' => $this->password);
$this->client = new OC_Connector_Sabre_Client($settings);
if ($caview = \OCP\Files::getStorage('files_external')) {
$certPath = \OCP\Config::getSystemValue('datadirectory') . $caview->getAbsolutePath("") . 'rootcerts.crt';
if (file_exists($certPath)) {
$this->client->addTrustedCertificates($certPath);
}
}
//create the root folder if necesary
$this->mkdir('');
}
示例2: hostKeysPath
private function hostKeysPath()
{
try {
$storage_view = \OCP\Files::getStorage('files_external');
if ($storage_view) {
return \OCP\Config::getSystemValue('datadirectory') . $storage_view->getAbsolutePath('') . 'ssh_hostKeys';
}
} catch (\Exception $e) {
}
return false;
}
示例3: init
private function init()
{
if ($this->ready) {
return;
}
$this->ready = true;
$settings = array('baseUri' => $this->createBaseUri(), 'userName' => $this->user, 'password' => $this->password);
$this->client = new \Sabre_DAV_Client($settings);
$caview = \OCP\Files::getStorage('files_external');
if ($caview) {
$certPath = \OCP\Config::getSystemValue('datadirectory') . $caview->getAbsolutePath("") . 'rootcerts.crt';
if (file_exists($certPath)) {
$this->client->addTrustedCertificates($certPath);
}
}
}
示例4: rename_hook
/**
* @brief rename/move versions of renamed/moved files
* @param array with oldpath and newpath
*
* This function is connected to the rename signal of OC_Filesystem and adjust the name and location
* of the stored versions along the actual file
*/
public static function rename_hook($params)
{
$versions_fileview = \OCP\Files::getStorage('files_versions');
$rel_oldpath = $params['oldpath'];
$abs_oldpath = \OCP\Config::getSystemValue('datadirectory') . $versions_fileview->getAbsolutePath('') . $rel_oldpath . '.v';
$abs_newpath = \OCP\Config::getSystemValue('datadirectory') . $versions_fileview->getAbsolutePath('') . $params['newpath'] . '.v';
if (Storage::isversioned($rel_oldpath)) {
$info = pathinfo($abs_newpath);
if (!file_exists($info['dirname'])) {
mkdir($info['dirname'], 0750, true);
}
$versions = Storage::getVersions($rel_oldpath);
foreach ($versions as $v) {
rename($abs_oldpath . $v['version'], $abs_newpath . $v['version']);
}
}
}
示例5: av_scan
public static function av_scan($path)
{
$path = $path[\OC\Files\Filesystem::signal_param_path];
if ($path != '') {
if (isset($_POST['dirToken'])) {
//Public upload case
$filesView = \OC\Files\Filesystem::getView();
} else {
$filesView = \OCP\Files::getStorage("files");
}
if (!is_object($filesView)) {
\OCP\Util::writeLog('files_antivirus', 'Can\'t init filesystem view', \OCP\Util::WARN);
return;
}
// check if path is a directory
if ($filesView->is_dir($path)) {
return;
}
// we should have a file to work with, and the file shouldn't
// be empty
$fileExists = $filesView->file_exists($path);
if ($fileExists && $filesView->filesize($path) > 0) {
$fileStatus = self::scanFile($filesView, $path);
$result = $fileStatus->getNumericStatus();
switch ($result) {
case Status::SCANRESULT_UNCHECKED:
//TODO: Show warning to the user: The file can not be checked
break;
case Status::SCANRESULT_INFECTED:
//remove file
$filesView->unlink($path);
Notification::sendMail($path);
$message = \OCP\Util::getL10N('files_antivirus')->t("Virus detected! Can't upload the file %s", array(basename($path)));
\OCP\JSON::error(array("data" => array("message" => $message)));
exit;
break;
case Status::SCANRESULT_CLEAN:
//do nothing
break;
}
}
}
}
示例6: av_scan
public static function av_scan($path)
{
$path = $path[\OC\Files\Filesystem::signal_param_path];
if ($path != '') {
$files_view = \OCP\Files::getStorage("files");
if ($files_view->file_exists($path)) {
$root = OC_User::getHome(OC_User::getUser()) . '/files';
$file = $root . $path;
$result = self::clamav_scan($file);
switch ($result) {
case CLAMAV_SCANRESULT_UNCHECKED:
//TODO: Show warning to the user: The file can not be checked
break;
case CLAMAV_SCANRESULT_INFECTED:
//remove file
$files_view->unlink($path);
OCP\JSON::error(array("data" => array("message" => "Virus detected! Can't upload the file.")));
$email = OC_Preferences::getValue(OC_User::getUser(), 'settings', 'email', '');
\OCP\Util::writeLog('files_antivirus', 'Email: ' . $email, \OCP\Util::DEBUG);
if (!empty($email)) {
$tmpl = new OC_Template('files_antivirus', 'notification');
$tmpl->assign('file', $path);
$tmpl->assign('host', OCP\Util::getServerHost());
$tmpl->assign('user', OC_User::getUser());
$msg = $tmpl->fetchPage();
$from = OCP\Util::getDefaultEmailAddress('security-noreply');
OCP\Util::sendMail($email, OC_User::getUser(), 'Malware detected', $msg, $from, 'ownCloud', 1);
}
exit;
break;
case CLAMAV_SCANRESULT_CLEAN:
//do nothing
break;
}
}
}
}
示例7: ltrim
<?php
OCP\JSON::checkAppEnabled('files_external');
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
$view = \OCP\Files::getStorage("files_external");
$file = 'uploads/' . ltrim($_POST['cert'], "/\\.");
if ($view->file_exists($file)) {
$view->unlink($file);
OC_Mount_Config::createCertificateBundle();
}
示例8: DoAttachmentsActions
/**
* @return array
*
* @throws \MailSo\Base\Exceptions\Exception
*/
public function DoAttachmentsActions()
{
if (!$this->GetCapa(false, \RainLoop\Enumerations\Capa::ATTACHMENTS_ACTIONS)) {
return $this->FalseResponse(__FUNCTION__);
}
$oAccount = $this->initMailClientConnection();
$sAction = $this->GetActionParam('Do', '');
$aHashes = $this->GetActionParam('Hashes', null);
$mResult = false;
$bError = false;
$aData = false;
if (\is_array($aHashes) && 0 < \count($aHashes)) {
$aData = array();
foreach ($aHashes as $sZipHash) {
$aResult = $this->getMimeFileByHash($oAccount, $sZipHash);
if (\is_array($aResult) && !empty($aResult['FileHash'])) {
$aData[] = $aResult;
} else {
$bError = true;
break;
}
}
}
$oFilesProvider = $this->FilesProvider();
if (!empty($sAction) && !$bError && \is_array($aData) && 0 < \count($aData) && $oFilesProvider && $oFilesProvider->IsActive()) {
$bError = false;
switch (\strtolower($sAction)) {
case 'zip':
if (\class_exists('ZipArchive')) {
$sZipHash = \MailSo\Base\Utils::Md5Rand();
$sZipFileName = $oFilesProvider->GenerateLocalFullFileName($oAccount, $sZipHash);
if (!empty($sZipFileName)) {
$oZip = new \ZipArchive();
$oZip->open($sZipFileName, \ZIPARCHIVE::CREATE | \ZIPARCHIVE::OVERWRITE);
$oZip->setArchiveComment('RainLoop/' . APP_VERSION);
foreach ($aData as $aItem) {
$sFileName = (string) (isset($aItem['FileName']) ? $aItem['FileName'] : 'file.dat');
$sFileHash = (string) (isset($aItem['FileHash']) ? $aItem['FileHash'] : '');
if (!empty($sFileHash)) {
$sFullFileNameHash = $oFilesProvider->GetFileName($oAccount, $sFileHash);
if (!$oZip->addFile($sFullFileNameHash, $sFileName)) {
$bError = true;
}
}
}
if (!$bError) {
$bError = !$oZip->close();
} else {
$oZip->close();
}
}
foreach ($aData as $aItem) {
$sFileHash = (string) (isset($aItem['FileHash']) ? $aItem['FileHash'] : '');
if (!empty($sFileHash)) {
$oFilesProvider->Clear($oAccount, $sFileHash);
}
}
if (!$bError) {
$mResult = array('Files' => array(array('FileName' => 'attachments.zip', 'Hash' => \RainLoop\Utils::EncodeKeyValuesQ(array('V' => APP_VERSION, 'Account' => $oAccount ? \md5($oAccount->Hash()) : '', 'FileName' => 'attachments.zip', 'MimeType' => 'application/zip', 'FileHash' => $sZipHash)))));
}
}
break;
case 'owncloud':
$mResult = false;
if (\RainLoop\Utils::IsOwnCloudLoggedIn() && \class_exists('OCP\\Files')) {
$sSaveFolder = $this->Config()->Get('labs', 'owncloud_save_folder', '');
if (empty($sSaveFolder)) {
$sSaveFolder = 'Attachments';
}
$oFiles = \OCP\Files::getStorage('files');
if ($oFilesProvider && $oFiles && $oFilesProvider->IsActive() && \method_exists($oFiles, 'file_put_contents')) {
if (!$oFiles->is_dir($sSaveFolder)) {
$oFiles->mkdir($sSaveFolder);
}
$mResult = true;
foreach ($aData as $aItem) {
$sSavedFileName = isset($aItem['FileName']) ? $aItem['FileName'] : 'file.dat';
$sSavedFileHash = !empty($aItem['FileHash']) ? $aItem['FileHash'] : '';
if (!empty($sSavedFileHash)) {
$fFile = $oFilesProvider->GetFile($oAccount, $sSavedFileHash, 'rb');
if (\is_resource($fFile)) {
$sSavedFileNameFull = \MailSo\Base\Utils::SmartFileExists($sSaveFolder . '/' . $sSavedFileName, function ($sPath) use($oFiles) {
return $oFiles->file_exists($sPath);
});
if (!$oFiles->file_put_contents($sSavedFileNameFull, $fFile)) {
$mResult = false;
}
if (\is_resource($fFile)) {
@\fclose($fFile);
}
}
}
}
}
}
//.........这里部分代码省略.........
示例9: start
/**
* @NoAdminRequired
*/
public function start()
{
$request = $this->request;
$response = new JSONResponse();
$params = $this->request->urlParams;
$app = new App($this->api->getUserId());
$addressBook = $app->getAddressBook($params['backend'], $params['addressBookId']);
if (!$addressBook->hasPermission(\OCP\PERMISSION_CREATE)) {
$response->setStatus('403');
$response->bailOut(App::$l10n->t('You do not have permissions to import into this address book.'));
return $response;
}
$filename = isset($request->post['filename']) ? $request->post['filename'] : null;
$progresskey = isset($request->post['progresskey']) ? $request->post['progresskey'] : null;
if (is_null($filename)) {
$response->bailOut(App::$l10n->t('File name missing from request.'));
return $response;
}
if (is_null($progresskey)) {
$response->bailOut(App::$l10n->t('Progress key missing from request.'));
return $response;
}
$filename = strtr($filename, array('/' => '', "\\" => ''));
if (\OC\Files\Filesystem::isFileBlacklisted($filename)) {
$response->bailOut(App::$l10n->t('Attempt to access blacklisted file:') . $filename);
return $response;
}
$view = \OCP\Files::getStorage('contacts');
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
$file = $view->file_get_contents('/imports/' . $filename);
\OC_FileProxy::$enabled = $proxyStatus;
$writeProgress = function ($pct) use($progresskey) {
\OC_Cache::set($progresskey, $pct, 300);
};
$cleanup = function () use($view, $filename, $progresskey) {
if (!$view->unlink('/imports/' . $filename)) {
$response->debug('Unable to unlink /imports/' . $filename);
}
\OC_Cache::remove($progresskey);
};
$writeProgress('20');
$nl = "\n";
$file = str_replace(array("\r", "\n\n"), array("\n", "\n"), $file);
$lines = explode($nl, $file);
$inelement = false;
$parts = array();
$card = array();
foreach ($lines as $line) {
if (strtoupper(trim($line)) == 'BEGIN:VCARD') {
$inelement = true;
} elseif (strtoupper(trim($line)) == 'END:VCARD') {
$card[] = $line;
$parts[] = implode($nl, $card);
$card = array();
$inelement = false;
}
if ($inelement === true && trim($line) != '') {
$card[] = $line;
}
}
if (count($parts) === 0) {
$response->bailOut(App::$l10n->t('No contacts found in: ') . $filename);
$cleanup();
return $response;
}
//import the contacts
$imported = 0;
$failed = 0;
$partially = 0;
$processed = 0;
// TODO: Add a new group: "Imported at {date}"
foreach ($parts as $part) {
try {
$vcard = VObject\Reader::read($part);
} catch (VObject\ParseException $e) {
try {
$vcard = VObject\Reader::read($part, VObject\Reader::OPTION_IGNORE_INVALID_LINES);
$partially += 1;
$response->debug('Import: Retrying reading card. Error parsing VCard: ' . $e->getMessage());
} catch (\Exception $e) {
$failed += 1;
$response->debug('Import: skipping card. Error parsing VCard: ' . $e->getMessage());
continue;
// Ditch cards that can't be parsed by Sabre.
}
}
try {
$vcard->validate(MyVCard::REPAIR | MyVCard::UPGRADE);
} catch (\Exception $e) {
\OCP\Util::writeLog('contacts', __METHOD__ . ' ' . 'Error validating vcard: ' . $e->getMessage(), \OCP\Util::ERROR);
$failed += 1;
}
/**
* TODO
* - Check if a contact with identical UID exists.
* - If so, fetch that contact and call $contact->mergeFromVCard($vcard);
//.........这里部分代码省略.........
示例10: createCertificateBundle
/**
* creates certificate bundle
*/
public static function createCertificateBundle()
{
$view = \OCP\Files::getStorage("files_external");
$path = \OCP\Config::getSystemValue('datadirectory') . $view->getAbsolutePath("");
$certs = OC_Mount_Config::getCertificates();
$fh_certs = fopen($path . "/rootcerts.crt", 'w');
foreach ($certs as $cert) {
$file = $path . '/uploads/' . $cert;
$fh = fopen($file, "r");
$data = fread($fh, filesize($file));
fclose($fh);
if (strpos($data, 'BEGIN CERTIFICATE')) {
fwrite($fh_certs, $data);
fwrite($fh_certs, "\r\n");
}
}
fclose($fh_certs);
return true;
}
示例11: start
/**
* @NoAdminRequired
*/
public function start()
{
$request = $this->request;
$response = new JSONResponse();
$params = $this->request->urlParams;
$app = new App(\OCP\User::getUser());
$addressBookId = $params['addressBookId'];
$format = $params['importType'];
$addressBook = $app->getAddressBook($params['backend'], $addressBookId);
if (!$addressBook->hasPermission(\OCP\PERMISSION_CREATE)) {
$response->setStatus('403');
$response->bailOut(App::$l10n->t('You do not have permissions to import into this address book.'));
return $response;
}
$filename = isset($request->post['filename']) ? $request->post['filename'] : null;
$progresskey = isset($request->post['progresskey']) ? $request->post['progresskey'] : null;
if (is_null($filename)) {
$response->bailOut(App::$l10n->t('File name missing from request.'));
return $response;
}
if (is_null($progresskey)) {
$response->bailOut(App::$l10n->t('Progress key missing from request.'));
return $response;
}
$filename = strtr($filename, array('/' => '', "\\" => ''));
if (\OC\Files\Filesystem::isFileBlacklisted($filename)) {
$response->bailOut(App::$l10n->t('Attempt to access blacklisted file:') . $filename);
return $response;
}
$view = \OCP\Files::getStorage('contacts');
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
$file = $view->file_get_contents('/imports/' . $filename);
\OC_FileProxy::$enabled = $proxyStatus;
$importManager = new ImportManager();
$formatList = $importManager->getTypes();
$found = false;
$parts = array();
foreach ($formatList as $formatName => $formatDisplayName) {
if ($formatName == $format) {
$parts = $importManager->importFile($view->getLocalFile('/imports/' . $filename), $formatName);
$found = true;
}
}
if (!$found) {
// detect file type
$mostLikelyName = "";
$mostLikelyValue = 0;
$probability = $importManager->detectFileType($view->getLocalFile('/imports/' . $filename));
foreach ($probability as $probName => $probValue) {
if ($probValue > $mostLikelyValue) {
$mostLikelyName = $probName;
$mostLikelyValue = $probValue;
}
}
if ($mostLikelyValue > 0) {
// found one (most likely...)
$parts = $importManager->importFile($view->getLocalFile('/imports/' . $filename), $mostLikelyName);
}
}
if ($parts) {
//import the contacts
$imported = 0;
$failed = 0;
$processed = 0;
$total = count($parts);
foreach ($parts as $part) {
/**
* TODO
* - Check if a contact with identical UID exists.
* - If so, fetch that contact and call $contact->mergeFromVCard($part);
* - Increment $updated var (not present yet.)
* - continue
*/
try {
$id = $addressBook->addChild($part);
if ($id) {
$imported++;
$favourites = $part->select('X-FAVOURITES');
foreach ($favourites as $favourite) {
if ($favourite->getValue() == 'yes') {
$this->tagMgr->addToFavorites($id);
}
}
} else {
$failed++;
}
} catch (\Exception $e) {
$response->debug('Error importing vcard: ' . $e->getMessage() . $nl . $part->serialize());
$failed++;
}
$processed++;
$this->writeProcess($processed, $total, $progresskey);
}
} else {
$imported = 0;
$failed = 0;
//.........这里部分代码省略.........
示例12: delete
public function delete($path)
{
$thumbnail_storage = \OCP\Files::getStorage('gallery');
if ($thumbnail_storage->file_exists($path)) {
$thumbnail_storage->unlink($path);
}
}
示例13: expireAll
/**
* @brief Erase all old versions of all user files
* @return true/false
*/
public function expireAll()
{
$view = \OCP\Files::getStorage('files_versions');
return $view->deleteAll('', true);
}
示例14: bailOut
* @author Alessandro Cosentino
* Copyright (c) 2012 - Alessandro Cosentino <cosenal@gmail.com>
*
* This file is licensed under the Affero General Public License version 3 or later.
* See the COPYING-README file
*
*/
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('news');
OCP\JSON::callCheck();
$l = OC_L10N::get('news');
function bailOut($msg)
{
OCP\JSON::error(array('data' => array('message' => $msg)));
OCP\Util::writeLog('news', 'ajax/uploadopml.php: ' . $msg, OCP\Util::ERROR);
exit;
}
if (isset($_POST['path'])) {
OCP\JSON::success(array('data' => array('source' => 'cloud', 'path' => $_POST['path'])));
} elseif (isset($_FILES['file'])) {
$storage = \OCP\Files::getStorage('news');
$filename = 'opmlfile.xml';
if ($storage->fromTmpFile($_FILES['file']['tmp_name'], $filename)) {
OCP\JSON::success(array('data' => array('source' => 'local', 'path' => $filename)));
} else {
bailOut('Could not create the temporary file');
}
} else {
bailOut('No file loaded');
}