kt3template.inc.php
9.41 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<?php
/* KT3 Template Base
*
* Represents core UI logic, including how sub-components interact with the overall page.
* For the meaning of each of the variables and functions, see inline.
*
* author: Brad Shuttleworth <brad@jamwarehouse.com>
*/
require_once(KT_LIB_DIR . "/templating/templating.inc.php");
require_once(KT_LIB_DIR . "/session/control.inc");
class KTPage {
/** resources are "filename"->1 to allow subcomponents to require items. */
var $js_resources = Array();
var $css_resources = Array();
var $js_standalone = Array();
var $css_standalone = Array();
/** context-relevant information */
var $errStack = Array();
var $infoStack = Array();
var $portlets = Array();
var $show_portlets = true;
/** miscellaneous items */
var $title = '';
var $systemName = 'KnowledgeTree';
var $systemURL = 'http://ktdms.com/';
var $breadcrumbs = false;
var $breadcrumbDetails = false;
var $breadcrumbSection = false;
var $menu = null;
var $userMenu = null;
/** the "component". Used to set the page header (see documentation for explanation). */
var $componentLabel = 'Browse Collections';
var $componentClass = 'browse_collections';
/** $contents is the center of the page. In KT < 3, this was CentralPayload. */
var $contents = '';
var $template = "kt3/standard_page";
/* further initialisation */
function KTPage() {
/* default css files initialisation */
$aCSS = Array(
"resources/css/kt-framing.css",
"resources/css/kt-contenttypes.css",
"resources/css/kt-headings.css"
);
$this->requireCSSResources($aCSS);
/* default js files initialisation */
$aJS = Array();
$this->requireJSResources($aJS);
/* menu initialisation*/
// FIXME: how do we want to handle the menu?
$this->initMenu();
/* portlet initialisation */
$this->show_portlets = true;
/* breadcrumbs */
}
// initiliase the menu.
function initMenu() {
// FIXME: we lost the getDefaultAction stuff - do we care?
// note that key == action. this is _important_, since we crossmatch the breadcrumbs against this for "active"
$this->menu = array(
"dashboard" => $this->_actionHelper(array("name" => _("Dashboard"), "action" => "dashboard", "active" => 0)),
"browse" => $this->_actionHelper(array("name" => _("Browse Collections"), "action" => "browse", "active" => 0)),
"administration" => $this->_actionHelper(array("name" => _("DMS Administration"), "action" => "administration", "active" => 0)),
);
$this->userMenu = array(
"preferences" => $this->_actionHelper(array("name" => _("Preferences"), "action" => "preferences", "active" => 0)),
"logout" => $this->_actionHelper(array("name" => _("Logout"), "action" => "logout", "active" => 0)),
);
}
function setTitle($sTitle) { $this->title = $sTitle; }
/* javascript handling */
// require that the specified JS file is referenced.
function requireJSResource($sResourceURL) {
$this->js_resources[$sResourceURL] = 1; // use the keys to prevent multiple copies.
}
// require that the specified JS files are referenced.
function requireJSResources($aResourceURLs) {
foreach ($aResourceURLs as $sResourceURL) {
$this->js_resources[$sResourceURL] = 1;
}
}
// list the distinct js resources.
function getJSResources() {
return array_keys($this->js_resources);
}
function requireJSStandalone($sJavascript) {
$this->js_standalone[$sJavascript] = 1; // use the keys to prevent multiple copies.
}
// list the distinct js resources.
function getJSStandalone() {
return array_keys($this->js_standalone);
}
/* css handling */
// require that the specified CSS file is referenced.
function requireCSSResource($sResourceURL) {
$this->css_resources[$sResourceURL] = 1; // use the keys to prevent multiple copies.
}
// require that the specified CSS files are referenced.
function requireCSSResources($aResourceURLs) {
foreach ($aResourceURLs as $sResourceURL) {
$this->css_resources[$sResourceURL] = 1;
}
}
// list the distinct CSS resources.
function getCSSResources() {
return array_keys($this->css_resources);
}
function requireCSSStandalone($sCSS) {
$this->css_standalone[$sCSS] = 1;
}
function getCSSStandalone() {
return array_keys($this->css_standalone);
}
function setPageContents($contents) { $this->contents = $contents; }
function setShowPortlets($bShow) { $this->show_portlets = $bShow; }
/* set the breadcrumbs. the first item is the area name.
the rest are breadcrumbs. */
function setBreadcrumbs($aBreadcrumbs) {
$breadLength = count($aBreadcrumbs);
if ($breadLength != 0) {
$this->breadcrumbSection = $this->_actionhelper($aBreadcrumbs[0]);
// handle the menu
if (($aBreadcrumbs[0]["action"]) && ($this->menu[$aBreadcrumbs[0]["action"]])) {
$this->menu[$aBreadcrumbs[0]["action"]]["active"] = 1;
}
}
if ($breadLength > 1) {
$this->breadcrumbs = array_map(array(&$this, "_actionhelper"), array_slice($aBreadcrumbs, 1));
}
}
function setBreadcrumbDetails($sBreadcrumbDetails) { $this->breadcrumbDetails = $sBreadcrumbDetails; }
function setUser($oUser) { $this->user = $oUser; }
// FIXME refactor setSection to be generic, not an if-else.
// assume this is admin for now.
function setSection($sSection) {
if ($sSection == 'administration') {
$this->componentLabel = _('DMS Administration');
$this->componentClass = 'administration';
} else if ($sSection == 'dashboard') {
$this->componentLabel = _('Dashboard');
$this->componentClass = 'dashboard';
} else if ($sSection == 'browse') {
$this->componentLabel = _('Browse Documents');
$this->componentClass = 'browse_collections';
} else if ($sSection == 'view_details') {
$this->componentLabel = _('Document Details');
$this->componentClass = 'document_details';
} else if ($sSection == 'search') {
$this->componentLabel = _('Search');
$this->componentClass = 'search';
} else if ($sSection == 'preferences') {
$this->componentLabel = _('Preferences');
$this->componentClass = 'preferences';
} else {
$this->componentLabel = _('Dashboard');
$this->componentClass = 'dashboard';
}
}
function addError($sError) { array_push($this->errStack, $sError); }
function addInfo($sInfo) { array_push($this->infoStack, $sInfo); }
/** no-one cares what a portlet is, but it should be renderable, and have its ->title member set. */
function addPortlet($oPortlet) {
array_push($this->portlets, $oPortlet);
}
/* LEGACY */
var $deprecationWarning = "Legacy UI API: ";
function setCentralPayload($sCentral) {
$this->contents = $sCentral;
$this->addError($this->deprecationWarning . "called <strong>setCentralPayload</strong>");
}
function setOnloadJavascript($appendix) { $this->addError($this->deprecationWarning . "called <strong>setOnloadJavascript (no-act)</strong>"); }
function setDHtmlScrolling($appendix) { $this->addError($this->deprecationWarning . "called <strong>setDHTMLScrolling (no-act)</strong>"); }
function setFormAction($appendix) { $this->addError($this->deprecationWarning . "called <strong>setFormAction (no-act)</strong>"); }
function setSubmitMethod($appendix) { $this->addError($this->deprecationWarning . "called <strong>setSubmitMethod (no-act)</strong>"); }
function setHasRequiredFields($appendix) { $this->addError($this->deprecationWarning . "called <strong>setHasRequiredFields (no-act)</strong>"); }
function setAdditionalJavascript($appendix) { $this->addError($this->deprecationWarning . "called <strong>setAdditionalJavascript (no-act)</strong>"); }
/* final render call. */
function render() {
if (empty($this->contents)) {
$this->contents = "";
}
if (is_string($this->contents) && (trim($this->contents) === "")) {
$this->addError(_("This page did not produce any content"));
$this->contents = "";
}
if (!is_string($this->contents)) {
$this->contents = $this->contents->render();
}
// if we have no portlets, make the ui a tad nicer.
if (empty($this->portlets)) {
$this->show_portlets = false;
}
$oTemplating = new KTTemplating;
$oTemplate = $oTemplating->loadTemplate($this->template);
$aTemplateData = array(
"page" => $this,
);
// unlike the rest of KT, we use echo here.
echo $oTemplate->render($aTemplateData);
}
/** heler functions */
// returns an array ("url", "label")
function _actionhelper($aActionTuple) {
$aTuple = Array("label" => $aActionTuple["name"]);
if ($aActionTuple["action"]) {
$aTuple["url"] = generateControllerLink($aActionTuple["action"], $aActionTuple["query"]);
} else if ($aActionTuple["url"]) {
$aTuple["url"] = $aActionTuple["url"];
} else {
$aTuple["url"] = false;
}
return $aTuple;
}
}
/* set $main - this is used by the rest of the system. */
$GLOBALS['main'] =& new KTPage();
?>