Completed
Push — master ( 538c9f...f6ad35 )
by Andrey
03:04 queued 53s
created

Content.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
    public function __construct(){
20
        # Config
21
        self::$config = (new Config)->get();
22
        # Host
23
        self::$host = parse_url('http://'.$_SERVER['HTTP_HOST'])['host'];
24
        # Url
25
        self::$path = explode('/',parse_url(urldecode($_SERVER['REQUEST_URI']))['path']);
26 View Code Duplication
        foreach(self::$path as $key=>$value){
27
            $value = trim($value);
28
            if(empty($value)) unset(self::$path[$key]);
29
        }
30
        self::$path = array_values(self::$path);
31
        # Application
32
        self::$app = new Application;
33
        # View
34
        self::$view = new View;
35
        # Widget
36
        self::$widget = new Widget;
37
        # Js
38
        self::$js = new Js;
39
        # Css
40
        self::$css = new Css;
41
        # Title
42
        self::$title = new Title;
43
        # Desctiption
44
        self::$description = new Description;
45
        # Keywords
46
        self::$keywords = new Keywords;
47
        # Uri
48
        self::$uri = explode('/',$_SERVER['REQUEST_URI']);
49 View Code Duplication
        foreach(self::$uri as $key=>$value){
50
            if(empty($value)) unset(self::$uri[$key]);
51
            else self::$uri[$key] = urldecode($value);
52
        }
53
        self::$uri = array_values(self::$uri);
54
    }
55
56
    public function view($name){
57
        $file = $this->file($name);
58
        if(is_file($file)) require $file;
59
    }
60
61
    public function page(){
62
        # get file
63
        $file = $this->file();
64
        # get content
65
        ob_start();
66
        require $file;
67
        $content = ob_get_clean();
68
        # get css
69
        $css = self::$css->get();
70
        # get css
71
        $js = self::$js->get();
72
        # get title
73
        $title = self::$title->get();
74
        # get description
75
        $description = self::$description->get();
76
        # get keywords
77
        $keywords = self::$keywords->get();
78
        # include for page
79
        $content = preg_replace('/<head>/',"<head>$keywords",$content);
80
        $content = preg_replace('/<head>/',"<head>$description",$content);
81
        $content = preg_replace('/<head>/',"<head>$title",$content);
82
        $content = preg_replace('/<\/head>/',"$css</head>",$content);
83
        $content = preg_replace('/<\/body>/',"$js</body>",$content);
84
        $minify = new MinifyHTML($content);
85
        $content = $minify->compress();
86
        echo $content;
87
    }
88
89
    public function js($query){
90
        echo self::$js->compile($query);
0 ignored issues
show
The call to Js::compile() has too many arguments starting with $query.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
91
    }
92
93
    # $type - page,view
94
    public function file($name=false){
95
        if($name === false){
96
            $path = self::$config['core']['page'];
97
        } else {
98
            $path = self::$config['core']['view'].'/'.$name;
99
        }
100
        # Route
101
        $uri = self::$path;
102
        array_push($uri,'');
103
        foreach($uri as $key=>$value){ if(empty(trim($value))) { unset($uri[$key]); continue; } }
104
        $uri = array_values($uri);
105
        $isFile = null;
106
        $currentUri = null;
107
        $filePhtml = null;
108
        for($i=count($uri)-1; $i>=0; $i--){
109
          $nextUri = implode('/',array_slice($uri,0,$i+1));
110
          $getFile = function($type) use($path,$nextUri){
111
            $file = $path.'/'.$nextUri.'/index.'.$type;
112
            if(is_file($file)) return $file;
113
            return null;
114
          };
115
          $filePhtml = $getFile('phtml');
116
          if($filePhtml) { $currentUri = $nextUri; break; }
117
        }
118
        if($filePhtml === null) {
119
          $filePhtml = $path.'/index.phtml';
120
        }
121
        return $filePhtml;
122
    }
123
124
}
125
?>
126