]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/RSSCloud/LoggingAggregator.php
Added intial README
[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 class LoggingAggregatorAction extends Action
36 {
37
38     var $challenge = null;
39     var $url       = null;
40
41     /**
42      * Initialization.
43      *
44      * @param array $args Web and URL arguments
45      *
46      * @return boolean false if user doesn't exist
47      */
48     function prepare($args)
49     {
50         parent::prepare($args);
51
52         $this->url       = $this->arg('url');
53         $this->challenge = $this->arg('challenge');
54
55         common_debug("args = " . var_export($this->args, true));
56         common_debug('url = ' . $this->url . ' challenge = ' . $this->challenge);
57
58         return true;
59     }
60
61     function handle($args)
62     {
63         parent::handle($args);
64
65         if (empty($this->url)) {
66             $this->showError('Hey, you have to provide a url parameter.');
67             return;
68         }
69
70         if (!empty($this->challenge)) {
71
72             // must be a GET
73
74             if ($_SERVER['REQUEST_METHOD'] != 'GET') {
75                 $this->showError('This resource requires an HTTP GET.');
76                 return;
77             }
78
79             header('Content-Type: text/xml');
80             echo $this->challenge;
81
82         } else {
83
84             // must be a POST
85
86             if ($_SERVER['REQUEST_METHOD'] != 'POST') {
87                 $this->showError('This resource requires an HTTP POST.');
88                 return;
89             }
90
91             header('Content-Type: text/xml');
92             echo '<notifyResult success=\'true\' msg=\'Thanks for the update.\' />' . "\n";
93         }
94
95         $this->ip = $_SERVER['REMOTE_ADDR'];
96
97         common_log(LOG_INFO, 'RSSCloud Logging Aggregator - ' . $this->ip . ' claims the feed at ' .
98                    $this->url . ' has been updated.');
99     }
100
101     function showError($msg)
102     {
103         header('HTTP/1.1 400 Bad Request');
104         header('Content-Type: text/xml');
105         echo "<?xml version='1.0'?>\n";
106         echo "<notifyResult success='false' msg='$msg' />\n";
107     }
108
109 }