1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23: 24:
25: class cGuiPage {
26:
27: 28: 29: 30: 31: 32:
33: protected $_pagename;
34:
35: 36: 37: 38: 39:
40: protected $_pluginname;
41:
42: 43: 44: 45: 46:
47: protected $_pagetemplate;
48:
49: 50: 51: 52: 53: 54:
55: protected $_contenttemplate;
56:
57: 58: 59: 60: 61: 62:
63: protected $_scripts;
64:
65: 66: 67: 68: 69: 70:
71: protected $_styles;
72:
73: 74: 75: 76: 77: 78:
79: protected $_subnav;
80:
81: 82: 83: 84: 85: 86:
87: protected $_markscript;
88:
89: 90: 91: 92: 93: 94:
95: protected $_error;
96:
97: 98: 99: 100: 101: 102:
103: protected $_warning;
104:
105: 106: 107: 108: 109: 110:
111: protected $_info;
112:
113: 114: 115: 116: 117:
118: protected $_abort;
119:
120: 121: 122: 123: 124: 125:
126: protected $_objects;
127:
128: 129: 130: 131: 132:
133: protected $_metaTags;
134:
135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148:
149: public function __construct($pagename, $pluginname = "", $submenu = "") {
150: global $lang, $cfg, $sess;
151:
152: $this->_pagename = $pagename;
153: $this->_pluginname = $pluginname;
154: $this->_pagetemplate = new cTemplate();
155: $this->_contenttemplate = new cTemplate();
156: $this->_scripts = array();
157: $this->_styles = array();
158: $this->_subnav = "";
159: $this->_markscript = "";
160: $this->_error = "";
161: $this->_warning = "";
162: $this->_info = "";
163: $this->_abort = false;
164: $this->_objects = array();
165: $this->_metaTags = array();
166:
167:
168: $clang = new cApiLanguage($lang);
169:
170: if ($clang->isLoaded()) {
171: $this->setEncoding($clang->get("encoding"));
172: }
173:
174: $this->_pagetemplate->set("s", "SUBMENU", $submenu);
175: $this->_pagetemplate->set("s", "PAGENAME", $pagename);
176:
177: if (cFileHandler::exists($cfg['path']['styles'] . $pagename . ".css")) {
178: $this->addStyle($pagename . ".css");
179: }
180:
181:
182: foreach (new DirectoryIterator($cfg['path']['styles']) as $stylefile) {
183: if (cString::endsWith($stylefile->getFilename(), "." . $pagename . ".css")) {
184: $this->addStyle($stylefile->getFilename());
185: }
186: }
187:
188: if (cFileHandler::exists($cfg['path']['scripts'] . $pagename . ".js")) {
189: $this->addScript($pagename . ".js");
190: }
191:
192:
193: foreach (new DirectoryIterator($cfg['path']['scripts']) as $scriptfile) {
194: if (cString::endsWith($scriptfile->getFilename(), "." . $pagename . ".js")) {
195: $this->addScript($scriptfile->getFilename());
196: }
197: }
198: }
199:
200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212:
213: public function addScript($script) {
214: $cfg = cRegistry::getConfig();
215: $backendUrl = cRegistry::getBackendUrl();
216: $backendPath = cRegistry::getBackendPath();
217:
218: if (strpos(trim($script), 'http') === 0 || strpos(trim($script), '<script') === 0 || strpos(trim($script), '//') === 0) {
219: if (strpos(trim($script), '<script') === 0) {
220: cDeprecated("You shouldn't use inline JS for backend pages");
221: }
222:
223: $this->_scripts[] = $script;
224: } else if (cFileHandler::exists($backendPath . $cfg['path']['plugins'] . $this->_pluginname . '/' . $cfg['path']['scripts'] . $script)) {
225:
226: $fullpath = $backendUrl . $cfg['path']['plugins'] . $this->_pluginname . '/' . $cfg['path']['scripts'] . $script;
227: $this->_scripts[] = $fullpath;
228: } else if (cFileHandler::exists($backendPath . $cfg['path']['scripts'] . $script)) {
229:
230: $fullpath = $backendUrl . $cfg['path']['scripts'] . $script;
231: $this->_scripts[] = $fullpath;
232: }
233: }
234:
235: 236: 237: 238: 239: 240: 241: 242:
243: public function addStyle($stylesheet) {
244: $cfg = cRegistry::getConfig();
245: $backendUrl = cRegistry::getBackendUrl();
246: $backendPath = cRegistry::getBackendPath();
247:
248: if (strpos($stylesheet, 'http') === 0 || strpos($stylesheet, '//') === 0) {
249:
250: $this->_styles[] = $stylesheet;
251: } else if (cFileHandler::exists($backendPath . $cfg['path']['plugins'] . $this->_pluginname . '/' . $cfg['path']['styles'] . $stylesheet)) {
252:
253:
254: $fullpath = $backendUrl . $cfg['path']['plugins'] . $this->_pluginname . '/' . $cfg['path']['styles'] . $stylesheet;
255: $this->_styles[] = $fullpath;
256: } else if (cFileHandler::exists($backendPath . $cfg['path']['styles'] . $stylesheet)) {
257:
258:
259: $fullpath = $backendUrl . $cfg['path']['styles'] . $stylesheet;
260: $this->_styles[] = $fullpath;
261: }
262: }
263:
264: 265: 266: 267: 268: 269: 270: 271:
272: public function addMeta(array $meta) {
273: $allowedAttributes = array(
274: 'charset',
275: 'content',
276: 'http-equiv',
277: 'name',
278: 'itemprop'
279: );
280: foreach ($meta as $key => $value) {
281: if (!in_array($key, $allowedAttributes)) {
282: throw new cInvalidArgumentException('Unallowed attribute for meta tag given - meta tag will be ignored!');
283: }
284: }
285: $this->_metaTags[] = $meta;
286: }
287:
288: 289: 290: 291: 292: 293: 294: 295:
296: public function setSubnav($additional = "", $aarea = "") {
297: global $area, $sess;
298:
299: if ($aarea == "") {
300: $aarea = $area;
301: }
302:
303: $this->_subnav = '
304: <script type="text/javascript">
305: parent.frames["right_top"].location.href = "' . $sess->url("main.php?area={$aarea}&frame=3&{$additional}") . '";
306: </script>
307: ';
308: }
309:
310: 311: 312:
313: public function setReload() {
314: $this->_scripts[] = "reload.js";
315: }
316:
317: 318: 319: 320: 321:
322: public function setMarkScript($item) {
323: $this->_markscript = markSubMenuItem($item, true);
324: }
325:
326: 327: 328: 329: 330: 331:
332: public function setEncoding($encoding) {
333: if (empty($encoding)) {
334: return;
335: }
336: $this->_metaTags[] = array(
337: 'http-equiv' => 'Content-type',
338: 'content' => 'text/html;charset=' . $encoding
339: );
340: }
341:
342: 343: 344: 345: 346: 347: 348: 349:
350: public function set($type, $key, $value) {
351: $this->_contenttemplate->set($type, $key, $value);
352: }
353:
354: 355: 356: 357: 358:
359: public function next() {
360: $this->_contenttemplate->next();
361: }
362:
363: 364: 365: 366: 367:
368: public function abortRendering() {
369: $this->_abort = true;
370: }
371:
372: 373: 374: 375: 376: 377:
378: public function displayCriticalError($msg) {
379: $this->_error = $msg;
380: $this->_abort = true;
381: }
382:
383: 384: 385: 386: 387: 388:
389: public function displayError($msg) {
390: $this->_error .= $msg . "<br>";
391: }
392:
393: 394: 395: 396: 397:
398: public function displayWarning($msg) {
399: $this->_warning .= $msg . "<br>";
400: }
401:
402: 403: 404: 405: 406:
407: public function displayInfo($msg) {
408: $this->_info .= $msg . "<br>";
409: }
410:
411: 412: 413: 414: 415: 416: 417: 418:
419: public function setContent($objects) {
420: if (!is_array($objects)) {
421: $objects = array(
422: $objects
423: );
424: }
425: $this->_objects = $objects;
426: }
427:
428: 429: 430: 431: 432: 433: 434: 435: 436:
437: public function appendContent($objects) {
438: if (!is_array($objects)) {
439: $this->_objects[] = $objects;
440: } else {
441: $this->_objects = array_merge($this->_objects, $objects);
442: }
443: }
444:
445: 446: 447: 448: 449: 450: 451: 452: 453: 454:
455: public function setPluginScript($plugin, $filename) {
456: global $cfg;
457: $path = $cfg['pica']['script_complexlist'];
458: }
459:
460: public function setStyleDirect($filepath) {
461: global $cfg;
462: $path = $cfg['pica']['style_complexlist'];
463: $this->_pagetemplate->set("s", "SCRIPTS", $path);
464:
465: $strstyle = "";
466:
467: $strstyle .= "<link href='styles/" . $path . "' type='text/css' rel='stylesheet'>\n";
468:
469: $this->_pagetemplate->set("s", "STYLES", $strstyle);
470: return $this->_pagetemplate->generate($cfg['path']['templates'] . $cfg['templates']['generic_page'], false);
471: }
472:
473: 474: 475: 476: 477: 478: 479: 480:
481: public function render($template = NULL, $return = false) {
482: global $cfg, $notification;
483:
484: if ($template == NULL) {
485: $template = $this->_contenttemplate;
486: }
487:
488:
489: $produceXhtml = getEffectiveSetting('generator', 'xhtml', 'false');
490: $meta = '';
491: foreach ($this->_metaTags as $metaTag) {
492: $tag = '<meta';
493: foreach ($metaTag as $key => $value) {
494: $tag .= ' ' . $key . '="' . $value . '"';
495: }
496: if ($produceXhtml) {
497: $tag .= ' /';
498: }
499: $tag .= ">\n";
500: $meta .= $tag;
501: }
502: if (!empty($meta)) {
503: $this->_pagetemplate->set('s', 'META', $meta);
504: } else {
505: $this->_pagetemplate->set('s', 'META', "");
506: }
507:
508: $strscript = $this->_subnav . "\n" . $this->_markscript . "\n";
509: foreach ($this->_scripts as $script) {
510: if (strpos($script, "http") === 0 || strpos($script, "//") === 0) {
511: $strscript .= '<script type="text/javascript" src="' . $script . '"></script>' . "\n";
512: } else if (strpos($script, "<script") === false) {
513: $strscript .= '<script type="text/javascript" src="scripts/' . $script . '"></script>' . "\n";
514: } else {
515: $strscript .= $script;
516: }
517: }
518: $this->_pagetemplate->set("s", "SCRIPTS", $strscript);
519:
520: $strstyle = "";
521: foreach ($this->_styles as $style) {
522: if (strpos($style, "http") === 0 || strpos($style, "//") === 0) {
523: $strstyle .= '<link href="' . $style . '" type="text/css" rel="stylesheet">' . "\n";
524: } else {
525: $strstyle .= '<link href="styles/' . $style . '" type="text/css" rel="stylesheet">' . "\n";
526: }
527: }
528: $this->_pagetemplate->set("s", "STYLES", $strstyle);
529:
530:
531: $infoMessages = cRegistry::getInfoMessages();
532: foreach ($infoMessages as $message) {
533: $this->displayInfo($message);
534: }
535:
536: $errorMessages = cRegistry::getErrorMessages();
537: foreach ($errorMessages as $message) {
538: $this->displayError($message);
539: }
540:
541: $warningMessages = cRegistry::getWarningMessages();
542: foreach ($warningMessages as $message) {
543: $this->displayWarning($message);
544: }
545: $text = "";
546: if ($this->_info != "") {
547: $text .= $notification->returnNotification("info", $this->_info) . "<br>";
548: }
549: if ($this->_warning != "") {
550: $text .= $notification->returnNotification("warning", $this->_warning) . "<br>";
551: }
552: if ($this->_error != "") {
553: $text .= $notification->returnNotification("error", $this->_error) . "<br>";
554: }
555:
556: $file = "";
557: if ($this->_pluginname == "") {
558: $file = $cfg['path']['templates'] . "template." . $this->_pagename . ".html";
559: } else {
560: $file = $cfg['path']['plugins'] . $this->_pluginname . "/templates/template." . $this->_pagename . ".html";
561: }
562:
563: if (!$this->_abort) {
564: if (count($this->_objects) == 0) {
565: if (cFileHandler::exists($file)) {
566: $this->_pagetemplate->set("s", "CONTENT", $text . $template->generate($file, true));
567: } else {
568: $this->_pagetemplate->set("s", "CONTENT", $text);
569: }
570: } else {
571: $str = "";
572: foreach ($this->_objects as $obj) {
573: if (method_exists($obj, "render")) {
574:
575:
576:
577: $old_str = $str;
578: ob_start();
579:
580:
581: $str .= $obj->render(false);
582:
583:
584: $str .= ob_get_contents();
585: if ($old_str == $str) {
586: cWarning(__FILE__, __LINE__, "Rendering this object (" . print_r($obj, true) . ") doesn't seem to have any effect.");
587: }
588: ob_end_clean();
589: }
590: }
591: $this->_pagetemplate->set("s", "CONTENT", $text . $str);
592: }
593: } else {
594: $this->_pagetemplate->set("s", "CONTENT", $text);
595: }
596:
597: return $this->_pagetemplate->generate($cfg['path']['templates'] . $cfg['templates']['generic_page'], $return);
598: }
599:
600: }
601: