From: Mikael Nordfeldth Date: Mon, 12 May 2014 09:41:51 +0000 (+0200) Subject: ConversationTree is now a plugin (not oldschool setting) X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=cd3cff451f2ac12ebe1b98c6ab643a0e4e931599;p=quix0rs-gnu-social.git ConversationTree is now a plugin (not oldschool setting) Conversation trees works pretty bad with the current layout, javascript etc. So it's best if we separate it and work on it as a side-project. The oldschool settings are currently being deprecated (or broken out like this). I'll wait with removing User preferences for oldschool conversation tree, since that might be reusable data. But I guess it will go in the near future. --- diff --git a/actions/oldschoolsettings.php b/actions/oldschoolsettings.php index 8c4ff9be27..25ec13e481 100644 --- a/actions/oldschoolsettings.php +++ b/actions/oldschoolsettings.php @@ -110,7 +110,6 @@ class OldschoolsettingsAction extends SettingsAction } $osp->stream_mode_only = $this->boolean('stream_mode_only'); - $osp->conversation_tree = $this->boolean('conversation_tree'); $osp->stream_nicknames = $this->boolean('stream_nicknames'); $osp->modified = common_sql_now(); @@ -162,10 +161,6 @@ class OldSchoolForm extends Form $this->user->streamModeOnly()); $this->elementEnd('li'); $this->elementStart('li'); - $this->checkbox('conversation_tree', _('Show conversation page as hierarchical trees'), - $this->user->conversationTree()); - $this->elementEnd('li'); - $this->elementStart('li'); $this->checkbox('stream_nicknames', _('Show nicknames (not full names) in timelines'), $this->user->streamNicknames()); $this->elementEnd('li'); diff --git a/classes/User.php b/classes/User.php index 115bda09b7..3e2873c75f 100644 --- a/classes/User.php +++ b/classes/User.php @@ -981,18 +981,6 @@ class User extends Managed_DataObject return false; } - function conversationTree() - { - if (common_config('oldschool', 'enabled')) { - $osp = Old_school_prefs::getKV('user_id', $this->id); - if (!empty($osp)) { - return $osp->conversation_tree; - } - } - - return false; - } - function streamNicknames() { if (common_config('oldschool', 'enabled')) { diff --git a/lib/conversationnoticestream.php b/lib/conversationnoticestream.php index 7d2e703545..b9b03c45c5 100644 --- a/lib/conversationnoticestream.php +++ b/lib/conversationnoticestream.php @@ -76,12 +76,8 @@ class RawConversationNoticeStream extends NoticeStream $this->id = $id; } - function getNoticeIds($offset, $limit, $since_id, $max_id) + function getNoticeIds($offset, $limit, $since_id=null, $max_id=null) { - $conv = Conversation::getKV('id', $this->id); - if (!$conv instanceof Conversation) { - throw new ServerException('Could not find conversation'); - } $notice = new Notice(); // SELECT $notice->selectAdd(); @@ -95,11 +91,14 @@ class RawConversationNoticeStream extends NoticeStream if (!empty($max_id)) { $notice->whereAdd(sprintf('notice.id <= %d', $max_id)); } - $notice->limit($offset, $limit); + if (!is_null($offset)) { + $notice->limit($offset, $limit); + } // ORDER BY // currently imitates the previously used "_reverseChron" sorting $notice->orderBy('notice.created DESC'); + $notice->find(); return $notice->fetchAll('id'); } } diff --git a/lib/conversationtree.php b/lib/conversationtree.php deleted file mode 100644 index ee24310fa1..0000000000 --- a/lib/conversationtree.php +++ /dev/null @@ -1,215 +0,0 @@ -. - * - * @category Widget - * @package StatusNet - * @author Evan Prodromou - * @copyright 2011 StatusNet, Inc. - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 - * @link http://status.net/ - */ - -if (!defined('STATUSNET')) { - // This check helps protect against security problems; - // your code file can't be executed directly from the web. - exit(1); -} - -/** - * Conversation tree - * - * The widget class for displaying a hierarchical list of notices. - * - * @category Widget - * @package StatusNet - * @author Evan Prodromou - * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 - * @link http://status.net/ - */ -class ConversationTree extends NoticeList -{ - var $tree = null; - var $table = null; - - /** - * Show the tree of notices - * - * @return void - */ - function show() - { - $cnt = $this->_buildTree(); - - $this->out->elementStart('div', array('id' =>'notices_primary')); - // TRANS: Header on conversation page. Hidden by default (h2). - $this->out->element('h2', null, _('Notices')); - $this->out->elementStart('ol', array('class' => 'notices xoxo old-school')); - - if (array_key_exists('root', $this->tree)) { - $rootid = $this->tree['root'][0]; - $this->showNoticePlus($rootid); - } - - $this->out->elementEnd('ol'); - $this->out->elementEnd('div'); - - return $cnt; - } - - function _buildTree() - { - $cnt = 0; - - $this->tree = array(); - $this->table = array(); - - while ($this->notice->fetch()) { - - $cnt++; - - $id = $this->notice->id; - $notice = clone($this->notice); - - $this->table[$id] = $notice; - - if (is_null($notice->reply_to)) { - $this->tree['root'] = array($notice->id); - } else if (array_key_exists($notice->reply_to, $this->tree)) { - $this->tree[$notice->reply_to][] = $notice->id; - } else { - $this->tree[$notice->reply_to] = array($notice->id); - } - } - - return $cnt; - } - - /** - * Shows a notice plus its list of children. - * - * @param integer $id ID of the notice to show - * - * @return void - */ - function showNoticePlus($id) - { - $notice = $this->table[$id]; - - $this->out->elementStart('li', array('class' => 'hentry notice', - 'id' => 'notice-' . $id)); - - $item = $this->newListItem($notice); - $item->show(); - - if (array_key_exists($id, $this->tree)) { - $children = $this->tree[$id]; - - $this->out->elementStart('ol', array('class' => 'notices')); - - sort($children); - - foreach ($children as $child) { - $this->showNoticePlus($child); - } - - $this->out->elementEnd('ol'); - } - - $this->out->elementEnd('li'); - } - - /** - * Override parent class to return our preferred item. - * - * @param Notice $notice Notice to display - * - * @return NoticeListItem a list item to show - */ - function newListItem($notice) - { - return new ConversationTreeItem($notice, $this->out); - } -} - -/** - * Conversation tree list item - * - * Special class of NoticeListItem for use inside conversation trees. - * - * @category Widget - * @package StatusNet - * @author Evan Prodromou - * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 - * @link http://status.net/ - */ -class ConversationTreeItem extends NoticeListItem -{ - /** - * start a single notice. - * - * The default creates the
  • ; we skip, since the ConversationTree - * takes care of that. - * - * @return void - */ - function showStart() - { - return; - } - - /** - * finish the notice - * - * The default closes the
  • ; we skip, since the ConversationTree - * takes care of that. - * - * @return void - */ - function showEnd() - { - return; - } - - /** - * show link to notice conversation page - * - * Since we're only used on the conversation page, we skip this - * - * @return void - */ - function showContext() - { - return; - } - - /** - * show people this notice is in reply to - * - * Tree context shows this, so we skip it. - * - * @return void - */ - function showAddressees() - { - return; - } -} diff --git a/plugins/ConversationTree/ConversationTreePlugin.php b/plugins/ConversationTree/ConversationTreePlugin.php new file mode 100644 index 0000000000..5532adb66e --- /dev/null +++ b/plugins/ConversationTree/ConversationTreePlugin.php @@ -0,0 +1,46 @@ +. + */ + +if (!defined('GNUSOCIAL')) { exit(1); } + +/** + * @package UI + * @maintainer Mikael Nordfeldth + */ +class ConversationTreePlugin extends Plugin +{ + public function onStartShowConversation(Action $action, Conversation $conv, Profile $scoped=null) { + $nl = new ConversationTree($conv->getNotices(), $action); + $cnt = $nl->show(); + return false; + } + + public function onPluginVersion(array &$versions) + { + $versions[] = array('name' => 'ConversationTree', + 'version' => GNUSOCIAL_VERSION, + 'author' => 'Mikael Nordfeldth', + 'homepage' => 'http://gnu.io/', + 'rawdescription' => + // TRANS: Plugin description. + _m('Enables conversation tree view.')); + + return true; + } +} diff --git a/plugins/ConversationTree/lib/conversationtree.php b/plugins/ConversationTree/lib/conversationtree.php new file mode 100644 index 0000000000..05282abcc4 --- /dev/null +++ b/plugins/ConversationTree/lib/conversationtree.php @@ -0,0 +1,147 @@ +. + * + * @category Widget + * @package StatusNet + * @author Evan Prodromou + * @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); } + +/** + * Conversation tree + * + * The widget class for displaying a hierarchical list of notices. + * + * @category Widget + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://status.net/ + */ +class ConversationTree extends NoticeList +{ + var $tree = null; + var $table = null; + + /** + * Show the tree of notices + * + * @return void + */ + function show() + { + $cnt = $this->_buildTree(); + + $this->out->elementStart('div', array('id' =>'notices_primary')); + // TRANS: Header on conversation page. Hidden by default (h2). + $this->out->element('h2', null, _('Notices')); + $this->out->elementStart('ol', array('class' => 'notices xoxo old-school')); + + if (array_key_exists('root', $this->tree)) { + $rootid = $this->tree['root'][0]; + $this->showNoticePlus($rootid); + } + + $this->out->elementEnd('ol'); + $this->out->elementEnd('div'); + + return $cnt; + } + + function _buildTree() + { + $cnt = 0; + + $this->tree = array(); + $this->table = array(); + + while ($this->notice->fetch()) { + + $cnt++; + + $id = $this->notice->id; + $notice = clone($this->notice); + + $this->table[$id] = $notice; + + if (is_null($notice->reply_to)) { + $this->tree['root'] = array($notice->id); + } else if (array_key_exists($notice->reply_to, $this->tree)) { + $this->tree[$notice->reply_to][] = $notice->id; + } else { + $this->tree[$notice->reply_to] = array($notice->id); + } + } + + return $cnt; + } + + /** + * Shows a notice plus its list of children. + * + * @param integer $id ID of the notice to show + * + * @return void + */ + function showNoticePlus($id) + { + $notice = $this->table[$id]; + + $this->out->elementStart('li', array('class' => 'hentry notice', + 'id' => 'notice-' . $id)); + + $item = $this->newListItem($notice); + $item->show(); + + if (array_key_exists($id, $this->tree)) { + $children = $this->tree[$id]; + + $this->out->elementStart('ol', array('class' => 'notices threaded-replies xoxo')); + + sort($children); + + foreach ($children as $child) { + $this->showNoticePlus($child); + } + + $this->out->elementEnd('ol'); + } + + $this->out->elementEnd('li'); + } + + /** + * Override parent class to return our preferred item. + * + * @param Notice $notice Notice to display + * + * @return NoticeListItem a list item to show + */ + function newListItem($notice) + { + return new ConversationTreeItem($notice, $this->out); + } +} diff --git a/plugins/ConversationTree/lib/conversationtreeitem.php b/plugins/ConversationTree/lib/conversationtreeitem.php new file mode 100644 index 0000000000..d7db04e1dd --- /dev/null +++ b/plugins/ConversationTree/lib/conversationtreeitem.php @@ -0,0 +1,95 @@ +. + * + * @category Widget + * @package StatusNet + * @author Evan Prodromou + * @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); } + +/** + * Conversation tree list item + * + * Special class of NoticeListItem for use inside conversation trees. + * + * @category Widget + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://status.net/ + */ +class ConversationTreeItem extends NoticeListItem +{ + /** + * start a single notice. + * + * The default creates the
  • ; we skip, since the ConversationTree + * takes care of that. + * + * @return void + */ + function showStart() + { + return; + } + + /** + * finish the notice + * + * The default closes the
  • ; we skip, since the ConversationTree + * takes care of that. + * + * @return void + */ + function showEnd() + { + return; + } + + /** + * show link to notice conversation page + * + * Since we're only used on the conversation page, we skip this + * + * @return void + */ + function showContext() + { + return; + } + + /** + * show people this notice is in reply to + * + * Tree context shows this, so we skip it. + * + * @return void + */ + function showAddressees() + { + return; + } +}