@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | $this->app->semaphore()->unlock(); |
82 | 82 | |
83 | 83 | if ( is_wp_error( $result ) ) { |
84 | - /* @var WP_Error $result */ |
|
84 | + /* @var WP_Error $result */ |
|
85 | 85 | return $this->app->response()->error( $result ); |
86 | 86 | } |
87 | 87 | |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | |
114 | 114 | $this->app->semaphore()->unlock(); |
115 | 115 | |
116 | - if ( is_wp_error( $result ) ) { |
|
117 | - /* @var WP_Error $result */ |
|
118 | - update_option( '_wogh_import_error', $result->get_error_message() ); |
|
116 | + if ( is_wp_error( $result ) ) { |
|
117 | + /* @var WP_Error $result */ |
|
118 | + update_option( '_wogh_import_error', $result->get_error_message() ); |
|
119 | 119 | |
120 | 120 | return $this->app->response()->error( $result ); |
121 | 121 | } |
@@ -128,10 +128,10 @@ discard block |
||
128 | 128 | /** |
129 | 129 | * Export all the posts in the database to GitHub. |
130 | 130 | * |
131 | - * @param int $user_id |
|
132 | - * @param boolean $force |
|
133 | - * @return boolean |
|
134 | - */ |
|
131 | + * @param int $user_id |
|
132 | + * @param boolean $force |
|
133 | + * @return boolean |
|
134 | + */ |
|
135 | 135 | public function export_all( $user_id = 0, $force = false ) { |
136 | 136 | if ( ! $this->app->semaphore()->is_open() ) { |
137 | 137 | return $this->app->response()->error( new WP_Error( |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | |
152 | 152 | // Maybe move option updating out of this class/upgrade message display? |
153 | 153 | if ( is_wp_error( $result ) ) { |
154 | - /* @var WP_Error $result */ |
|
154 | + /* @var WP_Error $result */ |
|
155 | 155 | update_option( '_wogh_export_error', $result->get_error_message() ); |
156 | 156 | |
157 | 157 | return $this->app->response()->error( $result ); |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | $this->app->semaphore()->unlock(); |
190 | 190 | |
191 | 191 | if ( is_wp_error( $result ) ) { |
192 | - /* @var WP_Error $result */ |
|
192 | + /* @var WP_Error $result */ |
|
193 | 193 | return $this->app->response()->error( $result ); |
194 | 194 | } |
195 | 195 | |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | $this->app->semaphore()->unlock(); |
223 | 223 | |
224 | 224 | if ( is_wp_error( $result ) ) { |
225 | - /* @var WP_Error $result */ |
|
225 | + /* @var WP_Error $result */ |
|
226 | 226 | return $this->app->response()->error( $result ); |
227 | 227 | } |
228 | 228 |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param Writing_On_GitHub $app Applicatio container. |
23 | 23 | */ |
24 | - public function __construct( Writing_On_GitHub $app ) { |
|
24 | + public function __construct(Writing_On_GitHub $app) { |
|
25 | 25 | $this->app = $app; |
26 | 26 | } |
27 | 27 | |
@@ -34,58 +34,58 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function pull_posts() { |
36 | 36 | $this->set_ajax(); |
37 | - if ( ! $this->app->semaphore()->is_open() ) { |
|
38 | - return $this->app->response()->error( new WP_Error( |
|
37 | + if ( ! $this->app->semaphore()->is_open()) { |
|
38 | + return $this->app->response()->error(new WP_Error( |
|
39 | 39 | 'semaphore_locked', |
40 | - sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::pull_posts()' ) |
|
41 | - ) ); |
|
40 | + sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::pull_posts()') |
|
41 | + )); |
|
42 | 42 | } |
43 | 43 | |
44 | - if ( ! $this->app->request()->is_secret_valid() ) { |
|
45 | - return $this->app->response()->error( new WP_Error( |
|
44 | + if ( ! $this->app->request()->is_secret_valid()) { |
|
45 | + return $this->app->response()->error(new WP_Error( |
|
46 | 46 | 'invalid_headers', |
47 | - __( 'Failed to validate secret.', 'writing-on-github' ) |
|
48 | - ) ); |
|
47 | + __('Failed to validate secret.', 'writing-on-github') |
|
48 | + )); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | // ping |
52 | - if ( $this->app->request()->is_ping() ) { |
|
53 | - return $this->app->response()->success( __( 'Wordpress is ready.', 'writing-on-github' ) ); |
|
52 | + if ($this->app->request()->is_ping()) { |
|
53 | + return $this->app->response()->success(__('Wordpress is ready.', 'writing-on-github')); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | // push |
57 | - if ( ! $this->app->request()->is_push() ) { |
|
58 | - return $this->app->response()->error( new WP_Error( |
|
57 | + if ( ! $this->app->request()->is_push()) { |
|
58 | + return $this->app->response()->error(new WP_Error( |
|
59 | 59 | 'invalid_headers', |
60 | - __( 'Failed to validate webhook event.', 'writing-on-github' ) |
|
61 | - ) ); |
|
60 | + __('Failed to validate webhook event.', 'writing-on-github') |
|
61 | + )); |
|
62 | 62 | } |
63 | 63 | $payload = $this->app->request()->payload(); |
64 | 64 | |
65 | - if ( ! $payload->should_import() ) { |
|
66 | - return $this->app->response()->error( new WP_Error( |
|
65 | + if ( ! $payload->should_import()) { |
|
66 | + return $this->app->response()->error(new WP_Error( |
|
67 | 67 | 'invalid_payload', |
68 | 68 | sprintf( |
69 | - __( "%s won't be imported.", 'writing-on-github' ), |
|
70 | - strtolower( $payload->get_commit_id() ) ? : '[Missing Commit ID]' |
|
69 | + __("%s won't be imported.", 'writing-on-github'), |
|
70 | + strtolower($payload->get_commit_id()) ?: '[Missing Commit ID]' |
|
71 | 71 | ) |
72 | - ) ); |
|
72 | + )); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | $this->app->semaphore()->lock(); |
76 | - remove_action( 'save_post', array( $this, 'export_post' ) ); |
|
77 | - remove_action( 'delete_post', array( $this, 'delete_post' ) ); |
|
76 | + remove_action('save_post', array($this, 'export_post')); |
|
77 | + remove_action('delete_post', array($this, 'delete_post')); |
|
78 | 78 | |
79 | - $result = $this->app->import()->payload( $payload ); |
|
79 | + $result = $this->app->import()->payload($payload); |
|
80 | 80 | |
81 | 81 | $this->app->semaphore()->unlock(); |
82 | 82 | |
83 | - if ( is_wp_error( $result ) ) { |
|
83 | + if (is_wp_error($result)) { |
|
84 | 84 | /* @var WP_Error $result */ |
85 | - return $this->app->response()->error( $result ); |
|
85 | + return $this->app->response()->error($result); |
|
86 | 86 | } |
87 | 87 | |
88 | - return $this->app->response()->success( $result ); |
|
88 | + return $this->app->response()->success($result); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -93,36 +93,36 @@ discard block |
||
93 | 93 | * |
94 | 94 | * @return boolean |
95 | 95 | */ |
96 | - public function import_master( $user_id = 0 ) { |
|
97 | - if ( ! $this->app->semaphore()->is_open() ) { |
|
98 | - return $this->app->response()->error( new WP_Error( |
|
96 | + public function import_master($user_id = 0) { |
|
97 | + if ( ! $this->app->semaphore()->is_open()) { |
|
98 | + return $this->app->response()->error(new WP_Error( |
|
99 | 99 | 'semaphore_locked', |
100 | - sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::import_master()' ) |
|
101 | - ) ); |
|
100 | + sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::import_master()') |
|
101 | + )); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | $this->app->semaphore()->lock(); |
105 | - remove_action( 'save_post', array( $this, 'export_post' ) ); |
|
106 | - remove_action( 'save_post', array( $this, 'delete_post' ) ); |
|
105 | + remove_action('save_post', array($this, 'export_post')); |
|
106 | + remove_action('save_post', array($this, 'delete_post')); |
|
107 | 107 | |
108 | - if ( $user_id ) { |
|
109 | - wp_set_current_user( $user_id ); |
|
108 | + if ($user_id) { |
|
109 | + wp_set_current_user($user_id); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | $result = $this->app->import()->master(); |
113 | 113 | |
114 | 114 | $this->app->semaphore()->unlock(); |
115 | 115 | |
116 | - if ( is_wp_error( $result ) ) { |
|
116 | + if (is_wp_error($result)) { |
|
117 | 117 | /* @var WP_Error $result */ |
118 | - update_option( '_wogh_import_error', $result->get_error_message() ); |
|
118 | + update_option('_wogh_import_error', $result->get_error_message()); |
|
119 | 119 | |
120 | - return $this->app->response()->error( $result ); |
|
120 | + return $this->app->response()->error($result); |
|
121 | 121 | } |
122 | 122 | |
123 | - update_option( '_wogh_import_complete', 'yes' ); |
|
123 | + update_option('_wogh_import_complete', 'yes'); |
|
124 | 124 | |
125 | - return $this->app->response()->success( $result ); |
|
125 | + return $this->app->response()->success($result); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -132,34 +132,34 @@ discard block |
||
132 | 132 | * @param boolean $force |
133 | 133 | * @return boolean |
134 | 134 | */ |
135 | - public function export_all( $user_id = 0, $force = false ) { |
|
136 | - if ( ! $this->app->semaphore()->is_open() ) { |
|
137 | - return $this->app->response()->error( new WP_Error( |
|
135 | + public function export_all($user_id = 0, $force = false) { |
|
136 | + if ( ! $this->app->semaphore()->is_open()) { |
|
137 | + return $this->app->response()->error(new WP_Error( |
|
138 | 138 | 'semaphore_locked', |
139 | - sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::export_all()' ) |
|
140 | - ) ); |
|
139 | + sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::export_all()') |
|
140 | + )); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | $this->app->semaphore()->lock(); |
144 | 144 | |
145 | - if ( $user_id ) { |
|
146 | - wp_set_current_user( $user_id ); |
|
145 | + if ($user_id) { |
|
146 | + wp_set_current_user($user_id); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | $result = $this->app->export()->full($force); |
150 | 150 | $this->app->semaphore()->unlock(); |
151 | 151 | |
152 | 152 | // Maybe move option updating out of this class/upgrade message display? |
153 | - if ( is_wp_error( $result ) ) { |
|
153 | + if (is_wp_error($result)) { |
|
154 | 154 | /* @var WP_Error $result */ |
155 | - update_option( '_wogh_export_error', $result->get_error_message() ); |
|
155 | + update_option('_wogh_export_error', $result->get_error_message()); |
|
156 | 156 | |
157 | - return $this->app->response()->error( $result ); |
|
157 | + return $this->app->response()->error($result); |
|
158 | 158 | } else { |
159 | - update_option( '_wogh_export_complete', 'yes' ); |
|
160 | - update_option( '_wogh_fully_exported', 'yes' ); |
|
159 | + update_option('_wogh_export_complete', 'yes'); |
|
160 | + update_option('_wogh_fully_exported', 'yes'); |
|
161 | 161 | |
162 | - return $this->app->response()->success( $result ); |
|
162 | + return $this->app->response()->success($result); |
|
163 | 163 | } |
164 | 164 | } |
165 | 165 | |
@@ -172,28 +172,28 @@ discard block |
||
172 | 172 | * |
173 | 173 | * @return boolean |
174 | 174 | */ |
175 | - public function export_post( $post_id ) { |
|
176 | - if ( wp_is_post_revision( $post_id ) ) { |
|
175 | + public function export_post($post_id) { |
|
176 | + if (wp_is_post_revision($post_id)) { |
|
177 | 177 | return; |
178 | 178 | } |
179 | 179 | |
180 | - if ( ! $this->app->semaphore()->is_open() ) { |
|
181 | - return $this->app->response()->error( new WP_Error( |
|
180 | + if ( ! $this->app->semaphore()->is_open()) { |
|
181 | + return $this->app->response()->error(new WP_Error( |
|
182 | 182 | 'semaphore_locked', |
183 | - sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::export_post()' ) |
|
184 | - ) ); |
|
183 | + sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::export_post()') |
|
184 | + )); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | $this->app->semaphore()->lock(); |
188 | - $result = $this->app->export()->update( $post_id ); |
|
188 | + $result = $this->app->export()->update($post_id); |
|
189 | 189 | $this->app->semaphore()->unlock(); |
190 | 190 | |
191 | - if ( is_wp_error( $result ) ) { |
|
191 | + if (is_wp_error($result)) { |
|
192 | 192 | /* @var WP_Error $result */ |
193 | - return $this->app->response()->error( $result ); |
|
193 | + return $this->app->response()->error($result); |
|
194 | 194 | } |
195 | 195 | |
196 | - return $this->app->response()->success( $result ); |
|
196 | + return $this->app->response()->success($result); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -205,28 +205,28 @@ discard block |
||
205 | 205 | * |
206 | 206 | * @return boolean |
207 | 207 | */ |
208 | - public function delete_post( $post_id ) { |
|
209 | - if ( wp_is_post_revision( $post_id ) ) { |
|
208 | + public function delete_post($post_id) { |
|
209 | + if (wp_is_post_revision($post_id)) { |
|
210 | 210 | return; |
211 | 211 | } |
212 | 212 | |
213 | - if ( ! $this->app->semaphore()->is_open() ) { |
|
214 | - return $this->app->response()->error( new WP_Error( |
|
213 | + if ( ! $this->app->semaphore()->is_open()) { |
|
214 | + return $this->app->response()->error(new WP_Error( |
|
215 | 215 | 'semaphore_locked', |
216 | - sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::delete_post()' ) |
|
217 | - ) ); |
|
216 | + sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::delete_post()') |
|
217 | + )); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | $this->app->semaphore()->lock(); |
221 | - $result = $this->app->export()->delete( $post_id ); |
|
221 | + $result = $this->app->export()->delete($post_id); |
|
222 | 222 | $this->app->semaphore()->unlock(); |
223 | 223 | |
224 | - if ( is_wp_error( $result ) ) { |
|
224 | + if (is_wp_error($result)) { |
|
225 | 225 | /* @var WP_Error $result */ |
226 | - return $this->app->response()->error( $result ); |
|
226 | + return $this->app->response()->error($result); |
|
227 | 227 | } |
228 | 228 | |
229 | - return $this->app->response()->success( $result ); |
|
229 | + return $this->app->response()->success($result); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -235,8 +235,8 @@ discard block |
||
235 | 235 | * than just returning data. |
236 | 236 | */ |
237 | 237 | protected function set_ajax() { |
238 | - if ( ! defined( 'WOGH_AJAX' ) ) { |
|
239 | - define( 'WOGH_AJAX', true ); |
|
238 | + if ( ! defined('WOGH_AJAX')) { |
|
239 | + define('WOGH_AJAX', true); |
|
240 | 240 | } |
241 | 241 | } |
242 | 242 | } |
@@ -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 | |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | $post = $this->app->database()->fetch_by_id( $post_id ); |
223 | 223 | |
224 | 224 | if ( is_wp_error( $post ) ) { |
225 | - /* @var WP_Error $post */ |
|
225 | + /* @var WP_Error $post */ |
|
226 | 226 | return $post; |
227 | 227 | } |
228 | 228 | |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | $result = $this->app->api()->persist()->delete_file( $github_path, $post->sha(), $message ); |
243 | 243 | |
244 | 244 | if ( is_wp_error( $result ) ) { |
245 | - /* @var WP_Error $result */ |
|
245 | + /* @var WP_Error $result */ |
|
246 | 246 | return $result; |
247 | 247 | } |
248 | 248 |
@@ -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,30 +84,30 @@ 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 | return $result; |
108 | 108 | } |
109 | 109 | |
110 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
110 | + return __('Export to GitHub completed successfully.', 'writing-on-github'); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -117,16 +117,16 @@ discard block |
||
117 | 117 | * |
118 | 118 | * @return string|WP_Error|true |
119 | 119 | */ |
120 | - public function new_posts( array $posts ) { |
|
120 | + public function new_posts(array $posts) { |
|
121 | 121 | $error = false; |
122 | 122 | |
123 | 123 | $persist = $this->app->api()->persist(); |
124 | 124 | |
125 | - foreach ( $posts as $post ) { |
|
126 | - $result = $this->new_post( $post, $persist ); |
|
127 | - if ( is_wp_error( $result ) ) { |
|
128 | - if ( $error ) { |
|
129 | - $error->add( $result->get_error_code(), $result->get_error_message() ); |
|
125 | + foreach ($posts as $post) { |
|
126 | + $result = $this->new_post($post, $persist); |
|
127 | + if (is_wp_error($result)) { |
|
128 | + if ($error) { |
|
129 | + $error->add($result->get_error_code(), $result->get_error_message()); |
|
130 | 130 | } else { |
131 | 131 | $error = $result; |
132 | 132 | } |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | |
138 | 138 | // $result = $this->app->api()->persist()->commit( $master ); |
139 | 139 | |
140 | - if ( is_wp_error( $error ) ) { |
|
140 | + if (is_wp_error($error)) { |
|
141 | 141 | return $error; |
142 | 142 | } |
143 | 143 | |
@@ -145,13 +145,13 @@ discard block |
||
145 | 145 | return true; |
146 | 146 | } |
147 | 147 | |
148 | - protected function new_post( $post, $persist ) { |
|
148 | + protected function new_post($post, $persist) { |
|
149 | 149 | $github_path = $post->github_path(); |
150 | 150 | $old_github_path = $post->old_github_path(); |
151 | 151 | $blob = $post->to_blob(); |
152 | 152 | $result = false; |
153 | 153 | |
154 | - if ( $old_github_path && $old_github_path != $github_path ) { |
|
154 | + if ($old_github_path && $old_github_path != $github_path) { |
|
155 | 155 | // rename |
156 | 156 | $message = apply_filters( |
157 | 157 | 'wogh_commit_msg_move_post', |
@@ -159,20 +159,20 @@ discard block |
||
159 | 159 | 'Move %s to %s via WordPress at %s (%s)', |
160 | 160 | $old_github_path, $github_path, |
161 | 161 | site_url(), |
162 | - get_bloginfo( 'name' ) |
|
162 | + get_bloginfo('name') |
|
163 | 163 | ) |
164 | 164 | ) . $this->get_commit_msg_tag(); |
165 | 165 | |
166 | - $result = $persist->delete_file( $post->old_github_path(), $blob->sha(), $message ); |
|
167 | - if ( is_wp_error( $result ) ) { |
|
166 | + $result = $persist->delete_file($post->old_github_path(), $blob->sha(), $message); |
|
167 | + if (is_wp_error($result)) { |
|
168 | 168 | return $result; |
169 | 169 | } |
170 | 170 | |
171 | - $result = $persist->create_file( $blob, $message ); |
|
172 | - if ( is_wp_error( $result ) ) { |
|
171 | + $result = $persist->create_file($blob, $message); |
|
172 | + if (is_wp_error($result)) { |
|
173 | 173 | return $result; |
174 | 174 | } |
175 | - } elseif ( ! $old_github_path ) { |
|
175 | + } elseif ( ! $old_github_path) { |
|
176 | 176 | // create new |
177 | 177 | $message = apply_filters( |
178 | 178 | 'wogh_commit_msg_new_post', |
@@ -180,14 +180,14 @@ discard block |
||
180 | 180 | 'Create new post %s from WordPress at %s (%s)', |
181 | 181 | $github_path, |
182 | 182 | site_url(), |
183 | - get_bloginfo( 'name' ) |
|
183 | + get_bloginfo('name') |
|
184 | 184 | ) |
185 | 185 | ) . $this->get_commit_msg_tag(); |
186 | - $result = $persist->create_file( $blob, $message ); |
|
187 | - if ( is_wp_error( $result ) ) { |
|
186 | + $result = $persist->create_file($blob, $message); |
|
187 | + if (is_wp_error($result)) { |
|
188 | 188 | return $result; |
189 | 189 | } |
190 | - } elseif ( $old_github_path && $old_github_path == $github_path ) { |
|
190 | + } elseif ($old_github_path && $old_github_path == $github_path) { |
|
191 | 191 | // update |
192 | 192 | $message = apply_filters( |
193 | 193 | 'wogh_commit_msg_update_post', |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | 'Update post %s from WordPress at %s (%s)', |
196 | 196 | $github_path, |
197 | 197 | site_url(), |
198 | - get_bloginfo( 'name' ) |
|
198 | + get_bloginfo('name') |
|
199 | 199 | ) |
200 | 200 | ) . $this->get_commit_msg_tag(); |
201 | - $result = $persist->update_file( $blob, $message ); |
|
202 | - if ( is_wp_error( $result ) ) { |
|
201 | + $result = $persist->update_file($blob, $message); |
|
202 | + if (is_wp_error($result)) { |
|
203 | 203 | return $result; |
204 | 204 | } |
205 | 205 | } |
@@ -218,15 +218,15 @@ discard block |
||
218 | 218 | * |
219 | 219 | * @return string|WP_Error |
220 | 220 | */ |
221 | - public function delete( $post_id ) { |
|
222 | - $post = $this->app->database()->fetch_by_id( $post_id ); |
|
221 | + public function delete($post_id) { |
|
222 | + $post = $this->app->database()->fetch_by_id($post_id); |
|
223 | 223 | |
224 | - if ( is_wp_error( $post ) ) { |
|
224 | + if (is_wp_error($post)) { |
|
225 | 225 | /* @var WP_Error $post */ |
226 | 226 | return $post; |
227 | 227 | } |
228 | 228 | |
229 | - $github_path = get_post_meta( $post_id, '_wogh_github_path', true ); |
|
229 | + $github_path = get_post_meta($post_id, '_wogh_github_path', true); |
|
230 | 230 | |
231 | 231 | $message = apply_filters( |
232 | 232 | 'wogh_commit_msg_delete', |
@@ -234,19 +234,19 @@ discard block |
||
234 | 234 | 'Deleting %s via WordPress at %s (%s)', |
235 | 235 | $github_path, |
236 | 236 | site_url(), |
237 | - get_bloginfo( 'name' ) |
|
237 | + get_bloginfo('name') |
|
238 | 238 | ), |
239 | 239 | $post |
240 | 240 | ) . $this->get_commit_msg_tag(); |
241 | 241 | |
242 | - $result = $this->app->api()->persist()->delete_file( $github_path, $post->sha(), $message ); |
|
242 | + $result = $this->app->api()->persist()->delete_file($github_path, $post->sha(), $message); |
|
243 | 243 | |
244 | - if ( is_wp_error( $result ) ) { |
|
244 | + if (is_wp_error($result)) { |
|
245 | 245 | /* @var WP_Error $result */ |
246 | 246 | return $result; |
247 | 247 | } |
248 | 248 | |
249 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
249 | + return __('Export to GitHub completed successfully.', 'writing-on-github'); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | |
@@ -257,8 +257,8 @@ discard block |
||
257 | 257 | * |
258 | 258 | * @return bool |
259 | 259 | */ |
260 | - public function set_user( $user_id ) { |
|
261 | - return update_option( self::EXPORT_USER_OPTION, (int) $user_id ); |
|
260 | + public function set_user($user_id) { |
|
261 | + return update_option(self::EXPORT_USER_OPTION, (int) $user_id); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
@@ -267,10 +267,10 @@ discard block |
||
267 | 267 | * @return string |
268 | 268 | */ |
269 | 269 | protected function get_commit_msg_tag() { |
270 | - $tag = apply_filters( 'wogh_commit_msg_tag', 'wogh' ); |
|
270 | + $tag = apply_filters('wogh_commit_msg_tag', 'wogh'); |
|
271 | 271 | |
272 | - if ( ! $tag ) { |
|
273 | - throw new Exception( __( 'Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github' ) ); |
|
272 | + if ( ! $tag) { |
|
273 | + throw new Exception(__('Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github')); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | return ' - ' . $tag; |
@@ -41,7 +41,7 @@ |
||
41 | 41 | */ |
42 | 42 | protected function call( $method, $endpoint, $body = array() ) { |
43 | 43 | if ( is_wp_error( $error = $this->can_call() ) ) { |
44 | - /* @var WP_Error $error */ |
|
44 | + /* @var WP_Error $error */ |
|
45 | 45 | return $error; |
46 | 46 | } |
47 | 47 |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @param Writing_On_GitHub $app Application container. |
28 | 28 | */ |
29 | - public function __construct( Writing_On_GitHub $app ) { |
|
29 | + public function __construct(Writing_On_GitHub $app) { |
|
30 | 30 | $this->app = $app; |
31 | 31 | } |
32 | 32 | |
@@ -39,8 +39,8 @@ discard block |
||
39 | 39 | * |
40 | 40 | * @return stdClass|WP_Error |
41 | 41 | */ |
42 | - protected function call( $method, $endpoint, $body = array() ) { |
|
43 | - if ( is_wp_error( $error = $this->can_call() ) ) { |
|
42 | + protected function call($method, $endpoint, $body = array()) { |
|
43 | + if (is_wp_error($error = $this->can_call())) { |
|
44 | 44 | /* @var WP_Error $error */ |
45 | 45 | return $error; |
46 | 46 | } |
@@ -52,24 +52,23 @@ discard block |
||
52 | 52 | ), |
53 | 53 | ); |
54 | 54 | |
55 | - if ( 'GET' !== $method ) { |
|
56 | - $args['body'] = function_exists( 'wp_json_encode' ) ? |
|
57 | - wp_json_encode( $body ) : |
|
58 | - json_encode( $body ); |
|
55 | + if ('GET' !== $method) { |
|
56 | + $args['body'] = function_exists('wp_json_encode') ? |
|
57 | + wp_json_encode($body) : json_encode($body); |
|
59 | 58 | } |
60 | 59 | |
61 | 60 | $tmpbody = isset($args['body']) ? $args['body'] : ''; |
62 | 61 | error_log("writing-on-github-call $method $endpoint $tmpbody"); |
63 | 62 | |
64 | - $response = wp_remote_request( $endpoint, $args ); |
|
65 | - $status = wp_remote_retrieve_header( $response, 'status' ); |
|
66 | - $body = json_decode( wp_remote_retrieve_body( $response ) ); |
|
63 | + $response = wp_remote_request($endpoint, $args); |
|
64 | + $status = wp_remote_retrieve_header($response, 'status'); |
|
65 | + $body = json_decode(wp_remote_retrieve_body($response)); |
|
67 | 66 | |
68 | - if ( '2' !== substr( $status, 0, 1 ) && '3' !== substr( $status, 0, 1 ) ) { |
|
67 | + if ('2' !== substr($status, 0, 1) && '3' !== substr($status, 0, 1)) { |
|
69 | 68 | return new WP_Error( |
70 | - strtolower( str_replace( ' ', '_', $status ) ), |
|
69 | + strtolower(str_replace(' ', '_', $status)), |
|
71 | 70 | sprintf( |
72 | - __( 'Method %s to endpoint %s failed with error: %s', 'writing-on-github' ), |
|
71 | + __('Method %s to endpoint %s failed with error: %s', 'writing-on-github'), |
|
73 | 72 | $method, |
74 | 73 | $endpoint, |
75 | 74 | $body && $body->message ? $body->message : 'Unknown error' |
@@ -86,28 +85,28 @@ discard block |
||
86 | 85 | * @return true|WP_Error |
87 | 86 | */ |
88 | 87 | protected function can_call() { |
89 | - if ( ! $this->oauth_token() ) { |
|
88 | + if ( ! $this->oauth_token()) { |
|
90 | 89 | return new WP_Error( |
91 | 90 | 'missing_token', |
92 | - __( 'Writing On GitHub needs an auth token. Please update your settings.', 'writing-on-github' ) |
|
91 | + __('Writing On GitHub needs an auth token. Please update your settings.', 'writing-on-github') |
|
93 | 92 | ); |
94 | 93 | } |
95 | 94 | |
96 | 95 | $repo = $this->repository(); |
97 | 96 | |
98 | - if ( ! $repo ) { |
|
97 | + if ( ! $repo) { |
|
99 | 98 | return new WP_Error( |
100 | 99 | 'missing_repository', |
101 | - __( 'Writing On GitHub needs a repository. Please update your settings.', 'writing-on-github' ) |
|
100 | + __('Writing On GitHub needs a repository. Please update your settings.', 'writing-on-github') |
|
102 | 101 | ); |
103 | 102 | } |
104 | 103 | |
105 | - $parts = explode( '/', $repo ); |
|
104 | + $parts = explode('/', $repo); |
|
106 | 105 | |
107 | - if ( 2 !== count( $parts ) ) { |
|
106 | + if (2 !== count($parts)) { |
|
108 | 107 | return new WP_Error( |
109 | 108 | 'malformed_repository', |
110 | - __( 'Writing On GitHub needs a properly formed repository. Please update your settings.', 'writing-on-github' ) |
|
109 | + __('Writing On GitHub needs a properly formed repository. Please update your settings.', 'writing-on-github') |
|
111 | 110 | ); |
112 | 111 | } |
113 | 112 | |
@@ -120,7 +119,7 @@ discard block |
||
120 | 119 | * @return string |
121 | 120 | */ |
122 | 121 | public function repository() { |
123 | - return (string) get_option( self::REPO_OPTION_KEY ); |
|
122 | + return (string) get_option(self::REPO_OPTION_KEY); |
|
124 | 123 | } |
125 | 124 | |
126 | 125 | /** |
@@ -129,18 +128,18 @@ discard block |
||
129 | 128 | * @return string |
130 | 129 | */ |
131 | 130 | public function oauth_token() { |
132 | - return (string) get_option( self::TOKEN_OPTION_KEY ); |
|
131 | + return (string) get_option(self::TOKEN_OPTION_KEY); |
|
133 | 132 | } |
134 | 133 | |
135 | 134 | /** |
136 | 135 | * Returns the GitHub host to sync with (for GitHub Enterprise support) |
137 | 136 | */ |
138 | 137 | public function api_base() { |
139 | - return get_option( self::HOST_OPTION_KEY ); |
|
138 | + return get_option(self::HOST_OPTION_KEY); |
|
140 | 139 | } |
141 | 140 | |
142 | 141 | public function branch() { |
143 | - $branch = get_option( self::BRANCH_OPTION_KEY ); |
|
142 | + $branch = get_option(self::BRANCH_OPTION_KEY); |
|
144 | 143 | return $branch ? $branch : 'master'; |
145 | 144 | } |
146 | 145 | |
@@ -201,11 +200,11 @@ discard block |
||
201 | 200 | * |
202 | 201 | * Returns String the relative API call path |
203 | 202 | */ |
204 | - public function content_endpoint( $path = false ) { |
|
203 | + public function content_endpoint($path = false) { |
|
205 | 204 | $url = $this->api_base() . '/repos/'; |
206 | 205 | $url = $url . $this->repository() . '/contents'; |
207 | 206 | |
208 | - if ( ! empty($path) ) { |
|
207 | + if ( ! empty($path)) { |
|
209 | 208 | $url .= '/' . $path; |
210 | 209 | } |
211 | 210 |
@@ -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 | } |