From 2d494997ab25f61264b539ffc56ff7c854166ca3 Mon Sep 17 00:00:00 2001 From: Klaus Leithoff Date: Fri, 16 Sep 2011 13:03:46 +0000 Subject: [PATCH] rework of bo_merge::getExportLimit, apply to etemplate, importexport, addressbook, calendar --- ...ss.addressbook_export_contacts_csv.inc.php | 2 +- .../inc/class.addressbook_hooks.inc.php | 2 +- .../inc/class.addressbook_merge.inc.php | 2 +- addressbook/inc/class.addressbook_ui.inc.php | 2 +- .../inc/class.calendar_export_csv.inc.php | 2 +- .../inc/class.calendar_export_ical.inc.php | 2 +- calendar/inc/class.calendar_hooks.inc.php | 2 +- calendar/inc/class.calendar_merge.inc.php | 2 +- calendar/inc/class.calendar_uilist.inc.php | 4 +- etemplate/inc/class.bo_merge.inc.php | 62 ++++++++++--------- etemplate/inc/class.nextmatch_widget.inc.php | 6 +- ...rtexport_admin_prefs_sidebox_hooks.inc.php | 7 ++- .../inc/class.importexport_export_csv.inc.php | 5 +- .../inc/class.importexport_export_ui.inc.php | 15 +++-- 14 files changed, 60 insertions(+), 55 deletions(-) diff --git a/addressbook/inc/class.addressbook_export_contacts_csv.inc.php b/addressbook/inc/class.addressbook_export_contacts_csv.inc.php index 58a470f02b..2b87fae10b 100644 --- a/addressbook/inc/class.addressbook_export_contacts_csv.inc.php +++ b/addressbook/inc/class.addressbook_export_contacts_csv.inc.php @@ -40,7 +40,7 @@ class addressbook_export_contacts_csv implements importexport_iface_export_plugi // Addressbook defines its own export imits $limit_exception = bo_merge::is_export_limit_excepted(); - $export_limit = $export_object->export_limit = addressbook_hooks::getAppExportLimit($location='addressbook'); + $export_limit = $export_object->export_limit = bo_merge::getExportLimit($app='addressbook'); if($export_limit == 'no' && !$limit_exception) { return; } diff --git a/addressbook/inc/class.addressbook_hooks.inc.php b/addressbook/inc/class.addressbook_hooks.inc.php index cb484dfb6a..40e1d47a8c 100644 --- a/addressbook/inc/class.addressbook_hooks.inc.php +++ b/addressbook/inc/class.addressbook_hooks.inc.php @@ -382,7 +382,7 @@ class addressbook_hooks */ static function getAppExportLimit($location) { - return bo_merge::getExportLimit($GLOBALS['egw_info']['server']['contact_export_limit']); + return $GLOBALS['egw_info']['server']['contact_export_limit']; } /** diff --git a/addressbook/inc/class.addressbook_merge.inc.php b/addressbook/inc/class.addressbook_merge.inc.php index 82e0d5c9d3..acb0a83b0a 100644 --- a/addressbook/inc/class.addressbook_merge.inc.php +++ b/addressbook/inc/class.addressbook_merge.inc.php @@ -32,7 +32,7 @@ class addressbook_merge extends bo_merge parent::__construct(); // overwrite global export-limit, if an addressbook one is set - $this->export_limit = addressbook_hooks::getAppExportLimit($location='addressbook'); + $this->export_limit = bo_merge::getExportLimit('addressbook'); } /** diff --git a/addressbook/inc/class.addressbook_ui.inc.php b/addressbook/inc/class.addressbook_ui.inc.php index 945a9772dd..f4dd556265 100644 --- a/addressbook/inc/class.addressbook_ui.inc.php +++ b/addressbook/inc/class.addressbook_ui.inc.php @@ -89,7 +89,7 @@ class addressbook_ui extends addressbook_bo $this->config =& $GLOBALS['egw_info']['server']; // check if a contact specific export limit is set, if yes use it also for etemplate's csv export - $this->config['export_limit'] = $this->config['contact_export_limit'] = addressbook_hooks::getAppExportLimit($location='addressbook'); + $this->config['export_limit'] = $this->config['contact_export_limit'] = bo_merge::getExportLimit($app='addressbook'); if ($this->config['copy_fields'] && ($fields = is_array($this->config['copy_fields']) ? $this->config['copy_fields'] : unserialize($this->config['copy_fields']))) diff --git a/calendar/inc/class.calendar_export_csv.inc.php b/calendar/inc/class.calendar_export_csv.inc.php index bef98d36c5..469a4a8331 100644 --- a/calendar/inc/class.calendar_export_csv.inc.php +++ b/calendar/inc/class.calendar_export_csv.inc.php @@ -26,7 +26,7 @@ class calendar_export_csv implements importexport_iface_export_plugin { $this->bo = new calendar_bo(); $limit_exception = bo_merge::is_export_limit_excepted(); - if (!$limit_exception) $export_limit = calendar_hooks::getAppExportLimit($location='calendar'); + if (!$limit_exception) $export_limit = bo_merge::getExportLimit('calendar'); // Custom fields need to be specifically requested $cfs = array(); foreach($options['mapping'] as $key => $label) { diff --git a/calendar/inc/class.calendar_export_ical.inc.php b/calendar/inc/class.calendar_export_ical.inc.php index cf7d0fe38b..377c58de23 100644 --- a/calendar/inc/class.calendar_export_ical.inc.php +++ b/calendar/inc/class.calendar_export_ical.inc.php @@ -33,7 +33,7 @@ class calendar_export_ical extends calendar_export_csv { } $limit_exception = bo_merge::is_export_limit_excepted(); - if (!$limit_exception) $export_limit = calendar_hooks::getAppExportLimit($location='calendar'); + if (!$limit_exception) $export_limit = bo_merge::getExportLimit('calendar'); if($options['selection']['select'] == 'criteria') { $query = array( diff --git a/calendar/inc/class.calendar_hooks.inc.php b/calendar/inc/class.calendar_hooks.inc.php index 14d21cf969..bf32d1a439 100644 --- a/calendar/inc/class.calendar_hooks.inc.php +++ b/calendar/inc/class.calendar_hooks.inc.php @@ -51,7 +51,7 @@ class calendar_hooks */ static function getAppExportLimit($location) { - return bo_merge::getExportLimit($GLOBALS['egw_info']['server']['calendar_export_limit']); + return $GLOBALS['egw_info']['server']['calendar_export_limit']; } /** diff --git a/calendar/inc/class.calendar_merge.inc.php b/calendar/inc/class.calendar_merge.inc.php index 4aa24a6969..275f68f16e 100644 --- a/calendar/inc/class.calendar_merge.inc.php +++ b/calendar/inc/class.calendar_merge.inc.php @@ -69,7 +69,7 @@ class calendar_merge extends bo_merge parent::__construct(); // overwrite global export-limit, if one is set for calendar/appointments - $this->export_limit = bo_merge::getExportLimit($GLOBALS['egw_info']['server']['calendar_export_limit']); + $this->export_limit = bo_merge::getExportLimit('calendar'); $this->bo = new calendar_boupdate(); diff --git a/calendar/inc/class.calendar_uilist.inc.php b/calendar/inc/class.calendar_uilist.inc.php index c8f445f9be..ba23763b84 100644 --- a/calendar/inc/class.calendar_uilist.inc.php +++ b/calendar/inc/class.calendar_uilist.inc.php @@ -799,9 +799,9 @@ class calendar_uilist extends calendar_ui 'hint' => 'Download this event as iCal', 'disableClass' => 'rowNoView', ); - $actions['documents'] = addressbook_merge::document_action( + $actions['documents'] = calendar_merge::document_action( $this->bo->cal_prefs['document_dir'], ++$group, 'Insert in document', 'document_', - $this->bo->cal_prefs['default_document'] + $this->bo->cal_prefs['default_document'],bo_merge::getExportLimit('calendar') ); ++$group; $actions['delete'] = array( diff --git a/etemplate/inc/class.bo_merge.inc.php b/etemplate/inc/class.bo_merge.inc.php index 8f7f4b501f..0c3ca060d5 100644 --- a/etemplate/inc/class.bo_merge.inc.php +++ b/etemplate/inc/class.bo_merge.inc.php @@ -345,30 +345,40 @@ abstract class bo_merge * @return mixed - no if no export is allowed, false if there is no restriction and int as there is a valid restriction * you may have to cast the returned value to int, if you want to use it as number */ - public static function getExportLimit($app_limit='') + public static function getExportLimit($app='common') { - //error_log(__METHOD__.__LINE__.' -> '.$app_limit.' '.function_backtrace()); - $exportLimit = $GLOBALS['egw_info']['server']['export_limit']; - if (!empty($app_limit)) + static $exportLimitStore; + if (is_null($exportLimitStore)) $exportLimitStore=array(); + if (empty($app)) $app='common'; + //error_log(__METHOD__.__LINE__.' called with app:'.$app); + if (!array_key_exists($app,$exportLimitStore)) { - $exportLimit = $app_limit; - } - //error_log(__METHOD__.__LINE__.' -> '.$exportLimit); - if (empty($exportLimit)) - { - return false; - } + //error_log(__METHOD__.__LINE__.' -> '.$app_limit.' '.function_backtrace()); + $exportLimitStore[$app] = $GLOBALS['egw_info']['server']['export_limit']; + if ($app !='common') + { + $app_limit = $GLOBALS['egw']->hooks->single('export_limit',$app); + if ($app_limit) $exportLimitStore[$app] = $app_limit; + } + //error_log(__METHOD__.__LINE__.' building cache for app:'.$app.' -> '.$exportLimitStore[$app]); + if (empty($exportLimitStore[$app])) + { + $exportLimitStore[$app] = false; + return false; + } - if (is_numeric($exportLimit)) - { - $exportLimit = (int)$exportLimit; + if (is_numeric($exportLimitStore[$app])) + { + $exportLimitStore[$app] = (int)$exportLimitStore[$app]; + } + else + { + $exportLimitStore[$app] = 'no'; + } + //error_log(__METHOD__.__LINE__.' -> '.$exportLimit); } - else - { - $exportLimit = $limit = 'no'; - } - //error_log(__METHOD__.__LINE__.' -> '.$exportLimit); - return $exportLimit; + //error_log(__METHOD__.__LINE__.' app:'.$app.' -> '.$exportLimitStore[$app]); + return $exportLimitStore[$app]; } /** @@ -379,9 +389,8 @@ abstract class bo_merge * * @return bool - true if no export is allowed or a limit is set, false if there is no restriction */ - public static function hasExportLimit($app_limit='',$checkas='AND') + public static function hasExportLimit($app_limit,$checkas='AND') { - $app_limit = self::getExportLimit($app_limit); if (strtoupper($checkas) == 'ISALLOWED') return (empty($app_limit) || ($app_limit !='no' && $app_limit > 0) ); if (empty($app_limit)) return false; if ($app_limit == 'no') return true; @@ -406,7 +415,7 @@ abstract class bo_merge return false; } - if (self::hasExportLimit() && !self::is_export_limit_excepted() && count($ids) > (int)$this->export_limit) + if (self::hasExportLimit($this->export_limit) && !self::is_export_limit_excepted() && count($ids) > (int)$this->export_limit) { $err = lang('No rights to export more than %1 entries!',(int)$this->export_limit); return false; @@ -1172,8 +1181,7 @@ abstract class bo_merge */ public static function get_documents($dirs, $prefix='document_', $mime_filter=null, $app='') { - $export_limit = null; - if (!empty($app)) $export_limit=$GLOBALS['egw']->hooks->single('export_limit',$app); + $export_limit=self::getExportLimit($app); if (!$dirs || (!self::hasExportLimit($export_limit,'ISALLOWED') && !self::is_export_limit_excepted())) return array(); // split multiple comma or whitespace separated directories @@ -1231,10 +1239,8 @@ abstract class bo_merge public static function document_action($dirs, $group=0, $caption='Insert in document', $prefix='document_', $default_doc='', $export_limit=null) { - $export_limit = self::getExportLimit($export_limit); - $documents = array(); - + if ($export_limit == null) $export_limit = self::getExportLimit(); // check if there is a globalsetting if ($default_doc && ($file = egw_vfs::stat($default_doc))) // put default document on top { $documents['document'] = array( diff --git a/etemplate/inc/class.nextmatch_widget.inc.php b/etemplate/inc/class.nextmatch_widget.inc.php index 6d4c669c79..e77d53d6aa 100644 --- a/etemplate/inc/class.nextmatch_widget.inc.php +++ b/etemplate/inc/class.nextmatch_widget.inc.php @@ -276,8 +276,7 @@ class nextmatch_widget unset($value['rows']); $extension_data += $value; list($app) = explode('.',$tmpl->name); - $export_limit = $GLOBALS['egw_info']['server']['export_limit']; - if (empty($app)) $export_limit = $GLOBALS['egw']->hooks->single('export_limit',$app); + $export_limit = bo_merge::getExportLimit($app); $value['no_csv_export'] = $value['csv_fields'] === false || !bo_merge::hasExportLimit($export_limit,'ISALLOWED') && !bo_merge::is_export_limit_excepted(); @@ -1454,8 +1453,7 @@ class nextmatch_widget { $name = is_object($value['template']) ? $value['template']->name : $value['template']; list($app) = explode('.',$name); - $export_limit = $GLOBALS['egw_info']['server']['export_limit']; - if (!empty($app)) $export_limit = $GLOBALS['egw']->hooks->single('export_limit',$app); + $export_limit = bo_merge::getExportLimit($app); //if (isset($value['export_limit'])) $export_limit = $value['export_limit']; } $charset = $charset_out = translation::charset(); 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 fbd30df4f2..6c0a211e0e 100644 --- a/importexport/inc/class.importexport_admin_prefs_sidebox_hooks.inc.php +++ b/importexport/inc/class.importexport_admin_prefs_sidebox_hooks.inc.php @@ -37,7 +37,8 @@ class importexport_admin_prefs_sidebox_hooks 'icon' => 'import' ), ); - $export_limit = bo_merge::getExportLimit(); + $export_limit = bo_merge::getExportLimit($appname); + //error_log(__METHOD__.__LINE__.' app:'.$appname.' limit:'.$export_limit); if(bo_merge::is_export_limit_excepted() || $export_limit !== 'no') { $file[] = array( @@ -121,8 +122,8 @@ class importexport_admin_prefs_sidebox_hooks $file['Import CSV']['link'] = ''; } } - $export_limit = $GLOBALS['egw']->hooks->single('export_limit',$appname); - //error_log(__METHOD__.__LINE__.$appname.$export_limit); + $export_limit = bo_merge::getExportLimit($appname); + //error_log(__METHOD__.__LINE__.' app:'.$appname.' limit:'.$export_limit); if ((bo_merge::is_export_limit_excepted() || bo_merge::hasExportLimit($export_limit,'ISALLOWED')) && $cache[$appname]['export']) { $file['Export CSV'] = array('link' => "javascript:egw_openWindowCentered2('". diff --git a/importexport/inc/class.importexport_export_csv.inc.php b/importexport/inc/class.importexport_export_csv.inc.php index 00fd7751dc..a09160d94b 100644 --- a/importexport/inc/class.importexport_export_csv.inc.php +++ b/importexport/inc/class.importexport_export_csv.inc.php @@ -100,9 +100,10 @@ class importexport_export_csv implements importexport_iface_export_record if ( !empty( $_options ) ) { $this->csv_options = array_merge( $this->csv_options, $_options ); } - + //error_log(__METHOD__.__LINE__.array2string($_options['appname'])); if(!bo_merge::is_export_limit_excepted()) { - $this->export_limit = bo_merge::getExportLimit(); + $this->export_limit = bo_merge::getExportLimit($_options['appname']); + //error_log(__METHOD__.__LINE__.' app:'.$_options['appname'].' limit:'.$this->export_limit); if($this->export_limit == 'no') throw new egw_exception_no_permission_admin('Export disabled'); } } diff --git a/importexport/inc/class.importexport_export_ui.inc.php b/importexport/inc/class.importexport_export_ui.inc.php index 395a0086fd..b2d641d109 100644 --- a/importexport/inc/class.importexport_export_ui.inc.php +++ b/importexport/inc/class.importexport_export_ui.inc.php @@ -48,20 +48,19 @@ class importexport_export_ui { $readonlys = array(); $preserv = array(); - // Check global setting - if(!bo_merge::is_export_limit_excepted()) { - $export_limit = bo_merge::getExportLimit(); - if($export_limit == 'no') { - die(lang('Admin disabled exporting')); - } - } - $et = new etemplate(self::_appname. '.export_dialog'); $_appname = $_content['appname'] ? $_content['appname'] : $_GET['appname']; $_definition = $_content['definition'] ? $_content['definition'] : $_GET['definition']; $_plugin = $_content['plugin'] ? $_content['plugin'] : $_GET['plugin']; $_selection = $_content['selection'] ? $_content['selection'] : $_GET['selection']; + // Check global setting + if(!bo_merge::is_export_limit_excepted()) { + $export_limit = bo_merge::getExportLimit($_appname); + if($export_limit == 'no') { + die(lang('Admin disabled exporting')); + } + } //error_log(__FILE__.__FUNCTION__. '::$_GET[\'appname\']='. $_appname. ',$_GET[\'definition\']='. $_definition. ',$_GET[\'plugin\']='.$_plugin. ',$_GET[\'selection\']='.$_selection); // if appname is given and valid, list available definitions (if no definition is given) $readonlys['appname'] = (!empty($_appname) && $GLOBALS['egw']->acl->check('run',1,$_appname));