blob: 67670103b247898fb48d213b2e87e3ba39d6bd6a (
plain)
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
|
<?php /* Copyright (c) 2024 Freya Murphy */
class Main_model extends Model {
// stores the current request info
public $info;
// the main loader
public $load;
/**
* Loads the main model
* @param Loader $load - the main loader object
*/
function __construct($load) {
parent::__construct($load, TRUE);
$GLOBALS['main_model'] = $this;
}
/**
* Gets the stamp for a asset path
* @param string $path
*/
private function asset_stamp($path): int {
$root = $GLOBALS['webroot'];
$path = $root . '/../public/' . $path;
return filemtime($path);
}
/**
* Get the current IE version
* @returns the IE version if valid IE user agent, INT_MAX if not
*/
public function get_ie_version(): int {
if (preg_match('/MSIE\s(?P<v>\d+)/i', @$_SERVER['HTTP_USER_AGENT'], $B)) {
return $B['v'];
} else {
return PHP_INT_MAX;
}
}
/**
* Gets the full url including the http scheme and host part
* Needed for IE 6 & 7 need.
*/
public function get_url_full($path): string {
$host = $_SERVER['HTTP_HOST'];
$base = lang('base_path');
$url = "http://{$host}{$base}{$path}";
return $url;
}
/**
* Gets a full path url from a relative path
*/
public function get_url($path): string {
if ($this->get_ie_version() <= 7) {
return $this->get_url_full($path);
}
$base = lang('base_path');
$url = "{$base}{$path}";
return $url;
}
/**
* Loads a css html link
* @param string $path - the path to the css file
*/
public function link_css($path): string {
$stamp = $this->asset_stamp($path);
$href = $this->get_url("public/{$path}?stamp={$stamp}");
return '<link rel="stylesheet" href="'. $href .'">';
}
/**
* Loads a css html link
* @param string $path - the path to the css file
*/
public function embed_css($path): string {
$file = $GLOBALS['publicroot'] . '/' . $path;
if (file_exists($file)) {
$text = file_get_contents($file);
return "<style>{$text}</style>";
} else {
return "";
}
}
/**
* Formats a ISO date
* @param $iso_date the ISO date
*/
public function format_date($iso_date): string {
return date("Y-m-d D H:m", strtotime($iso_date));
}
}
?>
|