xref: /plugin/discussion/syntax/threads.php (revision fbb94835897873fcbf52548627eb2474df36b7d2)
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-12',
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){
61      if ((auth_quickaclcheck($ns.':*') >= AUTH_CREATE) && ($mode == 'xhtml'))
62        $renderer->doc .= $this->_newThreadForm($ns);
63      return true; // nothing to display
64    }
65
66    if ($mode == 'xhtml'){
67
68      // prevent caching to ensure content is always fresh
69      $renderer->info['cache'] = false;
70
71      // show form to start a new discussion thread?
72      $perm_create = (auth_quickaclcheck($ns.':*') >= AUTH_CREATE);
73      if ($perm_create && ($this->getConf('threads_formposition') == 'top'))
74        $renderer->doc .= $this->_newThreadForm($ns);
75
76      // let Pagelist Plugin do the work for us
77      if (!$pagelist =& plugin_load('helper', 'pagelist')){
78        msg('The Pagelist Plugin must be installed for threads lists to work.', -1);
79        return false;
80      }
81      $pagelist->column['comments'] = true;
82      $pagelist->startList();
83      foreach ($pages as $page){
84        $pagelist->addPage($page);
85      }
86      $renderer->doc .= $pagelist->finishList();
87
88      // show form to start a new discussion thread?
89      if ($perm_create && ($this->getConf('threads_formposition') == 'bottom'))
90        $renderer->doc .= $this->_newThreadForm($ns);
91
92      return true;
93
94    // for metadata renderer
95    } elseif ($mode == 'metadata'){
96      foreach ($pages as $page){
97        $renderer->meta['relation']['references'][$page['id']] = true;
98      }
99
100      return true;
101    }
102    return false;
103  }
104
105/* ---------- (X)HTML Output Functions ---------- */
106
107  /**
108   * Show the form to start a new discussion thread
109   */
110  function _newThreadForm($ns){
111    global $ID;
112    global $lang;
113
114    return '<div class="newthread_form">'.DOKU_LF.
115      '<form id="discussion__newthread_form"  method="post" action="'.script().'" accept-charset="'.$lang['encoding'].'">'.DOKU_LF.
116      DOKU_TAB.'<fieldset>'.DOKU_LF.
117      DOKU_TAB.DOKU_TAB.'<legend> '.$this->getLang('newthread').': </legend>'.DOKU_LF.
118      DOKU_TAB.DOKU_TAB.'<input type="hidden" name="id" value="'.$ID.'" />'.DOKU_LF.
119      DOKU_TAB.DOKU_TAB.'<input type="hidden" name="do" value="newthread" />'.DOKU_LF.
120      DOKU_TAB.DOKU_TAB.'<input type="hidden" name="ns" value="'.$ns.'" />'.DOKU_LF.
121      DOKU_TAB.DOKU_TAB.'<input class="edit" type="text" name="title" id="discussion__newthread_title" size="40" tabindex="1" />'.DOKU_LF.
122      DOKU_TAB.DOKU_TAB.'<input class="button" type="submit" value="'.$lang['btn_create'].'" tabindex="2" />'.DOKU_LF.
123      DOKU_TAB.'</fieldset>'.DOKU_LF.
124      '</form>'.DOKU_LF.
125      '</div>'.DOKU_LF;
126  }
127
128}
129
130//Setup VIM: ex: et ts=4 enc=utf-8 :
131