1<?php
2/**
3 * ShortURL Plugin
4 * based on redirect plugin
5 *
6 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author     Andreas Gohr <andi@splitbrain.org>
8 * @author     Frank Schiebel <frank@linuxmuster.net>
9 */
10
11// must be run within Dokuwiki
12if(!defined('DOKU_INC')) die();
13
14if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
15require_once(DOKU_PLUGIN.'action.php');
16
17class action_plugin_shorturl extends DokuWiki_Action_Plugin {
18
19    /**
20     * register the eventhandlers
21     */
22    function register(&$controller){
23        $controller->register_hook('DOKUWIKI_STARTED',
24                                   'AFTER',
25                                   $this,
26                                   'handle_start',
27                                   array());
28    }
29
30    /**
31     * handle event
32     */
33    function handle_start(&$event, $param){
34        global $ID;
35        global $ACT;
36
37        if($ACT != 'show') return;
38
39        $redirects = confToHash($this->getsavedir().'/shorturl.conf');
40        if($redirects[$ID]){
41            if(preg_match('/^https?:\/\//',$redirects[$ID])){
42                send_redirect($redirects[$ID]);
43            }else{
44                if($this->getConf('showmsg')){
45                    msg(sprintf($this->getLang('redirected'),hsc($ID)));
46                }
47                send_redirect(wl($redirects[$ID] ,'',true));
48            }
49            exit;
50        } else {
51            if ($_GET['generateShortURL'] != "" && auth_quickaclcheck($ID) >= AUTH_READ) {
52                $shorturl =& plugin_load('helper', 'shorturl');
53                if ($shorturl) {
54                    $shortID = $shorturl->autoGenerateShortUrl($ID);
55                }
56            }
57        }
58    }
59
60    /**
61      * get savedir
62      */
63    function getsavedir() {
64        global $conf;
65        if ( $this->getConf('saveconftocachedir') ) {
66            return rtrim($conf['savedir'],"/") . "/cache";
67        } else {
68            return dirname(__FILE__);
69        }
70    }
71
72}
73
74