-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender.php
61 lines (48 loc) · 1.51 KB
/
render.php
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
<?php
include 'maincontroller.php';
include __DIR__ . '/../config.php';
require "vendor/autoload.php";
use PHPHtmlParser\Dom;
use PHPHtmlParser\Collection;
global $delimiterStart, $delimiterEnd, $db;
function renderPage($route){
global $delimiterStart, $delimiterEnd;
$base=file_get_contents("views/base.bite");
$content = file_get_contents("views/$route.bite");
if ($content == false){
$content = file_get_contents("views/404.bite");
}
$delimitedString=$delimiterStart."content".$delimiterEnd;
//Creates the early version of the page
$page=str_replace($delimitedString, $content, $base);
//Regex to find your tags
$pregString = "/$delimiterStart\S+\s+\S+$delimiterEnd/";
preg_match_all($pregString, $page, $matches);
//Clear out tags from html
foreach($matches[0] as $match){
$page=str_replace("$match", '', $page);
}
//Get actions
$dom = new Dom();
$dom->loadFromFile("views/$route.bite");
$cont = $dom->find('form')[0];
if($cont){
$cont2 = $cont->getAttribute('action');
if($cont2){
$page=str_replace("$cont2", "actions/$cont2", $page);
$cont->delete();
unset($cont);
}
}
//Prints the page
echo $page;
//Runs the function specified in the tag
foreach($matches[0] as $match){
$match = str_replace($delimiterStart, '', $match);
$stripped = str_replace($delimiterEnd, '', $match);
$smth = explode(' ',$stripped);
$func = $smth[0];
$param = $smth[1];
$append = $func($param);
}
}