1
|
|
|
<?php |
2
|
|
|
namespace humanity; |
3
|
|
|
|
4
|
|
|
class Content { |
5
|
|
|
|
6
|
|
|
private static $host; |
|
|
|
|
7
|
|
|
private static $path; |
|
|
|
|
8
|
|
|
private static $config; |
9
|
|
|
private static $js; |
10
|
|
|
private static $css; |
11
|
|
|
private static $app; |
12
|
|
|
private static $view; |
13
|
|
|
private static $widget; |
14
|
|
|
private static $title; |
15
|
|
|
private static $description; |
16
|
|
|
private static $keywords; |
17
|
|
|
private static $uri; |
18
|
|
|
|
19
|
|
View Code Duplication |
public function __construct(){ |
|
|
|
|
20
|
|
|
# Config |
21
|
|
|
self::$config = (new Config)->get(); |
22
|
|
|
# Application |
23
|
|
|
self::$app = new Application; |
24
|
|
|
# View |
25
|
|
|
self::$view = new View; |
26
|
|
|
# Widget |
27
|
|
|
self::$widget = new Widget; |
28
|
|
|
# Js |
29
|
|
|
self::$js = new Js; |
30
|
|
|
# Css |
31
|
|
|
self::$css = new Css; |
32
|
|
|
# Title |
33
|
|
|
self::$title = new Title; |
34
|
|
|
# Desctiption |
35
|
|
|
self::$description = new Description; |
36
|
|
|
# Keywords |
37
|
|
|
self::$keywords = new Keywords; |
38
|
|
|
# Uri |
39
|
|
|
self::$uri = new Uri; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function view($name){ |
43
|
|
|
$file = $this->file($name); |
44
|
|
|
if(is_file($file)) require $file; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function page(){ |
48
|
|
|
# get file |
49
|
|
|
$file = $this->file(); |
50
|
|
|
# get content |
51
|
|
|
ob_start(); |
52
|
|
|
require $file; |
53
|
|
|
$content = ob_get_clean(); |
54
|
|
|
# get css |
55
|
|
|
$css = self::$css->get(); |
56
|
|
|
# get css |
57
|
|
|
$js = self::$js->get(); |
58
|
|
|
# get title |
59
|
|
|
$title = self::$title->get(); |
60
|
|
|
# get description |
61
|
|
|
$description = self::$description->get(); |
62
|
|
|
# get keywords |
63
|
|
|
$keywords = self::$keywords->get(); |
64
|
|
|
# include for page |
65
|
|
|
$content = preg_replace('/<head>/',"<head>$keywords",$content); |
66
|
|
|
$content = preg_replace('/<head>/',"<head>$description",$content); |
67
|
|
|
$content = preg_replace('/<head>/',"<head>$title",$content); |
68
|
|
|
$content = preg_replace('/<\/head>/',"$css</head>",$content); |
69
|
|
|
$content = preg_replace('/<\/body>/',"$js</body>",$content); |
70
|
|
|
$minify = new MinifyHTML($content); |
71
|
|
|
$content = $minify->compress(); |
72
|
|
|
echo $content; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function js($query){ |
76
|
|
|
echo self::$js->compile($query); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
# $type - page,view |
80
|
|
|
public function file($name=false){ |
81
|
|
|
if($name === false){ |
82
|
|
|
$path = self::$config['core']['page']; |
83
|
|
|
} else { |
84
|
|
|
$path = self::$config['core']['view'].'/'.$name; |
85
|
|
|
} |
86
|
|
|
# Route |
87
|
|
|
$uri = self::$uri->arr(); |
88
|
|
|
array_push($uri,''); |
89
|
|
|
foreach($uri as $key=>$value){ if(empty(trim($value))) { unset($uri[$key]); continue; } } |
90
|
|
|
$uri = array_values($uri); |
91
|
|
|
$isFile = null; |
|
|
|
|
92
|
|
|
$currentUri = null; |
|
|
|
|
93
|
|
|
$filePhtml = null; |
94
|
|
|
for($i=count($uri)-1; $i>=0; $i--){ |
95
|
|
|
$nextUri = implode('/',array_slice($uri,0,$i+1)); |
96
|
|
|
$getFile = function($type) use($path,$nextUri){ |
97
|
|
|
$file = $path.'/'.$nextUri.'/index.'.$type; |
98
|
|
|
if(is_file($file)) return $file; |
99
|
|
|
return null; |
100
|
|
|
}; |
101
|
|
|
$filePhtml = $getFile('phtml'); |
102
|
|
|
if($filePhtml) { $currentUri = $nextUri; break; } |
|
|
|
|
103
|
|
|
} |
104
|
|
|
if($filePhtml === null) { |
105
|
|
|
$filePhtml = $path.'/index.phtml'; |
106
|
|
|
} |
107
|
|
|
return $filePhtml; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
} |
111
|
|
|
?> |
|
|
|
|
112
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.