summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorCraig Andrews <candrews@integralblue.com>2010-02-16 10:25:57 -0500
committerCraig Andrews <candrews@integralblue.com>2010-02-16 10:25:57 -0500
commit32084e33a266797b306158df29e48f057651b410 (patch)
tree2a46e529783c8547aaae8ac00c8cac9bdfa61490 /classes
parent057ec1fceacbfec1f755a5bc6700a188aa70e33f (diff)
parentd4f6235d7b8a40bd1b51370e7eb405cdb14e61fb (diff)
Merge branch '0.9.x' into 1.0.x
Conflicts: lib/queuemanager.php
Diffstat (limited to 'classes')
-rw-r--r--classes/Inbox.php62
-rw-r--r--classes/Memcached_DataObject.php2
-rw-r--r--classes/Nonce.php15
-rw-r--r--classes/Notice.php81
-rw-r--r--classes/Profile.php86
-rw-r--r--classes/User.php14
-rw-r--r--classes/User_group.php37
-rw-r--r--classes/statusnet.ini3
-rw-r--r--classes/statusnet.links.ini7
9 files changed, 278 insertions, 29 deletions
diff --git a/classes/Inbox.php b/classes/Inbox.php
index 26b27d2b5..be62611a1 100644
--- a/classes/Inbox.php
+++ b/classes/Inbox.php
@@ -32,6 +32,7 @@ require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
class Inbox extends Memcached_DataObject
{
const BOXCAR = 128;
+ const MAX_NOTICES = 1024;
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
@@ -81,7 +82,7 @@ class Inbox extends Memcached_DataObject
$ni->selectAdd();
$ni->selectAdd('notice_id');
$ni->orderBy('notice_id DESC');
- $ni->limit(0, 1024);
+ $ni->limit(0, self::MAX_NOTICES);
if ($ni->find()) {
while($ni->fetch()) {
@@ -115,9 +116,11 @@ class Inbox extends Memcached_DataObject
$result = $inbox->query(sprintf('UPDATE inbox '.
'set notice_ids = concat(cast(0x%08x as binary(4)), '.
- 'substr(notice_ids, 1, 4092)) '.
+ 'substr(notice_ids, 1, %d)) '.
'WHERE user_id = %d',
- $notice_id, $user_id));
+ $notice_id,
+ 4 * (self::MAX_NOTICES - 1),
+ $user_id));
if ($result) {
self::blow('inbox:user_id:%d', $user_id);
@@ -173,4 +176,57 @@ class Inbox extends Memcached_DataObject
return $ids;
}
+
+ /**
+ * Wrapper for Inbox::stream() and Notice::getStreamByIds() returning
+ * additional items up to the limit if we were short due to deleted
+ * notices still being listed in the inbox.
+ *
+ * The fast path (when no items are deleted) should be just as fast; the
+ * offset parameter is applied *before* lookups for maximum efficiency.
+ *
+ * This means offset-based paging may show duplicates, but similar behavior
+ * already exists when new notices are posted between page views, so we
+ * think people will be ok with this until id-based paging is introduced
+ * to the user interface.
+ *
+ * @param int $user_id
+ * @param int $offset skip past the most recent N notices (after since_id checks)
+ * @param int $limit
+ * @param mixed $since_id return only notices after but not including this id
+ * @param mixed $max_id return only notices up to and including this id
+ * @param mixed $since obsolete/ignored
+ * @param mixed $own ignored?
+ * @return array of Notice objects
+ *
+ * @todo consider repacking the inbox when this happens?
+ */
+ function streamNotices($user_id, $offset, $limit, $since_id, $max_id, $since, $own=false)
+ {
+ $ids = self::stream($user_id, $offset, self::MAX_NOTICES, $since_id, $max_id, $since, $own);
+
+ // Do a bulk lookup for the first $limit items
+ // Fast path when nothing's deleted.
+ $firstChunk = array_slice($ids, 0, $limit);
+ $notices = Notice::getStreamByIds($firstChunk);
+
+ $wanted = count($firstChunk); // raw entry count in the inbox up to our $limit
+ if ($notices->N >= $wanted) {
+ return $notices;
+ }
+
+ // There were deleted notices, we'll need to look for more.
+ assert($notices instanceof ArrayWrapper);
+ $items = $notices->_items;
+ $remainder = array_slice($ids, $limit);
+
+ while (count($items) < $wanted && count($remainder) > 0) {
+ $notice = Notice::staticGet(array_shift($remainder));
+ if ($notice) {
+ $items[] = $notice;
+ } else {
+ }
+ }
+ return new ArrayWrapper($items);
+ }
}
diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php
index ab65c30ce..dfd06b57e 100644
--- a/classes/Memcached_DataObject.php
+++ b/classes/Memcached_DataObject.php
@@ -363,7 +363,7 @@ class Memcached_DataObject extends DB_DataObject
$cached[] = clone($inst);
}
$inst->free();
- $c->set($ckey, $cached, MEMCACHE_COMPRESSED, $expiry);
+ $c->set($ckey, $cached, Cache::COMPRESSED, $expiry);
return new ArrayWrapper($cached);
}
diff --git a/classes/Nonce.php b/classes/Nonce.php
index 486a65a3c..2f8ab00b5 100644
--- a/classes/Nonce.php
+++ b/classes/Nonce.php
@@ -22,4 +22,19 @@ class Nonce extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
+
+ /**
+ * Compatibility hack for PHP 5.3
+ *
+ * The statusnet.links.ini entry cannot be read because "," is no longer
+ * allowed in key names when read by parse_ini_file().
+ *
+ * @return array
+ * @access public
+ */
+ function links()
+ {
+ return array('consumer_key,token' => 'token:consumer_key,token');
+ }
+
}
diff --git a/classes/Notice.php b/classes/Notice.php
index 42878d94f..73b22d58a 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -783,7 +783,7 @@ class Notice extends Memcached_DataObject
$result = $gi->insert();
- if (!result) {
+ if (!$result) {
common_log_db_error($gi, 'INSERT', __FILE__);
throw new ServerException(_('Problem saving group inbox.'));
}
@@ -917,7 +917,7 @@ class Notice extends Memcached_DataObject
/**
* Same calculation as saveGroups but without the saving
* @fixme merge the functions
- * @return array of Group objects
+ * @return array of Group_inbox objects
*/
function getGroups()
{
@@ -957,7 +957,10 @@ class Notice extends Memcached_DataObject
if ($namespace) {
$attrs = array('xmlns' => 'http://www.w3.org/2005/Atom',
- 'xmlns:thr' => 'http://purl.org/syndication/thread/1.0');
+ 'xmlns:thr' => 'http://purl.org/syndication/thread/1.0',
+ 'xmlns:georss' => 'http://www.georss.org/georss',
+ 'xmlns:activity' => 'http://activitystrea.ms/spec/1.0/',
+ 'xmlns:ostatus' => 'http://ostatus.org/schema/1.0');
} else {
$attrs = array();
}
@@ -983,11 +986,6 @@ class Notice extends Memcached_DataObject
$xs->element('icon', null, $profile->avatarUrl(AVATAR_PROFILE_SIZE));
}
- $xs->elementStart('author');
- $xs->element('name', null, $profile->nickname);
- $xs->element('uri', null, $profile->profileurl);
- $xs->elementEnd('author');
-
if ($source) {
$xs->elementEnd('source');
}
@@ -995,6 +993,9 @@ class Notice extends Memcached_DataObject
$xs->element('title', null, $this->content);
$xs->element('summary', null, $this->content);
+ $xs->raw($profile->asAtomAuthor());
+ $xs->raw($profile->asActivityActor());
+
$xs->element('link', array('rel' => 'alternate',
'href' => $this->bestUrl()));
@@ -1014,6 +1015,43 @@ class Notice extends Memcached_DataObject
}
}
+ if (!empty($this->conversation)
+ && $this->conversation != $this->id) {
+ $xs->element(
+ 'link', array(
+ 'rel' => 'ostatus:conversation',
+ 'href' => common_local_url(
+ 'conversation',
+ array('id' => $this->conversation)
+ )
+ )
+ );
+ }
+
+ $reply_ids = $this->getReplies();
+
+ foreach ($reply_ids as $id) {
+ $profile = Profile::staticGet('id', $id);
+ if (!empty($profile)) {
+ $xs->element(
+ 'link', array(
+ 'rel' => 'ostatus:attention',
+ 'href' => $profile->getAcctUri()
+ )
+ );
+ }
+ }
+
+ if (!empty($this->repeat_of)) {
+ $repeat = Notice::staticGet('id', $this->repeat_of);
+ if (!empty($repeat)) {
+ $xs->element(
+ 'ostatus:forward',
+ array('ref' => $repeat->uri, 'href' => $repeat->bestUrl())
+ );
+ }
+ }
+
$xs->element('content', array('type' => 'html'), $this->rendered);
$tag = new Notice_tag();
@@ -1041,9 +1079,7 @@ class Notice extends Memcached_DataObject
}
if (!empty($this->lat) && !empty($this->lon)) {
- $xs->elementStart('geo', array('xmlns:georss' => 'http://www.georss.org/georss'));
$xs->element('georss:point', null, $this->lat . ' ' . $this->lon);
- $xs->elementEnd('geo');
}
$xs->elementEnd('entry');
@@ -1176,6 +1212,10 @@ class Notice extends Memcached_DataObject
// Figure out who that is.
$sender = Profile::staticGet('id', $profile_id);
+ if (empty($sender)) {
+ return null;
+ }
+
$recipient = common_relative_profile($sender, $nickname, common_sql_now());
if (empty($recipient)) {
@@ -1468,4 +1508,25 @@ class Notice extends Memcached_DataObject
$handler->handle($this);
}
}
+
+ function insert()
+ {
+ $result = parent::insert();
+
+ if ($result) {
+ // Profile::hasRepeated() abuses pkeyGet(), so we
+ // have to clear manually
+ if (!empty($this->repeat_of)) {
+ $c = self::memcache();
+ if (!empty($c)) {
+ $ck = self::multicacheKey('Notice',
+ array('profile_id' => $this->profile_id,
+ 'repeat_of' => $this->repeat_of));
+ $c->delete($ck);
+ }
+ }
+ }
+
+ return $result;
+ }
}
diff --git a/classes/Profile.php b/classes/Profile.php
index 1076fb2cb..ab05bb854 100644
--- a/classes/Profile.php
+++ b/classes/Profile.php
@@ -716,6 +716,7 @@ class Profile extends Memcached_DataObject
switch ($right)
{
case Right::DELETEOTHERSNOTICE:
+ case Right::MAKEGROUPADMIN:
case Right::SANDBOXUSER:
case Right::SILENCEUSER:
case Right::DELETEUSER:
@@ -753,4 +754,89 @@ class Profile extends Memcached_DataObject
return !empty($notice);
}
+
+ /**
+ * Returns an XML string fragment with limited profile information
+ * as an Atom <author> element.
+ *
+ * Assumes that Atom has been previously set up as the base namespace.
+ *
+ * @return string
+ */
+ function asAtomAuthor()
+ {
+ $xs = new XMLStringer(true);
+
+ $xs->elementStart('author');
+ $xs->element('name', null, $this->nickname);
+ $xs->element('uri', null, $this->profileurl);
+ $xs->elementEnd('author');
+
+ return $xs->getString();
+ }
+
+ /**
+ * Returns an XML string fragment with profile information as an
+ * Activity Streams <activity:actor> element.
+ *
+ * Assumes that 'activity' namespace has been previously defined.
+ *
+ * @return string
+ */
+ function asActivityActor()
+ {
+ return $this->asActivityNoun('actor');
+ }
+
+ /**
+ * Returns an XML string fragment with profile information as an
+ * Activity Streams noun object with the given element type.
+ *
+ * Assumes that 'activity' namespace has been previously defined.
+ *
+ * @param string $element one of 'actor', 'subject', 'object', 'target'
+ * @return string
+ */
+ function asActivityNoun($element)
+ {
+ $xs = new XMLStringer(true);
+
+ $xs->elementStart('activity:' . $element);
+ $xs->element(
+ 'activity:object-type',
+ null,
+ 'http://activitystrea.ms/schema/1.0/person'
+ );
+ $xs->element(
+ 'id',
+ null,
+ common_local_url(
+ 'userbyid',
+ array('id' => $this->id)
+ )
+ );
+ $xs->element('title', null, $this->getBestName());
+
+ $avatar = $this->getAvatar(AVATAR_PROFILE_SIZE);
+
+ $xs->element(
+ 'link', array(
+ 'type' => empty($avatar) ? 'image/png' : $avatar->mediatype,
+ 'href' => empty($avatar)
+ ? Avatar::defaultImage(AVATAR_PROFILE_SIZE)
+ : $avatar->displayUrl()
+ ),
+ ''
+ );
+
+ $xs->elementEnd('activity:' . $element);
+
+ return $xs->getString();
+ }
+
+ function getAcctUri()
+ {
+ return $this->nickname . '@' . common_config('site', 'server');
+ }
+
}
diff --git a/classes/User.php b/classes/User.php
index e7cecf975..1c967b527 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -497,28 +497,22 @@ class User extends Memcached_DataObject
function noticesWithFriends($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
{
- $ids = Inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, false);
- return Notice::getStreamByIds($ids);
+ return Inbox::streamNotices($this->id, $offset, $limit, $since_id, $before_id, $since, false);
}
function noticeInbox($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
{
- $ids = Inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, true);
- return Notice::getStreamByIds($ids);
+ return Inbox::streamNotices($this->id, $offset, $limit, $since_id, $before_id, $since, true);
}
function friendsTimeline($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
{
- $ids = Inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, false);
-
- return Notice::getStreamByIds($ids);
+ return Inbox::streamNotices($this->id, $offset, $limit, $since_id, $before_id, $since, false);
}
function ownFriendsTimeline($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
{
- $ids = Inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, true);
-
- return Notice::getStreamByIds($ids);
+ return Inbox::streamNotices($this->id, $offset, $limit, $since_id, $before_id, $since, true);
}
function blowFavesCache()
diff --git a/classes/User_group.php b/classes/User_group.php
index c86eadf8f..379e6b721 100644
--- a/classes/User_group.php
+++ b/classes/User_group.php
@@ -49,12 +49,12 @@ class User_group extends Memcached_DataObject
array('id' => $this->id));
}
- function getNotices($offset, $limit)
+ function getNotices($offset, $limit, $since_id=null, $max_id=null)
{
$ids = Notice::stream(array($this, '_streamDirect'),
array(),
'user_group:notice_ids:' . $this->id,
- $offset, $limit);
+ $offset, $limit, $since_id, $max_id);
return Notice::getStreamByIds($ids);
}
@@ -355,6 +355,39 @@ class User_group extends Memcached_DataObject
return $xs->getString();
}
+ function asAtomAuthor()
+ {
+ $xs = new XMLStringer(true);
+
+ $xs->elementStart('author');
+ $xs->element('name', null, $this->nickname);
+ $xs->element('uri', null, $this->permalink());
+ $xs->elementEnd('author');
+
+ return $xs->getString();
+ }
+
+ function asActivitySubject()
+ {
+ $xs = new XMLStringer(true);
+
+ $xs->elementStart('activity:subject');
+ $xs->element('activity:object', null, 'http://activitystrea.ms/schema/1.0/group');
+ $xs->element('id', null, $this->permalink());
+ $xs->element('title', null, $this->getBestName());
+ $xs->element(
+ 'link', array(
+ 'rel' => 'avatar',
+ 'href' => empty($this->homepage_logo)
+ ? User_group::defaultLogo(AVATAR_PROFILE_SIZE)
+ : $this->homepage_logo
+ )
+ );
+ $xs->elementEnd('activity:subject');
+
+ return $xs->getString();
+ }
+
static function register($fields) {
// MAGICALLY put fields into current scope
diff --git a/classes/statusnet.ini b/classes/statusnet.ini
index 9916384fd..bcff744bd 100644
--- a/classes/statusnet.ini
+++ b/classes/statusnet.ini
@@ -353,7 +353,7 @@ notice_id = K
id = 129
owner = 129
consumer_key = 130
-name = 2
+name = 130
description = 2
icon = 130
source_url = 2
@@ -580,6 +580,7 @@ modified = 384
[user_group__keys]
id = N
+nickname = U
[user_openid]
canonical = 130
diff --git a/classes/statusnet.links.ini b/classes/statusnet.links.ini
index 7f233e676..b9dd5af0c 100644
--- a/classes/statusnet.links.ini
+++ b/classes/statusnet.links.ini
@@ -19,8 +19,11 @@ profile_id = profile:id
[token]
consumer_key = consumer:consumer_key
-[nonce]
-consumer_key,token = token:consumer_key,token
+; Compatibility hack for PHP 5.3
+; This entry has been moved to the class definition, as commas are no longer
+; considered valid in keys, causing parse_ini_file() to reject the whole file.
+;[nonce]
+;consumer_key,token = token:consumer_key,token
[confirm_address]
user_id = user:id