]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/SlicedFavorites/SlicedFavoritesPlugin.php
XSS vulnerability when remote-subscribing
[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     /**
30      * Example:
31      *
32      *   addPlugin('SlicedFavorites', array(
33      *     'slices' => array(
34      *       // show only pop's notices on /favorited
35      *       'default' => array('include' => array('pop')),
36      *
37      *       // show only son's notices on /favorited/blog
38      *       'blog' => array('include' => array('son')),
39      *
40      *       // show all favorited notices except pop's and son's on /favorited/submitted
41      *       'submitted' => array('exclude' => array('pop', 'son')),
42      *
43      *       // show all favorited notices on /favorited/everybody
44      *       'everybody' => array(),
45      *     )
46      *   ));
47      *
48      * @var array
49      */
50     public $slices = array();
51
52     /**
53      * Hook for RouterInitialized event.
54      *
55      * @param URLMapper $m path-to-action mapper
56      * @return boolean hook return
57      */
58     public function onRouterInitialized(URLMapper $m)
59     {
60         $m->connect('favorited/:slice',
61                     array('action' => 'favoritedslice'),
62                     array('slice' => '[a-zA-Z0-9]+'));
63
64         return true;
65     }
66
67     // Take over the default... :D
68     function onArgsInitialize($args)
69     {
70         if (array_key_exists('action', $args)) {
71             $action = trim($args['action']);
72             if ($action == 'favorited') {
73                 common_redirect(common_local_url('favoritedslice', array('slice' => 'default')));
74                 exit(0);
75             }
76         }
77         return true;
78     }
79
80     function onSlicedFavoritesGetSettings($slice, &$data)
81     {
82         if (isset($this->slices[$slice])) {
83             $data = $this->slices[$slice];
84             return false;
85         }
86         return true;
87     }
88
89     /**
90      * Provide plugin version information.
91      *
92      * This data is used when showing the version page.
93      *
94      * @param array &$versions array of version data arrays; see EVENTS.txt
95      *
96      * @return boolean hook value
97      */
98     function onPluginVersion(array &$versions)
99     {
100         $url = 'http://status.net/wiki/Plugin:SlicedFavorites';
101
102         $versions[] = array('name' => 'SlicedFavorites',
103             'version' => GNUSOCIAL_VERSION,
104             'author' => 'Brion Vibber',
105             'homepage' => $url,
106             'rawdescription' =>
107             // TRANS: Plugin description.
108             _m('Shows timelines of popular notices for defined subsets of users.'));
109
110         return true;
111     }
112 }