Merge branch 'rationalize-activity' into testing

* rationalize-activity:
  Move ActivityObject and related stuff to core
  Add PoCo bits, avatar link, geo point, etc. to person activity obj output
This commit is contained in:
Zach Copley 2010-02-22 17:12:33 -08:00
commit cbf6ebae01
3 changed files with 152 additions and 102 deletions

View File

@ -1218,25 +1218,8 @@ class Notice extends Memcached_DataObject
*/ */
function asActivityNoun($element) function asActivityNoun($element)
{ {
$xs = new XMLStringer(true); $noun = ActivityObject::fromNotice($this);
return $noun->asString('activity:' . $element);
$xs->elementStart('activity:' . $element);
$xs->element('activity:object-type',
null,
'http://activitystrea.ms/schema/1.0/note');
$xs->element('id',
null,
$this->uri);
$xs->element('content',
array('type' => 'text/html'),
$this->rendered);
$xs->element('link',
array('type' => 'text/html',
'rel' => 'alternate',
'href' => $this->bestUrl()));
$xs->elementEnd('activity:' . $element);
return $xs->getString();
} }
function bestUrl() function bestUrl()

View File

@ -801,82 +801,8 @@ class Profile extends Memcached_DataObject
*/ */
function asActivityNoun($element) function asActivityNoun($element)
{ {
$xs = new XMLStringer(true); $noun = ActivityObject::fromProfile($this);
return $noun->asString('activity:' . $element);
$xs->elementStart('activity:' . $element);
$xs->element(
'activity:object-type',
null,
'http://activitystrea.ms/schema/1.0/person'
);
$xs->element(
'id',
null,
$this->getUri()
);
// title should contain fullname
$xs->element('title', null, $this->getBestName());
$xs->element('link', array('rel' => 'alternate',
'type' => 'text/html'),
$this->profileurl);
$xs->element('poco:preferredUsername', null, $this->nickname);
// Portable Contacts stuff
if (isset($this->bio)) {
// XXX: Possible to use OpenSocial's aboutMe?
$xs->element('poco:note', null, $this->bio);
}
if (isset($this->homepage)) {
$xs->elementStart('poco:urls');
$xs->element('poco:value', null, $this->homepage);
$xs->element('poco:type', null, 'homepage');
$xs->element('poco:primary', null, 'true');
$xs->elementEnd('poco:urls');
}
if (isset($this->location)) {
$xs->elementStart('poco:address');
$xs->element('poco:formatted', null, $this->location);
$xs->elementEnd('poco:address');
}
if (isset($this->lat) && isset($this->lon)) {
$this->element(
'georss:point',
null,
(float)$this->lat . ' ' . (float)$this->lon
);
}
// XXX: Should we send all avatar sizes we have? I think
// cliqset does -Z
$avatar = $this->getAvatar(AVATAR_PROFILE_SIZE);
$xs->element(
'link', array(
'type' => empty($avatar) ? 'image/png' : $avatar->mediatype,
'rel' => 'avatar',
'href' => empty($avatar)
? Avatar::defaultImage(AVATAR_PROFILE_SIZE)
: $avatar->displayUrl()
),
''
);
$xs->elementEnd('activity:' . $element);
// XXX: Add people tags with <poco:tags> plural?
return $xs->getString();
} }
/** /**

View File

@ -19,9 +19,10 @@
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
* @category OStatus * @category Feed
* @package StatusNet * @package StatusNet
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @author Zach Copley <zach@status.net>
* @copyright 2010 StatusNet, Inc. * @copyright 2010 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
* @link http://status.net/ * @link http://status.net/
@ -31,10 +32,117 @@ if (!defined('STATUSNET')) {
exit(1); exit(1);
} }
class PoCoURL
{
const TYPE = 'type';
const VALUE = 'value';
const PRIMARY = 'primary';
public $type;
public $value;
public $primary;
function __construct($type, $value, $primary = false)
{
$this->type = $type;
$this->value = $value;
$this->primary = $primary;
}
function asString()
{
$xs = new XMLStringer(true);
$xs->elementStart('poco:urls');
$xs->element('poco:type', null, $this->type);
$xs->element('poco:value', null, $this->value);
if ($this->primary) {
$xs->element('poco:primary', null, 'true');
}
$xs->elementEnd('poco:urls');
return $xs->getString();
}
}
class PoCoAddress
{
const ADDRESS = 'address';
const FORMATTED = 'formatted';
public $formatted;
function __construct($formatted)
{
if (empty($formatted)) {
return null;
}
$this->formatted = $formatted;
}
function asString()
{
$xs = new XMLStringer(true);
$xs->elementStart('poco:address');
$xs->element('poco:formatted', null, $this->formatted);
$xs->elementEnd('poco:address');
return $xs->getString();
}
}
class PoCo class PoCo
{ {
const NS = 'http://portablecontacts.net/spec/1.0'; const NS = 'http://portablecontacts.net/spec/1.0';
const USERNAME = 'preferredUsername'; const USERNAME = 'preferredUsername';
const NOTE = 'note';
const URLS = 'urls';
public $preferredUsername;
public $note;
public $address;
public $urls = array();
function __construct($profile)
{
$this->preferredUsername = $profile->nickname;
$this->note = $profile->bio;
$this->address = new PoCoAddress($profile->location);
if (!empty($profile->homepage)) {
array_push(
$this->urls,
new PoCoURL(
'homepage',
$profile->homepage,
true
)
);
}
}
function asString()
{
$xs = new XMLStringer(true);
$xs->element(
'poco:preferredUsername',
null,
$this->preferredUsername
);
if (!empty($this->note)) {
$xs->element('poco:note', null, $this->note);
}
if (!empty($this->address)) {
$xs->raw($this->address->asString());
}
foreach ($this->urls as $url) {
$xs->raw($url->asString());
}
return $xs->getString();
}
} }
/** /**
@ -265,6 +373,7 @@ class ActivityObject
public $link; public $link;
public $source; public $source;
public $avatar; public $avatar;
public $geopoint;
/** /**
* Constructor * Constructor
@ -378,6 +487,13 @@ class ActivityObject
$object->id = $profile->getUri(); $object->id = $profile->getUri();
$object->title = $profile->getBestName(); $object->title = $profile->getBestName();
$object->link = $profile->profileurl; $object->link = $profile->profileurl;
$object->avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
if (isset($profile->lat) && isset($profile->lon)) {
$object->geopoint = (float)$profile->lat . ' ' . (float)$profile->lon;
}
$object->poco = new PoCo($profile);
return $object; return $object;
} }
@ -410,7 +526,32 @@ class ActivityObject
if (!empty($this->link)) { if (!empty($this->link)) {
$xs->element('link', array('rel' => 'alternate', 'type' => 'text/html'), $xs->element('link', array('rel' => 'alternate', 'type' => 'text/html'),
$this->content); $this->link);
}
if ($this->type == ActivityObject::PERSON) {
$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()
),
''
);
}
if (!empty($this->geopoint)) {
$xs->element(
'georss:point',
null,
$this->geopoint
);
}
if (!empty($this->poco)) {
$xs->raw($this->poco->asString());
} }
$xs->elementEnd($tag); $xs->elementEnd($tag);