[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
// 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
*
* 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
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @author Sarven Capadisli <csarven@status.net>
* @copyright 2008-2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @copyright 2009 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();
/**
* User profile page
@ -58,7 +55,7 @@ class ShowstreamAction extends NoticestreamAction
return $stream;
}
function title()
public function title()
{
$base = $this->target->getFancyName();
if (!empty($this->tag)) {
@ -77,9 +74,11 @@ class ShowstreamAction extends NoticestreamAction
} else {
// TRANS: Extended page title showing tagged notices in one user's timeline.
// TRANS: %1$s is the username, %2$d is the page number.
return sprintf(_('Notices by %1$s, page %2$d'),
$base,
$this->page);
return sprintf(
_('Notices by %1$s, page %2$d'),
$base,
$this->page
);
}
}
}
@ -89,79 +88,120 @@ class ShowstreamAction extends NoticestreamAction
$this->showNotices();
}
function showProfileBlock()
public function showProfileBlock()
{
$block = new AccountProfileBlock($this, $this->target);
$block->show();
}
function showPageNoticeBlock()
public function showPageNoticeBlock()
{
return;
}
function getFeeds()
public function getFeeds()
{
if (!empty($this->tag)) {
return array(new Feed(Feed::RSS1,
common_local_url('userrss',
array('nickname' => $this->target->getNickname(),
'tag' => $this->tag)),
// TRANS: Title for link to notice feed.
// TRANS: %1$s is a user nickname, %2$s is a hashtag.
sprintf(_('Notice feed for %1$s tagged %2$s (RSS 1.0)'),
$this->target->getNickname(), $this->tag)));
return [new Feed(
Feed::RSS1,
common_local_url(
'userrss',
[
'nickname' => $this->target->getNickname(),
'tag' => $this->tag,
]
),
// TRANS: Title for link to notice feed.
// TRANS: %1$s is a user nickname, %2$s is a hashtag.
sprintf(
_('Notice feed for %1$s tagged %2$s (RSS 1.0)'),
$this->target->getNickname(),
$this->tag
)
)];
}
if (!$this->target->isLocal()) {
// remote profiles at least have Atom, but we can't guarantee anything else
return array(
new Feed(Feed::ATOM,
$this->target->getAtomFeed(),
// TRANS: Title for link to notice feed.
// TRANS: %s is a user nickname.
sprintf(_('Notice feed for %s (Atom)'),
$this->target->getNickname()))
);
return [new Feed(
Feed::ATOM,
$this->target->getAtomFeed(),
// TRANS: Title for link to notice feed.
// TRANS: %s is a user nickname.
sprintf(
_('Notice feed for %s (Atom)'),
$this->target->getNickname()
)
)];
}
return array(new Feed(Feed::JSON,
common_local_url('ApiTimelineUser',
array(
'id' => $this->target->getID(),
'format' => 'as')),
// TRANS: Title for link to notice feed.
// TRANS: %s is a user nickname.
sprintf(_('Notice feed for %s (Activity Streams JSON)'),
$this->target->getNickname())),
new Feed(Feed::RSS1,
common_local_url('userrss',
array('nickname' => $this->target->getNickname())),
// TRANS: Title for link to notice feed.
// TRANS: %s is a user nickname.
sprintf(_('Notice feed for %s (RSS 1.0)'),
$this->target->getNickname())),
new Feed(Feed::RSS2,
common_local_url('ApiTimelineUser',
array(
'id' => $this->target->getID(),
'format' => 'rss')),
// TRANS: Title for link to notice feed.
// TRANS: %s is a user nickname.
sprintf(_('Notice feed for %s (RSS 2.0)'),
$this->target->getNickname())),
new Feed(Feed::ATOM,
$this->target->getAtomFeed(),
// TRANS: Title for link to notice feed.
// TRANS: %s is a user nickname.
sprintf(_('Notice feed for %s (Atom)'),
$this->target->getNickname())),
new Feed(Feed::FOAF,
common_local_url('foaf', array('nickname' =>
$this->target->getNickname())),
// 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.
sprintf(_('FOAF for %s'), $this->target->getNickname())));
return [
new Feed(
Feed::JSON,
common_local_url(
'ApiTimelineUser',
[
'id' => $this->target->getID(),
'format' => 'as',
]
),
// TRANS: Title for link to notice feed.
// TRANS: %s is a user nickname.
sprintf(
_('Notice feed for %s (Activity Streams JSON)'),
$this->target->getNickname()
)
),
new Feed(
Feed::RSS1,
common_local_url(
'userrss',
['nickname' => $this->target->getNickname()]
),
// TRANS: Title for link to notice feed.
// TRANS: %s is a user nickname.
sprintf(
_('Notice feed for %s (RSS 1.0)'),
$this->target->getNickname()
)
),
new Feed(
Feed::RSS2,
common_local_url(
'ApiTimelineUser',
[
'id' => $this->target->getID(),
'format' => 'rss',
]
),
// TRANS: Title for link to notice feed.
// TRANS: %s is a user nickname.
sprintf(
_('Notice feed for %s (RSS 2.0)'),
$this->target->getNickname()
)
),
new Feed(
Feed::ATOM,
$this->target->getAtomFeed(),
// TRANS: Title for link to notice feed.
// TRANS: %s is a user nickname.
sprintf(
_('Notice feed for %s (Atom)'),
$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: More information at http://www.foaf-project.org. %s is a user nickname.
sprintf(_('FOAF for %s'), $this->target->getNickname())
)
];
}
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
if (get_class($this) == 'ShowstreamAction') {
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) {
$this->element('meta', array('name' => 'description',
'content' => $this->target->getDescription()));
$this->element(
'meta',
[
'name' => 'description',
'content' => $this->target->getDescription(),
]
);
}
$rsd = common_local_url('rsd',
array('nickname' => $this->target->getNickname()));
$rsd = common_local_url(
'rsd',
['nickname' => $this->target->getNickname()]
);
// RSD, http://tales.phrasewise.com/rfc/rsd
$this->element('link', array('rel' => 'EditURI',
'type' => 'application/rsd+xml',
'href' => $rsd));
$this->element(
'link',
[
'rel' => 'EditURI',
'type' => 'application/rsd+xml',
'href' => $rsd,
]
);
if ($this->page != 1) {
$this->element('link', array('rel' => 'canonical',
'href' => $this->target->getUrl()));
$this->element(
'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.
$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.
$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: 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());
@ -222,7 +278,7 @@ class ShowstreamAction extends NoticestreamAction
$this->elementEnd('div');
}
function showNotices()
public function showNotices()
{
$pnl = new PrimaryNoticeList($this->notice, $this);
$cnt = $pnl->show();
@ -232,41 +288,51 @@ class ShowstreamAction extends NoticestreamAction
// either nickname or id will be used, depending on which action (showstream, userbyid...)
$args = array('nickname' => $this->target->getNickname(), 'id' => $this->target->getID());
if (!empty($this->tag))
{
if (!empty($this->tag)) {
$args['tag'] = $this->tag;
}
$this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
$this->getActionName(), $args);
$this->pagination(
$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: 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 ' .
'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%%%%))'),
$this->target->getNickname(), $this->target->getNickname());
$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. ' .
'[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
$this->target->getNickname(),
$this->target->getNickname()
);
} else {
// 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.
$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.'),
$this->target->getNickname(), $this->target->getNickname());
$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.'),
$this->target->getNickname(),
$this->target->getNickname()
);
}
$this->elementStart('div', array('id' => 'anon_notice'));
$this->raw(common_markup_to_html($m));
$this->elementEnd('div');
}
function noticeFormOptions()
public function noticeFormOptions()
{
$options = parent::noticeFormOptions();
if (!$this->scoped instanceof Profile || !$this->scoped->sameAs($this->target)) {
$options['to_profile'] = $this->target;
$options['to_profile'] = $this->target;
}
return $options;

View File

@ -1,44 +1,40 @@
<?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.
*
* PHP version 5
*
* @category Action
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @author Robin Millette <millette@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
* 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/>.
* @category Action
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @author Robin Millette <millette@status.net>
* @copyright 2009 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();
/**
* User by ID action class.
*
* @category Action
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @author Robin Millette <millette@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
* @category Action
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @author Robin Millette <millette@status.net>
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class UserbyidAction extends ShowstreamAction
{
@ -56,10 +52,12 @@ class UserbyidAction extends ShowstreamAction
// 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';
$httpaccept = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : null;
$type = common_negotiate_type(common_accept_to_prefs($httpaccept),
common_accept_to_prefs($page_prefs));
$page = $type === 'application/rdf+xml' ? 'foaf' : 'showstream';
$url = common_local_url($page, array('nickname' => $this->target->getNickname()));
$type = common_negotiate_type(
common_accept_to_prefs($httpaccept),
common_accept_to_prefs($page_prefs)
);
$page = ($type === 'application/rdf+xml') ? 'foaf' : 'showstream';
$url = common_local_url($page, ['nickname' => $this->target->getNickname()]);
common_redirect($url, 303);
}
}

View File

@ -1,23 +1,27 @@
<?php
/*
* GNU Social - a federating social network
* Copyright (C) 2014, Free Software Foundation, 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/>.
// 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/>.
/**
* @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
@ -25,20 +29,19 @@ if (!defined('GNUSOCIAL')) { exit(1); }
* @category Activity
* @package GNUsocial
* @author Mikael Nordfeldth <mmn@hethane.se>
* @copyright 2014 Free Software Foundation, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://gnu.io/social
* @copyright 2014 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
abstract class ActivityHandlerModule extends Module
{
/**
/**
* Returns a key string which represents this activity in HTML classes,
* ids etc, as when offering selection of what type of post to make.
* In MicroAppPlugin, this is paired with the user-visible localizable appTitle().
* ids etc, as when offering selection of what type of post to make.
* In MicroAppPlugin, this is paired with the user-visible localizable appTitle().
*
* @return string (compatible with HTML classes)
*/
abstract function tag();
*/
abstract public function tag();
/**
* Return a list of ActivityStreams object type IRIs
@ -51,7 +54,7 @@ abstract class ActivityHandlerModule extends Module
*
* @return array of strings
*/
abstract function types();
abstract public function types();
/**
* Return a list of ActivityStreams verb IRIs which
@ -64,7 +67,8 @@ abstract class ActivityHandlerModule extends Module
*
* @return array of strings
*/
public function verbs() {
public function verbs()
{
return array(ActivityVerb::POST);
}
@ -80,7 +84,8 @@ abstract class ActivityHandlerModule extends Module
* @param Activity $activity
* @return boolean
*/
function isMyActivity(Activity $act) {
public function isMyActivity(Activity $act)
{
return (count($act->objects) == 1
&& ($act->objects[0] instanceof ActivityObject)
&& $this->isMyVerb($act->verb)
@ -98,18 +103,21 @@ abstract class ActivityHandlerModule extends Module
* @param Notice $notice
* @return boolean
*/
function isMyNotice(Notice $notice) {
public function isMyNotice(Notice $notice)
{
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
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)
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 Profile $actor
* @param array $options=array()
* @param array $options = []
*
* @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_
// override this function until they are migrated (this function will
@ -141,33 +149,33 @@ abstract class ActivityHandlerModule extends Module
}
/**
* Given a parsed ActivityStreams activity, your plugin gets
* to figure out itself how to store the additional data into
* the database, besides the base data stored by the core.
*
* This will handle just about all events where an activity
* object gets saved, whether it is via AtomPub, OStatus
* (WebSub and Salmon transports), or ActivityStreams-based
* backup/restore of account data.
*
* You should be able to accept as input the output from an
* asActivity() call on the stored object. Where applicable,
* try to use existing ActivityStreams structures and object
* types, and be liberal in accepting input from what might
* be other compatible apps.
*
* All micro-app classes must override this method.
*
* @fixme are there any standard options?
*
* @param Activity $activity
* @param Notice $stored The notice in our database for this certain object
* @param array $options=array()
*
* @return object If the verb handling plugin creates an object, it can be returned here (otherwise true)
* @throws exception On any error.
*/
protected function saveObjectFromActivity(Activity $activity, Notice $stored, array $options=array())
* Given a parsed ActivityStreams activity, your plugin gets
* to figure out itself how to store the additional data into
* the database, besides the base data stored by the core.
*
* This will handle just about all events where an activity
* object gets saved, whether it is via AtomPub, OStatus
* (WebSub and Salmon transports), or ActivityStreams-based
* backup/restore of account data.
*
* You should be able to accept as input the output from an
* asActivity() call on the stored object. Where applicable,
* try to use existing ActivityStreams structures and object
* types, and be liberal in accepting input from what might
* be other compatible apps.
*
* All micro-app classes must override this method.
*
* @fixme are there any standard options?
*
* @param Activity $activity
* @param Notice $stored The notice in our database for this certain object
* @param array $options = []
*
* @return object If the verb handling plugin creates an object, it can be returned here (otherwise true)
* @throws exception On any error.
*/
protected function saveObjectFromActivity(Activity $activity, Notice $stored, array $options = [])
{
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,
* 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
// Notice::saveActivity instead of Notice::saveNew
if (!$this->isMyActivity($act) || isset($this->oldSaveNew)) {
@ -208,7 +217,7 @@ abstract class ActivityHandlerModule extends Module
*
* @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
@ -218,7 +227,7 @@ abstract class ActivityHandlerModule extends Module
*
* @param Notice $notice
*/
abstract function deleteRelated(Notice $notice);
abstract public function deleteRelated(Notice $notice);
protected function notifyMentioned(Notice $stored, array &$mentioned_ids)
{
@ -242,7 +251,7 @@ abstract class ActivityHandlerModule extends Module
* @param ActivityObject $obj
* @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
}
@ -293,8 +302,8 @@ abstract class ActivityHandlerModule extends Module
}
/**
* @param Notice $stored The notice being distributed
* @param array &$mentioned_ids List of profiles (from $stored->getReplies())
* @param Notice $stored The notice being distributed
* @param array &$mentioned_ids List of profiles (from $stored->getReplies())
*/
public function onStartNotifyMentioned(Notice $stored, array &$mentioned_ids)
{
@ -308,12 +317,12 @@ abstract class ActivityHandlerModule extends Module
/**
* Render a notice as one of our objects
*
* @param Notice $notice Notice to render
* @param Notice $notice Notice to render
* @param ActivityObject &$object Empty object to fill
*
* @return boolean hook value
*/
function onStartActivityObjectFromNotice(Notice $notice, &$object)
public function onStartActivityObjectFromNotice(Notice $notice, &$object)
{
if (!$this->isMyNotice($notice)) {
return true;
@ -326,12 +335,12 @@ abstract class ActivityHandlerModule extends Module
/**
* Handle a posted object from WebSub
*
* @param Activity $activity activity to handle
* @param Profile $actor Profile for the feed
* @param Activity $activity activity to handle
* @param Profile $actor Profile for the feed
*
* @return boolean hook value
*/
function onStartHandleFeedEntryWithProfile(Activity $activity, Profile $profile, &$notice)
public function onStartHandleFeedEntryWithProfile(Activity $activity, Profile $profile, &$notice)
{
if (!$this->isMyActivity($activity)) {
return true;
@ -342,11 +351,13 @@ abstract class ActivityHandlerModule extends Module
$object = $activity->objects[0];
$options = array('uri' => $object->id,
'url' => $object->link,
'self' => $object->selfLink,
'is_local' => Notice::REMOTE,
'source' => 'ostatus');
$options = [
'uri' => $object->id,
'url' => $object->link,
'self' => $object->selfLink,
'is_local' => Notice::REMOTE,
'source' => 'ostatus',
];
if (!isset($this->oldSaveNew)) {
$notice = Notice::saveActivity($activity, $profile, $options);
@ -361,12 +372,12 @@ abstract class ActivityHandlerModule extends Module
* Handle a posted object from Salmon
*
* @param Activity $activity activity to handle
* @param mixed $target user or group targeted
* @param mixed $target user or group targeted
*
* @return boolean hook value
*/
function onStartHandleSalmonTarget(Activity $activity, $target)
public function onStartHandleSalmonTarget(Activity $activity, $target)
{
if (!$this->isMyActivity($activity)) {
return true;
@ -377,7 +388,7 @@ abstract class ActivityHandlerModule extends Module
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()) {
$uri = $target->getUri();
@ -399,7 +410,7 @@ abstract class ActivityHandlerModule extends Module
$original = Notice::getKV('uri', $activity->context->replyToID);
}
if ((!$original instanceof Notice || $original->profile_id != $target->id)
&& !array_key_exists($target->getUri(), $activity->context->attention)) {
&& !array_key_exists($target->getUri(), $activity->context->attention)) {
// @todo FIXME: Please document (i18n).
// TRANS: Client exception when ...
throw new ClientException(_('Object not posted to this user.'));
@ -419,11 +430,13 @@ abstract class ActivityHandlerModule extends Module
$object = $activity;
}
$options = array('uri' => $object->id,
'url' => $object->link,
'self' => $object->selfLink,
'is_local' => Notice::REMOTE,
'source' => 'ostatus');
$options = [
'uri' => $object->id,
'url' => $object->link,
'self' => $object->selfLink,
'is_local' => Notice::REMOTE,
'source' => 'ostatus',
];
$notice = $this->saveNoticeFromActivity($activity, $actor, $options);
@ -433,13 +446,13 @@ abstract class ActivityHandlerModule extends Module
/**
* Handle object posted via AtomPub
*
* @param Activity $activity Activity that was posted
* @param Profile $scoped Profile of user posting
* @param Notice &$notice Resulting notice
* @param Activity $activity Activity that was posted
* @param Profile $scoped Profile of user posting
* @param Notice &$notice Resulting notice
*
* @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)) {
return true;
@ -455,15 +468,15 @@ abstract class ActivityHandlerModule extends Module
/**
* Handle object imported from a backup file
*
* @param User $user User to import for
* @param ActivityObject $author Original author per import file
* @param Activity $activity Activity to import
* @param boolean $trusted Is this a trusted user?
* @param boolean &$done Is this done (success or unrecoverable error)
* @param User $user User to import for
* @param ActivityObject $author Original author per import file
* @param Activity $activity Activity to import
* @param boolean $trusted Is this a trusted user?
* @param boolean &$done Is this done (success or unrecoverable error)
*
* @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)) {
return true;
@ -471,15 +484,19 @@ abstract class ActivityHandlerModule extends Module
$obj = $activity->objects[0];
$options = array('uri' => $object->id,
'url' => $object->link,
'self' => $object->selfLink,
'source' => 'restore');
$options = [
'uri' => $object->id,
'url' => $object->link,
'self' => $object->selfLink,
'source' => 'restore',
];
// $user->getProfile() is a Profile
$saved = $this->saveNoticeFromActivity($activity,
$user->getProfile(),
$options);
$saved = $this->saveNoticeFromActivity(
$activity,
$user->getProfile(),
$options
);
if (!empty($saved)) {
$done = true;
@ -500,7 +517,7 @@ abstract class ActivityHandlerModule extends Module
* @param XMLOutputter $out to add elements at end of object
* @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())) {
$this->activityObjectOutputAtom($obj, $out);
@ -520,7 +537,7 @@ abstract class ActivityHandlerModule extends Module
* @param array &$out JSON-targeted array which can be modified
* @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())) {
$this->activityObjectOutputJson($obj, $out);
@ -529,26 +546,26 @@ abstract class ActivityHandlerModule extends Module
}
public function onStartOpenNoticeListItemElement(NoticeListItem $nli)
{
{
if (!$this->isMyNotice($nli->notice)) {
return true;
}
$this->openNoticeListItemElement($nli);
Event::handle('EndOpenNoticeListItemElement', array($nli));
Event::handle('EndOpenNoticeListItemElement', [$nli]);
return false;
}
public function onStartCloseNoticeListItemElement(NoticeListItem $nli)
{
{
if (!$this->isMyNotice($nli->notice)) {
return true;
}
$this->closeNoticeListItemElement($nli);
Event::handle('EndCloseNoticeListItemElement', array($nli));
Event::handle('EndCloseNoticeListItemElement', [$nli]);
return false;
}
@ -560,12 +577,14 @@ abstract class ActivityHandlerModule extends Module
$class .= ' limited-scope';
}
try {
$class .= ' notice-source-'.common_to_alphanumeric($nli->notice->source);
$class .= ' notice-source-' . common_to_alphanumeric($nli->notice->source);
} catch (Exception $e) {
// either source or what we filtered out was a zero-length string
}
$nli->out->elementStart('li', array('class' => $class,
'id' => 'notice-' . $id));
$nli->out->elementStart(
'li',
['class' => $class, 'id' => 'notice-' . $id]
);
}
protected function closeNoticeListItemElement(NoticeListItem $nli)
@ -576,7 +595,7 @@ abstract class ActivityHandlerModule extends Module
// FIXME: This is overriden in MicroAppPlugin but shouldn't have to be
public function onStartShowNoticeItem(NoticeListItem $nli)
{
{
if (!$this->isMyNotice($nli->notice)) {
return true;
}
@ -584,7 +603,7 @@ abstract class ActivityHandlerModule extends Module
try {
$this->showNoticeListItem($nli);
} 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()));
}
@ -619,7 +638,7 @@ abstract class ActivityHandlerModule extends Module
$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)) {
return true;
@ -633,7 +652,7 @@ abstract class ActivityHandlerModule extends Module
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());
}

View File

@ -1,23 +1,20 @@
<?php
/*
* GNU Social - a federating social network
* Copyright (C) 2014, Free Software Foundation, 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/>.
*/
// 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();
/**
* Superclass for plugins which add Activity types and such
@ -25,20 +22,19 @@ if (!defined('GNUSOCIAL')) { exit(1); }
* @category Activity
* @package GNUsocial
* @author Mikael Nordfeldth <mmn@hethane.se>
* @copyright 2014 Free Software Foundation, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://gnu.io/social
* @copyright 2014 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
abstract class ActivityHandlerPlugin extends Plugin
{
/**
/**
* Returns a key string which represents this activity in HTML classes,
* ids etc, as when offering selection of what type of post to make.
* In MicroAppPlugin, this is paired with the user-visible localizable appTitle().
* ids etc, as when offering selection of what type of post to make.
* In MicroAppPlugin, this is paired with the user-visible localizable appTitle().
*
* @return string (compatible with HTML classes)
*/
abstract function tag();
*/
abstract public function tag();
/**
* Return a list of ActivityStreams object type IRIs
@ -51,7 +47,7 @@ abstract class ActivityHandlerPlugin extends Plugin
*
* @return array of strings
*/
abstract function types();
abstract public function types();
/**
* Return a list of ActivityStreams verb IRIs which
@ -64,7 +60,8 @@ abstract class ActivityHandlerPlugin extends Plugin
*
* @return array of strings
*/
public function verbs() {
public function verbs()
{
return array(ActivityVerb::POST);
}
@ -80,7 +77,8 @@ abstract class ActivityHandlerPlugin extends Plugin
* @param Activity $activity
* @return boolean
*/
function isMyActivity(Activity $act) {
public function isMyActivity(Activity $act)
{
return (count($act->objects) == 1
&& ($act->objects[0] instanceof ActivityObject)
&& $this->isMyVerb($act->verb)
@ -98,18 +96,21 @@ abstract class ActivityHandlerPlugin extends Plugin
* @param Notice $notice
* @return boolean
*/
function isMyNotice(Notice $notice) {
public function isMyNotice(Notice $notice)
{
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
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)
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 Profile $actor
* @param array $options=array()
* @param array $options =array()
*
* @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_
// override this function until they are migrated (this function will
@ -141,33 +142,33 @@ abstract class ActivityHandlerPlugin extends Plugin
}
/**
* Given a parsed ActivityStreams activity, your plugin gets
* to figure out itself how to store the additional data into
* the database, besides the base data stored by the core.
*
* This will handle just about all events where an activity
* object gets saved, whether it is via AtomPub, OStatus
* (WebSub and Salmon transports), or ActivityStreams-based
* backup/restore of account data.
*
* You should be able to accept as input the output from an
* asActivity() call on the stored object. Where applicable,
* try to use existing ActivityStreams structures and object
* types, and be liberal in accepting input from what might
* be other compatible apps.
*
* All micro-app classes must override this method.
*
* @fixme are there any standard options?
*
* @param Activity $activity
* @param Notice $stored The notice in our database for this certain object
* @param array $options=array()
*
* @return object If the verb handling plugin creates an object, it can be returned here (otherwise true)
* @throws exception On any error.
*/
protected function saveObjectFromActivity(Activity $activity, Notice $stored, array $options=array())
* Given a parsed ActivityStreams activity, your plugin gets
* to figure out itself how to store the additional data into
* the database, besides the base data stored by the core.
*
* This will handle just about all events where an activity
* object gets saved, whether it is via AtomPub, OStatus
* (WebSub and Salmon transports), or ActivityStreams-based
* backup/restore of account data.
*
* You should be able to accept as input the output from an
* asActivity() call on the stored object. Where applicable,
* try to use existing ActivityStreams structures and object
* types, and be liberal in accepting input from what might
* be other compatible apps.
*
* All micro-app classes must override this method.
*
* @fixme are there any standard options?
*
* @param Activity $activity
* @param Notice $stored The notice in our database for this certain object
* @param array $options =array()
*
* @return object If the verb handling plugin creates an object, it can be returned here (otherwise true)
* @throws exception On any error.
*/
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');
}
@ -176,7 +177,8 @@ abstract class ActivityHandlerPlugin extends Plugin
* 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.
*/
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
// Notice::saveActivity instead of Notice::saveNew
if (!$this->isMyActivity($act) || isset($this->oldSaveNew)) {
@ -208,7 +210,7 @@ abstract class ActivityHandlerPlugin extends Plugin
*
* @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
@ -218,7 +220,7 @@ abstract class ActivityHandlerPlugin extends Plugin
*
* @param Notice $notice
*/
abstract function deleteRelated(Notice $notice);
abstract public function deleteRelated(Notice $notice);
protected function notifyMentioned(Notice $stored, array &$mentioned_ids)
{
@ -242,7 +244,7 @@ abstract class ActivityHandlerPlugin extends Plugin
* @param ActivityObject $obj
* @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
}
@ -293,8 +295,8 @@ abstract class ActivityHandlerPlugin extends Plugin
}
/**
* @param Notice $stored The notice being distributed
* @param array &$mentioned_ids List of profiles (from $stored->getReplies())
* @param Notice $stored The notice being distributed
* @param array &$mentioned_ids List of profiles (from $stored->getReplies())
*/
public function onStartNotifyMentioned(Notice $stored, array &$mentioned_ids)
{
@ -308,12 +310,12 @@ abstract class ActivityHandlerPlugin extends Plugin
/**
* Render a notice as one of our objects
*
* @param Notice $notice Notice to render
* @param Notice $notice Notice to render
* @param ActivityObject &$object Empty object to fill
*
* @return boolean hook value
*/
function onStartActivityObjectFromNotice(Notice $notice, &$object)
public function onStartActivityObjectFromNotice(Notice $notice, &$object)
{
if (!$this->isMyNotice($notice)) {
return true;
@ -326,12 +328,12 @@ abstract class ActivityHandlerPlugin extends Plugin
/**
* Handle a posted object from WebSub
*
* @param Activity $activity activity to handle
* @param Profile $actor Profile for the feed
* @param Activity $activity activity to handle
* @param Profile $actor Profile for the feed
*
* @return boolean hook value
*/
function onStartHandleFeedEntryWithProfile(Activity $activity, Profile $profile, &$notice)
public function onStartHandleFeedEntryWithProfile(Activity $activity, Profile $profile, &$notice)
{
if (!$this->isMyActivity($activity)) {
return true;
@ -342,11 +344,13 @@ abstract class ActivityHandlerPlugin extends Plugin
$object = $activity->objects[0];
$options = array('uri' => $object->id,
'url' => $object->link,
'self' => $object->selfLink,
'is_local' => Notice::REMOTE,
'source' => 'ostatus');
$options = [
'uri' => $object->id,
'url' => $object->link,
'self' => $object->selfLink,
'is_local' => Notice::REMOTE,
'source' => 'ostatus',
];
if (!isset($this->oldSaveNew)) {
$notice = Notice::saveActivity($activity, $profile, $options);
@ -361,12 +365,12 @@ abstract class ActivityHandlerPlugin extends Plugin
* Handle a posted object from Salmon
*
* @param Activity $activity activity to handle
* @param mixed $target user or group targeted
* @param mixed $target user or group targeted
*
* @return boolean hook value
*/
function onStartHandleSalmonTarget(Activity $activity, $target)
public function onStartHandleSalmonTarget(Activity $activity, $target)
{
if (!$this->isMyActivity($activity)) {
return true;
@ -377,7 +381,7 @@ abstract class ActivityHandlerPlugin extends Plugin
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()) {
$uri = $target->getUri();
@ -399,7 +403,7 @@ abstract class ActivityHandlerPlugin extends Plugin
$original = Notice::getKV('uri', $activity->context->replyToID);
}
if ((!$original instanceof Notice || $original->profile_id != $target->id)
&& !array_key_exists($target->getUri(), $activity->context->attention)) {
&& !array_key_exists($target->getUri(), $activity->context->attention)) {
// @todo FIXME: Please document (i18n).
// TRANS: Client exception when ...
throw new ClientException(_('Object not posted to this user.'));
@ -419,11 +423,13 @@ abstract class ActivityHandlerPlugin extends Plugin
$object = $activity;
}
$options = array('uri' => $object->id,
'url' => $object->link,
'self' => $object->selfLink,
'is_local' => Notice::REMOTE,
'source' => 'ostatus');
$options = [
'uri' => $object->id,
'url' => $object->link,
'self' => $object->selfLink,
'is_local' => Notice::REMOTE,
'source' => 'ostatus',
];
$notice = $this->saveNoticeFromActivity($activity, $actor, $options);
@ -433,13 +439,13 @@ abstract class ActivityHandlerPlugin extends Plugin
/**
* Handle object posted via AtomPub
*
* @param Activity $activity Activity that was posted
* @param Profile $scoped Profile of user posting
* @param Notice &$notice Resulting notice
* @param Activity $activity Activity that was posted
* @param Profile $scoped Profile of user posting
* @param Notice &$notice Resulting notice
*
* @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)) {
return true;
@ -455,15 +461,15 @@ abstract class ActivityHandlerPlugin extends Plugin
/**
* Handle object imported from a backup file
*
* @param User $user User to import for
* @param ActivityObject $author Original author per import file
* @param Activity $activity Activity to import
* @param boolean $trusted Is this a trusted user?
* @param boolean &$done Is this done (success or unrecoverable error)
* @param User $user User to import for
* @param ActivityObject $author Original author per import file
* @param Activity $activity Activity to import
* @param boolean $trusted Is this a trusted user?
* @param boolean &$done Is this done (success or unrecoverable error)
*
* @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)) {
return true;
@ -471,15 +477,19 @@ abstract class ActivityHandlerPlugin extends Plugin
$obj = $activity->objects[0];
$options = array('uri' => $object->id,
'url' => $object->link,
'self' => $object->selfLink,
'source' => 'restore');
$options = [
'uri' => $object->id,
'url' => $object->link,
'self' => $object->selfLink,
'source' => 'restore',
];
// $user->getProfile() is a Profile
$saved = $this->saveNoticeFromActivity($activity,
$user->getProfile(),
$options);
$saved = $this->saveNoticeFromActivity(
$activity,
$user->getProfile(),
$options
);
if (!empty($saved)) {
$done = true;
@ -500,7 +510,7 @@ abstract class ActivityHandlerPlugin extends Plugin
* @param XMLOutputter $out to add elements at end of object
* @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())) {
$this->activityObjectOutputAtom($obj, $out);
@ -520,7 +530,7 @@ abstract class ActivityHandlerPlugin extends Plugin
* @param array &$out JSON-targeted array which can be modified
* @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())) {
$this->activityObjectOutputJson($obj, $out);
@ -529,26 +539,26 @@ abstract class ActivityHandlerPlugin extends Plugin
}
public function onStartOpenNoticeListItemElement(NoticeListItem $nli)
{
{
if (!$this->isMyNotice($nli->notice)) {
return true;
}
$this->openNoticeListItemElement($nli);
Event::handle('EndOpenNoticeListItemElement', array($nli));
Event::handle('EndOpenNoticeListItemElement', [$nli]);
return false;
}
public function onStartCloseNoticeListItemElement(NoticeListItem $nli)
{
{
if (!$this->isMyNotice($nli->notice)) {
return true;
}
$this->closeNoticeListItemElement($nli);
Event::handle('EndCloseNoticeListItemElement', array($nli));
Event::handle('EndCloseNoticeListItemElement', [$nli]);
return false;
}
@ -560,12 +570,12 @@ abstract class ActivityHandlerPlugin extends Plugin
$class .= ' limited-scope';
}
try {
$class .= ' notice-source-'.common_to_alphanumeric($nli->notice->source);
$class .= ' notice-source-' . common_to_alphanumeric($nli->notice->source);
} catch (Exception $e) {
// either source or what we filtered out was a zero-length string
}
$nli->out->elementStart('li', array('class' => $class,
'id' => 'notice-' . $id));
'id' => 'notice-' . $id));
}
protected function closeNoticeListItemElement(NoticeListItem $nli)
@ -576,7 +586,7 @@ abstract class ActivityHandlerPlugin extends Plugin
// FIXME: This is overriden in MicroAppPlugin but shouldn't have to be
public function onStartShowNoticeItem(NoticeListItem $nli)
{
{
if (!$this->isMyNotice($nli->notice)) {
return true;
}
@ -584,7 +594,7 @@ abstract class ActivityHandlerPlugin extends Plugin
try {
$this->showNoticeListItem($nli);
} 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()));
}
@ -619,7 +629,7 @@ abstract class ActivityHandlerPlugin extends Plugin
$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)) {
return true;
@ -633,7 +643,7 @@ abstract class ActivityHandlerPlugin extends Plugin
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());
}

View File

@ -1,51 +1,48 @@
<?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
*
* 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
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
/**
* Notice stream for a conversation
*
* @category Stream
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class ConversationNoticeStream extends ScopingNoticeStream
{
function __construct($id, Profile $scoped=null)
public function __construct($id, Profile $scoped = null)
{
parent::__construct(new RawConversationNoticeStream($id),
$scoped);
parent::__construct(
new RawConversationNoticeStream($id),
$scoped
);
}
}
@ -53,23 +50,22 @@ class ConversationNoticeStream extends ScopingNoticeStream
* Notice stream for a conversation
*
* @category Stream
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class RawConversationNoticeStream extends NoticeStream
{
protected $id;
function __construct($id)
public function __construct($id)
{
parent::__construct();
$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();
// SELECT

View File

@ -1,34 +1,30 @@
<?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
*
* 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
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2010 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
/**
* widget for displaying a single notice
@ -39,24 +35,23 @@ if (!defined('GNUSOCIAL')) { exit(1); }
* ProfileNoticeListItem subclass, for example, overrides showAuthor() to skip
* author info (since that's implicit by the data in the page).
*
* @category UI
* @package StatusNet
* @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
* @link http://status.net/
* @see NoticeList
* @see ProfileNoticeListItem
* @category UI
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @see NoticeList
* @see ProfileNoticeListItem
*/
class NoticeListItem extends Widget
{
/** The notice this item will show. */
var $notice = null;
public $notice = null;
/** The notice that was repeated. */
var $repeat = null;
public $repeat = null;
/** The profile of the author of the notice, extracted once for convenience. */
var $profile = null;
public $profile = null;
protected $addressees = true;
protected $attachments = true;
@ -72,8 +67,10 @@ class NoticeListItem extends Widget
* Also initializes the profile attribute.
*
* @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);
if (!empty($notice->repeat_of)) {
@ -85,25 +82,25 @@ class NoticeListItem extends Widget
$this->repeat = $notice;
}
} else {
$this->notice = $notice;
$this->notice = $notice;
}
$this->profile = $this->notice->getProfile();
// integer preferences
foreach(array('maxchars') as $key) {
foreach (['maxchars'] as $key) {
if (array_key_exists($key, $prefs)) {
$this->$key = (int)$prefs[$key];
}
}
// boolean preferences
foreach(array('addressees', 'attachments', 'options') as $key) {
foreach (['addressees', 'attachments', 'options'] as $key) {
if (array_key_exists($key, $prefs)) {
$this->$key = (bool)$prefs[$key];
}
}
// string preferences
foreach(array('id_prefix', 'item_tag') as $key) {
foreach (['id_prefix', 'item_tag'] as $key) {
if (array_key_exists($key, $prefs)) {
$this->$key = $prefs[$key];
}
@ -118,12 +115,12 @@ class NoticeListItem extends Widget
*
* @return void
*/
function show()
public function show()
{
if (empty($this->notice)) {
common_log(LOG_WARNING, "Trying to show missing notice; skipping.");
return;
} else if (empty($this->profile)) {
} elseif (empty($this->profile)) {
common_log(LOG_WARNING, "Trying to show missing profile (" . $this->notice->profile_id . "); skipping.");
return;
}
@ -136,7 +133,7 @@ class NoticeListItem extends Widget
$this->showEnd();
}
function showNotice()
public function showNotice()
{
if (Event::handle('StartShowNoticeItemNotice', array($this))) {
$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->showAuthor();
@ -161,33 +158,44 @@ class NoticeListItem extends Widget
} catch (InvalidUrlException $e) {
// 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('section');
}
function showNoticeFooter()
public function showNoticeFooter()
{
$this->elementStart('footer');
$this->showNoticeInfo();
if ($this->options) { $this->showNoticeOptions(); }
if ($this->attachments) { $this->showNoticeAttachments(); }
if ($this->options) {
$this->showNoticeOptions();
}
if ($this->attachments) {
$this->showNoticeAttachments();
}
$this->elementEnd('footer');
}
function showNoticeTitle()
public function showNoticeTitle()
{
if (Event::handle('StartShowNoticeTitle', array($this))) {
$nameClass = $this->notice->getTitle(false) ? 'p-name ' : '';
$this->element('a', array('href' => $this->notice->getUri(),
'class' => $nameClass . 'u-uid'),
$this->notice->getTitle());
$this->element(
'a',
[
'href' => $this->notice->getUri(),
'class' => $nameClass . 'u-uid',
],
$this->notice->getTitle()
);
Event::handle('EndShowNoticeTitle', array($this));
}
}
function showNoticeInfo()
public function showNoticeInfo()
{
if (Event::handle('StartShowNoticeInfo', array($this))) {
$this->showContextLink();
@ -199,7 +207,7 @@ class NoticeListItem extends Widget
}
}
function showNoticeOptions()
public function showNoticeOptions()
{
if (Event::handle('StartShowNoticeOptions', array($this))) {
$user = common_current_user();
@ -221,23 +229,28 @@ class NoticeListItem extends Widget
*
* @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;
$class = 'h-entry notice';
if ($this->notice->scope != 0 && $this->notice->scope != 1) {
$class .= ' limited-scope';
}
try {
$class .= ' notice-source-'.common_to_alphanumeric($this->notice->source);
$class .= ' notice-source-' . common_to_alphanumeric($this->notice->source);
} catch (Exception $e) {
// either source or what we filtered out was a zero-length string
}
$id_prefix = (strlen($this->id_prefix) ? $this->id_prefix . '-' : '');
$this->out->elementStart($this->item_tag, array('class' => $class,
'id' => "${id_prefix}notice-${id}"));
Event::handle('EndOpenNoticeListItemElement', array($this));
$this->out->elementStart(
$this->item_tag,
[
'class' => $class,
'id' => "${id_prefix}notice-${id}",
]
);
Event::handle('EndOpenNoticeListItemElement', [$this]);
}
}
@ -249,12 +262,16 @@ class NoticeListItem extends Widget
* @return void
*/
function showAuthor()
public function showAuthor()
{
$attrs = array('href' => $this->profile->getUrl(),
'class' => 'h-card',
'title' => $this->profile->getHtmlTitle());
if(empty($this->repeat)) { $attrs['class'] .= ' p-author'; }
$attrs = [
'href' => $this->profile->getUrl(),
'class' => 'h-card',
'title' => $this->profile->getHtmlTitle(),
];
if (empty($this->repeat)) {
$attrs['class'] .= ' p-author';
}
if (Event::handle('StartShowNoticeItemAuthor', array($this->profile, $this->out, &$attrs))) {
$this->out->elementStart('a', $attrs);
@ -265,7 +282,7 @@ class NoticeListItem extends Widget
}
}
function showParent()
public function showParent()
{
$this->out->element(
'a',
@ -278,7 +295,7 @@ class NoticeListItem extends Widget
);
}
function showAddressees()
public function showAddressees()
{
$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();
$attentions = $this->getAttentionProfiles();
@ -311,16 +330,18 @@ class NoticeListItem extends Widget
$class = 'account';
$profileurl = common_local_url('userbyid', array('id' => $attn->getID()));
}
$this->pa[] = array('href' => $profileurl,
'title' => $attn->getHtmlTitle(),
'class' => "addressee {$class} p-name u-url",
'text' => $attn->getStreamName());
$this->pa[] = [
'href' => $profileurl,
'title' => $attn->getHtmlTitle(),
'class' => "addressee {$class} p-name u-url",
'text' => $attn->getStreamName(),
];
}
return $this->pa;
}
function getAttentionProfiles()
public function getAttentionProfiles()
{
return $this->notice->getAttentionProfiles();
}
@ -332,11 +353,13 @@ class NoticeListItem extends Widget
*
* @return void
*/
function showNickname()
public function showNickname()
{
$this->out->raw('<span class="p-name">' .
htmlspecialchars($this->profile->getNickname()) .
'</span>');
$this->out->raw(
'<span class="p-name">' .
htmlspecialchars($this->profile->getNickname()) .
'</span>'
);
}
/**
@ -348,7 +371,7 @@ class NoticeListItem extends Widget
*
* @return void
*/
function showContent()
public function showContent()
{
// FIXME: URL, image, video, audio
$nameClass = $this->notice->getTitle(false) ? '' : 'p-name ';
@ -364,7 +387,8 @@ class NoticeListItem extends Widget
$this->out->elementEnd('article');
}
function showNoticeAttachments() {
public function showNoticeAttachments()
{
if (common_config('attachments', 'show_thumbs')) {
$al = new InlineAttachmentList($this->notice, $this->out);
$al->show();
@ -378,12 +402,17 @@ class NoticeListItem extends Widget
*
* @return void
*/
function showNoticeLink()
public function showNoticeLink()
{
$this->out->element('time', array('class' => 'dt-published',
'datetime' => common_date_iso8601($this->notice->created),
'title' => common_exact_date($this->notice->created)),
common_date_string($this->notice->created));
$this->out->element(
'time',
[
'class' => 'dt-published',
'datetime' => common_date_iso8601($this->notice->created),
'title' => common_exact_date($this->notice->created),
],
common_date_string($this->notice->created)
);
}
/**
@ -395,7 +424,7 @@ class NoticeListItem extends Widget
*
* @return void
*/
function showNoticeLocation()
public function showNoticeLocation()
{
try {
$location = Notice_location::locFromStored($this->notice);
@ -409,7 +438,7 @@ class NoticeListItem extends Widget
$lat = $location->lat;
$lon = $location->lon;
$latlon = (!empty($lat) && !empty($lon)) ? $lat.';'.$lon : '';
$latlon = (!empty($lat) && !empty($lon)) ? $lat . ';' . $lon : '';
if (empty($name)) {
$latdms = $this->decimalDegreesToDMS(abs($lat));
@ -429,11 +458,18 @@ class NoticeListItem extends Widget
// 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,
_('%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),
$londms['deg'],$londms['min'], $londms['sec'],($lon>0? $east:$west));
$latdms['deg'],
$latdms['min'],
$latdms['sec'],
($lat > 0 ? $north : $south),
$londms['deg'],
$londms['min'],
$londms['sec'],
($lon > 0 ? $east : $west)
);
}
$url = $location->getUrl();
$url = $location->getUrl();
$this->out->text(' ');
$this->out->elementStart('span', array('class' => 'location'));
@ -441,16 +477,25 @@ class NoticeListItem extends Widget
$this->out->text(_('at'));
$this->out->text(' ');
if (empty($url)) {
$this->out->element('abbr', array('class' => 'geo',
'title' => $latlon),
$name);
$this->out->element(
'abbr',
[
'class' => 'geo',
'title' => $latlon,
],
$name
);
} else {
$xstr = new XMLStringer(false);
$xstr->elementStart('a', array('href' => $url,
'rel' => 'external'));
$xstr->element('abbr', array('class' => 'geo',
'title' => $latlon),
$name);
$xstr->elementStart(
'a',
['href' => $url, 'rel' => 'external']
);
$xstr->element(
'abbr',
['class' => 'geo', 'title' => $latlon],
$name
);
$xstr->elementEnd('a');
$this->out->raw($xstr->getString());
}
@ -461,16 +506,16 @@ class NoticeListItem extends Widget
* @param number $dec decimal degrees
* @return array split into 'deg', 'min', and 'sec'
*/
function decimalDegreesToDMS($dec)
public function decimalDegreesToDMS($dec)
{
$deg = intval($dec);
$tempma = abs($dec) - abs($deg);
$tempma = $tempma * 3600;
$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.
*
* @return void
* @throws Exception
*/
function showNoticeSource()
public function showNoticeSource()
{
$ns = $this->notice->getSource();
if (!$ns instanceof Notice_source) {
return false;
return;
}
// 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->elementStart('span', 'source');
// @todo FIXME: probably i18n issue. If "from" is followed by text, that should be a parameter to "from" (from %s).
@ -498,13 +544,13 @@ class NoticeListItem extends Widget
$this->out->text(_('from'));
$this->out->text(' ');
$name = $source_name;
$url = $ns->url;
$name = $source_name;
$url = $ns->url;
$title = null;
if (Event::handle('StartNoticeSourceLink', array($this->notice, &$name, &$url, &$title))) {
$name = $source_name;
$url = $ns->url;
$url = $ns->url;
}
Event::handle('EndNoticeSourceLink', array($this->notice, &$name, &$url, &$title));
@ -538,7 +584,7 @@ class NoticeListItem extends Widget
*
* @return void
*/
function showPermalink()
public function showPermalink()
{
$class = 'permalink u-url';
if (!$this->notice->isLocal()) {
@ -546,11 +592,15 @@ class NoticeListItem extends Widget
}
try {
if($this->repeat) {
$this->out->element('a',
array('href' => $this->repeat->getUrl(),
'class' => 'u-url'),
'');
if ($this->repeat) {
$this->out->element(
'a',
[
'href' => $this->repeat->getUrl(),
'class' => 'u-url',
],
''
);
$class = str_replace('u-url', 'u-repost-of', $class);
}
} catch (InvalidUrlException $e) {
@ -558,11 +608,15 @@ class NoticeListItem extends Widget
}
try {
$this->out->element('a',
array('href' => $this->notice->getUrl(true),
'class' => $class),
// TRANS: Addition in notice list item for single-notice view.
_('permalink'));
$this->out->element(
'a',
[
'href' => $this->notice->getUrl(true),
'class' => $class,
],
// TRANS: Addition in notice list item for single-notice view.
_('permalink')
);
} catch (InvalidUrlException $e) {
// no permalink available
}
@ -571,13 +625,18 @@ class NoticeListItem extends Widget
/**
* Show link to conversation view.
*/
function showContextLink()
public function showContextLink()
{
$this->out->element('a', array('rel' => 'bookmark',
'class' => 'timestamp',
'href' => Conversation::getUrlFromNotice($this->notice)),
// TRANS: A link to the conversation view of a notice, on the local server.
_('In conversation'));
$this->out->element(
'a',
[
'rel' => 'bookmark',
'class' => 'timestamp',
'href' => Conversation::getUrlFromNotice($this->notice),
],
// TRANS: A link to the conversation view of a notice, on the local server.
_('In conversation')
);
}
/**
@ -588,16 +647,26 @@ class NoticeListItem extends Widget
*
* @return void
*/
function showReplyLink()
public function showReplyLink()
{
if (common_logged_in()) {
$this->out->text(' ');
$reply_url = common_local_url('newnotice',
array('replyto' => $this->profile->getNickname(), 'inreplyto' => $this->notice->id));
$this->out->elementStart('a', array('href' => $reply_url,
'class' => 'notice_reply',
// TRANS: Link title in notice list item to reply to a notice.
'title' => _('Reply to this notice.')));
$reply_url = common_local_url(
'newnotice',
[
'replyto' => $this->profile->getNickname(),
'inreplyto' => $this->notice->id,
]
);
$this->out->elementStart(
'a',
[
'href' => $reply_url,
'class' => 'notice_reply',
// TRANS: Link title in notice list item to reply to a notice.
'title' => _('Reply to this notice.'),
]
);
// TRANS: Link text in notice list item to reply to a notice.
$this->out->text(_('Reply'));
$this->out->text(' ');
@ -610,8 +679,9 @@ class NoticeListItem extends Widget
* if the user is the author, let them delete the notice
*
* @return void
* @throws Exception
*/
function showDeleteLink()
public function showDeleteLink()
{
$user = common_current_user();
@ -621,14 +691,21 @@ class NoticeListItem extends Widget
!$this->notice->isVerb([ActivityVerb::DELETE]) &&
($todel->profile_id == $user->id || $user->hasRight(Right::DELETEOTHERSNOTICE))) {
$this->out->text(' ');
$deleteurl = common_local_url('deletenotice',
array('notice' => $todel->id));
$this->out->element('a', array('href' => $deleteurl,
'class' => 'notice_delete popup',
// TRANS: Link title in notice list item to delete a notice.
'title' => _('Delete this notice from the timeline.')),
// TRANS: Link text in notice list item to delete a notice.
_('Delete'));
$deleteurl = common_local_url(
'deletenotice',
['notice' => $todel->id]
);
$this->out->element(
'a',
[
'href' => $deleteurl,
'class' => 'notice_delete popup',
// TRANS: Link title in notice list item to delete a notice.
'title' => _m('Delete this notice from the timeline.'),
],
// TRANS: Link text in notice list item to delete a notice.
_m('Delete')
);
}
}
@ -639,11 +716,11 @@ class NoticeListItem extends Widget
*
* @return void
*/
function showEnd()
public function showEnd()
{
if (Event::handle('StartCloseNoticeListItemElement', array($this))) {
if (Event::handle('StartCloseNoticeListItemElement', [$this])) {
$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
*/
function getNotice()
public function getNotice()
{
return $this->notice;
}

View File

@ -1,76 +1,71 @@
<?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
*
* 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
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
/**
* Class for notice streams
*
* @category Stream
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
abstract class NoticeStream
{
protected $selectVerbs = array(ActivityVerb::POST => true,
ActivityVerb::SHARE => true);
protected $selectVerbs = [
ActivityVerb::POST => true,
ActivityVerb::SHARE => true,
];
public function __construct()
{
foreach ($this->selectVerbs as $key=>$val) {
foreach ($this->selectVerbs as $key => $val) {
$this->selectVerbs[ActivityUtils::resolveUri($key)] = $val;
// to avoid database inconsistency issues we can select both relative and absolute verbs
//$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);
$notices = self::getStreamByIds($ids);
return $notices;
return self::getStreamByIds($ids);
}
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));
if (!empty($filter)) {
@ -78,7 +73,9 @@ abstract class NoticeStream
$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)) {
// exclude verbs in selectVerbs with values that equate to false
$notice->whereAddIn('!verb', $filter, $notice->columnType('verb'));

View File

@ -1,9 +1,23 @@
<?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,
* where, and under which circumstances. Its key method is show(); this is a recipe
@ -11,25 +25,24 @@ if (!defined('GNUSOCIAL')) { exit(1); }
* ProfileNoticeListItem subclass, for example, overrides showAuthor() to skip
* author info (since that's implicit by the data in the page).
*
* @category UI
* @package StatusNet
* @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
* @link http://status.net/
* @see NoticeList
* @see ProfileNoticeListItem
* @category UI
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @see NoticeList
* @see ProfileNoticeListItem
*/
class ThreadedNoticeListItem extends NoticeListItem
{
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);
$this->userProfile = $profile;
}
function initialItems()
public function initialItems()
{
return 3;
}
@ -41,17 +54,17 @@ class ThreadedNoticeListItem extends NoticeListItem
*
* @return void
*/
function showEnd()
public function showEnd()
{
$max = $this->initialItems();
if (!$this->repeat instanceof Notice) {
$stream = new ConversationNoticeStream($this->notice->conversation, $this->userProfile);
$notice = $stream->getNotices(0, $max + 2);
$notices = array();
$notices = [];
$cnt = 0;
$moreCutoff = null;
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
if (!empty($notice->repeat_of)) {
continue;
@ -69,11 +82,11 @@ class ThreadedNoticeListItem extends NoticeListItem
$cnt++;
if ($cnt > $max) {
// boo-yah
$moreCutoff = clone($notice);
$moreCutoff = clone $notice;
break;
}
$notices[] = clone($notice); // *grumble* inefficient as hell
Event::handle('EndAddNoticeReply', array($this, $this->notice, $notice));
$notices[] = clone $notice; // *grumble* inefficient as hell
Event::handle('EndAddNoticeReply', [$this, $this->notice, $notice]);
}
}
@ -87,7 +100,7 @@ class ThreadedNoticeListItem extends NoticeListItem
Event::handle('EndShowThreadedNoticeTailItems', array($this, $this->notice, &$threadActive));
}
if (count($notices)>0) {
if (count($notices) > 0) {
if ($moreCutoff) {
$item = new ThreadedNoticeListMoreItem($moreCutoff, $this->out, count($notices));
$item->show();