Changeset 2723063
- Timestamp:
- 05/13/2022 12:39:13 AM (4 years ago)
- Location:
- shorthand-connect
- Files:
-
- 6 edited
- 1 copied
-
tags/1.3.12 (copied) (copied from shorthand-connect/trunk)
-
tags/1.3.12/README.txt (modified) (3 diffs)
-
tags/1.3.12/includes/shorthand_options.php (modified) (4 diffs)
-
tags/1.3.12/shorthand_connect.php (modified) (7 diffs)
-
trunk/README.txt (modified) (3 diffs)
-
trunk/includes/shorthand_options.php (modified) (4 diffs)
-
trunk/shorthand_connect.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
shorthand-connect/tags/1.3.12/README.txt
r2687312 r2723063 3 3 Donate link: 4 4 Tags: shorthand, api 5 Requires at least: 4 6 Tested up to: 5.9.1 7 Stable tag: 1.3.10 5 Requires at least: 4.0 6 Tested up to: 5.9.3 7 Stable tag: 1.3.12 8 Requires PHP: 5.6 8 9 License: GPLv2 or later 9 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 28 29 4. Optionally change the CSS settings in the options to best present stories within your theme. 29 30 5. Optionally your theme can override the display of Shorthand stories via `single-shorthand_story.php` in your theme directory. 31 6. Optionally apply post-processing in the form of regex queries; within Settings, Post-Processing. 32 33 ~~~ 34 { 35 "head": 36 [ 37 { 38 "query": "/<title.(.*?)<\/title>/", 39 "replace":"" 40 }, 41 { 42 "query": "/regex string/", 43 "replace":"String to replace it" 44 }, 45 ... 46 47 ], 48 "body":[] 49 } 50 ~~~ 51 30 52 31 53 == Updating == … … 37 59 38 60 == Changelog == 61 62 = 1.3.12 = 63 * Bumping versions 64 65 = 1.3.11 = 66 * Added Post-processing Regex JSON for stripping/modifying head and body content of Shorthand Stories. Also added custom field "no_update"; if true, updating the Wordpress Shorthand Story won't fetch and replace the existing content. 39 67 40 68 = 1.3.10 = -
shorthand-connect/tags/1.3.12/includes/shorthand_options.php
r2687312 r2723063 46 46 update_option('sh_api_version', sanitize_text_field($_POST['sh_api_version'])); 47 47 } 48 48 49 $token = esc_html(get_option('sh_token_key')); 49 50 $v2_token = esc_html(get_option('sh_v2_token')); 50 51 $user_id = esc_html(get_option('sh_user_id')); 51 52 $sh_api_version = esc_html(get_option('sh_api_version')); 53 52 54 53 55 if( isset($_POST['sh_submit_hidden_two']) && $_POST['sh_submit_hidden_two'] == 'Y' && check_admin_referer( 'sh-update-configuration' ) ) { … … 75 77 $sh_css = $default_sh_site_css; 76 78 } 79 80 if(isset($_POST['sh_submit_hidden_four']) && $_POST['sh_submit_hidden_four'] == 'Y' && check_admin_referer( 'sh-update-configuration' ) ) { 81 update_option('sh_regex_list', base64_encode(wp_unslash($_POST['sh_regex_list']))); 82 } 83 84 $sh_regex_list = base64_decode(get_option('sh_regex_list')); 77 85 78 86 $profile = sh_get_profile(); … … 150 158 </form> 151 159 160 <h3>Post-processing</h3> 161 <p>Use this to create a JSON object of regex queries and replacements.</p> 162 <p><em>This Example removes title tags from within the head tag by replacing it with nothing.</em></p> 163 <pre><code> 164 { 165 "head": 166 [ 167 { 168 "query":"/<title.(.*?)<\/title>/", 169 "replace":"" 170 } 171 ], 172 "body":[] 173 } 174 175 </code></pre> 176 <form name="form2" method="post" onsubmit="padJson()"> 177 <?php echo $n_once ?> 178 <input type="hidden" name="sh_submit_hidden_four" value="Y" /> 179 <textarea rows="10" cols="80" id="sh_regex_list" name="sh_regex_list"><?php echo stripslashes($sh_regex_list); ?></textarea> 180 <p class="submit"> 181 <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" /> 182 </p> 183 </form> 184 <script> 185 let textarea = document.querySelector("textarea#sh_regex_list"); 186 187 function padJson() { 188 console.log('updated JSON'); 189 textarea.value = textarea.value.replace(/\\/g, '\\\\'); 190 } 191 192 193 textarea.addEventListener("keyup", function(event) { 194 try{ 195 JSON.parse(textarea.value); 196 textarea.setCustomValidity(""); 197 198 }catch(err){ 199 if(textarea.value != ""){ 200 console.log("Invalid JSON"); 201 textarea.setCustomValidity("Invalid JSON in the Post-processing field"); 202 }else{ 203 textarea.setCustomValidity(""); 204 } 205 } 206 207 }); 208 </script> 209 152 210 <style> 153 211 img.grav { … … 171 229 display:none; 172 230 } 231 232 code { 233 font-family: monospace; 234 display: inherit; 235 } 173 236 </style> 174 237 <script> -
shorthand-connect/tags/1.3.12/shorthand_connect.php
r2602733 r2723063 3 3 /** 4 4 * @package Shorthand Connect 5 * @version 1.3. 95 * @version 1.3.11 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. 912 Version: 1.3.11 13 13 Author URI: http://shorthand.com 14 14 */ … … 59 59 ) 60 60 ); 61 61 62 62 register_taxonomy_for_object_type('category', 'shorthand_story'); 63 63 register_taxonomy_for_object_type('post_tag', 'shorthand_story'); … … 269 269 } 270 270 271 if(!get_post_meta($post_id, 'no_update')) { 272 update_post_meta($post_id, 'no_update', "false"); 273 } 274 271 275 if (isset($_REQUEST['extra_html'])) { 272 276 update_post_meta($post_id, 'extra_html', wp_kses_post($_REQUEST['extra_html'])); 273 277 } 274 278 275 if (isset($_REQUEST['story_id'])) { 279 if (isset($_REQUEST['story_id']) && get_post_meta($post_id, 'no_update')[0] !== "true") { 280 276 281 $safe_story_id = preg_replace("/\W|_/", '', $_REQUEST['story_id']); 277 282 update_post_meta($post_id, 'story_id', sanitize_text_field($safe_story_id)); … … 285 290 } 286 291 287 if (isset($story_path) ) {292 if (isset($story_path) ) { 288 293 // The story has been uploaded 289 294 update_post_meta($post_id, 'story_path', $story_path); … … 304 309 $article_file = $story_path . '/article.html'; 305 310 } 311 $post_processing_queries = json_decode(base64_decode(get_option('sh_regex_list'))); 312 306 313 $body = shand_fix_content_paths($assets_path, file_get_contents($article_file), $version); 314 if(isset($post_processing_queries->body)){ 315 $body = shand_post_processing($body,$post_processing_queries->body); 316 } 307 317 update_post_meta($post_id, 'story_body', wp_slash($body)); 308 318 $head = shand_fix_content_paths($assets_path, file_get_contents($head_file), $version); 319 if(isset($post_processing_queries->head)){ 320 $head = shand_post_processing($head, $post_processing_queries->head); 321 } 309 322 update_post_meta($post_id, 'story_head', wp_slash($head)); 310 323 … … 454 467 $content = str_replace('./media/', $assets_path . '/media/', $content); 455 468 } 469 470 return $content; 471 } 472 473 function shand_post_processing($content, $queries) 474 { 475 if ($queries == null){ 476 return $content; 477 } 478 479 foreach ($queries as $query) { 480 if(isset($query->query) && isset($query->replace)){ 481 $content = preg_replace($query->query, $query->replace, $content); 482 } 483 } 484 456 485 return $content; 457 486 } -
shorthand-connect/trunk/README.txt
r2687312 r2723063 3 3 Donate link: 4 4 Tags: shorthand, api 5 Requires at least: 4 6 Tested up to: 5.9.1 7 Stable tag: 1.3.10 5 Requires at least: 4.0 6 Tested up to: 5.9.3 7 Stable tag: 1.3.12 8 Requires PHP: 5.6 8 9 License: GPLv2 or later 9 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 28 29 4. Optionally change the CSS settings in the options to best present stories within your theme. 29 30 5. Optionally your theme can override the display of Shorthand stories via `single-shorthand_story.php` in your theme directory. 31 6. Optionally apply post-processing in the form of regex queries; within Settings, Post-Processing. 32 33 ~~~ 34 { 35 "head": 36 [ 37 { 38 "query": "/<title.(.*?)<\/title>/", 39 "replace":"" 40 }, 41 { 42 "query": "/regex string/", 43 "replace":"String to replace it" 44 }, 45 ... 46 47 ], 48 "body":[] 49 } 50 ~~~ 51 30 52 31 53 == Updating == … … 37 59 38 60 == Changelog == 61 62 = 1.3.12 = 63 * Bumping versions 64 65 = 1.3.11 = 66 * Added Post-processing Regex JSON for stripping/modifying head and body content of Shorthand Stories. Also added custom field "no_update"; if true, updating the Wordpress Shorthand Story won't fetch and replace the existing content. 39 67 40 68 = 1.3.10 = -
shorthand-connect/trunk/includes/shorthand_options.php
r2687312 r2723063 46 46 update_option('sh_api_version', sanitize_text_field($_POST['sh_api_version'])); 47 47 } 48 48 49 $token = esc_html(get_option('sh_token_key')); 49 50 $v2_token = esc_html(get_option('sh_v2_token')); 50 51 $user_id = esc_html(get_option('sh_user_id')); 51 52 $sh_api_version = esc_html(get_option('sh_api_version')); 53 52 54 53 55 if( isset($_POST['sh_submit_hidden_two']) && $_POST['sh_submit_hidden_two'] == 'Y' && check_admin_referer( 'sh-update-configuration' ) ) { … … 75 77 $sh_css = $default_sh_site_css; 76 78 } 79 80 if(isset($_POST['sh_submit_hidden_four']) && $_POST['sh_submit_hidden_four'] == 'Y' && check_admin_referer( 'sh-update-configuration' ) ) { 81 update_option('sh_regex_list', base64_encode(wp_unslash($_POST['sh_regex_list']))); 82 } 83 84 $sh_regex_list = base64_decode(get_option('sh_regex_list')); 77 85 78 86 $profile = sh_get_profile(); … … 150 158 </form> 151 159 160 <h3>Post-processing</h3> 161 <p>Use this to create a JSON object of regex queries and replacements.</p> 162 <p><em>This Example removes title tags from within the head tag by replacing it with nothing.</em></p> 163 <pre><code> 164 { 165 "head": 166 [ 167 { 168 "query":"/<title.(.*?)<\/title>/", 169 "replace":"" 170 } 171 ], 172 "body":[] 173 } 174 175 </code></pre> 176 <form name="form2" method="post" onsubmit="padJson()"> 177 <?php echo $n_once ?> 178 <input type="hidden" name="sh_submit_hidden_four" value="Y" /> 179 <textarea rows="10" cols="80" id="sh_regex_list" name="sh_regex_list"><?php echo stripslashes($sh_regex_list); ?></textarea> 180 <p class="submit"> 181 <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" /> 182 </p> 183 </form> 184 <script> 185 let textarea = document.querySelector("textarea#sh_regex_list"); 186 187 function padJson() { 188 console.log('updated JSON'); 189 textarea.value = textarea.value.replace(/\\/g, '\\\\'); 190 } 191 192 193 textarea.addEventListener("keyup", function(event) { 194 try{ 195 JSON.parse(textarea.value); 196 textarea.setCustomValidity(""); 197 198 }catch(err){ 199 if(textarea.value != ""){ 200 console.log("Invalid JSON"); 201 textarea.setCustomValidity("Invalid JSON in the Post-processing field"); 202 }else{ 203 textarea.setCustomValidity(""); 204 } 205 } 206 207 }); 208 </script> 209 152 210 <style> 153 211 img.grav { … … 171 229 display:none; 172 230 } 231 232 code { 233 font-family: monospace; 234 display: inherit; 235 } 173 236 </style> 174 237 <script> -
shorthand-connect/trunk/shorthand_connect.php
r2602733 r2723063 3 3 /** 4 4 * @package Shorthand Connect 5 * @version 1.3. 95 * @version 1.3.11 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. 912 Version: 1.3.11 13 13 Author URI: http://shorthand.com 14 14 */ … … 59 59 ) 60 60 ); 61 61 62 62 register_taxonomy_for_object_type('category', 'shorthand_story'); 63 63 register_taxonomy_for_object_type('post_tag', 'shorthand_story'); … … 269 269 } 270 270 271 if(!get_post_meta($post_id, 'no_update')) { 272 update_post_meta($post_id, 'no_update', "false"); 273 } 274 271 275 if (isset($_REQUEST['extra_html'])) { 272 276 update_post_meta($post_id, 'extra_html', wp_kses_post($_REQUEST['extra_html'])); 273 277 } 274 278 275 if (isset($_REQUEST['story_id'])) { 279 if (isset($_REQUEST['story_id']) && get_post_meta($post_id, 'no_update')[0] !== "true") { 280 276 281 $safe_story_id = preg_replace("/\W|_/", '', $_REQUEST['story_id']); 277 282 update_post_meta($post_id, 'story_id', sanitize_text_field($safe_story_id)); … … 285 290 } 286 291 287 if (isset($story_path) ) {292 if (isset($story_path) ) { 288 293 // The story has been uploaded 289 294 update_post_meta($post_id, 'story_path', $story_path); … … 304 309 $article_file = $story_path . '/article.html'; 305 310 } 311 $post_processing_queries = json_decode(base64_decode(get_option('sh_regex_list'))); 312 306 313 $body = shand_fix_content_paths($assets_path, file_get_contents($article_file), $version); 314 if(isset($post_processing_queries->body)){ 315 $body = shand_post_processing($body,$post_processing_queries->body); 316 } 307 317 update_post_meta($post_id, 'story_body', wp_slash($body)); 308 318 $head = shand_fix_content_paths($assets_path, file_get_contents($head_file), $version); 319 if(isset($post_processing_queries->head)){ 320 $head = shand_post_processing($head, $post_processing_queries->head); 321 } 309 322 update_post_meta($post_id, 'story_head', wp_slash($head)); 310 323 … … 454 467 $content = str_replace('./media/', $assets_path . '/media/', $content); 455 468 } 469 470 return $content; 471 } 472 473 function shand_post_processing($content, $queries) 474 { 475 if ($queries == null){ 476 return $content; 477 } 478 479 foreach ($queries as $query) { 480 if(isset($query->query) && isset($query->replace)){ 481 $content = preg_replace($query->query, $query->replace, $content); 482 } 483 } 484 456 485 return $content; 457 486 }
Note: See TracChangeset
for help on using the changeset viewer.