1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Bart Visscher <[email protected]> |
4
|
|
|
* @author Bernhard Posselt <[email protected]> |
5
|
|
|
* @author Georg Ehrke <[email protected]> |
6
|
|
|
* @author Joas Schilling <[email protected]> |
7
|
|
|
* @author Jörn Friedrich Dreyer <[email protected]> |
8
|
|
|
* @author Lukas Reschke <[email protected]> |
9
|
|
|
* @author Morris Jobke <[email protected]> |
10
|
|
|
* @author Robin McCorkell <[email protected]> |
11
|
|
|
* @author Thomas Müller <[email protected]> |
12
|
|
|
* @author Vincent Petry <[email protected]> |
13
|
|
|
* |
14
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc. |
15
|
|
|
* @license AGPL-3.0 |
16
|
|
|
* |
17
|
|
|
* This code is free software: you can redistribute it and/or modify |
18
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
19
|
|
|
* as published by the Free Software Foundation. |
20
|
|
|
* |
21
|
|
|
* This program is distributed in the hope that it will be useful, |
22
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
23
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24
|
|
|
* GNU Affero General Public License for more details. |
25
|
|
|
* |
26
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
27
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
28
|
|
|
* |
29
|
|
|
*/ |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Prints a sanitized string |
33
|
|
|
* @param string|array $string the string which will be escaped and printed |
34
|
|
|
*/ |
35
|
|
|
function p($string) { |
36
|
12 |
|
print(OC_Util::sanitizeHTML($string)); |
37
|
12 |
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Prints an unsanitized string - usage of this function may result into XSS. |
41
|
|
|
* Consider using p() instead. |
42
|
|
|
* @param string|array $string the string which will be printed as it is |
43
|
|
|
*/ |
44
|
|
|
function print_unescaped($string) { |
45
|
11 |
|
print($string); |
46
|
11 |
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Shortcut for adding scripts to a page |
50
|
|
|
* @param string $app the appname |
51
|
|
|
* @param string|string[] $file the filename, |
52
|
|
|
* if an array is given it will add all scripts |
53
|
|
|
*/ |
54
|
|
|
function script($app, $file = null) { |
55
|
|
|
if(is_array($file)) { |
56
|
|
|
foreach($file as $f) { |
57
|
|
|
OC_Util::addScript($app, $f); |
58
|
|
|
} |
59
|
|
|
} else { |
60
|
|
|
OC_Util::addScript($app, $file); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Shortcut for adding vendor scripts to a page |
66
|
|
|
* @param string $app the appname |
67
|
|
|
* @param string|string[] $file the filename, |
68
|
|
|
* if an array is given it will add all scripts |
69
|
|
|
*/ |
70
|
|
|
function vendor_script($app, $file = null) { |
71
|
|
|
if(is_array($file)) { |
72
|
|
|
foreach($file as $f) { |
73
|
|
|
OC_Util::addVendorScript($app, $f); |
74
|
|
|
} |
75
|
|
|
} else { |
76
|
|
|
OC_Util::addVendorScript($app, $file); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Shortcut for adding styles to a page |
82
|
|
|
* @param string $app the appname |
83
|
|
|
* @param string|string[] $file the filename, |
84
|
|
|
* if an array is given it will add all styles |
85
|
|
|
*/ |
86
|
|
|
function style($app, $file = null) { |
87
|
|
|
if(is_array($file)) { |
88
|
|
|
foreach($file as $f) { |
89
|
|
|
OC_Util::addStyle($app, $f); |
90
|
|
|
} |
91
|
|
|
} else { |
92
|
|
|
OC_Util::addStyle($app, $file); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Shortcut for adding vendor styles to a page |
98
|
|
|
* @param string $app the appname |
99
|
|
|
* @param string|string[] $file the filename, |
100
|
|
|
* if an array is given it will add all styles |
101
|
|
|
*/ |
102
|
|
|
function vendor_style($app, $file = null) { |
103
|
|
|
if(is_array($file)) { |
104
|
|
|
foreach($file as $f) { |
105
|
|
|
OC_Util::addVendorStyle($app, $f); |
106
|
|
|
} |
107
|
|
|
} else { |
108
|
|
|
OC_Util::addVendorStyle($app, $file); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Shortcut for adding translations to a page |
114
|
|
|
* @param string $app the appname |
115
|
|
|
* if an array is given it will add all styles |
116
|
|
|
*/ |
117
|
|
|
function translation($app) { |
118
|
|
|
OC_Util::addTranslations($app); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Shortcut for HTML imports |
123
|
|
|
* @param string $app the appname |
124
|
|
|
* @param string|string[] $file the path relative to the app's component folder, |
125
|
|
|
* if an array is given it will add all components |
126
|
|
|
*/ |
127
|
|
|
function component($app, $file) { |
128
|
|
|
if(is_array($file)) { |
129
|
|
|
foreach($file as $f) { |
130
|
|
|
$url = link_to($app, 'component/' . $f . '.html'); |
131
|
|
|
OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url)); |
132
|
|
|
} |
133
|
|
|
} else { |
134
|
|
|
$url = link_to($app, 'component/' . $file . '.html'); |
135
|
|
|
OC_Util::addHeader('link', array('rel' => 'import', 'href' => $url)); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* make OC_Helper::linkTo available as a simple function |
141
|
|
|
* @param string $app app |
142
|
|
|
* @param string $file file |
143
|
|
|
* @param array $args array with param=>value, will be appended to the returned url |
144
|
|
|
* @return string link to the file |
145
|
|
|
* |
146
|
|
|
* For further information have a look at OC_Helper::linkTo |
147
|
|
|
*/ |
148
|
|
|
function link_to( $app, $file, $args = array() ) { |
149
|
|
|
return OC_Helper::linkTo( $app, $file, $args ); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @param $key |
154
|
|
|
* @return string url to the online documentation |
155
|
|
|
*/ |
156
|
|
|
function link_to_docs($key) { |
157
|
|
|
return OC_Helper::linkToDocs($key); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* make OC_Helper::imagePath available as a simple function |
162
|
|
|
* @param string $app app |
163
|
|
|
* @param string $image image |
164
|
|
|
* @return string link to the image |
165
|
|
|
* |
166
|
|
|
* For further information have a look at OC_Helper::imagePath |
167
|
|
|
*/ |
168
|
|
|
function image_path( $app, $image ) { |
169
|
10 |
|
return OC_Helper::imagePath( $app, $image ); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* make OC_Helper::mimetypeIcon available as a simple function |
174
|
|
|
* @param string $mimetype mimetype |
175
|
|
|
* @return string link to the image |
176
|
|
|
* |
177
|
|
|
* For further information have a look at OC_Helper::mimetypeIcon |
178
|
|
|
*/ |
179
|
|
|
function mimetype_icon( $mimetype ) { |
180
|
|
|
return OC_Helper::mimetypeIcon( $mimetype ); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* make preview_icon available as a simple function |
185
|
|
|
* Returns the path to the preview of the image. |
186
|
|
|
* @param string $path path of file |
187
|
|
|
* @return link to the preview |
188
|
|
|
* |
189
|
|
|
* For further information have a look at OC_Helper::previewIcon |
190
|
|
|
*/ |
191
|
|
|
function preview_icon( $path ) { |
192
|
|
|
return OC_Helper::previewIcon( $path ); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @param string $path |
197
|
|
|
*/ |
198
|
|
|
function publicPreview_icon ( $path, $token ) { |
199
|
|
|
return OC_Helper::publicPreviewIcon( $path, $token ); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* make OC_Helper::humanFileSize available as a simple function |
204
|
|
|
* @param int $bytes size in bytes |
205
|
|
|
* @return string size as string |
206
|
|
|
* |
207
|
|
|
* For further information have a look at OC_Helper::humanFileSize |
208
|
|
|
*/ |
209
|
|
|
function human_file_size( $bytes ) { |
210
|
|
|
return OC_Helper::humanFileSize( $bytes ); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Strips the timestamp of its time value |
215
|
|
|
* @param int $timestamp UNIX timestamp to strip |
216
|
|
|
* @return $timestamp without time value |
|
|
|
|
217
|
|
|
*/ |
218
|
|
|
function strip_time($timestamp){ |
219
|
|
|
$date = new \DateTime("@{$timestamp}"); |
220
|
|
|
$date->setTime(0, 0, 0); |
221
|
1 |
|
return intval($date->format('U')); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Formats timestamp relatively to the current time using |
226
|
|
|
* a human-friendly format like "x minutes ago" or "yesterday" |
227
|
|
|
* @param int $timestamp timestamp to format |
228
|
|
|
* @param int $fromTime timestamp to compare from, defaults to current time |
229
|
|
|
* @param bool $dateOnly whether to strip time information |
230
|
|
|
* @return string timestamp |
231
|
|
|
*/ |
232
|
|
|
function relative_modified_date($timestamp, $fromTime = null, $dateOnly = false) { |
233
|
|
|
/** @var \OC\DateTimeFormatter $formatter */ |
234
|
15 |
|
$formatter = \OC::$server->query('DateTimeFormatter'); |
235
|
|
|
|
236
|
15 |
|
if ($dateOnly){ |
237
|
7 |
|
return $formatter->formatDateSpan($timestamp, $fromTime); |
238
|
|
|
} |
239
|
8 |
|
return $formatter->formatTimeSpan($timestamp, $fromTime); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
function html_select_options($options, $selected, $params=array()) { |
243
|
|
|
if (!is_array($selected)) { |
244
|
|
|
$selected=array($selected); |
245
|
|
|
} |
246
|
|
|
if (isset($params['combine']) && $params['combine']) { |
247
|
|
|
$options = array_combine($options, $options); |
248
|
|
|
} |
249
|
|
|
$value_name = $label_name = false; |
250
|
|
|
if (isset($params['value'])) { |
251
|
|
|
$value_name = $params['value']; |
252
|
|
|
} |
253
|
|
|
if (isset($params['label'])) { |
254
|
|
|
$label_name = $params['label']; |
255
|
|
|
} |
256
|
|
|
$html = ''; |
257
|
|
|
foreach($options as $value => $label) { |
258
|
|
|
if ($value_name && is_array($label)) { |
259
|
|
|
$value = $label[$value_name]; |
260
|
|
|
} |
261
|
|
|
if ($label_name && is_array($label)) { |
262
|
|
|
$label = $label[$label_name]; |
263
|
|
|
} |
264
|
|
|
$select = in_array($value, $selected) ? ' selected="selected"' : ''; |
265
|
|
|
$html .= '<option value="' . OC_Util::sanitizeHTML($value) . '"' . $select . '>' . OC_Util::sanitizeHTML($label) . '</option>'."\n"; |
266
|
|
|
} |
267
|
|
|
return $html; |
268
|
|
|
} |
269
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.