Changeset 2950391
- Timestamp:
- 08/09/2023 10:19:19 AM (3 years ago)
- Location:
- shorthand-connect/tags/1.3.29
- Files:
-
- 4 edited
- 1 copied
-
. (copied) (copied from shorthand-connect/trunk)
-
README.txt (modified) (3 diffs)
-
includes/api.php (modified) (1 diff)
-
includes/shorthand_options.php (modified) (10 diffs)
-
shorthand_connect.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
shorthand-connect/tags/1.3.29/README.txt
r2898299 r2950391 5 5 Requires at least: 4.0 6 6 Tested up to: 6.1 7 Stable tag: 1.3.2 87 Stable tag: 1.3.29 8 8 Requires PHP: 5.6 9 9 License: GPLv2 or later … … 36 36 [ 37 37 { 38 "query": "/<title.(.*?)<\/title>/",38 "query": "/<title>(.*?)<\\/title>/", 39 39 "replace":"" 40 40 }, … … 64 64 == Changelog == 65 65 66 = 1.3.29 = 67 * Security Fixes & Updates 68 * JSON Post-Processing Fixes 69 66 70 = 1.3.28 = 67 71 * Code clean up & bug fixes -
shorthand-connect/tags/1.3.29/includes/api.php
r2898299 r2950391 140 140 141 141 do_action('sh_copy_story', $post_id, $story_id, $story); 142 unlink($zip_file); 143 142 wp_delete_file($zip_file); 144 143 return $story; 145 144 } -
shorthand-connect/tags/1.3.29/includes/shorthand_options.php
r2898299 r2950391 26 26 '; 27 27 28 // JSON Checker 29 function validate_json($json_string) { 30 // Try to decode the JSON data. If it fails, the JSON is invalid. 31 $json_data = json_decode($json_string, true); 32 33 if (json_last_error() !== JSON_ERROR_NONE) { 34 // The JSON is invalid. 35 return false; 36 } 37 38 // Return the original JSON string if it's valid. 39 return $json_string; 40 } 41 28 42 function shand_shorthand_options() 29 43 { … … 35 49 } 36 50 if( isset($_POST['sh_submit_hidden']) && $_POST['sh_submit_hidden'] == 'Y' && check_admin_referer( 'sh-update-configuration' ) ) { 37 update_option('sh_v2_token', sanitize_text_field($_POST['sh_v2_token'])); 38 } 51 //If there's a token set, use it, if not set it to an empty string 52 $sh_v2_token = isset($_POST['sh_v2_token']) ? sanitize_text_field($_POST['sh_v2_token']) : ''; 53 update_option('sh_v2_token', $sh_v2_token); 54 } 55 39 56 $v2_token = esc_html(get_option('sh_v2_token')); 40 57 41 58 if( isset($_POST['sh_submit_hidden_two']) && $_POST['sh_submit_hidden_two'] == 'Y' && check_admin_referer( 'sh-update-configuration' ) ) { 42 update_option('sh_css', wp_kses_post($_POST['sh_css'])); 43 } 44 if( isset($_POST['sh_submit_hidden_three']) && $_POST['sh_submit_hidden_three'] == 'Y' && check_admin_referer( 'sh-update-configuration' ) ) { 45 update_option('sh_permalink', sanitize_text_field($_POST['sh_permalink'])); 59 //Check if there's custom CSS, if there is, use wp_kses_post() to sanitize otherwise set an empty string 60 $sh_css = isset($_POST['sh_css']) ? wp_kses_post($_POST['sh_css']) : ''; 61 update_option('sh_css', $sh_css); 62 } 63 64 65 // Rather than running a rewrite flush everytime a post is submitted, run it on plugin activate/deactivate 66 function shand_rewrite_flush() { 46 67 shand_create_post_type(); 47 68 flush_rewrite_rules(); 69 } 70 register_activation_hook( __FILE__, 'shand_rewrite_flush' ); 71 register_deactivation_hook( __FILE__, 'flush_rewrite_rules' ); 72 73 if( isset($_POST['sh_submit_hidden_three']) && $_POST['sh_submit_hidden_three'] == 'Y' && check_admin_referer( 'sh-update-configuration' ) ) { 74 //Check if there's custom permalink, if there is, use sanitize_text_field() to sanitize potential HTML and then set an empty string 75 $sh_permalink = isset($_POST['sh_permalink']) ? sanitize_text_field($_POST['sh_permalink']) : ''; 76 update_option('sh_permalink', $sh_permalink); 77 shand_rewrite_flush(); 48 78 } 49 79 $permalink_structure = esc_html(get_option('sh_permalink')); … … 63 93 } 64 94 65 if (isset($_POST['sh_submit_hidden_four']) && $_POST['sh_submit_hidden_four'] == 'Y' && check_admin_referer( 'sh-update-configuration' )) { 66 update_option('sh_regex_list', base64_encode(wp_unslash($_POST['sh_regex_list']))); 67 } 95 if (isset($_POST['sh_submit_hidden_four']) && $_POST['sh_submit_hidden_four'] == 'Y' && check_admin_referer('sh-update-configuration')) { 96 $sh_regex_list = isset($_POST['sh_regex_list']) ? wp_unslash($_POST['sh_regex_list']) : ''; 97 98 if (empty($sh_regex_list)) { 99 // Update the option with an empty value if the input is empty 100 update_option('sh_regex_list', ''); 101 } else { 102 // Validate if it's a valid JSON without sanitizing 103 $sh_regex_list = validate_json($sh_regex_list); 104 105 if ($sh_regex_list !== false) { 106 // Since we are storing it as base64, no need to sanitize the JSON, as base64_encode will handle that 107 update_option('sh_regex_list', base64_encode($sh_regex_list)); 108 } else { 109 // Handle invalid JSON error here. 110 } 111 } 112 } 113 114 68 115 69 116 $sh_regex_list = base64_decode(get_option('sh_regex_list')); … … 80 127 81 128 $profile = sh_get_profile(); 82 $n_once = wp_nonce_field( 'sh-update-configuration' ); 83 84 ?> 85 <h3>Shorthand API Configuration</h3> 129 130 ob_start(); 131 wp_nonce_field( 'sh-update-configuration' ); 132 $n_once = ob_get_clean(); 133 134 ?> 135 <div class="container"> 136 <div class="py-1"> 137 <h1>Shorthand API Configuration</h1> 138 <h2>Shorthand Connect Status</h2> 86 139 <form name="form1" method="post"> 87 140 <?php echo $n_once ?> … … 89 142 <table class="form-table"><tbody> 90 143 <tr class="v2row"> 91 <th scope="row"><label for="sh_v2_token"><?php _e("Shorthand Team Token", 'sh-v2-token' ); ?></label></th>144 <th scope="row"><label for="sh_v2_token"><?php esc_html_e("Shorthand Team Token", 'sh-v2-token' ); ?></label></th> 92 145 <td><input type="text" id="sh_v2_token" name="sh_v2_token" value="<?php echo esc_attr($v2_token); ?>" size="28"></td> 93 146 </tr> 94 147 </tbody></table> 95 <p class="submit"> 96 <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" /> 97 </p> 98 <hr /> 99 </form> 100 <h3>Shorthand Connect Status</h3> 101 <?php if ($profile) { ?> 148 <?php if ($profile) { ?> 102 149 <p class="status">Successfully connected</p> 103 <p><strong>Username</strong>: <?php echo $profile->username; ?></p>150 <p><strong>Username</strong>: <?php echo esc_html($profile->username); ?></p> 104 151 <?php } else { ?> 105 152 <p class="status warn">Not Connected</p> 106 153 <?php } ?> 107 154 <div style='clear:both'></div> 108 <h3>Shorthand Permalink Structure</h3> 155 <p class="submit"> 156 <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" /> 157 </p> 158 </form> 159 </div> 160 161 162 <div class="py-1"> 163 <h2>Shorthand Permalink Structure</h2> 109 164 <p>Use this to set the permalink structure of Shorthand story URLs</p> 110 <form name=" form2" method="post">165 <form name="permalinks" method="post"> 111 166 <?php echo $n_once ?> 112 167 <input type="hidden" name="sh_submit_hidden_three" value="Y" /> … … 118 173 </p> 119 174 </form> 120 121 122 123 <h 3>Shorthand Story Page CSS (theme wide CSS)</h3>175 </div> 176 177 <div class="py-1"> 178 <h2>Shorthand Story Page CSS (theme wide CSS)</h2> 124 179 <p>Use this CSS to customise Shorthand Story pages to better suit your theme</p> 125 180 <?php if ($no_css) { ?> 126 181 <p class="status warn">No custom CSS found, using default theme CSS</p> 127 182 <?php }?> 128 <form name=" form2" method="post">183 <form name="themecss" method="post"> 129 184 <?php echo $n_once ?> 130 185 <input type="hidden" name="sh_submit_hidden_two" value="Y" /> … … 134 189 </p> 135 190 </form> 136 137 <h3>Post-processing</h3> 191 </div> 192 193 <div class="py-1"> 194 <h2>Post-processing</h2> 138 195 <p>Use this to create a JSON object of regex queries and replacements.</p> 139 196 <p><em>This Example removes title tags from within the head tag by replacing it with nothing.</em></p> 140 197 <pre><code> 141 {142 "head":143 [ 144 { 145 "query":"/<title.(.*?)<\/title>/", 146 "replace":"" 147 } 148 ], 149 "body":[] 150 } 198 { 199 "head": [ 200 { 201 "query": "/<title>(.*?)<\\/title>/", 202 "replace": "" 203 } 204 ], 205 "body": [] 206 } 207 151 208 </code></pre> 152 <form name=" form2" method="post" onsubmit="padJson()">209 <form name="postprocessing" method="post"> 153 210 <?php echo $n_once ?> 154 211 <input type="hidden" name="sh_submit_hidden_four" value="Y" /> … … 160 217 <script> 161 218 let textarea = document.querySelector("textarea#sh_regex_list"); 162 163 function padJson() { 164 console.log('updated JSON'); 165 textarea.value = textarea.value.replace(/\\/g, '\\\\'); 166 } 167 168 219 169 220 textarea.addEventListener("keyup", function(event) { 170 221 try{ … … 183 234 }); 184 235 </script> 185 186 <style> 236 </div> 237 238 <div class="py-1"> 239 <h2>Experimental Features</h2> 240 <p>Early access features that are still subject to change.</p> 241 <form name="form_experimental" method="post"> 242 <?php echo $n_once ?> 243 <input type="hidden" name="sh_submit_hidden_experimental" value="Y" /> 244 <input type="checkbox" id="sh_media_cron_offload" name="sh_media_cron_offload" value="true" <?php echo esc_attr($sh_media_cron_offload ? 'checked' : '') ?> /> 245 <label for="sh_media_cron_offload">Import media assets via cron</label> 246 <p>Assets will be fetched after story save to prevent potential execution timeouts. Media won't be immediately available on save but progress will be updated based on the `media_status` field.</p> 247 <p>It is advised that Shorthand Story Posts are saved as a draft first to trigger the cron job prior to public publishing.</p> 248 <br/> 249 <input type="checkbox" id="sh_disable_acf" name="sh_disable_acf" value="true" <?php echo esc_attr($sh_disable_acf ? 'checked' : '') ?> /> 250 <label for="sh_disable_acf">Disable Advanced Custom Fields</label> 251 <p>Used to prevent any potential issues that could cause the Shorthand Custom Fields to become hidden by Advanced Custom Fields.</p> 252 </br> 253 <p class="submit"> 254 <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" /> 255 </p> 256 </form> 257 </div> 258 </div> 259 </div> 260 <style> 261 .py-1 { 262 padding: 1em; 263 } 264 .bg-white { 265 background: white; 266 } 267 .container { 268 max-width: 980px; 269 } 187 270 img.grav { 188 271 float: left; … … 205 288 display:none; 206 289 } 207 290 #wpfooter { 291 position: unset; 292 } 208 293 code { 209 font-family: monospace;210 display: inherit;211 }294 font-family: monospace; 295 display: inherit; 296 } 212 297 </style> 213 298 214 <h3>Experimental Features</h3> 215 <p>Early access features that are still subject to change.</p> 216 <form name="form_experimental" method="post"> 217 <?php echo $n_once ?> 218 <input type="hidden" name="sh_submit_hidden_experimental" value="Y" /> 219 <input type="checkbox" id="sh_media_cron_offload" name="sh_media_cron_offload" value="true" <?php echo esc_attr($sh_media_cron_offload ? 'checked' : '') ?> /> 220 <label for="sh_media_cron_offload">Import media assets via cron</label> 221 <p>Assets will be fetched after story save to prevent potential execution timeouts. Media won't be immediately available on save but progress will be updated based on the `media_status` field.</p> 222 <p>It is advised that Shorthand Story Posts are saved as a draft first to trigger the cron job prior to public publishing.</p> 223 <br/> 224 <input type="checkbox" id="sh_disable_acf" name="sh_disable_acf" value="true" <?php echo esc_attr($sh_disable_acf ? 'checked' : '') ?> /> 225 <label for="sh_disable_acf">Disable Advanced Custom Fields</label> 226 <p>Used to prevent any potential issues that could cause the Shorthand Custom Fields to become hidden by Advanced Custom Fields.</p> 227 </br> 228 <p class="submit"> 229 <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" /> 230 </p> 231 </form> 299 232 300 <?php 233 301 } -
shorthand-connect/tags/1.3.29/shorthand_connect.php
r2898299 r2950391 3 3 /** 4 4 * @package Shorthand Connect 5 * @version 1.3.2 85 * @version 1.3.29 6 6 */ 7 7 /* … … 10 10 Description: Import your Shorthand stories into your Wordpress CMS as simply as possible - magic! 11 11 Author: Shorthand 12 Version: 1.3.2 812 Version: 1.3.29 13 13 Author URI: http://shorthand.com 14 14 */ 15 15 16 if (file_exists( 'config.php')) {17 include_once( 'config.php');16 if (file_exists( plugin_dir_path( __FILE__) . 'config.php')) { 17 include_once( plugin_dir_path( __FILE__) . 'config.php'); 18 18 } else { 19 require_once( 'config.default.php');20 } 21 require_once( 'includes/api.php');22 require_once( 'includes/mass_pull.php');23 24 require_once( 'includes/shorthand_options.php');25 require_once( 'templates/abstract.php');19 require_once( plugin_dir_path( __FILE__) . 'config.default.php'); 20 } 21 require_once( plugin_dir_path( __FILE__) . 'includes/api.php'); 22 require_once( plugin_dir_path( __FILE__) . 'includes/mass_pull.php'); 23 24 require_once( plugin_dir_path( __FILE__) . 'includes/shorthand_options.php'); 25 require_once( plugin_dir_path( __FILE__) . 'templates/abstract.php'); 26 26 27 27 if ( !function_exists('WP_Filesystem') ) { … … 341 341 } 342 342 343 if (!$noabstract && isset($_REQUEST['abstract'])) { 344 update_post_meta($post_id, 'abstract', wp_kses_post($_REQUEST['abstract'])); 345 } else if ($noabstract && get_post_meta($post_id, 'abstract')) { 346 delete_post_meta($post_id, 'abstract'); 347 } 348 349 if (!get_post_meta($post_id, 'no_update')) { 350 update_post_meta($post_id, 'no_update', "false"); 351 } 352 353 if (isset($_REQUEST['extra_html'])) { 354 update_post_meta($post_id, 'extra_html', wp_kses_post($_REQUEST['extra_html'])); 355 } 356 357 $do_update_story = isset($_REQUEST['shand_update']) || get_post_meta($post_id, 'no_update')[0] !== "true"; 343 //Check if these fields are nonce_verified 344 if (isset($_POST['eventmeta_noncename']) && wp_verify_nonce(sanitize_text_field($_POST['eventmeta_noncename']), plugin_basename(__FILE__))) { 345 if (!$noabstract && isset($_REQUEST['abstract'])) { 346 update_post_meta($post_id, 'abstract', wp_kses_post($_REQUEST['abstract'])); 347 } else if ($noabstract && get_post_meta($post_id, 'abstract')) { 348 delete_post_meta($post_id, 'abstract'); 349 } 350 351 if (!get_post_meta($post_id, 'no_update')) { 352 update_post_meta($post_id, 'no_update', "false"); 353 } 354 355 if (isset($_REQUEST['extra_html'])) { 356 update_post_meta($post_id, 'extra_html', wp_kses_post($_REQUEST['extra_html'])); 357 } 358 } 359 360 $do_update_story = isset($_REQUEST['shand_update']) || get_post_meta($post_id, 'no_update', true) !== "true"; 358 361 359 362 if (isset($_REQUEST['story_id']) && $_REQUEST['story_id'] !== "" && $do_update_story) { 360 363 update_post_meta($post_id, 'no_update', "true"); 361 364 $sh_media_cron_offload = filter_var(get_option('sh_media_cron_offload'), FILTER_VALIDATE_BOOLEAN); 362 $safe_story_id = preg_replace("/\W|_/", '', $_REQUEST['story_id']); 365 366 //Sanitize but also check if the query is GET or POST 367 if (isset($_REQUEST['story_id'])) { 368 $story_id = filter_input(INPUT_GET, 'story_id', FILTER_SANITIZE_STRING); 369 if ($story_id === null) { // If the variable is not present in the $_GET array 370 $story_id = filter_input(INPUT_POST, 'story_id', FILTER_SANITIZE_STRING); 371 } 372 $safe_story_id = preg_replace("/\W|_/", '', $story_id); 373 } 374 375 363 376 update_post_meta($post_id, 'story_id', sanitize_text_field($safe_story_id)); 364 377 $err = sh_copy_story($post_id, $safe_story_id, $sh_media_cron_offload); 365 378 $story_path = sh_get_story_path($post_id, $safe_story_id); 379 366 380 //Sometimes the story needs to be gotten twice 367 381 if (!isset($story_path)) { … … 482 496 add_action('wp_head', 'hook_css'); 483 497 484 485 498 /* Get Posts Hook */ 486 499 function shand_shorthand_get_posts($query) 487 500 { 488 if (is_home() && $query->is_main_query()) { 489 $query->set( 'post_type', array( 'post', 'shorthand_story' ) ); 490 } 491 return $query; 501 if (is_admin()) { 502 return $query; 503 } 504 505 // Check if the query is the main query and it's for the front-end 506 if ($query->is_main_query() && !is_admin()) { 507 $queried_object = get_queried_object(); 508 $shorthand_templates = array('single-shorthand_story.php', 'templates/single-shorthand_story.php', 'template-parts/single-shorthand_story.php'); 509 510 // Check if the queried object uses a Shorthand Post template from the array 511 if ($queried_object 512 && isset($queried_object->ID) 513 && in_array(get_page_template_slug($queried_object->ID), $shorthand_templates)) { 514 515 // Get the current post type(s) 516 $post_type = $query->get('post_type'); 517 518 // If the post type hasn't been modified, then add the shorthand post type 519 if (empty($post_type) || $post_type == 'post') { 520 $query->set('post_type', array('post', 'shorthand_story')); 521 } 522 } 523 } 524 return $query; 492 525 } 493 526 add_filter('pre_get_posts', 'shand_shorthand_get_posts'); … … 519 552 function shand_shorthand_activate() 520 553 { 554 flush_rewrite_rules(); 521 555 shand_create_post_type(); 522 flush_rewrite_rules();523 556 } 524 557 register_activation_hook(__FILE__, 'shand_shorthand_activate'); … … 562 595 $extra_html = get_post_meta($post->ID, 'extra_html', true); 563 596 echo '<input type="hidden" name="eventmeta_noncename" id="eventmeta_noncename" value="' . 564 wp_create_nonce(plugin_basename(__FILE__)) . '" />';597 esc_attr(wp_create_nonce(plugin_basename(__FILE__))) . '" />'; 565 598 echo '<textarea id="codearea" name="extra_html">' . esc_textarea($extra_html) . '</textarea>'; 566 599 }
Note: See TracChangeset
for help on using the changeset viewer.