|
1
|
|
|
<?php declare(strict_types=1); defined('BASEPATH') or exit('No direct script access allowed'); |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Checks if view file exists. |
|
5
|
|
|
* @param string $path Location of view file. Use without /views/ & .php |
|
6
|
|
|
* @return bool |
|
7
|
|
|
*/ |
|
8
|
|
|
function view_exists(string $path) : bool { |
|
9
|
23 |
|
return file_exists(APPPATH . "/views/{$path}.php"); |
|
10
|
|
|
} |
|
11
|
|
|
|
|
12
|
|
|
function get_time_class(string $time_string) : string { |
|
13
|
4 |
|
$time = strtotime($time_string); |
|
14
|
|
|
|
|
15
|
4 |
|
if(is_int($time)) { |
|
16
|
3 |
|
if($time < strtotime('-1 month')) { |
|
17
|
|
|
//More than a month old. |
|
18
|
1 |
|
$time_string = "sprite-month"; |
|
19
|
2 |
|
} elseif($time < strtotime('-1 week')) { |
|
20
|
|
|
//More than a week old, but less than a month old. |
|
21
|
1 |
|
$time_string = "sprite-week"; |
|
22
|
|
|
} else { |
|
23
|
|
|
//Less than a week old. |
|
24
|
3 |
|
$time_string = "sprite-day"; |
|
25
|
|
|
} |
|
26
|
|
|
} else { |
|
27
|
1 |
|
$time_string = "sprite-error"; //TODO: Create the sprite for this |
|
28
|
|
|
} |
|
29
|
4 |
|
return $time_string; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
if (!function_exists('http_parse_headers')) { #http://www.php.net/manual/en/function.http-parse-headers.php#112917 |
|
33
|
|
|
function http_parse_headers ($raw_headers){ |
|
34
|
12 |
|
$headers = array(); // $headers = []; |
|
35
|
12 |
|
foreach (explode("\n", $raw_headers) as $i => $h) { |
|
36
|
12 |
|
$h = explode(':', $h, 2); |
|
37
|
12 |
|
if (isset($h[1])){ |
|
38
|
12 |
|
if(!isset($headers[$h[0]])){ |
|
39
|
12 |
|
$headers[$h[0]] = trim($h[1]); |
|
40
|
8 |
|
}else if(is_array($headers[$h[0]])){ |
|
41
|
2 |
|
$tmp = array_merge($headers[$h[0]],array(trim($h[1]))); |
|
|
|
|
|
|
42
|
2 |
|
$headers[$h[0]] = $tmp; |
|
43
|
|
|
}else{ |
|
44
|
8 |
|
$tmp = array_merge(array($headers[$h[0]]),array(trim($h[1]))); |
|
|
|
|
|
|
45
|
12 |
|
$headers[$h[0]] = $tmp; |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
12 |
|
return $headers; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.