2013-09-29 18:31:12 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 15:07:57 +00:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
2016-11-16 11:19:42 +00:00
|
|
|
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
|
2016-07-21 15:07:57 +00:00
|
|
|
*
|
2016-05-26 17:56:05 +00:00
|
|
|
* @author Björn Schießle <bjoern@schiessle.org>
|
2016-07-21 15:07:57 +00:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2015-03-26 10:44:34 +00:00
|
|
|
* @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/>
|
2013-09-29 18:31:12 +00:00
|
|
|
*
|
|
|
|
*/
|
2016-05-02 09:57:24 +00:00
|
|
|
namespace OC\Activity;
|
2013-09-29 18:31:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
use OCP\Activity\IConsumer;
|
2015-08-19 15:37:55 +00:00
|
|
|
use OCP\Activity\IEvent;
|
2014-07-03 11:48:15 +00:00
|
|
|
use OCP\Activity\IExtension;
|
2016-10-20 15:57:44 +00:00
|
|
|
use OCP\Activity\IFilter;
|
2013-10-09 16:06:21 +00:00
|
|
|
use OCP\Activity\IManager;
|
2016-11-04 10:33:33 +00:00
|
|
|
use OCP\Activity\IProvider;
|
2016-10-25 16:00:25 +00:00
|
|
|
use OCP\Activity\ISetting;
|
2015-03-25 14:18:11 +00:00
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IRequest;
|
2015-08-19 15:37:55 +00:00
|
|
|
use OCP\IUser;
|
2015-03-25 14:18:11 +00:00
|
|
|
use OCP\IUserSession;
|
2016-11-10 14:33:00 +00:00
|
|
|
use OCP\RichObjectStrings\IValidator;
|
2013-09-29 18:31:12 +00:00
|
|
|
|
2016-05-02 09:57:24 +00:00
|
|
|
class Manager implements IManager {
|
2015-03-25 14:18:11 +00:00
|
|
|
/** @var IRequest */
|
|
|
|
protected $request;
|
|
|
|
|
|
|
|
/** @var IUserSession */
|
|
|
|
protected $session;
|
|
|
|
|
|
|
|
/** @var IConfig */
|
|
|
|
protected $config;
|
|
|
|
|
2016-11-10 14:33:00 +00:00
|
|
|
/** @var IValidator */
|
|
|
|
protected $validator;
|
|
|
|
|
2015-10-02 07:53:39 +00:00
|
|
|
/** @var string */
|
|
|
|
protected $formattingObjectType;
|
|
|
|
|
|
|
|
/** @var int */
|
|
|
|
protected $formattingObjectId;
|
|
|
|
|
2016-03-24 08:33:00 +00:00
|
|
|
/** @var string */
|
|
|
|
protected $currentUserId;
|
|
|
|
|
2015-03-25 14:18:11 +00:00
|
|
|
/**
|
|
|
|
* constructor of the controller
|
|
|
|
*
|
|
|
|
* @param IRequest $request
|
|
|
|
* @param IUserSession $session
|
|
|
|
* @param IConfig $config
|
2016-11-10 14:33:00 +00:00
|
|
|
* @param IValidator $validator
|
2015-03-25 14:18:11 +00:00
|
|
|
*/
|
|
|
|
public function __construct(IRequest $request,
|
|
|
|
IUserSession $session,
|
2016-11-10 14:33:00 +00:00
|
|
|
IConfig $config,
|
|
|
|
IValidator $validator) {
|
2015-03-25 14:18:11 +00:00
|
|
|
$this->request = $request;
|
|
|
|
$this->session = $session;
|
|
|
|
$this->config = $config;
|
2016-11-10 14:33:00 +00:00
|
|
|
$this->validator = $validator;
|
2015-03-25 14:18:11 +00:00
|
|
|
}
|
2013-09-29 18:31:12 +00:00
|
|
|
|
2015-07-23 09:00:29 +00:00
|
|
|
/** @var \Closure[] */
|
|
|
|
private $consumersClosures = array();
|
|
|
|
|
|
|
|
/** @var IConsumer[] */
|
2013-09-29 18:31:12 +00:00
|
|
|
private $consumers = array();
|
|
|
|
|
2015-07-23 09:00:29 +00:00
|
|
|
/** @var \Closure[] */
|
|
|
|
private $extensionsClosures = array();
|
|
|
|
|
|
|
|
/** @var IExtension[] */
|
2014-07-03 11:48:15 +00:00
|
|
|
private $extensions = array();
|
|
|
|
|
2015-01-23 14:37:15 +00:00
|
|
|
/** @var array list of filters "name" => "is valid" */
|
2015-02-13 10:50:55 +00:00
|
|
|
protected $validFilters = array(
|
|
|
|
'all' => true,
|
|
|
|
'by' => true,
|
|
|
|
'self' => true,
|
|
|
|
);
|
2015-01-23 14:37:15 +00:00
|
|
|
|
|
|
|
/** @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();
|
|
|
|
|
2015-07-23 09:00:29 +00:00
|
|
|
/**
|
|
|
|
* @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;
|
|
|
|
}
|
|
|
|
|
2015-08-19 15:37:55 +00:00
|
|
|
/**
|
2015-08-20 13:35:24 +00:00
|
|
|
* 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()
|
|
|
|
*
|
2015-08-19 15:37:55 +00:00
|
|
|
* @return IEvent
|
|
|
|
*/
|
|
|
|
public function generateEvent() {
|
2016-11-10 14:33:00 +00:00
|
|
|
return new Event($this->validator);
|
2015-08-19 15:37:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Publish an event to the activity consumers
|
|
|
|
*
|
2015-08-20 13:35:24 +00:00
|
|
|
* Make sure to call at least the following methods before sending an Event:
|
|
|
|
* - setApp()
|
|
|
|
* - setType()
|
|
|
|
* - setAffectedUser()
|
|
|
|
* - setSubject()
|
|
|
|
*
|
2015-08-19 15:37:55 +00:00
|
|
|
* @param IEvent $event
|
|
|
|
* @throws \BadMethodCallException if required values have not been set
|
|
|
|
*/
|
|
|
|
public function publish(IEvent $event) {
|
2016-11-10 14:33:00 +00:00
|
|
|
if ($event->getAuthor() === '') {
|
2015-08-19 15:37:55 +00:00
|
|
|
if ($this->session->getUser() instanceof IUser) {
|
|
|
|
$event->setAuthor($this->session->getUser()->getUID());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$event->getTimestamp()) {
|
|
|
|
$event->setTimestamp(time());
|
|
|
|
}
|
|
|
|
|
2016-11-11 12:44:57 +00:00
|
|
|
if (!$event->isValid()) {
|
2016-10-28 12:55:53 +00:00
|
|
|
throw new \BadMethodCallException('The given event is invalid');
|
|
|
|
}
|
|
|
|
|
2015-08-19 15:37:55 +00:00
|
|
|
foreach ($this->getConsumers() as $c) {
|
|
|
|
$c->receive($event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-29 18:31:12 +00:00
|
|
|
/**
|
2015-08-18 07:03:56 +00:00
|
|
|
* @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
|
2015-08-19 15:37:55 +00:00
|
|
|
* @param int $priority Priority of the notification
|
2013-09-29 18:31:12 +00:00
|
|
|
*/
|
2015-08-19 15:37:55 +00:00
|
|
|
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);
|
|
|
|
|
2016-11-11 12:44:57 +00:00
|
|
|
$this->publish($event);
|
2013-09-29 18:31:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2015-08-18 07:03:56 +00:00
|
|
|
public function registerConsumer(\Closure $callable) {
|
2015-07-23 09:00:29 +00:00
|
|
|
array_push($this->consumersClosures, $callable);
|
|
|
|
$this->consumers = [];
|
2013-09-29 18:31:12 +00:00
|
|
|
}
|
2013-10-09 16:06:21 +00:00
|
|
|
|
2014-07-03 11:48:15 +00:00
|
|
|
/**
|
|
|
|
* In order to improve lazy loading a closure can be registered which will be called in case
|
|
|
|
* activity consumers are actually requested
|
|
|
|
*
|
2016-10-20 15:57:44 +00:00
|
|
|
* $callable has to return an instance of OCA\Activity\IExtension
|
2014-07-03 11:48:15 +00:00
|
|
|
*
|
|
|
|
* @param \Closure $callable
|
|
|
|
*/
|
2015-08-18 07:03:56 +00:00
|
|
|
public function registerExtension(\Closure $callable) {
|
2015-07-23 09:00:29 +00:00
|
|
|
array_push($this->extensionsClosures, $callable);
|
|
|
|
$this->extensions = [];
|
2014-07-03 11:48:15 +00:00
|
|
|
}
|
|
|
|
|
2016-10-25 16:00:25 +00:00
|
|
|
/** @var string[] */
|
2016-11-11 10:27:39 +00:00
|
|
|
protected $filterClasses = [];
|
2016-10-20 15:57:44 +00:00
|
|
|
|
|
|
|
/** @var IFilter[] */
|
2016-11-11 10:27:39 +00:00
|
|
|
protected $filters = [];
|
2016-10-20 15:57:44 +00:00
|
|
|
|
|
|
|
/** @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
|
2016-11-16 08:29:27 +00:00
|
|
|
* @since 11.0.0
|
2016-10-20 15:57:44 +00:00
|
|
|
*/
|
|
|
|
public function getFilterById($id) {
|
|
|
|
$filters = $this->getFilters();
|
|
|
|
|
|
|
|
if (isset($filters[$id])) {
|
|
|
|
return $filters[$id];
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new \InvalidArgumentException('Requested filter does not exist');
|
|
|
|
}
|
|
|
|
|
2016-11-04 10:33:33 +00:00
|
|
|
/** @var string[] */
|
2016-11-11 10:27:39 +00:00
|
|
|
protected $providerClasses = [];
|
2016-11-04 10:33:33 +00:00
|
|
|
|
|
|
|
/** @var IProvider[] */
|
2016-11-11 10:27:39 +00:00
|
|
|
protected $providers = [];
|
2016-11-04 10:33:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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;
|
|
|
|
}
|
|
|
|
|
2016-10-25 16:00:25 +00:00
|
|
|
/** @var string[] */
|
2016-11-11 10:27:39 +00:00
|
|
|
protected $settingsClasses = [];
|
2016-10-25 16:00:25 +00:00
|
|
|
|
|
|
|
/** @var ISetting[] */
|
2016-11-11 10:27:39 +00:00
|
|
|
protected $settings = [];
|
2016-10-25 16:00:25 +00:00
|
|
|
|
|
|
|
/** @var bool */
|
|
|
|
protected $loadedLegacyTypes = false;
|
|
|
|
|
2014-07-03 11:48:15 +00:00
|
|
|
/**
|
2016-10-25 16:00:25 +00:00
|
|
|
* @param string $setting Class must implement OCA\Activity\ISetting
|
|
|
|
* @return void
|
2014-07-03 11:48:15 +00:00
|
|
|
*/
|
2016-10-25 16:00:25 +00:00
|
|
|
public function registerSetting($setting) {
|
|
|
|
$this->settingsClasses[$setting] = false;
|
|
|
|
}
|
2015-08-28 16:40:50 +00:00
|
|
|
|
2016-10-25 16:00:25 +00:00
|
|
|
/**
|
|
|
|
* @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']);
|
2015-08-28 16:40:50 +00:00
|
|
|
}
|
|
|
|
|
2016-10-25 16:00:25 +00:00
|
|
|
$this->settings[$type] = new LegacySetting(
|
|
|
|
$type, $desc,
|
|
|
|
$canChangeStream, in_array($type, $streamTypes),
|
|
|
|
$canChangeMail, in_array($type, $mailTypes)
|
|
|
|
);
|
2014-07-03 11:48:15 +00:00
|
|
|
}
|
2016-10-25 16:00:25 +00:00
|
|
|
$this->loadedLegacyTypes = true;
|
2014-07-03 11:48:15 +00:00
|
|
|
}
|
|
|
|
|
2016-10-25 16:00:25 +00:00
|
|
|
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;
|
2014-07-03 11:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-10-25 16:00:25 +00:00
|
|
|
* @param string $id
|
|
|
|
* @return ISetting
|
|
|
|
* @throws \InvalidArgumentException when the setting was not found
|
2016-11-16 08:29:27 +00:00
|
|
|
* @since 11.0.0
|
2014-07-03 11:48:15 +00:00
|
|
|
*/
|
2016-10-25 16:00:25 +00:00
|
|
|
public function getSettingById($id) {
|
|
|
|
$settings = $this->getSettings();
|
|
|
|
|
|
|
|
if (isset($settings[$id])) {
|
|
|
|
return $settings[$id];
|
2014-07-03 11:48:15 +00:00
|
|
|
}
|
2016-10-25 16:00:25 +00:00
|
|
|
|
|
|
|
throw new \InvalidArgumentException('Requested setting does not exist');
|
2014-07-03 11:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-02-13 10:51:55 +00:00
|
|
|
* @param string $type
|
|
|
|
* @return string
|
2014-07-03 11:48:15 +00:00
|
|
|
*/
|
2015-08-18 07:03:56 +00:00
|
|
|
public function getTypeIcon($type) {
|
2015-02-13 10:51:55 +00:00
|
|
|
if (isset($this->typeIcons[$type])) {
|
|
|
|
return $this->typeIcons[$type];
|
|
|
|
}
|
|
|
|
|
2015-07-23 09:00:29 +00:00
|
|
|
foreach ($this->getExtensions() as $c) {
|
|
|
|
$icon = $c->getTypeIcon($type);
|
|
|
|
if (is_string($icon)) {
|
|
|
|
$this->typeIcons[$type] = $icon;
|
|
|
|
return $icon;
|
2014-07-03 11:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-13 10:51:55 +00:00
|
|
|
|
|
|
|
$this->typeIcons[$type] = '';
|
|
|
|
return '';
|
2014-07-03 11:48:15 +00:00
|
|
|
}
|
|
|
|
|
2015-10-02 07:53:39 +00:00
|
|
|
/**
|
|
|
|
* @param string $type
|
2016-02-02 09:11:19 +00:00
|
|
|
* @param string $id
|
2015-10-02 07:53:39 +00:00
|
|
|
*/
|
|
|
|
public function setFormattingObject($type, $id) {
|
|
|
|
$this->formattingObjectType = $type;
|
2016-02-02 09:11:19 +00:00
|
|
|
$this->formattingObjectId = (string) $id;
|
2015-10-02 07:53:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isFormattingFilteredObject() {
|
2016-03-24 08:32:11 +00:00
|
|
|
return $this->formattingObjectType !== null && $this->formattingObjectId !== null
|
|
|
|
&& $this->formattingObjectType === $this->request->getParam('object_type')
|
2016-02-02 09:11:19 +00:00
|
|
|
&& $this->formattingObjectId === $this->request->getParam('object_id');
|
2015-10-02 07:53:39 +00:00
|
|
|
}
|
|
|
|
|
2014-07-03 11:48:15 +00:00
|
|
|
/**
|
|
|
|
* @param string $app
|
|
|
|
* @param string $text
|
|
|
|
* @param array $params
|
|
|
|
* @param boolean $stripPath
|
|
|
|
* @param boolean $highlightParams
|
|
|
|
* @param string $languageCode
|
|
|
|
* @return string|false
|
|
|
|
*/
|
2015-08-18 07:03:56 +00:00
|
|
|
public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) {
|
2015-07-23 09:00:29 +00:00
|
|
|
foreach ($this->getExtensions() as $c) {
|
|
|
|
$translation = $c->translate($app, $text, $params, $stripPath, $highlightParams, $languageCode);
|
|
|
|
if (is_string($translation)) {
|
|
|
|
return $translation;
|
2014-07-03 11:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-12-11 13:54:50 +00:00
|
|
|
/**
|
|
|
|
* @param string $app
|
|
|
|
* @param string $text
|
|
|
|
* @return array|false
|
|
|
|
*/
|
2015-08-18 07:03:56 +00:00
|
|
|
public function getSpecialParameterList($app, $text) {
|
2015-01-23 14:37:15 +00:00
|
|
|
if (isset($this->specialParameters[$app][$text])) {
|
|
|
|
return $this->specialParameters[$app][$text];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($this->specialParameters[$app])) {
|
|
|
|
$this->specialParameters[$app] = array();
|
|
|
|
}
|
|
|
|
|
2015-07-23 09:00:29 +00:00
|
|
|
foreach ($this->getExtensions() as $c) {
|
|
|
|
$specialParameter = $c->getSpecialParameterList($app, $text);
|
|
|
|
if (is_array($specialParameter)) {
|
|
|
|
$this->specialParameters[$app][$text] = $specialParameter;
|
|
|
|
return $specialParameter;
|
2014-12-11 13:54:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-23 14:37:15 +00:00
|
|
|
$this->specialParameters[$app][$text] = false;
|
2014-12-11 13:54:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-03 11:48:15 +00:00
|
|
|
/**
|
|
|
|
* @param array $activity
|
|
|
|
* @return integer|false
|
|
|
|
*/
|
2015-08-18 07:03:56 +00:00
|
|
|
public function getGroupParameter($activity) {
|
2015-07-23 09:00:29 +00:00
|
|
|
foreach ($this->getExtensions() as $c) {
|
|
|
|
$parameter = $c->getGroupParameter($activity);
|
|
|
|
if ($parameter !== false) {
|
|
|
|
return $parameter;
|
2014-07-03 11:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-10-20 15:57:44 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
2014-07-03 11:48:15 +00:00
|
|
|
/**
|
|
|
|
* @return array
|
2016-11-16 08:29:27 +00:00
|
|
|
* @deprecated 11.0.0 - Use getFilters() instead
|
2014-07-03 11:48:15 +00:00
|
|
|
*/
|
2015-08-18 07:03:56 +00:00
|
|
|
public function getNavigation() {
|
2014-07-03 11:48:15 +00:00
|
|
|
$entries = array(
|
|
|
|
'apps' => array(),
|
|
|
|
'top' => array(),
|
|
|
|
);
|
2015-07-23 09:00:29 +00:00
|
|
|
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']);
|
2014-07-03 11:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $entries;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $filterValue
|
|
|
|
* @return boolean
|
2016-11-16 08:29:27 +00:00
|
|
|
* @deprecated 11.0.0 - Use getFilterById() instead
|
2014-07-03 11:48:15 +00:00
|
|
|
*/
|
2015-08-18 07:03:56 +00:00
|
|
|
public function isFilterValid($filterValue) {
|
2015-01-23 14:37:15 +00:00
|
|
|
if (isset($this->validFilters[$filterValue])) {
|
|
|
|
return $this->validFilters[$filterValue];
|
|
|
|
}
|
|
|
|
|
2015-07-23 09:00:29 +00:00
|
|
|
foreach ($this->getExtensions() as $c) {
|
|
|
|
if ($c->isFilterValid($filterValue) === true) {
|
|
|
|
$this->validFilters[$filterValue] = true;
|
|
|
|
return true;
|
2014-07-03 11:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-23 14:37:15 +00:00
|
|
|
$this->validFilters[$filterValue] = false;
|
2014-07-03 11:48:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-13 10:51:55 +00:00
|
|
|
/**
|
|
|
|
* @param array $types
|
|
|
|
* @param string $filter
|
|
|
|
* @return array
|
2016-11-16 08:29:27 +00:00
|
|
|
* @deprecated 11.0.0 - Use getFilterById()->filterTypes() instead
|
2015-02-13 10:51:55 +00:00
|
|
|
*/
|
2015-08-18 07:03:56 +00:00
|
|
|
public function filterNotificationTypes($types, $filter) {
|
2015-02-13 10:51:55 +00:00
|
|
|
if (!$this->isFilterValid($filter)) {
|
|
|
|
return $types;
|
|
|
|
}
|
|
|
|
|
2015-07-23 09:00:29 +00:00
|
|
|
foreach ($this->getExtensions() as $c) {
|
|
|
|
$result = $c->filterNotificationTypes($types, $filter);
|
|
|
|
if (is_array($result)) {
|
|
|
|
$types = $result;
|
2015-02-13 10:51:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $types;
|
|
|
|
}
|
|
|
|
|
2014-07-03 11:48:15 +00:00
|
|
|
/**
|
|
|
|
* @param string $filter
|
|
|
|
* @return array
|
2016-11-16 08:29:27 +00:00
|
|
|
* @deprecated 11.0.0 - Use getFilterById() instead
|
2014-07-03 11:48:15 +00:00
|
|
|
*/
|
2015-08-18 07:03:56 +00:00
|
|
|
public function getQueryForFilter($filter) {
|
2015-02-13 10:50:55 +00:00
|
|
|
if (!$this->isFilterValid($filter)) {
|
|
|
|
return [null, null];
|
|
|
|
}
|
2014-11-28 10:18:15 +00:00
|
|
|
|
|
|
|
$conditions = array();
|
|
|
|
$parameters = array();
|
|
|
|
|
2015-07-23 09:00:29 +00:00
|
|
|
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);
|
2014-07-03 11:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-28 10:18:15 +00:00
|
|
|
if (empty($conditions)) {
|
|
|
|
return array(null, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
return array(' and ((' . implode(') or (', $conditions) . '))', $parameters);
|
2014-07-03 11:48:15 +00:00
|
|
|
}
|
2016-10-25 16:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Will return additional notification types as specified by other apps
|
|
|
|
*
|
|
|
|
* @param string $languageCode
|
|
|
|
* @return array
|
2016-11-16 08:29:27 +00:00
|
|
|
* @deprecated 11.0.0 - Use getSettings() instead
|
2016-10-25 16:00:25 +00:00
|
|
|
*/
|
|
|
|
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
|
2016-11-16 08:29:27 +00:00
|
|
|
* @deprecated 11.0.0 - Use getSettings()->isDefaulEnabled<method>() instead
|
2016-10-25 16:00:25 +00:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
2013-09-29 18:31:12 +00:00
|
|
|
}
|