1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class Jetpack_Keyring_Service_Helper { |
4
|
|
|
/** |
5
|
|
|
* @var Jetpack_Keyring_Service_Helper |
6
|
|
|
**/ |
7
|
|
|
private static $instance = null; |
8
|
|
|
|
9
|
|
|
static function init() { |
10
|
|
|
if ( is_null( self::$instance ) ) { |
11
|
|
|
self::$instance = new Jetpack_Keyring_Service_Helper; |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
return self::$instance; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public static $SERVICES = array( |
18
|
|
|
'facebook', |
19
|
|
|
'twitter', |
20
|
|
|
'linkedin', |
21
|
|
|
'tumblr', |
22
|
|
|
'path', |
23
|
|
|
'google_plus', |
24
|
|
|
'google_site_verification', |
25
|
|
|
); |
26
|
|
|
|
27
|
|
|
private function __construct() { |
28
|
|
|
add_action( 'load-settings_page_sharing', array( __CLASS__, 'admin_page_load' ), 9 ); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
function get_services( $filter = 'all' ) { |
32
|
|
|
$services = array( |
33
|
|
|
|
34
|
|
|
); |
35
|
|
|
|
36
|
|
View Code Duplication |
if ( 'all' == $filter ) { |
37
|
|
|
return $services; |
38
|
|
|
} else { |
39
|
|
|
$connected_services = array(); |
40
|
|
|
foreach ( $services as $service => $empty ) { |
41
|
|
|
$connections = $this->get_connections( $service ); |
|
|
|
|
42
|
|
|
if ( $connections ) { |
43
|
|
|
$connected_services[ $service ] = $connections; |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
return $connected_services; |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Gets a URL to the public-api actions. Works like WP's admin_url |
52
|
|
|
* |
53
|
|
|
* @param string $service Shortname of a specific service. |
54
|
|
|
* |
55
|
|
|
* @return URL to specific public-api process |
56
|
|
|
*/ |
57
|
|
|
// on WordPress.com this is/calls Keyring::admin_url |
58
|
|
|
static function api_url( $service = false, $params = array() ) { |
59
|
|
|
/** |
60
|
|
|
* Filters the API URL used to interact with WordPress.com. |
61
|
|
|
* |
62
|
|
|
* @since 2.0.0 |
63
|
|
|
* |
64
|
|
|
* @param string https://public-api.wordpress.com/connect/?jetpack=publicize Default Publicize API URL. |
65
|
|
|
*/ |
66
|
|
|
$url = apply_filters( 'publicize_api_url', 'https://public-api.wordpress.com/connect/?jetpack=publicize' ); |
67
|
|
|
|
68
|
|
|
if ( $service ) { |
69
|
|
|
$url = add_query_arg( array( 'service' => $service ), $url ); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
if ( count( $params ) ) { |
73
|
|
|
$url = add_query_arg( $params, $url ); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $url; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
View Code Duplication |
static function connect_url( $service_name ) { |
80
|
|
|
return add_query_arg( array( |
81
|
|
|
'action' => 'request', |
82
|
|
|
'service' => $service_name, |
83
|
|
|
'kr_nonce' => wp_create_nonce( 'keyring-request' ), |
84
|
|
|
'nonce' => wp_create_nonce( "keyring-request-$service_name" ), |
85
|
|
|
), menu_page_url( 'sharing', false ) ); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
static function refresh_url( $service_name ) { |
89
|
|
|
return add_query_arg( array( |
90
|
|
|
'action' => 'request', |
91
|
|
|
'service' => $service_name, |
92
|
|
|
'kr_nonce' => wp_create_nonce( 'keyring-request' ), |
93
|
|
|
'refresh' => 1, |
94
|
|
|
'for' => 'publicize', |
95
|
|
|
'nonce' => wp_create_nonce( "keyring-request-$service_name" ), |
96
|
|
|
), admin_url( 'options-general.php?page=sharing' ) ); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
View Code Duplication |
static function disconnect_url( $service_name, $id ) { |
100
|
|
|
return add_query_arg( array( |
101
|
|
|
'action' => 'delete', |
102
|
|
|
'service' => $service_name, |
103
|
|
|
'id' => $id, |
104
|
|
|
'kr_nonce' => wp_create_nonce( 'keyring-request' ), |
105
|
|
|
'nonce' => wp_create_nonce( "keyring-request-$service_name" ), |
106
|
|
|
), menu_page_url( 'sharing', false ) ); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
static function admin_page_load() { |
110
|
|
|
if ( isset( $_GET['action'] ) ) { |
111
|
|
|
if ( isset( $_GET['service'] ) ) { |
112
|
|
|
$service_name = $_GET['service']; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
switch ( $_GET['action'] ) { |
116
|
|
|
|
117
|
|
|
case 'request': |
118
|
|
|
check_admin_referer( 'keyring-request', 'kr_nonce' ); |
119
|
|
|
check_admin_referer( "keyring-request-$service_name", 'nonce' ); |
|
|
|
|
120
|
|
|
|
121
|
|
|
$verification = Jetpack::generate_secrets( 'publicize' ); |
122
|
|
|
if ( ! $verification ) { |
|
|
|
|
123
|
|
|
$url = Jetpack::admin_url( 'jetpack#/settings' ); |
124
|
|
|
wp_die( sprintf( __( "Jetpack is not connected. Please connect Jetpack by visiting <a href='%s'>Settings</a>.", 'jetpack' ), $url ) ); |
125
|
|
|
|
126
|
|
|
} |
127
|
|
|
$stats_options = get_option( 'stats_options' ); |
128
|
|
|
$wpcom_blog_id = Jetpack_Options::get_option( 'id' ); |
129
|
|
|
$wpcom_blog_id = ! empty( $wpcom_blog_id ) ? $wpcom_blog_id : $stats_options['blog_id']; |
130
|
|
|
|
131
|
|
|
$user = wp_get_current_user(); |
132
|
|
|
$redirect = Jetpack_Keyring_Service_Helper::api_url( $service_name, urlencode_deep( array( |
133
|
|
|
'action' => 'request', |
134
|
|
|
'redirect_uri' => add_query_arg( array( 'action' => 'done' ), menu_page_url( 'sharing', false ) ), |
135
|
|
|
'for' => 'publicize', |
136
|
|
|
// required flag that says this connection is intended for publicize |
137
|
|
|
'siteurl' => site_url(), |
138
|
|
|
'state' => $user->ID, |
139
|
|
|
'blog_id' => $wpcom_blog_id, |
140
|
|
|
'secret_1' => $verification['secret_1'], |
141
|
|
|
'secret_2' => $verification['secret_2'], |
142
|
|
|
'eol' => $verification['exp'], |
143
|
|
|
) ) ); |
144
|
|
|
wp_redirect( $redirect ); |
145
|
|
|
exit; |
146
|
|
|
break; |
|
|
|
|
147
|
|
|
|
148
|
|
|
case 'completed': |
149
|
|
|
Jetpack::load_xml_rpc_client(); |
150
|
|
|
$xml = new Jetpack_IXR_Client(); |
151
|
|
|
$xml->query( 'jetpack.fetchPublicizeConnections' ); |
152
|
|
|
|
153
|
|
|
if ( ! $xml->isError() ) { |
154
|
|
|
$response = $xml->getResponse(); |
155
|
|
|
Jetpack_Options::update_option( 'publicize_connections', $response ); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
break; |
159
|
|
|
|
160
|
|
|
case 'delete': |
161
|
|
|
$id = $_GET['id']; |
162
|
|
|
|
163
|
|
|
check_admin_referer( 'keyring-request', 'kr_nonce' ); |
164
|
|
|
check_admin_referer( "keyring-request-$service_name", 'nonce' ); |
165
|
|
|
|
166
|
|
|
Jetpack_Keyring_Service_Helper::disconnect( $service_name, $id ); |
167
|
|
|
|
168
|
|
|
do_action( 'connection_disconnected', $service_name ); |
169
|
|
|
break; |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Remove a Publicize connection |
176
|
|
|
*/ |
177
|
|
|
static function disconnect( $service_name, $connection_id, $_blog_id = false, $_user_id = false, $force_delete = false ) { |
178
|
|
|
Jetpack::load_xml_rpc_client(); |
179
|
|
|
$xml = new Jetpack_IXR_Client(); |
180
|
|
|
$xml->query( 'jetpack.deletePublicizeConnection', $connection_id ); |
181
|
|
|
|
182
|
|
|
if ( ! $xml->isError() ) { |
183
|
|
|
Jetpack_Options::update_option( 'publicize_connections', $xml->getResponse() ); |
184
|
|
|
} else { |
185
|
|
|
return false; |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
} |
190
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.