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()) {
|
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();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2015-07-15 20:30:03 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2013-07-31 15:28:02 +00:00
|
|
|
* @params string $hook name of hook
|
2017-06-20 07:13:24 +00:00
|
|
|
* @return string concatenated string, merged arrays or whatever the hook
|
|
|
|
* function returns
|
2013-07-31 15:28:02 +00:00
|
|
|
*/
|
2018-04-06 06:31:11 +00:00
|
|
|
public function callHook($hook) { /* {{{ */
|
2013-05-02 10:12:28 +00:00
|
|
|
$tmp = explode('_', get_class($this));
|
2013-09-03 20:07:16 +00:00
|
|
|
$ret = null;
|
2013-07-21 09:52:58 +00:00
|
|
|
if(isset($GLOBALS['SEEDDMS_HOOKS']['view'][lcfirst($tmp[2])])) {
|
|
|
|
foreach($GLOBALS['SEEDDMS_HOOKS']['view'][lcfirst($tmp[2])] 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) {
|
2017-05-02 16:29:47 +00:00
|
|
|
if(is_string($tmpret))
|
|
|
|
$ret .= $tmpret;
|
2017-06-13 12:41:57 +00:00
|
|
|
elseif(is_array($tmpret) || is_object($tmpret)) {
|
2017-05-02 16:29:47 +00:00
|
|
|
$ret = ($ret === null) ? $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>
|
|
|
|
*
|
|
|
|
* @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) { /* {{{ */
|
2014-01-10 06:56:19 +00:00
|
|
|
$tmp = explode('_', get_class($this));
|
|
|
|
if(isset($GLOBALS['SEEDDMS_HOOKS']['view'][lcfirst($tmp[2])])) {
|
|
|
|
foreach($GLOBALS['SEEDDMS_HOOKS']['view'][lcfirst($tmp[2])] as $hookObj) {
|
|
|
|
if (method_exists($hookObj, $hook)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
} /* }}} */
|
|
|
|
|
2018-04-06 06:31:11 +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";
|
|
|
|
}
|
2013-01-11 16:55:34 +00:00
|
|
|
}
|
|
|
|
?>
|