2013-01-11 16:55:34 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Implementation of view class
|
|
|
|
*
|
|
|
|
* @category DMS
|
2013-02-14 11:10:53 +00:00
|
|
|
* @package SeedDMS
|
2013-01-11 16:55:34 +00:00
|
|
|
* @license GPL 2
|
|
|
|
* @version @version@
|
|
|
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright Copyright (C) 2002-2005 Markus Westphal,
|
|
|
|
* 2006-2008 Malcolm Cowe, 2010 Matteo Lucarelli,
|
|
|
|
* 2010-2012 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
|
|
|
|
2017-06-19 09:08:06 +00:00
|
|
|
require_once "inc.ClassHook.php";
|
2017-05-02 16:29:47 +00:00
|
|
|
|
2013-01-11 16:55:34 +00:00
|
|
|
/**
|
|
|
|
* Parent class for all view classes
|
|
|
|
*
|
|
|
|
* @category DMS
|
2013-02-14 11:10:53 +00:00
|
|
|
* @package SeedDMS
|
2013-01-11 16:55:34 +00:00
|
|
|
* @author Markus Westphal, Malcolm Cowe, Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright Copyright (C) 2002-2005 Markus Westphal,
|
|
|
|
* 2006-2008 Malcolm Cowe, 2010 Matteo Lucarelli,
|
|
|
|
* 2010-2012 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
2013-02-14 11:10:53 +00:00
|
|
|
class SeedDMS_View_Common {
|
2015-08-20 13:53:30 +00:00
|
|
|
protected $theme;
|
2013-01-11 16:55:34 +00:00
|
|
|
|
2015-08-20 13:53:30 +00:00
|
|
|
protected $params;
|
2013-01-11 16:55:34 +00:00
|
|
|
|
2018-04-06 06:31:11 +00:00
|
|
|
protected $baseurl;
|
|
|
|
|
|
|
|
protected $imgpath;
|
|
|
|
|
|
|
|
public function __construct($params, $theme='bootstrap') {
|
2013-01-11 16:55:34 +00:00
|
|
|
$this->theme = $theme;
|
|
|
|
$this->params = $params;
|
2018-04-06 06:31:11 +00:00
|
|
|
$this->baseurl = '';
|
|
|
|
$this->imgpath = '../views/'.$theme.'/images/';
|
2013-01-11 16:55:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-06 06:31:11 +00:00
|
|
|
public function __invoke($get=array()) {
|
2019-08-08 07:11:47 +00:00
|
|
|
$this->callHook('preRun', isset($get['action']) ? $get['action'] : 'show');
|
2015-08-20 13:53:30 +00:00
|
|
|
if(isset($get['action']) && $get['action']) {
|
|
|
|
if(method_exists($this, $get['action'])) {
|
|
|
|
$this->{$get['action']}();
|
|
|
|
} else {
|
2018-06-27 16:56:01 +00:00
|
|
|
echo "Missing action '".htmlspecialchars($get['action'])."'";
|
2015-08-20 13:53:30 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
$this->show();
|
2019-08-08 07:11:47 +00:00
|
|
|
$this->callHook('postRun', isset($get['action']) ? $get['action'] : 'show');
|
2015-08-20 13:53:30 +00:00
|
|
|
}
|
|
|
|
|
2018-04-06 06:31:11 +00:00
|
|
|
public function setParams($params) {
|
2013-01-11 16:55:34 +00:00
|
|
|
$this->params = $params;
|
|
|
|
}
|
|
|
|
|
2018-04-06 06:31:11 +00:00
|
|
|
public function setParam($name, $value) {
|
2013-01-11 16:55:34 +00:00
|
|
|
$this->params[$name] = $value;
|
|
|
|
}
|
|
|
|
|
2018-04-06 06:31:11 +00:00
|
|
|
public function getParam($name) {
|
2015-08-25 12:58:16 +00:00
|
|
|
if(isset($this->params[$name]))
|
|
|
|
return $this->params[$name];
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-05-12 10:02:03 +00:00
|
|
|
/**
|
|
|
|
* Check if the view has a parameter with the given name
|
|
|
|
*
|
|
|
|
* @param string $name name of parameter
|
|
|
|
* @return boolean true if parameter exists otherwise false
|
|
|
|
*/
|
|
|
|
function hasParam($name) {
|
|
|
|
return isset($this->params[$name]) ? true : false;
|
|
|
|
}
|
|
|
|
|
2018-04-06 06:31:11 +00:00
|
|
|
public function unsetParam($name) {
|
2013-06-18 16:14:14 +00:00
|
|
|
if(isset($this->params[$name]))
|
|
|
|
unset($this->params[$name]);
|
|
|
|
}
|
|
|
|
|
2018-04-06 06:31:11 +00:00
|
|
|
public function setBaseUrl($baseurl) {
|
|
|
|
$this->baseurl = $baseurl;
|
|
|
|
}
|
|
|
|
|
2021-01-13 08:05:19 +00:00
|
|
|
public function getTheme() {
|
|
|
|
return $this->theme;
|
|
|
|
}
|
|
|
|
|
2018-04-06 06:31:11 +00:00
|
|
|
public function show() {
|
2013-01-11 16:55:34 +00:00
|
|
|
}
|
2013-05-02 10:12:28 +00:00
|
|
|
|
2013-07-31 15:28:02 +00:00
|
|
|
/**
|
2021-04-23 07:56:25 +00:00
|
|
|
* Return a list of hook classes for the current class
|
2013-07-31 15:28:02 +00:00
|
|
|
*
|
2021-04-23 07:56:25 +00:00
|
|
|
* Hooks are associated to a view class. Calling a hook with
|
|
|
|
* SeedDMS_View_Common::callHook() will run through a list of
|
|
|
|
* view classes searching for the hook. This method returns this
|
|
|
|
* list.
|
2013-07-31 15:28:02 +00:00
|
|
|
*
|
2021-04-23 07:56:25 +00:00
|
|
|
* If a view is implemented in SeedDMS_View_Example which inherits
|
|
|
|
* from SeedDMS_Theme_Style which again inherits from SeedDMS_View_Common,
|
|
|
|
* then this method will return an array with the elments:
|
|
|
|
* 'Example', 'Style', 'Common'. If SeedDMS_View_Example also sets
|
|
|
|
* the class property 'viewAliasName', then this value will be added
|
|
|
|
* to the beginning of the list.
|
2015-07-15 20:30:03 +00:00
|
|
|
*
|
2021-04-23 07:56:25 +00:00
|
|
|
* When a hook is called, it will run through this list and checks
|
|
|
|
* if $GLOBALS['SEEDDMS_HOOKS']['view'][<element>] exists and contains
|
|
|
|
* an instanciated class. This class must implement the hook.
|
|
|
|
*
|
|
|
|
* @return array list of view class names.
|
2013-07-31 15:28:02 +00:00
|
|
|
*/
|
2021-04-23 07:56:25 +00:00
|
|
|
protected function getHookClassNames() { /* {{{ */
|
2019-08-08 07:11:47 +00:00
|
|
|
$tmps = array();
|
2021-04-23 04:55:10 +00:00
|
|
|
/* the viewAliasName can be set in the view to specify a different name
|
|
|
|
* than extracted from the class name.
|
|
|
|
*/
|
|
|
|
if(property_exists($this, 'viewAliasName') && !empty($this->viewAliasName)) {
|
|
|
|
$tmps[] = $this->viewAliasName;
|
|
|
|
}
|
2013-05-02 10:12:28 +00:00
|
|
|
$tmp = explode('_', get_class($this));
|
2019-08-08 07:11:47 +00:00
|
|
|
$tmps[] = $tmp[2];
|
2020-12-15 19:20:37 +00:00
|
|
|
foreach(class_parents($this) as $pc) {
|
|
|
|
$tmp = explode('_', $pc);
|
|
|
|
$tmps[] = $tmp[2];
|
|
|
|
}
|
2019-08-08 07:11:47 +00:00
|
|
|
/* Run array_unique() in case the parent class has the same suffix */
|
|
|
|
$tmps = array_unique($tmps);
|
2021-04-23 07:56:25 +00:00
|
|
|
return $tmps;
|
|
|
|
} /* }}} */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call a hook with a given name
|
|
|
|
*
|
|
|
|
* Checks if a hook with the given name and for the current view
|
|
|
|
* exists and executes it. The name of the current view is taken
|
|
|
|
* from the current class name by lower casing the first char.
|
|
|
|
* This function will execute all registered hooks in the order
|
|
|
|
* they were registered.
|
|
|
|
*
|
|
|
|
* Attention: as func_get_arg() cannot handle references passed to the hook,
|
|
|
|
* callHook() should not be called if that is required. In that case get
|
|
|
|
* a list of hook objects with getHookObjects() and call the hooks yourself.
|
|
|
|
*
|
|
|
|
* @params string $hook name of hook
|
|
|
|
* @return string concatenated string, merged arrays or whatever the hook
|
|
|
|
* function returns
|
|
|
|
*/
|
|
|
|
public function callHook($hook) { /* {{{ */
|
|
|
|
$tmps = $this->getHookClassNames();
|
2013-09-03 20:07:16 +00:00
|
|
|
$ret = null;
|
2019-08-08 07:11:47 +00:00
|
|
|
foreach($tmps as $tmp)
|
|
|
|
if(isset($GLOBALS['SEEDDMS_HOOKS']['view'][lcfirst($tmp)])) {
|
|
|
|
foreach($GLOBALS['SEEDDMS_HOOKS']['view'][lcfirst($tmp)] as $hookObj) {
|
2013-05-02 10:12:28 +00:00
|
|
|
if (method_exists($hookObj, $hook)) {
|
2013-07-31 15:28:02 +00:00
|
|
|
switch(func_num_args()) {
|
|
|
|
case 1:
|
2013-09-03 20:07:16 +00:00
|
|
|
$tmpret = $hookObj->$hook($this);
|
|
|
|
break;
|
2013-07-31 15:28:02 +00:00
|
|
|
case 2:
|
2013-09-03 20:07:16 +00:00
|
|
|
$tmpret = $hookObj->$hook($this, func_get_arg(1));
|
|
|
|
break;
|
2013-07-31 15:28:02 +00:00
|
|
|
case 3:
|
2013-09-03 20:07:16 +00:00
|
|
|
$tmpret = $hookObj->$hook($this, func_get_arg(1), func_get_arg(2));
|
2017-01-17 16:41:52 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
$tmpret = $hookObj->$hook($this, func_get_arg(1), func_get_arg(2), func_get_arg(3));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case 5:
|
|
|
|
$tmpret = $hookObj->$hook($this, func_get_arg(1), func_get_arg(2), func_get_arg(3), func_get_arg(4));
|
2017-05-02 16:29:47 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-06-13 12:41:57 +00:00
|
|
|
if($tmpret !== null) {
|
2019-01-17 17:30:10 +00:00
|
|
|
if(is_string($tmpret)) {
|
|
|
|
$ret = ($ret === null) ? $tmpret : (is_string($ret) ? $ret.$tmpret : array_merge($ret, array($tmpret)));
|
|
|
|
} elseif(is_array($tmpret) || is_object($tmpret)) {
|
|
|
|
$ret = ($ret === null) ? $tmpret : (is_string($ret) ? array_merge(array($ret), $tmpret) : array_merge($ret, $tmpret));
|
2017-06-13 12:41:57 +00:00
|
|
|
} else
|
2017-05-02 16:29:47 +00:00
|
|
|
$ret = $tmpret;
|
2013-07-31 15:28:02 +00:00
|
|
|
}
|
2013-05-02 10:12:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-09-03 20:07:16 +00:00
|
|
|
return $ret;
|
2014-01-10 06:56:19 +00:00
|
|
|
} /* }}} */
|
|
|
|
|
2015-07-15 20:30:03 +00:00
|
|
|
/**
|
|
|
|
* Return all hook objects for the given or calling class
|
|
|
|
*
|
|
|
|
* <code>
|
|
|
|
* <?php
|
|
|
|
* $hookObjs = $this->getHookObjects();
|
|
|
|
* foreach($hookObjs as $hookObj) {
|
|
|
|
* if (method_exists($hookObj, $hook)) {
|
|
|
|
* $ret = $hookObj->$hook($this, ...);
|
|
|
|
* ...
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ?>
|
|
|
|
* </code>
|
|
|
|
*
|
2021-04-23 07:56:25 +00:00
|
|
|
* The method does not return hooks for parent classes nor does it
|
|
|
|
* evaluate the viewAliasName property.
|
|
|
|
*
|
2015-07-15 20:30:03 +00:00
|
|
|
* @params string $classname name of class (current class if left empty)
|
|
|
|
* @return array list of hook objects registered for the class
|
|
|
|
*/
|
2018-04-06 06:31:11 +00:00
|
|
|
public function getHookObjects($classname='') { /* {{{ */
|
2015-07-15 20:30:03 +00:00
|
|
|
if($classname)
|
|
|
|
$tmp = explode('_', $classname);
|
|
|
|
else
|
|
|
|
$tmp = explode('_', get_class($this));
|
|
|
|
if(isset($GLOBALS['SEEDDMS_HOOKS']['view'][lcfirst($tmp[2])])) {
|
|
|
|
return $GLOBALS['SEEDDMS_HOOKS']['view'][lcfirst($tmp[2])];
|
|
|
|
}
|
|
|
|
return array();
|
|
|
|
} /* }}} */
|
|
|
|
|
2014-01-10 06:56:19 +00:00
|
|
|
/**
|
|
|
|
* Check if a hook is registered
|
|
|
|
*
|
|
|
|
* @param $hook string name of hook
|
|
|
|
* @return mixed false if one of the hooks fails,
|
|
|
|
* true if all hooks succedded,
|
|
|
|
* null if no hook was called
|
|
|
|
*/
|
2018-04-06 06:31:11 +00:00
|
|
|
public function hasHook($hook) { /* {{{ */
|
2021-04-23 07:56:25 +00:00
|
|
|
$tmps = $this->getHookClassNames();
|
2019-10-01 12:06:00 +00:00
|
|
|
foreach($tmps as $tmp) {
|
|
|
|
if(isset($GLOBALS['SEEDDMS_HOOKS']['view'][lcfirst($tmp)])) {
|
|
|
|
foreach($GLOBALS['SEEDDMS_HOOKS']['view'][lcfirst($tmp)] as $hookObj) {
|
|
|
|
if (method_exists($hookObj, $hook)) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-01-10 06:56:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
} /* }}} */
|
|
|
|
|
2019-08-08 07:11:47 +00:00
|
|
|
public function jsTranslations($keys) { /* {{{ */
|
2016-03-08 09:37:07 +00:00
|
|
|
echo "var trans = {\n";
|
|
|
|
foreach($keys as $key) {
|
|
|
|
echo " '".$key."': '".str_replace("'", "\\\'", getMLText($key))."',\n";
|
|
|
|
}
|
|
|
|
echo "};\n";
|
2019-08-08 07:11:47 +00:00
|
|
|
} /* }}} */
|
2013-01-11 16:55:34 +00:00
|
|
|
}
|