PluginProbe
CryptX / 3.4.3
CryptX v3.4.3
4.2.0 4.1.1 trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.9 2.0 2.1 2.2 2.3 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 All 92 releases
cryptx / include / admin_option_page.php

admin_option_page.php in CryptX 3.4.3, at include/admin_option_page.php

256 lines 6.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Don't load this file direct!
4 */
5 if (!defined('ABSPATH')) {
6 return ;
7 }
8
9 /**
10 * load required code
11 */
12 require_once(CRYPTX_DIR_PATH . 'include/admin_general.php');
13 require_once(CRYPTX_DIR_PATH . 'include/admin_presentation.php');
14 require_once(CRYPTX_DIR_PATH . 'include/admin_howto.php');
15 require_once(CRYPTX_DIR_PATH . 'include/admin_changelog.php');
16
17 /**
18 * Add css to header
19 */
20 function rw_cryptx_admin_css_script($hook) {
21 // Load only on ?page=cryptx
22 if($hook != 'settings_page_cryptx') {
23 return;
24 }
25 wp_enqueue_style( 'cryptx-admin-css', CRYPTX_DIR_URL . 'css/admin.css' );
26 wp_enqueue_style( 'wp-color-picker' );
27 wp_enqueue_script( 'cryptx-admin-js', CRYPTX_DIR_URL . 'js/cryptx-admin.min.js', array( 'jquery', 'wp-color-picker' ), false, true );
28 wp_enqueue_media();
29
30 }
31 add_action( 'admin_enqueue_scripts', 'rw_cryptx_admin_css_script' );
32
33 /**
34 * add links to plugin site
35 */
36 function rw_cryptx_init_row_meta($links, $file) {
37 if (CRYPTX_BASENAME == $file) {
38 return array_merge(
39 $links,
40 array(
41 sprintf(
42 '<a href="options-general.php?page=%s">%s</a>',
43 CRYPTX_BASEFOLDER,
44 __('Settings')
45 )
46 ),
47 array(
48 sprintf(
49 '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4026696">%s</a>',
50 __('Donate', 'cryptx')
51 )
52 )
53 );
54 }
55 return $links;
56 }
57
58 /**
59 * add CryptX to Option menu
60 */
61 function rw_cryptx_menu() {
62 add_submenu_page(
63 'options-general.php',
64 _x( 'CryptX', 'CryptX settings page', 'cryptx' ),
65 _x( 'CryptX', 'CryptX settings menu', 'cryptx' ),
66 'manage_options',
67 'cryptx',
68 'rw_cryptx_submenu'
69 );
70 }
71 if (is_admin()) add_action('admin_menu', 'rw_cryptx_menu');
72
73 /**
74 * save options
75 */
76 function rw_cryptx_saveOptions(): void {
77 if ( isValidPostRequest() ) {
78 $CryptX_instance = Cryptx\CryptX::getInstance();
79 $saveOptions = sanitizePostData();
80
81 check_admin_referer( 'cryptX' );
82
83 if ( isResetPost() ) {
84 // $saveOptions = rw_Defaults();
85 $saveOptions = $CryptX_instance->getCryptXOptionsDefaults();
86 }
87
88 if ( isSaveGeneralSettingsPost() ) {
89 $saveOptions = parseGeneralSettings( $saveOptions );
90 }
91
92 // $saveOptions = wp_parse_args( $saveOptions, rw_loadCryptXOptionsWithDefaults() );
93 $CryptX_instance->saveCryptXOptions($saveOptions);
94 // $saveOptions = wp_parse_args( $saveOptions, $CryptX_instance->loadCryptXOptionsWithDefaults() );
95 // update_option( 'cryptX', $saveOptions );
96 // $cryptXOptions = rw_loadCryptXOptionsWithDefaults();
97
98 displaySuccessMessage();
99 }
100 }
101
102 function isValidPostRequest(): bool {
103 if ( function_exists( 'current_user_can' ) === true && current_user_can( 'manage_options' ) === false ) {
104 wp_die( "You don't have permission to access!" );
105 }
106
107 return ! empty( $_POST['cryptX_var'] );
108 }
109
110 function sanitizePostData() {
111 return cryptx_sanitize_data( $_POST['cryptX_var'] );
112 }
113
114 function isResetPost(): bool {
115 return isset( $_POST['cryptX_var_reset'] );
116 }
117
118 function isSaveGeneralSettingsPost(): bool {
119 return isset( $_POST['cryptX_save_general_settings'] );
120 }
121
122 function parseGeneralSettings( $saveOptions ): array {
123 $checkboxes = [
124 'the_content' => 0,
125 'the_meta_key' => 0,
126 'the_excerpt' => 0,
127 'comment_text' => 0,
128 'widget_text' => 0,
129 'autolink' => 0,
130 'metaBox' => 0,
131 ];
132
133 return wp_parse_args( $saveOptions, $checkboxes );
134 }
135
136 function displaySuccessMessage(): void {
137 echo "<div id='message' class='updated fade'><p><strong>";
138 _e( 'Settings saved.' );
139 echo "</strong></p></div>";
140 }
141
142 /**
143 * sanitize given options
144 */
145 function cryptx_sanitize_data( $data ) {
146 $textFields = [
147 'version',
148 'at',
149 'dot',
150 'css_id',
151 'css_class',
152 'alt_linktext',
153 'http_linkimage_title',
154 'alt_linkimage_title',
155 'excludedIDs',
156 'alt_uploadedimage',
157 'c2i_font',
158 'c2i_fontRGB',
159 'whiteList'
160 ];
161
162 $intFields = [
163 'the_content',
164 'the_meta_key',
165 'the_excerpt',
166 'comment_text',
167 'java',
168 'load_java',
169 'opt_linktext',
170 'autolink',
171 'c2i_fontSize',
172 'echo'
173 ];
174
175 $boolFields = [ 'metaBox' ];
176
177 foreach ( $textFields as $field ) {
178 if ( isset( $data[ $field ] ) ) {
179 $data[ $field ] = sanitize_text_field( $data[ $field ] );
180 }
181 }
182
183 foreach ( $intFields as $field ) {
184 if ( isset( $data[ $field ] ) ) {
185 $data[ $field ] = (int) $data[ $field ];
186 }
187 }
188
189 foreach ( $boolFields as $field ) {
190 if ( isset( $data[ $field ] ) ) {
191 $data[ $field ] = (bool) $data[ $field ];
192 }
193 }
194
195 return $data;
196 }
197
198 /**
199 * print CryptX Option Page
200 */
201 function rw_cryptx_submenu() {
202 // global $cryptXOptions, $data, $rw_cryptx_active_tab;
203 rw_cryptx_saveOptions();
204
205 // Give meaningful name to tab variable
206 rw_cryptx_generateHtml();
207 }
208
209 function rw_cryptx_generateHtml(): void {
210 ?>
211 <div class="cryptx-option-page">
212 <h1><?php _e("CryptX settings", 'cryptx'); ?></h1>
213 <form method="post" action="">
214 <?php wp_nonce_field('cryptX') ?>
215 <h2 class="nav-tab-wrapper">
216 <?php
217 do_action('rw_cryptx_settings_tab');
218 ?>
219 </h2>
220 <div class="cryptx-tab-content-wrapper">
221 <?php
222 do_action('rw_cryptx_settings_content');
223 ?>
224 </div><!-- /.cryptx-tab-content-wrapper -->
225 </form>
226 </div><!-- /.cryptx-option-page -->
227 <?php
228 }
229
230 function rw_cryptx_getActiveTab() {
231 $allowedTabs = ['general', 'presentation', 'howto', 'changelog'];
232 $tab = $_GET['tab'] ?? 'general';
233 return in_array($tab, $allowedTabs) ? $tab : 'general';
234 }
235 /**
236 * Option page navigation
237 */
238 function rw_cryptx_settings_tab_presentation(): void {
239 //global $rw_cryptx_active_tab;
240 ?>
241 <a class="nav-tab <?php echo rw_cryptx_getActiveTab() == 'general' || '' ? 'nav-tab-active' : ''; ?>" href="<?php echo admin_url( 'options-general.php?page=' . CRYPTX_BASEFOLDER . '&tab=general' ); ?>">
242 <?php _e("General",'cryptx'); ?>
243 </a>
244 <a class="nav-tab <?php echo rw_cryptx_getActiveTab() == 'presentation' ? 'nav-tab-active' : ''; ?>" href="<?php echo admin_url( 'options-general.php?page=' . CRYPTX_BASEFOLDER . '&tab=presentation' ); ?>">
245 <?php _e("Presentation",'cryptx'); ?>
246 </a>
247 <a class="nav-tab <?php echo rw_cryptx_getActiveTab() == 'howto' ? 'nav-tab-active' : ''; ?>" href="<?php echo admin_url( 'options-general.php?page=' . CRYPTX_BASEFOLDER . '&tab=howto' ); ?>">
248 <?php _e("How to&hellip;",'cryptx'); ?>
249 </a>
250 <a class="nav-tab <?php echo rw_cryptx_getActiveTab() == 'changelog' ? 'nav-tab-active' : ''; ?>" href="<?php echo admin_url( 'options-general.php?page=' . CRYPTX_BASEFOLDER . '&tab=changelog' ); ?>">
251 <?php _e("Changelog",'cryptx'); ?>
252 </a>
253 <?php
254 }
255 add_action( 'rw_cryptx_settings_tab', 'rw_cryptx_settings_tab_presentation');
256