1<?php 2/** 3 * Discussion Plugin, threads component: displays a list of recently active discussions 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Esther Brunner <wikidesign@gmail.com> 7 */ 8 9// must be run within Dokuwiki 10if(!defined('DOKU_INC')) die(); 11 12if (!defined('DOKU_LF')) define('DOKU_LF', "\n"); 13if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t"); 14if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/'); 15 16require_once(DOKU_PLUGIN.'syntax.php'); 17 18class syntax_plugin_discussion_threads extends DokuWiki_Syntax_Plugin { 19 20 function getInfo(){ 21 return array( 22 'author' => 'Esther Brunner', 23 'email' => 'wikidesign@gmail.com', 24 'date' => '2007-01-11', 25 'name' => 'Discussion Plugin (threads component)', 26 'desc' => 'Displays a list of recently active discussions', 27 'url' => 'http://www.wikidesign.ch/en/plugin/discussion/start', 28 ); 29 } 30 31 function getType(){ return 'substition'; } 32 function getPType(){ return 'block'; } 33 function getSort(){ return 306; } 34 35 function connectTo($mode){ 36 $this->Lexer->addSpecialPattern('\{\{threads>.+?\}\}', $mode, 'plugin_discussion_threads'); 37 } 38 39 function handle($match, $state, $pos, &$handler){ 40 global $ID; 41 42 $ns = substr($match, 10, -2); // strip {{threads> from start and }} from end 43 44 if (($ns == '*') || ($ns == ':')) $ns = ''; 45 elseif ($ns == '.') $ns = getNS($ID); 46 else $ns = cleanID($ns); 47 48 return $ns; 49 } 50 51 function render($mode, &$renderer, $ns) { 52 if ($my =& plugin_load('helper', 'discussion')) $pages = $my->getThreads($ns); 53 if (!$pages){ 54 if ((auth_quickaclcheck($ns.':*') >= AUTH_CREATE) && ($mode == 'xhtml')){ 55 $renderer->info['cache'] = false; 56 $renderer->doc .= $this->_newThreadForm($ns); 57 } 58 return true; // nothing to display 59 } 60 61 if ($mode == 'xhtml'){ 62 63 // prevent caching to ensure content is always fresh 64 $renderer->info['cache'] = false; 65 66 // show form to start a new discussion thread? 67 $perm_create = (auth_quickaclcheck($ns.':*') >= AUTH_CREATE); 68 if ($perm_create && ($this->getConf('threads_formposition') == 'top')) 69 $renderer->doc .= $this->_newThreadForm($ns); 70 71 // let Pagelist Plugin do the work for us 72 if (plugin_isdisabled('pagelist') 73 || (!$pagelist =& plugin_load('helper', 'pagelist'))){ 74 msg('The Pagelist Plugin must be installed for threads lists to work.', -1); 75 return false; 76 } 77 $pagelist->column['comments'] = true; 78 $pagelist->startList(); 79 foreach ($pages as $page){ 80 $pagelist->addPage($page); 81 } 82 $renderer->doc .= $pagelist->finishList(); 83 84 // show form to start a new discussion thread? 85 if ($perm_create && ($this->getConf('threads_formposition') == 'bottom')) 86 $renderer->doc .= $this->_newThreadForm($ns); 87 88 return true; 89 90 // for metadata renderer 91 } elseif ($mode == 'metadata'){ 92 foreach ($pages as $page){ 93 $renderer->meta['relation']['references'][$page['id']] = true; 94 } 95 96 return true; 97 } 98 return false; 99 } 100 101/* ---------- (X)HTML Output Functions ---------- */ 102 103 /** 104 * Show the form to start a new discussion thread 105 */ 106 function _newThreadForm($ns){ 107 global $ID; 108 global $lang; 109 110 return '<div class="newthread_form">'.DOKU_LF. 111 '<form id="discussion__newthread_form" method="post" action="'.script().'" accept-charset="'.$lang['encoding'].'">'.DOKU_LF. 112 DOKU_TAB.'<fieldset>'.DOKU_LF. 113 DOKU_TAB.DOKU_TAB.'<legend> '.$this->getLang('newthread').': </legend>'.DOKU_LF. 114 DOKU_TAB.DOKU_TAB.'<input type="hidden" name="id" value="'.$ID.'" />'.DOKU_LF. 115 DOKU_TAB.DOKU_TAB.'<input type="hidden" name="do" value="newthread" />'.DOKU_LF. 116 DOKU_TAB.DOKU_TAB.'<input type="hidden" name="ns" value="'.$ns.'" />'.DOKU_LF. 117 DOKU_TAB.DOKU_TAB.'<input class="edit" type="text" name="title" id="discussion__newthread_title" size="40" tabindex="1" />'.DOKU_LF. 118 DOKU_TAB.DOKU_TAB.'<input class="button" type="submit" value="'.$lang['btn_create'].'" tabindex="2" />'.DOKU_LF. 119 DOKU_TAB.'</fieldset>'.DOKU_LF. 120 '</form>'.DOKU_LF. 121 '</div>'.DOKU_LF; 122 } 123 124} 125 126//Setup VIM: ex: et ts=4 enc=utf-8 : 127