-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonstra_cms_fb_gallery.plugin.php
229 lines (186 loc) · 7.65 KB
/
monstra_cms_fb_gallery.plugin.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
/**
* Facebook page Gallery plugin
*
* @package Monstra
* @subpackage Plugins
* @author Graeme Moss / Gambi
* @copyright 2014 Graeme Moss / Gambi
* @version 1.0.0
*
*/
// Register plugin
Plugin::register( __FILE__,
__('Facebook page Gallery'),
__('Facebook page Gallery plugin for Monstra.'),
'1.0.0',
'Gambi',
'http://www.gambi.co.za','');
if (Session::exists('user_role') && in_array(Session::get('user_role'), array('admin'))) {
Plugin::admin('monstra_cms_fb_gallery');
}
Shortcode::add('fb_gallery', 'fb_gallery::_shortcode');
class fb_gallery extends Frontend{
public static $fb_id = "";
public static $un_num = "";
public static $page_name = "XGames";
public static function _shortcode($attributes) {
if (!empty($attributes['page'])){
fb_gallery::$page_name = $attributes['page'];
}
fb_gallery::main();
return fb_gallery::content();
}
public static function theme_footer() {
echo ('<script src="'.site::url(). DS .'plugins'. DS .'monstra_cms_fb_gallery/lib/ekko-lightbox.min.js"></script>');
echo ('<script type="text/javascript">
$(document).ready(function ($) {
$(document).delegate(\'*[data-toggle="lightbox"]\', \'click\', function(event) {
event.preventDefault();
$(this).ekkoLightbox();
});
});
</script>
');
}
public static function theme_header() {
echo (' <link href="'.site::url(). DS .'plugins'. DS .'monstra_cms_fb_gallery'.DS.'lib/ekko-lightbox.min.css" rel="stylesheet">');
echo ('<style type="text/css">
.post-content'.fb_gallery::$un_num.' {
margin: 0 auto;
margin-top: 0px;
text-align:center
position: relative;
}
.thumbnail'.fb_gallery::$un_num.' {
margin:0 auto;
text-align:center;
}
.wrapper'.fb_gallery::$un_num.' {
text-align:center;
padding:0;
}
</style>');
}
public static function main(){
fb_gallery::$un_num = rand(00000,99999);
fb_gallery::theme_header();
Action::add('theme_footer', 'fb_gallery::theme_footer');
fb_gallery::$fb_id = fb_gallery::getPageId(fb_gallery::$page_name);
}
/**
* Set Sandbox title
*/
public static function title()
{
return 'Gallery';
}
public static function name()
{
return 'Gallery';
}
/**
* Set Sandbox content
*/
public static function content()
{
$id = Request::get('fb_gallery_id');
if(empty($id)){
return fb_gallery::displayAlbums();
}
else{
return fb_gallery::displayPhotos(Request::get('fb_gallery_id'),Request::get('title'));
}
//return View::factory('monstra-cms-fb-gallery/views/frontend/index')
// ->display();
}
public static function displayPhotos($album_id,$title='Photos')
{
Cache::configure('cache_time', 43200);
$photocache = array();
$json_array = array();
$photocache = Cache::get('fb_gallery',$album_id);
$gallery = '';
if ($photocache) {
$json_array['data'] = $photocache;
}else{
$json_array = fb_gallery::getData($album_id,$type='photos');
Cache::put('fb_gallery',$album_id,$json_array['data']);
}
$data_count = count($json_array['data']);
if($data_count > 0)
{
$gallery = View::factory('monstra_cms_fb_gallery/views/frontend/photos')
->assign('photo_list', $json_array['data'])
->assign('photo_count', $data_count)
->assign('album_id', $album_id)
->assign('title', $title)
->render();
}else{
$gallery = 'no photos in this gallery';
}
return $gallery;
}
public static function displayAlbums()
{
Cache::configure('cache_time', 43200);
$albumcache = array();
$json_array = array();
$data = array();
$albumcache = Cache::get('fb_gallery',fb_gallery::$fb_id);
if ($albumcache) {
$json_array['data'] = $albumcache;
}else{
$json_array = fb_gallery::getData(fb_gallery::$fb_id,$type='albums');
Cache::put('fb_gallery',fb_gallery::$fb_id,$json_array['data']);
}
$data_count = count($json_array['data']);
for($x=0; $x<$data_count; $x++)
{
if(trim($json_array['data'][$x]['name']) == "Cover Photos"){continue;}
if($json_array['data'][$x]['name'] == "Profile Pictures"){continue;}
if(!empty($json_array['data'][$x]['object_id']) AND $json_array['data'][$x]['size'] > 0) // do not include empty albums
{
$data[] = $json_array['data'][$x];
}
}
$gallery = View::factory('monstra_cms_fb_gallery/views/frontend/album')
->assign('album_list', $data)
->assign('un_num', fb_gallery::$un_num)
->assign('album_count', $data_count)
->render();
return $gallery;
}
public static function getPageId($string)
{
/**
* Checks to see if page id is vaild
*/
if(is_numeric($string)){$query_where = 'page_id';}
else{$query_where = 'username';}
$query = "SELECT page_id FROM page WHERE $query_where = '$string'";
$url = 'https://graph.facebook.com/fql?q='.rawurlencode($query).'&format=json-strings';
$curlopts = array(CURLOPT_HEADER => '0', CURLOPT_RETURNTRANSFER => '1');
$return_data = Curl::get($url, $curlopts);
$json_array = json_decode($return_data,true);
if(isset($json_array['data'][0]['page_id'])){return $json_array['data'][0]['page_id'];}
else{die('invalid page id or name');}
}
public static function getData($id,$type='')
{
/**
* Sends each request Facebook (currently only for 'albums' and 'photos')
*/
if(!empty($id))
{
if($type == 'photos'){$query = "SELECT src,src_big,caption FROM photo WHERE aid = '$id'";}
else{$query = "SELECT aid,object_id,name,size,type FROM album WHERE owner = '$id' ORDER BY modified DESC";}
$url = 'https://graph.facebook.com/fql?q='.rawurlencode($query).'&format=json-strings';
$curlopts = array(CURLOPT_HEADER => '0', CURLOPT_RETURNTRANSFER => '1');
$return_data = Curl::get($url, $curlopts);
$json_array = json_decode($return_data,true);
return $json_array;
}
else{return 'id was empty';}
}
}