summaryrefslogtreecommitdiff
path: root/plugins/SubMirror/actions
diff options
context:
space:
mode:
authorBrion Vibber <brion@status.net>2010-08-06 10:56:18 -0700
committerBrion Vibber <brion@status.net>2010-08-06 11:49:52 -0700
commit7e55fc00447923b40b2ffc87329fd95347d776f5 (patch)
treec0ec54c201306fc1ee781676c9080ec0b6815dbb /plugins/SubMirror/actions
parentebd2fc2f7cb799cc190b2d4a77d8d0057a8854c0 (diff)
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
Diffstat (limited to 'plugins/SubMirror/actions')
-rw-r--r--plugins/SubMirror/actions/addmirror.php92
-rw-r--r--plugins/SubMirror/actions/editmirror.php9
-rw-r--r--plugins/SubMirror/actions/mirrorsettings.php5
3 files changed, 18 insertions, 88 deletions
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)