PluginProbe ʕ •ᴥ•ʔ
Easy HTTPS Redirection (SSL) / 2.0.1
Easy HTTPS Redirection (SSL) v2.0.1
trunk 1.5 1.6 1.8 1.9.1 1.9.2 2.0.0 2.0.1
https-redirection / admin / ehssl-admin-init.php
https-redirection / admin Last commit date
ehssl-admin-init.php 1 year ago ehssl-admin-menu.php 1 day ago ehssl-certificate-expiry-menu.php 1 day ago ehssl-dashboard-menu.php 1 day ago ehssl-settings-menu-old.php 1 year ago ehssl-settings-menu.php 1 day ago ehssl-ssl-management-menu.php 1 year ago index.php 1 year ago
ehssl-admin-init.php
257 lines
1 <?php
2 /**
3 * Inits the admin dashboard side of things.
4 * Main admin file which loads all settings panels and sets up admin menus.
5 */
6 class EHSSL_Admin_Init
7 {
8 public $main_menu_page;
9 public $dashboard_menu;
10 public $settings_menu;
11
12 public function __construct()
13 {
14 $this->admin_includes();
15 add_action('admin_print_scripts', array($this, 'admin_menu_page_scripts'));
16 add_action('admin_print_styles', array($this, 'admin_menu_page_styles'));
17 add_action('admin_menu', array($this, 'create_admin_menus'));
18 add_action('admin_init', array($this, 'plugin_admin_init'));
19 add_action('admin_enqueue_scripts', array($this, 'plugin_admin_head'));
20
21 //Handle any admin notices.
22 add_action('admin_notices', array($this, 'easy_https_plugin_admin_notices'));
23 }
24
25 public function admin_includes()
26 {
27 include_once 'ehssl-admin-menu.php';
28 include_once EASY_HTTPS_SSL_PATH . '/classes/ehssl-rules-helper.php';
29
30 // TODO: Need to work on this later.
31 // require_once EASY_HTTPS_SSL_PATH."/vendor/autoload.php";
32 // include_once EASY_HTTPS_SSL_PATH . '/classes/ehssl-ssl-certificate.php';
33 }
34
35 public function admin_menu_page_scripts()
36 {
37 // Make sure we are on the appropriate menu page.
38 if (isset($_GET['page']) && strpos($_GET['page'], EHSSL_MENU_SLUG_PREFIX) !== false) {
39 wp_enqueue_script('postbox');
40 wp_enqueue_script('dashboard');
41 wp_enqueue_script('thickbox');
42 wp_enqueue_script('media-upload');
43 }
44 }
45
46 public function admin_menu_page_styles()
47 {
48 // Make sure we are on the appropriate menu page.
49 if (isset($_GET['page']) && strpos($_GET['page'], EHSSL_MENU_SLUG_PREFIX) !== false) {
50 wp_enqueue_style('dashboard');
51 wp_enqueue_style('thickbox');
52 wp_enqueue_style('global');
53 wp_enqueue_style('wp-admin');
54 wp_enqueue_style('ehssl-admin-css', EASY_HTTPS_SSL_URL . '/css/ehssl-admin-styles.css');
55 }
56 }
57
58 public function create_admin_menus() {
59 //Going to use the lock dashicon for the menu icon for now.
60 $menu_icon_url = 'dashicons-lock';
61 //$menu_icon_url = EASY_HTTPS_SSL_URL . '/images/plugin-icon.png';
62
63 $this->main_menu_page = add_menu_page(__('Easy HTTPS & SSL', 'https-redirection'), __('Easy HTTPS & SSL', 'https-redirection'), EHSSL_MANAGEMENT_PERMISSION, EHSSL_MAIN_MENU_SLUG, array($this, 'handle_dashboard_menu_rendering'), $menu_icon_url);
64 add_submenu_page(EHSSL_MAIN_MENU_SLUG, __('Dashboard', 'https-redirection'), __('Dashboard', 'https-redirection'), EHSSL_MANAGEMENT_PERMISSION, EHSSL_MAIN_MENU_SLUG, array($this, 'handle_dashboard_menu_rendering'));
65 add_submenu_page(EHSSL_MAIN_MENU_SLUG, __('Settings', 'https-redirection'), __('Settings', 'https-redirection'), EHSSL_MANAGEMENT_PERMISSION, EHSSL_SETTINGS_MENU_SLUG, array($this, 'handle_settings_menu_rendering'));
66 add_submenu_page(EHSSL_MAIN_MENU_SLUG, __('Certificate Expiry', 'https-redirection'), __('Certificate Expiry', 'https-redirection'), EHSSL_MANAGEMENT_PERMISSION, EHSSL_CERTIFICATE_EXPIRY_MENU_SLUG, array($this, 'handle_certificate_expiry_menu_rendering'));
67
68 // TODO: Need to work on this menu.
69 // add_submenu_page(EHSSL_MAIN_MENU_SLUG, __('SSL Management', 'https-redirection'), __('SSL Management', 'https-redirection'), EHSSL_MANAGEMENT_PERMISSION, EHSSL_SSL_MGMT_MENU_SLUG, array($this, 'handle_ssl_mgmt_menu_rendering'));
70
71 //Keeping the old settings menu for now for backwards compatibility. There is a link to the new settings page in the old settings menu.
72 add_submenu_page('options-general.php', __('HTTPS Redirection', 'https-redirection'), __('HTTPS Redirection', 'https-redirection'), EHSSL_MANAGEMENT_PERMISSION, 'https-redirection', array($this, 'handle_settings_menu_rendering_old'));
73
74 //Trigger the action for the menu creation.
75 do_action('ehssl_admin_menu_created');
76 }
77
78 public function handle_dashboard_menu_rendering()
79 {
80 include_once EASY_HTTPS_SSL_PATH . '/admin/ehssl-dashboard-menu.php';
81 $this->dashboard_menu = new EHSSL_Dashboard_Menu();
82 }
83
84 public function handle_settings_menu_rendering()
85 {
86 include_once EASY_HTTPS_SSL_PATH . '/admin/ehssl-settings-menu.php';
87 $this->settings_menu = new EHSSL_Settings_Menu();
88 }
89
90 public function handle_certificate_expiry_menu_rendering()
91 {
92 include_once EASY_HTTPS_SSL_PATH . '/admin/ehssl-certificate-expiry-menu.php';
93 $this->settings_menu = new EHSSL_Certificate_Expiry_Menu();
94 }
95
96 public function handle_settings_menu_rendering_old()
97 {
98 include_once EASY_HTTPS_SSL_PATH . '/admin/ehssl-settings-menu-old.php';
99 $this->settings_menu = new EHSSL_Settings_Menu_Old();
100 }
101
102 public function handle_ssl_mgmt_menu_rendering()
103 {
104 include_once EASY_HTTPS_SSL_PATH . '/admin/ehssl-ssl-management-menu.php';
105 $this->settings_menu = new EHSSL_SSL_MGMT_Menu();
106 }
107
108 public function plugin_admin_init()
109 {
110 global $httpsrdrctn_plugin_info;
111
112 $httpsrdrctn_plugin_info = get_plugin_data(__FILE__, false);
113
114 /* Call register settings function */
115 if (isset($_GET['page']) && "ehssl_settings" == $_GET['page']) {
116 $this->register_httpsrdrctn_settings();
117 }
118
119 $this->handle_log_file_action();
120
121 add_action( 'wp_ajax_ehssl_reset_log', array( $this, 'handle_reset_log' ) );
122 add_action('wp_ajax_ehssl_save_dashboard_order', array($this, 'handle_save_dashboard_sorting_order'));
123 }
124
125 /**
126 * Register settings function
127 */
128 public function register_httpsrdrctn_settings()
129 {
130 global $wpmu, $httpsrdrctn_options, $httpsrdrctn_plugin_info;
131
132 $httpsrdrctn_option_defaults = array(
133 'https' => 0,
134 'https_domain' => 1,
135 'https_pages_array' => array(),
136 'force_resources' => 0,
137 'plugin_option_version' => $httpsrdrctn_plugin_info["Version"],
138 );
139
140 // Install the option defaults.
141 if (1 == $wpmu) {
142 if (!get_site_option('httpsrdrctn_options')) {
143 add_site_option('httpsrdrctn_options', $httpsrdrctn_option_defaults, '', 'yes');
144 }
145
146 } else {
147 if (!get_option('httpsrdrctn_options')) {
148 add_option('httpsrdrctn_options', $httpsrdrctn_option_defaults, '', 'yes');
149 }
150 }
151
152 // Get options from the database.
153 if (1 == $wpmu) {
154 $httpsrdrctn_options = get_site_option('httpsrdrctn_options');
155 } else {
156 $httpsrdrctn_options = get_option('httpsrdrctn_options');
157 }
158
159 // Array merge incase this version has added new options.
160 if (!isset($httpsrdrctn_options['plugin_option_version']) || $httpsrdrctn_options['plugin_option_version'] != $httpsrdrctn_plugin_info["Version"]) {
161 $httpsrdrctn_options = array_merge($httpsrdrctn_option_defaults, $httpsrdrctn_options);
162 $httpsrdrctn_options['plugin_option_version'] = $httpsrdrctn_plugin_info["Version"];
163 update_option('httpsrdrctn_options', $httpsrdrctn_options);
164 }
165 }
166
167 public function plugin_admin_head()
168 {
169 wp_enqueue_script('ehssl_script', EASY_HTTPS_SSL_URL . '/js/script.js', array('jquery'), EASY_HTTPS_SSL_VERSION);
170 }
171
172 public function handle_log_file_action()
173 {
174 if (isset($_GET['ehssl-debug-action']) && esc_attr($_GET['ehssl-debug-action']) === 'view_log') {
175 if ( ! user_can( wp_get_current_user(), 'administrator' ) ) {
176 // User is not an admin
177 return;
178 }
179 $this->handle_view_log();
180 }
181 }
182
183 public function handle_view_log()
184 {
185 if (!check_admin_referer('ehssl_view_log_nonce')) {
186 //The nonce check failed
187 echo 'Error! Nonce security check failed. Could not reset the log file.';
188 wp_die(0);
189 }
190
191 $filename = EHSSL_Logger::get_log_file();
192 if (file_exists($filename)) {
193 $logfile = fopen(EHSSL_Logger::get_log_file(), 'rb');
194 header('Content-Type: text/plain');
195 fpassthru($logfile);
196 }
197 die;
198 }
199
200 public function handle_reset_log()
201 {
202 if (!current_user_can('manage_options')) {
203 EHSSL_Logger::log("Error! No permission to reset log file.");
204 //No permission for the current user to do this operation.
205 wp_die(0);
206 }
207
208 if (!check_ajax_referer('ehssl_settings_ajax_nonce', 'nonce', false)) {
209 //The nonce check failed
210 echo 'Error! Nonce security check failed. Could not reset the log file.';
211 wp_die(0);
212 }
213
214 $file_name = EHSSL_Logger::get_log_file_name();
215
216 EHSSL_Logger::reset_log_file($file_name);
217
218 echo '1';
219 wp_die();
220 }
221
222 public function handle_save_dashboard_sorting_order(){
223 global $httpsrdrctn_options;
224
225 if (isset($_POST['ehssl_sort_order']) && ! empty($_POST['ehssl_sort_order'])) {
226 $sorting_data = $_POST['ehssl_sort_order'];
227 $httpsrdrctn_options['dashboard_widget_sort_order'] = json_encode($sorting_data);
228 update_option('httpsrdrctn_options', $httpsrdrctn_options);
229 wp_send_json_success( $httpsrdrctn_options['dashboard_widget_sort_order'] );
230 } else {
231 wp_send_json_error("Invalid request");
232 }
233
234 // Always exit to avoid further execution
235 wp_die();
236 }
237
238 public function easy_https_plugin_admin_notices() {
239 $missing_extensions = EHSSL_Utils::get_missing_extensions();
240 if (!empty($missing_extensions)){
241 $output = '<div class="notice notice-error">';
242 $output .= '<p><b>'.__('NOTE:', 'https-redirection').'</b> ';
243 $output .= __('The following php extensions are missing which is required by this plugin to work properly. Contact you hosting provider enable this.', 'https-redirection');
244 $output .= '<ol>';
245 foreach ($missing_extensions as $ext){
246 $output .= '<li>'. $ext .'</li>';
247 }
248 $output .= '</ol>';
249 $output .= '</p>';
250 $output .= '</div>';
251
252 echo $output;
253 }
254 }
255
256 } //End of class
257