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