Passed
Branch master (45fe3e)
by Rakesh
02:18
created

member.php (2 issues)

Labels
Severity
1
<?php
2
if(!session_id()) {
3
  session_start();
4
}
5
require_once 'lib\Facebook\autoload.php';
6
7
if(isset($_SESSION['fb_access_token'])){
8
  // Get access token from session
9
  $accessToken = $_SESSION['fb_access_token'];
10
  $user = (array) $_SESSION['user'];
11
  
12
echo '<br/> User ID: ' . $user['id']; 
13
echo '<br/> Welcome , ' . $user['name'];
14
echo '<a href=""  >Logout</a>';
15
16
// Get photo albums of Facebook page using Facebook Graph API
17
$fields = "id,name,description,link,cover_photo,count";
18
$fb_page_id = $user['id'];
19
$graphAlbLink = "https://graph.facebook.com/v3.2/{$fb_page_id}/albums?fields={$fields}&access_token={$accessToken}";
20
21
$jsonData = file_get_contents($graphAlbLink);
22
$fbAlbumObj = json_decode($jsonData, true, 512, JSON_BIGINT_AS_STRING);
23
24
// Facebook albums content
25
$fbAlbumData = $fbAlbumObj['data'];
26
27
// Render all photo albums
28
echo "<br/><br/>";
29
foreach($fbAlbumData as $data){
30
    $id = isset($data['id'])?$data['id']:'';
31
    $name = isset($data['name'])?$data['name']:'';
32
    $description = isset($data['description'])?$data['description']:'';
33
    $link = isset($data['link'])?$data['link']:'';
34
    $cover_photo_id = isset($data['cover_photo']['id'])?$data['cover_photo']['id']:'';
35
    $count = isset($data['count'])?$data['count']:'';
36
    
37
    $pictureLink = "fb-callback.php?album_id={$id}&album_name={$name}";
38
    
39
40
    echo "<a href='{$pictureLink}'>";
41
    $cover_photo_id = (!empty($cover_photo_id ))?$cover_photo_id : 123456;
42
    echo "<img width=100px height=100px src='https://graph.facebook.com/v3.2/{$cover_photo_id}/picture?access_token={$accessToken}' alt=''>";
43
    echo "</a>";
44
    echo "<p>{$name}</p>";
45
46
    $photoCount = ($count > 1)?$count. 'Photos':$count. 'Photo';
47
    
48
    echo "<p><span style='color:#888;'>{$photoCount} / <a href='{$link}' target='_blank'>View on Facebook</a></span></p>";
49
    echo "<p>{$description}</p>";
50
}
51
//}
52
53
$album_id = isset($_GET['album_id'])?$_GET['album_id']:header("Location: fb-callback.php");
0 ignored issues
show
Are you sure the usage of header('Location: fb-callback.php') is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
54
$album_name = isset($_GET['album_name'])?$_GET['album_name']:header("Location: fb-callback.php");
0 ignored issues
show
Are you sure the usage of header('Location: fb-callback.php') is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
55
56
// Get photos of Facebook page album using Facebook Graph API
57
$graphPhoLink = "https://graph.facebook.com/v3.2/{$album_id}/photos?fields=source,images,name&access_token={$accessToken}";
58
$jsonData = file_get_contents($graphPhoLink);
59
$fbPhotoObj = json_decode($jsonData, true, 512, JSON_BIGINT_AS_STRING);
60
61
// Facebook photos content
62
$fbPhotoData = $fbPhotoObj['data'];
63
64
echo "<h2>".$album_name."</h2>";
65
66
// Render all photos   
67
if (is_array($fbPhotoData) || is_object($fbPhotoData))
68
{  
69
foreach($fbPhotoData as $data){
70
    $imageData = end($data['images']);
71
    $imgSource = isset($imageData['source'])?$imageData['source']:'';
72
    $name = isset($data['name'])?$data['name']:'';
73
74
    echo "<div class='item'>";
75
    echo "<img src='{$imgSource}' alt=''>";
76
 echo "<p>{$name}</p>";
77
    echo "</div>";
78
}
79
}
80
}
81
echo'</div>';
82
83
echo "<div class='slideshow-container'>";
84
85
// Render all photos 
86
if (is_array($fbPhotoData) || is_object($fbPhotoData))
87
{   
88
foreach($fbPhotoData as $data){
89
    $imageData = end($data['images']);
90
    $imgSource = isset($imageData['source'])?$imageData['source']:'';
91
    $name = isset($data['name'])?$data['name']:'';
92
93
echo "<div class='mySlides fade'>";
94
echo "<img src='{$imgSource}' alt='' style='width:100%'>";
95
echo "<div class='text'>{$name}</div>";
96
echo "</div>";
97
}
98
}
99
?>
100
<br>
101
102
  <div style="text-align:center">
103
  <?php
104
  if (is_array($fbPhotoData) || is_object($fbPhotoData))
105
  { 
106
    foreach($fbPhotoData as $data){
107
      echo "<span class='dot'></span>";
108
   }
109
  }
110
  ?>
111
  </div>
112
113
</div>
114
115
116
<script>
117
var slideIndex = 0;
118
showSlides();
119
120
function showSlides() {
121
  var i;
122
  var slides = document.getElementsByClassName("mySlides");
123
  var dots = document.getElementsByClassName("dot");
124
  for (i = 0; i < slides.length; i++) {
125
    slides[i].style.display = "none";  
126
  }
127
  slideIndex++;
128
  if (slideIndex > slides.length) {slideIndex = 1}    
129
  for (i = 0; i < dots.length; i++) {
130
    dots[i].className = dots[i].className.replace("active", "");
131
  }
132
  slides[slideIndex-1].style.display = "block";  
133
  dots[slideIndex-1].className += "active";
134
  setTimeout(showSlides, 2000); // Change image every 2 seconds
135
}
136
</script>
137
138
<style>
139
* {box-sizing: border-box;}
140
body {font-family: Verdana, sans-serif;}
141
.mySlides {display: none;}
142
img {vertical-align: middle;}
143
144
/* Slideshow container */
145
.slideshow-container {
146
  max-width: 1000px;
147
  position: relative;
148
  margin: auto;
149
}
150
151
/* Caption text */
152
.text {
153
  color: #f2f2f2;
154
  font-size: 15px;
155
  padding: 8px 12px;
156
  position: absolute;
157
  bottom: 8px;
158
  width: 100%;
159
  text-align: center;
160
}
161
162
/* Number text (1/3 etc) */
163
.numbertext {
164
  color: #f2f2f2;
165
  font-size: 12px;
166
  padding: 8px 12px;
167
  position: absolute;
168
  top: 0;
169
}
170
171
/* The dots/bullets/indicators */
172
.dot {
173
  height: 15px;
174
  width: 15px;
175
  margin: 0 2px;
176
  background-color: #bbb;
177
  border-radius: 50%;
178
  display: inline-block;
179
  transition: background-color 0.6s ease;
180
}
181
182
.active {
183
  background-color: #717171;
184
}
185
186
/* Fading animation */
187
.fade {
188
  -webkit-animation-name: fade;
189
  -webkit-animation-duration: 1.5s;
190
  animation-name: fade;
191
  animation-duration: 1.5s;
192
}
193
194
@-webkit-keyframes fade {
195
  from {opacity: .4} 
196
  to {opacity: 1}
197
}
198
199
@keyframes fade {
200
  from {opacity: .4} 
201
  to {opacity: 1}
202
}
203
204
/* On smaller screens, decrease text size */
205
@media only screen and (max-width: 300px) {
206
  .text {font-size: 11px}
207
}
208
</style>
209
210
}else{
211
    header('location:index.php');
212
}
213
?>