|
21 | 21 | // Doesn't contain web-specific stuff like translation.inc |
22 | 22 |
|
23 | 23 | require_once("../inc/random_compat/random.inc"); |
| 24 | + // for random_bytes() |
24 | 25 |
|
25 | 26 | // show PHP errors in output (e.g. web pages). |
26 | 27 | // Call this from your project.inc if you want. |
@@ -215,6 +216,33 @@ function pretty_time_str($x) { |
215 | 216 | return time_str($x); |
216 | 217 | } |
217 | 218 |
|
| 219 | +// convert time interval in seconds to a string of the form |
| 220 | +// 'D days h hours m min s sec'. |
| 221 | + |
| 222 | +function time_diff($x, $res=3) { |
| 223 | + $x = (int)$x; |
| 224 | + $days = (int)($x/86400); |
| 225 | + $hours = (int)(($x-$days*86400)/3600); |
| 226 | + $minutes = (int)(($x-$days*86400-$hours*3600)/60); |
| 227 | + $seconds = $x % 60; |
| 228 | + |
| 229 | + $s = ""; |
| 230 | + if ($days) { |
| 231 | + $s .= "$days ".tra("days")." "; |
| 232 | + } |
| 233 | + if ($res>0 && ($hours || strlen($s))) { |
| 234 | + $s .= "$hours ".tra("hours")." "; |
| 235 | + } |
| 236 | + if ($res>1 && ($minutes || strlen($s))) { |
| 237 | + $s .= "$minutes ".tra("min")." "; |
| 238 | + } |
| 239 | + if ($res>2) { |
| 240 | + $s .= "$seconds ".tra("sec")." "; |
| 241 | + } |
| 242 | + return $s; |
| 243 | +} |
| 244 | + |
| 245 | + |
218 | 246 | // security vulnerabilities and user-supplied strings: |
219 | 247 | // sources: |
220 | 248 | // GET and POST arguments |
@@ -250,4 +278,9 @@ function filename_rules() { |
250 | 278 | return 'Names can contain only A-Z a-z 0-9 . - _ space'; |
251 | 279 | } |
252 | 280 |
|
| 281 | +define('KILO', 1024); |
| 282 | +define('MEGA', 1024*KILO); |
| 283 | +define('GIGA', 1024*MEGA); |
| 284 | +define('TERA', 1024*GIGA); |
| 285 | + |
253 | 286 | ?> |
0 commit comments