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

download-album.php (1 issue)

1
<?php
2
3
/** 
4
 * Copyright 2018 Social Manager.
5
 * 
6
 * PHP version 7.2.8
7
 *
8
 * @category Album_Manager
9
 * @package  Facebook
10
 * @author   Kishan Jasani <[email protected]>
11
 * @license  https://localhost/SocialManager/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
require_once "fb-callback.php";
22
23
$zip_folder = "";
24
$album_download_directory = 'public/' . uniqid() . '/';
25
mkdir($album_download_directory, 0777, true);
26
27
/**
28
 * It will downloads the album from facebook
29
 * 
30
 * @param String $accessToken              acess token for the access albums
31
 * @param String $album_download_directory directory where album will be store
32
 * @param String $album_id                 Id of ther album 
33
 * @param String $album_name               Album name
34
 * @param String $fb                       Facebook Object
35
 * 
36
 * @return ""
0 ignored issues
show
Documentation Bug introduced by
The doc comment "" at position 0 could not be parsed: Unknown type name '""' at position 0 in "".
Loading history...
37
 */
38
function Download_album(
39
    $accessToken, 
40
    $album_download_directory, 
41
    $album_id, 
42
    $album_name, 
43
    $fb
44
) {
45
    $request_album_photos = $fb->get($album_id . "/photos?fields=source", $accessToken); //photos?fields=source
46
    $album_photos=$request_album_photos->getGraphEdge()->asArray();
47
48
    $album_directory = $album_download_directory.$album_name;
49
    if (!file_exists($album_directory)) {
50
            mkdir($album_directory, 0777);
51
    }
52
53
    $i = 1;
54
    foreach ( $album_photos as $album_photo ) {
55
        file_put_contents(
56
            $album_directory.'/'.$i.".jpg", 
57
            fopen($album_photo['source'], 'r')
58
        );
59
        $i++;
60
    }
61
}
62
63
//---------- For 1 album download -------------------------------------------------//
64
if (isset($_GET['single_album']) && !empty($_GET['single_album'])) {
65
    $single_album = explode(",", $_GET['single_album']);
66
    Download_album(
67
        $accessToken, 
68
        $album_download_directory, 
69
        $single_album[0], 
70
        $single_album[1], 
71
        $fb
72
    );
73
}
74
75
//---------- For Selected Albums download -----------------------------------------//
76
if (isset($_GET['selected_albums']) && !empty($_GET['selected_albums'])) {
77
    $selected_albums = explode("/", $_GET['selected_albums']);
78
    foreach ($selected_albums as $selected_album) {
79
        $selected_album = explode(",", $selected_album);
80
        Download_album(
81
            $accessToken, 
82
            $album_download_directory, 
83
            $selected_album[0], 
84
            $selected_album[1], 
85
            $fb
86
        );
87
    }
88
}
89
90
//---------- Download all album code --------------------------------------//
91
if (isset($_GET['all_albums']) && !empty($_GET['all_albums'])) {
92
    if ($_GET['all_albums'] == 'all_albums') {
93
        $response_albums = $fb->get('/me/albums?fields=id,name', $accessToken);
94
        $albums = $response_albums->getGraphEdge()->asArray();
95
        if (!empty($albums)) {
96
            foreach ($albums as $album) {
97
                Download_album(
98
                    $accessToken, 
99
                    $album_download_directory, 
100
                    $album['id'], 
101
                    $album['name'], 
102
                    $fb
103
                );
104
            }
105
        }
106
    }
107
}
108
109
if (isset($_GET['zip'])) {
110
    include_once 'zipper.php';
111
    $zipper = new Zipper();
112
    echo $zipper->getZip($album_download_directory);
113
}
114
?>