Plugin Directory

Changeset 2817526


Ignore:
Timestamp:
11/14/2022 09:37:13 AM (3 years ago)
Author:
shorthandconnect
Message:

Created tag 1.3.26

Location:
shorthand-connect
Files:
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • shorthand-connect/tags/1.3.26/README.txt

    r2803964 r2817526  
    44Tags: shorthand, api
    55Requires at least: 4.0
    6 Tested up to: 6.0.1
    7 Stable tag: 1.3.25
     6Tested up to: 6.1
     7Stable tag: 1.3.26
    88Requires PHP: 5.6
    99License: GPLv2 or later
     
    5050~~~
    5151
     52== Experimental Features ==
     53
     541. 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
    5256
    5357== Updating ==
     
    5963
    6064== Changelog ==
     65
     66= 1.3.26 =
     67* Restyled and repositioned "Update Shorthand Story" button for better clarity.
    6168
    6269= 1.3.25 =
  • shorthand-connect/tags/1.3.26/includes/api-v2.php

    r2796659 r2817526  
    176176    return $story;
    177177}
    178 
    179 
    180 // DEBUG
    181 
    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 server
    192     $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_file
    197     ));
    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' => $response
    207         );
    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 server
    223     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_file
    229     ));
    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' => $response
    239         );
    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_file
    261         );
    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 server
    279     $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  
    8080    if( isset($_POST['sh_submit_hidden_experimental']) && $_POST['sh_submit_hidden_experimental'] == 'Y' && check_admin_referer( 'sh-update-configuration' ) ) {
    8181        update_option('sh_media_cron_offload', $_POST['sh_media_cron_offload']);
    82         update_option('sh_debug_test', $_POST['sh_debug_test']);
    8382    }
    8483    $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);
    8684
    8785    $profile = sh_get_profile();
     
    230228            <p>It is advised that Shorthand Story Posts are saved as a draft first to trigger the cron job prior to public publishing.</p>
    231229            <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>
    234230            <p class="submit">
    235231                <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  
    33/**
    44 * @package Shorthand Connect
    5  * @version 1.3.25
     5 * @version 1.3.26
    66 */
    77/*
     
    1010Description: Import your Shorthand stories into your Wordpress CMS as simply as possible - magic!
    1111Author: Shorthand
    12 Version: 1.3.25
     12Version: 1.3.26
    1313Author URI: http://shorthand.com
    1414*/
     
    6767add_action('init', 'shand_create_post_type');
    6868
    69 function shand_wpt_shorthand_media_fetch(){
     69function shand_wpt_shorthand_story()
     70{
     71
    7072    global $post;
    7173
     
    7476    global $showArchivedStories;
    7577
    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     <?php
    95 }
    96 
    97 
    98 function shand_wpt_shorthand_story()
    99 {
    100 
    101     global $post;
    102 
    103     global $serverURL;
    104     global $serverv2URL;
    105     global $showArchivedStories;
    106 
    10778    $baseurl = '';
    10879
    10980    $version = 'v2';
    110 
    111     $sh_debug_test = filter_var(get_option('sh_debug_test'), FILTER_VALIDATE_BOOLEAN);
    112    
    113 
    11481
    11582?>
     
    156123        }
    157124
     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
    158163        #codearea {
    159164            border: 1px solid #999999;
     
    187192
    188193    $selected_story = get_post_meta($post->ID, 'story_id', true);
    189     $story_api_version = get_post_meta($post->ID, 'api_version', true);
    190194    if ($selected_story) {
    191195        shand_wpt_update_story($selected_story);
     
    227231    <script>
    228232        jQuery('li.story input:radio').click(function() {
    229 
    230             <?php if($sh_debug_test){ ?>
    231             //DEBUG MODE
    232             jQuery('button.shand_test_action').attr('data-storyid', jQuery(this).val()); // inform test buttons of selection
    233             jQuery('button.shand_test_action').prop('disabled', false); // enable test buttons
    234             <?php } ?>
    235233            jQuery('li.story').removeClass('selected');
    236234            jQuery(this).parent().parent().addClass('selected');
     
    243241    </script>
    244242<?php
    245     if($sh_debug_test){
    246         shand_wpt_shorthand_tests();
    247     }
    248243}
    249244
     
    254249    <p>This will update Wordpress with the latest version of the story from Shorthand.</p>
    255250    <?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   
    258275<?php
    259276}
     
    264281    global $post;
    265282    global $noabstract;
    266     $sh_debug_test = filter_var(get_option('sh_debug_test'), FILTER_VALIDATE_BOOLEAN);
    267283    $selected_story = get_post_meta($post->ID, 'story_id', true);
    268284    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        );
    270293    } 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        );
    275301    }
    276302    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        );
    278311    }
    279312    add_meta_box('shand_wpt_shorthand_extra_html', 'Add additional HTML', 'shand_wpt_shorthand_extra_html', 'shorthand_story', 'normal', 'default');
     
    473506function shand_add_shorthand_story_columns($columns)
    474507{
    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);
    477509}
    478510add_filter('manage_shorthand_story_posts_columns', 'shand_add_shorthand_story_columns');
     
    569601}
    570602
    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 <?php
    618 }
    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 
    668603function shand_wpt_shorthand_abstract()
    669604{
  • shorthand-connect/trunk/README.txt

    r2803964 r2817526  
    44Tags: shorthand, api
    55Requires at least: 4.0
    6 Tested up to: 6.0.1
    7 Stable tag: 1.3.25
     6Tested up to: 6.1
     7Stable tag: 1.3.26
    88Requires PHP: 5.6
    99License: GPLv2 or later
     
    5050~~~
    5151
     52== Experimental Features ==
     53
     541. 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
    5256
    5357== Updating ==
     
    5963
    6064== Changelog ==
     65
     66= 1.3.26 =
     67* Restyled and repositioned "Update Shorthand Story" button for better clarity.
    6168
    6269= 1.3.25 =
  • shorthand-connect/trunk/includes/api-v2.php

    r2796659 r2817526  
    176176    return $story;
    177177}
    178 
    179 
    180 // DEBUG
    181 
    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 server
    192     $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_file
    197     ));
    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' => $response
    207         );
    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 server
    223     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_file
    229     ));
    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' => $response
    239         );
    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_file
    261         );
    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 server
    279     $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  
    8080    if( isset($_POST['sh_submit_hidden_experimental']) && $_POST['sh_submit_hidden_experimental'] == 'Y' && check_admin_referer( 'sh-update-configuration' ) ) {
    8181        update_option('sh_media_cron_offload', $_POST['sh_media_cron_offload']);
    82         update_option('sh_debug_test', $_POST['sh_debug_test']);
    8382    }
    8483    $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);
    8684
    8785    $profile = sh_get_profile();
     
    230228            <p>It is advised that Shorthand Story Posts are saved as a draft first to trigger the cron job prior to public publishing.</p>
    231229            <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>
    234230            <p class="submit">
    235231                <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" />
  • shorthand-connect/trunk/shorthand_connect.php

    r2803964 r2817526  
    33/**
    44 * @package Shorthand Connect
    5  * @version 1.3.25
     5 * @version 1.3.26
    66 */
    77/*
     
    1010Description: Import your Shorthand stories into your Wordpress CMS as simply as possible - magic!
    1111Author: Shorthand
    12 Version: 1.3.25
     12Version: 1.3.26
    1313Author URI: http://shorthand.com
    1414*/
     
    6767add_action('init', 'shand_create_post_type');
    6868
    69 function shand_wpt_shorthand_media_fetch(){
     69function shand_wpt_shorthand_story()
     70{
     71
    7072    global $post;
    7173
     
    7476    global $showArchivedStories;
    7577
    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     <?php
    95 }
    96 
    97 
    98 function shand_wpt_shorthand_story()
    99 {
    100 
    101     global $post;
    102 
    103     global $serverURL;
    104     global $serverv2URL;
    105     global $showArchivedStories;
    106 
    10778    $baseurl = '';
    10879
    10980    $version = 'v2';
    110 
    111     $sh_debug_test = filter_var(get_option('sh_debug_test'), FILTER_VALIDATE_BOOLEAN);
    112    
    113 
    11481
    11582?>
     
    156123        }
    157124
     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
    158163        #codearea {
    159164            border: 1px solid #999999;
     
    187192
    188193    $selected_story = get_post_meta($post->ID, 'story_id', true);
    189     $story_api_version = get_post_meta($post->ID, 'api_version', true);
    190194    if ($selected_story) {
    191195        shand_wpt_update_story($selected_story);
     
    227231    <script>
    228232        jQuery('li.story input:radio').click(function() {
    229 
    230             <?php if($sh_debug_test){ ?>
    231             //DEBUG MODE
    232             jQuery('button.shand_test_action').attr('data-storyid', jQuery(this).val()); // inform test buttons of selection
    233             jQuery('button.shand_test_action').prop('disabled', false); // enable test buttons
    234             <?php } ?>
    235233            jQuery('li.story').removeClass('selected');
    236234            jQuery(this).parent().parent().addClass('selected');
     
    243241    </script>
    244242<?php
    245     if($sh_debug_test){
    246         shand_wpt_shorthand_tests();
    247     }
    248243}
    249244
     
    254249    <p>This will update Wordpress with the latest version of the story from Shorthand.</p>
    255250    <?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   
    258275<?php
    259276}
     
    264281    global $post;
    265282    global $noabstract;
    266     $sh_debug_test = filter_var(get_option('sh_debug_test'), FILTER_VALIDATE_BOOLEAN);
    267283    $selected_story = get_post_meta($post->ID, 'story_id', true);
    268284    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        );
    270293    } 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        );
    275301    }
    276302    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        );
    278311    }
    279312    add_meta_box('shand_wpt_shorthand_extra_html', 'Add additional HTML', 'shand_wpt_shorthand_extra_html', 'shorthand_story', 'normal', 'default');
     
    473506function shand_add_shorthand_story_columns($columns)
    474507{
    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);
    477509}
    478510add_filter('manage_shorthand_story_posts_columns', 'shand_add_shorthand_story_columns');
     
    569601}
    570602
    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 <?php
    618 }
    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 
    668603function shand_wpt_shorthand_abstract()
    669604{
Note: See TracChangeset for help on using the changeset viewer.