Changeset 1862235
- Timestamp:
- 04/21/2018 12:55:26 PM (8 years ago)
- Location:
- tistorywriter/trunk
- Files:
-
- 4 edited
-
assets/pages/metabox.php (modified) (1 diff)
-
features/api_manager.php (modified) (8 diffs)
-
readme.txt (modified) (2 diffs)
-
tistorywriter.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
tistorywriter/trunk/assets/pages/metabox.php
r1846025 r1862235 47 47 $account = $api_mgr->getBlogAccount(); 48 48 if (!isset($account)) { 49 echo "Access 토큰이 정상적으로 발급되지 않았습니다 .";49 echo "Access 토큰이 정상적으로 발급되지 않았습니다jf."; 50 50 } else { 51 51 echo esc_html($account); -
tistorywriter/trunk/features/api_manager.php
r1859195 r1862235 39 39 'access_token' => get_option(OPTION_KEY\ACCESS_TOKEN) 40 40 ); 41 42 $xml = $this->requestPost($url, $data); 43 if ($xml == null) { 44 if (method_exists('\\tistory_writer\\Logger', 'log')) { 45 Logger::log("getPostInfoWithTitle, Request에 실패했습니다."); 46 return false; 47 } 48 } 49 50 return true; 51 } 52 53 public function getBlogAccount() 54 { 55 $url = 'https://www.tistory.com/apis/blog/info'; 56 $data = array( 57 'access_token' => get_option(OPTION_KEY\ACCESS_TOKEN) 58 ); 59 60 $xml = $this->requestPost($url, $data); 61 if ($xml == null) { 62 if (method_exists('\\tistory_writer\\Logger', 'log')) { 63 Logger::log("getPostInfoWithTitle, Request에 실패했습니다."); 64 } 65 return null; 66 } 67 68 return $xml->item->id; 69 } 70 71 public function requestPost($url, $data) 72 { 73 // Step 1. POST 74 $response = wp_remote_post($url, array( 75 'body' => $data, 76 'output' => 'xml', 77 )); 78 79 $body = wp_remote_retrieve_body($response); 80 $xml = simplexml_load_string($body); 81 82 if ($xml != null && $xml->status == 200) { 83 return $xml; 84 } 85 86 // Try 2. GET 87 $xml = $this->requestGet($url, $data); 88 if ($xml != null && $xml->status == 200) { 89 return $xml; 90 } 91 92 // Try 3. Request - RAW 93 $xml = $this->requestFallback($url, $data); 94 if ($xml != null && $xml->status == 200) { 95 return $xml; 96 } else { 97 return null; 98 } 99 } 100 101 public function requestFallback($url, $data) 102 { 41 103 $response = wp_remote_request($url, array( 42 104 'body' => $data, 43 105 'output' => 'xml', 44 106 )); 107 45 108 $body = wp_remote_retrieve_body($response); 46 109 $xml = simplexml_load_string($body); 47 110 48 if ($xml->status == 200) { 49 return true; 50 } else { 51 return false; 52 } 53 } 54 55 public function getBlogAccount() 56 { 57 $url = 'https://www.tistory.com/apis/blog/info'; 58 $data = array( 59 'access_token' => get_option(OPTION_KEY\ACCESS_TOKEN) 60 ); 61 $response = wp_remote_request($url, array( 111 if ($xml != null && $xml->status == 200) { 112 return $xml; 113 } else { 114 return null; 115 } 116 } 117 118 public function requestGet($url, $data) 119 { 120 $response = wp_remote_get($url, array( 62 121 'body' => $data, 63 122 'output' => 'xml', 64 123 )); 124 65 125 $body = wp_remote_retrieve_body($response); 66 126 $xml = simplexml_load_string($body); 67 127 68 return $xml->item->id; 128 if ($xml != null && $xml->status == 200) { 129 return $xml; 130 } else { 131 return null; 132 } 69 133 } 70 134 … … 77 141 'targetUrl' => get_option(OPTION_KEY\BLOG_NAME), 78 142 ); 79 $response = wp_remote_request($url, array( 80 'body' => $data,81 'output' => 'xml',82 ));83 $body = wp_remote_retrieve_body($response);84 $xml = simplexml_load_string($body); 143 144 $xml = $this->requestPost($url, $data); 145 if ($xml == null) { 146 return null; 147 } 148 85 149 $array = json_decode(json_encode((array)$xml->item->categories), true); 86 150 return $array; … … 102 166 'tag' => $tag 103 167 ); 104 $response = wp_remote_post($url, array( 105 'body' => $data, 106 'output' => 'xml', 107 )); 168 169 $this->requestPost($url, $data); 108 170 } 109 171 … … 127 189 'tag' => $tag, 128 190 ); 129 $response = wp_remote_post($url, array( 130 'body' => $data, 131 'output' => 'xml', 132 )); 191 192 $this->requestPost($url, $data); 133 193 } 134 194 } … … 143 203 'sort' => 'date', 144 204 ); 145 $response = wp_remote_post($url, array( 146 'body' => $data, 147 'output' => 'xml', 148 )); 149 $rValue = ""; 150 151 $body = wp_remote_retrieve_body($response); 152 $xml = simplexml_load_string($body); 205 206 $xml = $this->requestPost($url, $data); 207 if ($xml == null) { 208 if (method_exists('\\tistory_writer\\Logger', 'log')) { 209 Logger::log("getPostInfoWithTitle, Request에 실패했습니다."); 210 return; 211 } 212 } 213 153 214 $posts = json_decode(json_encode((array)$xml->item->posts), true); 154 215 155 foreach ($posts as $k => $v) { 156 foreach ($v as $key => $value) { 157 if (stripslashes($value['title']) === stripslashes($title)) { 158 $id = $value['id']; 216 if (is_array($posts) && isset($posts)) { 217 foreach ($posts as $k => $v) { 218 if (is_array($v) && isset($v)) { 219 foreach ($v as $key => $value) { 220 if (stripslashes($value['title']) === stripslashes($title)) { 221 $id = $value['id']; 222 } 223 } 224 } else { 225 if (method_exists('\\tistory_writer\\Logger', 'log')) { 226 Logger::log("getPostIdWithTitle, 얻어온 post id 값 이상"); 227 } 159 228 } 160 } 161 } 229 } // foreach ($post as $k => $v) ends here 230 } // if statement ends here 162 231 } 163 232 … … 171 240 'sort' => 'date', 172 241 ); 173 $response = wp_remote_request($url, array( 174 'body' => $data, 175 'output' => 'xml', 176 )); 177 $rValue = ""; 178 179 $body = wp_remote_retrieve_body($response); 180 $xml = simplexml_load_string($body); 242 243 $xml = $this->requestPost($url, $data); 244 if ($xml == null) { 245 if (method_exists('\\tistory_writer\\Logger', 'log')) { 246 Logger::log("getPostInfoWithTitle, Request에 실패했습니다."); 247 } 248 return; 249 } 250 181 251 $posts = json_decode(json_encode((array)$xml->item->posts), true); 182 252 183 foreach ($posts as $k => $v) { 184 foreach ($v as $key => $value) { 185 if ($this->decodeCharacters(stripslashes($value['title'])) === $this->decodeCharacters(stripslashes($title))) { 186 return array( 187 'id' => $value['id'], 188 'url' => $value['postUrl'], 189 'date' => $value['date'], 190 'visibility' => $value['visibility'], 191 'category_id' => $value['categoryId'], 192 ); 253 if (is_array($posts) && isset($posts)) { 254 foreach ($posts as $k => $v) { 255 if (is_array($v) && isset($v)) { 256 foreach ($v as $key => $value) { 257 if ($this->decodeCharacters(stripslashes($value['title'])) === $this->decodeCharacters(stripslashes($title))) { 258 return array( 259 'id' => $value['id'], 260 'url' => $value['postUrl'], 261 'date' => $value['date'], 262 'visibility' => $value['visibility'], 263 'category_id' => $value['categoryId'], 264 ); 265 } 266 } 267 } else { 268 if (method_exists('\\tistory_writer\\Logger', 'log')) { 269 Logger::log("getPostInfoWithTitle, 얻어온 post 반환값 이상"); 270 } 193 271 } 194 272 } … … 211 289 ); 212 290 213 $ response = wp_remote_request($url, array(214 'body' => $data,215 'output' => 'xml',216 ));217 218 $body = wp_remote_retrieve_body($response);219 $xml = simplexml_load_string($body);291 $xml = $this->requestPost($url, $data); 292 if ($xml == null) { 293 if (method_exists('\\tistory_writer\\Logger', 'log')) { 294 Logger::log("getPostInfoWithTitle, Request에 실패했습니다."); 295 } 296 return null; 297 } 220 298 return $xml->item->acceptComment; 221 299 } … … 231 309 ); 232 310 233 $ response = wp_remote_request($url, array(234 'body' => $data,235 'output' => 'xml',236 ));237 238 $body = wp_remote_retrieve_body($response);239 $xml = simplexml_load_string($body);311 $xml = $this->requestPost($url, $data); 312 if ($xml == null) { 313 if (method_exists('\\tistory_writer\\Logger', 'log')) { 314 Logger::log("getPostInfoWithTitle, Request에 실패했습니다."); 315 } 316 return null; 317 } 240 318 241 319 $tags = json_decode(json_encode((array)$xml->item->tags), true); -
tistorywriter/trunk/readme.txt
r1859197 r1862235 4 4 Tags: content, tistory, development, integration 5 5 Requires at least: 1.5 6 Tested up to: 4. 1.17 Stable tag: 1.0. 16 Tested up to: 4.9.5 7 Stable tag: 1.0.2 8 8 License: MIT License 9 9 License URI: https://mit-license.org/ … … 42 42 43 43 == Changelog == 44 = 1.0.2 = 45 * 포스팅 글 작성 중 자동 저장 시마다 블로그에 글 포스팅되는 결함 해결 46 * 플러그인 내 API 사용 방식 개선 47 44 48 = 1.0.1 = 45 49 * 티스토리 연동 문제 수정 -
tistorywriter/trunk/tistorywriter.php
r1859202 r1862235 256 256 $postId = wp_kses_post($_POST['postId']); 257 257 258 $apiMgr->updatePost($title, $content, $visibility, $category_id, $isProtected, $isAllowComment, $tag, $postId); 258 if (!wp_is_post_autosave($postId)) { 259 $apiMgr->updatePost($title, $content, $visibility, $category_id, $isProtected, $isAllowComment, $tag, $postId); 260 } 259 261 } 260 262 }
Note: See TracChangeset
for help on using the changeset viewer.