-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOutputXMLHelper.php
122 lines (113 loc) · 3.4 KB
/
OutputXMLHelper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
/**
* This is the Dokuwiki export for FINDOLOGIC.
* If any bugs occur, please submit a new issue
* @see https://github.com/findologic/dokuwiki-plugin-findologic-xml-export/issues/new
* @author Dominik Brader <[email protected]>
*/
require_once(__DIR__ . '/DokuwikiXMLExport.php');
class OutputXMLHelper
{
/**
* Default DokuWiki include path
*/
const DOKUWIKI_INC = 'DOKU_INC';
/**
* Name of count _GET parameter
*/
const COUNT_NAME = 'count';
/**
* Name of start _GET parameter
*/
const START_NAME = 'start';
/**
* Header if export succeeds
*/
const EXPORT_HEADER = 'Content-type: text/xml';
/**
* Default value for count _GET parameter
*/
const DEFAULT_COUNT_VALUE = 20;
/**
* Default value for start _GET parameter
*/
const DEFAULT_START_VALUE = 0;
/**
* Gets set when an error appears.
* An error may appear if _GET parameters are not valid.
*/
const EXPORT_ERROR_HEADER = 'Status: 400 Bad Request';
/**
* This error message will be outputted if an error occurs.
*/
const EXPORT_ERROR_MESSAGE = 'start and count values are not valid';
/**
* Error code that will be returned if an error occurs.
*/
const EXPORT_ERROR_CODE = 400;
/**
* Error level for DokuWiki functions.
*/
const ERROR_LEVEL = -1;
/**
* Validates count and start values
*
* @param $start int start value
* @param $count int count value
* @param $type int ID of the type to check.
* @return bool true if parameters are valid, else false
*/
public function paramsValid($start, $count, $type)
{
$start = filter_var($start, $type);
$count = filter_var($count, $type);
return (is_int($count) && is_int($start) && $start >= 0 && $count > 0);
}
/**
* Gets the value of _GET param converted to HTML entities, or the default value if _GET param was not set.
*
* @param $paramName string Name of the URL parameter
* @param $defaultValue string Default value if _GET parameter is not set
* @param $getParam array _GET param
* @return string value of the _GET parameter or default value if _GET parameter is not set
*/
public function getUrlParam($paramName, $defaultValue, $getParam)
{
if (isset($getParam[$paramName])) {
return htmlspecialchars($getParam[$paramName]);
} else {
return $defaultValue;
}
}
/**
* Returns generated XML from export
*
* @param $start int start value
* @param $count int count value
* @return string Generated XML
*/
public function getXml($start, $count)
{
global $conf;
$dokuwikiXmlExport = new DokuwikiXMLExport($conf);
return $dokuwikiXmlExport->generateXMLExport($start, $count);
}
/**
* Sets the export error header and prints an error message
*/
public function throwError() {
header(self::EXPORT_ERROR_HEADER, true, self::EXPORT_ERROR_CODE);
msg(self::EXPORT_ERROR_MESSAGE, self::ERROR_LEVEL);
html_msgarea();
}
/**
* Sets export header and prints the XML.
*
* @param $start int start value
* @param $count int count value
*/
public function printXml($start, $count) {
header(self::EXPORT_HEADER);
echo $this->getXml($start, $count);
}
}