Passed
Push — master ( 51cb81...d434c4 )
by Kishan
04:32
created

moveToDrive()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 42
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 33
nc 4
nop 6
dl 0
loc 42
rs 9.392
c 0
b 0
f 0
1
<?php
2
/** 
3
 * Copyright 2018 Social Manager.
4
 * PHP version 7.2.8
5
 *
6
 * It will Zip the file
7
 * 
8
 * @category Album_Manager
9
 * @package  Zipper
10
 * @author   Kishan Jasani <[email protected]>
11
 * @license  https://rtfbchallenge.000webhostapp.com/privacy_policy/privacy_policy.php 
12
 * @link     ""
13
 * 
14
 * You are hereby granted a non-exclusive, worldwide, royalty-free license to
15
 * use, copy, modify, and distribute this software in source code or binary
16
 * form for use in connection with the web services and APIs provided by
17
 * Kishan Jasani.
18
 *
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND
20
 */
21
ini_set('max_execution_time', 999999);
22
require_once __DIR__.'/gClient.php';
23
require_once "../fb-callback.php";
24
require_once '../LibGearman.php';
25
26
$gClient =new CreateGoogleClient();
27
$client = $gClient->createClient();
28
29
if (isset($_SESSION['google_access_token'])) {
30
    $client->setAccessToken($_SESSION['google_access_token']);
31
32
    $drive = new Google_Service_Drive($client);
33
34
    $rootFolderName = 'facebook_' . $_SESSION['userid'] . '_albums';
35
    $fileMetaData = new Google_Service_Drive_DriveFile(
36
        array(
37
            'name' => $rootFolderName,
38
            'mimeType' => 'application/vnd.google-apps.folder')
39
    );
40
    $parentFolder = $drive->files->create(
41
        $fileMetaData, 
42
        array('fields' => 'id')
43
    );
44
    $parentFolderId = $parentFolder->getId();
45
46
    if (isset($_GET['single_album']) && !empty($_GET['single_album'])) {
47
        $single_album = explode(",", $_GET['single_album']);
48
        if (class_exists('GearmanClient')) {
49
            $gearman = new LibGearman();
50
            $gearman->gearman_client();
51
            try{
52
                $gearman->do_job_background('moveToDrive', serialize(['accessToken' => $_SESSION['accessToken'], 'albumId' => $single_album[0], 'albumName' => $single_album[1],'google_access_token' => $_SESSION['google_access_token'], 'parentFolderId' => $parentFolderId]));
53
            } catch (Exception $e) {
54
                echo "Gearman Client unable to handle request : " . $e->getMessage();
55
            }  
56
        }
57
        else {
58
            echo "Gearman Does Not Support";
59
        }
60
        $response = "Your Albums Will successfully backuped with in few time!!!";
61
        echo $response;
62
    }
63
64
    if (isset($_GET['selected_albums']) && !empty($_GET['selected_albums'])) {
65
        $selected_albums = explode("-", $_GET['selected_albums']);
66
        foreach ($selected_albums as $selected_album) {
67
            $selected_album = explode(",", $selected_album);
68
            if (class_exists('GearmanClient')) {
69
                $gearman = new LibGearman();
70
                $gearman->gearman_client();
71
                try{
72
                    $gearman->do_job_background('moveToDrive', serialize(['accessToken' => $_SESSION['accessToken'], 'albumId' => $selected_album[0], 'albumName' => $selected_album[1],'google_access_token' => $_SESSION['google_access_token'], 'parentFolderId' => $parentFolderId]));
73
                } catch (Exception $e) {
74
                    echo "Gearman Client unable to handle request : " . $e->getMessage();
75
                }  
76
            }
77
            else {
78
                echo "Gearman Does Not Support";
79
            }
80
        }
81
        $response = "Your Selected Albums will successfully backuped with in few time!!!";
82
        echo $response;
83
    }
84
85
    if (isset($_GET['all_albums']) && !empty($_GET['all_albums'])) {
86
        if ($_GET['all_albums'] == 'all_albums') {
87
            // graph api request for user data
88
            $response_albums = $fb->get('/me/albums?fields=id,name', $accessToken);
89
            // get response
90
            $albums = $response_albums->getGraphEdge()->asArray();
91
92
            if (!empty($albums)) {
93
                foreach ($albums as $album) {
94
                    if (class_exists('GearmanClient')) {
95
                        $gearman = new LibGearman();
96
                        $gearman->gearman_client();
97
                        try{
98
                            $gearman->do_job_background('moveToDrive', serialize(['accessToken' => $_SESSION['accessToken'], 'albumId' => $album['id'], 'albumName' => $album['name'],'google_access_token' => $_SESSION['google_access_token'], 'parentFolderId' => $parentFolderId]));
99
                        } catch (Exception $e) {
100
                            echo "Gearman Client unable to handle request : " . $e->getMessage();
101
                        }  
102
                    }
103
                    else {
104
                        echo "Gearman Does Not Support";
105
                    }
106
                }
107
                $response = "Your All Albums will successfully backuped with in few time!!!";
108
                echo $response;
109
            }
110
        }
111
    }
112
113
} else {
114
    $redirect_uri = 'https://localhost:8443/SociaManager/google_drive/g-callback.php';
115
    header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
116
}
117
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
118