@@ -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_metas' ); |
|
88 | - add_settings_field( 'wogh_ignore_metas', __( 'Ignore post metas', 'writing-on-github' ), array( &$this, 'textarea_field_callback' ), Writing_On_GitHub::$text_domain, 'general', array( |
|
87 | + register_setting(Writing_On_GitHub::$text_domain, 'wogh_ignore_metas'); |
|
88 | + add_settings_field('wogh_ignore_metas', __('Ignore post metas', 'writing-on-github'), array(&$this, 'textarea_field_callback'), Writing_On_GitHub::$text_domain, 'general', array( |
|
89 | 89 | 'default' => '', |
90 | 90 | 'name' => 'wogh_ignore_metas', |
91 | - 'help_text' => __( 'These meta keys will be ignored and cannot be imported and exported. One meta key per line.', 'writing-on-github' ), |
|
91 | + 'help_text' => __('These meta keys will be ignored and cannot be imported and exported. One meta key per line.', 'writing-on-github'), |
|
92 | 92 | ) |
93 | 93 | ); |
94 | 94 | } |
@@ -98,8 +98,8 @@ discard block |
||
98 | 98 | * |
99 | 99 | * @param array $args Field arguments. |
100 | 100 | */ |
101 | - public function field_callback( $args ) { |
|
102 | - include dirname( dirname( __FILE__ ) ) . '/views/setting-field.php'; |
|
101 | + public function field_callback($args) { |
|
102 | + include dirname(dirname(__FILE__)) . '/views/setting-field.php'; |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -107,8 +107,8 @@ discard block |
||
107 | 107 | * |
108 | 108 | * @param array $args Field arguments. |
109 | 109 | */ |
110 | - public function user_field_callback( $args ) { |
|
111 | - include dirname( dirname( __FILE__ ) ) . '/views/user-setting-field.php'; |
|
110 | + public function user_field_callback($args) { |
|
111 | + include dirname(dirname(__FILE__)) . '/views/user-setting-field.php'; |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -116,58 +116,58 @@ discard block |
||
116 | 116 | * |
117 | 117 | * @param array $args Field arguments. |
118 | 118 | */ |
119 | - public function textarea_field_callback( $args ) { |
|
120 | - include dirname( dirname( __FILE__ ) ) . '/views/textarea-setting-field.php'; |
|
119 | + public function textarea_field_callback($args) { |
|
120 | + include dirname(dirname(__FILE__)) . '/views/textarea-setting-field.php'; |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
124 | 124 | * Displays settings messages from background processes |
125 | 125 | */ |
126 | 126 | public function section_callback() { |
127 | - if ( get_current_screen()->id !== 'settings_page_' . Writing_On_GitHub::$text_domain ) { |
|
127 | + if (get_current_screen()->id !== 'settings_page_' . Writing_On_GitHub::$text_domain) { |
|
128 | 128 | return; |
129 | 129 | } |
130 | 130 | |
131 | - if ( 'yes' === get_option( '_wogh_export_started' ) ) { ?> |
|
131 | + if ('yes' === get_option('_wogh_export_started')) { ?> |
|
132 | 132 | <div class="updated"> |
133 | - <p><?php esc_html_e( 'Export to GitHub started.', 'writing-on-github' ); ?></p> |
|
133 | + <p><?php esc_html_e('Export to GitHub started.', 'writing-on-github'); ?></p> |
|
134 | 134 | </div><?php |
135 | - delete_option( '_wogh_export_started' ); |
|
135 | + delete_option('_wogh_export_started'); |
|
136 | 136 | } |
137 | 137 | |
138 | - if ( $message = get_option( '_wogh_export_error' ) ) { ?> |
|
138 | + if ($message = get_option('_wogh_export_error')) { ?> |
|
139 | 139 | <div class="error"> |
140 | - <p><?php esc_html_e( 'Export to GitHub failed with error:', 'writing-on-github' ); ?> <?php echo esc_html( $message );?></p> |
|
140 | + <p><?php esc_html_e('Export to GitHub failed with error:', 'writing-on-github'); ?> <?php echo esc_html($message); ?></p> |
|
141 | 141 | </div><?php |
142 | - delete_option( '_wogh_export_error' ); |
|
142 | + delete_option('_wogh_export_error'); |
|
143 | 143 | } |
144 | 144 | |
145 | - if ( 'yes' === get_option( '_wogh_export_complete' ) ) { ?> |
|
145 | + if ('yes' === get_option('_wogh_export_complete')) { ?> |
|
146 | 146 | <div class="updated"> |
147 | - <p><?php esc_html_e( 'Export to GitHub completed successfully.', 'writing-on-github' );?></p> |
|
147 | + <p><?php esc_html_e('Export to GitHub completed successfully.', 'writing-on-github'); ?></p> |
|
148 | 148 | </div><?php |
149 | - delete_option( '_wogh_export_complete' ); |
|
149 | + delete_option('_wogh_export_complete'); |
|
150 | 150 | } |
151 | 151 | |
152 | - if ( 'yes' === get_option( '_wogh_import_started' ) ) { ?> |
|
152 | + if ('yes' === get_option('_wogh_import_started')) { ?> |
|
153 | 153 | <div class="updated"> |
154 | - <p><?php esc_html_e( 'Import from GitHub started.', 'writing-on-github' ); ?></p> |
|
154 | + <p><?php esc_html_e('Import from GitHub started.', 'writing-on-github'); ?></p> |
|
155 | 155 | </div><?php |
156 | - delete_option( '_wogh_import_started' ); |
|
156 | + delete_option('_wogh_import_started'); |
|
157 | 157 | } |
158 | 158 | |
159 | - if ( $message = get_option( '_wogh_import_error' ) ) { ?> |
|
159 | + if ($message = get_option('_wogh_import_error')) { ?> |
|
160 | 160 | <div class="error"> |
161 | - <p><?php esc_html_e( 'Import from GitHub failed with error:', 'writing-on-github' ); ?> <?php echo esc_html( $message );?></p> |
|
161 | + <p><?php esc_html_e('Import from GitHub failed with error:', 'writing-on-github'); ?> <?php echo esc_html($message); ?></p> |
|
162 | 162 | </div><?php |
163 | - delete_option( '_wogh_import_error' ); |
|
163 | + delete_option('_wogh_import_error'); |
|
164 | 164 | } |
165 | 165 | |
166 | - if ( 'yes' === get_option( '_wogh_import_complete' ) ) { ?> |
|
166 | + if ('yes' === get_option('_wogh_import_complete')) { ?> |
|
167 | 167 | <div class="updated"> |
168 | - <p><?php esc_html_e( 'Import from GitHub completed successfully.', 'writing-on-github' );?></p> |
|
168 | + <p><?php esc_html_e('Import from GitHub completed successfully.', 'writing-on-github'); ?></p> |
|
169 | 169 | </div><?php |
170 | - delete_option( '_wogh_import_complete' ); |
|
170 | + delete_option('_wogh_import_complete'); |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | |
@@ -176,11 +176,11 @@ discard block |
||
176 | 176 | */ |
177 | 177 | public function add_admin_menu() { |
178 | 178 | add_options_page( |
179 | - __( 'Writing On GitHub', 'writing-on-github' ), |
|
180 | - __( 'Writing On GitHub', 'writing-on-github' ), |
|
179 | + __('Writing On GitHub', 'writing-on-github'), |
|
180 | + __('Writing On GitHub', 'writing-on-github'), |
|
181 | 181 | 'manage_options', |
182 | 182 | Writing_On_GitHub::$text_domain, |
183 | - array( $this, 'settings_page' ) |
|
183 | + array($this, 'settings_page') |
|
184 | 184 | ); |
185 | 185 | } |
186 | 186 | |
@@ -188,27 +188,27 @@ discard block |
||
188 | 188 | * Admin callback to trigger import/export because WordPress admin routing lol |
189 | 189 | */ |
190 | 190 | public function trigger_cron() { |
191 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
191 | + if ( ! current_user_can('manage_options')) { |
|
192 | 192 | return; |
193 | 193 | } |
194 | 194 | |
195 | - if ( get_current_screen()->id !== 'settings_page_' . Writing_On_GitHub::$text_domain ) { |
|
195 | + if (get_current_screen()->id !== 'settings_page_' . Writing_On_GitHub::$text_domain) { |
|
196 | 196 | return; |
197 | 197 | } |
198 | 198 | |
199 | - if ( ! isset( $_GET['action'] ) ) { |
|
199 | + if ( ! isset($_GET['action'])) { |
|
200 | 200 | return; |
201 | 201 | } |
202 | 202 | |
203 | - if ( 'export' === $_GET['action'] ) { |
|
203 | + if ('export' === $_GET['action']) { |
|
204 | 204 | Writing_On_GitHub::$instance->start_export(); |
205 | 205 | } |
206 | 206 | |
207 | - if ( 'import' === $_GET['action'] ) { |
|
207 | + if ('import' === $_GET['action']) { |
|
208 | 208 | Writing_On_GitHub::$instance->start_import(); |
209 | 209 | } |
210 | 210 | |
211 | - wp_redirect( admin_url( 'options-general.php?page=writing-on-github' ) ); |
|
211 | + wp_redirect(admin_url('options-general.php?page=writing-on-github')); |
|
212 | 212 | die; |
213 | 213 | } |
214 | 214 | } |
@@ -60,26 +60,26 @@ discard block |
||
60 | 60 | * |
61 | 61 | * @todo remove database operations from this method |
62 | 62 | */ |
63 | - public function __construct( $id_or_args, Writing_On_GitHub_Api $api ) { |
|
63 | + public function __construct($id_or_args, Writing_On_GitHub_Api $api) { |
|
64 | 64 | $this->api = $api; |
65 | 65 | |
66 | - if ( is_numeric( $id_or_args ) ) { |
|
66 | + if (is_numeric($id_or_args)) { |
|
67 | 67 | $this->id = (int) $id_or_args; |
68 | - $this->post = get_post( $this->id ); |
|
68 | + $this->post = get_post($this->id); |
|
69 | 69 | $this->new = false; |
70 | 70 | } |
71 | 71 | |
72 | - if ( is_array( $id_or_args ) ) { |
|
72 | + if (is_array($id_or_args)) { |
|
73 | 73 | $this->args = $id_or_args; |
74 | 74 | |
75 | - if ( isset( $this->args['ID'] ) ) { |
|
76 | - $this->post = get_post( $this->args['ID'] ); |
|
75 | + if (isset($this->args['ID'])) { |
|
76 | + $this->post = get_post($this->args['ID']); |
|
77 | 77 | |
78 | - if ( $this->post ) { |
|
78 | + if ($this->post) { |
|
79 | 79 | $this->id = $this->post->ID; |
80 | 80 | $this->new = false; |
81 | 81 | } else { |
82 | - unset( $this->args['ID'] ); |
|
82 | + unset($this->args['ID']); |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * @return bool |
116 | 116 | */ |
117 | 117 | public function has_password() { |
118 | - return ! empty( $this->post->post_password ); |
|
118 | + return ! empty($this->post->post_password); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -123,9 +123,9 @@ discard block |
||
123 | 123 | */ |
124 | 124 | public function github_content() { |
125 | 125 | $content = $this->front_matter() . $this->post_content(); |
126 | - $ending = apply_filters( 'wogh_line_endings', "\n" ); |
|
126 | + $ending = apply_filters('wogh_line_endings', "\n"); |
|
127 | 127 | |
128 | - return preg_replace( '~(*BSR_ANYCRLF)\R~', $ending, $content ); |
|
128 | + return preg_replace('~(*BSR_ANYCRLF)\R~', $ending, $content); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * Returns String the YAML frontmatter, ready to be written to the file |
135 | 135 | */ |
136 | 136 | public function front_matter() { |
137 | - return "---\n" . spyc_dump( $this->meta() ) . "---\n"; |
|
137 | + return "---\n" . spyc_dump($this->meta()) . "---\n"; |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -145,24 +145,24 @@ discard block |
||
145 | 145 | public function post_content() { |
146 | 146 | $content = $this->post->post_content; |
147 | 147 | |
148 | - if ( function_exists( 'wpmarkdown_html_to_markdown' ) ) { |
|
149 | - $content = wpmarkdown_html_to_markdown( $content ); |
|
150 | - } else if ( class_exists( 'WPCom_Markdown' ) ) { |
|
151 | - if ( WPCom_Markdown::get_instance()->is_markdown( $this->post->ID ) ) { |
|
148 | + if (function_exists('wpmarkdown_html_to_markdown')) { |
|
149 | + $content = wpmarkdown_html_to_markdown($content); |
|
150 | + } else if (class_exists('WPCom_Markdown')) { |
|
151 | + if (WPCom_Markdown::get_instance()->is_markdown($this->post->ID)) { |
|
152 | 152 | $content = $this->post->post_content_filtered; |
153 | 153 | } |
154 | 154 | } |
155 | 155 | |
156 | - return apply_filters( 'wogh_content_export', $content, $this ); |
|
156 | + return apply_filters('wogh_content_export', $content, $this); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | public function old_github_path() { |
160 | 160 | return $this->old_github_path; |
161 | 161 | } |
162 | 162 | |
163 | - public function set_old_github_path( $path ) { |
|
163 | + public function set_old_github_path($path) { |
|
164 | 164 | $this->old_github_path = $path; |
165 | - update_post_meta( $this->id, '_wogh_github_path', $path); |
|
165 | + update_post_meta($this->id, '_wogh_github_path', $path); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | |
@@ -184,13 +184,13 @@ discard block |
||
184 | 184 | * @return string |
185 | 185 | */ |
186 | 186 | public function github_directory() { |
187 | - if ( 'publish' !== $this->status() ) { |
|
188 | - return apply_filters( 'wogh_directory_unpublished', '_drafts/', $this ); |
|
187 | + if ('publish' !== $this->status()) { |
|
188 | + return apply_filters('wogh_directory_unpublished', '_drafts/', $this); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | $name = ''; |
192 | 192 | |
193 | - switch ( $this->type() ) { |
|
193 | + switch ($this->type()) { |
|
194 | 194 | case 'post': |
195 | 195 | $name = 'posts'; |
196 | 196 | break; |
@@ -198,35 +198,35 @@ discard block |
||
198 | 198 | $name = 'pages'; |
199 | 199 | break; |
200 | 200 | default: |
201 | - $obj = get_post_type_object( $this->type() ); |
|
201 | + $obj = get_post_type_object($this->type()); |
|
202 | 202 | |
203 | - if ( $obj ) { |
|
204 | - $name = strtolower( $obj->labels->name ); |
|
203 | + if ($obj) { |
|
204 | + $name = strtolower($obj->labels->name); |
|
205 | 205 | } |
206 | 206 | |
207 | - if ( ! $name ) { |
|
207 | + if ( ! $name) { |
|
208 | 208 | $name = ''; |
209 | 209 | } |
210 | 210 | } |
211 | 211 | |
212 | - if ( $name ) { |
|
212 | + if ($name) { |
|
213 | 213 | $name = '_' . $name . '/'; |
214 | 214 | } |
215 | 215 | |
216 | - return apply_filters( 'wogh_directory_published', $name, $this ); |
|
216 | + return apply_filters('wogh_directory_published', $name, $this); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
220 | 220 | * Build GitHub filename based on post |
221 | 221 | */ |
222 | 222 | public function github_filename() { |
223 | - if ( 'post' === $this->type() ) { |
|
224 | - $filename = get_the_time( 'Y-m-d-', $this->id ) . $this->get_name() . '.md'; |
|
223 | + if ('post' === $this->type()) { |
|
224 | + $filename = get_the_time('Y-m-d-', $this->id) . $this->get_name() . '.md'; |
|
225 | 225 | } else { |
226 | 226 | $filename = $this->get_name() . '.md'; |
227 | 227 | } |
228 | 228 | |
229 | - return apply_filters( 'wogh_filename', $filename, $this ); |
|
229 | + return apply_filters('wogh_filename', $filename, $this); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -235,11 +235,11 @@ discard block |
||
235 | 235 | * @return string |
236 | 236 | */ |
237 | 237 | protected function get_name() { |
238 | - if ( '' !== $this->name() ) { |
|
238 | + if ('' !== $this->name()) { |
|
239 | 239 | return $this->name(); |
240 | 240 | } |
241 | 241 | |
242 | - return sanitize_title( get_the_title( $this->post ) ); |
|
242 | + return sanitize_title(get_the_title($this->post)); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
@@ -247,9 +247,9 @@ discard block |
||
247 | 247 | * @return boolean |
248 | 248 | */ |
249 | 249 | public function is_on_github() { |
250 | - $sha = get_post_meta( $this->id, '_wogh_sha', true ); |
|
251 | - $github_path = get_post_meta( $this->id, '_wogh_github_path', true ); |
|
252 | - if ( $sha && $github_path ) { |
|
250 | + $sha = get_post_meta($this->id, '_wogh_sha', true); |
|
251 | + $github_path = get_post_meta($this->id, '_wogh_github_path', true); |
|
252 | + if ($sha && $github_path) { |
|
253 | 253 | return true; |
254 | 254 | } |
255 | 255 | return false; |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | * @return string |
262 | 262 | */ |
263 | 263 | public function github_view_url() { |
264 | - $github_path = get_post_meta( $this->id, '_wogh_github_path', true ); |
|
264 | + $github_path = get_post_meta($this->id, '_wogh_github_path', true); |
|
265 | 265 | $repository = $this->api->fetch()->repository(); |
266 | 266 | $branch = $this->api->fetch()->branch(); |
267 | 267 | |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | * @return string |
275 | 275 | */ |
276 | 276 | public function github_edit_url() { |
277 | - $github_path = get_post_meta( $this->id, '_wogh_github_path', true ); |
|
277 | + $github_path = get_post_meta($this->id, '_wogh_github_path', true); |
|
278 | 278 | $repository = $this->api->fetch()->repository(); |
279 | 279 | $branch = $this->api->fetch()->branch(); |
280 | 280 | |
@@ -288,9 +288,9 @@ discard block |
||
288 | 288 | * |
289 | 289 | * @return string |
290 | 290 | */ |
291 | - public function get_directory_from_path( $path ) { |
|
292 | - $directory = explode( '/', $path ); |
|
293 | - $directory = count( $directory ) > 0 ? $directory[0] : ''; |
|
291 | + public function get_directory_from_path($path) { |
|
292 | + $directory = explode('/', $path); |
|
293 | + $directory = count($directory) > 0 ? $directory[0] : ''; |
|
294 | 294 | |
295 | 295 | return $directory; |
296 | 296 | } |
@@ -301,11 +301,11 @@ discard block |
||
301 | 301 | * Returns Array an array containing the author name and email |
302 | 302 | */ |
303 | 303 | public function last_modified_author() { |
304 | - if ( $last_id = get_post_meta( $this->id, '_edit_last', true ) ) { |
|
305 | - $user = get_userdata( $last_id ); |
|
304 | + if ($last_id = get_post_meta($this->id, '_edit_last', true)) { |
|
305 | + $user = get_userdata($last_id); |
|
306 | 306 | |
307 | - if ( $user ) { |
|
308 | - return array( 'name' => $user->display_name, 'email' => $user->user_email ); |
|
307 | + if ($user) { |
|
308 | + return array('name' => $user->display_name, 'email' => $user->user_email); |
|
309 | 309 | } |
310 | 310 | } |
311 | 311 | |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | * Returns String the sha1 hash |
320 | 320 | */ |
321 | 321 | public function sha() { |
322 | - $sha = get_post_meta( $this->id, '_wogh_sha', true ); |
|
322 | + $sha = get_post_meta($this->id, '_wogh_sha', true); |
|
323 | 323 | |
324 | 324 | // If we've done a full export and we have no sha |
325 | 325 | // then we should try a live check to see if it exists. |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | // } |
336 | 336 | |
337 | 337 | // if the sha still doesn't exist, then it's empty |
338 | - if ( ! $sha || is_wp_error( $sha ) ) { |
|
338 | + if ( ! $sha || is_wp_error($sha)) { |
|
339 | 339 | $sha = ''; |
340 | 340 | } |
341 | 341 | |
@@ -347,8 +347,8 @@ discard block |
||
347 | 347 | * |
348 | 348 | * @param string $sha |
349 | 349 | */ |
350 | - public function set_sha( $sha ) { |
|
351 | - update_post_meta( $this->id, '_wogh_sha', $sha ); |
|
350 | + public function set_sha($sha) { |
|
351 | + update_post_meta($this->id, '_wogh_sha', $sha); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | /** |
@@ -359,32 +359,32 @@ discard block |
||
359 | 359 | public function meta() { |
360 | 360 | $meta = array( |
361 | 361 | 'ID' => $this->id, |
362 | - 'post_title' => get_the_title( $this->post ), |
|
363 | - 'author' => ( $author = get_userdata( $this->post->post_author ) ) ? $author->display_name : '', |
|
362 | + 'post_title' => get_the_title($this->post), |
|
363 | + 'author' => ($author = get_userdata($this->post->post_author)) ? $author->display_name : '', |
|
364 | 364 | 'post_date' => $this->post->post_date, |
365 | 365 | 'post_excerpt' => $this->post->post_excerpt, |
366 | - 'layout' => get_post_type( $this->post ), |
|
367 | - 'permalink' => get_permalink( $this->post ), |
|
366 | + 'layout' => get_post_type($this->post), |
|
367 | + 'permalink' => get_permalink($this->post), |
|
368 | 368 | 'published' => 'publish' === $this->status() ? true : false, |
369 | - 'tags' => wp_get_post_tags( $this->id, array( 'fields' => 'names' ) ), |
|
370 | - 'categories' => wp_get_post_categories( $this->id, array( 'fields' => 'names' ) ) |
|
369 | + 'tags' => wp_get_post_tags($this->id, array('fields' => 'names')), |
|
370 | + 'categories' => wp_get_post_categories($this->id, array('fields' => 'names')) |
|
371 | 371 | ); |
372 | - if ( !empty($this->post->post_name) ) { |
|
372 | + if ( ! empty($this->post->post_name)) { |
|
373 | 373 | $meta['post_name'] = $this->post->post_name; |
374 | 374 | } |
375 | 375 | |
376 | 376 | //convert traditional post_meta values, hide hidden values, skip already populated values |
377 | - foreach ( get_post_custom( $this->id ) as $key => $value ) { |
|
377 | + foreach (get_post_custom($this->id) as $key => $value) { |
|
378 | 378 | |
379 | - if ( '_' === substr( $key, 0, 1 ) || isset( $meta[ $key ] ) ) { |
|
379 | + if ('_' === substr($key, 0, 1) || isset($meta[$key])) { |
|
380 | 380 | continue; |
381 | 381 | } |
382 | 382 | |
383 | - $meta[ $key ] = $value; |
|
383 | + $meta[$key] = $value; |
|
384 | 384 | |
385 | 385 | } |
386 | 386 | |
387 | - return apply_filters( 'wogh_post_meta', $meta, $this ); |
|
387 | + return apply_filters('wogh_post_meta', $meta, $this); |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | /** |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | * |
402 | 402 | * @param array $meta |
403 | 403 | */ |
404 | - public function set_meta( $meta ) { |
|
404 | + public function set_meta($meta) { |
|
405 | 405 | $this->meta = $meta; |
406 | 406 | } |
407 | 407 | |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | * |
431 | 431 | * @return $this |
432 | 432 | */ |
433 | - public function set_post( WP_Post $post ) { |
|
433 | + public function set_post(WP_Post $post) { |
|
434 | 434 | $this->post = $post; |
435 | 435 | $this->id = $post->ID; |
436 | 436 | |
@@ -449,6 +449,6 @@ discard block |
||
449 | 449 | $data->content = $this->github_content(); |
450 | 450 | $data->sha = $this->sha(); |
451 | 451 | |
452 | - return new Writing_On_GitHub_Blob( $data ); |
|
452 | + return new Writing_On_GitHub_Blob($data); |
|
453 | 453 | } |
454 | 454 | } |
@@ -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 | |
@@ -70,21 +70,21 @@ discard block |
||
70 | 70 | // return __( 'Payload processed', 'writing-on-github' ); |
71 | 71 | // } |
72 | 72 | |
73 | - public function payload( Writing_On_GitHub_Payload $payload ) { |
|
73 | + public function payload(Writing_On_GitHub_Payload $payload) { |
|
74 | 74 | |
75 | - $result = $this->app->api()->fetch()->compare( $payload->get_before_commit_id() ); |
|
75 | + $result = $this->app->api()->fetch()->compare($payload->get_before_commit_id()); |
|
76 | 76 | |
77 | - if ( is_wp_error( $result ) ) { |
|
77 | + if (is_wp_error($result)) { |
|
78 | 78 | return $result; |
79 | 79 | } |
80 | 80 | |
81 | - $result = $this->import_files( $result ); |
|
81 | + $result = $this->import_files($result); |
|
82 | 82 | |
83 | - if ( is_wp_error( $result ) ) { |
|
83 | + if (is_wp_error($result)) { |
|
84 | 84 | return $files; |
85 | 85 | } |
86 | 86 | |
87 | - return __( 'Payload processed', 'writing-on-github' ); |
|
87 | + return __('Payload processed', 'writing-on-github'); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -92,23 +92,23 @@ discard block |
||
92 | 92 | * @param array $files [Writing_On_GitHub_File_Info] |
93 | 93 | * @return string|WP_ERROR |
94 | 94 | */ |
95 | - protected function import_files( $files ) { |
|
95 | + protected function import_files($files) { |
|
96 | 96 | |
97 | - $error = false; |
|
97 | + $error = false; |
|
98 | 98 | $delete_ids = false; |
99 | 99 | |
100 | - $result = $this->compare( $files, $delete_ids ); |
|
100 | + $result = $this->compare($files, $delete_ids); |
|
101 | 101 | |
102 | - if ( is_wp_error( $result ) ) { |
|
102 | + if (is_wp_error($result)) { |
|
103 | 103 | return $result; |
104 | 104 | } |
105 | 105 | |
106 | - if ( $delete_ids ) { |
|
106 | + if ($delete_ids) { |
|
107 | 107 | foreach ($delete_ids as $id) { |
108 | - $result = $this->app->database()->delete_post( $id ); |
|
109 | - if ( is_wp_error( $result ) ) { |
|
110 | - if ( $error ) { |
|
111 | - $error->add( $result->get_error_code(), $result->get_error_message() ); |
|
108 | + $result = $this->app->database()->delete_post($id); |
|
109 | + if (is_wp_error($result)) { |
|
110 | + if ($error) { |
|
111 | + $error->add($result->get_error_code(), $result->get_error_message()); |
|
112 | 112 | } else { |
113 | 113 | $error = $result; |
114 | 114 | } |
@@ -127,21 +127,21 @@ discard block |
||
127 | 127 | public function master() { |
128 | 128 | $result = $this->app->api()->fetch()->tree_recursive(); |
129 | 129 | |
130 | - if ( is_wp_error( $result ) ) { |
|
130 | + if (is_wp_error($result)) { |
|
131 | 131 | return $result; |
132 | 132 | } |
133 | 133 | |
134 | - $result = $this->import_files( $result ); |
|
134 | + $result = $this->import_files($result); |
|
135 | 135 | |
136 | - if ( is_wp_error( $result ) ) { |
|
136 | + if (is_wp_error($result)) { |
|
137 | 137 | return $result; |
138 | 138 | } |
139 | 139 | |
140 | - return __( 'Payload processed', 'writing-on-github' ); |
|
140 | + return __('Payload processed', 'writing-on-github'); |
|
141 | 141 | } |
142 | 142 | |
143 | - protected function compare( $files, &$delete_ids ) { |
|
144 | - if ( is_wp_error( $files ) ) { |
|
143 | + protected function compare($files, &$delete_ids) { |
|
144 | + if (is_wp_error($files)) { |
|
145 | 145 | return $files; |
146 | 146 | } |
147 | 147 | |
@@ -150,38 +150,38 @@ discard block |
||
150 | 150 | |
151 | 151 | $idsmap = array(); |
152 | 152 | |
153 | - foreach ( $files as $file ) { |
|
154 | - if ( ! $this->importable_file( $file ) ) { |
|
153 | + foreach ($files as $file) { |
|
154 | + if ( ! $this->importable_file($file)) { |
|
155 | 155 | continue; |
156 | 156 | } |
157 | 157 | |
158 | 158 | $blob = $this->app->api()->fetch()->blob($file); |
159 | 159 | // network error ? |
160 | - if ( is_wp_error($blob) ) { |
|
160 | + if (is_wp_error($blob)) { |
|
161 | 161 | continue; |
162 | 162 | } |
163 | 163 | |
164 | - if ( ! $this->importable_blob($blob) ) { |
|
164 | + if ( ! $this->importable_blob($blob)) { |
|
165 | 165 | continue; |
166 | 166 | } |
167 | 167 | |
168 | - $post = $this->blob_to_post( $blob ); |
|
168 | + $post = $this->blob_to_post($blob); |
|
169 | 169 | |
170 | - if ( $file->status == 'removed' ) { |
|
171 | - if ( $blob->id() ) { |
|
170 | + if ($file->status == 'removed') { |
|
171 | + if ($blob->id()) { |
|
172 | 172 | $idsmap[$blob->id()] = true; |
173 | 173 | } |
174 | - } elseif ( $post != false ) { |
|
174 | + } elseif ($post != false) { |
|
175 | 175 | $posts[] = $post; |
176 | - if ( $post->is_new() ) { |
|
176 | + if ($post->is_new()) { |
|
177 | 177 | $new[] = $post; |
178 | 178 | } |
179 | 179 | } |
180 | 180 | } |
181 | 181 | |
182 | 182 | foreach ($posts as $post) { |
183 | - if ( $post->id() && isset( $idsmap[$post->id()] ) ) { |
|
184 | - unset( $idsmap[$post->id()] ); |
|
183 | + if ($post->id() && isset($idsmap[$post->id()])) { |
|
184 | + unset($idsmap[$post->id()]); |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | $delete_ids = array(); |
@@ -191,16 +191,16 @@ discard block |
||
191 | 191 | |
192 | 192 | // $this->app->database()->save_posts( $posts, $commit->author_email() ); |
193 | 193 | |
194 | - $result = $this->app->database()->save_posts( $posts ); |
|
194 | + $result = $this->app->database()->save_posts($posts); |
|
195 | 195 | |
196 | - if ( is_wp_error( $result ) ) { |
|
196 | + if (is_wp_error($result)) { |
|
197 | 197 | return $result; |
198 | 198 | } |
199 | 199 | |
200 | - if ( $new ) { |
|
201 | - $result = $this->app->export()->new_posts( $new ); |
|
200 | + if ($new) { |
|
201 | + $result = $this->app->export()->new_posts($new); |
|
202 | 202 | |
203 | - if ( is_wp_error( $result ) ) { |
|
203 | + if (is_wp_error($result)) { |
|
204 | 204 | return $result; |
205 | 205 | } |
206 | 206 | } |
@@ -215,11 +215,11 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @return bool |
217 | 217 | */ |
218 | - protected function importable_file( Writing_On_GitHub_File_Info $file ) { |
|
218 | + protected function importable_file(Writing_On_GitHub_File_Info $file) { |
|
219 | 219 | |
220 | 220 | // only _pages and _posts |
221 | - if ( strncasecmp($file->path, '_pages/', strlen('_pages/') ) != 0 && |
|
222 | - strncasecmp($file->path, '_posts/', strlen('_posts/') ) != 0 ) { |
|
221 | + if (strncasecmp($file->path, '_pages/', strlen('_pages/')) != 0 && |
|
222 | + strncasecmp($file->path, '_posts/', strlen('_posts/')) != 0) { |
|
223 | 223 | return false; |
224 | 224 | } |
225 | 225 | |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | * |
239 | 239 | * @return bool |
240 | 240 | */ |
241 | - protected function importable_blob( Writing_On_GitHub_Blob $blob ) { |
|
241 | + protected function importable_blob(Writing_On_GitHub_Blob $blob) { |
|
242 | 242 | // global $wpdb; |
243 | 243 | |
244 | 244 | // // Skip the repo's readme. |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | // return false; |
252 | 252 | // } |
253 | 253 | |
254 | - if ( ! $blob->has_frontmatter() ) { |
|
254 | + if ( ! $blob->has_frontmatter()) { |
|
255 | 255 | return false; |
256 | 256 | } |
257 | 257 | |
@@ -265,57 +265,57 @@ discard block |
||
265 | 265 | * |
266 | 266 | * @return Writing_On_GitHub_Post |
267 | 267 | */ |
268 | - protected function blob_to_post( Writing_On_GitHub_Blob $blob ) { |
|
269 | - $args = array( 'post_content' => $blob->content_import() ); |
|
268 | + protected function blob_to_post(Writing_On_GitHub_Blob $blob) { |
|
269 | + $args = array('post_content' => $blob->content_import()); |
|
270 | 270 | $meta = $blob->meta(); |
271 | 271 | |
272 | 272 | $id = false; |
273 | 273 | |
274 | - if ( $meta ) { |
|
275 | - if ( array_key_exists( 'layout', $meta ) ) { |
|
274 | + if ($meta) { |
|
275 | + if (array_key_exists('layout', $meta)) { |
|
276 | 276 | $args['post_type'] = $meta['layout']; |
277 | - unset( $meta['layout'] ); |
|
277 | + unset($meta['layout']); |
|
278 | 278 | } |
279 | 279 | |
280 | - if ( array_key_exists( 'published', $meta ) ) { |
|
280 | + if (array_key_exists('published', $meta)) { |
|
281 | 281 | $args['post_status'] = true === $meta['published'] ? 'publish' : 'draft'; |
282 | - unset( $meta['published'] ); |
|
282 | + unset($meta['published']); |
|
283 | 283 | } |
284 | 284 | |
285 | - if ( array_key_exists( 'post_title', $meta ) ) { |
|
285 | + if (array_key_exists('post_title', $meta)) { |
|
286 | 286 | $args['post_title'] = $meta['post_title']; |
287 | - unset( $meta['post_title'] ); |
|
287 | + unset($meta['post_title']); |
|
288 | 288 | } |
289 | 289 | |
290 | - if ( array_key_exists( 'post_name', $meta ) ) { |
|
290 | + if (array_key_exists('post_name', $meta)) { |
|
291 | 291 | $args['post_name'] = $meta['post_name']; |
292 | - unset( $meta['post_name'] ); |
|
292 | + unset($meta['post_name']); |
|
293 | 293 | } |
294 | 294 | |
295 | - if ( array_key_exists( 'ID', $meta ) ) { |
|
295 | + if (array_key_exists('ID', $meta)) { |
|
296 | 296 | $id = $args['ID'] = $meta['ID']; |
297 | 297 | $blob->set_id($id); |
298 | - unset( $meta['ID'] ); |
|
298 | + unset($meta['ID']); |
|
299 | 299 | } |
300 | 300 | } |
301 | 301 | |
302 | 302 | $meta['_wogh_sha'] = $blob->sha(); |
303 | 303 | |
304 | - if ( $id ) { |
|
305 | - $old_sha = get_post_meta( $id, '_wogh_sha', true ); |
|
306 | - $old_github_path = get_post_meta( $id, '_wogh_github_path', true ); |
|
304 | + if ($id) { |
|
305 | + $old_sha = get_post_meta($id, '_wogh_sha', true); |
|
306 | + $old_github_path = get_post_meta($id, '_wogh_github_path', true); |
|
307 | 307 | |
308 | 308 | // dont save post when has same sha |
309 | - if ( $old_sha && $old_sha == $meta['_wogh_sha'] && |
|
310 | - $old_github_path && $old_github_path == $blob->path() ) { |
|
309 | + if ($old_sha && $old_sha == $meta['_wogh_sha'] && |
|
310 | + $old_github_path && $old_github_path == $blob->path()) { |
|
311 | 311 | return false; |
312 | 312 | } |
313 | 313 | } |
314 | 314 | |
315 | - $post = new Writing_On_GitHub_Post( $args, $this->app->api() ); |
|
316 | - $post->set_old_github_path( $blob->path() ); |
|
317 | - $post->set_meta( $meta ); |
|
318 | - $blob->set_id( $post->id() ); |
|
315 | + $post = new Writing_On_GitHub_Post($args, $this->app->api()); |
|
316 | + $post->set_old_github_path($blob->path()); |
|
317 | + $post->set_meta($meta); |
|
318 | + $blob->set_id($post->id()); |
|
319 | 319 | |
320 | 320 | return $post; |
321 | 321 | } |
@@ -21,21 +21,21 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @var array |
23 | 23 | */ |
24 | - protected $whitelisted_post_types = array( 'post', 'page' ); |
|
24 | + protected $whitelisted_post_types = array('post', 'page'); |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Currently whitelisted post statuses. |
28 | 28 | * |
29 | 29 | * @var array |
30 | 30 | */ |
31 | - protected $whitelisted_post_statuses = array( 'publish' ); |
|
31 | + protected $whitelisted_post_statuses = array('publish'); |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * Instantiates a new Database object. |
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,31 +45,31 @@ discard block |
||
45 | 45 | * @return Writing_On_GitHub_Post[]|WP_Error |
46 | 46 | */ |
47 | 47 | public function fetch_all_supported() { |
48 | - $args = array( |
|
48 | + $args = array( |
|
49 | 49 | 'post_type' => $this->get_whitelisted_post_types(), |
50 | 50 | 'post_status' => $this->get_whitelisted_post_statuses(), |
51 | 51 | 'nopaging' => true, |
52 | 52 | 'fields' => 'ids', |
53 | 53 | ); |
54 | 54 | |
55 | - $query = new WP_Query( apply_filters( 'wogh_pre_fetch_all_supported', $args ) ); |
|
55 | + $query = new WP_Query(apply_filters('wogh_pre_fetch_all_supported', $args)); |
|
56 | 56 | |
57 | 57 | $post_ids = $query->get_posts(); |
58 | 58 | |
59 | - if ( ! $post_ids ) { |
|
59 | + if ( ! $post_ids) { |
|
60 | 60 | return new WP_Error( |
61 | 61 | 'no_results', |
62 | - __( 'Querying for supported posts returned no results.', 'writing-on-github' ) |
|
62 | + __('Querying for supported posts returned no results.', 'writing-on-github') |
|
63 | 63 | ); |
64 | 64 | } |
65 | 65 | |
66 | 66 | $results = array(); |
67 | - foreach ( $post_ids as $post_id ) { |
|
67 | + foreach ($post_ids as $post_id) { |
|
68 | 68 | // Do not export posts that have already been exported |
69 | - if ( ! get_post_meta( $post_id, '_wogh_sha', true ) || |
|
70 | - ! get_post_meta( $post_id, '_wogh_github_path', true) ) { |
|
69 | + if ( ! get_post_meta($post_id, '_wogh_sha', true) || |
|
70 | + ! get_post_meta($post_id, '_wogh_github_path', true)) { |
|
71 | 71 | |
72 | - $results[] = new Writing_On_GitHub_Post( $post_id, $this->app->api() ); |
|
72 | + $results[] = new Writing_On_GitHub_Post($post_id, $this->app->api()); |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 | |
@@ -83,10 +83,10 @@ discard block |
||
83 | 83 | * |
84 | 84 | * @return WP_Error|Writing_On_GitHub_Post |
85 | 85 | */ |
86 | - public function fetch_by_id( $post_id ) { |
|
87 | - $post = new Writing_On_GitHub_Post( $post_id, $this->app->api() ); |
|
86 | + public function fetch_by_id($post_id) { |
|
87 | + $post = new Writing_On_GitHub_Post($post_id, $this->app->api()); |
|
88 | 88 | |
89 | - if ( ! $this->is_post_supported( $post ) ) { |
|
89 | + if ( ! $this->is_post_supported($post)) { |
|
90 | 90 | return new WP_Error( |
91 | 91 | 'unsupported_post', |
92 | 92 | sprintf( |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * |
112 | 112 | * @return string|WP_Error |
113 | 113 | */ |
114 | - public function save_posts( array $posts ) { |
|
114 | + public function save_posts(array $posts) { |
|
115 | 115 | |
116 | 116 | /** |
117 | 117 | * Whether an error has occurred. |
@@ -120,20 +120,19 @@ discard block |
||
120 | 120 | */ |
121 | 121 | $error = false; |
122 | 122 | |
123 | - foreach ( $posts as $post ) { |
|
124 | - $args = apply_filters( 'wogh_pre_import_args', $this->post_args( $post ), $post ); |
|
123 | + foreach ($posts as $post) { |
|
124 | + $args = apply_filters('wogh_pre_import_args', $this->post_args($post), $post); |
|
125 | 125 | |
126 | 126 | remove_filter('content_save_pre', 'wp_filter_post_kses'); |
127 | 127 | $post_id = $post->is_new() ? |
128 | - wp_insert_post( $args, true ) : |
|
129 | - wp_update_post( $args, true ); |
|
128 | + wp_insert_post($args, true) : wp_update_post($args, true); |
|
130 | 129 | add_filter('content_save_pre', 'wp_filter_post_kses'); |
131 | 130 | |
132 | - if ( is_wp_error( $post_id ) ) { |
|
133 | - if ( ! $error ) { |
|
131 | + if (is_wp_error($post_id)) { |
|
132 | + if ( ! $error) { |
|
134 | 133 | $error = $post_id; |
135 | 134 | } else { |
136 | - $error->add( $post_id->get_error_code(), $post_id->get_error_message() ); |
|
135 | + $error->add($post_id->get_error_code(), $post_id->get_error_message()); |
|
137 | 136 | } |
138 | 137 | |
139 | 138 | // Abort saving if updating the post fails. |
@@ -142,53 +141,53 @@ discard block |
||
142 | 141 | |
143 | 142 | // $this->set_revision_author( $post_id, $user_id ); |
144 | 143 | |
145 | - if ( $post->is_new() ) { |
|
144 | + if ($post->is_new()) { |
|
146 | 145 | $author = false; |
147 | 146 | $meta = $post->get_meta(); |
148 | - if ( ! empty( $meta ) && ! empty( $meta['author'] ) ) { |
|
147 | + if ( ! empty($meta) && ! empty($meta['author'])) { |
|
149 | 148 | $author = $meta['author']; |
150 | 149 | } |
151 | - $user = $this->fetch_commit_user( $author ); |
|
152 | - $user_id = ! is_wp_error( $user ) ? $user->ID : 0; |
|
153 | - $this->set_post_author( $post_id, $user_id ); |
|
150 | + $user = $this->fetch_commit_user($author); |
|
151 | + $user_id = ! is_wp_error($user) ? $user->ID : 0; |
|
152 | + $this->set_post_author($post_id, $user_id); |
|
154 | 153 | } |
155 | 154 | |
156 | - $post->set_post( get_post( $post_id ) ); |
|
155 | + $post->set_post(get_post($post_id)); |
|
157 | 156 | |
158 | - $meta = apply_filters( 'wogh_pre_import_meta', $post->get_meta(), $post ); |
|
157 | + $meta = apply_filters('wogh_pre_import_meta', $post->get_meta(), $post); |
|
159 | 158 | |
160 | - unset( $meta['tags'] ); |
|
161 | - unset( $meta['categories'] ); |
|
162 | - unset( $meta['author'] ); |
|
163 | - unset( $meta['post_date'] ); |
|
164 | - unset( $meta['post_excerpt'] ); |
|
165 | - unset( $meta['permalink'] ); |
|
159 | + unset($meta['tags']); |
|
160 | + unset($meta['categories']); |
|
161 | + unset($meta['author']); |
|
162 | + unset($meta['post_date']); |
|
163 | + unset($meta['post_excerpt']); |
|
164 | + unset($meta['permalink']); |
|
166 | 165 | |
167 | - foreach ( $meta as $key => $value ) { |
|
168 | - update_post_meta( $post_id, $key, $value ); |
|
166 | + foreach ($meta as $key => $value) { |
|
167 | + update_post_meta($post_id, $key, $value); |
|
169 | 168 | } |
170 | 169 | } |
171 | 170 | |
172 | - if ( $error ) { |
|
171 | + if ($error) { |
|
173 | 172 | return $error; |
174 | 173 | } |
175 | 174 | |
176 | - return __( 'Successfully saved posts.', 'writing-on-github' ); |
|
175 | + return __('Successfully saved posts.', 'writing-on-github'); |
|
177 | 176 | } |
178 | 177 | |
179 | - protected function post_args( $post ) { |
|
178 | + protected function post_args($post) { |
|
180 | 179 | $args = $post->get_args(); |
181 | 180 | $meta = $post->get_meta(); |
182 | 181 | |
183 | 182 | // update tags |
184 | - if ( isset( $meta['tags'] ) && $meta['tags'] ) { |
|
183 | + if (isset($meta['tags']) && $meta['tags']) { |
|
185 | 184 | $args['tags_input'] = $meta['tags']; |
186 | 185 | } |
187 | 186 | |
188 | 187 | // update categories |
189 | - if ( isset( $meta['categories'] ) && $meta['categories'] ) { |
|
188 | + if (isset($meta['categories']) && $meta['categories']) { |
|
190 | 189 | $categories = $meta['categories']; |
191 | - if (!is_array($categories)) { |
|
190 | + if ( ! is_array($categories)) { |
|
192 | 191 | $categories = array($categories); |
193 | 192 | } |
194 | 193 | $terms = get_terms(array( |
@@ -204,7 +203,7 @@ discard block |
||
204 | 203 | } |
205 | 204 | |
206 | 205 | $ids = array(); |
207 | - if (!empty($terms)) { |
|
206 | + if ( ! empty($terms)) { |
|
208 | 207 | foreach ($terms as $id => $name) { |
209 | 208 | $ids[] = $id; |
210 | 209 | unset($map[$name]); |
@@ -212,7 +211,7 @@ discard block |
||
212 | 211 | } |
213 | 212 | |
214 | 213 | // create new terms |
215 | - if (!empty($map)) { |
|
214 | + if ( ! empty($map)) { |
|
216 | 215 | foreach ($map as $name => $value) { |
217 | 216 | $term = wp_insert_term($name, 'category', array('parent' => 0)); |
218 | 217 | // array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id); |
@@ -233,77 +232,77 @@ discard block |
||
233 | 232 | * |
234 | 233 | * @return string|WP_Error |
235 | 234 | */ |
236 | - public function delete_post_by_path( $path ) { |
|
237 | - $query = new WP_Query( array( |
|
235 | + public function delete_post_by_path($path) { |
|
236 | + $query = new WP_Query(array( |
|
238 | 237 | 'meta_key' => '_wogh_github_path', |
239 | 238 | 'meta_value' => $path, |
240 | 239 | 'meta_compare' => '=', |
241 | 240 | 'posts_per_page' => 1, |
242 | 241 | 'fields' => 'ids', |
243 | - ) ); |
|
242 | + )); |
|
244 | 243 | |
245 | 244 | $post_id = $query->get_posts(); |
246 | - $post_id = array_pop( $post_id ); |
|
245 | + $post_id = array_pop($post_id); |
|
247 | 246 | |
248 | - if ( ! $post_id ) { |
|
249 | - $parts = explode( '/', $path ); |
|
250 | - $filename = array_pop( $parts ); |
|
251 | - $directory = $parts ? array_shift( $parts ) : ''; |
|
247 | + if ( ! $post_id) { |
|
248 | + $parts = explode('/', $path); |
|
249 | + $filename = array_pop($parts); |
|
250 | + $directory = $parts ? array_shift($parts) : ''; |
|
252 | 251 | |
253 | - if ( false !== strpos( $directory, 'post' ) ) { |
|
254 | - preg_match( '/([0-9]{4})-([0-9]{2})-([0-9]{2})-(.*)\.md/', $filename, $matches ); |
|
252 | + if (false !== strpos($directory, 'post')) { |
|
253 | + preg_match('/([0-9]{4})-([0-9]{2})-([0-9]{2})-(.*)\.md/', $filename, $matches); |
|
255 | 254 | $title = $matches[4]; |
256 | 255 | |
257 | - $query = new WP_Query( array( |
|
256 | + $query = new WP_Query(array( |
|
258 | 257 | 'name' => $title, |
259 | 258 | 'posts_per_page' => 1, |
260 | 259 | 'post_type' => $this->get_whitelisted_post_types(), |
261 | 260 | 'fields' => 'ids', |
262 | - ) ); |
|
261 | + )); |
|
263 | 262 | |
264 | 263 | $post_id = $query->get_posts(); |
265 | - $post_id = array_pop( $post_id ); |
|
264 | + $post_id = array_pop($post_id); |
|
266 | 265 | } |
267 | 266 | |
268 | - if ( ! $post_id ) { |
|
269 | - preg_match( '/(.*)\.md/', $filename, $matches ); |
|
267 | + if ( ! $post_id) { |
|
268 | + preg_match('/(.*)\.md/', $filename, $matches); |
|
270 | 269 | $title = $matches[1]; |
271 | 270 | |
272 | - $query = new WP_Query( array( |
|
271 | + $query = new WP_Query(array( |
|
273 | 272 | 'name' => $title, |
274 | 273 | 'posts_per_page' => 1, |
275 | 274 | 'post_type' => $this->get_whitelisted_post_types(), |
276 | 275 | 'fields' => 'ids', |
277 | - ) ); |
|
276 | + )); |
|
278 | 277 | |
279 | 278 | $post_id = $query->get_posts(); |
280 | - $post_id = array_pop( $post_id ); |
|
279 | + $post_id = array_pop($post_id); |
|
281 | 280 | } |
282 | 281 | } |
283 | 282 | |
284 | - if ( ! $post_id ) { |
|
283 | + if ( ! $post_id) { |
|
285 | 284 | return new WP_Error( |
286 | 285 | 'path_not_found', |
287 | 286 | sprintf( |
288 | - __( 'Post not found for path %s.', 'writing-on-github' ), |
|
287 | + __('Post not found for path %s.', 'writing-on-github'), |
|
289 | 288 | $path |
290 | 289 | ) |
291 | 290 | ); |
292 | 291 | } |
293 | 292 | |
294 | - $result = wp_delete_post( $post_id ); |
|
293 | + $result = wp_delete_post($post_id); |
|
295 | 294 | |
296 | 295 | // If deleting fails... |
297 | - if ( false === $result ) { |
|
298 | - $post = get_post( $post_id ); |
|
296 | + if (false === $result) { |
|
297 | + $post = get_post($post_id); |
|
299 | 298 | |
300 | 299 | // ...and the post both exists and isn't in the trash... |
301 | - if ( $post && 'trash' !== $post->post_status ) { |
|
300 | + if ($post && 'trash' !== $post->post_status) { |
|
302 | 301 | // ... then something went wrong. |
303 | 302 | return new WP_Error( |
304 | 303 | 'db_error', |
305 | 304 | sprintf( |
306 | - __( 'Failed to delete post ID %d.', 'writing-on-github' ), |
|
305 | + __('Failed to delete post ID %d.', 'writing-on-github'), |
|
307 | 306 | $post_id |
308 | 307 | ) |
309 | 308 | ); |
@@ -311,25 +310,25 @@ discard block |
||
311 | 310 | } |
312 | 311 | |
313 | 312 | return sprintf( |
314 | - __( 'Successfully deleted post ID %d.', 'writing-on-github' ), |
|
313 | + __('Successfully deleted post ID %d.', 'writing-on-github'), |
|
315 | 314 | $post_id |
316 | 315 | ); |
317 | 316 | } |
318 | 317 | |
319 | - public function delete_post( $post_id ) { |
|
320 | - $result = wp_delete_post( $post_id ); |
|
318 | + public function delete_post($post_id) { |
|
319 | + $result = wp_delete_post($post_id); |
|
321 | 320 | |
322 | 321 | // If deleting fails... |
323 | - if ( false === $result ) { |
|
324 | - $post = get_post( $post_id ); |
|
322 | + if (false === $result) { |
|
323 | + $post = get_post($post_id); |
|
325 | 324 | |
326 | 325 | // ...and the post both exists and isn't in the trash... |
327 | - if ( $post && 'trash' !== $post->post_status ) { |
|
326 | + if ($post && 'trash' !== $post->post_status) { |
|
328 | 327 | // ... then something went wrong. |
329 | 328 | return new WP_Error( |
330 | 329 | 'db_error', |
331 | 330 | sprintf( |
332 | - __( 'Failed to delete post ID %d.', 'writing-on-github' ), |
|
331 | + __('Failed to delete post ID %d.', 'writing-on-github'), |
|
333 | 332 | $post_id |
334 | 333 | ) |
335 | 334 | ); |
@@ -337,7 +336,7 @@ discard block |
||
337 | 336 | } |
338 | 337 | |
339 | 338 | return sprintf( |
340 | - __( 'Successfully deleted post ID %d.', 'writing-on-github' ), |
|
339 | + __('Successfully deleted post ID %d.', 'writing-on-github'), |
|
341 | 340 | $post_id |
342 | 341 | ); |
343 | 342 | } |
@@ -348,7 +347,7 @@ discard block |
||
348 | 347 | * @return array |
349 | 348 | */ |
350 | 349 | protected function get_whitelisted_post_types() { |
351 | - return apply_filters( 'wogh_whitelisted_post_types', $this->whitelisted_post_types ); |
|
350 | + return apply_filters('wogh_whitelisted_post_types', $this->whitelisted_post_types); |
|
352 | 351 | } |
353 | 352 | |
354 | 353 | /** |
@@ -357,7 +356,7 @@ discard block |
||
357 | 356 | * @return array |
358 | 357 | */ |
359 | 358 | protected function get_whitelisted_post_statuses() { |
360 | - return apply_filters( 'wogh_whitelisted_post_statuses', $this->whitelisted_post_statuses ); |
|
359 | + return apply_filters('wogh_whitelisted_post_statuses', $this->whitelisted_post_statuses); |
|
361 | 360 | } |
362 | 361 | |
363 | 362 | /** |
@@ -367,12 +366,12 @@ discard block |
||
367 | 366 | * |
368 | 367 | * @return string Whitelist formatted for query |
369 | 368 | */ |
370 | - protected function format_for_query( $whitelist ) { |
|
371 | - foreach ( $whitelist as $key => $value ) { |
|
372 | - $whitelist[ $key ] = "'$value'"; |
|
369 | + protected function format_for_query($whitelist) { |
|
370 | + foreach ($whitelist as $key => $value) { |
|
371 | + $whitelist[$key] = "'$value'"; |
|
373 | 372 | } |
374 | 373 | |
375 | - return implode( ', ', $whitelist ); |
|
374 | + return implode(', ', $whitelist); |
|
376 | 375 | } |
377 | 376 | |
378 | 377 | /** |
@@ -383,25 +382,25 @@ discard block |
||
383 | 382 | * |
384 | 383 | * @return boolean True if supported, false if not. |
385 | 384 | */ |
386 | - protected function is_post_supported( Writing_On_GitHub_Post $post ) { |
|
387 | - if ( wp_is_post_revision( $post->id ) ) { |
|
385 | + protected function is_post_supported(Writing_On_GitHub_Post $post) { |
|
386 | + if (wp_is_post_revision($post->id)) { |
|
388 | 387 | return false; |
389 | 388 | } |
390 | 389 | |
391 | 390 | // We need to allow trashed posts to be queried, but they are not whitelisted for export. |
392 | - if ( ! in_array( $post->status(), $this->get_whitelisted_post_statuses() ) && 'trash' !== $post->status() ) { |
|
391 | + if ( ! in_array($post->status(), $this->get_whitelisted_post_statuses()) && 'trash' !== $post->status()) { |
|
393 | 392 | return false; |
394 | 393 | } |
395 | 394 | |
396 | - if ( ! in_array( $post->type(), $this->get_whitelisted_post_types() ) ) { |
|
395 | + if ( ! in_array($post->type(), $this->get_whitelisted_post_types())) { |
|
397 | 396 | return false; |
398 | 397 | } |
399 | 398 | |
400 | - if ( $post->has_password() ) { |
|
399 | + if ($post->has_password()) { |
|
401 | 400 | return false; |
402 | 401 | } |
403 | 402 | |
404 | - return apply_filters( 'wogh_is_post_supported', true, $post ); |
|
403 | + return apply_filters('wogh_is_post_supported', true, $post); |
|
405 | 404 | } |
406 | 405 | |
407 | 406 | /** |
@@ -414,35 +413,35 @@ discard block |
||
414 | 413 | * |
415 | 414 | * @return WP_Error|WP_User |
416 | 415 | */ |
417 | - protected function fetch_commit_user( $display_name ) { |
|
416 | + protected function fetch_commit_user($display_name) { |
|
418 | 417 | // If we can't find a user and a default hasn't been set, |
419 | 418 | // we're just going to set the revision author to 0. |
420 | 419 | $user = false; |
421 | 420 | |
422 | - if ( ! empty( $display_name ) ) { |
|
423 | - $search_string = esc_attr( $display_name ); |
|
424 | - $query = new WP_User_Query( array( |
|
421 | + if ( ! empty($display_name)) { |
|
422 | + $search_string = esc_attr($display_name); |
|
423 | + $query = new WP_User_Query(array( |
|
425 | 424 | 'search' => "{$search_string}", |
426 | 425 | 'search_columns' => array( |
427 | 426 | 'display_name', |
428 | 427 | 'user_nicename', |
429 | 428 | 'user_login', |
430 | 429 | ) |
431 | - ) ); |
|
430 | + )); |
|
432 | 431 | $users = $query->get_results(); |
433 | 432 | $user = empty($users) ? false : $users[0]; |
434 | 433 | } |
435 | 434 | |
436 | - if ( ! $user ) { |
|
435 | + if ( ! $user) { |
|
437 | 436 | // Use the default user. |
438 | - $user = get_user_by( 'id', (int) get_option( 'wogh_default_user' ) ); |
|
437 | + $user = get_user_by('id', (int) get_option('wogh_default_user')); |
|
439 | 438 | } |
440 | 439 | |
441 | - if ( ! $user ) { |
|
440 | + if ( ! $user) { |
|
442 | 441 | return new WP_Error( |
443 | 442 | 'user_not_found', |
444 | 443 | sprintf( |
445 | - __( 'Commit user not found for email %s', 'writing-on-github' ), |
|
444 | + __('Commit user not found for email %s', 'writing-on-github'), |
|
446 | 445 | |
447 | 446 | ) |
448 | 447 | ); |
@@ -460,28 +459,28 @@ discard block |
||
460 | 459 | * |
461 | 460 | * @return string|WP_Error |
462 | 461 | */ |
463 | - protected function set_revision_author( $post_id, $user_id ) { |
|
464 | - $revision = wp_get_post_revisions( $post_id ); |
|
462 | + protected function set_revision_author($post_id, $user_id) { |
|
463 | + $revision = wp_get_post_revisions($post_id); |
|
465 | 464 | |
466 | - if ( ! $revision ) { |
|
467 | - $new_revision = wp_save_post_revision( $post_id ); |
|
465 | + if ( ! $revision) { |
|
466 | + $new_revision = wp_save_post_revision($post_id); |
|
468 | 467 | |
469 | - if ( ! $new_revision || is_wp_error( $new_revision ) ) { |
|
470 | - return new WP_Error( 'db_error', 'There was a problem saving a new revision.' ); |
|
468 | + if ( ! $new_revision || is_wp_error($new_revision)) { |
|
469 | + return new WP_Error('db_error', 'There was a problem saving a new revision.'); |
|
471 | 470 | } |
472 | 471 | |
473 | 472 | // `wp_save_post_revision` returns the ID, whereas `get_post_revision` returns the whole object |
474 | 473 | // in order to be consistent, let's make sure we have the whole object before continuing. |
475 | - $revision = get_post( $new_revision ); |
|
474 | + $revision = get_post($new_revision); |
|
476 | 475 | |
477 | - if ( ! $revision ) { |
|
478 | - return new WP_Error( 'db_error', 'There was a problem retrieving the newly recreated revision.' ); |
|
476 | + if ( ! $revision) { |
|
477 | + return new WP_Error('db_error', 'There was a problem retrieving the newly recreated revision.'); |
|
479 | 478 | } |
480 | 479 | } else { |
481 | - $revision = array_shift( $revision ); |
|
480 | + $revision = array_shift($revision); |
|
482 | 481 | } |
483 | 482 | |
484 | - return $this->set_post_author( $revision->ID, $user_id ); |
|
483 | + return $this->set_post_author($revision->ID, $user_id); |
|
485 | 484 | } |
486 | 485 | |
487 | 486 | /** |
@@ -494,7 +493,7 @@ discard block |
||
494 | 493 | * |
495 | 494 | * @return string|WP_Error |
496 | 495 | */ |
497 | - protected function set_post_author( $post_id, $user_id ) { |
|
496 | + protected function set_post_author($post_id, $user_id) { |
|
498 | 497 | global $wpdb; |
499 | 498 | |
500 | 499 | $result = $wpdb->update( |
@@ -505,25 +504,25 @@ discard block |
||
505 | 504 | array( |
506 | 505 | 'ID' => (int) $post_id, |
507 | 506 | ), |
508 | - array( '%d' ), |
|
509 | - array( '%d' ) |
|
507 | + array('%d'), |
|
508 | + array('%d') |
|
510 | 509 | ); |
511 | 510 | |
512 | - if ( false === $result ) { |
|
513 | - return new WP_Error( 'db_error', $wpdb->last_error ); |
|
511 | + if (false === $result) { |
|
512 | + return new WP_Error('db_error', $wpdb->last_error); |
|
514 | 513 | } |
515 | 514 | |
516 | - if ( 0 === $result ) { |
|
515 | + if (0 === $result) { |
|
517 | 516 | return sprintf( |
518 | - __( 'No change for post ID %d.', 'writing-on-github' ), |
|
517 | + __('No change for post ID %d.', 'writing-on-github'), |
|
519 | 518 | $post_id |
520 | 519 | ); |
521 | 520 | } |
522 | 521 | |
523 | - clean_post_cache( $post_id ); |
|
522 | + clean_post_cache($post_id); |
|
524 | 523 | |
525 | 524 | return sprintf( |
526 | - __( 'Successfully updated post ID %d.', 'writing-on-github' ), |
|
525 | + __('Successfully updated post ID %d.', 'writing-on-github'), |
|
527 | 526 | $post_id |
528 | 527 | ); |
529 | 528 | } |
@@ -536,7 +535,7 @@ discard block |
||
536 | 535 | * |
537 | 536 | * @return bool|int |
538 | 537 | */ |
539 | - public function set_post_sha( $post, $sha ) { |
|
540 | - return update_post_meta( $post->id, '_wogh_sha', $sha ); |
|
538 | + public function set_post_sha($post, $sha) { |
|
539 | + return update_post_meta($post->id, '_wogh_sha', $sha); |
|
541 | 540 | } |
542 | 541 | } |
@@ -16,13 +16,13 @@ discard block |
||
16 | 16 | * |
17 | 17 | * @return array[Writing_On_GitHub_File_Info]|WP_Error |
18 | 18 | */ |
19 | - public function compare( $sha ) { |
|
19 | + public function compare($sha) { |
|
20 | 20 | // https://api.github.com/repos/litefeel/testwpsync/compare/861f87e8851b8debb78db548269d29f8da4d94ac...master |
21 | 21 | $endpoint = $this->compare_endpoint(); |
22 | 22 | $branch = $this->branch(); |
23 | - $data = $this->call( 'GET', "$endpoint/$sha...$branch" ); |
|
23 | + $data = $this->call('GET', "$endpoint/$sha...$branch"); |
|
24 | 24 | |
25 | - if ( is_wp_error( $data ) ) { |
|
25 | + if (is_wp_error($data)) { |
|
26 | 26 | return $data; |
27 | 27 | } |
28 | 28 | |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @return mixed |
46 | 46 | */ |
47 | - public function remote_contents( $post ) { |
|
48 | - return $this->call( 'GET', $this->content_endpoint( $post->github_path() ) ); |
|
47 | + public function remote_contents($post) { |
|
48 | + return $this->call('GET', $this->content_endpoint($post->github_path())); |
|
49 | 49 | } |
50 | 50 | |
51 | - public function exists( $path ) { |
|
52 | - $result = $this->call( 'GET', $this->content_endpoint( $path ) ); |
|
53 | - if ( is_wp_error( $result ) ) { |
|
51 | + public function exists($path) { |
|
52 | + $result = $this->call('GET', $this->content_endpoint($path)); |
|
53 | + if (is_wp_error($result)) { |
|
54 | 54 | return false; |
55 | 55 | } |
56 | 56 | return true; |
@@ -63,27 +63,27 @@ discard block |
||
63 | 63 | * |
64 | 64 | * @return Writing_On_GitHub_Tree|WP_Error |
65 | 65 | */ |
66 | - public function tree_recursive( $sha = '_default' ) { |
|
66 | + public function tree_recursive($sha = '_default') { |
|
67 | 67 | |
68 | - if ( '_default' === $sha ) { |
|
68 | + if ('_default' === $sha) { |
|
69 | 69 | $sha = $this->branch(); |
70 | 70 | } |
71 | 71 | |
72 | - $data = $this->call( 'GET', $this->tree_endpoint() . '/' . $sha . '?recursive=1' ); |
|
72 | + $data = $this->call('GET', $this->tree_endpoint() . '/' . $sha . '?recursive=1'); |
|
73 | 73 | |
74 | - if ( is_wp_error( $data ) ) { |
|
74 | + if (is_wp_error($data)) { |
|
75 | 75 | return $data; |
76 | 76 | } |
77 | 77 | |
78 | 78 | $files = array(); |
79 | 79 | |
80 | - foreach ( $data->tree as $index => $thing ) { |
|
80 | + foreach ($data->tree as $index => $thing) { |
|
81 | 81 | // We need to remove the trees because |
82 | 82 | // the recursive tree includes both |
83 | 83 | // the subtrees as well the subtrees' blobs. |
84 | - if ( 'blob' === $thing->type ) { |
|
84 | + if ('blob' === $thing->type) { |
|
85 | 85 | $thing->status = ''; |
86 | - $files[] = new Writing_On_GitHub_File_Info( $thing ); |
|
86 | + $files[] = new Writing_On_GitHub_File_Info($thing); |
|
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
@@ -97,20 +97,20 @@ discard block |
||
97 | 97 | * |
98 | 98 | * @return Writing_On_GitHub_Blob|WP_Error |
99 | 99 | */ |
100 | - public function blob( $blob ) { |
|
101 | - if ( $cache = $this->app->cache()->fetch_blob( $blob->sha ) ) { |
|
100 | + public function blob($blob) { |
|
101 | + if ($cache = $this->app->cache()->fetch_blob($blob->sha)) { |
|
102 | 102 | return $cache; |
103 | 103 | } |
104 | 104 | |
105 | - $data = $this->call( 'GET', $this->blob_endpoint() . '/' . $blob->sha ); |
|
105 | + $data = $this->call('GET', $this->blob_endpoint() . '/' . $blob->sha); |
|
106 | 106 | |
107 | - if ( is_wp_error( $data ) ) { |
|
107 | + if (is_wp_error($data)) { |
|
108 | 108 | return $data; |
109 | 109 | } |
110 | 110 | |
111 | 111 | $data->path = $blob->path; |
112 | - $obj = new Writing_On_GitHub_Blob( $data ); |
|
112 | + $obj = new Writing_On_GitHub_Blob($data); |
|
113 | 113 | |
114 | - return $this->app->cache()->set_blob( $obj->sha(), $obj ); |
|
114 | + return $this->app->cache()->set_blob($obj->sha(), $obj); |
|
115 | 115 | } |
116 | 116 | } |
@@ -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,57 +34,57 @@ 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 ) ) { |
|
84 | - return $this->app->response()->error( $result ); |
|
83 | + if (is_wp_error($result)) { |
|
84 | + return $this->app->response()->error($result); |
|
85 | 85 | } |
86 | 86 | |
87 | - return $this->app->response()->success( $result ); |
|
87 | + return $this->app->response()->success($result); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -92,35 +92,35 @@ discard block |
||
92 | 92 | * |
93 | 93 | * @return boolean |
94 | 94 | */ |
95 | - public function import_master( $user_id ) { |
|
96 | - if ( ! $this->app->semaphore()->is_open() ) { |
|
97 | - return $this->app->response()->error( new WP_Error( |
|
95 | + public function import_master($user_id) { |
|
96 | + if ( ! $this->app->semaphore()->is_open()) { |
|
97 | + return $this->app->response()->error(new WP_Error( |
|
98 | 98 | 'semaphore_locked', |
99 | - sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::import_master()' ) |
|
100 | - ) ); |
|
99 | + sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::import_master()') |
|
100 | + )); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | $this->app->semaphore()->lock(); |
104 | - remove_action( 'save_post', array( $this, 'export_post' ) ); |
|
105 | - remove_action( 'save_post', array( $this, 'delete_post' ) ); |
|
104 | + remove_action('save_post', array($this, 'export_post')); |
|
105 | + remove_action('save_post', array($this, 'delete_post')); |
|
106 | 106 | |
107 | - if ( $user_id ) { |
|
108 | - wp_set_current_user( $user_id ); |
|
107 | + if ($user_id) { |
|
108 | + wp_set_current_user($user_id); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | $result = $this->app->import()->master(); |
112 | 112 | |
113 | 113 | $this->app->semaphore()->unlock(); |
114 | 114 | |
115 | - if ( is_wp_error( $result ) ) { |
|
116 | - update_option( '_wogh_import_error', $result->get_error_message() ); |
|
115 | + if (is_wp_error($result)) { |
|
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 | /** |
@@ -128,33 +128,33 @@ discard block |
||
128 | 128 | * |
129 | 129 | * @return boolean |
130 | 130 | */ |
131 | - public function export_all( $user_id ) { |
|
132 | - if ( ! $this->app->semaphore()->is_open() ) { |
|
133 | - return $this->app->response()->error( new WP_Error( |
|
131 | + public function export_all($user_id) { |
|
132 | + if ( ! $this->app->semaphore()->is_open()) { |
|
133 | + return $this->app->response()->error(new WP_Error( |
|
134 | 134 | 'semaphore_locked', |
135 | - sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::export_all()' ) |
|
136 | - ) ); |
|
135 | + sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::export_all()') |
|
136 | + )); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | $this->app->semaphore()->lock(); |
140 | 140 | |
141 | - if ( $user_id ) { |
|
142 | - wp_set_current_user( $user_id ); |
|
141 | + if ($user_id) { |
|
142 | + wp_set_current_user($user_id); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | $result = $this->app->export()->full(); |
146 | 146 | $this->app->semaphore()->unlock(); |
147 | 147 | |
148 | 148 | // Maybe move option updating out of this class/upgrade message display? |
149 | - if ( is_wp_error( $result ) ) { |
|
150 | - update_option( '_wogh_export_error', $result->get_error_message() ); |
|
149 | + if (is_wp_error($result)) { |
|
150 | + update_option('_wogh_export_error', $result->get_error_message()); |
|
151 | 151 | |
152 | - return $this->app->response()->error( $result ); |
|
152 | + return $this->app->response()->error($result); |
|
153 | 153 | } else { |
154 | - update_option( '_wogh_export_complete', 'yes' ); |
|
155 | - update_option( '_wogh_fully_exported', 'yes' ); |
|
154 | + update_option('_wogh_export_complete', 'yes'); |
|
155 | + update_option('_wogh_fully_exported', 'yes'); |
|
156 | 156 | |
157 | - return $this->app->response()->success( $result ); |
|
157 | + return $this->app->response()->success($result); |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | |
@@ -167,27 +167,27 @@ discard block |
||
167 | 167 | * |
168 | 168 | * @return boolean |
169 | 169 | */ |
170 | - public function export_post( $post_id ) { |
|
171 | - if ( wp_is_post_revision( $post_id ) ) { |
|
170 | + public function export_post($post_id) { |
|
171 | + if (wp_is_post_revision($post_id)) { |
|
172 | 172 | return; |
173 | 173 | } |
174 | 174 | |
175 | - if ( ! $this->app->semaphore()->is_open() ) { |
|
176 | - return $this->app->response()->error( new WP_Error( |
|
175 | + if ( ! $this->app->semaphore()->is_open()) { |
|
176 | + return $this->app->response()->error(new WP_Error( |
|
177 | 177 | 'semaphore_locked', |
178 | - sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::export_post()' ) |
|
179 | - ) ); |
|
178 | + sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::export_post()') |
|
179 | + )); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | $this->app->semaphore()->lock(); |
183 | - $result = $this->app->export()->update( $post_id ); |
|
183 | + $result = $this->app->export()->update($post_id); |
|
184 | 184 | $this->app->semaphore()->unlock(); |
185 | 185 | |
186 | - if ( is_wp_error( $result ) ) { |
|
187 | - return $this->app->response()->error( $result ); |
|
186 | + if (is_wp_error($result)) { |
|
187 | + return $this->app->response()->error($result); |
|
188 | 188 | } |
189 | 189 | |
190 | - return $this->app->response()->success( $result ); |
|
190 | + return $this->app->response()->success($result); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | /** |
@@ -199,27 +199,27 @@ discard block |
||
199 | 199 | * |
200 | 200 | * @return boolean |
201 | 201 | */ |
202 | - public function delete_post( $post_id ) { |
|
203 | - if ( wp_is_post_revision( $post_id ) ) { |
|
202 | + public function delete_post($post_id) { |
|
203 | + if (wp_is_post_revision($post_id)) { |
|
204 | 204 | return; |
205 | 205 | } |
206 | 206 | |
207 | - if ( ! $this->app->semaphore()->is_open() ) { |
|
208 | - return $this->app->response()->error( new WP_Error( |
|
207 | + if ( ! $this->app->semaphore()->is_open()) { |
|
208 | + return $this->app->response()->error(new WP_Error( |
|
209 | 209 | 'semaphore_locked', |
210 | - sprintf( __( '%s : Semaphore is locked, import/export already in progress.', 'writing-on-github' ), 'Controller::delete_post()' ) |
|
211 | - ) ); |
|
210 | + sprintf(__('%s : Semaphore is locked, import/export already in progress.', 'writing-on-github'), 'Controller::delete_post()') |
|
211 | + )); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | $this->app->semaphore()->lock(); |
215 | - $result = $this->app->export()->delete( $post_id ); |
|
215 | + $result = $this->app->export()->delete($post_id); |
|
216 | 216 | $this->app->semaphore()->unlock(); |
217 | 217 | |
218 | - if ( is_wp_error( $result ) ) { |
|
219 | - return $this->app->response()->error( $result ); |
|
218 | + if (is_wp_error($result)) { |
|
219 | + return $this->app->response()->error($result); |
|
220 | 220 | } |
221 | 221 | |
222 | - return $this->app->response()->success( $result ); |
|
222 | + return $this->app->response()->success($result); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
@@ -228,8 +228,8 @@ discard block |
||
228 | 228 | * than just returning data. |
229 | 229 | */ |
230 | 230 | protected function set_ajax() { |
231 | - if ( ! defined( 'WOGH_AJAX' ) ) { |
|
232 | - define( 'WOGH_AJAX', true ); |
|
231 | + if ( ! defined('WOGH_AJAX')) { |
|
232 | + define('WOGH_AJAX', true); |
|
233 | 233 | } |
234 | 234 | } |
235 | 235 | } |
@@ -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 | |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | public function full() { |
35 | 35 | $posts = $this->app->database()->fetch_all_supported(); |
36 | 36 | |
37 | - if ( is_wp_error( $posts ) ) { |
|
37 | + if (is_wp_error($posts)) { |
|
38 | 38 | return $posts; |
39 | 39 | } |
40 | 40 | |
@@ -53,11 +53,11 @@ discard block |
||
53 | 53 | |
54 | 54 | // $result = $this->app->api()->persist()->commit( $master ); |
55 | 55 | |
56 | - if ( is_wp_error( $result ) ) { |
|
56 | + if (is_wp_error($result)) { |
|
57 | 57 | return $result; |
58 | 58 | } |
59 | 59 | |
60 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
60 | + return __('Export to GitHub completed successfully.', 'writing-on-github'); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | * @param int $post_id |
67 | 67 | * @return boolean |
68 | 68 | */ |
69 | - protected function github_path( $post_id ) { |
|
70 | - $github_path = get_post_meta( $post_id, '_wogh_github_path', true ); |
|
69 | + protected function github_path($post_id) { |
|
70 | + $github_path = get_post_meta($post_id, '_wogh_github_path', true); |
|
71 | 71 | |
72 | - if ( $github_path && $this->app->api()->fetch()->exists( $github_path ) ) { |
|
72 | + if ($github_path && $this->app->api()->fetch()->exists($github_path)) { |
|
73 | 73 | return $github_path; |
74 | 74 | } |
75 | 75 | |
@@ -83,29 +83,29 @@ discard block |
||
83 | 83 | * |
84 | 84 | * @return string|WP_Error |
85 | 85 | */ |
86 | - public function update( $post_id ) { |
|
87 | - $post = $this->app->database()->fetch_by_id( $post_id ); |
|
86 | + public function update($post_id) { |
|
87 | + $post = $this->app->database()->fetch_by_id($post_id); |
|
88 | 88 | |
89 | - if ( is_wp_error( $post ) ) { |
|
89 | + if (is_wp_error($post)) { |
|
90 | 90 | return $post; |
91 | 91 | } |
92 | 92 | |
93 | - if ( 'trash' === $post->status() ) { |
|
94 | - return $this->delete( $post_id ); |
|
93 | + if ('trash' === $post->status()) { |
|
94 | + return $this->delete($post_id); |
|
95 | 95 | } |
96 | 96 | |
97 | - if ( $old_github_path = $this->github_path( $post->id() ) ) { |
|
97 | + if ($old_github_path = $this->github_path($post->id())) { |
|
98 | 98 | error_log("old_github_path: $old_github_path"); |
99 | 99 | $post->set_old_github_path($old_github_path); |
100 | 100 | } |
101 | 101 | |
102 | - $result = $this->new_posts( array( $post ) ); |
|
102 | + $result = $this->new_posts(array($post)); |
|
103 | 103 | |
104 | - if ( is_wp_error( $result ) ) { |
|
104 | + if (is_wp_error($result)) { |
|
105 | 105 | return $result; |
106 | 106 | } |
107 | 107 | |
108 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
108 | + return __('Export to GitHub completed successfully.', 'writing-on-github'); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -115,16 +115,16 @@ discard block |
||
115 | 115 | * |
116 | 116 | * @return string|WP_Error |
117 | 117 | */ |
118 | - public function new_posts( array $posts ) { |
|
118 | + public function new_posts(array $posts) { |
|
119 | 119 | $error = false; |
120 | 120 | |
121 | 121 | $persist = $this->app->api()->persist(); |
122 | 122 | |
123 | - foreach ( $posts as $post ) { |
|
124 | - $result = $this->new_post( $post, $persist ); |
|
125 | - if ( is_wp_error( $result ) ) { |
|
126 | - if ( $error ) { |
|
127 | - $error->add( $result->get_error_code(), $result->get_error_message() ); |
|
123 | + foreach ($posts as $post) { |
|
124 | + $result = $this->new_post($post, $persist); |
|
125 | + if (is_wp_error($result)) { |
|
126 | + if ($error) { |
|
127 | + $error->add($result->get_error_code(), $result->get_error_message()); |
|
128 | 128 | } else { |
129 | 129 | $error = $result; |
130 | 130 | } |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | |
136 | 136 | // $result = $this->app->api()->persist()->commit( $master ); |
137 | 137 | |
138 | - if ( is_wp_error( $error ) ) { |
|
138 | + if (is_wp_error($error)) { |
|
139 | 139 | return $error; |
140 | 140 | } |
141 | 141 | |
@@ -143,13 +143,13 @@ discard block |
||
143 | 143 | return true; |
144 | 144 | } |
145 | 145 | |
146 | - protected function new_post( $post, $persist ) { |
|
146 | + protected function new_post($post, $persist) { |
|
147 | 147 | $github_path = $post->github_path(); |
148 | 148 | $old_github_path = $post->old_github_path(); |
149 | 149 | $blob = $post->to_blob(); |
150 | 150 | $result = false; |
151 | 151 | |
152 | - if ( $old_github_path && $old_github_path != $github_path ) { |
|
152 | + if ($old_github_path && $old_github_path != $github_path) { |
|
153 | 153 | // rename |
154 | 154 | $message = apply_filters( |
155 | 155 | 'wogh_commit_msg_move_post', |
@@ -157,20 +157,20 @@ discard block |
||
157 | 157 | 'Moving %s to %s via WordPress at %s (%s)', |
158 | 158 | $old_github_path, $github_path, |
159 | 159 | site_url(), |
160 | - get_bloginfo( 'name' ) |
|
160 | + get_bloginfo('name') |
|
161 | 161 | ) |
162 | 162 | ) . $this->get_commit_msg_tag(); |
163 | 163 | |
164 | - $result = $persist->delete_file( $post->old_github_path(), $blob->sha(), $message ); |
|
165 | - if ( is_wp_error( $result ) ) { |
|
164 | + $result = $persist->delete_file($post->old_github_path(), $blob->sha(), $message); |
|
165 | + if (is_wp_error($result)) { |
|
166 | 166 | return $result; |
167 | 167 | } |
168 | 168 | |
169 | - $result = $persist->create_file( $blob, $message ); |
|
170 | - if ( is_wp_error( $result ) ) { |
|
169 | + $result = $persist->create_file($blob, $message); |
|
170 | + if (is_wp_error($result)) { |
|
171 | 171 | return $result; |
172 | 172 | } |
173 | - } elseif ( ! $old_github_path ) { |
|
173 | + } elseif ( ! $old_github_path) { |
|
174 | 174 | // create new |
175 | 175 | $message = apply_filters( |
176 | 176 | 'wogh_commit_msg_new_post', |
@@ -178,14 +178,14 @@ discard block |
||
178 | 178 | 'Creating new posts %s from WordPress at %s (%s)', |
179 | 179 | $github_path, |
180 | 180 | site_url(), |
181 | - get_bloginfo( 'name' ) |
|
181 | + get_bloginfo('name') |
|
182 | 182 | ) |
183 | 183 | ) . $this->get_commit_msg_tag(); |
184 | - $result = $persist->create_file( $blob, $message ); |
|
185 | - if ( is_wp_error( $result ) ) { |
|
184 | + $result = $persist->create_file($blob, $message); |
|
185 | + if (is_wp_error($result)) { |
|
186 | 186 | return $result; |
187 | 187 | } |
188 | - } elseif ( $old_github_path && $old_github_path == $github_path ) { |
|
188 | + } elseif ($old_github_path && $old_github_path == $github_path) { |
|
189 | 189 | // update |
190 | 190 | $message = apply_filters( |
191 | 191 | 'wogh_commit_msg_update_post', |
@@ -193,11 +193,11 @@ discard block |
||
193 | 193 | 'Creating new posts %s from WordPress at %s (%s)', |
194 | 194 | $github_path, |
195 | 195 | site_url(), |
196 | - get_bloginfo( 'name' ) |
|
196 | + get_bloginfo('name') |
|
197 | 197 | ) |
198 | 198 | ) . $this->get_commit_msg_tag(); |
199 | - $result = $persist->update_file( $blob, $message ); |
|
200 | - if ( is_wp_error( $result ) ) { |
|
199 | + $result = $persist->update_file($blob, $message); |
|
200 | + if (is_wp_error($result)) { |
|
201 | 201 | return $result; |
202 | 202 | } |
203 | 203 | } |
@@ -216,14 +216,14 @@ discard block |
||
216 | 216 | * |
217 | 217 | * @return string|WP_Error |
218 | 218 | */ |
219 | - public function delete( $post_id ) { |
|
220 | - $post = $this->app->database()->fetch_by_id( $post_id ); |
|
219 | + public function delete($post_id) { |
|
220 | + $post = $this->app->database()->fetch_by_id($post_id); |
|
221 | 221 | |
222 | - if ( is_wp_error( $post ) ) { |
|
222 | + if (is_wp_error($post)) { |
|
223 | 223 | return $post; |
224 | 224 | } |
225 | 225 | |
226 | - $github_path = get_post_meta( $post_id, '_wogh_github_path', true ); |
|
226 | + $github_path = get_post_meta($post_id, '_wogh_github_path', true); |
|
227 | 227 | |
228 | 228 | $message = apply_filters( |
229 | 229 | 'wogh_commit_msg_delete', |
@@ -231,18 +231,18 @@ discard block |
||
231 | 231 | 'Deleting %s via WordPress at %s (%s)', |
232 | 232 | $github_path, |
233 | 233 | site_url(), |
234 | - get_bloginfo( 'name' ) |
|
234 | + get_bloginfo('name') |
|
235 | 235 | ), |
236 | 236 | $post |
237 | 237 | ) . $this->get_commit_msg_tag(); |
238 | 238 | |
239 | - $result = $this->app->api()->persist()->delete_file( $github_path, $post->sha(), $message ); |
|
239 | + $result = $this->app->api()->persist()->delete_file($github_path, $post->sha(), $message); |
|
240 | 240 | |
241 | - if ( is_wp_error( $result ) ) { |
|
241 | + if (is_wp_error($result)) { |
|
242 | 242 | return $result; |
243 | 243 | } |
244 | 244 | |
245 | - return __( 'Export to GitHub completed successfully.', 'writing-on-github' ); |
|
245 | + return __('Export to GitHub completed successfully.', 'writing-on-github'); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | |
@@ -253,8 +253,8 @@ discard block |
||
253 | 253 | * |
254 | 254 | * @return bool |
255 | 255 | */ |
256 | - public function set_user( $user_id ) { |
|
257 | - return update_option( self::EXPORT_USER_OPTION, (int) $user_id ); |
|
256 | + public function set_user($user_id) { |
|
257 | + return update_option(self::EXPORT_USER_OPTION, (int) $user_id); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
@@ -263,10 +263,10 @@ discard block |
||
263 | 263 | * @return string |
264 | 264 | */ |
265 | 265 | protected function get_commit_msg_tag() { |
266 | - $tag = apply_filters( 'wogh_commit_msg_tag', 'wogh' ); |
|
266 | + $tag = apply_filters('wogh_commit_msg_tag', 'wogh'); |
|
267 | 267 | |
268 | - if ( ! $tag ) { |
|
269 | - throw new Exception( __( 'Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github' ) ); |
|
268 | + if ( ! $tag) { |
|
269 | + throw new Exception(__('Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github')); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | return ' - ' . $tag; |
@@ -9,77 +9,77 @@ discard block |
||
9 | 9 | public function setUp() { |
10 | 10 | parent::setUp(); |
11 | 11 | |
12 | - $this->fetch = new Writing_On_GitHub_Fetch_Client( $this->app ); |
|
12 | + $this->fetch = new Writing_On_GitHub_Fetch_Client($this->app); |
|
13 | 13 | $this->api_cache |
14 | - ->shouldReceive( 'fetch_blob' ) |
|
15 | - ->andReturn( false ) |
|
14 | + ->shouldReceive('fetch_blob') |
|
15 | + ->andReturn(false) |
|
16 | 16 | ->byDefault(); |
17 | 17 | } |
18 | 18 | |
19 | 19 | public function test_should_fail_if_missing_token() { |
20 | - delete_option( Base::TOKEN_OPTION_KEY ); |
|
20 | + delete_option(Base::TOKEN_OPTION_KEY); |
|
21 | 21 | |
22 | - $this->assertInstanceOf( 'WP_Error', $error = $this->fetch->tree_recursive() ); |
|
23 | - $this->assertSame( 'missing_token', $error->get_error_code() ); |
|
22 | + $this->assertInstanceOf('WP_Error', $error = $this->fetch->tree_recursive()); |
|
23 | + $this->assertSame('missing_token', $error->get_error_code()); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | public function test_should_fail_if_missing_repo() { |
27 | - delete_option( Base::REPO_OPTION_KEY ); |
|
27 | + delete_option(Base::REPO_OPTION_KEY); |
|
28 | 28 | |
29 | - $this->assertInstanceOf( 'WP_Error', $error = $this->fetch->tree_recursive() ); |
|
30 | - $this->assertSame( 'missing_repository', $error->get_error_code() ); |
|
29 | + $this->assertInstanceOf('WP_Error', $error = $this->fetch->tree_recursive()); |
|
30 | + $this->assertSame('missing_repository', $error->get_error_code()); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | public function test_should_fail_if_malformed_repo() { |
34 | 34 | // If you find a particular name passing that shouldn't, |
35 | 35 | // add it to the list here and make it pass. |
36 | - $this->malformed_repo( 'repositoryname' ); |
|
36 | + $this->malformed_repo('repositoryname'); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | public function test_should_return_files_with_tree() { |
40 | 40 | // $this->set_get_refs_heads_master( true ); |
41 | 41 | // $this->set_get_commits( true ); |
42 | - $this->set_get_trees( true, 'master' ); |
|
42 | + $this->set_get_trees(true, 'master'); |
|
43 | 43 | |
44 | - $this->assertCount( 3, $this->fetch->tree_recursive() ); |
|
44 | + $this->assertCount(3, $this->fetch->tree_recursive()); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | public function test_should_fail_if_cant_fetch_tree() { |
48 | - $this->set_get_trees( false, 'master' ); |
|
48 | + $this->set_get_trees(false, 'master'); |
|
49 | 49 | |
50 | - $this->assertInstanceOf( 'WP_Error', $error = $this->fetch->tree_recursive() ); |
|
51 | - $this->assertSame( '422_unprocessable_entity', $error->get_error_code() ); |
|
50 | + $this->assertInstanceOf('WP_Error', $error = $this->fetch->tree_recursive()); |
|
51 | + $this->assertSame('422_unprocessable_entity', $error->get_error_code()); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | public function test_should_return_commit_with_blobs_from_cache() { |
55 | - $this->set_get_trees( true, 'master' ); |
|
56 | - $this->set_get_blobs( true ); |
|
55 | + $this->set_get_trees(true, 'master'); |
|
56 | + $this->set_get_blobs(true); |
|
57 | 57 | $this->api_cache |
58 | - ->shouldReceive( 'fetch_blob' ) |
|
59 | - ->times( 3 ) |
|
60 | - ->with( Mockery::anyOf( |
|
58 | + ->shouldReceive('fetch_blob') |
|
59 | + ->times(3) |
|
60 | + ->with(Mockery::anyOf( |
|
61 | 61 | '9fa5c7537f8582b71028ff34b8c20dfd0f3b2a25', |
62 | 62 | '8d9b2e6fd93761211dc03abd71f4a9189d680fd0', |
63 | 63 | '2d73165945b0ccbe4932f1363457986b0ed49f19' |
64 | - ) ) |
|
65 | - ->andReturn( $this->blob ); |
|
64 | + )) |
|
65 | + ->andReturn($this->blob); |
|
66 | 66 | |
67 | - $this->assertCount( 3, $files = $this->fetch->tree_recursive() ); |
|
67 | + $this->assertCount(3, $files = $this->fetch->tree_recursive()); |
|
68 | 68 | |
69 | - foreach ( $files as $file ) { |
|
70 | - $this->assertSame( $this->blob, $this->fetch->blob( $file ) ); |
|
69 | + foreach ($files as $file) { |
|
70 | + $this->assertSame($this->blob, $this->fetch->blob($file)); |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | |
74 | 74 | public function test_should_return_commit_with_no_blobs_if_api_fails() { |
75 | - $this->set_get_trees( true, 'master' ); |
|
76 | - $this->set_get_blobs( false ); |
|
75 | + $this->set_get_trees(true, 'master'); |
|
76 | + $this->set_get_blobs(false); |
|
77 | 77 | |
78 | - $this->assertCount( 3, $files = $this->fetch->tree_recursive() ); |
|
78 | + $this->assertCount(3, $files = $this->fetch->tree_recursive()); |
|
79 | 79 | |
80 | - foreach ( $files as $file ) { |
|
81 | - $this->assertInstanceOf( 'WP_Error', $error = $this->fetch->blob( $file ) ); |
|
82 | - $this->assertSame( '404_not_found', $error->get_error_code() ); |
|
80 | + foreach ($files as $file) { |
|
81 | + $this->assertInstanceOf('WP_Error', $error = $this->fetch->blob($file)); |
|
82 | + $this->assertSame('404_not_found', $error->get_error_code()); |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
@@ -159,10 +159,10 @@ discard block |
||
159 | 159 | // } |
160 | 160 | // } |
161 | 161 | |
162 | - protected function malformed_repo( $repo ) { |
|
163 | - update_option( Base::REPO_OPTION_KEY, $repo ); |
|
162 | + protected function malformed_repo($repo) { |
|
163 | + update_option(Base::REPO_OPTION_KEY, $repo); |
|
164 | 164 | |
165 | - $this->assertInstanceOf( 'WP_Error', $error = $this->fetch->tree_recursive() ); |
|
166 | - $this->assertSame( 'malformed_repository', $error->get_error_code() ); |
|
165 | + $this->assertInstanceOf('WP_Error', $error = $this->fetch->tree_recursive()); |
|
166 | + $this->assertSame('malformed_repository', $error->get_error_code()); |
|
167 | 167 | } |
168 | 168 | } |