-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-images.php
132 lines (114 loc) · 5.37 KB
/
get-images.php
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
if (!session_id())
{
session_start();
}
// include required files
require_once('fb-config.php');
require_once('getallimages.php');
$permissions = ['user_photos'];
$accessToken = $_SESSION['access_token'];
if (isset($accessToken))
{
// get user data
$response = $fb->get('/me?fields=name,id,email,albums', $accessToken);
$user = $response->getGraphuser();
// Fetches Images from Single Album for Slider
if(isset($_REQUEST['slidealbumid'])){
$images = "true~";
$albumID = $_REQUEST['slidealbumid'];
// get all images source in string format separated by "~"
$AllAlbums = getAllImages($albumID, $fb);
$arr = explode("~",$AllAlbums);
for($j=0;$j<count($arr)-1;$j++)
{
$images .="<div class='slide'><img src='".$arr[$j]."' alt='slide".($j+1)."' width='100%' /></div>";
}
echo $images;
}
// End - Fetches Images from Single Album for Slider
// Fetches Images from Single Album, generate zip file and return name of zip file
if(isset($_REQUEST['downloadsingle'])){
$result = "true";
$album_id=$_REQUEST['downloadsingle'];
// get all images source in string format separated by "~"
$AllAlbums = getAllImages($album_id, $fb);
$arr = explode("~",$AllAlbums);
$zip=new ZipArchive();
try{
if(file_exists('Downloads/'.$album_id.'.zip')){
unlink('Downloads/'.$album_id.'.zip');
}
$zip->open('Downloads/'.$album_id.'.zip', ZipArchive::CREATE);
for($j=0;$j<count($arr)-1;$j++)
{
$zip->addFromString($j.'.jpg', file_get_contents($arr[$j]));
}
$zip->close();
$result .= "~Downloads/".$album_id.".zip";
echo $result;
}catch(Facebook\Exceptions\FacebookSDKException $e){
echo "SDK Exception: ".$e->getMessage();
}
}
// End - Fetches Images from Single Album, generate zip file and return name of zip file
// Fetches Images from All Album, generate zip file and return name of zip file
if(isset($_REQUEST['downloadall'])){
$result = "true";
if(file_exists('Downloads/'.$user['id']."_".$user['name'].'.zip')){
unlink('Downloads/'.$user['id']."_".$user['name'].'.zip');
}
for($i=0;$i<count($user['albums']);$i++)
{
// get all images source in string format separated by "~"
$AllAlbums = getAllImages($user['albums'][$i]['id'], $fb);
$arr = explode("~",$AllAlbums);
$zip=new ZipArchive();
try{
$zip->open('Downloads/'.$user['id']."_".$user['name'].'.zip', ZipArchive::CREATE);
$zip->addEmptyDir($user['albums'][$i]['name']);
for($j=0;$j<count($arr)-1;$j++)
{
$zip->addFromString($user['albums'][$i]['name']."/".$j.'.jpg', file_get_contents($arr[$j]));
}
$zip->close();
}catch(Facebook\Exceptions\FacebookSDKException $e){
echo "SDK Exception: ".$e->getMessage();
}
}
echo $result."~Downloads/".$user['id']."_".$user['name'].".zip";
}
// End - Fetches Images from All Album, generate zip file and return name of zip file
// Fetches Images from Selected Album, generate zip file and return name of zip file
if(isset($_REQUEST['downloadselected'])){
$result = "true";
if(file_exists('Downloads/'.$user['id']."_".$user['name'].'.zip')){
unlink('Downloads/'.$user['id']."_".$user['name'].'.zip');
}
$selected_album_list=explode("/",$_REQUEST['downloadselected']);
for($i = 0; $i < count($selected_album_list)-1; $i++){
$album_IDs_Names = explode('-', $selected_album_list[$i]);
// get all images source in string format separated by "~"
$AllAlbums = getAllImages($album_IDs_Names[0], $fb);
$arr = explode("~",$AllAlbums);
$zip=new ZipArchive();
try{
$zip->open('Downloads/'.$user['id']."_".$user['name'].'.zip', ZipArchive::CREATE);
$zip->addEmptyDir($album_IDs_Names[1]);
for($j=0;$j<count($arr)-1;$j++)
{
$zip->addFromString($album_IDs_Names[1]."/".$j.'.jpg', file_get_contents($arr[$j]));
}
$zip->close();
}catch(Facebook\Exceptions\FacebookSDKException $e){
echo "SDK Exception: ".$e->getMessage();
}
}
echo $result."~Downloads/".$user['id']."_".$user['name'].".zip";
}
// End - Fetches Images from Selected Album, generate zip file and return name of zip file
} else {
$fb_json = json_decode(file_get_contents("lib/conf/fb-key.json"), true);
$loginUrl = $helper->getLoginUrl($fb_json["location"].'index.php', $permissions);
}
?>