Passed
Branch ci (072b24)
by litefeel
03:24
created
views/options.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -6,35 +6,35 @@
 block discarded – undo
6 6
 
7 7
 ?>
8 8
 <div class="wrap">
9
-	<h2><?php esc_html_e( 'Writing On GitHub', 'writing-on-github' ); ?></h2>
9
+	<h2><?php esc_html_e('Writing On GitHub', 'writing-on-github'); ?></h2>
10 10
 
11 11
 	<form method="post" action="options.php">
12
-		<?php settings_fields( Writing_On_GitHub::$text_domain ); ?>
13
-		<?php do_settings_sections( Writing_On_GitHub::$text_domain ); ?>
12
+		<?php settings_fields(Writing_On_GitHub::$text_domain); ?>
13
+		<?php do_settings_sections(Writing_On_GitHub::$text_domain); ?>
14 14
 		<table class="form-table">
15 15
 			<tr>
16
-				<th scope="row"><?php esc_html_e( 'Webhook callback', 'writing-on-github' ); ?></th>
17
-				<td><code><?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>?action=wogh_push_request</code></td>
16
+				<th scope="row"><?php esc_html_e('Webhook callback', 'writing-on-github'); ?></th>
17
+				<td><code><?php echo esc_url(admin_url('admin-ajax.php')); ?>?action=wogh_push_request</code></td>
18 18
 			</tr>
19 19
 			<tr>
20
-                <th scope="row"><?php esc_html_e( 'Export', 'writing-on-github' ); ?></th>
20
+                <th scope="row"><?php esc_html_e('Export', 'writing-on-github'); ?></th>
21 21
                 <td>
22
-                    <p><a href="<?php echo esc_url( add_query_arg( array( 'action' => 'export' ) ) ); ?>">
23
-                        <input type="button" class="button button-secondary" value="<?php esc_html_e( 'Export to GitHub', 'writing-on-github' ); ?>" />
22
+                    <p><a href="<?php echo esc_url(add_query_arg(array('action' => 'export'))); ?>">
23
+                        <input type="button" class="button button-secondary" value="<?php esc_html_e('Export to GitHub', 'writing-on-github'); ?>" />
24 24
                     </a></p>
25
-                    <p><a href="<?php echo esc_url( add_query_arg( array( 'action' => 'force_export' ) ) ); ?>">
26
-                        <input type="button" class="button button-secondary" value="<?php esc_html_e( 'Force export to GitHub', 'writing-on-github' ); ?>" />
25
+                    <p><a href="<?php echo esc_url(add_query_arg(array('action' => 'force_export'))); ?>">
26
+                        <input type="button" class="button button-secondary" value="<?php esc_html_e('Force export to GitHub', 'writing-on-github'); ?>" />
27 27
                     </a></p>
28 28
                 </td>
29 29
             </tr>
30 30
             <tr>
31
-                <th scope="row"><?php esc_html_e( 'Import', 'writing-on-github' ); ?></th>
31
+                <th scope="row"><?php esc_html_e('Import', 'writing-on-github'); ?></th>
32 32
                 <td>
33
-                    <p><a href="<?php echo esc_url( add_query_arg( array( 'action' => 'import' ) ) ); ?>">
34
-                        <input type="button" class="button button-secondary" value="<?php esc_html_e( 'Import from GitHub', 'writing-on-github' ); ?>" />
33
+                    <p><a href="<?php echo esc_url(add_query_arg(array('action' => 'import'))); ?>">
34
+                        <input type="button" class="button button-secondary" value="<?php esc_html_e('Import from GitHub', 'writing-on-github'); ?>" />
35 35
                     </a></p>
36
-                     <p><a href="<?php echo esc_url( add_query_arg( array( 'action' => 'force_import' ) ) ); ?>">
37
-                        <input type="button" class="button button-secondary" value="<?php esc_html_e( 'Force Import from GitHub', 'writing-on-github' ); ?>" />
36
+                     <p><a href="<?php echo esc_url(add_query_arg(array('action' => 'force_import'))); ?>">
37
+                        <input type="button" class="button button-secondary" value="<?php esc_html_e('Force Import from GitHub', 'writing-on-github'); ?>" />
38 38
                     </a></p>
39 39
                 </td>
40 40
             </tr>
Please login to merge, or discard this patch.
lib/payload.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -29,9 +29,9 @@  discard block
 block discarded – undo
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,10 +41,10 @@  discard block
 block discarded – undo
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 new WP_Error(
46 46
                 'incorrect_repository',
47
-                sprintf( 'Incorrect repository, %s -> %s .',
47
+                sprintf('Incorrect repository, %s -> %s .',
48 48
                     $this->data->repository->full_name,
49 49
                     $this->app->api()->fetch()->repository()
50 50
                 )
@@ -52,15 +52,15 @@  discard block
 block discarded – undo
52 52
         }
53 53
 
54 54
         // The last term in the ref is the payload_branch name.
55
-        $refs   = explode( '/', $this->data->ref );
56
-        $payload_branch = array_pop( $refs );
55
+        $refs   = explode('/', $this->data->ref);
56
+        $payload_branch = array_pop($refs);
57 57
 
58 58
         $branch = $this->app->api()->fetch()->branch();
59 59
 
60
-        if ( $branch !== $payload_branch ) {
60
+        if ($branch !== $payload_branch) {
61 61
             return new WP_Error(
62 62
                 'incorrect_branch',
63
-                sprintf( 'Incorrect branch, %s -> %s .',
63
+                sprintf('Incorrect branch, %s -> %s .',
64 64
                     $payload_branch,
65 65
                     $branch
66 66
                 )
@@ -68,20 +68,20 @@  discard block
 block discarded – undo
68 68
         }
69 69
 
70 70
         // We add a tag to commits we push out, so we shouldn't pull them in again.
71
-        $tag = apply_filters( 'wogh_commit_msg_tag', 'wogh' );
71
+        $tag = apply_filters('wogh_commit_msg_tag', 'wogh');
72 72
 
73
-        if ( ! $tag ) {
74
-            throw new Exception( __( 'Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github' ) );
73
+        if ( ! $tag) {
74
+            throw new Exception(__('Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github'));
75 75
         }
76 76
 
77
-        if ( $tag === substr( $this->message(), -1 * strlen( $tag ) ) ) {
77
+        if ($tag === substr($this->message(), -1 * strlen($tag))) {
78 78
             return new WP_Error(
79 79
                 'skip_import',
80 80
                 'Skip import on auto export post.'
81 81
             );
82 82
         }
83 83
 
84
-        if ( ! $this->get_commit_id() ) {
84
+        if ( ! $this->get_commit_id()) {
85 85
             return new WP_Error(
86 86
                 'invalid_payload',
87 87
                 "[Missing Commit ID] won't be imported."
Please login to merge, or discard this patch.
lib/controller.php 1 patch
Spacing   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
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,55 +34,55 @@  discard block
 block discarded – undo
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
-                sprintf( 'Failed to validate webhook event: %s.',
61
-                    $this->app->request()->webhook_event() )
62
-            ) );
60
+                sprintf('Failed to validate webhook event: %s.',
61
+                    $this->app->request()->webhook_event())
62
+            ));
63 63
         }
64 64
         $payload = $this->app->request()->payload();
65 65
 
66 66
         $error = $payload->should_import();
67
-        if ( is_wp_error( $error ) ) {
67
+        if (is_wp_error($error)) {
68 68
             /* @var WP_Error $error */
69
-            return $this->app->response()->error( $error );
69
+            return $this->app->response()->error($error);
70 70
         }
71 71
 
72 72
         $this->app->semaphore()->lock();
73
-        remove_action( 'save_post', array( $this, 'export_post' ) );
74
-        remove_action( 'delete_post', array( $this, 'delete_post' ) );
73
+        remove_action('save_post', array($this, 'export_post'));
74
+        remove_action('delete_post', array($this, 'delete_post'));
75 75
 
76
-        $result = $this->app->import()->payload( $payload );
76
+        $result = $this->app->import()->payload($payload);
77 77
 
78 78
         $this->app->semaphore()->unlock();
79 79
 
80
-        if ( is_wp_error( $result ) ) {
80
+        if (is_wp_error($result)) {
81 81
             /* @var WP_Error $result */
82
-            return $this->app->response()->error( $result );
82
+            return $this->app->response()->error($result);
83 83
         }
84 84
 
85
-        return $this->app->response()->success( $result );
85
+        return $this->app->response()->success($result);
86 86
     }
87 87
 
88 88
     /**
@@ -91,36 +91,36 @@  discard block
 block discarded – undo
91 91
      * @param  boolean $force
92 92
      * @return boolean
93 93
      */
94
-    public function import_master( $user_id = 0, $force = false ) {
95
-        if ( ! $this->app->semaphore()->is_open() ) {
96
-            return $this->app->response()->error( new WP_Error(
94
+    public function import_master($user_id = 0, $force = false) {
95
+        if ( ! $this->app->semaphore()->is_open()) {
96
+            return $this->app->response()->error(new WP_Error(
97 97
                 'semaphore_locked',
98
-                sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::import_master()' )
99
-            ) );
98
+                sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::import_master()')
99
+            ));
100 100
         }
101 101
 
102 102
         $this->app->semaphore()->lock();
103
-        remove_action( 'save_post', array( $this, 'export_post' ) );
104
-        remove_action( 'save_post', array( $this, 'delete_post' ) );
103
+        remove_action('save_post', array($this, 'export_post'));
104
+        remove_action('save_post', array($this, 'delete_post'));
105 105
 
106
-        if ( $user_id ) {
107
-            wp_set_current_user( $user_id );
106
+        if ($user_id) {
107
+            wp_set_current_user($user_id);
108 108
         }
109 109
 
110
-        $result = $this->app->import()->master( $force );
110
+        $result = $this->app->import()->master($force);
111 111
 
112 112
         $this->app->semaphore()->unlock();
113 113
 
114
-        if ( is_wp_error( $result ) ) {
114
+        if (is_wp_error($result)) {
115 115
             /* @var WP_Error $result */
116
-            update_option( '_wogh_import_error', $result->get_error_message() );
116
+            update_option('_wogh_import_error', $result->get_error_message());
117 117
 
118
-            return $this->app->response()->error( $result );
118
+            return $this->app->response()->error($result);
119 119
         }
120 120
 
121
-        update_option( '_wogh_import_complete', 'yes' );
121
+        update_option('_wogh_import_complete', 'yes');
122 122
 
123
-        return $this->app->response()->success( $result );
123
+        return $this->app->response()->success($result);
124 124
     }
125 125
 
126 126
     /**
@@ -130,34 +130,34 @@  discard block
 block discarded – undo
130 130
      * @param  boolean    $force
131 131
      * @return boolean
132 132
      */
133
-    public function export_all( $user_id = 0, $force = false ) {
134
-        if ( ! $this->app->semaphore()->is_open() ) {
135
-            return $this->app->response()->error( new WP_Error(
133
+    public function export_all($user_id = 0, $force = false) {
134
+        if ( ! $this->app->semaphore()->is_open()) {
135
+            return $this->app->response()->error(new WP_Error(
136 136
                 'semaphore_locked',
137
-                sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::export_all()' )
138
-            ) );
137
+                sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::export_all()')
138
+            ));
139 139
         }
140 140
 
141 141
         $this->app->semaphore()->lock();
142 142
 
143
-        if ( $user_id ) {
144
-            wp_set_current_user( $user_id );
143
+        if ($user_id) {
144
+            wp_set_current_user($user_id);
145 145
         }
146 146
 
147 147
         $result = $this->app->export()->full($force);
148 148
         $this->app->semaphore()->unlock();
149 149
 
150 150
         // Maybe move option updating out of this class/upgrade message display?
151
-        if ( is_wp_error( $result ) ) {
151
+        if (is_wp_error($result)) {
152 152
             /* @var WP_Error $result */
153
-            update_option( '_wogh_export_error', $result->get_error_message() );
153
+            update_option('_wogh_export_error', $result->get_error_message());
154 154
 
155
-            return $this->app->response()->error( $result );
155
+            return $this->app->response()->error($result);
156 156
         } else {
157
-            update_option( '_wogh_export_complete', 'yes' );
158
-            update_option( '_wogh_fully_exported', 'yes' );
157
+            update_option('_wogh_export_complete', 'yes');
158
+            update_option('_wogh_fully_exported', 'yes');
159 159
 
160
-            return $this->app->response()->success( $result );
160
+            return $this->app->response()->success($result);
161 161
         }
162 162
     }
163 163
 
@@ -170,28 +170,28 @@  discard block
 block discarded – undo
170 170
      *
171 171
      * @return boolean
172 172
      */
173
-    public function export_post( $post_id ) {
174
-        if ( wp_is_post_revision( $post_id ) ) {
173
+    public function export_post($post_id) {
174
+        if (wp_is_post_revision($post_id)) {
175 175
             return;
176 176
         }
177 177
 
178
-        if ( ! $this->app->semaphore()->is_open() ) {
179
-            return $this->app->response()->error( new WP_Error(
178
+        if ( ! $this->app->semaphore()->is_open()) {
179
+            return $this->app->response()->error(new WP_Error(
180 180
                 'semaphore_locked',
181
-                sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::export_post()' )
182
-            ) );
181
+                sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::export_post()')
182
+            ));
183 183
         }
184 184
 
185 185
         $this->app->semaphore()->lock();
186
-        $result = $this->app->export()->update( $post_id );
186
+        $result = $this->app->export()->update($post_id);
187 187
         $this->app->semaphore()->unlock();
188 188
 
189
-        if ( is_wp_error( $result ) ) {
189
+        if (is_wp_error($result)) {
190 190
             /* @var WP_Error $result */
191
-            return $this->app->response()->error( $result );
191
+            return $this->app->response()->error($result);
192 192
         }
193 193
 
194
-        return $this->app->response()->success( $result );
194
+        return $this->app->response()->success($result);
195 195
     }
196 196
 
197 197
     /**
@@ -203,28 +203,28 @@  discard block
 block discarded – undo
203 203
      *
204 204
      * @return boolean
205 205
      */
206
-    public function delete_post( $post_id ) {
207
-        if ( wp_is_post_revision( $post_id ) ) {
206
+    public function delete_post($post_id) {
207
+        if (wp_is_post_revision($post_id)) {
208 208
             return;
209 209
         }
210 210
 
211
-        if ( ! $this->app->semaphore()->is_open() ) {
212
-            return $this->app->response()->error( new WP_Error(
211
+        if ( ! $this->app->semaphore()->is_open()) {
212
+            return $this->app->response()->error(new WP_Error(
213 213
                 'semaphore_locked',
214
-                sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::delete_post()' )
215
-            ) );
214
+                sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::delete_post()')
215
+            ));
216 216
         }
217 217
 
218 218
         $this->app->semaphore()->lock();
219
-        $result = $this->app->export()->delete( $post_id );
219
+        $result = $this->app->export()->delete($post_id);
220 220
         $this->app->semaphore()->unlock();
221 221
 
222
-        if ( is_wp_error( $result ) ) {
222
+        if (is_wp_error($result)) {
223 223
             /* @var WP_Error $result */
224
-            return $this->app->response()->error( $result );
224
+            return $this->app->response()->error($result);
225 225
         }
226 226
 
227
-        return $this->app->response()->success( $result );
227
+        return $this->app->response()->success($result);
228 228
     }
229 229
 
230 230
     /**
@@ -233,8 +233,8 @@  discard block
 block discarded – undo
233 233
      * than just returning data.
234 234
      */
235 235
     protected function set_ajax() {
236
-        if ( ! defined( 'WOGH_AJAX' ) ) {
237
-            define( 'WOGH_AJAX', true );
236
+        if ( ! defined('WOGH_AJAX')) {
237
+            define('WOGH_AJAX', true);
238 238
         }
239 239
     }
240 240
 }
Please login to merge, or discard this patch.
lib/import.php 1 patch
Spacing   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
      *
23 23
      * @param Writing_On_GitHub $app Application container.
24 24
      */
25
-    public function __construct( Writing_On_GitHub $app ) {
25
+    public function __construct(Writing_On_GitHub $app) {
26 26
         $this->app = $app;
27 27
     }
28 28
 
@@ -32,24 +32,24 @@  discard block
 block discarded – undo
32 32
      *
33 33
      * @return string|WP_Error
34 34
      */
35
-    public function payload( Writing_On_GitHub_Payload $payload ) {
35
+    public function payload(Writing_On_GitHub_Payload $payload) {
36 36
 
37
-        $result = $this->app->api()->fetch()->compare( $payload->get_before_commit_id() );
37
+        $result = $this->app->api()->fetch()->compare($payload->get_before_commit_id());
38 38
 
39
-        if ( is_wp_error( $result ) ) {
39
+        if (is_wp_error($result)) {
40 40
             /* @var WP_Error $result */
41 41
             return $result;
42 42
         }
43 43
 
44
-        if ( is_array( $result ) ) {
45
-            $result = $this->import_files( $result );
44
+        if (is_array($result)) {
45
+            $result = $this->import_files($result);
46 46
         }
47 47
 
48
-        if ( is_wp_error( $result ) ) {
48
+        if (is_wp_error($result)) {
49 49
             return $files;
50 50
         }
51 51
 
52
-        return __( 'Payload processed', 'writing-on-github' );
52
+        return __('Payload processed', 'writing-on-github');
53 53
     }
54 54
 
55 55
     /**
@@ -59,37 +59,37 @@  discard block
 block discarded – undo
59 59
      *
60 60
      * @return true|WP_Error
61 61
      */
62
-    protected function import_files( $files, $force = false ) {
62
+    protected function import_files($files, $force = false) {
63 63
 
64 64
         $error = true;
65 65
 
66
-        foreach ( $files as $file ) {
67
-            if ( ! $this->importable_file( $file ) ) {
66
+        foreach ($files as $file) {
67
+            if ( ! $this->importable_file($file)) {
68 68
                 continue;
69 69
             }
70 70
 
71
-            $blob = $this->app->api()->fetch()->blob( $file );
71
+            $blob = $this->app->api()->fetch()->blob($file);
72 72
             // network error ?
73
-            if ( ! $blob instanceof Writing_On_GitHub_Blob ) {
73
+            if ( ! $blob instanceof Writing_On_GitHub_Blob) {
74 74
                 continue;
75 75
             }
76 76
 
77 77
             $is_remove = 'removed' == $file->status;
78 78
 
79 79
             $result = false;
80
-            if ( $this->importable_raw_file( $blob ) ) {
81
-                $result = $this->import_raw_file( $blob, $is_remove );
82
-            } elseif ( $this->importable_post( $blob ) ) {
83
-                if ( $is_remove ) {
84
-                    $result = $this->delete_post( $blob );
80
+            if ($this->importable_raw_file($blob)) {
81
+                $result = $this->import_raw_file($blob, $is_remove);
82
+            } elseif ($this->importable_post($blob)) {
83
+                if ($is_remove) {
84
+                    $result = $this->delete_post($blob);
85 85
                 } else {
86
-                    $result = $this->import_post( $blob, $force );
86
+                    $result = $this->import_post($blob, $force);
87 87
                 }
88 88
             }
89 89
 
90
-            if ( is_wp_error( $result ) ) {
90
+            if (is_wp_error($result)) {
91 91
                 /* @var WP_Error $result */
92
-                $error = wogh_append_error( $error, $result );
92
+                $error = wogh_append_error($error, $result);
93 93
             }
94 94
         }
95 95
 
@@ -102,24 +102,24 @@  discard block
 block discarded – undo
102 102
      * @param  boolean $force
103 103
      * @return string|WP_Error
104 104
      */
105
-    public function master( $force = false ) {
105
+    public function master($force = false) {
106 106
         $result = $this->app->api()->fetch()->tree_recursive();
107 107
 
108
-        if ( is_wp_error( $result ) ) {
108
+        if (is_wp_error($result)) {
109 109
             /* @var WP_Error $result */
110 110
             return $result;
111 111
         }
112 112
 
113
-        if ( is_array( $result ) ) {
114
-            $result = $this->import_files( $result, $force );
113
+        if (is_array($result)) {
114
+            $result = $this->import_files($result, $force);
115 115
         }
116 116
 
117
-        if ( is_wp_error( $result ) ) {
117
+        if (is_wp_error($result)) {
118 118
             /* @var WP_Error $result */
119 119
             return $result;
120 120
         }
121 121
 
122
-        return __( 'Payload processed', 'writing-on-github' );
122
+        return __('Payload processed', 'writing-on-github');
123 123
     }
124 124
 
125 125
     /**
@@ -129,14 +129,14 @@  discard block
 block discarded – undo
129 129
      *
130 130
      * @return bool
131 131
      */
132
-    protected function importable_file( Writing_On_GitHub_File_Info $file ) {
132
+    protected function importable_file(Writing_On_GitHub_File_Info $file) {
133 133
 
134 134
         $path = $file->path;
135 135
 
136 136
         // only _pages, _posts and images
137
-        $prefixs = array( '_pages/', '_posts/', 'images/');
137
+        $prefixs = array('_pages/', '_posts/', 'images/');
138 138
         foreach ($prefixs as $prefix) {
139
-            if ( ! strncasecmp($path, $prefix, strlen( $prefix ) ) ) {
139
+            if ( ! strncasecmp($path, $prefix, strlen($prefix))) {
140 140
                 return true;
141 141
             }
142 142
         }
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
      *
151 151
      * @return bool
152 152
      */
153
-    protected function importable_post( Writing_On_GitHub_Blob $blob ) {
153
+    protected function importable_post(Writing_On_GitHub_Blob $blob) {
154 154
         // global $wpdb;
155 155
 
156 156
         // // Skip the repo's readme.
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
         //  return false;
164 164
         // }
165 165
 
166
-        if ( ! $blob->has_frontmatter() ) {
166
+        if ( ! $blob->has_frontmatter()) {
167 167
             return false;
168 168
         }
169 169
 
@@ -175,13 +175,13 @@  discard block
 block discarded – undo
175 175
      * @param  Writing_On_GitHub_Blob $blob
176 176
      * @return WP_Error|bool
177 177
      */
178
-    protected function delete_post( Writing_On_GitHub_Blob $blob ) {
178
+    protected function delete_post(Writing_On_GitHub_Blob $blob) {
179 179
         $id = $blob->id();
180
-        if ( empty( $id ) ) {
180
+        if (empty($id)) {
181 181
             return false;
182 182
         }
183
-        $result = $this->app->database()->delete_post( $id );
184
-        if ( is_wp_error( $result ) ) {
183
+        $result = $this->app->database()->delete_post($id);
184
+        if (is_wp_error($result)) {
185 185
             /* @var WP_Error $result */
186 186
             return $result;
187 187
         }
@@ -194,31 +194,31 @@  discard block
 block discarded – undo
194 194
      * @param  boolean                $force
195 195
      * @return WP_Error|bool
196 196
      */
197
-    protected function import_post( Writing_On_GitHub_Blob $blob, $force = false ) {
198
-        $post = $this->blob_to_post( $blob, $force );
197
+    protected function import_post(Writing_On_GitHub_Blob $blob, $force = false) {
198
+        $post = $this->blob_to_post($blob, $force);
199 199
 
200
-        if ( ! $post instanceof Writing_On_GitHub_Post ) {
200
+        if ( ! $post instanceof Writing_On_GitHub_Post) {
201 201
             return false;
202 202
         }
203 203
 
204
-        $result = $this->app->database()->save_post( $post );
205
-        if ( is_wp_error( $result ) ) {
204
+        $result = $this->app->database()->save_post($post);
205
+        if (is_wp_error($result)) {
206 206
             /** @var WP_Error $result */
207 207
             return $result;
208 208
         }
209 209
 
210
-        if ( $post->is_new() ||
211
-                ! wogh_equal_front_matter( $post, $blob ) ) {
210
+        if ($post->is_new() ||
211
+                ! wogh_equal_front_matter($post, $blob)) {
212 212
 
213
-            $result = $this->app->export()->export_post( $post );
213
+            $result = $this->app->export()->export_post($post);
214 214
 
215
-            if ( is_wp_error( $result ) ) {
215
+            if (is_wp_error($result)) {
216 216
                 /** @var WP_Error $result */
217 217
                 return $result;
218 218
             }
219 219
         }
220 220
 
221
-        clean_post_cache( $post->id() );
221
+        clean_post_cache($post->id());
222 222
 
223 223
         return true;
224 224
     }
@@ -228,13 +228,13 @@  discard block
 block discarded – undo
228 228
      * @param  Writing_On_GitHub_Blob $blob
229 229
      * @return bool
230 230
      */
231
-    protected function importable_raw_file( Writing_On_GitHub_Blob $blob ) {
232
-        if ( $blob->has_frontmatter() ) {
231
+    protected function importable_raw_file(Writing_On_GitHub_Blob $blob) {
232
+        if ($blob->has_frontmatter()) {
233 233
             return false;
234 234
         }
235 235
 
236 236
         // only images
237
-        if ( strncasecmp($blob->path(), 'images/', strlen('images/') ) != 0) {
237
+        if (strncasecmp($blob->path(), 'images/', strlen('images/')) != 0) {
238 238
             return false;
239 239
         }
240 240
 
@@ -246,16 +246,16 @@  discard block
 block discarded – undo
246 246
      * @param  Writing_On_GitHub_Blob $blob
247 247
      * @param  bool                   $is_remove
248 248
      */
249
-    protected function import_raw_file( Writing_On_GitHub_Blob $blob, $is_remove ) {
249
+    protected function import_raw_file(Writing_On_GitHub_Blob $blob, $is_remove) {
250 250
         $arr = wp_upload_dir();
251 251
         $path = $arr['basedir'] . '/writing-on-github/' . $blob->path();
252
-        if ( $is_remove ) {
253
-            if ( file_exists($path) ) {
252
+        if ($is_remove) {
253
+            if (file_exists($path)) {
254 254
                 unlink($path);
255 255
             }
256 256
         } else {
257 257
             $dirname = dirname($path);
258
-            if ( ! file_exists($dirname) ) {
258
+            if ( ! file_exists($dirname)) {
259 259
                 wp_mkdir_p($dirname);
260 260
             }
261 261
 
@@ -272,67 +272,67 @@  discard block
 block discarded – undo
272 272
      *
273 273
      * @return Writing_On_GitHub_Post|false
274 274
      */
275
-    protected function blob_to_post( Writing_On_GitHub_Blob $blob, $force = false ) {
276
-        $args = array( 'post_content' => $blob->content_import() );
275
+    protected function blob_to_post(Writing_On_GitHub_Blob $blob, $force = false) {
276
+        $args = array('post_content' => $blob->content_import());
277 277
         $meta = $blob->meta();
278 278
 
279 279
         $id = false;
280 280
 
281
-        if ( ! empty( $meta ) ) {
282
-            if ( array_key_exists( 'layout', $meta ) ) {
281
+        if ( ! empty($meta)) {
282
+            if (array_key_exists('layout', $meta)) {
283 283
                 $args['post_type'] = $meta['layout'];
284
-                unset( $meta['layout'] );
284
+                unset($meta['layout']);
285 285
             }
286 286
 
287
-            if ( array_key_exists( 'published', $meta ) ) {
287
+            if (array_key_exists('published', $meta)) {
288 288
                 $args['post_status'] = true === $meta['published'] ? 'publish' : 'draft';
289
-                unset( $meta['published'] );
289
+                unset($meta['published']);
290 290
             }
291 291
 
292
-            if ( array_key_exists( 'post_title', $meta ) ) {
292
+            if (array_key_exists('post_title', $meta)) {
293 293
                 $args['post_title'] = $meta['post_title'];
294
-                unset( $meta['post_title'] );
294
+                unset($meta['post_title']);
295 295
             }
296 296
 
297
-            if ( array_key_exists( 'post_name', $meta ) ) {
297
+            if (array_key_exists('post_name', $meta)) {
298 298
                 $args['post_name'] = $meta['post_name'];
299
-                unset( $meta['post_name'] );
299
+                unset($meta['post_name']);
300 300
             }
301 301
 
302
-            if ( array_key_exists( 'ID', $meta ) ) {
302
+            if (array_key_exists('ID', $meta)) {
303 303
                 $id = $args['ID'] = $meta['ID'];
304 304
                 $blob->set_id($id);
305
-                unset( $meta['ID'] );
305
+                unset($meta['ID']);
306 306
             }
307 307
 
308
-            if ( array_key_exists( 'post_date', $meta ) ) {
309
-                if ( empty( $meta['post_date'] ) ) {
310
-                    $meta['post_date'] = current_time( 'mysql' );
308
+            if (array_key_exists('post_date', $meta)) {
309
+                if (empty($meta['post_date'])) {
310
+                    $meta['post_date'] = current_time('mysql');
311 311
                 }
312 312
 
313 313
                 $args['post_date'] = $meta['post_date'];
314
-                unset( $meta['post_date'] );
314
+                unset($meta['post_date']);
315 315
             }
316 316
         }
317 317
 
318 318
         $meta['_wogh_sha'] = $blob->sha();
319 319
 
320
-        if ( ! $force && $id ) {
321
-            $old_sha = get_post_meta( $id, '_wogh_sha', true );
322
-            $old_github_path = get_post_meta( $id, '_wogh_github_path', true );
320
+        if ( ! $force && $id) {
321
+            $old_sha = get_post_meta($id, '_wogh_sha', true);
322
+            $old_github_path = get_post_meta($id, '_wogh_github_path', true);
323 323
 
324 324
             // dont save post when has same sha
325
-            if ( $old_sha  && $old_sha == $meta['_wogh_sha'] &&
326
-                 $old_github_path && $old_github_path == $blob->path() ) {
325
+            if ($old_sha && $old_sha == $meta['_wogh_sha'] &&
326
+                 $old_github_path && $old_github_path == $blob->path()) {
327 327
                 return false;
328 328
             }
329 329
         }
330 330
 
331
-        $post = new Writing_On_GitHub_Post( $args, $this->app->api() );
332
-        $post->set_old_github_path( $blob->path() );
333
-        $post->set_meta( $meta );
334
-        $post->set_blob( $blob );
335
-        $blob->set_id( $post->id() );
331
+        $post = new Writing_On_GitHub_Post($args, $this->app->api());
332
+        $post->set_old_github_path($blob->path());
333
+        $post->set_meta($meta);
334
+        $post->set_blob($blob);
335
+        $blob->set_id($post->id());
336 336
 
337 337
         return $post;
338 338
     }
Please login to merge, or discard this patch.