summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBrenda Wallace <shiny@cpan.org>2009-12-28 01:57:51 +0000
committerBrenda Wallace <shiny@cpan.org>2009-12-28 01:57:51 +0000
commitf4459dfedcdea2f2a6078bedf9530deb45b6d52c (patch)
tree942db6159710f5dd17e0c43a5659e1eec027a9e6 /lib
parent9d3829df9d29581c1d0281e57fda8ba4452ce2c2 (diff)
parentce8c69a49fc6668a19886ebc354ea5bef808d12a (diff)
Merge commit 'origin/0.9.x' into 0.9.x
Diffstat (limited to 'lib')
-rw-r--r--lib/api.php35
-rw-r--r--lib/apiauth.php2
-rw-r--r--lib/command.php62
-rw-r--r--lib/commandinterpreter.php13
-rw-r--r--lib/common.php4
-rw-r--r--lib/curry.php36
-rw-r--r--lib/default.php2
-rw-r--r--lib/language.php17
-rw-r--r--lib/mail.php4
-rw-r--r--lib/noticelist.php33
-rw-r--r--lib/profileformaction.php4
-rw-r--r--lib/repeatform.php4
-rw-r--r--lib/router.php5
-rw-r--r--lib/util.php71
14 files changed, 229 insertions, 63 deletions
diff --git a/lib/api.php b/lib/api.php
index b7ab407a1..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.
@@ -190,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);
@@ -218,14 +220,15 @@ class ApiAction extends Action
{
$base = $this->twitterSimpleStatusArray($notice, $include_user);
- if (empty($notice->repeat_of)) {
- return $base;
- } else {
+ if (!empty($notice->repeat_of)) {
$original = Notice::staticGet('id', $notice->repeat_of);
- $original_array = $this->twitterSimpleStatusArray($original, $include_user);
- $original_array['retweeted_status'] = $base;
- return $original_array;
+ if (!empty($original)) {
+ $original_array = $this->twitterSimpleStatusArray($original, $include_user);
+ $base['retweeted_status'] = $original_array;
+ }
}
+
+ return $base;
}
function twitterSimpleStatusArray($notice, $include_user=true)
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 085331f82..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;
@@ -696,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/common.php b/lib/common.php
index 732c22bfd..7fa1910af 100644
--- a/lib/common.php
+++ b/lib/common.php
@@ -20,9 +20,9 @@
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
//exit with 200 response, if this is checking fancy from the installer
-if (isset($_REQUEST['p']) && $_REQUEST['p'] == 'check-fancy') { exit; }
+if (isset($_REQUEST['p']) && $_REQUEST['p'] == 'check-fancy') { exit; }
-define('STATUSNET_VERSION', '0.9.0dev');
+define('STATUSNET_VERSION', '0.9.0rc2');
define('LACONICA_VERSION', STATUSNET_VERSION); // compatibility
define('STATUSNET_CODENAME', 'Stand');
diff --git a/lib/curry.php b/lib/curry.php
new file mode 100644
index 000000000..6136dcdc3
--- /dev/null
+++ b/lib/curry.php
@@ -0,0 +1,36 @@
+<?php
+/*
+ * 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/>.
+ */
+
+/**
+ * PHP 5.3 implementation of function currying, using native closures.
+ * On 5.2 and lower we use the fallback implementation in util.php
+ *
+ * @param callback $fn
+ * @param ... any remaining arguments will be appended to call-time params
+ * @return callback
+ */
+function curry($fn) {
+ $extra_args = func_get_args();
+ array_shift($extra_args);
+ return function() use ($fn, $extra_args) {
+ $args = func_get_args();
+ return call_user_func_array($fn,
+ array_merge($args, $extra_args));
+ };
+}
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 c037d30c3..f5ee7fac5 100644
--- a/lib/language.php
+++ b/lib/language.php
@@ -32,6 +32,21 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
+// Locale category constants are usually predefined, but may not be
+// on some systems such as Win32.
+$LC_CATEGORIES = array('LC_CTYPE',
+ 'LC_NUMERIC',
+ 'LC_TIME',
+ 'LC_COLLATE',
+ 'LC_MONETARY',
+ 'LC_MESSAGES',
+ 'LC_ALL');
+foreach ($LC_CATEGORIES as $key => $name) {
+ if (!defined($name)) {
+ define($name, $key);
+ }
+}
+
if (!function_exists('gettext')) {
require_once("php-gettext/gettext.inc");
}
@@ -283,10 +298,12 @@ function get_all_languages() {
'en' => array('q' => 1, 'lang' => 'en', 'name' => 'English (US)', 'direction' => 'ltr'),
'es' => array('q' => 1, 'lang' => 'es', 'name' => 'Spanish', 'direction' => 'ltr'),
'fi' => array('q' => 1, 'lang' => 'fi', 'name' => 'Finnish', 'direction' => 'ltr'),
+ 'fa' => array('q' => 1, 'lang' => 'fa', 'name' => 'Persian', 'direction' => 'rtl'),
'fr-fr' => array('q' => 1, 'lang' => 'fr', 'name' => 'French', 'direction' => 'ltr'),
'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/mail.php b/lib/mail.php
index dffac3262..472a88e06 100644
--- a/lib/mail.php
+++ b/lib/mail.php
@@ -599,6 +599,10 @@ function mail_notify_attn($user, $notice)
$sender = $notice->getProfile();
+ if ($sender->id == $user->id) {
+ return;
+ }
+
if (!$sender->hasRight(Right::EMAILONREPLY)) {
return;
}
diff --git a/lib/noticelist.php b/lib/noticelist.php
index aa6ea278c..4c11ceed6 100644
--- a/lib/noticelist.php
+++ b/lib/noticelist.php
@@ -243,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));
}
/**
@@ -542,29 +543,17 @@ class NoticeListItem extends Widget
$attrs['title'] = $repeater->fullname . ' (' . $repeater->nickname . ')';
}
- $this->out->elementStart('span', 'repeat');
+ $this->out->elementStart('span', 'repeat vcard');
- $this->out->elementStart('a', $attrs);
+ $this->out->raw(_('Repeated by'));
$avatar = $repeater->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' =>
- ($repeater->fullname) ?
- $repeater->fullname :
- $repeater->nickname));
+ $this->out->elementStart('a', $attrs);
+ $this->out->element('span', 'nickname', $repeater->nickname);
$this->out->elementEnd('a');
- $text_link = XMLStringer::estring('a', $attrs, $repeater->nickname);
-
- $this->out->raw(sprintf(_('Repeated by %s'), $text_link));
-
$this->out->elementEnd('span');
}
}
@@ -602,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'));
@@ -625,7 +616,9 @@ class NoticeListItem extends Widget
if ($user && $user->id != $this->notice->profile_id) {
$profile = $user->getProfile();
if ($profile->hasRepeated($this->notice->id)) {
- $this->out->text(_('Repeated'));
+ $this->out->element('span', array('class' => 'repeated',
+ 'title' => _('Notice repeated')),
+ _('Repeated'));
} else {
$rf = new RepeatForm($this->out, $this->notice);
$rf->show();
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
index 50e5d6dbe..4f1c8aa32 100644
--- a/lib/repeatform.php
+++ b/lib/repeatform.php
@@ -104,7 +104,7 @@ class RepeatForm extends Form
*/
function formLegend()
{
- $this->out->element('legend', null, _('Repeat this notice'));
+ $this->out->element('legend', null, _('Repeat this notice?'));
}
/**
@@ -129,7 +129,7 @@ class RepeatForm extends Form
function formActions()
{
$this->out->submit('repeat-submit-' . $this->notice->id,
- _('Repeat'), 'submit', null, _('Repeat this notice'));
+ _('Yes'), 'submit', null, _('Repeat this notice'));
}
/**
diff --git a/lib/router.php b/lib/router.php
index 8f68f86ac..474e05996 100644
--- a/lib/router.php
+++ b/lib/router.php
@@ -283,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)'));
diff --git a/lib/util.php b/lib/util.php
index 14d666503..ed81aeba1 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -91,8 +91,16 @@ function common_language()
if (_have_config() && common_logged_in()) {
$user = common_current_user();
$user_language = $user->language;
- if ($user_language)
- return $user_language;
+
+ if ($user->language) {
+ // Validate -- we don't want to end up with a bogus code
+ // left over from some old junk.
+ foreach (common_config('site', 'languages') as $code => $info) {
+ if ($info['lang'] == $user_language) {
+ return $user_language;
+ }
+ }
+ }
}
// Otherwise, find the best match for the languages requested by the
@@ -523,19 +531,23 @@ function callback_helper($matches, $callback, $notice_id) {
return substr($matches[0],0,$left) . $result . substr($matches[0],$right);
}
-function curry($fn) {
- //TODO switch to a PHP 5.3 function closure based approach if PHP 5.3 is used
- $args = func_get_args();
- array_shift($args);
- $id = uniqid('_partial');
- $GLOBALS[$id] = array($fn, $args);
- return create_function('',
- '$args = func_get_args(); '.
- 'return call_user_func_array('.
- '$GLOBALS["'.$id.'"][0],'.
- 'array_merge('.
- '$args,'.
- '$GLOBALS["'.$id.'"][1]));');
+if (version_compare(PHP_VERSION, '5.3.0', 'ge')) {
+ // lambda implementation in a separate file; PHP 5.2 won't parse it.
+ require_once INSTALLDIR . "/lib/curry.php";
+} else {
+ function curry($fn) {
+ $args = func_get_args();
+ array_shift($args);
+ $id = uniqid('_partial');
+ $GLOBALS[$id] = array($fn, $args);
+ return create_function('',
+ '$args = func_get_args(); '.
+ 'return call_user_func_array('.
+ '$GLOBALS["'.$id.'"][0],'.
+ 'array_merge('.
+ '$args,'.
+ '$GLOBALS["'.$id.'"][1]));');
+ }
}
function common_linkify($url) {
@@ -1240,8 +1252,12 @@ function common_copy_args($from)
return $to;
}
-// Neutralise the evil effects of magic_quotes_gpc in the current request.
-// This is used before handing a request off to OAuthRequest::from_request.
+/**
+ * Neutralise the evil effects of magic_quotes_gpc in the current request.
+ * This is used before handing a request off to OAuthRequest::from_request.
+ * @fixme Doesn't consider vars other than _POST and _GET?
+ * @fixme Can't be undone and could corrupt data if run twice.
+ */
function common_remove_magic_from_request()
{
if(get_magic_quotes_gpc()) {
@@ -1443,6 +1459,17 @@ function common_database_tablename($tablename)
return $tablename;
}
+/**
+ * Shorten a URL with the current user's configured shortening service,
+ * or ur1.ca if configured, or not at all if no shortening is set up.
+ * Length is not considered.
+ *
+ * @param string $long_url
+ * @return string may return the original URL if shortening failed
+ *
+ * @fixme provide a way to specify a particular shortener
+ * @fixme provide a way to specify to use a given user's shortening preferences
+ */
function common_shorten_url($long_url)
{
$user = common_current_user();
@@ -1463,6 +1490,16 @@ function common_shorten_url($long_url)
}
}
+/**
+ * @return mixed array($proxy, $ip) for web requests; proxy may be null
+ * null if not a web request
+ *
+ * @fixme X-Forwarded-For can be chained by multiple proxies;
+ we should parse the list and provide a cleaner array
+ * @fixme X-Forwarded-For can be forged by clients; only use them if trusted
+ * @fixme X_Forwarded_For headers will override X-Forwarded-For read through $_SERVER;
+ * use function to get exact request headers from Apache if possible.
+ */
function common_client_ip()
{
if (!isset($_SERVER) || !array_key_exists('REQUEST_METHOD', $_SERVER)) {