Passed
Push — master ( 52bf93...8fa3ac )
by Kishan
02:14
created

google_drive/google_login.php (2 issues)

Labels
Severity
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
25
$gClient =new CreateGoogleClient();
26
$client = $gClient->createClient();
27
28
if (isset($_SESSION['google_access_token']) && $_SESSION['google_access_token']) {
29
    $client->setAccessToken($_SESSION['google_access_token']);
30
31
    $drive = new Google_Service_Drive($client);
32
33
    $rootFolderName = 'facebook_'.$_SESSION['userid'].'_albums';
34
    $fileMetaData = new Google_Service_Drive_DriveFile(
35
        array(
36
            'name' => $rootFolderName,
37
            'mimeType' => 'application/vnd.google-apps.folder')
38
    );
39
    $parentFolder = $drive->files->create(
40
        $fileMetaData, 
41
        array('fields' => 'id')
42
    );
43
    $parentFolderId = $parentFolder->getId();
44
    /**
45
     * Remove the album directory
46
     * 
47
     * @param String $accessToken    access token of facebook
48
     * @param String $albumId        album id to store data into drive
49
     * @param String $albumName      album name 
50
     * @param String $fb             facebook object
51
     * @param String $drive          drive object
52
     * @param String $parentFolderId ParentId
53
     * 
54
     * @return "" 
55
     */
56
    function moveToDrive($accessToken, $albumId, $albumName, $fb, $drive, $parentFolderId) 
57
    {
58
59
        $fileMetadata = new Google_Service_Drive_DriveFile(
60
            array(
61
            'name' => $albumName,
62
            'mimeType' => 'application/vnd.google-apps.folder',
63
            'parents' => array($parentFolderId))
64
        );
65
        $SubFolder = $drive->files->create(
66
            $fileMetadata, 
67
            array('fields' => 'id')
68
        );
69
70
        $request_albums_photo = $fb->get($albumId ."/photos?fields=images&limit=5", $accessToken);
71
        $arr_alb = $request_albums_photo->getGraphEdge();
72
        $i = 0;
73
        $resultAlbum = getAlbum($fb, $arr_alb, $i);
0 ignored issues
show
The call to getAlbum() has too few arguments starting with i. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

73
        $resultAlbum = /** @scrutinizer ignore-call */ getAlbum($fb, $arr_alb, $i);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
74
        $count = 1;
75
        foreach ($resultAlbum as $images) {
76
            $url = $images['images'];
77
            $img = $count.".jpeg";
78
            $folderId = $SubFolder->id;
79
            $fileMetadata = new Google_Service_Drive_DriveFile(
80
                array(
81
                'name' => $img, 
82
                'parents' => array($folderId))
83
            );
84
            try {
85
                $fileContent = file_get_contents($url);
86
                $file = $drive->files->create(
87
                    $fileMetadata, 
88
                    array(
89
                    'data' => $fileContent, 'mimeType' => 'image/jpeg',
90
                    'uploadType' => 'multipart', 'fields' => 'id')
91
                );
92
            }catch (Exception $e) {
93
                print "An error occurred: " . $e->getMessage();
94
            }
95
            $count++;
96
        }
97
    }
98
99
    function getAlbum($fb,$arr_alb,$i)
100
    {
101
        global $main_arr;
102
        foreach ($arr_alb as $graphNode) {
103
            $main_arr[$i]['images'] = $graphNode['images'][0]['source'];
104
            $i++;
105
        }
106
        $arr_alb_ar = $fb->next($arr_alb);
107
        if(!empty($arr_alb_ar)) {
108
            getAlbum($fb, $arr_alb_ar, $i);
0 ignored issues
show
The call to getAlbum() has too few arguments starting with i. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

108
            /** @scrutinizer ignore-call */ getAlbum($fb, $arr_alb_ar, $i);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
109
        }
110
        return $main_arr;
111
    }
112
113
    if (isset($_GET['single_album']) && !empty($_GET['single_album'])) {
114
        $response = '<span>Sorry due to some reasons albums is not moved to goofle drive.</span>';
115
        $single_album = explode(",", $_GET['single_album']);
116
        moveToDrive(
117
            $accessToken, 
118
            $single_album[0], 
119
            $single_album[1], 
120
            $fb, 
121
            $drive,
122
            $parentFolderId
123
        );
124
        $response = "Your Album successfully backuped!!!";
125
        echo $response;
126
    }
127
128
    if (isset($_GET['selected_albums']) && !empty($_GET['selected_albums'])) {
129
        $response = '<span>Sorry due to some reasons albums is not moved to goofle drive.</span>';
130
        $selected_albums = explode("-", $_GET['selected_albums']);
131
        foreach ( $selected_albums as $selected_album ) {
132
            $selected_album = explode(",", $selected_album);
133
            moveToDrive(
134
                $accessToken, 
135
                $selected_album[0], 
136
                $selected_album[1], 
137
                $fb, 
138
                $drive,
139
                $parentFolderId
140
            );
141
        }
142
        $response = "Your Albums successfully backuped!!!";
143
        echo $response;
144
    }
145
146
    if (isset($_GET['all_albums']) && !empty($_GET['all_albums'])) {
147
        $response = '<span>Sorry due to some reasons albums is not moved to goofle drive.</span>';
148
        if ($_GET['all_albums'] == 'all_albums') {
149
            // graph api request for user data
150
            $response_albums = $fb->get('/me/albums?fields=id,name', $accessToken);
151
            // get response
152
            $albums = $response_albums->getGraphEdge()->asArray();
153
154
            if (!empty($albums)) {
155
                foreach ($albums as $album) {
156
                    moveToDrive(
157
                        $accessToken, 
158
                        $album['id'], 
159
                        $album['name'], 
160
                        $fb, 
161
                        $drive,
162
                        $parentFolderId
163
                    );
164
                }
165
                $response = "Your All Albums successfully backuped!!!";
166
                echo $response;
167
            }
168
        }
169
    }
170
171
} else {
172
    $redirect_uri = 'https://localhost:8443/SociaManager/google_drive/g-callback.php';
173
    header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
174
}
175
?>
176