<?php
/**
 * DokuWiki Plugin wikistats (Syntax Component)
 *
 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
 * @author  Chris4x4 <4x4.chris@gmail.com>
 */

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

if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');

class helper_plugin_wikistats extends DokuWiki_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 confToHash(dirname(__FILE__).'/plugin.info.txt');
    }

    function getMethods()
    {
        $result = array();
        $result[] = array(
            'name'   => 'add_stats_link',
            'desc'   => 'Include a html link',
            'params' => array(),
            'return' => array()
        );
        return $result;
    }

    /**
     * Create the HTML for the stats link
     *
     * If $return is set to FALSE, will directly echo the HTML
     *  
     * @param bool $return
     * @return string
     */
    public function add_stats_link($return = false)
    {
        global $conf;

        $label = $this->getLang('btn_display_stats');
        if (!$label) {
            // Translation not found
            $label = 'Stats';
        }
        $tip = htmlspecialchars($label);

        // Filter id (without urlencoding)
        $id = idfilter($this->getConf('stats_page'), false);
        $url = DOKU_BASE.DOKU_SCRIPT.'/'.$id;

        $ret = '<li><a class="action wikistats" href="'.$url.'" rel="nofollow" title="'.$label.'">'.$label.'</a></li>';

        if (!$return) echo $ret;
        return $ret;
    }
}

