Changeset 2898299
- Timestamp:
- 04/13/2023 08:02:08 AM (3 years ago)
- Location:
- shorthand-connect
- Files:
-
- 14 edited
- 1 copied
-
tags/1.3.28 (copied) (copied from shorthand-connect/trunk)
-
tags/1.3.28/README.txt (modified) (2 diffs)
-
tags/1.3.28/config.default.php (modified) (1 diff)
-
tags/1.3.28/includes/api.php (modified) (1 diff)
-
tags/1.3.28/includes/mass_pull.php (modified) (7 diffs)
-
tags/1.3.28/includes/shorthand_options.php (modified) (8 diffs)
-
tags/1.3.28/shorthand_connect.php (modified) (21 diffs)
-
tags/1.3.28/templates/single-shorthand_story.php (modified) (1 diff)
-
trunk/README.txt (modified) (2 diffs)
-
trunk/config.default.php (modified) (1 diff)
-
trunk/includes/api.php (modified) (1 diff)
-
trunk/includes/mass_pull.php (modified) (7 diffs)
-
trunk/includes/shorthand_options.php (modified) (8 diffs)
-
trunk/shorthand_connect.php (modified) (21 diffs)
-
trunk/templates/single-shorthand_story.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
shorthand-connect/tags/1.3.28/README.txt
r2860602 r2898299 5 5 Requires at least: 4.0 6 6 Tested up to: 6.1 7 Stable tag: 1.3.2 77 Stable tag: 1.3.28 8 8 Requires PHP: 5.6 9 9 License: GPLv2 or later … … 64 64 == Changelog == 65 65 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 66 71 = 1.3.27 = 67 72 * Added Mass Publishing Feature -
shorthand-connect/tags/1.3.28/config.default.php
r2803964 r2898299 2 2 3 3 global $serverURL; 4 global $serverv2URL;5 global $allowversionswitch;6 global $showServerURL;7 4 global $showArchivedStories; 8 5 global $noabstract; 9 6 10 7 $serverURL = 'https://api.shorthand.com'; 11 $serverv2URL = 'https://api.shorthand.com';12 $allowversionswitch = true;13 $showServerURL = false;14 8 $showArchivedStories = false; 15 9 16 if ( defined( 'SHORTHAND_NOABSTRACT' ) ){10 if (defined('SHORTHAND_NOABSTRACT')) { 17 11 $noabstract = SHORTHAND_NOABSTRACT; 18 12 } else { -
shorthand-connect/tags/1.3.28/includes/api.php
r2762662 r2898299 1 1 <?php 2 3 // VERSION 1 API 4 5 function sh_get_profile() { 6 2 function sh_v2_api_get($url, $options) 3 { 4 $token = get_option('sh_v2_token'); 5 if (!$token) { 6 return false; 7 } 7 8 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( 20 19 '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, 22 22 ), 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); 30 32 } 31 return $data;33 32 34 } 33 35 34 function sh_get_stories() { 35 global $serverURL; 36 $token = get_option('sh_token_key'); 37 $user_id = get_option('sh_user_id'); 36 function 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 } 38 42 39 $valid_token = false; 43 function 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 } 40 56 57 function sh_get_stories() 58 { 41 59 $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; 62 79 } 63 80 } 81 64 82 return $stories; 65 83 } 66 84 67 function sh_get_story_path($post_id, $story_id) { 68 WP_Filesystem(); 85 function sh_get_story_path($post_id, $story_id) 86 { 87 init_WP_Filesystem(); 69 88 $destination = wp_upload_dir(); 70 89 $destination_path = $destination['path'].'/shorthand/'.$post_id.'/'.$story_id; 71 if(!file_exists($destination_path)) { 90 91 if (!file_exists($destination_path)) { 72 92 $destination_path = null; 73 93 } 94 95 $destination_path = apply_filters('sh_get_story_path', $destination_path, $destination); 96 74 97 return $destination_path; 75 98 } 76 99 77 function sh_get_story_url($post_id, $story_id) { 78 WP_Filesystem(); 100 function sh_get_story_url($post_id, $story_id) 101 { 102 init_WP_Filesystem(); 79 103 $destination = wp_upload_dir(); 80 104 $destination_url = $destination['url'].'/shorthand/'.$post_id.'/'.$story_id; 105 $destination_url = apply_filters('sh_get_story_url', $destination_url); 106 81 107 return $destination_url; 82 108 } 83 109 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(); 110 function 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(); 90 115 $destination = wp_upload_dir(); 91 116 $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 } 93 146 94 global $serverURL;95 $token = get_option('sh_token_key');96 $user_id = get_option('sh_user_id');97 147 98 $valid_token = false; 148 function 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 } 99 157 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' 158 function 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 128 171 ); 172 if (function_exists("wp_filesize")){ 173 $story['error']['downloaded zip size'] = wp_filesize($zip_file); 129 174 } 130 175 } 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; 136 177 } 178 } else { 179 $story['error'] = array( 180 'pretty' => 'Could not unzip file' 181 ); 137 182 } 183 138 184 return $story; 139 185 } -
shorthand-connect/tags/1.3.28/includes/mass_pull.php
r2860602 r2898299 1 1 <?php 2 3 2 /* 4 3 /* Name: Update Story Meta Fields Function */ … … 6 5 /* Note: Unzipping a fresh story copy won't update the fields 7 6 */ 8 function shand_update_story($post_id, $story_id) {9 7 function shand_update_story($post_id, $story_id) 8 { 10 9 init_WP_Filesystem(); 11 10 global $wp_filesystem; … … 20 19 21 20 $err = sh_copy_story($post_id, $safe_story_id, $sh_media_cron_offload); 22 23 $sh_title = get_post_meta( $post_id, 'title', true );24 21 25 22 $story_path = sh_get_story_path($post_id, $safe_story_id); … … 39 36 update_post_meta($post_id, 'story_path', $story_path); 40 37 41 //Log any story-specific errors to the metadata 38 //Log any story-specific errors to the metadata 42 39 if(isset($err['error'])){ 43 40 update_post_meta($post_id, 'ERROR', json_encode($err)); … … 50 47 51 48 // 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'; 56 50 $article_file = $story_path . '/article.html'; 57 51 … … 87 81 88 82 } else { 89 90 83 update_post_meta($post_id, 'story_diagnostic', $err); 91 92 84 echo 'Something went wrong, please try again'; 93 85 print_r($err); … … 96 88 97 89 } 98 ?> -
shorthand-connect/tags/1.3.28/includes/shorthand_options.php
r2817526 r2898299 1 1 <?php 2 3 2 /* Options */ 4 3 function shand_shorthand_menu() { 5 4 add_options_page( 'Shorthand Options', 'Shorthand', 'manage_options', 'shorthand-options', 'shand_shorthand_options' ); 6 5 } 7 8 6 $default_sh_site_css = ' 9 7 /* START CSS FOR DEFAULT WP THEMES */ … … 28 26 '; 29 27 30 function shand_shorthand_options() {31 28 function shand_shorthand_options() 29 { 32 30 global $default_sh_site_css; 33 31 global $serverURL; 34 global $serverv2URL;35 global $allowversionswitch;36 global $showServerURL;37 32 38 33 if ( !current_user_can( 'manage_options' ) ) { … … 42 37 update_option('sh_v2_token', sanitize_text_field($_POST['sh_v2_token'])); 43 38 } 44 45 39 $v2_token = esc_html(get_option('sh_v2_token')); 46 40 47 48 41 if( isset($_POST['sh_submit_hidden_two']) && $_POST['sh_submit_hidden_two'] == 'Y' && check_admin_referer( 'sh-update-configuration' ) ) { 49 42 update_option('sh_css', wp_kses_post($_POST['sh_css'])); … … 60 53 $permalink_structure = esc_html(get_option('sh_permalink')); 61 54 } 62 63 55 $sh_css = get_option('sh_css'); 64 56 $no_css = false; 65 57 if ($sh_css == '') { 66 58 $no_css = true; 67 if (isset($default_site_css)){59 if (isset($default_site_css)){ 68 60 update_option('sh_css', $default_site_css); 69 61 } … … 71 63 } 72 64 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' )) { 74 66 update_option('sh_regex_list', base64_encode(wp_unslash($_POST['sh_regex_list']))); 75 67 } … … 77 69 $sh_regex_list = base64_decode(get_option('sh_regex_list')); 78 70 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 85 81 $profile = sh_get_profile(); 86 82 $n_once = wp_nonce_field( 'sh-update-configuration' ); … … 143 139 <p><em>This Example removes title tags from within the head tag by replacing it with nothing.</em></p> 144 140 <pre><code> 145 { 141 { 146 142 "head": 147 143 [ 148 { 144 { 149 145 "query":"/<title.(.*?)<\/title>/", 150 146 "replace":"" 151 147 } 152 148 ], 153 "body":[] 149 "body":[] 154 150 } 155 156 151 </code></pre> 157 152 <form name="form2" method="post" onsubmit="padJson()"> … … 218 213 219 214 <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> 234 232 <?php 235 233 } -
shorthand-connect/tags/1.3.28/shorthand_connect.php
r2860602 r2898299 3 3 /** 4 4 * @package Shorthand Connect 5 * @version 1.3.2 75 * @version 1.3.28 6 6 */ 7 7 /* … … 10 10 Description: Import your Shorthand stories into your Wordpress CMS as simply as possible - magic! 11 11 Author: Shorthand 12 Version: 1.3.2 712 Version: 1.3.28 13 13 Author URI: http://shorthand.com 14 14 */ 15 15 16 $included = @include_once('config.php'); 17 if (!$included) { 16 if (file_exists('config.php')) { 17 include_once('config.php'); 18 } else { 18 19 require_once('config.default.php'); 19 20 } 20 $version = 'v2'; 21 22 require_once('includes/api-v2.php'); 21 require_once('includes/api.php'); 23 22 require_once('includes/mass_pull.php'); 24 23 … … 70 69 function shand_wpt_shorthand_story() 71 70 { 72 73 71 global $post; 74 75 72 global $serverURL; 76 global $serverv2URL;77 73 global $showArchivedStories; 78 79 74 $baseurl = ''; 80 81 $version = 'v2';82 75 83 76 ?> … … 198 191 } 199 192 $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) { 204 198 echo 'You currently have no stories ready for publishing on Shorthand. Please check that your story is set to be ready for publishing.'; 205 199 } else { … … 213 207 } 214 208 $archived = ''; 215 if ( $version == 'v2' &&isset($story->story_version) && $story->story_version == '1') {209 if (isset($story->story_version) && $story->story_version == '1') { 216 210 if ($showArchivedStories) { 217 211 $archived = ' (archived)'; … … 279 273 function shand_add_shorthand_metaboxes() 280 274 { 281 global $version;282 275 global $post; 283 276 global $noabstract; … … 332 325 333 326 /* Save the shorthand story */ 334 function shand_save_shorthand_story($post_id, $post , $update)327 function shand_save_shorthand_story($post_id, $post) 335 328 { 336 329 WP_Filesystem(); 337 338 330 global $wp_filesystem; 339 331 340 332 if ( ! is_a( $wp_filesystem, 'WP_Filesystem_Base') ) { 341 333 $creds = request_filesystem_credentials( site_url() ); … … 355 347 } 356 348 357 if (!get_post_meta($post_id, 'no_update')) {349 if (!get_post_meta($post_id, 'no_update')) { 358 350 update_post_meta($post_id, 'no_update', "false"); 359 351 } … … 378 370 379 371 } 380 if ($sh_media_cron_offload){372 if ($sh_media_cron_offload){ 381 373 update_post_meta($post_id, 'media_status', '[Awaiting media fetch...]'); 382 374 wp_schedule_single_event(time() + 30, 'sh_media_fetch', array( $post_id, $safe_story_id )); … … 387 379 update_post_meta($post_id, 'story_path', $story_path); 388 380 389 //Log any story-specific errors to the metadata 381 //Log any story-specific errors to the metadata 390 382 if(isset($err['error'])){ 391 383 update_post_meta($post_id, 'ERROR', json_encode($err)); … … 398 390 399 391 // Save the head and body 400 $version = get_option('sh_api_version');401 update_post_meta($post_id, 'api_version', $version);402 392 $head_file = $story_path . '/head.html'; 403 393 $article_file = $story_path . '/article.html'; … … 411 401 $head = apply_filters('sh_pre_process_head', $head, $assets_path, $head_file); 412 402 413 if (isset($post_processing_queries->body)){403 if (isset($post_processing_queries->body)){ 414 404 $body = shand_post_processing($body,$post_processing_queries->body); 415 405 } 416 406 417 if (isset($post_processing_queries->head)){407 if (isset($post_processing_queries->head)){ 418 408 $head = shand_post_processing($head, $post_processing_queries->head); 419 409 } … … 496 486 function shand_shorthand_get_posts($query) 497 487 { 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 } 501 491 return $query; 502 492 } … … 512 502 513 503 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 540 504 /* Filter to fix post type tags */ 541 505 function shand_post_type_tags_fix($request) … … 561 525 562 526 563 /* UTILITY FUNCTIONS */564 565 527 /* Fix content paths */ 566 528 function shand_fix_content_paths($assets_path, $content) 567 529 { 568 569 530 $content = str_replace('./assets/', $assets_path . '/assets/', $content); 570 531 $content = str_replace('./static/', $assets_path . '/static/', $content); 571 532 $content = preg_replace('/.(\/theme-\w+.min.css)/', $assets_path . '$1', $content); 572 573 533 $content = apply_filters('shand_fix_content_paths', $content); 574 575 534 return $content; 576 535 } … … 581 540 return $content; 582 541 } 583 584 542 foreach ($queries as $query) { 585 543 if(isset($query->query) && isset($query->replace)){ … … 587 545 } 588 546 } 589 590 547 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';602 548 } 603 549 … … 620 566 } 621 567 568 function 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 622 578 /* Add "Pull Story" to post dropdown */ 623 add_filter('bulk_actions-edit-shorthand_story', function ($bulk_actions) {579 add_filter('bulk_actions-edit-shorthand_story', function ($bulk_actions) { 624 580 $bulk_actions['bulk-pull-stories'] = __('Pull Story', 'txtdomain'); 625 581 return $bulk_actions; … … 627 583 628 584 /* Pull the stories */ 629 add_filter('handle_bulk_actions-edit-shorthand_story', function ($redirect_url, $action, $post_ids) {585 add_filter('handle_bulk_actions-edit-shorthand_story', function ($redirect_url, $action, $post_ids) { 630 586 //Run on posts which have bulk-pull-stories set to true 631 587 if ($action == 'bulk-pull-stories') { … … 649 605 650 606 /* Add Notice after post has pulled */ 651 add_action('admin_notices', function () {607 add_action('admin_notices', function () { 652 608 if (!empty($_REQUEST['bulk-pulled-stories'])) { 653 609 $num_changed = (int) $_REQUEST['bulk-pulled-stories']; … … 655 611 } 656 612 }); 657 658 ?> -
shorthand-connect/tags/1.3.28/templates/single-shorthand_story.php
r2009514 r2898299 1 1 <?php get_header(); 2 3 2 // 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)) { 6 4 echo get_the_password_form(); 7 8 5 } else { 9 10 6 while ( have_posts() ) : the_post(); 11 7 $meta = get_post_meta($post->ID); 12 8 ?> 13 14 9 <?php echo trim($meta['story_body'][0]); ?> 15 16 10 <div id="extraHTML"> 17 11 <?php echo trim($meta['extra_html'][0]); ?> 18 12 </div> 19 20 13 <style type="text/css"> 21 14 <?php echo get_option('sh_css'); ?> 22 15 </style> 23 24 16 <?php 25 17 endwhile; 26 27 18 } 28 29 19 get_footer(); -
shorthand-connect/trunk/README.txt
r2860602 r2898299 5 5 Requires at least: 4.0 6 6 Tested up to: 6.1 7 Stable tag: 1.3.2 77 Stable tag: 1.3.28 8 8 Requires PHP: 5.6 9 9 License: GPLv2 or later … … 64 64 == Changelog == 65 65 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 66 71 = 1.3.27 = 67 72 * Added Mass Publishing Feature -
shorthand-connect/trunk/config.default.php
r2803964 r2898299 2 2 3 3 global $serverURL; 4 global $serverv2URL;5 global $allowversionswitch;6 global $showServerURL;7 4 global $showArchivedStories; 8 5 global $noabstract; 9 6 10 7 $serverURL = 'https://api.shorthand.com'; 11 $serverv2URL = 'https://api.shorthand.com';12 $allowversionswitch = true;13 $showServerURL = false;14 8 $showArchivedStories = false; 15 9 16 if ( defined( 'SHORTHAND_NOABSTRACT' ) ){10 if (defined('SHORTHAND_NOABSTRACT')) { 17 11 $noabstract = SHORTHAND_NOABSTRACT; 18 12 } else { -
shorthand-connect/trunk/includes/api.php
r2762662 r2898299 1 1 <?php 2 3 // VERSION 1 API 4 5 function sh_get_profile() { 6 2 function sh_v2_api_get($url, $options) 3 { 4 $token = get_option('sh_v2_token'); 5 if (!$token) { 6 return false; 7 } 7 8 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( 20 19 '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, 22 22 ), 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); 30 32 } 31 return $data;33 32 34 } 33 35 34 function sh_get_stories() { 35 global $serverURL; 36 $token = get_option('sh_token_key'); 37 $user_id = get_option('sh_user_id'); 36 function 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 } 38 42 39 $valid_token = false; 43 function 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 } 40 56 57 function sh_get_stories() 58 { 41 59 $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; 62 79 } 63 80 } 81 64 82 return $stories; 65 83 } 66 84 67 function sh_get_story_path($post_id, $story_id) { 68 WP_Filesystem(); 85 function sh_get_story_path($post_id, $story_id) 86 { 87 init_WP_Filesystem(); 69 88 $destination = wp_upload_dir(); 70 89 $destination_path = $destination['path'].'/shorthand/'.$post_id.'/'.$story_id; 71 if(!file_exists($destination_path)) { 90 91 if (!file_exists($destination_path)) { 72 92 $destination_path = null; 73 93 } 94 95 $destination_path = apply_filters('sh_get_story_path', $destination_path, $destination); 96 74 97 return $destination_path; 75 98 } 76 99 77 function sh_get_story_url($post_id, $story_id) { 78 WP_Filesystem(); 100 function sh_get_story_url($post_id, $story_id) 101 { 102 init_WP_Filesystem(); 79 103 $destination = wp_upload_dir(); 80 104 $destination_url = $destination['url'].'/shorthand/'.$post_id.'/'.$story_id; 105 $destination_url = apply_filters('sh_get_story_url', $destination_url); 106 81 107 return $destination_url; 82 108 } 83 109 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(); 110 function 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(); 90 115 $destination = wp_upload_dir(); 91 116 $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 } 93 146 94 global $serverURL;95 $token = get_option('sh_token_key');96 $user_id = get_option('sh_user_id');97 147 98 $valid_token = false; 148 function 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 } 99 157 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' 158 function 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 128 171 ); 172 if (function_exists("wp_filesize")){ 173 $story['error']['downloaded zip size'] = wp_filesize($zip_file); 129 174 } 130 175 } 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; 136 177 } 178 } else { 179 $story['error'] = array( 180 'pretty' => 'Could not unzip file' 181 ); 137 182 } 183 138 184 return $story; 139 185 } -
shorthand-connect/trunk/includes/mass_pull.php
r2860602 r2898299 1 1 <?php 2 3 2 /* 4 3 /* Name: Update Story Meta Fields Function */ … … 6 5 /* Note: Unzipping a fresh story copy won't update the fields 7 6 */ 8 function shand_update_story($post_id, $story_id) {9 7 function shand_update_story($post_id, $story_id) 8 { 10 9 init_WP_Filesystem(); 11 10 global $wp_filesystem; … … 20 19 21 20 $err = sh_copy_story($post_id, $safe_story_id, $sh_media_cron_offload); 22 23 $sh_title = get_post_meta( $post_id, 'title', true );24 21 25 22 $story_path = sh_get_story_path($post_id, $safe_story_id); … … 39 36 update_post_meta($post_id, 'story_path', $story_path); 40 37 41 //Log any story-specific errors to the metadata 38 //Log any story-specific errors to the metadata 42 39 if(isset($err['error'])){ 43 40 update_post_meta($post_id, 'ERROR', json_encode($err)); … … 50 47 51 48 // 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'; 56 50 $article_file = $story_path . '/article.html'; 57 51 … … 87 81 88 82 } else { 89 90 83 update_post_meta($post_id, 'story_diagnostic', $err); 91 92 84 echo 'Something went wrong, please try again'; 93 85 print_r($err); … … 96 88 97 89 } 98 ?> -
shorthand-connect/trunk/includes/shorthand_options.php
r2817526 r2898299 1 1 <?php 2 3 2 /* Options */ 4 3 function shand_shorthand_menu() { 5 4 add_options_page( 'Shorthand Options', 'Shorthand', 'manage_options', 'shorthand-options', 'shand_shorthand_options' ); 6 5 } 7 8 6 $default_sh_site_css = ' 9 7 /* START CSS FOR DEFAULT WP THEMES */ … … 28 26 '; 29 27 30 function shand_shorthand_options() {31 28 function shand_shorthand_options() 29 { 32 30 global $default_sh_site_css; 33 31 global $serverURL; 34 global $serverv2URL;35 global $allowversionswitch;36 global $showServerURL;37 32 38 33 if ( !current_user_can( 'manage_options' ) ) { … … 42 37 update_option('sh_v2_token', sanitize_text_field($_POST['sh_v2_token'])); 43 38 } 44 45 39 $v2_token = esc_html(get_option('sh_v2_token')); 46 40 47 48 41 if( isset($_POST['sh_submit_hidden_two']) && $_POST['sh_submit_hidden_two'] == 'Y' && check_admin_referer( 'sh-update-configuration' ) ) { 49 42 update_option('sh_css', wp_kses_post($_POST['sh_css'])); … … 60 53 $permalink_structure = esc_html(get_option('sh_permalink')); 61 54 } 62 63 55 $sh_css = get_option('sh_css'); 64 56 $no_css = false; 65 57 if ($sh_css == '') { 66 58 $no_css = true; 67 if (isset($default_site_css)){59 if (isset($default_site_css)){ 68 60 update_option('sh_css', $default_site_css); 69 61 } … … 71 63 } 72 64 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' )) { 74 66 update_option('sh_regex_list', base64_encode(wp_unslash($_POST['sh_regex_list']))); 75 67 } … … 77 69 $sh_regex_list = base64_decode(get_option('sh_regex_list')); 78 70 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 85 81 $profile = sh_get_profile(); 86 82 $n_once = wp_nonce_field( 'sh-update-configuration' ); … … 143 139 <p><em>This Example removes title tags from within the head tag by replacing it with nothing.</em></p> 144 140 <pre><code> 145 { 141 { 146 142 "head": 147 143 [ 148 { 144 { 149 145 "query":"/<title.(.*?)<\/title>/", 150 146 "replace":"" 151 147 } 152 148 ], 153 "body":[] 149 "body":[] 154 150 } 155 156 151 </code></pre> 157 152 <form name="form2" method="post" onsubmit="padJson()"> … … 218 213 219 214 <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> 234 232 <?php 235 233 } -
shorthand-connect/trunk/shorthand_connect.php
r2860602 r2898299 3 3 /** 4 4 * @package Shorthand Connect 5 * @version 1.3.2 75 * @version 1.3.28 6 6 */ 7 7 /* … … 10 10 Description: Import your Shorthand stories into your Wordpress CMS as simply as possible - magic! 11 11 Author: Shorthand 12 Version: 1.3.2 712 Version: 1.3.28 13 13 Author URI: http://shorthand.com 14 14 */ 15 15 16 $included = @include_once('config.php'); 17 if (!$included) { 16 if (file_exists('config.php')) { 17 include_once('config.php'); 18 } else { 18 19 require_once('config.default.php'); 19 20 } 20 $version = 'v2'; 21 22 require_once('includes/api-v2.php'); 21 require_once('includes/api.php'); 23 22 require_once('includes/mass_pull.php'); 24 23 … … 70 69 function shand_wpt_shorthand_story() 71 70 { 72 73 71 global $post; 74 75 72 global $serverURL; 76 global $serverv2URL;77 73 global $showArchivedStories; 78 79 74 $baseurl = ''; 80 81 $version = 'v2';82 75 83 76 ?> … … 198 191 } 199 192 $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) { 204 198 echo 'You currently have no stories ready for publishing on Shorthand. Please check that your story is set to be ready for publishing.'; 205 199 } else { … … 213 207 } 214 208 $archived = ''; 215 if ( $version == 'v2' &&isset($story->story_version) && $story->story_version == '1') {209 if (isset($story->story_version) && $story->story_version == '1') { 216 210 if ($showArchivedStories) { 217 211 $archived = ' (archived)'; … … 279 273 function shand_add_shorthand_metaboxes() 280 274 { 281 global $version;282 275 global $post; 283 276 global $noabstract; … … 332 325 333 326 /* Save the shorthand story */ 334 function shand_save_shorthand_story($post_id, $post , $update)327 function shand_save_shorthand_story($post_id, $post) 335 328 { 336 329 WP_Filesystem(); 337 338 330 global $wp_filesystem; 339 331 340 332 if ( ! is_a( $wp_filesystem, 'WP_Filesystem_Base') ) { 341 333 $creds = request_filesystem_credentials( site_url() ); … … 355 347 } 356 348 357 if (!get_post_meta($post_id, 'no_update')) {349 if (!get_post_meta($post_id, 'no_update')) { 358 350 update_post_meta($post_id, 'no_update', "false"); 359 351 } … … 378 370 379 371 } 380 if ($sh_media_cron_offload){372 if ($sh_media_cron_offload){ 381 373 update_post_meta($post_id, 'media_status', '[Awaiting media fetch...]'); 382 374 wp_schedule_single_event(time() + 30, 'sh_media_fetch', array( $post_id, $safe_story_id )); … … 387 379 update_post_meta($post_id, 'story_path', $story_path); 388 380 389 //Log any story-specific errors to the metadata 381 //Log any story-specific errors to the metadata 390 382 if(isset($err['error'])){ 391 383 update_post_meta($post_id, 'ERROR', json_encode($err)); … … 398 390 399 391 // Save the head and body 400 $version = get_option('sh_api_version');401 update_post_meta($post_id, 'api_version', $version);402 392 $head_file = $story_path . '/head.html'; 403 393 $article_file = $story_path . '/article.html'; … … 411 401 $head = apply_filters('sh_pre_process_head', $head, $assets_path, $head_file); 412 402 413 if (isset($post_processing_queries->body)){403 if (isset($post_processing_queries->body)){ 414 404 $body = shand_post_processing($body,$post_processing_queries->body); 415 405 } 416 406 417 if (isset($post_processing_queries->head)){407 if (isset($post_processing_queries->head)){ 418 408 $head = shand_post_processing($head, $post_processing_queries->head); 419 409 } … … 496 486 function shand_shorthand_get_posts($query) 497 487 { 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 } 501 491 return $query; 502 492 } … … 512 502 513 503 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 540 504 /* Filter to fix post type tags */ 541 505 function shand_post_type_tags_fix($request) … … 561 525 562 526 563 /* UTILITY FUNCTIONS */564 565 527 /* Fix content paths */ 566 528 function shand_fix_content_paths($assets_path, $content) 567 529 { 568 569 530 $content = str_replace('./assets/', $assets_path . '/assets/', $content); 570 531 $content = str_replace('./static/', $assets_path . '/static/', $content); 571 532 $content = preg_replace('/.(\/theme-\w+.min.css)/', $assets_path . '$1', $content); 572 573 533 $content = apply_filters('shand_fix_content_paths', $content); 574 575 534 return $content; 576 535 } … … 581 540 return $content; 582 541 } 583 584 542 foreach ($queries as $query) { 585 543 if(isset($query->query) && isset($query->replace)){ … … 587 545 } 588 546 } 589 590 547 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';602 548 } 603 549 … … 620 566 } 621 567 568 function 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 622 578 /* Add "Pull Story" to post dropdown */ 623 add_filter('bulk_actions-edit-shorthand_story', function ($bulk_actions) {579 add_filter('bulk_actions-edit-shorthand_story', function ($bulk_actions) { 624 580 $bulk_actions['bulk-pull-stories'] = __('Pull Story', 'txtdomain'); 625 581 return $bulk_actions; … … 627 583 628 584 /* Pull the stories */ 629 add_filter('handle_bulk_actions-edit-shorthand_story', function ($redirect_url, $action, $post_ids) {585 add_filter('handle_bulk_actions-edit-shorthand_story', function ($redirect_url, $action, $post_ids) { 630 586 //Run on posts which have bulk-pull-stories set to true 631 587 if ($action == 'bulk-pull-stories') { … … 649 605 650 606 /* Add Notice after post has pulled */ 651 add_action('admin_notices', function () {607 add_action('admin_notices', function () { 652 608 if (!empty($_REQUEST['bulk-pulled-stories'])) { 653 609 $num_changed = (int) $_REQUEST['bulk-pulled-stories']; … … 655 611 } 656 612 }); 657 658 ?> -
shorthand-connect/trunk/templates/single-shorthand_story.php
r2009514 r2898299 1 1 <?php get_header(); 2 3 2 // 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)) { 6 4 echo get_the_password_form(); 7 8 5 } else { 9 10 6 while ( have_posts() ) : the_post(); 11 7 $meta = get_post_meta($post->ID); 12 8 ?> 13 14 9 <?php echo trim($meta['story_body'][0]); ?> 15 16 10 <div id="extraHTML"> 17 11 <?php echo trim($meta['extra_html'][0]); ?> 18 12 </div> 19 20 13 <style type="text/css"> 21 14 <?php echo get_option('sh_css'); ?> 22 15 </style> 23 24 16 <?php 25 17 endwhile; 26 27 18 } 28 29 19 get_footer();
Note: See TracChangeset
for help on using the changeset viewer.