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