From f275ea19272a376f07abd033e5945dee05ce5bfa Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Fri, 23 Apr 2021 06:54:43 +0200 Subject: [PATCH 1/6] add example on how to set viewAliasName --- views/bootstrap/class.ViewFolder.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/views/bootstrap/class.ViewFolder.php b/views/bootstrap/class.ViewFolder.php index b6bcf6b68..6af5228e5 100644 --- a/views/bootstrap/class.ViewFolder.php +++ b/views/bootstrap/class.ViewFolder.php @@ -36,6 +36,11 @@ require_once("SeedDMS/Preview.php"); */ class SeedDMS_View_ViewFolder extends SeedDMS_Theme_Style { + /** + * set a different name which is used to specify the hooks. + */ + //public $viewAliasName = ''; + function data() { /* {{{ */ $dms = $this->params['dms']; $user = $this->params['user']; @@ -565,7 +570,7 @@ $('body').on('click', '.order-btn', function(ev) { //$this->htmlAddHeader(''."\n", 'js'); - echo $this->callHook('startPage'); +// echo $this->callHook('startPage'); $this->htmlStartPage(getMLText("folder_title", array("foldername" => htmlspecialchars($folder->getName())))); $this->globalNavigation($folder); $this->contentStart(); From 3d15736772ebd39b421388f01b5a8d63577e6300 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Fri, 23 Apr 2021 06:55:10 +0200 Subject: [PATCH 2/6] read property viewAliasName --- inc/inc.ClassViewCommon.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/inc/inc.ClassViewCommon.php b/inc/inc.ClassViewCommon.php index e92788c51..efce8acf8 100644 --- a/inc/inc.ClassViewCommon.php +++ b/inc/inc.ClassViewCommon.php @@ -114,6 +114,12 @@ class SeedDMS_View_Common { */ public function callHook($hook) { /* {{{ */ $tmps = array(); + /* 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; + } $tmp = explode('_', get_class($this)); $tmps[] = $tmp[2]; foreach(class_parents($this) as $pc) { From 1a114830a505421a08a2d3311a21b06b6da90aec Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Fri, 23 Apr 2021 09:54:36 +0200 Subject: [PATCH 3/6] do not include page navigation with ajax anymore --- views/bootstrap/class.AddSubFolder.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/views/bootstrap/class.AddSubFolder.php b/views/bootstrap/class.AddSubFolder.php index 0282c54fb..393e67510 100644 --- a/views/bootstrap/class.AddSubFolder.php +++ b/views/bootstrap/class.AddSubFolder.php @@ -74,10 +74,12 @@ $(document).ready( function() { $this->htmlStartPage(getMLText("folder_title", array("foldername" => htmlspecialchars($folder->getName())))); $this->globalNavigation($folder); $this->contentStart(); -// $this->pageNavigation($this->getFolderPathHTML($folder, true), "view_folder", $folder); + $this->pageNavigation($this->getFolderPathHTML($folder, true), "view_folder", $folder); + /* ?>
getID()."\"" : "") ?>>
contentHeading(getMLText("add_subfolder")); $this->contentContainerStart(); ?> From fd90623de47bd36d9ce862bf816be21b6d41c8c6 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Fri, 23 Apr 2021 09:55:25 +0200 Subject: [PATCH 4/6] use callHook() instead of interating over hookObjects --- views/bootstrap/class.Bootstrap.php | 38 ++++++++--------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/views/bootstrap/class.Bootstrap.php b/views/bootstrap/class.Bootstrap.php index 32bed970f..8032f59c6 100644 --- a/views/bootstrap/class.Bootstrap.php +++ b/views/bootstrap/class.Bootstrap.php @@ -79,12 +79,8 @@ class SeedDMS_Theme_Style extends SeedDMS_View_Common { header($name . ": " . $value); } } - $hookObjs = $this->getHookObjects('SeedDMS_View_Bootstrap'); - foreach($hookObjs as $hookObj) { - if (method_exists($hookObj, 'startPage')) { - $hookObj->startPage($this); - } - } + if($this->hasHook('startPage')) + $this->callHook('startPage'); echo "\n"; echo "\n\n"; echo "\n"; @@ -147,11 +143,8 @@ background-image: linear-gradient(to bottom, #882222, #111111);; echo "
".$flashmsg['msg']."
\n"; } echo "

".getMLText('recent_uploads')."

\n"; - foreach($hookObjs as $hookObj) { - if (method_exists($hookObj, 'startBody')) { - $hookObj->startBody($this); - } - } + if($this->hasHook('startBody')) + $this->callHook('startBody'); } /* }}} */ function htmlAddHeader($head, $type='js') { /* {{{ */ @@ -166,13 +159,9 @@ background-image: linear-gradient(to bottom, #882222, #111111);; function htmlEndPage($nofooter=false) { /* {{{ */ if(!$nofooter) { - $hookObjs = $this->getHookObjects('SeedDMS_View_Bootstrap'); $html = $this->footNote(); - foreach($hookObjs as $hookObj) { - if (method_exists($hookObj, 'footNote')) { - $html = $hookObj->footNote($this, $html); - } - } + if($this->hasHook('footNote')) + $html = $this->callHook('footNote', $html); echo $html; if($this->params['showmissingtranslations']) { $this->missingLanguageKeys(); @@ -326,12 +315,8 @@ background-image: linear-gradient(to bottom, #882222, #111111);; $menuitems['my_documents'] = array('link'=>"../out/out.MyDocuments.php?inProcess=1", 'label'=>'my_documents'); if ($accessobject->check_view_access('MyAccount')) $menuitems['my_account'] = array('link'=>"../out/out.MyAccount.php", 'label'=>'my_account'); - $hookObjs = $this->getHookObjects('SeedDMS_View_Bootstrap'); - foreach($hookObjs as $hookObj) { - if (method_exists($hookObj, 'userMenuItems')) { - $menuitems = $hookObj->userMenuItems($this, $menuitems); - } - } + if($this->hasHook('userMenuItems')) + $menuitems = $this->callHook('userMenuItems', $menuitems); if($menuitems) { foreach($menuitems as $menuitem) { echo "
  • ".getMLText($menuitem['label'])."
  • "; @@ -427,11 +412,8 @@ background-image: linear-gradient(to bottom, #882222, #111111);; $menuitems['help'] = array('link'=>'../out/out.Help.php?context='.$tmp[1], 'label'=>"help"); } /* Check if hook exists because otherwise callHook() will override $menuitems */ - foreach($hookObjs as $hookObj) { - if (method_exists($hookObj, 'globalNavigationBar')) { - $menuitems = $hookObj->globalNavigationBar($this, $menuitems); - } - } + if($this->hasHook('globalNavigationBar')) + $menuitems = $this->callHook('globalNavigationBar', $menuitems); foreach($menuitems as $menuitem) { if(!empty($menuitem['children'])) { echo "
  • \n"; From a7e214b5a93c7061a454baf2d7167dc97ba67c21 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Fri, 23 Apr 2021 09:55:58 +0200 Subject: [PATCH 5/6] check for missing class 'finfo', add style table-sm --- views/bootstrap/class.Info.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/views/bootstrap/class.Info.php b/views/bootstrap/class.Info.php index 67a33747c..ffdc5f759 100644 --- a/views/bootstrap/class.Info.php +++ b/views/bootstrap/class.Info.php @@ -59,7 +59,7 @@ class SeedDMS_View_Info extends SeedDMS_Theme_Style { $this->columnStart(6); $this->contentHeading(getMLText("seeddms_info")); $seedextensions = $extmgr->getExtensionConfiguration(); - echo "\n"; + echo "
    \n"; echo "\n\n"; echo "\n"; @@ -76,7 +76,7 @@ class SeedDMS_View_Info extends SeedDMS_Theme_Style { $this->columnStart(6); if($user->isAdmin()) { $this->contentHeading(getMLText("php_info")); - echo "
    ".getMLText("name"); echo "
    \n"; + echo "
    \n"; echo "\n\n"; echo "\n"; @@ -87,7 +87,7 @@ class SeedDMS_View_Info extends SeedDMS_Theme_Style { $this->contentHeading(getMLText("installed_php_extensions")); $phpextensions = get_loaded_extensions(false); - echo "
    ".getMLText("name"); echo "
    \n"; + echo "
    \n"; echo "\n\n"; echo "\n"; @@ -97,7 +97,7 @@ class SeedDMS_View_Info extends SeedDMS_Theme_Style { echo "\n
    ".getMLText("name"); echo "
    \n"; $this->contentHeading(getMLText("missing_php_extensions")); - echo "\n"; + echo "
    \n"; echo "\n\n"; echo "\n"; @@ -107,11 +107,11 @@ class SeedDMS_View_Info extends SeedDMS_Theme_Style { echo "\n"; echo "\n
    ".getMLText("name"); echo "
    ".$extname.""."
    \n"; - $this->contentHeading(getMLText("missing_php_functions")); - echo "\n"; + $this->contentHeading(getMLText("missing_php_functions_and_classes")); + echo "
    \n"; echo "\n\n"; echo "\n"; echo "\n\n\n"; foreach(array('proc_open') as $funcname) { @@ -119,12 +119,17 @@ class SeedDMS_View_Info extends SeedDMS_Theme_Style { echo ""; } } + foreach(array('finfo') as $classname) { + if(!class_exists($classname)) { + echo ""; + } + } echo "\n
    ".getMLText("name"); - echo "".getMLText("missing_func_note"); + echo "".getMLText("missing_func_class_note"); echo "
    ".$funcname."".getMLText('func_'.$funcname."_missing")."
    ".$classname."".getMLText('class_'.$classname."_missing")."
    \n"; if(function_exists('apache_get_modules')) { $this->contentHeading(getMLText("installed_apache_extensions")); $apacheextensions = apache_get_modules(); - echo "\n"; + echo "
    \n"; echo "\n\n"; echo "\n"; From ffdc6482922a2c16dc3f40d44296a25d0c4564be Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Fri, 23 Apr 2021 09:56:25 +0200 Subject: [PATCH 6/6] use same way to check for hooks in hasHook() and callHook() --- inc/inc.ClassControllerCommon.php | 54 ++++++++++++++++++------ inc/inc.ClassViewCommon.php | 68 ++++++++++++++++++++----------- 2 files changed, 87 insertions(+), 35 deletions(-) diff --git a/inc/inc.ClassControllerCommon.php b/inc/inc.ClassControllerCommon.php index c0454150d..ec2bd1cd3 100644 --- a/inc/inc.ClassControllerCommon.php +++ b/inc/inc.ClassControllerCommon.php @@ -139,6 +139,46 @@ class SeedDMS_Controller_Common { $this->errormsg = $msg; } /* }}} */ + /** + * Return a list of hook classes for the current class + * + * Hooks are associated to a controller class. Calling a hook with + * SeedDMS_View_Common::callHook() will run through a list of + * controller classes searching for the hook. This method returns this + * list. + * + * If a controller 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 'controllerAliasName', then this value will be added + * to the beginning of the list. + * + * When a hook is called, it will run through this list and checks + * if $GLOBALS['SEEDDMS_HOOKS']['controller'][] exists and contains + * an instanciated class. This class must implement the hook. + * + * @return array list of controller class names. + */ + protected function getHookClassNames() { /* {{{ */ + $tmps = array(); + /* the controllerAliasName can be set in the controller to specify a different name + * than extracted from the class name. + */ + if(property_exists($this, 'controllerAliasName') && !empty($this->controllerAliasName)) { + $tmps[] = $this->controllerAliasName; + } + $tmp = explode('_', get_class($this)); + $tmps[] = $tmp[2]; + foreach(class_parents($this) as $pc) { + $tmp = explode('_', $pc); + $tmps[] = $tmp[2]; + } + /* Run array_unique() in case the parent class has the same suffix */ + $tmps = array_unique($tmps); + return $tmps; + } /* }}} */ + /** * Call all hooks registered for a controller * @@ -190,17 +230,7 @@ class SeedDMS_Controller_Common { * null if no hook was called */ function callHook($hook) { /* {{{ */ - $tmps = array(); - $tmp = explode('_', get_class($this)); - $tmps[] = $tmp[2]; - foreach(class_parents($this) as $pc) { - $tmp = explode('_', $pc); - $tmps[] = $tmp[2]; - } -// $tmp = explode('_', get_parent_class($this)); -// $tmps[] = $tmp[2]; - /* Run array_unique() in case the parent class has the same suffix */ - $tmps = array_unique($tmps); + $tmps = $this->getHookClassNames(); foreach($tmps as $tmp) if(isset($GLOBALS['SEEDDMS_HOOKS']['controller'][lcfirst($tmp)])) { $this->lasthookresult = null; @@ -242,7 +272,7 @@ class SeedDMS_Controller_Common { * null if no hook was called */ function hasHook($hook) { /* {{{ */ - $tmp = explode('_', get_class($this)); + $tmps = $this->getHookClassNames(); if(isset($GLOBALS['SEEDDMS_HOOKS']['controller'][lcfirst($tmp[2])])) { foreach($GLOBALS['SEEDDMS_HOOKS']['controller'][lcfirst($tmp[2])] as $hookObj) { if (method_exists($hookObj, $hook)) { diff --git a/inc/inc.ClassViewCommon.php b/inc/inc.ClassViewCommon.php index efce8acf8..c388291b2 100644 --- a/inc/inc.ClassViewCommon.php +++ b/inc/inc.ClassViewCommon.php @@ -95,6 +95,46 @@ class SeedDMS_View_Common { public function show() { } + /** + * Return a list of hook classes for the current class + * + * 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. + * + * 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. + * + * When a hook is called, it will run through this list and checks + * if $GLOBALS['SEEDDMS_HOOKS']['view'][] exists and contains + * an instanciated class. This class must implement the hook. + * + * @return array list of view class names. + */ + protected function getHookClassNames() { /* {{{ */ + $tmps = array(); + /* 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; + } + $tmp = explode('_', get_class($this)); + $tmps[] = $tmp[2]; + foreach(class_parents($this) as $pc) { + $tmp = explode('_', $pc); + $tmps[] = $tmp[2]; + } + /* Run array_unique() in case the parent class has the same suffix */ + $tmps = array_unique($tmps); + return $tmps; + } /* }}} */ + /** * Call a hook with a given name * @@ -113,21 +153,7 @@ class SeedDMS_View_Common { * function returns */ public function callHook($hook) { /* {{{ */ - $tmps = array(); - /* 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; - } - $tmp = explode('_', get_class($this)); - $tmps[] = $tmp[2]; - foreach(class_parents($this) as $pc) { - $tmp = explode('_', $pc); - $tmps[] = $tmp[2]; - } - /* Run array_unique() in case the parent class has the same suffix */ - $tmps = array_unique($tmps); + $tmps = $this->getHookClassNames(); $ret = null; foreach($tmps as $tmp) if(isset($GLOBALS['SEEDDMS_HOOKS']['view'][lcfirst($tmp)])) { @@ -180,6 +206,9 @@ class SeedDMS_View_Common { * ?> * * + * The method does not return hooks for parent classes nor does it + * evaluate the viewAliasName property. + * * @params string $classname name of class (current class if left empty) * @return array list of hook objects registered for the class */ @@ -203,14 +232,7 @@ class SeedDMS_View_Common { * null if no hook was called */ public function hasHook($hook) { /* {{{ */ - $tmps = array(); - $tmp = explode('_', get_class($this)); - $tmps[] = $tmp[2]; - $tmp = explode('_', get_parent_class($this)); - $tmps[] = $tmp[2]; - /* Run array_unique() in case the parent class has the same suffix */ - $tmps = array_unique($tmps); - $ret = null; + $tmps = $this->getHookClassNames(); foreach($tmps as $tmp) { if(isset($GLOBALS['SEEDDMS_HOOKS']['view'][lcfirst($tmp)])) { foreach($GLOBALS['SEEDDMS_HOOKS']['view'][lcfirst($tmp)] as $hookObj) {
    ".getMLText("name"); echo "