<?php
/**
 @file       clacks/action.php 
 @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 @author     Luis Machuca Bezzaza <luis [dot] machuca [at] gulix [dot] cl>
 @version    2018-11-12
**/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
if(!defined('DW_LF')) define('DW_LF',"\n");

if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
define('THIS_PLUGIN', DOKU_PLUGIN.'noiewarning/');
require_once(DOKU_PLUGIN.'action.php');
require_once(DOKU_INC.'inc/confutils.php');
require_once(DOKU_INC.'inc/infoutils.php'); // for notify facilities

/**
 * All DokuWiki plugins to extend the admin function
 * need to inherit from this class
 */
class action_plugin_clacks extends DokuWiki_Action_Plugin {

	var $oh;

    function action_plugin_clacks () {
        $this->oh = $this->getConf('overhead');
        $arr = explode('\n', $this->oh);
        $this->oh= $arr[0];
        // load options from configuration
    }

    /***
     * Register its handlers with the DokuWiki's event controller
     */
    function register(Doku_Event_Handler $controller) {
        global $ACT;
        global $conf;
        if ($ACT != 'show') return;
        $controller->register_hook(
			'ACTION_HEADERS_SEND','BEFORE', $this, 'GNU', array()
		);
/*
		if ($this->getConf('alsometa')!=='') {
			$controller->register_hook(
				'TPL_METAHEADER_OUTPUT','BEFORE', $this, 'GNU_Meta', array()
			);
		}
*/
    }


    function GNU (Doku_Event $event, $param) {
        @file_put_contents('/tmp/oh.txt', $this->oh);
        $event->data[] = "X-Clacks-Overhead: GNU {$this->oh}";
    // end function
    }

    function GNU_Meta (Doku_Event $event, $param) {
        $pre = 'X-Clacks-Overhead';
        $event->data['meta'][] = array( 'http-equiv' => 'X-Clacks-Overhead'
			, 'content' => 'GNU '. $this->oh
			);
    // end function
    }

        


}
