protected function action_install()
{
// Get list of styles to install
$dirs = $this->request_vars('dir', '', true);
// Get list of styles that can be installed
$styles = $this->find_available(false);
// Install each style
$messages = array();
$installed_names = array();
$installed_dirs = array();
$last_installed = false;
foreach ($dirs as $dir) {
if (in_array($dir, $this->reserved_style_names)) {
$messages[] = $this->user->lang('STYLE_NAME_RESERVED', htmlspecialchars($dir));
continue;
}
$found = false;
foreach ($styles as &$style) {
// Check if:
// 1. Directory matches directory we are looking for
// 2. Style is not installed yet
// 3. Style with same name or directory hasn't been installed already within this function
if ($style['style_path'] == $dir && empty($style['_installed']) && !in_array($style['style_path'], $installed_dirs) && !in_array($style['style_name'], $installed_names)) {
// Install style
$style['style_active'] = 1;
$style['style_id'] = $this->install_style($style);
$style['_installed'] = true;
$found = true;
$last_installed = $style['style_id'];
$installed_names[] = $style['style_name'];
$installed_dirs[] = $style['style_path'];
$messages[] = sprintf($this->user->lang['STYLE_INSTALLED'], htmlspecialchars($style['style_name']));
}
}
if (!$found) {
$messages[] = sprintf($this->user->lang['STYLE_NOT_INSTALLED'], htmlspecialchars($dir));
}
}
// Invalidate the text formatter's cache for the new styles to take effect
if (!empty($installed_names)) {
$this->text_formatter_cache->invalidate();
}
// Show message
if (!count($messages)) {
trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING);
}
$message = implode('<br />', $messages);
$message .= '<br /><br /><a href="' . $this->u_base_action . '&mode=style' . '">« ' . $this->user->lang('STYLE_INSTALLED_RETURN_INSTALLED_STYLES') . '</a>';
$message .= '<br /><br /><a href="' . $this->u_base_action . '&mode=install' . '">» ' . $this->user->lang('STYLE_INSTALLED_RETURN_UNINSTALLED_STYLES') . '</a>';
trigger_error($message, E_USER_NOTICE);
}