summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-02-26 09:35:28 -0800
committerBrion Vibber <brion@pobox.com>2010-02-26 09:35:28 -0800
commit8dfc8f1635940b096e7f4025e3aef0ca4f909eb2 (patch)
tree9fce4aa765d56496031698f219da2f0f82b33e80 /lib
parent8914b69d5055c1bc7d0604ee338ffdaf6b0a8606 (diff)
parentb331e971b055386a126aaec27d661f26ba3b813c (diff)
Merge branch 'testing' into 0.9.x
Diffstat (limited to 'lib')
-rw-r--r--lib/activity.php334
-rw-r--r--lib/apiaction.php (renamed from lib/api.php)21
-rw-r--r--lib/apiauth.php1
-rw-r--r--lib/atomnoticefeed.php5
-rw-r--r--lib/common.php2
-rw-r--r--lib/default.php1
-rw-r--r--lib/distribqueuehandler.php12
-rw-r--r--lib/joinform.php2
-rw-r--r--lib/leaveform.php2
-rw-r--r--lib/profilequeuehandler.php6
-rw-r--r--lib/router.php7
-rw-r--r--lib/util.php8
12 files changed, 345 insertions, 56 deletions
diff --git a/lib/activity.php b/lib/activity.php
index 25727bf2b..b20153213 100644
--- a/lib/activity.php
+++ b/lib/activity.php
@@ -154,7 +154,15 @@ class PoCo
PoCo::NS
);
- array_push($urls, new PoCoURL($type, $value, $primary));
+ $isPrimary = false;
+
+ if (isset($primary) && $primary == 'true') {
+ $isPrimary = true;
+ }
+
+ // @todo check to make sure a primary hasn't already been added
+
+ array_push($urls, new PoCoURL($type, $value, $isPrimary));
}
return $urls;
}
@@ -215,6 +223,46 @@ class PoCo
return $poco;
}
+ function fromGroup($group)
+ {
+ if (empty($group)) {
+ return null;
+ }
+
+ $poco = new PoCo();
+
+ $poco->preferredUsername = $group->nickname;
+ $poco->displayName = $group->getBestName();
+
+ $poco->note = $group->description;
+
+ $paddy = new PoCoAddress();
+ $paddy->formatted = $group->location;
+ $poco->address = $paddy;
+
+ if (!empty($group->homepage)) {
+ array_push(
+ $poco->urls,
+ new PoCoURL(
+ 'homepage',
+ $group->homepage,
+ true
+ )
+ );
+ }
+
+ return $poco;
+ }
+
+ function getPrimaryURL()
+ {
+ foreach ($this->urls as $url) {
+ if ($url->primary) {
+ return $url;
+ }
+ }
+ }
+
function asString()
{
$xs = new XMLStringer(true);
@@ -312,6 +360,25 @@ class ActivityUtils
return null;
}
+ static function getLinks(DOMNode $element, $rel, $type=null)
+ {
+ $links = $element->getElementsByTagnameNS(self::ATOM, self::LINK);
+ $out = array();
+
+ foreach ($links as $link) {
+
+ $linkRel = $link->getAttribute(self::REL);
+ $linkType = $link->getAttribute(self::TYPE);
+
+ if ($linkRel == $rel &&
+ (is_null($type) || $linkType == $type)) {
+ $out[] = $link;
+ }
+ }
+
+ return $out;
+ }
+
/**
* Gets the first child element with the given tag
*
@@ -417,6 +484,75 @@ class ActivityUtils
}
}
+// XXX: Arg! This wouldn't be necessary if we used Avatars conistently
+class AvatarLink
+{
+ public $url;
+ public $type;
+ public $size;
+ public $width;
+ public $height;
+
+ function __construct($element=null)
+ {
+ if ($element) {
+ // @fixme use correct namespaces
+ $this->url = $element->getAttribute('href');
+ $this->type = $element->getAttribute('type');
+ $width = $element->getAttribute('media:width');
+ if ($width != null) {
+ $this->width = intval($width);
+ }
+ $height = $element->getAttribute('media:height');
+ if ($height != null) {
+ $this->height = intval($height);
+ }
+ }
+ }
+
+ static function fromAvatar($avatar)
+ {
+ if (empty($avatar)) {
+ return null;
+ }
+ $alink = new AvatarLink();
+ $alink->type = $avatar->mediatype;
+ $alink->height = $avatar->height;
+ $alink->width = $avatar->width;
+ $alink->url = $avatar->displayUrl();
+ return $alink;
+ }
+
+ static function fromFilename($filename, $size)
+ {
+ $alink = new AvatarLink();
+ $alink->url = $filename;
+ $alink->height = $size;
+ if (!empty($filename)) {
+ $alink->width = $size;
+ $alink->type = self::mediatype($filename);
+ } else {
+ $alink->url = User_group::defaultLogo($size);
+ $alink->type = 'image/png';
+ }
+ return $alink;
+ }
+
+ // yuck!
+ static function mediatype($filename) {
+ $ext = strtolower(end(explode('.', $filename)));
+ if ($ext == 'jpeg') {
+ $ext = 'jpg';
+ }
+ // hope we don't support any others
+ $types = array('png', 'gif', 'jpg', 'jpeg');
+ if (in_array($ext, $types)) {
+ return 'image/' . $ext;
+ }
+ return null;
+ }
+}
+
/**
* A noun-ish thing in the activity universe
*
@@ -473,7 +609,7 @@ class ActivityObject
public $content;
public $link;
public $source;
- public $avatar;
+ public $avatarLinks = array();
public $geopoint;
public $poco;
public $displayName;
@@ -496,6 +632,12 @@ class ActivityObject
$this->element = $element;
+ $this->geopoint = $this->_childContent(
+ $element,
+ ActivityContext::POINT,
+ ActivityContext::GEORSS
+ );
+
if ($element->tagName == 'author') {
$this->type = self::PERSON; // XXX: is this fair?
@@ -535,8 +677,10 @@ class ActivityObject
if ($this->type == self::PERSON || $this->type == self::GROUP) {
$this->displayName = $this->title;
- // @fixme we may have multiple avatars with different resolutions specified
- $this->avatar = ActivityUtils::getLink($element, 'avatar');
+ $avatars = ActivityUtils::getLinks($element, 'avatar');
+ foreach ($avatars as $link) {
+ $this->avatarLinks[] = new AvatarLink($link);
+ }
$this->poco = new PoCo($element);
}
@@ -587,10 +731,40 @@ class ActivityObject
$object->id = $profile->getUri();
$object->title = $profile->getBestName();
$object->link = $profile->profileurl;
- $object->avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
+
+ $orig = $profile->getOriginalAvatar();
+
+ if (!empty($orig)) {
+ $object->avatarLinks[] = AvatarLink::fromAvatar($orig);
+ }
+
+ $sizes = array(
+ AVATAR_PROFILE_SIZE,
+ AVATAR_STREAM_SIZE,
+ AVATAR_MINI_SIZE
+ );
+
+ foreach ($sizes as $size) {
+
+ $alink = null;
+ $avatar = $profile->getAvatar($size);
+
+ if (!empty($avatar)) {
+ $alink = AvatarLink::fromAvatar($avatar);
+ } else {
+ $alink = new AvatarLink();
+ $alink->type = 'image/png';
+ $alink->height = $size;
+ $alink->width = $size;
+ $alink->url = Avatar::defaultImage($size);
+ }
+
+ $object->avatarLinks[] = $alink;
+ }
if (isset($profile->lat) && isset($profile->lon)) {
- $object->geopoint = (float)$profile->lat . ' ' . (float)$profile->lon;
+ $object->geopoint = (float)$profile->lat
+ . ' ' . (float)$profile->lon;
}
$object->poco = PoCo::fromProfile($profile);
@@ -598,6 +772,36 @@ class ActivityObject
return $object;
}
+ static function fromGroup($group)
+ {
+ $object = new ActivityObject();
+
+ $object->type = ActivityObject::GROUP;
+ $object->id = $group->getUri();
+ $object->title = $group->getBestName();
+ $object->link = $group->getUri();
+
+ $object->avatarLinks[] = AvatarLink::fromFilename(
+ $group->homepage_logo,
+ AVATAR_PROFILE_SIZE
+ );
+
+ $object->avatarLinks[] = AvatarLink::fromFilename(
+ $group->stream_logo,
+ AVATAR_STREAM_SIZE
+ );
+
+ $object->avatarLinks[] = AvatarLink::fromFilename(
+ $group->mini_logo,
+ AVATAR_MINI_SIZE
+ );
+
+ $object->poco = PoCo::fromGroup($group);
+
+ return $object;
+ }
+
+
function asString($tag='activity:object')
{
$xs = new XMLStringer(true);
@@ -635,16 +839,19 @@ class ActivityObject
if ($this->type == ActivityObject::PERSON
|| $this->type == ActivityObject::GROUP) {
- $xs->element(
- 'link', array(
- 'type' => empty($this->avatar) ? 'image/png' : $this->avatar->mediatype,
- 'rel' => 'avatar',
- 'href' => empty($this->avatar)
- ? Avatar::defaultImage(AVATAR_PROFILE_SIZE)
- : $this->avatar->displayUrl()
- ),
- null
- );
+
+ foreach ($this->avatarLinks as $avatar) {
+ $xs->element(
+ 'link', array(
+ 'rel' => 'avatar',
+ 'type' => $avatar->type,
+ 'media:width' => $avatar->width,
+ 'media:height' => $avatar->height,
+ 'href' => $avatar->url
+ ),
+ null
+ );
+ }
}
if (!empty($this->geopoint)) {
@@ -761,22 +968,29 @@ class ActivityContext
for ($i = 0; $i < $points->length; $i++) {
$point = $points->item($i)->textContent;
- $point = str_replace(',', ' ', $point); // per spec "treat commas as whitespace"
- $point = preg_replace('/\s+/', ' ', $point);
- $point = trim($point);
- $coords = explode(' ', $point);
- if (count($coords) == 2) {
- list($lat, $lon) = $coords;
- if (is_numeric($lat) && is_numeric($lon)) {
- common_log(LOG_INFO, "Looking up location for $lat $lon from georss");
- return Location::fromLatLon($lat, $lon);
- }
- }
- common_log(LOG_ERR, "Ignoring bogus georss:point value $point");
+ return self::locationFromPoint($point);
}
return null;
}
+
+ // XXX: Move to ActivityUtils or Location?
+ static function locationFromPoint($point)
+ {
+ $point = str_replace(',', ' ', $point); // per spec "treat commas as whitespace"
+ $point = preg_replace('/\s+/', ' ', $point);
+ $point = trim($point);
+ $coords = explode(' ', $point);
+ if (count($coords) == 2) {
+ list($lat, $lon) = $coords;
+ if (is_numeric($lat) && is_numeric($lon)) {
+ common_log(LOG_INFO, "Looking up location for $lat $lon from georss point");
+ return Location::fromLatLon($lat, $lon);
+ }
+ }
+ common_log(LOG_ERR, "Ignoring bogus georss:point value $point");
+ return null;
+ }
}
/**
@@ -829,6 +1043,7 @@ class Activity
public $content; // HTML content of activity
public $id; // ID of the activity
public $title; // title of the activity
+ public $categories = array(); // list of AtomCategory objects
/**
* Turns a regular old Atom <entry> into a magical activity
@@ -917,6 +1132,14 @@ class Activity
$this->summary = ActivityUtils::childContent($entry, 'summary');
$this->id = ActivityUtils::childContent($entry, 'id');
$this->content = ActivityUtils::getContent($entry);
+
+ $catEls = $entry->getElementsByTagNameNS(self::ATOM, 'category');
+ if ($catEls) {
+ for ($i = 0; $i < $catEls->length; $i++) {
+ $catEl = $catEls->item($i);
+ $this->categories[] = new AtomCategory($catEl);
+ }
+ }
}
/**
@@ -939,7 +1162,8 @@ class Activity
'xmlns:activity' => 'http://activitystrea.ms/spec/1.0/',
'xmlns:georss' => 'http://www.georss.org/georss',
'xmlns:ostatus' => 'http://ostatus.org/schema/1.0',
- 'xmlns:poco' => 'http://portablecontacts.net/spec/1.0');
+ 'xmlns:poco' => 'http://portablecontacts.net/spec/1.0',
+ 'xmlns:media' => 'http://purl.org/syndication/atommedia');
} else {
$attrs = array();
}
@@ -981,6 +1205,10 @@ class Activity
$xs->raw($this->target->asString('activity:target'));
}
+ foreach ($this->categories as $cat) {
+ $xs->raw($cat->asString());
+ }
+
$xs->elementEnd('entry');
return $xs->getString();
@@ -990,4 +1218,50 @@ class Activity
{
return ActivityUtils::child($element, $tag, $namespace);
}
-} \ No newline at end of file
+}
+
+class AtomCategory
+{
+ public $term;
+ public $scheme;
+ public $label;
+
+ function __construct($element=null)
+ {
+ if ($element && $element->attributes) {
+ $this->term = $this->extract($element, 'term');
+ $this->scheme = $this->extract($element, 'scheme');
+ $this->label = $this->extract($element, 'label');
+ }
+ }
+
+ protected function extract($element, $attrib)
+ {
+ $node = $element->attributes->getNamedItemNS(Activity::ATOM, $attrib);
+ if ($node) {
+ return trim($node->textContent);
+ }
+ $node = $element->attributes->getNamedItem($attrib);
+ if ($node) {
+ return trim($node->textContent);
+ }
+ return null;
+ }
+
+ function asString()
+ {
+ $attribs = array();
+ if ($this->term !== null) {
+ $attribs['term'] = $this->term;
+ }
+ if ($this->scheme !== null) {
+ $attribs['scheme'] = $this->scheme;
+ }
+ if ($this->label !== null) {
+ $attribs['label'] = $this->label;
+ }
+ $xs = new XMLStringer();
+ $xs->element('category', $attribs);
+ return $xs->asString();
+ }
+}
diff --git a/lib/api.php b/lib/apiaction.php
index 26977c90f..9bfca3b66 100644
--- a/lib/api.php
+++ b/lib/apiaction.php
@@ -1219,7 +1219,12 @@ class ApiAction extends Action
return User_group::staticGet($this->arg('id'));
} else if ($this->arg('id')) {
$nickname = common_canonical_nickname($this->arg('id'));
- return User_group::staticGet('nickname', $nickname);
+ $local = Local_group::staticGet('nickname', $nickname);
+ if (empty($local)) {
+ return null;
+ } else {
+ return User_group::staticGet('id', $local->id);
+ }
} else if ($this->arg('group_id')) {
// This is to ensure that a non-numeric user_id still
// overrides screen_name even if it doesn't get used
@@ -1228,14 +1233,24 @@ class ApiAction extends Action
}
} else if ($this->arg('group_name')) {
$nickname = common_canonical_nickname($this->arg('group_name'));
- return User_group::staticGet('nickname', $nickname);
+ $local = Local_group::staticGet('nickname', $nickname);
+ if (empty($local)) {
+ return null;
+ } else {
+ return User_group::staticGet('id', $local->id);
+ }
}
} else if (is_numeric($id)) {
return User_group::staticGet($id);
} else {
$nickname = common_canonical_nickname($id);
- return User_group::staticGet('nickname', $nickname);
+ $local = Local_group::staticGet('nickname', $nickname);
+ if (empty($local)) {
+ return null;
+ } else {
+ return User_group::staticGet('id', $local->group_id);
+ }
}
}
diff --git a/lib/apiauth.php b/lib/apiauth.php
index 25e2196cf..5090871cf 100644
--- a/lib/apiauth.php
+++ b/lib/apiauth.php
@@ -38,7 +38,6 @@ if (!defined('STATUSNET')) {
exit(1);
}
-require_once INSTALLDIR . '/lib/api.php';
require_once INSTALLDIR . '/lib/apioauth.php';
/**
diff --git a/lib/atomnoticefeed.php b/lib/atomnoticefeed.php
index d2bf2a416..3c3556cb9 100644
--- a/lib/atomnoticefeed.php
+++ b/lib/atomnoticefeed.php
@@ -65,6 +65,11 @@ class AtomNoticeFeed extends Atom10Feed
);
$this->addNamespace(
+ 'media',
+ 'http://purl.org/syndication/atommedia'
+ );
+
+ $this->addNamespace(
'poco',
'http://portablecontacts.net/spec/1.0'
);
diff --git a/lib/common.php b/lib/common.php
index 68723955e..2dbe3b3c5 100644
--- a/lib/common.php
+++ b/lib/common.php
@@ -22,7 +22,7 @@ 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; }
-define('STATUSNET_VERSION', '0.9.0beta5');
+define('STATUSNET_VERSION', '0.9.0beta6');
define('LACONICA_VERSION', STATUSNET_VERSION); // compatibility
define('STATUSNET_CODENAME', 'Stand');
diff --git a/lib/default.php b/lib/default.php
index 70e00ea75..b06b96157 100644
--- a/lib/default.php
+++ b/lib/default.php
@@ -278,7 +278,6 @@ $default =
'TightUrl' => array('shortenerName' => '2tu.us', 'freeService' => true,'serviceUrl'=>'http://2tu.us/?save=y&url=%1$s'),
'Geonames' => null,
'Mapstraction' => null,
- 'Linkback' => null,
'WikiHashtags' => null,
'RSSCloud' => null,
'OpenID' => null),
diff --git a/lib/distribqueuehandler.php b/lib/distribqueuehandler.php
index dc183fb36..d2be7a92c 100644
--- a/lib/distribqueuehandler.php
+++ b/lib/distribqueuehandler.php
@@ -63,24 +63,12 @@ class DistribQueueHandler
// XXX: do we need to change this for remote users?
try {
- $notice->saveTags();
- } catch (Exception $e) {
- $this->logit($notice, $e);
- }
-
- try {
$notice->addToInboxes();
} catch (Exception $e) {
$this->logit($notice, $e);
}
try {
- $notice->saveUrls();
- } catch (Exception $e) {
- $this->logit($notice, $e);
- }
-
- try {
Event::handle('EndNoticeSave', array($notice));
// Enqueue for other handlers
} catch (Exception $e) {
diff --git a/lib/joinform.php b/lib/joinform.php
index aefb553aa..aa8bc20e2 100644
--- a/lib/joinform.php
+++ b/lib/joinform.php
@@ -100,7 +100,7 @@ class JoinForm extends Form
function action()
{
return common_local_url('joingroup',
- array('nickname' => $this->group->nickname));
+ array('id' => $this->group->id));
}
/**
diff --git a/lib/leaveform.php b/lib/leaveform.php
index e63d96ee8..5469b5704 100644
--- a/lib/leaveform.php
+++ b/lib/leaveform.php
@@ -100,7 +100,7 @@ class LeaveForm extends Form
function action()
{
return common_local_url('leavegroup',
- array('nickname' => $this->group->nickname));
+ array('id' => $this->group->id));
}
/**
diff --git a/lib/profilequeuehandler.php b/lib/profilequeuehandler.php
index e8a00aef3..6ce93229b 100644
--- a/lib/profilequeuehandler.php
+++ b/lib/profilequeuehandler.php
@@ -39,7 +39,11 @@ class ProfileQueueHandler extends QueueHandler
if (Event::handle('StartBroadcastProfile', array($profile))) {
require_once(INSTALLDIR.'/lib/omb.php');
- omb_broadcast_profile($profile);
+ try {
+ omb_broadcast_profile($profile);
+ } catch (Exception $e) {
+ common_log(LOG_ERR, "Failed sending OMB profiles: " . $e->getMessage());
+ }
}
Event::handle('EndBroadcastProfile', array($profile));
return true;
diff --git a/lib/router.php b/lib/router.php
index 987d0152e..abbce041d 100644
--- a/lib/router.php
+++ b/lib/router.php
@@ -247,6 +247,9 @@ class Router
$m->connect('group/:nickname/'.$v,
array('action' => $v.'group'),
array('nickname' => '[a-zA-Z0-9]+'));
+ $m->connect('group/:id/id/'.$v,
+ array('action' => $v.'group'),
+ array('id' => '[0-9]+'));
}
foreach (array('members', 'logo', 'rss', 'designsettings') as $n) {
@@ -668,7 +671,7 @@ class Router
foreach (array('subscriptions', 'subscribers',
'all', 'foaf', 'xrds',
- 'replies', 'microsummary') as $a) {
+ 'replies', 'microsummary', 'hcard') as $a) {
$m->connect($a,
array('action' => $a,
'nickname' => $nickname));
@@ -734,7 +737,7 @@ class Router
foreach (array('subscriptions', 'subscribers',
'nudge', 'all', 'foaf', 'xrds',
- 'replies', 'inbox', 'outbox', 'microsummary') as $a) {
+ 'replies', 'inbox', 'outbox', 'microsummary', 'hcard') as $a) {
$m->connect(':nickname/'.$a,
array('action' => $a),
array('nickname' => '[a-zA-Z0-9]{1,64}'));
diff --git a/lib/util.php b/lib/util.php
index 094cd8772..1231f4c8d 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -134,7 +134,7 @@ function common_check_user($nickname, $password)
$authenticatedUser = false;
if (Event::handle('StartCheckPassword', array($nickname, $password, &$authenticatedUser))) {
- $user = User::staticGet('nickname', $nickname);
+ $user = User::staticGet('nickname', common_canonical_nickname($nickname));
if (!empty($user)) {
if (!empty($password)) { // never allow login with blank password
if (0 == strcmp(common_munge_password($password, $user->id),
@@ -1599,6 +1599,7 @@ function common_database_tablename($tablename)
*/
function common_shorten_url($long_url)
{
+ $long_url = trim($long_url);
$user = common_current_user();
if (empty($user)) {
// common current user does not find a user when called from the XMPP daemon
@@ -1613,7 +1614,7 @@ function common_shorten_url($long_url)
return $long_url;
}else{
//URL was shortened, so return the result
- return $shortenedUrl;
+ return trim($shortenedUrl);
}
}
@@ -1690,7 +1691,8 @@ function common_url_to_nickname($url)
# Strip starting, ending slashes
$path = preg_replace('@/$@', '', $parts['path']);
$path = preg_replace('@^/@', '', $path);
- if (strpos($path, '/') === false) {
+ $path = basename($path);
+ if ($path) {
return common_nicknamize($path);
}
}