From d645b342ac4a678b9f7932ee38858e25cd611f35 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 12 Jul 2010 14:22:36 -0700 Subject: Commit hubprepqueuehandler.php -- fix for OStatus bulk output. --- plugins/OStatus/lib/hubprepqueuehandler.php | 87 +++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 plugins/OStatus/lib/hubprepqueuehandler.php (limited to 'plugins') diff --git a/plugins/OStatus/lib/hubprepqueuehandler.php b/plugins/OStatus/lib/hubprepqueuehandler.php new file mode 100644 index 000000000..0d585938f --- /dev/null +++ b/plugins/OStatus/lib/hubprepqueuehandler.php @@ -0,0 +1,87 @@ +. + */ + +/** + * When we have a large batch of PuSH consumers, we break the data set + * into smaller chunks. Enqueue final destinations... + * + * @package Hub + * @author Brion Vibber + */ +class HubPrepQueueHandler extends QueueHandler +{ + // Enqueue this many low-level distributions before re-queueing the rest + // of the batch to be processed later. Helps to keep latency down for other + // things happening during a particularly long OStatus delivery session. + // + // [Could probably ditch this if we had working message delivery priorities + // for queueing, but this isn't supported in ActiveMQ 5.3.] + const ROLLING_BATCH = 20; + + function transport() + { + return 'hubprep'; + } + + function handle($data) + { + $topic = $data['topic']; + $atom = $data['atom']; + $pushCallbacks = $data['pushCallbacks']; + + assert(is_string($atom)); + assert(is_string($topic)); + assert(is_array($pushCallbacks)); + + // Set up distribution for the first n subscribing sites... + // If we encounter an uncatchable error, queue handling should + // automatically re-run the batch, which could lead to some dupe + // distributions. + // + // Worst case is if one of these hubprep entries dies too many + // times and gets dropped; the rest of the batch won't get processed. + try { + $n = 0; + while (count($pushCallbacks) && $n < self::ROLLING_BATCH) { + $n++; + $callback = array_shift($pushCallbacks); + $sub = HubSub::staticGet($topic, $callback); + if (!$sub) { + common_log(LOG_ERR, "Skipping PuSH delivery for deleted(?) consumer $callback on $topic"); + continue; + } + + $sub->distribute($atom); + } + } catch (Exception $e) { + common_log(LOG_ERR, "Exception during PuSH batch out: " . + $e->getMessage() . + " prepping $topic to $callback"); + } + + // And re-queue the rest of the batch! + if (count($pushCallbacks) > 0) { + $sub = new HubSub(); + $sub->topic = $topic; + $sub->bulkDistribute($atom, $pushCallbacks); + } + + return true; + } +} -- cgit v1.2.3-54-g00ecf From 659e8b26acffd3bfbe097693d3f75e20d2f78a0f Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 28 Jul 2010 17:50:36 -0400 Subject: add admin panel for Adsense --- plugins/Adsense/AdsensePlugin.php | 48 ++++++++ plugins/Adsense/adsenseadminpanel.php | 223 ++++++++++++++++++++++++++++++++++ 2 files changed, 271 insertions(+) create mode 100644 plugins/Adsense/adsenseadminpanel.php (limited to 'plugins') diff --git a/plugins/Adsense/AdsensePlugin.php b/plugins/Adsense/AdsensePlugin.php index ab2b9a6fb..cd6fc3503 100644 --- a/plugins/Adsense/AdsensePlugin.php +++ b/plugins/Adsense/AdsensePlugin.php @@ -83,6 +83,21 @@ class AdsensePlugin extends UAPPlugin public $adScript = 'http://pagead2.googlesyndication.com/pagead/show_ads.js'; public $client = null; + function initialize() + { + parent::initialize(); + + // A little bit of chicanery so we avoid overwriting values that + // are passed in with the constructor + + foreach (array('mediumRectangle', 'rectangle', 'leaderboard', 'wideSkyscraper', 'adScript', 'client') as $setting) { + $value = common_config('adsense', strtolower($setting)); + if (!empty($value)) { // not found + $this->$setting = $value; + } + } + } + /** * Show a medium rectangle 'ad' * @@ -157,4 +172,37 @@ class AdsensePlugin extends UAPPlugin $action->script($this->adScript); } + + function onRouterInitialized($m) + { + $m->connect('admin/adsense', + array('action' => 'adsenseadminpanel')); + + return true; + } + + function onAutoload($cls) + { + $dir = dirname(__FILE__); + + switch ($cls) + { + case 'AdsenseadminpanelAction': + require_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php'; + return false; + default: + return true; + } + } + + function onEndAdminPanelNav($menu) { + if (AdminPanelAction::canAdmin('adsense')) { + // TRANS: Menu item title/tooltip + $menu_title = _('Adsense configuration'); + // TRANS: Menu item for site administration + $menu->out->menuItem(common_local_url('adsenseadminpanel'), _('Adsense'), + $menu_title, $action_name == 'adsenseadminpanel', 'nav_adsense_admin_panel'); + } + return true; + } } \ No newline at end of file diff --git a/plugins/Adsense/adsenseadminpanel.php b/plugins/Adsense/adsenseadminpanel.php new file mode 100644 index 000000000..7b99cf805 --- /dev/null +++ b/plugins/Adsense/adsenseadminpanel.php @@ -0,0 +1,223 @@ +. + * + * @category Adsense + * @package StatusNet + * @author Evan Prodromou + * @copyright 2010 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); +} + +/** + * Administer adsense settings + * + * @category Adsense + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +class AdsenseadminpanelAction extends AdminPanelAction +{ + /** + * Returns the page title + * + * @return string page title + */ + + function title() + { + return _('Adsense'); + } + + /** + * Instructions for using this form. + * + * @return string instructions + */ + + function getInstructions() + { + return _('Adsense settings for this StatusNet site'); + } + + /** + * Show the site admin panel form + * + * @return void + */ + + function showForm() + { + $form = new AdsenseAdminPanelForm($this); + $form->show(); + return; + } + + /** + * Save settings from the form + * + * @return void + */ + + function saveSettings() + { + static $settings = array('adsense' => array('adScript', 'client', 'mediumRectangle', 'rectangle', 'leaderboard', 'wideSkyscraper')); + + $values = array(); + + foreach ($settings as $section => $parts) { + foreach ($parts as $setting) { + $values[$section][$setting] = $this->trimmed($setting); + } + } + + // This throws an exception on validation errors + + $this->validate($values); + + // assert(all values are valid); + + $config = new Config(); + + $config->query('BEGIN'); + + foreach ($settings as $section => $parts) { + foreach ($parts as $setting) { + Config::save($section, $setting, $values[$section][$setting]); + } + } + + $config->query('COMMIT'); + + return; + } + + function validate(&$values) + { + } +} + +/** + * Form for the adsense admin panel + */ + +class AdsenseAdminPanelForm extends AdminForm +{ + /** + * ID of the form + * + * @return int ID of the form + */ + + function id() + { + return 'form_adsense_admin_panel'; + } + + /** + * class of the form + * + * @return string class of the form + */ + + function formClass() + { + return 'form_adsense'; + } + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + return common_local_url('adsenseadminpanel'); + } + + /** + * Data elements of the form + * + * @return void + */ + + function formData() + { + $this->out->elementStart('fieldset', array('id' => 'adsense_admin')); + $this->out->elementStart('ul', 'form_data'); + $this->li(); + $this->input('client', + _('Client ID'), + _('Google client ID'), + 'adsense'); + $this->unli(); + $this->li(); + $this->input('adScript', + _('Ad Script URL'), + _('Script URL (advanced)'), + 'adsense'); + $this->unli(); + $this->li(); + $this->input('mediumRectangle', + _('Medium rectangle'), + _('Medium rectangle slot code'), + 'adsense'); + $this->unli(); + $this->li(); + $this->input('rectangle', + _('Rectangle'), + _('Rectangle slot code'), + 'adsense'); + $this->unli(); + $this->li(); + $this->input('leaderboard', + _('Leaderboard'), + _('Leaderboard slot code'), + 'adsense'); + $this->unli(); + $this->li(); + $this->input('wideSkyscraper', + _('Skyscraper'), + _('Wide skyscraper slot code'), + 'adsense'); + $this->unli(); + $this->out->elementEnd('ul'); + } + + /** + * Action elements + * + * @return void + */ + + function formActions() + { + $this->out->submit('submit', _('Save'), 'submit', null, _('Save AdSense settings')); + } +} -- cgit v1.2.3-54-g00ecf From 84726791d33f63ba229aeba8b3c6035244ad2899 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 30 Jul 2010 14:12:37 -0700 Subject: Fix for ticket #2286: [mobile] Text extends beyond border of repeat confirmation dialog floater box on iPhone http://status.net/open-source/issues/2286 This bit of CSS was constricting the vertical size of the popup form for repeats: .notice-options form { width:16px; height:16px; } I can only assume this was originally meant to constrain the mini inline AJAX forms to the size of the clickable buttons, but it doesn't make a difference to how those are displayed on iPhone, Android, or Opera Mini. Removing the statement lets the popup form go to its natural size, covering the button. --- plugins/MobileProfile/mp-screen.css | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'plugins') diff --git a/plugins/MobileProfile/mp-screen.css b/plugins/MobileProfile/mp-screen.css index 0fc801612..1f70b5612 100644 --- a/plugins/MobileProfile/mp-screen.css +++ b/plugins/MobileProfile/mp-screen.css @@ -2,7 +2,7 @@ * * @package StatusNet * @author Sarven Capadisli - * @copyright 2009 StatusNet, Inc. + * @copyright 2009-2010 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/ */ @@ -195,10 +195,6 @@ width:43px; margin-right:1%; } -.notice-options form { -width:16px; -height:16px; -} .notice-options form.processing { background-image:none; } -- cgit v1.2.3-54-g00ecf From 517c7483d1b55fcc78b1d69e8ffd7de763faa772 Mon Sep 17 00:00:00 2001 From: James Walker Date: Mon, 2 Aug 2010 13:23:55 -0400 Subject: move to rel="salmon" (per latest spec) --- plugins/OStatus/OStatusPlugin.php | 3 +++ plugins/OStatus/lib/salmon.php | 4 +++- plugins/OStatus/lib/xrdaction.php | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php index c61e2cc5f..c735c02db 100644 --- a/plugins/OStatus/OStatusPlugin.php +++ b/plugins/OStatus/OStatusPlugin.php @@ -158,6 +158,9 @@ class OStatusPlugin extends Plugin // Also, we'll add in the salmon link $salmon = common_local_url($salmonAction, array('id' => $id)); + $feed->addLink($salmon, array('rel' => Salmon::REL_SALMON)); + + // XXX: these are deprecated $feed->addLink($salmon, array('rel' => Salmon::NS_REPLIES)); $feed->addLink($salmon, array('rel' => Salmon::NS_MENTIONS)); } diff --git a/plugins/OStatus/lib/salmon.php b/plugins/OStatus/lib/salmon.php index 3d3341bc6..ef7719a40 100644 --- a/plugins/OStatus/lib/salmon.php +++ b/plugins/OStatus/lib/salmon.php @@ -28,9 +28,11 @@ */ class Salmon { + const REL_SALMON = 'salmon'; + const REL_MENTIONED = 'mentioned'; + // XXX: these are deprecated const NS_REPLIES = "http://salmon-protocol.org/ns/salmon-replies"; - const NS_MENTIONS = "http://salmon-protocol.org/ns/salmon-mention"; /** diff --git a/plugins/OStatus/lib/xrdaction.php b/plugins/OStatus/lib/xrdaction.php index f1a56e0a8..71c70b96e 100644 --- a/plugins/OStatus/lib/xrdaction.php +++ b/plugins/OStatus/lib/xrdaction.php @@ -76,6 +76,9 @@ class XrdAction extends Action $salmon_url = common_local_url('usersalmon', array('id' => $this->user->id)); + $xrd->links[] = array('rel' => Salmon::REL_SALMON, + 'href' => $salmon_url); + // XXX : Deprecated - to be removed. $xrd->links[] = array('rel' => Salmon::NS_REPLIES, 'href' => $salmon_url); -- cgit v1.2.3-54-g00ecf From 56294016a753c43c366bf4680da28a17cccc21d5 Mon Sep 17 00:00:00 2001 From: James Walker Date: Mon, 2 Aug 2010 14:47:13 -0400 Subject: fix #2478 - ensure all XRD documents get proper content-type headers --- plugins/OStatus/actions/hostmeta.php | 3 +-- plugins/OStatus/lib/xrdaction.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'plugins') diff --git a/plugins/OStatus/actions/hostmeta.php b/plugins/OStatus/actions/hostmeta.php index 6d35ada6c..8ca07f916 100644 --- a/plugins/OStatus/actions/hostmeta.php +++ b/plugins/OStatus/actions/hostmeta.php @@ -35,14 +35,13 @@ class HostMetaAction extends Action $url = common_local_url('userxrd'); $url.= '?uri={uri}'; - $xrd = new XRD(); - $xrd = new XRD(); $xrd->host = $domain; $xrd->links[] = array('rel' => Discovery::LRDD_REL, 'template' => $url, 'title' => array('Resource Descriptor')); + header('Content-type: application/xrd+xml'); print $xrd->toXML(); } } diff --git a/plugins/OStatus/lib/xrdaction.php b/plugins/OStatus/lib/xrdaction.php index 71c70b96e..d8cf648d6 100644 --- a/plugins/OStatus/lib/xrdaction.php +++ b/plugins/OStatus/lib/xrdaction.php @@ -101,7 +101,7 @@ class XrdAction extends Action $xrd->links[] = array('rel' => 'http://ostatus.org/schema/1.0/subscribe', 'template' => $url ); - header('Content-type: text/xml'); + header('Content-type: application/xrd+xml'); print $xrd->toXML(); } -- cgit v1.2.3-54-g00ecf From c56939d59632560e93d1e4f3b29713c3cfdb61c6 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 2 Aug 2010 13:00:50 -0700 Subject: Remove the 'Enable Twitter import' checkbox from Twitter admin panel by default; can be re-added with setting: addPlugin('TwitterBridge', array('adminImportControl' => true, ....)); Added a note on the label that it requires manual daemon setup. (Note that by default the admin panel won't be shown, so it's no biggie to be hiding this for now.) --- plugins/TwitterBridge/TwitterBridgePlugin.php | 13 ++++++++++++ plugins/TwitterBridge/twitteradminpanel.php | 29 ++++++++++++++++++--------- 2 files changed, 33 insertions(+), 9 deletions(-) (limited to 'plugins') diff --git a/plugins/TwitterBridge/TwitterBridgePlugin.php b/plugins/TwitterBridge/TwitterBridgePlugin.php index 65b3a6b38..0505a328f 100644 --- a/plugins/TwitterBridge/TwitterBridgePlugin.php +++ b/plugins/TwitterBridge/TwitterBridgePlugin.php @@ -50,6 +50,7 @@ class TwitterBridgePlugin extends Plugin { const VERSION = STATUSNET_VERSION; + public $adminImportControl = false; // Should the 'import' checkbox be exposed in the admin panel? /** * Initializer for the plugin. @@ -322,5 +323,17 @@ class TwitterBridgePlugin extends Plugin return true; } + /** + * Expose the adminImportControl setting to the administration panel code. + * This allows us to disable the import bridge enabling checkbox for administrators, + * since on a bulk farm site we can't yet automate the import daemon setup. + * + * @return boolean hook value; + */ + function onTwitterBridgeAdminImportControl() + { + return (bool)$this->adminImportControl; + } + } diff --git a/plugins/TwitterBridge/twitteradminpanel.php b/plugins/TwitterBridge/twitteradminpanel.php index a78a92c66..69f8da078 100644 --- a/plugins/TwitterBridge/twitteradminpanel.php +++ b/plugins/TwitterBridge/twitteradminpanel.php @@ -92,9 +92,11 @@ class TwitteradminpanelAction extends AdminPanelAction ); static $booleans = array( - 'twitter' => array('signin'), - 'twitterimport' => array('enabled') + 'twitter' => array('signin') ); + if (Event::handle('TwitterBridgeAdminImportControl')) { + $booleans['twitterimport'] = array('enabled'); + } $values = array(); @@ -155,6 +157,13 @@ class TwitteradminpanelAction extends AdminPanelAction ); } } + + function isImportEnabled() + { + // Since daemon setup isn't automated yet... + // @todo: if merged into main queues, detect presence of daemon config + return true; + } } class TwitterAdminPanelForm extends AdminForm @@ -263,13 +272,15 @@ class TwitterAdminPanelForm extends AdminForm ); $this->unli(); - $this->li(); - $this->out->checkbox( - 'enabled', _m('Enable Twitter import'), - (bool) $this->value('enabled', 'twitterimport'), - _m('Allow users to import their Twitter friends\' timelines') - ); - $this->unli(); + if (Event::handle('TwitterBridgeAdminImportControl')) { + $this->li(); + $this->out->checkbox( + 'enabled', _m('Enable Twitter import'), + (bool) $this->value('enabled', 'twitterimport'), + _m('Allow users to import their Twitter friends\' timelines. Requires daemons to be manually configured.') + ); + $this->unli(); + } $this->out->elementEnd('ul'); -- cgit v1.2.3-54-g00ecf From 8120842780319089f47144acf82685163237b8bc Mon Sep 17 00:00:00 2001 From: James Walker Date: Mon, 2 Aug 2010 16:42:28 -0400 Subject: Fix for #2429 - move OStatus XML writing to XMLStringer --- plugins/OStatus/lib/magicenvelope.php | 28 ++++------- plugins/OStatus/lib/xrd.php | 94 ++++++++++++----------------------- 2 files changed, 44 insertions(+), 78 deletions(-) (limited to 'plugins') diff --git a/plugins/OStatus/lib/magicenvelope.php b/plugins/OStatus/lib/magicenvelope.php index f39686b71..3bdf24b31 100644 --- a/plugins/OStatus/lib/magicenvelope.php +++ b/plugins/OStatus/lib/magicenvelope.php @@ -97,24 +97,18 @@ class MagicEnvelope } public function toXML($env) { - $dom = new DOMDocument(); - - $envelope = $dom->createElementNS(MagicEnvelope::NS, 'me:env'); - $envelope->setAttribute('xmlns:me', MagicEnvelope::NS); - $data = $dom->createElementNS(MagicEnvelope::NS, 'me:data', $env['data']); - $data->setAttribute('type', $env['data_type']); - $envelope->appendChild($data); - $enc = $dom->createElementNS(MagicEnvelope::NS, 'me:encoding', $env['encoding']); - $envelope->appendChild($enc); - $alg = $dom->createElementNS(MagicEnvelope::NS, 'me:alg', $env['alg']); - $envelope->appendChild($alg); - $sig = $dom->createElementNS(MagicEnvelope::NS, 'me:sig', $env['sig']); - $envelope->appendChild($sig); - - $dom->appendChild($envelope); + $xs = new XMLStringer(); + $xs->startXML(); + $xs->elementStart('me:env', array('xmlns:me' => MagicEnvelope::NS)); + $xs->element('me:data', array('type' => $env['data_type']), $env['data']); + $xs->element('me:encoding', null, $env['encoding']); + $xs->element('me:alg', null, $env['alg']); + $xs->element('me:sig', null, $env['sig']); + $xs->elementEnd('me:env'); - - return $dom->saveXML(); + $string = $xs->getString(); + common_debug($string); + return $string; } diff --git a/plugins/OStatus/lib/xrd.php b/plugins/OStatus/lib/xrd.php index 34b28790b..a10b9f427 100644 --- a/plugins/OStatus/lib/xrd.php +++ b/plugins/OStatus/lib/xrd.php @@ -106,44 +106,43 @@ class XRD public function toXML() { - $dom = new DOMDocument('1.0', 'UTF-8'); - $dom->formatOutput = true; - - $xrd_dom = $dom->createElementNS(XRD::XRD_NS, 'XRD'); - $dom->appendChild($xrd_dom); + $xs = new XMLStringer(); + + $xs->startXML(); + $xs->elementStart('XRD', array('xmlns' => XRD::XRD_NS)); if ($this->host) { - $host_dom = $dom->createElement('hm:Host', $this->host); - $xrd_dom->setAttributeNS(XRD::XML_NS, 'xmlns:hm', XRD::HOST_META_NS); - $xrd_dom->appendChild($host_dom); + $xs->element('hm:Host', array('xmlns:hm' => XRD::HOST_META_NS), $this->host); } - if ($this->expires) { - $expires_dom = $dom->createElement('Expires', $this->expires); - $xrd_dom->appendChild($expires_dom); - } - - if ($this->subject) { - $subject_dom = $dom->createElement('Subject', $this->subject); - $xrd_dom->appendChild($subject_dom); - } - - foreach ($this->alias as $alias) { - $alias_dom = $dom->createElement('Alias', $alias); - $xrd_dom->appendChild($alias_dom); - } - - foreach ($this->types as $type) { - $type_dom = $dom->createElement('Type', $type); - $xrd_dom->appendChild($type_dom); - } - - foreach ($this->links as $link) { - $link_dom = $this->saveLink($dom, $link); - $xrd_dom->appendChild($link_dom); - } - - return $dom->saveXML(); + if ($this->expires) { + $xs->element('Expires', null, $this->expires); + } + + if ($this->subject) { + $xs->element('Subject', null, $this->subject); + } + + foreach ($this->alias as $alias) { + $xs->element('Alias', null, $alias); + } + + foreach ($this->links as $link) { + $titles = array(); + if (isset($link['title'])) { + $titles = $link['title']; + unset($link['title']); + } + $xs->elementStart('Link', $link); + foreach ($titles as $title) { + $xs->element('Title', null, $title); + } + $xs->elementEnd('Link'); + } + + $xs->elementEnd('XRD'); + + return $xs->getString(); } function parseType($element) @@ -169,32 +168,5 @@ class XRD return $link; } - - function saveLink($doc, $link) - { - $link_element = $doc->createElement('Link'); - if (!empty($link['rel'])) { - $link_element->setAttribute('rel', $link['rel']); - } - if (!empty($link['type'])) { - $link_element->setAttribute('type', $link['type']); - } - if (!empty($link['href'])) { - $link_element->setAttribute('href', $link['href']); - } - if (!empty($link['template'])) { - $link_element->setAttribute('template', $link['template']); - } - - if (!empty($link['title']) && is_array($link['title'])) { - foreach($link['title'] as $title) { - $title = $doc->createElement('Title', $title); - $link_element->appendChild($title); - } - } - - - return $link_element; - } } -- cgit v1.2.3-54-g00ecf From f83171824f835ff9cd24bf0aea26f13c62b806cf Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 3 Aug 2010 15:50:21 -0700 Subject: correctly show for atom feeds --- classes/Notice.php | 48 ++++++++++++++++++++++++++------------- classes/Profile.php | 29 +++++++++++++++++------ plugins/OStatus/OStatusPlugin.php | 12 ++++++++++ 3 files changed, 66 insertions(+), 23 deletions(-) (limited to 'plugins') diff --git a/classes/Notice.php b/classes/Notice.php index f6e9eb585..61844d487 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1215,29 +1215,45 @@ class Notice extends Memcached_DataObject if ($source) { - $xs->elementStart('source'); + $atom_feed = $profile->getAtomFeed(); - $xs->element('id', null, $profile->profileurl); - $xs->element('title', null, $profile->nickname . " - " . common_config('site', 'name')); - $xs->element('link', array('href' => $profile->profileurl)); + if (!empty($atom_feed)) { - $user = User::staticGet('id', $profile->id); + $xs->elementStart('source'); + + // XXX: we should store the actual feed ID + + $xs->element('id', null, $atom_feed); + + // XXX: we should store the actual feed title + + $xs->element('title', null, $profile->getBestName()); + + $xs->element('link', array('rel' => 'alternate', + 'type' => 'text/html', + 'href' => $profile->profileurl)); - if (!empty($user)) { - $atom_feed = common_local_url('ApiTimelineUser', - array('format' => 'atom', - 'id' => $profile->nickname)); $xs->element('link', array('rel' => 'self', 'type' => 'application/atom+xml', - 'href' => $profile->profileurl)); - $xs->element('link', array('rel' => 'license', - 'href' => common_config('license', 'url'))); - } + 'href' => $atom_feed)); - $xs->element('icon', null, $profile->avatarUrl(AVATAR_PROFILE_SIZE)); - $xs->element('updated', null, common_date_w3dtf($this->created)); // FIXME: not true! + $xs->element('icon', null, $profile->avatarUrl(AVATAR_PROFILE_SIZE)); - $xs->elementEnd('source'); + $notice = $profile->getCurrentNotice(); + + if (!empty($notice)) { + $xs->element('updated', null, common_date_w3dtf($notice->created)); + } + + $user = User::staticGet('id', $profile->id); + + if (!empty($user)) { + $xs->element('link', array('rel' => 'license', + 'href' => common_config('license', 'url'))); + } + + $xs->elementEnd('source'); + } } Event::handle('EndActivitySource', array(&$this, &$xs)); } diff --git a/classes/Profile.php b/classes/Profile.php index a303469e9..abd6eb031 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -152,17 +152,16 @@ class Profile extends Memcached_DataObject * * @return mixed Notice or null */ + function getCurrentNotice() { - $notice = new Notice(); - $notice->profile_id = $this->id; - // @fixme change this to sort on notice.id only when indexes are updated - $notice->orderBy('created DESC, notice.id DESC'); - $notice->limit(1); - if ($notice->find(true)) { + $notice = $this->getNotices(0, 1); + + if ($notice->fetch()) { return $notice; + } else { + return null; } - return null; } function getTaggedNotices($tag, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0) @@ -943,4 +942,20 @@ class Profile extends Memcached_DataObject return $result; } + + function getAtomFeed() + { + $feed = null; + + if (Event::handle('StartProfileGetAtomFeed', array($this, &$feed))) { + $user = User::staticGet('id', $this->id); + if (!empty($user)) { + $feed = common_local_url('ApiTimelineUser', array('id' => $user->id, + 'format' => 'atom')); + } + Event::handle('EndProfileGetAtomFeed', array($this, $feed)); + } + + return $feed; + } } diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php index c61e2cc5f..4fc9d4108 100644 --- a/plugins/OStatus/OStatusPlugin.php +++ b/plugins/OStatus/OStatusPlugin.php @@ -953,4 +953,16 @@ class OStatusPlugin extends Plugin } return false; } + + public function onStartProfileGetAtomFeed($profile, &$feed) + { + $oprofile = Ostatus_profile::staticGet('profile_id', $profile->id); + + if (empty($oprofile)) { + return true; + } + + $feed = $oprofile->feeduri; + return false; + } } -- cgit v1.2.3-54-g00ecf From 300ed65d301d21c33a5f0a196d6acfe762a34f29 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 5 Aug 2010 13:37:47 -0700 Subject: SubMirror plugin initial checkin: allows setting up automatic mirroring of posts from any of your subscriptions into your own stream, either via repeat or by copying the text. The UI for setup and editing is a bit nasty for now. Can be reached via 'Mirroring' tab in account settings, or from a link at top of subscriptions list. Currently relies on the OStatus plugin to handle actual setup, parsing, and importing of feeds; to support more general feed formatting we may need some further work there to accept weird feeds. Also requires an actual live subscription, but this could be changed in future. (Ensuring that PSHB feed subscriptions remain live even if nobody's directly subscribed might be tricky.) The repeat style is our preferred method since it retains full attribution, but right now we don't handle repeats very well across site boundaries; when pushed out to Twitter or to other StatusNet instances via OStatus, currently we end up losing some of the data and can end up with the 'RT @blah' version. WARNING: There's no loop detection yet; it's most likely possible to set up a fun loop of profiles repeating each others' stuff forever and ever and ever and ever... --- plugins/SubMirror/SubMirrorPlugin.php | 149 +++++++++++++++++++ plugins/SubMirror/actions/addmirror.php | 155 +++++++++++++++++++ plugins/SubMirror/actions/editmirror.php | 105 +++++++++++++ plugins/SubMirror/actions/mirrorsettings.php | 105 +++++++++++++ plugins/SubMirror/classes/SubMirror.php | 213 +++++++++++++++++++++++++++ plugins/SubMirror/lib/addmirrorform.php | 171 +++++++++++++++++++++ plugins/SubMirror/lib/editmirrorform.php | 189 ++++++++++++++++++++++++ plugins/SubMirror/lib/mirrorqueuehandler.php | 44 ++++++ 8 files changed, 1131 insertions(+) create mode 100644 plugins/SubMirror/SubMirrorPlugin.php create mode 100644 plugins/SubMirror/actions/addmirror.php create mode 100644 plugins/SubMirror/actions/editmirror.php create mode 100644 plugins/SubMirror/actions/mirrorsettings.php create mode 100644 plugins/SubMirror/classes/SubMirror.php create mode 100644 plugins/SubMirror/lib/addmirrorform.php create mode 100644 plugins/SubMirror/lib/editmirrorform.php create mode 100644 plugins/SubMirror/lib/mirrorqueuehandler.php (limited to 'plugins') diff --git a/plugins/SubMirror/SubMirrorPlugin.php b/plugins/SubMirror/SubMirrorPlugin.php new file mode 100644 index 000000000..8678cc3dd --- /dev/null +++ b/plugins/SubMirror/SubMirrorPlugin.php @@ -0,0 +1,149 @@ +. + */ + +/** + * @package SubMirrorPlugin + * @maintainer Brion Vibber + */ + +if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } + + +class SubMirrorPlugin extends Plugin +{ + /** + * Hook for RouterInitialized event. + * + * @param Net_URL_Mapper $m path-to-action mapper + * @return boolean hook return + */ + function onRouterInitialized($m) + { + $m->connect('settings/mirror', + array('action' => 'mirrorsettings')); + $m->connect('settings/mirror/add', + array('action' => 'addmirror')); + $m->connect('settings/mirror/edit', + array('action' => 'editmirror')); + return true; + } + + /** + * Automatically load the actions and libraries used by the plugin + * + * @param Class $cls the class + * + * @return boolean hook return + * + */ + function onAutoload($cls) + { + $base = dirname(__FILE__); + $lower = strtolower($cls); + $files = array("$base/lib/$lower.php", + "$base/classes/$cls.php"); + if (substr($lower, -6) == 'action') { + $files[] = "$base/actions/" . substr($lower, 0, -6) . ".php"; + } + foreach ($files as $file) { + if (file_exists($file)) { + include_once $file; + return false; + } + } + return true; + } + + function handle($notice) + { + // Is anybody mirroring? + $mirror = new SubMirror(); + $mirror->subscribed = $notice->profile_id; + if ($mirror->find()) { + while ($mirror->fetch()) { + $mirror->repeat($notice); + } + } + } + + function onPluginVersion(&$versions) + { + $versions[] = array('name' => 'SubMirror', + 'version' => STATUSNET_VERSION, + 'author' => 'Brion Vibber', + 'homepage' => 'http://status.net/wiki/Plugin:SubMirror', + 'rawdescription' => + _m('Pull feeds into your timeline!')); + + return true; + } + + /** + * Menu item for settings + * + * @param Action &$action Action being executed + * + * @return boolean hook return + */ + + function onEndAccountSettingsNav(&$action) + { + $action_name = $action->trimmed('action'); + + $action->menuItem(common_local_url('mirrorsettings'), + // TRANS: SubMirror plugin menu item on user settings page. + _m('MENU', 'Mirroring'), + // TRANS: SubMirror plugin tooltip for user settings menu item. + _m('Configure mirroring of posts from other feeds'), + $action_name === 'mirrorsettings'); + + return true; + } + + function onCheckSchema() + { + $schema = Schema::get(); + $schema->ensureTable('submirror', SubMirror::schemaDef()); + return true; + } + + /** + * Set up queue handlers for outgoing hub pushes + * @param QueueManager $qm + * @return boolean hook return + */ + function onEndInitializeQueueManager(QueueManager $qm) + { + // After each notice save, check if there's any repeat mirrors. + $qm->connect('mirror', 'MirrorQueueHandler'); + return true; + } + + function onStartEnqueueNotice($notice, &$transports) + { + $transports[] = 'mirror'; + } + + function onStartShowSubscriptionsContent($action) + { + $action->element('a', + array('href' => common_local_url('mirrorsettings')), + _m('Set up mirroring options...')); + } +} diff --git a/plugins/SubMirror/actions/addmirror.php b/plugins/SubMirror/actions/addmirror.php new file mode 100644 index 000000000..df6939491 --- /dev/null +++ b/plugins/SubMirror/actions/addmirror.php @@ -0,0 +1,155 @@ +. + * + * PHP version 5 + * + * @category Action + * @package StatusNet + * @author Brion Vibber + * @copyright 2010 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + exit(1); +} + +/** + * Takes parameters: + * + * - feed: a profile ID + * - token: session token to prevent CSRF attacks + * - ajax: boolean; whether to return Ajax or full-browser results + * + * Only works if the current user is logged in. + * + * @category Action + * @package StatusNet + * @copyright 2010 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3 + * @link http://status.net/ + */ + +class AddMirrorAction extends Action +{ + var $user; + var $feedurl; + + /** + * Check pre-requisites and instantiate attributes + * + * @param Array $args array of arguments (URL, GET, POST) + * + * @return boolean success flag + */ + + function prepare($args) + { + parent::prepare($args); + $ok = $this->sharedBoilerplate(); + if ($ok) { + // and now do something useful! + $this->profile = $this->validateProfile($this->trimmed('profile')); + return true; + } else { + return $ok; + } + } + + function validateProfile($id) + { + $id = intval($id); + $profile = Profile::staticGet('id', $id); + if ($profile && $profile->id != $this->user->id) { + return $profile; + } + // TRANS: Error message returned to user when setting up feed mirroring, but we were unable to resolve the given URL to a working feed. + $this->clientError(_m("Invalid profile for mirroring.")); + } + + /** + * @fixme none of this belongs in end classes + * this stuff belongs in shared code! + */ + function sharedBoilerplate() + { + // Only allow POST requests + + if ($_SERVER['REQUEST_METHOD'] != 'POST') { + $this->clientError(_('This action only accepts POST requests.')); + return false; + } + + // CSRF protection + + $token = $this->trimmed('token'); + + if (!$token || $token != common_session_token()) { + $this->clientError(_('There was a problem with your session token.'. + ' Try again, please.')); + return false; + } + + // Only for logged-in users + + $this->user = common_current_user(); + + if (empty($this->user)) { + $this->clientError(_('Not logged in.')); + return false; + } + return true; + } + + /** + * Handle request + * + * Does the subscription and returns results. + * + * @param Array $args unused. + * + * @return void + */ + + function handle($args) + { + // Throws exception on error + $this->saveMirror(); + + if ($this->boolean('ajax')) { + $this->startHTML('text/xml;charset=utf-8'); + $this->elementStart('head'); + $this->element('title', null, _('Subscribed')); + $this->elementEnd('head'); + $this->elementStart('body'); + $unsubscribe = new EditMirrorForm($this, $this->profile); + $unsubscribe->show(); + $this->elementEnd('body'); + $this->elementEnd('html'); + } else { + $url = common_local_url('mirrorsettings'); + common_redirect($url, 303); + } + } + + function saveMirror() + { + SubMirror::saveMirror($this->user, $this->profile); + } +} diff --git a/plugins/SubMirror/actions/editmirror.php b/plugins/SubMirror/actions/editmirror.php new file mode 100644 index 000000000..7ddd32ef3 --- /dev/null +++ b/plugins/SubMirror/actions/editmirror.php @@ -0,0 +1,105 @@ +. + * + * PHP version 5 + * + * @category Action + * @package StatusNet + * @author Brion Vibber + * @copyright 2010 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + exit(1); +} + +/** + * Takes parameters: + * + * - feed: a profile ID + * - token: session token to prevent CSRF attacks + * - ajax: boolean; whether to return Ajax or full-browser results + * + * Only works if the current user is logged in. + * + * @category Action + * @package StatusNet + * @copyright 2010 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3 + * @link http://status.net/ + */ + +class EditMirrorAction extends AddMirrorAction +{ + + /** + * Check pre-requisites and instantiate attributes + * + * @param Array $args array of arguments (URL, GET, POST) + * + * @return boolean success flag + */ + + function prepare($args) + { + parent::prepare($args); + $this->mirror = SubMirror::pkeyGet(array('subscriber' => $this->user->id, + 'subscribed' => $this->profile->id)); + + if (!$this->mirror) { + $this->clientError(_m("Requested invalid profile to edit.")); + } + + $this->style = $this->validateStyle($this->trimmed('style')); + + // DO NOT change to $this->boolean(), it will be wrong. + // We're checking for the presence of the setting, not its value. + $this->delete = (bool)$this->arg('delete'); + + return true; + } + + protected function validateStyle($style) + { + $allowed = array('repeat', 'copy'); + if (in_array($style, $allowed)) { + return $style; + } else { + $this->clientError(_m("Bad form data.")); + } + } + + function saveMirror() + { + $mirror = SubMirror::getMirror($this->user, $this->profile); + if (!$mirror) { + $this->clientError(_m('Requested edit of missing mirror')); + } + + if ($this->delete) { + $mirror->delete(); + } else if ($this->style != $mirror->style) { + $orig = clone($mirror); + $mirror->style = $this->style; + $mirror->modified = common_sql_now(); + $mirror->update($orig); + } + } +} diff --git a/plugins/SubMirror/actions/mirrorsettings.php b/plugins/SubMirror/actions/mirrorsettings.php new file mode 100644 index 000000000..edb024183 --- /dev/null +++ b/plugins/SubMirror/actions/mirrorsettings.php @@ -0,0 +1,105 @@ +. + * + * @category Plugins + * @package StatusNet + * @author Brion Vibber + * @copyright 2010 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') && !defined('LACONICA')) { + exit(1); +} + +class MirrorSettingsAction extends AccountSettingsAction +{ + /** + * Title of the page + * + * @return string Page title + */ + + function title() + { + return _m('Feed mirror settings'); + } + + /** + * Instructions for use + * + * @return string Instructions for use + */ + + function getInstructions() + { + return _m('You can mirror updates from your RSS and Atom feeds ' . + 'into your StatusNet timeline!'); + } + + /** + * Show the form for OpenID management + * + * We have one form with a few different submit buttons to do different things. + * + * @return void + */ + + function showContent() + { + $user = common_current_user(); + + $mirror = new SubMirror(); + $mirror->subscriber = $user->id; + if ($mirror->find()) { + while ($mirror->fetch()) { + $this->showFeedForm($mirror); + } + } + $this->showAddFeedForm(); + } + + function showFeedForm($mirror) + { + $profile = Profile::staticGet('id', $mirror->subscribed); + if ($profile) { + $form = new EditMirrorForm($this, $profile); + $form->show(); + } + } + + function showAddFeedForm() + { + $form = new AddMirrorForm($this); + $form->show(); + } + + /** + * Handle a POST request + * + * Muxes to different sub-functions based on which button was pushed + * + * @return void + */ + + function handlePost() + { + } +} diff --git a/plugins/SubMirror/classes/SubMirror.php b/plugins/SubMirror/classes/SubMirror.php new file mode 100644 index 000000000..4e7e005db --- /dev/null +++ b/plugins/SubMirror/classes/SubMirror.php @@ -0,0 +1,213 @@ +. + */ + +/** + * @package SubMirrorPlugin + * @maintainer Brion Vibber + */ + +class SubMirror extends Memcached_DataObject +{ + public $__table = 'submirror'; + + public $subscriber; + public $subscribed; + + public $style; + + public $created; + public $modified; + + public /*static*/ function staticGet($k, $v=null) + { + return parent::staticGet(__CLASS__, $k, $v); + } + + /** + * return table definition for DB_DataObject + * + * DB_DataObject needs to know something about the table to manipulate + * instances. This method provides all the DB_DataObject needs to know. + * + * @return array array of column definitions + */ + + function table() + { + return array('subscriber' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL, + 'subscribed' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL, + + 'style' => DB_DATAOBJECT_STR, + + 'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL, + 'modified' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL); + } + + static function schemaDef() + { + // @fixme need a reverse key on (subscribed, subscriber) as well + return array(new ColumnDef('subscriber', 'integer', + null, false, 'PRI'), + new ColumnDef('subscribed', 'integer', + null, false, 'PRI'), + + new ColumnDef('style', 'varchar', + 16, true), + + new ColumnDef('created', 'datetime', + null, false), + new ColumnDef('modified', 'datetime', + null, false)); + } + + /** + * return key definitions for DB_DataObject + * + * DB_DataObject needs to know about keys that the table has; this function + * defines them. + * + * @return array key definitions + */ + + function keys() + { + return array_keys($this->keyTypes()); + } + + /** + * return key definitions for Memcached_DataObject + * + * Our caching system uses the same key definitions, but uses a different + * method to get them. + * + * @return array key definitions + */ + + function keyTypes() + { + // @fixme keys + // need a sane key for reverse lookup too + return array('subscriber' => 'K', 'subscribed' => 'K'); + } + + function sequenceKey() + { + return array(false, false, false); + } + + /** + * @param Profile $subscribed + * @param Profile $subscribed + * @return SubMirror + * @throws ServerException + */ + public static function saveMirror($subscriber, $subscribed, $style='repeat') + { + // @fixme make sure they're subscribed! + $mirror = new SubMirror(); + + $mirror->subscriber = $subscriber->id; + $mirror->subscribed = $subscribed->id; + $mirror->style = $style; + + $mirror->created = common_sql_now(); + $mirror->modified = common_sql_now(); + $mirror->insert(); + + return $mirror; + } + + /** + * @param Notice $notice + * @return mixed Notice on successful mirroring, boolean if not + */ + public function mirrorNotice($notice) + { + $profile = Profile::staticGet('id', $this->subscriber); + if (!$profile) { + common_log(LOG_ERROR, "SubMirror plugin skipping auto-repeat of notice $notice->id for missing user $profile->id"); + return false; + } + + if ($this->style == 'copy') { + return $this->copyNotice($profile, $notice); + } else { // default to repeat mode + return $this->repeatNotice($profile, $notice); + } + } + + /** + * Mirror a notice using StatusNet's repeat functionality. + * This retains attribution within the site, and other nice things, + * but currently ends up looking like 'RT @foobar bla bla' when + * bridged out over OStatus or TwitterBridge. + * + * @param Notice $notice + * @return mixed Notice on successful repeat, true if already repeated, false on failure + */ + protected function repeatNotice($profile, $notice) + { + if($profile->hasRepeated($notice->id)) { + common_log(LOG_INFO, "SubMirror plugin skipping auto-repeat of notice $notice->id for user $profile->id; already repeated."); + return true; + } else { + common_log(LOG_INFO, "SubMirror plugin auto-repeating notice $notice->id for $profile->id"); + return $notice->repeat($profile->id, 'mirror'); + } + } + + /** + * Mirror a notice by emitting a new notice with the same contents. + * Kind of dirty, but if pulling an external data feed into an account + * that may be what you want. + * + * @param Notice $notice + * @return mixed Notice on successful repeat, true if already repeated, false on failure + */ + protected function copyNotice($profile, $notice) + { + $options = array('is_local' => Notice::LOCAL_PUBLIC, + 'url' => $notice->bestUrl(), // pass through the foreign link... + 'rendered' => $notice->rendered); + + $saved = Notice::saveNew($profile->id, + $notice->content, + 'feed', + $options); + return $saved; + } + + public /*static*/ function pkeyGet($v) + { + return parent::pkeyGet(__CLASS__, $v); + } + + /** + * Get the mirroring setting for a pair of profiles, if existing. + * + * @param Profile $subscriber + * @param Profile $subscribed + * @return mixed Profile or empty + */ + public static function getMirror($subscriber, $subscribed) + { + return self::pkeyGet(array('subscriber' => $subscriber->id, + 'subscribed' => $subscribed->id)); + } +} diff --git a/plugins/SubMirror/lib/addmirrorform.php b/plugins/SubMirror/lib/addmirrorform.php new file mode 100644 index 000000000..9ee59661a --- /dev/null +++ b/plugins/SubMirror/lib/addmirrorform.php @@ -0,0 +1,171 @@ +. + * + * @package StatusNet + * @copyright 2010 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') && !defined('LACONICA')) { + exit(1); +} + +class AddMirrorForm extends Form +{ + + /** + * Name of the form + * + * Sub-classes should overload this with the name of their form. + * + * @return void + */ + + function formLegend() + { + } + + /** + * Visible or invisible data elements + * + * Display the form fields that make up the data of the form. + * Sub-classes should overload this to show their data. + * + * @return void + */ + + function formData() + { + $this->out->elementStart('fieldset'); + + $this->out->elementStart('ul'); + + $this->li(); + $this->out->element('label', array('for' => $this->id() . '-profile'), + _m("Mirror one of your existing subscriptions:")); + $this->out->elementStart('select', array('name' => 'profile')); + + $user = common_current_user(); + $profile = $user->getSubscriptions(); + while ($profile->fetch()) { + $mirror = SubMirror::pkeyGet(array('subscriber' => $user->id, + 'subscribed' => $profile->id)); + if (!$mirror) { + $this->out->element('option', + array('value' => $profile->id), + $profile->getBestName()); + } + } + $this->out->elementEnd('select'); + $this->out->submit($this->id() . '-save', _m('Save')); + $this->unli(); + + + $this->li(); + + $this->out->elementStart('fieldset', array('style' => 'width: 360px; margin-left: auto; margin-right: auto')); + $this->out->element('p', false, + _m("Not already subscribed to the feed you want? " . + "Add a new remote subscription and paste in the URL!")); + + $this->out->elementStart('div', 'entity_actions'); + $this->out->elementStart('p', array('id' => 'entity_remote_subscribe', + 'class' => 'entity_subscribe')); + $this->out->element('a', array('href' => common_local_url('ostatussub'), + 'class' => 'entity_remote_subscribe') + , _m('Remote')); + $this->out->elementEnd('p'); + $this->out->elementEnd('div'); + + $this->out->element('div', array('style' => 'clear: both')); + $this->out->elementEnd('fieldset'); + $this->unli(); + + $this->out->elementEnd('ul'); + $this->out->elementEnd('fieldset'); + } + + private function doInput($id, $name, $label, $value=null, $instructions=null) + { + $this->out->element('label', array('for' => $id), $label); + $attrs = array('name' => $name, + 'type' => 'text', + 'id' => $id); + if ($value) { + $attrs['value'] = $value; + } + $this->out->element('input', $attrs); + if ($instructions) { + $this->out->element('p', 'form_guide', $instructions); + } + } + + /** + * Buttons for form actions + * + * Submit and cancel buttons (or whatever) + * Sub-classes should overload this to show their own buttons. + * + * @return void + */ + + function formActions() + { + } + + /** + * ID of the form + * + * Should be unique on the page. Sub-classes should overload this + * to show their own IDs. + * + * @return string ID of the form + */ + + function id() + { + return 'add-mirror-form'; + } + + /** + * Action of the form. + * + * URL to post to. Should be overloaded by subclasses to give + * somewhere to post to. + * + * @return string URL to post to + */ + + function action() + { + return common_local_url('addmirror'); + } + + /** + * Class of the form. + * + * @return string the form's class + */ + + function formClass() + { + return 'form_settings'; + } + +} diff --git a/plugins/SubMirror/lib/editmirrorform.php b/plugins/SubMirror/lib/editmirrorform.php new file mode 100644 index 000000000..8236da389 --- /dev/null +++ b/plugins/SubMirror/lib/editmirrorform.php @@ -0,0 +1,189 @@ +. + * + * @package StatusNet + * @copyright 2010 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') && !defined('LACONICA')) { + exit(1); +} + +class EditMirrorForm extends Form +{ + function __construct($action, $profile) + { + parent::__construct($action); + + $this->profile = clone($profile); + $this->user = common_current_user(); + $this->mirror = SubMirror::pkeyGet(array('subscriber' => $this->user->id, + 'subscribed' => $this->profile->id)); + } + + /** + * Name of the form + * + * Sub-classes should overload this with the name of their form. + * + * @return void + */ + + function formLegend() + { + } + + /** + * Visible or invisible data elements + * + * Display the form fields that make up the data of the form. + * Sub-classes should overload this to show their data. + * + * @return void + */ + + function formData() + { + $this->out->elementStart('fieldset'); + + $this->out->hidden('profile', $this->profile->id); + + $this->out->elementStart('div', array('style' => 'float: left; width: 80px;')); + $img = $this->getAvatar($this->profile); + $feed = $this->getFeed($this->profile); + $this->out->elementStart('a', array('href' => $this->profile->profileurl)); + $this->out->element('img', array('src' => $img, 'style' => 'float: left')); + $this->out->elementEnd('a'); + $this->out->elementEnd('div'); + + + $this->out->elementStart('div', array('style' => 'margin-left: 80px; margin-right: 20px')); + $this->out->elementStart('p'); + $this->out->elementStart('div'); + $this->out->element('a', array('href' => $this->profile->profileurl), $this->profile->getBestName()); + $this->out->elementEnd('div'); + $this->out->elementStart('div'); + if ($feed) { + $this->out->text(_m('LABEL', 'Remote feed:') . ' '); + //$this->out->element('a', array('href' => $feed), $feed); + $this->out->element('input', array('value' => $feed, 'readonly' => 'readonly', 'style' => 'width: 100%')); + } else { + $this->out->text(_m('LABEL', 'Local user')); + } + $this->out->elementEnd('div'); + $this->out->elementEnd('p'); + + $this->out->elementStart('fieldset', array('style' => 'margin-top: 20px')); + $this->out->element('legend', false, _m("Mirroring style")); + + $styles = array('repeat' => _m("Repeat: reference the original user's post (sometimes shows as 'RT @blah')"), + 'copy' => _m("Repost the content under my account")); + foreach ($styles as $key => $label) { + $this->out->elementStart('div'); + $attribs = array('type' => 'radio', + 'value' => $key, + 'name' => 'style', + 'id' => $this->id() . '-style'); + if ($key == $this->mirror->style || ($key == 'repeat' && empty($this->mirror->style))) { + $attribs['checked'] = 'checked'; + } + $this->out->element('input', $attribs); + $this->out->element('span', false, $label); // @fixme should be label, but the styles muck it up for now + $this->out->elementEnd('div'); + + } + $this->out->elementEnd('fieldset'); + + + $this->out->elementStart('div'); + $this->out->submit($this->id() . '-save', _m('Save')); + $this->out->element('input', array('type' => 'submit', + 'value' => _m('Stop mirroring'), + 'name' => 'delete', + 'class' => 'submit')); + $this->out->elementEnd('div'); + + $this->out->elementEnd('div'); + $this->out->elementEnd('fieldset'); + } + + private function getAvatar($profile) + { + $avatar = $this->profile->getAvatar(48); + if ($avatar) { + return $avatar->displayUrl(); + } else { + return Avatar::defaultImage(48); + } + } + + private function getFeed($profile) + { + // Ok this is a bit of a hack. ;) + if (class_exists('Ostatus_profile')) { + $oprofile = Ostatus_profile::staticGet('profile_id', $profile->id); + if ($oprofile) { + return $oprofile->feeduri; + } + } + var_dump('wtf'); + return false; + } + + /** + * ID of the form + * + * Should be unique on the page. Sub-classes should overload this + * to show their own IDs. + * + * @return string ID of the form + */ + + function id() + { + return 'edit-mirror-form-' . $this->profile->id; + } + + /** + * Action of the form. + * + * URL to post to. Should be overloaded by subclasses to give + * somewhere to post to. + * + * @return string URL to post to + */ + + function action() + { + return common_local_url('editmirror'); + } + + /** + * Class of the form. + * + * @return string the form's class + */ + + function formClass() + { + return 'form_settings'; + } + +} diff --git a/plugins/SubMirror/lib/mirrorqueuehandler.php b/plugins/SubMirror/lib/mirrorqueuehandler.php new file mode 100644 index 000000000..0306180ee --- /dev/null +++ b/plugins/SubMirror/lib/mirrorqueuehandler.php @@ -0,0 +1,44 @@ +. + */ + +/** + * Check for subscription mirroring options on each newly seen post! + * + * @package SubMirror + * @author Brion Vibber + */ + +class MirrorQueueHandler extends QueueHandler +{ + function transport() + { + return 'mirror'; + } + + function handle($notice) + { + $mirror = new SubMirror(); + $mirror->subscribed = $notice->profile_id; + if ($mirror->find()) { + while ($mirror->fetch()) { + $mirror->mirrorNotice($notice); + } + } + } +} -- cgit v1.2.3-54-g00ecf From 7e55fc00447923b40b2ffc87329fd95347d776f5 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 6 Aug 2010 10:56:18 -0700 Subject: OStatus/FeedSub: tweaked PuSH feed garbage collection so other plugins can declare usage of a low-level feed or an OStatus profile besides profile subscriptions & group memberships. SubMirror: redid add-mirror frontend to accept a feed URL, then pass that on to OStatus, instead of pulling from your subscriptions. Profile: tweaked subscriberCount() so it doesn't subtract 1 for foreign profiles who aren't subscribed to themselves; instead excludes the self-subscription in the count query. Memcached_DataObject: tweak to avoid extra error spew in the DB error raising Work in progress: tweaking feedsub garbage collection so we can count other uses --- classes/Memcached_DataObject.php | 2 +- classes/Profile.php | 4 +- plugins/OStatus/OStatusPlugin.php | 18 ++++++ plugins/OStatus/classes/FeedSub.php | 30 +++++++++ plugins/OStatus/classes/Ostatus_profile.php | 45 ++++++++------ plugins/SubMirror/SubMirrorPlugin.php | 23 +++++++ plugins/SubMirror/actions/addmirror.php | 92 +++------------------------- plugins/SubMirror/actions/editmirror.php | 9 ++- plugins/SubMirror/actions/mirrorsettings.php | 5 +- plugins/SubMirror/lib/addmirrorform.php | 44 +++---------- 10 files changed, 124 insertions(+), 148 deletions(-) (limited to 'plugins') diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index 7768fe757..0f1ed0489 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -574,7 +574,7 @@ class Memcached_DataObject extends Safe_DataObject function raiseError($message, $type = null, $behaviour = null) { $id = get_class($this); - if ($this->id) { + if (!empty($this->id)) { $id .= ':' . $this->id; } if ($message instanceof PEAR_Error) { diff --git a/classes/Profile.php b/classes/Profile.php index 0d0463b73..d7617f0b7 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -464,11 +464,9 @@ class Profile extends Memcached_DataObject $sub = new Subscription(); $sub->subscribed = $this->id; - + $sub->whereAdd('subscriber != subscribed'); $cnt = (int) $sub->count('distinct subscriber'); - $cnt = ($cnt > 0) ? $cnt - 1 : $cnt; - if (!empty($c)) { $c->set(common_cache_key('profile:subscriber_count:'.$this->id), $cnt); } diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php index 70971c5b3..3b073a5d1 100644 --- a/plugins/OStatus/OStatusPlugin.php +++ b/plugins/OStatus/OStatusPlugin.php @@ -479,6 +479,24 @@ class OStatusPlugin extends Plugin } } + /** + * Tell the FeedSub infrastructure whether we have any active OStatus + * usage for the feed; if not it'll be able to garbage-collect the + * feed subscription. + * + * @param FeedSub $feedsub + * @param integer $count in/out + * @return mixed hook return code + */ + function onFeedSubSubscriberCount($feedsub, &$count) + { + $oprofile = Ostatus_profile::staticGet('feeduri', $feedsub->uri); + if ($oprofile) { + $count += $oprofile->subscriberCount(); + } + return true; + } + /** * When about to subscribe to a remote user, start a server-to-server * PuSH subscription if needed. If we can't establish that, abort. diff --git a/plugins/OStatus/classes/FeedSub.php b/plugins/OStatus/classes/FeedSub.php index b10509dae..9cd35e29c 100644 --- a/plugins/OStatus/classes/FeedSub.php +++ b/plugins/OStatus/classes/FeedSub.php @@ -255,6 +255,9 @@ class FeedSub extends Memcached_DataObject /** * Send a PuSH unsubscription request to the hub for this feed. * The hub will later send us a confirmation POST to /main/push/callback. + * Warning: this will cancel the subscription even if someone else in + * the system is using it. Most callers will want garbageCollect() instead, + * which confirms there's no uses left. * * @return bool true on success, false on failure * @throws ServerException if feed state is not valid @@ -275,6 +278,33 @@ class FeedSub extends Memcached_DataObject return $this->doSubscribe('unsubscribe'); } + /** + * Check if there are any active local uses of this feed, and if not then + * make sure it's inactive, unsubscribing if necessary. + * + * @return boolean true if the subscription is now inactive, false if still active. + */ + public function garbageCollect() + { + if ($this->sub_state == '' || $this->sub_state == 'inactive') { + // No active PuSH subscription, we can just leave it be. + return true; + } else { + // PuSH subscription is either active or in an indeterminate state. + // Check if we're out of subscribers, and if so send an unsubscribe. + $count = 0; + Event::handle('FeedSubSubscriberCount', array($this, &$count)); + + if ($count) { + common_log(LOG_INFO, __METHOD__ . ': ok, ' . $count . ' user(s) left for ' . $this->uri); + return false; + } else { + common_log(LOG_INFO, __METHOD__ . ': unsubscribing, no users left for ' . $this->uri); + return $this->unsubscribe(); + } + } + } + protected function doSubscribe($mode) { $orig = clone($this); diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php index 5d3f37cd0..2d7c632e6 100644 --- a/plugins/OStatus/classes/Ostatus_profile.php +++ b/plugins/OStatus/classes/Ostatus_profile.php @@ -215,22 +215,13 @@ class Ostatus_profile extends Memcached_DataObject } /** - * Send a PuSH unsubscription request to the hub for this feed. - * The hub will later send us a confirmation POST to /main/push/callback. + * Check if this remote profile has any active local subscriptions, and + * if not drop the PuSH subscription feed. * * @return bool true on success, false on failure - * @throws ServerException if feed state is not valid */ public function unsubscribe() { - $feedsub = FeedSub::staticGet('uri', $this->feeduri); - if (!$feedsub || $feedsub->sub_state == '' || $feedsub->sub_state == 'inactive') { - // No active PuSH subscription, we can just leave it be. - return true; - } else { - // PuSH subscription is either active or in an indeterminate state. - // Send an unsubscribe. - return $feedsub->unsubscribe(); - } + $this->garbageCollect(); } /** @@ -240,6 +231,21 @@ class Ostatus_profile extends Memcached_DataObject * @return boolean */ public function garbageCollect() + { + $feedsub = FeedSub::staticGet('uri', $this->feeduri); + return $feedsub->garbageCollect(); + } + + /** + * Check if this remote profile has any active local subscriptions, so the + * PuSH subscription layer can decide if it can drop the feed. + * + * This gets called via the FeedSubSubscriberCount event when running + * FeedSub::garbageCollect(). + * + * @return int + */ + public function subscriberCount() { if ($this->isGroup()) { $members = $this->localGroup()->getMembers(0, 1); @@ -247,13 +253,14 @@ class Ostatus_profile extends Memcached_DataObject } else { $count = $this->localProfile()->subscriberCount(); } - if ($count == 0) { - common_log(LOG_INFO, "Unsubscribing from now-unused remote feed $this->feeduri"); - $this->unsubscribe(); - return true; - } else { - return false; - } + common_log(LOG_INFO, __METHOD__ . " SUB COUNT BEFORE: $count"); + + // Other plugins may be piggybacking on OStatus without having + // an active group or user-to-user subscription we know about. + Event::handle('Ostatus_profileSubscriberCount', array($this, &$count)); + common_log(LOG_INFO, __METHOD__ . " SUB COUNT AFTER: $count"); + + return $count; } /** diff --git a/plugins/SubMirror/SubMirrorPlugin.php b/plugins/SubMirror/SubMirrorPlugin.php index 8678cc3dd..00c04ad0b 100644 --- a/plugins/SubMirror/SubMirrorPlugin.php +++ b/plugins/SubMirror/SubMirrorPlugin.php @@ -146,4 +146,27 @@ class SubMirrorPlugin extends Plugin array('href' => common_local_url('mirrorsettings')), _m('Set up mirroring options...')); } + + /** + * Let the OStatus subscription garbage collection know if we're + * making use of a remote feed, so it doesn't get dropped out + * from under us. + * + * @param Ostatus_profile $oprofile + * @param int $count in/out + * @return mixed hook return value + */ + function onOstatus_profileSubscriberCount($oprofile, &$count) + { + if ($oprofile->profile_id) { + $mirror = new SubMirror(); + $mirror->subscribed = $oprofile->profile_id; + if ($mirror->find()) { + while ($mirror->fetch()) { + $count++; + } + } + } + return true; + } } diff --git a/plugins/SubMirror/actions/addmirror.php b/plugins/SubMirror/actions/addmirror.php index df6939491..5acdf1dfe 100644 --- a/plugins/SubMirror/actions/addmirror.php +++ b/plugins/SubMirror/actions/addmirror.php @@ -46,9 +46,8 @@ if (!defined('STATUSNET')) { * @link http://status.net/ */ -class AddMirrorAction extends Action +class AddMirrorAction extends BaseMirrorAction { - var $user; var $feedurl; /** @@ -62,94 +61,17 @@ class AddMirrorAction extends Action function prepare($args) { parent::prepare($args); - $ok = $this->sharedBoilerplate(); - if ($ok) { - // and now do something useful! - $this->profile = $this->validateProfile($this->trimmed('profile')); - return true; - } else { - return $ok; - } - } - - function validateProfile($id) - { - $id = intval($id); - $profile = Profile::staticGet('id', $id); - if ($profile && $profile->id != $this->user->id) { - return $profile; - } - // TRANS: Error message returned to user when setting up feed mirroring, but we were unable to resolve the given URL to a working feed. - $this->clientError(_m("Invalid profile for mirroring.")); - } - - /** - * @fixme none of this belongs in end classes - * this stuff belongs in shared code! - */ - function sharedBoilerplate() - { - // Only allow POST requests - - if ($_SERVER['REQUEST_METHOD'] != 'POST') { - $this->clientError(_('This action only accepts POST requests.')); - return false; - } - - // CSRF protection - - $token = $this->trimmed('token'); - - if (!$token || $token != common_session_token()) { - $this->clientError(_('There was a problem with your session token.'. - ' Try again, please.')); - return false; - } - - // Only for logged-in users - - $this->user = common_current_user(); - - if (empty($this->user)) { - $this->clientError(_('Not logged in.')); - return false; - } + $this->feedurl = $this->validateFeedUrl($this->trimmed('feedurl')); + $this->profile = $this->profileForFeed($this->feedurl); return true; } - /** - * Handle request - * - * Does the subscription and returns results. - * - * @param Array $args unused. - * - * @return void - */ - - function handle($args) + function saveMirror() { - // Throws exception on error - $this->saveMirror(); - - if ($this->boolean('ajax')) { - $this->startHTML('text/xml;charset=utf-8'); - $this->elementStart('head'); - $this->element('title', null, _('Subscribed')); - $this->elementEnd('head'); - $this->elementStart('body'); - $unsubscribe = new EditMirrorForm($this, $this->profile); - $unsubscribe->show(); - $this->elementEnd('body'); - $this->elementEnd('html'); + if ($this->oprofile->subscribe()) { + SubMirror::saveMirror($this->user, $this->profile); } else { - $url = common_local_url('mirrorsettings'); - common_redirect($url, 303); + $this->serverError(_m("Could not subscribe to feed.")); } } - - function saveMirror() - { - SubMirror::saveMirror($this->user, $this->profile); - } } diff --git a/plugins/SubMirror/actions/editmirror.php b/plugins/SubMirror/actions/editmirror.php index 7ddd32ef3..c7fdab0d6 100644 --- a/plugins/SubMirror/actions/editmirror.php +++ b/plugins/SubMirror/actions/editmirror.php @@ -46,7 +46,7 @@ if (!defined('STATUSNET')) { * @link http://status.net/ */ -class EditMirrorAction extends AddMirrorAction +class EditMirrorAction extends BaseMirrorAction { /** @@ -60,6 +60,9 @@ class EditMirrorAction extends AddMirrorAction function prepare($args) { parent::prepare($args); + + $this->profile = $this->validateProfile($this->trimmed('profile')); + $this->mirror = SubMirror::pkeyGet(array('subscriber' => $this->user->id, 'subscribed' => $this->profile->id)); @@ -95,6 +98,10 @@ class EditMirrorAction extends AddMirrorAction if ($this->delete) { $mirror->delete(); + $oprofile = Ostatus_profile::staticGet('profile_id', $this->profile->id); + if ($oprofile) { + $oprofile->garbageCollect(); + } } else if ($this->style != $mirror->style) { $orig = clone($mirror); $mirror->style = $this->style; diff --git a/plugins/SubMirror/actions/mirrorsettings.php b/plugins/SubMirror/actions/mirrorsettings.php index edb024183..5463a8dc0 100644 --- a/plugins/SubMirror/actions/mirrorsettings.php +++ b/plugins/SubMirror/actions/mirrorsettings.php @@ -50,7 +50,7 @@ class MirrorSettingsAction extends AccountSettingsAction function getInstructions() { - return _m('You can mirror updates from your RSS and Atom feeds ' . + return _m('You can mirror updates from many RSS and Atom feeds ' . 'into your StatusNet timeline!'); } @@ -65,6 +65,8 @@ class MirrorSettingsAction extends AccountSettingsAction function showContent() { $user = common_current_user(); + + $this->showAddFeedForm(); $mirror = new SubMirror(); $mirror->subscriber = $user->id; @@ -73,7 +75,6 @@ class MirrorSettingsAction extends AccountSettingsAction $this->showFeedForm($mirror); } } - $this->showAddFeedForm(); } function showFeedForm($mirror) diff --git a/plugins/SubMirror/lib/addmirrorform.php b/plugins/SubMirror/lib/addmirrorform.php index 9ee59661a..0a798c9ea 100644 --- a/plugins/SubMirror/lib/addmirrorform.php +++ b/plugins/SubMirror/lib/addmirrorform.php @@ -57,46 +57,15 @@ class AddMirrorForm extends Form $this->out->elementStart('ul'); $this->li(); - $this->out->element('label', array('for' => $this->id() . '-profile'), - _m("Mirror one of your existing subscriptions:")); - $this->out->elementStart('select', array('name' => 'profile')); - - $user = common_current_user(); - $profile = $user->getSubscriptions(); - while ($profile->fetch()) { - $mirror = SubMirror::pkeyGet(array('subscriber' => $user->id, - 'subscribed' => $profile->id)); - if (!$mirror) { - $this->out->element('option', - array('value' => $profile->id), - $profile->getBestName()); - } - } - $this->out->elementEnd('select'); - $this->out->submit($this->id() . '-save', _m('Save')); + $this->doInput('addmirror-feedurl', + 'feedurl', + _m('Web page or feed URL:'), + $this->out->trimmed('feedurl')); $this->unli(); - $this->li(); - - $this->out->elementStart('fieldset', array('style' => 'width: 360px; margin-left: auto; margin-right: auto')); - $this->out->element('p', false, - _m("Not already subscribed to the feed you want? " . - "Add a new remote subscription and paste in the URL!")); - - $this->out->elementStart('div', 'entity_actions'); - $this->out->elementStart('p', array('id' => 'entity_remote_subscribe', - 'class' => 'entity_subscribe')); - $this->out->element('a', array('href' => common_local_url('ostatussub'), - 'class' => 'entity_remote_subscribe') - , _m('Remote')); - $this->out->elementEnd('p'); - $this->out->elementEnd('div'); - - $this->out->element('div', array('style' => 'clear: both')); - $this->out->elementEnd('fieldset'); + $this->out->submit('addmirror-save', _m('Add feed')); $this->unli(); - $this->out->elementEnd('ul'); $this->out->elementEnd('fieldset'); } @@ -106,7 +75,8 @@ class AddMirrorForm extends Form $this->out->element('label', array('for' => $id), $label); $attrs = array('name' => $name, 'type' => 'text', - 'id' => $id); + 'id' => $id, + 'style' => 'width: 80%'); if ($value) { $attrs['value'] = $value; } -- cgit v1.2.3-54-g00ecf From 79485340ab31ef9444431a098a5909b0be874264 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 6 Aug 2010 11:55:56 -0700 Subject: SubMirror: Drop mirror link from subscriptions list; has decoupled from subscriptions. --- plugins/SubMirror/SubMirrorPlugin.php | 7 ------- 1 file changed, 7 deletions(-) (limited to 'plugins') diff --git a/plugins/SubMirror/SubMirrorPlugin.php b/plugins/SubMirror/SubMirrorPlugin.php index 00c04ad0b..7289e7793 100644 --- a/plugins/SubMirror/SubMirrorPlugin.php +++ b/plugins/SubMirror/SubMirrorPlugin.php @@ -140,13 +140,6 @@ class SubMirrorPlugin extends Plugin $transports[] = 'mirror'; } - function onStartShowSubscriptionsContent($action) - { - $action->element('a', - array('href' => common_local_url('mirrorsettings')), - _m('Set up mirroring options...')); - } - /** * Let the OStatus subscription garbage collection know if we're * making use of a remote feed, so it doesn't get dropped out -- cgit v1.2.3-54-g00ecf From 729912e36a826f63ae109ae82125a97d1b100ce5 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 6 Aug 2010 12:00:31 -0700 Subject: Missing file from SubMirror. :P --- plugins/SubMirror/actions/basemirror.php | 169 +++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 plugins/SubMirror/actions/basemirror.php (limited to 'plugins') diff --git a/plugins/SubMirror/actions/basemirror.php b/plugins/SubMirror/actions/basemirror.php new file mode 100644 index 000000000..5be0699f0 --- /dev/null +++ b/plugins/SubMirror/actions/basemirror.php @@ -0,0 +1,169 @@ +. + * + * PHP version 5 + * + * @category Action + * @package StatusNet + * @author Brion Vibber + * @copyright 2010 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + exit(1); +} + +/** + * Takes parameters: + * + * - feed: a profile ID + * - token: session token to prevent CSRF attacks + * - ajax: boolean; whether to return Ajax or full-browser results + * + * Only works if the current user is logged in. + * + * @category Action + * @package StatusNet + * @copyright 2010 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3 + * @link http://status.net/ + */ + +abstract class BaseMirrorAction extends Action +{ + var $user; + var $profile; + + /** + * Check pre-requisites and instantiate attributes + * + * @param Array $args array of arguments (URL, GET, POST) + * + * @return boolean success flag + */ + + function prepare($args) + { + parent::prepare($args); + return $this->sharedBoilerplate(); + } + + protected function validateFeedUrl($url) + { + if (common_valid_http_url($url)) { + return $url; + } else { + $this->clientError(_m("Invalid feed URL.")); + } + } + + protected function validateProfile($id) + { + $id = intval($id); + $profile = Profile::staticGet('id', $id); + if ($profile && $profile->id != $this->user->id) { + return $profile; + } + // TRANS: Error message returned to user when setting up feed mirroring, but we were unable to resolve the given URL to a working feed. + $this->clientError(_m("Invalid profile for mirroring.")); + } + + /** + * + * @param string $url + * @return Profile + */ + protected function profileForFeed($url) + { + $oprofile = Ostatus_profile::ensureProfileURL($url); + if ($oprofile->isGroup()) { + $this->clientError(_m("Can't mirror a StatusNet group at this time.")); + } + $this->oprofile = $oprofile; // @fixme ugly side effect :D + return $oprofile->localProfile(); + } + + /** + * @fixme none of this belongs in end classes + * this stuff belongs in shared code! + */ + function sharedBoilerplate() + { + // Only allow POST requests + + if ($_SERVER['REQUEST_METHOD'] != 'POST') { + $this->clientError(_('This action only accepts POST requests.')); + return false; + } + + // CSRF protection + + $token = $this->trimmed('token'); + + if (!$token || $token != common_session_token()) { + $this->clientError(_('There was a problem with your session token.'. + ' Try again, please.')); + return false; + } + + // Only for logged-in users + + $this->user = common_current_user(); + + if (empty($this->user)) { + $this->clientError(_('Not logged in.')); + return false; + } + return true; + } + + /** + * Handle request + * + * Does the subscription and returns results. + * + * @param Array $args unused. + * + * @return void + */ + + function handle($args) + { + // Throws exception on error + $this->saveMirror(); + + if ($this->boolean('ajax')) { + $this->startHTML('text/xml;charset=utf-8'); + $this->elementStart('head'); + $this->element('title', null, _('Subscribed')); + $this->elementEnd('head'); + $this->elementStart('body'); + $unsubscribe = new EditMirrorForm($this, $this->profile); + $unsubscribe->show(); + $this->elementEnd('body'); + $this->elementEnd('html'); + } else { + $url = common_local_url('mirrorsettings'); + common_redirect($url, 303); + } + } + + abstract function saveMirror(); +} -- cgit v1.2.3-54-g00ecf From 39277ebf78dbe21e27bb93550689a983bd0237ae Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 6 Aug 2010 12:04:34 -0700 Subject: And.... one more fix for queueing in SubMirror. --- plugins/SubMirror/lib/mirrorqueuehandler.php | 1 + 1 file changed, 1 insertion(+) (limited to 'plugins') diff --git a/plugins/SubMirror/lib/mirrorqueuehandler.php b/plugins/SubMirror/lib/mirrorqueuehandler.php index 0306180ee..92b36b5eb 100644 --- a/plugins/SubMirror/lib/mirrorqueuehandler.php +++ b/plugins/SubMirror/lib/mirrorqueuehandler.php @@ -40,5 +40,6 @@ class MirrorQueueHandler extends QueueHandler $mirror->mirrorNotice($notice); } } + return true; } } -- cgit v1.2.3-54-g00ecf From fd2919be18c6045f948b77d4eba1a81212548d4a Mon Sep 17 00:00:00 2001 From: Eric Helgeson Date: Fri, 6 Aug 2010 22:48:00 -0500 Subject: Fixed PHP 5.3 by & value Cleaned up {}'s --- plugins/Gravatar/GravatarPlugin.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'plugins') diff --git a/plugins/Gravatar/GravatarPlugin.php b/plugins/Gravatar/GravatarPlugin.php index 580852072..8a9721ea9 100644 --- a/plugins/Gravatar/GravatarPlugin.php +++ b/plugins/Gravatar/GravatarPlugin.php @@ -30,11 +30,13 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { class GravatarPlugin extends Plugin { - function onInitializePlugin() { + function onInitializePlugin() + { return true; } - function onStartAvatarFormData($action) { + function onStartAvatarFormData($action) + { $user = common_current_user(); $hasGravatar = $this->hasGravatar($user->id); @@ -43,7 +45,8 @@ class GravatarPlugin extends Plugin } } - function onEndAvatarFormData(&$action) { + function onEndAvatarFormData($action) + { $user = common_current_user(); $hasGravatar = $this->hasGravatar($user->id); @@ -89,7 +92,8 @@ class GravatarPlugin extends Plugin } } - function onStartAvatarSaveForm($action) { + function onStartAvatarSaveForm($action) + { if ($action->arg('add')) { $result = $this->gravatar_save(); @@ -178,7 +182,8 @@ class GravatarPlugin extends Plugin 'success' => true); } - function gravatar_url($email, $size) { + function gravatar_url($email, $size) + { $url = "http://www.gravatar.com/avatar.php?gravatar_id=". md5(strtolower($email)). "&default=".urlencode(Avatar::defaultImage($size)). @@ -197,4 +202,4 @@ class GravatarPlugin extends Plugin return true; } -} +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf From c8a706081e45d67280dd6be2d68922236adc85f2 Mon Sep 17 00:00:00 2001 From: James Walker Date: Sat, 7 Aug 2010 09:48:21 -0400 Subject: strip whitespace from me:data and me:sig (per spec) --- plugins/OStatus/lib/magicenvelope.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'plugins') diff --git a/plugins/OStatus/lib/magicenvelope.php b/plugins/OStatus/lib/magicenvelope.php index 3bdf24b31..967e5f6d1 100644 --- a/plugins/OStatus/lib/magicenvelope.php +++ b/plugins/OStatus/lib/magicenvelope.php @@ -210,13 +210,13 @@ class MagicEnvelope } $data_element = $env_element->getElementsByTagNameNS(MagicEnvelope::NS, 'data')->item(0); - + $sig_element = $env_element->getElementsByTagNameNS(MagicEnvelope::NS, 'sig')->item(0); return array( - 'data' => trim($data_element->nodeValue), + 'data' => preg_replace('/\s/', '', $data_element->nodeValue), 'data_type' => $data_element->getAttribute('type'), 'encoding' => $env_element->getElementsByTagNameNS(MagicEnvelope::NS, 'encoding')->item(0)->nodeValue, 'alg' => $env_element->getElementsByTagNameNS(MagicEnvelope::NS, 'alg')->item(0)->nodeValue, - 'sig' => $env_element->getElementsByTagNameNS(MagicEnvelope::NS, 'sig')->item(0)->nodeValue, + 'sig' => preg_replace('/\s/', '', $sig_element->nodeValue), ); } -- cgit v1.2.3-54-g00ecf From 6a2659ed67577b3f33c5c4d55067744a4b812a06 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 10 Aug 2010 11:45:34 -0700 Subject: Workaround for index setup on SubMirror until I'm done w/ arbitrary index support for Schema setup. --- lib/mysqlschema.php | 2 +- plugins/SubMirror/SubMirrorPlugin.php | 3 +++ plugins/SubMirror/classes/SubMirror.php | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/lib/mysqlschema.php b/lib/mysqlschema.php index 464c718f9..f9552c1dc 100644 --- a/lib/mysqlschema.php +++ b/lib/mysqlschema.php @@ -333,7 +333,7 @@ class MysqlSchema extends Schema } if (empty($name)) { - $name = "$table_".implode("_", $columnNames)."_idx"; + $name = "{$table}_".implode("_", $columnNames)."_idx"; } $res = $this->conn->query("ALTER TABLE $table ". diff --git a/plugins/SubMirror/SubMirrorPlugin.php b/plugins/SubMirror/SubMirrorPlugin.php index 7289e7793..80c6c5a88 100644 --- a/plugins/SubMirror/SubMirrorPlugin.php +++ b/plugins/SubMirror/SubMirrorPlugin.php @@ -120,6 +120,9 @@ class SubMirrorPlugin extends Plugin { $schema = Schema::get(); $schema->ensureTable('submirror', SubMirror::schemaDef()); + + // @hack until key definition support is merged + SubMirror::fixIndexes($schema); return true; } diff --git a/plugins/SubMirror/classes/SubMirror.php b/plugins/SubMirror/classes/SubMirror.php index 4e7e005db..bd8fc80a5 100644 --- a/plugins/SubMirror/classes/SubMirror.php +++ b/plugins/SubMirror/classes/SubMirror.php @@ -76,6 +76,22 @@ class SubMirror extends Memcached_DataObject null, false)); } + /** + * Temporary hack to set up the compound index, since we can't do + * it yet through regular Schema interface. (Coming for 1.0...) + * + * @param Schema $schema + * @return void + */ + static function fixIndexes($schema) + { + try { + $schema->createIndex('submirror', array('subscribed', 'subscriber')); + } catch (Exception $e) { + common_log(LOG_ERR, __METHOD__ . ': ' . $e->getMessage()); + } + } + /** * return key definitions for DB_DataObject * -- cgit v1.2.3-54-g00ecf From 9a53be4669e53ba343f4c6433405ae8de747a86f Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 2 Aug 2010 16:08:54 -0700 Subject: Initial support for third-party fallback hub such as Superfeedr for feed subscriptions. If set up, this hub will be used to subscribe to feeds that don't specify a hub of their own. Assumes that the fallback hub will, in fact, handle polling and updates for any feed we throw at it! Authentication may be specified for the fallback hub. Example: $config['feedsub']['fallback_hub'] = 'https://superfeedr.com/hubbub'; $config['feedsub']['hub_user'] = 'abcd'; $config['feedsub']['hub_pass'] = 'ckcmdkmckdmkcdk'; Also: * Fix for WordPress-RSS-via-Superfeedr-Atom; if we have info but no ID from a native ActivityStreams actor, don't freak out in the low-level processing code that checks for identity matches. * enhanced messages for low-level FeedSub exceptions if they make it to outside display --- plugins/OStatus/OStatusPlugin.php | 9 +++++++ plugins/OStatus/README | 39 +++++++++++++++++++++++------ plugins/OStatus/classes/FeedSub.php | 32 +++++++++++++++++++---- plugins/OStatus/classes/Ostatus_profile.php | 16 ++++++++---- plugins/OStatus/lib/feeddiscovery.php | 10 ++++++++ plugins/OStatus/scripts/update-profile.php | 2 +- 6 files changed, 89 insertions(+), 19 deletions(-) (limited to 'plugins') diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php index 3b073a5d1..6fef20d6f 100644 --- a/plugins/OStatus/OStatusPlugin.php +++ b/plugins/OStatus/OStatusPlugin.php @@ -28,6 +28,15 @@ set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/ext class FeedSubException extends Exception { + function __construct($msg=null) + { + $type = get_class($this); + if ($msg) { + parent::__construct("$type: $msg"); + } else { + parent::__construct($type); + } + } } class OStatusPlugin extends Plugin diff --git a/plugins/OStatus/README b/plugins/OStatus/README index 3a98b7b25..ea5dfc055 100644 --- a/plugins/OStatus/README +++ b/plugins/OStatus/README @@ -1,18 +1,42 @@ -Plugin to support importing updates from external RSS and Atom feeds into your timeline. +Plugin to support importing and exporting notices through Atom and RSS feeds. +The OStatus plugin concentrates on user-to-user cases for federating StatusNet +and similar social networking / microblogging / blogging sites, but includes +low-level feed subscription systems which are used by some other plugins. + +Uses PubSubHubbub for push feed updates; currently non-PuSH feeds cannot be +subscribed unless an external PuSH hub proxy is used. -Uses PubSubHubbub for push feed updates; currently non-PuSH feeds cannot be subscribed. Configuration options available: $config['ostatus']['hub'] (default internal hub) - Set to URL of an external PuSH hub to use it instead of our internal hub. + Set to URL of an external PuSH hub to use it instead of our internal hub + for sending outgoing updates in user and group feeds. $config['ostatus']['hub_retries'] (default 0) Number of times to retry a PuSH send to consumers if using internal hub +Settings controlling incoming feed subscription: + +$config['feedsub']['fallback_hub'] + To subscribe to feeds that don't have a hub, an external PuSH proxy hub + such as Superfeedr may be used. Any feed without a hub of its own will + be subscribed through the specified hub URL instead. If the external hub + has usage charges, be aware that there is no restriction placed to how + many feeds may be subscribed! + + $config['feedsub']['fallback_hub'] = 'https://superfeedr.com/hubbub'; + +$config['feedsub']['hub_user'] +$config['feedsub']['hub_password'] + If using the fallback hub mode, these settings may be used to provide + HTTP authentication credentials for contacting the hub. Default hubs + specified from feeds are assumed to not require + + For testing, shouldn't be used in production: $config['ostatus']['skip_signatures'] @@ -23,12 +47,11 @@ $config['feedsub']['nohub'] (default require hub) Allow low-level feed subscription setup for feeds without hubs. Not actually usable at this stage, OStatus will check for hubs too - and we have no polling backend. + and we have no polling backend. (The fallback hub option can be used + with a 3rd-party service to provide such polling.) Todo: -* fully functional l10n -* redo non-OStatus feed support -** rssCloud support? -** possibly a polling daemon to support non-PuSH feeds? +* better support for feeds that aren't natively oriented at social networking * make use of tags/categories from feeds +* better repeat handling diff --git a/plugins/OStatus/classes/FeedSub.php b/plugins/OStatus/classes/FeedSub.php index 9cd35e29c..dd1968db1 100644 --- a/plugins/OStatus/classes/FeedSub.php +++ b/plugins/OStatus/classes/FeedSub.php @@ -207,8 +207,8 @@ class FeedSub extends Memcached_DataObject $discover = new FeedDiscovery(); $discover->discoverFromFeedURL($feeduri); - $huburi = $discover->getAtomLink('hub'); - if (!$huburi) { + $huburi = $discover->getHubLink(); + if (!$huburi && !common_config('feedsub', 'fallback_hub')) { throw new FeedSubNoHubException(); } @@ -241,8 +241,12 @@ class FeedSub extends Memcached_DataObject common_log(LOG_WARNING, "Attempting to (re)start PuSH subscription to $this->uri in unexpected state $this->sub_state"); } if (empty($this->huburi)) { - if (common_config('feedsub', 'nohub')) { + if (common_config('feedsub', 'fallback_hub')) { + // No native hub on this feed? + // Use our fallback hub, which handles polling on our behalf. + } else if (common_config('feedsub', 'nohub')) { // Fake it! We're just testing remote feeds w/o hubs. + // We'll never actually get updates in this mode. return true; } else { throw new ServerException("Attempting to start PuSH subscription for feed with no hub"); @@ -267,8 +271,12 @@ class FeedSub extends Memcached_DataObject common_log(LOG_WARNING, "Attempting to (re)end PuSH subscription to $this->uri in unexpected state $this->sub_state"); } if (empty($this->huburi)) { - if (common_config('feedsub', 'nohub')) { + if (common_config('feedsub', 'fallback_hub')) { + // No native hub on this feed? + // Use our fallback hub, which handles polling on our behalf. + } else if (common_config('feedsub', 'nohub')) { // Fake it! We're just testing remote feeds w/o hubs. + // We'll never actually get updates in this mode. return true; } else { throw new ServerException("Attempting to end PuSH subscription for feed with no hub"); @@ -326,7 +334,21 @@ class FeedSub extends Memcached_DataObject 'hub.secret' => $this->secret, 'hub.topic' => $this->uri); $client = new HTTPClient(); - $response = $client->post($this->huburi, $headers, $post); + if ($this->huburi) { + $hub = $this->huburi; + } else { + if (common_config('feedsub', 'fallback_hub')) { + $hub = common_config('feedsub', 'fallback_hub'); + if (common_config('feedsub', 'hub_user')) { + $u = common_config('feedsub', 'hub_user'); + $p = common_config('feedsub', 'hub_pass'); + $client->setAuth($u, $p); + } + } else { + throw new FeedSubException('WTF?'); + } + } + $response = $client->post($hub, $headers, $post); $status = $response->getStatus(); if ($status == 202) { common_log(LOG_INFO, __METHOD__ . ': sub req ok, awaiting verification callback'); diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php index 2d7c632e6..77a5e22cc 100644 --- a/plugins/OStatus/classes/Ostatus_profile.php +++ b/plugins/OStatus/classes/Ostatus_profile.php @@ -493,8 +493,14 @@ class Ostatus_profile extends Memcached_DataObject // OK here! assume the default } else if ($actor->id == $this->uri || $actor->link == $this->uri) { $this->updateFromActivityObject($actor); - } else { + } else if ($actor->id) { + // We have an ActivityStreams actor with an explicit ID that doesn't match the feed owner. + // This isn't what we expect from mainline OStatus person feeds! + // Group feeds go down another path, with different validation. throw new Exception("Got an actor '{$actor->title}' ({$actor->id}) on single-user feed for {$this->uri}"); + } else { + // Plain without ActivityStreams actor info. + // We'll just ignore this info for now and save the update under the feed's identity. } $oprofile = $this; @@ -869,12 +875,12 @@ class Ostatus_profile extends Memcached_DataObject $feeduri = $discover->discoverFromFeedURL($feed_url); $hints['feedurl'] = $feeduri; - $huburi = $discover->getAtomLink('hub'); + $huburi = $discover->getHubLink(); $hints['hub'] = $huburi; $salmonuri = $discover->getAtomLink(Salmon::NS_REPLIES); $hints['salmon'] = $salmonuri; - if (!$huburi) { + if (!$huburi && !common_config('feedsub', 'fallback_hub')) { // We can only deal with folks with a PuSH hub throw new FeedSubNoHubException(); } @@ -1270,10 +1276,10 @@ class Ostatus_profile extends Memcached_DataObject $discover = new FeedDiscovery(); $discover->discoverFromFeedURL($hints['feedurl']); } - $huburi = $discover->getAtomLink('hub'); + $huburi = $discover->getHubLink(); } - if (!$huburi) { + if (!$huburi && !common_config('feedsub', 'fallback_hub')) { // We can only deal with folks with a PuSH hub throw new FeedSubNoHubException(); } diff --git a/plugins/OStatus/lib/feeddiscovery.php b/plugins/OStatus/lib/feeddiscovery.php index 4ac243832..a55399d7c 100644 --- a/plugins/OStatus/lib/feeddiscovery.php +++ b/plugins/OStatus/lib/feeddiscovery.php @@ -87,6 +87,16 @@ class FeedDiscovery return ActivityUtils::getLink($this->root, $rel, $type); } + /** + * Get the referenced PuSH hub link from an Atom feed. + * + * @return mixed string or false + */ + public function getHubLink() + { + return $this->getAtomLink('hub'); + } + /** * @param string $url * @param bool $htmlOk pass false here if you don't want to follow web pages. diff --git a/plugins/OStatus/scripts/update-profile.php b/plugins/OStatus/scripts/update-profile.php index d06de4f90..64afa0f35 100644 --- a/plugins/OStatus/scripts/update-profile.php +++ b/plugins/OStatus/scripts/update-profile.php @@ -55,7 +55,7 @@ print "Re-running feed discovery for profile URL $oprofile->uri\n"; // @fixme will bork where the URI isn't the profile URL for now $discover = new FeedDiscovery(); $feedurl = $discover->discoverFromURL($oprofile->uri); -$huburi = $discover->getAtomLink('hub'); +$huburi = $discover->getHubLink(); $salmonuri = $discover->getAtomLink(Salmon::NS_REPLIES); print " Feed URL: $feedurl\n"; -- cgit v1.2.3-54-g00ecf From 4fdfc6b1ce7e5ffa50b24bdddca55cc73d54a09f Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 10 Aug 2010 13:19:27 -0700 Subject: Fix for FeedDiscovery test cases: note that some test cases with relative URLs fail that include a schema but not a host. Not 100% sure those are legit, need to check. --- plugins/OStatus/tests/FeedDiscoveryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/OStatus/tests/FeedDiscoveryTest.php b/plugins/OStatus/tests/FeedDiscoveryTest.php index 1c5249701..0e6354a86 100644 --- a/plugins/OStatus/tests/FeedDiscoveryTest.php +++ b/plugins/OStatus/tests/FeedDiscoveryTest.php @@ -10,7 +10,7 @@ define('STATUSNET', true); define('LACONICA', true); require_once INSTALLDIR . '/lib/common.php'; -require_once INSTALLDIR . '/plugins/FeedSub/feedsub.php'; +require_once INSTALLDIR . '/plugins/OStatus/lib/feeddiscovery.php'; class FeedDiscoveryTest extends PHPUnit_Framework_TestCase { -- cgit v1.2.3-54-g00ecf From 08fc6053ec55e911b842fd05dafc5e0c99c4e992 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 10 Aug 2010 13:36:38 -0700 Subject: Fix for regression with OStatus mention processing (duplicated new and old style lead to trying to save a reply entry twice). --- classes/Notice.php | 7 ++++--- lib/activitycontext.php | 6 ++++-- plugins/OStatus/classes/Ostatus_profile.php | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) (limited to 'plugins') diff --git a/classes/Notice.php b/classes/Notice.php index 4646fc6ab..0eeebfadf 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -485,7 +485,7 @@ class Notice extends Memcached_DataObject function saveKnownUrls($urls) { // @fixme validation? - foreach ($urls as $url) { + foreach (array_unique($urls) as $url) { File::processNew($url, $this->id); } } @@ -893,7 +893,7 @@ class Notice extends Memcached_DataObject } $groups = array(); - foreach ($group_ids as $id) { + foreach (array_unique($group_ids) as $id) { $group = User_group::staticGet('id', $id); if ($group) { common_log(LOG_ERR, "Local delivery to group id $id, $group->nickname"); @@ -1016,7 +1016,7 @@ class Notice extends Memcached_DataObject } $sender = Profile::staticGet($this->profile_id); - foreach ($uris as $uri) { + foreach (array_unique($uris) as $uri) { $user = User::staticGet('uri', $uri); @@ -1029,6 +1029,7 @@ class Notice extends Memcached_DataObject $reply->notice_id = $this->id; $reply->profile_id = $user->id; + common_log(LOG_INFO, __METHOD__ . ": saving reply: notice $this->id to profile $user->id"); $id = $reply->insert(); } diff --git a/lib/activitycontext.php b/lib/activitycontext.php index 5afbb7fd2..09a457924 100644 --- a/lib/activitycontext.php +++ b/lib/activitycontext.php @@ -71,6 +71,7 @@ class ActivityContext $links = $element->getElementsByTagNameNS(ActivityUtils::ATOM, ActivityUtils::LINK); + $attention = array(); for ($i = 0; $i < $links->length; $i++) { $link = $links->item($i); @@ -80,11 +81,12 @@ class ActivityContext // XXX: Deprecate this in favour of "mentioned" from Salmon spec // http://salmon-protocol.googlecode.com/svn/trunk/draft-panzer-salmon-00.html#SALR if ($linkRel == self::ATTENTION) { - $this->attention[] = $link->getAttribute(self::HREF); + $attention[] = $link->getAttribute(self::HREF); } elseif ($linkRel == self::MENTIONED) { - $this->attention[] = $link->getAttribute(self::HREF); + $attention[] = $link->getAttribute(self::HREF); } } + $this->attention = array_unique($attention); } /** diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php index 77a5e22cc..8f8eb773f 100644 --- a/plugins/OStatus/classes/Ostatus_profile.php +++ b/plugins/OStatus/classes/Ostatus_profile.php @@ -681,7 +681,7 @@ class Ostatus_profile extends Memcached_DataObject common_log(LOG_DEBUG, "Original reply recipients: " . implode(', ', $attention_uris)); $groups = array(); $replies = array(); - foreach ($attention_uris as $recipient) { + foreach (array_unique($attention_uris) as $recipient) { // Is the recipient a local user? $user = User::staticGet('uri', $recipient); if ($user) { -- cgit v1.2.3-54-g00ecf