mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-26 08:38:54 +01:00
calendar/addressbook/API: introduce hook to fetch the export_limit to be applied for an app; introduce method to test if a specific hook exists for an application; fetch the export_limit via hook where appropriate
This commit is contained in:
parent
c7d3cba6c6
commit
d9905d3fb4
@ -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 = bo_merge::getExportLimit($GLOBALS['egw_info']['server']['contact_export_limit']);
|
||||
$export_limit = $export_object->export_limit = addressbook_hooks::getAppExportLimit($location='addressbook');
|
||||
if($export_limit == 'no' && !$limit_exception) {
|
||||
return;
|
||||
}
|
||||
|
@ -374,6 +374,17 @@ class addressbook_hooks
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook called to retrieve a app specific exportLimit
|
||||
*
|
||||
* @param array/string $location location and other parameters (not used)
|
||||
* @return the export_limit to be applied for the app, may be empty, int or string
|
||||
*/
|
||||
static function getAppExportLimit($location)
|
||||
{
|
||||
return bo_merge::getExportLimit($GLOBALS['egw_info']['server']['contact_export_limit']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register contacts as calendar resources (items which can be sheduled by the calendar)
|
||||
*
|
||||
|
@ -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 = bo_merge::getExportLimit($GLOBALS['egw_info']['server']['contact_export_limit']);
|
||||
$this->export_limit = addressbook_hooks::getAppExportLimit($location='addressbook');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,17 +82,15 @@ class addressbook_ui extends addressbook_bo
|
||||
{
|
||||
$GLOBALS['egw_info']['flags']['java_script'].= $this->js();
|
||||
}
|
||||
|
||||
// make sure the hook for export_limit is registered
|
||||
if (!$GLOBALS['egw']->hooks->hook_exists('export_limit','addressbook')) $GLOBALS['egw']->hooks->register_hooks('addressbook');
|
||||
|
||||
$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
|
||||
if ($this->config['contact_export_limit'])
|
||||
{
|
||||
$this->config['export_limit'] = $this->config['contact_export_limit'];
|
||||
}
|
||||
else // if not use the global one
|
||||
{
|
||||
$this->config['contact_export_limit'] = $this->config['export_limit'];
|
||||
}
|
||||
$this->config['export_limit'] = $this->config['contact_export_limit'] = addressbook_hooks::getAppExportLimit($location='addressbook');
|
||||
|
||||
if ($this->config['copy_fields'] && ($fields = is_array($this->config['copy_fields']) ?
|
||||
$this->config['copy_fields'] : unserialize($this->config['copy_fields'])))
|
||||
{
|
||||
|
@ -45,6 +45,8 @@ $setup_info['addressbook']['hooks']['edit_user'] = 'addressbook_hooks::edit_u
|
||||
$setup_info['addressbook']['hooks'][] = 'config';
|
||||
$setup_info['addressbook']['hooks']['group_acl'] = 'addressbook_hooks::group_acl';
|
||||
$setup_info['addressbook']['hooks']['not_enum_group_acls'] = 'addressbook_hooks::not_enum_group_acls';
|
||||
$setup_info['addressbook']['hooks']['export_limit'] = 'addressbook_hooks::getAppExportLimit';
|
||||
|
||||
|
||||
/* Dependencies for this app to work */
|
||||
$setup_info['addressbook']['depends'][] = array(
|
||||
|
@ -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 = bo_merge::getExportLimit($GLOBALS['egw_info']['server']['calendar_export_limit']);
|
||||
if (!$limit_exception) $export_limit = calendar_hooks::getAppExportLimit($location='calendar');
|
||||
// Custom fields need to be specifically requested
|
||||
$cfs = array();
|
||||
foreach($options['mapping'] as $key => $label) {
|
||||
|
@ -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 = bo_merge::getExportLimit($GLOBALS['egw_info']['server']['calendar_export_limit']);
|
||||
if (!$limit_exception) $export_limit = calendar_hooks::getAppExportLimit($location='calendar');
|
||||
|
||||
if($options['selection']['select'] == 'criteria') {
|
||||
$query = array(
|
||||
|
@ -43,6 +43,17 @@ class calendar_hooks
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook called to retrieve a app specific exportLimit
|
||||
*
|
||||
* @param array/string $location location and other parameters (not used)
|
||||
* @return the export_limit to be applied for the app, may be empty, int or string
|
||||
*/
|
||||
static function getAppExportLimit($location)
|
||||
{
|
||||
return bo_merge::getExportLimit($GLOBALS['egw_info']['server']['calendar_export_limit']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw calendar part of home
|
||||
*/
|
||||
|
@ -164,10 +164,8 @@ class calendar_ui
|
||||
// calendar does not work with hidden sidebox atm.
|
||||
unset($GLOBALS['egw_info']['user']['preferences']['common']['auto_hide_sidebox']);
|
||||
|
||||
$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['calendar_export_limit'] = bo_merge::getExportLimit($this->config['calendar_export_limit']);
|
||||
// make sure the hook for export_limit is registered
|
||||
if (!$GLOBALS['egw']->hooks->hook_exists('export_limit','calendar')) $GLOBALS['egw']->hooks->register_hooks('calendar');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -825,7 +823,7 @@ function load_cal(url,id) {
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||
);
|
||||
}
|
||||
$documents = calendar_merge::get_documents($GLOBALS['egw_info']['user']['preferences']['calendar']['document_dir'], '', $mime_filter);
|
||||
$documents = calendar_merge::get_documents($GLOBALS['egw_info']['user']['preferences']['calendar']['document_dir'], '', $mime_filter,'calendar');
|
||||
foreach($documents as $key => $value)
|
||||
{
|
||||
$options .= '<option value="'.html::htmlspecialchars($key).'">'.html::htmlspecialchars($value)."</option>\n";
|
||||
|
@ -43,6 +43,7 @@ $setup_info['calendar']['hooks']['sidebox_menu'] = 'calendar.calendar_ui.sidebox
|
||||
$setup_info['calendar']['hooks']['search_link'] = 'calendar_hooks::search_link';
|
||||
$setup_info['calendar']['hooks']['config_validate'] = 'calendar_hooks::config_validate';
|
||||
$setup_info['calendar']['hooks']['timesheet_set'] = 'calendar.calendar_bo.timesheet_set';
|
||||
$setup_info['calendar']['hooks']['export_limit'] = 'calendar_hooks::getAppExportLimit';
|
||||
|
||||
/* Dependencies for this app to work */
|
||||
$setup_info['calendar']['depends'][] = array(
|
||||
|
@ -1170,9 +1170,11 @@ abstract class bo_merge
|
||||
* @param array|string $mime_filter=null allowed mime type(s), default all, negative filter if $mime_filter[0] === '!'
|
||||
* @return array List of documents, suitable for a selectbox. The key is document_<filename>.
|
||||
*/
|
||||
public static function get_documents($dirs, $prefix='document_', $mime_filter=null)
|
||||
public static function get_documents($dirs, $prefix='document_', $mime_filter=null, $app='')
|
||||
{
|
||||
if (!$dirs || (!self::hasExportLimit('','ISALLOWED') && !self::is_export_limit_excepted())) return array();
|
||||
$export_limit = null;
|
||||
if (!empty($app)) $export_limit=$GLOBALS['egw']->hooks->single('export_limit',$app);
|
||||
if (!$dirs || (!self::hasExportLimit($export_limit,'ISALLOWED') && !self::is_export_limit_excepted())) return array();
|
||||
|
||||
// split multiple comma or whitespace separated directories
|
||||
// to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split
|
||||
|
@ -275,9 +275,11 @@ class nextmatch_widget
|
||||
// save values in persistent extension_data to be able use it in post_process
|
||||
unset($value['rows']);
|
||||
$extension_data += $value;
|
||||
|
||||
$tname = is_object($value['template']) ? $value['template']->name : $value['template'];
|
||||
list($app) = explode('.',$tname);
|
||||
$export_limit = $GLOBALS['egw']->hooks->single('export_limit',$app);
|
||||
$value['no_csv_export'] = $value['csv_fields'] === false ||
|
||||
$GLOBALS['egw_info']['server']['export_limit'] && !is_numeric($GLOBALS['egw_info']['server']['export_limit']) &&
|
||||
!bo_merge::hasExportLimit($export_limit,'ISALLOWED') &&
|
||||
!bo_merge::is_export_limit_excepted();
|
||||
|
||||
if (!$value['filter_onchange']) $value['filter_onchange'] = 'this.form.submit();';
|
||||
@ -1447,9 +1449,12 @@ class nextmatch_widget
|
||||
*/
|
||||
static public function csv_export(&$value,$separator=';')
|
||||
{
|
||||
if (!bo_merge::is_export_limit_excepted())
|
||||
$exportLimitExempted = bo_merge::is_export_limit_excepted();
|
||||
if (!$exportLimitExempted)
|
||||
{
|
||||
$export_limit = $GLOBALS['egw_info']['server']['export_limit'];
|
||||
$name = is_object($value['template']) ? $value['template']->name : $value['template'];
|
||||
list($app) = explode('.',$name);
|
||||
$export_limit = $GLOBALS['egw']->hooks->single('export_limit',$app);
|
||||
//if (isset($value['export_limit'])) $export_limit = $value['export_limit'];
|
||||
}
|
||||
$charset = $charset_out = translation::charset();
|
||||
@ -1473,9 +1478,9 @@ class nextmatch_widget
|
||||
{
|
||||
break; // nothing to export
|
||||
}
|
||||
if ($export_limit && (!is_numeric($export_limit) || $export_limit < $total))
|
||||
if (!$exportLimitExempted && (!bo_merge::hasExportLimit($export_limit,'ISALLOWED') || (int)$export_limit < $total))
|
||||
{
|
||||
etemplate::set_validation_error($name,lang('You are not allowed to export more than %1 entries!',$export_limit));
|
||||
etemplate::set_validation_error($name,lang('You are not allowed to export more than %1 entries!',(int)$export_limit));
|
||||
return false;
|
||||
}
|
||||
if (!isset($value['no_csv_support'])) $value['no_csv_support'] = !is_array($value['csv_fields']);
|
||||
|
@ -188,6 +188,19 @@ class hooks
|
||||
return count($this->locations[$location]);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if a given hook for an application is registered
|
||||
*
|
||||
* @param string $location location-name
|
||||
* @param string $app appname
|
||||
* @return int the number of found hooks
|
||||
*/
|
||||
function hook_exists($location, $app)
|
||||
{
|
||||
//error_log(__METHOD__.__LINE__.array2string($this->locations[$location]));
|
||||
return count($this->locations[$location][$app]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register and/or de-register an application's hooks
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user