From fa3457f3915cdfc95f4fb937e18c8616ed2d43bf Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Mon, 9 Mar 2015 17:36:21 +0100 Subject: [PATCH] First ActivityVerbPlugin sketch --- plugins/ActivityVerb/ActivityVerbPlugin.php | 57 +++++++++++++++ plugins/ActivityVerb/actions/activityverb.php | 70 +++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 plugins/ActivityVerb/ActivityVerbPlugin.php create mode 100644 plugins/ActivityVerb/actions/activityverb.php diff --git a/plugins/ActivityVerb/ActivityVerbPlugin.php b/plugins/ActivityVerb/ActivityVerbPlugin.php new file mode 100644 index 0000000000..70c5682479 --- /dev/null +++ b/plugins/ActivityVerb/ActivityVerbPlugin.php @@ -0,0 +1,57 @@ +. + * + * @category Plugin + * @package GNUsocial + * @author Mikael Nordfeldth + * @copyright 2014 Free Software Foundation http://fsf.org + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link https://www.gnu.org/software/social/ + */ + +if (!defined('GNUSOCIAL')) { exit(1); } + +class ActivityVerbPlugin extends Plugin +{ + public function onRouterInitialized(URLMapper $m) + { + $m->connect('notice/:id/:verb', + array('action' => 'activityverb'), + array('id' => '[0-9]+', + 'verb' => '[a-z]+')); + $m->connect('activity/:id/:verb', + array('action' => 'activityverb'), + array('id' => '[0-9]+', + 'verb' => '[a-z]+')); + } + + public function onPluginVersion(&$versions) + { + $versions[] = array('name' => 'Activity Verb', + 'version' => GNUSOCIAL_VERSION, + 'author' => 'Mikael Nordfeldth', + 'homepage' => 'https://www.gnu.org/software/social/', + 'rawdescription' => + // TRANS: Plugin description. + _m('Adds more standardized verb handling for activities.')); + return true; + } +} diff --git a/plugins/ActivityVerb/actions/activityverb.php b/plugins/ActivityVerb/actions/activityverb.php new file mode 100644 index 0000000000..1121056de6 --- /dev/null +++ b/plugins/ActivityVerb/actions/activityverb.php @@ -0,0 +1,70 @@ +. + * + * @category Plugin + * @package GNUsocial + * @author Mikael Nordfeldth + * @copyright 2015 Free Software Foundaction, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link https://gnu.io/social + */ + +if (!defined('GNUSOCIAL')) { exit(1); } + +class ActivityverbAction extends ManagedAction +{ + protected $needLogin = true; + protected $canPost = true; + + protected $verb = null; + + protected function doPreparation($args) + { + $this->verb = $this->trimmed('verb'); + if (empty($this->verb)) { + throw new ServerException('A verb has not been specified.'); + } + + $this->notice = Notice::getById($this->trimmed('id')); + + if (!$this->notice->inScope($this->scoped)) { + // TRANS: %1$s is a user nickname, %2$d is a notice ID (number). + throw new ClientException(sprintf(_('%1$s has no access to notice %2$d.'), + $this->scoped->getNickname(), $this->notice->getID()), 403); + } + } + + protected function doPost() + { + if (Event::handle('ActivityVerbDoPost', array($this, $this->verb, $this->notice, $this->scoped))) { + // TRANS: Error when a POST method for an activity verb has not been handled by a plugin. + throw new ClientException(_('Could not show content for verb "%1$s".')); + } + } + + protected function showContent() + { + if (Event::handle('ActivityVerbShowContent', array($this, $this->verb, $this->notice, $this->scoped))) { + // TRANS: Error when a page for an activity verb has not been handled by a plugin. + throw new ClientException(_('Could not show content for verb "%1$s".')); + } + } +} -- 2.39.5