<?php
/**
 * DokuWiki Plugin custombuttons (Admin Component)
 *
 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
 * @author  Xanthopoulos Constantinos <conx@xanthopoulos.info>
 */

// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();

if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');

require_once DOKU_PLUGIN.'admin.php';

class admin_plugin_codebutton2 extends DokuWiki_Admin_Plugin
{

	function getInfo(){
		return array(
			'author' => 'Reshetnikov Anton',
			'email'  => 'resheto@gmail.com',
			'date'   => '2010-12-11',
			'name'   => 'CodeButton2',
			'desc'   => 'A plugin for adding code buttons',
			'url'    => 'http://www.dokuwiki.org/plugin:codebutton2',
		);
	}

	
	function forAdminOnly()
	{
		 return true;
	}

	function handle()
	{
		global $config_cascade;
	
		if (isset($_REQUEST['config']))
	       	{
			$fh = fopen(DOKU_PLUGIN."codebutton2/config.ini", 'w');
			
			if($fh)
			{
				fwrite($fh, $_REQUEST["config"]);
			}
			fclose($fh);
			@touch(reset($config_cascade['main']['local']));
		}
	}

	function html()
	{
		global $ID;
	
		ptln('<h1>CodeButtons2 Configurations</h1>');
		ptln('<div>Add your code buttons in CODE block of your edit toolbar the following format:<br><pre class="code">&lt;button name&gt; = &lt;geshi code name&gt;<br></pre>Example:</br><pre class="code">.bat=winbatch</pre>');
		ptln('It will produce button with name ".bat". Push on this button surround your selected text with &lt;code winbatch&gt; &lt;/code&gt;</div>');
		ptln('<form name="frm" action="'.wl($ID).'" method="post">');
		ptln('<input type="hidden" name="do"   value="admin" />');
		ptln('<input type="hidden" name="page" value="'.$this->getPluginName().'" />');
		ptln('<input type="hidden" name="id" value="'.$ID.'" />');
		ptln('<textarea rows=10 cols=50 name="config">');
		echo file_get_contents(DOKU_PLUGIN."codebutton2/config.ini");
		ptln('</textarea>');
		ptln('<br><input type=submit value="Save"></form>');
	}
}

// vim:ts=4:sw=4:et:enc=utf-8:
