forked from SpaceApi-archive/OpenSpaceLint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPage.php
151 lines (126 loc) · 3.73 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
class Page
{
private $prefetch_assets = array();
private $scripts = array();
private $require_global_scripts = array();
private $stylesheets = array();
private $inline_styles = array();
private $content = "";
private $app_dir = "";
/* not yet used */
private $routes = array();
public function __construct($page_id)
{
$this->app_dir = _APPSDIR . $page_id;
}
public function process_backend_route($delegator = "", $action = "", $resource = "")
{
// get the headers list before processing the route
// $before = headers_list();
ob_start();
Route::execute($delegator, $action, $resource);
$result = ob_get_contents();
ob_end_clean();
// get the possibly changed headers list
//$after = headers_list();
// recover the old headers
//header_remove();
/*
// doesn't work, the content type is application/json anyway
// after the loop
foreach(array_diff($after, $before) as $header)
{
$header = preg_replace("|:.*|", "", $header);
header_remove($header);
}
*/
// we need to fix the content-type
// if other headers were set they possibly need to be
// overridden too if they make trouble, think also about
// not visible effects
header("Content-Type: text/html");
return $result;
}
/**
* Adds an app script to be loaded in the header
* @param string $script
* @param boolean $is_global Flag to denote if it's a script from the global to be included
*/
// TODO: this method should allow a flag whether the script should be loaded in the head or on the bottom of the page
public function addScript($script, $is_global = false)
{
$path = "";
if(! $is_global)
$path = $this->app_dir .'/';
$this->scripts[] = $path . $script;
}
/**
* Adds a script to the required scripts array which must be loaded before the app scripts
* @param $script
*/
public function requireScript($script)
{
$this->require_global_scripts[] = $script;
}
public function requireScripts()
{
return $this->require_global_scripts;
}
/**
* @param $stylesheet
* @param boolean $is_global Flag to denote if it's a script from the global to be included
*/
public function addStylesheet($stylesheet, $is_global = false)
{
$path = "";
if(! $is_global)
$path = $this->app_dir .'/';
$this->stylesheets[] = $path . $stylesheet;
}
public function addInlineStyle($style)
{
$style = $this->processPlaceholders($style);
$this->inline_styles[] = $style;
}
public function inlineStyles()
{
return $this->inline_styles;
}
private function processPlaceholders($str)
{
$str = str_replace("%APPDIR%", $this->app_dir, $str);
$str = str_replace("%SITEURL%", SITE_URL, $str);
return $str;
}
public function addContent($content)
{
$content = $this->processPlaceholders($content);
$this->content .= $content;
}
public function addPrefetchAsset($asset)
{
$asset = $this->processPlaceholders($asset);
$this->prefetch_assets[] = $asset;
}
public function content()
{
return $this->content;
}
public function scripts()
{
return $this->scripts;
}
public function stylesheets()
{
return $this->stylesheets;
}
public function prefetchAssets()
{
return $this->prefetch_assets;
}
public function activePage()
{
return basename($this->app_dir);
}
}