Changeset 2817526
- Timestamp:
- 11/14/2022 09:37:13 AM (3 years ago)
- Location:
- shorthand-connect
- Files:
-
- 8 edited
- 1 copied
-
tags/1.3.26 (copied) (copied from shorthand-connect/trunk)
-
tags/1.3.26/README.txt (modified) (3 diffs)
-
tags/1.3.26/includes/api-v2.php (modified) (1 diff)
-
tags/1.3.26/includes/shorthand_options.php (modified) (2 diffs)
-
tags/1.3.26/shorthand_connect.php (modified) (12 diffs)
-
trunk/README.txt (modified) (3 diffs)
-
trunk/includes/api-v2.php (modified) (1 diff)
-
trunk/includes/shorthand_options.php (modified) (2 diffs)
-
trunk/shorthand_connect.php (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
shorthand-connect/tags/1.3.26/README.txt
r2803964 r2817526 4 4 Tags: shorthand, api 5 5 Requires at least: 4.0 6 Tested up to: 6. 0.17 Stable tag: 1.3.2 56 Tested up to: 6.1 7 Stable tag: 1.3.26 8 8 Requires PHP: 5.6 9 9 License: GPLv2 or later … … 50 50 ~~~ 51 51 52 == Experimental Features == 53 54 1. Import media assets via cron - This feature allows your Wordpress installation to ingest Shorthand Story assets via a delayed CRON. This feature was introduced for users with VIP Hosted sites and those who have hard timeout limits set. 55 52 56 53 57 == Updating == … … 59 63 60 64 == Changelog == 65 66 = 1.3.26 = 67 * Restyled and repositioned "Update Shorthand Story" button for better clarity. 61 68 62 69 = 1.3.25 = -
shorthand-connect/tags/1.3.26/includes/api-v2.php
r2796659 r2817526 176 176 return $story; 177 177 } 178 179 180 // DEBUG181 182 function sh_test_1a_fetch_story_to_tmp($post_id, $story_id) {183 184 wp_raise_memory_limit('admin');185 init_WP_Filesystem();186 187 $destination = wp_upload_dir();188 $tmpdir = get_temp_dir();189 $destination_path = $destination['path'].'/shorthand/'.$post_id;190 191 //Attempt to connect to the server192 $zip_file = wp_tempnam('sh_zip',$tmpdir);193 $response = sh_v2_api_get('/v2/stories/'.$story_id, array(194 'timeout' => '600',195 'stream' => true,196 'filename' => $zip_file197 ));198 if (is_wp_error($response)) {199 $story['error'] = array(200 'pretty' => ' Request to Shorthand failed',201 'error' => $response->get_error_message($response)202 );203 } else if (!$response || $response['response']['code'] != 200) {204 $story['error'] = array(205 'pretty' => 'Request to Shorthand failed; check the token is configured correctly',206 'response' => $response207 );208 }209 210 return $story;211 }212 213 function sh_test_1b_fetch_story_to_uploads($post_id, $story_id) {214 215 wp_raise_memory_limit('admin');216 init_WP_Filesystem();217 218 $destination = wp_upload_dir();219 $tmpdir = $destination['path'].'/zips/'.$post_id;220 $destination_path = $destination['path'].'/shorthand/'.$post_id;221 222 //Attempt to connect to the server223 wp_mkdir_p($tmpdir);224 $zip_file = $tmpdir . '/' . $story_id . '.zip';225 $response = sh_v2_api_get('/v2/stories/'.$story_id, array(226 'timeout' => '600',227 'stream' => true,228 'filename' => $zip_file229 ));230 if (is_wp_error($response)) {231 $story['error'] = array(232 'pretty' => ' Request to Shorthand failed',233 'error' => $response->get_error_message($response)234 );235 } else if (!$response || $response['response']['code'] != 200) {236 $story['error'] = array(237 'pretty' => 'Request to Shorthand failed; check the token is configured correctly',238 'response' => $response239 );240 }241 242 return $story;243 }244 245 function sh_test_2a_extract_story_from_tmp($post_id, $story_id) {246 247 wp_raise_memory_limit('admin');248 init_WP_Filesystem();249 250 $destination = wp_upload_dir();251 $tmpdir = get_temp_dir();252 $uploads_zip_file = $destination['path'].'/zips/'.$post_id . '/' . $story_id . '.zip';253 $destination_path = $destination['path'].'/shorthand/'.$post_id;254 255 $zip_file = $tmpdir . $post_id . '_' . $story_id . '.zip';256 if (!copy($uploads_zip_file, $zip_file)) {257 $story['error'] = array(258 'pretty' => 'Copying file from uploads to tmp failed',259 'source' => $uploads_zip_file,260 'dest' => $zip_file261 );262 } else {263 $story = extractStoryContent($zip_file, $destination_path, $story_id);264 }265 266 return $story;267 }268 269 function sh_test_2b_extract_story_from_uploads($post_id, $story_id) {270 271 wp_raise_memory_limit('admin');272 init_WP_Filesystem();273 274 $destination = wp_upload_dir();275 $tmpdir = $destination['path'].'/zips/'.$post_id;276 $destination_path = $destination['path'].'/shorthand/'.$post_id;277 278 //Attempt to connect to the server279 $zip_file = $tmpdir . '/' . $story_id . '.zip';280 $story = extractStoryContent($zip_file, $destination_path, $story_id);281 282 return $story;283 } -
shorthand-connect/tags/1.3.26/includes/shorthand_options.php
r2794163 r2817526 80 80 if( isset($_POST['sh_submit_hidden_experimental']) && $_POST['sh_submit_hidden_experimental'] == 'Y' && check_admin_referer( 'sh-update-configuration' ) ) { 81 81 update_option('sh_media_cron_offload', $_POST['sh_media_cron_offload']); 82 update_option('sh_debug_test', $_POST['sh_debug_test']);83 82 } 84 83 $sh_media_cron_offload = filter_var(get_option('sh_media_cron_offload'), FILTER_VALIDATE_BOOLEAN); 85 $sh_debug_test = filter_var(get_option('sh_debug_test'), FILTER_VALIDATE_BOOLEAN);86 84 87 85 $profile = sh_get_profile(); … … 230 228 <p>It is advised that Shorthand Story Posts are saved as a draft first to trigger the cron job prior to public publishing.</p> 231 229 <br/> 232 <input type="checkbox" id="sh_debug_test" name="sh_debug_test" value="true" <?php echo esc_attr($sh_debug_test ? 'checked' : '') ?> />233 <label for="sh_debug_test">Show/Hide extra debug tests on Shorthand Story form.</label>234 230 <p class="submit"> 235 231 <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" /> -
shorthand-connect/tags/1.3.26/shorthand_connect.php
r2803964 r2817526 3 3 /** 4 4 * @package Shorthand Connect 5 * @version 1.3.2 55 * @version 1.3.26 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 512 Version: 1.3.26 13 13 Author URI: http://shorthand.com 14 14 */ … … 67 67 add_action('init', 'shand_create_post_type'); 68 68 69 function shand_wpt_shorthand_media_fetch(){ 69 function shand_wpt_shorthand_story() 70 { 71 70 72 global $post; 71 73 … … 74 76 global $showArchivedStories; 75 77 76 $story_id = get_post_meta($post->ID, 'story_id', true);77 78 ?>79 <button id="shand_test_media_fetch" class="shand_test_media_fetch" data-postid="<?php echo $post->ID; ?>" data-storyid="<?php echo $story_id; ?>">Execute Media Fetch Function</button>80 <script>81 jQuery( document ).ready( function($) {82 $( 'button.shand_test_media_fetch' ).on( 'click', function(e) {83 e.preventDefault();84 var action = jQuery(this).attr('id');85 var story_id = jQuery(this).attr('data-storyid');86 var post_id = jQuery(this).attr('data-postid');87 $.post(ajaxurl, {action, story_id, post_id}, function( data ) {88 console.log('Test: ' + action);89 console.log(data);90 } );91 } );92 } );93 </script>94 <?php95 }96 97 98 function shand_wpt_shorthand_story()99 {100 101 global $post;102 103 global $serverURL;104 global $serverv2URL;105 global $showArchivedStories;106 107 78 $baseurl = ''; 108 79 109 80 $version = 'v2'; 110 111 $sh_debug_test = filter_var(get_option('sh_debug_test'), FILTER_VALIDATE_BOOLEAN);112 113 114 81 115 82 ?> … … 156 123 } 157 124 125 div.publishing-actions{ 126 padding: 10px; 127 clear: both; 128 border-top: 1px solid #dcdcde; 129 background: #f6f7f7; 130 margin: -12px; 131 margin-top: -12px; 132 margin-top: 10px; 133 display: flex; 134 justify-content: center; 135 } 136 137 .button-shorthand{ 138 background-color: #000; 139 border: 1px solid #000; 140 transition: background-color .15s ease,color .15s ease; 141 color: #fff; 142 font-family: poppins,sans-serif; 143 font-size: 13px; 144 font-weight: 600; 145 letter-spacing: 0; 146 line-height: 1; 147 padding: 1em 2em; 148 text-decoration: none; 149 cursor:pointer; 150 border-radius: .9em; 151 } 152 153 .button-shorthand:hover{ 154 background-color: #fff; 155 border-color: #000; 156 color: #000; 157 } 158 159 .button-shorthand:disabled{ 160 pointer-events:none; 161 } 162 158 163 #codearea { 159 164 border: 1px solid #999999; … … 187 192 188 193 $selected_story = get_post_meta($post->ID, 'story_id', true); 189 $story_api_version = get_post_meta($post->ID, 'api_version', true);190 194 if ($selected_story) { 191 195 shand_wpt_update_story($selected_story); … … 227 231 <script> 228 232 jQuery('li.story input:radio').click(function() { 229 230 <?php if($sh_debug_test){ ?>231 //DEBUG MODE232 jQuery('button.shand_test_action').attr('data-storyid', jQuery(this).val()); // inform test buttons of selection233 jQuery('button.shand_test_action').prop('disabled', false); // enable test buttons234 <?php } ?>235 233 jQuery('li.story').removeClass('selected'); 236 234 jQuery(this).parent().parent().addClass('selected'); … … 243 241 </script> 244 242 <?php 245 if($sh_debug_test){246 shand_wpt_shorthand_tests();247 }248 243 } 249 244 … … 254 249 <p>This will update Wordpress with the latest version of the story from Shorthand.</p> 255 250 <?php wp_nonce_field('shand_update_story', 'shand_update_story_nonce'); ?> 256 <input name="story_id" type="hidden" value="<?php esc_attr_e($storyId); ?>"/> 257 <input name="save" type="submit" value="Update Story" formaction="?shand_update"/> 251 252 253 <div class="publishing-actions"> 254 <input name="story_id" type="hidden" value="<?php esc_attr_e($storyId); ?>"/> 255 <input 256 id="shorthand_update" 257 name="save" 258 class="button-shorthand" 259 type="submit" 260 value="Update Shorthand Story" 261 formaction="?shand_update" 262 /> 263 264 <script> 265 jQuery('#post').submit(function() { 266 jQuery('#shorthand_update').prop('disabled', true); 267 }); 268 </script> 269 270 </div> 271 272 273 274 258 275 <?php 259 276 } … … 264 281 global $post; 265 282 global $noabstract; 266 $sh_debug_test = filter_var(get_option('sh_debug_test'), FILTER_VALIDATE_BOOLEAN);267 283 $selected_story = get_post_meta($post->ID, 'story_id', true); 268 284 if ($selected_story) { 269 add_meta_box('shand_wpt_shorthand_story', 'Update Shorthand Story', 'shand_wpt_shorthand_story', 'shorthand_story', 'normal', 'default'); 285 add_meta_box( 286 'shand_wpt_shorthand_story_update', 287 'Update Shorthand Story', 288 'shand_wpt_shorthand_story', 289 'shorthand_story', 290 'side', 291 'high' 292 ); 270 293 } else { 271 add_meta_box('shand_wpt_shorthand_story', 'Select Shorthand Story', 'shand_wpt_shorthand_story', 'shorthand_story', 'normal', 'default'); 272 } 273 if($sh_debug_test && $selected_story){ 274 add_meta_box('shand_wpt_shorthand_media_fetch', 'DEBUG: Manual Media Fetch (Simulate Cron Task)', 'shand_wpt_shorthand_media_fetch', 'shorthand_story', 'normal', 'default'); 294 add_meta_box( 295 'shand_wpt_shorthand_story', 296 'Select Shorthand Story', 297 'shand_wpt_shorthand_story', 298 'shorthand_story', 'normal', 299 'default' 300 ); 275 301 } 276 302 if (!$noabstract) { 277 add_meta_box('shand_wpt_shorthand_abstract', 'Add story abstract', 'shand_wpt_shorthand_abstract', 'shorthand_story', 'normal', 'default'); 303 add_meta_box( 304 'shand_wpt_shorthand_abstract', 305 'Add story abstract', 306 'shand_wpt_shorthand_abstract', 307 'shorthand_story', 308 'normal', 309 'default' 310 ); 278 311 } 279 312 add_meta_box('shand_wpt_shorthand_extra_html', 'Add additional HTML', 'shand_wpt_shorthand_extra_html', 'shorthand_story', 'normal', 'default'); … … 473 506 function shand_add_shorthand_story_columns($columns) 474 507 { 475 $cols = array_slice($columns, 0, 2, true) + array('story_id' => __('Shorthand Story ID')) + array('api_version' => __('API Version')) + array_slice($columns, 2, count($columns) - 2, true); 476 return $cols; 508 return array_slice($columns, 0, 2, true) + array('story_id' => __('Shorthand Story ID')) + array_slice($columns, 2, count($columns) - 2, true); 477 509 } 478 510 add_filter('manage_shorthand_story_posts_columns', 'shand_add_shorthand_story_columns'); … … 569 601 } 570 602 571 /* UI AND ACTIONS FOR TESTING DOWNLOADS */572 573 574 add_action('wp_ajax_shand_test_1a', 'shand_test_1a');575 add_action('wp_ajax_shand_test_1b', 'shand_test_1b');576 add_action('wp_ajax_shand_test_2a', 'shand_test_2a');577 add_action('wp_ajax_shand_test_2b', 'shand_test_2b');578 add_action('wp_ajax_shand_test_media_fetch', 'shand_test_media_fetch');579 580 function shand_test_media_fetch(){581 global $post;582 $story_id = $_REQUEST['story_id'];583 $post_id = $_REQUEST['post_id'];584 shand_save_media_fetch($post_id, $story_id);585 die();586 }587 588 /* Show testing buttons */589 function shand_wpt_shorthand_tests()590 {591 global $post;592 $selected_story = get_post_meta($post->ID, 'story_id', true);593 594 if ($selected_story) {595 $disabled=false;596 } else {597 $disabled=true;598 }599 ?>600 <button id="shand_test_1a" disabled="<?php echo $disabled; ?>" class="shand_test_action" data-storyid="<?php echo $selected_story; ?>">Test 1A - save to tmp</button>601 <button id="shand_test_1b" disabled="<?php echo $disabled; ?>" class="shand_test_action" data-storyid="<?php echo $selected_story; ?>">Test 1B - save to uploads</button>602 <button id="shand_test_2a" disabled="<?php echo $disabled; ?>" class="shand_test_action" data-storyid="<?php echo $selected_story; ?>">Test 2A - (copy from uploads and) extract from tmp</button>603 <button id="shand_test_2b" disabled="<?php echo $disabled; ?>" class="shand_test_action" data-storyid="<?php echo $selected_story; ?>">Test 2B - extract from uploads</button>604 <script type="text/javascript">605 jQuery( document ).ready( function($) {606 $( 'button.shand_test_action' ).on( 'click', function(e) {607 e.preventDefault();608 var action = jQuery(this).attr('id');609 var story_id = jQuery(this).attr('data-storyid');610 $.post(ajaxurl, {action, story_id}, function( data ) {611 console.log('Test: ' + action);612 console.log(data);613 } );614 } );615 } );616 </script>617 <?php618 }619 620 function shand_test_1a() {621 global $post;622 $story_id = $_REQUEST['story_id'];623 $err = sh_test_1a_fetch_story_to_tmp($post->ID ?? "unsaved", $story_id);624 if (isset($err["error"])) {625 wp_send_json_error($err, 500);626 } else {627 wp_send_json($err);628 }629 die();630 }631 632 function shand_test_1b() {633 global $post;634 $story_id = $_REQUEST['story_id'];635 $err = sh_test_1b_fetch_story_to_uploads($post->ID ?? "unsaved", $story_id);636 if (isset($err["error"])) {637 wp_send_json_error($err, 500);638 } else {639 wp_send_json($err);640 }641 die();642 }643 644 function shand_test_2a() {645 global $post;646 $story_id = $_REQUEST['story_id'];647 $err = sh_test_2a_extract_story_from_tmp($post->ID ?? "unsaved", $story_id);648 if (isset($err["error"])) {649 wp_send_json_error($err, 500);650 } else {651 wp_send_json($err);652 }653 die();654 }655 656 function shand_test_2b() {657 global $post;658 $story_id = $_REQUEST['story_id'];659 $err = sh_test_2b_extract_story_from_uploads($post->ID ?? "unsaved", $story_id);660 if (isset($err["error"])) {661 wp_send_json_error($err, 500);662 } else {663 wp_send_json($err);664 }665 die();666 }667 668 603 function shand_wpt_shorthand_abstract() 669 604 { -
shorthand-connect/trunk/README.txt
r2803964 r2817526 4 4 Tags: shorthand, api 5 5 Requires at least: 4.0 6 Tested up to: 6. 0.17 Stable tag: 1.3.2 56 Tested up to: 6.1 7 Stable tag: 1.3.26 8 8 Requires PHP: 5.6 9 9 License: GPLv2 or later … … 50 50 ~~~ 51 51 52 == Experimental Features == 53 54 1. Import media assets via cron - This feature allows your Wordpress installation to ingest Shorthand Story assets via a delayed CRON. This feature was introduced for users with VIP Hosted sites and those who have hard timeout limits set. 55 52 56 53 57 == Updating == … … 59 63 60 64 == Changelog == 65 66 = 1.3.26 = 67 * Restyled and repositioned "Update Shorthand Story" button for better clarity. 61 68 62 69 = 1.3.25 = -
shorthand-connect/trunk/includes/api-v2.php
r2796659 r2817526 176 176 return $story; 177 177 } 178 179 180 // DEBUG181 182 function sh_test_1a_fetch_story_to_tmp($post_id, $story_id) {183 184 wp_raise_memory_limit('admin');185 init_WP_Filesystem();186 187 $destination = wp_upload_dir();188 $tmpdir = get_temp_dir();189 $destination_path = $destination['path'].'/shorthand/'.$post_id;190 191 //Attempt to connect to the server192 $zip_file = wp_tempnam('sh_zip',$tmpdir);193 $response = sh_v2_api_get('/v2/stories/'.$story_id, array(194 'timeout' => '600',195 'stream' => true,196 'filename' => $zip_file197 ));198 if (is_wp_error($response)) {199 $story['error'] = array(200 'pretty' => ' Request to Shorthand failed',201 'error' => $response->get_error_message($response)202 );203 } else if (!$response || $response['response']['code'] != 200) {204 $story['error'] = array(205 'pretty' => 'Request to Shorthand failed; check the token is configured correctly',206 'response' => $response207 );208 }209 210 return $story;211 }212 213 function sh_test_1b_fetch_story_to_uploads($post_id, $story_id) {214 215 wp_raise_memory_limit('admin');216 init_WP_Filesystem();217 218 $destination = wp_upload_dir();219 $tmpdir = $destination['path'].'/zips/'.$post_id;220 $destination_path = $destination['path'].'/shorthand/'.$post_id;221 222 //Attempt to connect to the server223 wp_mkdir_p($tmpdir);224 $zip_file = $tmpdir . '/' . $story_id . '.zip';225 $response = sh_v2_api_get('/v2/stories/'.$story_id, array(226 'timeout' => '600',227 'stream' => true,228 'filename' => $zip_file229 ));230 if (is_wp_error($response)) {231 $story['error'] = array(232 'pretty' => ' Request to Shorthand failed',233 'error' => $response->get_error_message($response)234 );235 } else if (!$response || $response['response']['code'] != 200) {236 $story['error'] = array(237 'pretty' => 'Request to Shorthand failed; check the token is configured correctly',238 'response' => $response239 );240 }241 242 return $story;243 }244 245 function sh_test_2a_extract_story_from_tmp($post_id, $story_id) {246 247 wp_raise_memory_limit('admin');248 init_WP_Filesystem();249 250 $destination = wp_upload_dir();251 $tmpdir = get_temp_dir();252 $uploads_zip_file = $destination['path'].'/zips/'.$post_id . '/' . $story_id . '.zip';253 $destination_path = $destination['path'].'/shorthand/'.$post_id;254 255 $zip_file = $tmpdir . $post_id . '_' . $story_id . '.zip';256 if (!copy($uploads_zip_file, $zip_file)) {257 $story['error'] = array(258 'pretty' => 'Copying file from uploads to tmp failed',259 'source' => $uploads_zip_file,260 'dest' => $zip_file261 );262 } else {263 $story = extractStoryContent($zip_file, $destination_path, $story_id);264 }265 266 return $story;267 }268 269 function sh_test_2b_extract_story_from_uploads($post_id, $story_id) {270 271 wp_raise_memory_limit('admin');272 init_WP_Filesystem();273 274 $destination = wp_upload_dir();275 $tmpdir = $destination['path'].'/zips/'.$post_id;276 $destination_path = $destination['path'].'/shorthand/'.$post_id;277 278 //Attempt to connect to the server279 $zip_file = $tmpdir . '/' . $story_id . '.zip';280 $story = extractStoryContent($zip_file, $destination_path, $story_id);281 282 return $story;283 } -
shorthand-connect/trunk/includes/shorthand_options.php
r2794163 r2817526 80 80 if( isset($_POST['sh_submit_hidden_experimental']) && $_POST['sh_submit_hidden_experimental'] == 'Y' && check_admin_referer( 'sh-update-configuration' ) ) { 81 81 update_option('sh_media_cron_offload', $_POST['sh_media_cron_offload']); 82 update_option('sh_debug_test', $_POST['sh_debug_test']);83 82 } 84 83 $sh_media_cron_offload = filter_var(get_option('sh_media_cron_offload'), FILTER_VALIDATE_BOOLEAN); 85 $sh_debug_test = filter_var(get_option('sh_debug_test'), FILTER_VALIDATE_BOOLEAN);86 84 87 85 $profile = sh_get_profile(); … … 230 228 <p>It is advised that Shorthand Story Posts are saved as a draft first to trigger the cron job prior to public publishing.</p> 231 229 <br/> 232 <input type="checkbox" id="sh_debug_test" name="sh_debug_test" value="true" <?php echo esc_attr($sh_debug_test ? 'checked' : '') ?> />233 <label for="sh_debug_test">Show/Hide extra debug tests on Shorthand Story form.</label>234 230 <p class="submit"> 235 231 <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" /> -
shorthand-connect/trunk/shorthand_connect.php
r2803964 r2817526 3 3 /** 4 4 * @package Shorthand Connect 5 * @version 1.3.2 55 * @version 1.3.26 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 512 Version: 1.3.26 13 13 Author URI: http://shorthand.com 14 14 */ … … 67 67 add_action('init', 'shand_create_post_type'); 68 68 69 function shand_wpt_shorthand_media_fetch(){ 69 function shand_wpt_shorthand_story() 70 { 71 70 72 global $post; 71 73 … … 74 76 global $showArchivedStories; 75 77 76 $story_id = get_post_meta($post->ID, 'story_id', true);77 78 ?>79 <button id="shand_test_media_fetch" class="shand_test_media_fetch" data-postid="<?php echo $post->ID; ?>" data-storyid="<?php echo $story_id; ?>">Execute Media Fetch Function</button>80 <script>81 jQuery( document ).ready( function($) {82 $( 'button.shand_test_media_fetch' ).on( 'click', function(e) {83 e.preventDefault();84 var action = jQuery(this).attr('id');85 var story_id = jQuery(this).attr('data-storyid');86 var post_id = jQuery(this).attr('data-postid');87 $.post(ajaxurl, {action, story_id, post_id}, function( data ) {88 console.log('Test: ' + action);89 console.log(data);90 } );91 } );92 } );93 </script>94 <?php95 }96 97 98 function shand_wpt_shorthand_story()99 {100 101 global $post;102 103 global $serverURL;104 global $serverv2URL;105 global $showArchivedStories;106 107 78 $baseurl = ''; 108 79 109 80 $version = 'v2'; 110 111 $sh_debug_test = filter_var(get_option('sh_debug_test'), FILTER_VALIDATE_BOOLEAN);112 113 114 81 115 82 ?> … … 156 123 } 157 124 125 div.publishing-actions{ 126 padding: 10px; 127 clear: both; 128 border-top: 1px solid #dcdcde; 129 background: #f6f7f7; 130 margin: -12px; 131 margin-top: -12px; 132 margin-top: 10px; 133 display: flex; 134 justify-content: center; 135 } 136 137 .button-shorthand{ 138 background-color: #000; 139 border: 1px solid #000; 140 transition: background-color .15s ease,color .15s ease; 141 color: #fff; 142 font-family: poppins,sans-serif; 143 font-size: 13px; 144 font-weight: 600; 145 letter-spacing: 0; 146 line-height: 1; 147 padding: 1em 2em; 148 text-decoration: none; 149 cursor:pointer; 150 border-radius: .9em; 151 } 152 153 .button-shorthand:hover{ 154 background-color: #fff; 155 border-color: #000; 156 color: #000; 157 } 158 159 .button-shorthand:disabled{ 160 pointer-events:none; 161 } 162 158 163 #codearea { 159 164 border: 1px solid #999999; … … 187 192 188 193 $selected_story = get_post_meta($post->ID, 'story_id', true); 189 $story_api_version = get_post_meta($post->ID, 'api_version', true);190 194 if ($selected_story) { 191 195 shand_wpt_update_story($selected_story); … … 227 231 <script> 228 232 jQuery('li.story input:radio').click(function() { 229 230 <?php if($sh_debug_test){ ?>231 //DEBUG MODE232 jQuery('button.shand_test_action').attr('data-storyid', jQuery(this).val()); // inform test buttons of selection233 jQuery('button.shand_test_action').prop('disabled', false); // enable test buttons234 <?php } ?>235 233 jQuery('li.story').removeClass('selected'); 236 234 jQuery(this).parent().parent().addClass('selected'); … … 243 241 </script> 244 242 <?php 245 if($sh_debug_test){246 shand_wpt_shorthand_tests();247 }248 243 } 249 244 … … 254 249 <p>This will update Wordpress with the latest version of the story from Shorthand.</p> 255 250 <?php wp_nonce_field('shand_update_story', 'shand_update_story_nonce'); ?> 256 <input name="story_id" type="hidden" value="<?php esc_attr_e($storyId); ?>"/> 257 <input name="save" type="submit" value="Update Story" formaction="?shand_update"/> 251 252 253 <div class="publishing-actions"> 254 <input name="story_id" type="hidden" value="<?php esc_attr_e($storyId); ?>"/> 255 <input 256 id="shorthand_update" 257 name="save" 258 class="button-shorthand" 259 type="submit" 260 value="Update Shorthand Story" 261 formaction="?shand_update" 262 /> 263 264 <script> 265 jQuery('#post').submit(function() { 266 jQuery('#shorthand_update').prop('disabled', true); 267 }); 268 </script> 269 270 </div> 271 272 273 274 258 275 <?php 259 276 } … … 264 281 global $post; 265 282 global $noabstract; 266 $sh_debug_test = filter_var(get_option('sh_debug_test'), FILTER_VALIDATE_BOOLEAN);267 283 $selected_story = get_post_meta($post->ID, 'story_id', true); 268 284 if ($selected_story) { 269 add_meta_box('shand_wpt_shorthand_story', 'Update Shorthand Story', 'shand_wpt_shorthand_story', 'shorthand_story', 'normal', 'default'); 285 add_meta_box( 286 'shand_wpt_shorthand_story_update', 287 'Update Shorthand Story', 288 'shand_wpt_shorthand_story', 289 'shorthand_story', 290 'side', 291 'high' 292 ); 270 293 } else { 271 add_meta_box('shand_wpt_shorthand_story', 'Select Shorthand Story', 'shand_wpt_shorthand_story', 'shorthand_story', 'normal', 'default'); 272 } 273 if($sh_debug_test && $selected_story){ 274 add_meta_box('shand_wpt_shorthand_media_fetch', 'DEBUG: Manual Media Fetch (Simulate Cron Task)', 'shand_wpt_shorthand_media_fetch', 'shorthand_story', 'normal', 'default'); 294 add_meta_box( 295 'shand_wpt_shorthand_story', 296 'Select Shorthand Story', 297 'shand_wpt_shorthand_story', 298 'shorthand_story', 'normal', 299 'default' 300 ); 275 301 } 276 302 if (!$noabstract) { 277 add_meta_box('shand_wpt_shorthand_abstract', 'Add story abstract', 'shand_wpt_shorthand_abstract', 'shorthand_story', 'normal', 'default'); 303 add_meta_box( 304 'shand_wpt_shorthand_abstract', 305 'Add story abstract', 306 'shand_wpt_shorthand_abstract', 307 'shorthand_story', 308 'normal', 309 'default' 310 ); 278 311 } 279 312 add_meta_box('shand_wpt_shorthand_extra_html', 'Add additional HTML', 'shand_wpt_shorthand_extra_html', 'shorthand_story', 'normal', 'default'); … … 473 506 function shand_add_shorthand_story_columns($columns) 474 507 { 475 $cols = array_slice($columns, 0, 2, true) + array('story_id' => __('Shorthand Story ID')) + array('api_version' => __('API Version')) + array_slice($columns, 2, count($columns) - 2, true); 476 return $cols; 508 return array_slice($columns, 0, 2, true) + array('story_id' => __('Shorthand Story ID')) + array_slice($columns, 2, count($columns) - 2, true); 477 509 } 478 510 add_filter('manage_shorthand_story_posts_columns', 'shand_add_shorthand_story_columns'); … … 569 601 } 570 602 571 /* UI AND ACTIONS FOR TESTING DOWNLOADS */572 573 574 add_action('wp_ajax_shand_test_1a', 'shand_test_1a');575 add_action('wp_ajax_shand_test_1b', 'shand_test_1b');576 add_action('wp_ajax_shand_test_2a', 'shand_test_2a');577 add_action('wp_ajax_shand_test_2b', 'shand_test_2b');578 add_action('wp_ajax_shand_test_media_fetch', 'shand_test_media_fetch');579 580 function shand_test_media_fetch(){581 global $post;582 $story_id = $_REQUEST['story_id'];583 $post_id = $_REQUEST['post_id'];584 shand_save_media_fetch($post_id, $story_id);585 die();586 }587 588 /* Show testing buttons */589 function shand_wpt_shorthand_tests()590 {591 global $post;592 $selected_story = get_post_meta($post->ID, 'story_id', true);593 594 if ($selected_story) {595 $disabled=false;596 } else {597 $disabled=true;598 }599 ?>600 <button id="shand_test_1a" disabled="<?php echo $disabled; ?>" class="shand_test_action" data-storyid="<?php echo $selected_story; ?>">Test 1A - save to tmp</button>601 <button id="shand_test_1b" disabled="<?php echo $disabled; ?>" class="shand_test_action" data-storyid="<?php echo $selected_story; ?>">Test 1B - save to uploads</button>602 <button id="shand_test_2a" disabled="<?php echo $disabled; ?>" class="shand_test_action" data-storyid="<?php echo $selected_story; ?>">Test 2A - (copy from uploads and) extract from tmp</button>603 <button id="shand_test_2b" disabled="<?php echo $disabled; ?>" class="shand_test_action" data-storyid="<?php echo $selected_story; ?>">Test 2B - extract from uploads</button>604 <script type="text/javascript">605 jQuery( document ).ready( function($) {606 $( 'button.shand_test_action' ).on( 'click', function(e) {607 e.preventDefault();608 var action = jQuery(this).attr('id');609 var story_id = jQuery(this).attr('data-storyid');610 $.post(ajaxurl, {action, story_id}, function( data ) {611 console.log('Test: ' + action);612 console.log(data);613 } );614 } );615 } );616 </script>617 <?php618 }619 620 function shand_test_1a() {621 global $post;622 $story_id = $_REQUEST['story_id'];623 $err = sh_test_1a_fetch_story_to_tmp($post->ID ?? "unsaved", $story_id);624 if (isset($err["error"])) {625 wp_send_json_error($err, 500);626 } else {627 wp_send_json($err);628 }629 die();630 }631 632 function shand_test_1b() {633 global $post;634 $story_id = $_REQUEST['story_id'];635 $err = sh_test_1b_fetch_story_to_uploads($post->ID ?? "unsaved", $story_id);636 if (isset($err["error"])) {637 wp_send_json_error($err, 500);638 } else {639 wp_send_json($err);640 }641 die();642 }643 644 function shand_test_2a() {645 global $post;646 $story_id = $_REQUEST['story_id'];647 $err = sh_test_2a_extract_story_from_tmp($post->ID ?? "unsaved", $story_id);648 if (isset($err["error"])) {649 wp_send_json_error($err, 500);650 } else {651 wp_send_json($err);652 }653 die();654 }655 656 function shand_test_2b() {657 global $post;658 $story_id = $_REQUEST['story_id'];659 $err = sh_test_2b_extract_story_from_uploads($post->ID ?? "unsaved", $story_id);660 if (isset($err["error"])) {661 wp_send_json_error($err, 500);662 } else {663 wp_send_json($err);664 }665 die();666 }667 668 603 function shand_wpt_shorthand_abstract() 669 604 {
Note: See TracChangeset
for help on using the changeset viewer.