Changeset 2483930
- Timestamp:
- 03/02/2021 12:45:03 AM (5 years ago)
- Location:
- shorthand-connect/trunk
- Files:
-
- 6 edited
-
README.txt (modified) (1 diff)
-
config.default.php (modified) (1 diff)
-
includes/api-v2.php (modified) (3 diffs)
-
includes/api.php (modified) (1 diff)
-
shorthand_connect.php (modified) (2 diffs)
-
templates/abstract.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
shorthand-connect/trunk/README.txt
r2375587 r2483930 5 5 Requires at least: 4 6 6 Tested up to: 5.0.3 7 Stable tag: 1.3. 67 Stable tag: 1.3.7 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html -
shorthand-connect/trunk/config.default.php
r2026714 r2483930 12 12 $noabstract = false; 13 13 } 14 15 ?> -
shorthand-connect/trunk/includes/api-v2.php
r2009514 r2483930 3 3 // VERSION 2 API 4 4 5 function sh_get_profile() { 6 5 function sh_v2_api_get($url, $options) { 7 6 global $serverv2URL; 8 7 $token = get_option('sh_v2_token'); 9 8 10 $tokeninfo = array(); 9 if (!$token) { 10 return false; 11 } 11 12 12 if($token) {13 $url = $serverv2URL.'/v2/token-info';14 $response = wp_remote_get( $url,array(15 headers=> array(13 $url = $serverv2URL.$url; 14 $request_options = array_merge( 15 array( 16 'headers' => array( 16 17 'Authorization' => 'Token '.$token, 17 18 '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', 18 19 ) 19 ) ); 20 $body = wp_remote_retrieve_body( $response ); 21 $data = json_decode($body); 22 if(isset($data) && isset($data->name)) { 23 $tokeninfo['username'] = $data->name . ' ('.$data->token_type.' Token)'; 24 $tokeninfo['gravatar'] = $data->logo; 25 $tokeninfo = (object)$tokeninfo; 26 } 20 ), 21 $options 22 ); 23 24 return wp_remote_get($url, $request_options); 25 } 26 27 function sh_v2_api_get_json($url, $options) { 28 $response = sh_v2_api_get($url, $options); 29 $body = wp_remote_retrieve_body($response); 30 return json_decode($body); 31 } 32 33 function sh_get_profile() { 34 $tokeninfo = array(); 35 36 $data = sh_v2_api_get_json('/v2/token-info', array()); 37 if ($data && isset($data->name)) { 38 $tokeninfo['username'] = $data->name . ' ('.$data->token_type.' Token)'; 39 $tokeninfo['gravatar'] = $data->logo; 40 $tokeninfo = (object)$tokeninfo; 27 41 } 28 42 … … 31 45 32 46 function sh_get_stories() { 33 global $serverv2URL;34 $token = get_option('sh_v2_token');35 36 $valid_token = true;37 38 47 $stories = null; 39 48 40 //Attempt to connect to the server 41 if($token) { 42 $url = $serverv2URL.'/v2/stories'; 43 $response = wp_remote_get( $url, array( 44 'headers' => array( 45 'Authorization' => 'Token '.$token, 46 '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', 47 ), 48 'timeout' => '240' 49 ) ); 50 $body = wp_remote_retrieve_body( $response ); 51 $data = json_decode($body); 52 if(isset($data)) { 53 $stories = array(); 54 $valid_token = true; 55 //Something went wrong 56 if ($data->status) { 57 return null; 58 } 59 foreach($data as $storydata) { 60 $story = array( 61 'image' => $storydata->cover, 62 'id' => $storydata->id, 63 'metadata' => (object)array( 64 'description' => $storydata->description 65 ), 66 'title' => $storydata->title, 67 'story_version' => ''.$storydata->version 68 ); 69 $stories[] = (object)$story; 70 } 49 $data = sh_v2_api_get_json('/v2/stories', array('timeout' => '240')); 50 if($data) { 51 $stories = array(); 52 //Something went wrong 53 if ($data->status) { 54 return null; 55 } 56 foreach($data as $storydata) { 57 $story = array( 58 'image' => $storydata->cover, 59 'id' => $storydata->id, 60 'metadata' => (object)array( 61 'description' => $storydata->description 62 ), 63 'title' => $storydata->title, 64 'story_version' => ''.$storydata->version 65 ); 66 $stories[] = (object)$story; 71 67 } 72 68 } 69 73 70 return $stories; 74 71 } … … 102 99 $destination_path = $destination['path'].'/shorthand/'.$post_id; 103 100 104 global $serverv2URL;105 $token = get_option('sh_v2_token');106 107 $valid_token = false;108 109 101 $story = array(); 110 102 111 103 //Attempt to connect to the server 112 if($token) { 113 $url = $serverv2URL.'/v2/stories/'.$story_id; 114 $zipfile = tempnam($tmpdir, 'sh_zip'); 115 $unzipdir = tempnam($tmpdir, 'sh_unzip').'_dir'; 116 $response = wp_remote_get( $url, array( 117 'headers' => array( 118 'Authorization' => 'Token '.$token, 119 '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', 120 ), 121 'timeout' => '600', 122 'stream' => true, 123 'filename' => $zipfile 124 ) ); 125 if($response['response']['code'] == 200) { 126 $unzipfile = unzip_file( $zipfile, $unzipdir); 127 if ( $unzipfile == 1 ) { 128 wp_mkdir_p($destination_path.'/'.$story_id); 129 $err = copy_dir($unzipdir, $destination_path.'/'.$story_id); 130 $story['path'] = $destination_path.'/'.$story_id; 131 } else { 132 $story['error'] = array( 104 $zipfile = tempnam($tmpdir, 'sh_zip'); 105 $unzipdir = tempnam($tmpdir, 'sh_unzip').'_dir'; 106 $response = sh_v2_api_get('/v2/stories/'.$story_id, array( 107 'timeout' => '600', 108 'stream' => true, 109 'filename' => $zipfile 110 )); 111 if($response['response']['code'] == 200) { 112 $unzipfile = unzip_file( $zipfile, $unzipdir); 113 if ( $unzipfile == 1 ) { 114 wp_mkdir_p($destination_path.'/'.$story_id); 115 $err = copy_dir($unzipdir, $destination_path.'/'.$story_id); 116 $story['path'] = $destination_path.'/'.$story_id; 117 } else { 118 $story['error'] = array( 133 119 'pretty' => 'Could not unzip file' 134 120 ); 135 } 136 } else { 137 $story['error'] = array( 138 'pretty' => 'Could not get zip file', 139 'error' => curl_error($ch), 140 'response' => $response 141 ); 142 } 121 } 122 } else { 123 $story['error'] = array( 124 'pretty' => 'Could not get zip file', 125 'response' => $response 126 ); 143 127 } 128 144 129 return $story; 145 130 } 146 147 ?> -
shorthand-connect/trunk/includes/api.php
r2009514 r2483930 138 138 return $story; 139 139 } 140 141 ?> -
shorthand-connect/trunk/shorthand_connect.php
r2375587 r2483930 3 3 /** 4 4 * @package Shorthand Connect 5 * @version 1.3. 65 * @version 1.3.7 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. 612 Version: 1.3.7 13 13 Author URI: http://shorthand.com 14 14 */ -
shorthand-connect/trunk/templates/abstract.php
r1522745 r2483930 9 9 return $abstract; 10 10 } 11 12 ?>
Note: See TracChangeset
for help on using the changeset viewer.