* @author_link http://isp-control.net
* @license MPL 1.1
*
*/
// If we are in admin settings context, we register our action hooks for him
if(IspCP_Registry::get('Plugin')->get_context() == 'admin_settings'):
/**
* Set display error field under admin/settings.tpl
*
* This function use the ERRORS_SETTINGS_HOOK template variable hook to add new
* html elements to allow to setup the PHP display_errors parameters
*
* @param ptemplate $tpl pTemplate instance provided by before_update action hook
* @return void
*/
function show_display_error($tpl) {
IspCP_Registry::get('Config');
$plugins_path = IspCP_Registry::get('Plugin')->base_path;
$tpl->define_dynamic(
'display_errors',
$plugins_path . '/display_errors/display_errors.tpl'
);
$tpl->assign(
array(
'TR_DISPLAY_ERRORS' => tr('Display errors'),
'TR_DISPLAY_ERRORS_ON' => tr('Enabled'),
'TR_DISPLAY_ERRORS_OFF' => tr('Disabled')
)
);
if (isset($cfg->DISPLAY_ERRORS) && $cfg->DISPLAY_ERRORS) {
$tpl->assign('DISPLAY_ERRORS_ON', $cfg['HTML_SELECTED'];);
$tpl->assign('DISPLAY_ERRORS_OFF', '');
} else {
$tpl->assign('DISPLAY_ERRORS_ON', '');
$tpl->assign('DISPLAY_ERRORS_OFF', $cfg['HTML_SELECTED'];);
}
$tpl->parse('ERRORS_SETTINGS_HOOK','.display_errors');
}
/**
* Update the display_error configuration parameter in the database
*
* @return void
*/
function update_display_errors() {
$db_cfg = IspCP_Registry::get('Config');
$db_cfg->display_errors = (int) $_POST['display_errors'];
}
// Action that will be launch before the setting show page
IspCP_Plugin::add_action('before_output', 'show_display_error');
// Action that will be launch before settings update
IspCP_Plugin::add_action('before_update', 'update_display_errors');
endif;
// Action that will be always launch (Action hook from main context)
/**
* Setup the PHP display_errors parameter
*
* @param IspCP_ConfigHandler_File $cfg provided by before_config action hook
* @return void
*/
function set_display_errors($cfg) {
if(isset($cfg->DISPLAY_ERRORS)) {
ini_set('display_errors', $cfg->DISPLAY_ERRORS);
}
}
// Will be launch at configuration process
IspCP_Plugin::add_action('before_config', 'set_display_errors');
===== Template file (include/plugins/display_errors/display_errors.tpl): =====
{TR_DISPLAY_ERRORS}