]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/TagCloud/TagCloudPlugin.php
[ROUTES] Allow accept-header specification during router creation
[quix0rs-gnu-social.git] / plugins / TagCloud / TagCloudPlugin.php
1 <?php
2 /**
3  * GNU social plugin for "tag clouds" in the UI
4  *
5  * @category  UI
6  * @package   GNUsocial
7  * @author    Mikael Nordfeldth <mmn@hethane.se>
8  * @copyright 2016 Free Software Foundation, Inc.
9  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
10  * @link      http://gnu.io/social/
11  */
12
13 if (!defined('GNUSOCIAL')) { exit(1); }
14
15 class TagCloudPlugin extends Plugin {
16     const PLUGIN_VERSION = '2.0.0';
17
18     public function onRouterInitialized(URLMapper $m)
19     {
20         $m->connect('tags/', ['action' => 'publictagcloud']);
21         $m->connect('tag/', ['action' => 'publictagcloud']);
22         $m->connect('tags', ['action' => 'publictagcloud']);
23         $m->connect('tag', ['action' => 'publictagcloud']);
24     }
25
26     public function onEndPublicGroupNav(Menu $menu)
27     {
28         // TRANS: Menu item in search group navigation panel.
29         $menu->out->menuItem(common_local_url('publictagcloud'), _m('MENU','Recent tags'),
30                              // TRANS: Menu item title in search group navigation panel.
31                              _('Recent tags'), $menu->actionName === 'publictagcloud', 'nav_recent-tags');
32     }
33
34     public function onEndShowSections(Action $action)
35     {
36         $cloud = null;
37
38         switch (true) {
39         case $action instanceof AllAction:
40             $cloud = new InboxTagCloudSection($action, $action->getTarget());
41             break;
42         case $action instanceof AttachmentAction:
43             $cloud = new AttachmentTagCloudSection($action);
44             break;
45         case $action instanceof PublicAction:
46             $cloud = new PublicTagCloudSection($action);
47             break;
48         case $action instanceof ShowstreamAction:
49             $cloud = new PersonalTagCloudSection($action, $action->getTarget());
50             break;
51         case $action instanceof GroupAction:
52             $cloud = new GroupTagCloudSection($action, $action->getGroup());
53         }
54
55         if (!is_null($cloud)) {
56             $cloud->show();
57         }
58     }
59
60     public function onPluginVersion(array &$versions)
61     {
62         $versions[] = array('name' => 'TagCloud',
63                             'version' => self::PLUGIN_VERSION,
64                             'author' => 'Mikael Nordfeldth',
65                             'homepage' => 'https://gnu.io/social',
66                             'description' =>
67                             // TRANS: Plugin description.
68                             _m('Adds tag clouds to stream pages'));
69         return true;
70     }
71 }