kishanjasani /
SociaManager
| 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 "" |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 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, $album_name, $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 "" |
||
|
0 ignored issues
–
show
|
|||
| 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 "$main_arr" |
||
| 103 | */ |
||
| 104 | function getAlbum($fb, $arr_alb, $album_name, $i) |
||
| 105 | {
|
||
| 106 | global $main_arr; |
||
| 107 | foreach ($arr_alb as $graphNode) {
|
||
| 108 | $main_arr[$i]['images'] = $graphNode['images'][0]['source']; |
||
| 109 | $i++; |
||
| 110 | } |
||
| 111 | $arr_alb_ar = $fb->next($arr_alb); |
||
| 112 | if (!empty($arr_alb_ar)) {
|
||
| 113 | getAlbum($fb, $arr_alb_ar, $album_name, $i); |
||
| 114 | } |
||
| 115 | return $main_arr; |
||
| 116 | } |
||
| 117 | |||
| 118 | //---------- For 1 album download -------------------------------------------------// |
||
| 119 | if (isset($_GET['single_album']) && !empty($_GET['single_album'])) {
|
||
| 120 | $single_album = explode(",", $_GET['single_album']);
|
||
| 121 | Download_album( |
||
| 122 | $accessToken, |
||
| 123 | $album_download_directory, |
||
| 124 | $single_album[0], |
||
| 125 | $single_album[1], |
||
| 126 | $fb |
||
| 127 | ); |
||
| 128 | } |
||
| 129 | |||
| 130 | //---------- For Selected Albums download -----------------------------------------// |
||
| 131 | if (isset($_GET['selected_albums']) && !empty($_GET['selected_albums'])) {
|
||
| 132 | $selected_albums = explode("/", $_GET['selected_albums']);
|
||
| 133 | foreach ($selected_albums as $selected_album) {
|
||
| 134 | $selected_album = explode(",", $selected_album);
|
||
| 135 | Download_album( |
||
| 136 | $accessToken, |
||
| 137 | $album_download_directory, |
||
| 138 | $selected_album[0], |
||
| 139 | $selected_album[1], |
||
| 140 | $fb |
||
| 141 | ); |
||
| 142 | } |
||
| 143 | } |
||
| 144 | |||
| 145 | //---------- Download all album code --------------------------------------// |
||
| 146 | if (isset($_GET['all_albums']) && !empty($_GET['all_albums'])) {
|
||
| 147 | if ($_GET['all_albums'] == 'all_albums') {
|
||
| 148 | $response_albums = $fb->get('/me/albums?fields=id,name', $accessToken);
|
||
| 149 | $albums = $response_albums->getGraphEdge()->asArray(); |
||
| 150 | if (!empty($albums)) {
|
||
| 151 | foreach ($albums as $album) {
|
||
| 152 | Download_album( |
||
| 153 | $accessToken, |
||
| 154 | $album_download_directory, |
||
| 155 | $album['id'], |
||
| 156 | $album['name'], |
||
| 157 | $fb |
||
| 158 | ); |
||
| 159 | } |
||
| 160 | } |
||
| 161 | } |
||
| 162 | } |
||
| 163 | |||
| 164 | //---------------Export Single album-------------------------// |
||
| 165 | if (isset($_GET['single_export']) && !empty($_GET['single_export'])) {
|
||
| 166 | $single_album = explode(",", $_GET['single_export']);
|
||
| 167 | Export_album( |
||
| 168 | $accessToken, |
||
| 169 | $single_album[0], |
||
| 170 | $single_album[1], |
||
| 171 | $fb |
||
| 172 | ); |
||
| 173 | } |
||
| 174 | |||
| 175 | if (isset($_GET['zip'])) {
|
||
| 176 | include_once 'zipper.php'; |
||
| 177 | $zipper = new Zipper(); |
||
| 178 | echo $zipper->getZip($album_download_directory); |
||
| 179 | } |
||
| 180 | ?> |