]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/SubMirror/actions/addmirror.php
31805c166936088e19c8f9306093384c8cfc1d57
[quix0rs-gnu-social.git] / plugins / SubMirror / actions / addmirror.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  * PHP version 5
20  *
21  * @category  Action
22  * @package   StatusNet
23  * @author    Brion Vibber <brion@status.net>
24  * @copyright 2010 StatusNet, Inc.
25  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
26  * @link      http://status.net/
27  */
28
29 if (!defined('STATUSNET')) {
30     exit(1);
31 }
32
33 /**
34  * Takes parameters:
35  *
36  *    - feed: a profile ID
37  *    - token: session token to prevent CSRF attacks
38  *    - ajax: boolean; whether to return Ajax or full-browser results
39  *
40  * Only works if the current user is logged in.
41  *
42  * @category  Action
43  * @package   StatusNet
44  * @copyright 2010 StatusNet, Inc.
45  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
46  * @link      http://status.net/
47  */
48 class AddMirrorAction extends BaseMirrorAction
49 {
50     var $feedurl;
51
52     /**
53      * Check pre-requisites and instantiate attributes
54      *
55      * @param Array $args array of arguments (URL, GET, POST)
56      *
57      * @return boolean success flag
58      */
59     function prepare($args)
60     {
61         parent::prepare($args);
62         $feedurl = $this->getFeedUrl();
63         $this->feedurl = $this->validateFeedUrl($feedurl);
64         $this->profile = $this->profileForFeed($this->feedurl);
65         return true;
66     }
67
68     function getFeedUrl()
69     {
70         $provider = $this->trimmed('provider');
71         switch ($provider) {
72         case 'feed':
73             return $this->trimmed('feedurl');
74         case 'twitter':
75             $screenie = $this->trimmed('screen_name');
76             $base = 'http://api.twitter.com/1/statuses/user_timeline.atom?screen_name=';
77             return $base . urlencode($screenie);
78         default:
79             throw new Exception('Internal form error: unrecognized feed provider.');
80         }
81     }
82
83     function saveMirror()
84     {
85         if ($this->oprofile->subscribe()) {
86             SubMirror::saveMirror($this->user, $this->profile);
87         } else {
88             $this->serverError(_m("Could not subscribe to feed."));
89         }
90     }
91 }