-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathCdn_GoogleDrive_Popup_AuthReturn.php
More file actions
57 lines (49 loc) · 1.61 KB
/
Cdn_GoogleDrive_Popup_AuthReturn.php
File metadata and controls
57 lines (49 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* File: Cdn_GoogleDrive_Popup_AuthReturn.php
*
* @package W3TC
*/
namespace W3TC;
/**
* Class Cdn_GoogleDrive_Popup_AuthReturn
*/
class Cdn_GoogleDrive_Popup_AuthReturn {
/**
* Renders the Google Drive authorization return view.
*
* This method retrieves the client ID, refresh token, and access token from the request,
* sets the access token for a new Google client, and queries Google Drive for folders.
* It then filters the folders to include only those that are direct children of the root.
* Finally, it includes the view to display the results.
*
* @return void
*/
public function render() {
$client_id = Util_Request::get_string( 'oa_client_id' );
$refresh_token = Util_Request::get_string( 'oa_refresh_token' );
$token_array = array(
'access_token' => Util_Request::get_string( 'oa_access_token' ),
'token_type' => Util_Request::get_string( 'oa_token_type' ),
'expires_in' => Util_Request::get_string( 'oa_expires_in' ),
'created' => Util_Request::get_string( 'oa_created' ),
);
$access_token = wp_json_encode( $token_array );
$client = new \W3TCG_Google_Client();
$client->setClientId( $client_id );
$client->setAccessToken( $access_token );
$service = new \W3TCG_Google_Service_Drive( $client );
$items = $service->files->listFiles(
array(
'q' => "mimeType = 'application/vnd.google-apps.folder'",
)
);
$folders = array();
foreach ( $items as $item ) {
if ( count( $item->parents ) > 0 && $item->parents[0]->isRoot ) {
$folders[] = $item;
}
}
include W3TC_DIR . '/Cdn_GoogleDrive_Popup_AuthReturn_View.php';
}
}