1<?php
2/**
3 * DokuWiki Plugin wikistats (Syntax Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Chris4x4 <4x4.chris@gmail.com>
7 */
8
9// must be run within Dokuwiki
10if (!defined('DOKU_INC')) die();
11
12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13
14class helper_plugin_wikistats extends DokuWiki_Plugin
15{
16   /**
17    * Get an associative array with plugin info.
18    *
19    * <p>
20    * The returned array holds the following fields:
21    * <dl>
22    * <dt>author</dt><dd>Author of the plugin</dd>
23    * <dt>email</dt><dd>Email address to contact the author</dd>
24    * <dt>date</dt><dd>Last modified date of the plugin in
25    * <tt>YYYY-MM-DD</tt> format</dd>
26    * <dt>name</dt><dd>Name of the plugin</dd>
27    * <dt>desc</dt><dd>Short description of the plugin (Text only)</dd>
28    * <dt>url</dt><dd>Website with more information on the plugin
29    * (eg. syntax description)</dd>
30    * </dl>
31    * @param none
32    * @return Array Information about this plugin class.
33    * @public
34    * @static
35    */
36    function getInfo()
37    {
38        return confToHash(dirname(__FILE__).'/plugin.info.txt');
39    }
40
41    function getMethods()
42    {
43        $result = array();
44        $result[] = array(
45            'name'   => 'add_stats_link',
46            'desc'   => 'Include a html link',
47            'params' => array(),
48            'return' => array()
49        );
50        return $result;
51    }
52
53    /**
54     * Create the HTML for the stats link
55     *
56     * If $return is set to FALSE, will directly echo the HTML
57     *
58     * @param bool $return
59     * @return string
60     */
61    public function add_stats_link($return = false)
62    {
63        global $conf;
64
65        $label = $this->getLang('btn_display_stats');
66        if (!$label) {
67            // Translation not found
68            $label = 'Stats';
69        }
70        $tip = htmlspecialchars($label);
71
72        // Filter id (without urlencoding)
73        $id = idfilter($this->getConf('stats_page'), false);
74        $url = DOKU_BASE.DOKU_SCRIPT.'/'.$id;
75
76        $ret = '<li><a class="action wikistats" href="'.$url.'" rel="nofollow" title="'.$label.'">'.$label.'</a></li>';
77
78        if (!$return) echo $ret;
79        return $ret;
80    }
81}
82
83