PluginProbe
Weaver Show Posts / trunk
Weaver Show Posts vtrunk
2.0.5 2.0.4 trunk 1.0.1 1.0.2 1.0.3 1.0.4 1.0.6 1.0.7 1.1 1.2 1.2.1 1.2.2 1.2.4 1.3 1.3.1 1.3.1.1 1.3.10 1.3.13 1.3.15 1.3.2 1.3.3 1.3.5 1.3.6 1.3.7 All 37 releases
show-posts / includes / atw-admin-lib.php

atw-admin-lib.php in Weaver Show Posts trunk, at includes/atw-admin-lib.php

283 lines 10.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) exit;
3 function atw_posts_help_link($ref, $label)
4 {
5
6 $t_dir = atw_posts_plugins_url('/help/' . $ref, '');
7 $icon = atw_posts_plugins_url('/help/help.png', '');
8 $pp_help = '<a href="' . $t_dir . '" target="_blank" title="' . $label . '">'
9 . '<img class="entry-cat-img" src="' . $icon . '" style="position:relative; top:4px; padding-left:4px;" title="Click for help" alt="Click for help" /></a>';
10 echo wp_kses_post($pp_help);
11 }
12
13
14 function atw_posts_save_msg($msg)
15 {
16 echo wp_kses_post('<div id="message" class="updated fade" style="width:70%;"><p><strong>' . esc_html($msg) .
17 '</strong></p></div>');
18 }
19
20 /*function atw_posts_error_msg($msg)
21 {
22 echo '<div id="message" class="updated fade" style="background:#F88;" style="width:70%;"><p><strong>' . esc_html($msg) .
23 '</strong></p></div>';
24 }*/
25 function atw_posts_error_msg( $msg ) {
26 // shows error message in popup
27 ?>
28 <div id="atw-msg-overlay" style="
29 position:fixed;
30 top:0; left:0;
31 width:100%; height:100%;
32 background:rgba(0,0,0,0.5);
33 z-index:9999;
34 display:flex;
35 align-items:center;
36 justify-content:center;
37 ">
38 <div style="
39 background:#fff5f5;
40 padding:20px;
41 //border:2px solid #A00;
42 max-width:500px;
43 width:60%;
44 box-shadow:0 0 20px rgba(0,0,0,0.5);
45 text-align:center;
46 overlay:background:rgba(0,0,0,0.4);
47 popup:background:#fff5f5;
48 border:2px solid #cc0000;
49 ">
50 <div style="margin-bottom:15px; font-weight:bold; color:#A00;">
51 <?php echo esc_html( $msg ); ?>
52 </div>
53
54 <button id="atw-msg-close" class="button button-primary">
55 Dismiss
56 </button>
57 </div>
58 </div>
59
60 <script>
61 document.addEventListener("DOMContentLoaded", function () {
62 var btn = document.getElementById("atw-msg-close");
63 var overlay = document.getElementById("atw-msg-overlay");
64
65 if (btn && overlay) {
66 btn.addEventListener("click", function () {
67 overlay.style.display = "none";
68 });
69 }
70 });
71 </script>
72 <?php
73 }
74
75 function atw_media_lib_button($fillin = '')
76 {
77 ?>
78 &nbsp;&nbsp;&larr;&nbsp;<a style='text-decoration:none;'
79 href="javascript:atw_media_lib('<?php echo esc_html($fillin); ?>');"><img
80 src="<?php echo esc_url(atw_posts_plugins_url('/images/media-button.png')); ?>"
81 title="Select image from Media Library. Click 'Insert into Post' to paste url here." alt="media"/></a>
82 <?php
83 }
84
85 // =======================================>>> Save/Restore <<<=================================
86 function atw_posts_download_link($desc, $filebase, $ext, $time)
87 {
88 $nonce = wp_create_nonce('show_posts_download');
89
90 $downloader = plugins_url() . '/show-posts/includes/atw-downloader.php';
91 $download_img_path = plugins_url() . '/show-posts/images/download.png';
92 $filename = "{$filebase}-{$time}.{$ext}";
93 $href = $downloader . "?_wpnonce={$nonce}&_ext={$ext}&_file={$filename}";
94 ?>
95 <a style="margin-left:9em;text-decoration: none;" href="<?php echo esc_url($href); ?>">
96 <span class="download-link"><img src="<?php echo esc_url($download_img_path); ?>"/>
97 <?php esc_html_e('Download', 'show-posts' /*adm*/);
98 echo '</span></a> - ';
99 echo wp_kses_post($desc);
100 echo ' &nbsp;';
101
102 echo 'Save as:';
103 echo ' ' . esc_html($filename) . "<br /><br />\n";
104 }
105
106 function atw_posts_restore_filter()
107 {
108 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- verified elsewhere
109 if (!(isset($_POST['uploadit']) && $_POST['uploadit'] == 'yes')) return;
110
111 if (!atw_posts_allow_file_read()) {
112 atw_posts_save_msg('File Read Access problem. File not restored.');
113 return;
114 }
115
116 // upload theme from users computer
117 // they've supplied and uploaded a file
118
119 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce handled earlier in admin flow
120 //echo '<pre>'; print_r($_FILES); echo '</pre>';
121
122 $ok = true; // no errors so far
123
124 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce handled earlier in admin flow
125 if (isset($_FILES['post_uploaded']['name'])) {
126 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- file upload handled in admin flow
127 $filename = $_FILES['post_uploaded']['tmp_name'];
128 //$filename = sanitize_file_name(wp_unslash($_FILES['post_uploaded']['tmp_name']));
129 } else
130 $filename = "";
131
132 //Check the file extension
133 $check_file = strtolower($filename);
134 $pat = '.'; // PHP version strict checking bug...
135 $end = explode($pat, $check_file);
136 $ext_check = end($end);
137
138
139 if ($filename == "") {
140 $errors[] = 'You didn\'t select a file to upload.' . "<br />";
141 $ok = false;
142 }
143
144 if (!$ok) {
145 echo '<div id="message" class="updated fade"><p><strong><em style="color:red;">' .
146 'ERROR' . '</em></strong></p><p>';
147 foreach ($errors as $error) {
148 echo esc_html($error) . '<br />';
149
150 }
151 echo '</p></div>';
152 } else { // OK - read file and save to My Saved Theme
153 // $handle has file handle to temp file.//
154 $contents = file_get_contents($filename);
155
156 if (!atw_posts_set_to_serialized_values($contents)) {
157 echo '<div id="message" class="updated fade"><p><strong><em style="color:red;">' .
158 'Sorry, there was a problem uploading your file.
159 The file you picked was not a valid Weaver Show Posts settings file.' .
160 '</em></strong></p></div>';
161 } else {
162 atw_posts_save_msg('Weaver Show Posts set to uploaded Filter.');
163 }
164 }
165 }
166
167 function atw_posts_set_to_serialized_values($contents)
168 {
169 if (!atw_posts_allow_file_read()) {
170 return false;
171 }
172
173 $restore = unserialize($contents);
174
175 if (!isset($restore['cur_filter']))
176 return false;
177
178 $current_filter = $restore['cur_filter'];
179
180 if (!isset($restore[$current_filter]))
181 return false;
182
183 atw_posts_setopt('current_filter', $current_filter);
184
185 global $atw_posts_opts_cache;
186
187 unset($atw_posts_opts_cache['filters'][$current_filter]);
188
189 $atw_posts_opts_cache['filters'][$current_filter] = $restore[$current_filter];
190 atw_posts_wpupdate_option('atw_posts_settings', $atw_posts_opts_cache);
191
192 return true;
193 }
194
195 /*
196 ================= nonce helpers =====================
197 */
198 function atw_posts_submitted($submit_name)
199 {
200 // do a nonce check for each form submit button
201 // pairs 1:1 with aspen_nonce_field
202 $nonce_act = $submit_name . '_act';
203 $nonce_name = $submit_name . '_nonce';
204
205 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- verified elsewhere
206 if (isset($_POST[$submit_name])) {
207 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce handled earlier in admin flow
208 if (isset($_POST[$nonce_name]) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST[$nonce_name])), $nonce_act)) {
209 return true;
210 } else {
211 die(esc_html("WARNING: invalid form submit detected ($submit_name). Probably caused by session time-out, or, rarely, a failed security check. Please contact WeaverTheme.com if you continue to receive this message."));
212 }
213 } else {
214 return false;
215 }
216 }
217
218 function atw_posts_nonce_field($submit_name, $echo = true)
219 {
220 // pairs 1:1 with sumbitted
221 // will be one for each form submit button
222
223 return wp_nonce_field($submit_name . '_act', $submit_name . '_nonce', $echo);
224 }
225
226 /*
227 ================= form helpers =====================
228 */
229
230 function atw_posts_get_POST($id)
231 {
232 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- verified elsewhere
233 if (!isset($_POST[$id])) {
234 return '';
235 }
236
237 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- verified via atw_posts_submitted()
238 return sanitize_text_field(wp_unslash($_POST[$id]));
239 }
240
241 // general values - atw_posts_getopt
242
243 function atw_posts_form_checkbox($id, $desc, $br = '<br />') {
244 ?>
245 <div style="display:inline;padding-left:2.5em;text-indent:-1.7em;"><label><input type="checkbox"
246 name="<?php echo esc_html($id) ?>"
247 id="<?php echo esc_html($id); ?>"
248 <?php checked(atw_posts_getopt($id)); ?> >&nbsp;
249 <?php echo wp_kses_post($desc) . '</label></div>' . wp_kses_post($br) . "\n";
250 }
251
252 // filter values - atw_posts_get_filter_opts
253
254 function atw_posts_filter_checkbox($id, $desc, $br = '<br />') {
255 ?>
256 <div style="display:inline;padding-left:2.5em;text-indent:-1.7em;"><label><input type="checkbox"
257 name="<?php echo esc_html($id); ?>"
258 id="<?php echo esc_html($id); ?>"
259 <?php checked(atw_posts_get_filter_opt($id)); ?> >&nbsp;
260
261 <?php echo esc_html($desc) . '</label></div>' . wp_kses_post($br) . "\n";
262 }
263
264 function atw_posts_filter_textarea($id, $desc, $br = '<br />') {
265 ?>
266 <div style="margin-top:5px;display:inline-block;padding-left:4em;text-indent:-1.7em;"><label>
267 <textarea style="margin-bottom:-8px;" cols=32 rows=1 maxlength=64
268 name="<?php echo esc_html($id); ?>"><?php echo wp_kses_post(sanitize_text_field(atw_posts_get_filter_opt($id))); ?></textarea>
269 &nbsp;
270 <?php echo wp_kses_post($desc . '</label></div>' . $br) . "\n";
271 }
272
273 function atw_posts_filter_val($id, $desc, $br = '<br />')
274 {
275 ?>
276 <div style="margin-top:5px;display:inline-block;padding-left:2.5em;text-indent:-1.7em;"><label>
277 <input class="regular-text" type="text" style="width:50px;height:22px;" name="<?php echo esc_html($id); ?>"
278 value="<?php echo wp_kses_post(sanitize_text_field(atw_posts_get_filter_opt($id))); ?>"/>
279 &nbsp;
280 <?php echo wp_kses_post($desc . '</label></div>' . $br) . "\n";
281 }
282
283