-
Notifications
You must be signed in to change notification settings - Fork 0
/
snippet.php
151 lines (120 loc) · 3.52 KB
/
snippet.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/*
#fbAlbum#
##About##
* By Philipp Schmidt
* fbAlbum
* Version: 0.1
* Creator: http://www.servingpixels.com
* GitHub: https://github.com/phantomphondler/FBAlbum
fbAlbum is a simple snippet for ModX Revolution that let you retrieve FB album pics.
© servingpixels.com 2018
###Thanks###
A big thank you goes to the creators of MODx Revolution!
###Usage###
<code>
[[!fbAlbum]]
</code>
##Configuration##
The variables that are available are listed below with a description.
* tpl - the chunk you want to use
* fb_page_id - Page id you can get it here https://findmyfbid.com or search google
* access_token - app key and secret key seperated by a | e.g. 9746629959044937|h9GLXXk3jKSeDpUBMS0pdvEiX0lA
* pics_per_page - how many pics you want to load. Note lots of pics will really slow down the page
* show_all - also show cover pic etc
* albumid - FB album URL you can get it from the URL
* debug - turn debug on off
##Chunk##
You can use the following
[[+large_image]]
[[+small_image]]
[[+orientation]]
[[+count]]
[[+album]]
[[+total]]
*/
$tpl = isset($tpl)? $tpl : "fbAlbumTpl";
$fb_page_id = isset($fb_page_id)? $fb_page_id : "";
$access_token = isset($access_token)? $access_token : "";
$pics_per_page = isset($pics_per_page)? $pics_per_page :10;
$show_all = isset($show_all)? $show_all :FALSE; //Set to TRUE to show Timelime Photos, Cover Photos & Profile Pictures
$albumid = isset($albumid)? $albumid :"";
$debug = isset($debug)? $debug :0;
if($access_token == ''){
$modx->log(modX::LOG_LEVEL_ERROR, '[FB] missing required properties!');
return;
}
function curl_get_contents($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$fields = "count,created_time,description,link,name";
$json_link = "https://graph.facebook.com/".$albumid."/?access_token={$access_token}&fields={$fields}";
$album = json_decode(curl_get_contents($json_link));
$album_name = $album->name;
$extra_params = "&limit=" . $pics_per_page;
$json_linkz = "https://graph.facebook.com/{$albumid}/photos/?access_token={$access_token}". $extra_params;
$json = json_decode(curl_get_contents($json_linkz));
$count = 0;
$totalsize = sizeof($json->data);
for($i = 1; $i <= $totalsize ; $i++):
$photo = $json->data[$i - 1];
$fields = "id,height,images,width,link,name,picture";
$album_link = "https://graph.facebook.com/{$photo->id}/?access_token={$access_token}&fields={$fields}";
$album_json = json_decode(curl_get_contents($album_link));
if(isset($album_json->images[4]->source))
{
$cover_ind = 4;
$pic = $album_json->images[$cover_ind]->source;
}
else
{
$cover_ind = 0;
$pic = $album_json->images[0]->source;
}
if($album_json->images[$cover_ind]->height < $album_json->images[$cover_ind]->width)
{
$orientation = "landscape";
}
else
{
$orientation = "portrait";
}
if(isset($album_json->images[1]))
{
$large = $album_json->images[1]->source;
}
else
{
$large = $album_json->images[0]->source;
}
$count++;
$output .= $modx->getChunk($tpl ,array(
'large_image'=> $large,
'small_image'=> $pic,
'orientation'=> $orientation,
'count' => $count,
'album' => $album_name,
'total' => $totalsize
));
$results .= $large.$pic.$orientation.$count.$album_name.$totalsize;
endfor;
if($debug == 0){
return $output;
}
else
if($debug == 1){
echo '
<pre>
';
print_r($results);
echo '
</pre>';
}