1 | <?php |
||
16 | class Manager implements Manager_Interface { |
||
17 | |||
18 | const SECRETS_MISSING = 'secrets_missing'; |
||
19 | const SECRETS_EXPIRED = 'secrets_expired'; |
||
20 | |||
21 | /** |
||
22 | * The object for managing options. |
||
23 | * |
||
24 | * @var \Automattic\Jetpack\Options\Manager |
||
25 | */ |
||
26 | protected $option_manager; |
||
27 | |||
28 | /** |
||
29 | * The procedure that should be run to generate secrets. |
||
30 | * |
||
31 | * @var Callable |
||
32 | */ |
||
33 | protected $secret_callable; |
||
34 | |||
35 | /** |
||
36 | * Initializes all needed hooks and request handlers. Handles API calls, upload |
||
37 | * requests, authentication requests. Also XMLRPC options requests. |
||
38 | * Fallback XMLRPC is also a bridge, but probably can be a class that inherits |
||
39 | * this one. Among other things it should strip existing methods. |
||
40 | * |
||
41 | * @param Array $methods an array of API method names for the Connection to accept and |
||
42 | * pass on to existing callables. It's possible to specify whether |
||
43 | * each method should be available for unauthenticated calls or not. |
||
44 | * @see Jetpack::__construct |
||
45 | */ |
||
46 | public function initialize( $methods ) { |
||
49 | |||
50 | /** |
||
51 | * Returns true if the current site is connected to WordPress.com. |
||
52 | * |
||
53 | * @return Boolean is the site connected? |
||
54 | */ |
||
55 | public function is_active() { |
||
58 | |||
59 | /** |
||
60 | * Returns true if the user with the specified identifier is connected to |
||
61 | * WordPress.com. |
||
62 | * |
||
63 | * @param Integer $user_id the user identifier. |
||
64 | * @return Boolean is the user connected? |
||
65 | */ |
||
66 | public function is_user_connected( $user_id ) { |
||
69 | |||
70 | /** |
||
71 | * Get the wpcom user data of the current|specified connected user. |
||
72 | * |
||
73 | * @param Integer $user_id the user identifier. |
||
74 | * @return Object the user object. |
||
75 | */ |
||
76 | public function get_connected_user_data( $user_id ) { |
||
79 | |||
80 | /** |
||
81 | * Is the user the connection owner. |
||
82 | * |
||
83 | * @param Integer $user_id the user identifier. |
||
84 | * @return Boolean is the user the connection owner? |
||
85 | */ |
||
86 | public function is_connection_owner( $user_id ) { |
||
89 | |||
90 | /** |
||
91 | * Unlinks the current user from the linked WordPress.com user |
||
92 | * |
||
93 | * @param Integer $user_id the user identifier. |
||
94 | */ |
||
95 | public static function disconnect_user( $user_id ) { |
||
98 | |||
99 | /** |
||
100 | * Initializes a transport server, whatever it may be, saves into the object property. |
||
101 | * Should be changed to be protected. |
||
102 | */ |
||
103 | public function initialize_server() { |
||
106 | |||
107 | /** |
||
108 | * Checks if the current request is properly authenticated, bails if not. |
||
109 | * Should be changed to be protected. |
||
110 | */ |
||
111 | public function require_authentication() { |
||
114 | |||
115 | /** |
||
116 | * Verifies the correctness of the request signature. |
||
117 | * Should be changed to be protected. |
||
118 | */ |
||
119 | public function verify_signature() { |
||
122 | |||
123 | /** |
||
124 | * Attempts Jetpack registration which sets up the site for connection. Should |
||
125 | * remain public because the call to action comes from the current site, not from |
||
126 | * WordPress.com. |
||
127 | * |
||
128 | * @return Integer zero on success, or a bitmask on failure. |
||
129 | */ |
||
130 | public function register() { |
||
133 | |||
134 | /** |
||
135 | * Returns the callable that would be used to generate secrets. |
||
136 | * |
||
137 | * @return Callable a function that returns a secure string to be used as a secret. |
||
138 | */ |
||
139 | protected function get_secret_callable() { |
||
151 | |||
152 | /** |
||
153 | * Generates two secret tokens and the end of life timestamp for them. |
||
154 | * |
||
155 | * @param String $action The action name. |
||
156 | * @param Integer $user_id The user identifier. |
||
157 | * @param Integer $exp Expiration time in seconds. |
||
158 | */ |
||
159 | public function generate_secrets( $action, $user_id, $exp ) { |
||
183 | |||
184 | /** |
||
185 | * Returns two secret tokens and the end of life timestamp for them. |
||
186 | * |
||
187 | * @param String $action The action name. |
||
188 | * @param Integer $user_id The user identifier. |
||
189 | * @return string|array an array of secrets or an error string. |
||
190 | */ |
||
191 | public function get_secrets( $action, $user_id ) { |
||
206 | |||
207 | /** |
||
208 | * Deletes secret tokens in case they, for example, have expired. |
||
209 | * |
||
210 | * @param String $action The action name. |
||
211 | * @param Integer $user_id The user identifier. |
||
212 | */ |
||
213 | public function delete_secrets( $action, $user_id ) { |
||
221 | |||
222 | /** |
||
223 | * Responds to a WordPress.com call to register the current site. |
||
224 | * Should be changed to protected. |
||
225 | */ |
||
226 | public function handle_registration() { |
||
229 | |||
230 | /** |
||
231 | * Responds to a WordPress.com call to authorize the current user. |
||
232 | * Should be changed to protected. |
||
233 | */ |
||
234 | public function handle_authorization() { |
||
237 | |||
238 | /** |
||
239 | * Builds a URL to the Jetpack connection auth page. |
||
240 | * This needs rethinking. |
||
241 | * |
||
242 | * @param bool $raw If true, URL will not be escaped. |
||
243 | * @param bool|string $redirect If true, will redirect back to Jetpack wp-admin landing page after connection. |
||
244 | * If string, will be a custom redirect. |
||
245 | * @param bool|string $from If not false, adds 'from=$from' param to the connect URL. |
||
246 | * @param bool $register If true, will generate a register URL regardless of the existing token, since 4.9.0. |
||
247 | * |
||
248 | * @return string Connect URL |
||
249 | */ |
||
250 | public function build_connect_url( $raw, $redirect, $from, $register ) { |
||
253 | |||
254 | /** |
||
255 | * Disconnects from the Jetpack servers. |
||
256 | * Forgets all connection details and tells the Jetpack servers to do the same. |
||
257 | */ |
||
258 | public function disconnect_site() { |
||
261 | } |
||
262 |