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 /** 25 * return some info 26 */ 27 function getInfo(){ 28 return array( 29 'author' => 'Esther Brunner', 30 'email' => 'wikidesign@gmail.com', 31 'date' => '2007-08-21', 32 'name' => 'Discussion Plugin (comments component)', 33 'desc' => 'Enables discussion features', 34 'url' => 'http://www.wikidesign.ch/en/plugin/discussion/start', 35 ); 36 } 37 38 function getType(){ return 'substition'; } 39 function getPType(){ return 'block'; } 40 function getSort(){ return 230; } 41 42 /** 43 * Connect pattern to lexer 44 */ 45 function connectTo($mode){ 46 if ($mode == 'base'){ 47 $this->Lexer->addSpecialPattern('~~DISCUSSION[^\r\n]*?~~', $mode, 'plugin_discussion_comments'); 48 } 49 } 50 51 /** 52 * Handle the match 53 */ 54 function handle($match, $state, $pos, &$handler){ 55 global $ID, $ACT; 56 57 // strip markup 58 $match = substr($match, 12, -2); 59 60 // split title (if there is one) 61 list($match, $title) = explode('|', $match, 2); 62 63 // assign discussion state 64 if ($match == ':off') $status = 0; 65 else if ($match == ':closed') $status = 2; 66 else $status = 1; 67 68 // get discussion meta file name 69 $file = metaFN($ID, '.comments'); 70 71 $data = array(); 72 if (@file_exists($file)) $data = unserialize(io_readFile($file, false)); 73 if (($data['status'] != $status) || ($data['title'] != $title)){ 74 $data['title'] = $title; 75 $data['status'] = $status; 76 io_saveFile($file, serialize($data)); 77 } 78 79 return $status; 80 } 81 82 function render($mode, &$renderer, $status){ 83 return true; // do nothing -> everything is handled in action component 84 } 85 86} 87 88//Setup VIM: ex: et ts=4 enc=utf-8 :