|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package content |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* The AjaxParameters returns an JSON array of all available parameters. |
|
8
|
|
|
*/ |
|
9
|
|
|
class contentAjaxParameters extends JSONPage |
|
10
|
|
|
{ |
|
11
|
|
|
private $template = '$%s'; |
|
12
|
|
|
|
|
13
|
|
|
public function view() |
|
14
|
|
|
{ |
|
15
|
|
|
$params = array(); |
|
16
|
|
|
$filter = $_GET['query']; |
|
17
|
|
|
|
|
18
|
|
|
if ($_GET['template']) { |
|
19
|
|
|
$this->template = General::sanitize($_GET['template']); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
// Environment parameters |
|
23
|
|
|
if ($filter === 'env') { |
|
24
|
|
|
$params = array_merge($params, $this->__getEnvParams()); |
|
25
|
|
|
|
|
26
|
|
|
// Page parameters |
|
27
|
|
|
} elseif ($filter === 'page') { |
|
28
|
|
|
$params = array_merge($params, $this->__getPageParams()); |
|
29
|
|
|
|
|
30
|
|
|
// Data source parameters |
|
31
|
|
|
} elseif ($filter === 'ds') { |
|
32
|
|
|
$params = array_merge($params, $this->__getDSParams()); |
|
33
|
|
|
|
|
34
|
|
|
// All parameters |
|
35
|
|
|
} else { |
|
36
|
|
|
$params = array_merge($params, $this->__getEnvParams()); |
|
37
|
|
|
$params = array_merge($params, $this->__getPageParams()); |
|
38
|
|
|
$params = array_merge($params, $this->__getDSParams()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
foreach ($params as $param) { |
|
42
|
|
|
if (empty($filter) || strripos($param, $filter) !== false) { |
|
43
|
|
|
$this->_Result[] = $param; |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
sort($this->_Result); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Utilities |
|
52
|
|
|
*/ |
|
53
|
|
|
private function __getEnvParams() |
|
54
|
|
|
{ |
|
55
|
|
|
$params = array(); |
|
56
|
|
|
$env = array( |
|
57
|
|
|
'today', |
|
58
|
|
|
'current-time', |
|
59
|
|
|
'this-year', |
|
60
|
|
|
'this-month', |
|
61
|
|
|
'this-day', |
|
62
|
|
|
'timezone', |
|
63
|
|
|
'website-name', |
|
64
|
|
|
'page-title', |
|
65
|
|
|
'root', |
|
66
|
|
|
'workspace', |
|
67
|
|
|
'root-page', |
|
68
|
|
|
'current-page', |
|
69
|
|
|
'current-page-id', |
|
70
|
|
|
'current-path', |
|
71
|
|
|
'current-query-string', |
|
72
|
|
|
'current-url', |
|
73
|
|
|
'cookie-username', |
|
74
|
|
|
'cookie-pass', |
|
75
|
|
|
'page-types', |
|
76
|
|
|
'upload-limit' |
|
77
|
|
|
); |
|
78
|
|
|
|
|
79
|
|
|
foreach ($env as $param) { |
|
80
|
|
|
$params[] = sprintf($this->template, $param); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
return $params; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
private function __getPageParams() |
|
87
|
|
|
{ |
|
88
|
|
|
$params = array(); |
|
89
|
|
|
$pages = PageManager::fetch(true, array('params')); |
|
90
|
|
|
|
|
91
|
|
|
foreach ($pages as $key => $pageparams) { |
|
|
|
|
|
|
92
|
|
|
if (empty($pageparams['params'])) { |
|
93
|
|
|
continue; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
$pageparams = explode('/', $pageparams['params']); |
|
97
|
|
|
|
|
98
|
|
|
foreach ($pageparams as $pageparam) { |
|
99
|
|
|
$param = sprintf($this->template, $pageparam); |
|
100
|
|
|
|
|
101
|
|
|
if (!in_array($param, $params)) { |
|
102
|
|
|
$params[] = $param; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
return $params; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
private function __getDSParams() |
|
111
|
|
|
{ |
|
112
|
|
|
$params = array(); |
|
113
|
|
|
$datasources = DatasourceManager::listAll(); |
|
114
|
|
|
|
|
115
|
|
|
foreach ($datasources as $datasource) { |
|
116
|
|
|
$current = DatasourceManager::create($datasource['handle'], array(), false); |
|
117
|
|
|
|
|
118
|
|
|
// Get parameters |
|
119
|
|
|
if (is_array($current->dsParamPARAMOUTPUT)) { |
|
120
|
|
|
foreach ($current->dsParamPARAMOUTPUT as $id => $param) { |
|
|
|
|
|
|
121
|
|
|
$params[] = sprintf($this->template, |
|
122
|
|
|
'ds-' . Lang::createHandle($datasource['name']) . '.' . Lang::createHandle($param)); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
return $params; |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.