PluginProbe
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress / 1.5.9
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress v1.5.9
4.12.0 4.10.0 4.9.0 4.8.1 trunk 1.0 1.1 1.12.1 1.2.3 1.2.4 1.2.5 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.4.0 1.4.1 1.4.2 All 171 releases
custom-facebook-feed / custom-facebook-feed.php
custom-facebook-feed.php
963 lines 46.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Custom Facebook Feed
4 Plugin URI: http://smashballoon.com/custom-facebook-feed
5 Description: Add a completely customizable Facebook feed to your WordPress site
6 Version: 1.6.0
7 Author: Smash Balloon
8 Author URI: http://smashballoon.com/
9 License: GPLv2 or later
10 */
11 /*
12 Copyright 2013 Smash Balloon (email : hey@smashballoon.com)
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25 //Include admin
26 include dirname( __FILE__ ) .'/custom-facebook-feed-admin.php';
27 // Add shortcodes
28 add_shortcode('custom-facebook-feed', 'display_cff');
29 function display_cff($atts) {
30
31 //Style options
32 $options = get_option('cff_style_settings');
33 //Create the types string to set as shortcode default
34 if($options[ 'cff_show_links_type' ]) $type_string .= 'links,';
35 if($options[ 'cff_show_event_type' ]) $type_string .= 'events,';
36 if($options[ 'cff_show_video_type' ]) $type_string .= 'videos,';
37 if($options[ 'cff_show_photos_type' ]) $type_string .= 'photos,';
38 if($options[ 'cff_show_status_type' ]) $type_string .= 'statuses,';
39 //Create the types string to set as shortcode default
40 if($options[ 'cff_show_text' ]) $include_string .= 'text,';
41 if($options[ 'cff_show_desc' ]) $include_string .= 'desc,';
42 if($options[ 'cff_show_shared_links' ]) $include_string .= 'sharedlinks,';
43 if($options[ 'cff_show_date' ]) $include_string .= 'date,';
44 if($options[ 'cff_show_media' ]) $include_string .= 'media,';
45 if($options[ 'cff_show_event_title' ]) $include_string .= 'eventtitle,';
46 if($options[ 'cff_show_event_details' ]) $include_string .= 'eventdetails,';
47 if($options[ 'cff_show_meta' ]) $include_string .= 'social,';
48 if($options[ 'cff_show_link' ]) $include_string .= 'link,';
49 if($options[ 'cff_show_like_box' ]) $include_string .= 'likebox,';
50 //Pass in shortcode attrbutes
51 $atts = shortcode_atts(
52 array(
53 'id' => get_option('cff_page_id'),
54 'num' => get_option('cff_num_show'),
55 'limit' => get_option('cff_post_limit'),
56 'others' => get_option('cff_show_others'),
57 'cachetime' => get_option('cff_cache_time'),
58 'cacheunit' => get_option('cff_cache_time_unit'),
59 'width' => $options[ 'cff_feed_width' ],
60 'height' => $options[ 'cff_feed_height' ],
61 'padding' => $options[ 'cff_feed_padding' ],
62 'bgcolor' => $options[ 'cff_bg_color' ],
63 'showauthor' => $options[ 'cff_show_author' ],
64 'class' => $options[ 'cff_class' ],
65 'layout' => $options[ 'cff_preset_layout' ],
66 'type' => $type_string,
67 'include' => $include_string,
68 //Typography
69 'seemoretext' => $options[ 'cff_see_more_text' ],
70 'seelesstext' => $options[ 'cff_see_less_text' ],
71 'textformat' => $options[ 'cff_title_format' ],
72 'textsize' => $options[ 'cff_title_size' ],
73 'textweight' => $options[ 'cff_title_weight' ],
74 'textcolor' => $options[ 'cff_title_color' ],
75 'textlink' => $options[ 'cff_title_link' ],
76 'descsize' => $options[ 'cff_body_size' ],
77 'descweight' => $options[ 'cff_body_weight' ],
78 'desccolor' => $options[ 'cff_body_color' ],
79 //Event title
80 'eventtitleformat' => $options[ 'cff_event_title_format' ],
81 'eventtitlesize' => $options[ 'cff_event_title_size' ],
82 'eventtitleweight' => $options[ 'cff_event_title_weight' ],
83 'eventtitlecolor' => $options[ 'cff_event_title_color' ],
84 'eventtitlelink' => $options[ 'cff_event_title_link' ],
85 //Event date
86 'eventdatesize' => $options[ 'cff_event_date_size' ],
87 'eventdateweight' => $options[ 'cff_event_date_weight' ],
88 'eventdatecolor' => $options[ 'cff_event_date_color' ],
89 'eventdatepos' => $options[ 'cff_event_date_position' ],
90 'eventdateformat' => $options[ 'cff_event_date_formatting' ],
91 'eventdatecustom' => $options[ 'cff_event_date_custom' ],
92 //Event details
93 'eventdetailssize' => $options[ 'cff_event_details_size' ],
94 'eventdetailsweight' => $options[ 'cff_event_details_weight' ],
95 'eventdetailscolor' => $options[ 'cff_event_details_color' ],
96 //Date
97 'datepos' => $options[ 'cff_date_position' ],
98 'datesize' => $options[ 'cff_date_size' ],
99 'dateweight' => $options[ 'cff_date_weight' ],
100 'datecolor' => $options[ 'cff_date_color' ],
101 'dateformat' => $options[ 'cff_date_formatting' ],
102 'datecustom' => $options[ 'cff_date_custom' ],
103 'linksize' => $options[ 'cff_link_size' ],
104 'linkweight' => $options[ 'cff_link_weight' ],
105 'linkcolor' => $options[ 'cff_link_color' ],
106 'facebooklinktext' => $options[ 'cff_facebook_link_text' ],
107 'viewlinktext' => $options[ 'cff_view_link_text' ],
108 'iconstyle' => $options[ 'cff_icon_style' ],
109 'socialtextcolor' => $options[ 'cff_meta_text_color' ],
110 'socialbgcolor' => $options[ 'cff_meta_bg_color' ],
111 //Misc
112 'textlength' => get_option('cff_title_length'),
113 'desclength' => get_option('cff_body_length'),
114 'likeboxpos' => $options[ 'cff_like_box_position' ],
115 'likeboxoutside' => $options[ 'cff_like_box_outside' ],
116 'likeboxcolor' => $options[ 'cff_likebox_bg_color' ],
117 'videoheight' => $options[ 'cff_video_height' ],
118 'videoaction' => $options[ 'cff_video_action' ],
119 'sepcolor' => $options[ 'cff_sep_color' ],
120 'sepsize' => $options[ 'cff_sep_size' ]
121 ), $atts);
122 /********** GENERAL **********/
123 $cff_feed_width = $atts['width'];
124 $cff_feed_height = $atts[ 'height' ];
125 $cff_feed_padding = $atts[ 'padding' ];
126 $cff_bg_color = $atts[ 'bgcolor' ];
127 $cff_show_author = $atts[ 'showauthor' ];
128 $cff_cache_time = $atts[ 'cachetime' ];
129 if (!isset($cff_cache_time)) $cff_cache_time = 0;
130 $cff_cache_time_unit = $atts[ 'cacheunit' ];
131 $cff_class = $atts['class'];
132 //Compile feed styles
133 $cff_feed_styles = 'style="';
134 if ( !empty($cff_feed_width) ) $cff_feed_styles .= 'width:' . $cff_feed_width . '; ';
135 if ( !empty($cff_feed_height) ) $cff_feed_styles .= 'height:' . $cff_feed_height . '; ';
136 if ( !empty($cff_feed_padding) ) $cff_feed_styles .= 'padding:' . $cff_feed_padding . '; ';
137 if ( !empty($cff_bg_color) ) $cff_feed_styles .= 'background-color:#' . $cff_bg_color . '; ';
138 $cff_feed_styles .= '"';
139 //Like box
140 $cff_like_box_position = $atts[ 'likeboxpos' ];
141 $cff_like_box_outside = $atts[ 'likeboxoutside' ];
142 //Open links in new window?
143 $cff_open_links = $options[ 'cff_open_links' ];
144 $target = 'target="_blank"';
145 if ($cff_open_links) $target = 'target="_blank"';
146 /********** POST TYPES **********/
147 $cff_types = $atts[ 'type' ];
148 //Look for non-plural version of string in the types string in case user specifies singular in shortcode
149 $cff_show_links_type = true;
150 $cff_show_event_type = true;
151 $cff_show_video_type = true;
152 $cff_show_photos_type = true;
153 $cff_show_status_type = true;
154 $cff_events_only = false;
155 //Are we showing ONLY events?
156 if ($cff_show_event_type && !$cff_show_links_type && !$cff_show_video_type && !$cff_show_photos_type && !$cff_show_status_type) $cff_events_only = true;
157 /********** LAYOUT **********/
158 $cff_includes = $atts[ 'include' ];
159 //Look for non-plural version of string in the types string in case user specifies singular in shortcode
160 if ( stripos($cff_includes, 'text') !== false ) $cff_show_text = true;
161 if ( stripos($cff_includes, 'desc') !== false ) $cff_show_desc = true;
162 if ( stripos($cff_includes, 'sharedlink') !== false ) $cff_show_shared_links = true;
163 if ( stripos($cff_includes, 'date') !== false ) $cff_show_date = true;
164 if ( stripos($cff_includes, 'media') !== false ) $cff_show_media = true;
165 if ( stripos($cff_includes, 'eventtitle') !== false ) $cff_show_event_title = true;
166 if ( stripos($cff_includes, 'eventdetail') !== false ) $cff_show_event_details = true;
167 if ( stripos($cff_includes, 'social') !== false ) $cff_show_meta = true;
168 if ( stripos($cff_includes, ',link') !== false ) $cff_show_link = true; //comma used to separate it from 'sharedlinks' - which also contains 'link' string
169 if ( stripos($cff_includes, 'like') !== false ) $cff_show_like_box = true;
170 $cff_preset_layout = 'thumb';
171
172 /********** META **********/
173 $cff_icon_style = $atts[ 'iconstyle' ];
174 $cff_meta_text_color = $atts[ 'socialtextcolor' ];
175 $cff_meta_bg_color = $atts[ 'socialbgcolor' ];
176 $cff_meta_styles = 'style="';
177 if ( !empty($cff_meta_text_color) ) $cff_meta_styles .= 'color:#' . $cff_meta_text_color . ';';
178 if ( !empty($cff_meta_bg_color) ) $cff_meta_styles .= 'background-color:#' . $cff_meta_bg_color . ';';
179 $cff_meta_styles .= '"';
180 $cff_nocomments_text = $options[ 'cff_nocomments_text' ];
181 $cff_hide_comments = $options[ 'cff_hide_comments' ];
182 if (!isset($cff_nocomments_text) || empty($cff_nocomments_text)) $cff_hide_comments = true;
183 /********** TYPOGRAPHY **********/
184 //See More text
185 $cff_see_more_text = $atts[ 'seemoretext' ];
186 $cff_see_less_text = $atts[ 'seelesstext' ];
187 //See Less text
188 //Title
189 $cff_title_format = $atts[ 'textformat' ];
190 if (empty($cff_title_format)) $cff_title_format = 'p';
191 $cff_title_size = $atts[ 'textsize' ];
192 $cff_title_weight = $atts[ 'textweight' ];
193 $cff_title_color = $atts[ 'textcolor' ];
194 $cff_title_styles = 'style="';
195 if ( !empty($cff_title_size) && $cff_title_size != 'inherit' ) $cff_title_styles .= 'font-size:' . $cff_title_size . 'px; ';
196 if ( !empty($cff_title_weight) && $cff_title_weight != 'inherit' ) $cff_title_styles .= 'font-weight:' . $cff_title_weight . '; ';
197 if ( !empty($cff_title_color) ) $cff_title_styles .= 'color:#' . $cff_title_color . ';';
198 $cff_title_styles .= '"';
199 $cff_title_link = $atts[ 'textlink' ];
200 //Description
201 $cff_body_size = $atts[ 'descsize' ];
202 $cff_body_weight = $atts[ 'descweight' ];
203 $cff_body_color = $atts[ 'desccolor' ];
204 $cff_body_styles = 'style="';
205 if ( !empty($cff_body_size) && $cff_body_size != 'inherit' ) $cff_body_styles .= 'font-size:' . $cff_body_size . 'px; ';
206 if ( !empty($cff_body_weight) && $cff_body_weight != 'inherit' ) $cff_body_styles .= 'font-weight:' . $cff_body_weight . '; ';
207 if ( !empty($cff_body_color) ) $cff_body_styles .= 'color:#' . $cff_body_color . ';';
208 $cff_body_styles .= '"';
209 //Event Title
210 $cff_event_title_format = $atts[ 'eventtitleformat' ];
211 if (empty($cff_event_title_format)) $cff_event_title_format = 'p';
212 $cff_event_title_size = $atts[ 'eventtitlesize' ];
213 $cff_event_title_weight = $atts[ 'eventtitleweight' ];
214 $cff_event_title_color = $atts[ 'eventtitlecolor' ];
215 $cff_event_title_styles = 'style="';
216 if ( !empty($cff_event_title_size) && $cff_event_title_size != 'inherit' ) $cff_event_title_styles .= 'font-size:' . $cff_event_title_size . 'px; ';
217 if ( !empty($cff_event_title_weight) && $cff_event_title_weight != 'inherit' ) $cff_event_title_styles .= 'font-weight:' . $cff_event_title_weight . '; ';
218 if ( !empty($cff_event_title_color) ) $cff_event_title_styles .= 'color:#' . $cff_event_title_color . ';';
219 $cff_event_title_styles .= '"';
220 $cff_event_title_link = $atts[ 'eventtitlelink' ];
221 //Event Date
222 $cff_event_date_size = $atts[ 'eventdatesize' ];
223 $cff_event_date_weight = $atts[ 'eventdateweight' ];
224 $cff_event_date_color = $atts[ 'eventdatecolor' ];
225 $cff_event_date_position = $atts[ 'eventdatepos' ];
226 $cff_event_date_formatting = $atts[ 'eventdateformat' ];
227 $cff_event_date_custom = $atts[ 'eventdatecustom' ];
228 $cff_event_date_styles = 'style="';
229 if ( !empty($cff_event_date_size) && $cff_event_date_size != 'inherit' ) $cff_event_date_styles .= 'font-size:' . $cff_event_date_size . 'px; ';
230 if ( !empty($cff_event_date_weight) && $cff_event_date_weight != 'inherit' ) $cff_event_date_styles .= 'font-weight:' . $cff_event_date_weight . '; ';
231 if ( !empty($cff_event_date_color) ) $cff_event_date_styles .= 'color:#' . $cff_event_date_color . ';';
232 $cff_event_date_styles .= '"';
233 //Event Details
234 $cff_event_details_size = $atts[ 'eventdetailssize' ];
235 $cff_event_details_weight = $atts[ 'eventdetailsweight' ];
236 $cff_event_details_color = $atts[ 'eventdetailscolor' ];
237 $cff_event_details_styles = 'style="';
238 if ( !empty($cff_event_details_size) && $cff_event_details_size != 'inherit' ) $cff_event_details_styles .= 'font-size:' . $cff_event_details_size . 'px; ';
239 if ( !empty($cff_event_details_weight) && $cff_event_details_weight != 'inherit' ) $cff_event_details_styles .= 'font-weight:' . $cff_event_details_weight . '; ';
240 if ( !empty($cff_event_details_color) ) $cff_event_details_styles .= 'color:#' . $cff_event_details_color . ';';
241 $cff_event_details_styles .= '"';
242 //Date
243 $cff_date_position = $atts[ 'datepos' ];
244 if (!isset($cff_date_position)) $cff_date_position = 'below';
245 $cff_date_size = $atts[ 'datesize' ];
246 $cff_date_weight = $atts[ 'dateweight' ];
247 $cff_date_color = $atts[ 'datecolor' ];
248 $cff_date_styles = 'style="';
249 if ( !empty($cff_date_size) && $cff_date_size != 'inherit' ) $cff_date_styles .= 'font-size:' . $cff_date_size . 'px; ';
250 if ( !empty($cff_date_weight) && $cff_date_weight != 'inherit' ) $cff_date_styles .= 'font-weight:' . $cff_date_weight . '; ';
251 if ( !empty($cff_date_color) ) $cff_date_styles .= 'color:#' . $cff_date_color . ';';
252 $cff_date_styles .= '"';
253 $cff_date_before = $options[ 'cff_date_before' ];
254 $cff_date_after = $options[ 'cff_date_after' ];
255 //Link to Facebook
256 $cff_link_size = $atts[ 'linksize' ];
257 $cff_link_weight = $atts[ 'linkweight' ];
258 $cff_link_color = $atts[ 'linkcolor' ];
259 $cff_link_styles = 'style="';
260 if ( !empty($cff_link_size) && $cff_link_size != 'inherit' ) $cff_link_styles .= 'font-size:' . $cff_link_size . 'px; ';
261 if ( !empty($cff_link_weight) && $cff_link_weight != 'inherit' ) $cff_link_styles .= 'font-weight:' . $cff_link_weight . '; ';
262 if ( !empty($cff_link_color) ) $cff_link_styles .= 'color:#' . $cff_link_color . ';';
263 $cff_link_styles .= '"';
264 $cff_facebook_link_text = $atts[ 'facebooklinktext' ];
265 $cff_view_link_text = $atts[ 'viewlinktext' ];
266 /********** MISC **********/
267 //Like Box styles
268 $cff_likebox_bg_color = $atts[ 'likeboxcolor' ];
269 $cff_likebox_styles = 'style="';
270 if ( !empty($cff_likebox_bg_color) ) $cff_likebox_styles .= 'background-color:#' . $cff_likebox_bg_color . '; margin-left: 0; ';
271 $cff_likebox_styles .= '"';
272 //Video
273 //Dimensions
274 $cff_video_width = 640;
275 $cff_video_height = $atts[ 'videoheight' ];
276
277 if ($cff_thumb_layout) {
278 if(empty($cff_video_height)) $cff_video_height = 100;
279 } else if ($cff_half_layout) {
280 if(empty($cff_video_height)) $cff_video_height = 180;
281 } else {
282 if(empty($cff_video_height)) $cff_video_height = 360;
283 }
284 //Action
285 $cff_video_action = $atts[ 'videoaction' ];
286 //Separating Line
287 $cff_sep_color = $atts[ 'sepcolor' ];
288 if (empty($cff_sep_color)) $cff_sep_color = 'ddd';
289 $cff_sep_size = $atts[ 'sepsize' ];
290 if (empty($cff_sep_size)) $cff_sep_size = 0;
291 //CFF item styles
292 $cff_item_styles = 'style="';
293 $cff_item_styles .= 'border-bottom: ' . $cff_sep_size . 'px solid #' . $cff_sep_color . '; ';
294 $cff_item_styles .= '"';
295
296 //Text limits
297 $title_limit = $atts['textlength'];
298 if (!isset($title_limit)) $title_limit = 9999;
299 $body_limit = $atts['desclength'];
300 //Assign the Access Token and Page ID variables
301 $access_token = get_option('cff_access_token');
302 $page_id = $atts['id'];
303 //Get show posts attribute. If not set then default to 25
304 $show_posts = $atts['num'];
305 if (empty($show_posts)) $show_posts = 25;
306 if ( $show_posts == 0 || $show_posts == undefined ) $show_posts = 25;
307 //Check whether the Access Token is present and valid
308 if ($access_token == '') {
309 echo 'Please enter a valid Access Token. You can do this in the Custom Facebook Feed plugin settings.<br /><br />';
310 return false;
311 }
312 //Check whether a Page ID has been defined
313 if ($page_id == '') {
314 echo "Please enter the Page ID of the Facebook feed you'd like to display. You can do this in either the Custom Facebook Feed plugin settings or in the shortcode itself. For example [custom_facebook_feed id=<b>YOUR_PAGE_ID</b>].<br /><br />";
315 return false;
316 }
317 //Use posts? or feed?
318 $show_others = $atts['others'];
319 $graph_query = 'posts';
320 if ($show_others) $graph_query = 'feed';
321 $cff_post_limit = $atts['limit'];
322 //Calculate the cache time in seconds
323 if($cff_cache_time_unit == 'minutes') $cff_cache_time_unit = 60;
324 if($cff_cache_time_unit == 'hours') $cff_cache_time_unit = 60*60;
325 if($cff_cache_time_unit == 'days') $cff_cache_time_unit = 60*60*24;
326 $cache_seconds = $cff_cache_time * $cff_cache_time_unit;
327 //Set like box variable
328 $like_box = '<div class="cff-likebox';
329 if ($cff_like_box_outside) $like_box .= ' outside';
330 $like_box .= ($cff_like_box_position == 'top') ? ' top' : ' bottom';
331 $like_box .= '"' . $cff_likebox_styles . '><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like-box href="http://www.facebook.com/' . $page_id . '" width="300" show_faces="false" stream="false" header="true"></fb:like-box></div>';
332 //***START FEED***
333 $content = '';
334 //Add like box to the outside of the top of feed
335 if ($cff_like_box_position == 'top' && $cff_show_like_box && $cff_like_box_outside) $content .= $like_box;
336 //Create CFF container HTML
337 $content .= '<div id="cff" rel="'.$title_limit.'" class="';
338 if( !empty($cff_class) ) $content .= $cff_class . ' ';
339 if ( !empty($cff_feed_height) ) $content .= 'fixed-height ';
340 if ( $cff_thumb_layout ) $content .= 'thumb-layout ';
341 // if ( $cff_media_medium ) $content .= 'medium-image ';
342 if ( $cff_half_layout ) $content .= 'half-layout ';
343 $content .= '" ' . $cff_feed_styles . '>';
344 //Add like box to the inside of the top of feed
345 if ($cff_like_box_position == 'top' && $cff_show_like_box && !$cff_like_box_outside) $content .= $like_box;
346 //Limit var
347 $i = 0;
348
349
350 //ALL POSTS
351 if (!$cff_events_only){
352
353 // Get any existing copy of our transient data
354 $transient_name = 'cff_posts_json_' . $page_id;
355 if ( false === ( $posts_json = get_transient( $transient_name ) ) || $posts_json === null ) {
356 //Get the contents of the Facebook page
357 $posts_json = fetchUrl('https://graph.facebook.com/' . $page_id . '/' . $graph_query . '?access_token=' . $access_token . '&limit=' . $cff_post_limit);
358 //Cache the JSON
359 set_transient( $transient_name, $posts_json, $cache_seconds );
360 } else {
361 $posts_json = get_transient( $transient_name );
362 }
363
364 //Interpret data with JSON
365 $FBdata = json_decode($posts_json);
366 //***STARTS POSTS LOOP***
367 foreach ($FBdata->data as $news )
368 {
369 //Explode News and Page ID's into 2 values
370 $PostID = explode("_", $news->id);
371 //Check the post type
372 $cff_post_type = $news->type;
373 if ($cff_post_type == 'link') {
374 $story = $news->story;
375 //Check whether it's an event
376 $created_event = 'created an event.';
377 $shared_event = 'shared an event.';
378 $created_event = stripos($story, $created_event);
379 $shared_event = stripos($story, $shared_event);
380 if ( $created_event || $shared_event ) $cff_post_type = 'event';
381 }
382 //Should we show this post or not?
383 $cff_show_post = false;
384 switch ($cff_post_type) {
385 case 'link':
386 if ( $cff_show_links_type ) $cff_show_post = true;
387 break;
388 case 'event':
389 if ( $cff_show_event_type ) $cff_show_post = true;
390 break;
391 case 'video':
392 if ( $cff_show_video_type ) $cff_show_post = true;
393 break;
394 case 'swf':
395 if ( $cff_show_video_type ) $cff_show_post = true;
396 break;
397 case 'photo':
398 if ( $cff_show_photos_type ) $cff_show_post = true;
399 break;
400 case 'status':
401 //Check whether it's a status (author comment or like)
402 if ( $cff_show_status_type && !empty($news->message) ) $cff_show_post = true;
403 break;
404 }
405 //Is it a duplicate post?
406 if ( ($prev_post_message == $news->message) && ($prev_post_link == $news->link) && ($prev_post_description == $news->description) ) $cff_show_post = false;
407 //Check post type and display post if selected
408 if ( $cff_show_post ) {
409 //If it isn't then create the post
410 //Only create posts for the amount of posts specified
411 if ( $i == $show_posts ) break;
412 $i++;
413 //********************************//
414 //***COMPILE SECTION VARIABLES***//
415 //********************************//
416
417 //Set the post link
418 $link = $news->link;
419 //Is it a shared album?
420 $shared_album_string = 'shared an album:';
421 $shared_album = stripos($news->story, $shared_album_string);
422 if ( $shared_album ) {
423 $link = str_replace('photo.php?','media/set/?',$link);
424 }
425 //If there's no link provided then link to Facebook page
426 if (empty($news->link)) $link = 'http://facebook.com/' . $page_id;
427 //POST AUTHOR
428 $cff_author = '<a class="cff-author" href="http://facebook.com/' . $news->from->id . '" '.$target.' title="'.$news->from->name.' on Facebook">';
429 $cff_author .= '<img src="http://graph.facebook.com/' . $news->from->id . '/picture">';
430 $cff_author .= '<p>'.$news->from->name.'</p>';
431 $cff_author .= '</a>';
432 //POST TEXT
433 $cff_post_text = '<' . $cff_title_format . ' class="cff-post-text" ' . $cff_title_styles . '>';
434 $cff_post_text .= '<span class="text">';
435 if ($cff_title_link) $cff_post_text .= '<a class="cff-post-text-link" href="'.$link.'" '.$target.'>';
436 if (!empty($news->story)) $post_text = $news->story;
437 if (!empty($news->message)) $post_text = $news->message;
438 if (!empty($news->name) && empty($news->story) && empty($news->message)) $post_text = $news->name;
439 //If the text is wrapped in a link then don't hyperlink any text within
440 if ($cff_title_link) {
441 //Wrap links in a span so we can break the text if it's too long
442 $cff_post_text .= cff_wrap_span($post_text) . ' ';
443 } else {
444 $cff_post_text .= cff_make_clickable($post_text) . ' ';
445 }
446
447 if ($cff_title_link) $cff_post_text .= '</a>';
448 $cff_post_text .= '</span>';
449 //'See More' link
450 $cff_post_text .= '<span class="cff-expand">... <a href="#"><span class="more">' . $cff_see_more_text . '</span><span class="less">' . $cff_see_less_text . '</span></a></span>';
451 $cff_post_text .= '</' . $cff_title_format . '>';
452 //DESCRIPTION
453 $cff_description = '';
454 if (!empty($news->description)) {
455 $description_text = $news->description;
456 if (!empty($body_limit)) {
457 if (strlen($description_text) > $body_limit) $description_text = substr($description_text, 0, $body_limit) . '...';
458 }
459 $cff_description .= '<p class="cff-post-desc" '.$cff_body_styles.'><span>' . cff_make_clickable($description_text) . '</span></p>';
460 }
461 //LINK
462 $cff_shared_link = '';
463 //Display shared link
464 if ($news->type == 'link') {
465 //Display link name and description
466 if (!empty($news->description)) {
467 $cff_shared_link .= '<p class="text-link ';
468 $cff_shared_link .= 'no-image';
469 $cff_shared_link .= '"><a href="'.$link.'" '.$target.'>'. '<b>' . $news->name . '</b></a></p>';
470 }
471 }
472 //DATE
473 $cff_date_formatting = $atts[ 'dateformat' ];
474 $cff_date_custom = $atts[ 'datecustom' ];
475 $cff_date = '<p class="cff-date" '.$cff_date_styles.'>'. $cff_date_before . ' ' . cff_getdate(strtotime($news->created_time), $cff_date_formatting, $cff_date_custom) . ' ' . $cff_date_after . '</p>';
476 //EVENT
477 $cff_event = '';
478 if ($cff_show_event_title || $cff_show_event_details) {
479 //Check for media
480 if ($cff_post_type == 'event') {
481
482 //Get the event object
483 $eventID = $PostID[1];
484 if ( $shared_event ) {
485 //Get the event id from the event URL. eg: http://www.facebook.com/events/123451234512345/
486 $event_url = parse_url($link);
487 $url_parts = explode('/', $event_url['path']);
488 //Get the id from the parts
489 $eventID = $url_parts[count($url_parts)-2];
490 }
491 //Get the contents of the event using the WP HTTP API
492 $event_json = fetchUrl('https://graph.facebook.com/'.$eventID.'?access_token=' . $access_token);
493 //Interpret data with JSON
494 $event_object = json_decode($event_json);
495 //Event date
496 $event_time = $event_object->start_time;
497 //If timezone migration is enabled then remove last 5 characters
498 if ( strlen($event_time) == 24 ) $event_time = substr($event_time, 0, -5);
499 if (!empty($event_time)) $cff_event_date = '<p class="cff-date" '.$cff_event_date_styles.'>' . cff_eventdate(strtotime($event_time), $cff_event_date_formatting, $cff_event_date_custom) . '</p>';
500 //EVENT
501 //Display the event details
502 $cff_event .= '<div class="details">';
503 //show event date above title
504 if ($cff_event_date_position == 'above') $cff_event .= $cff_event_date;
505 //Show event title
506 if ($cff_show_event_title && !empty($event_object->name)) {
507 if ($cff_event_title_link) $cff_event .= '<a href="'.$link.'">';
508 $cff_event .= '<' . $cff_event_title_format . ' ' . $cff_event_title_styles . '>' . $event_object->name . '</' . $cff_event_title_format . '>';
509 if ($cff_event_title_link) $cff_event .= '</a>';
510 }
511 //show event date below title
512 if ($cff_event_date_position !== 'above') $cff_event .= $cff_event_date;
513 //Show event details
514 if ($cff_show_event_details){
515 //Location
516 if (!empty($event_object->location)) $cff_event .= '<p class="where" ' . $cff_event_details_styles . '>' . $event_object->location . '</p>';
517 //Description
518 if (!empty($event_object->description)){
519 $description = $event_object->description;
520 if (!empty($body_limit)) {
521 if (strlen($description) > $body_limit) $description = substr($description, 0, $body_limit) . '...';
522 }
523 $cff_event .= '<p class="info" ' . $cff_event_details_styles . '>' . cff_make_clickable($description) . '</p>';
524 }
525 }
526 $cff_event .= '</div>';
527
528 }
529 }
530
531 //Display the link to the Facebook post or external link
532 $cff_link = '';
533 //Default link
534 if ($cff_facebook_link_text == '') $cff_facebook_link_text = 'View on Facebook';
535 $link_text = $cff_facebook_link_text;
536 if (!empty($news->link)) {
537 //Check whether it links to facebook or somewhere else
538 $facebook_str = 'facebook.com';
539 if(stripos($link, $facebook_str) == false) {
540 if ($cff_view_link_text == '') $cff_view_link_text = 'View Link';
541 $link_text = $cff_view_link_text;
542 }
543 }
544 $cff_link = '<a class="cff-viewpost" href="' . $link . '" title="' . $link_text . '" ' . $target . ' ' . $cff_link_styles . '>' . $link_text . '</a>';
545 //Compile the meta and link if included
546 if ($cff_show_meta) $cff_meta_total .= $cff_meta;
547 if ($cff_show_link) $cff_meta_total .= $cff_link;
548 $cff_meta_total .= '</div>';
549 $cff_comments = '';
550 if ( !($comment_count == 0 && $cff_hide_comments) ) {
551 //Create the comments box
552 $cff_comments .= '<div class="comments-box" ' . $cff_meta_styles . '>';
553 //Get the comments
554 if (!empty($news->comments->data)){
555 foreach ($news->comments->data as $comment_item ) {
556 $comment = $comment_item->message;
557 $cff_comments .= '<p><a href="http://facebook.com/'. $comment_item->from->id .'" class="name" '.$target.' ' . $cff_meta_styles . '>' . $comment_item->from->name . '</a>' . cff_make_clickable($comment) . '<span class="time">'. cff_timeSince(strtotime($comment_item->created_time)) . '</span></p>';
558 }
559 } else {
560 $cff_comments .= '<p>' . $cff_nocomments_text . '</p>';
561 }
562 $cff_comments .= '</div>';
563 }
564 //Compile comments if meta is included
565 if ($cff_show_meta) $cff_meta_total .= $cff_comments;
566 //**************************//
567 //***CREATE THE POST HTML***//
568 //**************************//
569 //Start the container
570 $content .= '<div class="cff-item ';
571 if ($news->type == 'link') $content .= 'link-item';
572 $content .= '" id="'. $news->id .'" ' . $cff_item_styles . '>';
573
574 //POST AUTHOR
575 if($cff_show_author) $content .= $cff_author;
576 //DATE ABOVE
577 if ($cff_show_date && $cff_date_position == 'above') $content .= $cff_date;
578 //POST TEXT
579 if($cff_show_text) $content .= $cff_post_text;
580 //DESCRIPTION
581 if($cff_show_desc) $content .= $cff_description;
582 //LINK
583 if($cff_show_shared_links) $content .= $cff_shared_link;
584 //DATE BELOW
585 if ($cff_show_date && $cff_date_position == 'below') $content .= $cff_date;
586 //VIEW ON FACEBOOK LINK
587 if($cff_show_link) $content .= $cff_link;
588
589 //EVENT
590 if($cff_show_event_title || $cff_show_event_details) $content .= $cff_event;
591
592 //End the post item
593 $content .= '</div><div class="clear"></div>';
594 } // End post type check
595 $prev_post_message = $news->message;
596 $prev_post_link = $news->link;
597 $prev_post_description = $news->description;
598 } // End the loop
599 } // End ALL POSTS
600 //Load more posts
601 // $content .= '<button class="loadmore">Load More Posts</button>';
602 //Add the Like Box inside
603 if ($cff_like_box_position == 'bottom' && $cff_show_like_box && !$cff_like_box_outside) $content .= $like_box;
604 //End the feed
605 $content .= '</div><div class="clear"></div>';
606 //Add the Like Box outside
607 if ($cff_like_box_position == 'bottom' && $cff_show_like_box && $cff_like_box_outside) $content .= $like_box;
608 //Return our feed HTML to display
609 return $content;
610 }
611 //Get JSON object of feed data
612 function fetchUrl($url){
613 //Can we use cURL?
614 if(is_callable('curl_init')){
615 $ch = curl_init();
616 curl_setopt($ch, CURLOPT_URL, $url);
617 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
618 curl_setopt($ch, CURLOPT_TIMEOUT, 20);
619 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
620 $feedData = curl_exec($ch);
621 curl_close($ch);
622 //If not then use file_get_contents
623 } elseif ( ini_get('allow_url_fopen') == 1 || ini_get('allow_url_fopen') === TRUE ) {
624 $feedData = @file_get_contents($url);
625 //Or else use the WP HTTP API
626 } else {
627 if( !class_exists( 'WP_Http' ) ) include_once( ABSPATH . WPINC. '/class-http.php' );
628 $request = new WP_Http;
629 $result = $request->request($url);
630 $feedData = $result['body'];
631 }
632
633 return $feedData;
634 }
635 //***FUNCTIONS***
636 //Make links in text clickable
637 function cff_make_clickable($text) {
638 $pattern = '#\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#';
639 return preg_replace_callback($pattern, 'auto_link_text_callback', $text);
640 }
641 function auto_link_text_callback($matches) {
642 $max_url_length = 50;
643 $max_depth_if_over_length = 2;
644 $ellipsis = '&hellip;';
645 $target = 'target="_blank"';
646 $url_full = $matches[0];
647 $url_short = '';
648 if (strlen($url_full) > $max_url_length) {
649 $parts = parse_url($url_full);
650 $url_short = $parts['scheme'] . '://' . preg_replace('/^www\./', '', $parts['host']) . '/';
651 $path_components = explode('/', trim($parts['path'], '/'));
652 foreach ($path_components as $dir) {
653 $url_string_components[] = $dir . '/';
654 }
655 if (!empty($parts['query'])) {
656 $url_string_components[] = '?' . $parts['query'];
657 }
658 if (!empty($parts['fragment'])) {
659 $url_string_components[] = '#' . $parts['fragment'];
660 }
661 for ($k = 0; $k < count($url_string_components); $k++) {
662 $curr_component = $url_string_components[$k];
663 if ($k >= $max_depth_if_over_length || strlen($url_short) + strlen($curr_component) > $max_url_length) {
664 if ($k == 0 && strlen($url_short) < $max_url_length) {
665 // Always show a portion of first directory
666 $url_short .= substr($curr_component, 0, $max_url_length - strlen($url_short));
667 }
668 $url_short .= $ellipsis;
669 break;
670 }
671 $url_short .= $curr_component;
672 }
673 } else {
674 $url_short = $url_full;
675 }
676 return "<a class='break-word' rel=\"nofollow\" href=\"$url_full\">$url_full</a>";
677 }
678 //Make links into span instead when the post text is made clickable
679 function cff_wrap_span($text) {
680 $pattern = '#\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#';
681 return preg_replace_callback($pattern, 'cff_wrap_span_callback', $text);
682 }
683 function cff_wrap_span_callback($matches) {
684 $max_url_length = 50;
685 $max_depth_if_over_length = 2;
686 $ellipsis = '&hellip;';
687 $target = 'target="_blank"';
688 $url_full = $matches[0];
689 $url_short = '';
690 if (strlen($url_full) > $max_url_length) {
691 $parts = parse_url($url_full);
692 $url_short = $parts['scheme'] . '://' . preg_replace('/^www\./', '', $parts['host']) . '/';
693 $path_components = explode('/', trim($parts['path'], '/'));
694 foreach ($path_components as $dir) {
695 $url_string_components[] = $dir . '/';
696 }
697 if (!empty($parts['query'])) {
698 $url_string_components[] = '?' . $parts['query'];
699 }
700 if (!empty($parts['fragment'])) {
701 $url_string_components[] = '#' . $parts['fragment'];
702 }
703 for ($k = 0; $k < count($url_string_components); $k++) {
704 $curr_component = $url_string_components[$k];
705 if ($k >= $max_depth_if_over_length || strlen($url_short) + strlen($curr_component) > $max_url_length) {
706 if ($k == 0 && strlen($url_short) < $max_url_length) {
707 // Always show a portion of first directory
708 $url_short .= substr($curr_component, 0, $max_url_length - strlen($url_short));
709 }
710 $url_short .= $ellipsis;
711 break;
712 }
713 $url_short .= $curr_component;
714 }
715 } else {
716 $url_short = $url_full;
717 }
718 return "<span class='break-word'>$url_short</span>";
719 }
720 //2013-04-28T21:06:56+0000
721 //Time stamp function - used for posts
722 function cff_getdate($original, $date_format, $custom_date) {
723 switch ($date_format) {
724
725 case '2':
726 $print = date('F jS, g:i a', $original);
727 break;
728 case '3':
729 $print = date('F jS', $original);
730 break;
731 case '4':
732 $print = date('D F jS', $original);
733 break;
734 case '5':
735 $print = date('l F jS', $original);
736 break;
737 case '6':
738 $print = date('D M jS, Y', $original);
739 break;
740 case '7':
741 $print = date('l F jS, Y', $original);
742 break;
743 case '8':
744 $print = date('l F jS, Y - g:i a', $original);
745 break;
746 case '9':
747 $print = date("l M jS, 'y", $original);
748 break;
749 case '10':
750 $print = date('m.d.y', $original);
751 break;
752 case '11':
753 $print = date('m/d/y', $original);
754 break;
755 case '12':
756 $print = date('d.m.y', $original);
757 break;
758 case '13':
759 $print = date('d/m/y', $original);
760 break;
761 default:
762
763 $periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
764 $lengths = array("60","60","24","7","4.35","12","10");
765 $now = time();
766
767 // is it future date or past date
768 if($now > $original) {
769 $difference = $now - $original;
770 $tense = "ago";
771 } else {
772 $difference = $original - $now;
773 $tense = "from now";
774 }
775 for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
776 $difference /= $lengths[$j];
777 }
778
779 $difference = round($difference);
780
781 if($difference != 1) {
782 $periods[$j].= "s";
783 }
784 $print = "$difference $periods[$j] {$tense}";
785 break;
786
787 }
788 if ( !empty($custom_date) ){
789 $print = date($custom_date, $original);
790 }
791 return $print;
792 }
793 function cff_eventdate($original, $date_format, $custom_date) {
794 switch ($date_format) {
795
796 case '2':
797 $print = date('F jS, g:ia', $original);
798 break;
799 case '3':
800 $print = date('g:ia - F jS', $original);
801 break;
802 case '4':
803 $print = date('g:ia, F jS', $original);
804 break;
805 case '5':
806 $print = date('l F jS - g:ia', $original);
807 break;
808 case '6':
809 $print = date('D M jS, Y, g:iA', $original);
810 break;
811 case '7':
812 $print = date('l F jS, Y, g:iA', $original);
813 break;
814 case '8':
815 $print = date('l F jS, Y - g:ia', $original);
816 break;
817 case '9':
818 $print = date("l M jS, 'y", $original);
819 break;
820 case '10':
821 $print = date('m.d.y - g:iA', $original);
822 break;
823 case '11':
824 $print = date('m/d/y, g:ia', $original);
825 break;
826 case '12':
827 $print = date('d.m.y - g:iA', $original);
828 break;
829 case '13':
830 $print = date('d/m/y, g:ia', $original);
831 break;
832 default:
833 $print = date('F j, Y, g:ia', $original);
834 break;
835 }
836 if ( !empty($custom_date) ){
837 $print = date($custom_date, $original);
838 }
839 return $print;
840 }
841 //Time stamp function - used for comments
842 function cff_timesince($original) {
843
844 $periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
845 $lengths = array("60","60","24","7","4.35","12","10");
846 $now = time();
847
848 // is it future date or past date
849 if($now > $original) {
850 $difference = $now - $original;
851 $tense = "ago";
852 } else {
853 $difference = $original - $now;
854 $tense = "from now";
855 }
856 for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
857 $difference /= $lengths[$j];
858 }
859
860 $difference = round($difference);
861
862 if($difference != 1) {
863 $periods[$j].= "s";
864 }
865 return "$difference $periods[$j] {$tense}";
866
867 }
868 //Use custom stripos function if it's not available (only available in PHP 5+)
869 if(!is_callable('stripos')){
870 function stripos($haystack, $needle){
871 return strpos($haystack, stristr( $haystack, $needle ));
872 }
873 }
874 //Enqueue stylesheet
875 add_action( 'wp_enqueue_scripts', 'cff_add_my_stylesheet' );
876 function cff_add_my_stylesheet() {
877 // Respects SSL, Style.css is relative to the current file
878 wp_register_style( 'cff', plugins_url('css/cff-style.css?3', __FILE__) );
879 wp_enqueue_style( 'cff' );
880 }
881 //Enqueue scripts
882 add_action( 'wp_enqueue_scripts', 'cff_scripts_method' );
883 function cff_scripts_method() {
884 wp_enqueue_script(
885 'cffscripts',
886 plugins_url( '/js/cff-scripts.js?3' , __FILE__ ),
887 array( 'jquery' )
888 );
889 }
890 //Allows shortcodes in theme
891 add_filter('widget_text', 'do_shortcode');
892 function cff_activate() {
893 $options = get_option('cff_style_settings');
894 $options[ 'cff_show_links_type' ] = true;
895 $options[ 'cff_show_event_type' ] = true;
896 $options[ 'cff_show_video_type' ] = true;
897 $options[ 'cff_show_photos_type' ] = true;
898 $options[ 'cff_show_status_type' ] = true;
899 // Show all parts of the feed by default on activation
900 $options[ 'cff_show_text' ] = true;
901 $options[ 'cff_show_desc' ] = true;
902 $options[ 'cff_show_shared_links' ] = true;
903 $options[ 'cff_show_date' ] = true;
904 $options[ 'cff_show_media' ] = true;
905 $options[ 'cff_show_event_title' ] = true;
906 $options[ 'cff_show_event_details' ] = true;
907 $options[ 'cff_show_meta' ] = true;
908 $options[ 'cff_show_link' ] = true;
909 $options[ 'cff_show_like_box' ] = true;
910 update_option( 'cff_style_settings', $options );
911 }
912 register_activation_hook( __FILE__, 'cff_activate' );
913 //Uninstall
914 function cff_uninstall()
915 {
916 if ( ! current_user_can( 'activate_plugins' ) )
917 return;
918 //Settings
919 delete_option( 'cff_access_token' );
920 delete_option( 'cff_page_id' );
921 delete_option( 'cff_num_show' );
922 delete_option( 'cff_post_limit' );
923 delete_option( 'cff_show_others' );
924 delete_option('cff_cache_time');
925 delete_option('cff_cache_time_unit');
926 //Style & Layout
927 delete_option( 'cff_title_length' );
928 delete_option( 'cff_body_length' );
929 delete_option('cff_style_settings');
930 }
931 register_uninstall_hook( __FILE__, 'cff_uninstall' );
932 add_action( 'wp_head', 'cff_custom_css' );
933 function cff_custom_css() {
934 $options = get_option('cff_style_settings');
935 $cff_custom_css = $options[ 'cff_custom_css' ];
936 echo '<!-- Custom Facebook Feed Custom CSS -->';
937 echo "\r\n";
938 echo '<style type="text/css">';
939 echo "\r\n";
940 echo $cff_custom_css;
941 echo "\r\n";
942 echo '</style>';
943 echo "\r\n";
944 }
945 add_action( 'wp_footer', 'cff_js' );
946 function cff_js() {
947 // $path = site_url();
948 $url = site_url();
949 $path = urlencode(ABSPATH);
950 echo '<!-- Custom Facebook Feed JS -->';
951 echo "\r\n";
952 echo '<script type="text/javascript">';
953 echo "\r\n";
954 echo 'var siteURL = "' . $url . '";';
955 echo "\r\n";
956 echo 'var rootPath = "' . $path . '";';
957 echo "\r\n";
958 echo '</script>';
959 echo "\r\n";
960 }
961 //Comment out the line below to view errors
962 error_reporting(0);
963 ?>