1<?php
2// must be run within DokuWiki
3if(!defined('DOKU_INC')) die();
4
5if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
6require_once DOKU_PLUGIN.'syntax.php';
7
8/**
9 * All DokuWiki plugins to extend the parser/rendering mechanism
10 * need to inherit from this class
11 */
12class helper_plugin_filterrss extends dokuwiki_plugin
13{
14    function getMethods(){
15      $result = array();
16      $result[] = array(
17	'name'   => 'bbcode_parse',
18	'desc'   => 'parse bbcode to html',
19	'params' => array('bbcode_input' => 'string'),
20	'return' => array('html_output' => 'string'),
21      );
22      $result[] = array(
23	'name'   => 'int_sort',
24	'desc'   => 'numeric sort assoc array using key passed in the second argument',
25	'params' => array('array' => 'array', 'key' => 'string'),
26	'return' => array('sorted_array' => 'array'),
27      );
28      $result[] = array(
29	'name'   => 'nat_sort',
30	'desc'   => 'natural sort assoc array using php strnatcmp function and key passed in the second argument',
31	'params' => array('array' => 'array', 'key' => 'string'),
32	'return' => array('sorted_array' => 'array'),
33      );
34    }
35    function bbcode_parse($bbcode_input)
36    {
37	$bbcode = array("<", ">",
38		    "[list]", "[*]", "[/list]",
39		    "[img]", "[/img]",
40		    "[b]", "[/b]",
41		    "[u]", "[/u]",
42		    "[i]", "[/i]",
43		    '[color=', "[/color]",
44		    "[size=", "[/size]",
45		    '[url=', "[/url]",
46		    "[mail=", "[/mail]",
47		    "[code]", "[/code]",
48		    "[quote]", "[/quote]",
49		    ']');
50	$htmlcode = array("&lt;", "&gt;",
51		    "<ul>", "<li>", "</ul>",
52		    "<img src=\"", "\">",
53		    "<b>", "</b>",
54		    "<u>", "</u>",
55		    "<i>", "</i>",
56		    "<span style=\"color:", "</span>",
57		    "<span style=\"font-size:", "</span>",
58		    '<a href="', "</a>",
59		    "<a href=\"mailto:", "</a>",
60		    "<code>", "</code>",
61		    "<blockquote>", "</blockquote>",
62		    '">');
63	$html_output = str_replace($bbcode, $htmlcode, $bbcode_input);
64	$html_output = nl2br($html_output);//second pass
65	return $html_output;
66    }
67    //Key using in curret cmp function
68    protected static $key = '';
69    protected function nat_key_cmp($a_ar, $b_ar)
70    {
71	$a = $a_ar[self::$key];
72	$b = $b_ar[self::$key];
73	return strnatcmp($a, $b);
74    }
75    protected function int_key_cmp($a_ar, $b_ar)
76    {
77	$a = $a_ar[self::$key];
78	$b = $b_ar[self::$key];
79	if ($a == $b) {
80	    return 0;
81	}
82	return ($a < $b) ? -1 : 1;
83    }
84    function int_sort($array, $key)
85    {
86	self::$key = $key;
87	usort($array, 'self::int_key_cmp');
88	return $array;
89    }
90    function nat_sort($array, $key)
91    {
92	self::$key = $key;
93	usort($array, 'self::nat_key_cmp');
94	return $array;
95    }
96}
97
98