/**
  * Constructor
  *
  * @param \phpbb\controller\helper	$helper		Controller helper object
  * @param \phpbb\template			$template	Template object
  * @param \phpbb\config\config		$config		Config object
  * @param \phpbb\user				$user		User object
  */
 public function __construct(\phpbb\controller\helper $helper, \phpbb\template\template $template, \phpbb\config\config $config, \phpbb\user $user)
 {
     $this->helper = $helper;
     $this->template = $template;
     $this->config = $config;
     $this->user = $user;
     $this->defaultavatar = \alfredoramos\defaultavatar\includes\defaultavatar::instance();
 }
 /**
  * Install BBCode data
  * @return array
  */
 public function update_data()
 {
     $defaultavatar = \alfredoramos\defaultavatar\includes\defaultavatar::instance();
     return [['config.add', ['default_avatar_type', 'style']], ['config.add', ['default_avatar_driver', 'avatar.driver.remote']], ['config.add', ['default_avatar_image', '']], ['config.add', ['default_avatar_image_female', '']], ['config.add', ['default_avatar_image_male', '']], ['config.add', ['default_avatar_width', $this->config['avatar_max_width']]], ['config.add', ['default_avatar_height', $this->config['avatar_max_height']]], ['config.add', ['default_avatar_by_gender', false]], ['config.add', ['default_avatar_image_extensions', 'jpg,png']], ['module.add', ['acp', 'ACP_CAT_DOT_MODS', 'ACP_DEFAULT_AVATAR']], ['module.add', ['acp', 'ACP_DEFAULT_AVATAR', ['module_basename' => '\\alfredoramos\\defaultavatar\\acp\\main_module', 'modes' => ['settings']]]]];
 }
 public function main($id, $mode)
 {
     global $db, $user, $auth, $template, $cache, $request;
     global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
     $user->add_lang('acp/common');
     $user->add_lang('acp/board');
     $this->tpl_name = 'acp_default_avatar_settings';
     $this->page_title = $user->lang('ACP_DEFAULT_AVATAR');
     add_form_key('alfredoramos/defaultavatar');
     // Helpers
     $defaultavatar = \alfredoramos\defaultavatar\includes\defaultavatar::instance();
     $avatar = ['type' => '', 'driver' => '', 'image' => ['default' => '', 'female' => '', 'male' => ''], 'width' => 0, 'height' => 0, 'gender' => false, 'extensions' => '', 'force' => false];
     // Current values stored in a new variable
     // to cast values to their correct type
     $current = ['type' => $config['default_avatar_type'], 'driver' => sprintf('avatar.driver.%s', $config['default_avatar_type'] === 'style' ? 'remote' : $config['default_avatar_type']), 'image' => ['default' => $config['default_avatar_image'], 'female' => $config['default_avatar_image_female'], 'male' => $config['default_avatar_image_male']], 'width' => ['min' => (int) $config['avatar_min_width'], 'max' => (int) $config['avatar_max_width'], 'conf' => (int) $config['default_avatar_width']], 'height' => ['min' => (int) $config['avatar_min_height'], 'max' => (int) $config['avatar_max_height'], 'conf' => (int) $config['default_avatar_height']], 'gender' => (bool) $config['default_avatar_by_gender'], 'extensions' => $config['default_avatar_extensions'], 'force' => (bool) $config['force_default_avatar']];
     if ($request->is_set_post('submit')) {
         if (!check_form_key('alfredoramos/defaultavatar')) {
             trigger_error('FORM_INVALID');
         }
         // Avatar type
         $avatar['type'] = $request->variable('default_avatar_type', $current['type']);
         $avatar['type'] = in_array($avatar['type'], ['style', 'local', 'remote', 'gravatar']) ? $avatar['type'] : 'style';
         // Avatar driver
         $avatar['driver'] = $current['driver'];
         // Avatar image
         $avatar['image']['default'] = $request->variable('default_avatar_image', $current['image']['default']);
         $avatar['image']['female'] = $request->variable('default_avatar_image_female', $current['image']['female']);
         $avatar['image']['male'] = $request->variable('default_avatar_image_male', $current['image']['male']);
         // Avatar width
         $avatar['width'] = $request->variable('default_avatar_width', $current['width']['conf']);
         $avatar['width'] = $avatar['width'] < $current['width']['min'] ? $current['width']['min'] : $avatar['width'];
         $avatar['width'] = $avatar['width'] > $current['width']['max'] ? $current['width']['max'] : $avatar['width'];
         // Avatar height
         $avatar['height'] = $request->variable('default_avatar_height', $current['height']['conf']);
         $avatar['height'] = $avatar['height'] < $current['height']['min'] ? $current['height']['min'] : $avatar['height'];
         $avatar['height'] = $avatar['height'] > $current['height']['max'] ? $current['height']['max'] : $avatar['height'];
         // Avatar by gender
         $avatar['gender'] = $request->variable('default_avatar_by_gender', $current['gender']);
         $avatar['gender'] = $defaultavatar->can_enable_gender_avatars() ? $avatar['gender'] : false;
         // Avatar image extensions
         $avatar['extensions'] = $request->variable('default_avatar_image_extensions', $current['extensions']);
         $avatar['extensions'] = trim($avatar['extensions'], ',');
         $avatar['extensions'] = array_map('trim', explode(',', $avatar['extensions']));
         $avatar['extensions'] = implode(',', $avatar['extensions']);
         // Force default avatar
         $avatar['force'] = $request->variable('force_default_avatar', $current['force']);
         // Avatar settings
         $config->set('default_avatar_type', $avatar['type']);
         $config->set('default_avatar_driver', $avatar['driver']);
         $config->set('default_avatar_image', $avatar['image']['default']);
         $config->set('default_avatar_image_female', $avatar['image']['female']);
         $config->set('default_avatar_image_male', $avatar['image']['male']);
         $config->set('default_avatar_width', $avatar['width']);
         $config->set('default_avatar_height', $avatar['height']);
         $config->set('default_avatar_by_gender', $avatar['gender']);
         $config->set('default_avatar_extensions', $avatar['extensions']);
         $config->set('force_default_avatar', $avatar['force']);
         trigger_error($user->lang('ACP_SETTINGS_SAVED') . adm_back_link($this->u_action));
     }
     // Template variables
     $template->assign_vars(['U_ACTION' => $this->u_action, 'BOARD_URL' => generate_board_url() . '/', 'BOARD_STYLE_PATH' => $defaultavatar->get_style($user->data['user_style'])['style_path'], 'AVATAR_TYPE_EXPLAIN' => vsprintf($user->lang('ACP_AVATAR_TYPE_EXPLAIN'), [$user->lang('ACP_AVATAR_FROM_STYLE'), $user->lang('ACP_AVATAR_FROM_STYLE_EXPLAIN'), $user->lang('ACP_LOCAL_AVATAR'), sprintf($user->lang('ACP_LOCAL_AVATAR_EXPLAIN'), './' . $config['avatar_gallery_path']), $user->lang('ACP_REMOTE_AVATAR'), $user->lang('ACP_REMOTE_AVATAR_EXPLAIN'), $user->lang('ACP_GRAVATAR_AVATAR'), $user->lang('ACP_GRAVATAR_AVATAR_EXPLAIN')]), 'IMAGE_EXTENSIONS_EXPLAIN' => vsprintf($user->lang('ACP_IMAGE_EXTENSIONS_EXPLAIN'), [$user->lang('ACP_AVATAR_TYPE'), $user->lang('ACP_AVATAR_FROM_STYLE')]), 'AVATAR_IMAGE_EXPLAIN' => vsprintf($user->lang('ACP_AVATAR_IMAGE_EXPLAIN'), [$user->lang('ACP_AVATAR_IMAGE'), $user->lang('ACP_AVATAR_TYPE'), $user->lang('ACP_AVATAR_FROM_STYLE')]), 'AVATAR_DIMENSIONS_EXPLAIN' => sprintf($user->lang('ACP_AVATAR_DIMENSIONS_EXPLAIN'), $user->lang('ACP_AVATAR_SETTINGS')), 'AVATAR_TYPE' => $current['type'], 'AVATAR_BY_GENDER' => $current['gender'], 'AVATAR_EXTENSIONS' => $current['extensions'], 'AVATAR_IMAGE' => $current['image']['default'], 'AVATAR_IMAGE_FEMALE' => $current['image']['female'], 'AVATAR_IMAGE_MALE' => $current['image']['male'], 'AVATAR_MIN_WIDTH' => $current['width']['min'], 'AVATAR_WIDTH' => $current['width']['conf'], 'AVATAR_MAX_WIDTH' => $current['width']['max'], 'AVATAR_MIN_HEIGHT' => $current['height']['min'], 'AVATAR_HEIGHT' => $current['height']['conf'], 'AVATAR_MAX_HEIGHT' => $current['height']['max'], 'FORCE_DEFAULT_AVATAR' => $current['force']]);
 }
 public function main($id, $mode)
 {
     global $db, $user, $auth, $template, $cache, $request;
     global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
     $user->add_lang('acp/common');
     $user->add_lang('acp/board');
     $this->tpl_name = 'acp_default_avatar_settings';
     $this->page_title = $user->lang('ACP_DEFAULT_AVATAR');
     add_form_key('alfredoramos/defaultavatar');
     $defaultavatar = \alfredoramos\defaultavatar\includes\defaultavatar::instance();
     if ($request->is_set_post('submit')) {
         if (!check_form_key('alfredoramos/defaultavatar')) {
             trigger_error('FORM_INVALID');
         }
         /**
          * Avatar type
          */
         $avatar_type = $request->variable('default_avatar_type', $config['default_avatar_type']);
         /**
          * Avatar driver
          */
         $avatar_driver = sprintf('avatar.driver.%s', $avatar_type === 'style' ? 'remote' : $avatar_type);
         /**
          * Avatar image
          */
         $avatar_image = $request->variable('default_avatar_image', $config['default_avatar_image']);
         $avatar_image_female = $request->variable('default_avatar_image_female', $config['default_avatar_image_female']);
         $avatar_image_male = $request->variable('default_avatar_image_male', $config['default_avatar_image_male']);
         /**
          * Avatar width
          */
         $avatar_width = $request->variable('default_avatar_width', $config['default_avatar_width']);
         $avatar_width = $avatar_width < $config['avatar_min_width'] ? $config['avatar_min_width'] : $avatar_width;
         $avatar_width = $avatar_width > $config['avatar_max_width'] ? $config['avatar_max_width'] : $avatar_width;
         /**
          * Avatar height
          */
         $avatar_height = $request->variable('default_avatar_height', $config['default_avatar_height']);
         $avatar_height = $avatar_height < $config['avatar_min_height'] ? $config['avatar_min_height'] : $avatar_height;
         $avatar_height = $avatar_height > $config['avatar_max_height'] ? $config['avatar_max_height'] : $avatar_height;
         /**
          * Avatar by gender
          */
         $avatar_by_gender = $request->variable('default_avatar_by_gender', $config['default_avatar_by_gender']);
         $avatar_by_gender = $defaultavatar->can_enable_gender_avatars() ? $avatar_by_gender : false;
         /**
          * Avatar image extensions
          */
         $avatar_image_extensions = $request->variable('default_avatar_image_extensions', $config['default_avatar_image_extensions']);
         /**
          * Avatar settings
          */
         $config->set('default_avatar_type', $avatar_type);
         $config->set('default_avatar_driver', $avatar_driver);
         $config->set('default_avatar_image', $avatar_image);
         $config->set('default_avatar_image_female', $avatar_image_female);
         $config->set('default_avatar_image_male', $avatar_image_male);
         $config->set('default_avatar_width', $avatar_width);
         $config->set('default_avatar_height', $avatar_height);
         $config->set('default_avatar_by_gender', $avatar_by_gender);
         $config->set('default_avatar_image_extensions', $avatar_image_extensions);
         trigger_error($user->lang('ACP_DEFAULT_AVATAR_SETTINGS_SAVED') . adm_back_link($this->u_action));
     }
     /**
      * Template variables
      */
     $template->assign_vars(['U_ACTION' => $this->u_action, 'BOARD_URL' => generate_board_url() . '/', 'BOARD_STYLE_PATH' => $defaultavatar->get_style($user->data['user_style'])['style_path'], 'DEFAULT_AVATAR_TYPE' => $config['default_avatar_type'], 'DEFAULT_AVATAR_IMAGE' => $config['default_avatar_image'], 'DEFAULT_AVATAR_IMAGE_FEMALE' => $config['default_avatar_image_female'], 'DEFAULT_AVATAR_IMAGE_MALE' => $config['default_avatar_image_male'], 'DEFAULT_AVATAR_WIDTH' => $config['default_avatar_width'], 'DEFAULT_AVATAR_HEIGHT' => $config['default_avatar_height'], 'DEFAULT_AVATAR_BY_GENDER' => $config['default_avatar_by_gender'], 'DEFAULT_AVATAR_IMAGE_EXTENSIONS' => $config['default_avatar_image_extensions'], 'DEFAULT_AVATAR_TYPE_NOTICE' => vsprintf('%s<br />%s<br />%s<br />%s<br />', [vsprintf('%s: %s', [$user->lang('ACP_DEFAULT_AVATAR_TYPE_STYLE'), $user->lang('ACP_DEFAULT_AVATAR_TYPE_STYLE_INFO')]), vsprintf('%s: %s', [$user->lang('ACP_DEFAULT_AVATAR_TYPE_LOCAL'), vsprintf($user->lang('ACP_DEFAULT_AVATAR_TYPE_LOCAL_INFO'), ['./' . $config['avatar_gallery_path']])]), vsprintf('%s: %s', [$user->lang('ACP_DEFAULT_AVATAR_TYPE_REMOTE'), $user->lang('ACP_DEFAULT_AVATAR_TYPE_REMOTE_INFO')]), vsprintf('%s: %s', [$user->lang('ACP_DEFAULT_AVATAR_TYPE_GRAVATAR'), $user->lang('ACP_DEFAULT_AVATAR_TYPE_GRAVATAR_INFO')])]), 'DEFAULT_AVATAR_BY_GENDER_NOTICE' => vsprintf($user->lang('ACP_DEFAULT_AVATAR_BY_GENDER_IMAGE_FORMATS_INFO'), [$user->lang('ACP_DEFAULT_AVATAR_TYPE'), $user->lang('ACP_DEFAULT_AVATAR_TYPE_STYLE')]), 'DEFAULT_AVATAR_IMAGE_NOTICE' => vsprintf($user->lang('ACP_DEFAULT_AVATAR_IMAGE_INFO'), [$user->lang('ACP_DEFAULT_AVATAR_IMAGE'), $user->lang('ACP_DEFAULT_AVATAR_TYPE'), $user->lang('ACP_DEFAULT_AVATAR_TYPE_STYLE')]), 'DEFAULT_AVATAR_DIMENSIONS_NOTICE' => sprintf($user->lang('ACP_DEFAULT_AVATAR_IMAGE_DIMENSIONS_INFO'), $user->lang('ACP_AVATAR_SETTINGS')), 'CONFIG_AVATAR_MIN_WIDTH' => $config['avatar_min_width'], 'CONFIG_AVATAR_MAX_WIDTH' => $config['avatar_max_width'], 'CONFIG_AVATAR_MIN_HEIGHT' => $config['avatar_min_height'], 'CONFIG_AVATAR_MAX_HEIGHT' => $config['avatar_max_height'], 'CAN_ENABLE_AVATAR_BY_GENDER' => $defaultavatar->can_enable_gender_avatars()]);
 }