summaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
Diffstat (limited to 'actions')
-rw-r--r--actions/apistatusesretweet.php136
-rw-r--r--actions/apistatusesretweets.php116
-rw-r--r--actions/repeat.php122
-rw-r--r--actions/showstream.php46
4 files changed, 420 insertions, 0 deletions
diff --git a/actions/apistatusesretweet.php b/actions/apistatusesretweet.php
new file mode 100644
index 000000000..fc71d2274
--- /dev/null
+++ b/actions/apistatusesretweet.php
@@ -0,0 +1,136 @@
+<?php
+/**
+ * StatusNet, the distributed open-source microblogging tool
+ *
+ * Repeat a notice through the API
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category API
+ * @package StatusNet
+ * @author Evan Prodromou <evan@status.net>
+ * @copyright 2009 StatusNet, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://status.net/
+ */
+
+if (!defined('STATUSNET')) {
+ exit(1);
+}
+
+require_once INSTALLDIR . '/lib/apiauth.php';
+require_once INSTALLDIR . '/lib/mediafile.php';
+
+/**
+ * Repeat a notice through the API
+ *
+ * @category API
+ * @package StatusNet
+ * @author Evan Prodromou <evan@status.net>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://status.net/
+ */
+
+class ApiStatusesRetweetAction extends ApiAuthAction
+{
+ var $original = null;
+
+ /**
+ * Take arguments for running
+ *
+ * @param array $args $_REQUEST args
+ *
+ * @return boolean success flag
+ *
+ */
+
+ function prepare($args)
+ {
+ parent::prepare($args);
+
+ if ($_SERVER['REQUEST_METHOD'] != 'POST') {
+ $this->clientError(_('This method requires a POST.'),
+ 400, $this->format);
+ return false;
+ }
+
+ $id = $this->trimmed('id');
+
+ $this->original = Notice::staticGet('id', $id);
+
+ if (empty($this->original)) {
+ $this->clientError(_('No such notice'),
+ 400, $this->format);
+ return false;
+ }
+
+ $this->user = $this->auth_user;
+
+ if ($this->user->id == $notice->profile_id) {
+ $this->clientError(_('Cannot repeat your own notice'));
+ 400, $this->format);
+ return false;
+ }
+
+ $profile = $this->user->getProfile();
+
+ if ($profile->hasRepeated($id)) {
+ $this->clientError(_('Already repeated that notice'),
+ 400, $this->format);
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Handle the request
+ *
+ * Make a new notice for the update, save it, and show it
+ *
+ * @param array $args $_REQUEST data (unused)
+ *
+ * @return void
+ */
+
+ function handle($args)
+ {
+ parent::handle($args);
+
+ $repeat = $this->original->repeat($this->user->id, $this->source);
+
+ common_broadcast_notice($repeat);
+
+ $this->showNotice($repeat);
+ }
+
+ /**
+ * Show the resulting notice
+ *
+ * @return void
+ */
+
+ function showNotice($notice)
+ {
+ if (!empty($notice)) {
+ if ($this->format == 'xml') {
+ $this->showSingleXmlStatus($notice);
+ } elseif ($this->format == 'json') {
+ $this->show_single_json_status($notice);
+ }
+ }
+ }
+}
diff --git a/actions/apistatusesretweets.php b/actions/apistatusesretweets.php
new file mode 100644
index 000000000..c54a374e2
--- /dev/null
+++ b/actions/apistatusesretweets.php
@@ -0,0 +1,116 @@
+<?php
+/**
+ * StatusNet, the distributed open-source microblogging tool
+ *
+ * Show up to 100 repeats of a notice
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category API
+ * @package StatusNet
+ * @author Evan Prodromou <evan@status.net>
+ * @copyright 2009 StatusNet, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://status.net/
+ */
+
+if (!defined('STATUSNET')) {
+ exit(1);
+}
+
+require_once INSTALLDIR . '/lib/apiauth.php';
+require_once INSTALLDIR . '/lib/mediafile.php';
+
+/**
+ * Show up to 100 repeats of a notice
+ *
+ * @category API
+ * @package StatusNet
+ * @author Evan Prodromou <evan@status.net>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://status.net/
+ */
+
+class ApiStatusesRetweetsAction extends ApiAuthAction
+{
+ const MAXCOUNT = 100;
+
+ var $original = null;
+ var $cnt = self::MAXCOUNT;
+
+ /**
+ * Take arguments for running
+ *
+ * @param array $args $_REQUEST args
+ *
+ * @return boolean success flag
+ *
+ */
+
+ function prepare($args)
+ {
+ parent::prepare($args);
+
+ $id = $this->trimmed('id');
+
+ $this->original = Notice::staticGet('id', $id);
+
+ if (empty($this->original)) {
+ $this->clientError(_('No such notice'),
+ 400, $this->format);
+ return false;
+ }
+
+ $cnt = $this->trimmed('count');
+
+ if (empty($cnt) || !is_integer($cnt)) {
+ $cnt = 100;
+ } else {
+ $this->cnt = min((int)$cnt, self::MAXCOUNT);
+ }
+
+ return true;
+ }
+
+ /**
+ * Handle the request
+ *
+ * Make a new notice for the update, save it, and show it
+ *
+ * @param array $args $_REQUEST data (unused)
+ *
+ * @return void
+ */
+
+ function handle($args)
+ {
+ parent::handle($args);
+
+ $strm = $this->original->repeatStream($this->cnt);
+
+ switch ($this->format) {
+ case 'xml':
+ $this->showXmlTimeline($strm);
+ break;
+ case 'json':
+ $this->showJsonTimeline($strm);
+ break;
+ default:
+ $this->clientError(_('API method not found!'), $code = 404);
+ break;
+ }
+ }
+}
diff --git a/actions/repeat.php b/actions/repeat.php
new file mode 100644
index 000000000..a1c5f443f
--- /dev/null
+++ b/actions/repeat.php
@@ -0,0 +1,122 @@
+<?php
+
+/**
+ * Repeat action.
+ *
+ * PHP version 5
+ *
+ * @category Action
+ * @package StatusNet
+ * @author Evan Prodromou <evan@status.net>
+ * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
+ * @link http://status.net/
+ *
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2008, 2009, StatusNet, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+if (!defined('STATUSNET')) {
+ exit(1);
+}
+
+/**
+ * Repeat action
+ *
+ * @category Action
+ * @package StatusNet
+ * @author Evan Prodromou <evan@status.net>
+ * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
+ * @link http://status.net/
+ */
+
+class RepeatAction extends Action
+{
+ var $user = null;
+ var $notice = null;
+
+ function prepare($args)
+ {
+ parent::prepare($args);
+
+ $this->user = common_current_user();
+
+ if (empty($this->user)) {
+ $this->clientError(_("Only logged-in users can repeat notices."));
+ return false;
+ }
+
+ $id = $this->trimmed('notice');
+
+ if (empty($id)) {
+ $this->clientError(_("No notice specified."));
+ return false;
+ }
+
+ $this->notice = Notice::staticGet('id', $id);
+
+ if (empty($this->notice)) {
+ $this->clientError(_("No notice specified."));
+ return false;
+ }
+
+ if ($this->user->id == $this->notice->profile_id) {
+ $this->clientError(_("You can't repeat your own notice."));
+ return false;
+ }
+
+ $token = $this->trimmed('token-'.$id);
+
+ if (empty($token) || $token != common_session_token()) {
+ $this->clientError(_("There was a problem with your session token. Try again, please."));
+ return false;
+ }
+
+ $profile = $this->user->getProfile();
+
+ if ($profile->hasRepeated($id)) {
+ $this->clientError(_("You already repeated that notice."));
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Class handler.
+ *
+ * @param array $args query arguments
+ *
+ * @return void
+ */
+
+ function handle($args)
+ {
+ $repeat = $this->notice->repeat($this->user->id, 'web');
+
+ if ($this->boolean('ajax')) {
+ $this->startHTML('text/xml;charset=utf-8');
+ $this->elementStart('head');
+ $this->element('title', null, _('Repeated'));
+ $this->elementEnd('head');
+ $this->elementStart('body');
+ $this->element('p', array('id' => 'repeat_response'), _('Repeated!'));
+ $this->elementEnd('body');
+ $this->elementEnd('html');
+ } else {
+ // FIXME!
+ }
+ }
+}
diff --git a/actions/showstream.php b/actions/showstream.php
index 663638c18..74b46cc95 100644
--- a/actions/showstream.php
+++ b/actions/showstream.php
@@ -269,4 +269,50 @@ class ProfileNoticeListItem extends NoticeListItem
{
return;
}
+
+ /**
+ * show a link to the author of repeat
+ *
+ * @return void
+ */
+
+ function showRepeat()
+ {
+ if (!empty($this->repeat)) {
+
+ // FIXME: this code is almost identical to default; need to refactor
+
+ $attrs = array('href' => $this->profile->profileurl,
+ 'class' => 'url');
+
+ if (!empty($this->profile->fullname)) {
+ $attrs['title'] = $this->profile->fullname . ' (' . $this->profile->nickname . ')';
+ }
+
+ $this->out->elementStart('span', 'repeat');
+
+ $this->out->elementStart('a', $attrs);
+
+ $avatar = $this->profile->getAvatar(AVATAR_MINI_SIZE);
+
+ $this->out->element('img', array('src' => ($avatar) ?
+ $avatar->displayUrl() :
+ Avatar::defaultImage(AVATAR_MINI_SIZE),
+ 'class' => 'avatar photo',
+ 'width' => AVATAR_MINI_SIZE,
+ 'height' => AVATAR_MINI_SIZE,
+ 'alt' =>
+ ($this->profile->fullname) ?
+ $this->profile->fullname :
+ $this->profile->nickname));
+
+ $this->out->elementEnd('a');
+
+ $text_link = XMLStringer::estring('a', $attrs, $this->profile->nickname);
+
+ $this->out->raw(sprintf(_('Repeat of %s'), $text_link));
+
+ $this->out->elementEnd('span');
+ }
+ }
}