<?php
/**
 * Qstat Plugin: Displays information about Quake 3 server (or compatible
 * like Openarena).
 *
 * Syntax: {{qstat}} - will be replaced with information about the server
 * 
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Mathieu <mathieu@guim.info>
 */
 
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'action.php');
 
/**
 * All DokuWiki plugins to extend the parser/rendering mechanism
 * need to inherit from this class
 */
class action_plugin_dwqstat extends DokuWiki_Action_Plugin {

	/**
	 * Get an associative array with plugin info.
	 *
	 * <p>
	 * The returned array holds the following fields:
	 * <dl>
	 * <dt>author</dt><dd>Author of the plugin</dd>
	 * <dt>email</dt><dd>Email address to contact the author</dd>
	 * <dt>date</dt><dd>Last modified date of the plugin in
	 * <tt>YYYY-MM-DD</tt> format</dd>
	 * <dt>name</dt><dd>Name of the plugin</dd>
	 * <dt>desc</dt><dd>Short description of the plugin (Text only)</dd>
	 * <dt>url</dt><dd>Website with more information on the plugin
	 * (eg. syntax description)</dd>
	 * </dl>
	 * @param none
	 * @return Array Information about this plugin class.
	 * @public
	 * @static
	 */
	function getInfo(){
		return array(
				'author' => 'Mathieu',
				'email'  => 'mathieu@guim.info',
				'date'   => rtrim(io_readFile(DOKU_PLUGIN.'dwqstat/VERSION.txt')),
				'name'   => 'DWQstat Plugin for openarena.tuxfamily.org',
				'desc'   => 'Provide informations about a Quake3 (or compatible) server',
				'url'    => 'http://www.guim.info/dokuwiki/dev:qstat',
			    );
	}

	/*
	 * plugin should use this method to register its handlers with the dokuwiki's event controller
	 */
	function register(&$controller) {
		$controller->register_hook('PARSER_CACHE_USE', 'BEFORE',  $this, '_purgecache');
	}

	/**
	 * Check for pages changes and eventually purge cache.
	 */
	function _purgecache(&$event, $param) {
		global $ID;
		$str = rawWiki($ID);
		if (strpos($str, '{{qstat') !== false) {
			$event->preventDefault();
			$event->stopPropagation();
			$event->result = false;
		}
	}

}
?>
