@@ -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 ( $this->headers ) { |
|
104 | + if ($this->headers) { |
|
105 | 105 | return $this->headers; |
106 | 106 | } |
107 | 107 | |
108 | - if ( function_exists( 'getallheaders' ) ) { |
|
108 | + if (function_exists('getallheaders')) { |
|
109 | 109 | |
110 | 110 | $this->headers = getallheaders(); |
111 | 111 | return $this->headers; |
@@ -115,9 +115,9 @@ discard block |
||
115 | 115 | * @see http://www.php.net/manual/en/function.getallheaders.php |
116 | 116 | */ |
117 | 117 | $this->headers = array(); |
118 | - foreach ( $_SERVER as $name => $value ) { |
|
119 | - if ( 'HTTP_' === substr( $name, 0, 5 ) ) { |
|
120 | - $this->headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value; |
|
118 | + foreach ($_SERVER as $name => $value) { |
|
119 | + if ('HTTP_' === substr($name, 0, 5)) { |
|
120 | + $this->headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; |
|
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | * @return string |
131 | 131 | */ |
132 | 132 | protected function read_raw_data() { |
133 | - return file_get_contents( 'php://input' ); |
|
133 | + return file_get_contents('php://input'); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -139,6 +139,6 @@ discard block |
||
139 | 139 | * @return string |
140 | 140 | */ |
141 | 141 | protected function secret() { |
142 | - return get_option( 'wogh_secret' ); |
|
142 | + return get_option('wogh_secret'); |
|
143 | 143 | } |
144 | 144 | } |
@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | /** |
30 | 30 | * Updates all of the current posts in the database on master. |
31 | 31 | * |
32 | - * @param bool $force_all |
|
33 | - * @return string|WP_Error |
|
34 | - */ |
|
32 | + * @param bool $force_all |
|
33 | + * @return string|WP_Error |
|
34 | + */ |
|
35 | 35 | public function full( $force_all = false ) { |
36 | 36 | $posts = $this->app->database()->fetch_all_supported($force_all); |
37 | 37 | |
@@ -39,24 +39,24 @@ discard block |
||
39 | 39 | return $posts; |
40 | 40 | } |
41 | 41 | |
42 | - $error = false; |
|
42 | + $error = false; |
|
43 | 43 | |
44 | - foreach ( $posts as $post ) { |
|
45 | - $result = $this->update( $post->id() ); |
|
46 | - if ( is_wp_error( $result ) ) { |
|
47 | - if ( $error ) { |
|
48 | - $error->add( $result->get_error_code(), $result->get_error_message() ); |
|
49 | - } else { |
|
50 | - $error = $result; |
|
51 | - } |
|
52 | - } |
|
53 | - } |
|
44 | + foreach ( $posts as $post ) { |
|
45 | + $result = $this->update( $post->id() ); |
|
46 | + if ( is_wp_error( $result ) ) { |
|
47 | + if ( $error ) { |
|
48 | + $error->add( $result->get_error_code(), $result->get_error_message() ); |
|
49 | + } else { |
|
50 | + $error = $result; |
|
51 | + } |
|
52 | + } |
|
53 | + } |
|
54 | 54 | |
55 | - if ( is_wp_error( $error ) ) { |
|
56 | - return $error; |
|
57 | - } |
|
55 | + if ( is_wp_error( $error ) ) { |
|
56 | + return $error; |
|
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 |
@@ -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,31 +32,31 @@ discard block |
||
32 | 32 | * @param bool $force_all |
33 | 33 | * @return string|WP_Error |
34 | 34 | */ |
35 | - public function full( $force_all = false ) { |
|
35 | + public function full($force_all = false) { |
|
36 | 36 | $posts = $this->app->database()->fetch_all_supported($force_all); |
37 | 37 | |
38 | - if ( is_wp_error( $posts ) ) { |
|
38 | + if (is_wp_error($posts)) { |
|
39 | 39 | return $posts; |
40 | 40 | } |
41 | 41 | |
42 | 42 | $error = false; |
43 | 43 | |
44 | - foreach ( $posts as $post ) { |
|
45 | - $result = $this->update( $post->id() ); |
|
46 | - if ( is_wp_error( $result ) ) { |
|
47 | - if ( $error ) { |
|
48 | - $error->add( $result->get_error_code(), $result->get_error_message() ); |
|
44 | + foreach ($posts as $post) { |
|
45 | + $result = $this->update($post->id()); |
|
46 | + if (is_wp_error($result)) { |
|
47 | + if ($error) { |
|
48 | + $error->add($result->get_error_code(), $result->get_error_message()); |
|
49 | 49 | } else { |
50 | 50 | $error = $result; |
51 | 51 | } |
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
55 | - if ( is_wp_error( $error ) ) { |
|
55 | + if (is_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,29 +82,29 @@ 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 | return $post; |
90 | 90 | } |
91 | 91 | |
92 | - if ( 'trash' === $post->status() ) { |
|
93 | - return $this->delete( $post_id ); |
|
92 | + if ('trash' === $post->status()) { |
|
93 | + return $this->delete($post_id); |
|
94 | 94 | } |
95 | 95 | |
96 | - if ( $old_github_path = $this->github_path( $post->id() ) ) { |
|
96 | + if ($old_github_path = $this->github_path($post->id())) { |
|
97 | 97 | error_log("old_github_path: $old_github_path"); |
98 | 98 | $post->set_old_github_path($old_github_path); |
99 | 99 | } |
100 | 100 | |
101 | - $result = $this->new_posts( array( $post ) ); |
|
101 | + $result = $this->new_posts(array($post)); |
|
102 | 102 | |
103 | - if ( is_wp_error( $result ) ) { |
|
103 | + if (is_wp_error($result)) { |
|
104 | 104 | return $result; |
105 | 105 | } |
106 | 106 | |
107 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
107 | + return __('Export to GitHub completed successfully.', 'writing-on-github'); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -114,16 +114,16 @@ discard block |
||
114 | 114 | * |
115 | 115 | * @return string|WP_Error |
116 | 116 | */ |
117 | - public function new_posts( array $posts ) { |
|
117 | + public function new_posts(array $posts) { |
|
118 | 118 | $error = false; |
119 | 119 | |
120 | 120 | $persist = $this->app->api()->persist(); |
121 | 121 | |
122 | - foreach ( $posts as $post ) { |
|
123 | - $result = $this->new_post( $post, $persist ); |
|
124 | - if ( is_wp_error( $result ) ) { |
|
125 | - if ( $error ) { |
|
126 | - $error->add( $result->get_error_code(), $result->get_error_message() ); |
|
122 | + foreach ($posts as $post) { |
|
123 | + $result = $this->new_post($post, $persist); |
|
124 | + if (is_wp_error($result)) { |
|
125 | + if ($error) { |
|
126 | + $error->add($result->get_error_code(), $result->get_error_message()); |
|
127 | 127 | } else { |
128 | 128 | $error = $result; |
129 | 129 | } |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | |
135 | 135 | // $result = $this->app->api()->persist()->commit( $master ); |
136 | 136 | |
137 | - if ( is_wp_error( $error ) ) { |
|
137 | + if (is_wp_error($error)) { |
|
138 | 138 | return $error; |
139 | 139 | } |
140 | 140 | |
@@ -142,13 +142,13 @@ discard block |
||
142 | 142 | return true; |
143 | 143 | } |
144 | 144 | |
145 | - protected function new_post( $post, $persist ) { |
|
145 | + protected function new_post($post, $persist) { |
|
146 | 146 | $github_path = $post->github_path(); |
147 | 147 | $old_github_path = $post->old_github_path(); |
148 | 148 | $blob = $post->to_blob(); |
149 | 149 | $result = false; |
150 | 150 | |
151 | - if ( $old_github_path && $old_github_path != $github_path ) { |
|
151 | + if ($old_github_path && $old_github_path != $github_path) { |
|
152 | 152 | // rename |
153 | 153 | $message = apply_filters( |
154 | 154 | 'wogh_commit_msg_move_post', |
@@ -156,20 +156,20 @@ discard block |
||
156 | 156 | 'Move %s to %s via WordPress at %s (%s)', |
157 | 157 | $old_github_path, $github_path, |
158 | 158 | site_url(), |
159 | - get_bloginfo( 'name' ) |
|
159 | + get_bloginfo('name') |
|
160 | 160 | ) |
161 | 161 | ) . $this->get_commit_msg_tag(); |
162 | 162 | |
163 | - $result = $persist->delete_file( $post->old_github_path(), $blob->sha(), $message ); |
|
164 | - if ( is_wp_error( $result ) ) { |
|
163 | + $result = $persist->delete_file($post->old_github_path(), $blob->sha(), $message); |
|
164 | + if (is_wp_error($result)) { |
|
165 | 165 | return $result; |
166 | 166 | } |
167 | 167 | |
168 | - $result = $persist->create_file( $blob, $message ); |
|
169 | - if ( is_wp_error( $result ) ) { |
|
168 | + $result = $persist->create_file($blob, $message); |
|
169 | + if (is_wp_error($result)) { |
|
170 | 170 | return $result; |
171 | 171 | } |
172 | - } elseif ( ! $old_github_path ) { |
|
172 | + } elseif ( ! $old_github_path) { |
|
173 | 173 | // create new |
174 | 174 | $message = apply_filters( |
175 | 175 | 'wogh_commit_msg_new_post', |
@@ -177,14 +177,14 @@ discard block |
||
177 | 177 | 'Create new post %s from WordPress at %s (%s)', |
178 | 178 | $github_path, |
179 | 179 | site_url(), |
180 | - get_bloginfo( 'name' ) |
|
180 | + get_bloginfo('name') |
|
181 | 181 | ) |
182 | 182 | ) . $this->get_commit_msg_tag(); |
183 | - $result = $persist->create_file( $blob, $message ); |
|
184 | - if ( is_wp_error( $result ) ) { |
|
183 | + $result = $persist->create_file($blob, $message); |
|
184 | + if (is_wp_error($result)) { |
|
185 | 185 | return $result; |
186 | 186 | } |
187 | - } elseif ( $old_github_path && $old_github_path == $github_path ) { |
|
187 | + } elseif ($old_github_path && $old_github_path == $github_path) { |
|
188 | 188 | // update |
189 | 189 | $message = apply_filters( |
190 | 190 | 'wogh_commit_msg_update_post', |
@@ -192,11 +192,11 @@ discard block |
||
192 | 192 | 'Update post %s from WordPress at %s (%s)', |
193 | 193 | $github_path, |
194 | 194 | site_url(), |
195 | - get_bloginfo( 'name' ) |
|
195 | + get_bloginfo('name') |
|
196 | 196 | ) |
197 | 197 | ) . $this->get_commit_msg_tag(); |
198 | - $result = $persist->update_file( $blob, $message ); |
|
199 | - if ( is_wp_error( $result ) ) { |
|
198 | + $result = $persist->update_file($blob, $message); |
|
199 | + if (is_wp_error($result)) { |
|
200 | 200 | return $result; |
201 | 201 | } |
202 | 202 | } |
@@ -215,14 +215,14 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @return string|WP_Error |
217 | 217 | */ |
218 | - public function delete( $post_id ) { |
|
219 | - $post = $this->app->database()->fetch_by_id( $post_id ); |
|
218 | + public function delete($post_id) { |
|
219 | + $post = $this->app->database()->fetch_by_id($post_id); |
|
220 | 220 | |
221 | - if ( is_wp_error( $post ) ) { |
|
221 | + if (is_wp_error($post)) { |
|
222 | 222 | return $post; |
223 | 223 | } |
224 | 224 | |
225 | - $github_path = get_post_meta( $post_id, '_wogh_github_path', true ); |
|
225 | + $github_path = get_post_meta($post_id, '_wogh_github_path', true); |
|
226 | 226 | |
227 | 227 | $message = apply_filters( |
228 | 228 | 'wogh_commit_msg_delete', |
@@ -230,18 +230,18 @@ discard block |
||
230 | 230 | 'Deleting %s via WordPress at %s (%s)', |
231 | 231 | $github_path, |
232 | 232 | site_url(), |
233 | - get_bloginfo( 'name' ) |
|
233 | + get_bloginfo('name') |
|
234 | 234 | ), |
235 | 235 | $post |
236 | 236 | ) . $this->get_commit_msg_tag(); |
237 | 237 | |
238 | - $result = $this->app->api()->persist()->delete_file( $github_path, $post->sha(), $message ); |
|
238 | + $result = $this->app->api()->persist()->delete_file($github_path, $post->sha(), $message); |
|
239 | 239 | |
240 | - if ( is_wp_error( $result ) ) { |
|
240 | + if (is_wp_error($result)) { |
|
241 | 241 | return $result; |
242 | 242 | } |
243 | 243 | |
244 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
244 | + return __('Export to GitHub completed successfully.', 'writing-on-github'); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | |
@@ -252,8 +252,8 @@ discard block |
||
252 | 252 | * |
253 | 253 | * @return bool |
254 | 254 | */ |
255 | - public function set_user( $user_id ) { |
|
256 | - return update_option( self::EXPORT_USER_OPTION, (int) $user_id ); |
|
255 | + public function set_user($user_id) { |
|
256 | + return update_option(self::EXPORT_USER_OPTION, (int) $user_id); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
@@ -262,10 +262,10 @@ discard block |
||
262 | 262 | * @return string |
263 | 263 | */ |
264 | 264 | protected function get_commit_msg_tag() { |
265 | - $tag = apply_filters( 'wogh_commit_msg_tag', 'wogh' ); |
|
265 | + $tag = apply_filters('wogh_commit_msg_tag', 'wogh'); |
|
266 | 266 | |
267 | - if ( ! $tag ) { |
|
268 | - throw new Exception( __( 'Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github' ) ); |
|
267 | + if ( ! $tag) { |
|
268 | + throw new Exception(__('Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github')); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | return ' - ' . $tag; |
@@ -16,9 +16,9 @@ discard block |
||
16 | 16 | */ |
17 | 17 | protected function export_user() { |
18 | 18 | $user_id = get_current_user_id(); |
19 | - $user = get_userdata( $user_id ); |
|
19 | + $user = get_userdata($user_id); |
|
20 | 20 | |
21 | - if ( $user ) { |
|
21 | + if ($user) { |
|
22 | 22 | return array( |
23 | 23 | 'name' => $user->display_name, |
24 | 24 | 'email' => $user->user_email, |
@@ -33,17 +33,17 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @return array |
35 | 35 | */ |
36 | - public function delete_file( $path, $sha, $message ) { |
|
36 | + public function delete_file($path, $sha, $message) { |
|
37 | 37 | $body = new stdClass(); |
38 | 38 | $body->message = $message; |
39 | 39 | $body->sha = $sha; |
40 | 40 | $body->branch = $this->branch(); |
41 | 41 | |
42 | - if ( $author = $this->export_user() ) { |
|
42 | + if ($author = $this->export_user()) { |
|
43 | 43 | $body->author = $author; |
44 | 44 | } |
45 | 45 | |
46 | - return $this->call( 'DELETE', $this->content_endpoint( $path ), $body ); |
|
46 | + return $this->call('DELETE', $this->content_endpoint($path), $body); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -51,17 +51,17 @@ discard block |
||
51 | 51 | * |
52 | 52 | * @return array |
53 | 53 | */ |
54 | - public function create_file( $blob, $message ) { |
|
54 | + public function create_file($blob, $message) { |
|
55 | 55 | $body = $blob->to_body(); |
56 | 56 | $body->message = $message; |
57 | 57 | $body->branch = $this->branch(); |
58 | 58 | unset($body->sha); |
59 | 59 | |
60 | - if ( $author = $this->export_user() ) { |
|
60 | + if ($author = $this->export_user()) { |
|
61 | 61 | $body->author = $author; |
62 | 62 | } |
63 | 63 | |
64 | - return $this->call( 'PUT', $this->content_endpoint( $blob->path() ), $body ); |
|
64 | + return $this->call('PUT', $this->content_endpoint($blob->path()), $body); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -69,15 +69,15 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return array |
71 | 71 | */ |
72 | - public function update_file( $blob, $message ) { |
|
72 | + public function update_file($blob, $message) { |
|
73 | 73 | $body = $blob->to_body(); |
74 | 74 | $body->message = $message; |
75 | 75 | $body->branch = $this->branch(); |
76 | 76 | |
77 | - if ( $author = $this->export_user() ) { |
|
77 | + if ($author = $this->export_user()) { |
|
78 | 78 | $body->author = $author; |
79 | 79 | } |
80 | 80 | |
81 | - return $this->call( 'PUT', $this->content_endpoint( $blob->path() ), $body ); |
|
81 | + return $this->call('PUT', $this->content_endpoint($blob->path()), $body); |
|
82 | 82 | } |
83 | 83 | } |
@@ -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 | return $error; |
45 | 45 | } |
46 | 46 | |
@@ -51,24 +51,23 @@ discard block |
||
51 | 51 | ), |
52 | 52 | ); |
53 | 53 | |
54 | - if ( 'GET' !== $method ) { |
|
55 | - $args['body'] = function_exists( 'wp_json_encode' ) ? |
|
56 | - wp_json_encode( $body ) : |
|
57 | - json_encode( $body ); |
|
54 | + if ('GET' !== $method) { |
|
55 | + $args['body'] = function_exists('wp_json_encode') ? |
|
56 | + wp_json_encode($body) : json_encode($body); |
|
58 | 57 | } |
59 | 58 | |
60 | 59 | $tmpbody = isset($args['body']) ? $args['body'] : ''; |
61 | 60 | error_log("writing-on-github-call $method $endpoint $tmpbody"); |
62 | 61 | |
63 | - $response = wp_remote_request( $endpoint, $args ); |
|
64 | - $status = wp_remote_retrieve_header( $response, 'status' ); |
|
65 | - $body = json_decode( wp_remote_retrieve_body( $response ) ); |
|
62 | + $response = wp_remote_request($endpoint, $args); |
|
63 | + $status = wp_remote_retrieve_header($response, 'status'); |
|
64 | + $body = json_decode(wp_remote_retrieve_body($response)); |
|
66 | 65 | |
67 | - if ( '2' !== substr( $status, 0, 1 ) && '3' !== substr( $status, 0, 1 ) ) { |
|
66 | + if ('2' !== substr($status, 0, 1) && '3' !== substr($status, 0, 1)) { |
|
68 | 67 | return new WP_Error( |
69 | - strtolower( str_replace( ' ', '_', $status ) ), |
|
68 | + strtolower(str_replace(' ', '_', $status)), |
|
70 | 69 | sprintf( |
71 | - __( 'Method %s to endpoint %s failed with error: %s', 'writing-on-github' ), |
|
70 | + __('Method %s to endpoint %s failed with error: %s', 'writing-on-github'), |
|
72 | 71 | $method, |
73 | 72 | $endpoint, |
74 | 73 | $body && $body->message ? $body->message : 'Unknown error' |
@@ -85,28 +84,28 @@ discard block |
||
85 | 84 | * @return true|WP_Error |
86 | 85 | */ |
87 | 86 | protected function can_call() { |
88 | - if ( ! $this->oauth_token() ) { |
|
87 | + if ( ! $this->oauth_token()) { |
|
89 | 88 | return new WP_Error( |
90 | 89 | 'missing_token', |
91 | - __( 'Writing On GitHub needs an auth token. Please update your settings.', 'writing-on-github' ) |
|
90 | + __('Writing On GitHub needs an auth token. Please update your settings.', 'writing-on-github') |
|
92 | 91 | ); |
93 | 92 | } |
94 | 93 | |
95 | 94 | $repo = $this->repository(); |
96 | 95 | |
97 | - if ( ! $repo ) { |
|
96 | + if ( ! $repo) { |
|
98 | 97 | return new WP_Error( |
99 | 98 | 'missing_repository', |
100 | - __( 'Writing On GitHub needs a repository. Please update your settings.', 'writing-on-github' ) |
|
99 | + __('Writing On GitHub needs a repository. Please update your settings.', 'writing-on-github') |
|
101 | 100 | ); |
102 | 101 | } |
103 | 102 | |
104 | - $parts = explode( '/', $repo ); |
|
103 | + $parts = explode('/', $repo); |
|
105 | 104 | |
106 | - if ( 2 !== count( $parts ) ) { |
|
105 | + if (2 !== count($parts)) { |
|
107 | 106 | return new WP_Error( |
108 | 107 | 'malformed_repository', |
109 | - __( 'Writing On GitHub needs a properly formed repository. Please update your settings.', 'writing-on-github' ) |
|
108 | + __('Writing On GitHub needs a properly formed repository. Please update your settings.', 'writing-on-github') |
|
110 | 109 | ); |
111 | 110 | } |
112 | 111 | |
@@ -119,7 +118,7 @@ discard block |
||
119 | 118 | * @return string |
120 | 119 | */ |
121 | 120 | public function repository() { |
122 | - return (string) get_option( self::REPO_OPTION_KEY ); |
|
121 | + return (string) get_option(self::REPO_OPTION_KEY); |
|
123 | 122 | } |
124 | 123 | |
125 | 124 | /** |
@@ -128,18 +127,18 @@ discard block |
||
128 | 127 | * @return string |
129 | 128 | */ |
130 | 129 | public function oauth_token() { |
131 | - return (string) get_option( self::TOKEN_OPTION_KEY ); |
|
130 | + return (string) get_option(self::TOKEN_OPTION_KEY); |
|
132 | 131 | } |
133 | 132 | |
134 | 133 | /** |
135 | 134 | * Returns the GitHub host to sync with (for GitHub Enterprise support) |
136 | 135 | */ |
137 | 136 | public function api_base() { |
138 | - return get_option( self::HOST_OPTION_KEY ); |
|
137 | + return get_option(self::HOST_OPTION_KEY); |
|
139 | 138 | } |
140 | 139 | |
141 | 140 | public function branch() { |
142 | - $branch = get_option( self::BRANCH_OPTION_KEY ); |
|
141 | + $branch = get_option(self::BRANCH_OPTION_KEY); |
|
143 | 142 | return $branch ? $branch : 'master'; |
144 | 143 | } |
145 | 144 | |
@@ -200,11 +199,11 @@ discard block |
||
200 | 199 | * |
201 | 200 | * Returns String the relative API call path |
202 | 201 | */ |
203 | - public function content_endpoint( $path = false ) { |
|
202 | + public function content_endpoint($path = false) { |
|
204 | 203 | $url = $this->api_base() . '/repos/'; |
205 | 204 | $url = $url . $this->repository() . '/contents'; |
206 | 205 | |
207 | - if ( ! empty($path) ) { |
|
206 | + if ( ! empty($path)) { |
|
208 | 207 | $url .= '/' . $path; |
209 | 208 | } |
210 | 209 |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param Writing_On_GitHub $app Application 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 | |
@@ -32,30 +32,30 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @return false |
34 | 34 | */ |
35 | - public function error( WP_Error $error ) { |
|
35 | + public function error(WP_Error $error) { |
|
36 | 36 | global $wp_version; |
37 | 37 | |
38 | - $this->log( $error ); |
|
38 | + $this->log($error); |
|
39 | 39 | |
40 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX && defined( 'WOGH_AJAX' ) && WOGH_AJAX ) { |
|
40 | + if (defined('DOING_AJAX') && DOING_AJAX && defined('WOGH_AJAX') && WOGH_AJAX) { |
|
41 | 41 | /** |
42 | 42 | * WordPress 4.1.0 introduced allowing WP_Error objects to be |
43 | 43 | * passed directly into `wp_send_json_error`. This shims in |
44 | 44 | * compatibility for older versions. We're currently supporting 3.9+. |
45 | 45 | */ |
46 | - if ( version_compare( $wp_version, '4.1.0', '<' ) ) { |
|
46 | + if (version_compare($wp_version, '4.1.0', '<')) { |
|
47 | 47 | $result = array(); |
48 | 48 | |
49 | - foreach ( $error->errors as $code => $messages ) { |
|
50 | - foreach ( $messages as $message ) { |
|
51 | - $result[] = array( 'code' => $code, 'message' => $message ); |
|
49 | + foreach ($error->errors as $code => $messages) { |
|
50 | + foreach ($messages as $message) { |
|
51 | + $result[] = array('code' => $code, 'message' => $message); |
|
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
55 | 55 | $error = $result; |
56 | 56 | } |
57 | 57 | |
58 | - wp_send_json_error( $error ); |
|
58 | + wp_send_json_error($error); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | return false; |
@@ -68,11 +68,11 @@ discard block |
||
68 | 68 | * |
69 | 69 | * @return true |
70 | 70 | */ |
71 | - public function success( $success ) { |
|
72 | - $this->log( $success ); |
|
71 | + public function success($success) { |
|
72 | + $this->log($success); |
|
73 | 73 | |
74 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX && defined( 'WOGH_AJAX' ) && WOGH_AJAX ) { |
|
75 | - wp_send_json_success( $success ); |
|
74 | + if (defined('DOING_AJAX') && DOING_AJAX && defined('WOGH_AJAX') && WOGH_AJAX) { |
|
75 | + wp_send_json_success($success); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | return true; |
@@ -85,11 +85,11 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @param string|WP_Error $msg Message to log. |
87 | 87 | */ |
88 | - protected function log( $msg ) { |
|
89 | - if ( is_wp_error( $msg ) ) { |
|
88 | + protected function log($msg) { |
|
89 | + if (is_wp_error($msg)) { |
|
90 | 90 | $msg = $msg->get_error_message(); |
91 | 91 | } |
92 | 92 | |
93 | - Writing_On_GitHub::write_log( $msg ); |
|
93 | + Writing_On_GitHub::write_log($msg); |
|
94 | 94 | } |
95 | 95 | } |
@@ -84,13 +84,13 @@ discard block |
||
84 | 84 | ) |
85 | 85 | ); |
86 | 86 | |
87 | - register_setting( Writing_On_GitHub::$text_domain, 'wogh_ignore_author' ); |
|
88 | - add_settings_field( 'wogh_ignore_author', __( 'Ignore author', 'writing-on-github' ), array( &$this, 'checkbox_field_callback' ), Writing_On_GitHub::$text_domain, 'general', array( |
|
89 | - 'default' => '', |
|
90 | - 'name' => 'wogh_ignore_author', |
|
91 | - 'help_text' => __( 'Do not export author and do not use author info from GitHub.', 'writing-on-github' ), |
|
92 | - ) |
|
93 | - ); |
|
87 | + register_setting( Writing_On_GitHub::$text_domain, 'wogh_ignore_author' ); |
|
88 | + add_settings_field( 'wogh_ignore_author', __( 'Ignore author', 'writing-on-github' ), array( &$this, 'checkbox_field_callback' ), Writing_On_GitHub::$text_domain, 'general', array( |
|
89 | + 'default' => '', |
|
90 | + 'name' => 'wogh_ignore_author', |
|
91 | + 'help_text' => __( 'Do not export author and do not use author info from GitHub.', 'writing-on-github' ), |
|
92 | + ) |
|
93 | + ); |
|
94 | 94 | |
95 | 95 | // register_setting( Writing_On_GitHub::$text_domain, 'wogh_ignore_metas' ); |
96 | 96 | // add_settings_field( 'wogh_ignore_metas', __( 'Ignore post metas', 'writing-on-github' ), array( &$this, 'textarea_field_callback' ), Writing_On_GitHub::$text_domain, 'general', array( |
@@ -128,14 +128,14 @@ discard block |
||
128 | 128 | include dirname( dirname( __FILE__ ) ) . '/views/textarea-setting-field.php'; |
129 | 129 | } |
130 | 130 | |
131 | - /** |
|
132 | - * Callback to render the checkbox field. |
|
133 | - * |
|
134 | - * @param array $args Field arguments. |
|
135 | - */ |
|
136 | - public function checkbox_field_callback( $args ) { |
|
137 | - include dirname( dirname( __FILE__ ) ) . '/views/checkbox-setting-field.php'; |
|
138 | - } |
|
131 | + /** |
|
132 | + * Callback to render the checkbox field. |
|
133 | + * |
|
134 | + * @param array $args Field arguments. |
|
135 | + */ |
|
136 | + public function checkbox_field_callback( $args ) { |
|
137 | + include dirname( dirname( __FILE__ ) ) . '/views/checkbox-setting-field.php'; |
|
138 | + } |
|
139 | 139 | |
140 | 140 | /** |
141 | 141 | * Displays settings messages from background processes |
@@ -221,9 +221,9 @@ discard block |
||
221 | 221 | Writing_On_GitHub::$instance->start_export(); |
222 | 222 | } |
223 | 223 | |
224 | - if ( 'force_export' === $_GET['action'] ) { |
|
225 | - Writing_On_GitHub::$instance->start_export(true); |
|
226 | - } |
|
224 | + if ( 'force_export' === $_GET['action'] ) { |
|
225 | + Writing_On_GitHub::$instance->start_export(true); |
|
226 | + } |
|
227 | 227 | |
228 | 228 | if ( 'import' === $_GET['action'] ) { |
229 | 229 | Writing_On_GitHub::$instance->start_import(); |
@@ -13,16 +13,16 @@ discard block |
||
13 | 13 | * Hook into GitHub API |
14 | 14 | */ |
15 | 15 | public function __construct() { |
16 | - add_action( 'admin_menu', array( $this, 'add_admin_menu' ) ); |
|
17 | - add_action( 'admin_init', array( $this, 'register_settings' ) ); |
|
18 | - add_action( 'current_screen', array( $this, 'trigger_cron' ) ); |
|
16 | + add_action('admin_menu', array($this, 'add_admin_menu')); |
|
17 | + add_action('admin_init', array($this, 'register_settings')); |
|
18 | + add_action('current_screen', array($this, 'trigger_cron')); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Callback to render the settings page view |
23 | 23 | */ |
24 | 24 | public function settings_page() { |
25 | - include dirname( dirname( __FILE__ ) ) . '/views/options.php'; |
|
25 | + include dirname(dirname(__FILE__)) . '/views/options.php'; |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -32,63 +32,63 @@ discard block |
||
32 | 32 | add_settings_section( |
33 | 33 | 'general', |
34 | 34 | 'General Settings', |
35 | - array( $this, 'section_callback' ), |
|
35 | + array($this, 'section_callback'), |
|
36 | 36 | Writing_On_GitHub::$text_domain |
37 | 37 | ); |
38 | 38 | |
39 | - register_setting( Writing_On_GitHub::$text_domain, 'wogh_host' ); |
|
40 | - add_settings_field( 'wogh_host', __( 'GitHub hostname', 'writing-on-github' ), array( $this, 'field_callback' ), Writing_On_GitHub::$text_domain, 'general', array( |
|
39 | + register_setting(Writing_On_GitHub::$text_domain, 'wogh_host'); |
|
40 | + add_settings_field('wogh_host', __('GitHub hostname', 'writing-on-github'), array($this, 'field_callback'), Writing_On_GitHub::$text_domain, 'general', array( |
|
41 | 41 | 'default' => 'https://api.github.com', |
42 | 42 | 'name' => 'wogh_host', |
43 | - 'help_text' => __( 'The GitHub host to use. This only needs to be changed to support a GitHub Enterprise installation.', 'writing-on-github' ), |
|
43 | + 'help_text' => __('The GitHub host to use. This only needs to be changed to support a GitHub Enterprise installation.', 'writing-on-github'), |
|
44 | 44 | ) |
45 | 45 | ); |
46 | 46 | |
47 | - register_setting( Writing_On_GitHub::$text_domain, 'wogh_repository' ); |
|
48 | - add_settings_field( 'wogh_repository', __( 'Repository', 'writing-on-github' ), array( $this, 'field_callback' ), Writing_On_GitHub::$text_domain, 'general', array( |
|
47 | + register_setting(Writing_On_GitHub::$text_domain, 'wogh_repository'); |
|
48 | + add_settings_field('wogh_repository', __('Repository', 'writing-on-github'), array($this, 'field_callback'), Writing_On_GitHub::$text_domain, 'general', array( |
|
49 | 49 | 'default' => '', |
50 | 50 | 'name' => 'wogh_repository', |
51 | - 'help_text' => __( 'The GitHub repository to commit to, with owner (<code>[OWNER]/[REPOSITORY]</code>), e.g., <code>github/hubot.github.com</code>. The repository should contain an initial commit, which is satisfied by including a README when you create the repository on GitHub.', 'writing-on-github' ), |
|
51 | + 'help_text' => __('The GitHub repository to commit to, with owner (<code>[OWNER]/[REPOSITORY]</code>), e.g., <code>github/hubot.github.com</code>. The repository should contain an initial commit, which is satisfied by including a README when you create the repository on GitHub.', 'writing-on-github'), |
|
52 | 52 | ) |
53 | 53 | ); |
54 | 54 | |
55 | - register_setting( Writing_On_GitHub::$text_domain, 'wogh_branch' ); |
|
56 | - add_settings_field( 'wogh_branch', __( 'Branch', 'writing-on-github' ), array( $this, 'field_callback' ), Writing_On_GitHub::$text_domain, 'general', array( |
|
55 | + register_setting(Writing_On_GitHub::$text_domain, 'wogh_branch'); |
|
56 | + add_settings_field('wogh_branch', __('Branch', 'writing-on-github'), array($this, 'field_callback'), Writing_On_GitHub::$text_domain, 'general', array( |
|
57 | 57 | 'default' => 'master', |
58 | 58 | 'name' => 'wogh_branch', |
59 | - 'help_text' => __( 'The GitHub branch to commit to, default is master.', 'writing-on-github' ), |
|
59 | + 'help_text' => __('The GitHub branch to commit to, default is master.', 'writing-on-github'), |
|
60 | 60 | ) |
61 | 61 | ); |
62 | 62 | |
63 | - register_setting( Writing_On_GitHub::$text_domain, 'wogh_oauth_token' ); |
|
64 | - add_settings_field( 'wogh_oauth_token', __( 'Oauth Token', 'writing-on-github' ), array( $this, 'field_callback' ), Writing_On_GitHub::$text_domain, 'general', array( |
|
63 | + register_setting(Writing_On_GitHub::$text_domain, 'wogh_oauth_token'); |
|
64 | + add_settings_field('wogh_oauth_token', __('Oauth Token', 'writing-on-github'), array($this, 'field_callback'), Writing_On_GitHub::$text_domain, 'general', array( |
|
65 | 65 | 'default' => '', |
66 | 66 | 'name' => 'wogh_oauth_token', |
67 | - 'help_text' => __( "A <a href='https://github.com/settings/tokens/new'>personal oauth token</a> with <code>public_repo</code> scope.", 'writing-on-github' ), |
|
67 | + 'help_text' => __("A <a href='https://github.com/settings/tokens/new'>personal oauth token</a> with <code>public_repo</code> scope.", 'writing-on-github'), |
|
68 | 68 | ) |
69 | 69 | ); |
70 | 70 | |
71 | - register_setting( Writing_On_GitHub::$text_domain, 'wogh_secret' ); |
|
72 | - add_settings_field( 'wogh_secret', __( 'Webhook Secret', 'writing-on-github' ), array( $this, 'field_callback' ), Writing_On_GitHub::$text_domain, 'general', array( |
|
71 | + register_setting(Writing_On_GitHub::$text_domain, 'wogh_secret'); |
|
72 | + add_settings_field('wogh_secret', __('Webhook Secret', 'writing-on-github'), array($this, 'field_callback'), Writing_On_GitHub::$text_domain, 'general', array( |
|
73 | 73 | 'default' => '', |
74 | 74 | 'name' => 'wogh_secret', |
75 | - 'help_text' => __( "The webhook's secret phrase. This should be password strength, as it is used to verify the webhook's payload.", 'writing-on-github' ), |
|
75 | + 'help_text' => __("The webhook's secret phrase. This should be password strength, as it is used to verify the webhook's payload.", 'writing-on-github'), |
|
76 | 76 | ) |
77 | 77 | ); |
78 | 78 | |
79 | - register_setting( Writing_On_GitHub::$text_domain, 'wogh_default_user' ); |
|
80 | - add_settings_field( 'wogh_default_user', __( 'Default Import User', 'writing-on-github' ), array( &$this, 'user_field_callback' ), Writing_On_GitHub::$text_domain, 'general', array( |
|
79 | + register_setting(Writing_On_GitHub::$text_domain, 'wogh_default_user'); |
|
80 | + add_settings_field('wogh_default_user', __('Default Import User', 'writing-on-github'), array(&$this, 'user_field_callback'), Writing_On_GitHub::$text_domain, 'general', array( |
|
81 | 81 | 'default' => '', |
82 | 82 | 'name' => 'wogh_default_user', |
83 | - 'help_text' => __( 'The fallback user for import, in case Writing On GitHub cannot find the committer in the database.', 'writing-on-github' ), |
|
83 | + 'help_text' => __('The fallback user for import, in case Writing On GitHub cannot find the committer in the database.', 'writing-on-github'), |
|
84 | 84 | ) |
85 | 85 | ); |
86 | 86 | |
87 | - register_setting( Writing_On_GitHub::$text_domain, 'wogh_ignore_author' ); |
|
88 | - add_settings_field( 'wogh_ignore_author', __( 'Ignore author', 'writing-on-github' ), array( &$this, 'checkbox_field_callback' ), Writing_On_GitHub::$text_domain, 'general', array( |
|
87 | + register_setting(Writing_On_GitHub::$text_domain, 'wogh_ignore_author'); |
|
88 | + add_settings_field('wogh_ignore_author', __('Ignore author', 'writing-on-github'), array(&$this, 'checkbox_field_callback'), Writing_On_GitHub::$text_domain, 'general', array( |
|
89 | 89 | 'default' => '', |
90 | 90 | 'name' => 'wogh_ignore_author', |
91 | - 'help_text' => __( 'Do not export author and do not use author info from GitHub.', 'writing-on-github' ), |
|
91 | + 'help_text' => __('Do not export author and do not use author info from GitHub.', 'writing-on-github'), |
|
92 | 92 | ) |
93 | 93 | ); |
94 | 94 | |
@@ -106,8 +106,8 @@ discard block |
||
106 | 106 | * |
107 | 107 | * @param array $args Field arguments. |
108 | 108 | */ |
109 | - public function field_callback( $args ) { |
|
110 | - include dirname( dirname( __FILE__ ) ) . '/views/setting-field.php'; |
|
109 | + public function field_callback($args) { |
|
110 | + include dirname(dirname(__FILE__)) . '/views/setting-field.php'; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -115,8 +115,8 @@ discard block |
||
115 | 115 | * |
116 | 116 | * @param array $args Field arguments. |
117 | 117 | */ |
118 | - public function user_field_callback( $args ) { |
|
119 | - include dirname( dirname( __FILE__ ) ) . '/views/user-setting-field.php'; |
|
118 | + public function user_field_callback($args) { |
|
119 | + include dirname(dirname(__FILE__)) . '/views/user-setting-field.php'; |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * |
125 | 125 | * @param array $args Field arguments. |
126 | 126 | */ |
127 | - public function textarea_field_callback( $args ) { |
|
128 | - include dirname( dirname( __FILE__ ) ) . '/views/textarea-setting-field.php'; |
|
127 | + public function textarea_field_callback($args) { |
|
128 | + include dirname(dirname(__FILE__)) . '/views/textarea-setting-field.php'; |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -133,58 +133,58 @@ discard block |
||
133 | 133 | * |
134 | 134 | * @param array $args Field arguments. |
135 | 135 | */ |
136 | - public function checkbox_field_callback( $args ) { |
|
137 | - include dirname( dirname( __FILE__ ) ) . '/views/checkbox-setting-field.php'; |
|
136 | + public function checkbox_field_callback($args) { |
|
137 | + include dirname(dirname(__FILE__)) . '/views/checkbox-setting-field.php'; |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
141 | 141 | * Displays settings messages from background processes |
142 | 142 | */ |
143 | 143 | public function section_callback() { |
144 | - if ( get_current_screen()->id !== 'settings_page_' . Writing_On_GitHub::$text_domain ) { |
|
144 | + if (get_current_screen()->id !== 'settings_page_' . Writing_On_GitHub::$text_domain) { |
|
145 | 145 | return; |
146 | 146 | } |
147 | 147 | |
148 | - if ( 'yes' === get_option( '_wogh_export_started' ) ) { ?> |
|
148 | + if ('yes' === get_option('_wogh_export_started')) { ?> |
|
149 | 149 | <div class="updated"> |
150 | - <p><?php esc_html_e( 'Export to GitHub started.', 'writing-on-github' ); ?></p> |
|
150 | + <p><?php esc_html_e('Export to GitHub started.', 'writing-on-github'); ?></p> |
|
151 | 151 | </div><?php |
152 | - delete_option( '_wogh_export_started' ); |
|
152 | + delete_option('_wogh_export_started'); |
|
153 | 153 | } |
154 | 154 | |
155 | - if ( $message = get_option( '_wogh_export_error' ) ) { ?> |
|
155 | + if ($message = get_option('_wogh_export_error')) { ?> |
|
156 | 156 | <div class="error"> |
157 | - <p><?php esc_html_e( 'Export to GitHub failed with error:', 'writing-on-github' ); ?> <?php echo esc_html( $message );?></p> |
|
157 | + <p><?php esc_html_e('Export to GitHub failed with error:', 'writing-on-github'); ?> <?php echo esc_html($message); ?></p> |
|
158 | 158 | </div><?php |
159 | - delete_option( '_wogh_export_error' ); |
|
159 | + delete_option('_wogh_export_error'); |
|
160 | 160 | } |
161 | 161 | |
162 | - if ( 'yes' === get_option( '_wogh_export_complete' ) ) { ?> |
|
162 | + if ('yes' === get_option('_wogh_export_complete')) { ?> |
|
163 | 163 | <div class="updated"> |
164 | - <p><?php esc_html_e( 'Export to GitHub completed successfully.', 'writing-on-github' );?></p> |
|
164 | + <p><?php esc_html_e('Export to GitHub completed successfully.', 'writing-on-github'); ?></p> |
|
165 | 165 | </div><?php |
166 | - delete_option( '_wogh_export_complete' ); |
|
166 | + delete_option('_wogh_export_complete'); |
|
167 | 167 | } |
168 | 168 | |
169 | - if ( 'yes' === get_option( '_wogh_import_started' ) ) { ?> |
|
169 | + if ('yes' === get_option('_wogh_import_started')) { ?> |
|
170 | 170 | <div class="updated"> |
171 | - <p><?php esc_html_e( 'Import from GitHub started.', 'writing-on-github' ); ?></p> |
|
171 | + <p><?php esc_html_e('Import from GitHub started.', 'writing-on-github'); ?></p> |
|
172 | 172 | </div><?php |
173 | - delete_option( '_wogh_import_started' ); |
|
173 | + delete_option('_wogh_import_started'); |
|
174 | 174 | } |
175 | 175 | |
176 | - if ( $message = get_option( '_wogh_import_error' ) ) { ?> |
|
176 | + if ($message = get_option('_wogh_import_error')) { ?> |
|
177 | 177 | <div class="error"> |
178 | - <p><?php esc_html_e( 'Import from GitHub failed with error:', 'writing-on-github' ); ?> <?php echo esc_html( $message );?></p> |
|
178 | + <p><?php esc_html_e('Import from GitHub failed with error:', 'writing-on-github'); ?> <?php echo esc_html($message); ?></p> |
|
179 | 179 | </div><?php |
180 | - delete_option( '_wogh_import_error' ); |
|
180 | + delete_option('_wogh_import_error'); |
|
181 | 181 | } |
182 | 182 | |
183 | - if ( 'yes' === get_option( '_wogh_import_complete' ) ) { ?> |
|
183 | + if ('yes' === get_option('_wogh_import_complete')) { ?> |
|
184 | 184 | <div class="updated"> |
185 | - <p><?php esc_html_e( 'Import from GitHub completed successfully.', 'writing-on-github' );?></p> |
|
185 | + <p><?php esc_html_e('Import from GitHub completed successfully.', 'writing-on-github'); ?></p> |
|
186 | 186 | </div><?php |
187 | - delete_option( '_wogh_import_complete' ); |
|
187 | + delete_option('_wogh_import_complete'); |
|
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
@@ -193,11 +193,11 @@ discard block |
||
193 | 193 | */ |
194 | 194 | public function add_admin_menu() { |
195 | 195 | add_options_page( |
196 | - __( 'Writing On GitHub', 'writing-on-github' ), |
|
197 | - __( 'Writing On GitHub', 'writing-on-github' ), |
|
196 | + __('Writing On GitHub', 'writing-on-github'), |
|
197 | + __('Writing On GitHub', 'writing-on-github'), |
|
198 | 198 | 'manage_options', |
199 | 199 | Writing_On_GitHub::$text_domain, |
200 | - array( $this, 'settings_page' ) |
|
200 | + array($this, 'settings_page') |
|
201 | 201 | ); |
202 | 202 | } |
203 | 203 | |
@@ -205,31 +205,31 @@ discard block |
||
205 | 205 | * Admin callback to trigger import/export because WordPress admin routing lol |
206 | 206 | */ |
207 | 207 | public function trigger_cron() { |
208 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
208 | + if ( ! current_user_can('manage_options')) { |
|
209 | 209 | return; |
210 | 210 | } |
211 | 211 | |
212 | - if ( get_current_screen()->id !== 'settings_page_' . Writing_On_GitHub::$text_domain ) { |
|
212 | + if (get_current_screen()->id !== 'settings_page_' . Writing_On_GitHub::$text_domain) { |
|
213 | 213 | return; |
214 | 214 | } |
215 | 215 | |
216 | - if ( ! isset( $_GET['action'] ) ) { |
|
216 | + if ( ! isset($_GET['action'])) { |
|
217 | 217 | return; |
218 | 218 | } |
219 | 219 | |
220 | - if ( 'export' === $_GET['action'] ) { |
|
220 | + if ('export' === $_GET['action']) { |
|
221 | 221 | Writing_On_GitHub::$instance->start_export(); |
222 | 222 | } |
223 | 223 | |
224 | - if ( 'force_export' === $_GET['action'] ) { |
|
224 | + if ('force_export' === $_GET['action']) { |
|
225 | 225 | Writing_On_GitHub::$instance->start_export(true); |
226 | 226 | } |
227 | 227 | |
228 | - if ( 'import' === $_GET['action'] ) { |
|
228 | + if ('import' === $_GET['action']) { |
|
229 | 229 | Writing_On_GitHub::$instance->start_import(); |
230 | 230 | } |
231 | 231 | |
232 | - wp_redirect( admin_url( 'options-general.php?page=writing-on-github' ) ); |
|
232 | + wp_redirect(admin_url('options-general.php?page=writing-on-github')); |
|
233 | 233 | die; |
234 | 234 | } |
235 | 235 | } |
@@ -152,9 +152,9 @@ |
||
152 | 152 | array_pop( $matches ); |
153 | 153 | |
154 | 154 | $meta = spyc_load( $matches[2] ); |
155 | - if ( 'yes' == get_option('wogh_ignore_author') ) { |
|
156 | - unset($meta['author']); |
|
157 | - } |
|
155 | + if ( 'yes' == get_option('wogh_ignore_author') ) { |
|
156 | + unset($meta['author']); |
|
157 | + } |
|
158 | 158 | // if ( isset( $meta['link'] ) ) { |
159 | 159 | // $meta['link'] = str_replace( home_url(), '', $meta['link'] ); |
160 | 160 | // } |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | * |
50 | 50 | * @param stdClass $data Raw blob data. |
51 | 51 | */ |
52 | - public function __construct( stdClass $data ) { |
|
53 | - $this->interpret_data( $data ); |
|
52 | + public function __construct(stdClass $data) { |
|
53 | + $this->interpret_data($data); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | public function id() { |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @return $this |
80 | 80 | */ |
81 | - public function set_content( $content, $base64 = false ) { |
|
82 | - if ( $base64 ) { |
|
83 | - $content = base64_decode( $content ); |
|
81 | + public function set_content($content, $base64 = false) { |
|
82 | + if ($base64) { |
|
83 | + $content = base64_decode($content); |
|
84 | 84 | } |
85 | 85 | |
86 | - $this->frontmatter = '---' === substr( $this->content = $content, 0, 3 ) ? true : false; |
|
86 | + $this->frontmatter = '---' === substr($this->content = $content, 0, 3) ? true : false; |
|
87 | 87 | |
88 | 88 | return $this; |
89 | 89 | } |
@@ -122,20 +122,20 @@ discard block |
||
122 | 122 | public function content_import() { |
123 | 123 | $content = $this->content(); |
124 | 124 | |
125 | - if ( $this->has_frontmatter() ) { |
|
125 | + if ($this->has_frontmatter()) { |
|
126 | 126 | // Break out content. |
127 | - preg_match( '/(^---(.*?)---$)?(.*)/ms', $content, $matches ); |
|
128 | - $content = array_pop( $matches ); |
|
127 | + preg_match('/(^---(.*?)---$)?(.*)/ms', $content, $matches); |
|
128 | + $content = array_pop($matches); |
|
129 | 129 | } |
130 | 130 | |
131 | - if ( function_exists( 'wpmarkdown_markdown_to_html' ) ) { |
|
132 | - $content = wpmarkdown_markdown_to_html( $content ); |
|
131 | + if (function_exists('wpmarkdown_markdown_to_html')) { |
|
132 | + $content = wpmarkdown_markdown_to_html($content); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
136 | 136 | * Filters the content for import. |
137 | 137 | */ |
138 | - return apply_filters( 'wogh_content_import', trim( $content ) ); |
|
138 | + return apply_filters('wogh_content_import', trim($content)); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -146,13 +146,13 @@ discard block |
||
146 | 146 | public function meta() { |
147 | 147 | $meta = array(); |
148 | 148 | |
149 | - if ( $this->has_frontmatter() ) { |
|
149 | + if ($this->has_frontmatter()) { |
|
150 | 150 | // Break out meta, if present. |
151 | - preg_match( '/(^---(.*?)---$)?(.*)/ms', $this->content(), $matches ); |
|
152 | - array_pop( $matches ); |
|
151 | + preg_match('/(^---(.*?)---$)?(.*)/ms', $this->content(), $matches); |
|
152 | + array_pop($matches); |
|
153 | 153 | |
154 | - $meta = spyc_load( $matches[2] ); |
|
155 | - if ( 'yes' == get_option('wogh_ignore_author') ) { |
|
154 | + $meta = spyc_load($matches[2]); |
|
155 | + if ('yes' == get_option('wogh_ignore_author')) { |
|
156 | 156 | unset($meta['author']); |
157 | 157 | } |
158 | 158 | // if ( isset( $meta['link'] ) ) { |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | // $data->type = 'blob'; |
199 | 199 | |
200 | 200 | $data->path = $this->path(); |
201 | - $data->content = base64_encode( $this->content() ); |
|
201 | + $data->content = base64_encode($this->content()); |
|
202 | 202 | $data->sha = $this->sha; |
203 | 203 | |
204 | 204 | return $data; |
@@ -207,13 +207,13 @@ discard block |
||
207 | 207 | /** |
208 | 208 | * Interprets the blob's data into properties. |
209 | 209 | */ |
210 | - protected function interpret_data( $data ) { |
|
211 | - $this->sha = isset( $data->sha ) ? $data->sha : ''; |
|
212 | - $this->path = isset( $data->path ) ? $data->path : ''; |
|
210 | + protected function interpret_data($data) { |
|
211 | + $this->sha = isset($data->sha) ? $data->sha : ''; |
|
212 | + $this->path = isset($data->path) ? $data->path : ''; |
|
213 | 213 | |
214 | 214 | $this->set_content( |
215 | - isset( $data->content ) ? trim( $data->content ) : '', |
|
216 | - isset( $data->encoding ) && 'base64' === $data->encoding ? true : false |
|
215 | + isset($data->content) ? trim($data->content) : '', |
|
216 | + isset($data->encoding) && 'base64' === $data->encoding ? true : false |
|
217 | 217 | ); |
218 | 218 | } |
219 | 219 | } |
@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | * @param Writing_On_GitHub $app Application container. |
30 | 30 | * @param string $raw_data Raw request data. |
31 | 31 | */ |
32 | - public function __construct( Writing_On_GitHub $app, $raw_data ) { |
|
32 | + public function __construct(Writing_On_GitHub $app, $raw_data) { |
|
33 | 33 | $this->app = $app; |
34 | - $this->data = json_decode( $raw_data ); |
|
34 | + $this->data = json_decode($raw_data); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
@@ -41,32 +41,32 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function should_import() { |
43 | 43 | // @todo how do we get this without importing the whole api object just for this? |
44 | - if ( strtolower( $this->data->repository->full_name ) !== strtolower( $this->app->api()->fetch()->repository() ) ) { |
|
44 | + if (strtolower($this->data->repository->full_name) !== strtolower($this->app->api()->fetch()->repository())) { |
|
45 | 45 | return false; |
46 | 46 | } |
47 | 47 | |
48 | 48 | // The last term in the ref is the payload_branch name. |
49 | - $refs = explode( '/', $this->data->ref ); |
|
50 | - $payload_branch = array_pop( $refs ); |
|
49 | + $refs = explode('/', $this->data->ref); |
|
50 | + $payload_branch = array_pop($refs); |
|
51 | 51 | |
52 | 52 | $branch = $this->app->api()->fetch()->branch(); |
53 | 53 | |
54 | - if ( $branch !== $payload_branch ) { |
|
54 | + if ($branch !== $payload_branch) { |
|
55 | 55 | return false; |
56 | 56 | } |
57 | 57 | |
58 | 58 | // We add a tag to commits we push out, so we shouldn't pull them in again. |
59 | - $tag = apply_filters( 'wogh_commit_msg_tag', 'wogh' ); |
|
59 | + $tag = apply_filters('wogh_commit_msg_tag', 'wogh'); |
|
60 | 60 | |
61 | - if ( ! $tag ) { |
|
62 | - throw new Exception( __( 'Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github' ) ); |
|
61 | + if ( ! $tag) { |
|
62 | + throw new Exception(__('Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github')); |
|
63 | 63 | } |
64 | 64 | |
65 | - if ( $tag === substr( $this->message(), -1 * strlen( $tag ) ) ) { |
|
65 | + if ($tag === substr($this->message(), -1 * strlen($tag))) { |
|
66 | 66 | return false; |
67 | 67 | } |
68 | 68 | |
69 | - if ( ! $this->get_commit_id() ) { |
|
69 | + if ( ! $this->get_commit_id()) { |
|
70 | 70 | return false; |
71 | 71 | } |
72 | 72 |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @param Writing_On_GitHub $app Application container. |
37 | 37 | */ |
38 | - public function __construct( Writing_On_GitHub $app ) { |
|
38 | + public function __construct(Writing_On_GitHub $app) { |
|
39 | 39 | $this->app = $app; |
40 | 40 | } |
41 | 41 | |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | * @return Writing_On_GitHub_Fetch_Client |
46 | 46 | */ |
47 | 47 | public function fetch() { |
48 | - if ( ! $this->fetch ) { |
|
49 | - $this->fetch = new Writing_On_GitHub_Fetch_Client( $this->app ); |
|
48 | + if ( ! $this->fetch) { |
|
49 | + $this->fetch = new Writing_On_GitHub_Fetch_Client($this->app); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | return $this->fetch; |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | * @return Writing_On_GitHub_Persist_Client |
59 | 59 | */ |
60 | 60 | public function persist() { |
61 | - if ( ! $this->persist ) { |
|
62 | - $this->persist = new Writing_On_GitHub_Persist_Client( $this->app ); |
|
61 | + if ( ! $this->persist) { |
|
62 | + $this->persist = new Writing_On_GitHub_Persist_Client($this->app); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | return $this->persist; |