[FORMAT] Ran php-cs-fixer on the handlers of notice items and streams

This was to keep the following two commits readable
- actions/showstream.php
- actions/userbyid.php
- lib/modules/ActivityHandlerModule.php
- lib/modules/ActivityHandlerPlugin.php
- lib/notices/conversationnoticestream.php
- lib/notices/noticelistitem.php
- lib/notices/noticestream.php
- lib/notices/threadednoticelistitem.php
This commit is contained in:
Diogo Cordeiro 2020-01-09 21:41:34 +00:00 committed by Diogo Peralta Cordeiro
parent 3951ccbef7
commit 684a1a4143
8 changed files with 786 additions and 610 deletions

View File

@ -1,34 +1,31 @@
<?php <?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/** /**
* StatusNet, the distributed open-source microblogging tool
*
* User profile page * User profile page
* *
* PHP version 5
*
* LICENCE: 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*
* @category Personal * @category Personal
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @author Sarven Capadisli <csarven@status.net> * @author Sarven Capadisli <csarven@status.net>
* @copyright 2008-2009 StatusNet, Inc. * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
*/ */
if (!defined('GNUSOCIAL')) { exit(1); } defined('GNUSOCIAL') || die();
/** /**
* User profile page * User profile page
@ -58,7 +55,7 @@ class ShowstreamAction extends NoticestreamAction
return $stream; return $stream;
} }
function title() public function title()
{ {
$base = $this->target->getFancyName(); $base = $this->target->getFancyName();
if (!empty($this->tag)) { if (!empty($this->tag)) {
@ -77,9 +74,11 @@ class ShowstreamAction extends NoticestreamAction
} else { } else {
// TRANS: Extended page title showing tagged notices in one user's timeline. // TRANS: Extended page title showing tagged notices in one user's timeline.
// TRANS: %1$s is the username, %2$d is the page number. // TRANS: %1$s is the username, %2$d is the page number.
return sprintf(_('Notices by %1$s, page %2$d'), return sprintf(
_('Notices by %1$s, page %2$d'),
$base, $base,
$this->page); $this->page
);
} }
} }
} }
@ -89,79 +88,120 @@ class ShowstreamAction extends NoticestreamAction
$this->showNotices(); $this->showNotices();
} }
function showProfileBlock() public function showProfileBlock()
{ {
$block = new AccountProfileBlock($this, $this->target); $block = new AccountProfileBlock($this, $this->target);
$block->show(); $block->show();
} }
function showPageNoticeBlock() public function showPageNoticeBlock()
{ {
return; return;
} }
function getFeeds() public function getFeeds()
{ {
if (!empty($this->tag)) { if (!empty($this->tag)) {
return array(new Feed(Feed::RSS1, return [new Feed(
common_local_url('userrss', Feed::RSS1,
array('nickname' => $this->target->getNickname(), common_local_url(
'tag' => $this->tag)), 'userrss',
[
'nickname' => $this->target->getNickname(),
'tag' => $this->tag,
]
),
// TRANS: Title for link to notice feed. // TRANS: Title for link to notice feed.
// TRANS: %1$s is a user nickname, %2$s is a hashtag. // TRANS: %1$s is a user nickname, %2$s is a hashtag.
sprintf(_('Notice feed for %1$s tagged %2$s (RSS 1.0)'), sprintf(
$this->target->getNickname(), $this->tag))); _('Notice feed for %1$s tagged %2$s (RSS 1.0)'),
$this->target->getNickname(),
$this->tag
)
)];
} }
if (!$this->target->isLocal()) { if (!$this->target->isLocal()) {
// remote profiles at least have Atom, but we can't guarantee anything else // remote profiles at least have Atom, but we can't guarantee anything else
return array( return [new Feed(
new Feed(Feed::ATOM, Feed::ATOM,
$this->target->getAtomFeed(), $this->target->getAtomFeed(),
// TRANS: Title for link to notice feed. // TRANS: Title for link to notice feed.
// TRANS: %s is a user nickname. // TRANS: %s is a user nickname.
sprintf(_('Notice feed for %s (Atom)'), sprintf(
$this->target->getNickname())) _('Notice feed for %s (Atom)'),
); $this->target->getNickname()
)
)];
} }
return array(new Feed(Feed::JSON, return [
common_local_url('ApiTimelineUser', new Feed(
array( Feed::JSON,
common_local_url(
'ApiTimelineUser',
[
'id' => $this->target->getID(), 'id' => $this->target->getID(),
'format' => 'as')), 'format' => 'as',
]
),
// TRANS: Title for link to notice feed. // TRANS: Title for link to notice feed.
// TRANS: %s is a user nickname. // TRANS: %s is a user nickname.
sprintf(_('Notice feed for %s (Activity Streams JSON)'), sprintf(
$this->target->getNickname())), _('Notice feed for %s (Activity Streams JSON)'),
new Feed(Feed::RSS1, $this->target->getNickname()
common_local_url('userrss', )
array('nickname' => $this->target->getNickname())), ),
new Feed(
Feed::RSS1,
common_local_url(
'userrss',
['nickname' => $this->target->getNickname()]
),
// TRANS: Title for link to notice feed. // TRANS: Title for link to notice feed.
// TRANS: %s is a user nickname. // TRANS: %s is a user nickname.
sprintf(_('Notice feed for %s (RSS 1.0)'), sprintf(
$this->target->getNickname())), _('Notice feed for %s (RSS 1.0)'),
new Feed(Feed::RSS2, $this->target->getNickname()
common_local_url('ApiTimelineUser', )
array( ),
new Feed(
Feed::RSS2,
common_local_url(
'ApiTimelineUser',
[
'id' => $this->target->getID(), 'id' => $this->target->getID(),
'format' => 'rss')), 'format' => 'rss',
]
),
// TRANS: Title for link to notice feed. // TRANS: Title for link to notice feed.
// TRANS: %s is a user nickname. // TRANS: %s is a user nickname.
sprintf(_('Notice feed for %s (RSS 2.0)'), sprintf(
$this->target->getNickname())), _('Notice feed for %s (RSS 2.0)'),
new Feed(Feed::ATOM, $this->target->getNickname()
)
),
new Feed(
Feed::ATOM,
$this->target->getAtomFeed(), $this->target->getAtomFeed(),
// TRANS: Title for link to notice feed. // TRANS: Title for link to notice feed.
// TRANS: %s is a user nickname. // TRANS: %s is a user nickname.
sprintf(_('Notice feed for %s (Atom)'), sprintf(
$this->target->getNickname())), _('Notice feed for %s (Atom)'),
new Feed(Feed::FOAF, $this->target->getNickname()
common_local_url('foaf', array('nickname' => )
$this->target->getNickname())), ),
new Feed(
Feed::FOAF,
common_local_url(
'foaf',
['nickname' => $this->target->getNickname()]
),
// TRANS: Title for link to notice feed. FOAF stands for Friend of a Friend. // TRANS: Title for link to notice feed. FOAF stands for Friend of a Friend.
// TRANS: More information at http://www.foaf-project.org. %s is a user nickname. // TRANS: More information at http://www.foaf-project.org. %s is a user nickname.
sprintf(_('FOAF for %s'), $this->target->getNickname()))); sprintf(_('FOAF for %s'), $this->target->getNickname())
)
];
} }
public function extraHeaders() public function extraHeaders()
@ -170,33 +210,50 @@ class ShowstreamAction extends NoticestreamAction
// Publish all the rel="me" in the HTTP headers on our main profile page // Publish all the rel="me" in the HTTP headers on our main profile page
if (get_class($this) == 'ShowstreamAction') { if (get_class($this) == 'ShowstreamAction') {
foreach ($this->target->getRelMes() as $relMe) { foreach ($this->target->getRelMes() as $relMe) {
header('Link: <'.htmlspecialchars($relMe['href']).'>; rel="me"', false); header('Link: <' . htmlspecialchars($relMe['href']) . '>; rel="me"', false);
} }
} }
} }
function extraHead() public function extraHead()
{ {
if ($this->target->bio) { if ($this->target->bio) {
$this->element('meta', array('name' => 'description', $this->element(
'content' => $this->target->getDescription())); 'meta',
[
'name' => 'description',
'content' => $this->target->getDescription(),
]
);
} }
$rsd = common_local_url('rsd', $rsd = common_local_url(
array('nickname' => $this->target->getNickname())); 'rsd',
['nickname' => $this->target->getNickname()]
);
// RSD, http://tales.phrasewise.com/rfc/rsd // RSD, http://tales.phrasewise.com/rfc/rsd
$this->element('link', array('rel' => 'EditURI', $this->element(
'link',
[
'rel' => 'EditURI',
'type' => 'application/rsd+xml', 'type' => 'application/rsd+xml',
'href' => $rsd)); 'href' => $rsd,
]
);
if ($this->page != 1) { if ($this->page != 1) {
$this->element('link', array('rel' => 'canonical', $this->element(
'href' => $this->target->getUrl())); 'link',
[
'rel' => 'canonical',
'href' => $this->target->getUrl(),
]
);
} }
} }
function showEmptyListMessage() public function showEmptyListMessage()
{ {
// TRANS: First sentence of empty list message for a timeline. $1%s is a user nickname. // TRANS: First sentence of empty list message for a timeline. $1%s is a user nickname.
$message = sprintf(_('This is the timeline for %1$s, but %1$s hasn\'t posted anything yet.'), $this->target->getNickname()) . ' '; $message = sprintf(_('This is the timeline for %1$s, but %1$s hasn\'t posted anything yet.'), $this->target->getNickname()) . ' ';
@ -210,8 +267,7 @@ class ShowstreamAction extends NoticestreamAction
// TRANS: This message contains a Markdown link. Keep "](" together. // TRANS: This message contains a Markdown link. Keep "](" together.
$message .= sprintf(_('You can try to nudge %1$s or [post something to them](%%%%action.newnotice%%%%?status_textarea=%2$s).'), $this->target->getNickname(), '@' . $this->target->getNickname()); $message .= sprintf(_('You can try to nudge %1$s or [post something to them](%%%%action.newnotice%%%%?status_textarea=%2$s).'), $this->target->getNickname(), '@' . $this->target->getNickname());
} }
} } else {
else {
// TRANS: Second sentence of empty message for anonymous users. %s is a user nickname. // TRANS: Second sentence of empty message for anonymous users. %s is a user nickname.
// TRANS: This message contains a Markdown link. Keep "](" together. // TRANS: This message contains a Markdown link. Keep "](" together.
$message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->target->getNickname()); $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->target->getNickname());
@ -222,7 +278,7 @@ class ShowstreamAction extends NoticestreamAction
$this->elementEnd('div'); $this->elementEnd('div');
} }
function showNotices() public function showNotices()
{ {
$pnl = new PrimaryNoticeList($this->notice, $this); $pnl = new PrimaryNoticeList($this->notice, $this);
$cnt = $pnl->show(); $cnt = $pnl->show();
@ -232,36 +288,46 @@ class ShowstreamAction extends NoticestreamAction
// either nickname or id will be used, depending on which action (showstream, userbyid...) // either nickname or id will be used, depending on which action (showstream, userbyid...)
$args = array('nickname' => $this->target->getNickname(), 'id' => $this->target->getID()); $args = array('nickname' => $this->target->getNickname(), 'id' => $this->target->getID());
if (!empty($this->tag)) if (!empty($this->tag)) {
{
$args['tag'] = $this->tag; $args['tag'] = $this->tag;
} }
$this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page, $this->pagination(
$this->getActionName(), $args); $this->page > 1,
$cnt > NOTICES_PER_PAGE,
$this->page,
$this->getActionName(),
$args
);
} }
function showAnonymousMessage() public function showAnonymousMessage()
{ {
if (!(common_config('site','closed') || common_config('site','inviteonly'))) { if (!(common_config('site', 'closed') || common_config('site', 'inviteonly'))) {
// TRANS: Announcement for anonymous users showing a timeline if site registrations are open. // TRANS: Announcement for anonymous users showing a timeline if site registrations are open.
// TRANS: This message contains a Markdown link. Keep "](" together. // TRANS: This message contains a Markdown link. Keep "](" together.
$m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' . $m = sprintf(
_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
'based on the Free Software [StatusNet](http://status.net/) tool. ' . 'based on the Free Software [StatusNet](http://status.net/) tool. ' .
'[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'), '[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
$this->target->getNickname(), $this->target->getNickname()); $this->target->getNickname(),
$this->target->getNickname()
);
} else { } else {
// TRANS: Announcement for anonymous users showing a timeline if site registrations are closed or invite only. // TRANS: Announcement for anonymous users showing a timeline if site registrations are closed or invite only.
// TRANS: This message contains a Markdown link. Keep "](" together. // TRANS: This message contains a Markdown link. Keep "](" together.
$m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' . $m = sprintf(
_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
'based on the Free Software [StatusNet](http://status.net/) tool.'), 'based on the Free Software [StatusNet](http://status.net/) tool.'),
$this->target->getNickname(), $this->target->getNickname()); $this->target->getNickname(),
$this->target->getNickname()
);
} }
$this->elementStart('div', array('id' => 'anon_notice')); $this->elementStart('div', array('id' => 'anon_notice'));
$this->raw(common_markup_to_html($m)); $this->raw(common_markup_to_html($m));
$this->elementEnd('div'); $this->elementEnd('div');
} }
function noticeFormOptions() public function noticeFormOptions()
{ {
$options = parent::noticeFormOptions(); $options = parent::noticeFormOptions();

View File

@ -1,44 +1,40 @@
<?php <?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/** /**
* User by ID action class. * User by ID action class.
* *
* PHP version 5
*
* @category Action * @category Action
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @author Robin Millette <millette@status.net> * @author Robin Millette <millette@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
* @link http://status.net/ * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2008, 2009, StatusNet, 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*/ */
if (!defined('GNUSOCIAL')) { exit(1); } defined('GNUSOCIAL') || die();
/** /**
* User by ID action class. * User by ID action class.
* *
* @category Action * @category Action
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @author Robin Millette <millette@status.net> * @author Robin Millette <millette@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
*/ */
class UserbyidAction extends ShowstreamAction class UserbyidAction extends ShowstreamAction
{ {
@ -56,10 +52,12 @@ class UserbyidAction extends ShowstreamAction
// ensure that only user-agents who specifically ask for RDF get it. // ensure that only user-agents who specifically ask for RDF get it.
$page_prefs = 'text/html,application/xhtml+xml,application/rdf+xml,application/xml;q=0.3,text/xml;q=0.2'; $page_prefs = 'text/html,application/xhtml+xml,application/rdf+xml,application/xml;q=0.3,text/xml;q=0.2';
$httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null; $httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null;
$type = common_negotiate_type(common_accept_to_prefs($httpaccept), $type = common_negotiate_type(
common_accept_to_prefs($page_prefs)); common_accept_to_prefs($httpaccept),
$page = $type === 'application/rdf+xml' ? 'foaf' : 'showstream'; common_accept_to_prefs($page_prefs)
$url = common_local_url($page, array('nickname' => $this->target->getNickname())); );
$page = ($type === 'application/rdf+xml') ? 'foaf' : 'showstream';
$url = common_local_url($page, ['nickname' => $this->target->getNickname()]);
common_redirect($url, 303); common_redirect($url, 303);
} }
} }

View File

@ -1,23 +1,27 @@
<?php <?php
/* // This file is part of GNU social - https://www.gnu.org/software/social
* GNU Social - a federating social network //
* Copyright (C) 2014, Free Software Foundation, Inc. // GNU social is free software: you can redistribute it and/or modify
* // it under the terms of the GNU Affero General Public License as published by
* This program is free software: you can redistribute it and/or modify // the Free Software Foundation, either version 3 of the License, or
* it under the terms of the GNU Affero General Public License as published by // (at your option) any later version.
* the Free Software Foundation, either version 3 of the License, or //
* (at your option) any later version. // GNU social is distributed in the hope that it will be useful,
* // but WITHOUT ANY WARRANTY; without even the implied warranty of
* This program is distributed in the hope that it will be useful, // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* but WITHOUT ANY WARRANTY; without even the implied warranty of // GNU Affero General Public License for more details.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
* GNU Affero General Public License for more details. // You should have received a copy of the GNU Affero General Public License
* // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
* 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/>. /**
* @package GNUsocial
* @author Mikael Nordfeldth <mmn@hethane.se>
* @copyright 2014 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/ */
if (!defined('GNUSOCIAL')) { exit(1); } defined('GNUSOCIAL') || die();
/** /**
* Superclass for plugins which add Activity types and such * Superclass for plugins which add Activity types and such
@ -25,9 +29,8 @@ if (!defined('GNUSOCIAL')) { exit(1); }
* @category Activity * @category Activity
* @package GNUsocial * @package GNUsocial
* @author Mikael Nordfeldth <mmn@hethane.se> * @author Mikael Nordfeldth <mmn@hethane.se>
* @copyright 2014 Free Software Foundation, Inc. * @copyright 2014 Free Software Foundation, Inc http://www.fsf.org
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://gnu.io/social
*/ */
abstract class ActivityHandlerModule extends Module abstract class ActivityHandlerModule extends Module
{ {
@ -38,7 +41,7 @@ abstract class ActivityHandlerModule extends Module
* *
* @return string (compatible with HTML classes) * @return string (compatible with HTML classes)
*/ */
abstract function tag(); abstract public function tag();
/** /**
* Return a list of ActivityStreams object type IRIs * Return a list of ActivityStreams object type IRIs
@ -51,7 +54,7 @@ abstract class ActivityHandlerModule extends Module
* *
* @return array of strings * @return array of strings
*/ */
abstract function types(); abstract public function types();
/** /**
* Return a list of ActivityStreams verb IRIs which * Return a list of ActivityStreams verb IRIs which
@ -64,7 +67,8 @@ abstract class ActivityHandlerModule extends Module
* *
* @return array of strings * @return array of strings
*/ */
public function verbs() { public function verbs()
{
return array(ActivityVerb::POST); return array(ActivityVerb::POST);
} }
@ -80,7 +84,8 @@ abstract class ActivityHandlerModule extends Module
* @param Activity $activity * @param Activity $activity
* @return boolean * @return boolean
*/ */
function isMyActivity(Activity $act) { public function isMyActivity(Activity $act)
{
return (count($act->objects) == 1 return (count($act->objects) == 1
&& ($act->objects[0] instanceof ActivityObject) && ($act->objects[0] instanceof ActivityObject)
&& $this->isMyVerb($act->verb) && $this->isMyVerb($act->verb)
@ -98,18 +103,21 @@ abstract class ActivityHandlerModule extends Module
* @param Notice $notice * @param Notice $notice
* @return boolean * @return boolean
*/ */
function isMyNotice(Notice $notice) { public function isMyNotice(Notice $notice)
{
return $this->isMyVerb($notice->verb) && $this->isMyType($notice->object_type); return $this->isMyVerb($notice->verb) && $this->isMyType($notice->object_type);
} }
function isMyVerb($verb) { public function isMyVerb($verb)
{
$verb = $verb ?: ActivityVerb::POST; // post is the default verb $verb = $verb ?: ActivityVerb::POST; // post is the default verb
return ActivityUtils::compareVerbs($verb, $this->verbs()); return ActivityUtils::compareVerbs($verb, $this->verbs());
} }
function isMyType($type) { public function isMyType($type)
{
// Third argument to compareTypes is true, to allow for notices with empty object_type for example (verb-only) // Third argument to compareTypes is true, to allow for notices with empty object_type for example (verb-only)
return count($this->types())===0 || ActivityUtils::compareTypes($type, $this->types()); return count($this->types()) === 0 || ActivityUtils::compareTypes($type, $this->types());
} }
/** /**
@ -123,11 +131,11 @@ abstract class ActivityHandlerModule extends Module
* *
* @param Activity $activity * @param Activity $activity
* @param Profile $actor * @param Profile $actor
* @param array $options=array() * @param array $options = []
* *
* @return Notice the resulting notice * @return Notice the resulting notice
*/ */
public function saveNoticeFromActivity(Activity $activity, Profile $actor, array $options=array()) public function saveNoticeFromActivity(Activity $activity, Profile $actor, array $options = [])
{ {
// Any plugin which has not implemented saveObjectFromActivity _must_ // Any plugin which has not implemented saveObjectFromActivity _must_
// override this function until they are migrated (this function will // override this function until they are migrated (this function will
@ -162,12 +170,12 @@ abstract class ActivityHandlerModule extends Module
* *
* @param Activity $activity * @param Activity $activity
* @param Notice $stored The notice in our database for this certain object * @param Notice $stored The notice in our database for this certain object
* @param array $options=array() * @param array $options = []
* *
* @return object If the verb handling plugin creates an object, it can be returned here (otherwise true) * @return object If the verb handling plugin creates an object, it can be returned here (otherwise true)
* @throws exception On any error. * @throws exception On any error.
*/ */
protected function saveObjectFromActivity(Activity $activity, Notice $stored, array $options=array()) protected function saveObjectFromActivity(Activity $activity, Notice $stored, array $options = [])
{ {
throw new ServerException('This function should be abstract when all plugins have migrated to saveObjectFromActivity'); throw new ServerException('This function should be abstract when all plugins have migrated to saveObjectFromActivity');
} }
@ -176,7 +184,8 @@ abstract class ActivityHandlerModule extends Module
* This usually gets called from Notice::saveActivity after a Notice object has been created, * This usually gets called from Notice::saveActivity after a Notice object has been created,
* so it contains a proper id and a uri for the object to be saved. * so it contains a proper id and a uri for the object to be saved.
*/ */
public function onStoreActivityObject(Activity $act, Notice $stored, array $options, &$object) { public function onStoreActivityObject(Activity $act, Notice $stored, array $options, &$object)
{
// $this->oldSaveNew is there during a migration period of plugins, to start using // $this->oldSaveNew is there during a migration period of plugins, to start using
// Notice::saveActivity instead of Notice::saveNew // Notice::saveActivity instead of Notice::saveNew
if (!$this->isMyActivity($act) || isset($this->oldSaveNew)) { if (!$this->isMyActivity($act) || isset($this->oldSaveNew)) {
@ -208,7 +217,7 @@ abstract class ActivityHandlerModule extends Module
* *
* @return ActivityObject * @return ActivityObject
*/ */
abstract function activityObjectFromNotice(Notice $notice); abstract public function activityObjectFromNotice(Notice $notice);
/** /**
* When a notice is deleted, you'll be called here for a chance * When a notice is deleted, you'll be called here for a chance
@ -218,7 +227,7 @@ abstract class ActivityHandlerModule extends Module
* *
* @param Notice $notice * @param Notice $notice
*/ */
abstract function deleteRelated(Notice $notice); abstract public function deleteRelated(Notice $notice);
protected function notifyMentioned(Notice $stored, array &$mentioned_ids) protected function notifyMentioned(Notice $stored, array &$mentioned_ids)
{ {
@ -242,7 +251,7 @@ abstract class ActivityHandlerModule extends Module
* @param ActivityObject $obj * @param ActivityObject $obj
* @param XMLOutputter $out to add elements at end of object * @param XMLOutputter $out to add elements at end of object
*/ */
function activityObjectOutputAtom(ActivityObject $obj, XMLOutputter $out) public function activityObjectOutputAtom(ActivityObject $obj, XMLOutputter $out)
{ {
// default is a no-op // default is a no-op
} }
@ -313,7 +322,7 @@ abstract class ActivityHandlerModule extends Module
* *
* @return boolean hook value * @return boolean hook value
*/ */
function onStartActivityObjectFromNotice(Notice $notice, &$object) public function onStartActivityObjectFromNotice(Notice $notice, &$object)
{ {
if (!$this->isMyNotice($notice)) { if (!$this->isMyNotice($notice)) {
return true; return true;
@ -331,7 +340,7 @@ abstract class ActivityHandlerModule extends Module
* *
* @return boolean hook value * @return boolean hook value
*/ */
function onStartHandleFeedEntryWithProfile(Activity $activity, Profile $profile, &$notice) public function onStartHandleFeedEntryWithProfile(Activity $activity, Profile $profile, &$notice)
{ {
if (!$this->isMyActivity($activity)) { if (!$this->isMyActivity($activity)) {
return true; return true;
@ -342,11 +351,13 @@ abstract class ActivityHandlerModule extends Module
$object = $activity->objects[0]; $object = $activity->objects[0];
$options = array('uri' => $object->id, $options = [
'uri' => $object->id,
'url' => $object->link, 'url' => $object->link,
'self' => $object->selfLink, 'self' => $object->selfLink,
'is_local' => Notice::REMOTE, 'is_local' => Notice::REMOTE,
'source' => 'ostatus'); 'source' => 'ostatus',
];
if (!isset($this->oldSaveNew)) { if (!isset($this->oldSaveNew)) {
$notice = Notice::saveActivity($activity, $profile, $options); $notice = Notice::saveActivity($activity, $profile, $options);
@ -366,7 +377,7 @@ abstract class ActivityHandlerModule extends Module
* @return boolean hook value * @return boolean hook value
*/ */
function onStartHandleSalmonTarget(Activity $activity, $target) public function onStartHandleSalmonTarget(Activity $activity, $target)
{ {
if (!$this->isMyActivity($activity)) { if (!$this->isMyActivity($activity)) {
return true; return true;
@ -377,7 +388,7 @@ abstract class ActivityHandlerModule extends Module
return true; return true;
} }
$this->log(LOG_INFO, get_called_class()." checking {$activity->id} as a valid Salmon slap."); $this->log(LOG_INFO, get_called_class() . " checking {$activity->id} as a valid Salmon slap.");
if ($target instanceof User_group || $target->isGroup()) { if ($target instanceof User_group || $target->isGroup()) {
$uri = $target->getUri(); $uri = $target->getUri();
@ -419,11 +430,13 @@ abstract class ActivityHandlerModule extends Module
$object = $activity; $object = $activity;
} }
$options = array('uri' => $object->id, $options = [
'uri' => $object->id,
'url' => $object->link, 'url' => $object->link,
'self' => $object->selfLink, 'self' => $object->selfLink,
'is_local' => Notice::REMOTE, 'is_local' => Notice::REMOTE,
'source' => 'ostatus'); 'source' => 'ostatus',
];
$notice = $this->saveNoticeFromActivity($activity, $actor, $options); $notice = $this->saveNoticeFromActivity($activity, $actor, $options);
@ -439,7 +452,7 @@ abstract class ActivityHandlerModule extends Module
* *
* @return boolean hook value * @return boolean hook value
*/ */
public function onStartAtomPubNewActivity(Activity $activity, Profile $scoped, Notice &$notice=null) public function onStartAtomPubNewActivity(Activity $activity, Profile $scoped, Notice &$notice = null)
{ {
if (!$this->isMyActivity($activity)) { if (!$this->isMyActivity($activity)) {
return true; return true;
@ -463,7 +476,7 @@ abstract class ActivityHandlerModule extends Module
* *
* @return boolean hook value * @return boolean hook value
*/ */
function onStartImportActivity($user, $author, Activity $activity, $trusted, &$done) public function onStartImportActivity($user, $author, Activity $activity, $trusted, &$done)
{ {
if (!$this->isMyActivity($activity)) { if (!$this->isMyActivity($activity)) {
return true; return true;
@ -471,15 +484,19 @@ abstract class ActivityHandlerModule extends Module
$obj = $activity->objects[0]; $obj = $activity->objects[0];
$options = array('uri' => $object->id, $options = [
'uri' => $object->id,
'url' => $object->link, 'url' => $object->link,
'self' => $object->selfLink, 'self' => $object->selfLink,
'source' => 'restore'); 'source' => 'restore',
];
// $user->getProfile() is a Profile // $user->getProfile() is a Profile
$saved = $this->saveNoticeFromActivity($activity, $saved = $this->saveNoticeFromActivity(
$activity,
$user->getProfile(), $user->getProfile(),
$options); $options
);
if (!empty($saved)) { if (!empty($saved)) {
$done = true; $done = true;
@ -500,7 +517,7 @@ abstract class ActivityHandlerModule extends Module
* @param XMLOutputter $out to add elements at end of object * @param XMLOutputter $out to add elements at end of object
* @return boolean hook return value * @return boolean hook return value
*/ */
function onEndActivityObjectOutputAtom(ActivityObject $obj, XMLOutputter $out) public function onEndActivityObjectOutputAtom(ActivityObject $obj, XMLOutputter $out)
{ {
if (in_array($obj->type, $this->types())) { if (in_array($obj->type, $this->types())) {
$this->activityObjectOutputAtom($obj, $out); $this->activityObjectOutputAtom($obj, $out);
@ -520,7 +537,7 @@ abstract class ActivityHandlerModule extends Module
* @param array &$out JSON-targeted array which can be modified * @param array &$out JSON-targeted array which can be modified
* @return boolean hook return value * @return boolean hook return value
*/ */
function onEndActivityObjectOutputJson(ActivityObject $obj, array &$out) public function onEndActivityObjectOutputJson(ActivityObject $obj, array &$out)
{ {
if (in_array($obj->type, $this->types())) { if (in_array($obj->type, $this->types())) {
$this->activityObjectOutputJson($obj, $out); $this->activityObjectOutputJson($obj, $out);
@ -536,7 +553,7 @@ abstract class ActivityHandlerModule extends Module
$this->openNoticeListItemElement($nli); $this->openNoticeListItemElement($nli);
Event::handle('EndOpenNoticeListItemElement', array($nli)); Event::handle('EndOpenNoticeListItemElement', [$nli]);
return false; return false;
} }
@ -548,7 +565,7 @@ abstract class ActivityHandlerModule extends Module
$this->closeNoticeListItemElement($nli); $this->closeNoticeListItemElement($nli);
Event::handle('EndCloseNoticeListItemElement', array($nli)); Event::handle('EndCloseNoticeListItemElement', [$nli]);
return false; return false;
} }
@ -560,12 +577,14 @@ abstract class ActivityHandlerModule extends Module
$class .= ' limited-scope'; $class .= ' limited-scope';
} }
try { try {
$class .= ' notice-source-'.common_to_alphanumeric($nli->notice->source); $class .= ' notice-source-' . common_to_alphanumeric($nli->notice->source);
} catch (Exception $e) { } catch (Exception $e) {
// either source or what we filtered out was a zero-length string // either source or what we filtered out was a zero-length string
} }
$nli->out->elementStart('li', array('class' => $class, $nli->out->elementStart(
'id' => 'notice-' . $id)); 'li',
['class' => $class, 'id' => 'notice-' . $id]
);
} }
protected function closeNoticeListItemElement(NoticeListItem $nli) protected function closeNoticeListItemElement(NoticeListItem $nli)
@ -584,7 +603,7 @@ abstract class ActivityHandlerModule extends Module
try { try {
$this->showNoticeListItem($nli); $this->showNoticeListItem($nli);
} catch (Exception $e) { } catch (Exception $e) {
common_log(LOG_ERR, 'Error showing notice '.$nli->getNotice()->getID().': ' . $e->getMessage()); common_log(LOG_ERR, 'Error showing notice ' . $nli->getNotice()->getID() . ': ' . $e->getMessage());
$nli->out->element('p', 'error', sprintf(_('Error showing notice: %s'), $e->getMessage())); $nli->out->element('p', 'error', sprintf(_('Error showing notice: %s'), $e->getMessage()));
} }
@ -619,7 +638,7 @@ abstract class ActivityHandlerModule extends Module
$nli->showContent(); $nli->showContent();
} }
public function onStartShowNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped=null) public function onStartShowNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped = null)
{ {
if (!$this->isMyNotice($stored)) { if (!$this->isMyNotice($stored)) {
return true; return true;
@ -633,7 +652,7 @@ abstract class ActivityHandlerModule extends Module
return false; return false;
} }
protected function showNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped=null) protected function showNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped = null)
{ {
$out->text($stored->getContent()); $out->text($stored->getContent());
} }

View File

@ -1,23 +1,20 @@
<?php <?php
/* // This file is part of GNU social - https://www.gnu.org/software/social
* GNU Social - a federating social network //
* Copyright (C) 2014, Free Software Foundation, Inc. // GNU social is free software: you can redistribute it and/or modify
* // it under the terms of the GNU Affero General Public License as published by
* This program is free software: you can redistribute it and/or modify // the Free Software Foundation, either version 3 of the License, or
* it under the terms of the GNU Affero General Public License as published by // (at your option) any later version.
* the Free Software Foundation, either version 3 of the License, or //
* (at your option) any later version. // GNU social is distributed in the hope that it will be useful,
* // but WITHOUT ANY WARRANTY; without even the implied warranty of
* This program is distributed in the hope that it will be useful, // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* but WITHOUT ANY WARRANTY; without even the implied warranty of // GNU Affero General Public License for more details.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
* GNU Affero General Public License for more details. // You should have received a copy of the GNU Affero General Public License
* // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
* 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/>.
*/
if (!defined('GNUSOCIAL')) { exit(1); } defined('GNUSOCIAL') || die();
/** /**
* Superclass for plugins which add Activity types and such * Superclass for plugins which add Activity types and such
@ -25,9 +22,8 @@ if (!defined('GNUSOCIAL')) { exit(1); }
* @category Activity * @category Activity
* @package GNUsocial * @package GNUsocial
* @author Mikael Nordfeldth <mmn@hethane.se> * @author Mikael Nordfeldth <mmn@hethane.se>
* @copyright 2014 Free Software Foundation, Inc. * @copyright 2014 Free Software Foundation, Inc http://www.fsf.org
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://gnu.io/social
*/ */
abstract class ActivityHandlerPlugin extends Plugin abstract class ActivityHandlerPlugin extends Plugin
{ {
@ -38,7 +34,7 @@ abstract class ActivityHandlerPlugin extends Plugin
* *
* @return string (compatible with HTML classes) * @return string (compatible with HTML classes)
*/ */
abstract function tag(); abstract public function tag();
/** /**
* Return a list of ActivityStreams object type IRIs * Return a list of ActivityStreams object type IRIs
@ -51,7 +47,7 @@ abstract class ActivityHandlerPlugin extends Plugin
* *
* @return array of strings * @return array of strings
*/ */
abstract function types(); abstract public function types();
/** /**
* Return a list of ActivityStreams verb IRIs which * Return a list of ActivityStreams verb IRIs which
@ -64,7 +60,8 @@ abstract class ActivityHandlerPlugin extends Plugin
* *
* @return array of strings * @return array of strings
*/ */
public function verbs() { public function verbs()
{
return array(ActivityVerb::POST); return array(ActivityVerb::POST);
} }
@ -80,7 +77,8 @@ abstract class ActivityHandlerPlugin extends Plugin
* @param Activity $activity * @param Activity $activity
* @return boolean * @return boolean
*/ */
function isMyActivity(Activity $act) { public function isMyActivity(Activity $act)
{
return (count($act->objects) == 1 return (count($act->objects) == 1
&& ($act->objects[0] instanceof ActivityObject) && ($act->objects[0] instanceof ActivityObject)
&& $this->isMyVerb($act->verb) && $this->isMyVerb($act->verb)
@ -98,18 +96,21 @@ abstract class ActivityHandlerPlugin extends Plugin
* @param Notice $notice * @param Notice $notice
* @return boolean * @return boolean
*/ */
function isMyNotice(Notice $notice) { public function isMyNotice(Notice $notice)
{
return $this->isMyVerb($notice->verb) && $this->isMyType($notice->object_type); return $this->isMyVerb($notice->verb) && $this->isMyType($notice->object_type);
} }
function isMyVerb($verb) { public function isMyVerb($verb)
{
$verb = $verb ?: ActivityVerb::POST; // post is the default verb $verb = $verb ?: ActivityVerb::POST; // post is the default verb
return ActivityUtils::compareVerbs($verb, $this->verbs()); return ActivityUtils::compareVerbs($verb, $this->verbs());
} }
function isMyType($type) { public function isMyType($type)
{
// Third argument to compareTypes is true, to allow for notices with empty object_type for example (verb-only) // Third argument to compareTypes is true, to allow for notices with empty object_type for example (verb-only)
return count($this->types())===0 || ActivityUtils::compareTypes($type, $this->types()); return count($this->types()) === 0 || ActivityUtils::compareTypes($type, $this->types());
} }
/** /**
@ -123,11 +124,11 @@ abstract class ActivityHandlerPlugin extends Plugin
* *
* @param Activity $activity * @param Activity $activity
* @param Profile $actor * @param Profile $actor
* @param array $options=array() * @param array $options =array()
* *
* @return Notice the resulting notice * @return Notice the resulting notice
*/ */
public function saveNoticeFromActivity(Activity $activity, Profile $actor, array $options=array()) public function saveNoticeFromActivity(Activity $activity, Profile $actor, array $options = array())
{ {
// Any plugin which has not implemented saveObjectFromActivity _must_ // Any plugin which has not implemented saveObjectFromActivity _must_
// override this function until they are migrated (this function will // override this function until they are migrated (this function will
@ -162,12 +163,12 @@ abstract class ActivityHandlerPlugin extends Plugin
* *
* @param Activity $activity * @param Activity $activity
* @param Notice $stored The notice in our database for this certain object * @param Notice $stored The notice in our database for this certain object
* @param array $options=array() * @param array $options =array()
* *
* @return object If the verb handling plugin creates an object, it can be returned here (otherwise true) * @return object If the verb handling plugin creates an object, it can be returned here (otherwise true)
* @throws exception On any error. * @throws exception On any error.
*/ */
protected function saveObjectFromActivity(Activity $activity, Notice $stored, array $options=array()) protected function saveObjectFromActivity(Activity $activity, Notice $stored, array $options = array())
{ {
throw new ServerException('This function should be abstract when all plugins have migrated to saveObjectFromActivity'); throw new ServerException('This function should be abstract when all plugins have migrated to saveObjectFromActivity');
} }
@ -176,7 +177,8 @@ abstract class ActivityHandlerPlugin extends Plugin
* This usually gets called from Notice::saveActivity after a Notice object has been created, * This usually gets called from Notice::saveActivity after a Notice object has been created,
* so it contains a proper id and a uri for the object to be saved. * so it contains a proper id and a uri for the object to be saved.
*/ */
public function onStoreActivityObject(Activity $act, Notice $stored, array $options, &$object) { public function onStoreActivityObject(Activity $act, Notice $stored, array $options, &$object)
{
// $this->oldSaveNew is there during a migration period of plugins, to start using // $this->oldSaveNew is there during a migration period of plugins, to start using
// Notice::saveActivity instead of Notice::saveNew // Notice::saveActivity instead of Notice::saveNew
if (!$this->isMyActivity($act) || isset($this->oldSaveNew)) { if (!$this->isMyActivity($act) || isset($this->oldSaveNew)) {
@ -208,7 +210,7 @@ abstract class ActivityHandlerPlugin extends Plugin
* *
* @return ActivityObject * @return ActivityObject
*/ */
abstract function activityObjectFromNotice(Notice $notice); abstract public function activityObjectFromNotice(Notice $notice);
/** /**
* When a notice is deleted, you'll be called here for a chance * When a notice is deleted, you'll be called here for a chance
@ -218,7 +220,7 @@ abstract class ActivityHandlerPlugin extends Plugin
* *
* @param Notice $notice * @param Notice $notice
*/ */
abstract function deleteRelated(Notice $notice); abstract public function deleteRelated(Notice $notice);
protected function notifyMentioned(Notice $stored, array &$mentioned_ids) protected function notifyMentioned(Notice $stored, array &$mentioned_ids)
{ {
@ -242,7 +244,7 @@ abstract class ActivityHandlerPlugin extends Plugin
* @param ActivityObject $obj * @param ActivityObject $obj
* @param XMLOutputter $out to add elements at end of object * @param XMLOutputter $out to add elements at end of object
*/ */
function activityObjectOutputAtom(ActivityObject $obj, XMLOutputter $out) public function activityObjectOutputAtom(ActivityObject $obj, XMLOutputter $out)
{ {
// default is a no-op // default is a no-op
} }
@ -313,7 +315,7 @@ abstract class ActivityHandlerPlugin extends Plugin
* *
* @return boolean hook value * @return boolean hook value
*/ */
function onStartActivityObjectFromNotice(Notice $notice, &$object) public function onStartActivityObjectFromNotice(Notice $notice, &$object)
{ {
if (!$this->isMyNotice($notice)) { if (!$this->isMyNotice($notice)) {
return true; return true;
@ -331,7 +333,7 @@ abstract class ActivityHandlerPlugin extends Plugin
* *
* @return boolean hook value * @return boolean hook value
*/ */
function onStartHandleFeedEntryWithProfile(Activity $activity, Profile $profile, &$notice) public function onStartHandleFeedEntryWithProfile(Activity $activity, Profile $profile, &$notice)
{ {
if (!$this->isMyActivity($activity)) { if (!$this->isMyActivity($activity)) {
return true; return true;
@ -342,11 +344,13 @@ abstract class ActivityHandlerPlugin extends Plugin
$object = $activity->objects[0]; $object = $activity->objects[0];
$options = array('uri' => $object->id, $options = [
'uri' => $object->id,
'url' => $object->link, 'url' => $object->link,
'self' => $object->selfLink, 'self' => $object->selfLink,
'is_local' => Notice::REMOTE, 'is_local' => Notice::REMOTE,
'source' => 'ostatus'); 'source' => 'ostatus',
];
if (!isset($this->oldSaveNew)) { if (!isset($this->oldSaveNew)) {
$notice = Notice::saveActivity($activity, $profile, $options); $notice = Notice::saveActivity($activity, $profile, $options);
@ -366,7 +370,7 @@ abstract class ActivityHandlerPlugin extends Plugin
* @return boolean hook value * @return boolean hook value
*/ */
function onStartHandleSalmonTarget(Activity $activity, $target) public function onStartHandleSalmonTarget(Activity $activity, $target)
{ {
if (!$this->isMyActivity($activity)) { if (!$this->isMyActivity($activity)) {
return true; return true;
@ -377,7 +381,7 @@ abstract class ActivityHandlerPlugin extends Plugin
return true; return true;
} }
$this->log(LOG_INFO, get_called_class()." checking {$activity->id} as a valid Salmon slap."); $this->log(LOG_INFO, get_called_class() . " checking {$activity->id} as a valid Salmon slap.");
if ($target instanceof User_group || $target->isGroup()) { if ($target instanceof User_group || $target->isGroup()) {
$uri = $target->getUri(); $uri = $target->getUri();
@ -419,11 +423,13 @@ abstract class ActivityHandlerPlugin extends Plugin
$object = $activity; $object = $activity;
} }
$options = array('uri' => $object->id, $options = [
'uri' => $object->id,
'url' => $object->link, 'url' => $object->link,
'self' => $object->selfLink, 'self' => $object->selfLink,
'is_local' => Notice::REMOTE, 'is_local' => Notice::REMOTE,
'source' => 'ostatus'); 'source' => 'ostatus',
];
$notice = $this->saveNoticeFromActivity($activity, $actor, $options); $notice = $this->saveNoticeFromActivity($activity, $actor, $options);
@ -439,7 +445,7 @@ abstract class ActivityHandlerPlugin extends Plugin
* *
* @return boolean hook value * @return boolean hook value
*/ */
public function onStartAtomPubNewActivity(Activity $activity, Profile $scoped, Notice &$notice=null) public function onStartAtomPubNewActivity(Activity $activity, Profile $scoped, Notice &$notice = null)
{ {
if (!$this->isMyActivity($activity)) { if (!$this->isMyActivity($activity)) {
return true; return true;
@ -463,7 +469,7 @@ abstract class ActivityHandlerPlugin extends Plugin
* *
* @return boolean hook value * @return boolean hook value
*/ */
function onStartImportActivity($user, $author, Activity $activity, $trusted, &$done) public function onStartImportActivity($user, $author, Activity $activity, $trusted, &$done)
{ {
if (!$this->isMyActivity($activity)) { if (!$this->isMyActivity($activity)) {
return true; return true;
@ -471,15 +477,19 @@ abstract class ActivityHandlerPlugin extends Plugin
$obj = $activity->objects[0]; $obj = $activity->objects[0];
$options = array('uri' => $object->id, $options = [
'uri' => $object->id,
'url' => $object->link, 'url' => $object->link,
'self' => $object->selfLink, 'self' => $object->selfLink,
'source' => 'restore'); 'source' => 'restore',
];
// $user->getProfile() is a Profile // $user->getProfile() is a Profile
$saved = $this->saveNoticeFromActivity($activity, $saved = $this->saveNoticeFromActivity(
$activity,
$user->getProfile(), $user->getProfile(),
$options); $options
);
if (!empty($saved)) { if (!empty($saved)) {
$done = true; $done = true;
@ -500,7 +510,7 @@ abstract class ActivityHandlerPlugin extends Plugin
* @param XMLOutputter $out to add elements at end of object * @param XMLOutputter $out to add elements at end of object
* @return boolean hook return value * @return boolean hook return value
*/ */
function onEndActivityObjectOutputAtom(ActivityObject $obj, XMLOutputter $out) public function onEndActivityObjectOutputAtom(ActivityObject $obj, XMLOutputter $out)
{ {
if (in_array($obj->type, $this->types())) { if (in_array($obj->type, $this->types())) {
$this->activityObjectOutputAtom($obj, $out); $this->activityObjectOutputAtom($obj, $out);
@ -520,7 +530,7 @@ abstract class ActivityHandlerPlugin extends Plugin
* @param array &$out JSON-targeted array which can be modified * @param array &$out JSON-targeted array which can be modified
* @return boolean hook return value * @return boolean hook return value
*/ */
function onEndActivityObjectOutputJson(ActivityObject $obj, array &$out) public function onEndActivityObjectOutputJson(ActivityObject $obj, array &$out)
{ {
if (in_array($obj->type, $this->types())) { if (in_array($obj->type, $this->types())) {
$this->activityObjectOutputJson($obj, $out); $this->activityObjectOutputJson($obj, $out);
@ -536,7 +546,7 @@ abstract class ActivityHandlerPlugin extends Plugin
$this->openNoticeListItemElement($nli); $this->openNoticeListItemElement($nli);
Event::handle('EndOpenNoticeListItemElement', array($nli)); Event::handle('EndOpenNoticeListItemElement', [$nli]);
return false; return false;
} }
@ -548,7 +558,7 @@ abstract class ActivityHandlerPlugin extends Plugin
$this->closeNoticeListItemElement($nli); $this->closeNoticeListItemElement($nli);
Event::handle('EndCloseNoticeListItemElement', array($nli)); Event::handle('EndCloseNoticeListItemElement', [$nli]);
return false; return false;
} }
@ -560,7 +570,7 @@ abstract class ActivityHandlerPlugin extends Plugin
$class .= ' limited-scope'; $class .= ' limited-scope';
} }
try { try {
$class .= ' notice-source-'.common_to_alphanumeric($nli->notice->source); $class .= ' notice-source-' . common_to_alphanumeric($nli->notice->source);
} catch (Exception $e) { } catch (Exception $e) {
// either source or what we filtered out was a zero-length string // either source or what we filtered out was a zero-length string
} }
@ -584,7 +594,7 @@ abstract class ActivityHandlerPlugin extends Plugin
try { try {
$this->showNoticeListItem($nli); $this->showNoticeListItem($nli);
} catch (Exception $e) { } catch (Exception $e) {
common_log(LOG_ERR, 'Error showing notice '.$nli->getNotice()->getID().': ' . $e->getMessage()); common_log(LOG_ERR, 'Error showing notice ' . $nli->getNotice()->getID() . ': ' . $e->getMessage());
$nli->out->element('p', 'error', sprintf(_('Error showing notice: %s'), $e->getMessage())); $nli->out->element('p', 'error', sprintf(_('Error showing notice: %s'), $e->getMessage()));
} }
@ -619,7 +629,7 @@ abstract class ActivityHandlerPlugin extends Plugin
$nli->showContent(); $nli->showContent();
} }
public function onStartShowNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped=null) public function onStartShowNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped = null)
{ {
if (!$this->isMyNotice($stored)) { if (!$this->isMyNotice($stored)) {
return true; return true;
@ -633,7 +643,7 @@ abstract class ActivityHandlerPlugin extends Plugin
return false; return false;
} }
protected function showNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped=null) protected function showNoticeContent(Notice $stored, HTMLOutputter $out, Profile $scoped = null)
{ {
$out->text($stored->getContent()); $out->text($stored->getContent());
} }

View File

@ -1,51 +1,48 @@
<?php <?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/** /**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2011, StatusNet, Inc.
*
* Notice stream for a conversation * Notice stream for a conversation
* *
* PHP version 5
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*
* @category NoticeStream * @category NoticeStream
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc. * @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
*/ */
if (!defined('GNUSOCIAL')) { exit(1); } defined('GNUSOCIAL') || die();
/** /**
* Notice stream for a conversation * Notice stream for a conversation
* *
* @category Stream * @category Stream
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc. * @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
*/ */
class ConversationNoticeStream extends ScopingNoticeStream class ConversationNoticeStream extends ScopingNoticeStream
{ {
function __construct($id, Profile $scoped=null) public function __construct($id, Profile $scoped = null)
{ {
parent::__construct(new RawConversationNoticeStream($id), parent::__construct(
$scoped); new RawConversationNoticeStream($id),
$scoped
);
} }
} }
@ -53,23 +50,22 @@ class ConversationNoticeStream extends ScopingNoticeStream
* Notice stream for a conversation * Notice stream for a conversation
* *
* @category Stream * @category Stream
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc. * @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
*/ */
class RawConversationNoticeStream extends NoticeStream class RawConversationNoticeStream extends NoticeStream
{ {
protected $id; protected $id;
function __construct($id) public function __construct($id)
{ {
parent::__construct(); parent::__construct();
$this->id = $id; $this->id = $id;
} }
function getNoticeIds($offset, $limit, $since_id=null, $max_id=null) public function getNoticeIds($offset, $limit, $since_id = null, $max_id = null)
{ {
$notice = new Notice(); $notice = new Notice();
// SELECT // SELECT

View File

@ -1,34 +1,30 @@
<?php <?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/** /**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2010, StatusNet, Inc.
*
* An item in a notice list * An item in a notice list
* *
* PHP version 5
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*
* @category Widget * @category Widget
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @copyright 2010 StatusNet, Inc. * @copyright 2010 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
*/ */
if (!defined('GNUSOCIAL')) { exit(1); } defined('GNUSOCIAL') || die();
/** /**
* widget for displaying a single notice * widget for displaying a single notice
@ -40,23 +36,22 @@ if (!defined('GNUSOCIAL')) { exit(1); }
* author info (since that's implicit by the data in the page). * author info (since that's implicit by the data in the page).
* *
* @category UI * @category UI
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
* @see NoticeList * @see NoticeList
* @see ProfileNoticeListItem * @see ProfileNoticeListItem
*/ */
class NoticeListItem extends Widget class NoticeListItem extends Widget
{ {
/** The notice this item will show. */ /** The notice this item will show. */
var $notice = null; public $notice = null;
/** The notice that was repeated. */ /** The notice that was repeated. */
var $repeat = null; public $repeat = null;
/** The profile of the author of the notice, extracted once for convenience. */ /** The profile of the author of the notice, extracted once for convenience. */
var $profile = null; public $profile = null;
protected $addressees = true; protected $addressees = true;
protected $attachments = true; protected $attachments = true;
@ -72,8 +67,10 @@ class NoticeListItem extends Widget
* Also initializes the profile attribute. * Also initializes the profile attribute.
* *
* @param Notice $notice The notice we'll display * @param Notice $notice The notice we'll display
* @param Action|null $out
* @param array $prefs
*/ */
function __construct(Notice $notice, Action $out=null, array $prefs=array()) public function __construct(Notice $notice, Action $out = null, array $prefs = [])
{ {
parent::__construct($out); parent::__construct($out);
if (!empty($notice->repeat_of)) { if (!empty($notice->repeat_of)) {
@ -91,19 +88,19 @@ class NoticeListItem extends Widget
$this->profile = $this->notice->getProfile(); $this->profile = $this->notice->getProfile();
// integer preferences // integer preferences
foreach(array('maxchars') as $key) { foreach (['maxchars'] as $key) {
if (array_key_exists($key, $prefs)) { if (array_key_exists($key, $prefs)) {
$this->$key = (int)$prefs[$key]; $this->$key = (int)$prefs[$key];
} }
} }
// boolean preferences // boolean preferences
foreach(array('addressees', 'attachments', 'options') as $key) { foreach (['addressees', 'attachments', 'options'] as $key) {
if (array_key_exists($key, $prefs)) { if (array_key_exists($key, $prefs)) {
$this->$key = (bool)$prefs[$key]; $this->$key = (bool)$prefs[$key];
} }
} }
// string preferences // string preferences
foreach(array('id_prefix', 'item_tag') as $key) { foreach (['id_prefix', 'item_tag'] as $key) {
if (array_key_exists($key, $prefs)) { if (array_key_exists($key, $prefs)) {
$this->$key = $prefs[$key]; $this->$key = $prefs[$key];
} }
@ -118,12 +115,12 @@ class NoticeListItem extends Widget
* *
* @return void * @return void
*/ */
function show() public function show()
{ {
if (empty($this->notice)) { if (empty($this->notice)) {
common_log(LOG_WARNING, "Trying to show missing notice; skipping."); common_log(LOG_WARNING, "Trying to show missing notice; skipping.");
return; return;
} else if (empty($this->profile)) { } elseif (empty($this->profile)) {
common_log(LOG_WARNING, "Trying to show missing profile (" . $this->notice->profile_id . "); skipping."); common_log(LOG_WARNING, "Trying to show missing profile (" . $this->notice->profile_id . "); skipping.");
return; return;
} }
@ -136,7 +133,7 @@ class NoticeListItem extends Widget
$this->showEnd(); $this->showEnd();
} }
function showNotice() public function showNotice()
{ {
if (Event::handle('StartShowNoticeItemNotice', array($this))) { if (Event::handle('StartShowNoticeItemNotice', array($this))) {
$this->showNoticeHeaders(); $this->showNoticeHeaders();
@ -146,9 +143,9 @@ class NoticeListItem extends Widget
} }
} }
function showNoticeHeaders() public function showNoticeHeaders()
{ {
$this->elementStart('section', array('class'=>'notice-headers')); $this->elementStart('section', ['class' => 'notice-headers']);
$this->showNoticeTitle(); $this->showNoticeTitle();
$this->showAuthor(); $this->showAuthor();
@ -161,33 +158,44 @@ class NoticeListItem extends Widget
} catch (InvalidUrlException $e) { } catch (InvalidUrlException $e) {
// parent had an invalid URL so we can't show it // parent had an invalid URL so we can't show it
} }
if ($this->addressees) { $this->showAddressees(); } if ($this->addressees) {
$this->showAddressees();
}
$this->elementEnd('div'); $this->elementEnd('div');
} }
$this->elementEnd('section'); $this->elementEnd('section');
} }
function showNoticeFooter() public function showNoticeFooter()
{ {
$this->elementStart('footer'); $this->elementStart('footer');
$this->showNoticeInfo(); $this->showNoticeInfo();
if ($this->options) { $this->showNoticeOptions(); } if ($this->options) {
if ($this->attachments) { $this->showNoticeAttachments(); } $this->showNoticeOptions();
}
if ($this->attachments) {
$this->showNoticeAttachments();
}
$this->elementEnd('footer'); $this->elementEnd('footer');
} }
function showNoticeTitle() public function showNoticeTitle()
{ {
if (Event::handle('StartShowNoticeTitle', array($this))) { if (Event::handle('StartShowNoticeTitle', array($this))) {
$nameClass = $this->notice->getTitle(false) ? 'p-name ' : ''; $nameClass = $this->notice->getTitle(false) ? 'p-name ' : '';
$this->element('a', array('href' => $this->notice->getUri(), $this->element(
'class' => $nameClass . 'u-uid'), 'a',
$this->notice->getTitle()); [
'href' => $this->notice->getUri(),
'class' => $nameClass . 'u-uid',
],
$this->notice->getTitle()
);
Event::handle('EndShowNoticeTitle', array($this)); Event::handle('EndShowNoticeTitle', array($this));
} }
} }
function showNoticeInfo() public function showNoticeInfo()
{ {
if (Event::handle('StartShowNoticeInfo', array($this))) { if (Event::handle('StartShowNoticeInfo', array($this))) {
$this->showContextLink(); $this->showContextLink();
@ -199,7 +207,7 @@ class NoticeListItem extends Widget
} }
} }
function showNoticeOptions() public function showNoticeOptions()
{ {
if (Event::handle('StartShowNoticeOptions', array($this))) { if (Event::handle('StartShowNoticeOptions', array($this))) {
$user = common_current_user(); $user = common_current_user();
@ -221,23 +229,28 @@ class NoticeListItem extends Widget
* *
* @return void * @return void
*/ */
function showStart() public function showStart()
{ {
if (Event::handle('StartOpenNoticeListItemElement', array($this))) { if (Event::handle('StartOpenNoticeListItemElement', [$this])) {
$id = (empty($this->repeat)) ? $this->notice->id : $this->repeat->id; $id = (empty($this->repeat)) ? $this->notice->id : $this->repeat->id;
$class = 'h-entry notice'; $class = 'h-entry notice';
if ($this->notice->scope != 0 && $this->notice->scope != 1) { if ($this->notice->scope != 0 && $this->notice->scope != 1) {
$class .= ' limited-scope'; $class .= ' limited-scope';
} }
try { try {
$class .= ' notice-source-'.common_to_alphanumeric($this->notice->source); $class .= ' notice-source-' . common_to_alphanumeric($this->notice->source);
} catch (Exception $e) { } catch (Exception $e) {
// either source or what we filtered out was a zero-length string // either source or what we filtered out was a zero-length string
} }
$id_prefix = (strlen($this->id_prefix) ? $this->id_prefix . '-' : ''); $id_prefix = (strlen($this->id_prefix) ? $this->id_prefix . '-' : '');
$this->out->elementStart($this->item_tag, array('class' => $class, $this->out->elementStart(
'id' => "${id_prefix}notice-${id}")); $this->item_tag,
Event::handle('EndOpenNoticeListItemElement', array($this)); [
'class' => $class,
'id' => "${id_prefix}notice-${id}",
]
);
Event::handle('EndOpenNoticeListItemElement', [$this]);
} }
} }
@ -249,12 +262,16 @@ class NoticeListItem extends Widget
* @return void * @return void
*/ */
function showAuthor() public function showAuthor()
{ {
$attrs = array('href' => $this->profile->getUrl(), $attrs = [
'href' => $this->profile->getUrl(),
'class' => 'h-card', 'class' => 'h-card',
'title' => $this->profile->getHtmlTitle()); 'title' => $this->profile->getHtmlTitle(),
if(empty($this->repeat)) { $attrs['class'] .= ' p-author'; } ];
if (empty($this->repeat)) {
$attrs['class'] .= ' p-author';
}
if (Event::handle('StartShowNoticeItemAuthor', array($this->profile, $this->out, &$attrs))) { if (Event::handle('StartShowNoticeItemAuthor', array($this->profile, $this->out, &$attrs))) {
$this->out->elementStart('a', $attrs); $this->out->elementStart('a', $attrs);
@ -265,7 +282,7 @@ class NoticeListItem extends Widget
} }
} }
function showParent() public function showParent()
{ {
$this->out->element( $this->out->element(
'a', 'a',
@ -278,7 +295,7 @@ class NoticeListItem extends Widget
); );
} }
function showAddressees() public function showAddressees()
{ {
$pa = $this->getProfileAddressees(); $pa = $this->getProfileAddressees();
@ -296,9 +313,11 @@ class NoticeListItem extends Widget
} }
} }
function getProfileAddressees() public function getProfileAddressees()
{ {
if($this->pa) { return $this->pa; } if ($this->pa) {
return $this->pa;
}
$this->pa = array(); $this->pa = array();
$attentions = $this->getAttentionProfiles(); $attentions = $this->getAttentionProfiles();
@ -311,16 +330,18 @@ class NoticeListItem extends Widget
$class = 'account'; $class = 'account';
$profileurl = common_local_url('userbyid', array('id' => $attn->getID())); $profileurl = common_local_url('userbyid', array('id' => $attn->getID()));
} }
$this->pa[] = array('href' => $profileurl, $this->pa[] = [
'href' => $profileurl,
'title' => $attn->getHtmlTitle(), 'title' => $attn->getHtmlTitle(),
'class' => "addressee {$class} p-name u-url", 'class' => "addressee {$class} p-name u-url",
'text' => $attn->getStreamName()); 'text' => $attn->getStreamName(),
];
} }
return $this->pa; return $this->pa;
} }
function getAttentionProfiles() public function getAttentionProfiles()
{ {
return $this->notice->getAttentionProfiles(); return $this->notice->getAttentionProfiles();
} }
@ -332,11 +353,13 @@ class NoticeListItem extends Widget
* *
* @return void * @return void
*/ */
function showNickname() public function showNickname()
{ {
$this->out->raw('<span class="p-name">' . $this->out->raw(
'<span class="p-name">' .
htmlspecialchars($this->profile->getNickname()) . htmlspecialchars($this->profile->getNickname()) .
'</span>'); '</span>'
);
} }
/** /**
@ -348,7 +371,7 @@ class NoticeListItem extends Widget
* *
* @return void * @return void
*/ */
function showContent() public function showContent()
{ {
// FIXME: URL, image, video, audio // FIXME: URL, image, video, audio
$nameClass = $this->notice->getTitle(false) ? '' : 'p-name '; $nameClass = $this->notice->getTitle(false) ? '' : 'p-name ';
@ -364,7 +387,8 @@ class NoticeListItem extends Widget
$this->out->elementEnd('article'); $this->out->elementEnd('article');
} }
function showNoticeAttachments() { public function showNoticeAttachments()
{
if (common_config('attachments', 'show_thumbs')) { if (common_config('attachments', 'show_thumbs')) {
$al = new InlineAttachmentList($this->notice, $this->out); $al = new InlineAttachmentList($this->notice, $this->out);
$al->show(); $al->show();
@ -378,12 +402,17 @@ class NoticeListItem extends Widget
* *
* @return void * @return void
*/ */
function showNoticeLink() public function showNoticeLink()
{ {
$this->out->element('time', array('class' => 'dt-published', $this->out->element(
'time',
[
'class' => 'dt-published',
'datetime' => common_date_iso8601($this->notice->created), 'datetime' => common_date_iso8601($this->notice->created),
'title' => common_exact_date($this->notice->created)), 'title' => common_exact_date($this->notice->created),
common_date_string($this->notice->created)); ],
common_date_string($this->notice->created)
);
} }
/** /**
@ -395,7 +424,7 @@ class NoticeListItem extends Widget
* *
* @return void * @return void
*/ */
function showNoticeLocation() public function showNoticeLocation()
{ {
try { try {
$location = Notice_location::locFromStored($this->notice); $location = Notice_location::locFromStored($this->notice);
@ -409,7 +438,7 @@ class NoticeListItem extends Widget
$lat = $location->lat; $lat = $location->lat;
$lon = $location->lon; $lon = $location->lon;
$latlon = (!empty($lat) && !empty($lon)) ? $lat.';'.$lon : ''; $latlon = (!empty($lat) && !empty($lon)) ? $lat . ';' . $lon : '';
if (empty($name)) { if (empty($name)) {
$latdms = $this->decimalDegreesToDMS(abs($lat)); $latdms = $this->decimalDegreesToDMS(abs($lat));
@ -429,8 +458,15 @@ class NoticeListItem extends Widget
// TRANS: %5$s is longitude degrees, %6$s is longitude minutes, // TRANS: %5$s is longitude degrees, %6$s is longitude minutes,
// TRANS: %7$s is longitude seconds, %8$s is E (east) or W (west) depending on longitude, // TRANS: %7$s is longitude seconds, %8$s is E (east) or W (west) depending on longitude,
_('%1$u°%2$u\'%3$u"%4$s %5$u°%6$u\'%7$u"%8$s'), _('%1$u°%2$u\'%3$u"%4$s %5$u°%6$u\'%7$u"%8$s'),
$latdms['deg'],$latdms['min'], $latdms['sec'],($lat>0? $north:$south), $latdms['deg'],
$londms['deg'],$londms['min'], $londms['sec'],($lon>0? $east:$west)); $latdms['min'],
$latdms['sec'],
($lat > 0 ? $north : $south),
$londms['deg'],
$londms['min'],
$londms['sec'],
($lon > 0 ? $east : $west)
);
} }
$url = $location->getUrl(); $url = $location->getUrl();
@ -441,16 +477,25 @@ class NoticeListItem extends Widget
$this->out->text(_('at')); $this->out->text(_('at'));
$this->out->text(' '); $this->out->text(' ');
if (empty($url)) { if (empty($url)) {
$this->out->element('abbr', array('class' => 'geo', $this->out->element(
'title' => $latlon), 'abbr',
$name); [
'class' => 'geo',
'title' => $latlon,
],
$name
);
} else { } else {
$xstr = new XMLStringer(false); $xstr = new XMLStringer(false);
$xstr->elementStart('a', array('href' => $url, $xstr->elementStart(
'rel' => 'external')); 'a',
$xstr->element('abbr', array('class' => 'geo', ['href' => $url, 'rel' => 'external']
'title' => $latlon), );
$name); $xstr->element(
'abbr',
['class' => 'geo', 'title' => $latlon],
$name
);
$xstr->elementEnd('a'); $xstr->elementEnd('a');
$this->out->raw($xstr->getString()); $this->out->raw($xstr->getString());
} }
@ -461,16 +506,16 @@ class NoticeListItem extends Widget
* @param number $dec decimal degrees * @param number $dec decimal degrees
* @return array split into 'deg', 'min', and 'sec' * @return array split into 'deg', 'min', and 'sec'
*/ */
function decimalDegreesToDMS($dec) public function decimalDegreesToDMS($dec)
{ {
$deg = intval($dec); $deg = intval($dec);
$tempma = abs($dec) - abs($deg); $tempma = abs($dec) - abs($deg);
$tempma = $tempma * 3600; $tempma = $tempma * 3600;
$min = floor($tempma / 60); $min = floor($tempma / 60);
$sec = $tempma - ($min*60); $sec = $tempma - ($min * 60);
return array("deg"=>$deg,"min"=>$min,"sec"=>$sec); return ['deg' => $deg, 'min' => $min, 'sec' => $sec];
} }
/** /**
@ -480,17 +525,18 @@ class NoticeListItem extends Widget
* or one of other other channels. * or one of other other channels.
* *
* @return void * @return void
* @throws Exception
*/ */
function showNoticeSource() public function showNoticeSource()
{ {
$ns = $this->notice->getSource(); $ns = $this->notice->getSource();
if (!$ns instanceof Notice_source) { if (!$ns instanceof Notice_source) {
return false; return;
} }
// TRANS: A possible notice source (web interface). // TRANS: A possible notice source (web interface).
$source_name = (empty($ns->name)) ? ($ns->code ? _($ns->code) : _m('SOURCE','web')) : _($ns->name); $source_name = (empty($ns->name)) ? ($ns->code ? _($ns->code) : _m('SOURCE', 'web')) : _($ns->name);
$this->out->text(' '); $this->out->text(' ');
$this->out->elementStart('span', 'source'); $this->out->elementStart('span', 'source');
// @todo FIXME: probably i18n issue. If "from" is followed by text, that should be a parameter to "from" (from %s). // @todo FIXME: probably i18n issue. If "from" is followed by text, that should be a parameter to "from" (from %s).
@ -538,7 +584,7 @@ class NoticeListItem extends Widget
* *
* @return void * @return void
*/ */
function showPermalink() public function showPermalink()
{ {
$class = 'permalink u-url'; $class = 'permalink u-url';
if (!$this->notice->isLocal()) { if (!$this->notice->isLocal()) {
@ -546,11 +592,15 @@ class NoticeListItem extends Widget
} }
try { try {
if($this->repeat) { if ($this->repeat) {
$this->out->element('a', $this->out->element(
array('href' => $this->repeat->getUrl(), 'a',
'class' => 'u-url'), [
''); 'href' => $this->repeat->getUrl(),
'class' => 'u-url',
],
''
);
$class = str_replace('u-url', 'u-repost-of', $class); $class = str_replace('u-url', 'u-repost-of', $class);
} }
} catch (InvalidUrlException $e) { } catch (InvalidUrlException $e) {
@ -558,11 +608,15 @@ class NoticeListItem extends Widget
} }
try { try {
$this->out->element('a', $this->out->element(
array('href' => $this->notice->getUrl(true), 'a',
'class' => $class), [
'href' => $this->notice->getUrl(true),
'class' => $class,
],
// TRANS: Addition in notice list item for single-notice view. // TRANS: Addition in notice list item for single-notice view.
_('permalink')); _('permalink')
);
} catch (InvalidUrlException $e) { } catch (InvalidUrlException $e) {
// no permalink available // no permalink available
} }
@ -571,13 +625,18 @@ class NoticeListItem extends Widget
/** /**
* Show link to conversation view. * Show link to conversation view.
*/ */
function showContextLink() public function showContextLink()
{ {
$this->out->element('a', array('rel' => 'bookmark', $this->out->element(
'a',
[
'rel' => 'bookmark',
'class' => 'timestamp', 'class' => 'timestamp',
'href' => Conversation::getUrlFromNotice($this->notice)), 'href' => Conversation::getUrlFromNotice($this->notice),
],
// TRANS: A link to the conversation view of a notice, on the local server. // TRANS: A link to the conversation view of a notice, on the local server.
_('In conversation')); _('In conversation')
);
} }
/** /**
@ -588,16 +647,26 @@ class NoticeListItem extends Widget
* *
* @return void * @return void
*/ */
function showReplyLink() public function showReplyLink()
{ {
if (common_logged_in()) { if (common_logged_in()) {
$this->out->text(' '); $this->out->text(' ');
$reply_url = common_local_url('newnotice', $reply_url = common_local_url(
array('replyto' => $this->profile->getNickname(), 'inreplyto' => $this->notice->id)); 'newnotice',
$this->out->elementStart('a', array('href' => $reply_url, [
'replyto' => $this->profile->getNickname(),
'inreplyto' => $this->notice->id,
]
);
$this->out->elementStart(
'a',
[
'href' => $reply_url,
'class' => 'notice_reply', 'class' => 'notice_reply',
// TRANS: Link title in notice list item to reply to a notice. // TRANS: Link title in notice list item to reply to a notice.
'title' => _('Reply to this notice.'))); 'title' => _('Reply to this notice.'),
]
);
// TRANS: Link text in notice list item to reply to a notice. // TRANS: Link text in notice list item to reply to a notice.
$this->out->text(_('Reply')); $this->out->text(_('Reply'));
$this->out->text(' '); $this->out->text(' ');
@ -610,8 +679,9 @@ class NoticeListItem extends Widget
* if the user is the author, let them delete the notice * if the user is the author, let them delete the notice
* *
* @return void * @return void
* @throws Exception
*/ */
function showDeleteLink() public function showDeleteLink()
{ {
$user = common_current_user(); $user = common_current_user();
@ -621,14 +691,21 @@ class NoticeListItem extends Widget
!$this->notice->isVerb([ActivityVerb::DELETE]) && !$this->notice->isVerb([ActivityVerb::DELETE]) &&
($todel->profile_id == $user->id || $user->hasRight(Right::DELETEOTHERSNOTICE))) { ($todel->profile_id == $user->id || $user->hasRight(Right::DELETEOTHERSNOTICE))) {
$this->out->text(' '); $this->out->text(' ');
$deleteurl = common_local_url('deletenotice', $deleteurl = common_local_url(
array('notice' => $todel->id)); 'deletenotice',
$this->out->element('a', array('href' => $deleteurl, ['notice' => $todel->id]
);
$this->out->element(
'a',
[
'href' => $deleteurl,
'class' => 'notice_delete popup', 'class' => 'notice_delete popup',
// TRANS: Link title in notice list item to delete a notice. // TRANS: Link title in notice list item to delete a notice.
'title' => _('Delete this notice from the timeline.')), 'title' => _m('Delete this notice from the timeline.'),
],
// TRANS: Link text in notice list item to delete a notice. // TRANS: Link text in notice list item to delete a notice.
_('Delete')); _m('Delete')
);
} }
} }
@ -639,11 +716,11 @@ class NoticeListItem extends Widget
* *
* @return void * @return void
*/ */
function showEnd() public function showEnd()
{ {
if (Event::handle('StartCloseNoticeListItemElement', array($this))) { if (Event::handle('StartCloseNoticeListItemElement', [$this])) {
$this->out->elementEnd('li'); $this->out->elementEnd('li');
Event::handle('EndCloseNoticeListItemElement', array($this)); Event::handle('EndCloseNoticeListItemElement', [$this]);
} }
} }
@ -655,7 +732,7 @@ class NoticeListItem extends Widget
* @return Notice The notice we're showing * @return Notice The notice we're showing
*/ */
function getNotice() public function getNotice()
{ {
return $this->notice; return $this->notice;
} }

View File

@ -1,76 +1,71 @@
<?php <?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/** /**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2011, StatusNet, Inc.
*
* A stream of notices * A stream of notices
* *
* PHP version 5
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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/>.
*
* @category Stream * @category Stream
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc. * @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
*/ */
if (!defined('GNUSOCIAL')) { exit(1); } defined('GNUSOCIAL') || die();
/** /**
* Class for notice streams * Class for notice streams
* *
* @category Stream * @category Stream
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc. * @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
*/ */
abstract class NoticeStream abstract class NoticeStream
{ {
protected $selectVerbs = array(ActivityVerb::POST => true, protected $selectVerbs = [
ActivityVerb::SHARE => true); ActivityVerb::POST => true,
ActivityVerb::SHARE => true,
];
public function __construct() public function __construct()
{ {
foreach ($this->selectVerbs as $key=>$val) { foreach ($this->selectVerbs as $key => $val) {
$this->selectVerbs[ActivityUtils::resolveUri($key)] = $val; $this->selectVerbs[ActivityUtils::resolveUri($key)] = $val;
// to avoid database inconsistency issues we can select both relative and absolute verbs // to avoid database inconsistency issues we can select both relative and absolute verbs
//$this->selectVerbs[ActivityUtils::resolveUri($key, true)] = $val; //$this->selectVerbs[ActivityUtils::resolveUri($key, true)] = $val;
} }
} }
abstract function getNoticeIds($offset, $limit, $since_id, $max_id); abstract public function getNoticeIds($offset, $limit, $since_id, $max_id);
function getNotices($offset, $limit, $sinceId = null, $maxId = null) public function getNotices($offset, $limit, $sinceId = null, $maxId = null)
{ {
$ids = $this->getNoticeIds($offset, $limit, $sinceId, $maxId); $ids = $this->getNoticeIds($offset, $limit, $sinceId, $maxId);
$notices = self::getStreamByIds($ids); return self::getStreamByIds($ids);
return $notices;
} }
static function getStreamByIds($ids) public static function getStreamByIds($ids)
{ {
return Notice::multiGet('id', $ids); return Notice::multiGet('id', $ids);
} }
static function filterVerbs(Notice $notice, array $selectVerbs) public static function filterVerbs(Notice $notice, array $selectVerbs)
{ {
$filter = array_keys(array_filter($selectVerbs)); $filter = array_keys(array_filter($selectVerbs));
if (!empty($filter)) { if (!empty($filter)) {
@ -78,7 +73,9 @@ abstract class NoticeStream
$notice->whereAddIn('verb', $filter, $notice->columnType('verb')); $notice->whereAddIn('verb', $filter, $notice->columnType('verb'));
} }
$filter = array_keys(array_filter($selectVerbs, function ($v) { return !$v; })); $filter = array_keys(array_filter($selectVerbs, function ($v) {
return !$v;
}));
if (!empty($filter)) { if (!empty($filter)) {
// exclude verbs in selectVerbs with values that equate to false // exclude verbs in selectVerbs with values that equate to false
$notice->whereAddIn('!verb', $filter, $notice->columnType('verb')); $notice->whereAddIn('!verb', $filter, $notice->columnType('verb'));

View File

@ -1,9 +1,23 @@
<?php <?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
if (!defined('GNUSOCIAL')) { exit(1); } defined('GNUSOCIAL') || die();
/** /**
* widget for displaying a single notice * Widget for displaying a single notice.
* *
* This widget has the core smarts for showing a single notice: what to display, * This widget has the core smarts for showing a single notice: what to display,
* where, and under which circumstances. Its key method is show(); this is a recipe * where, and under which circumstances. Its key method is show(); this is a recipe
@ -12,10 +26,9 @@ if (!defined('GNUSOCIAL')) { exit(1); }
* author info (since that's implicit by the data in the page). * author info (since that's implicit by the data in the page).
* *
* @category UI * @category UI
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
* @see NoticeList * @see NoticeList
* @see ProfileNoticeListItem * @see ProfileNoticeListItem
*/ */
@ -23,13 +36,13 @@ class ThreadedNoticeListItem extends NoticeListItem
{ {
protected $userProfile = null; protected $userProfile = null;
function __construct(Notice $notice, Action $out=null, $profile=null) public function __construct(Notice $notice, Action $out = null, $profile = null)
{ {
parent::__construct($notice, $out); parent::__construct($notice, $out);
$this->userProfile = $profile; $this->userProfile = $profile;
} }
function initialItems() public function initialItems()
{ {
return 3; return 3;
} }
@ -41,17 +54,17 @@ class ThreadedNoticeListItem extends NoticeListItem
* *
* @return void * @return void
*/ */
function showEnd() public function showEnd()
{ {
$max = $this->initialItems(); $max = $this->initialItems();
if (!$this->repeat instanceof Notice) { if (!$this->repeat instanceof Notice) {
$stream = new ConversationNoticeStream($this->notice->conversation, $this->userProfile); $stream = new ConversationNoticeStream($this->notice->conversation, $this->userProfile);
$notice = $stream->getNotices(0, $max + 2); $notice = $stream->getNotices(0, $max + 2);
$notices = array(); $notices = [];
$cnt = 0; $cnt = 0;
$moreCutoff = null; $moreCutoff = null;
while ($notice->fetch()) { while ($notice->fetch()) {
if (Event::handle('StartAddNoticeReply', array($this, $this->notice, $notice))) { if (Event::handle('StartAddNoticeReply', [$this, $this->notice, $notice])) {
// Don't list repeats as separate notices in a conversation // Don't list repeats as separate notices in a conversation
if (!empty($notice->repeat_of)) { if (!empty($notice->repeat_of)) {
continue; continue;
@ -69,11 +82,11 @@ class ThreadedNoticeListItem extends NoticeListItem
$cnt++; $cnt++;
if ($cnt > $max) { if ($cnt > $max) {
// boo-yah // boo-yah
$moreCutoff = clone($notice); $moreCutoff = clone $notice;
break; break;
} }
$notices[] = clone($notice); // *grumble* inefficient as hell $notices[] = clone $notice; // *grumble* inefficient as hell
Event::handle('EndAddNoticeReply', array($this, $this->notice, $notice)); Event::handle('EndAddNoticeReply', [$this, $this->notice, $notice]);
} }
} }
@ -87,7 +100,7 @@ class ThreadedNoticeListItem extends NoticeListItem
Event::handle('EndShowThreadedNoticeTailItems', array($this, $this->notice, &$threadActive)); Event::handle('EndShowThreadedNoticeTailItems', array($this, $this->notice, &$threadActive));
} }
if (count($notices)>0) { if (count($notices) > 0) {
if ($moreCutoff) { if ($moreCutoff) {
$item = new ThreadedNoticeListMoreItem($moreCutoff, $this->out, count($notices)); $item = new ThreadedNoticeListMoreItem($moreCutoff, $this->out, count($notices));
$item->show(); $item->show();