@@ -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,30 +33,30 @@ 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 = ''; |
| 45 | 45 | |
| 46 | - foreach ( $posts as $post ) { |
|
| 47 | - $result = $this->update( $post->id() ); |
|
| 48 | - if ( is_wp_error( $result ) ) { |
|
| 46 | + foreach ($posts as $post) { |
|
| 47 | + $result = $this->update($post->id()); |
|
| 48 | + if (is_wp_error($result)) { |
|
| 49 | 49 | /* @var WP_Error $result */ |
| 50 | - $error = wogh_append_error( $error, $result ); |
|
| 50 | + $error = wogh_append_error($error, $result); |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - if ( is_wp_error( $error ) ) { |
|
| 54 | + if (is_wp_error($error)) { |
|
| 55 | 55 | /* @var WP_Error $error */ |
| 56 | 56 | return $error; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
| 59 | + return __('Export to GitHub completed successfully.', 'writing-on-github'); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | |
@@ -65,10 +65,10 @@ discard block |
||
| 65 | 65 | * @param int $post_id |
| 66 | 66 | * @return boolean |
| 67 | 67 | */ |
| 68 | - protected function github_path( $post_id ) { |
|
| 69 | - $github_path = get_post_meta( $post_id, '_wogh_github_path', true ); |
|
| 68 | + protected function github_path($post_id) { |
|
| 69 | + $github_path = get_post_meta($post_id, '_wogh_github_path', true); |
|
| 70 | 70 | |
| 71 | - if ( $github_path && $this->app->api()->fetch()->exists( $github_path ) ) { |
|
| 71 | + if ($github_path && $this->app->api()->fetch()->exists($github_path)) { |
|
| 72 | 72 | return $github_path; |
| 73 | 73 | } |
| 74 | 74 | |
@@ -82,31 +82,31 @@ discard block |
||
| 82 | 82 | * |
| 83 | 83 | * @return string|WP_Error |
| 84 | 84 | */ |
| 85 | - public function update( $post_id ) { |
|
| 86 | - $post = $this->app->database()->fetch_by_id( $post_id ); |
|
| 85 | + public function update($post_id) { |
|
| 86 | + $post = $this->app->database()->fetch_by_id($post_id); |
|
| 87 | 87 | |
| 88 | - if ( is_wp_error( $post ) ) { |
|
| 88 | + if (is_wp_error($post)) { |
|
| 89 | 89 | /* @var WP_Error $post */ |
| 90 | 90 | return $post; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - if ( 'trash' === $post->status() ) { |
|
| 94 | - return $this->delete( $post_id ); |
|
| 93 | + if ('trash' === $post->status()) { |
|
| 94 | + return $this->delete($post_id); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - if ( $old_github_path = $this->github_path( $post->id() ) ) { |
|
| 97 | + if ($old_github_path = $this->github_path($post->id())) { |
|
| 98 | 98 | error_log("old_github_path: $old_github_path"); |
| 99 | 99 | $post->set_old_github_path($old_github_path); |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - $result = $this->export_post( $post ); |
|
| 102 | + $result = $this->export_post($post); |
|
| 103 | 103 | |
| 104 | - if ( is_wp_error( $result ) ) { |
|
| 104 | + if (is_wp_error($result)) { |
|
| 105 | 105 | /* @var WP_Error $result */ |
| 106 | 106 | return $result; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
| 109 | + return __('Export to GitHub completed successfully.', 'writing-on-github'); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -114,20 +114,20 @@ discard block |
||
| 114 | 114 | * @param Writing_On_GitHub_Post $post |
| 115 | 115 | * @return WP_Error|string |
| 116 | 116 | */ |
| 117 | - protected function post_to_blob( Writing_On_GitHub_Post $post ) { |
|
| 117 | + protected function post_to_blob(Writing_On_GitHub_Post $post) { |
|
| 118 | 118 | if ( ! $post->get_blob() |
| 119 | 119 | && $post->old_github_path() |
| 120 | - && wogh_is_dont_export_content() ) { |
|
| 120 | + && wogh_is_dont_export_content()) { |
|
| 121 | 121 | |
| 122 | 122 | |
| 123 | - $blob = $this->app->api()->fetch()->blob_by_path( $post->old_github_path() ); |
|
| 123 | + $blob = $this->app->api()->fetch()->blob_by_path($post->old_github_path()); |
|
| 124 | 124 | |
| 125 | - if ( is_wp_error( $blob ) ) { |
|
| 125 | + if (is_wp_error($blob)) { |
|
| 126 | 126 | /** @var WP_Error $blob */ |
| 127 | 127 | return $blob; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - $post->set_blob( $blob ); |
|
| 130 | + $post->set_blob($blob); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | return $post->to_blob(); |
@@ -138,10 +138,10 @@ discard block |
||
| 138 | 138 | * @param Writing_On_GitHub_Post $post |
| 139 | 139 | * @return WP_Error|true |
| 140 | 140 | */ |
| 141 | - public function export_post( Writing_On_GitHub_Post $post ) { |
|
| 141 | + public function export_post(Writing_On_GitHub_Post $post) { |
|
| 142 | 142 | // check blob |
| 143 | - $blob = $this->post_to_blob( $post ); |
|
| 144 | - if ( is_wp_error( $blob ) ) { |
|
| 143 | + $blob = $this->post_to_blob($post); |
|
| 144 | + if (is_wp_error($blob)) { |
|
| 145 | 145 | /** @var WP_Error $blob */ |
| 146 | 146 | return $blob; |
| 147 | 147 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | $github_path = $post->github_path(); |
| 153 | 153 | $old_github_path = $post->old_github_path(); |
| 154 | 154 | |
| 155 | - if ( $old_github_path && $old_github_path != $github_path ) { |
|
| 155 | + if ($old_github_path && $old_github_path != $github_path) { |
|
| 156 | 156 | // rename |
| 157 | 157 | $message = apply_filters( |
| 158 | 158 | 'wogh_commit_msg_move_post', |
@@ -160,20 +160,20 @@ discard block |
||
| 160 | 160 | 'Move %s to %s via WordPress at %s (%s)', |
| 161 | 161 | $old_github_path, $github_path, |
| 162 | 162 | site_url(), |
| 163 | - get_bloginfo( 'name' ) |
|
| 163 | + get_bloginfo('name') |
|
| 164 | 164 | ) |
| 165 | 165 | ) . $this->get_commit_msg_tag(); |
| 166 | 166 | |
| 167 | - $result = $persist->delete_file( $post->old_github_path(), $blob->sha(), $message ); |
|
| 168 | - if ( is_wp_error( $result ) ) { |
|
| 167 | + $result = $persist->delete_file($post->old_github_path(), $blob->sha(), $message); |
|
| 168 | + if (is_wp_error($result)) { |
|
| 169 | 169 | return $result; |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - $result = $persist->create_file( $blob, $message ); |
|
| 173 | - if ( is_wp_error( $result ) ) { |
|
| 172 | + $result = $persist->create_file($blob, $message); |
|
| 173 | + if (is_wp_error($result)) { |
|
| 174 | 174 | return $result; |
| 175 | 175 | } |
| 176 | - } elseif ( ! $old_github_path ) { |
|
| 176 | + } elseif ( ! $old_github_path) { |
|
| 177 | 177 | // create new |
| 178 | 178 | $message = apply_filters( |
| 179 | 179 | 'wogh_commit_msg_new_post', |
@@ -181,14 +181,14 @@ discard block |
||
| 181 | 181 | 'Create new post %s from WordPress at %s (%s)', |
| 182 | 182 | $github_path, |
| 183 | 183 | site_url(), |
| 184 | - get_bloginfo( 'name' ) |
|
| 184 | + get_bloginfo('name') |
|
| 185 | 185 | ) |
| 186 | 186 | ) . $this->get_commit_msg_tag(); |
| 187 | - $result = $persist->create_file( $blob, $message ); |
|
| 188 | - if ( is_wp_error( $result ) ) { |
|
| 187 | + $result = $persist->create_file($blob, $message); |
|
| 188 | + if (is_wp_error($result)) { |
|
| 189 | 189 | return $result; |
| 190 | 190 | } |
| 191 | - } elseif ( $old_github_path && $old_github_path == $github_path ) { |
|
| 191 | + } elseif ($old_github_path && $old_github_path == $github_path) { |
|
| 192 | 192 | // update |
| 193 | 193 | $message = apply_filters( |
| 194 | 194 | 'wogh_commit_msg_update_post', |
@@ -196,11 +196,11 @@ discard block |
||
| 196 | 196 | 'Update post %s from WordPress at %s (%s)', |
| 197 | 197 | $github_path, |
| 198 | 198 | site_url(), |
| 199 | - get_bloginfo( 'name' ) |
|
| 199 | + get_bloginfo('name') |
|
| 200 | 200 | ) |
| 201 | 201 | ) . $this->get_commit_msg_tag(); |
| 202 | - $result = $persist->update_file( $blob, $message ); |
|
| 203 | - if ( is_wp_error( $result ) ) { |
|
| 202 | + $result = $persist->update_file($blob, $message); |
|
| 203 | + if (is_wp_error($result)) { |
|
| 204 | 204 | return $result; |
| 205 | 205 | } |
| 206 | 206 | } |
@@ -219,15 +219,15 @@ discard block |
||
| 219 | 219 | * |
| 220 | 220 | * @return string|WP_Error |
| 221 | 221 | */ |
| 222 | - public function delete( $post_id ) { |
|
| 223 | - $post = $this->app->database()->fetch_by_id( $post_id ); |
|
| 222 | + public function delete($post_id) { |
|
| 223 | + $post = $this->app->database()->fetch_by_id($post_id); |
|
| 224 | 224 | |
| 225 | - if ( is_wp_error( $post ) ) { |
|
| 225 | + if (is_wp_error($post)) { |
|
| 226 | 226 | /* @var WP_Error $post */ |
| 227 | 227 | return $post; |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - $github_path = get_post_meta( $post_id, '_wogh_github_path', true ); |
|
| 230 | + $github_path = get_post_meta($post_id, '_wogh_github_path', true); |
|
| 231 | 231 | |
| 232 | 232 | $message = apply_filters( |
| 233 | 233 | 'wogh_commit_msg_delete', |
@@ -235,19 +235,19 @@ discard block |
||
| 235 | 235 | 'Deleting %s via WordPress at %s (%s)', |
| 236 | 236 | $github_path, |
| 237 | 237 | site_url(), |
| 238 | - get_bloginfo( 'name' ) |
|
| 238 | + get_bloginfo('name') |
|
| 239 | 239 | ), |
| 240 | 240 | $post |
| 241 | 241 | ) . $this->get_commit_msg_tag(); |
| 242 | 242 | |
| 243 | - $result = $this->app->api()->persist()->delete_file( $github_path, $post->sha(), $message ); |
|
| 243 | + $result = $this->app->api()->persist()->delete_file($github_path, $post->sha(), $message); |
|
| 244 | 244 | |
| 245 | - if ( is_wp_error( $result ) ) { |
|
| 245 | + if (is_wp_error($result)) { |
|
| 246 | 246 | /* @var WP_Error $result */ |
| 247 | 247 | return $result; |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
| 250 | + return __('Export to GitHub completed successfully.', 'writing-on-github'); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | |
@@ -258,8 +258,8 @@ discard block |
||
| 258 | 258 | * |
| 259 | 259 | * @return bool |
| 260 | 260 | */ |
| 261 | - public function set_user( $user_id ) { |
|
| 262 | - return update_option( self::EXPORT_USER_OPTION, (int) $user_id ); |
|
| 261 | + public function set_user($user_id) { |
|
| 262 | + return update_option(self::EXPORT_USER_OPTION, (int) $user_id); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | /** |
@@ -268,10 +268,10 @@ discard block |
||
| 268 | 268 | * @return string |
| 269 | 269 | */ |
| 270 | 270 | protected function get_commit_msg_tag() { |
| 271 | - $tag = apply_filters( 'wogh_commit_msg_tag', 'wogh' ); |
|
| 271 | + $tag = apply_filters('wogh_commit_msg_tag', 'wogh'); |
|
| 272 | 272 | |
| 273 | - if ( ! $tag ) { |
|
| 274 | - throw new Exception( __( 'Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github' ) ); |
|
| 273 | + if ( ! $tag) { |
|
| 274 | + throw new Exception(__('Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github')); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | return ' - ' . $tag; |
@@ -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,24 +32,24 @@ 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 | - if ( is_array( $result ) ) { |
|
| 45 | - $result = $this->import_files( $result ); |
|
| 44 | + if (is_array($result)) { |
|
| 45 | + $result = $this->import_files($result); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - if ( is_wp_error( $result ) ) { |
|
| 48 | + if (is_wp_error($result)) { |
|
| 49 | 49 | return $files; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - return __( 'Payload processed', 'writing-on-github' ); |
|
| 52 | + return __('Payload processed', 'writing-on-github'); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
@@ -58,37 +58,37 @@ discard block |
||
| 58 | 58 | * |
| 59 | 59 | * @return true|WP_Error |
| 60 | 60 | */ |
| 61 | - protected function import_files( $files ) { |
|
| 61 | + protected function import_files($files) { |
|
| 62 | 62 | |
| 63 | 63 | $error = true; |
| 64 | 64 | |
| 65 | - foreach ( $files as $file ) { |
|
| 66 | - if ( ! $this->importable_file( $file ) ) { |
|
| 65 | + foreach ($files as $file) { |
|
| 66 | + if ( ! $this->importable_file($file)) { |
|
| 67 | 67 | continue; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - $blob = $this->app->api()->fetch()->blob( $file ); |
|
| 70 | + $blob = $this->app->api()->fetch()->blob($file); |
|
| 71 | 71 | // network error ? |
| 72 | - if ( ! $blob instanceof Writing_On_GitHub_Blob ) { |
|
| 72 | + if ( ! $blob instanceof Writing_On_GitHub_Blob) { |
|
| 73 | 73 | continue; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | $is_remove = 'removed' == $file->status; |
| 77 | 77 | |
| 78 | 78 | $result = false; |
| 79 | - if ( $this->importable_raw_file( $blob ) ) { |
|
| 80 | - $result = $this->import_raw_file( $blob, $is_remove ); |
|
| 81 | - } elseif ( $this->importable_post( $blob ) ) { |
|
| 82 | - if ( $is_remove ) { |
|
| 83 | - $result = $this->delete_post( $blob ); |
|
| 79 | + if ($this->importable_raw_file($blob)) { |
|
| 80 | + $result = $this->import_raw_file($blob, $is_remove); |
|
| 81 | + } elseif ($this->importable_post($blob)) { |
|
| 82 | + if ($is_remove) { |
|
| 83 | + $result = $this->delete_post($blob); |
|
| 84 | 84 | } else { |
| 85 | - $result = $this->import_post( $blob ); |
|
| 85 | + $result = $this->import_post($blob); |
|
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - if ( is_wp_error( $result ) ) { |
|
| 89 | + if (is_wp_error($result)) { |
|
| 90 | 90 | /* @var WP_Error $result */ |
| 91 | - $error = wogh_append_error( $error, $result ); |
|
| 91 | + $error = wogh_append_error($error, $result); |
|
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | |
@@ -103,21 +103,21 @@ discard block |
||
| 103 | 103 | public function master() { |
| 104 | 104 | $result = $this->app->api()->fetch()->tree_recursive(); |
| 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 | - if ( is_array( $result ) ) { |
|
| 112 | - $result = $this->import_files( $result ); |
|
| 111 | + if (is_array($result)) { |
|
| 112 | + $result = $this->import_files($result); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - if ( is_wp_error( $result ) ) { |
|
| 115 | + if (is_wp_error($result)) { |
|
| 116 | 116 | /* @var WP_Error $result */ |
| 117 | 117 | return $result; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - return __( 'Payload processed', 'writing-on-github' ); |
|
| 120 | + return __('Payload processed', 'writing-on-github'); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -127,14 +127,14 @@ discard block |
||
| 127 | 127 | * |
| 128 | 128 | * @return bool |
| 129 | 129 | */ |
| 130 | - protected function importable_file( Writing_On_GitHub_File_Info $file ) { |
|
| 130 | + protected function importable_file(Writing_On_GitHub_File_Info $file) { |
|
| 131 | 131 | |
| 132 | 132 | $path = $file->path; |
| 133 | 133 | |
| 134 | 134 | // only _pages, _posts and images |
| 135 | - $prefixs = array( '_pages/', '_posts/', 'images/'); |
|
| 135 | + $prefixs = array('_pages/', '_posts/', 'images/'); |
|
| 136 | 136 | foreach ($prefixs as $prefix) { |
| 137 | - if ( ! strncasecmp($path, $prefix, strlen( $prefix ) ) ) { |
|
| 137 | + if ( ! strncasecmp($path, $prefix, strlen($prefix))) { |
|
| 138 | 138 | return true; |
| 139 | 139 | } |
| 140 | 140 | } |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | * |
| 149 | 149 | * @return bool |
| 150 | 150 | */ |
| 151 | - protected function importable_post( Writing_On_GitHub_Blob $blob ) { |
|
| 151 | + protected function importable_post(Writing_On_GitHub_Blob $blob) { |
|
| 152 | 152 | // global $wpdb; |
| 153 | 153 | |
| 154 | 154 | // // Skip the repo's readme. |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | // return false; |
| 162 | 162 | // } |
| 163 | 163 | |
| 164 | - if ( ! $blob->has_frontmatter() ) { |
|
| 164 | + if ( ! $blob->has_frontmatter()) { |
|
| 165 | 165 | return false; |
| 166 | 166 | } |
| 167 | 167 | |
@@ -173,13 +173,13 @@ discard block |
||
| 173 | 173 | * @param Writing_On_GitHub_Blob $blob |
| 174 | 174 | * @return WP_Error|bool |
| 175 | 175 | */ |
| 176 | - protected function delete_post( Writing_On_GitHub_Blob $blob ) { |
|
| 176 | + protected function delete_post(Writing_On_GitHub_Blob $blob) { |
|
| 177 | 177 | $id = $blob->id(); |
| 178 | - if ( empty( $id ) ) { |
|
| 178 | + if (empty($id)) { |
|
| 179 | 179 | return false; |
| 180 | 180 | } |
| 181 | - $result = $this->app->database()->delete_post( $id ); |
|
| 182 | - if ( is_wp_error( $result ) ) { |
|
| 181 | + $result = $this->app->database()->delete_post($id); |
|
| 182 | + if (is_wp_error($result)) { |
|
| 183 | 183 | /* @var WP_Error $result */ |
| 184 | 184 | return $result; |
| 185 | 185 | } |
@@ -191,31 +191,31 @@ discard block |
||
| 191 | 191 | * @param Writing_On_GitHub_Blob $blob |
| 192 | 192 | * @return WP_Error|bool |
| 193 | 193 | */ |
| 194 | - protected function import_post( Writing_On_GitHub_Blob $blob ) { |
|
| 195 | - $post = $this->blob_to_post( $blob ); |
|
| 194 | + protected function import_post(Writing_On_GitHub_Blob $blob) { |
|
| 195 | + $post = $this->blob_to_post($blob); |
|
| 196 | 196 | |
| 197 | - if ( ! $post instanceof Writing_On_GitHub_Post ) { |
|
| 197 | + if ( ! $post instanceof Writing_On_GitHub_Post) { |
|
| 198 | 198 | return false; |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - $result = $this->app->database()->save_post( $post ); |
|
| 202 | - if ( is_wp_error( $result ) ) { |
|
| 201 | + $result = $this->app->database()->save_post($post); |
|
| 202 | + if (is_wp_error($result)) { |
|
| 203 | 203 | /** @var WP_Error $result */ |
| 204 | 204 | return $result; |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - if ( $post->is_new() || |
|
| 208 | - ! wogh_equal_front_matter( $post, $blob ) ) { |
|
| 207 | + if ($post->is_new() || |
|
| 208 | + ! wogh_equal_front_matter($post, $blob)) { |
|
| 209 | 209 | |
| 210 | - $result = $this->app->export()->export_post( $post ); |
|
| 210 | + $result = $this->app->export()->export_post($post); |
|
| 211 | 211 | |
| 212 | - if ( is_wp_error( $result ) ) { |
|
| 212 | + if (is_wp_error($result)) { |
|
| 213 | 213 | /** @var WP_Error $result */ |
| 214 | 214 | return $result; |
| 215 | 215 | } |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - clean_post_cache( $post->id() ); |
|
| 218 | + clean_post_cache($post->id()); |
|
| 219 | 219 | |
| 220 | 220 | return true; |
| 221 | 221 | } |
@@ -225,13 +225,13 @@ discard block |
||
| 225 | 225 | * @param Writing_On_GitHub_Blob $blob |
| 226 | 226 | * @return bool |
| 227 | 227 | */ |
| 228 | - protected function importable_raw_file( Writing_On_GitHub_Blob $blob ) { |
|
| 229 | - if ( $blob->has_frontmatter() ) { |
|
| 228 | + protected function importable_raw_file(Writing_On_GitHub_Blob $blob) { |
|
| 229 | + if ($blob->has_frontmatter()) { |
|
| 230 | 230 | return false; |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | // only images |
| 234 | - if ( strncasecmp($blob->path(), 'images/', strlen('images/') ) != 0) { |
|
| 234 | + if (strncasecmp($blob->path(), 'images/', strlen('images/')) != 0) { |
|
| 235 | 235 | return false; |
| 236 | 236 | } |
| 237 | 237 | |
@@ -243,16 +243,16 @@ discard block |
||
| 243 | 243 | * @param Writing_On_GitHub_Blob $blob |
| 244 | 244 | * @param bool $is_remove |
| 245 | 245 | */ |
| 246 | - protected function import_raw_file( Writing_On_GitHub_Blob $blob, $is_remove ) { |
|
| 246 | + protected function import_raw_file(Writing_On_GitHub_Blob $blob, $is_remove) { |
|
| 247 | 247 | $arr = wp_upload_dir(); |
| 248 | 248 | $path = $arr['basedir'] . '/writing-on-github/' . $blob->path(); |
| 249 | - if ( $is_remove ) { |
|
| 250 | - if ( file_exists($path) ) { |
|
| 249 | + if ($is_remove) { |
|
| 250 | + if (file_exists($path)) { |
|
| 251 | 251 | unlink($path); |
| 252 | 252 | } |
| 253 | 253 | } else { |
| 254 | 254 | $dirname = dirname($path); |
| 255 | - if ( ! file_exists($dirname) ) { |
|
| 255 | + if ( ! file_exists($dirname)) { |
|
| 256 | 256 | wp_mkdir_p($dirname); |
| 257 | 257 | } |
| 258 | 258 | |
@@ -268,58 +268,58 @@ discard block |
||
| 268 | 268 | * |
| 269 | 269 | * @return Writing_On_GitHub_Post|false |
| 270 | 270 | */ |
| 271 | - protected function blob_to_post( Writing_On_GitHub_Blob $blob ) { |
|
| 272 | - $args = array( 'post_content' => $blob->content_import() ); |
|
| 271 | + protected function blob_to_post(Writing_On_GitHub_Blob $blob) { |
|
| 272 | + $args = array('post_content' => $blob->content_import()); |
|
| 273 | 273 | $meta = $blob->meta(); |
| 274 | 274 | |
| 275 | 275 | $id = false; |
| 276 | 276 | |
| 277 | - if ( ! empty( $meta ) ) { |
|
| 278 | - if ( array_key_exists( 'layout', $meta ) ) { |
|
| 277 | + if ( ! empty($meta)) { |
|
| 278 | + if (array_key_exists('layout', $meta)) { |
|
| 279 | 279 | $args['post_type'] = $meta['layout']; |
| 280 | - unset( $meta['layout'] ); |
|
| 280 | + unset($meta['layout']); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - if ( array_key_exists( 'published', $meta ) ) { |
|
| 283 | + if (array_key_exists('published', $meta)) { |
|
| 284 | 284 | $args['post_status'] = true === $meta['published'] ? 'publish' : 'draft'; |
| 285 | - unset( $meta['published'] ); |
|
| 285 | + unset($meta['published']); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | - if ( array_key_exists( 'post_title', $meta ) ) { |
|
| 288 | + if (array_key_exists('post_title', $meta)) { |
|
| 289 | 289 | $args['post_title'] = $meta['post_title']; |
| 290 | - unset( $meta['post_title'] ); |
|
| 290 | + unset($meta['post_title']); |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | - if ( array_key_exists( 'post_name', $meta ) ) { |
|
| 293 | + if (array_key_exists('post_name', $meta)) { |
|
| 294 | 294 | $args['post_name'] = $meta['post_name']; |
| 295 | - unset( $meta['post_name'] ); |
|
| 295 | + unset($meta['post_name']); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - if ( array_key_exists( 'ID', $meta ) ) { |
|
| 298 | + if (array_key_exists('ID', $meta)) { |
|
| 299 | 299 | $id = $args['ID'] = $meta['ID']; |
| 300 | 300 | $blob->set_id($id); |
| 301 | - unset( $meta['ID'] ); |
|
| 301 | + unset($meta['ID']); |
|
| 302 | 302 | } |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | $meta['_wogh_sha'] = $blob->sha(); |
| 306 | 306 | |
| 307 | - if ( $id ) { |
|
| 308 | - $old_sha = get_post_meta( $id, '_wogh_sha', true ); |
|
| 309 | - $old_github_path = get_post_meta( $id, '_wogh_github_path', true ); |
|
| 307 | + if ($id) { |
|
| 308 | + $old_sha = get_post_meta($id, '_wogh_sha', true); |
|
| 309 | + $old_github_path = get_post_meta($id, '_wogh_github_path', true); |
|
| 310 | 310 | |
| 311 | 311 | // dont save post when has same sha |
| 312 | - if ( $old_sha && $old_sha == $meta['_wogh_sha'] && |
|
| 313 | - $old_github_path && $old_github_path == $blob->path() ) { |
|
| 312 | + if ($old_sha && $old_sha == $meta['_wogh_sha'] && |
|
| 313 | + $old_github_path && $old_github_path == $blob->path()) { |
|
| 314 | 314 | return false; |
| 315 | 315 | } |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - $post = new Writing_On_GitHub_Post( $args, $this->app->api() ); |
|
| 319 | - $post->set_old_github_path( $blob->path() ); |
|
| 320 | - $post->set_meta( $meta ); |
|
| 321 | - $post->set_blob( $blob ); |
|
| 322 | - $blob->set_id( $post->id() ); |
|
| 318 | + $post = new Writing_On_GitHub_Post($args, $this->app->api()); |
|
| 319 | + $post->set_old_github_path($blob->path()); |
|
| 320 | + $post->set_meta($meta); |
|
| 321 | + $post->set_blob($blob); |
|
| 322 | + $blob->set_id($post->id()); |
|
| 323 | 323 | |
| 324 | 324 | return $post; |
| 325 | 325 | } |
@@ -66,26 +66,26 @@ discard block |
||
| 66 | 66 | * |
| 67 | 67 | * @todo remove database operations from this method |
| 68 | 68 | */ |
| 69 | - public function __construct( $id_or_args, Writing_On_GitHub_Api $api ) { |
|
| 69 | + public function __construct($id_or_args, Writing_On_GitHub_Api $api) { |
|
| 70 | 70 | $this->api = $api; |
| 71 | 71 | |
| 72 | - if ( is_numeric( $id_or_args ) ) { |
|
| 72 | + if (is_numeric($id_or_args)) { |
|
| 73 | 73 | $this->id = (int) $id_or_args; |
| 74 | - $this->post = get_post( $this->id ); |
|
| 74 | + $this->post = get_post($this->id); |
|
| 75 | 75 | $this->new = false; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - if ( is_array( $id_or_args ) ) { |
|
| 78 | + if (is_array($id_or_args)) { |
|
| 79 | 79 | $this->args = $id_or_args; |
| 80 | 80 | |
| 81 | - if ( isset( $this->args['ID'] ) ) { |
|
| 82 | - $this->post = get_post( $this->args['ID'] ); |
|
| 81 | + if (isset($this->args['ID'])) { |
|
| 82 | + $this->post = get_post($this->args['ID']); |
|
| 83 | 83 | |
| 84 | - if ( $this->post ) { |
|
| 84 | + if ($this->post) { |
|
| 85 | 85 | $this->id = $this->post->ID; |
| 86 | 86 | $this->new = false; |
| 87 | 87 | } else { |
| 88 | - unset( $this->args['ID'] ); |
|
| 88 | + unset($this->args['ID']); |
|
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * @return bool |
| 122 | 122 | */ |
| 123 | 123 | public function has_password() { |
| 124 | - return ! empty( $this->post->post_password ); |
|
| 124 | + return ! empty($this->post->post_password); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -129,9 +129,9 @@ discard block |
||
| 129 | 129 | */ |
| 130 | 130 | public function github_content() { |
| 131 | 131 | $content = $this->front_matter() . $this->post_content(); |
| 132 | - $ending = apply_filters( 'wogh_line_endings', "\n" ); |
|
| 132 | + $ending = apply_filters('wogh_line_endings', "\n"); |
|
| 133 | 133 | |
| 134 | - return preg_replace( '~(*BSR_ANYCRLF)\R~', $ending, $content ); |
|
| 134 | + return preg_replace('~(*BSR_ANYCRLF)\R~', $ending, $content); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | * Returns String the YAML frontmatter, ready to be written to the file |
| 141 | 141 | */ |
| 142 | 142 | public function front_matter() { |
| 143 | - return "---\n" . spyc_dump( $this->meta() ) . "---\n"; |
|
| 143 | + return "---\n" . spyc_dump($this->meta()) . "---\n"; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -151,24 +151,24 @@ discard block |
||
| 151 | 151 | public function post_content() { |
| 152 | 152 | $content = $this->post->post_content; |
| 153 | 153 | |
| 154 | - if ( function_exists( 'wpmarkdown_html_to_markdown' ) ) { |
|
| 155 | - $content = wpmarkdown_html_to_markdown( $content ); |
|
| 156 | - } else if ( class_exists( 'WPCom_Markdown' ) ) { |
|
| 157 | - if ( WPCom_Markdown::get_instance()->is_markdown( $this->post->ID ) ) { |
|
| 154 | + if (function_exists('wpmarkdown_html_to_markdown')) { |
|
| 155 | + $content = wpmarkdown_html_to_markdown($content); |
|
| 156 | + } else if (class_exists('WPCom_Markdown')) { |
|
| 157 | + if (WPCom_Markdown::get_instance()->is_markdown($this->post->ID)) { |
|
| 158 | 158 | $content = $this->post->post_content_filtered; |
| 159 | 159 | } |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - return apply_filters( 'wogh_content_export', $content, $this ); |
|
| 162 | + return apply_filters('wogh_content_export', $content, $this); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | public function old_github_path() { |
| 166 | 166 | return $this->old_github_path; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - public function set_old_github_path( $path ) { |
|
| 169 | + public function set_old_github_path($path) { |
|
| 170 | 170 | $this->old_github_path = $path; |
| 171 | - update_post_meta( $this->id, '_wogh_github_path', $path ); |
|
| 171 | + update_post_meta($this->id, '_wogh_github_path', $path); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | |
@@ -189,13 +189,13 @@ discard block |
||
| 189 | 189 | * @return string |
| 190 | 190 | */ |
| 191 | 191 | public function github_directory() { |
| 192 | - if ( 'publish' !== $this->status() ) { |
|
| 193 | - return apply_filters( 'wogh_directory_unpublished', '_drafts/', $this ); |
|
| 192 | + if ('publish' !== $this->status()) { |
|
| 193 | + return apply_filters('wogh_directory_unpublished', '_drafts/', $this); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | $name = ''; |
| 197 | 197 | |
| 198 | - switch ( $this->type() ) { |
|
| 198 | + switch ($this->type()) { |
|
| 199 | 199 | case 'post': |
| 200 | 200 | $name = 'posts'; |
| 201 | 201 | break; |
@@ -203,35 +203,35 @@ discard block |
||
| 203 | 203 | $name = 'pages'; |
| 204 | 204 | break; |
| 205 | 205 | default: |
| 206 | - $obj = get_post_type_object( $this->type() ); |
|
| 206 | + $obj = get_post_type_object($this->type()); |
|
| 207 | 207 | |
| 208 | - if ( $obj ) { |
|
| 209 | - $name = strtolower( $obj->labels->name ); |
|
| 208 | + if ($obj) { |
|
| 209 | + $name = strtolower($obj->labels->name); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | - if ( ! $name ) { |
|
| 212 | + if ( ! $name) { |
|
| 213 | 213 | $name = ''; |
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - if ( $name ) { |
|
| 217 | + if ($name) { |
|
| 218 | 218 | $name = '_' . $name . '/'; |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - return apply_filters( 'wogh_directory_published', $name, $this ); |
|
| 221 | + return apply_filters('wogh_directory_published', $name, $this); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | /** |
| 225 | 225 | * Build GitHub filename based on post |
| 226 | 226 | */ |
| 227 | 227 | public function github_filename() { |
| 228 | - if ( 'post' === $this->type() ) { |
|
| 229 | - $filename = get_the_time( 'Y-m-d-', $this->id ) . $this->get_name() . '.md'; |
|
| 228 | + if ('post' === $this->type()) { |
|
| 229 | + $filename = get_the_time('Y-m-d-', $this->id) . $this->get_name() . '.md'; |
|
| 230 | 230 | } else { |
| 231 | 231 | $filename = $this->get_name() . '.md'; |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - return apply_filters( 'wogh_filename', $filename, $this ); |
|
| 234 | + return apply_filters('wogh_filename', $filename, $this); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -240,11 +240,11 @@ discard block |
||
| 240 | 240 | * @return string |
| 241 | 241 | */ |
| 242 | 242 | protected function get_name() { |
| 243 | - if ( '' !== $this->name() ) { |
|
| 243 | + if ('' !== $this->name()) { |
|
| 244 | 244 | return $this->name(); |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - return sanitize_title( get_the_title( $this->post ) ); |
|
| 247 | + return sanitize_title(get_the_title($this->post)); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | /** |
@@ -252,9 +252,9 @@ discard block |
||
| 252 | 252 | * @return boolean |
| 253 | 253 | */ |
| 254 | 254 | public function is_on_github() { |
| 255 | - $sha = get_post_meta( $this->id, '_wogh_sha', true ); |
|
| 256 | - $github_path = get_post_meta( $this->id, '_wogh_github_path', true ); |
|
| 257 | - if ( $sha && $github_path ) { |
|
| 255 | + $sha = get_post_meta($this->id, '_wogh_sha', true); |
|
| 256 | + $github_path = get_post_meta($this->id, '_wogh_github_path', true); |
|
| 257 | + if ($sha && $github_path) { |
|
| 258 | 258 | return true; |
| 259 | 259 | } |
| 260 | 260 | return false; |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | * @return string |
| 267 | 267 | */ |
| 268 | 268 | public function github_view_url() { |
| 269 | - $github_path = get_post_meta( $this->id, '_wogh_github_path', true ); |
|
| 269 | + $github_path = get_post_meta($this->id, '_wogh_github_path', true); |
|
| 270 | 270 | $repository = $this->api->fetch()->repository(); |
| 271 | 271 | $branch = $this->api->fetch()->branch(); |
| 272 | 272 | |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | * @return string |
| 280 | 280 | */ |
| 281 | 281 | public function github_edit_url() { |
| 282 | - $github_path = get_post_meta( $this->id, '_wogh_github_path', true ); |
|
| 282 | + $github_path = get_post_meta($this->id, '_wogh_github_path', true); |
|
| 283 | 283 | $repository = $this->api->fetch()->repository(); |
| 284 | 284 | $branch = $this->api->fetch()->branch(); |
| 285 | 285 | |
@@ -293,9 +293,9 @@ discard block |
||
| 293 | 293 | * |
| 294 | 294 | * @return string |
| 295 | 295 | */ |
| 296 | - public function get_directory_from_path( $path ) { |
|
| 297 | - $directory = explode( '/', $path ); |
|
| 298 | - $directory = count( $directory ) > 0 ? $directory[0] : ''; |
|
| 296 | + public function get_directory_from_path($path) { |
|
| 297 | + $directory = explode('/', $path); |
|
| 298 | + $directory = count($directory) > 0 ? $directory[0] : ''; |
|
| 299 | 299 | |
| 300 | 300 | return $directory; |
| 301 | 301 | } |
@@ -306,11 +306,11 @@ discard block |
||
| 306 | 306 | * Returns Array an array containing the author name and email |
| 307 | 307 | */ |
| 308 | 308 | public function last_modified_author() { |
| 309 | - if ( $last_id = get_post_meta( $this->id, '_edit_last', true ) ) { |
|
| 310 | - $user = get_userdata( $last_id ); |
|
| 309 | + if ($last_id = get_post_meta($this->id, '_edit_last', true)) { |
|
| 310 | + $user = get_userdata($last_id); |
|
| 311 | 311 | |
| 312 | - if ( $user ) { |
|
| 313 | - return array( 'name' => $user->display_name, 'email' => $user->user_email ); |
|
| 312 | + if ($user) { |
|
| 313 | + return array('name' => $user->display_name, 'email' => $user->user_email); |
|
| 314 | 314 | } |
| 315 | 315 | } |
| 316 | 316 | |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | * Returns String the sha1 hash |
| 325 | 325 | */ |
| 326 | 326 | public function sha() { |
| 327 | - $sha = get_post_meta( $this->id, '_wogh_sha', true ); |
|
| 327 | + $sha = get_post_meta($this->id, '_wogh_sha', true); |
|
| 328 | 328 | |
| 329 | 329 | // If we've done a full export and we have no sha |
| 330 | 330 | // then we should try a live check to see if it exists. |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | // } |
| 341 | 341 | |
| 342 | 342 | // if the sha still doesn't exist, then it's empty |
| 343 | - if ( ! $sha || is_wp_error( $sha ) ) { |
|
| 343 | + if ( ! $sha || is_wp_error($sha)) { |
|
| 344 | 344 | $sha = ''; |
| 345 | 345 | } |
| 346 | 346 | |
@@ -352,8 +352,8 @@ discard block |
||
| 352 | 352 | * |
| 353 | 353 | * @param string $sha |
| 354 | 354 | */ |
| 355 | - public function set_sha( $sha ) { |
|
| 356 | - update_post_meta( $this->id, '_wogh_sha', $sha ); |
|
| 355 | + public function set_sha($sha) { |
|
| 356 | + update_post_meta($this->id, '_wogh_sha', $sha); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -364,24 +364,24 @@ discard block |
||
| 364 | 364 | public function meta() { |
| 365 | 365 | $meta = array( |
| 366 | 366 | 'ID' => $this->id, |
| 367 | - 'post_title' => get_the_title( $this->post ), |
|
| 367 | + 'post_title' => get_the_title($this->post), |
|
| 368 | 368 | 'post_name' => $this->post->post_name, |
| 369 | - 'author' => ( $author = get_userdata( $this->post->post_author ) ) ? $author->display_name : '', |
|
| 369 | + 'author' => ($author = get_userdata($this->post->post_author)) ? $author->display_name : '', |
|
| 370 | 370 | 'post_date' => $this->post->post_date, |
| 371 | 371 | 'post_excerpt' => $this->post->post_excerpt, |
| 372 | - 'layout' => get_post_type( $this->post ), |
|
| 373 | - 'link' => get_permalink( $this->post ), |
|
| 372 | + 'layout' => get_post_type($this->post), |
|
| 373 | + 'link' => get_permalink($this->post), |
|
| 374 | 374 | 'published' => 'publish' === $this->status() ? true : false, |
| 375 | - 'tags' => wp_get_post_tags( $this->id, array( 'fields' => 'names' ) ), |
|
| 376 | - 'categories' => wp_get_post_categories( $this->id, array( 'fields' => 'names' ) ) |
|
| 375 | + 'tags' => wp_get_post_tags($this->id, array('fields' => 'names')), |
|
| 376 | + 'categories' => wp_get_post_categories($this->id, array('fields' => 'names')) |
|
| 377 | 377 | ); |
| 378 | - if ( empty($this->post->post_name) ) { |
|
| 378 | + if (empty($this->post->post_name)) { |
|
| 379 | 379 | unset($meta['post_name']); |
| 380 | 380 | } |
| 381 | - if ( empty($this->post->post_excerpt) ) { |
|
| 381 | + if (empty($this->post->post_excerpt)) { |
|
| 382 | 382 | unset($meta['post_excerpt']); |
| 383 | 383 | } |
| 384 | - if ( 'yes' == get_option('wogh_ignore_author') ) { |
|
| 384 | + if ('yes' == get_option('wogh_ignore_author')) { |
|
| 385 | 385 | unset($meta['author']); |
| 386 | 386 | } |
| 387 | 387 | |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | |
| 397 | 397 | // } |
| 398 | 398 | |
| 399 | - return apply_filters( 'wogh_post_meta', $meta, $this ); |
|
| 399 | + return apply_filters('wogh_post_meta', $meta, $this); |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | /** |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | * |
| 414 | 414 | * @param array $meta |
| 415 | 415 | */ |
| 416 | - public function set_meta( $meta ) { |
|
| 416 | + public function set_meta($meta) { |
|
| 417 | 417 | $this->meta = $meta; |
| 418 | 418 | } |
| 419 | 419 | |
@@ -447,7 +447,7 @@ discard block |
||
| 447 | 447 | * Set the blob |
| 448 | 448 | * @param Writing_On_GitHub_Blob $blob |
| 449 | 449 | */ |
| 450 | - public function set_blob( Writing_On_GitHub_Blob $blob ) { |
|
| 450 | + public function set_blob(Writing_On_GitHub_Blob $blob) { |
|
| 451 | 451 | $this->blob = $blob; |
| 452 | 452 | } |
| 453 | 453 | |
@@ -458,7 +458,7 @@ discard block |
||
| 458 | 458 | * |
| 459 | 459 | * @return $this |
| 460 | 460 | */ |
| 461 | - public function set_post( WP_Post $post ) { |
|
| 461 | + public function set_post(WP_Post $post) { |
|
| 462 | 462 | $this->post = $post; |
| 463 | 463 | $this->id = $post->ID; |
| 464 | 464 | |
@@ -477,6 +477,6 @@ discard block |
||
| 477 | 477 | $data->content = $this->github_content(); |
| 478 | 478 | $data->sha = $this->sha(); |
| 479 | 479 | |
| 480 | - return new Writing_On_GitHub_Blob( $data ); |
|
| 480 | + return new Writing_On_GitHub_Blob($data); |
|
| 481 | 481 | } |
| 482 | 482 | } |
@@ -7,9 +7,9 @@ discard block |
||
| 7 | 7 | * @param WP_Error $error2 |
| 8 | 8 | * @return WP_Error |
| 9 | 9 | */ |
| 10 | -function wogh_append_error( $error, $error2 ) { |
|
| 11 | - if ( is_wp_error( $error ) ) { |
|
| 12 | - $error->add( $error2->get_error_code(), $error2->get_error_message() ); |
|
| 10 | +function wogh_append_error($error, $error2) { |
|
| 11 | + if (is_wp_error($error)) { |
|
| 12 | + $error->add($error2->get_error_code(), $error2->get_error_message()); |
|
| 13 | 13 | } |
| 14 | 14 | return $error2; |
| 15 | 15 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * @param Writing_On_GitHub_Blob $blob |
| 21 | 21 | * @return bool |
| 22 | 22 | */ |
| 23 | -function wogh_equal_front_matter( $post, $blob ) { |
|
| 23 | +function wogh_equal_front_matter($post, $blob) { |
|
| 24 | 24 | $str1 = $post->front_matter(); |
| 25 | 25 | $str2 = $blob->front_matter(); |
| 26 | 26 | return trim($str1) === trim($str2); |
@@ -31,5 +31,5 @@ discard block |
||
| 31 | 31 | * @return bool |
| 32 | 32 | */ |
| 33 | 33 | function wogh_is_dont_export_content() { |
| 34 | - return 'yes' === get_option( 'wogh_dont_export_content' ); |
|
| 34 | + return 'yes' === get_option('wogh_dont_export_content'); |
|
| 35 | 35 | } |
@@ -16,13 +16,13 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @return Writing_On_GitHub_File_Info[]|WP_Error |
| 18 | 18 | */ |
| 19 | - public function compare( $sha ) { |
|
| 19 | + public function compare($sha) { |
|
| 20 | 20 | // https://api.github.com/repos/litefeel/testwpsync/compare/861f87e8851b8debb78db548269d29f8da4d94ac...master |
| 21 | 21 | $endpoint = $this->compare_endpoint(); |
| 22 | 22 | $branch = $this->branch(); |
| 23 | - $data = $this->call( 'GET', "$endpoint/$sha...$branch" ); |
|
| 23 | + $data = $this->call('GET', "$endpoint/$sha...$branch"); |
|
| 24 | 24 | |
| 25 | - if ( is_wp_error( $data ) ) { |
|
| 25 | + if (is_wp_error($data)) { |
|
| 26 | 26 | return $data; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -44,15 +44,15 @@ discard block |
||
| 44 | 44 | * |
| 45 | 45 | * @return mixed |
| 46 | 46 | */ |
| 47 | - public function remote_contents( $post ) { |
|
| 48 | - return $this->call( 'GET', $this->content_endpoint( $post->github_path() ) ); |
|
| 47 | + public function remote_contents($post) { |
|
| 48 | + return $this->call('GET', $this->content_endpoint($post->github_path())); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | |
| 52 | 52 | |
| 53 | - public function exists( $path ) { |
|
| 54 | - $result = $this->call( 'GET', $this->content_endpoint( $path ) ); |
|
| 55 | - if ( is_wp_error( $result ) ) { |
|
| 53 | + public function exists($path) { |
|
| 54 | + $result = $this->call('GET', $this->content_endpoint($path)); |
|
| 55 | + if (is_wp_error($result)) { |
|
| 56 | 56 | return false; |
| 57 | 57 | } |
| 58 | 58 | return true; |
@@ -65,27 +65,27 @@ discard block |
||
| 65 | 65 | * |
| 66 | 66 | * @return Writing_On_GitHub_File_Info[]|WP_Error |
| 67 | 67 | */ |
| 68 | - public function tree_recursive( $sha = '_default' ) { |
|
| 68 | + public function tree_recursive($sha = '_default') { |
|
| 69 | 69 | |
| 70 | - if ( '_default' === $sha ) { |
|
| 70 | + if ('_default' === $sha) { |
|
| 71 | 71 | $sha = $this->branch(); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - $data = $this->call( 'GET', $this->tree_endpoint() . '/' . $sha . '?recursive=1' ); |
|
| 74 | + $data = $this->call('GET', $this->tree_endpoint() . '/' . $sha . '?recursive=1'); |
|
| 75 | 75 | |
| 76 | - if ( is_wp_error( $data ) ) { |
|
| 76 | + if (is_wp_error($data)) { |
|
| 77 | 77 | return $data; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | $files = array(); |
| 81 | 81 | |
| 82 | - foreach ( $data->tree as $index => $thing ) { |
|
| 82 | + foreach ($data->tree as $index => $thing) { |
|
| 83 | 83 | // We need to remove the trees because |
| 84 | 84 | // the recursive tree includes both |
| 85 | 85 | // the subtrees as well the subtrees' blobs. |
| 86 | - if ( 'blob' === $thing->type ) { |
|
| 86 | + if ('blob' === $thing->type) { |
|
| 87 | 87 | $thing->status = ''; |
| 88 | - $files[] = new Writing_On_GitHub_File_Info( $thing ); |
|
| 88 | + $files[] = new Writing_On_GitHub_File_Info($thing); |
|
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | |
@@ -99,15 +99,15 @@ discard block |
||
| 99 | 99 | * |
| 100 | 100 | * @return Writing_On_GitHub_Blob|WP_Error |
| 101 | 101 | */ |
| 102 | - public function blob( Writing_On_GitHub_File_Info $fileinfo ) { |
|
| 103 | - $data = $this->call( 'GET', $this->blob_endpoint() . '/' . $fileinfo->sha ); |
|
| 102 | + public function blob(Writing_On_GitHub_File_Info $fileinfo) { |
|
| 103 | + $data = $this->call('GET', $this->blob_endpoint() . '/' . $fileinfo->sha); |
|
| 104 | 104 | |
| 105 | - if ( is_wp_error( $data ) ) { |
|
| 105 | + if (is_wp_error($data)) { |
|
| 106 | 106 | return $data; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | $data->path = $fileinfo->path; |
| 110 | - return new Writing_On_GitHub_Blob( $data ); |
|
| 110 | + return new Writing_On_GitHub_Blob($data); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -115,12 +115,12 @@ discard block |
||
| 115 | 115 | * @param string $path |
| 116 | 116 | * @return Writing_On_GitHub_Blob|WP_Error |
| 117 | 117 | */ |
| 118 | - public function blob_by_path( $path ) { |
|
| 119 | - $result = $this->call( 'GET', $this->content_endpoint( $path ) ); |
|
| 120 | - if ( is_wp_error( $result ) ) { |
|
| 118 | + public function blob_by_path($path) { |
|
| 119 | + $result = $this->call('GET', $this->content_endpoint($path)); |
|
| 120 | + if (is_wp_error($result)) { |
|
| 121 | 121 | return $result; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - return new Writing_On_GitHub_Blob( $result ); |
|
| 124 | + return new Writing_On_GitHub_Blob($result); |
|
| 125 | 125 | } |
| 126 | 126 | } |