From d4be70de5a3549b3c487be7f035194b097b7478f Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Mon, 4 Nov 2013 17:23:58 +0000 Subject: [PATCH] - Use a hook for app's custom widgets to avoid scanning filesystem - Use new hook to load importexport's filter widget - Remove some typos & error_log()s --- etemplate/inc/class.etemplate.inc.php | 21 +++++++++++++++++-- etemplate/inc/class.etemplate_widget.inc.php | 2 +- ...rtexport_admin_prefs_sidebox_hooks.inc.php | 8 +++++++ .../class.importexport_definitions_ui.inc.php | 2 -- .../class.importexport_widget_filter.inc.php | 6 +----- ...portexport_wizard_basic_export_csv.inc.php | 4 ---- importexport/setup/setup.inc.php | 1 + 7 files changed, 30 insertions(+), 14 deletions(-) diff --git a/etemplate/inc/class.etemplate.inc.php b/etemplate/inc/class.etemplate.inc.php index 5a1862f1d7..5403e20651 100644 --- a/etemplate/inc/class.etemplate.inc.php +++ b/etemplate/inc/class.etemplate.inc.php @@ -108,7 +108,7 @@ class etemplate_new extends etemplate_widget_template if (!$this->rel_path) throw new egw_exception_assertion_failed("No (valid) template '$this->name' found!"); self::$request->output_mode = $output_mode; // let extensions "know" they are run eg. in a popup - self::$request->content = $content; + self::$request->content = self::$cont = $content; self::$request->changes = $changes; self::$request->sel_options = $sel_options ? $sel_options : array(); self::$request->readonlys = $readonlys ? $readonlys : array(); @@ -284,7 +284,7 @@ class etemplate_new extends etemplate_widget_template self::$response->script($GLOBALS['egw_info']['flags']['java_script']); //error_log($app .' added javascript to $GLOBALS[egw_info][flags][java_script] - use egw_json_response->script() instead.'); } - + return $content; } @@ -586,3 +586,20 @@ foreach($files as $filename) } } } + +// Use hook to load custom widgets from other apps +$widgets = $GLOBALS['egw']->hooks->process('etemplate2_register_widgets'); +foreach($widgets as $app => $list) +{ + foreach($list as $class) + { + try + { + __autoload($class); + } + catch(Exception $e) + { + error_log($e->getMessage()); + } + } +} diff --git a/etemplate/inc/class.etemplate_widget.inc.php b/etemplate/inc/class.etemplate_widget.inc.php index 773afbcb9c..aa326741e4 100644 --- a/etemplate/inc/class.etemplate_widget.inc.php +++ b/etemplate/inc/class.etemplate_widget.inc.php @@ -267,7 +267,7 @@ class etemplate_widget { if (!is_subclass_of($class, __CLASS__)) { - throw new egw_exception_wrong_parameter(__METHOD__."('$class', ".array2string($widgets).") $class is no subclass or ".__CLASS__.'!'); + throw new egw_exception_wrong_parameter(__METHOD__."('$class', ".array2string($widgets).") $class is no subclass of ".__CLASS__.'!'); } foreach((array)$widgets as $widget) { diff --git a/importexport/inc/class.importexport_admin_prefs_sidebox_hooks.inc.php b/importexport/inc/class.importexport_admin_prefs_sidebox_hooks.inc.php index 671589198e..fea7cff741 100644 --- a/importexport/inc/class.importexport_admin_prefs_sidebox_hooks.inc.php +++ b/importexport/inc/class.importexport_admin_prefs_sidebox_hooks.inc.php @@ -146,4 +146,12 @@ class importexport_admin_prefs_sidebox_hooks } if($file) display_sidebox($appname,lang('importexport'),$file); } + + /** + * Returns a list of custom widgets classes for etemplate2 + */ + public static function widgets() + { + return array('importexport_widget_filter'); + } } diff --git a/importexport/inc/class.importexport_definitions_ui.inc.php b/importexport/inc/class.importexport_definitions_ui.inc.php index 5960d3686a..fd8e9c4f98 100644 --- a/importexport/inc/class.importexport_definitions_ui.inc.php +++ b/importexport/inc/class.importexport_definitions_ui.inc.php @@ -587,9 +587,7 @@ class importexport_definitions_ui unset($content['button']); $content['wizard_content'] = $this->wizard_content_template; - error_log('------- STARTING EXEC --------'); $this->etpl->exec(self::_appname.'.importexport_definitions_ui.wizard',$content,$sel_options,$readonlys,$preserv); - error_log('------- DONE EXEC --------'); } else { diff --git a/importexport/inc/class.importexport_widget_filter.inc.php b/importexport/inc/class.importexport_widget_filter.inc.php index 15da5f3e20..46f725567c 100644 --- a/importexport/inc/class.importexport_widget_filter.inc.php +++ b/importexport/inc/class.importexport_widget_filter.inc.php @@ -60,7 +60,7 @@ class importexport_widget_filter extends etemplate_widget_transformer ); return parent::beforeSendToClient($cname); } -error_log(array2string(array_keys($fields))); + $n = 1; foreach($fields as $lname => &$field) { @@ -142,8 +142,6 @@ error_log('Trying to filter with unsupported field type: ' . $field['type']); } } - error_log($type); - $widget = self::factory($type, '<'.$type.' type="'.$type.'" id="'.self::$prefix.$lname.'"/>', self::$prefix.$lname); if(method_exists($widget, 'beforeSendToClient')) { @@ -159,7 +157,6 @@ error_log('Trying to filter with unsupported field type: ' . $field['type']); } $this->setElementAttribute($form_name, 'customfields', $fields); $this->setElementAttribute($form_name, 'fields',array_fill_keys(array_keys($fields), true)); - error_log($this); parent::beforeSendToClient($cname); @@ -230,7 +227,6 @@ error_log('Trying to filter with unsupported field type: ' . $field['type']); public function validate($cname, array $expand, array $content, &$validated=array()) { $form_name = self::form_name($cname, $this->id, $expand); - error_log('Validating ' . $form_name); if (!$this->is_readonly($cname, $form_name)) { $value_in = self::get_array($content, $form_name); diff --git a/importexport/inc/class.importexport_wizard_basic_export_csv.inc.php b/importexport/inc/class.importexport_wizard_basic_export_csv.inc.php index 8d7e94be4e..ada2942ee9 100644 --- a/importexport/inc/class.importexport_wizard_basic_export_csv.inc.php +++ b/importexport/inc/class.importexport_wizard_basic_export_csv.inc.php @@ -269,8 +269,6 @@ class importexport_wizard_basic_export_csv $preserv = $content; unset ($preserv['button']); - error_log('-------'); - error_log('Filter ' . array2string($content['filter'])); $content['set_filter']['fields'] = importexport_helper_functions::get_filter_fields( $content['application'],$content['plugin'],$this ); @@ -280,8 +278,6 @@ class importexport_wizard_basic_export_csv $content['set_filter'][$field] = $content['filter'][$field]; } - error_log('SET FILTER ' . array2string($content['set_filter'])); - error_log('----------'); if(!$content['set_filter']['fields']) { // No fields diff --git a/importexport/setup/setup.inc.php b/importexport/setup/setup.inc.php index 3c1f36cb3a..20c7dee150 100644 --- a/importexport/setup/setup.inc.php +++ b/importexport/setup/setup.inc.php @@ -32,6 +32,7 @@ $setup_info['importexport']['note'] = $setup_info['importexport']['hooks']['admin'] = $setup_info['importexport']['hooks']['sidebox_menu'] = 'importexport_admin_prefs_sidebox_hooks::all_hooks'; $setup_info['importexport']['hooks']['sidebox_all'] = 'importexport_admin_prefs_sidebox_hooks::other_apps'; +$setup_info['importexport']['hooks']['etemplate2_register_widgets'] = 'importexport_admin_prefs_sidebox_hooks::widgets'; /* Dependencies for this app to work */ $setup_info['importexport']['depends'][] = array(