We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit d30df079 authored by Sarven Capadisli's avatar Sarven Capadisli

Merge branch '0.7.x' into 0.8.x

Resolved Conflicts:
	lib/queuehandler.php
	lib/util.php
	theme/base/css/display.css
parents f798d1ea b79fef30
......@@ -59,7 +59,7 @@ class AccesstokenAction extends Action
try {
common_debug('getting request from env variables', __FILE__);
common_remove_magic_from_request();
$req = OAuthRequest::from_request('POST', common_locale_url('accesstoken'));
$req = OAuthRequest::from_request('POST', common_local_url('accesstoken'));
common_debug('getting a server', __FILE__);
$server = omb_oauth_server();
common_debug('fetching the access token', __FILE__);
......
......@@ -93,7 +93,7 @@ class AllAction extends ProfileAction
if (common_logged_in()) {
$current_user = common_current_user();
if ($this->user->id === $current_user->id) {
$message .= _('Try subscribing to more people, [join a group](%%action.groups) or post something yourself.');
$message .= _('Try subscribing to more people, [join a group](%%action.groups%%) or post something yourself.');
} else {
$message .= sprintf(_('You can try to [nudge %s](../%s) from his profile or [post something to his or her attention](%%%%action.newnotice%%%%?status_textarea=%s).'), $this->user->nickname, $this->user->nickname, '@' . $this->user->nickname);
}
......
......@@ -130,6 +130,7 @@ class ApiAction extends Action
'statuses/friends_timeline',
'statuses/friends',
'statuses/replies',
'statuses/mentions',
'statuses/followers',
'favorites/favorites');
......
......@@ -172,15 +172,54 @@ class NewmessageAction extends Action
$this->notify($user, $this->other, $message);
$url = common_local_url('outbox', array('nickname' => $user->nickname));
if ($this->boolean('ajax')) {
$this->startHTML('text/xml;charset=utf-8');
$this->elementStart('head');
$this->element('title', null, _('Message sent'));
$this->elementEnd('head');
$this->elementStart('body');
$this->element('p', array('id' => 'command_result'),
sprintf(_('Direct message to %s sent'),
$this->other->nickname));
$this->elementEnd('body');
$this->elementEnd('html');
} else {
$url = common_local_url('outbox',
array('nickname' => $user->nickname));
common_redirect($url, 303);
}
}
common_redirect($url, 303);
/**
* Show an Ajax-y error message
*
* Goes back to the browser, where it's shown in a popup.
*
* @param string $msg Message to show
*
* @return void
*/
function ajaxErrorMsg($msg)
{
$this->startHTML('text/xml;charset=utf-8', true);
$this->elementStart('head');
$this->element('title', null, _('Ajax Error'));
$this->elementEnd('head');
$this->elementStart('body');
$this->element('p', array('id' => 'error'), $msg);
$this->elementEnd('body');
$this->elementEnd('html');
}
function showForm($msg = null)
{
$this->msg = $msg;
if ($msg && $this->boolean('ajax')) {
$this->ajaxErrorMsg($msg);
return;
}
$this->msg = $msg;
$this->showPage();
}
......
......@@ -133,11 +133,7 @@ class TwitapifriendshipsAction extends TwitterapiAction
return;
}
if ($user_a->isSubscribed($user_b)) {
$result = 'true';
} else {
$result = 'false';
}
$result = $user_a->isSubscribed($user_b);
switch ($apidata['content-type']) {
case 'xml':
......
......@@ -144,10 +144,10 @@ class TwitapistatusesAction extends TwitterapiAction
break;
case 'atom':
if (isset($apidata['api_arg'])) {
$selfuri = $selfuri = common_root_url() .
$selfuri = common_root_url() .
'api/statuses/friends_timeline/' . $apidata['api_arg'] . '.atom';
} else {
$selfuri = $selfuri = common_root_url() .
$selfuri = common_root_url() .
'api/statuses/friends_timeline.atom';
}
$this->show_atom_timeline($notice, $title, $id, $link, $subtitle, null, $selfuri);
......@@ -231,10 +231,10 @@ class TwitapistatusesAction extends TwitterapiAction
break;
case 'atom':
if (isset($apidata['api_arg'])) {
$selfuri = $selfuri = common_root_url() .
$selfuri = common_root_url() .
'api/statuses/user_timeline/' . $apidata['api_arg'] . '.atom';
} else {
$selfuri = $selfuri = common_root_url() .
$selfuri = common_root_url() .
'api/statuses/user_timeline.atom';
}
$this->show_atom_timeline($notice, $title, $id, $link, $subtitle, $suplink, $selfuri);
......@@ -344,7 +344,7 @@ class TwitapistatusesAction extends TwitterapiAction
$this->show($args, $apidata);
}
function replies($args, $apidata)
function mentions($args, $apidata)
{
parent::handle($args);
......@@ -360,11 +360,13 @@ class TwitapistatusesAction extends TwitterapiAction
$profile = $user->getProfile();
$sitename = common_config('site', 'name');
$title = sprintf(_('%1$s / Updates replying to %2$s'), $sitename, $user->nickname);
$title = sprintf(_('%1$s / Updates mentioning %2$s'),
$sitename, $user->nickname);
$taguribase = common_config('integration', 'taguri');
$id = "tag:$taguribase:Replies:".$user->id;
$id = "tag:$taguribase:Mentions:".$user->id;
$link = common_local_url('replies', array('nickname' => $user->nickname));
$subtitle = sprintf(_('%1$s updates that reply to updates from %2$s / %3$s.'), $sitename, $user->nickname, $profile->getBestName());
$subtitle = sprintf(_('%1$s updates that reply to updates from %2$s / %3$s.'),
$sitename, $user->nickname, $profile->getBestName());
if (!$page) {
$page = 1;
......@@ -385,7 +387,8 @@ class TwitapistatusesAction extends TwitterapiAction
$since = strtotime($this->arg('since'));
$notice = $user->getReplies((($page-1)*20), $count, $since_id, $before_id, $since);
$notice = $user->getReplies((($page-1)*20),
$count, $since_id, $before_id, $since);
$notices = array();
while ($notice->fetch()) {
......@@ -400,14 +403,10 @@ class TwitapistatusesAction extends TwitterapiAction
$this->show_rss_timeline($notices, $title, $link, $subtitle);
break;
case 'atom':
if (isset($apidata['api_arg'])) {
$selfuri = $selfuri = common_root_url() .
'api/statuses/replies/' . $apidata['api_arg'] . '.atom';
} else {
$selfuri = $selfuri = common_root_url() .
'api/statuses/replies.atom';
}
$this->show_atom_timeline($notices, $title, $id, $link, $subtitle, null, $selfuri);
$selfuri = common_root_url() .
ltrim($_SERVER['QUERY_STRING'], 'p=');
$this->show_atom_timeline($notices, $title, $id, $link, $subtitle,
null, $selfuri);
break;
case 'json':
$this->show_json_timeline($notices);
......@@ -418,6 +417,11 @@ class TwitapistatusesAction extends TwitterapiAction
}
function replies($args, $apidata)
{
call_user_func(array($this, 'mentions'), $args, $apidata);
}
function show($args, $apidata)
{
parent::handle($args);
......
......@@ -82,8 +82,8 @@ class TwitapiusersAction extends TwitterapiAction
$twitter_user['profile_text_color'] = '';
$twitter_user['profile_link_color'] = '';
$twitter_user['profile_sidebar_fill_color'] = '';
$twitter_user['profile_sidebar_border_color'] = '';
$twitter_user['profile_background_tile'] = 'false';
$twitter_user['profile_sidebar_border_color'] = '';
$twitter_user['profile_background_tile'] = false;
$faves = DB_DataObject::factory('fave');
$faves->user_id = $user->id;
......@@ -103,24 +103,16 @@ class TwitapiusersAction extends TwitterapiAction
if (isset($apidata['user'])) {
if ($apidata['user']->isSubscribed($profile)) {
$twitter_user['following'] = 'true';
} else {
$twitter_user['following'] = 'false';
}
$twitter_user['following'] = $apidata['user']->isSubscribed($profile);
// Notifications on?
$sub = Subscription::pkeyGet(array('subscriber' =>
$apidata['user']->id, 'subscribed' => $profile->id));
// Notifications on?
$sub = Subscription::pkeyGet(array('subscriber' =>
$apidata['user']->id, 'subscribed' => $profile->id));
if ($sub) {
if ($sub->jabber || $sub->sms) {
$twitter_user['notifications'] = 'true';
} else {
$twitter_user['notifications'] = 'false';
}
}
}
if ($sub) {
$twitter_user['notifications'] = ($sub->jabber || $sub->sms);
}
}
if ($apidata['content-type'] == 'xml') {
$this->init_document('xml');
......
......@@ -206,7 +206,12 @@ class Notice extends Memcached_DataObject
$notice->saveTags();
$notice->saveGroups();
$notice->addToInboxes();
if (common_config('queue', 'enabled')) {
$notice->addToAuthorInbox();
} else {
$notice->addToInboxes();
}
$notice->query('COMMIT');
Event::handle('EndNoticeSave', array($notice));
......@@ -216,7 +221,11 @@ class Notice extends Memcached_DataObject
# XXX: someone clever could prepend instead of clearing the cache
if (common_config('memcached', 'enabled')) {
$notice->blowCaches();
if (common_config('queue', 'enabled')) {
$notice->blowAuthorCaches();
} else {
$notice->blowCaches();
}
}
return $notice;
......@@ -280,6 +289,17 @@ class Notice extends Memcached_DataObject
$this->blowGroupCache($blowLast);
}
function blowAuthorCaches($blowLast=false)
{
// Clear the user's cache
$cache = common_memcache();
if (!empty($cache)) {
$cache->delete(common_cache_key('notice_inbox:by_user:'.$this->profile_id));
}
$this->blowNoticeCache($blowLast);
$this->blowPublicCache($blowLast);
}
function blowGroupCache($blowLast=false)
{
$cache = common_memcache();
......@@ -296,9 +316,9 @@ class Notice extends Memcached_DataObject
$member->group_id = $group_inbox->group_id;
if ($member->find()) {
while ($member->fetch()) {
$cache->delete(common_cache_key('user:notices_with_friends:' . $member->profile_id));
$cache->delete(common_cache_key('notice_inbox:by_user:' . $member->profile_id));
if ($blowLast) {
$cache->delete(common_cache_key('user:notices_with_friends:' . $member->profile_id . ';last'));
$cache->delete(common_cache_key('notice_inbox:by_user:' . $member->profile_id . ';last'));
}
}
}
......@@ -341,9 +361,9 @@ class Notice extends Memcached_DataObject
'WHERE subscription.subscribed = ' . $this->profile_id);
while ($user->fetch()) {
$cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));
$cache->delete(common_cache_key('notice_inbox:by_user:'.$user->id));
if ($blowLast) {
$cache->delete(common_cache_key('user:notices_with_friends:' . $user->id . ';last'));
$cache->delete(common_cache_key('notice_inbox:by_user:'.$user->id.';last'));
}
}
$user->free();
......@@ -602,27 +622,80 @@ class Notice extends Memcached_DataObject
return $wrapper;
}
function getStreamByIds($ids)
{
$cache = common_memcache();
if (!empty($cache)) {
$notices = array();
foreach ($ids as $id) {
$notices[] = Notice::staticGet('id', $id);
}
return new ArrayWrapper($notices);
} else {
$notice = new Notice();
$notice->whereAdd('id in (' . implode(', ', $ids) . ')');
$notice->orderBy('id DESC');
$notice->find();
return $notice;
}
}
function publicStream($offset=0, $limit=20, $since_id=0, $before_id=0, $since=null)
{
$ids = Notice::stream(array('Notice', '_publicStreamDirect'),
array(),
'public',
$offset, $limit, $since_id, $before_id, $since);
$parts = array();
return Notice::getStreamByIds($ids);
}
$qry = 'SELECT * FROM notice ';
function _publicStreamDirect($offset=0, $limit=20, $since_id=0, $before_id=0, $since=null)
{
$notice = new Notice();
$notice->selectAdd(); // clears it
$notice->selectAdd('id');
$notice->orderBy('id DESC');
if (!is_null($offset)) {
$notice->limit($offset, $limit);
}
if (common_config('public', 'localonly')) {
$parts[] = 'is_local = 1';
$notice->whereAdd('is_local = 1');
} else {
# -1 == blacklisted
$parts[] = 'is_local != -1';
$notice->whereAdd('is_local != -1');
}
if ($since_id != 0) {
$notice->whereAdd('id > ' . $since_id);
}
if ($before_id != 0) {
$notice->whereAdd('id < ' . $before_id);
}
if (!is_null($since)) {
$notice->whereAdd('created > \'' . date('Y-m-d H:i:s', $since) . '\'');
}
if ($parts) {
$qry .= ' WHERE ' . implode(' AND ', $parts);
$ids = array();
if ($notice->find()) {
while ($notice->fetch()) {
$ids[] = $notice->id;
}
}
return Notice::getStream($qry,
'public',
$offset, $limit, $since_id, $before_id, null, $since);
$notice->free();
$notice = NULL;
return $ids;
}
function addToInboxes()
......@@ -648,6 +721,33 @@ class Notice extends Memcached_DataObject
return;
}
function addToAuthorInbox()
{
$enabled = common_config('inboxes', 'enabled');
if ($enabled === true || $enabled === 'transitional') {
$user = User::staticGet('id', $this->profile_id);
if (empty($user)) {
return;
}
$inbox = new Notice_inbox();
$UT = common_config('db','type')=='pgsql'?'"user"':'user';
$qry = 'INSERT INTO notice_inbox (user_id, notice_id, created) ' .
"SELECT $UT.id, " . $this->id . ", '" . $this->created . "' " .
"FROM $UT " .
"WHERE $UT.id = " . $this->profile_id . ' ' .
'AND NOT EXISTS (SELECT user_id, notice_id ' .
'FROM notice_inbox ' .
"WHERE user_id = " . $this->profile_id . ' '.
'AND notice_id = ' . $this->id . ' )';
if ($enabled === 'transitional') {
$qry .= " AND $UT.inboxed = 1";
}
$inbox->query($qry);
}
return;
}
function saveGroups()
{
$enabled = common_config('inboxes', 'enabled');
......@@ -700,24 +800,29 @@ class Notice extends Memcached_DataObject
// FIXME: do this in an offline daemon
$inbox = new Notice_inbox();
$UT = common_config('db','type')=='pgsql'?'"user"':'user';
$qry = 'INSERT INTO notice_inbox (user_id, notice_id, created, source) ' .
"SELECT $UT.id, " . $this->id . ", '" . $this->created . "', 2 " .
"FROM $UT JOIN group_member ON $UT.id = group_member.profile_id " .
'WHERE group_member.group_id = ' . $group->id . ' ' .
'AND NOT EXISTS (SELECT user_id, notice_id ' .
'FROM notice_inbox ' .
"WHERE user_id = $UT.id " .
'AND notice_id = ' . $this->id . ' )';
if ($enabled === 'transitional') {
$qry .= " AND $UT.inboxed = 1";
}
$result = $inbox->query($qry);
$this->addToGroupInboxes($group);
}
}
}
function addToGroupInboxes($group)
{
$inbox = new Notice_inbox();
$UT = common_config('db','type')=='pgsql'?'"user"':'user';
$qry = 'INSERT INTO notice_inbox (user_id, notice_id, created, source) ' .
"SELECT $UT.id, " . $this->id . ", '" . $this->created . "', 2 " .
"FROM $UT JOIN group_member ON $UT.id = group_member.profile_id " .
'WHERE group_member.group_id = ' . $group->id . ' ' .
'AND NOT EXISTS (SELECT user_id, notice_id ' .
'FROM notice_inbox ' .
"WHERE user_id = $UT.id " .
'AND notice_id = ' . $this->id . ' )';
if ($enabled === 'transitional') {
$qry .= " AND $UT.inboxed = 1";
}
$result = $inbox->query($qry);
}
function saveReplies()
{
// Alternative reply format
......@@ -913,4 +1018,59 @@ class Notice extends Memcached_DataObject
array('notice' => $this->id));
}
}
function stream($fn, $args, $cachekey, $offset=0, $limit=20, $since_id=0, $before_id=0, $since=null)
{
$cache = common_memcache();
if (empty($cache) ||
$since_id != 0 || $before_id != 0 || !is_null($since) ||
($offset + $limit) > NOTICE_CACHE_WINDOW) {
return call_user_func_array($fn, array_merge($args, array($offset, $limit, $since_id,
$before_id, $since)));
}
$idkey = common_cache_key($cachekey);
$idstr = $cache->get($idkey);
if (!empty($idstr)) {
// Cache hit! Woohoo!
$window = explode(',', $idstr);
$ids = array_slice($window, $offset, $limit);
return $ids;
}
$laststr = $cache->get($idkey.';last');
if (!empty($laststr)) {
$window = explode(',', $laststr);
$last_id = $window[0];
$new_ids = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW,
$last_id, 0, null)));
$new_window = array_merge($new_ids, $window);
$new_windowstr = implode(',', $new_window);
$result = $cache->set($idkey, $new_windowstr);
$result = $cache->set($idkey . ';last', $new_windowstr);
$ids = array_slice($new_window, $offset, $limit);
return $ids;
}
$window = call_user_func_array($fn, array_merge($args, array(0, NOTICE_CACHE_WINDOW,
0, 0, null)));
$windowstr = implode(',', $window);
$result = $cache->set($idkey, $windowstr);
$result = $cache->set($idkey . ';last', $windowstr);
$ids = array_slice($window, $offset, $limit);
return $ids;
}
}
<?php
/*
* Laconica - a distributed open-source microblogging tool
* Copyright (C) 2008, Controlez-Vous, Inc.
* Copyright (C) 2008, 2009, Control Yourself, 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
......@@ -21,7 +21,11 @@ if (!defined('LACONICA')) { exit(1); }
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
class Notice_inbox extends Memcached_DataObject
// We keep 5 pages of inbox notices in memcache, +1 for pagination check
define('INBOX_CACHE_WINDOW', 101);
class Notice_inbox extends Memcached_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
......@@ -38,4 +42,47 @@ class Notice_inbox extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
function stream($user_id, $offset, $limit, $since_id, $before_id, $since)
{
return Notice::stream(array('Notice_inbox', '_streamDirect'),
array($user_id),
'notice_inbox:by_user:'.$user_id,
$offset, $limit, $since_id, $before_id, $since);
}
function _streamDirect($user_id, $offset, $limit, $since_id, $before_id, $since)
{
$inbox = new Notice_inbox();
$inbox->user_id = $user_id;
if ($since_id != 0) {
$inbox->whereAdd('notice_id > ' . $since_id);
}
if ($before_id != 0) {
$inbox->whereAdd('notice_id < ' . $before_id);
}
if (!is_null($since)) {
$inbox->whereAdd('created > \'' . date('Y-m-d H:i:s', $since) . '\'');
}
$inbox->orderBy('notice_id DESC');
if (!is_null($offset)) {
$inbox->limit($offset, $limit);
}
$ids = array();
if ($inbox->find()) {
while ($inbox->fetch()) {
$ids[] = $inbox->notice_id;
}
}
return $ids;
}
}
......@@ -444,21 +444,17 @@ class User extends Memcached_DataObject
'SELECT notice.* ' .
'FROM notice JOIN subscription ON notice.profile_id = subscription.subscribed ' .
'WHERE subscription.subscriber = %d ';
$order = null;
return Notice::getStream(sprintf($qry, $this->id),
'user:notices_with_friends:' . $this->id,
$offset, $limit, $since_id, $before_id,
$order, $since);
} else if ($enabled === true ||
($enabled == 'transitional' && $this->inboxed == 1)) {
$qry =
'SELECT notice.* ' .
'FROM notice JOIN notice_inbox ON notice.id = notice_inbox.notice_id ' .
'WHERE notice_inbox.user_id = %d ';
// NOTE: we override ORDER
$order = null;
$ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since);
return Notice::getStreamByIds($ids);
}
return Notice::getStream(sprintf($qry, $this->id),
'user:notices_with_friends:' . $this->id,
$offset, $limit, $since_id, $before_id,
$order, $since);
}
function blowFavesCache()
......
......@@ -8,6 +8,7 @@ VALUES