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;
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 (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 (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 = '<script type="text/javascript">';
304: $this->_subnav .= 'parent.frames["right_top"].location.href = "';
305: $this->_subnav .= $sess->url("main.php?area=" . $aarea . "&frame=3&" . $additional) . '";';
306: $this->_subnav .= '</script>';
307: }
308:
309: 310: 311:
312: public function setReload() {
313: $this->_scripts[] = "reload.js";
314: }
315:
316: 317: 318: 319: 320:
321: public function setMarkScript($item) {
322: $this->_markscript = markSubMenuItem($item, true);
323: }
324:
325: 326: 327: 328: 329: 330:
331: public function setEncoding($encoding) {
332: if (empty($encoding)) {
333: return;
334: }
335: $this->_metaTags[] = array(
336: 'http-equiv' => 'Content-type',
337: 'content' => 'text/html;charset=' . $encoding
338: );
339: }
340:
341: 342: 343: 344: 345: 346: 347: 348:
349: public function set($type, $key, $value) {
350: $this->_contenttemplate->set($type, $key, $value);
351: }
352:
353: 354: 355: 356: 357:
358: public function next() {
359: $this->_contenttemplate->next();
360: }
361:
362: 363: 364: 365: 366:
367: public function abortRendering() {
368: $this->_abort = true;
369: }
370:
371: 372: 373: 374: 375: 376:
377: public function displayCriticalError($msg) {
378: $this->_error = $msg;
379: $this->_abort = true;
380: }
381:
382: 383: 384: 385: 386: 387:
388: public function displayError($msg) {
389: $this->_error .= $msg . "<br>";
390: }
391:
392: 393: 394: 395: 396:
397: public function displayWarning($msg) {
398: $this->_warning .= $msg . "<br>";
399: }
400:
401: 402: 403: 404: 405:
406: public function displayInfo($msg) {
407: $this->_info .= $msg . "<br>";
408: }
409:
410: 411: 412: 413: 414: 415: 416: 417:
418: public function setContent($objects) {
419: if (!is_array($objects)) {
420: $objects = array(
421: $objects
422: );
423: }
424: $this->_objects = $objects;
425: }
426:
427: 428: 429: 430: 431: 432: 433: 434: 435:
436: public function appendContent($objects) {
437: if (!is_array($objects)) {
438: $this->_objects[] = $objects;
439: } else {
440: $this->_objects = array_merge($this->_objects, $objects);
441: }
442: }
443:
444: 445: 446: 447: 448: 449: 450: 451: 452: 453:
454: public function setPluginScript($plugin, $filename) {
455: global $cfg;
456: $path = $cfg['pica']['script_complexlist'];
457: }
458:
459: public function setStyleDirect($filepath) {
460: global $cfg;
461: $path = $cfg['pica']['style_complexlist'];
462: $this->_pagetemplate->set("s", "SCRIPTS", $path);
463:
464: $strstyle = "";
465:
466: $strstyle .= "<link href='styles/" . $path . "' type='text/css' rel='stylesheet'>\n";
467:
468: $this->_pagetemplate->set("s", "STYLES", $strstyle);
469: return $this->_pagetemplate->generate($cfg['path']['templates'] . $cfg['templates']['generic_page'], false);
470: }
471:
472: 473: 474: 475: 476: 477: 478: 479:
480: public function render($template = null, $return = false) {
481: global $cfg, $notification;
482:
483: if ($template == null) {
484: $template = $this->_contenttemplate;
485: }
486:
487:
488: $produceXhtml = getEffectiveSetting('generator', 'xhtml', 'false');
489: $meta = '';
490: foreach ($this->_metaTags as $metaTag) {
491: $tag = '<meta';
492: foreach ($metaTag as $key => $value) {
493: $tag .= ' ' . $key . '="' . $value . '"';
494: }
495: if ($produceXhtml) {
496: $tag .= ' /';
497: }
498: $tag .= ">\n";
499: $meta .= $tag;
500: }
501: if (!empty($meta)) {
502: $this->_pagetemplate->set('s', 'META', $meta);
503: } else {
504: $this->_pagetemplate->set('s', 'META', "");
505: }
506:
507: $strscript = $this->_subnav . "\n" . $this->_markscript . "\n";
508: foreach ($this->_scripts as $script) {
509: if (strpos($script, "http") === 0 || strpos($script, "//") === 0) {
510: $strscript .= '<script type="text/javascript" src="' . $script . '"></script>' . "\n";
511: } else if (strpos($script, "<script") === false) {
512: $strscript .= '<script type="text/javascript" src="scripts/' . $script . '"></script>' . "\n";
513: } else {
514: $strscript .= $script;
515: }
516: }
517: $this->_pagetemplate->set("s", "SCRIPTS", $strscript);
518:
519: $strstyle = "";
520: foreach ($this->_styles as $style) {
521: if (strpos($style, "http") === 0 || strpos($style, "//") === 0) {
522: $strstyle .= '<link href="' . $style . '" type="text/css" rel="stylesheet">' . "\n";
523: } else {
524: $strstyle .= '<link href="styles/' . $style . '" type="text/css" rel="stylesheet">' . "\n";
525: }
526: }
527: $this->_pagetemplate->set("s", "STYLES", $strstyle);
528:
529:
530: $infoMessages = cRegistry::getInfoMessages();
531: foreach ($infoMessages as $message) {
532: $this->displayInfo($message);
533: }
534:
535: $errorMessages = cRegistry::getErrorMessages();
536: foreach ($errorMessages as $message) {
537: $this->displayError($message);
538: }
539:
540: $warningMessages = cRegistry::getWarningMessages();
541: foreach ($warningMessages as $message) {
542: $this->displayWarning($message);
543: }
544: $text = "";
545: if ($this->_info != "") {
546: $text .= $notification->returnNotification("info", $this->_info) . "<br>";
547: }
548: if ($this->_warning != "") {
549: $text .= $notification->returnNotification("warning", $this->_warning) . "<br>";
550: }
551: if ($this->_error != "") {
552: $text .= $notification->returnNotification("error", $this->_error) . "<br>";
553: }
554:
555: $file = "";
556: if ($this->_pluginname == "") {
557: $file = $cfg['path']['templates'] . "template." . $this->_pagename . ".html";
558: } else {
559: $file = $cfg['path']['plugins'] . $this->_pluginname . "/templates/template." . $this->_pagename . ".html";
560: }
561:
562: if (!$this->_abort) {
563: if (count($this->_objects) == 0) {
564: if (cFileHandler::exists($file)) {
565: $this->_pagetemplate->set("s", "CONTENT", $text . $template->generate($file, true));
566: } else {
567: $this->_pagetemplate->set("s", "CONTENT", $text);
568: }
569: } else {
570: $str = "";
571: foreach ($this->_objects as $obj) {
572: if (method_exists($obj, "render")) {
573:
574:
575:
576: $old_str = $str;
577: ob_start();
578:
579:
580: $str .= $obj->render(false);
581:
582:
583: $str .= ob_get_contents();
584: if ($old_str == $str) {
585: cWarning(__FILE__, __LINE__, "Rendering this object (" . print_r($obj, true) . ") doesn't seem to have any effect.");
586: }
587: ob_end_clean();
588: }
589: }
590: $this->_pagetemplate->set("s", "CONTENT", $text . $str);
591: }
592: } else {
593: $this->_pagetemplate->set("s", "CONTENT", $text);
594: }
595:
596: return $this->_pagetemplate->generate($cfg['path']['templates'] . $cfg['templates']['generic_page'], $return);
597: }
598:
599: }
600: