[ConversationTree] Format the plugin, add strict typing and fix docblocks
This commit is contained in:
parent
76609d8f37
commit
68db757269
|
@ -1,47 +1,54 @@
|
||||||
<?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); }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @package UI
|
* The ConversationTree plugin displays conversation replies in a hierarchical
|
||||||
* @maintainer Mikael Nordfeldth <mmn@hethane.se>
|
* manner like StatusNet pre-v1.0 used to.
|
||||||
|
*
|
||||||
|
* @category UI
|
||||||
|
* @package ConversationTreePlugin
|
||||||
|
* @author Mikael Nordfeldth <mmn@hethane.se>
|
||||||
|
* @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
|
||||||
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
defined('GNUSOCIAL') || die();
|
||||||
|
|
||||||
class ConversationTreePlugin extends Plugin
|
class ConversationTreePlugin extends Plugin
|
||||||
{
|
{
|
||||||
const PLUGIN_VERSION = '2.0.0';
|
const PLUGIN_VERSION = '2.0.0';
|
||||||
|
|
||||||
public function onStartShowConversation(Action $action, Conversation $conv, Profile $scoped=null) {
|
public function onStartShowConversation(Action $action, Conversation $conv, Profile $scoped = null): bool
|
||||||
|
{
|
||||||
$nl = new ConversationTree($conv->getNotices($action->getScoped()), $action);
|
$nl = new ConversationTree($conv->getNotices($action->getScoped()), $action);
|
||||||
$cnt = $nl->show();
|
$nl->show();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onPluginVersion(array &$versions): bool
|
public function onPluginVersion(array &$versions): bool
|
||||||
{
|
{
|
||||||
$versions[] = array('name' => 'ConversationTree',
|
$versions[] = [
|
||||||
|
'name' => 'ConversationTree',
|
||||||
'version' => self::PLUGIN_VERSION,
|
'version' => self::PLUGIN_VERSION,
|
||||||
'author' => 'Mikael Nordfeldth',
|
'author' => 'Evan Prodromou, Mikael Nordfeldth',
|
||||||
'homepage' => 'http://gnu.io/',
|
'homepage' => 'http://gnu.io/',
|
||||||
'rawdescription' =>
|
'rawdescription' =>
|
||||||
// TRANS: Plugin description.
|
// TRANS: Module description.
|
||||||
_m('Enables conversation tree view.'));
|
_m('Enables conversation tree view.')
|
||||||
|
];
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,34 +1,20 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
||||||
* StatusNet - the distributed open-source microblogging tool
|
//
|
||||||
* Copyright (C) 2011, StatusNet, 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
|
||||||
* Conversation tree widget for oooooold school playas
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
*
|
// (at your option) any later version.
|
||||||
* PHP version 5
|
//
|
||||||
*
|
// GNU social is distributed in the hope that it will be useful,
|
||||||
* This program is free software: you can redistribute it and/or modify
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
// GNU Affero General Public License for more details.
|
||||||
* (at your option) any later version.
|
//
|
||||||
*
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
* This program is distributed in the hope that it will be useful,
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* 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
|
|
||||||
* @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/
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
defined('GNUSOCIAL') || die();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Conversation tree
|
* Conversation tree
|
||||||
|
@ -36,29 +22,29 @@ if (!defined('GNUSOCIAL')) { exit(1); }
|
||||||
* The widget class for displaying a hierarchical list of notices.
|
* The widget class for displaying a hierarchical list of notices.
|
||||||
*
|
*
|
||||||
* @category Widget
|
* @category Widget
|
||||||
* @package StatusNet
|
* @package ConversationTreePlugin
|
||||||
* @author Evan Prodromou <evan@status.net>
|
* @author Evan Prodromou <evan@status.net>
|
||||||
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
|
* @copyright 2019 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
|
||||||
*/
|
*/
|
||||||
class ConversationTree extends NoticeList
|
class ConversationTree extends NoticeList
|
||||||
{
|
{
|
||||||
var $tree = null;
|
public $tree = null;
|
||||||
var $table = null;
|
public $table = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the tree of notices
|
* Show the tree of notices
|
||||||
*
|
*
|
||||||
* @return void
|
* @return int
|
||||||
*/
|
*/
|
||||||
function show()
|
public function show(): int
|
||||||
{
|
{
|
||||||
$cnt = $this->_buildTree();
|
$cnt = $this->_buildTree();
|
||||||
|
|
||||||
$this->out->elementStart('div', array('id' =>'notices_primary'));
|
$this->out->elementStart('div', ['id' => 'notices_primary']);
|
||||||
// TRANS: Header on conversation page. Hidden by default (h2).
|
// TRANS: Header on conversation page. Hidden by default (h2).
|
||||||
$this->out->element('h2', null, _('Notices'));
|
$this->out->element('h2', null, _('Notices'));
|
||||||
$this->out->elementStart('ol', array('class' => 'notices xoxo old-school'));
|
$this->out->elementStart('ol', ['class' => 'notices xoxo old-school']);
|
||||||
|
|
||||||
if (array_key_exists('root', $this->tree)) {
|
if (array_key_exists('root', $this->tree)) {
|
||||||
$rootid = $this->tree['root'][0];
|
$rootid = $this->tree['root'][0];
|
||||||
|
@ -71,15 +57,14 @@ class ConversationTree extends NoticeList
|
||||||
return $cnt;
|
return $cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _buildTree()
|
public function _buildTree(): int
|
||||||
{
|
{
|
||||||
$cnt = 0;
|
$cnt = 0;
|
||||||
|
|
||||||
$this->tree = array();
|
$this->tree = [];
|
||||||
$this->table = array();
|
$this->table = [];
|
||||||
|
|
||||||
while ($this->notice->fetch()) {
|
while ($this->notice->fetch()) {
|
||||||
|
|
||||||
$cnt++;
|
$cnt++;
|
||||||
|
|
||||||
$id = $this->notice->id;
|
$id = $this->notice->id;
|
||||||
|
@ -88,11 +73,11 @@ class ConversationTree extends NoticeList
|
||||||
$this->table[$id] = $notice;
|
$this->table[$id] = $notice;
|
||||||
|
|
||||||
if (is_null($notice->reply_to)) {
|
if (is_null($notice->reply_to)) {
|
||||||
$this->tree['root'] = array($notice->id);
|
$this->tree['root'] = [$notice->id];
|
||||||
} else if (array_key_exists($notice->reply_to, $this->tree)) {
|
} elseif (array_key_exists($notice->reply_to, $this->tree)) {
|
||||||
$this->tree[$notice->reply_to][] = $notice->id;
|
$this->tree[$notice->reply_to][] = $notice->id;
|
||||||
} else {
|
} else {
|
||||||
$this->tree[$notice->reply_to] = array($notice->id);
|
$this->tree[$notice->reply_to] = [$notice->id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,12 +91,12 @@ class ConversationTree extends NoticeList
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function showNoticePlus($id)
|
public function showNoticePlus($id): void
|
||||||
{
|
{
|
||||||
$notice = $this->table[$id];
|
$notice = $this->table[$id];
|
||||||
|
|
||||||
$this->out->elementStart('li', array('class' => 'h-entry notice',
|
$this->out->elementStart('li', ['class' => 'h-entry notice',
|
||||||
'id' => 'notice-' . $id));
|
'id' => 'notice-' . $id]);
|
||||||
|
|
||||||
$item = $this->newListItem($notice);
|
$item = $this->newListItem($notice);
|
||||||
$item->show();
|
$item->show();
|
||||||
|
@ -119,7 +104,7 @@ class ConversationTree extends NoticeList
|
||||||
if (array_key_exists($id, $this->tree)) {
|
if (array_key_exists($id, $this->tree)) {
|
||||||
$children = $this->tree[$id];
|
$children = $this->tree[$id];
|
||||||
|
|
||||||
$this->out->elementStart('ol', array('class' => 'notices threaded-replies xoxo'));
|
$this->out->elementStart('ol', ['class' => 'notices threaded-replies xoxo']);
|
||||||
|
|
||||||
sort($children);
|
sort($children);
|
||||||
|
|
||||||
|
@ -138,9 +123,9 @@ class ConversationTree extends NoticeList
|
||||||
*
|
*
|
||||||
* @param Notice $notice Notice to display
|
* @param Notice $notice Notice to display
|
||||||
*
|
*
|
||||||
* @return NoticeListItem a list item to show
|
* @return ConversationTreeItem a list item to show
|
||||||
*/
|
*/
|
||||||
function newListItem(Notice $notice)
|
public function newListItem(Notice $notice): ConversationTreeItem
|
||||||
{
|
{
|
||||||
return new ConversationTreeItem($notice, $this->out);
|
return new ConversationTreeItem($notice, $this->out);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,34 +1,20 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
||||||
* StatusNet - the distributed open-source microblogging tool
|
//
|
||||||
* Copyright (C) 2011, StatusNet, 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
|
||||||
* Conversation tree widget for oooooold school playas
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
*
|
// (at your option) any later version.
|
||||||
* PHP version 5
|
//
|
||||||
*
|
// GNU social is distributed in the hope that it will be useful,
|
||||||
* This program is free software: you can redistribute it and/or modify
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
// GNU Affero General Public License for more details.
|
||||||
* (at your option) any later version.
|
//
|
||||||
*
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
* This program is distributed in the hope that it will be useful,
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* 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
|
|
||||||
* @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/
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
defined('GNUSOCIAL') || die();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Conversation tree list item
|
* Conversation tree list item
|
||||||
|
@ -36,10 +22,10 @@ if (!defined('GNUSOCIAL')) { exit(1); }
|
||||||
* Special class of NoticeListItem for use inside conversation trees.
|
* Special class of NoticeListItem for use inside conversation trees.
|
||||||
*
|
*
|
||||||
* @category Widget
|
* @category Widget
|
||||||
* @package StatusNet
|
* @package ConversationTreePlugin
|
||||||
* @author Evan Prodromou <evan@status.net>
|
* @author Evan Prodromou <evan@status.net>
|
||||||
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
|
* @copyright 2019 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
|
||||||
*/
|
*/
|
||||||
class ConversationTreeItem extends NoticeListItem
|
class ConversationTreeItem extends NoticeListItem
|
||||||
{
|
{
|
||||||
|
@ -51,7 +37,7 @@ class ConversationTreeItem extends NoticeListItem
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function showStart()
|
public function showStart(): void
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -64,7 +50,7 @@ class ConversationTreeItem extends NoticeListItem
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function showEnd()
|
public function showEnd(): void
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -76,7 +62,7 @@ class ConversationTreeItem extends NoticeListItem
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function showAddressees()
|
public function showAddressees(): void
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user