本文整理汇总了PHP中OC_Filesystem::init方法的典型用法代码示例。如果您正苦于以下问题:PHP OC_Filesystem::init方法的具体用法?PHP OC_Filesystem::init怎么用?PHP OC_Filesystem::init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC_Filesystem
的用法示例。
在下文中一共展示了OC_Filesystem::init方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setupFS
public static function setupFS($user = "", $root = "files")
{
// configure the initial filesystem based on the configuration
if (self::$fsSetup) {
//setting up the filesystem twice can only lead to trouble
return false;
}
$CONFIG_DATADIRECTORY_ROOT = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data");
$CONFIG_BACKUPDIRECTORY = OC_Config::getValue("backupdirectory", OC::$SERVERROOT . "/backup");
// Check if config folder is writable.
if (!is_writable(OC::$SERVERROOT . "/config/")) {
$tmpl = new OC_Template('', 'error', 'guest');
$tmpl->assign('errors', array(1 => array('error' => "Can't write into config directory 'config'", 'hint' => "You can usually fix this by giving the webserver user write access to the config directory in owncloud")));
$tmpl->printPage();
exit;
}
// Check if apps folder is writable.
if (!is_writable(OC::$SERVERROOT . "/apps/")) {
$tmpl = new OC_Template('', 'error', 'guest');
$tmpl->assign('errors', array(1 => array('error' => "Can't write into apps directory 'apps'", 'hint' => "You can usually fix this by giving the webserver user write access to the config directory in owncloud")));
$tmpl->printPage();
exit;
}
// Create root dir.
if (!is_dir($CONFIG_DATADIRECTORY_ROOT)) {
$success = @mkdir($CONFIG_DATADIRECTORY_ROOT);
if (!$success) {
$tmpl = new OC_Template('', 'error', 'guest');
$tmpl->assign('errors', array(1 => array('error' => "Can't create data directory (" . $CONFIG_DATADIRECTORY_ROOT . ")", 'hint' => "You can usually fix this by giving the webserver write access to the ownCloud directory '" . OC::$SERVERROOT . "' (in a terminal, use the command 'chown -R www-data:www-data /path/to/your/owncloud/install/data' ")));
$tmpl->printPage();
exit;
}
}
// If we are not forced to load a specific user we load the one that is logged in
if ($user == "" && OC_User::isLoggedIn()) {
$user = OC_User::getUser();
}
//first set up the local "root" storage
if (!self::$rootMounted) {
OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => $CONFIG_DATADIRECTORY_ROOT), '/');
self::$rootMounted = true;
}
if ($user != "") {
//if we aren't logged in, there is no use to set up the filesystem
OC::$CONFIG_DATADIRECTORY = $CONFIG_DATADIRECTORY_ROOT . "/{$user}/{$root}";
if (!is_dir(OC::$CONFIG_DATADIRECTORY)) {
mkdir(OC::$CONFIG_DATADIRECTORY, 0755, true);
}
//jail the user into his "home" directory
OC_Filesystem::init('/' . $user . '/' . $root);
$quotaProxy = new OC_FileProxy_Quota();
OC_FileProxy::register($quotaProxy);
self::$fsSetup = true;
}
}
示例2: setupFS
public static function setupFS($user = '')
{
// configure the initial filesystem based on the configuration
if (self::$fsSetup) {
//setting up the filesystem twice can only lead to trouble
return false;
}
// If we are not forced to load a specific user we load the one that is logged in
if ($user == "" && OC_User::isLoggedIn()) {
$user = OC_User::getUser();
}
// the filesystem will finish when $user is not empty,
// mark fs setup here to avoid doing the setup from loading
// OC_Filesystem
if ($user != '') {
self::$fsSetup = true;
}
$CONFIG_DATADIRECTORY = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data");
//first set up the local "root" storage
if (!self::$rootMounted) {
OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => $CONFIG_DATADIRECTORY), '/');
self::$rootMounted = true;
}
if ($user != "") {
//if we aren't logged in, there is no use to set up the filesystem
$user_dir = '/' . $user . '/files';
$user_root = OC_User::getHome($user);
$userdirectory = $user_root . '/files';
if (!is_dir($userdirectory)) {
mkdir($userdirectory, 0755, true);
}
//jail the user into his "home" directory
OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => $user_root), $user);
OC_Filesystem::init($user_dir);
$quotaProxy = new OC_FileProxy_Quota();
OC_FileProxy::register($quotaProxy);
// Load personal mount config
if (is_file($user_root . '/mount.php')) {
$mountConfig = (include $user_root . '/mount.php');
if (isset($mountConfig['user'][$user])) {
foreach ($mountConfig['user'][$user] as $mountPoint => $options) {
OC_Filesystem::mount($options['class'], $options['options'], $mountPoint);
}
}
$mtime = filemtime($user_root . '/mount.php');
$previousMTime = OC_Preferences::getValue($user, 'files', 'mountconfigmtime', 0);
if ($mtime > $previousMTime) {
//mount config has changed, filecache needs to be updated
OC_FileCache::triggerUpdate($user);
OC_Preferences::setValue($user, 'files', 'mountconfigmtime', $mtime);
}
}
OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $user_dir));
}
}
示例3: setupFS
public static function setupFS($user = '')
{
// configure the initial filesystem based on the configuration
if (self::$fsSetup) {
//setting up the filesystem twice can only lead to trouble
return false;
}
// If we are not forced to load a specific user we load the one that is logged in
if ($user == "" && OC_User::isLoggedIn()) {
$user = OC_User::getUser();
}
// load all filesystem apps before, so no setup-hook gets lost
if (!isset($RUNTIME_NOAPPS) || !$RUNTIME_NOAPPS) {
OC_App::loadApps(array('filesystem'));
}
// the filesystem will finish when $user is not empty,
// mark fs setup here to avoid doing the setup from loading
// OC_Filesystem
if ($user != '') {
self::$fsSetup = true;
}
$CONFIG_DATADIRECTORY = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data");
//first set up the local "root" storage
if (!self::$rootMounted) {
OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => $CONFIG_DATADIRECTORY), '/');
self::$rootMounted = true;
}
if ($user != "") {
//if we aren't logged in, there is no use to set up the filesystem
$user_dir = '/' . $user . '/files';
$user_root = OC_User::getHome($user);
$userdirectory = $user_root . '/files';
if (!is_dir($userdirectory)) {
mkdir($userdirectory, 0755, true);
}
//jail the user into his "home" directory
OC_Filesystem::mount('OC_Filestorage_Local', array('datadir' => $user_root), $user);
OC_Filesystem::init($user_dir, $user);
$quotaProxy = new OC_FileProxy_Quota();
$fileOperationProxy = new OC_FileProxy_FileOperations();
OC_FileProxy::register($quotaProxy);
OC_FileProxy::register($fileOperationProxy);
// Load personal mount config
self::loadUserMountPoints($user);
OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $user_dir));
}
}
示例4: setUp
public function setUp()
{
$user = OC_User::getUser();
$this->oldConfig = OCP\Config::getAppValue('files_encryption', 'enable_encryption', 'true');
OCP\Config::setAppValue('files_encryption', 'enable_encryption', 'true');
$this->oldKey = isset($_SESSION['enckey']) ? $_SESSION['enckey'] : null;
//set testing key
$_SESSION['enckey'] = md5(time());
//clear all proxies and hooks so we can do clean testing
OC_FileProxy::clearProxies();
OC_Hook::clear('OC_Filesystem');
//enable only the encryption hook
OC_FileProxy::register(new OC_FileProxy_Encryption());
//set up temporary storage
OC_Filesystem::clearMounts();
OC_Filesystem::mount('OC_Filestorage_Temporary', array(), '/');
OC_Filesystem::init('/' . $user . '/files');
//set up the users home folder in the temp storage
$rootView = new OC_FilesystemView('');
$rootView->mkdir('/' . $user);
$rootView->mkdir('/' . $user . '/files');
}
示例5: quotaGet
/**
* get the quota of a user
* @param string $format
* @param string $user
* @return string xml/json
*/
private static function quotaGet($format, $user)
{
$login = OC_OCS::checkpassword();
if (OC_Group::inGroup($login, 'admin') or $login == $user) {
if (OC_User::userExists($user)) {
// calculate the disc space
$user_dir = '/' . $user . '/files';
OC_Filesystem::init($user_dir);
$rootInfo = OC_FileCache::get('');
$sharedInfo = OC_FileCache::get('/Shared');
$used = $rootInfo['size'] - $sharedInfo['size'];
$free = OC_Filesystem::free_space();
$total = $free + $used;
if ($total == 0) {
$total = 1;
}
// prevent division by zero
$relative = round($used / $total * 10000) / 100;
$xml = array();
$xml['quota'] = $total;
$xml['free'] = $free;
$xml['used'] = $used;
$xml['relative'] = $relative;
$txt = OC_OCS::generatexml($format, 'ok', 100, '', $xml, 'cloud', '', 1, 0, 0);
echo $txt;
} else {
echo self::generateXml('', 'fail', 300, 'User does not exist');
}
} else {
echo self::generateXml('', 'fail', 300, 'You don´t have permission to access this ressource.');
}
}
示例6: testHooks
public function testHooks()
{
if (OC_Filesystem::getView()) {
$user = OC_User::getUser();
} else {
$user = uniqid();
OC_Filesystem::init('/' . $user . '/files');
}
OC_Hook::clear('OC_Filesystem');
OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');
OC_Filesystem::mount('OC_Filestorage_Temporary', array(), '/');
$rootView = new OC_FilesystemView('');
$rootView->mkdir('/' . $user);
$rootView->mkdir('/' . $user . '/files');
OC_Filesystem::file_put_contents('/foo', 'foo');
OC_Filesystem::mkdir('/bar');
OC_Filesystem::file_put_contents('/bar//foo', 'foo');
$tmpFile = OC_Helper::tmpFile();
file_put_contents($tmpFile, 'foo');
$fh = fopen($tmpFile, 'r');
OC_Filesystem::file_put_contents('/bar//foo', $fh);
}