xref: /plugin/discussion/admin.php (revision 264b73272ebcbccec9920e099b7167f8a9cb3d9b)
1<?php
2/**
3 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
4 * @author     Esther Brunner <wikidesign@gmail.com>
5 */
6
7// must be run within Dokuwiki
8if (!defined('DOKU_INC')) die();
9
10if (!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
11if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
12if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
13if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
14
15require_once(DOKU_PLUGIN.'admin.php');
16
17class admin_plugin_discussion extends DokuWiki_Admin_Plugin {
18
19  function getInfo(){
20    return array(
21      'author' => 'Esther Brunner',
22      'email'  => 'wikidesign@gmail.com',
23      'date'   => '2007-02-22',
24      'name'   => 'Discussion Plugin (admin component)',
25      'desc'   => 'Manage all discussions',
26      'url'    => 'http://www.wikidesign.ch/en/plugin/discussion/start',
27    );
28  }
29
30  function getMenuSort(){ return 200; }
31  function handle(){}
32  function forAdminOnly(){ return false; }
33
34  /**
35   * output appropriate html
36   */
37  function html(){
38    global $conf;
39
40    echo '<h1>'.$this->getLang('menu').'</h1>';
41
42    $my =& plugin_load('helper', 'discussion');
43
44    $threads = $my->getThreads('', $conf['recent'], true);
45    foreach ($threads as $thread){
46      echo $this->_threadHead($thread);
47      if (($thread['status'] == 0) || ($thread['num'] == 0)){
48        echo '</div>';
49        continue;
50      }
51      $comments = $my->getFullComments($thread);
52
53      echo '<form action="'.script().'">'.
54        '<div class="no">'.
55        '<input type="hidden" name="id" value="'.$thread['id'].'" />'.
56        '<input type="hidden" name="do" value="admin" />'.
57        '<input type="hidden" name="page" value="discussion" />';
58      echo html_buildlist($comments, 'admin_discussion', array($this, '_commentItem'), array($this, '_li_comment'));
59      echo $this->_actionButtons($thread['id']);
60    }
61  }
62
63  /**
64   * Header, page ID and status of a discussion thread
65   */
66  function _threadHead($thread){
67    $label = array(
68      $this->getLang('off'),
69      $this->getLang('open'),
70      $this->getLang('closed')
71    );
72    $status = $label[$thread['status']];
73    return '<h2>'.hsc($thread['title']).'</h2>'.
74      '<div class="rightalign">'.$this->getLang('status').': '.$status.
75      ' '.$this->getLang('btn_change').'</div>'.
76      '<div class="level2">'.
77      '<a href="'.wl($thread['id']).'" class="wikilinik1">'.$thread['id'].'</a> ';
78  }
79
80  /**
81   * Checkbox and info about a comment item
82   */
83  function _commentItem($comment){
84    global $conf;
85
86    // prepare variables
87    if (is_array($comment['user'])){ // new format
88      $name    = $comment['user']['name'];
89      $mail    = $comment['user']['mail'];
90    } else {                         // old format
91      $name    = $comment['name'];
92      $mail    = $comment['mail'];
93    }
94    if (is_array($comment['date'])){ // new format
95      $created  = $comment['date']['created'];
96    } else {                         // old format
97      $created  = $comment['date'];
98    }
99    $abstract = strip_tags($comment['xhtml']);
100    if (utf8_strlen($abstract) > 160) $abstract = utf8_substr($abstract, 0, 160).'...';
101
102    return '<input type="checkbox" name="cid['.$comment['id'].']" value="'.$comment['id'].'" /> '.$this->email($mail, $name, 'email').', '.
103      date($conf['dformat'], $created).': <span class="abstract">'.$abstract.'</span>';
104  }
105
106  /**
107   * list item tag
108   */
109  function _li_comment($comment){
110    $show = ($comment['show'] ? '' : ' hidden');
111    return '<li class="level'.$comment['level'].$show.'">';
112  }
113
114  /**
115   * Show buttons to bulk remove, hide or show comments
116   */
117  function _actionButtons($id){
118    global $lang;
119
120    return '<div class="comment_buttons">'.
121      '<input type="submit" name="comment" value="'.$this->getLang('btn_show').'" class="button" title="'.$this->getLang('btn_show').'" />'.
122      '<input type="submit" name="comment" value="'.$this->getLang('btn_hide').'" class="button" title="'.$this->getLang('btn_hide').'" />'.
123      '<input type="submit" name="comment" value="'.$lang['btn_delete'].'" class="button" title="'.$lang['btn_delete'].'" />'.
124      '</div>'.
125      '</div>'.
126      '</form>'.
127      '</div>'; // class="level2"
128  }
129
130    /**
131     * function by iDo
132     */
133    function _html() {
134    	require_once(DOKU_PLUGIN.'action.php');
135		$actionDiscussion= new action_plugin_discussion();
136
137		global $conf;
138		global $INFO;
139		global $ID;
140		global $ADMDISCUSSION;
141
142		$oID=$ID;
143		$ADMDISCUSSION['page']="adm";
144		//Execute action for page
145		if (isset($_REQUEST['comment'])) {
146			if ($_REQUEST['comment']!='edit') {
147
148				if (($_REQUEST['comment']=='add') && (isset($_REQUEST['cid']))) {
149
150				} else {
151					$obj=new unusedclass();
152					$actionDiscussion->comments($obj, null);
153				}
154			}
155		}
156
157		$chem=DOKU_INC.$conf['savedir']."/meta/";
158		$arr=$this->globr($chem,"*.comments");
159		$com =array();
160		foreach ($arr as $v) {
161			$ap=unserialize(io_readFile($v, false));
162			if (isset($ap['comments'])){
163				$ID=substr(str_replace(array($chem,".comments",'/'),array("","",':'),$v),1);
164				$ADMDISCUSSION['page']=' : <a href="'.wl($ID,'').'">'.str_replace("/doku.php/","",wl($ID,'')).'</a>';
165
166				if ((isset($_REQUEST['comment'])) && ($_REQUEST['comment']=='edit'))
167					$actionDiscussion->_show(NULL, $_REQUEST['cid']);
168				else
169					$actionDiscussion->_show((($oID==$ID)?@$_REQUEST['cid']:null));
170
171			}
172		}
173		$ID = $oID;
174		$ADMDISCUSSION['breakaction']=true;
175    }
176
177	/**
178	 * Recursive version of glob
179	 *
180	 * @return array containing all pattern-matched files.
181	 *
182	 * @param string $sDir      Directory to start with.
183	 * @param string $sPattern  Pattern to glob for.
184	 * @param int $nFlags      Flags sent to glob.
185	 */
186	function globr($sDir, $sPattern, $nFlags = NULL) {
187	  $sDir = escapeshellcmd($sDir);
188	  // Get the list of all matching files currently in the
189	  // directory.
190	  $aFiles = glob("$sDir/$sPattern", $nFlags);
191	  // Then get a list of all directories in this directory, and
192	  // run ourselves on the resulting array.  This is the
193	  // recursion step, which will not execute if there are no
194	  // directories.
195	  foreach (glob("$sDir/*", GLOB_ONLYDIR) as $sSubDir)  {
196	   $aSubFiles = $this->globr($sSubDir, $sPattern, $nFlags);
197	   $aFiles = array_merge($aFiles, $aSubFiles);
198	  }
199	  // The array we return contains the files we found, and the
200	  // files all of our children found.
201	  return $aFiles;
202	}
203
204}
205
206//Setup VIM: ex: et ts=4 enc=utf-8 :