-
Notifications
You must be signed in to change notification settings - Fork 2
/
layouts.php
43 lines (38 loc) · 846 Bytes
/
layouts.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
<?php
// Copyright © 2014 Max Penrose
?>
<?php
class Layout {
var $header;
var $footer;
function __construct($header, $footer){
$this->header = $header;
$this->footer = $footer;
}
function writeHeader(){
echo $this->header;
}
function writeFooter(){
echo $this->footer;
}
}
function getLayout($layoutPage){
try {
$file = fopen($layoutPage, "r");
} catch(Exception $e) {
throw new Exception('Unknown layout file');
}
$fileText = fread($file, filesize($layoutPage));
fclose($file);
$textParts = explode("@content", $fileText);
if(sizeof($textParts) < 2){
throw new Exception('No @content marker in file');
} else if(sizeof($textParts) > 2) {
throw new Exception('Too many @content markers in file');
} else {
$header = $textParts[0];
$footer = $textParts[1];
return new Layout($header, $footer);
}
}
?>