File manager - Edit - /home/jardides/www/Jardi-design/images/administrator/Activity.tar
Back
Event.php 0000604 00000027745 15247131570 0006356 0 ustar 00 <?php /** * @copyright Copyright (c) 2016, ownCloud, Inc. * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> * * @author Joas Schilling <coding@schilljs.com> * @author Phil Davis <phil.davis@inf.org> * * @license AGPL-3.0 * * This code is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License, version 3, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License, version 3, * along with this program. If not, see <http://www.gnu.org/licenses/> * */ namespace OC\Activity; use OCP\Activity\IEvent; use OCP\RichObjectStrings\InvalidObjectExeption; use OCP\RichObjectStrings\IValidator; class Event implements IEvent { /** @var string */ protected $app = ''; /** @var string */ protected $type = ''; /** @var string */ protected $affectedUser = ''; /** @var string */ protected $author = ''; /** @var int */ protected $timestamp = 0; /** @var string */ protected $subject = ''; /** @var array */ protected $subjectParameters = []; /** @var string */ protected $subjectParsed; /** @var string */ protected $subjectRich; /** @var array */ protected $subjectRichParameters; /** @var string */ protected $message = ''; /** @var array */ protected $messageParameters = []; /** @var string */ protected $messageParsed; /** @var string */ protected $messageRich; /** @var array */ protected $messageRichParameters; /** @var string */ protected $objectType = ''; /** @var int */ protected $objectId = 0; /** @var string */ protected $objectName = ''; /** @var string */ protected $link = ''; /** @var string */ protected $icon = ''; /** @var IEvent */ protected $child = null; /** @var IValidator */ protected $richValidator; /** * @param IValidator $richValidator */ public function __construct(IValidator $richValidator) { $this->richValidator = $richValidator; } /** * Set the app of the activity * * @param string $app * @return IEvent * @throws \InvalidArgumentException if the app id is invalid * @since 8.2.0 */ public function setApp($app) { if (!is_string($app) || $app === '' || isset($app[32])) { throw new \InvalidArgumentException('The given app is invalid'); } $this->app = (string) $app; return $this; } /** * @return string */ public function getApp() { return $this->app; } /** * Set the type of the activity * * @param string $type * @return IEvent * @throws \InvalidArgumentException if the type is invalid * @since 8.2.0 */ public function setType($type) { if (!is_string($type) || $type === '' || isset($type[255])) { throw new \InvalidArgumentException('The given type is invalid'); } $this->type = (string) $type; return $this; } /** * @return string */ public function getType() { return $this->type; } /** * Set the affected user of the activity * * @param string $affectedUser * @return IEvent * @throws \InvalidArgumentException if the affected user is invalid * @since 8.2.0 */ public function setAffectedUser($affectedUser) { if (!is_string($affectedUser) || $affectedUser === '' || isset($affectedUser[64])) { throw new \InvalidArgumentException('The given affected user is invalid'); } $this->affectedUser = (string) $affectedUser; return $this; } /** * @return string */ public function getAffectedUser() { return $this->affectedUser; } /** * Set the author of the activity * * @param string $author * @return IEvent * @throws \InvalidArgumentException if the author is invalid * @since 8.2.0 */ public function setAuthor($author) { if (!is_string($author) || isset($author[64])) { throw new \InvalidArgumentException('The given author user is invalid'. serialize($author)); } $this->author = (string) $author; return $this; } /** * @return string */ public function getAuthor() { return $this->author; } /** * Set the timestamp of the activity * * @param int $timestamp * @return IEvent * @throws \InvalidArgumentException if the timestamp is invalid * @since 8.2.0 */ public function setTimestamp($timestamp) { if (!is_int($timestamp)) { throw new \InvalidArgumentException('The given timestamp is invalid'); } $this->timestamp = (int) $timestamp; return $this; } /** * @return int */ public function getTimestamp() { return $this->timestamp; } /** * Set the subject of the activity * * @param string $subject * @param array $parameters * @return IEvent * @throws \InvalidArgumentException if the subject or parameters are invalid * @since 8.2.0 */ public function setSubject($subject, array $parameters = []) { if (!is_string($subject) || isset($subject[255])) { throw new \InvalidArgumentException('The given subject is invalid'); } $this->subject = (string) $subject; $this->subjectParameters = $parameters; return $this; } /** * @return string */ public function getSubject() { return $this->subject; } /** * @return array */ public function getSubjectParameters() { return $this->subjectParameters; } /** * @param string $subject * @return $this * @throws \InvalidArgumentException if the subject is invalid * @since 11.0.0 */ public function setParsedSubject($subject) { if (!is_string($subject) || $subject === '') { throw new \InvalidArgumentException('The given parsed subject is invalid'); } $this->subjectParsed = $subject; return $this; } /** * @return string * @since 11.0.0 */ public function getParsedSubject() { return $this->subjectParsed; } /** * @param string $subject * @param array $parameters * @return $this * @throws \InvalidArgumentException if the subject or parameters are invalid * @since 11.0.0 */ public function setRichSubject($subject, array $parameters = []) { if (!is_string($subject) || $subject === '') { throw new \InvalidArgumentException('The given parsed subject is invalid'); } $this->subjectRich = $subject; if (!is_array($parameters)) { throw new \InvalidArgumentException('The given subject parameters are invalid'); } $this->subjectRichParameters = $parameters; return $this; } /** * @return string * @since 11.0.0 */ public function getRichSubject() { return $this->subjectRich; } /** * @return array[] * @since 11.0.0 */ public function getRichSubjectParameters() { return $this->subjectRichParameters; } /** * Set the message of the activity * * @param string $message * @param array $parameters * @return IEvent * @throws \InvalidArgumentException if the message or parameters are invalid * @since 8.2.0 */ public function setMessage($message, array $parameters = []) { if (!is_string($message) || isset($message[255])) { throw new \InvalidArgumentException('The given message is invalid'); } $this->message = (string) $message; $this->messageParameters = $parameters; return $this; } /** * @return string */ public function getMessage() { return $this->message; } /** * @return array */ public function getMessageParameters() { return $this->messageParameters; } /** * @param string $message * @return $this * @throws \InvalidArgumentException if the message is invalid * @since 11.0.0 */ public function setParsedMessage($message) { if (!is_string($message)) { throw new \InvalidArgumentException('The given parsed message is invalid'); } $this->messageParsed = $message; return $this; } /** * @return string * @since 11.0.0 */ public function getParsedMessage() { return $this->messageParsed; } /** * @param string $message * @param array $parameters * @return $this * @throws \InvalidArgumentException if the subject or parameters are invalid * @since 11.0.0 */ public function setRichMessage($message, array $parameters = []) { if (!is_string($message)) { throw new \InvalidArgumentException('The given parsed message is invalid'); } $this->messageRich = $message; if (!is_array($parameters)) { throw new \InvalidArgumentException('The given message parameters are invalid'); } $this->messageRichParameters = $parameters; return $this; } /** * @return string * @since 11.0.0 */ public function getRichMessage() { return $this->messageRich; } /** * @return array[] * @since 11.0.0 */ public function getRichMessageParameters() { return $this->messageRichParameters; } /** * Set the object of the activity * * @param string $objectType * @param int $objectId * @param string $objectName * @return IEvent * @throws \InvalidArgumentException if the object is invalid * @since 8.2.0 */ public function setObject($objectType, $objectId, $objectName = '') { if (!is_string($objectType) || isset($objectType[255])) { throw new \InvalidArgumentException('The given object type is invalid'); } if (!is_int($objectId)) { throw new \InvalidArgumentException('The given object id is invalid'); } if (!is_string($objectName) || isset($objectName[4000])) { throw new \InvalidArgumentException('The given object name is invalid'); } $this->objectType = (string) $objectType; $this->objectId = (int) $objectId; $this->objectName = (string) $objectName; return $this; } /** * @return string */ public function getObjectType() { return $this->objectType; } /** * @return string */ public function getObjectId() { return $this->objectId; } /** * @return string */ public function getObjectName() { return $this->objectName; } /** * Set the link of the activity * * @param string $link * @return IEvent * @throws \InvalidArgumentException if the link is invalid * @since 8.2.0 */ public function setLink($link) { if (!is_string($link) || isset($link[4000])) { throw new \InvalidArgumentException('The given link is invalid'); } $this->link = (string) $link; return $this; } /** * @return string */ public function getLink() { return $this->link; } /** * @param string $icon * @return $this * @throws \InvalidArgumentException if the icon is invalid * @since 11.0.0 */ public function setIcon($icon) { if (!is_string($icon) || isset($icon[4000])) { throw new \InvalidArgumentException('The given icon is invalid'); } $this->icon = $icon; return $this; } /** * @return string * @since 11.0.0 */ public function getIcon() { return $this->icon; } /** * @param IEvent $child * @since 11.0.0 */ public function setChildEvent(IEvent $child) { $this->child = $child; } /** * @return IEvent|null * @since 11.0.0 */ public function getChildEvent() { return $this->child; } /** * @return bool * @since 8.2.0 */ public function isValid() { return $this->isValidCommon() && $this->getSubject() !== '' ; } /** * @return bool * @since 8.2.0 */ public function isValidParsed() { if ($this->getRichSubject() !== '' || !empty($this->getRichSubjectParameters())) { try { $this->richValidator->validate($this->getRichSubject(), $this->getRichSubjectParameters()); } catch (InvalidObjectExeption $e) { return false; } } if ($this->getRichMessage() !== '' || !empty($this->getRichMessageParameters())) { try { $this->richValidator->validate($this->getRichMessage(), $this->getRichMessageParameters()); } catch (InvalidObjectExeption $e) { return false; } } return $this->isValidCommon() && $this->getParsedSubject() !== '' ; } /** * @return bool */ protected function isValidCommon() { return $this->getApp() !== '' && $this->getType() !== '' && $this->getAffectedUser() !== '' && $this->getTimestamp() !== 0 /** * Disabled for BC with old activities && $this->getObjectType() !== '' && $this->getObjectId() !== 0 */ ; } } LegacySetting.php 0000604 00000006113 15247131570 0010021 0 ustar 00 <?php /** * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ namespace OC\Activity; use OCP\Activity\ISetting; class LegacySetting implements ISetting { /** @var string */ protected $identifier; /** @var string */ protected $name; /** @var bool */ protected $canChangeStream; /** @var bool */ protected $isDefaultEnabledStream; /** @var bool */ protected $canChangeMail; /** @var bool */ protected $isDefaultEnabledMail; /** * LegacySetting constructor. * * @param string $identifier * @param string $name * @param bool $canChangeStream * @param bool $isDefaultEnabledStream * @param bool $canChangeMail * @param bool $isDefaultEnabledMail */ public function __construct($identifier, $name, $canChangeStream, $isDefaultEnabledStream, $canChangeMail, $isDefaultEnabledMail) { $this->identifier = $identifier; $this->name = $name; $this->canChangeStream = $canChangeStream; $this->isDefaultEnabledStream = $isDefaultEnabledStream; $this->canChangeMail = $canChangeMail; $this->isDefaultEnabledMail = $isDefaultEnabledMail; } /** * @return string Lowercase a-z and underscore only identifier * @since 11.0.0 */ public function getIdentifier() { return $this->identifier; } /** * @return string A translated string * @since 11.0.0 */ public function getName() { return $this->name; } /** * @return int whether the filter should be rather on the top or bottom of * the admin section. The filters are arranged in ascending order of the * priority values. It is required to return a value between 0 and 100. * @since 11.0.0 */ public function getPriority() { return 70; } /** * @return bool True when the option can be changed for the stream * @since 11.0.0 */ public function canChangeStream() { return $this->canChangeStream; } /** * @return bool True when the option can be changed for the stream * @since 11.0.0 */ public function isDefaultEnabledStream() { return $this->isDefaultEnabledStream; } /** * @return bool True when the option can be changed for the mail * @since 11.0.0 */ public function canChangeMail() { return $this->canChangeMail; } /** * @return bool True when the option can be changed for the stream * @since 11.0.0 */ public function isDefaultEnabledMail() { return $this->isDefaultEnabledMail; } } Manager.php 0000604 00000044164 15247131570 0006641 0 ustar 00 <?php /** * @copyright Copyright (c) 2016, ownCloud, Inc. * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> * * @author Björn Schießle <bjoern@schiessle.org> * @author Joas Schilling <coding@schilljs.com> * @author Thomas Müller <thomas.mueller@tmit.eu> * * @license AGPL-3.0 * * This code is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License, version 3, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License, version 3, * along with this program. If not, see <http://www.gnu.org/licenses/> * */ namespace OC\Activity; use OCP\Activity\IConsumer; use OCP\Activity\IEvent; use OCP\Activity\IExtension; use OCP\Activity\IFilter; use OCP\Activity\IManager; use OCP\Activity\IProvider; use OCP\Activity\ISetting; use OCP\IConfig; use OCP\IRequest; use OCP\IUser; use OCP\IUserSession; use OCP\RichObjectStrings\IValidator; class Manager implements IManager { /** @var IRequest */ protected $request; /** @var IUserSession */ protected $session; /** @var IConfig */ protected $config; /** @var IValidator */ protected $validator; /** @var string */ protected $formattingObjectType; /** @var int */ protected $formattingObjectId; /** @var bool */ protected $requirePNG; /** @var string */ protected $currentUserId; /** * constructor of the controller * * @param IRequest $request * @param IUserSession $session * @param IConfig $config * @param IValidator $validator */ public function __construct(IRequest $request, IUserSession $session, IConfig $config, IValidator $validator) { $this->request = $request; $this->session = $session; $this->config = $config; $this->validator = $validator; } /** @var \Closure[] */ private $consumersClosures = array(); /** @var IConsumer[] */ private $consumers = array(); /** @var \Closure[] */ private $extensionsClosures = array(); /** @var IExtension[] */ private $extensions = array(); /** @var array list of filters "name" => "is valid" */ protected $validFilters = array( 'all' => true, 'by' => true, 'self' => true, ); /** @var array list of type icons "type" => "css class" */ protected $typeIcons = array(); /** @var array list of special parameters "app" => ["text" => ["parameter" => "type"]] */ protected $specialParameters = array(); /** * @return \OCP\Activity\IConsumer[] */ protected function getConsumers() { if (!empty($this->consumers)) { return $this->consumers; } $this->consumers = []; foreach($this->consumersClosures as $consumer) { $c = $consumer(); if ($c instanceof IConsumer) { $this->consumers[] = $c; } else { throw new \InvalidArgumentException('The given consumer does not implement the \OCP\Activity\IConsumer interface'); } } return $this->consumers; } /** * @return \OCP\Activity\IExtension[] */ protected function getExtensions() { if (!empty($this->extensions)) { return $this->extensions; } $this->extensions = []; foreach($this->extensionsClosures as $extension) { $e = $extension(); if ($e instanceof IExtension) { $this->extensions[] = $e; } else { throw new \InvalidArgumentException('The given extension does not implement the \OCP\Activity\IExtension interface'); } } return $this->extensions; } /** * Generates a new IEvent object * * Make sure to call at least the following methods before sending it to the * app with via the publish() method: * - setApp() * - setType() * - setAffectedUser() * - setSubject() * * @return IEvent */ public function generateEvent() { return new Event($this->validator); } /** * Publish an event to the activity consumers * * Make sure to call at least the following methods before sending an Event: * - setApp() * - setType() * - setAffectedUser() * - setSubject() * * @param IEvent $event * @throws \BadMethodCallException if required values have not been set */ public function publish(IEvent $event) { if ($event->getAuthor() === '') { if ($this->session->getUser() instanceof IUser) { $event->setAuthor($this->session->getUser()->getUID()); } } if (!$event->getTimestamp()) { $event->setTimestamp(time()); } if (!$event->isValid()) { throw new \BadMethodCallException('The given event is invalid'); } foreach ($this->getConsumers() as $c) { $c->receive($event); } } /** * @param string $app The app where this event is associated with * @param string $subject A short description of the event * @param array $subjectParams Array with parameters that are filled in the subject * @param string $message A longer description of the event * @param array $messageParams Array with parameters that are filled in the message * @param string $file The file including path where this event is associated with * @param string $link A link where this event is associated with * @param string $affectedUser Recipient of the activity * @param string $type Type of the notification * @param int $priority Priority of the notification */ public function publishActivity($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority) { $event = $this->generateEvent(); $event->setApp($app) ->setType($type) ->setAffectedUser($affectedUser) ->setSubject($subject, $subjectParams) ->setMessage($message, $messageParams) ->setObject('', 0, $file) ->setLink($link); $this->publish($event); } /** * In order to improve lazy loading a closure can be registered which will be called in case * activity consumers are actually requested * * $callable has to return an instance of OCA\Activity\IConsumer * * @param \Closure $callable */ public function registerConsumer(\Closure $callable) { array_push($this->consumersClosures, $callable); $this->consumers = []; } /** * In order to improve lazy loading a closure can be registered which will be called in case * activity consumers are actually requested * * $callable has to return an instance of OCA\Activity\IExtension * * @param \Closure $callable */ public function registerExtension(\Closure $callable) { array_push($this->extensionsClosures, $callable); $this->extensions = []; } /** @var string[] */ protected $filterClasses = []; /** @var IFilter[] */ protected $filters = []; /** @var bool */ protected $loadedLegacyFilters = false; /** * @param string $filter Class must implement OCA\Activity\IFilter * @return void */ public function registerFilter($filter) { $this->filterClasses[$filter] = false; } /** * @return IFilter[] * @throws \InvalidArgumentException */ public function getFilters() { if (!$this->loadedLegacyFilters) { $legacyFilters = $this->getNavigation(); foreach ($legacyFilters['top'] as $filter => $data) { $this->filters[$filter] = new LegacyFilter( $this, $filter, $data['name'], true ); } foreach ($legacyFilters['apps'] as $filter => $data) { $this->filters[$filter] = new LegacyFilter( $this, $filter, $data['name'], false ); } $this->loadedLegacyFilters = true; } foreach ($this->filterClasses as $class => $false) { /** @var IFilter $filter */ $filter = \OC::$server->query($class); if (!$filter instanceof IFilter) { throw new \InvalidArgumentException('Invalid activity filter registered'); } $this->filters[$filter->getIdentifier()] = $filter; unset($this->filterClasses[$class]); } return $this->filters; } /** * @param string $id * @return IFilter * @throws \InvalidArgumentException when the filter was not found * @since 11.0.0 */ public function getFilterById($id) { $filters = $this->getFilters(); if (isset($filters[$id])) { return $filters[$id]; } throw new \InvalidArgumentException('Requested filter does not exist'); } /** @var string[] */ protected $providerClasses = []; /** @var IProvider[] */ protected $providers = []; /** * @param string $provider Class must implement OCA\Activity\IProvider * @return void */ public function registerProvider($provider) { $this->providerClasses[$provider] = false; } /** * @return IProvider[] * @throws \InvalidArgumentException */ public function getProviders() { foreach ($this->providerClasses as $class => $false) { /** @var IProvider $provider */ $provider = \OC::$server->query($class); if (!$provider instanceof IProvider) { throw new \InvalidArgumentException('Invalid activity provider registered'); } $this->providers[] = $provider; unset($this->providerClasses[$class]); } return $this->providers; } /** @var string[] */ protected $settingsClasses = []; /** @var ISetting[] */ protected $settings = []; /** @var bool */ protected $loadedLegacyTypes = false; /** * @param string $setting Class must implement OCA\Activity\ISetting * @return void */ public function registerSetting($setting) { $this->settingsClasses[$setting] = false; } /** * @return ISetting[] * @throws \InvalidArgumentException */ public function getSettings() { if (!$this->loadedLegacyTypes) { $l = \OC::$server->getL10N('core'); $legacyTypes = $this->getNotificationTypes($l->getLanguageCode()); $streamTypes = $this->getDefaultTypes(IExtension::METHOD_STREAM); $mailTypes = $this->getDefaultTypes(IExtension::METHOD_MAIL); foreach ($legacyTypes as $type => $data) { if (is_string($data)) { $desc = $data; $canChangeStream = true; $canChangeMail = true; } else { $desc = $data['desc']; $canChangeStream = in_array(IExtension::METHOD_STREAM, $data['methods']); $canChangeMail = in_array(IExtension::METHOD_MAIL, $data['methods']); } $this->settings[$type] = new LegacySetting( $type, $desc, $canChangeStream, in_array($type, $streamTypes), $canChangeMail, in_array($type, $mailTypes) ); } $this->loadedLegacyTypes = true; } foreach ($this->settingsClasses as $class => $false) { /** @var ISetting $setting */ $setting = \OC::$server->query($class); if (!$setting instanceof ISetting) { throw new \InvalidArgumentException('Invalid activity filter registered'); } $this->settings[$setting->getIdentifier()] = $setting; unset($this->settingsClasses[$class]); } return $this->settings; } /** * @param string $id * @return ISetting * @throws \InvalidArgumentException when the setting was not found * @since 11.0.0 */ public function getSettingById($id) { $settings = $this->getSettings(); if (isset($settings[$id])) { return $settings[$id]; } throw new \InvalidArgumentException('Requested setting does not exist'); } /** * @param string $type * @return string */ public function getTypeIcon($type) { if (isset($this->typeIcons[$type])) { return $this->typeIcons[$type]; } foreach ($this->getExtensions() as $c) { $icon = $c->getTypeIcon($type); if (is_string($icon)) { $this->typeIcons[$type] = $icon; return $icon; } } $this->typeIcons[$type] = ''; return ''; } /** * @param string $type * @param string $id */ public function setFormattingObject($type, $id) { $this->formattingObjectType = $type; $this->formattingObjectId = (string) $id; } /** * @return bool */ public function isFormattingFilteredObject() { return $this->formattingObjectType !== null && $this->formattingObjectId !== null && $this->formattingObjectType === $this->request->getParam('object_type') && $this->formattingObjectId === $this->request->getParam('object_id'); } /** * @param bool $status Set to true, when parsing events should not use SVG icons */ public function setRequirePNG($status) { $this->requirePNG = $status; } /** * @return bool */ public function getRequirePNG() { return $this->requirePNG; } /** * @param string $app * @param string $text * @param array $params * @param boolean $stripPath * @param boolean $highlightParams * @param string $languageCode * @return string|false */ public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) { foreach ($this->getExtensions() as $c) { $translation = $c->translate($app, $text, $params, $stripPath, $highlightParams, $languageCode); if (is_string($translation)) { return $translation; } } return false; } /** * @param string $app * @param string $text * @return array|false */ public function getSpecialParameterList($app, $text) { if (isset($this->specialParameters[$app][$text])) { return $this->specialParameters[$app][$text]; } if (!isset($this->specialParameters[$app])) { $this->specialParameters[$app] = array(); } foreach ($this->getExtensions() as $c) { $specialParameter = $c->getSpecialParameterList($app, $text); if (is_array($specialParameter)) { $this->specialParameters[$app][$text] = $specialParameter; return $specialParameter; } } $this->specialParameters[$app][$text] = false; return false; } /** * @param array $activity * @return integer|false */ public function getGroupParameter($activity) { foreach ($this->getExtensions() as $c) { $parameter = $c->getGroupParameter($activity); if ($parameter !== false) { return $parameter; } } return false; } /** * Set the user we need to use * * @param string|null $currentUserId * @throws \UnexpectedValueException If the user is invalid */ public function setCurrentUserId($currentUserId) { if (!is_string($currentUserId) && $currentUserId !== null) { throw new \UnexpectedValueException('The given current user is invalid'); } $this->currentUserId = $currentUserId; } /** * Get the user we need to use * * Either the user is logged in, or we try to get it from the token * * @return string * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique */ public function getCurrentUserId() { if ($this->currentUserId !== null) { return $this->currentUserId; } else if (!$this->session->isLoggedIn()) { return $this->getUserFromToken(); } else { return $this->session->getUser()->getUID(); } } /** * Get the user for the token * * @return string * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique */ protected function getUserFromToken() { $token = (string) $this->request->getParam('token', ''); if (strlen($token) !== 30) { throw new \UnexpectedValueException('The token is invalid'); } $users = $this->config->getUsersForUserValue('activity', 'rsstoken', $token); if (sizeof($users) !== 1) { // No unique user found throw new \UnexpectedValueException('The token is invalid'); } // Token found login as that user return array_shift($users); } /** * @return array * @deprecated 11.0.0 - Use getFilters() instead */ public function getNavigation() { $entries = array( 'apps' => array(), 'top' => array(), ); foreach ($this->getExtensions() as $c) { $additionalEntries = $c->getNavigation(); if (is_array($additionalEntries)) { $entries['apps'] = array_merge($entries['apps'], $additionalEntries['apps']); $entries['top'] = array_merge($entries['top'], $additionalEntries['top']); } } return $entries; } /** * @param string $filterValue * @return boolean * @deprecated 11.0.0 - Use getFilterById() instead */ public function isFilterValid($filterValue) { if (isset($this->validFilters[$filterValue])) { return $this->validFilters[$filterValue]; } foreach ($this->getExtensions() as $c) { if ($c->isFilterValid($filterValue) === true) { $this->validFilters[$filterValue] = true; return true; } } $this->validFilters[$filterValue] = false; return false; } /** * @param array $types * @param string $filter * @return array * @deprecated 11.0.0 - Use getFilterById()->filterTypes() instead */ public function filterNotificationTypes($types, $filter) { if (!$this->isFilterValid($filter)) { return $types; } foreach ($this->getExtensions() as $c) { $result = $c->filterNotificationTypes($types, $filter); if (is_array($result)) { $types = $result; } } return $types; } /** * @param string $filter * @return array * @deprecated 11.0.0 - Use getFilterById() instead */ public function getQueryForFilter($filter) { if (!$this->isFilterValid($filter)) { return [null, null]; } $conditions = array(); $parameters = array(); foreach ($this->getExtensions() as $c) { $result = $c->getQueryForFilter($filter); if (is_array($result)) { list($condition, $parameter) = $result; if ($condition && is_array($parameter)) { $conditions[] = $condition; $parameters = array_merge($parameters, $parameter); } } } if (empty($conditions)) { return array(null, null); } return array(' and ((' . implode(') or (', $conditions) . '))', $parameters); } /** * Will return additional notification types as specified by other apps * * @param string $languageCode * @return array * @deprecated 11.0.0 - Use getSettings() instead */ public function getNotificationTypes($languageCode) { $notificationTypes = $sharingNotificationTypes = []; foreach ($this->getExtensions() as $c) { $result = $c->getNotificationTypes($languageCode); if (is_array($result)) { $notificationTypes = array_merge($notificationTypes, $result); } } return array_merge($sharingNotificationTypes, $notificationTypes); } /** * @param string $method * @return array * @deprecated 11.0.0 - Use getSettings()->isDefaulEnabled<method>() instead */ public function getDefaultTypes($method) { $defaultTypes = array(); foreach ($this->getExtensions() as $c) { $types = $c->getDefaultTypes($method); if (is_array($types)) { $defaultTypes = array_merge($types, $defaultTypes); } } return $defaultTypes; } } EventMerger.php 0000604 00000016712 15247131570 0007510 0 ustar 00 <?php /** * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ namespace OC\Activity; use OCP\Activity\IEvent; use OCP\Activity\IEventMerger; use OCP\IL10N; class EventMerger implements IEventMerger { /** @var IL10N */ protected $l10n; /** * @param IL10N $l10n */ public function __construct(IL10N $l10n) { $this->l10n = $l10n; } /** * Combines two events when possible to have grouping: * * Example1: Two events with subject '{user} created {file}' and * $mergeParameter file with different file and same user will be merged * to '{user} created {file1} and {file2}' and the childEvent on the return * will be set, if the events have been merged. * * Example2: Two events with subject '{user} created {file}' and * $mergeParameter file with same file and same user will be merged to * '{user} created {file1}' and the childEvent on the return will be set, if * the events have been merged. * * The following requirements have to be met, in order to be merged: * - Both events need to have the same `getApp()` * - Both events must not have a message `getMessage()` * - Both events need to have the same subject `getSubject()` * - Both events need to have the same object type `getObjectType()` * - The time difference between both events must not be bigger then 3 hours * - Only up to 5 events can be merged. * - All parameters apart from such starting with $mergeParameter must be * the same for both events. * * @param string $mergeParameter * @param IEvent $event * @param IEvent|null $previousEvent * @return IEvent */ public function mergeEvents($mergeParameter, IEvent $event, IEvent $previousEvent = null) { // No second event => can not combine if (!$previousEvent instanceof IEvent) { return $event; } // Different app => can not combine if ($event->getApp() !== $previousEvent->getApp()) { return $event; } // Message is set => can not combine if ($event->getMessage() !== '' || $previousEvent->getMessage() !== '') { return $event; } // Different subject => can not combine if ($event->getSubject() !== $previousEvent->getSubject()) { return $event; } // Different object type => can not combine if ($event->getObjectType() !== $previousEvent->getObjectType()) { return $event; } // More than 3 hours difference => can not combine if (abs($event->getTimestamp() - $previousEvent->getTimestamp()) > 3 * 60 * 60) { return $event; } // Other parameters are not the same => can not combine try { list($combined, $parameters) = $this->combineParameters($mergeParameter, $event, $previousEvent); } catch (\UnexpectedValueException $e) { return $event; } try { $newSubject = $this->getExtendedSubject($event->getRichSubject(), $mergeParameter, $combined); $parsedSubject = $this->generateParsedSubject($newSubject, $parameters); $event->setRichSubject($newSubject, $parameters) ->setParsedSubject($parsedSubject) ->setChildEvent($previousEvent); } catch (\UnexpectedValueException $e) { return $event; } return $event; } /** * @param string $mergeParameter * @param IEvent $event * @param IEvent $previousEvent * @return array * @throws \UnexpectedValueException */ protected function combineParameters($mergeParameter, IEvent $event, IEvent $previousEvent) { $params1 = $event->getRichSubjectParameters(); $params2 = $previousEvent->getRichSubjectParameters(); $params = []; $combined = 0; // Check that all parameters from $event exist in $previousEvent foreach ($params1 as $key => $parameter) { if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { $combined++; $params[$mergeParameter . $combined] = $parameter; } continue; } if (!isset($params2[$key]) || $params2[$key] !== $parameter) { // Parameter missing on $previousEvent or different => can not combine throw new \UnexpectedValueException(); } $params[$key] = $parameter; } // Check that all parameters from $previousEvent exist in $event foreach ($params2 as $key => $parameter) { if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { $combined++; $params[$mergeParameter . $combined] = $parameter; } continue; } if (!isset($params1[$key]) || $params1[$key] !== $parameter) { // Parameter missing on $event or different => can not combine throw new \UnexpectedValueException(); } $params[$key] = $parameter; } return [$combined, $params]; } /** * @param array[] $parameters * @param string $mergeParameter * @param array $parameter * @return bool */ protected function checkParameterAlreadyExits($parameters, $mergeParameter, $parameter) { foreach ($parameters as $key => $param) { if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { if ($param === $parameter) { return true; } } } return false; } /** * @param string $subject * @param string $parameter * @param int $counter * @return mixed */ protected function getExtendedSubject($subject, $parameter, $counter) { switch ($counter) { case 1: $replacement = '{' . $parameter . '1}'; break; case 2: $replacement = $this->l10n->t( '%1$s and %2$s', ['{' . $parameter . '2}', '{' . $parameter . '1}'] ); break; case 3: $replacement = $this->l10n->t( '%1$s, %2$s and %3$s', ['{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] ); break; case 4: $replacement = $this->l10n->t( '%1$s, %2$s, %3$s and %4$s', ['{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] ); break; case 5: $replacement = $this->l10n->t( '%1$s, %2$s, %3$s, %4$s and %5$s', ['{' . $parameter . '5}', '{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] ); break; default: throw new \UnexpectedValueException(); } return str_replace( '{' . $parameter . '}', $replacement, $subject ); } /** * @param string $subject * @param array[] $parameters * @return string */ protected function generateParsedSubject($subject, $parameters) { $placeholders = $replacements = []; foreach ($parameters as $placeholder => $parameter) { $placeholders[] = '{' . $placeholder . '}'; if ($parameter['type'] === 'file') { $replacements[] = trim($parameter['path'], '/'); } else if (isset($parameter['name'])) { $replacements[] = $parameter['name']; } else { $replacements[] = $parameter['id']; } } return str_replace($placeholders, $replacements, $subject); } } LegacyFilter.php 0000604 00000005270 15247131570 0007634 0 ustar 00 <?php /** * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com> * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ namespace OC\Activity; use OCP\Activity\IFilter; use OCP\Activity\IManager; class LegacyFilter implements IFilter { /** @var IManager */ protected $manager; /** @var string */ protected $identifier; /** @var string */ protected $name; /** @var bool */ protected $isTopFilter; /** * LegacySetting constructor. * * @param IManager $manager * @param string $identifier * @param string $name * @param bool $isTopFilter */ public function __construct(IManager $manager, $identifier, $name, $isTopFilter) { $this->manager = $manager; $this->identifier = $identifier; $this->name = $name; $this->isTopFilter = $isTopFilter; } /** * @return string Lowercase a-z and underscore only identifier * @since 11.0.0 */ public function getIdentifier() { return $this->identifier; } /** * @return string A translated string * @since 11.0.0 */ public function getName() { return $this->name; } /** * @return int whether the filter should be rather on the top or bottom of * the admin section. The filters are arranged in ascending order of the * priority values. It is required to return a value between 0 and 100. * @since 11.0.0 */ public function getPriority() { return $this->isTopFilter ? 40 : 50; } /** * @return string Full URL to an icon, empty string when none is given * @since 11.0.0 */ public function getIcon() { // Old API was CSS class, so we can not use this... return ''; } /** * @param string[] $types * @return string[] An array of allowed apps from which activities should be displayed * @since 11.0.0 */ public function filterTypes(array $types) { return $this->manager->filterNotificationTypes($types, $this->getIdentifier()); } /** * @return string[] An array of allowed apps from which activities should be displayed * @since 11.0.0 */ public function allowedApps() { return []; } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings