1<?php
2/**
3 *  Tools Action component
4 *
5 *  $Id: action.php 111 2008-12-25 19:33:15Z wingedfox $
6 *  $HeadURL: https://svn.debugger.ru/repos/common/DokuWiki/BookmarkMe/tags/BookmarkMe.v0.8/action.php $
7 *
8 *  @lastmodified $Date: 2008-12-25 22:33:15 +0300 (???, 25 ??? 2008) $
9 *  @license      LGPL 2 (http://www.gnu.org/licenses/lgpl.html)
10 *  @author       Ilya Lebedev <ilya@lebedev.net>
11 *  @version      $Rev: 111 $
12 *  @copyright    (c) 2005-2007, Ilya Lebedev
13 */
14
15if(!defined('DOKU_INC')) die();
16
17if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
18require_once(DOKU_PLUGIN.'action.php');
19
20class action_plugin_tools extends DokuWiki_Action_Plugin {
21
22  /**
23   *  Constants for controlling toolbar show
24   */
25  var $TOOLS_SHOW_OFF    = 0;
26  var $TOOLS_SHOW_ON     = 1;  // equals to bottom, pre-0.7 compatible
27  var $TOOLS_SHOW_BOTTOM = 1;
28  var $TOOLS_SHOW_TOP    = 2;
29  var $TOOLS_SHOW_BOTH   = 3;
30
31  /**
32   * return some info
33   */
34  function getInfo(){
35    return array (
36      'author' => 'Luigi Micco',
37      'email' => 'l.micco@tiscali.it',
38      'date' => '2012-07-27',
39      'name' => 'Tools plugin (action component)',
40      'desc' => 'Insert toolbar with tools on pages<br />Allows to override config options for a certain pages<br />Syntax: ~~TOOLS:(off|top|bottom|both)~~.',
41      'url' => 'http://www.dokuwiki.org/plugin:tools',
42    );
43  }
44
45
46  /*
47   * plugin should use this method to register its handlers with the dokuwiki's event controller
48   */
49  function register(&$controller) {
50      $controller->register_hook('TPL_ACT_RENDER','AFTER',$this,'tools',array("show" => $this->TOOLS_SHOW_BOTTOM));
51      $controller->register_hook('TPL_ACT_RENDER','BEFORE',$this,'tools',array("show" => $this->TOOLS_SHOW_TOP));
52  }
53  /**
54   *  Prints tools icons, if allowed
55   *
56   *  @author Ilya Lebedev <ilya@lebedev.net>
57   */
58  function tools(&$event, $param) {
59    global $ID;
60    global $conf;
61
62    if ($event->data != 'show') return; // nothing to do for us
63
64    $show = $this->getConf('show_tools');
65
66    //Check if tools is allowed
67    $bm = p_get_metadata($ID,'tools');
68
69    if (null !== $bm) {
70        $bm = 'TOOLS_SHOW_'.strtoupper($bm);
71        $bm = (int)$this->$bm;
72        if (is_numeric($bm))
73            $show = $bm;
74    }
75
76    if ( !($show & $this->TOOLS_SHOW_BOTTOM & $param['show'])
77      && !($show & $this->TOOLS_SHOW_TOP & $param['show']))
78        return;
79
80    /*
81    *  assume that page does not exists
82    */
83    $exists = false;
84    $id = $ID;
85    resolve_pageid('',$id,$exists);
86
87    /*
88    *  find skip pages
89    */
90    $sp = join("|",explode(",",preg_quote($this->getConf('skip_ids'))));
91
92    if (!$exists || preg_match("/$sp/i",$ID))
93        return;
94
95    $be = explode(",",$this->getConf('tools'));
96
97    $ip = dirname(__FILE__)."/img/";
98    $iu = DOKU_URL."lib/plugins/tools/img/";
99    $title = p_get_first_heading($ID);
100    if (!$title) $title = $ID;
101
102    $pml = wl($ID,'',true);
103
104    $html = array('<ul class="tools">');
105
106    $book_lng = htmlspecialchars($this->getLang('tools_title'));
107
108    $tools = array(
109        'print' => wl($ID, array("rev" =>(int)$rev, "mddo" => "print"), false, "&")
110       ,'email' => wl($ID, array('rev' =>(int)$rev, 'do' => 'tellafriend'), false, '&')
111       ,'odt' => wl($ID, array("rev" =>(int)$rev, "do" => "export_odt"), false, "&")
112       ,'pdf' => wl($ID, array("rev" =>(int)$rev, "do" => "export_pdf"), false, "&")
113       ,'csv' => wl($ID, array("rev" =>(int)$rev, "do" => "export_csv"), false, "&")
114       ,'timeline' => wl($ID, array("rev" =>(int)$rev, "do" => "export_timeline"), false, "&")
115       ,'bookcreator' => wl($ID, array("rev" =>(int)$rev, "do" => "addtobook"), false, "&")
116    );
117
118    foreach ($tools as $k=>$v) {
119        $i = strtolower( str_replace( array("."," "),array("" ,"_"),$k)).".png";
120        if (in_array($k,$be)) {
121          $label = '';
122          $image = '';
123          if (($this->getConf('show_link') == 0) || ($this->getConf('show_link') == 2)) {
124            if (file_exists($ip.$i)) {
125              list($w,$h) = @getimagesize($ip.$i);
126              $image = "<img src='$iu$i' width='$w' height='$h' alt='".$this->getLang('tools_'.$k)."' title='".$this->getLang('tools_'.$k)."' />";
127            }
128          }
129          if (($this->getConf('show_link') == 1) || ($this->getConf('show_link') == 2)) {
130            $label = $this->getLang('tools_'.$k);
131          }
132          $html[] = "<li><a href='$v' >".$image.$label."</a></li>";
133        }
134
135    }
136
137    /*
138    *  show header only if allowed in config
139    */
140    if ($this->getConf('show_header')) $html[] = '<li class="head">'.$this->getLang('tools').'</li>';
141
142    $html[] = '</ul>';
143    if (sizeof($html)>2) echo join("\n",$html);
144  }
145}
146