@@ -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 | } |
@@ -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> |
@@ -1,8 +1,8 @@ |
||
1 | -<?php $value = get_option( $args['name'], $args['default'] ); ?> |
|
2 | -<select name="<?php echo esc_attr( $args['name'] ) ?>" id="<?php echo esc_attr( $args['name'] ) ?>"> |
|
3 | - <?php foreach ( get_users() as $user ) : ?> |
|
4 | - <option value="<?php echo esc_attr( $user->ID ); ?>"<?php echo (int) $value === $user->ID ? ' selected' : '';?>> |
|
5 | - <?php echo esc_html( $user->display_name ); ?> |
|
1 | +<?php $value = get_option($args['name'], $args['default']); ?> |
|
2 | +<select name="<?php echo esc_attr($args['name']) ?>" id="<?php echo esc_attr($args['name']) ?>"> |
|
3 | + <?php foreach (get_users() as $user) : ?> |
|
4 | + <option value="<?php echo esc_attr($user->ID); ?>"<?php echo (int) $value === $user->ID ? ' selected' : ''; ?>> |
|
5 | + <?php echo esc_html($user->display_name); ?> |
|
6 | 6 | </option> |
7 | 7 | <?php endforeach; ?> |
8 | 8 | </select> |
@@ -5,6 +5,6 @@ |
||
5 | 5 | */ |
6 | 6 | |
7 | 7 | ?> |
8 | -<?php $value = get_option( $args['name'], $args['default'] ); ?> |
|
9 | -<input name="<?php echo esc_attr( $args['name'] ); ?>" id="<?php echo esc_attr( $args['name'] ); ?>" type="<?php echo 'wogh_secret' === $args['name'] ? 'password' : 'text'; ?>" value="<?php echo esc_attr( $value ); ?>" /> |
|
8 | +<?php $value = get_option($args['name'], $args['default']); ?> |
|
9 | +<input name="<?php echo esc_attr($args['name']); ?>" id="<?php echo esc_attr($args['name']); ?>" type="<?php echo 'wogh_secret' === $args['name'] ? 'password' : 'text'; ?>" value="<?php echo esc_attr($value); ?>" /> |
|
10 | 10 | <p class="description"><?php echo $args['help_text']; ?></p> |
@@ -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 | } |
@@ -12,8 +12,8 @@ discard block |
||
12 | 12 | |
13 | 13 | // If the functions have already been autoloaded, don't reload. |
14 | 14 | // This fixes function duplication during unit testing. |
15 | -if ( defined( 'WRITING_ON_GITHUB_TEST' ) && WRITING_ON_GITHUB_TEST ) { |
|
16 | - $path = dirname( __FILE__ ) . '/vendor/autoload_52.php'; |
|
15 | +if (defined('WRITING_ON_GITHUB_TEST') && WRITING_ON_GITHUB_TEST) { |
|
16 | + $path = dirname(__FILE__) . '/vendor/autoload_52.php'; |
|
17 | 17 | include_once $path; |
18 | 18 | } |
19 | 19 | |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | // require_once(dirname(__FILE__) . '/views/options.php'); |
42 | 42 | // require_once(dirname(__FILE__) . '/views/user-setting-field.php'); |
43 | 43 | |
44 | -add_action( 'plugins_loaded', array( new Writing_On_GitHub, 'boot' ) ); |
|
44 | +add_action('plugins_loaded', array(new Writing_On_GitHub, 'boot')); |
|
45 | 45 | |
46 | 46 | class Writing_On_GitHub { |
47 | 47 | |
@@ -144,14 +144,14 @@ discard block |
||
144 | 144 | public function __construct() { |
145 | 145 | self::$instance = $this; |
146 | 146 | |
147 | - if ( is_admin() ) { |
|
147 | + if (is_admin()) { |
|
148 | 148 | $this->admin = new Writing_On_GitHub_Admin; |
149 | 149 | } |
150 | 150 | |
151 | - $this->controller = new Writing_On_GitHub_Controller( $this ); |
|
151 | + $this->controller = new Writing_On_GitHub_Controller($this); |
|
152 | 152 | |
153 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
154 | - WP_CLI::add_command( 'wogh', $this->cli() ); |
|
153 | + if (defined('WP_CLI') && WP_CLI) { |
|
154 | + WP_CLI::add_command('wogh', $this->cli()); |
|
155 | 155 | } |
156 | 156 | } |
157 | 157 | |
@@ -159,29 +159,29 @@ discard block |
||
159 | 159 | * Attaches the plugin's hooks into WordPress. |
160 | 160 | */ |
161 | 161 | public function boot() { |
162 | - register_activation_hook( __FILE__, array( $this, 'activate' ) ); |
|
163 | - add_action( 'admin_notices', array( $this, 'activation_notice' ) ); |
|
162 | + register_activation_hook(__FILE__, array($this, 'activate')); |
|
163 | + add_action('admin_notices', array($this, 'activation_notice')); |
|
164 | 164 | |
165 | - add_action( 'init', array( $this, 'l10n' ) ); |
|
165 | + add_action('init', array($this, 'l10n')); |
|
166 | 166 | |
167 | 167 | // Controller actions. |
168 | - add_action( 'save_post', array( $this->controller, 'export_post' ) ); |
|
169 | - add_action( 'delete_post', array( $this->controller, 'delete_post' ) ); |
|
170 | - add_action( 'wp_ajax_nopriv_wogh_push_request', array( $this->controller, 'pull_posts' ) ); |
|
171 | - add_action( 'wogh_export', array( $this->controller, 'export_all' ), 10, 1 ); |
|
172 | - add_action( 'wogh_import', array( $this->controller, 'import_master' ), 10, 1 ); |
|
173 | - add_filter( 'get_edit_post_link', array( $this, 'edit_post_link' ), 10, 3 ); |
|
168 | + add_action('save_post', array($this->controller, 'export_post')); |
|
169 | + add_action('delete_post', array($this->controller, 'delete_post')); |
|
170 | + add_action('wp_ajax_nopriv_wogh_push_request', array($this->controller, 'pull_posts')); |
|
171 | + add_action('wogh_export', array($this->controller, 'export_all'), 10, 1); |
|
172 | + add_action('wogh_import', array($this->controller, 'import_master'), 10, 1); |
|
173 | + add_filter('get_edit_post_link', array($this, 'edit_post_link'), 10, 3); |
|
174 | 174 | |
175 | - add_filter( 'wogh_post_meta', array( $this, 'ignore_post_meta' ), 10, 1 ); |
|
176 | - add_filter( 'wogh_pre_import_meta', array( $this, 'ignore_post_meta' ), 10, 1 ); |
|
175 | + add_filter('wogh_post_meta', array($this, 'ignore_post_meta'), 10, 1); |
|
176 | + add_filter('wogh_pre_import_meta', array($this, 'ignore_post_meta'), 10, 1); |
|
177 | 177 | |
178 | - do_action( 'wogh_boot', $this ); |
|
178 | + do_action('wogh_boot', $this); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | public function edit_post_link($link, $postID, $context) { |
182 | - if ( ! wp_is_post_revision( $postID ) ) { |
|
183 | - $post = new Writing_On_GitHub_Post( $postID, Writing_On_GitHub::$instance->api() ); |
|
184 | - if ( $post->is_on_github() ) { |
|
182 | + if ( ! wp_is_post_revision($postID)) { |
|
183 | + $post = new Writing_On_GitHub_Post($postID, Writing_On_GitHub::$instance->api()); |
|
184 | + if ($post->is_on_github()) { |
|
185 | 185 | return $post->github_edit_url(); |
186 | 186 | } |
187 | 187 | } |
@@ -216,29 +216,29 @@ discard block |
||
216 | 216 | * Init i18n files |
217 | 217 | */ |
218 | 218 | public function l10n() { |
219 | - load_plugin_textdomain( self::$text_domain ); |
|
219 | + load_plugin_textdomain(self::$text_domain); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
223 | 223 | * Sets and kicks off the export cronjob |
224 | 224 | */ |
225 | 225 | public function start_export() { |
226 | - $this->start_cron( 'export' ); |
|
226 | + $this->start_cron('export'); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
230 | 230 | * Sets and kicks off the import cronjob |
231 | 231 | */ |
232 | 232 | public function start_import() { |
233 | - $this->start_cron( 'import' ); |
|
233 | + $this->start_cron('import'); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
237 | 237 | * Enables the admin notice on initial activation |
238 | 238 | */ |
239 | 239 | public function activate() { |
240 | - if ( 'yes' !== get_option( '_wogh_fully_exported' ) ) { |
|
241 | - set_transient( '_wogh_activated', 'yes' ); |
|
240 | + if ('yes' !== get_option('_wogh_fully_exported')) { |
|
241 | + set_transient('_wogh_activated', 'yes'); |
|
242 | 242 | } |
243 | 243 | } |
244 | 244 | |
@@ -246,18 +246,18 @@ discard block |
||
246 | 246 | * Displays the activation admin notice |
247 | 247 | */ |
248 | 248 | public function activation_notice() { |
249 | - if ( ! get_transient( '_wogh_activated' ) ) { |
|
249 | + if ( ! get_transient('_wogh_activated')) { |
|
250 | 250 | return; |
251 | 251 | } |
252 | 252 | |
253 | - delete_transient( '_wogh_activated' ); |
|
253 | + delete_transient('_wogh_activated'); |
|
254 | 254 | |
255 | 255 | ?><div class="updated"> |
256 | 256 | <p> |
257 | 257 | <?php |
258 | 258 | printf( |
259 | - __( 'To set up your site to sync with GitHub, update your <a href="%s">settings</a> and click "Export to GitHub."', 'writing-on-github' ), |
|
260 | - admin_url( 'options-general.php?page=' . static::$text_domain) |
|
259 | + __('To set up your site to sync with GitHub, update your <a href="%s">settings</a> and click "Export to GitHub."', 'writing-on-github'), |
|
260 | + admin_url('options-general.php?page=' . static::$text_domain) |
|
261 | 261 | ); |
262 | 262 | ?> |
263 | 263 | </p> |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | * @return Writing_On_GitHub_CLI |
280 | 280 | */ |
281 | 281 | public function cli() { |
282 | - if ( ! $this->cli ) { |
|
282 | + if ( ! $this->cli) { |
|
283 | 283 | $this->cli = new Writing_On_GitHub_CLI; |
284 | 284 | } |
285 | 285 | |
@@ -292,8 +292,8 @@ discard block |
||
292 | 292 | * @return Writing_On_GitHub_Request |
293 | 293 | */ |
294 | 294 | public function request() { |
295 | - if ( ! $this->request ) { |
|
296 | - $this->request = new Writing_On_GitHub_Request( $this ); |
|
295 | + if ( ! $this->request) { |
|
296 | + $this->request = new Writing_On_GitHub_Request($this); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | return $this->request; |
@@ -305,8 +305,8 @@ discard block |
||
305 | 305 | * @return Writing_On_GitHub_Response |
306 | 306 | */ |
307 | 307 | public function response() { |
308 | - if ( ! $this->response ) { |
|
309 | - $this->response = new Writing_On_GitHub_Response( $this ); |
|
308 | + if ( ! $this->response) { |
|
309 | + $this->response = new Writing_On_GitHub_Response($this); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | return $this->response; |
@@ -318,8 +318,8 @@ discard block |
||
318 | 318 | * @return Writing_On_GitHub_Api |
319 | 319 | */ |
320 | 320 | public function api() { |
321 | - if ( ! $this->api ) { |
|
322 | - $this->api = new Writing_On_GitHub_Api( $this ); |
|
321 | + if ( ! $this->api) { |
|
322 | + $this->api = new Writing_On_GitHub_Api($this); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | return $this->api; |
@@ -331,8 +331,8 @@ discard block |
||
331 | 331 | * @return Writing_On_GitHub_Import |
332 | 332 | */ |
333 | 333 | public function import() { |
334 | - if ( ! $this->import ) { |
|
335 | - $this->import = new Writing_On_GitHub_Import( $this ); |
|
334 | + if ( ! $this->import) { |
|
335 | + $this->import = new Writing_On_GitHub_Import($this); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | return $this->import; |
@@ -344,8 +344,8 @@ discard block |
||
344 | 344 | * @return Writing_On_GitHub_Export |
345 | 345 | */ |
346 | 346 | public function export() { |
347 | - if ( ! $this->export ) { |
|
348 | - $this->export = new Writing_On_GitHub_Export( $this ); |
|
347 | + if ( ! $this->export) { |
|
348 | + $this->export = new Writing_On_GitHub_Export($this); |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | return $this->export; |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | * @return Writing_On_GitHub_Semaphore |
358 | 358 | */ |
359 | 359 | public function semaphore() { |
360 | - if ( ! $this->semaphore ) { |
|
360 | + if ( ! $this->semaphore) { |
|
361 | 361 | $this->semaphore = new Writing_On_GitHub_Semaphore; |
362 | 362 | } |
363 | 363 | |
@@ -370,8 +370,8 @@ discard block |
||
370 | 370 | * @return Writing_On_GitHub_Database |
371 | 371 | */ |
372 | 372 | public function database() { |
373 | - if ( ! $this->database ) { |
|
374 | - $this->database = new Writing_On_GitHub_Database( $this ); |
|
373 | + if ( ! $this->database) { |
|
374 | + $this->database = new Writing_On_GitHub_Database($this); |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | return $this->database; |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | * @return Writing_On_GitHub_Cache |
384 | 384 | */ |
385 | 385 | public function cache() { |
386 | - if ( ! $this->cache ) { |
|
386 | + if ( ! $this->cache) { |
|
387 | 387 | $this->cache = new Writing_On_GitHub_Cache; |
388 | 388 | } |
389 | 389 | |
@@ -398,18 +398,18 @@ discard block |
||
398 | 398 | * @param mixed $msg |
399 | 399 | * @param string $write |
400 | 400 | */ |
401 | - public static function write_log( $msg, $write = 'line' ) { |
|
402 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
403 | - if ( is_array( $msg ) || is_object( $msg ) ) { |
|
404 | - WP_CLI::print_value( $msg ); |
|
401 | + public static function write_log($msg, $write = 'line') { |
|
402 | + if (defined('WP_CLI') && WP_CLI) { |
|
403 | + if (is_array($msg) || is_object($msg)) { |
|
404 | + WP_CLI::print_value($msg); |
|
405 | 405 | } else { |
406 | - WP_CLI::$write( $msg ); |
|
406 | + WP_CLI::$write($msg); |
|
407 | 407 | } |
408 | - } elseif ( true === WP_DEBUG ) { |
|
409 | - if ( is_array( $msg ) || is_object( $msg ) ) { |
|
410 | - error_log( print_r( $msg, true ) ); |
|
408 | + } elseif (true === WP_DEBUG) { |
|
409 | + if (is_array($msg) || is_object($msg)) { |
|
410 | + error_log(print_r($msg, true)); |
|
411 | 411 | } else { |
412 | - error_log( $msg ); |
|
412 | + error_log($msg); |
|
413 | 413 | } |
414 | 414 | } |
415 | 415 | } |
@@ -419,10 +419,10 @@ discard block |
||
419 | 419 | * |
420 | 420 | * @param $type |
421 | 421 | */ |
422 | - protected function start_cron( $type ) { |
|
423 | - update_option( '_wogh_' . $type . '_started', 'yes' ); |
|
422 | + protected function start_cron($type) { |
|
423 | + update_option('_wogh_' . $type . '_started', 'yes'); |
|
424 | 424 | $user_id = get_current_user_id(); |
425 | - wp_schedule_single_event( time(), 'wogh_' . $type . '', array( $user_id ) ); |
|
425 | + wp_schedule_single_event(time(), 'wogh_' . $type . '', array($user_id)); |
|
426 | 426 | spawn_cron(); |
427 | 427 | } |
428 | 428 | } |
@@ -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> |