-
Notifications
You must be signed in to change notification settings - Fork 0
/
Page.php
75 lines (57 loc) · 1.55 KB
/
Page.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
class Theme_Page extends Mvc_Base {
private $data = null, $twig = null;
var $logged_in = false, $id = null;
static $params = [];
function __construct($slug, Twig_Environment &$twig) {
$this->data = $this->load_data($slug);
$this->id = $this->data->getID();
$this->twig = $twig;
}
static function &attach_object($name, $value) {
self::$params[$name] = &$value;
}
function get($name){
return $this->data->$name;
}
/**
*
* @return RedBeanPHP\OODBBean
*/
function &data(){
return $data = &$this->data;
}
function content(){
//Load the template
// echo $this->data->template;
$content = $this->twig->render($this->data->template, array_merge(self::$params,['this'=> $this]));
$processor = new Theme_Process($this);
$processor->logged_in = $this->logged_in;
$content = $processor->process($content);
return $content;
}
function meta(){
return "<title>{$this->data->title}</title><meta name=\"description\" content=\"{$this->data->description}\" >";
}
static function page_exists($slug){
$page = R::findOne('page','slug = :slug',['slug' => $slug]);
if(empty($page)){
return false;
} else return $page;
}
function load_data($slug){
$page = R::findOne('page','slug = :slug',['slug' => $slug]);
if(empty($page)){
$page = $this->create_data($slug);
}
return $page;
}
function create_data($slug){
$page = R::dispense('page');
$page->slug = $slug;
//Load the default page template
$page->template = 'templates/index.twig';
R::store($page);
return $page;
}
}