]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/RSSCloud/actions/loggingaggregator.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / plugins / RSSCloud / actions / 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     var $challenge = null;
51     var $url       = null;
52
53     /**
54      * Initialization.
55      *
56      * @param array $args Web and URL arguments
57      *
58      * @return boolean false if user doesn't exist
59      */
60     function prepare(array $args=array())
61     {
62         parent::prepare($args);
63
64         $this->url       = $this->arg('url');
65         $this->challenge = $this->arg('challenge');
66
67         common_debug("args = " . var_export($this->args, true));
68         common_debug('url = ' . $this->url . ' challenge = ' . $this->challenge);
69
70         return true;
71     }
72
73     /**
74      * Handle the request
75      *
76      * @param array $args $_REQUEST data (unused)
77      *
78      * @return void
79      */
80     function handle(array $args=array())
81     {
82         parent::handle($args);
83
84         if (empty($this->url)) {
85             // TRANS: Form validation error displayed when a URL parameter is missing.
86             $this->showError(_m('A URL parameter is required.'));
87             return;
88         }
89
90         if (!empty($this->challenge)) {
91             // must be a GET
92             if ($_SERVER['REQUEST_METHOD'] != 'GET') {
93                 // TRANS: Form validation error displayed when HTTP GET is not used.
94                 $this->showError(_m('This resource requires an HTTP GET.'));
95                 return;
96             }
97
98             header('Content-Type: text/xml');
99             echo $this->challenge;
100         } else {
101             // must be a POST
102             if ($_SERVER['REQUEST_METHOD'] != 'POST') {
103                 // TRANS: Form validation error displayed when HTTP POST is not used.
104                 $this->showError(_m('This resource requires an HTTP POST.'));
105                 return;
106             }
107
108             header('Content-Type: text/xml');
109             Echo "<notifyResult success='true' msg='Thanks for the update.' />\n";
110         }
111
112         $this->ip = $_SERVER['REMOTE_ADDR'];
113
114         common_log(LOG_INFO, 'RSSCloud Logging Aggregator - ' .
115                    $this->ip . ' claims the feed at ' .
116                    $this->url . ' has been updated.');
117     }
118
119     /**
120      * Show an XML error when things go badly
121      *
122      * @param string $msg the error message
123      *
124      * @return void
125      */
126     function showError($msg)
127     {
128         header('HTTP/1.1 400 Bad Request');
129         header('Content-Type: text/xml');
130         echo "<?xml version='1.0'?>\n";
131         echo "<notifyResult success='false' msg='$msg' />\n";
132     }
133 }