2023-10-18 22:42:01 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Page is the Controller Class
|
|
|
|
* which should be extended by any page
|
|
|
|
*
|
|
|
|
* @author Christian Haschek
|
|
|
|
*/
|
|
|
|
class Page
|
|
|
|
{
|
|
|
|
protected $_controller;
|
|
|
|
protected $_action;
|
|
|
|
protected $_template;
|
|
|
|
public $variables;
|
|
|
|
public $params;
|
|
|
|
public $render;
|
|
|
|
public $menu_text;
|
|
|
|
public $menu_image;
|
|
|
|
public $menu_priority;
|
|
|
|
public $submenu;
|
|
|
|
|
2023-10-18 19:08:38 +02:00
|
|
|
private $r;
|
|
|
|
|
2023-10-18 22:42:01 +02:00
|
|
|
function __construct($controller, $action, $r = 1, $params = [])
|
|
|
|
{
|
|
|
|
$this->_controller = $controller;
|
|
|
|
$this->_action = $action;
|
|
|
|
$this->render = $r;
|
|
|
|
$this->submenu = array();
|
|
|
|
$this->setMenu();
|
|
|
|
$this->params = $params;
|
|
|
|
if(is_array($GLOBALS['vars']) && is_array($this->params))
|
|
|
|
$this->params = array_merge($this->params, $GLOBALS['vars']);
|
|
|
|
$this->menu_image = '/css/imgs/empty.png';
|
2023-10-18 19:08:38 +02:00
|
|
|
|
|
|
|
if($GLOBALS['redis'] !== false)
|
|
|
|
$this->r = $GLOBALS['redis'];
|
|
|
|
else
|
|
|
|
$this->r = false;
|
2023-10-18 22:42:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function setMenu()
|
|
|
|
{
|
|
|
|
$this->menu_text = '';
|
|
|
|
$this->menu_priority = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function redirect($url)
|
|
|
|
{
|
2023-10-22 01:46:22 +02:00
|
|
|
//header("Location: $url");
|
|
|
|
header("HX-Redirect: ". $url);
|
2023-10-18 22:42:01 +02:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* override this function to check if a user can use this object
|
|
|
|
* @return true -> user will be able to access
|
|
|
|
* @return false -> user will not be able to access and this page won't
|
|
|
|
* be shown in the menu
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function maySeeThisPage()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function set($name, $value)
|
|
|
|
{
|
|
|
|
$this->variables[$name] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
function get($name)
|
|
|
|
{
|
|
|
|
return $this->variables[$name];
|
|
|
|
}
|
|
|
|
|
|
|
|
function __destruct()
|
|
|
|
{
|
|
|
|
// if($this->render)
|
|
|
|
// $this->_template->render();
|
|
|
|
}
|
|
|
|
|
|
|
|
function addHelpers($m)
|
|
|
|
{
|
|
|
|
$m->addHelper('case', [
|
|
|
|
'lower' => function($value) { return strtolower((string) $value); },
|
|
|
|
'upper' => function($value) { return strtoupper((string) $value); }
|
|
|
|
]);
|
|
|
|
$m->addHelper('!!', function($value) { return $value . '!!'; });
|
|
|
|
|
|
|
|
return $m;
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderPagecontent()
|
|
|
|
{
|
|
|
|
$controller_dir = ROOT . DS . 'pages' . DS . $this->_controller . DS;
|
|
|
|
|
2023-10-21 21:21:52 +02:00
|
|
|
//when the template path starts with a / it is relative to the root of the project
|
|
|
|
if($this->variables['template'][0]=='/')
|
|
|
|
$this->variables['template'] = '../../'.$this->variables['template'];
|
2023-10-18 22:42:01 +02:00
|
|
|
if($this->variables['template'] && file_exists(ROOT . DS . 'pages' . DS . $this->_controller . DS . $this->variables['template']))
|
2023-10-21 17:06:20 +02:00
|
|
|
$templatefile = ROOT . DS . 'pages' . DS . $this->_controller . DS . $this->variables['template'];
|
2023-10-18 22:42:01 +02:00
|
|
|
|
2023-10-21 21:21:52 +02:00
|
|
|
|
2023-10-21 17:06:20 +02:00
|
|
|
//render template by running include
|
|
|
|
ob_start();
|
2023-10-21 22:12:56 +02:00
|
|
|
if(is_array($this->variables))
|
|
|
|
extract($this->variables);
|
2023-10-21 21:30:20 +02:00
|
|
|
if($templatefile!= '')
|
|
|
|
include($templatefile);
|
2023-10-21 17:06:20 +02:00
|
|
|
$pagecontent = ob_get_contents();
|
|
|
|
ob_end_clean();
|
|
|
|
|
|
|
|
|
|
|
|
//$pagecontent = $m->render($template, $this->variables);
|
2023-10-18 22:42:01 +02:00
|
|
|
|
|
|
|
return $pagecontent;
|
|
|
|
}
|
|
|
|
}
|