]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/RSSCloud/LoggingAggregator.php
Merge branch 'testing' of gitorious.org:statusnet/mainline into 0.9.x
[quix0rs-gnu-social.git] / plugins / RSSCloud / LoggingAggregator.php
1 <?php
2 /**
3  * This test class pretends to be an RSS aggregator. It logs notifications
4  * from the cloud.
5  *
6  * PHP version 5
7  *
8  * @category Plugin
9  * @package  StatusNet
10  * @author   Zach Copley <zach@status.net>
11  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
12  * @link     http://status.net/
13  *
14  * StatusNet - the distributed open-source microblogging tool
15  * Copyright (C) 2009, StatusNet, Inc.
16  *
17  * This program is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU Affero General Public License as published by
19  * the Free Software Foundation, either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU Affero General Public License for more details.
26  *
27  * You should have received a copy of the GNU Affero General Public License
28  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
29  */
30
31 if (!defined('STATUSNET')) {
32     exit(1);
33 }
34
35 /**
36  * Dummy aggregator that acts as a proper notification handler. It
37  * doesn't do anything but respond correctly when notified via
38  * REST.  Mostly, this is just and action I used to develop the plugin
39  * and easily test things end-to-end. I'm leaving it in here as it
40  * may be useful for developing the plugin further.
41  *
42  * @category Plugin
43  * @package  StatusNet
44  * @author   Zach Copley <zach@status.net>
45  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
46  * @link     http://status.net/
47  **/
48 class LoggingAggregatorAction extends Action
49 {
50
51     var $challenge = null;
52     var $url       = null;
53
54     /**
55      * Initialization.
56      *
57      * @param array $args Web and URL arguments
58      *
59      * @return boolean false if user doesn't exist
60      */
61
62     function prepare($args)
63     {
64         parent::prepare($args);
65
66         $this->url       = $this->arg('url');
67         $this->challenge = $this->arg('challenge');
68
69         common_debug("args = " . var_export($this->args, true));
70         common_debug('url = ' . $this->url . ' challenge = ' . $this->challenge);
71
72         return true;
73     }
74
75     /**
76      * Handle the request
77      *
78      * @param array $args $_REQUEST data (unused)
79      *
80      * @return void
81      */
82
83     function handle($args)
84     {
85         parent::handle($args);
86
87         if (empty($this->url)) {
88             $this->showError('Hey, you have to provide a url parameter.');
89             return;
90         }
91
92         if (!empty($this->challenge)) {
93
94             // must be a GET
95
96             if ($_SERVER['REQUEST_METHOD'] != 'GET') {
97                 $this->showError('This resource requires an HTTP GET.');
98                 return;
99             }
100
101             header('Content-Type: text/xml');
102             echo $this->challenge;
103
104         } else {
105
106             // must be a POST
107
108             if ($_SERVER['REQUEST_METHOD'] != 'POST') {
109                 $this->showError('This resource requires an HTTP POST.');
110                 return;
111             }
112
113             header('Content-Type: text/xml');
114             Echo "<notifyResult success='true' msg='Thanks for the update.' />\n";
115         }
116
117         $this->ip = $_SERVER['REMOTE_ADDR'];
118
119         common_log(LOG_INFO, 'RSSCloud Logging Aggregator - ' .
120                    $this->ip . ' claims the feed at ' .
121                    $this->url . ' has been updated.');
122     }
123
124     /**
125      * Show an XML error when things go badly
126      *
127      * @param string $msg the error message
128      *
129      * @return void
130      */
131
132     function showError($msg)
133     {
134         header('HTTP/1.1 400 Bad Request');
135         header('Content-Type: text/xml');
136         echo "<?xml version='1.0'?>\n";
137         echo "<notifyResult success='false' msg='$msg' />\n";
138     }
139
140 }