From 3a240eb67c62c65af24ed292d9ca18eee931cef8 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Tue, 22 Sep 2015 11:26:15 +0000 Subject: [PATCH] Add a patch from Stefan Werfling. -Add new hooks etemplate2_before_exec, etemplate2_before_process and etemplate2_after_process into etemplate2 execution process --- etemplate/inc/class.etemplate_new.inc.php | 77 +++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/etemplate/inc/class.etemplate_new.inc.php b/etemplate/inc/class.etemplate_new.inc.php index 9fa896933f..f001b1f9ed 100644 --- a/etemplate/inc/class.etemplate_new.inc.php +++ b/etemplate/inc/class.etemplate_new.inc.php @@ -102,6 +102,32 @@ class etemplate_new extends etemplate_widget_template */ function exec($method,array $content,array $sel_options=null,array $readonlys=null,array $preserv=null,$output_mode=0,$ignore_validation='',array $changes=null) { + $hook_data = $GLOBALS['egw']->hooks->process( + array('location' => 'etemplate2_before_exec') + + array('location_name' => $this->name) + + array('location_object' => &$this) + + $content + ); + + foreach($hook_data as $extras) { + if (!$extras) continue; + + foreach(isset($extras[0]) ? $extras : array($extras) as $extra) { + if ($extra['data'] && is_array($extra['data'])) { + $content = array_merge($content, $extra['data']); + } + + if ($extra['preserve'] && is_array($extra['preserve'])) { + $preserv = array_merge($preserv, $extra['preserve']); + } + + if ($extra['readonlys'] && is_array($extra['readonlys'])) { + $readonlys = array_merge($readonlys, $extra['readonlys']); + } + } + } + unset($hook_data); + // Include the etemplate2 javascript code egw_framework::validate_file('.', 'etemplate2', 'etemplate'); @@ -322,10 +348,61 @@ class etemplate_new extends etemplate_widget_template // tell request call to remove request, if it is not modified eg. by call to exec in callback self::$request->remove_if_not_modified(); + $hook_data = $GLOBALS['egw']->hooks->process( + array( + 'location' => 'etemplate2_before_process', + 'location_name' => $template->id) + + self::complete_array_merge(self::$request->preserv, $validated) + ); + + foreach($hook_data as $extras) { + if (!$extras) continue; + + foreach(isset($extras[0]) ? $extras : array($extras) as $extra) { + if ($extra['data'] && is_array($extra['data'])) { + $validated = array_merge($validated, $extra['data']); + } + } + } + unset($hook_data); + //error_log(__METHOD__."(,".array2string($content).')'); //error_log(' validated='.array2string($validated)); $content = ExecMethod(self::$request->method, self::complete_array_merge(self::$request->preserv, $validated)); + $tcontent = array(); + + if( is_array($content) ) { + $tcontent = $content; + } + else { + $tcontent = self::complete_array_merge( + self::$request->preserv, + $validated + ); + } + + $hook_data = $GLOBALS['egw']->hooks->process( + array( + 'location' => 'etemplate2_after_process', + 'location_name' => $template->id) + + $tcontent + ); + unset($tcontent); + + if( is_array($content) ) { + foreach($hook_data as $extras) { + if (!$extras) continue; + + foreach(isset($extras[0]) ? $extras : array($extras) as $extra) { + if ($extra['data'] && is_array($extra['data'])) { + $content = array_merge($content, $extra['data']); + } + } + } + } + unset($hook_data); + if (isset($GLOBALS['egw_info']['flags']['java_script'])) { // Strip out any script tags