Plugin Directory

Changeset 2898299


Ignore:
Timestamp:
04/13/2023 08:02:08 AM (3 years ago)
Author:
shorthandconnect
Message:

Created tag 1.3.28

Location:
shorthand-connect
Files:
14 edited
1 copied

Legend:

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

    r2860602 r2898299  
    55Requires at least: 4.0
    66Tested up to: 6.1
    7 Stable tag: 1.3.27
     7Stable tag: 1.3.28
    88Requires PHP: 5.6
    99License: GPLv2 or later
     
    6464== Changelog ==
    6565
     66= 1.3.28 =
     67* Code clean up & bug fixes
     68* Remove legacy API code
     69* Introduce a 'Disable Advanced Custom Fields' option under Experimental Features
     70
    6671= 1.3.27 =
    6772* Added Mass Publishing Feature
  • shorthand-connect/tags/1.3.28/config.default.php

    r2803964 r2898299  
    22
    33global $serverURL;
    4 global $serverv2URL;
    5 global $allowversionswitch;
    6 global $showServerURL;
    74global $showArchivedStories;
    85global $noabstract;
    96
    107$serverURL = 'https://api.shorthand.com';
    11 $serverv2URL = 'https://api.shorthand.com';
    12 $allowversionswitch = true;
    13 $showServerURL = false;
    148$showArchivedStories = false;
    159
    16 if ( defined( 'SHORTHAND_NOABSTRACT' ) ){
     10if (defined('SHORTHAND_NOABSTRACT')) {
    1711    $noabstract = SHORTHAND_NOABSTRACT;
    1812} else {
  • shorthand-connect/tags/1.3.28/includes/api.php

    r2762662 r2898299  
    11<?php
    2 
    3 // VERSION 1 API
    4 
    5 function sh_get_profile() {
    6 
     2function sh_v2_api_get($url, $options)
     3{
     4    $token = get_option('sh_v2_token');
     5    if (!$token) {
     6        return false;
     7    }
    78    global $serverURL;
    8     $token = get_option('sh_token_key');
    9     $user_id = get_option('sh_user_id');
    10 
    11     $valid_token = false;
    12 
    13     $data = array();
    14 
    15     //Attempt to connect to the server
    16     if($token && $user_id) {
    17         $url = $serverURL.'/api/profile/';
    18         $vars = 'user='.$user_id.'&token='.$token;
    19         $response = wp_remote_post( $url, array(
     9    $url = $serverURL . $url;
     10    $plugin_path = plugin_dir_path( dirname( __FILE__ ) ) . '/shorthand_connect.php';
     11    $plugin_data = get_file_data( $plugin_path, array( 'Version' => 'Version' ) );
     12    $plugin_version = $plugin_data['Version'];
     13   
     14    $wp_version = $GLOBALS['wp_version'];
     15    $user_agent = 'WordPress/' . $wp_version . ' Shorthand/' . $plugin_version;
     16   
     17    $request_options = array_merge(
     18        array(
    2019            'headers' => array(
    21                 'user-agent'  =>  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8) AppleWebKit/535.6.2 (KHTML, like Gecko) Version/5.2 Safari/535.6.2',
     20                'Authorization' => 'Token ' . $token,
     21                'user-agent'  => $user_agent,
    2222            ),
    23             'body'    => array(
    24                 'user' => $user_id,
    25                 'token' => $token
    26             ),
    27         ));
    28         $body = wp_remote_retrieve_body( $response );
    29         $data = json_decode($body);
     23            'http_api_args' => $options
     24        ),
     25        $options
     26    );
     27   
     28    if (function_exists("vip_safe_wp_remote_get") && !isset($options['timeout'])){
     29        return vip_safe_wp_remote_get($url,false,1,3,10, $request_options);
     30    } else {
     31        return wp_remote_get($url, $request_options);
    3032    }
    31     return $data;
     33   
    3234}
    3335
    34 function sh_get_stories() {
    35     global $serverURL;
    36     $token = get_option('sh_token_key');
    37     $user_id = get_option('sh_user_id');
     36function sh_v2_api_get_json($url, $options)
     37{
     38    $response = sh_v2_api_get($url, $options);
     39    $body = wp_remote_retrieve_body($response);
     40    return json_decode($body);
     41}
    3842
    39     $valid_token = false;
     43function sh_get_profile()
     44{
     45    $tokeninfo = array();
     46   
     47    $data = sh_v2_api_get_json('/v2/token-info', array());
     48    if ($data && isset($data->organisation_id)) {
     49        $tokeninfo['username'] = $data->name . ' ('.$data->token_type.' Token)';
     50        $tokeninfo['gravatar'] = $data->logo;
     51        $tokeninfo = (object)$tokeninfo;
     52    }
     53   
     54    return $tokeninfo;
     55}
    4056
     57function sh_get_stories()
     58{
    4159    $stories = null;
    42 
    43     //Attempt to connect to the server
    44     if($token && $user_id) {
    45         $url = $serverURL.'/api/index/';
    46         $response = wp_remote_post( $url, array(
    47             'headers' => array(
    48                 'user-agent'  =>  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8) AppleWebKit/535.6.2 (KHTML, like Gecko) Version/5.2 Safari/535.6.2',
    49             ),
    50             'body'    => array(
    51                 'user' => $user_id,
    52                 'token' => $token
    53             ),
    54             'timeout' => '240'
    55         ));
    56         $body = wp_remote_retrieve_body( $response );
    57         $data = json_decode($body);
    58 
    59         if(isset($data->stories)) {
    60             $valid_token = true;
    61             $stories = $data->stories;
     60   
     61    $data = sh_v2_api_get_json('/v2/stories', array('timeout' => '240'));
     62    if ($data) {
     63        $stories = array();
     64        //Something went wrong
     65        if (isset($data->status) && $data->status) {
     66            return null;
     67        }
     68        foreach ($data as $storydata) {
     69            $story = array(
     70                'image' => $storydata->signedCover,
     71                'id' => $storydata->id,
     72                'metadata' => (object)array(
     73                    'description' => $storydata->description
     74                ),
     75                'title' => $storydata->title,
     76                'story_version' => ''.$storydata->version
     77            );
     78            $stories[] = (object)$story;
    6279        }
    6380    }
     81   
    6482    return $stories;
    6583}
    6684
    67 function sh_get_story_path($post_id, $story_id) {
    68     WP_Filesystem();
     85function sh_get_story_path($post_id, $story_id)
     86{
     87    init_WP_Filesystem();
    6988    $destination = wp_upload_dir();
    7089    $destination_path = $destination['path'].'/shorthand/'.$post_id.'/'.$story_id;
    71     if(!file_exists($destination_path)) {
     90   
     91    if (!file_exists($destination_path)) {
    7292        $destination_path = null;
    7393    }
     94   
     95    $destination_path = apply_filters('sh_get_story_path', $destination_path, $destination);
     96   
    7497    return $destination_path;
    7598}
    7699
    77 function sh_get_story_url($post_id, $story_id) {
    78     WP_Filesystem();
     100function sh_get_story_url($post_id, $story_id)
     101{
     102    init_WP_Filesystem();
    79103    $destination = wp_upload_dir();
    80104    $destination_url = $destination['url'].'/shorthand/'.$post_id.'/'.$story_id;
     105    $destination_url = apply_filters('sh_get_story_url', $destination_url);
     106   
    81107    return $destination_url;
    82108}
    83109
    84 function sh_copy_story($post_id, $story_id) {
    85 
    86     // Set the maximum memory limit for the entire operation (this is already called later by unzip_file, but lets do it earlier)
    87     @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
    88 
    89     WP_Filesystem();
     110function sh_copy_story($post_id, $story_id, $without_assets=false, $assets_only=false)
     111{
     112   
     113    wp_raise_memory_limit('admin');
     114    init_WP_Filesystem();
    90115    $destination = wp_upload_dir();
    91116    $tmpdir = get_temp_dir();
    92     $destination_path = $destination['path'].'/shorthand/'.$post_id.'/'.$story_id;
     117    $destination_path = $destination['path'].'/shorthand/'.$post_id;
     118    $story = array();
     119   
     120    //Attempt to connect to the server
     121    $zip_file = wp_tempnam('sh_zip',$tmpdir);
     122    $response = sh_v2_api_get('/v2/stories/'.$story_id.($without_assets?'?without_assets=true':'').($assets_only?'?assets_only=true':''), array(
     123        'timeout' => '600',
     124        'stream' => true,
     125        'filename' => $zip_file
     126    ));
     127    if (is_wp_error($response)) {
     128        $story['error'] = array(
     129            'pretty' => ' Request to Shorthand failed',
     130            'error' => $response->get_error_message($response)
     131        );
     132    } elseif (!$response || $response['response']['code'] != 200) {
     133        $story['error'] = array(
     134            'pretty' => 'Request to Shorthand failed; check the token is configured correctly',
     135            'response' => $response
     136        );
     137    } else {
     138        $story = extractStoryContent($zip_file, $destination_path, $story_id);
     139    }
     140   
     141    do_action('sh_copy_story', $post_id, $story_id, $story);
     142    unlink($zip_file);
     143   
     144    return $story;
     145}
    93146
    94     global $serverURL;
    95     $token = get_option('sh_token_key');
    96     $user_id = get_option('sh_user_id');
    97147
    98     $valid_token = false;
     148function init_WP_Filesystem()
     149{
     150    WP_Filesystem();
     151    global $wp_filesystem;
     152    if (!is_a($wp_filesystem, 'WP_Filesystem_Base')) {
     153        $creds = request_filesystem_credentials(site_url());
     154        wp_filesystem($creds);
     155    }
     156}
    99157
    100     $story = array();
    101 
    102     //Attempt to connect to the server
    103     if($token && $user_id) {
    104         $url = $serverURL.'/api/story/'.$story_id.'/';
    105         $vars = 'user='.$user_id.'&token='.$token;
    106         $zipfile = wp_tempnam($tmpdir, 'sh_zip');
    107         $response = wp_remote_post( $url, array(
    108             'headers' => array(
    109                 'user-agent'  =>  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8) AppleWebKit/535.6.2 (KHTML, like Gecko) Version/5.2 Safari/535.6.2',
    110             ),
    111             'body'    => array(
    112                 'user' => $user_id,
    113                 'token' => $token
    114             ),
    115             'timeout' => '600',
    116             'stream' => true,
    117             'filename' => $zipfile
    118         ));
    119         $body = wp_remote_retrieve_body( $response );
    120         $data = json_decode($body);
    121         if($response['response']['code'] == 200) {
    122             $unzipfile = unzip_file( $zipfile, $destination_path);
    123             if ( $unzipfile ) {
    124                 $story['path'] = $destination_path;
    125             } else {
    126                 $story['error'] = array(
    127                 'pretty' => 'Could not unzip file'
     158function extractStoryContent($zip_file, $destination_path, $story_id)
     159{
     160    //WP VIP HOSTING COMPATIBILITY
     161    $zip = new ZipArchive;
     162    if ($zip->open($zip_file)) {
     163        wp_mkdir_p($destination_path.'/'.$story_id);
     164        $zip->extractTo($destination_path.'/'.$story_id);
     165        $zip->close();
     166        if (is_wp_error($zip)) {
     167            $story['error'] = array(
     168                'pretty' => 'Could not copy story into Wordpress',
     169                'error' => $zip->get_error_message(),
     170                'unzip error'=> $zip_file
    128171            );
     172            if (function_exists("wp_filesize")){
     173                $story['error']['downloaded zip size'] = wp_filesize($zip_file);
    129174            }
    130175        } else {
    131             $story['error'] = array(
    132                 'pretty' => 'Could not upload file',
    133                 'error' => curl_error($ch),
    134                 'response' => $response
    135             );
     176            $story['path'] = $destination_path.'/'.$story_id;
    136177        }
     178    } else {
     179        $story['error'] = array(
     180            'pretty' => 'Could not unzip file'
     181        );
    137182    }
     183   
    138184    return $story;
    139185}
  • shorthand-connect/tags/1.3.28/includes/mass_pull.php

    r2860602 r2898299  
    11<?php
    2 
    32/*
    43/* Name: Update Story Meta Fields Function */
     
    65/* Note: Unzipping a fresh story copy won't update the fields
    76*/
    8 function shand_update_story($post_id, $story_id) {
    9 
     7function shand_update_story($post_id, $story_id)
     8{
    109    init_WP_Filesystem();
    1110    global $wp_filesystem;
     
    2019   
    2120    $err = sh_copy_story($post_id, $safe_story_id, $sh_media_cron_offload);
    22 
    23     $sh_title = get_post_meta( $post_id, 'title', true );
    2421
    2522    $story_path = sh_get_story_path($post_id, $safe_story_id);
     
    3936        update_post_meta($post_id, 'story_path', $story_path);
    4037
    41         //Log any story-specific errors to the metadata 
     38        //Log any story-specific errors to the metadata
    4239        if(isset($err['error'])){
    4340            update_post_meta($post_id, 'ERROR', json_encode($err));
     
    5047
    5148        // Save the head and body
    52         $version = get_option('sh_api_version');
    53        
    54         update_post_meta($post_id, 'api_version', $version);
    55         $head_file = $story_path . '/head.html';
     49                $head_file = $story_path . '/head.html';
    5650        $article_file = $story_path . '/article.html';
    5751
     
    8781
    8882    } else {
    89 
    9083        update_post_meta($post_id, 'story_diagnostic', $err);
    91 
    9284        echo 'Something went wrong, please try again';
    9385        print_r($err);
     
    9688
    9789}
    98 ?>
  • shorthand-connect/tags/1.3.28/includes/shorthand_options.php

    r2817526 r2898299  
    11<?php
    2 
    32/* Options */
    43function shand_shorthand_menu() {
    54    add_options_page( 'Shorthand Options', 'Shorthand', 'manage_options', 'shorthand-options', 'shand_shorthand_options' );
    65}
    7 
    86$default_sh_site_css = '
    97/* START CSS FOR DEFAULT WP THEMES */
     
    2826';
    2927
    30 function shand_shorthand_options() {
    31 
     28function shand_shorthand_options()
     29{
    3230    global $default_sh_site_css;
    3331    global $serverURL;
    34     global $serverv2URL;
    35     global $allowversionswitch;
    36     global $showServerURL;
    3732
    3833    if ( !current_user_can( 'manage_options' ) )  {
     
    4237        update_option('sh_v2_token', sanitize_text_field($_POST['sh_v2_token']));
    4338    }
    44 
    4539    $v2_token = esc_html(get_option('sh_v2_token'));
    4640   
    47 
    4841    if( isset($_POST['sh_submit_hidden_two']) && $_POST['sh_submit_hidden_two'] == 'Y' && check_admin_referer( 'sh-update-configuration' ) ) {
    4942        update_option('sh_css', wp_kses_post($_POST['sh_css']));
     
    6053        $permalink_structure = esc_html(get_option('sh_permalink'));
    6154    }
    62 
    6355    $sh_css = get_option('sh_css');
    6456    $no_css = false;
    6557    if ($sh_css == '') {
    6658        $no_css = true;
    67         if(isset($default_site_css)){
     59        if (isset($default_site_css)){
    6860            update_option('sh_css', $default_site_css);
    6961        }
     
    7163    }
    7264
    73     if(isset($_POST['sh_submit_hidden_four']) && $_POST['sh_submit_hidden_four'] == 'Y' && check_admin_referer( 'sh-update-configuration' ) ) {
     65    if (isset($_POST['sh_submit_hidden_four']) && $_POST['sh_submit_hidden_four'] == 'Y' && check_admin_referer( 'sh-update-configuration' )) {
    7466        update_option('sh_regex_list', base64_encode(wp_unslash($_POST['sh_regex_list'])));
    7567    }
     
    7769    $sh_regex_list = base64_decode(get_option('sh_regex_list'));
    7870
    79     //Experimental Settings
    80     if( isset($_POST['sh_submit_hidden_experimental']) && $_POST['sh_submit_hidden_experimental'] == 'Y' && check_admin_referer( 'sh-update-configuration' ) ) {
    81         update_option('sh_media_cron_offload', $_POST['sh_media_cron_offload']);
    82     }
    83     $sh_media_cron_offload = filter_var(get_option('sh_media_cron_offload'), FILTER_VALIDATE_BOOLEAN);
    84 
     71    // Experimental Settings
     72    if (isset($_POST['sh_submit_hidden_experimental']) && $_POST['sh_submit_hidden_experimental'] == 'Y' && check_admin_referer('sh-update-configuration')) {
     73        $sh_media_cron_offload = isset($_POST['sh_media_cron_offload']) ? filter_var($_POST['sh_media_cron_offload'], FILTER_VALIDATE_BOOLEAN) : false;
     74        $sh_disable_acf = isset($_POST['sh_disable_acf']) ? filter_var($_POST['sh_disable_acf'], FILTER_VALIDATE_BOOLEAN) : false;
     75        update_option('sh_media_cron_offload', $sh_media_cron_offload);
     76        update_option('sh_disable_acf', $sh_disable_acf);
     77    }
     78  $sh_media_cron_offload = filter_var(get_option('sh_media_cron_offload'), FILTER_VALIDATE_BOOLEAN);
     79  $sh_disable_acf = filter_var(get_option('sh_disable_acf'), FILTER_VALIDATE_BOOLEAN);
     80 
    8581    $profile = sh_get_profile();
    8682    $n_once = wp_nonce_field( 'sh-update-configuration' );
     
    143139        <p><em>This Example removes title tags from within the head tag by replacing it with nothing.</em></p>
    144140<pre><code>
    145   { 
     141  {
    146142    "head":
    147143    [
    148       { 
     144      {
    149145        &quot;query&quot;:&quot;/&lt;title.(.*?)&lt;\/title&gt;/&quot;,
    150146        &quot;replace&quot;:&quot;&quot;
    151147      }
    152148    ],
    153     "body":[] 
     149    "body":[]
    154150  }
    155 
    156151</code></pre>
    157152        <form name="form2" method="post" onsubmit="padJson()">
     
    218213
    219214<h3>Experimental Features</h3>
    220         <p>Early access features that are still subject to change.</p>
    221        
    222         <form name="form_experimental" method="post">
    223             <?php echo $n_once ?>
    224             <input type="hidden" name="sh_submit_hidden_experimental" value="Y" />
    225             <input type="checkbox" id="sh_media_cron_offload" name="sh_media_cron_offload" value="true" <?php echo esc_attr($sh_media_cron_offload ? 'checked' : '') ?> />
    226             <label for="sh_media_cron_offload">Import media assets via cron</label>
    227             <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>
    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>
    229             <br/>
    230             <p class="submit">
    231                 <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" />
    232             </p>
    233         </form>
     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>
    234232<?php
    235233}
  • shorthand-connect/tags/1.3.28/shorthand_connect.php

    r2860602 r2898299  
    33/**
    44 * @package Shorthand Connect
    5  * @version 1.3.27
     5 * @version 1.3.28
    66 */
    77/*
     
    1010Description: Import your Shorthand stories into your Wordpress CMS as simply as possible - magic!
    1111Author: Shorthand
    12 Version: 1.3.27
     12Version: 1.3.28
    1313Author URI: http://shorthand.com
    1414*/
    1515
    16 $included = @include_once('config.php');
    17 if (!$included) {
     16if (file_exists('config.php')) {
     17    include_once('config.php');
     18} else {
    1819    require_once('config.default.php');
    1920}
    20 $version = 'v2';
    21 
    22 require_once('includes/api-v2.php');
     21require_once('includes/api.php');
    2322require_once('includes/mass_pull.php');
    2423
     
    7069function shand_wpt_shorthand_story()
    7170{
    72 
    7371    global $post;
    74 
    7572    global $serverURL;
    76     global $serverv2URL;
    7773    global $showArchivedStories;
    78 
    7974    $baseurl = '';
    80 
    81     $version = 'v2';
    8275
    8376?>
     
    198191    }
    199192    $stories = sh_get_stories();
    200 
    201     if (!is_array($stories)) {
    202         echo 'Could not connect to Shorthand, please check your <a href="options-general.php?page=shorthand-options">Wordpress Shorthand settings</a>.';
    203     } else if (sizeOf($stories) == 0) {
     193    $profile = sh_get_profile();
     194
     195    if (!($profile)) {
     196        echo 'Could not connect to Shorthand, please check your API token in <a href="options-general.php?page=shorthand-options">Shorthand settings</a>.';
     197    } elseif ($stories === null) {
    204198        echo 'You currently have no stories ready for publishing on Shorthand. Please check that your story is set to be ready for publishing.';
    205199    } else {
     
    213207            }
    214208            $archived = '';
    215             if ($version == 'v2' && isset($story->story_version) && $story->story_version == '1') {
     209            if (isset($story->story_version) && $story->story_version == '1') {
    216210                if ($showArchivedStories) {
    217211                    $archived = ' (archived)';
     
    279273function shand_add_shorthand_metaboxes()
    280274{
    281     global $version;
    282275    global $post;
    283276    global $noabstract;
     
    332325
    333326/* Save the shorthand story */
    334 function shand_save_shorthand_story($post_id, $post, $update)
     327function shand_save_shorthand_story($post_id, $post)
    335328{
    336329    WP_Filesystem();
    337 
    338330    global $wp_filesystem;
    339 
     331   
    340332    if ( ! is_a( $wp_filesystem, 'WP_Filesystem_Base') ) {
    341333        $creds = request_filesystem_credentials( site_url() );
     
    355347    }
    356348
    357     if(!get_post_meta($post_id, 'no_update')) {
     349    if (!get_post_meta($post_id, 'no_update')) {
    358350        update_post_meta($post_id, 'no_update', "false");
    359351    }
     
    378370           
    379371        }
    380         if($sh_media_cron_offload){
     372        if ($sh_media_cron_offload){
    381373            update_post_meta($post_id, 'media_status', '[Awaiting media fetch...]');
    382374            wp_schedule_single_event(time() + 30, 'sh_media_fetch', array( $post_id, $safe_story_id ));
     
    387379            update_post_meta($post_id, 'story_path', $story_path);
    388380
    389             //Log any story-specific errors to the metadata 
     381            //Log any story-specific errors to the metadata
    390382            if(isset($err['error'])){
    391383                update_post_meta($post_id, 'ERROR', json_encode($err));
     
    398390
    399391            // Save the head and body
    400             $version = get_option('sh_api_version');
    401             update_post_meta($post_id, 'api_version', $version);
    402392            $head_file = $story_path . '/head.html';
    403393            $article_file = $story_path . '/article.html';
     
    411401            $head = apply_filters('sh_pre_process_head', $head, $assets_path, $head_file);
    412402           
    413             if(isset($post_processing_queries->body)){
     403            if (isset($post_processing_queries->body)){
    414404                $body = shand_post_processing($body,$post_processing_queries->body);
    415405            }
    416406           
    417             if(isset($post_processing_queries->head)){
     407            if (isset($post_processing_queries->head)){
    418408                $head = shand_post_processing($head, $post_processing_queries->head);
    419409            }
     
    496486function shand_shorthand_get_posts($query)
    497487{
    498     if (is_home() && $query->is_main_query())
    499         $query->set('post_type', array('post', 'shorthand_story'));
    500 
     488    if (is_home() && $query->is_main_query()) {
     489        $query->set( 'post_type', array( 'post', 'shorthand_story' ) );
     490    }
    501491    return $query;
    502492}
     
    512502
    513503
    514 /* Table Hook */
    515 function shand_shorthand_show_columns($name)
    516 {
    517     global $post;
    518     switch ($name) {
    519         case 'story_id':
    520             $views = get_post_meta($post->ID, 'story_id', true);
    521             echo $views;
    522             break;
    523         case 'api_version':
    524             $views = get_post_meta($post->ID, 'api_version', true);
    525             if ($views == '') {
    526                 // Determine the version, save it if possible;
    527                 $views = 'Unknown';
    528                 $story_id = get_post_meta($post->ID, 'story_id', true);
    529                 if ($story_id) {
    530                     $views = determine_version_id($story_id);
    531                 }
    532             }
    533             echo $views;
    534             break;
    535     }
    536 }
    537 add_action('manage_posts_custom_column',  'shand_shorthand_show_columns');
    538 
    539 
    540504/* Filter to fix post type tags */
    541505function shand_post_type_tags_fix($request)
     
    561525
    562526
    563 /* UTILITY FUNCTIONS */
    564 
    565527/* Fix content paths */
    566528function shand_fix_content_paths($assets_path, $content)
    567529{
    568    
    569530    $content = str_replace('./assets/', $assets_path . '/assets/', $content);
    570531    $content = str_replace('./static/', $assets_path . '/static/', $content);
    571532    $content = preg_replace('/.(\/theme-\w+.min.css)/', $assets_path . '$1', $content);
    572    
    573533    $content = apply_filters('shand_fix_content_paths', $content);
    574    
    575534    return $content;
    576535}
     
    581540        return $content;
    582541    }
    583    
    584542    foreach ($queries as $query) {
    585543        if(isset($query->query) && isset($query->replace)){
     
    587545        }
    588546    }
    589 
    590547    return $content;
    591 }
    592 
    593 function determine_version_id($story_id)
    594 {
    595     if (substr($story_id, 0, 2) == 'v1') {
    596         return 'v1';
    597     }
    598     if (intval($story_id) > 0) {
    599         return 'v1';
    600     }
    601     return 'v2';
    602548}
    603549
     
    620566}
    621567
     568function remove_wp_meta_box() {
     569    if (function_exists('acf')) { // Check if ACF is installed and enabled
     570      $sh_disable_acf = filter_var(get_option('sh_disable_acf'), FILTER_VALIDATE_BOOLEAN);
     571      if ($sh_disable_acf) {
     572        add_filter('acf/settings/remove_wp_meta_box', '__return_false');
     573      }
     574    }
     575  }
     576  add_action('acf/init', 'remove_wp_meta_box');
     577 
    622578/* Add "Pull Story" to post dropdown */
    623 add_filter('bulk_actions-edit-shorthand_story', function($bulk_actions) {
     579add_filter('bulk_actions-edit-shorthand_story', function ($bulk_actions) {
    624580    $bulk_actions['bulk-pull-stories'] = __('Pull Story', 'txtdomain');
    625581    return $bulk_actions;
     
    627583
    628584/* Pull the stories */
    629 add_filter('handle_bulk_actions-edit-shorthand_story', function($redirect_url, $action, $post_ids) {
     585add_filter('handle_bulk_actions-edit-shorthand_story', function ($redirect_url, $action, $post_ids) {
    630586    //Run on posts which have bulk-pull-stories set to true
    631587    if ($action == 'bulk-pull-stories') {
     
    649605
    650606/* Add Notice after post has pulled */
    651 add_action('admin_notices', function() {
     607add_action('admin_notices', function () {
    652608    if (!empty($_REQUEST['bulk-pulled-stories'])) {
    653609        $num_changed = (int) $_REQUEST['bulk-pulled-stories'];
     
    655611    }
    656612});
    657 
    658 ?>
  • shorthand-connect/tags/1.3.28/templates/single-shorthand_story.php

    r2009514 r2898299  
    11<?php get_header();
    2 
    32    // Check to see if there is a password set against the post
    4     if ( post_password_required( $post->ID ) ) {
    5 
     3    if (post_password_required($post->ID)) {
    64         echo get_the_password_form();
    7 
    85    } else {
    9 
    106        while ( have_posts() ) : the_post();
    117            $meta = get_post_meta($post->ID);
    128        ?>
    13 
    149        <?php echo trim($meta['story_body'][0]); ?>
    15 
    1610        <div id="extraHTML">
    1711            <?php echo trim($meta['extra_html'][0]); ?>
    1812        </div>
    19 
    2013        <style type="text/css">
    2114            <?php echo get_option('sh_css'); ?>
    2215        </style>
    23 
    2416        <?php
    2517        endwhile;
    26 
    2718    }
    28 
    2919get_footer();
  • shorthand-connect/trunk/README.txt

    r2860602 r2898299  
    55Requires at least: 4.0
    66Tested up to: 6.1
    7 Stable tag: 1.3.27
     7Stable tag: 1.3.28
    88Requires PHP: 5.6
    99License: GPLv2 or later
     
    6464== Changelog ==
    6565
     66= 1.3.28 =
     67* Code clean up & bug fixes
     68* Remove legacy API code
     69* Introduce a 'Disable Advanced Custom Fields' option under Experimental Features
     70
    6671= 1.3.27 =
    6772* Added Mass Publishing Feature
  • shorthand-connect/trunk/config.default.php

    r2803964 r2898299  
    22
    33global $serverURL;
    4 global $serverv2URL;
    5 global $allowversionswitch;
    6 global $showServerURL;
    74global $showArchivedStories;
    85global $noabstract;
    96
    107$serverURL = 'https://api.shorthand.com';
    11 $serverv2URL = 'https://api.shorthand.com';
    12 $allowversionswitch = true;
    13 $showServerURL = false;
    148$showArchivedStories = false;
    159
    16 if ( defined( 'SHORTHAND_NOABSTRACT' ) ){
     10if (defined('SHORTHAND_NOABSTRACT')) {
    1711    $noabstract = SHORTHAND_NOABSTRACT;
    1812} else {
  • shorthand-connect/trunk/includes/api.php

    r2762662 r2898299  
    11<?php
    2 
    3 // VERSION 1 API
    4 
    5 function sh_get_profile() {
    6 
     2function sh_v2_api_get($url, $options)
     3{
     4    $token = get_option('sh_v2_token');
     5    if (!$token) {
     6        return false;
     7    }
    78    global $serverURL;
    8     $token = get_option('sh_token_key');
    9     $user_id = get_option('sh_user_id');
    10 
    11     $valid_token = false;
    12 
    13     $data = array();
    14 
    15     //Attempt to connect to the server
    16     if($token && $user_id) {
    17         $url = $serverURL.'/api/profile/';
    18         $vars = 'user='.$user_id.'&token='.$token;
    19         $response = wp_remote_post( $url, array(
     9    $url = $serverURL . $url;
     10    $plugin_path = plugin_dir_path( dirname( __FILE__ ) ) . '/shorthand_connect.php';
     11    $plugin_data = get_file_data( $plugin_path, array( 'Version' => 'Version' ) );
     12    $plugin_version = $plugin_data['Version'];
     13   
     14    $wp_version = $GLOBALS['wp_version'];
     15    $user_agent = 'WordPress/' . $wp_version . ' Shorthand/' . $plugin_version;
     16   
     17    $request_options = array_merge(
     18        array(
    2019            'headers' => array(
    21                 'user-agent'  =>  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8) AppleWebKit/535.6.2 (KHTML, like Gecko) Version/5.2 Safari/535.6.2',
     20                'Authorization' => 'Token ' . $token,
     21                'user-agent'  => $user_agent,
    2222            ),
    23             'body'    => array(
    24                 'user' => $user_id,
    25                 'token' => $token
    26             ),
    27         ));
    28         $body = wp_remote_retrieve_body( $response );
    29         $data = json_decode($body);
     23            'http_api_args' => $options
     24        ),
     25        $options
     26    );
     27   
     28    if (function_exists("vip_safe_wp_remote_get") && !isset($options['timeout'])){
     29        return vip_safe_wp_remote_get($url,false,1,3,10, $request_options);
     30    } else {
     31        return wp_remote_get($url, $request_options);
    3032    }
    31     return $data;
     33   
    3234}
    3335
    34 function sh_get_stories() {
    35     global $serverURL;
    36     $token = get_option('sh_token_key');
    37     $user_id = get_option('sh_user_id');
     36function sh_v2_api_get_json($url, $options)
     37{
     38    $response = sh_v2_api_get($url, $options);
     39    $body = wp_remote_retrieve_body($response);
     40    return json_decode($body);
     41}
    3842
    39     $valid_token = false;
     43function sh_get_profile()
     44{
     45    $tokeninfo = array();
     46   
     47    $data = sh_v2_api_get_json('/v2/token-info', array());
     48    if ($data && isset($data->organisation_id)) {
     49        $tokeninfo['username'] = $data->name . ' ('.$data->token_type.' Token)';
     50        $tokeninfo['gravatar'] = $data->logo;
     51        $tokeninfo = (object)$tokeninfo;
     52    }
     53   
     54    return $tokeninfo;
     55}
    4056
     57function sh_get_stories()
     58{
    4159    $stories = null;
    42 
    43     //Attempt to connect to the server
    44     if($token && $user_id) {
    45         $url = $serverURL.'/api/index/';
    46         $response = wp_remote_post( $url, array(
    47             'headers' => array(
    48                 'user-agent'  =>  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8) AppleWebKit/535.6.2 (KHTML, like Gecko) Version/5.2 Safari/535.6.2',
    49             ),
    50             'body'    => array(
    51                 'user' => $user_id,
    52                 'token' => $token
    53             ),
    54             'timeout' => '240'
    55         ));
    56         $body = wp_remote_retrieve_body( $response );
    57         $data = json_decode($body);
    58 
    59         if(isset($data->stories)) {
    60             $valid_token = true;
    61             $stories = $data->stories;
     60   
     61    $data = sh_v2_api_get_json('/v2/stories', array('timeout' => '240'));
     62    if ($data) {
     63        $stories = array();
     64        //Something went wrong
     65        if (isset($data->status) && $data->status) {
     66            return null;
     67        }
     68        foreach ($data as $storydata) {
     69            $story = array(
     70                'image' => $storydata->signedCover,
     71                'id' => $storydata->id,
     72                'metadata' => (object)array(
     73                    'description' => $storydata->description
     74                ),
     75                'title' => $storydata->title,
     76                'story_version' => ''.$storydata->version
     77            );
     78            $stories[] = (object)$story;
    6279        }
    6380    }
     81   
    6482    return $stories;
    6583}
    6684
    67 function sh_get_story_path($post_id, $story_id) {
    68     WP_Filesystem();
     85function sh_get_story_path($post_id, $story_id)
     86{
     87    init_WP_Filesystem();
    6988    $destination = wp_upload_dir();
    7089    $destination_path = $destination['path'].'/shorthand/'.$post_id.'/'.$story_id;
    71     if(!file_exists($destination_path)) {
     90   
     91    if (!file_exists($destination_path)) {
    7292        $destination_path = null;
    7393    }
     94   
     95    $destination_path = apply_filters('sh_get_story_path', $destination_path, $destination);
     96   
    7497    return $destination_path;
    7598}
    7699
    77 function sh_get_story_url($post_id, $story_id) {
    78     WP_Filesystem();
     100function sh_get_story_url($post_id, $story_id)
     101{
     102    init_WP_Filesystem();
    79103    $destination = wp_upload_dir();
    80104    $destination_url = $destination['url'].'/shorthand/'.$post_id.'/'.$story_id;
     105    $destination_url = apply_filters('sh_get_story_url', $destination_url);
     106   
    81107    return $destination_url;
    82108}
    83109
    84 function sh_copy_story($post_id, $story_id) {
    85 
    86     // Set the maximum memory limit for the entire operation (this is already called later by unzip_file, but lets do it earlier)
    87     @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
    88 
    89     WP_Filesystem();
     110function sh_copy_story($post_id, $story_id, $without_assets=false, $assets_only=false)
     111{
     112   
     113    wp_raise_memory_limit('admin');
     114    init_WP_Filesystem();
    90115    $destination = wp_upload_dir();
    91116    $tmpdir = get_temp_dir();
    92     $destination_path = $destination['path'].'/shorthand/'.$post_id.'/'.$story_id;
     117    $destination_path = $destination['path'].'/shorthand/'.$post_id;
     118    $story = array();
     119   
     120    //Attempt to connect to the server
     121    $zip_file = wp_tempnam('sh_zip',$tmpdir);
     122    $response = sh_v2_api_get('/v2/stories/'.$story_id.($without_assets?'?without_assets=true':'').($assets_only?'?assets_only=true':''), array(
     123        'timeout' => '600',
     124        'stream' => true,
     125        'filename' => $zip_file
     126    ));
     127    if (is_wp_error($response)) {
     128        $story['error'] = array(
     129            'pretty' => ' Request to Shorthand failed',
     130            'error' => $response->get_error_message($response)
     131        );
     132    } elseif (!$response || $response['response']['code'] != 200) {
     133        $story['error'] = array(
     134            'pretty' => 'Request to Shorthand failed; check the token is configured correctly',
     135            'response' => $response
     136        );
     137    } else {
     138        $story = extractStoryContent($zip_file, $destination_path, $story_id);
     139    }
     140   
     141    do_action('sh_copy_story', $post_id, $story_id, $story);
     142    unlink($zip_file);
     143   
     144    return $story;
     145}
    93146
    94     global $serverURL;
    95     $token = get_option('sh_token_key');
    96     $user_id = get_option('sh_user_id');
    97147
    98     $valid_token = false;
     148function init_WP_Filesystem()
     149{
     150    WP_Filesystem();
     151    global $wp_filesystem;
     152    if (!is_a($wp_filesystem, 'WP_Filesystem_Base')) {
     153        $creds = request_filesystem_credentials(site_url());
     154        wp_filesystem($creds);
     155    }
     156}
    99157
    100     $story = array();
    101 
    102     //Attempt to connect to the server
    103     if($token && $user_id) {
    104         $url = $serverURL.'/api/story/'.$story_id.'/';
    105         $vars = 'user='.$user_id.'&token='.$token;
    106         $zipfile = wp_tempnam($tmpdir, 'sh_zip');
    107         $response = wp_remote_post( $url, array(
    108             'headers' => array(
    109                 'user-agent'  =>  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8) AppleWebKit/535.6.2 (KHTML, like Gecko) Version/5.2 Safari/535.6.2',
    110             ),
    111             'body'    => array(
    112                 'user' => $user_id,
    113                 'token' => $token
    114             ),
    115             'timeout' => '600',
    116             'stream' => true,
    117             'filename' => $zipfile
    118         ));
    119         $body = wp_remote_retrieve_body( $response );
    120         $data = json_decode($body);
    121         if($response['response']['code'] == 200) {
    122             $unzipfile = unzip_file( $zipfile, $destination_path);
    123             if ( $unzipfile ) {
    124                 $story['path'] = $destination_path;
    125             } else {
    126                 $story['error'] = array(
    127                 'pretty' => 'Could not unzip file'
     158function extractStoryContent($zip_file, $destination_path, $story_id)
     159{
     160    //WP VIP HOSTING COMPATIBILITY
     161    $zip = new ZipArchive;
     162    if ($zip->open($zip_file)) {
     163        wp_mkdir_p($destination_path.'/'.$story_id);
     164        $zip->extractTo($destination_path.'/'.$story_id);
     165        $zip->close();
     166        if (is_wp_error($zip)) {
     167            $story['error'] = array(
     168                'pretty' => 'Could not copy story into Wordpress',
     169                'error' => $zip->get_error_message(),
     170                'unzip error'=> $zip_file
    128171            );
     172            if (function_exists("wp_filesize")){
     173                $story['error']['downloaded zip size'] = wp_filesize($zip_file);
    129174            }
    130175        } else {
    131             $story['error'] = array(
    132                 'pretty' => 'Could not upload file',
    133                 'error' => curl_error($ch),
    134                 'response' => $response
    135             );
     176            $story['path'] = $destination_path.'/'.$story_id;
    136177        }
     178    } else {
     179        $story['error'] = array(
     180            'pretty' => 'Could not unzip file'
     181        );
    137182    }
     183   
    138184    return $story;
    139185}
  • shorthand-connect/trunk/includes/mass_pull.php

    r2860602 r2898299  
    11<?php
    2 
    32/*
    43/* Name: Update Story Meta Fields Function */
     
    65/* Note: Unzipping a fresh story copy won't update the fields
    76*/
    8 function shand_update_story($post_id, $story_id) {
    9 
     7function shand_update_story($post_id, $story_id)
     8{
    109    init_WP_Filesystem();
    1110    global $wp_filesystem;
     
    2019   
    2120    $err = sh_copy_story($post_id, $safe_story_id, $sh_media_cron_offload);
    22 
    23     $sh_title = get_post_meta( $post_id, 'title', true );
    2421
    2522    $story_path = sh_get_story_path($post_id, $safe_story_id);
     
    3936        update_post_meta($post_id, 'story_path', $story_path);
    4037
    41         //Log any story-specific errors to the metadata 
     38        //Log any story-specific errors to the metadata
    4239        if(isset($err['error'])){
    4340            update_post_meta($post_id, 'ERROR', json_encode($err));
     
    5047
    5148        // Save the head and body
    52         $version = get_option('sh_api_version');
    53        
    54         update_post_meta($post_id, 'api_version', $version);
    55         $head_file = $story_path . '/head.html';
     49                $head_file = $story_path . '/head.html';
    5650        $article_file = $story_path . '/article.html';
    5751
     
    8781
    8882    } else {
    89 
    9083        update_post_meta($post_id, 'story_diagnostic', $err);
    91 
    9284        echo 'Something went wrong, please try again';
    9385        print_r($err);
     
    9688
    9789}
    98 ?>
  • shorthand-connect/trunk/includes/shorthand_options.php

    r2817526 r2898299  
    11<?php
    2 
    32/* Options */
    43function shand_shorthand_menu() {
    54    add_options_page( 'Shorthand Options', 'Shorthand', 'manage_options', 'shorthand-options', 'shand_shorthand_options' );
    65}
    7 
    86$default_sh_site_css = '
    97/* START CSS FOR DEFAULT WP THEMES */
     
    2826';
    2927
    30 function shand_shorthand_options() {
    31 
     28function shand_shorthand_options()
     29{
    3230    global $default_sh_site_css;
    3331    global $serverURL;
    34     global $serverv2URL;
    35     global $allowversionswitch;
    36     global $showServerURL;
    3732
    3833    if ( !current_user_can( 'manage_options' ) )  {
     
    4237        update_option('sh_v2_token', sanitize_text_field($_POST['sh_v2_token']));
    4338    }
    44 
    4539    $v2_token = esc_html(get_option('sh_v2_token'));
    4640   
    47 
    4841    if( isset($_POST['sh_submit_hidden_two']) && $_POST['sh_submit_hidden_two'] == 'Y' && check_admin_referer( 'sh-update-configuration' ) ) {
    4942        update_option('sh_css', wp_kses_post($_POST['sh_css']));
     
    6053        $permalink_structure = esc_html(get_option('sh_permalink'));
    6154    }
    62 
    6355    $sh_css = get_option('sh_css');
    6456    $no_css = false;
    6557    if ($sh_css == '') {
    6658        $no_css = true;
    67         if(isset($default_site_css)){
     59        if (isset($default_site_css)){
    6860            update_option('sh_css', $default_site_css);
    6961        }
     
    7163    }
    7264
    73     if(isset($_POST['sh_submit_hidden_four']) && $_POST['sh_submit_hidden_four'] == 'Y' && check_admin_referer( 'sh-update-configuration' ) ) {
     65    if (isset($_POST['sh_submit_hidden_four']) && $_POST['sh_submit_hidden_four'] == 'Y' && check_admin_referer( 'sh-update-configuration' )) {
    7466        update_option('sh_regex_list', base64_encode(wp_unslash($_POST['sh_regex_list'])));
    7567    }
     
    7769    $sh_regex_list = base64_decode(get_option('sh_regex_list'));
    7870
    79     //Experimental Settings
    80     if( isset($_POST['sh_submit_hidden_experimental']) && $_POST['sh_submit_hidden_experimental'] == 'Y' && check_admin_referer( 'sh-update-configuration' ) ) {
    81         update_option('sh_media_cron_offload', $_POST['sh_media_cron_offload']);
    82     }
    83     $sh_media_cron_offload = filter_var(get_option('sh_media_cron_offload'), FILTER_VALIDATE_BOOLEAN);
    84 
     71    // Experimental Settings
     72    if (isset($_POST['sh_submit_hidden_experimental']) && $_POST['sh_submit_hidden_experimental'] == 'Y' && check_admin_referer('sh-update-configuration')) {
     73        $sh_media_cron_offload = isset($_POST['sh_media_cron_offload']) ? filter_var($_POST['sh_media_cron_offload'], FILTER_VALIDATE_BOOLEAN) : false;
     74        $sh_disable_acf = isset($_POST['sh_disable_acf']) ? filter_var($_POST['sh_disable_acf'], FILTER_VALIDATE_BOOLEAN) : false;
     75        update_option('sh_media_cron_offload', $sh_media_cron_offload);
     76        update_option('sh_disable_acf', $sh_disable_acf);
     77    }
     78  $sh_media_cron_offload = filter_var(get_option('sh_media_cron_offload'), FILTER_VALIDATE_BOOLEAN);
     79  $sh_disable_acf = filter_var(get_option('sh_disable_acf'), FILTER_VALIDATE_BOOLEAN);
     80 
    8581    $profile = sh_get_profile();
    8682    $n_once = wp_nonce_field( 'sh-update-configuration' );
     
    143139        <p><em>This Example removes title tags from within the head tag by replacing it with nothing.</em></p>
    144140<pre><code>
    145   { 
     141  {
    146142    "head":
    147143    [
    148       { 
     144      {
    149145        &quot;query&quot;:&quot;/&lt;title.(.*?)&lt;\/title&gt;/&quot;,
    150146        &quot;replace&quot;:&quot;&quot;
    151147      }
    152148    ],
    153     "body":[] 
     149    "body":[]
    154150  }
    155 
    156151</code></pre>
    157152        <form name="form2" method="post" onsubmit="padJson()">
     
    218213
    219214<h3>Experimental Features</h3>
    220         <p>Early access features that are still subject to change.</p>
    221        
    222         <form name="form_experimental" method="post">
    223             <?php echo $n_once ?>
    224             <input type="hidden" name="sh_submit_hidden_experimental" value="Y" />
    225             <input type="checkbox" id="sh_media_cron_offload" name="sh_media_cron_offload" value="true" <?php echo esc_attr($sh_media_cron_offload ? 'checked' : '') ?> />
    226             <label for="sh_media_cron_offload">Import media assets via cron</label>
    227             <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>
    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>
    229             <br/>
    230             <p class="submit">
    231                 <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" />
    232             </p>
    233         </form>
     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>
    234232<?php
    235233}
  • shorthand-connect/trunk/shorthand_connect.php

    r2860602 r2898299  
    33/**
    44 * @package Shorthand Connect
    5  * @version 1.3.27
     5 * @version 1.3.28
    66 */
    77/*
     
    1010Description: Import your Shorthand stories into your Wordpress CMS as simply as possible - magic!
    1111Author: Shorthand
    12 Version: 1.3.27
     12Version: 1.3.28
    1313Author URI: http://shorthand.com
    1414*/
    1515
    16 $included = @include_once('config.php');
    17 if (!$included) {
     16if (file_exists('config.php')) {
     17    include_once('config.php');
     18} else {
    1819    require_once('config.default.php');
    1920}
    20 $version = 'v2';
    21 
    22 require_once('includes/api-v2.php');
     21require_once('includes/api.php');
    2322require_once('includes/mass_pull.php');
    2423
     
    7069function shand_wpt_shorthand_story()
    7170{
    72 
    7371    global $post;
    74 
    7572    global $serverURL;
    76     global $serverv2URL;
    7773    global $showArchivedStories;
    78 
    7974    $baseurl = '';
    80 
    81     $version = 'v2';
    8275
    8376?>
     
    198191    }
    199192    $stories = sh_get_stories();
    200 
    201     if (!is_array($stories)) {
    202         echo 'Could not connect to Shorthand, please check your <a href="options-general.php?page=shorthand-options">Wordpress Shorthand settings</a>.';
    203     } else if (sizeOf($stories) == 0) {
     193    $profile = sh_get_profile();
     194
     195    if (!($profile)) {
     196        echo 'Could not connect to Shorthand, please check your API token in <a href="options-general.php?page=shorthand-options">Shorthand settings</a>.';
     197    } elseif ($stories === null) {
    204198        echo 'You currently have no stories ready for publishing on Shorthand. Please check that your story is set to be ready for publishing.';
    205199    } else {
     
    213207            }
    214208            $archived = '';
    215             if ($version == 'v2' && isset($story->story_version) && $story->story_version == '1') {
     209            if (isset($story->story_version) && $story->story_version == '1') {
    216210                if ($showArchivedStories) {
    217211                    $archived = ' (archived)';
     
    279273function shand_add_shorthand_metaboxes()
    280274{
    281     global $version;
    282275    global $post;
    283276    global $noabstract;
     
    332325
    333326/* Save the shorthand story */
    334 function shand_save_shorthand_story($post_id, $post, $update)
     327function shand_save_shorthand_story($post_id, $post)
    335328{
    336329    WP_Filesystem();
    337 
    338330    global $wp_filesystem;
    339 
     331   
    340332    if ( ! is_a( $wp_filesystem, 'WP_Filesystem_Base') ) {
    341333        $creds = request_filesystem_credentials( site_url() );
     
    355347    }
    356348
    357     if(!get_post_meta($post_id, 'no_update')) {
     349    if (!get_post_meta($post_id, 'no_update')) {
    358350        update_post_meta($post_id, 'no_update', "false");
    359351    }
     
    378370           
    379371        }
    380         if($sh_media_cron_offload){
     372        if ($sh_media_cron_offload){
    381373            update_post_meta($post_id, 'media_status', '[Awaiting media fetch...]');
    382374            wp_schedule_single_event(time() + 30, 'sh_media_fetch', array( $post_id, $safe_story_id ));
     
    387379            update_post_meta($post_id, 'story_path', $story_path);
    388380
    389             //Log any story-specific errors to the metadata 
     381            //Log any story-specific errors to the metadata
    390382            if(isset($err['error'])){
    391383                update_post_meta($post_id, 'ERROR', json_encode($err));
     
    398390
    399391            // Save the head and body
    400             $version = get_option('sh_api_version');
    401             update_post_meta($post_id, 'api_version', $version);
    402392            $head_file = $story_path . '/head.html';
    403393            $article_file = $story_path . '/article.html';
     
    411401            $head = apply_filters('sh_pre_process_head', $head, $assets_path, $head_file);
    412402           
    413             if(isset($post_processing_queries->body)){
     403            if (isset($post_processing_queries->body)){
    414404                $body = shand_post_processing($body,$post_processing_queries->body);
    415405            }
    416406           
    417             if(isset($post_processing_queries->head)){
     407            if (isset($post_processing_queries->head)){
    418408                $head = shand_post_processing($head, $post_processing_queries->head);
    419409            }
     
    496486function shand_shorthand_get_posts($query)
    497487{
    498     if (is_home() && $query->is_main_query())
    499         $query->set('post_type', array('post', 'shorthand_story'));
    500 
     488    if (is_home() && $query->is_main_query()) {
     489        $query->set( 'post_type', array( 'post', 'shorthand_story' ) );
     490    }
    501491    return $query;
    502492}
     
    512502
    513503
    514 /* Table Hook */
    515 function shand_shorthand_show_columns($name)
    516 {
    517     global $post;
    518     switch ($name) {
    519         case 'story_id':
    520             $views = get_post_meta($post->ID, 'story_id', true);
    521             echo $views;
    522             break;
    523         case 'api_version':
    524             $views = get_post_meta($post->ID, 'api_version', true);
    525             if ($views == '') {
    526                 // Determine the version, save it if possible;
    527                 $views = 'Unknown';
    528                 $story_id = get_post_meta($post->ID, 'story_id', true);
    529                 if ($story_id) {
    530                     $views = determine_version_id($story_id);
    531                 }
    532             }
    533             echo $views;
    534             break;
    535     }
    536 }
    537 add_action('manage_posts_custom_column',  'shand_shorthand_show_columns');
    538 
    539 
    540504/* Filter to fix post type tags */
    541505function shand_post_type_tags_fix($request)
     
    561525
    562526
    563 /* UTILITY FUNCTIONS */
    564 
    565527/* Fix content paths */
    566528function shand_fix_content_paths($assets_path, $content)
    567529{
    568    
    569530    $content = str_replace('./assets/', $assets_path . '/assets/', $content);
    570531    $content = str_replace('./static/', $assets_path . '/static/', $content);
    571532    $content = preg_replace('/.(\/theme-\w+.min.css)/', $assets_path . '$1', $content);
    572    
    573533    $content = apply_filters('shand_fix_content_paths', $content);
    574    
    575534    return $content;
    576535}
     
    581540        return $content;
    582541    }
    583    
    584542    foreach ($queries as $query) {
    585543        if(isset($query->query) && isset($query->replace)){
     
    587545        }
    588546    }
    589 
    590547    return $content;
    591 }
    592 
    593 function determine_version_id($story_id)
    594 {
    595     if (substr($story_id, 0, 2) == 'v1') {
    596         return 'v1';
    597     }
    598     if (intval($story_id) > 0) {
    599         return 'v1';
    600     }
    601     return 'v2';
    602548}
    603549
     
    620566}
    621567
     568function remove_wp_meta_box() {
     569    if (function_exists('acf')) { // Check if ACF is installed and enabled
     570      $sh_disable_acf = filter_var(get_option('sh_disable_acf'), FILTER_VALIDATE_BOOLEAN);
     571      if ($sh_disable_acf) {
     572        add_filter('acf/settings/remove_wp_meta_box', '__return_false');
     573      }
     574    }
     575  }
     576  add_action('acf/init', 'remove_wp_meta_box');
     577 
    622578/* Add "Pull Story" to post dropdown */
    623 add_filter('bulk_actions-edit-shorthand_story', function($bulk_actions) {
     579add_filter('bulk_actions-edit-shorthand_story', function ($bulk_actions) {
    624580    $bulk_actions['bulk-pull-stories'] = __('Pull Story', 'txtdomain');
    625581    return $bulk_actions;
     
    627583
    628584/* Pull the stories */
    629 add_filter('handle_bulk_actions-edit-shorthand_story', function($redirect_url, $action, $post_ids) {
     585add_filter('handle_bulk_actions-edit-shorthand_story', function ($redirect_url, $action, $post_ids) {
    630586    //Run on posts which have bulk-pull-stories set to true
    631587    if ($action == 'bulk-pull-stories') {
     
    649605
    650606/* Add Notice after post has pulled */
    651 add_action('admin_notices', function() {
     607add_action('admin_notices', function () {
    652608    if (!empty($_REQUEST['bulk-pulled-stories'])) {
    653609        $num_changed = (int) $_REQUEST['bulk-pulled-stories'];
     
    655611    }
    656612});
    657 
    658 ?>
  • shorthand-connect/trunk/templates/single-shorthand_story.php

    r2009514 r2898299  
    11<?php get_header();
    2 
    32    // Check to see if there is a password set against the post
    4     if ( post_password_required( $post->ID ) ) {
    5 
     3    if (post_password_required($post->ID)) {
    64         echo get_the_password_form();
    7 
    85    } else {
    9 
    106        while ( have_posts() ) : the_post();
    117            $meta = get_post_meta($post->ID);
    128        ?>
    13 
    149        <?php echo trim($meta['story_body'][0]); ?>
    15 
    1610        <div id="extraHTML">
    1711            <?php echo trim($meta['extra_html'][0]); ?>
    1812        </div>
    19 
    2013        <style type="text/css">
    2114            <?php echo get_option('sh_css'); ?>
    2215        </style>
    23 
    2416        <?php
    2517        endwhile;
    26 
    2718    }
    28 
    2919get_footer();
Note: See TracChangeset for help on using the changeset viewer.