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