@@ -49,8 +49,8 @@ discard block |
||
| 49 | 49 | * |
| 50 | 50 | * @param stdClass $data Raw blob data. |
| 51 | 51 | */ |
| 52 | - public function __construct( stdClass $data ) { |
|
| 53 | - $this->interpret_data( $data ); |
|
| 52 | + public function __construct(stdClass $data) { |
|
| 53 | + $this->interpret_data($data); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | public function id() { |
@@ -78,12 +78,12 @@ discard block |
||
| 78 | 78 | * |
| 79 | 79 | * @return $this |
| 80 | 80 | */ |
| 81 | - public function set_content( $content, $base64 = false ) { |
|
| 82 | - if ( $base64 ) { |
|
| 83 | - $content = base64_decode( $content ); |
|
| 81 | + public function set_content($content, $base64 = false) { |
|
| 82 | + if ($base64) { |
|
| 83 | + $content = base64_decode($content); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - $this->frontmatter = '---' === substr( $this->content = $content, 0, 3 ) ? true : false; |
|
| 86 | + $this->frontmatter = '---' === substr($this->content = $content, 0, 3) ? true : false; |
|
| 87 | 87 | |
| 88 | 88 | return $this; |
| 89 | 89 | } |
@@ -122,20 +122,20 @@ discard block |
||
| 122 | 122 | public function content_import() { |
| 123 | 123 | $content = $this->content(); |
| 124 | 124 | |
| 125 | - if ( $this->has_frontmatter() ) { |
|
| 125 | + if ($this->has_frontmatter()) { |
|
| 126 | 126 | // Break out content. |
| 127 | - preg_match( '/(^---(.*?)---$)?(.*)/ms', $content, $matches ); |
|
| 128 | - $content = array_pop( $matches ); |
|
| 127 | + preg_match('/(^---(.*?)---$)?(.*)/ms', $content, $matches); |
|
| 128 | + $content = array_pop($matches); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - if ( function_exists( 'wpmarkdown_markdown_to_html' ) ) { |
|
| 132 | - $content = wpmarkdown_markdown_to_html( $content ); |
|
| 131 | + if (function_exists('wpmarkdown_markdown_to_html')) { |
|
| 132 | + $content = wpmarkdown_markdown_to_html($content); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
| 136 | 136 | * Filters the content for import. |
| 137 | 137 | */ |
| 138 | - return apply_filters( 'wogh_content_import', trim( $content ) ); |
|
| 138 | + return apply_filters('wogh_content_import', trim($content)); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -146,13 +146,13 @@ discard block |
||
| 146 | 146 | public function meta() { |
| 147 | 147 | $meta = array(); |
| 148 | 148 | |
| 149 | - if ( $this->has_frontmatter() ) { |
|
| 149 | + if ($this->has_frontmatter()) { |
|
| 150 | 150 | // Break out meta, if present. |
| 151 | - preg_match( '/(^---(.*?)---$)?(.*)/ms', $this->content(), $matches ); |
|
| 152 | - array_pop( $matches ); |
|
| 151 | + preg_match('/(^---(.*?)---$)?(.*)/ms', $this->content(), $matches); |
|
| 152 | + array_pop($matches); |
|
| 153 | 153 | |
| 154 | - $meta = spyc_load( $matches[2] ); |
|
| 155 | - if ( 'yes' == get_option('wogh_ignore_author') ) { |
|
| 154 | + $meta = spyc_load($matches[2]); |
|
| 155 | + if ('yes' == get_option('wogh_ignore_author')) { |
|
| 156 | 156 | unset($meta['author']); |
| 157 | 157 | } |
| 158 | 158 | // if ( isset( $meta['link'] ) ) { |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | // $data->type = 'blob'; |
| 199 | 199 | |
| 200 | 200 | $data->path = $this->path(); |
| 201 | - $data->content = base64_encode( $this->content() ); |
|
| 201 | + $data->content = base64_encode($this->content()); |
|
| 202 | 202 | $data->sha = $this->sha; |
| 203 | 203 | |
| 204 | 204 | return $data; |
@@ -207,13 +207,13 @@ discard block |
||
| 207 | 207 | /** |
| 208 | 208 | * Interprets the blob's data into properties. |
| 209 | 209 | */ |
| 210 | - protected function interpret_data( $data ) { |
|
| 211 | - $this->sha = isset( $data->sha ) ? $data->sha : ''; |
|
| 212 | - $this->path = isset( $data->path ) ? $data->path : ''; |
|
| 210 | + protected function interpret_data($data) { |
|
| 211 | + $this->sha = isset($data->sha) ? $data->sha : ''; |
|
| 212 | + $this->path = isset($data->path) ? $data->path : ''; |
|
| 213 | 213 | |
| 214 | 214 | $this->set_content( |
| 215 | - isset( $data->content ) ? trim( $data->content ) : '', |
|
| 216 | - isset( $data->encoding ) && 'base64' === $data->encoding ? true : false |
|
| 215 | + isset($data->content) ? trim($data->content) : '', |
|
| 216 | + isset($data->encoding) && 'base64' === $data->encoding ? true : false |
|
| 217 | 217 | ); |
| 218 | 218 | } |
| 219 | 219 | } |
@@ -29,9 +29,9 @@ discard block |
||
| 29 | 29 | * @param Writing_On_GitHub $app Application container. |
| 30 | 30 | * @param string $raw_data Raw request data. |
| 31 | 31 | */ |
| 32 | - public function __construct( Writing_On_GitHub $app, $raw_data ) { |
|
| 32 | + public function __construct(Writing_On_GitHub $app, $raw_data) { |
|
| 33 | 33 | $this->app = $app; |
| 34 | - $this->data = json_decode( $raw_data ); |
|
| 34 | + $this->data = json_decode($raw_data); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
@@ -41,32 +41,32 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function should_import() { |
| 43 | 43 | // @todo how do we get this without importing the whole api object just for this? |
| 44 | - if ( strtolower( $this->data->repository->full_name ) !== strtolower( $this->app->api()->fetch()->repository() ) ) { |
|
| 44 | + if (strtolower($this->data->repository->full_name) !== strtolower($this->app->api()->fetch()->repository())) { |
|
| 45 | 45 | return false; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | // The last term in the ref is the payload_branch name. |
| 49 | - $refs = explode( '/', $this->data->ref ); |
|
| 50 | - $payload_branch = array_pop( $refs ); |
|
| 49 | + $refs = explode('/', $this->data->ref); |
|
| 50 | + $payload_branch = array_pop($refs); |
|
| 51 | 51 | |
| 52 | 52 | $branch = $this->app->api()->fetch()->branch(); |
| 53 | 53 | |
| 54 | - if ( $branch !== $payload_branch ) { |
|
| 54 | + if ($branch !== $payload_branch) { |
|
| 55 | 55 | return false; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | // We add a tag to commits we push out, so we shouldn't pull them in again. |
| 59 | - $tag = apply_filters( 'wogh_commit_msg_tag', 'wogh' ); |
|
| 59 | + $tag = apply_filters('wogh_commit_msg_tag', 'wogh'); |
|
| 60 | 60 | |
| 61 | - if ( ! $tag ) { |
|
| 62 | - throw new Exception( __( 'Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github' ) ); |
|
| 61 | + if ( ! $tag) { |
|
| 62 | + throw new Exception(__('Commit message tag not set. Filter `wogh_commit_msg_tag` misconfigured.', 'writing-on-github')); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - if ( $tag === substr( $this->message(), -1 * strlen( $tag ) ) ) { |
|
| 65 | + if ($tag === substr($this->message(), -1 * strlen($tag))) { |
|
| 66 | 66 | return false; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - if ( ! $this->get_commit_id() ) { |
|
| 69 | + if ( ! $this->get_commit_id()) { |
|
| 70 | 70 | return false; |
| 71 | 71 | } |
| 72 | 72 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * |
| 36 | 36 | * @param Writing_On_GitHub $app Application container. |
| 37 | 37 | */ |
| 38 | - public function __construct( Writing_On_GitHub $app ) { |
|
| 38 | + public function __construct(Writing_On_GitHub $app) { |
|
| 39 | 39 | $this->app = $app; |
| 40 | 40 | } |
| 41 | 41 | |
@@ -45,8 +45,8 @@ discard block |
||
| 45 | 45 | * @return Writing_On_GitHub_Fetch_Client |
| 46 | 46 | */ |
| 47 | 47 | public function fetch() { |
| 48 | - if ( ! $this->fetch ) { |
|
| 49 | - $this->fetch = new Writing_On_GitHub_Fetch_Client( $this->app ); |
|
| 48 | + if ( ! $this->fetch) { |
|
| 49 | + $this->fetch = new Writing_On_GitHub_Fetch_Client($this->app); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | return $this->fetch; |
@@ -58,8 +58,8 @@ discard block |
||
| 58 | 58 | * @return Writing_On_GitHub_Persist_Client |
| 59 | 59 | */ |
| 60 | 60 | public function persist() { |
| 61 | - if ( ! $this->persist ) { |
|
| 62 | - $this->persist = new Writing_On_GitHub_Persist_Client( $this->app ); |
|
| 61 | + if ( ! $this->persist) { |
|
| 62 | + $this->persist = new Writing_On_GitHub_Persist_Client($this->app); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | return $this->persist; |
@@ -6,13 +6,13 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | class Writing_On_GitHub_File_Info { |
| 8 | 8 | |
| 9 | - public function __construct( stdClass $data ) { |
|
| 9 | + public function __construct(stdClass $data) { |
|
| 10 | 10 | $this->sha = $data->sha; |
| 11 | 11 | $this->path = $data->path; |
| 12 | - $this->status = $data->status; |
|
| 12 | + $this->status = $data->status; |
|
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | public $sha; |
| 16 | 16 | public $path; |
| 17 | - public $status; // added removed modified |
|
| 17 | + public $status; // added removed modified |
|
| 18 | 18 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * Clean up the old values on instantiation. |
| 29 | 29 | */ |
| 30 | 30 | public function __construct() { |
| 31 | - delete_option( self::KEY ); |
|
| 31 | + delete_option(self::KEY); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * @return bool |
| 41 | 41 | */ |
| 42 | 42 | public function is_open() { |
| 43 | - if ( self::VALUE_LOCKED === get_transient( self::KEY ) ) { |
|
| 43 | + if (self::VALUE_LOCKED === get_transient(self::KEY)) { |
|
| 44 | 44 | return false; |
| 45 | 45 | } |
| 46 | 46 | |
@@ -51,13 +51,13 @@ discard block |
||
| 51 | 51 | * Enables the push lock. |
| 52 | 52 | */ |
| 53 | 53 | public function lock() { |
| 54 | - set_transient( self::KEY, self::VALUE_LOCKED, MINUTE_IN_SECONDS ); |
|
| 54 | + set_transient(self::KEY, self::VALUE_LOCKED, MINUTE_IN_SECONDS); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * Disables the push lock. |
| 59 | 59 | */ |
| 60 | 60 | public function unlock() { |
| 61 | - set_transient( self::KEY, self::VALUE_UNLOCKED, MINUTE_IN_SECONDS ); |
|
| 61 | + set_transient(self::KEY, self::VALUE_UNLOCKED, MINUTE_IN_SECONDS); |
|
| 62 | 62 | } |
| 63 | 63 | } |
@@ -44,28 +44,28 @@ discard block |
||
| 44 | 44 | * |
| 45 | 45 | * @param array $args Command arguments. |
| 46 | 46 | */ |
| 47 | - public function export( $args ) { |
|
| 48 | - list( $post_id, $user_id ) = $args; |
|
| 47 | + public function export($args) { |
|
| 48 | + list($post_id, $user_id) = $args; |
|
| 49 | 49 | |
| 50 | - if ( ! is_numeric( $user_id ) ) { |
|
| 51 | - WP_CLI::error( __( 'Invalid user ID', 'writing-on-github' ) ); |
|
| 50 | + if ( ! is_numeric($user_id)) { |
|
| 51 | + WP_CLI::error(__('Invalid user ID', 'writing-on-github')); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - $this->app->export()->set_user( $user_id ); |
|
| 54 | + $this->app->export()->set_user($user_id); |
|
| 55 | 55 | |
| 56 | - if ( 'all' === $post_id ) { |
|
| 57 | - WP_CLI::line( __( 'Starting full export to GitHub.', 'writing-on-github' ) ); |
|
| 56 | + if ('all' === $post_id) { |
|
| 57 | + WP_CLI::line(__('Starting full export to GitHub.', 'writing-on-github')); |
|
| 58 | 58 | $this->app->controller()->export_all(); |
| 59 | - } elseif ( is_numeric( $post_id ) ) { |
|
| 59 | + } elseif (is_numeric($post_id)) { |
|
| 60 | 60 | WP_CLI::line( |
| 61 | 61 | sprintf( |
| 62 | - __( 'Exporting post ID to GitHub: %d', 'writing-on-github' ), |
|
| 62 | + __('Exporting post ID to GitHub: %d', 'writing-on-github'), |
|
| 63 | 63 | $post_id |
| 64 | 64 | ) |
| 65 | 65 | ); |
| 66 | - $this->app->controller()->export_post( (int) $post_id ); |
|
| 66 | + $this->app->controller()->export_post((int) $post_id); |
|
| 67 | 67 | } else { |
| 68 | - WP_CLI::error( __( 'Invalid post ID', 'writing-on-github' ) ); |
|
| 68 | + WP_CLI::error(__('Invalid post ID', 'writing-on-github')); |
|
| 69 | 69 | } |
| 70 | 70 | } |
| 71 | 71 | |
@@ -86,16 +86,16 @@ discard block |
||
| 86 | 86 | * |
| 87 | 87 | * @param array $args Command arguments. |
| 88 | 88 | */ |
| 89 | - public function import( $args ) { |
|
| 90 | - list( $user_id ) = $args; |
|
| 89 | + public function import($args) { |
|
| 90 | + list($user_id) = $args; |
|
| 91 | 91 | |
| 92 | - if ( ! is_numeric( $user_id ) ) { |
|
| 93 | - WP_CLI::error( __( 'Invalid user ID', 'writing-on-github' ) ); |
|
| 92 | + if ( ! is_numeric($user_id)) { |
|
| 93 | + WP_CLI::error(__('Invalid user ID', 'writing-on-github')); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - update_option( '_wogh_export_user_id', (int) $user_id ); |
|
| 96 | + update_option('_wogh_export_user_id', (int) $user_id); |
|
| 97 | 97 | |
| 98 | - WP_CLI::line( __( 'Starting import from GitHub.', 'writing-on-github' ) ); |
|
| 98 | + WP_CLI::line(__('Starting import from GitHub.', 'writing-on-github')); |
|
| 99 | 99 | |
| 100 | 100 | $this->app->controller()->import_master(); |
| 101 | 101 | } |
@@ -119,40 +119,40 @@ discard block |
||
| 119 | 119 | * @param array $args Command arguments. |
| 120 | 120 | * @param array $assoc_args Command associated arguments. |
| 121 | 121 | */ |
| 122 | - public function prime( $args, $assoc_args ) { |
|
| 123 | - if ( isset( $assoc_args['branch'] ) ) { |
|
| 124 | - WP_CLI::line( __( 'Starting branch import.', 'writing-on-github' ) ); |
|
| 122 | + public function prime($args, $assoc_args) { |
|
| 123 | + if (isset($assoc_args['branch'])) { |
|
| 124 | + WP_CLI::line(__('Starting branch import.', 'writing-on-github')); |
|
| 125 | 125 | |
| 126 | 126 | $commit = $this->app->api()->fetch()->master(); |
| 127 | 127 | |
| 128 | - if ( is_wp_error( $commit ) ) { |
|
| 128 | + if (is_wp_error($commit)) { |
|
| 129 | 129 | WP_CLI::error( |
| 130 | 130 | sprintf( |
| 131 | - __( 'Failed to import and cache branch with error: %s', 'writing-on-github' ), |
|
| 131 | + __('Failed to import and cache branch with error: %s', 'writing-on-github'), |
|
| 132 | 132 | $commit->get_error_message() |
| 133 | 133 | ) |
| 134 | 134 | ); |
| 135 | 135 | } else { |
| 136 | 136 | WP_CLI::success( |
| 137 | 137 | sprintf( |
| 138 | - __( 'Successfully imported and cached commit %s from branch.', 'writing-on-github' ), |
|
| 138 | + __('Successfully imported and cached commit %s from branch.', 'writing-on-github'), |
|
| 139 | 139 | $commit->sha() |
| 140 | 140 | ) |
| 141 | 141 | ); |
| 142 | 142 | } |
| 143 | - } else if ( isset( $assoc_args['sha'] ) ) { |
|
| 144 | - WP_CLI::line( 'Starting sha import.' ); |
|
| 143 | + } else if (isset($assoc_args['sha'])) { |
|
| 144 | + WP_CLI::line('Starting sha import.'); |
|
| 145 | 145 | |
| 146 | - $commit = $this->app->api()->fetch()->commit( $assoc_args['sha'] ); |
|
| 146 | + $commit = $this->app->api()->fetch()->commit($assoc_args['sha']); |
|
| 147 | 147 | |
| 148 | 148 | WP_CLI::success( |
| 149 | 149 | sprintf( |
| 150 | - __( 'Successfully imported and cached commit %s.', 'writing-on-github' ), |
|
| 150 | + __('Successfully imported and cached commit %s.', 'writing-on-github'), |
|
| 151 | 151 | $commit->sha() |
| 152 | 152 | ) |
| 153 | 153 | ); |
| 154 | 154 | } else { |
| 155 | - WP_CLI::error( 'Invalid fetch.' ); |
|
| 155 | + WP_CLI::error('Invalid fetch.'); |
|
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | 158 | } |
@@ -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,24 +359,24 @@ discard block |
||
| 359 | 359 | public function meta() { |
| 360 | 360 | $meta = array( |
| 361 | 361 | 'ID' => $this->id, |
| 362 | - 'post_title' => get_the_title( $this->post ), |
|
| 362 | + 'post_title' => get_the_title($this->post), |
|
| 363 | 363 | 'post_name' => $this->post->post_name, |
| 364 | - 'author' => ( $author = get_userdata( $this->post->post_author ) ) ? $author->display_name : '', |
|
| 364 | + 'author' => ($author = get_userdata($this->post->post_author)) ? $author->display_name : '', |
|
| 365 | 365 | 'post_date' => $this->post->post_date, |
| 366 | 366 | 'post_excerpt' => $this->post->post_excerpt, |
| 367 | - 'layout' => get_post_type( $this->post ), |
|
| 368 | - 'link' => get_permalink( $this->post ), |
|
| 367 | + 'layout' => get_post_type($this->post), |
|
| 368 | + 'link' => get_permalink($this->post), |
|
| 369 | 369 | 'published' => 'publish' === $this->status() ? true : false, |
| 370 | - 'tags' => wp_get_post_tags( $this->id, array( 'fields' => 'names' ) ), |
|
| 371 | - 'categories' => wp_get_post_categories( $this->id, array( 'fields' => 'names' ) ) |
|
| 370 | + 'tags' => wp_get_post_tags($this->id, array('fields' => 'names')), |
|
| 371 | + 'categories' => wp_get_post_categories($this->id, array('fields' => 'names')) |
|
| 372 | 372 | ); |
| 373 | - if ( empty($this->post->post_name) ) { |
|
| 373 | + if (empty($this->post->post_name)) { |
|
| 374 | 374 | unset($meta['post_name']); |
| 375 | 375 | } |
| 376 | - if ( empty($this->post->post_excerpt) ) { |
|
| 376 | + if (empty($this->post->post_excerpt)) { |
|
| 377 | 377 | unset($meta['post_excerpt']); |
| 378 | 378 | } |
| 379 | - if ( 'yes' == get_option('wogh_ignore_author') ) { |
|
| 379 | + if ('yes' == get_option('wogh_ignore_author')) { |
|
| 380 | 380 | unset($meta['author']); |
| 381 | 381 | } |
| 382 | 382 | |
@@ -391,7 +391,7 @@ discard block |
||
| 391 | 391 | |
| 392 | 392 | // } |
| 393 | 393 | |
| 394 | - return apply_filters( 'wogh_post_meta', $meta, $this ); |
|
| 394 | + return apply_filters('wogh_post_meta', $meta, $this); |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | /** |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | * |
| 409 | 409 | * @param array $meta |
| 410 | 410 | */ |
| 411 | - public function set_meta( $meta ) { |
|
| 411 | + public function set_meta($meta) { |
|
| 412 | 412 | $this->meta = $meta; |
| 413 | 413 | } |
| 414 | 414 | |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | * |
| 438 | 438 | * @return $this |
| 439 | 439 | */ |
| 440 | - public function set_post( WP_Post $post ) { |
|
| 440 | + public function set_post(WP_Post $post) { |
|
| 441 | 441 | $this->post = $post; |
| 442 | 442 | $this->id = $post->ID; |
| 443 | 443 | |
@@ -456,6 +456,6 @@ discard block |
||
| 456 | 456 | $data->content = $this->github_content(); |
| 457 | 457 | $data->sha = $this->sha(); |
| 458 | 458 | |
| 459 | - return new Writing_On_GitHub_Blob( $data ); |
|
| 459 | + return new Writing_On_GitHub_Blob($data); |
|
| 460 | 460 | } |
| 461 | 461 | } |
@@ -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,44 +150,44 @@ 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 | 164 | |
| 165 | - if ( $this->importable_raw_file($blob) ) { |
|
| 165 | + if ($this->importable_raw_file($blob)) { |
|
| 166 | 166 | $this->import_raw_file($blob, $file->status == 'removed'); |
| 167 | 167 | continue; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - if ( ! $this->importable_blob($blob) ) { |
|
| 170 | + if ( ! $this->importable_blob($blob)) { |
|
| 171 | 171 | continue; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - $post = $this->blob_to_post( $blob ); |
|
| 174 | + $post = $this->blob_to_post($blob); |
|
| 175 | 175 | |
| 176 | - if ( $file->status == 'removed' ) { |
|
| 177 | - if ( $blob->id() ) { |
|
| 176 | + if ($file->status == 'removed') { |
|
| 177 | + if ($blob->id()) { |
|
| 178 | 178 | $idsmap[$blob->id()] = true; |
| 179 | 179 | } |
| 180 | - } elseif ( $post != false ) { |
|
| 180 | + } elseif ($post != false) { |
|
| 181 | 181 | $posts[] = $post; |
| 182 | - if ( $post->is_new() ) { |
|
| 182 | + if ($post->is_new()) { |
|
| 183 | 183 | $new[] = $post; |
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | foreach ($posts as $post) { |
| 189 | - if ( $post->id() && isset( $idsmap[$post->id()] ) ) { |
|
| 190 | - unset( $idsmap[$post->id()] ); |
|
| 189 | + if ($post->id() && isset($idsmap[$post->id()])) { |
|
| 190 | + unset($idsmap[$post->id()]); |
|
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | 193 | $delete_ids = array(); |
@@ -197,16 +197,16 @@ discard block |
||
| 197 | 197 | |
| 198 | 198 | // $this->app->database()->save_posts( $posts, $commit->author_email() ); |
| 199 | 199 | |
| 200 | - $result = $this->app->database()->save_posts( $posts ); |
|
| 200 | + $result = $this->app->database()->save_posts($posts); |
|
| 201 | 201 | |
| 202 | - if ( is_wp_error( $result ) ) { |
|
| 202 | + if (is_wp_error($result)) { |
|
| 203 | 203 | return $result; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - if ( $new ) { |
|
| 207 | - $result = $this->app->export()->new_posts( $new ); |
|
| 206 | + if ($new) { |
|
| 207 | + $result = $this->app->export()->new_posts($new); |
|
| 208 | 208 | |
| 209 | - if ( is_wp_error( $result ) ) { |
|
| 209 | + if (is_wp_error($result)) { |
|
| 210 | 210 | return $result; |
| 211 | 211 | } |
| 212 | 212 | } |
@@ -221,12 +221,12 @@ discard block |
||
| 221 | 221 | * |
| 222 | 222 | * @return bool |
| 223 | 223 | */ |
| 224 | - protected function importable_file( Writing_On_GitHub_File_Info $file ) { |
|
| 224 | + protected function importable_file(Writing_On_GitHub_File_Info $file) { |
|
| 225 | 225 | |
| 226 | 226 | // only _pages and _posts |
| 227 | - if ( strncasecmp($file->path, '_pages/', strlen('_pages/') ) != 0 && |
|
| 228 | - strncasecmp($file->path, '_posts/', strlen('_posts/') ) != 0 && |
|
| 229 | - strncasecmp($file->path, 'images/', strlen('images/') ) != 0 ) { |
|
| 227 | + if (strncasecmp($file->path, '_pages/', strlen('_pages/')) != 0 && |
|
| 228 | + strncasecmp($file->path, '_posts/', strlen('_posts/')) != 0 && |
|
| 229 | + strncasecmp($file->path, 'images/', strlen('images/')) != 0) { |
|
| 230 | 230 | return false; |
| 231 | 231 | } |
| 232 | 232 | |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | * |
| 246 | 246 | * @return bool |
| 247 | 247 | */ |
| 248 | - protected function importable_blob( Writing_On_GitHub_Blob $blob ) { |
|
| 248 | + protected function importable_blob(Writing_On_GitHub_Blob $blob) { |
|
| 249 | 249 | // global $wpdb; |
| 250 | 250 | |
| 251 | 251 | // // Skip the repo's readme. |
@@ -258,20 +258,20 @@ discard block |
||
| 258 | 258 | // return false; |
| 259 | 259 | // } |
| 260 | 260 | |
| 261 | - if ( ! $blob->has_frontmatter() ) { |
|
| 261 | + if ( ! $blob->has_frontmatter()) { |
|
| 262 | 262 | return false; |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | return true; |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - protected function importable_raw_file( Writing_On_GitHub_Blob $blob ) { |
|
| 269 | - if ( $blob->has_frontmatter() ) { |
|
| 268 | + protected function importable_raw_file(Writing_On_GitHub_Blob $blob) { |
|
| 269 | + if ($blob->has_frontmatter()) { |
|
| 270 | 270 | return false; |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | // only images |
| 274 | - if ( strncasecmp($blob->path(), 'images/', strlen('images/') ) != 0) { |
|
| 274 | + if (strncasecmp($blob->path(), 'images/', strlen('images/')) != 0) { |
|
| 275 | 275 | return false; |
| 276 | 276 | } |
| 277 | 277 | |
@@ -283,16 +283,16 @@ discard block |
||
| 283 | 283 | * @param Writing_On_GitHub_Blob $blob |
| 284 | 284 | * @param bool $is_remove |
| 285 | 285 | */ |
| 286 | - protected function import_raw_file( Writing_On_GitHub_Blob $blob, $is_remove ) { |
|
| 286 | + protected function import_raw_file(Writing_On_GitHub_Blob $blob, $is_remove) { |
|
| 287 | 287 | $arr = wp_upload_dir(); |
| 288 | 288 | $path = $arr['basedir'] . '/writing-on-github/' . $blob->path(); |
| 289 | - if ( $is_remove ) { |
|
| 290 | - if ( file_exists($path) ) { |
|
| 289 | + if ($is_remove) { |
|
| 290 | + if (file_exists($path)) { |
|
| 291 | 291 | unlink($path); |
| 292 | 292 | } |
| 293 | 293 | } else { |
| 294 | 294 | $dirname = dirname($path); |
| 295 | - if ( ! file_exists($dirname) ) { |
|
| 295 | + if ( ! file_exists($dirname)) { |
|
| 296 | 296 | wp_mkdir_p($dirname); |
| 297 | 297 | } |
| 298 | 298 | |
@@ -307,57 +307,57 @@ discard block |
||
| 307 | 307 | * |
| 308 | 308 | * @return Writing_On_GitHub_Post |
| 309 | 309 | */ |
| 310 | - protected function blob_to_post( Writing_On_GitHub_Blob $blob ) { |
|
| 311 | - $args = array( 'post_content' => $blob->content_import() ); |
|
| 310 | + protected function blob_to_post(Writing_On_GitHub_Blob $blob) { |
|
| 311 | + $args = array('post_content' => $blob->content_import()); |
|
| 312 | 312 | $meta = $blob->meta(); |
| 313 | 313 | |
| 314 | 314 | $id = false; |
| 315 | 315 | |
| 316 | - if ( $meta ) { |
|
| 317 | - if ( array_key_exists( 'layout', $meta ) ) { |
|
| 316 | + if ($meta) { |
|
| 317 | + if (array_key_exists('layout', $meta)) { |
|
| 318 | 318 | $args['post_type'] = $meta['layout']; |
| 319 | - unset( $meta['layout'] ); |
|
| 319 | + unset($meta['layout']); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | - if ( array_key_exists( 'published', $meta ) ) { |
|
| 322 | + if (array_key_exists('published', $meta)) { |
|
| 323 | 323 | $args['post_status'] = true === $meta['published'] ? 'publish' : 'draft'; |
| 324 | - unset( $meta['published'] ); |
|
| 324 | + unset($meta['published']); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | - if ( array_key_exists( 'post_title', $meta ) ) { |
|
| 327 | + if (array_key_exists('post_title', $meta)) { |
|
| 328 | 328 | $args['post_title'] = $meta['post_title']; |
| 329 | - unset( $meta['post_title'] ); |
|
| 329 | + unset($meta['post_title']); |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | - if ( array_key_exists( 'post_name', $meta ) ) { |
|
| 332 | + if (array_key_exists('post_name', $meta)) { |
|
| 333 | 333 | $args['post_name'] = $meta['post_name']; |
| 334 | - unset( $meta['post_name'] ); |
|
| 334 | + unset($meta['post_name']); |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | - if ( array_key_exists( 'ID', $meta ) ) { |
|
| 337 | + if (array_key_exists('ID', $meta)) { |
|
| 338 | 338 | $id = $args['ID'] = $meta['ID']; |
| 339 | 339 | $blob->set_id($id); |
| 340 | - unset( $meta['ID'] ); |
|
| 340 | + unset($meta['ID']); |
|
| 341 | 341 | } |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | $meta['_wogh_sha'] = $blob->sha(); |
| 345 | 345 | |
| 346 | - if ( $id ) { |
|
| 347 | - $old_sha = get_post_meta( $id, '_wogh_sha', true ); |
|
| 348 | - $old_github_path = get_post_meta( $id, '_wogh_github_path', true ); |
|
| 346 | + if ($id) { |
|
| 347 | + $old_sha = get_post_meta($id, '_wogh_sha', true); |
|
| 348 | + $old_github_path = get_post_meta($id, '_wogh_github_path', true); |
|
| 349 | 349 | |
| 350 | 350 | // dont save post when has same sha |
| 351 | - if ( $old_sha && $old_sha == $meta['_wogh_sha'] && |
|
| 352 | - $old_github_path && $old_github_path == $blob->path() ) { |
|
| 351 | + if ($old_sha && $old_sha == $meta['_wogh_sha'] && |
|
| 352 | + $old_github_path && $old_github_path == $blob->path()) { |
|
| 353 | 353 | return false; |
| 354 | 354 | } |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - $post = new Writing_On_GitHub_Post( $args, $this->app->api() ); |
|
| 358 | - $post->set_old_github_path( $blob->path() ); |
|
| 359 | - $post->set_meta( $meta ); |
|
| 360 | - $blob->set_id( $post->id() ); |
|
| 357 | + $post = new Writing_On_GitHub_Post($args, $this->app->api()); |
|
| 358 | + $post->set_old_github_path($blob->path()); |
|
| 359 | + $post->set_meta($meta); |
|
| 360 | + $blob->set_id($post->id()); |
|
| 361 | 361 | |
| 362 | 362 | return $post; |
| 363 | 363 | } |
@@ -5,8 +5,8 @@ |
||
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | ?> |
| 8 | -<?php $value = get_option( $args['name'], $args['default'] ); ?> |
|
| 9 | -<textarea name="<?php echo esc_attr( $args['name'] ); ?>" id="<?php echo esc_attr( $args['name'] ); ?>" rows="10" cols="40"> |
|
| 10 | -<?php echo esc_attr( $value ); ?> |
|
| 8 | +<?php $value = get_option($args['name'], $args['default']); ?> |
|
| 9 | +<textarea name="<?php echo esc_attr($args['name']); ?>" id="<?php echo esc_attr($args['name']); ?>" rows="10" cols="40"> |
|
| 10 | +<?php echo esc_attr($value); ?> |
|
| 11 | 11 | </textarea> |
| 12 | 12 | <p class="description"><?php echo $args['help_text']; ?></p> |