本文整理汇总了PHP中OC_Hook::emit方法的典型用法代码示例。如果您正苦于以下问题:PHP OC_Hook::emit方法的具体用法?PHP OC_Hook::emit怎么用?PHP OC_Hook::emit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC_Hook
的用法示例。
在下文中一共展示了OC_Hook::emit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deleteSubAdmin
/**
* delete a SubAdmin
* @param string $uid uid of the SubAdmin
* @param string $gid gid of the group
* @return boolean
*/
public static function deleteSubAdmin($uid, $gid)
{
$stmt = OC_DB::prepare('DELETE FROM `*PREFIX*group_admin` WHERE `gid` = ? AND `uid` = ?');
$result = $stmt->execute(array($gid, $uid));
OC_Hook::emit("OC_SubAdmin", "post_deleteSubAdmin", array("gid" => $gid));
return true;
}
示例2: deleteSubAdmin
/**
* delete a SubAdmin
* @param IUser $user the user that is the SubAdmin
* @param IGroup $group the group
* @return bool
*/
public function deleteSubAdmin(IUser $user, IGroup $group)
{
$qb = $this->dbConn->getQueryBuilder();
$qb->delete('group_admin')->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID())))->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))->execute();
$this->emit('\\OC\\SubAdmin', 'postDeleteSubAdmin', [$user, $group]);
\OC_Hook::emit("OC_SubAdmin", "post_deleteSubAdmin", ["gid" => $group->getGID()]);
return true;
}
示例3: setupFS
/**
* @brief Can be set up
* @param string $user
* @return boolean
* @description configure the initial filesystem based on the configuration
*/
public static function setupFS($user = '')
{
//setting up the filesystem twice can only lead to trouble
if (self::$fsSetup) {
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;
}
$configDataDirectory = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data");
//first set up the local "root" storage
\OC\Files\Filesystem::initMounts();
if (!self::$rootMounted) {
\OC\Files\Filesystem::mount('\\OC\\Files\\Storage\\Local', array('datadir' => $configDataDirectory), '/');
self::$rootMounted = true;
}
//if we aren't logged in, there is no use to set up the filesystem
if ($user != "") {
\OC\Files\Filesystem::addStorageWrapper(function ($mountPoint, $storage) {
// set up quota for home storages, even for other users
// which can happen when using sharing
if ($storage instanceof \OC\Files\Storage\Home) {
$user = $storage->getUser()->getUID();
$quota = OC_Util::getUserQuota($user);
if ($quota !== \OC\Files\SPACE_UNLIMITED) {
return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota));
}
}
return $storage;
});
$userDir = '/' . $user . '/files';
$userRoot = OC_User::getHome($user);
$userDirectory = $userRoot . '/files';
if (!is_dir($userDirectory)) {
mkdir($userDirectory, 0755, true);
OC_Util::copySkeleton($userDirectory);
}
//jail the user into his "home" directory
\OC\Files\Filesystem::init($user, $userDir);
$fileOperationProxy = new OC_FileProxy_FileOperations();
OC_FileProxy::register($fileOperationProxy);
OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir));
}
return true;
}
示例4: 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));
}
}
示例5: get
/**
* get the filesystem info from the cache
* @param string path
* @param string root (optional)
* @return array
*
* returns an associative array with the following keys:
* - size
* - mtime
* - ctime
* - mimetype
* - encrypted
* - versioned
*/
public static function get($path, $root = false)
{
if (OC_FileCache_Update::hasUpdated($path, $root)) {
if ($root === false) {
//filesystem hooks are only valid for the default root
OC_Hook::emit('OC_Filesystem', 'post_write', array('path' => $path));
} else {
OC_FileCache_Update::update($path, $root);
}
}
return OC_FileCache_Cached::get($path, $root);
}
示例6: scanCollection
/**
* scan all music for the current user
*
* @return int the number of songs found
*/
public function scanCollection()
{
$music = $this->getMusic();
\OC_Hook::emit('media', 'song_count', array('count' => count($music)));
$songs = 0;
foreach ($music as $file) {
$this->scanFile($file);
$songs++;
\OC_Hook::emit('media', 'song_scanned', array('path' => $file, 'count' => $songs));
}
return $songs;
}
示例7: upgradeChilds
/**
* upgrade all child elements of an item
*
* @param int $id
* @param bool $mode
*/
function upgradeChilds($id, $mode = Scanner::SCAN_RECURSIVE)
{
$children = $this->legacy->getChildren($id);
foreach ($children as $child) {
$childData = $this->getNewData($child);
\OC_Hook::emit('\\OC\\Files\\Cache\\Upgrade', 'migrate_path', $child['path']);
if ($childData) {
$this->insert($childData);
if ($mode == Scanner::SCAN_RECURSIVE) {
$this->upgradeChilds($child['id']);
}
}
}
}
示例8: 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));
}
}
示例9: sendRemoteShare
/**
* send server-to-server share to remote server
*
* @param string $token
* @param string $shareWith
* @param string $name
* @param int $remote_id
* @param string $owner
* @return bool
*/
public function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner)
{
list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith);
if ($user && $remote) {
$url = $remote;
$local = $this->addressHandler->generateRemoteURL();
$fields = array('shareWith' => $user, 'token' => $token, 'name' => $name, 'remoteId' => $remote_id, 'owner' => $owner, 'remote' => $local);
$url = $this->addressHandler->removeProtocolFromUrl($url);
$result = $this->tryHttpPostToShareEndpoint($url, '', $fields);
$status = json_decode($result['result'], true);
if ($result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200)) {
\OC_Hook::emit('OCP\\Share', 'federated_share_added', ['server' => $remote]);
return true;
}
}
return false;
}
示例10: find
/**
* Find the mount for $path
*
* @param string $path
* @return MountPoint
*/
public function find($path)
{
\OC_Util::setupFS();
$path = $this->formatPath($path);
if (isset($this->mounts[$path])) {
return $this->mounts[$path];
}
\OC_Hook::emit('OC_Filesystem', 'get_mountpoint', array('path' => $path));
$foundMountPoint = '';
$mountPoints = array_keys($this->mounts);
foreach ($mountPoints as $mountpoint) {
if (strpos($path, $mountpoint) === 0 and strlen($mountpoint) > strlen($foundMountPoint)) {
$foundMountPoint = $mountpoint;
}
}
if (isset($this->mounts[$foundMountPoint])) {
return $this->mounts[$foundMountPoint];
} else {
return null;
}
}
示例11: testBlacklist
public function testBlacklist()
{
OC_Hook::clear('OC_Filesystem');
OC::registerFilesystemHooks();
$run = true;
OC_Hook::emit(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_write, array(OC_Filesystem::signal_param_path => '/test/.htaccess', OC_Filesystem::signal_param_run => &$run));
$this->assertFalse($run);
if (OC_Filesystem::getView()) {
$user = OC_User::getUser();
} else {
$user = uniqid();
OC_Filesystem::init('/' . $user . '/files');
}
OC_Filesystem::mount('OC_Filestorage_Temporary', array(), '/');
$rootView = new OC_FilesystemView('');
$rootView->mkdir('/' . $user);
$rootView->mkdir('/' . $user . '/files');
$this->assertFalse($rootView->file_put_contents('/.htaccess', 'foo'));
$this->assertFalse(OC_Filesystem::file_put_contents('/.htaccess', 'foo'));
$fh = fopen(__FILE__, 'r');
$this->assertFalse(OC_Filesystem::file_put_contents('/.htaccess', $fh));
}
示例12: sendRemoteShare
/**
* send server-to-server share to remote server
*
* @param string $token
* @param string $shareWith
* @param string $name
* @param int $remote_id
* @param string $owner
* @return bool
*/
private static function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner)
{
list($user, $remote) = Helper::splitUserRemote($shareWith);
if ($user && $remote) {
$url = $remote . self::BASE_PATH_TO_SHARE_API . '?format=' . self::RESPONSE_FORMAT;
$local = \OC::$server->getURLGenerator()->getAbsoluteURL('/');
$fields = array('shareWith' => $user, 'token' => $token, 'name' => $name, 'remoteId' => $remote_id, 'owner' => $owner, 'remote' => $local);
$url = self::removeProtocolFromUrl($url);
$result = self::tryHttpPost($url, $fields);
$status = json_decode($result['result'], true);
if ($result['success'] && $status['ocs']['meta']['statuscode'] === 100) {
\OC_Hook::emit('OCP\\Share', 'federated_share_added', ['server' => $remote]);
return true;
}
}
return false;
}
示例13: setupFS
/**
* Can be set up
*
* @param string $user
* @return boolean
* @description configure the initial filesystem based on the configuration
*/
public static function setupFS($user = '')
{
//setting up the filesystem twice can only lead to trouble
if (self::$fsSetup) {
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
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;
}
//check if we are using an object storage
$objectStore = OC_Config::getValue('objectstore');
if (isset($objectStore)) {
self::initObjectStoreRootFS($objectStore);
} else {
self::initLocalStorageRootFS();
}
if ($user != '' && !OCP\User::userExists($user)) {
return false;
}
//if we aren't logged in, there is no use to set up the filesystem
if ($user != "") {
\OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) {
// set up quota for home storages, even for other users
// which can happen when using sharing
/**
* @var \OC\Files\Storage\Storage $storage
*/
if ($storage->instanceOfStorage('\\OC\\Files\\Storage\\Home') || $storage->instanceOfStorage('\\OC\\Files\\ObjectStore\\HomeObjectStoreStorage')) {
if (is_object($storage->getUser())) {
$user = $storage->getUser()->getUID();
$quota = OC_Util::getUserQuota($user);
if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) {
return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files'));
}
}
}
return $storage;
});
// copy skeleton for local storage only
if (!isset($objectStore)) {
$userRoot = OC_User::getHome($user);
$userDirectory = $userRoot . '/files';
if (!is_dir($userDirectory)) {
mkdir($userDirectory, 0755, true);
OC_Util::copySkeleton($userDirectory);
}
}
$userDir = '/' . $user . '/files';
//jail the user into his "home" directory
\OC\Files\Filesystem::init($user, $userDir);
$fileOperationProxy = new OC_FileProxy_FileOperations();
OC_FileProxy::register($fileOperationProxy);
OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir));
}
return true;
}
示例14: backgroundScan
/**
* walk over any folders that are not fully scanned yet and scan them
*/
public function backgroundScan()
{
$lastPath = null;
while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) {
try {
$this->scan($path, self::SCAN_RECURSIVE, self::REUSE_ETAG);
\OC_Hook::emit('Scanner', 'correctFolderSize', array('path' => $path));
if ($this->cacheActive) {
$this->cache->correctFolderSize($path);
}
} catch (\OCP\Files\StorageInvalidException $e) {
// skip unavailable storages
} catch (\OCP\Files\StorageNotAvailableException $e) {
// skip unavailable storages
} catch (\OCP\Files\ForbiddenException $e) {
// skip forbidden storages
} catch (\OCP\Lock\LockedException $e) {
// skip unavailable storages
}
// FIXME: this won't proceed with the next item, needs revamping of getIncomplete()
// to make this possible
$lastPath = $path;
}
}
示例15: put
/**
* Put shared item into the database
* @param string $itemType Item type
* @param string $itemSource Item source
* @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
* @param string $shareWith User or group the item is being shared with
* @param string $uidOwner User that is the owner of shared item
* @param int $permissions CRUDS permissions
* @param boolean|array $parentFolder Parent folder target (optional)
* @param string $token (optional)
* @param string $itemSourceName name of the source item (optional)
* @param \DateTime $expirationDate (optional)
* @throws \Exception
* @return boolean Returns true on success or false on failure
*/
private static function put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, $parentFolder = null, $token = null, $itemSourceName = null, \DateTime $expirationDate = null)
{
$queriesToExecute = array();
$suggestedItemTarget = null;
$result = self::checkReshare($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, $itemSourceName, $expirationDate);
if (!empty($result)) {
$parent = $result['parent'];
$itemSource = $result['itemSource'];
$fileSource = $result['fileSource'];
$suggestedItemTarget = $result['suggestedItemTarget'];
$suggestedFileTarget = $result['suggestedFileTarget'];
$filePath = $result['filePath'];
$expirationDate = $result['expirationDate'];
}
$isGroupShare = false;
if ($shareType == self::SHARE_TYPE_GROUP) {
$isGroupShare = true;
$users = \OC_Group::usersInGroup($shareWith['group']);
// remove current user from list
if (in_array(\OCP\User::getUser(), $users)) {
unset($users[array_search(\OCP\User::getUser(), $users)]);
}
$groupItemTarget = Helper::generateTarget($itemType, $itemSource, $shareType, $shareWith['group'], $uidOwner, $suggestedItemTarget);
$groupFileTarget = $filePath;
// add group share to table and remember the id as parent
$queriesToExecute['groupShare'] = array('itemType' => $itemType, 'itemSource' => $itemSource, 'itemTarget' => $groupItemTarget, 'shareType' => $shareType, 'shareWith' => $shareWith['group'], 'uidOwner' => $uidOwner, 'permissions' => $permissions, 'shareTime' => time(), 'fileSource' => $fileSource, 'fileTarget' => $filePath, 'token' => $token, 'parent' => $parent, 'expiration' => $expirationDate);
} else {
$users = array($shareWith);
$itemTarget = Helper::generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $suggestedItemTarget);
}
$run = true;
$error = '';
$preHookData = array('itemType' => $itemType, 'itemSource' => $itemSource, 'shareType' => $shareType, 'uidOwner' => $uidOwner, 'permissions' => $permissions, 'fileSource' => $fileSource, 'expiration' => $expirationDate, 'token' => $token, 'run' => &$run, 'error' => &$error);
$preHookData['itemTarget'] = $isGroupShare ? $groupItemTarget : $itemTarget;
$preHookData['shareWith'] = $isGroupShare ? $shareWith['group'] : $shareWith;
\OC_Hook::emit('OCP\\Share', 'pre_shared', $preHookData);
if ($run === false) {
throw new \Exception($error);
}
foreach ($users as $user) {
$sourceId = $itemType === 'file' || $itemType === 'folder' ? $fileSource : $itemSource;
$sourceExists = self::getItemSharedWithBySource($itemType, $sourceId, self::FORMAT_NONE, null, true, $user);
$shareType = $isGroupShare ? self::$shareTypeGroupUserUnique : $shareType;
if ($sourceExists) {
$fileTarget = $sourceExists['file_target'];
$itemTarget = $sourceExists['item_target'];
// for group shares we don't need a additional entry if the target is the same
if ($isGroupShare && $groupItemTarget === $itemTarget) {
continue;
}
} elseif (!$sourceExists && !$isGroupShare) {
$itemTarget = Helper::generateTarget($itemType, $itemSource, $shareType, $user, $uidOwner, $suggestedItemTarget, $parent);
if (isset($fileSource)) {
if ($parentFolder) {
if ($parentFolder === true) {
$fileTarget = Helper::generateTarget('file', $filePath, $shareType, $user, $uidOwner, $suggestedFileTarget, $parent);
if ($fileTarget != $groupFileTarget) {
$parentFolders[$user]['folder'] = $fileTarget;
}
} else {
if (isset($parentFolder[$user])) {
$fileTarget = $parentFolder[$user]['folder'] . $itemSource;
$parent = $parentFolder[$user]['id'];
}
}
} else {
$fileTarget = Helper::generateTarget('file', $filePath, $shareType, $user, $uidOwner, $suggestedFileTarget, $parent);
}
} else {
$fileTarget = null;
}
} else {
// group share which doesn't exists until now, check if we need a unique target for this user
$itemTarget = Helper::generateTarget($itemType, $itemSource, self::SHARE_TYPE_USER, $user, $uidOwner, $suggestedItemTarget, $parent);
// do we also need a file target
if (isset($fileSource)) {
$fileTarget = Helper::generateTarget('file', $filePath, self::SHARE_TYPE_USER, $user, $uidOwner, $suggestedFileTarget, $parent);
} else {
$fileTarget = null;
}
if ($itemTarget === $groupItemTarget && (isset($fileSource) && $fileTarget === $groupItemTarget)) {
continue;
}
}
$queriesToExecute[] = array('itemType' => $itemType, 'itemSource' => $itemSource, 'itemTarget' => $itemTarget, 'shareType' => $shareType, 'shareWith' => $user, 'uidOwner' => $uidOwner, 'permissions' => $permissions, 'shareTime' => time(), 'fileSource' => $fileSource, 'fileTarget' => $fileTarget, 'token' => $token, 'parent' => $parent, 'expiration' => $expirationDate);
//.........这里部分代码省略.........