*/ // must be run within Dokuwiki if(!defined('DOKU_INC')) die(); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'syntax.php'); /** * All DokuWiki plugins to extend the parser/rendering mechanism * need to inherit from this class */ class syntax_plugin_discussion_threads extends DokuWiki_Syntax_Plugin { /** * return some info */ function getInfo(){ return array( 'author' => 'Esther Brunner', 'email' => 'wikidesign@gmail.com', 'date' => '2006-12-02', 'name' => 'Discussion Plugin (threads component)', 'desc' => 'Displays a list of recently active discussions', 'url' => 'http://www.wikidesign.ch/en/plugin/discussion/start', ); } function getType(){ return 'substition'; } function getPType(){ return 'block'; } function getSort(){ return 306; } function connectTo($mode) { $this->Lexer->addSpecialPattern('\{\{threads>.+?\}\}',$mode,'plugin_discussion_threads'); } /** * Handle the match */ function handle($match, $state, $pos, &$handler){ $match = substr($match, 10, -2); // strip {{threads> from start and }} from end return cleanID($match); } /** * Create output */ function render($mode, &$renderer, $ns) { global $ID; global $conf; if ($ns == ':') $ns = ''; elseif ($ns == '.') $ns = getNS($ID); $pages = $this->_threadList($ns); if (!count($pages)) return true; // nothing to display if ($mode == 'xhtml'){ // prevent caching to ensure content is always fresh $renderer->info['cache'] = false; // main table $renderer->doc .= ''; foreach ($pages as $page){ $renderer->doc .= ''; // last comment date if ($this->getConf('threads_showdate')){ $renderer->doc .= ''; } // topic starter if ($this->getConf('threads_showuser')){ if ($page['user']) $renderer->doc .= ''; else $renderer->doc .= ''; } // number of replies if ($page['num'] == 0) $repl = ''; elseif ($page['num'] == 1) $repl = '1 '.$this->getLang('reply'); else $repl = $page['num'].' '.$this->getLang('replies'); $renderer->doc .= ''; $renderer->doc .= ''; } $renderer->doc .= '
'; // page title $id = $page['id']; $title = $page['title']; if (!$title) $title = str_replace('_', ' ', noNS($id)); $renderer->doc .= $renderer->internallink(':'.$id, $title).''.date($conf['dformat'], $page['date']). ''.$page['user'].' '.$repl.'
'; // show form to start a new discussion thread? if (auth_quickaclcheck($ns.':*') >= AUTH_CREATE) $renderer->doc .= $this->_newthreadForm($ns); return true; // for metadata renderer } elseif ($mode == 'metadata'){ foreach ($pages as $page){ $id = $page['id']; $renderer->meta['relation']['references'][$id] = true; } return true; } return false; } /** * Returns an array of files with discussion sections, sorted by recent comments */ function _threadList($ns){ global $conf; require_once(DOKU_INC.'inc/search.php'); $dir = $conf['datadir'].($ns ? '/'.str_replace(':', '/', $ns): ''); // returns the list of pages in the given namespace and it's subspaces $items = array(); search($items, $dir, 'search_allpages', ''); // add pages with comments to result $result = array(); foreach ($items as $item){ $id = ($ns ? $ns.':' : '').$item['id']; if (auth_quickaclcheck($id) < AUTH_READ) continue; // skip if no permission $file = metaFN($id, '.comments'); if (!@file_exists($file)) continue; // skip if no comments file $data = unserialize(io_readFile($file, false)); if ($data['status'] == 0) continue; // skip if comments are off $date = filemtime($file); $meta = p_get_metadata($id); $result[$date] = array( 'id' => $id, 'title' => $meta['title'], 'user' => $meta['creator'], 'num' => $data['number'], 'date' => $date, ); } // finally sort by time of last comment krsort($result); return $result; } /** * Show the form to start a new discussion thread */ function _newthreadForm($ns){ global $ID; global $lang; return '
'. '
'. '
'. ''. ''. ''. ''. ''. '
'. '
'. '
'; } } //Setup VIM: ex: et ts=4 enc=utf-8 :