@@ -1,23 +1,23 @@ |
||
| 1 | 1 | <?php |
| 2 | -$_tests_dir = getenv( 'WP_TESTS_DIR' ); |
|
| 3 | -if ( ! $_tests_dir ) { |
|
| 2 | +$_tests_dir = getenv('WP_TESTS_DIR'); |
|
| 3 | +if ( ! $_tests_dir) { |
|
| 4 | 4 | $_tests_dir = '/tmp/wordpress-tests-lib'; |
| 5 | 5 | } |
| 6 | 6 | |
| 7 | -define( 'WRITING_ON_GITHUB_TEST', true ); |
|
| 7 | +define('WRITING_ON_GITHUB_TEST', true); |
|
| 8 | 8 | |
| 9 | 9 | require_once $_tests_dir . '/includes/functions.php'; |
| 10 | 10 | |
| 11 | 11 | function _manually_load_plugin() { |
| 12 | - require dirname( __FILE__ ) . '/../../writing-on-github.php'; |
|
| 13 | - remove_action( 'plugins_loaded', array( Writing_On_GitHub::$instance, 'boot' ) ); |
|
| 12 | + require dirname(__FILE__) . '/../../writing-on-github.php'; |
|
| 13 | + remove_action('plugins_loaded', array(Writing_On_GitHub::$instance, 'boot')); |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | -tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); |
|
| 16 | +tests_add_filter('muplugins_loaded', '_manually_load_plugin'); |
|
| 17 | 17 | |
| 18 | 18 | require $_tests_dir . '/includes/bootstrap.php'; |
| 19 | 19 | |
| 20 | -require dirname( __FILE__ ) . '/../../vendor/jdgrimes/wp-http-testcase/wp-http-testcase.php'; |
|
| 21 | -require dirname( __FILE__ ) . '/../../tests/include/testcase.php'; |
|
| 20 | +require dirname(__FILE__) . '/../../vendor/jdgrimes/wp-http-testcase/wp-http-testcase.php'; |
|
| 21 | +require dirname(__FILE__) . '/../../tests/include/testcase.php'; |
|
| 22 | 22 | |
| 23 | -error_reporting( E_ALL ^ E_DEPRECATED ); |
|
| 23 | +error_reporting(E_ALL ^ E_DEPRECATED); |
|
@@ -85,69 +85,69 @@ |
||
| 85 | 85 | public function setUp() { |
| 86 | 86 | parent::setUp(); |
| 87 | 87 | |
| 88 | - $this->data_dir = dirname( __DIR__ ) . '/data/'; |
|
| 89 | - |
|
| 90 | - $this->app = Mockery::mock( 'Writing_On_GitHub' ); |
|
| 91 | - $this->controller = Mockery::mock( 'Writing_On_GitHub_Controller' ); |
|
| 92 | - $this->request = Mockery::mock( 'Writing_On_GitHub_Request' ); |
|
| 93 | - $this->import = Mockery::mock( 'Writing_On_GitHub_Import' ); |
|
| 94 | - $this->export = Mockery::mock( 'Writing_On_GitHub_Export' ); |
|
| 95 | - $this->response = Mockery::mock( 'Writing_On_GitHub_Response' ); |
|
| 96 | - $this->payload = Mockery::mock( 'Writing_On_GitHub_Payload' ); |
|
| 97 | - $this->api = Mockery::mock( 'Writing_On_GitHub_Api' ); |
|
| 98 | - $this->semaphore = Mockery::mock( 'Writing_On_GitHub_Semaphore' ); |
|
| 99 | - $this->database = Mockery::mock( 'Writing_On_GitHub_Database' ); |
|
| 100 | - $this->post = Mockery::mock( 'Writing_On_GitHub_Post' ); |
|
| 101 | - $this->blob = Mockery::mock( 'Writing_On_GitHub_Blob' ); |
|
| 102 | - $this->api_cache = Mockery::mock( 'Writing_On_GitHub_Cache' ); |
|
| 103 | - $this->fetch = Mockery::mock( 'Writing_On_GitHub_Fetch_Client' ); |
|
| 104 | - $this->persist = Mockery::mock( 'Writing_On_GitHub_Persist_Client' ); |
|
| 88 | + $this->data_dir = dirname(__DIR__) . '/data/'; |
|
| 89 | + |
|
| 90 | + $this->app = Mockery::mock('Writing_On_GitHub'); |
|
| 91 | + $this->controller = Mockery::mock('Writing_On_GitHub_Controller'); |
|
| 92 | + $this->request = Mockery::mock('Writing_On_GitHub_Request'); |
|
| 93 | + $this->import = Mockery::mock('Writing_On_GitHub_Import'); |
|
| 94 | + $this->export = Mockery::mock('Writing_On_GitHub_Export'); |
|
| 95 | + $this->response = Mockery::mock('Writing_On_GitHub_Response'); |
|
| 96 | + $this->payload = Mockery::mock('Writing_On_GitHub_Payload'); |
|
| 97 | + $this->api = Mockery::mock('Writing_On_GitHub_Api'); |
|
| 98 | + $this->semaphore = Mockery::mock('Writing_On_GitHub_Semaphore'); |
|
| 99 | + $this->database = Mockery::mock('Writing_On_GitHub_Database'); |
|
| 100 | + $this->post = Mockery::mock('Writing_On_GitHub_Post'); |
|
| 101 | + $this->blob = Mockery::mock('Writing_On_GitHub_Blob'); |
|
| 102 | + $this->api_cache = Mockery::mock('Writing_On_GitHub_Cache'); |
|
| 103 | + $this->fetch = Mockery::mock('Writing_On_GitHub_Fetch_Client'); |
|
| 104 | + $this->persist = Mockery::mock('Writing_On_GitHub_Persist_Client'); |
|
| 105 | 105 | |
| 106 | 106 | Writing_On_GitHub::$instance = $this->app; |
| 107 | 107 | |
| 108 | 108 | $this->app |
| 109 | - ->shouldReceive( 'request' ) |
|
| 110 | - ->andReturn( $this->request ) |
|
| 109 | + ->shouldReceive('request') |
|
| 110 | + ->andReturn($this->request) |
|
| 111 | 111 | ->byDefault(); |
| 112 | 112 | $this->app |
| 113 | - ->shouldReceive( 'import' ) |
|
| 114 | - ->andReturn( $this->import ) |
|
| 113 | + ->shouldReceive('import') |
|
| 114 | + ->andReturn($this->import) |
|
| 115 | 115 | ->byDefault(); |
| 116 | 116 | $this->app |
| 117 | - ->shouldReceive( 'export' ) |
|
| 118 | - ->andReturn( $this->export ) |
|
| 117 | + ->shouldReceive('export') |
|
| 118 | + ->andReturn($this->export) |
|
| 119 | 119 | ->byDefault(); |
| 120 | 120 | $this->app |
| 121 | - ->shouldReceive( 'response' ) |
|
| 122 | - ->andReturn( $this->response ) |
|
| 121 | + ->shouldReceive('response') |
|
| 122 | + ->andReturn($this->response) |
|
| 123 | 123 | ->byDefault(); |
| 124 | 124 | $this->app |
| 125 | - ->shouldReceive( 'api' ) |
|
| 126 | - ->andReturn( $this->api ) |
|
| 125 | + ->shouldReceive('api') |
|
| 126 | + ->andReturn($this->api) |
|
| 127 | 127 | ->byDefault(); |
| 128 | 128 | $this->app |
| 129 | - ->shouldReceive( 'semaphore' ) |
|
| 130 | - ->andReturn( $this->semaphore ) |
|
| 129 | + ->shouldReceive('semaphore') |
|
| 130 | + ->andReturn($this->semaphore) |
|
| 131 | 131 | ->byDefault(); |
| 132 | 132 | $this->app |
| 133 | - ->shouldReceive( 'database' ) |
|
| 134 | - ->andReturn( $this->database ) |
|
| 133 | + ->shouldReceive('database') |
|
| 134 | + ->andReturn($this->database) |
|
| 135 | 135 | ->byDefault(); |
| 136 | 136 | $this->app |
| 137 | - ->shouldReceive( 'blob' ) |
|
| 138 | - ->andReturn( $this->blob ) |
|
| 137 | + ->shouldReceive('blob') |
|
| 138 | + ->andReturn($this->blob) |
|
| 139 | 139 | ->byDefault(); |
| 140 | 140 | $this->app |
| 141 | - ->shouldReceive( 'cache' ) |
|
| 142 | - ->andReturn( $this->api_cache ) |
|
| 141 | + ->shouldReceive('cache') |
|
| 142 | + ->andReturn($this->api_cache) |
|
| 143 | 143 | ->byDefault(); |
| 144 | 144 | $this->api |
| 145 | - ->shouldReceive( 'fetch' ) |
|
| 146 | - ->andReturn( $this->fetch ) |
|
| 145 | + ->shouldReceive('fetch') |
|
| 146 | + ->andReturn($this->fetch) |
|
| 147 | 147 | ->byDefault(); |
| 148 | 148 | $this->api |
| 149 | - ->shouldReceive( 'persist' ) |
|
| 150 | - ->andReturn( $this->persist ) |
|
| 149 | + ->shouldReceive('persist') |
|
| 150 | + ->andReturn($this->persist) |
|
| 151 | 151 | ->byDefault(); |
| 152 | 152 | } |
| 153 | 153 | |
@@ -31,10 +31,10 @@ discard block |
||
| 31 | 31 | parent::setUp(); |
| 32 | 32 | |
| 33 | 33 | WP_HTTP_TestCase::init(); |
| 34 | - update_option( 'wogh_repository', self::REPO_OPTION_VALUE ); |
|
| 35 | - update_option( 'wogh_oauth_token', self::TOKEN_OPTION_VALUE ); |
|
| 36 | - update_option( 'wogh_host', self::HOST_OPTION_VALUE ); |
|
| 37 | - $this->http_responder = array( $this, 'mock_github_api' ); |
|
| 34 | + update_option('wogh_repository', self::REPO_OPTION_VALUE); |
|
| 35 | + update_option('wogh_oauth_token', self::TOKEN_OPTION_VALUE); |
|
| 36 | + update_option('wogh_host', self::HOST_OPTION_VALUE); |
|
| 37 | + $this->http_responder = array($this, 'mock_github_api'); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -43,45 +43,45 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @return void|string |
| 45 | 45 | */ |
| 46 | - public function mock_github_api( $request, $url ) { |
|
| 47 | - $host_length = strlen( self::HOST_OPTION_VALUE ); |
|
| 46 | + public function mock_github_api($request, $url) { |
|
| 47 | + $host_length = strlen(self::HOST_OPTION_VALUE); |
|
| 48 | 48 | |
| 49 | - if ( self::HOST_OPTION_VALUE !== substr( $url, 0, $host_length ) ) { |
|
| 50 | - $this->assertTrue( false, 'Called wrong host.' ); |
|
| 49 | + if (self::HOST_OPTION_VALUE !== substr($url, 0, $host_length)) { |
|
| 50 | + $this->assertTrue(false, 'Called wrong host.'); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | if ( |
| 54 | - ! isset( $request['headers']['Authorization'] ) || |
|
| 54 | + ! isset($request['headers']['Authorization']) || |
|
| 55 | 55 | 'token ' . self::TOKEN_OPTION_VALUE !== $request['headers']['Authorization'] |
| 56 | 56 | ) { |
| 57 | - $this->assertTrue( false, 'Missing authorization key.' ); |
|
| 57 | + $this->assertTrue(false, 'Missing authorization key.'); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - $url = explode( '/', substr( $url, $host_length + 1 ) ); |
|
| 60 | + $url = explode('/', substr($url, $host_length + 1)); |
|
| 61 | 61 | |
| 62 | - if ( 'repos' !== $url[0] ) { |
|
| 63 | - $this->assertTrue( false, 'Called wrong endpoint.' ); |
|
| 62 | + if ('repos' !== $url[0]) { |
|
| 63 | + $this->assertTrue(false, 'Called wrong endpoint.'); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | $repo = $url[1] . '/' . $url[2]; |
| 67 | 67 | |
| 68 | - if ( self::REPO_OPTION_VALUE !== $repo ) { |
|
| 69 | - $this->assertTrue( false, 'Called wrong repo.' ); |
|
| 68 | + if (self::REPO_OPTION_VALUE !== $repo) { |
|
| 69 | + $this->assertTrue(false, 'Called wrong repo.'); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - $parts = array_slice( $url, 4 ); |
|
| 73 | - array_unshift( $parts, strtolower( $request['method'] ) ); |
|
| 74 | - $endpoint = implode( '_', $parts ); |
|
| 75 | - $endpoint = str_replace( '?recursive=1', '', $endpoint ); |
|
| 76 | - $this->assertTrue( call_user_func( static::$validations[ $endpoint ], $request ), 'Request did not validate.' ); |
|
| 72 | + $parts = array_slice($url, 4); |
|
| 73 | + array_unshift($parts, strtolower($request['method'])); |
|
| 74 | + $endpoint = implode('_', $parts); |
|
| 75 | + $endpoint = str_replace('?recursive=1', '', $endpoint); |
|
| 76 | + $this->assertTrue(call_user_func(static::$validations[$endpoint], $request), 'Request did not validate.'); |
|
| 77 | 77 | |
| 78 | - return static::$responses[ $endpoint ]; |
|
| 78 | + return static::$responses[$endpoint]; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - protected function set_get_refs_heads_master( $succeed ) { |
|
| 81 | + protected function set_get_refs_heads_master($succeed) { |
|
| 82 | 82 | $this->set_endpoint( |
| 83 | - function ( $request ) { |
|
| 84 | - if ( '[]' === $request['body'] ) { |
|
| 83 | + function($request) { |
|
| 84 | + if ('[]' === $request['body']) { |
|
| 85 | 85 | return false; |
| 86 | 86 | } |
| 87 | 87 | |
@@ -90,10 +90,10 @@ discard block |
||
| 90 | 90 | ); |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - protected function set_get_commits( $succeed ) { |
|
| 93 | + protected function set_get_commits($succeed) { |
|
| 94 | 94 | $this->set_endpoint( |
| 95 | - function ( $request ) { |
|
| 96 | - if ( '[]' === $request['body'] ) { |
|
| 95 | + function($request) { |
|
| 96 | + if ('[]' === $request['body']) { |
|
| 97 | 97 | return false; |
| 98 | 98 | } |
| 99 | 99 | |
@@ -102,10 +102,10 @@ discard block |
||
| 102 | 102 | ); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - protected function set_get_trees( $succeed, $sha = '' ) { |
|
| 105 | + protected function set_get_trees($succeed, $sha = '') { |
|
| 106 | 106 | $this->set_endpoint( |
| 107 | - function ( $request ) { |
|
| 108 | - if ( '[]' === $request['body'] ) { |
|
| 107 | + function($request) { |
|
| 108 | + if ('[]' === $request['body']) { |
|
| 109 | 109 | return false; |
| 110 | 110 | } |
| 111 | 111 | |
@@ -115,17 +115,17 @@ discard block |
||
| 115 | 115 | ); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - protected function set_get_blobs( $succeed ) { |
|
| 118 | + protected function set_get_blobs($succeed) { |
|
| 119 | 119 | $shas = array( |
| 120 | 120 | '9fa5c7537f8582b71028ff34b8c20dfd0f3b2a25', |
| 121 | 121 | '8d9b2e6fd93761211dc03abd71f4a9189d680fd0', |
| 122 | 122 | '2d73165945b0ccbe4932f1363457986b0ed49f19', |
| 123 | 123 | ); |
| 124 | 124 | |
| 125 | - foreach ( $shas as $sha ) { |
|
| 125 | + foreach ($shas as $sha) { |
|
| 126 | 126 | $this->set_endpoint( |
| 127 | - function ( $request ) { |
|
| 128 | - if ( '[]' === $request['body'] ) { |
|
| 127 | + function($request) { |
|
| 128 | + if ('[]' === $request['body']) { |
|
| 129 | 129 | return false; |
| 130 | 130 | } |
| 131 | 131 | |
@@ -135,26 +135,26 @@ discard block |
||
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - protected function set_post_trees( $succeed ) { |
|
| 138 | + protected function set_post_trees($succeed) { |
|
| 139 | 139 | $this->set_endpoint( |
| 140 | - function ( $request ) { |
|
| 141 | - $body = json_decode( $request['body'], true ); |
|
| 140 | + function($request) { |
|
| 141 | + $body = json_decode($request['body'], true); |
|
| 142 | 142 | |
| 143 | - if ( ! isset( $body['tree'] ) ) { |
|
| 143 | + if ( ! isset($body['tree'])) { |
|
| 144 | 144 | return false; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - if ( 1 !== count( $body['tree'] ) ) { |
|
| 147 | + if (1 !== count($body['tree'])) { |
|
| 148 | 148 | return false; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - $blob = reset( $body['tree'] ); |
|
| 151 | + $blob = reset($body['tree']); |
|
| 152 | 152 | |
| 153 | 153 | if ( |
| 154 | - ! isset( $blob['path'] ) || |
|
| 155 | - ! isset( $blob['type'] ) || |
|
| 156 | - ! isset( $blob['content'] ) || |
|
| 157 | - ! isset( $blob['mode'] ) |
|
| 154 | + ! isset($blob['path']) || |
|
| 155 | + ! isset($blob['type']) || |
|
| 156 | + ! isset($blob['content']) || |
|
| 157 | + ! isset($blob['mode']) |
|
| 158 | 158 | ) { |
| 159 | 159 | return false; |
| 160 | 160 | } |
@@ -166,25 +166,25 @@ discard block |
||
| 166 | 166 | ); |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - protected function set_post_commits( $succeed, $anonymous = true ) { |
|
| 169 | + protected function set_post_commits($succeed, $anonymous = true) { |
|
| 170 | 170 | $this->set_endpoint( |
| 171 | - function ( $request ) use ( $anonymous ) { |
|
| 172 | - $body = json_decode( $request['body'], true ); |
|
| 171 | + function($request) use ($anonymous) { |
|
| 172 | + $body = json_decode($request['body'], true); |
|
| 173 | 173 | |
| 174 | 174 | if ( |
| 175 | - ! isset( $body['tree'] ) || |
|
| 176 | - ! isset( $body['message'] ) || |
|
| 177 | - ! isset( $body['parents'] ) || |
|
| 178 | - ! isset( $body['author'] ) |
|
| 175 | + ! isset($body['tree']) || |
|
| 176 | + ! isset($body['message']) || |
|
| 177 | + ! isset($body['parents']) || |
|
| 178 | + ! isset($body['author']) |
|
| 179 | 179 | ) { |
| 180 | 180 | return false; |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - if ( 1 !== count( $body['parents'] ) ) { |
|
| 183 | + if (1 !== count($body['parents'])) { |
|
| 184 | 184 | return false; |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - if ( ! $anonymous ) { |
|
| 187 | + if ( ! $anonymous) { |
|
| 188 | 188 | if ( |
| 189 | 189 | 'James DiGioia' !== $body['author']['name'] || |
| 190 | 190 | '[email protected]' !== $body['author']['email'] |
@@ -207,12 +207,12 @@ discard block |
||
| 207 | 207 | ); |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - protected function set_patch_refs_heads_master( $succeed ) { |
|
| 210 | + protected function set_patch_refs_heads_master($succeed) { |
|
| 211 | 211 | $this->set_endpoint( |
| 212 | - function ( $request ) { |
|
| 213 | - $body = json_decode( $request['body'], true ); |
|
| 212 | + function($request) { |
|
| 213 | + $body = json_decode($request['body'], true); |
|
| 214 | 214 | |
| 215 | - if ( ! isset( $body['sha'] ) ) { |
|
| 215 | + if ( ! isset($body['sha'])) { |
|
| 216 | 216 | return false; |
| 217 | 217 | } |
| 218 | 218 | |
@@ -223,18 +223,18 @@ discard block |
||
| 223 | 223 | ); |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - private function set_endpoint( $validation, $status, $succeed, $sha = '' ) { |
|
| 227 | - list( , $caller ) = debug_backtrace( false ); |
|
| 228 | - $endpoint = substr( $caller['function'], 4 ) . ( $sha ? "_$sha" : '' ); |
|
| 226 | + private function set_endpoint($validation, $status, $succeed, $sha = '') { |
|
| 227 | + list(, $caller) = debug_backtrace(false); |
|
| 228 | + $endpoint = substr($caller['function'], 4) . ($sha ? "_$sha" : ''); |
|
| 229 | 229 | |
| 230 | - static::$validations[ $endpoint ] = $validation; |
|
| 230 | + static::$validations[$endpoint] = $validation; |
|
| 231 | 231 | |
| 232 | - static::$responses[ $endpoint ] = array( |
|
| 232 | + static::$responses[$endpoint] = array( |
|
| 233 | 233 | 'headers' => array( |
| 234 | 234 | 'status' => $status, |
| 235 | 235 | ), |
| 236 | 236 | 'body' => file_get_contents( |
| 237 | - $this->data_dir . $endpoint . '_' . ( $succeed ? 'succeed' : 'fail' ) . '.json' |
|
| 237 | + $this->data_dir . $endpoint . '_' . ($succeed ? 'succeed' : 'fail') . '.json' |
|
| 238 | 238 | ), |
| 239 | 239 | ); |
| 240 | 240 | } |
@@ -6,24 +6,24 @@ |
||
| 6 | 6 | |
| 7 | 7 | ?> |
| 8 | 8 | <div class="wrap"> |
| 9 | - <h2><?php esc_html_e( 'Writing On GitHub', 'writing-on-github' ); ?></h2> |
|
| 9 | + <h2><?php esc_html_e('Writing On GitHub', 'writing-on-github'); ?></h2> |
|
| 10 | 10 | |
| 11 | 11 | <form method="post" action="options.php"> |
| 12 | - <?php settings_fields( Writing_On_GitHub::$text_domain ); ?> |
|
| 13 | - <?php do_settings_sections( Writing_On_GitHub::$text_domain ); ?> |
|
| 12 | + <?php settings_fields(Writing_On_GitHub::$text_domain); ?> |
|
| 13 | + <?php do_settings_sections(Writing_On_GitHub::$text_domain); ?> |
|
| 14 | 14 | <table class="form-table"> |
| 15 | 15 | <tr> |
| 16 | - <th scope="row"><?php esc_html_e( 'Webhook callback', 'writing-on-github' ); ?></th> |
|
| 17 | - <td><code><?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>?action=wogh_push_request</code></td> |
|
| 16 | + <th scope="row"><?php esc_html_e('Webhook callback', 'writing-on-github'); ?></th> |
|
| 17 | + <td><code><?php echo esc_url(admin_url('admin-ajax.php')); ?>?action=wogh_push_request</code></td> |
|
| 18 | 18 | </tr> |
| 19 | 19 | <tr> |
| 20 | - <th scope="row"><?php esc_html_e( 'Bulk actions', 'writing-on-github' ); ?></th> |
|
| 20 | + <th scope="row"><?php esc_html_e('Bulk actions', 'writing-on-github'); ?></th> |
|
| 21 | 21 | <td> |
| 22 | - <a href="<?php echo esc_url( add_query_arg( array( 'action' => 'export' ) ) ); ?>"> |
|
| 23 | - <?php esc_html_e( 'Export to GitHub', 'writing-on-github' ); ?> |
|
| 22 | + <a href="<?php echo esc_url(add_query_arg(array('action' => 'export'))); ?>"> |
|
| 23 | + <?php esc_html_e('Export to GitHub', 'writing-on-github'); ?> |
|
| 24 | 24 | </a> | |
| 25 | - <a href="<?php echo esc_url( add_query_arg( array( 'action' => 'import' ) ) ); ?>"> |
|
| 26 | - <?php esc_html_e( 'Import from GitHub', 'writing-on-github' ); ?> |
|
| 25 | + <a href="<?php echo esc_url(add_query_arg(array('action' => 'import'))); ?>"> |
|
| 26 | + <?php esc_html_e('Import from GitHub', 'writing-on-github'); ?> |
|
| 27 | 27 | </a> |
| 28 | 28 | </td> |
| 29 | 29 | </table> |
@@ -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,14 +146,14 @@ 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 ( isset( $meta['permalink'] ) ) { |
|
| 156 | - $meta['permalink'] = str_replace( home_url(), '', $meta['permalink'] ); |
|
| 154 | + $meta = spyc_load($matches[2]); |
|
| 155 | + if (isset($meta['permalink'])) { |
|
| 156 | + $meta['permalink'] = str_replace(home_url(), '', $meta['permalink']); |
|
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | // $data->type = 'blob'; |
| 196 | 196 | |
| 197 | 197 | $data->path = $this->path(); |
| 198 | - $data->content = base64_encode( $this->content() ); |
|
| 198 | + $data->content = base64_encode($this->content()); |
|
| 199 | 199 | $data->sha = $this->sha; |
| 200 | 200 | |
| 201 | 201 | return $data; |
@@ -204,13 +204,13 @@ discard block |
||
| 204 | 204 | /** |
| 205 | 205 | * Interprets the blob's data into properties. |
| 206 | 206 | */ |
| 207 | - protected function interpret_data( $data ) { |
|
| 208 | - $this->sha = isset( $data->sha ) ? $data->sha : ''; |
|
| 209 | - $this->path = isset( $data->path ) ? $data->path : ''; |
|
| 207 | + protected function interpret_data($data) { |
|
| 208 | + $this->sha = isset($data->sha) ? $data->sha : ''; |
|
| 209 | + $this->path = isset($data->path) ? $data->path : ''; |
|
| 210 | 210 | |
| 211 | 211 | $this->set_content( |
| 212 | - isset( $data->content ) ? trim( $data->content ) : '', |
|
| 213 | - isset( $data->encoding ) && 'base64' === $data->encoding ? true : false |
|
| 212 | + isset($data->content) ? trim($data->content) : '', |
|
| 213 | + isset($data->encoding) && 'base64' === $data->encoding ? true : false |
|
| 214 | 214 | ); |
| 215 | 215 | } |
| 216 | 216 | } |
@@ -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 | } |
@@ -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 | } |