@@ -26,18 +26,18 @@ discard block |
||
| 26 | 26 | $this->app = $app; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Imports a payload. |
|
| 31 | - * @param Writing_On_GitHub_Payload $payload |
|
| 32 | - * |
|
| 33 | - * @return string|WP_Error |
|
| 34 | - */ |
|
| 29 | + /** |
|
| 30 | + * Imports a payload. |
|
| 31 | + * @param Writing_On_GitHub_Payload $payload |
|
| 32 | + * |
|
| 33 | + * @return string|WP_Error |
|
| 34 | + */ |
|
| 35 | 35 | public function payload( Writing_On_GitHub_Payload $payload ) { |
| 36 | 36 | |
| 37 | 37 | $result = $this->app->api()->fetch()->compare( $payload->get_before_commit_id() ); |
| 38 | 38 | |
| 39 | 39 | if ( is_wp_error( $result ) ) { |
| 40 | - /* @var WP_Error $result */ |
|
| 40 | + /* @var WP_Error $result */ |
|
| 41 | 41 | return $result; |
| 42 | 42 | } |
| 43 | 43 | |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | /** |
| 54 | 54 | * import blob by files |
| 55 | 55 | * @param Writing_On_GitHub_File_Info[] $files |
| 56 | - * |
|
| 56 | + * |
|
| 57 | 57 | * @return string|WP_Error |
| 58 | 58 | */ |
| 59 | 59 | protected function import_files( $files ) { |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | $result = $this->app->api()->fetch()->tree_recursive(); |
| 93 | 93 | |
| 94 | 94 | if ( is_wp_error( $result ) ) { |
| 95 | - /* @var WP_Error $result */ |
|
| 95 | + /* @var WP_Error $result */ |
|
| 96 | 96 | return $result; |
| 97 | 97 | } |
| 98 | 98 | |
@@ -105,16 +105,16 @@ discard block |
||
| 105 | 105 | return __( 'Payload processed', 'writing-on-github' ); |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Do compare |
|
| 110 | - * @param Writing_On_GitHub_File_Info[]|WP_Error $files |
|
| 111 | - * @param int[] &$delete_ids |
|
| 112 | - * |
|
| 113 | - * @return string|WP_Error |
|
| 114 | - */ |
|
| 108 | + /** |
|
| 109 | + * Do compare |
|
| 110 | + * @param Writing_On_GitHub_File_Info[]|WP_Error $files |
|
| 111 | + * @param int[] &$delete_ids |
|
| 112 | + * |
|
| 113 | + * @return string|WP_Error |
|
| 114 | + */ |
|
| 115 | 115 | protected function compare( $files, &$delete_ids ) { |
| 116 | 116 | if ( is_wp_error( $files ) ) { |
| 117 | - /* @var WP_Error $files */ |
|
| 117 | + /* @var WP_Error $files */ |
|
| 118 | 118 | return $files; |
| 119 | 119 | } |
| 120 | 120 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * |
| 23 | 23 | * @param Writing_On_GitHub $app Application container. |
| 24 | 24 | */ |
| 25 | - public function __construct( Writing_On_GitHub $app ) { |
|
| 25 | + public function __construct(Writing_On_GitHub $app) { |
|
| 26 | 26 | $this->app = $app; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -32,22 +32,22 @@ discard block |
||
| 32 | 32 | * |
| 33 | 33 | * @return string|WP_Error |
| 34 | 34 | */ |
| 35 | - public function payload( Writing_On_GitHub_Payload $payload ) { |
|
| 35 | + public function payload(Writing_On_GitHub_Payload $payload) { |
|
| 36 | 36 | |
| 37 | - $result = $this->app->api()->fetch()->compare( $payload->get_before_commit_id() ); |
|
| 37 | + $result = $this->app->api()->fetch()->compare($payload->get_before_commit_id()); |
|
| 38 | 38 | |
| 39 | - if ( is_wp_error( $result ) ) { |
|
| 39 | + if (is_wp_error($result)) { |
|
| 40 | 40 | /* @var WP_Error $result */ |
| 41 | 41 | return $result; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - $result = $this->import_files( $result ); |
|
| 44 | + $result = $this->import_files($result); |
|
| 45 | 45 | |
| 46 | - if ( is_wp_error( $result ) ) { |
|
| 46 | + if (is_wp_error($result)) { |
|
| 47 | 47 | return $files; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - return __( 'Payload processed', 'writing-on-github' ); |
|
| 50 | + return __('Payload processed', 'writing-on-github'); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -56,23 +56,23 @@ discard block |
||
| 56 | 56 | * |
| 57 | 57 | * @return string|WP_Error |
| 58 | 58 | */ |
| 59 | - protected function import_files( $files ) { |
|
| 59 | + protected function import_files($files) { |
|
| 60 | 60 | |
| 61 | - $error = false; |
|
| 61 | + $error = false; |
|
| 62 | 62 | $delete_ids = false; |
| 63 | 63 | |
| 64 | - $result = $this->compare( $files, $delete_ids ); |
|
| 64 | + $result = $this->compare($files, $delete_ids); |
|
| 65 | 65 | |
| 66 | - if ( is_wp_error( $result ) ) { |
|
| 66 | + if (is_wp_error($result)) { |
|
| 67 | 67 | return $result; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - if ( $delete_ids ) { |
|
| 70 | + if ($delete_ids) { |
|
| 71 | 71 | foreach ($delete_ids as $id) { |
| 72 | - $result = $this->app->database()->delete_post( $id ); |
|
| 73 | - if ( is_wp_error( $result ) ) { |
|
| 74 | - if ( $error ) { |
|
| 75 | - $error->add( $result->get_error_code(), $result->get_error_message() ); |
|
| 72 | + $result = $this->app->database()->delete_post($id); |
|
| 73 | + if (is_wp_error($result)) { |
|
| 74 | + if ($error) { |
|
| 75 | + $error->add($result->get_error_code(), $result->get_error_message()); |
|
| 76 | 76 | } else { |
| 77 | 77 | $error = $result; |
| 78 | 78 | } |
@@ -91,18 +91,18 @@ discard block |
||
| 91 | 91 | public function master() { |
| 92 | 92 | $result = $this->app->api()->fetch()->tree_recursive(); |
| 93 | 93 | |
| 94 | - if ( is_wp_error( $result ) ) { |
|
| 94 | + if (is_wp_error($result)) { |
|
| 95 | 95 | /* @var WP_Error $result */ |
| 96 | 96 | return $result; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - $result = $this->import_files( $result ); |
|
| 99 | + $result = $this->import_files($result); |
|
| 100 | 100 | |
| 101 | - if ( is_wp_error( $result ) ) { |
|
| 101 | + if (is_wp_error($result)) { |
|
| 102 | 102 | return $result; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - return __( 'Payload processed', 'writing-on-github' ); |
|
| 105 | + return __('Payload processed', 'writing-on-github'); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -112,8 +112,8 @@ discard block |
||
| 112 | 112 | * |
| 113 | 113 | * @return string|WP_Error |
| 114 | 114 | */ |
| 115 | - protected function compare( $files, &$delete_ids ) { |
|
| 116 | - if ( is_wp_error( $files ) ) { |
|
| 115 | + protected function compare($files, &$delete_ids) { |
|
| 116 | + if (is_wp_error($files)) { |
|
| 117 | 117 | /* @var WP_Error $files */ |
| 118 | 118 | return $files; |
| 119 | 119 | } |
@@ -123,62 +123,62 @@ discard block |
||
| 123 | 123 | |
| 124 | 124 | $idsmap = array(); |
| 125 | 125 | |
| 126 | - foreach ( $files as $file ) { |
|
| 127 | - if ( ! $this->importable_file( $file ) ) { |
|
| 126 | + foreach ($files as $file) { |
|
| 127 | + if ( ! $this->importable_file($file)) { |
|
| 128 | 128 | continue; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - $blob = $this->app->api()->fetch()->blob( $file ); |
|
| 131 | + $blob = $this->app->api()->fetch()->blob($file); |
|
| 132 | 132 | // network error ? |
| 133 | - if ( ! $blob instanceof Writing_On_GitHub_Blob ) { |
|
| 133 | + if ( ! $blob instanceof Writing_On_GitHub_Blob) { |
|
| 134 | 134 | continue; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - if ( $this->importable_raw_file( $blob ) ) { |
|
| 138 | - $this->import_raw_file( $blob, $file->status == 'removed' ); |
|
| 137 | + if ($this->importable_raw_file($blob)) { |
|
| 138 | + $this->import_raw_file($blob, $file->status == 'removed'); |
|
| 139 | 139 | continue; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - if ( ! $this->importable_blob( $blob ) ) { |
|
| 142 | + if ( ! $this->importable_blob($blob)) { |
|
| 143 | 143 | continue; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - $post = $this->blob_to_post( $blob ); |
|
| 146 | + $post = $this->blob_to_post($blob); |
|
| 147 | 147 | |
| 148 | - if ( $file->status == 'removed' ) { |
|
| 149 | - if ( $blob->id() ) { |
|
| 148 | + if ($file->status == 'removed') { |
|
| 149 | + if ($blob->id()) { |
|
| 150 | 150 | $idsmap[$blob->id()] = true; |
| 151 | 151 | } |
| 152 | - } elseif ( $post != false ) { |
|
| 152 | + } elseif ($post != false) { |
|
| 153 | 153 | $posts[] = $post; |
| 154 | - if ( $post->is_new() ) { |
|
| 154 | + if ($post->is_new()) { |
|
| 155 | 155 | $new[] = $post; |
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - foreach ( $posts as $post ) { |
|
| 161 | - if ( $post->id() && isset( $idsmap[ $post->id() ] ) ) { |
|
| 162 | - unset( $idsmap[ $post->id() ] ); |
|
| 160 | + foreach ($posts as $post) { |
|
| 161 | + if ($post->id() && isset($idsmap[$post->id()])) { |
|
| 162 | + unset($idsmap[$post->id()]); |
|
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 | $delete_ids = array(); |
| 166 | - foreach ( $idsmap as $id => $value ) { |
|
| 166 | + foreach ($idsmap as $id => $value) { |
|
| 167 | 167 | $delete_ids[] = $id; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | // $this->app->database()->save_posts( $posts, $commit->author_email() ); |
| 171 | 171 | |
| 172 | - $result = $this->app->database()->save_posts( $posts ); |
|
| 172 | + $result = $this->app->database()->save_posts($posts); |
|
| 173 | 173 | |
| 174 | - if ( is_wp_error( $result ) ) { |
|
| 174 | + if (is_wp_error($result)) { |
|
| 175 | 175 | return $result; |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - if ( ! empty( $new ) ) { |
|
| 179 | - $result = $this->app->export()->new_posts( $new ); |
|
| 178 | + if ( ! empty($new)) { |
|
| 179 | + $result = $this->app->export()->new_posts($new); |
|
| 180 | 180 | |
| 181 | - if ( is_wp_error( $result ) ) { |
|
| 181 | + if (is_wp_error($result)) { |
|
| 182 | 182 | return $result; |
| 183 | 183 | } |
| 184 | 184 | } |
@@ -193,12 +193,12 @@ discard block |
||
| 193 | 193 | * |
| 194 | 194 | * @return bool |
| 195 | 195 | */ |
| 196 | - protected function importable_file( Writing_On_GitHub_File_Info $file ) { |
|
| 196 | + protected function importable_file(Writing_On_GitHub_File_Info $file) { |
|
| 197 | 197 | |
| 198 | 198 | // only _pages and _posts |
| 199 | - if ( strncasecmp($file->path, '_pages/', strlen('_pages/') ) != 0 && |
|
| 200 | - strncasecmp($file->path, '_posts/', strlen('_posts/') ) != 0 && |
|
| 201 | - strncasecmp($file->path, 'images/', strlen('images/') ) != 0 ) { |
|
| 199 | + if (strncasecmp($file->path, '_pages/', strlen('_pages/')) != 0 && |
|
| 200 | + strncasecmp($file->path, '_posts/', strlen('_posts/')) != 0 && |
|
| 201 | + strncasecmp($file->path, 'images/', strlen('images/')) != 0) { |
|
| 202 | 202 | return false; |
| 203 | 203 | } |
| 204 | 204 | |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * |
| 218 | 218 | * @return bool |
| 219 | 219 | */ |
| 220 | - protected function importable_blob( Writing_On_GitHub_Blob $blob ) { |
|
| 220 | + protected function importable_blob(Writing_On_GitHub_Blob $blob) { |
|
| 221 | 221 | // global $wpdb; |
| 222 | 222 | |
| 223 | 223 | // // Skip the repo's readme. |
@@ -230,20 +230,20 @@ discard block |
||
| 230 | 230 | // return false; |
| 231 | 231 | // } |
| 232 | 232 | |
| 233 | - if ( ! $blob->has_frontmatter() ) { |
|
| 233 | + if ( ! $blob->has_frontmatter()) { |
|
| 234 | 234 | return false; |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | return true; |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - protected function importable_raw_file( Writing_On_GitHub_Blob $blob ) { |
|
| 241 | - if ( $blob->has_frontmatter() ) { |
|
| 240 | + protected function importable_raw_file(Writing_On_GitHub_Blob $blob) { |
|
| 241 | + if ($blob->has_frontmatter()) { |
|
| 242 | 242 | return false; |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | // only images |
| 246 | - if ( strncasecmp($blob->path(), 'images/', strlen('images/') ) != 0) { |
|
| 246 | + if (strncasecmp($blob->path(), 'images/', strlen('images/')) != 0) { |
|
| 247 | 247 | return false; |
| 248 | 248 | } |
| 249 | 249 | |
@@ -255,16 +255,16 @@ discard block |
||
| 255 | 255 | * @param Writing_On_GitHub_Blob $blob |
| 256 | 256 | * @param bool $is_remove |
| 257 | 257 | */ |
| 258 | - protected function import_raw_file( Writing_On_GitHub_Blob $blob, $is_remove ) { |
|
| 258 | + protected function import_raw_file(Writing_On_GitHub_Blob $blob, $is_remove) { |
|
| 259 | 259 | $arr = wp_upload_dir(); |
| 260 | 260 | $path = $arr['basedir'] . '/writing-on-github/' . $blob->path(); |
| 261 | - if ( $is_remove ) { |
|
| 262 | - if ( file_exists($path) ) { |
|
| 261 | + if ($is_remove) { |
|
| 262 | + if (file_exists($path)) { |
|
| 263 | 263 | unlink($path); |
| 264 | 264 | } |
| 265 | 265 | } else { |
| 266 | 266 | $dirname = dirname($path); |
| 267 | - if ( ! file_exists($dirname) ) { |
|
| 267 | + if ( ! file_exists($dirname)) { |
|
| 268 | 268 | wp_mkdir_p($dirname); |
| 269 | 269 | } |
| 270 | 270 | |
@@ -279,57 +279,57 @@ discard block |
||
| 279 | 279 | * |
| 280 | 280 | * @return Writing_On_GitHub_Post|false |
| 281 | 281 | */ |
| 282 | - protected function blob_to_post( Writing_On_GitHub_Blob $blob ) { |
|
| 283 | - $args = array( 'post_content' => $blob->content_import() ); |
|
| 282 | + protected function blob_to_post(Writing_On_GitHub_Blob $blob) { |
|
| 283 | + $args = array('post_content' => $blob->content_import()); |
|
| 284 | 284 | $meta = $blob->meta(); |
| 285 | 285 | |
| 286 | 286 | $id = false; |
| 287 | 287 | |
| 288 | - if ( ! empty( $meta ) ) { |
|
| 289 | - if ( array_key_exists( 'layout', $meta ) ) { |
|
| 288 | + if ( ! empty($meta)) { |
|
| 289 | + if (array_key_exists('layout', $meta)) { |
|
| 290 | 290 | $args['post_type'] = $meta['layout']; |
| 291 | - unset( $meta['layout'] ); |
|
| 291 | + unset($meta['layout']); |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | - if ( array_key_exists( 'published', $meta ) ) { |
|
| 294 | + if (array_key_exists('published', $meta)) { |
|
| 295 | 295 | $args['post_status'] = true === $meta['published'] ? 'publish' : 'draft'; |
| 296 | - unset( $meta['published'] ); |
|
| 296 | + unset($meta['published']); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - if ( array_key_exists( 'post_title', $meta ) ) { |
|
| 299 | + if (array_key_exists('post_title', $meta)) { |
|
| 300 | 300 | $args['post_title'] = $meta['post_title']; |
| 301 | - unset( $meta['post_title'] ); |
|
| 301 | + unset($meta['post_title']); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | - if ( array_key_exists( 'post_name', $meta ) ) { |
|
| 304 | + if (array_key_exists('post_name', $meta)) { |
|
| 305 | 305 | $args['post_name'] = $meta['post_name']; |
| 306 | - unset( $meta['post_name'] ); |
|
| 306 | + unset($meta['post_name']); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | - if ( array_key_exists( 'ID', $meta ) ) { |
|
| 309 | + if (array_key_exists('ID', $meta)) { |
|
| 310 | 310 | $id = $args['ID'] = $meta['ID']; |
| 311 | 311 | $blob->set_id($id); |
| 312 | - unset( $meta['ID'] ); |
|
| 312 | + unset($meta['ID']); |
|
| 313 | 313 | } |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | $meta['_wogh_sha'] = $blob->sha(); |
| 317 | 317 | |
| 318 | - if ( $id ) { |
|
| 319 | - $old_sha = get_post_meta( $id, '_wogh_sha', true ); |
|
| 320 | - $old_github_path = get_post_meta( $id, '_wogh_github_path', true ); |
|
| 318 | + if ($id) { |
|
| 319 | + $old_sha = get_post_meta($id, '_wogh_sha', true); |
|
| 320 | + $old_github_path = get_post_meta($id, '_wogh_github_path', true); |
|
| 321 | 321 | |
| 322 | 322 | // dont save post when has same sha |
| 323 | - if ( $old_sha && $old_sha == $meta['_wogh_sha'] && |
|
| 324 | - $old_github_path && $old_github_path == $blob->path() ) { |
|
| 323 | + if ($old_sha && $old_sha == $meta['_wogh_sha'] && |
|
| 324 | + $old_github_path && $old_github_path == $blob->path()) { |
|
| 325 | 325 | return false; |
| 326 | 326 | } |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - $post = new Writing_On_GitHub_Post( $args, $this->app->api() ); |
|
| 330 | - $post->set_old_github_path( $blob->path() ); |
|
| 331 | - $post->set_meta( $meta ); |
|
| 332 | - $blob->set_id( $post->id() ); |
|
| 329 | + $post = new Writing_On_GitHub_Post($args, $this->app->api()); |
|
| 330 | + $post->set_old_github_path($blob->path()); |
|
| 331 | + $post->set_meta($meta); |
|
| 332 | + $blob->set_id($post->id()); |
|
| 333 | 333 | |
| 334 | 334 | return $post; |
| 335 | 335 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * |
| 35 | 35 | * @param Writing_On_GitHub $app Application container. |
| 36 | 36 | */ |
| 37 | - public function __construct( Writing_On_GitHub $app ) { |
|
| 37 | + public function __construct(Writing_On_GitHub $app) { |
|
| 38 | 38 | $this->app = $app; |
| 39 | 39 | } |
| 40 | 40 | |
@@ -49,8 +49,8 @@ discard block |
||
| 49 | 49 | $this->raw_data = $this->read_raw_data(); |
| 50 | 50 | |
| 51 | 51 | // Validate request secret. |
| 52 | - $hash = hash_hmac( 'sha1', $this->raw_data, $this->secret() ); |
|
| 53 | - if ( 'sha1=' . $hash !== $headers['X-Hub-Signature'] ) { |
|
| 52 | + $hash = hash_hmac('sha1', $this->raw_data, $this->secret()); |
|
| 53 | + if ('sha1=' . $hash !== $headers['X-Hub-Signature']) { |
|
| 54 | 54 | return false; |
| 55 | 55 | } |
| 56 | 56 | |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @return Writing_On_GitHub_Payload |
| 91 | 91 | */ |
| 92 | 92 | public function payload() { |
| 93 | - return new Writing_On_GitHub_Payload( $this->app, $this->raw_data ); |
|
| 93 | + return new Writing_On_GitHub_Payload($this->app, $this->raw_data); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -101,11 +101,11 @@ discard block |
||
| 101 | 101 | * @return array |
| 102 | 102 | */ |
| 103 | 103 | protected function headers() { |
| 104 | - if ( ! empty( $this->headers ) ) { |
|
| 104 | + if ( ! empty($this->headers)) { |
|
| 105 | 105 | return $this->headers; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - if ( function_exists( 'getallheaders' ) ) { |
|
| 108 | + if (function_exists('getallheaders')) { |
|
| 109 | 109 | |
| 110 | 110 | $this->headers = getallheaders(); |
| 111 | 111 | return $this->headers; |
@@ -115,9 +115,9 @@ discard block |
||
| 115 | 115 | * @see http://www.php.net/manual/en/function.getallheaders.php |
| 116 | 116 | */ |
| 117 | 117 | $this->headers = array(); |
| 118 | - foreach ( $_SERVER as $name => $value ) { |
|
| 119 | - if ( 'HTTP_' === substr( $name, 0, 5 ) ) { |
|
| 120 | - $this->headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value; |
|
| 118 | + foreach ($_SERVER as $name => $value) { |
|
| 119 | + if ('HTTP_' === substr($name, 0, 5)) { |
|
| 120 | + $this->headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
|
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | * @return string |
| 131 | 131 | */ |
| 132 | 132 | protected function read_raw_data() { |
| 133 | - return file_get_contents( 'php://input' ); |
|
| 133 | + return file_get_contents('php://input'); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -139,6 +139,6 @@ discard block |
||
| 139 | 139 | * @return string |
| 140 | 140 | */ |
| 141 | 141 | protected function secret() { |
| 142 | - return get_option( 'wogh_secret' ); |
|
| 142 | + return get_option('wogh_secret'); |
|
| 143 | 143 | } |
| 144 | 144 | } |
@@ -29,36 +29,36 @@ discard block |
||
| 29 | 29 | /** |
| 30 | 30 | * Updates all of the current posts in the database on master. |
| 31 | 31 | * |
| 32 | - * @param bool $force |
|
| 33 | - * |
|
| 34 | - * @return string|WP_Error |
|
| 35 | - */ |
|
| 32 | + * @param bool $force |
|
| 33 | + * |
|
| 34 | + * @return string|WP_Error |
|
| 35 | + */ |
|
| 36 | 36 | public function full( $force = false ) { |
| 37 | 37 | $posts = $this->app->database()->fetch_all_supported( $force ); |
| 38 | 38 | |
| 39 | 39 | if ( is_wp_error( $posts ) ) { |
| 40 | - /* @var WP_Error $posts */ |
|
| 40 | + /* @var WP_Error $posts */ |
|
| 41 | 41 | return $posts; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - $error = false; |
|
| 44 | + $error = false; |
|
| 45 | 45 | |
| 46 | - foreach ( $posts as $post ) { |
|
| 47 | - $result = $this->update( $post->id() ); |
|
| 48 | - if ( is_wp_error( $result ) ) { |
|
| 49 | - if ( $error ) { |
|
| 50 | - $error->add( $result->get_error_code(), $result->get_error_message() ); |
|
| 51 | - } else { |
|
| 52 | - $error = $result; |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - } |
|
| 46 | + foreach ( $posts as $post ) { |
|
| 47 | + $result = $this->update( $post->id() ); |
|
| 48 | + if ( is_wp_error( $result ) ) { |
|
| 49 | + if ( $error ) { |
|
| 50 | + $error->add( $result->get_error_code(), $result->get_error_message() ); |
|
| 51 | + } else { |
|
| 52 | + $error = $result; |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - if ( is_wp_error( $error ) ) { |
|
| 58 | - return $error; |
|
| 59 | - } |
|
| 57 | + if ( is_wp_error( $error ) ) { |
|
| 58 | + return $error; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
| 61 | + return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | $post = $this->app->database()->fetch_by_id( $post_id ); |
| 89 | 89 | |
| 90 | 90 | if ( is_wp_error( $post ) ) { |
| 91 | - /* @var WP_Error $post */ |
|
| 91 | + /* @var WP_Error $post */ |
|
| 92 | 92 | return $post; |
| 93 | 93 | } |
| 94 | 94 | |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | $result = $this->new_posts( array( $post ) ); |
| 105 | 105 | |
| 106 | 106 | if ( is_wp_error( $result ) ) { |
| 107 | - /* @var WP_Error $result */ |
|
| 107 | + /* @var WP_Error $result */ |
|
| 108 | 108 | return $result; |
| 109 | 109 | } |
| 110 | 110 | |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | return $error; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
| 141 | + return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | protected function new_post( $post, $persist ) { |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | $post = $this->app->database()->fetch_by_id( $post_id ); |
| 219 | 219 | |
| 220 | 220 | if ( is_wp_error( $post ) ) { |
| 221 | - /* @var WP_Error $post */ |
|
| 221 | + /* @var WP_Error $post */ |
|
| 222 | 222 | return $post; |
| 223 | 223 | } |
| 224 | 224 | |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | $result = $this->app->api()->persist()->delete_file( $github_path, $post->sha(), $message ); |
| 239 | 239 | |
| 240 | 240 | if ( is_wp_error( $result ) ) { |
| 241 | - /* @var WP_Error $result */ |
|
| 241 | + /* @var WP_Error $result */ |
|
| 242 | 242 | return $result; |
| 243 | 243 | } |
| 244 | 244 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * |
| 23 | 23 | * @param Writing_On_GitHub $app Application container. |
| 24 | 24 | */ |
| 25 | - public function __construct( Writing_On_GitHub $app ) { |
|
| 25 | + public function __construct(Writing_On_GitHub $app) { |
|
| 26 | 26 | $this->app = $app; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -33,32 +33,32 @@ discard block |
||
| 33 | 33 | * |
| 34 | 34 | * @return string|WP_Error |
| 35 | 35 | */ |
| 36 | - public function full( $force = false ) { |
|
| 37 | - $posts = $this->app->database()->fetch_all_supported( $force ); |
|
| 36 | + public function full($force = false) { |
|
| 37 | + $posts = $this->app->database()->fetch_all_supported($force); |
|
| 38 | 38 | |
| 39 | - if ( is_wp_error( $posts ) ) { |
|
| 39 | + if (is_wp_error($posts)) { |
|
| 40 | 40 | /* @var WP_Error $posts */ |
| 41 | 41 | return $posts; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | $error = false; |
| 45 | 45 | |
| 46 | - foreach ( $posts as $post ) { |
|
| 47 | - $result = $this->update( $post->id() ); |
|
| 48 | - if ( is_wp_error( $result ) ) { |
|
| 49 | - if ( $error ) { |
|
| 50 | - $error->add( $result->get_error_code(), $result->get_error_message() ); |
|
| 46 | + foreach ($posts as $post) { |
|
| 47 | + $result = $this->update($post->id()); |
|
| 48 | + if (is_wp_error($result)) { |
|
| 49 | + if ($error) { |
|
| 50 | + $error->add($result->get_error_code(), $result->get_error_message()); |
|
| 51 | 51 | } else { |
| 52 | 52 | $error = $result; |
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - if ( is_wp_error( $error ) ) { |
|
| 57 | + if (is_wp_error($error)) { |
|
| 58 | 58 | return $error; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
| 61 | + return __('Export to GitHub completed successfully.', 'writing-on-github'); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | |
@@ -67,10 +67,10 @@ discard block |
||
| 67 | 67 | * @param int $post_id |
| 68 | 68 | * @return boolean |
| 69 | 69 | */ |
| 70 | - protected function github_path( $post_id ) { |
|
| 71 | - $github_path = get_post_meta( $post_id, '_wogh_github_path', true ); |
|
| 70 | + protected function github_path($post_id) { |
|
| 71 | + $github_path = get_post_meta($post_id, '_wogh_github_path', true); |
|
| 72 | 72 | |
| 73 | - if ( $github_path && $this->app->api()->fetch()->exists( $github_path ) ) { |
|
| 73 | + if ($github_path && $this->app->api()->fetch()->exists($github_path)) { |
|
| 74 | 74 | return $github_path; |
| 75 | 75 | } |
| 76 | 76 | |
@@ -84,31 +84,31 @@ discard block |
||
| 84 | 84 | * |
| 85 | 85 | * @return string|WP_Error |
| 86 | 86 | */ |
| 87 | - public function update( $post_id ) { |
|
| 88 | - $post = $this->app->database()->fetch_by_id( $post_id ); |
|
| 87 | + public function update($post_id) { |
|
| 88 | + $post = $this->app->database()->fetch_by_id($post_id); |
|
| 89 | 89 | |
| 90 | - if ( is_wp_error( $post ) ) { |
|
| 90 | + if (is_wp_error($post)) { |
|
| 91 | 91 | /* @var WP_Error $post */ |
| 92 | 92 | return $post; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - if ( 'trash' === $post->status() ) { |
|
| 96 | - return $this->delete( $post_id ); |
|
| 95 | + if ('trash' === $post->status()) { |
|
| 96 | + return $this->delete($post_id); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - if ( $old_github_path = $this->github_path( $post->id() ) ) { |
|
| 99 | + if ($old_github_path = $this->github_path($post->id())) { |
|
| 100 | 100 | error_log("old_github_path: $old_github_path"); |
| 101 | 101 | $post->set_old_github_path($old_github_path); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - $result = $this->new_posts( array( $post ) ); |
|
| 104 | + $result = $this->new_posts(array($post)); |
|
| 105 | 105 | |
| 106 | - if ( is_wp_error( $result ) ) { |
|
| 106 | + if (is_wp_error($result)) { |
|
| 107 | 107 | /* @var WP_Error $result */ |
| 108 | 108 | return $result; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
| 111 | + return __('Export to GitHub completed successfully.', 'writing-on-github'); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -118,36 +118,36 @@ discard block |
||
| 118 | 118 | * |
| 119 | 119 | * @return string|WP_Error |
| 120 | 120 | */ |
| 121 | - public function new_posts( array $posts ) { |
|
| 121 | + public function new_posts(array $posts) { |
|
| 122 | 122 | $error = false; |
| 123 | 123 | |
| 124 | 124 | $persist = $this->app->api()->persist(); |
| 125 | 125 | |
| 126 | - foreach ( $posts as $post ) { |
|
| 127 | - $result = $this->new_post( $post, $persist ); |
|
| 128 | - if ( is_wp_error( $result ) ) { |
|
| 129 | - if ( $error ) { |
|
| 130 | - $error->add( $result->get_error_code(), $result->get_error_message() ); |
|
| 126 | + foreach ($posts as $post) { |
|
| 127 | + $result = $this->new_post($post, $persist); |
|
| 128 | + if (is_wp_error($result)) { |
|
| 129 | + if ($error) { |
|
| 130 | + $error->add($result->get_error_code(), $result->get_error_message()); |
|
| 131 | 131 | } else { |
| 132 | 132 | $error = $result; |
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - if ( is_wp_error( $error ) ) { |
|
| 137 | + if (is_wp_error($error)) { |
|
| 138 | 138 | return $error; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
| 141 | + return __('Export to GitHub completed successfully.', 'writing-on-github'); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - protected function new_post( $post, $persist ) { |
|
| 144 | + protected function new_post($post, $persist) { |
|
| 145 | 145 | $github_path = $post->github_path(); |
| 146 | 146 | $old_github_path = $post->old_github_path(); |
| 147 | 147 | $blob = $post->to_blob(); |
| 148 | 148 | $result = false; |
| 149 | 149 | |
| 150 | - if ( $old_github_path && $old_github_path != $github_path ) { |
|
| 150 | + if ($old_github_path && $old_github_path != $github_path) { |
|
| 151 | 151 | // rename |
| 152 | 152 | $message = apply_filters( |
| 153 | 153 | 'wogh_commit_msg_move_post', |
@@ -155,20 +155,20 @@ discard block |
||
| 155 | 155 | 'Move %s to %s via WordPress at %s (%s)', |
| 156 | 156 | $old_github_path, $github_path, |
| 157 | 157 | site_url(), |
| 158 | - get_bloginfo( 'name' ) |
|
| 158 | + get_bloginfo('name') |
|
| 159 | 159 | ) |
| 160 | 160 | ) . $this->get_commit_msg_tag(); |
| 161 | 161 | |
| 162 | - $result = $persist->delete_file( $post->old_github_path(), $blob->sha(), $message ); |
|
| 163 | - if ( is_wp_error( $result ) ) { |
|
| 162 | + $result = $persist->delete_file($post->old_github_path(), $blob->sha(), $message); |
|
| 163 | + if (is_wp_error($result)) { |
|
| 164 | 164 | return $result; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - $result = $persist->create_file( $blob, $message ); |
|
| 168 | - if ( is_wp_error( $result ) ) { |
|
| 167 | + $result = $persist->create_file($blob, $message); |
|
| 168 | + if (is_wp_error($result)) { |
|
| 169 | 169 | return $result; |
| 170 | 170 | } |
| 171 | - } elseif ( ! $old_github_path ) { |
|
| 171 | + } elseif ( ! $old_github_path) { |
|
| 172 | 172 | // create new |
| 173 | 173 | $message = apply_filters( |
| 174 | 174 | 'wogh_commit_msg_new_post', |
@@ -176,14 +176,14 @@ discard block |
||
| 176 | 176 | 'Create new post %s from WordPress at %s (%s)', |
| 177 | 177 | $github_path, |
| 178 | 178 | site_url(), |
| 179 | - get_bloginfo( 'name' ) |
|
| 179 | + get_bloginfo('name') |
|
| 180 | 180 | ) |
| 181 | 181 | ) . $this->get_commit_msg_tag(); |
| 182 | - $result = $persist->create_file( $blob, $message ); |
|
| 183 | - if ( is_wp_error( $result ) ) { |
|
| 182 | + $result = $persist->create_file($blob, $message); |
|
| 183 | + if (is_wp_error($result)) { |
|
| 184 | 184 | return $result; |
| 185 | 185 | } |
| 186 | - } elseif ( $old_github_path && $old_github_path == $github_path ) { |
|
| 186 | + } elseif ($old_github_path && $old_github_path == $github_path) { |
|
| 187 | 187 | // update |
| 188 | 188 | $message = apply_filters( |
| 189 | 189 | 'wogh_commit_msg_update_post', |
@@ -191,11 +191,11 @@ discard block |
||
| 191 | 191 | 'Update post %s from WordPress at %s (%s)', |
| 192 | 192 | $github_path, |
| 193 | 193 | site_url(), |
| 194 | - get_bloginfo( 'name' ) |
|
| 194 | + get_bloginfo('name') |
|
| 195 | 195 | ) |
| 196 | 196 | ) . $this->get_commit_msg_tag(); |
| 197 | - $result = $persist->update_file( $blob, $message ); |
|
| 198 | - if ( is_wp_error( $result ) ) { |
|
| 197 | + $result = $persist->update_file($blob, $message); |
|
| 198 | + if (is_wp_error($result)) { |
|
| 199 | 199 | return $result; |
| 200 | 200 | } |
| 201 | 201 | } |
@@ -214,15 +214,15 @@ discard block |
||
| 214 | 214 | * |
| 215 | 215 | * @return string|WP_Error |
| 216 | 216 | */ |
| 217 | - public function delete( $post_id ) { |
|
| 218 | - $post = $this->app->database()->fetch_by_id( $post_id ); |
|
| 217 | + public function delete($post_id) { |
|
| 218 | + $post = $this->app->database()->fetch_by_id($post_id); |
|
| 219 | 219 | |
| 220 | - if ( is_wp_error( $post ) ) { |
|
| 220 | + if (is_wp_error($post)) { |
|
| 221 | 221 | /* @var WP_Error $post */ |
| 222 | 222 | return $post; |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | - $github_path = get_post_meta( $post_id, '_wogh_github_path', true ); |
|
| 225 | + $github_path = get_post_meta($post_id, '_wogh_github_path', true); |
|
| 226 | 226 | |
| 227 | 227 | $message = apply_filters( |
| 228 | 228 | 'wogh_commit_msg_delete', |
@@ -230,19 +230,19 @@ discard block |
||
| 230 | 230 | 'Deleting %s via WordPress at %s (%s)', |
| 231 | 231 | $github_path, |
| 232 | 232 | site_url(), |
| 233 | - get_bloginfo( 'name' ) |
|
| 233 | + get_bloginfo('name') |
|
| 234 | 234 | ), |
| 235 | 235 | $post |
| 236 | 236 | ) . $this->get_commit_msg_tag(); |
| 237 | 237 | |
| 238 | - $result = $this->app->api()->persist()->delete_file( $github_path, $post->sha(), $message ); |
|
| 238 | + $result = $this->app->api()->persist()->delete_file($github_path, $post->sha(), $message); |
|
| 239 | 239 | |
| 240 | - if ( is_wp_error( $result ) ) { |
|
| 240 | + if (is_wp_error($result)) { |
|
| 241 | 241 | /* @var WP_Error $result */ |
| 242 | 242 | return $result; |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
| 245 | + return __('Export to GitHub completed successfully.', 'writing-on-github'); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | |
@@ -253,8 +253,8 @@ discard block |
||
| 253 | 253 | * |
| 254 | 254 | * @return bool |
| 255 | 255 | */ |
| 256 | - public function set_user( $user_id ) { |
|
| 257 | - return update_option( self::EXPORT_USER_OPTION, (int) $user_id ); |
|
| 256 | + public function set_user($user_id) { |
|
| 257 | + return update_option(self::EXPORT_USER_OPTION, (int) $user_id); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | /** |
@@ -263,10 +263,10 @@ discard block |
||
| 263 | 263 | * @return string |
| 264 | 264 | */ |
| 265 | 265 | protected function get_commit_msg_tag() { |
| 266 | - $tag = apply_filters( 'wogh_commit_msg_tag', 'wogh' ); |
|
| 266 | + $tag = apply_filters('wogh_commit_msg_tag', 'wogh'); |
|
| 267 | 267 | |
| 268 | - if ( ! $tag ) { |
|
| 269 | - throw new Exception( __( 'Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github' ) ); |
|
| 268 | + if ( ! $tag) { |
|
| 269 | + throw new Exception(__('Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github')); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | return ' - ' . $tag; |