]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/SlicedFavorites/SlicedFavoritesPlugin.php
Merge branch '0.9.x' of gitorious.org:statusnet/mainline into 0.9.x
[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 YammerImportPlugin
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 Net_URL_Mapper $m path-to-action mapper
56      * @return boolean hook return
57      */
58     function onRouterInitialized($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     /**
81      * Automatically load the actions and libraries used by the plugin
82      *
83      * @param Class $cls the class
84      *
85      * @return boolean hook return
86      *
87      */
88     function onAutoload($cls)
89     {
90         $base = dirname(__FILE__);
91         $lower = strtolower($cls);
92         switch ($lower) {
93         case 'favoritedsliceaction':
94             require_once "$base/$lower.php";
95             return false;
96         default:
97             return true;
98         }
99     }
100
101     function onSlicedFavoritesGetSettings($slice, &$data)
102     {
103         if (isset($this->slices[$slice])) {
104             $data = $this->slices[$slice];
105             return false;
106         }
107         return true;
108     }
109 }