[XML/HTML Outputter] General improvements and refactoring as well as some bug fixes
This commit is contained in:
parent
c03ed457a6
commit
1536d3ef29
|
@ -31,7 +31,9 @@
|
|||
* @link http://status.net/
|
||||
*/
|
||||
|
||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||
if (!defined('GNUSOCIAL')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* We don't have a rate limit, but some clients check this method.
|
||||
|
@ -47,62 +49,6 @@ if (!defined('GNUSOCIAL')) { exit(1); }
|
|||
*/
|
||||
class ApiAccountRateLimitStatusAction extends ApiBareAuthAction
|
||||
{
|
||||
/**
|
||||
* Handle the request
|
||||
*
|
||||
* Return some Twitter-ish data about API limits
|
||||
*
|
||||
* @param array $args $_REQUEST data (unused)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function handle()
|
||||
{
|
||||
parent::handle();
|
||||
|
||||
if (!in_array($this->format, array('xml', 'json'))) {
|
||||
$this->clientError(
|
||||
// TRANS: Client error displayed when coming across a non-supported API method.
|
||||
_('API method not found.'),
|
||||
404,
|
||||
$this->format
|
||||
);
|
||||
}
|
||||
|
||||
$reset = new DateTime();
|
||||
$reset->modify('+1 hour');
|
||||
|
||||
$this->initDocument($this->format);
|
||||
|
||||
if ($this->format == 'xml') {
|
||||
$this->elementStart('hash');
|
||||
$this->element('remaining-hits', array('type' => 'integer'), 150);
|
||||
$this->element('hourly-limit', array('type' => 'integer'), 150);
|
||||
$this->element(
|
||||
'reset-time', array('type' => 'datetime'),
|
||||
common_date_iso8601($reset->format('r'))
|
||||
);
|
||||
$this->element(
|
||||
'reset_time_in_seconds',
|
||||
array('type' => 'integer'),
|
||||
strtotime('+1 hour')
|
||||
);
|
||||
$this->elementEnd('hash');
|
||||
} elseif ($this->format == 'json') {
|
||||
$out = array(
|
||||
'reset_time_in_seconds' => strtotime('+1 hour'),
|
||||
'remaining_hits' => 150,
|
||||
'hourly_limit' => 150,
|
||||
'reset_time' => common_date_rfc2822(
|
||||
$reset->format('r')
|
||||
)
|
||||
);
|
||||
print json_encode($out);
|
||||
}
|
||||
|
||||
$this->endDocument($this->format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if read only.
|
||||
*
|
||||
|
@ -112,8 +58,64 @@ class ApiAccountRateLimitStatusAction extends ApiBareAuthAction
|
|||
*
|
||||
* @return boolean is read only action?
|
||||
*/
|
||||
function isReadOnly($args)
|
||||
public function isReadOnly($args)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the request
|
||||
*
|
||||
* Return some Twitter-ish data about API limits
|
||||
*
|
||||
* @return void
|
||||
* @throws ClientException
|
||||
*/
|
||||
protected function handle()
|
||||
{
|
||||
parent::handle();
|
||||
|
||||
if (!in_array($this->format, ['xml', 'json'])) {
|
||||
$this->clientError(
|
||||
// TRANS: Client error displayed when coming across a non-supported API method.
|
||||
_('API method not found.'),
|
||||
404,
|
||||
$this->format
|
||||
);
|
||||
}
|
||||
|
||||
$reset = new DateTime();
|
||||
$reset->modify('+1 hour');
|
||||
|
||||
$this->initDocument($this->format);
|
||||
|
||||
if ($this->format == 'xml') {
|
||||
$this->elementStart('hash');
|
||||
$this->element('remaining-hits', ['type' => 'integer'], "150");
|
||||
$this->element('hourly-limit', ['type' => 'integer'], "150");
|
||||
$this->element(
|
||||
'reset-time',
|
||||
['type' => 'datetime'],
|
||||
common_date_iso8601($reset->format('r'))
|
||||
);
|
||||
$this->element(
|
||||
'reset_time_in_seconds',
|
||||
['type' => 'integer'],
|
||||
strtotime('+1 hour')
|
||||
);
|
||||
$this->elementEnd('hash');
|
||||
} elseif ($this->format == 'json') {
|
||||
$out = [
|
||||
'reset_time_in_seconds' => strtotime('+1 hour'),
|
||||
'remaining_hits' => 150,
|
||||
'hourly_limit' => 150,
|
||||
'reset_time' => common_date_rfc2822(
|
||||
$reset->format('r')
|
||||
)
|
||||
];
|
||||
print json_encode($out);
|
||||
}
|
||||
|
||||
$this->endDocument($this->format);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,25 +49,36 @@ class NetworkpublicAction extends SitestreamAction
|
|||
// Network public tag cloud?
|
||||
}
|
||||
|
||||
/**
|
||||
* Output <head> elements for RSS and Atom feeds
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function getFeeds()
|
||||
{
|
||||
return array(new Feed(Feed::JSON,
|
||||
common_local_url('ApiTimelineNetworkPublic',
|
||||
array('format' => 'as')),
|
||||
// TRANS: Link description for the _global_ network public timeline feed.
|
||||
_('Network Public Timeline Feed (Activity Streams JSON)')),
|
||||
new Feed(Feed::RSS1, common_local_url('publicrss'),
|
||||
// TRANS: Link description for the _global_ network public timeline feed.
|
||||
_('Network Public Timeline Feed (RSS 1.0)')),
|
||||
new Feed(Feed::RSS2,
|
||||
common_local_url('ApiTimelineNetworkPublic',
|
||||
array('format' => 'rss')),
|
||||
// TRANS: Link description for the _global_ network public timeline feed.
|
||||
_('Network Public Timeline Feed (RSS 2.0)')),
|
||||
new Feed(Feed::ATOM,
|
||||
common_local_url('ApiTimelineNetworkPublic',
|
||||
array('format' => 'atom')),
|
||||
// TRANS: Link description for the _global_ network public timeline feed.
|
||||
_('Network Public Timeline Feed (Atom)')));
|
||||
return [
|
||||
new Feed(Feed::ATOM,
|
||||
common_local_url('ApiTimelinePublic',
|
||||
array('format' => 'atom')),
|
||||
// TRANS: Link description for public timeline feed.
|
||||
_('Public Timeline Feed (Atom)')
|
||||
),
|
||||
new Feed(Feed::JSON,
|
||||
common_local_url('ApiTimelinePublic',
|
||||
array('format' => 'as')),
|
||||
// TRANS: Link description for public timeline feed.
|
||||
_('Public Timeline Feed (Activity Streams JSON)')
|
||||
),
|
||||
new Feed(Feed::RSS1, common_local_url('publicrss'),
|
||||
// TRANS: Link description for public timeline feed.
|
||||
_('Public Timeline Feed (RSS 1.0)')
|
||||
),
|
||||
new Feed(Feed::RSS2,
|
||||
common_local_url('ApiTimelinePublic',
|
||||
array('format' => 'rss')),
|
||||
// TRANS: Link description for public timeline feed.
|
||||
_('Public Timeline Feed (RSS 2.0)')
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ class PublicAction extends SitestreamAction
|
|||
/**
|
||||
* Output <head> elements for RSS and Atom feeds
|
||||
*
|
||||
* @return void
|
||||
* @return array
|
||||
*/
|
||||
function getFeeds()
|
||||
{
|
||||
|
|
1652
lib/action.php
1652
lib/action.php
File diff suppressed because it is too large
Load Diff
|
@ -28,9 +28,11 @@
|
|||
* @link http://status.net/
|
||||
*/
|
||||
|
||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||
if (!defined('GNUSOCIAL')) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
require_once(INSTALLDIR.'/lib/activitystreamjsondocument.php');
|
||||
require_once(INSTALLDIR . '/lib/activitystreamjsondocument.php');
|
||||
|
||||
/**
|
||||
* A noun-ish thing in the activity universe
|
||||
|
@ -51,47 +53,47 @@ require_once(INSTALLDIR.'/lib/activitystreamjsondocument.php');
|
|||
*/
|
||||
class ActivityObject
|
||||
{
|
||||
const ARTICLE = 'http://activitystrea.ms/schema/1.0/article';
|
||||
const BLOGENTRY = 'http://activitystrea.ms/schema/1.0/blog-entry';
|
||||
const NOTE = 'http://activitystrea.ms/schema/1.0/note';
|
||||
const STATUS = 'http://activitystrea.ms/schema/1.0/status';
|
||||
const FILE = 'http://activitystrea.ms/schema/1.0/file';
|
||||
const PHOTO = 'http://activitystrea.ms/schema/1.0/photo';
|
||||
const ALBUM = 'http://activitystrea.ms/schema/1.0/photo-album';
|
||||
const PLAYLIST = 'http://activitystrea.ms/schema/1.0/playlist';
|
||||
const VIDEO = 'http://activitystrea.ms/schema/1.0/video';
|
||||
const AUDIO = 'http://activitystrea.ms/schema/1.0/audio';
|
||||
const BOOKMARK = 'http://activitystrea.ms/schema/1.0/bookmark';
|
||||
const PERSON = 'http://activitystrea.ms/schema/1.0/person';
|
||||
const GROUP = 'http://activitystrea.ms/schema/1.0/group';
|
||||
const _LIST = 'http://activitystrea.ms/schema/1.0/list'; // LIST is reserved
|
||||
const PLACE = 'http://activitystrea.ms/schema/1.0/place';
|
||||
const COMMENT = 'http://activitystrea.ms/schema/1.0/comment';
|
||||
const ARTICLE = 'http://activitystrea.ms/schema/1.0/article';
|
||||
const BLOGENTRY = 'http://activitystrea.ms/schema/1.0/blog-entry';
|
||||
const NOTE = 'http://activitystrea.ms/schema/1.0/note';
|
||||
const STATUS = 'http://activitystrea.ms/schema/1.0/status';
|
||||
const FILE = 'http://activitystrea.ms/schema/1.0/file';
|
||||
const PHOTO = 'http://activitystrea.ms/schema/1.0/photo';
|
||||
const ALBUM = 'http://activitystrea.ms/schema/1.0/photo-album';
|
||||
const PLAYLIST = 'http://activitystrea.ms/schema/1.0/playlist';
|
||||
const VIDEO = 'http://activitystrea.ms/schema/1.0/video';
|
||||
const AUDIO = 'http://activitystrea.ms/schema/1.0/audio';
|
||||
const BOOKMARK = 'http://activitystrea.ms/schema/1.0/bookmark';
|
||||
const PERSON = 'http://activitystrea.ms/schema/1.0/person';
|
||||
const GROUP = 'http://activitystrea.ms/schema/1.0/group';
|
||||
const _LIST = 'http://activitystrea.ms/schema/1.0/list'; // LIST is reserved
|
||||
const PLACE = 'http://activitystrea.ms/schema/1.0/place';
|
||||
const COMMENT = 'http://activitystrea.ms/schema/1.0/comment';
|
||||
// ^^^^^^^^^^ tea!
|
||||
const ACTIVITY = 'http://activitystrea.ms/schema/1.0/activity';
|
||||
const SERVICE = 'http://activitystrea.ms/schema/1.0/service';
|
||||
const IMAGE = 'http://activitystrea.ms/schema/1.0/image';
|
||||
const COLLECTION = 'http://activitystrea.ms/schema/1.0/collection';
|
||||
const ACTIVITY = 'http://activitystrea.ms/schema/1.0/activity';
|
||||
const SERVICE = 'http://activitystrea.ms/schema/1.0/service';
|
||||
const IMAGE = 'http://activitystrea.ms/schema/1.0/image';
|
||||
const COLLECTION = 'http://activitystrea.ms/schema/1.0/collection';
|
||||
const APPLICATION = 'http://activitystrea.ms/schema/1.0/application';
|
||||
|
||||
// Atom elements we snarf
|
||||
|
||||
const TITLE = 'title';
|
||||
const TITLE = 'title';
|
||||
const SUMMARY = 'summary';
|
||||
const ID = 'id';
|
||||
const SOURCE = 'source';
|
||||
const ID = 'id';
|
||||
const SOURCE = 'source';
|
||||
|
||||
const NAME = 'name';
|
||||
const URI = 'uri';
|
||||
const NAME = 'name';
|
||||
const URI = 'uri';
|
||||
const EMAIL = 'email';
|
||||
|
||||
const POSTEROUS = 'http://posterous.com/help/rss/1.0';
|
||||
const AUTHOR = 'author';
|
||||
const USERIMAGE = 'userImage';
|
||||
const PROFILEURL = 'profileUrl';
|
||||
const NICKNAME = 'nickName';
|
||||
const POSTEROUS = 'http://posterous.com/help/rss/1.0';
|
||||
const AUTHOR = 'author';
|
||||
const USERIMAGE = 'userImage';
|
||||
const PROFILEURL = 'profileUrl';
|
||||
const NICKNAME = 'nickName';
|
||||
const DISPLAYNAME = 'displayName';
|
||||
|
||||
const MEDIA_DESCRIPTION = 'description';
|
||||
public $element;
|
||||
public $type;
|
||||
public $id;
|
||||
|
@ -99,21 +101,19 @@ class ActivityObject
|
|||
public $summary;
|
||||
public $content;
|
||||
public $owner;
|
||||
public $link;
|
||||
public $selfLink; // think APP (Atom Publishing Protocol)
|
||||
public $link; // think APP (Atom Publishing Protocol)
|
||||
public $selfLink;
|
||||
public $source;
|
||||
public $avatarLinks = array();
|
||||
public $avatarLinks = [];
|
||||
public $geopoint;
|
||||
public $poco;
|
||||
public $displayName;
|
||||
|
||||
// @todo move this stuff to it's own PHOTO activity object
|
||||
const MEDIA_DESCRIPTION = 'description';
|
||||
|
||||
public $displayName;
|
||||
public $thumbnail;
|
||||
public $largerImage;
|
||||
public $description;
|
||||
public $extra = array();
|
||||
public $extra = [];
|
||||
|
||||
public $stream;
|
||||
|
||||
|
@ -126,7 +126,7 @@ class ActivityObject
|
|||
*
|
||||
* @param DOMElement $element DOM thing to turn into an Activity thing
|
||||
*/
|
||||
function __construct($element = null)
|
||||
public function __construct($element = null)
|
||||
{
|
||||
if (empty($element)) {
|
||||
return;
|
||||
|
@ -142,7 +142,7 @@ class ActivityObject
|
|||
|
||||
if ($element->tagName == 'author') {
|
||||
$this->_fromAuthor($element);
|
||||
} else if ($element->tagName == 'item') {
|
||||
} elseif ($element->tagName == 'item') {
|
||||
$this->_fromRssItem($element);
|
||||
} else {
|
||||
$this->_fromAtomEntry($element);
|
||||
|
@ -168,8 +168,7 @@ class ActivityObject
|
|||
}
|
||||
|
||||
if ($this->type == self::PHOTO) {
|
||||
|
||||
$this->thumbnail = ActivityUtils::getLink($element, 'preview');
|
||||
$this->thumbnail = ActivityUtils::getLink($element, 'preview');
|
||||
$this->largerImage = ActivityUtils::getLink($element, 'enclosure');
|
||||
|
||||
$this->description = ActivityUtils::childContent(
|
||||
|
@ -184,11 +183,18 @@ class ActivityObject
|
|||
}
|
||||
}
|
||||
|
||||
private function _childContent($element, $tag, $namespace = ActivityUtils::ATOM)
|
||||
{
|
||||
return ActivityUtils::childContent($element, $tag, $namespace);
|
||||
}
|
||||
|
||||
private function _fromAuthor($element)
|
||||
{
|
||||
$this->type = $this->_childContent($element,
|
||||
Activity::OBJECTTYPE,
|
||||
Activity::SPEC);
|
||||
$this->type = $this->_childContent(
|
||||
$element,
|
||||
Activity::OBJECTTYPE,
|
||||
Activity::SPEC
|
||||
);
|
||||
|
||||
if (empty($this->type)) {
|
||||
$this->type = self::PERSON; // XXX: is this fair?
|
||||
|
@ -231,7 +237,7 @@ class ActivityObject
|
|||
$email = $this->_childContent($element, self::EMAIL);
|
||||
if (!empty($email)) {
|
||||
// XXX: acct: ?
|
||||
$this->id = 'mailto:'.$email;
|
||||
$this->id = 'mailto:' . $email;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -244,50 +250,8 @@ class ActivityObject
|
|||
}
|
||||
}
|
||||
|
||||
private function _fromAtomEntry($element)
|
||||
{
|
||||
$this->type = $this->_childContent($element, Activity::OBJECTTYPE,
|
||||
Activity::SPEC);
|
||||
|
||||
if (empty($this->type)) {
|
||||
$this->type = ActivityObject::NOTE;
|
||||
}
|
||||
|
||||
$this->summary = ActivityUtils::childHtmlContent($element, self::SUMMARY);
|
||||
$this->content = ActivityUtils::getContent($element);
|
||||
|
||||
// We don't like HTML in our titles, although it's technically allowed
|
||||
$this->title = common_strip_html(ActivityUtils::childHtmlContent($element, self::TITLE));
|
||||
|
||||
$this->source = $this->_getSource($element);
|
||||
|
||||
$this->link = ActivityUtils::getPermalink($element);
|
||||
$this->selfLink = ActivityUtils::getSelfLink($element);
|
||||
|
||||
$this->id = $this->_childContent($element, self::ID);
|
||||
|
||||
if (empty($this->id) && !empty($this->link)) { // fallback if there's no ID
|
||||
$this->id = $this->link;
|
||||
}
|
||||
|
||||
$els = $element->childNodes;
|
||||
$out = array();
|
||||
|
||||
for ($i = 0; $i < $els->length; $i++) {
|
||||
$link = $els->item($i);
|
||||
if ($link->localName == ActivityUtils::LINK && $link->namespaceURI == ActivityUtils::ATOM) {
|
||||
$attrs = array();
|
||||
foreach ($link->attributes as $attrName=>$attrNode) {
|
||||
$attrs[$attrName] = $attrNode->nodeValue;
|
||||
}
|
||||
$this->extra[] = [$link->localName,
|
||||
$attrs,
|
||||
$link->nodeValue];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @todo FIXME: rationalize with Activity::_fromRssItem()
|
||||
|
||||
private function _fromRssItem($item)
|
||||
{
|
||||
if (empty($this->type)) {
|
||||
|
@ -321,6 +285,67 @@ class ActivityObject
|
|||
}
|
||||
}
|
||||
|
||||
private function _fromAtomEntry($element)
|
||||
{
|
||||
$this->type = $this->_childContent(
|
||||
$element,
|
||||
Activity::OBJECTTYPE,
|
||||
Activity::SPEC
|
||||
);
|
||||
|
||||
if (empty($this->type)) {
|
||||
$this->type = ActivityObject::NOTE;
|
||||
}
|
||||
|
||||
$this->summary = ActivityUtils::childHtmlContent($element, self::SUMMARY);
|
||||
$this->content = ActivityUtils::getContent($element);
|
||||
|
||||
// We don't like HTML in our titles, although it's technically allowed
|
||||
$this->title = common_strip_html(ActivityUtils::childHtmlContent($element, self::TITLE));
|
||||
|
||||
$this->source = $this->_getSource($element);
|
||||
|
||||
$this->link = ActivityUtils::getPermalink($element);
|
||||
$this->selfLink = ActivityUtils::getSelfLink($element);
|
||||
|
||||
$this->id = $this->_childContent($element, self::ID);
|
||||
|
||||
if (empty($this->id) && !empty($this->link)) { // fallback if there's no ID
|
||||
$this->id = $this->link;
|
||||
}
|
||||
|
||||
$els = $element->childNodes;
|
||||
|
||||
for ($i = 0; $i < $els->length; $i++) {
|
||||
$link = $els->item($i);
|
||||
if ($link->localName == ActivityUtils::LINK && $link->namespaceURI == ActivityUtils::ATOM) {
|
||||
$attrs = [];
|
||||
foreach ($link->attributes as $attrName => $attrNode) {
|
||||
$attrs[$attrName] = $attrNode->nodeValue;
|
||||
}
|
||||
$this->extra[] = [$link->localName,
|
||||
$attrs,
|
||||
$link->nodeValue];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function _getSource($element)
|
||||
{
|
||||
$sourceEl = ActivityUtils::child($element, 'source');
|
||||
|
||||
if (empty($sourceEl)) {
|
||||
return null;
|
||||
} else {
|
||||
$href = ActivityUtils::getLink($sourceEl, 'self');
|
||||
if (!empty($href)) {
|
||||
return $href;
|
||||
} else {
|
||||
return ActivityUtils::childContent($sourceEl, 'id');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function fromRssAuthor($el)
|
||||
{
|
||||
$text = $el->textContent;
|
||||
|
@ -328,10 +353,10 @@ class ActivityObject
|
|||
if (preg_match('/^(.*?) \((.*)\)$/', $text, $match)) {
|
||||
$email = $match[1];
|
||||
$name = $match[2];
|
||||
} else if (preg_match('/^(.*?) <(.*)>$/', $text, $match)) {
|
||||
} elseif (preg_match('/^(.*?) <(.*)>$/', $text, $match)) {
|
||||
$name = $match[1];
|
||||
$email = $match[2];
|
||||
} else if (preg_match('/.*@.*/', $text)) {
|
||||
} elseif (preg_match('/.*@.*/', $text)) {
|
||||
$email = $text;
|
||||
$name = null;
|
||||
} else {
|
||||
|
@ -345,11 +370,11 @@ class ActivityObject
|
|||
|
||||
$obj->element = $el;
|
||||
|
||||
$obj->type = ActivityObject::PERSON;
|
||||
$obj->type = ActivityObject::PERSON;
|
||||
$obj->title = $name;
|
||||
|
||||
if (!empty($email)) {
|
||||
$obj->id = 'mailto:'.$email;
|
||||
$obj->id = 'mailto:' . $email;
|
||||
}
|
||||
|
||||
return $obj;
|
||||
|
@ -366,7 +391,7 @@ class ActivityObject
|
|||
$obj->element = $el;
|
||||
|
||||
$obj->title = $text;
|
||||
$obj->type = ActivityObject::PERSON;
|
||||
$obj->type = ActivityObject::PERSON;
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
@ -380,8 +405,8 @@ class ActivityObject
|
|||
$obj->type = ActivityObject::PERSON; // @fixme guess better
|
||||
|
||||
$obj->title = ActivityUtils::childContent($el, ActivityObject::TITLE, Activity::RSS);
|
||||
$obj->link = ActivityUtils::childContent($el, ActivityUtils::LINK, Activity::RSS);
|
||||
$obj->id = ActivityUtils::getLink($el, Activity::SELF);
|
||||
$obj->link = ActivityUtils::childContent($el, ActivityUtils::LINK, Activity::RSS);
|
||||
$obj->id = ActivityUtils::getLink($el, Activity::SELF);
|
||||
|
||||
if (empty($obj->id)) {
|
||||
$obj->id = $obj->link;
|
||||
|
@ -405,6 +430,8 @@ class ActivityObject
|
|||
return $obj;
|
||||
}
|
||||
|
||||
// Try to get a unique id for the source feed
|
||||
|
||||
public static function fromPosterousAuthor($el)
|
||||
{
|
||||
$obj = new ActivityObject();
|
||||
|
@ -420,93 +447,74 @@ class ActivityObject
|
|||
}
|
||||
|
||||
$obj->link = ActivityUtils::childContent($el, self::PROFILEURL, self::POSTEROUS);
|
||||
$obj->id = $obj->link;
|
||||
$obj->id = $obj->link;
|
||||
|
||||
$obj->poco = new PoCo();
|
||||
|
||||
$obj->poco->preferredUsername = ActivityUtils::childContent($el, self::NICKNAME, self::POSTEROUS);
|
||||
$obj->poco->displayName = ActivityUtils::childContent($el, self::DISPLAYNAME, self::POSTEROUS);
|
||||
$obj->poco->displayName = ActivityUtils::childContent($el, self::DISPLAYNAME, self::POSTEROUS);
|
||||
|
||||
$obj->title = $obj->poco->displayName;
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
private function _childContent($element, $tag, $namespace=ActivityUtils::ATOM)
|
||||
{
|
||||
return ActivityUtils::childContent($element, $tag, $namespace);
|
||||
}
|
||||
|
||||
// Try to get a unique id for the source feed
|
||||
|
||||
private function _getSource($element)
|
||||
{
|
||||
$sourceEl = ActivityUtils::child($element, 'source');
|
||||
|
||||
if (empty($sourceEl)) {
|
||||
return null;
|
||||
} else {
|
||||
$href = ActivityUtils::getLink($sourceEl, 'self');
|
||||
if (!empty($href)) {
|
||||
return $href;
|
||||
} else {
|
||||
return ActivityUtils::childContent($sourceEl, 'id');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static function fromGroup(User_group $group)
|
||||
public static function fromGroup(User_group $group)
|
||||
{
|
||||
$object = new ActivityObject();
|
||||
|
||||
if (Event::handle('StartActivityObjectFromGroup', array($group, &$object))) {
|
||||
if (Event::handle('StartActivityObjectFromGroup', [$group, &$object])) {
|
||||
$object->type = ActivityObject::GROUP;
|
||||
$object->id = $group->getUri();
|
||||
$object->title = $group->getBestName();
|
||||
$object->link = $group->getUri();
|
||||
|
||||
$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->homepage_logo,
|
||||
AVATAR_PROFILE_SIZE);
|
||||
$object->avatarLinks[] = AvatarLink::fromFilename(
|
||||
$group->stream_logo,
|
||||
AVATAR_STREAM_SIZE
|
||||
);
|
||||
|
||||
$object->avatarLinks[] = AvatarLink::fromFilename($group->stream_logo,
|
||||
AVATAR_STREAM_SIZE);
|
||||
|
||||
$object->avatarLinks[] = AvatarLink::fromFilename($group->mini_logo,
|
||||
AVATAR_MINI_SIZE);
|
||||
$object->avatarLinks[] = AvatarLink::fromFilename(
|
||||
$group->mini_logo,
|
||||
AVATAR_MINI_SIZE
|
||||
);
|
||||
|
||||
$object->poco = PoCo::fromGroup($group);
|
||||
Event::handle('EndActivityObjectFromGroup', array($group, &$object));
|
||||
Event::handle('EndActivityObjectFromGroup', [$group, &$object]);
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
static function fromPeopletag($ptag)
|
||||
public static function fromPeopletag($ptag)
|
||||
{
|
||||
$object = new ActivityObject();
|
||||
if (Event::handle('StartActivityObjectFromPeopletag', array($ptag, &$object))) {
|
||||
$object->type = ActivityObject::_LIST;
|
||||
if (Event::handle('StartActivityObjectFromPeopletag', [$ptag, &$object])) {
|
||||
$object->type = ActivityObject::_LIST;
|
||||
|
||||
$object->id = $ptag->getUri();
|
||||
$object->title = $ptag->tag;
|
||||
$object->id = $ptag->getUri();
|
||||
$object->title = $ptag->tag;
|
||||
$object->summary = $ptag->description;
|
||||
$object->link = $ptag->homeUrl();
|
||||
$object->owner = Profile::getKV('id', $ptag->tagger);
|
||||
$object->poco = PoCo::fromProfile($object->owner);
|
||||
Event::handle('EndActivityObjectFromPeopletag', array($ptag, &$object));
|
||||
$object->link = $ptag->homeUrl();
|
||||
$object->owner = Profile::getKV('id', $ptag->tagger);
|
||||
$object->poco = PoCo::fromProfile($object->owner);
|
||||
Event::handle('EndActivityObjectFromPeopletag', [$ptag, &$object]);
|
||||
}
|
||||
return $object;
|
||||
}
|
||||
|
||||
static function fromFile(File $file)
|
||||
public static function fromFile(File $file)
|
||||
{
|
||||
$object = new ActivityObject();
|
||||
|
||||
if (Event::handle('StartActivityObjectFromFile', array($file, &$object))) {
|
||||
|
||||
if (Event::handle('StartActivityObjectFromFile', [$file, &$object])) {
|
||||
$object->type = self::mimeTypeToObjectType($file->mimetype);
|
||||
$object->id = TagURI::mint(sprintf("file:%d", $file->id));
|
||||
$object->id = TagURI::mint(sprintf("file:%d", $file->id));
|
||||
$object->link = $file->getAttachmentUrl();
|
||||
|
||||
if ($file->title) {
|
||||
|
@ -527,39 +535,73 @@ class ActivityObject
|
|||
}
|
||||
|
||||
switch (self::canonicalType($object->type)) {
|
||||
case 'image':
|
||||
$object->largerImage = $file->getUrl();
|
||||
break;
|
||||
case 'video':
|
||||
case 'audio':
|
||||
$object->stream = $file->getUrl();
|
||||
break;
|
||||
case 'image':
|
||||
$object->largerImage = $file->getUrl();
|
||||
break;
|
||||
case 'video':
|
||||
case 'audio':
|
||||
$object->stream = $file->getUrl();
|
||||
break;
|
||||
}
|
||||
|
||||
Event::handle('EndActivityObjectFromFile', array($file, &$object));
|
||||
Event::handle('EndActivityObjectFromFile', [$file, &$object]);
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
static function fromNoticeSource(Notice_source $source)
|
||||
public static function mimeTypeToObjectType($mimeType)
|
||||
{
|
||||
$ot = null;
|
||||
|
||||
// Default
|
||||
|
||||
if (empty($mimeType)) {
|
||||
return self::FILE;
|
||||
}
|
||||
|
||||
$parts = explode('/', $mimeType);
|
||||
|
||||
switch ($parts[0]) {
|
||||
case 'image':
|
||||
$ot = self::IMAGE;
|
||||
break;
|
||||
case 'audio':
|
||||
$ot = self::AUDIO;
|
||||
break;
|
||||
case 'video':
|
||||
$ot = self::VIDEO;
|
||||
break;
|
||||
default:
|
||||
$ot = self::FILE;
|
||||
}
|
||||
|
||||
return $ot;
|
||||
}
|
||||
|
||||
public static function canonicalType($type)
|
||||
{
|
||||
return ActivityUtils::resolveUri($type, true);
|
||||
}
|
||||
|
||||
public static function fromNoticeSource(Notice_source $source)
|
||||
{
|
||||
$object = new ActivityObject();
|
||||
$wellKnown = array('web', 'xmpp', 'mail', 'omb', 'system', 'api', 'ostatus',
|
||||
'activity', 'feed', 'mirror', 'twitter', 'facebook');
|
||||
$wellKnown = ['web', 'xmpp', 'mail', 'omb', 'system', 'api', 'ostatus',
|
||||
'activity', 'feed', 'mirror', 'twitter', 'facebook'];
|
||||
|
||||
if (Event::handle('StartActivityObjectFromNoticeSource', array($source, &$object))) {
|
||||
if (Event::handle('StartActivityObjectFromNoticeSource', [$source, &$object])) {
|
||||
$object->type = ActivityObject::APPLICATION;
|
||||
|
||||
if (in_array($source->code, $wellKnown)) {
|
||||
// We use one ID for all well-known StatusNet sources
|
||||
$object->id = "tag:status.net,2009:notice-source:".$source->code;
|
||||
} else if ($source->url) {
|
||||
$object->id = "tag:status.net,2009:notice-source:" . $source->code;
|
||||
} elseif ($source->url) {
|
||||
// They registered with an URL
|
||||
$object->id = $source->url;
|
||||
} else {
|
||||
// Locally-registered, no URL
|
||||
$object->id = TagURI::mint("notice-source:".$source->code);
|
||||
$object->id = TagURI::mint("notice-source:" . $source->code);
|
||||
}
|
||||
|
||||
if ($source->url) {
|
||||
|
@ -575,47 +617,62 @@ class ActivityObject
|
|||
if ($source->created) {
|
||||
$object->date = $source->created;
|
||||
}
|
||||
|
||||
$object->extra[] = array('status_net', array('source_code' => $source->code));
|
||||
|
||||
Event::handle('EndActivityObjectFromNoticeSource', array($source, &$object));
|
||||
$object->extra[] = ['status_net', ['source_code' => $source->code]];
|
||||
|
||||
Event::handle('EndActivityObjectFromNoticeSource', [$source, &$object]);
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
static function fromMessage(Message $message)
|
||||
public static function fromMessage(Message $message)
|
||||
{
|
||||
$object = new ActivityObject();
|
||||
|
||||
if (Event::handle('StartActivityObjectFromMessage', array($message, &$object))) {
|
||||
|
||||
$object->type = ActivityObject::NOTE;
|
||||
$object->id = ($message->uri) ? $message->uri : (($message->url) ? $message->url : TagURI::mint(sprintf("message:%d", $message->id)));
|
||||
if (Event::handle('StartActivityObjectFromMessage', [$message, &$object])) {
|
||||
$object->type = ActivityObject::NOTE;
|
||||
$object->id = ($message->uri) ? $message->uri : (($message->url) ? $message->url : TagURI::mint(sprintf("message:%d", $message->id)));
|
||||
$object->content = $message->rendered;
|
||||
$object->date = $message->created;
|
||||
$object->date = $message->created;
|
||||
|
||||
if ($message->url) {
|
||||
$object->link = $message->url;
|
||||
} else {
|
||||
$object->link = common_local_url('showmessage', array('message' => $message->id));
|
||||
$object->link = common_local_url('showmessage', ['message' => $message->id]);
|
||||
}
|
||||
|
||||
$object->extra[] = array('status_net', array('message_id' => $message->id));
|
||||
|
||||
Event::handle('EndActivityObjectFromMessage', array($message, &$object));
|
||||
$object->extra[] = ['status_net', ['message_id' => $message->id]];
|
||||
|
||||
Event::handle('EndActivityObjectFromMessage', [$message, &$object]);
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
function outputTo($xo, $tag='activity:object')
|
||||
/*
|
||||
* Returns an array based on this Activity Object suitable for
|
||||
* encoding as JSON.
|
||||
*
|
||||
* @return array $object the activity object array
|
||||
*/
|
||||
|
||||
public function asString($tag = 'activity:object')
|
||||
{
|
||||
$xs = new XMLStringer(true);
|
||||
|
||||
$this->outputTo($xs, $tag);
|
||||
|
||||
return $xs->getString();
|
||||
}
|
||||
|
||||
public function outputTo($xo, $tag = 'activity:object')
|
||||
{
|
||||
if (!empty($tag)) {
|
||||
$xo->elementStart($tag);
|
||||
}
|
||||
|
||||
if (Event::handle('StartActivityObjectOutputAtom', array($this, $xo))) {
|
||||
if (Event::handle('StartActivityObjectOutputAtom', [$this, $xo])) {
|
||||
$xo->element('activity:object-type', null, $this->type);
|
||||
|
||||
// <author> uses URI
|
||||
|
@ -650,7 +707,7 @@ class ActivityObject
|
|||
// XXX: assuming HTML content here
|
||||
$xo->element(
|
||||
ActivityUtils::CONTENT,
|
||||
array('type' => 'html'),
|
||||
['type' => 'html'],
|
||||
common_xml_safe_str($this->content)
|
||||
);
|
||||
}
|
||||
|
@ -658,45 +715,43 @@ class ActivityObject
|
|||
if (!empty($this->link)) {
|
||||
$xo->element(
|
||||
'link',
|
||||
array(
|
||||
[
|
||||
'rel' => 'alternate',
|
||||
'type' => 'text/html',
|
||||
'href' => $this->link
|
||||
),
|
||||
null
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($this->selfLink)) {
|
||||
$xo->element(
|
||||
'link',
|
||||
array(
|
||||
[
|
||||
'rel' => 'self',
|
||||
'type' => 'application/atom+xml',
|
||||
'href' => $this->selfLink
|
||||
),
|
||||
null
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if(!empty($this->owner)) {
|
||||
if (!empty($this->owner)) {
|
||||
$owner = $this->owner->asActivityNoun(self::AUTHOR);
|
||||
$xo->raw($owner);
|
||||
}
|
||||
|
||||
if ($this->type == ActivityObject::PERSON
|
||||
|| $this->type == ActivityObject::GROUP) {
|
||||
|
||||
foreach ($this->avatarLinks as $alink) {
|
||||
$xo->element('link',
|
||||
array(
|
||||
'rel' => 'avatar',
|
||||
'type' => $alink->type,
|
||||
'media:width' => $alink->width,
|
||||
'media:height' => $alink->height,
|
||||
'href' => $alink->url,
|
||||
),
|
||||
null);
|
||||
$xo->element(
|
||||
'link',
|
||||
[
|
||||
'rel' => 'avatar',
|
||||
'type' => $alink->type,
|
||||
'media:width' => $alink->width,
|
||||
'media:height' => $alink->height,
|
||||
'href' => $alink->url,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -719,7 +774,7 @@ class ActivityObject
|
|||
$xo->element($extraTag, $attrs, $content);
|
||||
}
|
||||
|
||||
Event::handle('EndActivityObjectOutputAtom', array($this, $xo));
|
||||
Event::handle('EndActivityObjectOutputAtom', [$this, $xo]);
|
||||
}
|
||||
|
||||
if (!empty($tag)) {
|
||||
|
@ -729,27 +784,11 @@ class ActivityObject
|
|||
return;
|
||||
}
|
||||
|
||||
function asString($tag='activity:object')
|
||||
public function asArray()
|
||||
{
|
||||
$xs = new XMLStringer(true);
|
||||
$object = [];
|
||||
|
||||
$this->outputTo($xs, $tag);
|
||||
|
||||
return $xs->getString();
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns an array based on this Activity Object suitable for
|
||||
* encoding as JSON.
|
||||
*
|
||||
* @return array $object the activity object array
|
||||
*/
|
||||
|
||||
function asArray()
|
||||
{
|
||||
$object = array();
|
||||
|
||||
if (Event::handle('StartActivityObjectOutputJson', array($this, &$object))) {
|
||||
if (Event::handle('StartActivityObjectOutputJson', [$this, &$object])) {
|
||||
// XXX: attachments are added by Activity
|
||||
|
||||
// author (Add object for author? Could be useful for repeats.)
|
||||
|
@ -762,7 +801,7 @@ class ActivityObject
|
|||
|
||||
if ($this->id) {
|
||||
$object['id'] = $this->id;
|
||||
} else if ($this->link) {
|
||||
} elseif ($this->link) {
|
||||
$object['id'] = $this->link;
|
||||
}
|
||||
|
||||
|
@ -775,8 +814,8 @@ class ActivityObject
|
|||
// XXX: Not sure what the best avatar is to use for the
|
||||
// author's "image". For now, I'm using the large size.
|
||||
|
||||
$imgLink = null;
|
||||
$avatarMediaLinks = array();
|
||||
$imgLink = null;
|
||||
$avatarMediaLinks = [];
|
||||
|
||||
foreach ($this->avatarLinks as $a) {
|
||||
|
||||
|
@ -798,14 +837,14 @@ class ActivityObject
|
|||
}
|
||||
|
||||
if (!array_key_exists('status_net', $object)) {
|
||||
$object['status_net'] = array();
|
||||
$object['status_net'] = [];
|
||||
}
|
||||
|
||||
$object['status_net']['avatarLinks'] = $avatarMediaLinks; // extension
|
||||
|
||||
// image
|
||||
if (!empty($imgLink)) {
|
||||
$object['image'] = $imgLink->asArray();
|
||||
$object['image'] = $imgLink->asArray();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -843,7 +882,7 @@ class ActivityObject
|
|||
$parts = explode(":", $objectName);
|
||||
if (count($parts) == 2 && $parts[0] == "statusnet") {
|
||||
if (!array_key_exists('status_net', $object)) {
|
||||
$object['status_net'] = array();
|
||||
$object['status_net'] = [];
|
||||
}
|
||||
$object['status_net'][$parts[1]] = $props;
|
||||
} else {
|
||||
|
@ -853,16 +892,15 @@ class ActivityObject
|
|||
}
|
||||
|
||||
if (!empty($this->geopoint)) {
|
||||
|
||||
list($lat, $lon) = explode(' ', $this->geopoint);
|
||||
|
||||
if (!empty($lat) && !empty($lon)) {
|
||||
$object['location'] = array(
|
||||
$object['location'] = [
|
||||
'objectType' => 'place',
|
||||
'position' => sprintf("%+02.5F%+03.5F/", $lat, $lon),
|
||||
'lat' => $lat,
|
||||
'lon' => $lon
|
||||
);
|
||||
];
|
||||
|
||||
$loc = Location::fromLatLon((float)$lat, (float)$lon);
|
||||
|
||||
|
@ -887,9 +925,9 @@ class ActivityObject
|
|||
|
||||
if (!empty($this->thumbnail)) {
|
||||
if (is_string($this->thumbnail)) {
|
||||
$object['image'] = array('url' => $this->thumbnail);
|
||||
$object['image'] = ['url' => $this->thumbnail];
|
||||
} else {
|
||||
$object['image'] = array('url' => $this->thumbnail->getUrl());
|
||||
$object['image'] = ['url' => $this->thumbnail->getUrl()];
|
||||
if ($this->thumbnail->width) {
|
||||
$object['image']['width'] = $this->thumbnail->width;
|
||||
}
|
||||
|
@ -900,63 +938,32 @@ class ActivityObject
|
|||
}
|
||||
|
||||
switch (self::canonicalType($this->type)) {
|
||||
case 'image':
|
||||
if (!empty($this->largerImage)) {
|
||||
$object['fullImage'] = array('url' => $this->largerImage);
|
||||
}
|
||||
break;
|
||||
case 'audio':
|
||||
case 'video':
|
||||
if (!empty($this->stream)) {
|
||||
$object['stream'] = array('url' => $this->stream);
|
||||
}
|
||||
break;
|
||||
case 'image':
|
||||
if (!empty($this->largerImage)) {
|
||||
$object['fullImage'] = ['url' => $this->largerImage];
|
||||
}
|
||||
break;
|
||||
case 'audio':
|
||||
case 'video':
|
||||
if (!empty($this->stream)) {
|
||||
$object['stream'] = ['url' => $this->stream];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Event::handle('EndActivityObjectOutputJson', array($this, &$object));
|
||||
Event::handle('EndActivityObjectOutputJson', [$this, &$object]);
|
||||
}
|
||||
return array_filter($object);
|
||||
}
|
||||
|
||||
public function getIdentifiers() {
|
||||
$ids = array();
|
||||
foreach(array('id', 'link', 'url') as $id) {
|
||||
public function getIdentifiers()
|
||||
{
|
||||
$ids = [];
|
||||
foreach (['id', 'link', 'url'] as $id) {
|
||||
if (isset($this->$id)) {
|
||||
$ids[] = $this->$id;
|
||||
}
|
||||
}
|
||||
return array_unique($ids);
|
||||
}
|
||||
|
||||
static function canonicalType($type) {
|
||||
return ActivityUtils::resolveUri($type, true);
|
||||
}
|
||||
|
||||
static function mimeTypeToObjectType($mimeType) {
|
||||
$ot = null;
|
||||
|
||||
// Default
|
||||
|
||||
if (empty($mimeType)) {
|
||||
return self::FILE;
|
||||
}
|
||||
|
||||
$parts = explode('/', $mimeType);
|
||||
|
||||
switch ($parts[0]) {
|
||||
case 'image':
|
||||
$ot = self::IMAGE;
|
||||
break;
|
||||
case 'audio':
|
||||
$ot = self::AUDIO;
|
||||
break;
|
||||
case 'video':
|
||||
$ot = self::VIDEO;
|
||||
break;
|
||||
default:
|
||||
$ot = self::FILE;
|
||||
}
|
||||
|
||||
return $ot;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ class ApiAction extends Action
|
|||
{
|
||||
const READ_ONLY = 1;
|
||||
const READ_WRITE = 2;
|
||||
public static $reserved_sources = array('web', 'omb', 'ostatus', 'mail', 'xmpp', 'api');
|
||||
public static $reserved_sources = ['web', 'omb', 'ostatus', 'mail', 'xmpp', 'api'];
|
||||
public $user = null;
|
||||
public $auth_user = null;
|
||||
public $page = null;
|
||||
|
@ -136,19 +136,19 @@ class ApiAction extends Action
|
|||
|
||||
public function twitterRelationshipArray($source, $target)
|
||||
{
|
||||
$relationship = array();
|
||||
$relationship = [];
|
||||
|
||||
$relationship['source'] =
|
||||
$this->relationshipDetailsArray($source->getProfile(), $target->getProfile());
|
||||
$relationship['target'] =
|
||||
$this->relationshipDetailsArray($target->getProfile(), $source->getProfile());
|
||||
|
||||
return array('relationship' => $relationship);
|
||||
return ['relationship' => $relationship];
|
||||
}
|
||||
|
||||
public function relationshipDetailsArray(Profile $source, Profile $target)
|
||||
{
|
||||
$details = array();
|
||||
$details = [];
|
||||
|
||||
$details['screen_name'] = $source->getNickname();
|
||||
$details['followed_by'] = $target->isSubscribed($source);
|
||||
|
@ -195,19 +195,18 @@ class ApiAction extends Action
|
|||
* See that method's documentation for more info.
|
||||
*
|
||||
* @param string $tag Element type or tagname
|
||||
* @param array $attrs Array of element attributes, as
|
||||
* key-value pairs
|
||||
* @param string $content string content of the element
|
||||
* @param array|string|null $attrs Array of element attributes, as key-value pairs
|
||||
* @param string|null $content string content of the element
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function element($tag, $attrs = [], $content = "")
|
||||
public function element(string $tag, $attrs = null, $content = null)
|
||||
{
|
||||
if (is_bool($content)) {
|
||||
$content = ($content ? 'true' : 'false');
|
||||
$content = ($content ? "true" : "false");
|
||||
}
|
||||
|
||||
return parent::element($tag, $attrs, $content);
|
||||
parent::element($tag, $attrs, $content);
|
||||
}
|
||||
|
||||
public function showSingleXmlStatus($notice)
|
||||
|
@ -254,23 +253,23 @@ class ApiAction extends Action
|
|||
$this->startXML();
|
||||
$this->elementStart(
|
||||
'rss',
|
||||
array(
|
||||
[
|
||||
'version' => '2.0',
|
||||
'xmlns:atom' => 'http://www.w3.org/2005/Atom',
|
||||
'xmlns:georss' => 'http://www.georss.org/georss'
|
||||
)
|
||||
]
|
||||
);
|
||||
$this->elementStart('channel');
|
||||
Event::handle('StartApiRss', array($this));
|
||||
Event::handle('StartApiRss', [$this]);
|
||||
}
|
||||
|
||||
public function initTwitterAtom()
|
||||
{
|
||||
$this->startXML();
|
||||
// FIXME: don't hardcode the language here!
|
||||
$this->elementStart('feed', array('xmlns' => 'http://www.w3.org/2005/Atom',
|
||||
$this->elementStart('feed', ['xmlns' => 'http://www.w3.org/2005/Atom',
|
||||
'xml:lang' => 'en-US',
|
||||
'xmlns:thr' => 'http://purl.org/syndication/thread/1.0'));
|
||||
'xmlns:thr' => 'http://purl.org/syndication/thread/1.0']);
|
||||
}
|
||||
|
||||
public function twitterStatusArray($notice, $include_user = true)
|
||||
|
@ -293,7 +292,7 @@ class ApiAction extends Action
|
|||
{
|
||||
$profile = $notice->getProfile();
|
||||
|
||||
$twitter_status = array();
|
||||
$twitter_status = [];
|
||||
$twitter_status['text'] = $notice->content;
|
||||
$twitter_status['truncated'] = false; # Not possible on StatusNet
|
||||
$twitter_status['created_at'] = self::dateTwitter($notice->created);
|
||||
|
@ -346,9 +345,9 @@ class ApiAction extends Action
|
|||
try {
|
||||
$notloc = Notice_location::locFromStored($notice);
|
||||
// This is the format that GeoJSON expects stuff to be in
|
||||
$twitter_status['geo'] = array('type' => 'Point',
|
||||
'coordinates' => array((float)$notloc->lat,
|
||||
(float)$notloc->lon));
|
||||
$twitter_status['geo'] = ['type' => 'Point',
|
||||
'coordinates' => [(float)$notloc->lat,
|
||||
(float)$notloc->lon]];
|
||||
} catch (ServerException $e) {
|
||||
$twitter_status['geo'] = null;
|
||||
}
|
||||
|
@ -357,12 +356,12 @@ class ApiAction extends Action
|
|||
$attachments = $notice->attachments();
|
||||
|
||||
if (!empty($attachments)) {
|
||||
$twitter_status['attachments'] = array();
|
||||
$twitter_status['attachments'] = [];
|
||||
|
||||
foreach ($attachments as $attachment) {
|
||||
try {
|
||||
$enclosure_o = $attachment->getEnclosure();
|
||||
$enclosure = array();
|
||||
$enclosure = [];
|
||||
$enclosure['url'] = $enclosure_o->url;
|
||||
$enclosure['mimetype'] = $enclosure_o->mimetype;
|
||||
$enclosure['size'] = $enclosure_o->size;
|
||||
|
@ -385,8 +384,8 @@ class ApiAction extends Action
|
|||
$twitter_status['statusnet_conversation_id'] = intval($notice->conversation);
|
||||
|
||||
// The event call to handle NoticeSimpleStatusArray lets plugins add data to the output array
|
||||
Event::handle('NoticeSimpleStatusArray', array($notice, &$twitter_status, $this->scoped,
|
||||
array('include_user' => $include_user)));
|
||||
Event::handle('NoticeSimpleStatusArray', [$notice, &$twitter_status, $this->scoped,
|
||||
['include_user' => $include_user]]);
|
||||
|
||||
return $twitter_status;
|
||||
}
|
||||
|
@ -401,7 +400,7 @@ class ApiAction extends Action
|
|||
|
||||
public function twitterUserArray($profile, $get_notice = false)
|
||||
{
|
||||
$twitter_user = array();
|
||||
$twitter_user = [];
|
||||
|
||||
try {
|
||||
$user = $profile->getUser();
|
||||
|
@ -430,7 +429,7 @@ class ApiAction extends Action
|
|||
$twitter_user['profile_image_url_original'] = $origurl;
|
||||
|
||||
$twitter_user['groups_count'] = $profile->getGroupCount();
|
||||
foreach (array('linkcolor', 'backgroundcolor') as $key) {
|
||||
foreach (['linkcolor', 'backgroundcolor'] as $key) {
|
||||
$twitter_user[$key] = Profile_prefs::getConfigData($profile, 'theme', $key);
|
||||
}
|
||||
// END introduced by qvitter API, not necessary for StatusNet API
|
||||
|
@ -489,14 +488,14 @@ class ApiAction extends Action
|
|||
$twitter_user['statusnet_profile_url'] = $profile->profileurl;
|
||||
|
||||
// The event call to handle NoticeSimpleStatusArray lets plugins add data to the output array
|
||||
Event::handle('TwitterUserArray', array($profile, &$twitter_user, $this->scoped, array()));
|
||||
Event::handle('TwitterUserArray', [$profile, &$twitter_user, $this->scoped, []]);
|
||||
|
||||
return $twitter_user;
|
||||
}
|
||||
|
||||
public function showTwitterXmlStatus($twitter_status, $tag = 'status', $namespaces = false)
|
||||
{
|
||||
$attrs = array();
|
||||
$attrs = [];
|
||||
if ($namespaces) {
|
||||
$attrs['xmlns:statusnet'] = 'http://status.net/schema/api/1/';
|
||||
}
|
||||
|
@ -537,7 +536,7 @@ class ApiAction extends Action
|
|||
|
||||
public function showTwitterXmlUser($twitter_user, $role = 'user', $namespaces = false)
|
||||
{
|
||||
$attrs = array();
|
||||
$attrs = [];
|
||||
if ($namespaces) {
|
||||
$attrs['xmlns:statusnet'] = 'http://status.net/schema/api/1/';
|
||||
}
|
||||
|
@ -557,9 +556,9 @@ class ApiAction extends Action
|
|||
public function showXmlAttachments($attachments)
|
||||
{
|
||||
if (!empty($attachments)) {
|
||||
$this->elementStart('attachments', array('type' => 'array'));
|
||||
$this->elementStart('attachments', ['type' => 'array']);
|
||||
foreach ($attachments as $attachment) {
|
||||
$attrs = array();
|
||||
$attrs = [];
|
||||
$attrs['url'] = $attachment['url'];
|
||||
$attrs['mimetype'] = $attachment['mimetype'];
|
||||
$attrs['size'] = $attachment['size'];
|
||||
|
@ -575,7 +574,7 @@ class ApiAction extends Action
|
|||
// empty geo element
|
||||
$this->element('geo');
|
||||
} else {
|
||||
$this->elementStart('geo', array('xmlns:georss' => 'http://www.georss.org/georss'));
|
||||
$this->elementStart('geo', ['xmlns:georss' => 'http://www.georss.org/georss']);
|
||||
$this->element('georss:point', null, $geo['coordinates'][0] . ' ' . $geo['coordinates'][1]);
|
||||
$this->elementEnd('geo');
|
||||
}
|
||||
|
@ -641,12 +640,12 @@ class ApiAction extends Action
|
|||
public function showXmlTimeline($notice)
|
||||
{
|
||||
$this->initDocument('xml');
|
||||
$this->elementStart('statuses', array('type' => 'array',
|
||||
'xmlns:statusnet' => 'http://status.net/schema/api/1/'));
|
||||
$this->elementStart('statuses', ['type' => 'array',
|
||||
'xmlns:statusnet' => 'http://status.net/schema/api/1/']);
|
||||
|
||||
if (is_array($notice)) {
|
||||
//FIXME: make everything calling showJsonTimeline use only Notice objects
|
||||
$ids = array();
|
||||
$ids = [];
|
||||
foreach ($notice as $n) {
|
||||
$ids[] = $n->getID();
|
||||
}
|
||||
|
@ -677,20 +676,20 @@ class ApiAction extends Action
|
|||
if (!is_null($self)) {
|
||||
$this->element(
|
||||
'atom:link',
|
||||
array(
|
||||
[
|
||||
'type' => 'application/rss+xml',
|
||||
'href' => $self,
|
||||
'rel' => 'self'
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if (!is_null($suplink)) {
|
||||
// For FriendFeed's SUP protocol
|
||||
$this->element('link', array('xmlns' => 'http://www.w3.org/2005/Atom',
|
||||
$this->element('link', ['xmlns' => 'http://www.w3.org/2005/Atom',
|
||||
'rel' => 'http://api.friendfeed.com/2008/03#sup',
|
||||
'href' => $suplink,
|
||||
'type' => 'application/json'));
|
||||
'type' => 'application/json']);
|
||||
}
|
||||
|
||||
if (!is_null($logo)) {
|
||||
|
@ -707,7 +706,7 @@ class ApiAction extends Action
|
|||
|
||||
if (is_array($notice)) {
|
||||
//FIXME: make everything calling showJsonTimeline use only Notice objects
|
||||
$ids = array();
|
||||
$ids = [];
|
||||