]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/SlicedFavorites/SlicedFavoritesPlugin.php
fixed parser error (opps)
[quix0rs-gnu-social.git] / plugins / SlicedFavorites / SlicedFavoritesPlugin.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2010, StatusNet, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 /**
21  * @package SlicedFavoritesPlugin
22  * @maintainer Brion Vibber <brion@status.net>
23  */
24
25 if (!defined('STATUSNET')) { exit(1); }
26
27 class SlicedFavoritesPlugin extends Plugin
28 {
29     const PLUGIN_VERSION = '2.0.0';
30
31     /**
32      * Example:
33      *
34      *   addPlugin('SlicedFavorites', array(
35      *     'slices' => array(
36      *       // show only pop's notices on /favorited
37      *       'default' => array('include' => array('pop')),
38      *
39      *       // show only son's notices on /favorited/blog
40      *       'blog' => array('include' => array('son')),
41      *
42      *       // show all favorited notices except pop's and son's on /favorited/submitted
43      *       'submitted' => array('exclude' => array('pop', 'son')),
44      *
45      *       // show all favorited notices on /favorited/everybody
46      *       'everybody' => array(),
47      *     )
48      *   ));
49      *
50      * @var array
51      */
52     public $slices = array();
53
54     /**
55      * Hook for RouterInitialized event.
56      *
57      * @param URLMapper $m path-to-action mapper
58      * @return boolean hook return
59      */
60     public function onRouterInitialized(URLMapper $m)
61     {
62         $m->connect('favorited/:slice',
63                     ['action' => 'favoritedslice'],
64                     ['slice' => '[a-zA-Z0-9]+']);
65
66         return true;
67     }
68
69     // Take over the default... :D
70     function onArgsInitialize(array &$args)
71     {
72         if (array_key_exists('action', $args)) {
73             $action = trim($args['action']);
74             if ($action == 'favorited') {
75                 common_redirect(common_local_url('favoritedslice', array('slice' => 'default')));
76                 exit(0);
77             }
78         }
79         return true;
80     }
81
82     function onSlicedFavoritesGetSettings($slice, &$data)
83     {
84         if (isset($this->slices[$slice])) {
85             $data = $this->slices[$slice];
86             return false;
87         }
88         return true;
89     }
90
91     /**
92      * Provide plugin version information.
93      *
94      * This data is used when showing the version page.
95      *
96      * @param array &$versions array of version data arrays; see EVENTS.txt
97      *
98      * @return boolean hook value
99      */
100     function onPluginVersion(array &$versions)
101     {
102         $url = 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/SlicedFavorites';
103
104         $versions[] = array('name' => 'SlicedFavorites',
105             'version' => self::PLUGIN_VERSION,
106             'author' => 'Brion Vibber',
107             'homepage' => $url,
108             'rawdescription' =>
109             // TRANS: Plugin description.
110             _m('Shows timelines of popular notices for defined subsets of users.'));
111
112         return true;
113     }
114 }