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


PHP IManager::publish方法代码示例

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


在下文中一共展示了IManager::publish方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: mapperEvent

 /**
  * @param MapperEvent $event
  */
 public function mapperEvent(MapperEvent $event)
 {
     $tagIds = $event->getTags();
     if ($event->getObjectType() !== 'files' || empty($tagIds) || !in_array($event->getEvent(), [MapperEvent::EVENT_ASSIGN, MapperEvent::EVENT_UNASSIGN]) || !$this->appManager->isInstalled('activity')) {
         // System tags not for files, no tags, not (un-)assigning or no activity-app enabled (save the energy)
         return;
     }
     try {
         $tags = $this->tagManager->getTagsByIds($tagIds);
     } catch (TagNotFoundException $e) {
         // User assigned/unassigned a non-existing tag, ignore...
         return;
     }
     if (empty($tags)) {
         return;
     }
     // Get all mount point owners
     $cache = $this->mountCollection->getMountCache();
     $mounts = $cache->getMountsForFileId($event->getObjectId());
     if (empty($mounts)) {
         return;
     }
     $users = [];
     foreach ($mounts as $mount) {
         $owner = $mount->getUser()->getUID();
         $ownerFolder = $this->rootFolder->getUserFolder($owner);
         $nodes = $ownerFolder->getById($event->getObjectId());
         if (!empty($nodes)) {
             /** @var Node $node */
             $node = array_shift($nodes);
             $path = $node->getPath();
             if (strpos($path, '/' . $owner . '/files/') === 0) {
                 $path = substr($path, strlen('/' . $owner . '/files'));
             }
             // Get all users that have access to the mount point
             $users = array_merge($users, Share::getUsersSharingFile($path, $owner, true, true));
         }
     }
     $actor = $this->session->getUser();
     if ($actor instanceof IUser) {
         $actor = $actor->getUID();
     } else {
         $actor = '';
     }
     $activity = $this->activityManager->generateEvent();
     $activity->setApp(Extension::APP_NAME)->setType(Extension::APP_NAME)->setAuthor($actor)->setObject($event->getObjectType(), $event->getObjectId());
     foreach ($users as $user => $path) {
         $activity->setAffectedUser($user);
         foreach ($tags as $tag) {
             if ($event->getEvent() === MapperEvent::EVENT_ASSIGN) {
                 $activity->setSubject(Extension::ASSIGN_TAG, [$actor, $path, $this->prepareTagAsParameter($tag)]);
             } else {
                 if ($event->getEvent() === MapperEvent::EVENT_UNASSIGN) {
                     $activity->setSubject(Extension::UNASSIGN_TAG, [$actor, $path, $this->prepareTagAsParameter($tag)]);
                 }
             }
             $this->activityManager->publish($activity);
         }
     }
 }
开发者ID:farukuzun,项目名称:core-1,代码行数:63,代码来源:listener.php

示例2: createPublicity

 /**
  * @param int $id
  * @param string $authorId
  * @param int $timeStamp
  */
 protected function createPublicity($id, $authorId, $timeStamp)
 {
     $users = $this->userManager->search('');
     $event = $this->activityManager->generateEvent();
     $event->setApp('announcementcenter')->setType('announcementcenter')->setAuthor($authorId)->setTimestamp($timeStamp)->setSubject('announcementsubject#' . $id, [$authorId])->setMessage('announcementmessage#' . $id, [$authorId])->setObject('announcement', $id);
     $dateTime = new \DateTime();
     $dateTime->setTimestamp($timeStamp);
     $notification = $this->notificationManager->createNotification();
     $notification->setApp('announcementcenter')->setDateTime($dateTime)->setObject('announcement', $id)->setSubject('announced', [$authorId])->setLink($this->urlGenerator->linkToRoute('announcementcenter.page.index'));
     foreach ($users as $user) {
         $event->setAffectedUser($user->getUID());
         $this->activityManager->publish($event);
         if ($authorId !== $user->getUID()) {
             $notification->setUser($user->getUID());
             $this->notificationManager->notify($notification);
         }
     }
 }
开发者ID:arietimmerman,项目名称:announcementcenter,代码行数:23,代码来源:pagecontroller.php

示例3: commentEvent

 /**
  * @param CommentsEvent $event
  */
 public function commentEvent(CommentsEvent $event)
 {
     if ($event->getComment()->getObjectType() !== 'files' || !in_array($event->getEvent(), [CommentsEvent::EVENT_ADD]) || !$this->appManager->isInstalled('activity')) {
         // Comment not for file, not adding a comment or no activity-app enabled (save the energy)
         return;
     }
     // Get all mount point owners
     $cache = $this->mountCollection->getMountCache();
     $mounts = $cache->getMountsForFileId($event->getComment()->getObjectId());
     if (empty($mounts)) {
         return;
     }
     $users = [];
     foreach ($mounts as $mount) {
         $owner = $mount->getUser()->getUID();
         $ownerFolder = $this->rootFolder->getUserFolder($owner);
         $nodes = $ownerFolder->getById($event->getComment()->getObjectId());
         if (!empty($nodes)) {
             /** @var Node $node */
             $node = array_shift($nodes);
             $path = $node->getPath();
             if (strpos($path, '/' . $owner . '/files/') === 0) {
                 $path = substr($path, strlen('/' . $owner . '/files'));
             }
             // Get all users that have access to the mount point
             $users = array_merge($users, Share::getUsersSharingFile($path, $owner, true, true));
         }
     }
     $actor = $this->session->getUser();
     if ($actor instanceof IUser) {
         $actor = $actor->getUID();
     } else {
         $actor = '';
     }
     $activity = $this->activityManager->generateEvent();
     $activity->setApp(Extension::APP_NAME)->setType(Extension::APP_NAME)->setAuthor($actor)->setObject($event->getComment()->getObjectType(), $event->getComment()->getObjectId())->setMessage(Extension::ADD_COMMENT_MESSAGE, [$event->getComment()->getId()]);
     foreach ($users as $user => $path) {
         $activity->setAffectedUser($user);
         $activity->setSubject(Extension::ADD_COMMENT_SUBJECT, [$actor, $path]);
         $this->activityManager->publish($activity);
     }
 }
开发者ID:GitHubUser4234,项目名称:core,代码行数:45,代码来源:Listener.php

示例4: downloadShare

 /**
  * @PublicPage
  * @NoCSRFRequired
  *
  * @param string $token
  * @param string $files
  * @param string $path
  * @param string $downloadStartSecret
  * @return void|RedirectResponse
  */
 public function downloadShare($token, $files = null, $path = '', $downloadStartSecret = '')
 {
     \OC_User::setIncognitoMode(true);
     $share = $this->shareManager->getShareByToken($token);
     // Share is password protected - check whether the user is permitted to access the share
     if ($share->getPassword() !== null && !$this->linkShareAuth($share)) {
         return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate', ['token' => $token]));
     }
     $files_list = null;
     if (!is_null($files)) {
         // download selected files
         $files_list = json_decode($files);
         // in case we get only a single file
         if ($files_list === null) {
             $files_list = [$files];
         }
     }
     $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()->getUID());
     $originalSharePath = $userFolder->getRelativePath($share->getNode()->getPath());
     // Single file share
     if ($share->getNode() instanceof \OCP\Files\File) {
         // Single file download
         $event = $this->activityManager->generateEvent();
         $event->setApp('files_sharing')->setType(Activity::TYPE_PUBLIC_LINKS)->setSubject(Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED, [$userFolder->getRelativePath($share->getNode()->getPath())])->setAffectedUser($share->getShareOwner()->getUID())->setObject('files', $share->getNode()->getId(), $userFolder->getRelativePath($share->getNode()->getPath()));
         $this->activityManager->publish($event);
     } else {
         /** @var \OCP\Files\Folder $node */
         $node = $share->getNode();
         // Try to get the path
         if ($path !== '') {
             try {
                 $node = $node->get($path);
             } catch (NotFoundException $e) {
                 return new NotFoundResponse();
             }
         }
         $originalSharePath = $userFolder->getRelativePath($node->getPath());
         if ($node instanceof \OCP\Files\File) {
             // Single file download
             $event = $this->activityManager->generateEvent();
             $event->setApp('files_sharing')->setType(Activity::TYPE_PUBLIC_LINKS)->setSubject(Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED, [$userFolder->getRelativePath($node->getPath())])->setAffectedUser($share->getShareOwner()->getUID())->setObject('files', $node->getId(), $userFolder->getRelativePath($node->getPath()));
             $this->activityManager->publish($event);
         } else {
             if (!empty($files_list)) {
                 /** @var \OCP\Files\Folder $node */
                 // Subset of files is downloaded
                 foreach ($files_list as $file) {
                     $subNode = $node->get($file);
                     $event = $this->activityManager->generateEvent();
                     $event->setApp('files_sharing')->setType(Activity::TYPE_PUBLIC_LINKS)->setAffectedUser($share->getShareOwner()->getUID())->setObject('files', $subNode->getId(), $userFolder->getRelativePath($subNode->getPath()));
                     if ($subNode instanceof \OCP\Files\File) {
                         $event->setSubject(Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED, [$userFolder->getRelativePath($subNode->getPath())]);
                     } else {
                         $event->setSubject(Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED, [$userFolder->getRelativePath($subNode->getPath())]);
                     }
                     $this->activityManager->publish($event);
                 }
             } else {
                 // The folder is downloaded
                 $event = $this->activityManager->generateEvent();
                 $event->setApp('files_sharing')->setType(Activity::TYPE_PUBLIC_LINKS)->setSubject(Activity::SUBJECT_PUBLIC_SHARED_FOLDER_DOWNLOADED, [$userFolder->getRelativePath($node->getPath())])->setAffectedUser($share->getShareOwner()->getUID())->setObject('files', $node->getId(), $userFolder->getRelativePath($node->getPath()));
                 $this->activityManager->publish($event);
             }
         }
     }
     /* FIXME: We should do this all nicely in OCP */
     OC_Util::tearDownFS();
     OC_Util::setupFS($share->getShareOwner()->getUID());
     /**
      * this sets a cookie to be able to recognize the start of the download
      * the content must not be longer than 32 characters and must only contain
      * alphanumeric characters
      */
     if (!empty($downloadStartSecret) && !isset($downloadStartSecret[32]) && preg_match('!^[a-zA-Z0-9]+$!', $downloadStartSecret) === 1) {
         // FIXME: set on the response once we use an actual app framework response
         setcookie('ocDownloadStarted', $downloadStartSecret, time() + 20, '/');
     }
     // download selected files
     if (!is_null($files)) {
         // FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well
         // after dispatching the request which results in a "Cannot modify header information" notice.
         OC_Files::get($originalSharePath, $files_list, $_SERVER['REQUEST_METHOD'] == 'HEAD');
         exit;
     } else {
         // FIXME: The exit is required here because otherwise the AppFramework is trying to add headers as well
         // after dispatching the request which results in a "Cannot modify header information" notice.
         OC_Files::get(dirname($originalSharePath), basename($originalSharePath), $_SERVER['REQUEST_METHOD'] == 'HEAD');
         exit;
     }
 }
开发者ID:Pookay,项目名称:core,代码行数:100,代码来源:sharecontroller.php


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