1<?php
2/**
3 * Mediasyntax Plugin, redirect component: Mediawiki style redirects
4 * based on the cool goto plugin by Allen Ormond
5 *
6 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author     Thorsten Staerk
8 */
9class syntax_plugin_mediasyntax_redirect extends DokuWiki_Syntax_Plugin
10{
11
12  function getType(){ return 'formatting'; }
13  function getSort(){ return 58; }
14
15  function connectTo($mode)
16  {
17    $this->Lexer->addEntryPattern(
18      '^[\#]*REDIRECT[ ]+\[\[',
19      $mode,
20      'plugin_mediasyntax_redirect'
21    );
22    $this->Lexer->addEntryPattern(
23      '^[\#]*redirect[ ]+\[\[',
24      $mode,
25      'plugin_mediasyntax_redirect'
26    );
27    $this->Lexer->addEntryPattern(
28      '^[\#]*reDirect[ ]+\[\[',
29      $mode,
30      'plugin_mediasyntax_redirect'
31    );
32  }
33
34  function postConnect()
35  {
36    $this->Lexer->addExitPattern(
37      '\]\]',
38      'plugin_mediasyntax_redirect'
39    );
40  }
41
42  function handle($match, $state, $pos, Doku_Handler $handler)
43  {
44    if ($state == DOKU_LEXER_UNMATCHED)
45    {
46      if ($pos==13) return $match; // position must be at the beginning of the page
47    }
48  }
49
50  function render($mode, Doku_Renderer $renderer, $data)
51  {
52    if (strlen($data)>0)
53    {
54      $delay = $this->getConf('redirectPauseTime',2);
55      $renderer->doc = 'You will be redirected in '.$delay.' seconds to <a href="' . wl($data) . '">'.$data.'</a>';
56      $renderer->doc .= '<script>url="'.wl($data).'";setTimeout("location.href=url",'.($delay*1000).');</script>';
57    }
58    return true;
59  }
60}
61
62//Setup VIM: ex: et ts=4 enc=utf-8 :
63