Add LICENSE
[manlink.git] / syntax.php
1 <?php
2 /*
3  * Manlinks plugin: convert manpage descriptions to links to the manpages.
4  */
5
6 if(!defined('DOKU_INC')) die();
7 if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
8 require_once(DOKU_PLUGIN.'syntax.php');
9
10 class syntax_plugin_manlink extends DokuWiki_Syntax_Plugin {
11
12         function getType() { return 'substition'; }
13         function getPType() { return 'normal'; }
14         function getSort() { return 361; }
15
16         function connectTo($mode) {
17                 $this->Lexer->addSpecialPattern(
18                         '\!?[a-zA-Z0-9_.+\[\]-]*\([0-9]\)',
19                         $mode,
20                         'plugin_manlink');
21         }
22
23         function handle($match, $state, $pos, Doku_Handler $handler){
24                 if ($state != DOKU_LEXER_SPECIAL)
25                         return false;
26
27                 if (substr($match, 0, 1) == "!") {
28                         $handler->_addCall('cdata', array(substr($match, 1)), $pos);
29                         return true;
30                 }
31
32                 $mantarget = $this->getconf('mantarget');
33                 $manpage = preg_replace('/^([a-zA-Z0-9_+\[\].-]*)\(([0-9])\)$/', '\1', $match);
34                 $section = preg_replace('/^([a-zA-Z0-9_+\[\].-]*)\(([0-9])\)$/', '\2', $match);
35
36                 if ($mantarget == 'NetBSD')
37                         $target = 'http://mdoc.su/n/'.$manpage.'.'.$section;
38                 elseif ($mantarget == 'FreeBSD')
39                         $target = 'http://mdoc.su/f/'.$manpage.'.'.$section;
40                 elseif ($mantarget == 'OpenBSD')
41                         $target = 'http://mdoc.su/o/'.$manpage.'.'.$section;
42                 elseif ($mantarget == 'DragonFlyBSD')
43                         $target = 'http://mdoc.su/d/'.$manpage.'.'.$section;
44
45                 $handler->_addCall('externallink', array($target, $match), $pos);
46                 return true;
47         }
48
49         function render($format, Doku_Renderer $renderer, $data) {
50                 return true;
51         }
52 }
53
54 ?>