xref: /plugin/ireadit/helper.php (revision 4b88ed9d36b890d6d2047a21fbd0fb6a97d3584c)
1<?php
2/**
3 * Plugin Now: Inserts a timestamp.
4 *
5 * @license    GPL 3 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Szymon Olewniczak <szymon.olewniczak@rid.pl>
7 */
8
9// must be run within DokuWiki
10if(!defined('DOKU_INC')) die();
11
12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13require_once DOKU_PLUGIN.'syntax.php';
14
15/**
16 * All DokuWiki plugins to extend the parser/rendering mechanism
17 * need to inherit from this class
18 */
19class helper_plugin_dtable extends dokuwiki_plugin
20{
21    function getMethods(){
22      $result = array();
23      $result[] = array(
24	'name'   => 'md5_array',
25	'desc'   => 'returns array with md5 of each value',
26	'params' => array('array' => 'array'),
27	'return' => array('md5_array' => 'array'),
28      );
29      $result[] = array(
30	'name'   => 'file_path',
31	'desc'   => 'returns db path',
32	'params' => array('name' => 'string'),
33	'return' => array('path' => 'string'),
34      );
35      $result[] = array(
36	'name'   => 'db_path',
37	'desc'   => 'returns full db path',
38	'params' => array('name' => 'string'),
39      );
40      $result[] = array(
41	'name'   => 'db_meta_path',
42	'desc'   => 'returns full db path',
43	'params' => array('name' => 'string'),
44	'return' => array('path' => 'string'),
45      );
46      $result[] = array(
47	'name'   => 'separator',
48	'desc'   => 'csv separator',
49	'params' => array(),
50	'return' => array('separator' => 'string'),
51      );
52      $result[] = array(
53	'name'   => 'separator_en',
54	'desc'   => 'csv separator - utf code',
55	'params' => array(),
56	'return' => array('separator_en' => 'string'),
57      );
58      $result[] = array(
59	'name'   => 'error',
60	'desc'   => 'handle error',
61	'params' => array('code' => 'string', 'json' => 'boolen'),
62	'return' => array('msg' => 'string'),
63      );
64      $result[] = array(
65	'name'   => 'parse',
66	'desc'   => 'change dokuwiki syntax to html',
67	'params' => array('string' => 'string'),
68	'return' => array('content' => 'string'),
69      );
70      return $result;
71    }
72    function md5_array($array)
73    {
74	if(count($array) == 0)
75	    return $array;
76
77	$md5_array = array();
78	foreach($array as $k => $v)
79	{
80	    $md5_array[$k] = md5($v);
81	}
82	return $md5_array;
83    }
84    function file_path($name='')
85    {
86	$base_dir = $this->getConf('bases_dir');
87	return ($base_dir[0] != '/' ? DOKU_INC : '').$base_dir.'/'.$name;
88    }
89
90    function db_path($name)
91    {
92	return $this->file_path($name.'.txt');
93    }
94    function db_meta_path($name)
95    {
96	return $this->file_path('meta.'.$name.'.txt');
97    }
98    function separator()
99    {
100	return '\\';
101    }
102    function separator_en()
103    {
104	return '&#92;';
105    }
106    function error($code, $json=false)
107    {
108	if($json == true)
109	{
110	    return json_encode(array('type' => 'error', 'msg' => $this->getLang($code)));
111	} else
112	{
113	    return $this->getLang($code);
114	}
115    }
116    function parse($string)
117    {
118	$info = array();
119	$r_str = str_replace('<br>', "\n", str_replace($this->separator_en(), $this->separator(), $string));
120	return p_render('xhtml',p_get_instructions($r_str),$info);
121    }
122/*    function getMethods(){
123      $result = array();
124      $result[] = array(
125	'name'   => 'get_acl',
126	'desc'   => 'returns acl of the current user',
127	'params' => array(),
128	'return' => array('acl' => 'integer'),
129      );
130      return $result;
131    }
132    function get_acl()
133    {
134	$sesja = reset($_SESSION);
135	$grupy = $sesja['auth']['info']['grps'];
136	$user = $sesja['auth']['user'];
137
138	$acl = 0;
139	if(isset($grupy))
140	   $acl = auth_aclcheck($_GET['id'], $user, $grupy);
141	return $acl;
142    }
143    /*
144	    if(!function_exists('selfURL'))
145	    {
146		function selfURL($get_to_remove='') {
147		    $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
148		    $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
149		    $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
150		    if($get_to_remove == '')
151		    return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
152		    else
153		    return $protocol."://".$_SERVER['SERVER_NAME'].$port.preg_replace('/&'.$get_to_remove.'=[^&]*//*', '', $_SERVER['REQUEST_URI']);
154		}
155	    }
156	    if(!function_exists('wiki_url'))
157	    {
158		function wiki_url()
159		{
160		    $self = selfURL();
161		    $ex = explode('/', $self);
162		    array_pop($ex);
163		    return implode('/', $ex);
164		}
165	    }
166	    if(!function_exists('strleft'))
167	    {
168		function strleft($s1, $s2) {
169		    return substr($s1, 0, strpos($s1, $s2));
170		}
171	    }
172
173     */
174}
175
176