diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/action.php | 30 | ||||
-rw-r--r-- | lib/api.php | 73 | ||||
-rw-r--r-- | lib/apiauth.php | 2 | ||||
-rw-r--r-- | lib/command.php | 67 | ||||
-rw-r--r-- | lib/commandinterpreter.php | 13 | ||||
-rw-r--r-- | lib/default.php | 2 | ||||
-rw-r--r-- | lib/language.php | 2 | ||||
-rw-r--r-- | lib/noticelist.php | 85 | ||||
-rw-r--r-- | lib/oauthstore.php | 5 | ||||
-rw-r--r-- | lib/profileformaction.php | 4 | ||||
-rw-r--r-- | lib/repeatform.php | 145 | ||||
-rw-r--r-- | lib/router.php | 28 |
12 files changed, 421 insertions, 35 deletions
diff --git a/lib/action.php b/lib/action.php index 87d8a4399..dac0e2583 100644 --- a/lib/action.php +++ b/lib/action.php @@ -952,6 +952,36 @@ class Action extends HTMLOutputter // lawsuit } /** + * Integer value of an argument + * + * @param string $key query key we're interested in + * @param string $defValue optional default value (default null) + * @param string $maxValue optional max value (default null) + * @param string $minValue optional min value (default null) + * + * @return integer integer value + */ + + function int($key, $defValue=null, $maxValue=null, $minValue=null) + { + $arg = strtolower($this->trimmed($key)); + + if (is_null($arg) || !is_integer($arg)) { + return $defValue; + } + + if (!is_null($maxValue)) { + $arg = min($arg, $maxValue); + } + + if (!is_null($minValue)) { + $arg = max($arg, $minValue); + } + + return $arg; + } + + /** * Server error * * @param string $msg error message to display diff --git a/lib/api.php b/lib/api.php index eacb80dbe..4ed49e452 100644 --- a/lib/api.php +++ b/lib/api.php @@ -53,13 +53,14 @@ if (!defined('STATUSNET')) { class ApiAction extends Action { - var $format = null; - var $user = null; - var $page = null; - var $count = null; - var $max_id = null; - var $since_id = null; - var $since = null; + var $format = null; + var $user = null; + var $auth_user = null; + var $page = null; + var $count = null; + var $max_id = null; + var $since_id = null; + var $since = null; /** * Initialization. @@ -134,17 +135,19 @@ class ApiAction extends Action $twitter_user['protected'] = false; # not supported by StatusNet yet $twitter_user['followers_count'] = $profile->subscriberCount(); - $user = $profile->getUser(); $design = null; + $user = $profile->getUser(); // Note: some profiles don't have an associated user - $defaultDesign = Design::siteDesign(); - if (!empty($user)) { $design = $user->getDesign(); } + if (empty($design)) { + $design = Design::siteDesign(); + } + $color = Design::toWebColor(empty($design->backgroundcolor) ? $defaultDesign->backgroundcolor : $design->backgroundcolor); $twitter_user['profile_background_color'] = ($color == null) ? '' : '#'.$color->hexValue(); $color = Design::toWebColor(empty($design->textcolor) ? $defaultDesign->textcolor : $design->textcolor); @@ -163,7 +166,7 @@ class ApiAction extends Action $timezone = 'UTC'; - if (!empty($user) && !empty($user->timezone)) { + if ($user->timezone) { $timezone = $user->timezone; } @@ -188,13 +191,14 @@ class ApiAction extends Action $twitter_user['following'] = false; $twitter_user['notifications'] = false; - if (isset($apidata['user'])) { + if (isset($this->auth_user)) { - $twitter_user['following'] = $apidata['user']->isSubscribed($profile); + $twitter_user['following'] = $this->auth_user->isSubscribed($profile); // Notifications on? $sub = Subscription::pkeyGet(array('subscriber' => - $apidata['user']->id, 'subscribed' => $profile->id)); + $this->auth_user->id, + 'subscribed' => $profile->id)); if ($sub) { $twitter_user['notifications'] = ($sub->jabber || $sub->sms); @@ -214,6 +218,21 @@ class ApiAction extends Action function twitterStatusArray($notice, $include_user=true) { + $base = $this->twitterSimpleStatusArray($notice, $include_user); + + if (!empty($notice->repeat_of)) { + $original = Notice::staticGet('id', $notice->repeat_of); + if (!empty($original)) { + $original_array = $this->twitterSimpleStatusArray($original, $include_user); + $base['retweeted_status'] = $original_array; + } + } + + return $base; + } + + function twitterSimpleStatusArray($notice, $include_user=true) + { $profile = $notice->getProfile(); $twitter_status = array(); @@ -446,9 +465,9 @@ class ApiAction extends Action } } - function showTwitterXmlStatus($twitter_status) + function showTwitterXmlStatus($twitter_status, $tag='status') { - $this->elementStart('status'); + $this->elementStart($tag); foreach($twitter_status as $element => $value) { switch ($element) { case 'user': @@ -463,11 +482,14 @@ class ApiAction extends Action case 'geo': $this->showGeoRSS($value); break; + case 'retweeted_status': + $this->showTwitterXmlStatus($value, 'retweeted_status'); + break; default: $this->element($element, null, $value); } } - $this->elementEnd('status'); + $this->elementEnd($tag); } function showTwitterXmlGroup($twitter_group) @@ -586,7 +608,7 @@ class ApiAction extends Action $this->endDocument('xml'); } - function showRssTimeline($notice, $title, $link, $subtitle, $suplink=null) + function showRssTimeline($notice, $title, $link, $subtitle, $suplink=null, $logo=null) { $this->initDocument('rss'); @@ -600,6 +622,15 @@ class ApiAction extends Action 'href' => $suplink, 'type' => 'application/json')); } + + if (!is_null($logo)) { + $this->elementStart('image'); + $this->element('link', null, $link); + $this->element('title', null, $title); + $this->element('url', null, $logo); + $this->elementEnd('image'); + } + $this->element('description', null, $subtitle); $this->element('language', null, 'en-us'); $this->element('ttl', null, '40'); @@ -619,7 +650,7 @@ class ApiAction extends Action $this->endTwitterRss(); } - function showAtomTimeline($notice, $title, $id, $link, $subtitle=null, $suplink=null, $selfuri=null) + function showAtomTimeline($notice, $title, $id, $link, $subtitle=null, $suplink=null, $selfuri=null, $logo=null) { $this->initDocument('atom'); @@ -628,6 +659,10 @@ class ApiAction extends Action $this->element('id', null, $id); $this->element('link', array('href' => $link, 'rel' => 'alternate', 'type' => 'text/html'), null); + if (!is_null($logo)) { + $this->element('logo',null,$logo); + } + if (!is_null($suplink)) { # For FriendFeed's SUP protocol $this->element('link', array('rel' => 'http://api.friendfeed.com/2008/03#sup', diff --git a/lib/apiauth.php b/lib/apiauth.php index 0d1613d38..7102764cb 100644 --- a/lib/apiauth.php +++ b/lib/apiauth.php @@ -53,8 +53,6 @@ require_once INSTALLDIR . '/lib/api.php'; class ApiAuthAction extends ApiAction { - var $auth_user = null; - /** * Take arguments for running, and output basic auth header if needed * diff --git a/lib/command.php b/lib/command.php index 450db9da3..67140c348 100644 --- a/lib/command.php +++ b/lib/command.php @@ -372,6 +372,7 @@ class MessageCommand extends Command } $message = Message::saveNew($this->user->id, $other->id, $this->text, $channel->source()); if ($message) { + $message->notify(); $channel->output($this->user, sprintf(_('Direct message to %s sent'), $this->other)); } else { $channel->error($this->user, _('Error sending direct message.')); @@ -379,6 +380,65 @@ class MessageCommand extends Command } } +class RepeatCommand extends Command +{ + var $other = null; + function __construct($user, $other) + { + parent::__construct($user); + $this->other = $other; + } + + function execute($channel) + { + if(substr($this->other,0,1)=='#'){ + //repeating a specific notice_id + + $notice = Notice::staticGet(substr($this->other,1)); + if (!$notice) { + $channel->error($this->user, _('Notice with that id does not exist')); + return; + } + $recipient = $notice->getProfile(); + }else{ + //repeating a given user's last notice + + $recipient = + common_relative_profile($this->user, common_canonical_nickname($this->other)); + + if (!$recipient) { + $channel->error($this->user, _('No such user.')); + return; + } + $notice = $recipient->getCurrentNotice(); + if (!$notice) { + $channel->error($this->user, _('User has no last notice')); + return; + } + } + + if($this->user->id == $notice->profile_id) + { + $channel->error($this->user, _('Cannot repeat your own notice')); + return; + } + + if ($recipient->hasRepeated($notice->id)) { + $channel->error($this->user, _('Already repeated that notice')); + return; + } + + $repeat = $notice->repeat($this->user->id, $channel->source); + + if ($repeat) { + common_broadcast_notice($repeat); + $channel->output($this->user, sprintf(_('Notice from %s repeated'), $recipient->nickname)); + } else { + $channel->error($this->user, _('Error repeating notice.')); + } + } +} + class ReplyCommand extends Command { var $other = null; @@ -433,8 +493,9 @@ class ReplyCommand extends Command return; } - $notice = Notice::saveNew($this->user->id, $this->text, $channel->source(), 1, - $notice->id); + $notice = Notice::saveNew($this->user->id, $this->text, $channel->source(), + array('reply_to' => $notice->id)); + if ($notice) { $channel->output($this->user, sprintf(_('Reply to %s sent'), $recipient->nickname)); } else { @@ -695,6 +756,8 @@ class HelpCommand extends Command "whois <nickname> - get profile info on user\n". "fav <nickname> - add user's last notice as a 'fave'\n". "fav #<notice_id> - add notice with the given id as a 'fave'\n". + "repeat #<notice_id> - repeat a notice with a given id\n". + "repeat <nickname> - repeat the last notice from user\n". "reply #<notice_id> - reply to notice with a given id\n". "reply <nickname> - reply to the last notice from user\n". "join <group> - join group\n". diff --git a/lib/commandinterpreter.php b/lib/commandinterpreter.php index 665015afc..c2add7299 100644 --- a/lib/commandinterpreter.php +++ b/lib/commandinterpreter.php @@ -169,6 +169,19 @@ class CommandInterpreter } else { return new ReplyCommand($user, $other, $extra); } + case 'repeat': + case 'rp': + case 'rt': + case 'rd': + if (!$arg) { + return null; + } + list($other, $extra) = $this->split_arg($arg); + if ($extra) { + return null; + } else { + return new RepeatCommand($user, $other); + } case 'whois': if (!$arg) { return null; diff --git a/lib/default.php b/lib/default.php index ebb6f8d01..42d4623b1 100644 --- a/lib/default.php +++ b/lib/default.php @@ -229,4 +229,6 @@ $default = array('namespace' => 1), // 1 = geonames, 2 = Yahoo Where on Earth 'omb' => array('timeout' => 5), // HTTP request timeout in seconds when contacting remote hosts for OMB updates + 'logincommand' => + array('disabled' => true), ); diff --git a/lib/language.php b/lib/language.php index 916cee7ed..d8f529201 100644 --- a/lib/language.php +++ b/lib/language.php @@ -272,6 +272,7 @@ function get_nice_language_list() function get_all_languages() { return array( 'ar' => array('q' => 0.8, 'lang' => 'ar', 'name' => 'Arabic', 'direction' => 'rtl'), + 'arz' => array('q' => 0.8, 'lang' => 'arz', 'name' => 'Egyptian Spoken Arabic', 'direction' => 'rtl'), 'bg' => array('q' => 0.8, 'lang' => 'bg', 'name' => 'Bulgarian', 'direction' => 'ltr'), 'ca' => array('q' => 0.5, 'lang' => 'ca', 'name' => 'Catalan', 'direction' => 'ltr'), 'cs' => array('q' => 0.5, 'lang' => 'cs', 'name' => 'Czech', 'direction' => 'ltr'), @@ -286,6 +287,7 @@ function get_all_languages() { 'ga' => array('q' => 0.5, 'lang' => 'ga', 'name' => 'Galician', 'direction' => 'ltr'), 'he' => array('q' => 0.5, 'lang' => 'he', 'name' => 'Hebrew', 'direction' => 'rtl'), 'hsb' => array('q' => 0.8, 'lang' => 'hsb', 'name' => 'Upper Sorbian', 'direction' => 'ltr'), + 'ia' => array('q' => 0.8, 'lang' => 'ia', 'name' => 'Interlingua', 'direction' => 'ltr'), 'is' => array('q' => 0.1, 'lang' => 'is', 'name' => 'Icelandic', 'direction' => 'ltr'), 'it' => array('q' => 1, 'lang' => 'it', 'name' => 'Italian', 'direction' => 'ltr'), 'jp' => array('q' => 0.5, 'lang' => 'ja', 'name' => 'Japanese', 'direction' => 'ltr'), diff --git a/lib/noticelist.php b/lib/noticelist.php index 21cec528f..4c11ceed6 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -147,6 +147,10 @@ class NoticeListItem extends Widget var $notice = null; + /** The notice that was repeated. */ + + var $repeat = null; + /** The profile of the author of the notice, extracted once for convenience. */ var $profile = null; @@ -162,8 +166,18 @@ class NoticeListItem extends Widget function __construct($notice, $out=null) { parent::__construct($out); - $this->notice = $notice; - $this->profile = $notice->getProfile(); + if (!empty($notice->repeat_of)) { + $original = Notice::staticGet('id', $notice->repeat_of); + if (empty($original)) { // could have been deleted + $this->notice = $notice; + } else { + $this->notice = $original; + $this->repeat = $notice; + } + } else { + $this->notice = $notice; + } + $this->profile = $this->notice->getProfile(); } /** @@ -202,6 +216,7 @@ class NoticeListItem extends Widget $this->showNoticeSource(); $this->showNoticeLocation(); $this->showContext(); + $this->showRepeat(); $this->out->elementEnd('div'); } @@ -212,6 +227,7 @@ class NoticeListItem extends Widget $this->out->elementStart('div', 'notice-options'); $this->showFaveForm(); $this->showReplyLink(); + $this->showRepeatForm(); $this->showDeleteLink(); $this->out->elementEnd('div'); } @@ -227,8 +243,9 @@ class NoticeListItem extends Widget { // XXX: RDFa // TODO: add notice_type class e.g., notice_video, notice_image + $id = (empty($this->repeat)) ? $this->notice->id : $this->repeat->id; $this->out->elementStart('li', array('class' => 'hentry notice', - 'id' => 'notice-' . $this->notice->id)); + 'id' => 'notice-' . $id)); } /** @@ -508,6 +525,40 @@ class NoticeListItem extends Widget } /** + * show a link to the author of repeat + * + * @return void + */ + + function showRepeat() + { + if (!empty($this->repeat)) { + + $repeater = Profile::staticGet('id', $this->repeat->profile_id); + + $attrs = array('href' => $repeater->profileurl, + 'class' => 'url'); + + if (!empty($repeater->fullname)) { + $attrs['title'] = $repeater->fullname . ' (' . $repeater->nickname . ')'; + } + + $this->out->elementStart('span', 'repeat vcard'); + + $this->out->raw(_('Repeated by')); + + $avatar = $repeater->getAvatar(AVATAR_MINI_SIZE); + + $this->out->elementStart('a', $attrs); + + $this->out->element('span', 'nickname', $repeater->nickname); + $this->out->elementEnd('a'); + + $this->out->elementEnd('span'); + } + } + + /** * show a link to reply to the current notice * * Should either do the reply in the current notice form (if available), or @@ -540,11 +591,13 @@ class NoticeListItem extends Widget { $user = common_current_user(); + $todel = (empty($this->repeat)) ? $this->notice : $this->repeat; + if (!empty($user) && - ($this->notice->profile_id == $user->id || $user->hasRight(Right::DELETEOTHERSNOTICE))) { + ($todel->profile_id == $user->id || $user->hasRight(Right::DELETEOTHERSNOTICE))) { $deleteurl = common_local_url('deletenotice', - array('notice' => $this->notice->id)); + array('notice' => $todel->id)); $this->out->element('a', array('href' => $deleteurl, 'class' => 'notice_delete', 'title' => _('Delete this notice')), _('Delete')); @@ -552,6 +605,28 @@ class NoticeListItem extends Widget } /** + * show the form to repeat a notice + * + * @return void + */ + + function showRepeatForm() + { + $user = common_current_user(); + if ($user && $user->id != $this->notice->profile_id) { + $profile = $user->getProfile(); + if ($profile->hasRepeated($this->notice->id)) { + $this->out->element('span', array('class' => 'repeated', + 'title' => _('Notice repeated')), + _('Repeated')); + } else { + $rf = new RepeatForm($this->out, $this->notice); + $rf->show(); + } + } + } + + /** * finish the notice * * Close the last elements in the notice list item diff --git a/lib/oauthstore.php b/lib/oauthstore.php index e34bf8a5e..df63cc151 100644 --- a/lib/oauthstore.php +++ b/lib/oauthstore.php @@ -359,9 +359,8 @@ class StatusNetOAuthDataStore extends OAuthDataStore $notice = Notice::saveNew($author->id, $omb_notice->getContent(), 'omb', - false, - null, - $omb_notice->getIdentifierURI()); + array('is_local' => Notice::REMOTE_OMB, + 'uri' => $omb_notice->getIdentifierURI())); common_broadcast_notice($notice, true); } diff --git a/lib/profileformaction.php b/lib/profileformaction.php index 8cb5f6a93..8a934666e 100644 --- a/lib/profileformaction.php +++ b/lib/profileformaction.php @@ -120,7 +120,7 @@ class ProfileFormAction extends Action if ($action) { common_redirect(common_local_url($action, $args), 303); } else { - $this->clientError(_("No return-to arguments")); + $this->clientError(_("No return-to arguments.")); } } @@ -134,6 +134,6 @@ class ProfileFormAction extends Action function handlePost() { - $this->serverError(_("unimplemented method")); + $this->serverError(_("Unimplemented method.")); } } diff --git a/lib/repeatform.php b/lib/repeatform.php new file mode 100644 index 000000000..50e5d6dbe --- /dev/null +++ b/lib/repeatform.php @@ -0,0 +1,145 @@ +<?php +/** + * StatusNet, the distributed open-source microblogging tool + * + * Form for repeating 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 Form + * @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); +} + +/** + * Form for repeating a notice + * + * @category Form + * @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 RepeatForm extends Form +{ + /** + * Notice to repeat + */ + + var $notice = null; + + /** + * Constructor + * + * @param HTMLOutputter $out output channel + * @param Notice $notice notice to repeat + */ + + function __construct($out=null, $notice=null) + { + parent::__construct($out); + + $this->notice = $notice; + } + + /** + * ID of the form + * + * @return int ID of the form + */ + + function id() + { + return 'repeat-' . $this->notice->id; + } + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + return common_local_url('repeat'); + } + + /** + * Include a session token for CSRF protection + * + * @return void + */ + + function sessionToken() + { + $this->out->hidden('token-' . $this->notice->id, + common_session_token()); + } + + /** + * Legend of the Form + * + * @return void + */ + function formLegend() + { + $this->out->element('legend', null, _('Repeat this notice')); + } + + /** + * Data elements + * + * @return void + */ + + function formData() + { + $this->out->hidden('notice-n'.$this->notice->id, + $this->notice->id, + 'notice'); + } + + /** + * Action elements + * + * @return void + */ + + function formActions() + { + $this->out->submit('repeat-submit-' . $this->notice->id, + _('Repeat'), 'submit', null, _('Repeat this notice')); + } + + /** + * Class of the form. + * + * @return string the form's class + */ + + function formClass() + { + return 'form_repeat'; + } +} diff --git a/lib/router.php b/lib/router.php index 37525319f..474e05996 100644 --- a/lib/router.php +++ b/lib/router.php @@ -99,6 +99,7 @@ class Router 'groupblock', 'groupunblock', 'sandbox', 'unsandbox', 'silence', 'unsilence', + 'repeat', 'deleteuser'); foreach ($main as $a) { @@ -282,12 +283,13 @@ class Router array('action' => 'ApiTimelineFriends', 'id' => '[a-zA-Z0-9]+', 'format' => '(xml|json|rss|atom)')); + $m->connect('api/statuses/home_timeline.:format', - array('action' => 'ApiTimelineFriends', + array('action' => 'ApiTimelineHome', 'format' => '(xml|json|rss|atom)')); $m->connect('api/statuses/home_timeline/:id.:format', - array('action' => 'ApiTimelineFriends', + array('action' => 'ApiTimelineHome', 'id' => '[a-zA-Z0-9]+', 'format' => '(xml|json|rss|atom)')); @@ -318,6 +320,18 @@ class Router 'id' => '[a-zA-Z0-9]+', 'format' => '(xml|json|rss|atom)')); + $m->connect('api/statuses/retweeted_by_me.:format', + array('action' => 'ApiTimelineRetweetedByMe', + 'format' => '(xml|json|atom)')); + + $m->connect('api/statuses/retweeted_to_me.:format', + array('action' => 'ApiTimelineRetweetedToMe', + 'format' => '(xml|json|atom)')); + + $m->connect('api/statuses/retweets_of_me.:format', + array('action' => 'ApiTimelineRetweetsOfMe', + 'format' => '(xml|json|atom)')); + $m->connect('api/statuses/friends.:format', array('action' => 'ApiUserFriends', 'format' => '(xml|json)')); @@ -358,6 +372,16 @@ class Router 'id' => '[0-9]+', 'format' => '(xml|json)')); + $m->connect('api/statuses/retweet/:id.:format', + array('action' => 'ApiStatusesRetweet', + 'id' => '[0-9]+', + 'format' => '(xml|json)')); + + $m->connect('api/statuses/retweets/:id.:format', + array('action' => 'ApiStatusesRetweets', + 'id' => '[0-9]+', + 'format' => '(xml|json)')); + // users $m->connect('api/users/show.:format', |