1<?php 2/** 3 * Discussion Plugin 4 * 5 * Enables/disables discussion features based on config settings. 6 * 7 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 8 * @author Esther Brunner <wikidesign@gmail.com> 9 * @author Dave Lawson <dlawson@masterytech.com> 10 */ 11 12// must be run within Dokuwiki 13if(!defined('DOKU_INC')) die(); 14 15if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 16require_once(DOKU_PLUGIN.'syntax.php'); 17 18/** 19 * All DokuWiki plugins to extend the parser/rendering mechanism 20 * need to inherit from this class 21 */ 22class syntax_plugin_discussion_comments extends DokuWiki_Syntax_Plugin { 23 24 function getType() { return 'substition'; } 25 function getPType() { return 'block'; } 26 function getSort() { return 230; } 27 28 /** 29 * Connect pattern to lexer 30 */ 31 function connectTo($mode) { 32 if ($mode == 'base') { 33 $this->Lexer->addSpecialPattern('~~DISCUSSION[^\r\n]*?~~', $mode, 'plugin_discussion_comments'); 34 } 35 } 36 37 /** 38 * Handle the match 39 */ 40 function handle($match, $state, $pos, &$handler) { 41 global $ID, $ACT; 42 43 // strip markup 44 $match = substr($match, 12, -2); 45 46 // split title (if there is one) 47 list($match, $title) = explode('|', $match, 2); 48 49 // assign discussion state 50 if ($match == ':off') $status = 0; 51 else if ($match == ':closed') $status = 2; 52 else $status = 1; 53 54 if ($ACT == 'preview') return; 55 56 // get discussion meta file name 57 $file = metaFN($ID, '.comments'); 58 59 $data = array(); 60 if (@file_exists($file)) { 61 $data = unserialize(io_readFile($file, false)); 62 } 63 // only save when the status or title was actually changed, the timestamp of the .comments file is used 64 // as sorting criteria for the threads view! 65 // note that isset can't be used for the first test as isset returns false for NULL values! 66 if (!array_key_exists('title', $data) || $data['title'] !== $title || !isset($data['status']) || $data['status'] !== $status) { 67 $data['title'] = $title; 68 $data['status'] = $status; 69 io_saveFile($file, serialize($data)); 70 } 71 72 return $status; 73 } 74 75 function render($mode, &$renderer, $status) { 76 return true; // do nothing -> everything is handled in action component 77 } 78} 79// vim:ts=4:sw=4:et:enc=utf-8: 80