xref: /plugin/discussion/admin.php (revision a768ba620648a5515ac0cfe24148acf7bbcad11b)
1<?php
2if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
3if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
4require_once(DOKU_PLUGIN.'admin.php');
5
6/**
7 * All DokuWiki plugins to extend the admin function
8 * need to inherit from this class
9 */
10class admin_plugin_discussion extends DokuWiki_Admin_Plugin {
11
12    /**
13     * return some info
14     */
15    function getInfo(){
16      return array(
17        'author' => 'iDo',
18        'email'  => 'iDo@woow-fr.com',
19        'date'   => '2006-12-30',
20        'name'   => 'See all discussion',
21        'desc'   => '',
22        'url'    => '',
23      );
24    }
25
26    /**
27     * return sort order for position in admin menu
28     */
29    function getMenuSort() {
30      return 200;
31    }
32
33    /**
34     * handle user request
35     */
36    function handle() {
37    }
38
39    /**
40     * output appropriate html
41     */
42    function html() {
43		global $conf;
44		$chem=DOKU_INC.$conf['savedir']."/meta/";
45		$arr=$this->globr($chem,"*.comments");
46		$com =array();
47		foreach ($arr as $v) {
48			$ap=unserialize(io_readFile($v, false));
49			//si ya des commentaire
50			if (isset($ap['comments'])) {
51				//pour chaque commentaire
52				foreach ($ap['comments'] as $vv) {
53					$page=str_replace(array($chem,".comments"),array("",""),$v);
54					$com[$page][$vv['date']]=array("name"=>$vv['name'],"com"=>$vv['xhtml']);
55					//old method
56					//$com[$vv['date']]=array("name"=>$vv['name'],"com"=>$vv['xhtml'],"page"=>wl($page,''));
57				}
58			}
59		}
60
61		if (count($com > 1)) {
62			//sort discussion	for all page
63			foreach ($com as $k => $v)
64				krsort($com[$k],SORT_NUMERIC);
65
66
67			//for all page with discussion thread
68			echo "<ul>";
69			foreach ($com as $page => $thread) {
70				echo "<li>";
71				echo '<div class="cPage"><a href="'.wl($page,'').'">'.str_replace("/doku.php//","",wl($page,'')).'</a></div><div class="cComBlock">';
72
73				foreach ($thread as $dte => $coments) {
74					echo '<div class="cComSolo">';
75					echo '<div class="cDate">'.date("d/m/Y H:i:s",$dte).'</div>';
76					echo '<span class="cName">'.$coments['name'].'</span>';
77					echo '<span class="cCom">'.$coments['com'].'</span>';
78					echo "</div>";
79				}
80				echo "</div></li>";
81			}
82			echo "</ul>";
83		}
84    }
85
86	/**
87	 * Recursive version of glob
88	 *
89	 * @return array containing all pattern-matched files.
90	 *
91	 * @param string $sDir      Directory to start with.
92	 * @param string $sPattern  Pattern to glob for.
93	 * @param int $nFlags      Flags sent to glob.
94	 */
95	function globr($sDir, $sPattern, $nFlags = NULL) {
96	  $sDir = escapeshellcmd($sDir);
97	  // Get the list of all matching files currently in the
98	  // directory.
99	  $aFiles = glob("$sDir/$sPattern", $nFlags);
100	  // Then get a list of all directories in this directory, and
101	  // run ourselves on the resulting array.  This is the
102	  // recursion step, which will not execute if there are no
103	  // directories.
104	  foreach (glob("$sDir/*", GLOB_ONLYDIR) as $sSubDir)  {
105	   $aSubFiles = $this->globr($sSubDir, $sPattern, $nFlags);
106	   $aFiles = array_merge($aFiles, $aSubFiles);
107	  }
108	  // The array we return contains the files we found, and the
109	  // files all of our children found.
110	  return $aFiles;
111	}
112
113
114}
115?>
116