', 4);
ptln('
', 6);
ptln('
', 6);
echo html_buildlist($comments, 'admin_discussion', array($this, '_commentItem'), array($this, '_li_comment'));
$this->_actionButtons($thread['id']);
}
$this->_browseDiscussionLinks($more, $first, $num);
}
/**
* Returns an array of pages with discussion sections, sorted by recent comments
*/
function _getThreads(){
global $conf;
require_once(DOKU_INC.'inc/search.php');
// returns the list of pages in the given namespace and it's subspaces
$items = array();
search($items, $conf['datadir'], 'search_allpages', '');
// add pages with comments to result
$result = array();
foreach ($items as $item){
$id = $item['id'];
// some checks
$file = metaFN($id, '.comments');
if (!@file_exists($file)) continue; // skip if no comments file
$date = filemtime($file);
$result[$date] = array(
'id' => $id,
'file' => $file,
'date' => $date,
);
}
// finally sort by time of last comment
krsort($result);
return $result;
}
/**
* Outputs header, page ID and status of a discussion thread
*/
function _threadHead($thread){
$id = $thread['id'];
$labels = array(
0 => $this->getLang('off'),
1 => $this->getLang('open'),
2 => $this->getLang('closed')
);
ptln('
'.hsc(p_get_metadata($id, 'title')).'
');
ptln('
');
ptln('
');
ptln('
'.$id.' ', 2);
return true;
}
/**
* Returns the full comments data for a given wiki page
*/
function _getComments(&$thread){
$id = $thread['id'];
if (!$thread['file']) $thread['file'] = metaFN($id, '.comments');
if (!@file_exists($thread['file'])) return false; // no discussion thread at all
$data = unserialize(io_readFile($thread['file'], false));
$thread['status'] = $data['status'];
$thread['number'] = $data['number'];
if (!$data['status']) return false; // comments are turned off
if (!isset($data['comments']) || !$data['number']) return false; // no comments
$result = array();
foreach ($data['comments'] as $cid => $comment){
$this->_addComment($cid, $data, $result);
}
return $result;
}
/**
* Recursive function to add the comment hierarchy to the result
*/
function _addComment($cid, &$data, &$result, $parent = '', $level = 1){
if (!is_array($data['comments'][$cid])) return; // corrupt datatype
$comment = $data['comments'][$cid];
if ($comment['parent'] != $parent) return; // answer to another comment
// okay, add the comment to the result
$comment['id'] = $cid;
$comment['level'] = $level;
$result[] = $comment;
// check answers to this comment
if (count($comment['replies'])){
foreach ($comment['replies'] as $rid){
$this->_addComment($rid, $data, $result, $cid, $level + 1);
}
}
}
/**
* Checkbox and info about a comment item
*/
function _commentItem($comment){
global $conf;
// prepare variables
if (is_array($comment['user'])){ // new format
$name = $comment['user']['name'];
$mail = $comment['user']['mail'];
} else { // old format
$name = $comment['name'];
$mail = $comment['mail'];
}
if (is_array($comment['date'])){ // new format
$created = $comment['date']['created'];
} else { // old format
$created = $comment['date'];
}
$abstract = preg_replace('/\s+?/', ' ', strip_tags($comment['xhtml']));
if (utf8_strlen($abstract) > 160) $abstract = utf8_substr($abstract, 0, 160).'...';
return '
'.
$this->email($mail, $name, 'email').', '.date($conf['dformat'], $created).': '.
'
'.$abstract.'';
}
/**
* list item tag
*/
function _li_comment($comment){
$show = ($comment['show'] ? '' : ' hidden');
return '
', 4); // class="no"
ptln('', 2);
ptln('
'); // class="level2"
return true;
}
/**
* Displays links to older newer discussions
*/
function _browseDiscussionLinks($more, $first, $num){
global $ID;
$params = array('do' => 'admin', 'page' => 'discussion');
$last = $first+$num;
if ($first > 0){
$first -= $num;
if ($first < 0) $first = 0;
$params['first'] = $first;
ptln('