====== Discussion Forum ====== more content the next days ... ===== Summary ===== This plugin shows a Discussion Forum on your WikiPage.\\ Features: * show all threads ordered by the last active, * show all threads with Posts that you not readed before, * show an alphabetic ordered list of all Threads At the moment there are no categories possible. ===== syntax.php ===== This plugin is still under developemnt. It works only with a special DokuWiki configuration. I try to refactor this plugin to use it with all different configuartions. 'Thomas Preißler', 'email' => 'ding280@gmx.de', 'date' => '2006-06-25', 'name' => 'Forum', 'desc' => 'Zeigt die letzten Änderungen im Forum an', 'url' => 'http://www.dokuwiki.org/plugin:diskussion_forum', ); } function getType(){ return 'substition'; } //function getPType(){ return 'block'; } function getSort(){ return 280; } function connectTo($mode) { $this->Lexer->addSpecialPattern('~~FORUM:\w+~~', $mode, 'plugin_forum'); } /** * Handle the match */ function handle($match, $state, $pos, Doku_Handler $handler) { $array[] = strtolower(substr($match,8,-2)); return $array; } function render($mode, Doku_Renderer $renderer, $data) { $call = $data[0]; switch ($call) { case 'lastthreads': $this->lastThreads($renderer); break; case 'listthreads': $this->listThreads($renderer); break; case 'newthread': $this->newThread($renderer); break; case 'unreaded': $this->unreadedThreads($renderer); break; } } function lastThreads(&$renderer) { global $conf; $dir = $this->getDir(); $loglines = $this->readChanges(); $currentNamespace = $this->getNamespace(); $namespacePos = $this->getNamespacePos(); $last = array(); $blub = array(); $list = array(); foreach($loglines as $key => $val) { $namespaces = split(":", $val["page"]); $namespacePos = $this->getNamespacePos(); if($this->isCurrentNamespace($val["page"]) and $namespaces[$namespacePos+1] != "start" and count($namespaces) > 1) { $thread = $namespaces[$namespacePos+1]; $last[$thread]['thread'] = $thread; $last[$thread]['date'] = $val["time"]; $last[$thread]['user'] = $val["user"]; } } foreach($last as $line) { $blub[$line['date']] = $line['thread']; } krsort($blub); foreach($blub as $thread) { $list[$thread] = $last[$thread]; } $renderer->table_open(); $renderer->tablerow_open(); $renderer->tableheader_open(); $renderer->doc .= "Thread"; $renderer->tableheader_close(); $renderer->tableheader_open(); $renderer->doc .= "geändert"; $renderer->tableheader_close(); $renderer->tableheader_open(); $renderer->doc .= "von"; $renderer->tableheader_close(); $renderer->tablerow_close(); $max = 15; $i = 1; foreach($list as $thread) { if($i>$max) { break; } $i++; $goodName = $this->getHeader($dir."/".$thread['thread']."/start.txt"); $renderer->tablerow_open(); $renderer->tablecell_open(); $renderer->internallink(":$currentNamespace$goodName:start", $goodName); $renderer->tablecell_close(); $renderer->tablecell_open(); $renderer->doc .= date($conf['dformat'], $thread['date']); $renderer->tablecell_close(); $renderer->tablecell_open(); $renderer->doc .= $thread['user']; $renderer->tablecell_close(); $renderer->tablerow_close(); } $renderer->table_close(); } function unreadedThreads(&$renderer) { $dir = $this->getDir(); $accesslog = $this->readAccess(); $changelog = $this->readChanges(); $changed = array(); $readed = array(); $unreadedThreads = array(); $currentNamespace = $this->getNamespace(); $namespacePos = $this->getNamespacePos(); foreach($changelog as $key => $val) { $namespaces = split(":", $val["page"]); if($this->isCurrentNamespace($val["page"]) and $namespaces[$namespacePos+1] != "start" and count($namespaces) > 1) { $thread = $namespaces[$namespacePos+1]; $lastChange = $val["time"]; $changed[$thread] = $lastChange; } } foreach($accesslog as $key => $val) { if($val["user"] == $_SERVER["REMOTE_USER"]) { $namespaces = split("/", $val["page"]); $namespaceOK = str_replace("/", ":", $val["page"]); if($this->isCurrentNamespace($namespaceOK) and $namespaces[$namespacePos+1] != "start" and count($namespaces) > 1) { $thread = $namespaces[$namespacePos+1]; $lastReading = $val["time"]; $readed[$thread] = $lastReading; } } } foreach($changed as $key => $val) { if(!array_key_exists($key, $readed)) { $unreadedThreads[] = $key; } elseif($readed[$key] < $changed[$key]) { $unreadedThreads[] = $key; } } $renderer->listu_open(); if(count($unreadedThreads) == 0) { $renderer->listitem_open(1); $renderer->doc.= "Keine ungelesenen Threads."; $renderer->listitem_close(); } else { foreach($unreadedThreads as $key => $val) { $filename = $dir.$val; $thread = $this->getHeader($filename."/start.txt"); $renderer->listitem_open(1); $renderer->internallink(":$currentNamespace$thread:start", $thread); $renderer->listitem_close(); } } $renderer->listu_close(); } function listThreads(&$renderer) { $dir = $this->getDir(); $currentNamespace = $this->getNamespace(); $threads = array(); $temp = opendir($dir); while($file = readdir($temp)) { if($file != "." && $file != "..") { $filename = $dir.$file; if(is_dir($filename)) { $threads[] = $this->getHeader($filename."/start.txt"); } } } natcasesort($threads); $renderer->listu_open(); foreach($threads as $thread) { $renderer->listitem_open(1); $renderer->internallink(":$currentNamespace$thread:start", $thread); $renderer->listitem_close(); } $renderer->listu_close(); } function newThread(&$renderer) { $dir = $this->getDir(); $currentNamespace = cleanID($this->getNamespace()); if(isset($_POST['newthread'])) { $dir = $dir.cleanID($_POST['newthread']); mkdir($dir); $content = "====== ".$_POST['newthread']." ======\n"; $content .= "~~BLIKI~~\n"; fputs(fopen($dir."/start.txt", w), $content); $renderer->strong_open(); $renderer->internallink(".:".$_POST['newthread'].":start", $_POST['newthread']); $renderer->strong_close(); } else { $txt = ''; $txt .= '
'; $txt .= 'Thread-Titel: '; $txt .= ''; $txt .= ''; $txt .= '
'; $renderer->doc .= $txt; } } function getHeader($file) { $content = file($file); $header = trim(str_replace("=", "", $content[0])); return $header; } function sortArray($array) { foreach($array as $line) { $blub[$line['date']] = $line['thread']; } krsort($blub); foreach($blub as $thread) { $gugu[$thread] = $array[$thread]; } return $gugu; } function readAccess() { global $conf; $pattern = '!^([^ ]+) ([^ ]+) ([^ ]+) \[([^\]]+)\] "([^ ]+) ([^ ]+) ([^/]+)/([^"]+)" ([^ ]+) ([^ ]+) ([^ ]+) (.+)!'; $file = file($conf["accesslog"]); for($i=0; $isplitDate($result[4]); $time = $date["year"]."-".$date["month"]."-".$date["day"]." ".$date["hour"].":".$date["minute"].":".$date["second"]; $timestamp = strtotime($time); $fileline["logLine"] = $line; $fileline["host"] = $result[1]; $fileline["user"] = $result[3]; $fileline["time"] = $timestamp; $fileline["method"] = $result[5]; $fileline["page"] = $result[6]; $fileline["protocol"] = $result[7]."/".$result[8]; $fileline["status"] = $result[9]; $fileline["size"] = $result[10]; $fileline["agent"] = $result[12]; $accesslog[] = $fileline; } return $accesslog; } function readChanges() { global $conf; $handle = fopen($conf["changelog"], "r"); while ($log = fscanf($handle, "%s\t%s\t%s\t%s\t%s\n")) { list ($time, $ip, $page, $user, $action) = $log; $line["time"] = $time; $line["ip"] = $ip; $line["page"] = $page; $line["user"] = $user; $line["action"] = $action; $changelog[] = $line; } return $changelog; } function getDir() { global $ID; $fp = wikiFN($ID); $result = substr($fp, 0, strrpos($fp, '/'))."/"; return $result; } function isCurrentNamespace($ns) { $testNS = split(":", $ns); $currentNS = split(":", $this->getNamespace()); if(count($currentNS) > count($testNS)) { return false; } for($i=0; $igetNamespacePos(); $result = ""; for($i=0; $i<=$pos; $i++) { $result.= $namespaces[$i].":"; } return $result; } function getNamespacePos() { global $ID; $namespaces = split(":", $ID); $currentNamespace = count($namespaces)-2; return $currentNamespace; } function splitDate($date) { $arr['day'] = substr($date, 0, 2); $arr['month'] = substr($date, 3, 3); $arr['year'] = substr($date, 7, 4); $arr['hour'] = substr($date, 12, 2); $arr['minute'] = substr($date, 15, 2); $arr['second'] = substr($date, 18, 2); switch($arr['month']) { case 'Jan': $arr['month'] = "01"; break; case 'Feb': $arr['month'] = "02"; break; case 'Mar': $arr['month'] = "03"; break; case 'Apr': $arr['month'] = "04"; break; case 'May': $arr['month'] = "05"; break; case 'Jun': $arr['month'] = "06"; break; case 'Jul': $arr['month'] = "07"; break; case 'Aug': $arr['month'] = "08"; break; case 'Sep': $arr['month'] = "09"; break; case 'Oct': $arr['month'] = "10"; break; case 'Nov': $arr['month'] = "11"; break; case 'Dec': $arr['month'] = "12"; break; } return $arr; } }
===== Discussion ===== > Can you give me a short description of how you get this plugin to work and what you have to change at the dokuwiki-installation? I know, this is still under development :) \\ --- //[[mirko@romstadt.net|Mirko Romstadt]] 2006-09-22 13:00// * I tried to use your forum in my blog by adding a folder called forum as this path: hali-sy.com/lib/plugins/forum/syntax.php but i failed, so can you give me the suitable instructions for using Diskussion Forum? [[hali83@cec.sy|M. Bashir Al-Noimi]] \\ \\ ---- 2011-10-31 [[user>Taggic]] -> tested following on 2011-05-25a “Rincewind” >The php code has to be modified a slightly. It still has problems but it works. The plugin __**depends**__ on [[plugin:bliki|bliki plugin]], which has to be installed and modified also. I will do no further modification due to it does not deliver what I need but wanted to give you the things I have worked out so far. 'Thomas Preißler, modified by Taggic', 'email' => 'ding280@gmx.de; taggic@t-online.de', 'date' => '2011-10-31', 'name' => 'Forum', 'desc' => 'Zeigt die letzten Änderungen im Forum an', 'url' => 'http://www.dokuwiki.org/plugin:diskussion_forum', ); } function getType(){ return 'substition'; } //function getPType(){ return 'block'; } function getSort(){ return 169; } function connectTo($mode) { $this->Lexer->addSpecialPattern('~~FORUM:\w+~~', $mode, 'plugin_forum'); } /** * Handle the match */ function handle($match, $state, $pos, &$handler) { $array[] = strtolower(substr($match,8,-2)); return $array; } function render($mode, &$renderer, $data) { $call = $data[0]; switch ($call) { case 'lastthreads': $this->lastThreads($renderer); break; case 'listthreads': $this->listThreads($renderer); break; case 'newthread': $this->newThread($renderer); break; case 'unreaded': $this->unreadedThreads($renderer); break; } } function lastThreads(&$renderer) { global $conf; $dir = $this->getDir(); $loglines = $this->readChanges(); $currentNamespace = $this->getNamespace(); $namespacePos = $this->getNamespacePos(); $last = array(); $blub = array(); $list = array(); foreach($loglines as $key => $val) { $namespaces = split(":", $val["page"]); $namespacePos = $this->getNamespacePos(); if($this->isCurrentNamespace($val["page"]) and $namespaces[$namespacePos+1] != "start" and count($namespaces) > 1) { $thread = $namespaces[$namespacePos+1]; $last[$thread]['thread'] = $thread; $last[$thread]['date'] = $val["time"]; $last[$thread]['user'] = $val["user"]; } } foreach($last as $line) { $blub[$line['date']] = $line['thread']; } krsort($blub); foreach($blub as $thread) { $list[$thread] = $last[$thread]; } $renderer->table_open(); $renderer->tablerow_open(); $renderer->tableheader_open(); $renderer->doc .= "Thread"; $renderer->tableheader_close(); $renderer->tableheader_open(); $renderer->doc .= "geändert"; $renderer->tableheader_close(); $renderer->tableheader_open(); $renderer->doc .= "von"; $renderer->tableheader_close(); $renderer->tablerow_close(); $max = 15; $i = 1; foreach($list as $thread) { if($i>$max) { break; } $i++; $goodName = $this->getHeader($dir."/".$thread['thread']."/start.txt"); $renderer->tablerow_open(); $renderer->tablecell_open(); $renderer->internallink(":$currentNamespace$goodName:start", $goodName); $renderer->tablecell_close(); $renderer->tablecell_open(); $renderer->doc .= date($conf['dformat'], $thread['date']); $renderer->tablecell_close(); $renderer->tablecell_open(); $renderer->doc .= $thread['user']; $renderer->tablecell_close(); $renderer->tablerow_close(); } $renderer->table_close(); } function unreadedThreads(&$renderer) { $dir = $this->getDir(); $accesslog = $this->readAccess(); $changelog = $this->readChanges(); $changed = array(); $readed = array(); $unreadedThreads = array(); $currentNamespace = $this->getNamespace(); $namespacePos = $this->getNamespacePos(); foreach($changelog as $key => $val) { $namespaces = split(":", $val["page"]); if($this->isCurrentNamespace($val["page"]) and $namespaces[$namespacePos+1] != "start" and count($namespaces) > 1) { $thread = $namespaces[$namespacePos+1]; $lastChange = $val["time"]; $changed[$thread] = $lastChange; } } foreach($accesslog as $key => $val) { if($val["user"] == $_SERVER["REMOTE_USER"]) { $namespaces = split("/", $val["page"]); $namespaceOK = str_replace("/", ":", $val["page"]); if($this->isCurrentNamespace($namespaceOK) and $namespaces[$namespacePos+1] != "start" and count($namespaces) > 1) { $thread = $namespaces[$namespacePos+1]; $lastReading = $val["time"]; $readed[$thread] = $lastReading; } } } foreach($changed as $key => $val) { if(!array_key_exists($key, $readed)) { $unreadedThreads[] = $key; } elseif($readed[$key] < $changed[$key]) { $unreadedThreads[] = $key; } } $renderer->listu_open(); if(count($unreadedThreads) == 0) { $renderer->listitem_open(1); $renderer->doc.= "Keine ungelesenen Threads."; $renderer->listitem_close(); } else { foreach($unreadedThreads as $key => $val) { $filename = $dir.$val; $thread = $this->getHeader($filename."/start.txt"); $renderer->listitem_open(1); $renderer->internallink(":$currentNamespace$thread:start", $thread); $renderer->listitem_close(); } } $renderer->listu_close(); } function listThreads(&$renderer) { $dir = $this->getDir(); $currentNamespace = $this->getNamespace(); $threads = array(); $temp = opendir($dir); while($file = readdir($temp)) { if($file != "." && $file != "..") { $filename = $dir.$file; if(is_dir($filename)) { $threads[] = $this->getHeader($filename."/start.txt"); } } } natcasesort($threads); $renderer->listu_open(); foreach($threads as $thread) { $renderer->listitem_open(1); $renderer->internallink(":$currentNamespace$thread:start", $thread); $renderer->listitem_close(); } $renderer->listu_close(); } function newThread(&$renderer) { $dir = $this->getDir(); $currentNamespace = cleanID($this->getNamespace()); if(isset($_POST['newthread'])) { $dir = $dir.cleanID($_POST['newthread']); mkdir($dir); $content = "====== ".$_POST['newthread']." ======\n"; $content .= "~~BLIKI~~\n"; fputs(fopen($dir."/start.txt", w), $content); $renderer->strong_open(); $renderer->internallink(".:".$_POST['newthread'].":start", $_POST['newthread']); $renderer->strong_close(); } else { $txt = ''; $txt .= '
'; $txt .= 'Thread-Titel: '; $txt .= ''; $txt .= ''; $txt .= '
'; $renderer->doc .= $txt; } } function getHeader($file) { $content = file($file); $header = trim(str_replace("=", "", $content[0])); return $header; } function sortArray($array) { foreach($array as $line) { $blub[$line['date']] = $line['thread']; } krsort($blub); foreach($blub as $thread) { $gugu[$thread] = $array[$thread]; } return $gugu; } function readAccess() { global $conf; $pattern = '!^([^ ]+) ([^ ]+) ([^ ]+) \[([^\]]+)\] "([^ ]+) ([^ ]+) ([^/]+)/([^"]+)" ([^ ]+) ([^ ]+) ([^ ]+) (.+)!'; $file = file($conf["accesslog"]); for($i=0; $isplitDate($result[4]); $time = $date["year"]."-".$date["month"]."-".$date["day"]." ".$date["hour"].":".$date["minute"].":".$date["second"]; $timestamp = strtotime($time); $fileline["logLine"] = $line; $fileline["host"] = $result[1]; $fileline["user"] = $result[3]; $fileline["time"] = $timestamp; $fileline["method"] = $result[5]; $fileline["page"] = $result[6]; $fileline["protocol"] = $result[7]."/".$result[8]; $fileline["status"] = $result[9]; $fileline["size"] = $result[10]; $fileline["agent"] = $result[12]; $accesslog[] = $fileline; } return $accesslog; } function readChanges() { global $conf; $handle = fopen($conf["changelog"], "r"); while ($log = fscanf($handle, "%s\t%s\t%s\t%s\t%s\n")) { list ($time, $ip, $page, $user, $action) = $log; $line["time"] = $time; $line["ip"] = $ip; $line["page"] = $page; $line["user"] = $user; $line["action"] = $action; $changelog[] = $line; } return $changelog; } function getDir() { global $ID; $fp = wikiFN($ID); $result = substr($fp, 0, strrpos($fp, '/'))."/"; return $result; } function isCurrentNamespace($ns) { $testNS = split(":", $ns); $currentNS = split(":", $this->getNamespace()); if(count($currentNS) > count($testNS)) { return false; } for($i=0; $igetNamespacePos(); $result = ""; for($i=0; $i<=$pos; $i++) { $result.= $namespaces[$i].":"; } return $result; } function getNamespacePos() { global $ID; $namespaces = split(":", $ID); $currentNamespace = count($namespaces)-2; return $currentNamespace; } function splitDate($date) { $arr['day'] = substr($date, 0, 2); $arr['month'] = substr($date, 3, 3); $arr['year'] = substr($date, 7, 4); $arr['hour'] = substr($date, 12, 2); $arr['minute'] = substr($date, 15, 2); $arr['second'] = substr($date, 18, 2); switch($arr['month']) { case 'Jan': $arr['month'] = "01"; break; case 'Feb': $arr['month'] = "02"; break; case 'Mar': $arr['month'] = "03"; break; case 'Apr': $arr['month'] = "04"; break; case 'May': $arr['month'] = "05"; break; case 'Jun': $arr['month'] = "06"; break; case 'Jul': $arr['month'] = "07"; break; case 'Aug': $arr['month'] = "08"; break; case 'Sep': $arr['month'] = "09"; break; case 'Oct': $arr['month'] = "10"; break; case 'Nov': $arr['month'] = "11"; break; case 'Dec': $arr['month'] = "12"; break; } return $arr; } }
----