Completed
Push — master ( 27ce5d...276db7 )
by Rakesh
09:27
created

functions.php (1 issue)

Labels
Severity
1
<?php
2
session_start();
3
	require_once 'appconfig.php';
4
5
		use Facebook\GraphNodes\GraphObject;
6
		use Facebook\GraphNodes\GraphSessionInfo;
7
		use Facebook\Authentication\AccessToken;
8
		use Facebook\HttpClients\FacebookHttpable;
9
		use Facebook\HttpClients\FacebookCurl;
10
		use Facebook\HttpClients\FacebookCurlHttpClient;
11
		use Facebook\FacebookSession;
12
		use Facebook\Helpers\FacebookRedirectLoginHelper;
13
		use Facebook\FacebookRequest;
14
		use Facebook\FacebookResponse;
15
		use Facebook\Exceptions\FacebookSDKException;
16
		use Facebook\Exceptions\FacebookAuthorizationException;
17
18
    $session = $_SESSION['fb_access_token'];
19
20
	$zip_folder = "";
21
	$album_download_directory = 'lib/resources/albums/'.uniqid().'/';
22
	mkdir($album_download_directory, 0777);
23
24
	function download_album($session, $album_download_directory, $album_id, $album_name) {
25
		$request_album_photos = new FacebookRequest($session,'GET', '/'.$album_id.'/photos?fields=source');
26
		$response_album_photos = $request_album_photos->execute();			
0 ignored issues
show
The method execute() does not exist on Facebook\FacebookRequest. ( Ignorable by Annotation )

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

26
		/** @scrutinizer ignore-call */ 
27
  $response_album_photos = $request_album_photos->execute();			

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
27
		$album_photos = $response_album_photos->getGraphObject()->asArray();
28
29
		$album_directory = $album_download_directory.$album_name;
30
		if ( !file_exists( $album_directory ) ) {
31
			mkdir($album_directory, 0777);
32
		}
33
34
		$i = 1;
35
		foreach ( $album_photos['data'] as $album_photo ) {
36
			$album_photo = (array) $album_photo;
37
			file_put_contents( $album_directory.'/'.$i.".jpg", fopen( $album_photo['source'], 'r') );
38
			$i++;
39
		}
40
	}
41
42
	//---------- For 1 album download -------------------------------------------------//
43
	if ( isset( $_GET['single_album'] ) && !empty ( $_GET['single_album'] ) ) {
44
        
45
		$single_album = explode( ",", $_GET['single_album'] );
46
		download_album( $session, $album_download_directory, $single_album[0], $single_album[1] );
47
	}
48
	
49
	//---------- For Selected Albums download -----------------------------------------//
50
	if ( isset( $_GET['selected_albums'] ) and count( $_GET['selected_albums'] ) > 0) {
51
		$selected_albums = explode("/", $_GET['selected_albums']);
52
53
		foreach ( $selected_albums as $selected_album ) {
54
			$selected_album = explode( ",", $selected_album );
55
			download_album( $session, $album_download_directory, $selected_album[0], $selected_album[1] );
56
		}
57
	}
58
59
	//---------- Download all album code -------------------------------------------------//
60
	if ( isset( $_GET['all_albums'] ) && !empty ( $_GET['all_albums'] ) ) {
61
		if ( $_GET['all_albums'] == 'all_albums' ) {
62
63
			// graph api request for user data
64
			$request_albums = new FacebookRequest($session, 'GET', '/me/albums?fields=id,name');
65
			$response_albums = $request_albums->execute();
66
			
67
			// get response
68
			$albums = $response_albums->getGraphObject()->asArray();
69
70
			if ( !empty( $albums ) ) {
71
				foreach ( $albums['data'] as $album ) {
72
					$album = (array) $album;
73
					download_album( $session, $album_download_directory, $album['id'], $album['name'] );
74
				}
75
			}
76
		}
77
	}
78
79
	if ( isset( $_GET['zip'] ) ) {
80
		require_once('zipper.php');
81
		$zipper = new zipper();
82
		echo $zipper->get_zip($album_download_directory);
83
84
	} else {
85
86
		//$redirect = 'location:lib/move_to_picasa.php?album_download_directory='.$album_download_directory;
87
		//if ( isset( $_GET['ajax'] ) ) {
88
		//	$redirect = $redirect . '&ajax=1';
89
		//}
90
		//($redirect);
91
	}