From: Zach Copley Date: Wed, 16 Sep 2009 19:20:25 +0000 (+0000) Subject: Some foundational work. Not much to see here. Move along. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=391003c3c65572dd156244390d8eedd2dfd96f90;p=quix0rs-gnu-social.git Some foundational work. Not much to see here. Move along. --- diff --git a/plugins/RSSCloud/RSSCloudNotifier.php b/plugins/RSSCloud/RSSCloudNotifier.php new file mode 100644 index 0000000000..65bfd032e9 --- /dev/null +++ b/plugins/RSSCloud/RSSCloudNotifier.php @@ -0,0 +1,93 @@ +. + * + * @category Plugin + * @package StatusNet + * @author Zach Copley + * @copyright 2009 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + exit(1); +} + +class RSSCloudNotifier { + + function postUpdate($endpoint, $feed) { + common_debug("CloudNotifier->notify: $feed"); + + $params = 'url=' . urlencode($feed); + + $result = $this->httpPost($endpoint, $params); + + if ($result) { + common_debug('success notifying cloud'); + } else { + common_debug('failure notifying cloud'); + } + + } + + function userAgent() + { + return 'rssCloudPlugin/' . RSSCLOUDPLUGIN_VERSION . + ' StatusNet/' . STATUSNET_VERSION; + } + + private function httpPost($url, $params) { + + common_debug('params: ' . var_export($params, true)); + + $options = array(CURLOPT_URL => $url, + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => $params, + CURLOPT_USERAGENT => $this->userAgent(), + CURLOPT_RETURNTRANSFER => true, + CURLOPT_FAILONERROR => true, + CURLOPT_HEADER => false, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_CONNECTTIMEOUT => 5, + CURLOPT_TIMEOUT => 5); + + $ch = curl_init(); + curl_setopt_array($ch, $options); + + $response = curl_exec($ch); + + $info = curl_getinfo($ch); + + curl_close($ch); + + common_debug('curl response: ' . var_export($response, true)); + common_debug('curl info: ' . var_export($info, true)); + + if ($info['http_code'] == 200) { + return true; + } else { + return false; + } + } + +} + + diff --git a/plugins/RSSCloud/RSSCloudPlugin.php b/plugins/RSSCloud/RSSCloudPlugin.php index 816046ffbb..50d9060efe 100644 --- a/plugins/RSSCloud/RSSCloudPlugin.php +++ b/plugins/RSSCloud/RSSCloudPlugin.php @@ -33,30 +33,33 @@ if (!defined('STATUSNET')) { define('RSSCLOUDPLUGIN_VERSION', '0.1'); -class RSSCloudPlugin extends Plugin +class RSSCloudPlugin extends Plugin { function __construct() { parent::__construct(); } - + function onInitializePlugin(){ + + common_debug("RSSCloudPlugin onInitializePlugin()"); + $this->domain = common_config('rsscloud', 'domain'); $this->port = common_config('rsscloud', 'port'); $this->path = common_config('rsscloud', 'path'); $this->funct = common_config('rsscloud', 'function'); $this->protocol = common_config('rsscloud', 'protocol'); - + // set defaults - + if (empty($this->domain)) { $this->domain = 'rpc.rsscloud.org'; } - + if (empty($this->port)) { $this->port = '5337'; } - + if (empty($this->path)) { $this->path = '/rsscloud/pleaseNotify'; } @@ -69,9 +72,47 @@ class RSSCloudPlugin extends Plugin $this->protocol = 'http-post'; } } - + + /** + * Add RSSCloud-related paths to the router table + * + * Hook for RouterInitialized event. + * + * @return boolean hook return + */ + + function onRouterInitialized(&$m) + { + $m->connect('rsscloud/request_notify', array('action' => 'RSSCloudRequestNotify')); + $m->connect('rsscloud/notify', array('action' => 'LoggingAggregator')); + + return true; + } + + function onAutoload($cls) + { + common_debug("onAutoload() $cls"); + + switch ($cls) + { + + case 'RSSCloudNotifier': + require_once(INSTALLDIR . '/plugins/RSSCloud/RSSCloudNotifier.php'); + return false; + case 'RSSCloudRequestNotifyAction': + case 'LoggingAggregatorAction': + common_debug(mb_substr($cls, 0, -6) . '.php'); + require_once(INSTALLDIR . '/plugins/RSSCloud/' . mb_substr($cls, 0, -6) . '.php'); + return false; + default: + return true; + } + } + function onStartApiRss($action){ - + + // XXX: No sure we want every feed to be cloud enabled + $attrs = array('domain' => $this->domain, 'port' => $this->port, 'path' => $this->path, @@ -79,91 +120,31 @@ class RSSCloudPlugin extends Plugin 'protocol' => $this->protocol); // Dipping into XMLWriter to avoid a full end element (). - + $action->xw->startElement('cloud'); foreach ($attrs as $name => $value) { $action->xw->writeAttribute($name, $value); } $action->xw->endElement('cloud'); - + } function onEndNoticeSave($notice){ + common_debug("RSSCloudPlugin oneEndNoticeSave()"); + $user = User::staticGet('id', $notice->profile_id); - $rss = common_local_url('api', array('apiaction' => 'statuses', + $feed = common_local_url('api', array('apiaction' => 'statuses', 'method' => 'user_timeline', 'argument' => $user->nickname . '.rss')); - - $notifier = new CloudNotifier(); - $notifier->notify($rss); - } - - -} + // XXX: Dave's hub for testing -class CloudNotifier { - - - function notify($feed) { - common_debug("CloudNotifier->notify: $feed"); - - $params = 'url=' . urlencode($feed); - - $result = $this->httpPost('http://rpc.rsscloud.org:5337/rsscloud/ping', - $params); - - if ($result) { - common_debug('success notifying cloud'); - } else { - common_debug('failure notifying cloud'); - } + $endpoint = 'http://rpc.rsscloud.org:5337/rsscloud/ping'; + $notifier = new RSSCloudNotifier(); + $notifier->postUpdate($endpoint, $feed); } - - function userAgent() - { - return 'rssCloudPlugin/' . RSSCLOUDPLUGIN_VERSION . - ' StatusNet/' . STATUSNET_VERSION; - } - - - private function httpPost($url, $params) { - - - common_debug('params: ' . var_export($params, true)); - - $options = array(CURLOPT_URL => $url, - CURLOPT_POST => true, - CURLOPT_POSTFIELDS => $params, - CURLOPT_USERAGENT => $this->userAgent(), - CURLOPT_RETURNTRANSFER => true, - CURLOPT_FAILONERROR => true, - CURLOPT_HEADER => false, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_CONNECTTIMEOUT => 5, - CURLOPT_TIMEOUT => 5); - - $ch = curl_init(); - curl_setopt_array($ch, $options); - - $response = curl_exec($ch); - - - - $info = curl_getinfo($ch); - - curl_close($ch); - - common_debug('curl response: ' . var_export($response, true)); - common_debug('curl info: ' . var_export($info, true)); - - if ($info['http_code'] == 200) { - return true; - } else { - return false; - } - } - -} \ No newline at end of file + +} + diff --git a/plugins/RSSCloud/RSSCloudRequestNotify.php b/plugins/RSSCloud/RSSCloudRequestNotify.php new file mode 100644 index 0000000000..1d4087334f --- /dev/null +++ b/plugins/RSSCloud/RSSCloudRequestNotify.php @@ -0,0 +1,145 @@ + + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://status.net/ + * + * StatusNet - the distributed open-source microblogging tool + * Copyright (C) 2009, StatusNet, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +if (!defined('STATUSNET')) { + exit(1); +} + +class RSSCloudRequestNotifyAction extends Action +{ + + /** + * Initialization. + * + * @param array $args Web and URL arguments + * + * @return boolean false if user doesn't exist + */ + function prepare($args) + { + parent::prepare($args); + return true; + } + + function handle($args) + { + parent::handle($args); + + if ($_SERVER['REQUEST_METHOD'] != 'POST') { + showResult(false, 'Request must be POST.'); + } + + $ip = $_SERVER['REMOTE_ADDR']; + $missing = array(); + $port = $this->arg('port'); + + if (empty($this->port)) { + $missing[] = 'port'; + } + + $path = $this->arg('path'); + + if (empty($this->path)) { + $missing[] = 'path'; + } + + $protocol = $this->arg('protocol'); + + if (empty($this->protocol)) { + $missing[] = 'protocol'; + } + + if (empty($this->notifyProcedure)) { + $missing[] = 'notifyProcedure'; + } + + if (!empty($missing)) { + $msg = 'The following parameters were missing from the request body: ' . + implode(',', $missing) . '.'; + $this->showResult(false, $msg); + } + + $feeds = $this->getFeeds(); + + if (empty($feeds)) { + $this->showResult(false, + 'You must provide at least one feed url (url1, url2, url3 ... urlN).'); + } + + $endpoint = $ip . ':' . $port . $path; + + foreach ($feeds as $feed) { + + } + + + } + + + function getFeeds() + { + $feeds = array(); + + foreach ($this->args as $key => $feed ) { + if (preg_match('|url\d+|', $key)) { + + // XXX: validate feeds somehow and kick bad ones out + + $feeds[] = $feed; + } + } + + return $feeds; + } + + + function checkNotifyHandler() + { + + } + + function validateFeed() + { + } + + function showResult($success, $msg) + { + $this->startXML(); + $this->elementStart('notifyResult', array('success' => ($success) ? 'true' : 'false', + 'msg' => $msg)); + $this->endXML(); + + } + + +} + + +