|
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://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
|
|
|
require_once "fb-callback.php";
|
|
22
|
|
|
|
|
23
|
|
|
$zip_folder = "";
|
|
24
|
|
|
$album_download_directory = 'public/'.uniqid().'/';
|
|
25
|
|
|
mkdir($album_download_directory, 0777, true);
|
|
26
|
|
|
|
|
27
|
|
|
$main_arr = array();
|
|
28
|
|
|
|
|
29
|
|
|
/**
|
|
30
|
|
|
* It will downloads the album from facebook
|
|
31
|
|
|
*
|
|
32
|
|
|
* @param String $accessToken acess token for the access albums
|
|
33
|
|
|
* @param String $album_download_directory directory where album will be store
|
|
34
|
|
|
* @param String $album_id Id of ther album
|
|
35
|
|
|
* @param String $album_name Album name
|
|
36
|
|
|
* @param String $fb Facebook Object
|
|
37
|
|
|
*
|
|
38
|
|
|
* @return "Downloaded Album"
|
|
|
|
|
|
|
39
|
|
|
*/
|
|
40
|
|
|
function Download_album(
|
|
41
|
|
|
$accessToken,
|
|
42
|
|
|
$album_download_directory,
|
|
43
|
|
|
$album_id,
|
|
44
|
|
|
$album_name,
|
|
45
|
|
|
$fb
|
|
46
|
|
|
) {
|
|
47
|
|
|
$album_directory = $album_download_directory.$album_name;
|
|
48
|
|
|
if (!file_exists($album_directory)) {
|
|
49
|
|
|
mkdir($album_directory, 0777);
|
|
50
|
|
|
}
|
|
51
|
|
|
|
|
52
|
|
|
$request_albums_photo = $fb->get($album_id . "/photos?fields=images&limit=5", $accessToken);
|
|
53
|
|
|
$arr_alb = $request_albums_photo->getGraphEdge();
|
|
54
|
|
|
|
|
55
|
|
|
$i = 0;
|
|
56
|
|
|
$resultAlbum = getAlbum($fb, $arr_alb, $i);
|
|
|
|
|
|
|
57
|
|
|
$count = 1;
|
|
58
|
|
|
foreach ($resultAlbum as $album_photo) {
|
|
59
|
|
|
file_put_contents(
|
|
60
|
|
|
$album_directory . "/" . $count . ".jpg",
|
|
61
|
|
|
fopen($album_photo['images'], 'r')
|
|
62
|
|
|
);
|
|
63
|
|
|
$count++;
|
|
64
|
|
|
}
|
|
65
|
|
|
}
|
|
66
|
|
|
|
|
67
|
|
|
/**
|
|
68
|
|
|
* It will export the album from facebook and puut it into json file
|
|
69
|
|
|
*
|
|
70
|
|
|
* @param String $accessToken acess token for the access albums
|
|
71
|
|
|
* @param String $album_id Id of ther album
|
|
72
|
|
|
* @param String $album_name Album name
|
|
73
|
|
|
* @param String $fb Facebook Object
|
|
74
|
|
|
*
|
|
75
|
|
|
* @return "Exported Albums"
|
|
|
|
|
|
|
76
|
|
|
*/
|
|
77
|
|
|
function Export_album($accessToken, $album_id, $album_name, $fb)
|
|
78
|
|
|
{
|
|
79
|
|
|
$request_albums_photo = $fb->get($album_id ."/photos?fields=images&limit=5", $accessToken);
|
|
80
|
|
|
$arr_alb = $request_albums_photo->getGraphEdge();
|
|
81
|
|
|
$i = 0;
|
|
82
|
|
|
$resultAlbum = getAlbum($fb, $arr_alb, $album_name, $i);
|
|
83
|
|
|
|
|
84
|
|
|
$response_json = json_encode(array($album_name => $resultAlbum), JSON_PRETTY_PRINT);
|
|
85
|
|
|
$jsonFilename = './public/jsonData/fb-album_'.date("Y-m-d").'_'.date("H-i-s").'.json';
|
|
86
|
|
|
$jsonFile = fopen($jsonFilename, "a") or die("Unable to open file!");
|
|
|
|
|
|
|
87
|
|
|
fwrite($jsonFile, $response_json);
|
|
|
|
|
|
|
88
|
|
|
fclose($jsonFile);
|
|
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
echo '<a href="' . $jsonFilename . '" id="download-link" target="_blank" class="btn" >See JSON File</a>';
|
|
91
|
|
|
}
|
|
92
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
/**
|
|
95
|
|
|
* It will fetch all the album from the facebook and put it in array
|
|
96
|
|
|
*
|
|
97
|
|
|
* @param String $fb Facebook Object
|
|
98
|
|
|
* @param String $arr_alb limited array of the album
|
|
99
|
|
|
* @param String $album_name Album name
|
|
100
|
|
|
* @param String $i taking care of index value of array
|
|
101
|
|
|
*
|
|
102
|
|
|
* @return "Get Albums array"
|
|
|
|
|
|
|
103
|
|
|
*/
|
|
104
|
|
|
function getAlbum($fb, $arr_alb, $album_name, $i)
|
|
105
|
|
|
{
|
|
106
|
|
|
global $main_arr;
|
|
107
|
|
|
|
|
108
|
|
|
foreach ($arr_alb as $graphNode) {
|
|
|
|
|
|
|
109
|
|
|
$main_arr[$i]['images'] = $graphNode['images'][0]['source'];
|
|
110
|
|
|
$i++;
|
|
111
|
|
|
}
|
|
112
|
|
|
$arr_alb_ar = $fb->next($arr_alb);
|
|
113
|
|
|
if (!empty($arr_alb_ar)) {
|
|
114
|
|
|
getAlbum($fb, $arr_alb_ar, $album_name, $i);
|
|
115
|
|
|
}
|
|
116
|
|
|
return $main_arr;
|
|
117
|
|
|
}
|
|
118
|
|
|
|
|
119
|
|
|
//---------- For 1 album download -------------------------------------------------//
|
|
120
|
|
|
if (isset($_GET['single_album']) && !empty($_GET['single_album'])) {
|
|
121
|
|
|
$single_album = explode(",", $_GET['single_album']);
|
|
122
|
|
|
Download_album(
|
|
123
|
|
|
$accessToken,
|
|
124
|
|
|
$album_download_directory,
|
|
125
|
|
|
$single_album[0],
|
|
126
|
|
|
$single_album[1],
|
|
127
|
|
|
$fb
|
|
128
|
|
|
);
|
|
129
|
|
|
}
|
|
130
|
|
|
|
|
131
|
|
|
//---------- For Selected Albums download -----------------------------------------//
|
|
132
|
|
|
if (isset($_GET['selected_albums']) && !empty($_GET['selected_albums'])) {
|
|
133
|
|
|
$selected_albums = explode("/", $_GET['selected_albums']);
|
|
134
|
|
|
foreach ($selected_albums as $selected_album) {
|
|
135
|
|
|
$selected_album = explode(",", $selected_album);
|
|
136
|
|
|
Download_album(
|
|
137
|
|
|
$accessToken,
|
|
138
|
|
|
$album_download_directory,
|
|
139
|
|
|
$selected_album[0],
|
|
140
|
|
|
$selected_album[1],
|
|
141
|
|
|
$fb
|
|
142
|
|
|
);
|
|
143
|
|
|
}
|
|
144
|
|
|
}
|
|
145
|
|
|
|
|
146
|
|
|
//---------- Download all album code --------------------------------------//
|
|
147
|
|
|
if (isset($_GET['all_albums']) && !empty($_GET['all_albums'])) {
|
|
148
|
|
|
if ($_GET['all_albums'] == 'all_albums') {
|
|
149
|
|
|
$response_albums = $fb->get('/me/albums?fields=id,name', $accessToken);
|
|
150
|
|
|
$albums = $response_albums->getGraphEdge()->asArray();
|
|
151
|
|
|
if (!empty($albums)) {
|
|
152
|
|
|
foreach ($albums as $album) {
|
|
153
|
|
|
Download_album(
|
|
154
|
|
|
$accessToken,
|
|
155
|
|
|
$album_download_directory,
|
|
156
|
|
|
$album['id'],
|
|
157
|
|
|
$album['name'],
|
|
158
|
|
|
$fb
|
|
159
|
|
|
);
|
|
160
|
|
|
}
|
|
161
|
|
|
}
|
|
162
|
|
|
}
|
|
163
|
|
|
}
|
|
164
|
|
|
|
|
165
|
|
|
//---------------Export Single album-------------------------//
|
|
166
|
|
|
if (isset($_GET['single_export']) && !empty($_GET['single_export'])) {
|
|
167
|
|
|
$single_album = explode(",", $_GET['single_export']);
|
|
168
|
|
|
Export_album(
|
|
169
|
|
|
$accessToken,
|
|
170
|
|
|
$single_album[0],
|
|
171
|
|
|
$single_album[1],
|
|
172
|
|
|
$fb
|
|
173
|
|
|
);
|
|
174
|
|
|
}
|
|
175
|
|
|
|
|
176
|
|
|
if (isset($_GET['zip'])) {
|
|
177
|
|
|
include_once 'zipper.php';
|
|
178
|
|
|
$zipper = new Zipper();
|
|
179
|
|
|
echo $zipper->getZip($album_download_directory);
|
|
180
|
|
|
}
|
|
181
|
|
|
?> |
|
|
|
|
|