2009-03-01 08:12:31 +09:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Display a conversation in the browser
|
|
|
|
*
|
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* @category Action
|
2009-08-26 07:12:20 +09:00
|
|
|
* @package StatusNet
|
2009-08-26 07:19:04 +09:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
2009-03-01 08:12:31 +09:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
|
2009-08-26 07:16:46 +09:00
|
|
|
* @link http://status.net/
|
2009-03-01 08:12:31 +09:00
|
|
|
*
|
2009-08-26 07:14:12 +09:00
|
|
|
* StatusNet - the distributed open-source microblogging tool
|
2009-08-26 07:12:20 +09:00
|
|
|
* Copyright (C) 2009, StatusNet, Inc.
|
2009-03-01 08:12:31 +09:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('LACONICA')) {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2009-07-03 23:37:39 +09:00
|
|
|
// XXX: not sure how to do paging yet,
|
|
|
|
// so set a 60-notice limit
|
|
|
|
|
2009-05-22 00:43:09 +09:00
|
|
|
require_once INSTALLDIR.'/lib/noticelist.php';
|
2009-04-04 05:12:33 +09:00
|
|
|
|
2009-03-01 08:12:31 +09:00
|
|
|
/**
|
|
|
|
* Conversation tree in the browser
|
|
|
|
*
|
|
|
|
* @category Action
|
2009-08-26 07:12:20 +09:00
|
|
|
* @package StatusNet
|
2009-08-26 07:19:04 +09:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
2009-03-01 08:12:31 +09:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
|
2009-08-26 07:16:46 +09:00
|
|
|
* @link http://status.net/
|
2009-03-01 08:12:31 +09:00
|
|
|
*/
|
2009-05-16 02:55:49 +09:00
|
|
|
|
2009-03-01 08:12:31 +09:00
|
|
|
class ConversationAction extends Action
|
|
|
|
{
|
2009-05-22 00:43:09 +09:00
|
|
|
var $id = null;
|
2009-03-01 08:12:31 +09:00
|
|
|
var $page = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialization.
|
|
|
|
*
|
|
|
|
* @param array $args Web and URL arguments
|
|
|
|
*
|
|
|
|
* @return boolean false if id not passed in
|
|
|
|
*/
|
|
|
|
|
|
|
|
function prepare($args)
|
|
|
|
{
|
|
|
|
parent::prepare($args);
|
|
|
|
$this->id = $this->trimmed('id');
|
2009-04-04 05:12:33 +09:00
|
|
|
if (empty($this->id)) {
|
2009-03-01 08:12:31 +09:00
|
|
|
return false;
|
|
|
|
}
|
2009-06-26 01:43:30 +09:00
|
|
|
$this->id = $this->id+0;
|
2009-03-01 08:12:31 +09:00
|
|
|
$this->page = $this->trimmed('page');
|
|
|
|
if (empty($this->page)) {
|
|
|
|
$this->page = 1;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-05-22 00:43:09 +09:00
|
|
|
/**
|
|
|
|
* Handle the action
|
|
|
|
*
|
|
|
|
* @param array $args Web and URL arguments
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
|
2009-03-01 08:12:31 +09:00
|
|
|
function handle($args)
|
|
|
|
{
|
2009-04-04 05:12:33 +09:00
|
|
|
parent::handle($args);
|
2009-03-01 08:12:31 +09:00
|
|
|
$this->showPage();
|
|
|
|
}
|
|
|
|
|
2009-05-22 00:43:09 +09:00
|
|
|
/**
|
|
|
|
* Returns the page title
|
|
|
|
*
|
|
|
|
* @return string page title
|
|
|
|
*/
|
|
|
|
|
2009-03-01 08:12:31 +09:00
|
|
|
function title()
|
|
|
|
{
|
|
|
|
return _("Conversation");
|
|
|
|
}
|
|
|
|
|
2009-05-22 00:43:09 +09:00
|
|
|
/**
|
|
|
|
* Show content.
|
|
|
|
*
|
|
|
|
* Display a hierarchical unordered list in the content area.
|
|
|
|
* Uses ConversationTree to do most of the heavy lifting.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
|
2009-03-01 08:12:31 +09:00
|
|
|
function showContent()
|
|
|
|
{
|
2009-07-03 23:48:15 +09:00
|
|
|
$notices = Notice::conversationStream($this->id, null, null);
|
2009-04-04 05:12:33 +09:00
|
|
|
|
2009-05-16 02:55:49 +09:00
|
|
|
$ct = new ConversationTree($notices, $this);
|
2009-03-01 08:12:31 +09:00
|
|
|
|
2009-05-16 02:55:49 +09:00
|
|
|
$cnt = $ct->show();
|
2009-03-01 08:12:31 +09:00
|
|
|
}
|
2009-07-16 05:57:39 +09:00
|
|
|
|
|
|
|
function isReadOnly()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2009-03-01 08:12:31 +09:00
|
|
|
}
|
|
|
|
|
2009-05-22 00:43:09 +09:00
|
|
|
/**
|
|
|
|
* Conversation tree
|
|
|
|
*
|
|
|
|
* The widget class for displaying a hierarchical list of notices.
|
|
|
|
*
|
|
|
|
* @category Widget
|
2009-08-26 07:12:20 +09:00
|
|
|
* @package StatusNet
|
2009-08-26 07:19:04 +09:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
2009-05-22 00:43:09 +09:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
|
2009-08-26 07:16:46 +09:00
|
|
|
* @link http://status.net/
|
2009-05-22 00:43:09 +09:00
|
|
|
*/
|
|
|
|
|
2009-05-16 02:55:49 +09:00
|
|
|
class ConversationTree extends NoticeList
|
|
|
|
{
|
2009-05-22 00:43:09 +09:00
|
|
|
var $tree = null;
|
2009-05-16 02:55:49 +09:00
|
|
|
var $table = null;
|
|
|
|
|
2009-05-22 00:43:09 +09:00
|
|
|
/**
|
|
|
|
* Show the tree of notices
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
|
2009-05-16 02:55:49 +09:00
|
|
|
function show()
|
|
|
|
{
|
2009-07-02 03:45:48 +09:00
|
|
|
$cnt = $this->_buildTree();
|
2009-07-01 00:50:16 +09:00
|
|
|
|
|
|
|
$this->out->elementStart('div', array('id' =>'notices_primary'));
|
|
|
|
$this->out->element('h2', null, _('Notices'));
|
|
|
|
$this->out->elementStart('ol', array('class' => 'notices xoxo'));
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2009-08-02 20:52:27 +09:00
|
|
|
$cnt = 0;
|
|
|
|
|
2009-05-22 00:43:09 +09:00
|
|
|
$this->tree = array();
|
|
|
|
$this->table = array();
|
2009-05-16 02:55:49 +09:00
|
|
|
|
|
|
|
while ($this->notice->fetch()) {
|
2009-05-22 00:43:09 +09:00
|
|
|
|
2009-05-16 02:55:49 +09:00
|
|
|
$cnt++;
|
2009-05-22 00:43:09 +09:00
|
|
|
|
|
|
|
$id = $this->notice->id;
|
|
|
|
$notice = clone($this->notice);
|
|
|
|
|
|
|
|
$this->table[$id] = $notice;
|
|
|
|
|
2009-05-16 02:55:49 +09:00
|
|
|
if (is_null($notice->reply_to)) {
|
2009-05-22 00:43:09 +09:00
|
|
|
$this->tree['root'] = array($notice->id);
|
2009-05-16 02:55:49 +09:00
|
|
|
} 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);
|
|
|
|
}
|
|
|
|
}
|
2009-07-02 03:45:48 +09:00
|
|
|
|
|
|
|
return $cnt;
|
2009-05-16 02:55:49 +09:00
|
|
|
}
|
|
|
|
|
2009-05-22 00:43:09 +09:00
|
|
|
/**
|
|
|
|
* Shows a notice plus its list of children.
|
|
|
|
*
|
|
|
|
* @param integer $id ID of the notice to show
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
|
2009-05-16 02:55:49 +09:00
|
|
|
function showNoticePlus($id)
|
|
|
|
{
|
|
|
|
$notice = $this->table[$id];
|
|
|
|
|
|
|
|
// We take responsibility for doing the li
|
|
|
|
|
|
|
|
$this->out->elementStart('li', array('class' => 'hentry notice',
|
2009-06-13 11:02:13 +09:00
|
|
|
'id' => 'notice-' . $id));
|
2009-05-16 02:55:49 +09:00
|
|
|
|
|
|
|
$item = $this->newListItem($notice);
|
|
|
|
$item->show();
|
|
|
|
|
|
|
|
if (array_key_exists($id, $this->tree)) {
|
|
|
|
$children = $this->tree[$id];
|
|
|
|
|
2009-05-29 11:38:38 +09:00
|
|
|
$this->out->elementStart('ol', array('class' => 'notices'));
|
2009-05-16 02:55:49 +09:00
|
|
|
|
2009-06-18 16:12:53 +09:00
|
|
|
sort($children);
|
|
|
|
|
2009-05-16 02:55:49 +09:00
|
|
|
foreach ($children as $child) {
|
|
|
|
$this->showNoticePlus($child);
|
|
|
|
}
|
|
|
|
|
2009-05-29 11:38:38 +09:00
|
|
|
$this->out->elementEnd('ol');
|
2009-05-16 02:55:49 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->out->elementEnd('li');
|
|
|
|
}
|
|
|
|
|
2009-05-22 00:43:09 +09:00
|
|
|
/**
|
|
|
|
* Override parent class to return our preferred item.
|
|
|
|
*
|
|
|
|
* @param Notice $notice Notice to display
|
|
|
|
*
|
|
|
|
* @return NoticeListItem a list item to show
|
|
|
|
*/
|
|
|
|
|
2009-05-16 02:55:49 +09:00
|
|
|
function newListItem($notice)
|
|
|
|
{
|
|
|
|
return new ConversationTreeItem($notice, $this->out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-22 00:43:09 +09:00
|
|
|
/**
|
|
|
|
* Conversation tree list item
|
|
|
|
*
|
|
|
|
* Special class of NoticeListItem for use inside conversation trees.
|
|
|
|
*
|
|
|
|
* @category Widget
|
2009-08-26 07:12:20 +09:00
|
|
|
* @package StatusNet
|
2009-08-26 07:19:04 +09:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
2009-05-22 00:43:09 +09:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
|
2009-08-26 07:16:46 +09:00
|
|
|
* @link http://status.net/
|
2009-05-22 00:43:09 +09:00
|
|
|
*/
|
|
|
|
|
2009-05-16 02:55:49 +09:00
|
|
|
class ConversationTreeItem extends NoticeListItem
|
|
|
|
{
|
2009-05-22 00:43:09 +09:00
|
|
|
/**
|
|
|
|
* start a single notice.
|
|
|
|
*
|
|
|
|
* The default creates the <li>; we skip, since the ConversationTree
|
|
|
|
* takes care of that.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
|
2009-05-16 02:55:49 +09:00
|
|
|
function showStart()
|
|
|
|
{
|
2009-05-22 00:43:09 +09:00
|
|
|
return;
|
2009-05-16 02:55:49 +09:00
|
|
|
}
|
|
|
|
|
2009-05-22 00:43:09 +09:00
|
|
|
/**
|
|
|
|
* finish the notice
|
|
|
|
*
|
|
|
|
* The default closes the <li>; we skip, since the ConversationTree
|
|
|
|
* takes care of that.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
|
2009-05-16 02:55:49 +09:00
|
|
|
function showEnd()
|
|
|
|
{
|
2009-05-22 00:43:09 +09:00
|
|
|
return;
|
2009-05-16 02:55:49 +09:00
|
|
|
}
|
|
|
|
|
2009-05-22 00:43:09 +09:00
|
|
|
/**
|
|
|
|
* show link to notice conversation page
|
|
|
|
*
|
|
|
|
* Since we're only used on the conversation page, we skip this
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
|
2009-05-16 02:55:49 +09:00
|
|
|
function showContext()
|
|
|
|
{
|
2009-05-22 00:43:09 +09:00
|
|
|
return;
|
2009-05-16 02:55:49 +09:00
|
|
|
}
|
2009-05-29 11:38:38 +09:00
|
|
|
}
|