| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * Member Avatar & Status [MAS]. An extension for the phpBB Forum Software package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @copyright (c) 2018-2020, Dark❶ [dark1] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @license GNU General Public License, version 2 (GPL-2.0-only) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | namespace dark1\memberavatarstatus\controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @ignore | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use phpbb\language\language; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use phpbb\log\log; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use phpbb\request\request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use phpbb\template\template; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use phpbb\user; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * Member Avatar & Status [MAS] ACP controller Base. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | class acp_base | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 	/** @var \phpbb\language\language */ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	protected $language; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	/** @var \phpbb\log\log */ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 	protected $log; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 	/** @var \phpbb\request\request */ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 	protected $request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 	/** @var \phpbb\template\template */ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 	protected $template; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	/** @var \phpbb\user */ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	protected $user; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 	/** @var string The module ID */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 	protected $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 	/** @var string The module mode */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	protected $mode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	/** @var string Custom form action */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 	protected $u_action; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 	 * Constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 	 * @param \phpbb\language\language				$language		Language object | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 	 * @param \phpbb\log\log						$log			Log object | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 	 * @param \phpbb\request\request				$request		Request object | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 	 * @param \phpbb\template\template				$template		Template object | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 	 * @param \phpbb\user							$user			User object | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 	public function __construct(language $language, log $log, request $request, template $template, user $user) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 		$this->language		= $language; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 		$this->log			= $log; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 		$this->request		= $request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 		$this->template		= $template; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 		$this->user			= $user; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 	 * Set Data form. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 	 * @param int		$id			The module ID | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 	 * @param string	$mode		The module mode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 	 * @param string	$u_action	Custom form action | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 	 * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 	 * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 	public function set_data($id, $mode, $u_action) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 		$this->id = $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 		$this->mode = $mode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 		$this->u_action = $u_action; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 	 * Get Data form. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 	 * @return array Having keys 'tpl_name' & 'page_title' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 	 * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 	public function get_data() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 		return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 			'tpl_name' => 'acp_mas_' . $this->mode, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 			'page_title' => $this->language->lang('ACP_MAS_TITLE') . ' - ' . $this->language->lang('ACP_MAS_MODE_' . strtoupper($this->mode)), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 		]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 	 * Set Display form. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 	 * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 	 * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 	public function setup() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 		$ext_name_mas = 'Member Avatar & Status [MAS]'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 		$ext_by_dark1 = 'Dark❶ [dark1]'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 		// Add our common language file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 		$this->language->add_lang('lang_acp_mas', 'dark1/memberavatarstatus'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 		$this->language->add_lang('lang_mas', 'dark1/memberavatarstatus'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 		// Create a form key for preventing CSRF attacks | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 		add_form_key('acp_mas_' . $this->mode); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 		// Set u_action in the template | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 		$this->template->assign_vars([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 			'U_ACTION'		=> $this->u_action, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 			'MAS_EXT_MODE'	=> $this->language->lang('ACP_MAS_MODE_' . strtoupper($this->mode)), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 			'MAS_EXT_NAME'	=> $ext_name_mas, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 			'MAS_EXT_DEV'	=> $ext_by_dark1, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 		]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 	 * Check Form On Submit . | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 	 * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 	 * @access protected | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 132 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  | 	protected function check_form_on_submit() | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  | 	{ | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  | 		// Test if the submitted form is valid | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  | 		if (!check_form_key('acp_mas_' . $this->mode)) | 
            
                                                                        
                            
            
                                    
            
            
                | 137 |  |  | 		{ | 
            
                                                                        
                            
            
                                    
            
            
                | 138 |  |  | 			trigger_error('FORM_INVALID', E_USER_WARNING); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | 	 * Success Form On Submit. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 	 * Used to Log & Trigger Success Err0r. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 	 * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | 	 * @access protected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  | 	protected function success_form_on_submit() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 		// Add option settings change action to the admin log | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | 		$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'ACP_MAS_LOG_SET_SAV', time(), array($this->language->lang('ACP_MAS_MODE_' . strtoupper($this->mode)))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | 		// Option settings have been updated and logged | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  | 		// Confirm this to the user and provide link back to previous page | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  | 		trigger_error($this->language->lang('ACP_MAS_LOG_SET_SAV', $this->language->lang('ACP_MAS_MODE_' . strtoupper($this->mode))) . adm_back_link($this->u_action), E_USER_NOTICE); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 158 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 159 |  |  |  |