PluginProbe ʕ •ᴥ•ʔ
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress / 1.4.5
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress v1.4.5
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 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5 1.5.1 1.5.2 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.5.1 1.6.6 1.6.6.1 1.6.6.2 1.6.6.3 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.9.0 1.9.1 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.8.1 1.9.9 1.9.9.1 1.9.9.2 1.9.9.3 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.10 2.11 2.11.1 2.12 2.12.1 2.12.2 2.12.3 2.12.4 2.13 2.14 2.14.1 2.15 2.15.1 2.16 2.16.1 2.17 2.17.1 2.18 2.18.1 2.18.2 2.18.3 2.19 2.19.1 2.19.2 2.19.3 2.2 2.2.1 2.3 2.3.1 2.3.10 2.3.2 2.3.3 2.3.4 2.3.6 2.3.7 2.3.8 2.3.9 2.4 2.4.1 2.4.1.1 2.4.1.2 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5 2.5.1 2.5.2 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.7 2.7.1 2.7.2 2.8 2.9 2.9.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.7.5 4.7.6 4.7.7
custom-facebook-feed / custom-facebook-feed.php
custom-facebook-feed Last commit date
css 12 years ago img 12 years ago README.txt 12 years ago custom-facebook-feed-admin.php 12 years ago custom-facebook-feed.php 12 years ago gpl-2.0.txt 13 years ago
custom-facebook-feed.php
561 lines
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.4.5
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
34 //Create the types string to set as shortcode default
35 if($options[ 'cff_show_text' ]) $include_string .= 'text,';
36 if($options[ 'cff_show_desc' ]) $include_string .= 'desc,';
37 if($options[ 'cff_show_date' ]) $include_string .= 'date,';
38 if($options[ 'cff_show_event_title' ]) $include_string .= 'eventtitle,';
39 if($options[ 'cff_show_event_details' ]) $include_string .= 'eventdetails,';
40 if($options[ 'cff_show_link' ]) $include_string .= 'link';
41 if($options[ 'cff_show_like_box' ]) $include_string .= 'likebox,';
42
43 //Pass in shortcode attrbutes
44 $atts = shortcode_atts(
45 array(
46 'id' => get_option('cff_page_id'),
47 'show' => get_option('cff_num_show'),
48 'num' => get_option('cff_num_show'),
49 'width' => $options[ 'cff_feed_width' ],
50 'height' => $options[ 'cff_feed_height' ],
51 'padding' => $options[ 'cff_feed_padding' ],
52 'bgcolor' => $options[ 'cff_bg_color' ],
53 'include' => $include_string,
54 //Typography
55 'textformat' => $options[ 'cff_title_format' ],
56 'textsize' => $options[ 'cff_title_size' ],
57 'textweight' => $options[ 'cff_title_weight' ],
58 'textcolor' => $options[ 'cff_title_color' ],
59 'textlink' => $options[ 'cff_title_link' ],
60 'descsize' => $options[ 'cff_body_size' ],
61 'descweight' => $options[ 'cff_body_weight' ],
62 'desccolor' => $options[ 'cff_body_color' ],
63 'eventtitleformat' => $options[ 'cff_event_title_format' ],
64 'eventtitlesize' => $options[ 'cff_event_title_size' ],
65 'eventtitleweight' => $options[ 'cff_event_title_weight' ],
66 'eventtitlecolor' => $options[ 'cff_event_title_color' ],
67 'eventtitlelink' => $options[ 'cff_event_title_link' ],
68 'eventdetailssize' => $options[ 'cff_event_details_size' ],
69 'eventdetailsweight' => $options[ 'cff_event_details_weight' ],
70 'eventdetailscolor' => $options[ 'cff_event_details_color' ],
71 'datesize' => $options[ 'cff_date_size' ],
72 'dateweight' => $options[ 'cff_date_weight' ],
73 'datecolor' => $options[ 'cff_date_color' ],
74 'linksize' => $options[ 'cff_link_size' ],
75 'linkweight' => $options[ 'cff_link_weight' ],
76 'linkcolor' => $options[ 'cff_link_color' ],
77 //Misc
78 'textlength' => get_option('cff_title_length'),
79 'desclength' => get_option('cff_body_length'),
80 'likeboxpos' => $options[ 'cff_like_box_position' ],
81 'likeboxcolor' => $options[ 'cff_likebox_bg_color' ],
82 'videoheight' => $options[ 'cff_video_height' ],
83 'videoaction' => $options[ 'cff_video_action' ],
84 'sepcolor' => $options[ 'cff_sep_color' ],
85 'sepsize' => $options[ 'cff_sep_size' ]
86 ), $atts);
87
88
89
90
91 /********** GENERAL **********/
92 $cff_feed_width = $atts['width'];
93 $cff_feed_height = $atts[ 'height' ];
94 $cff_feed_padding = $atts[ 'padding' ];
95 $cff_bg_color = $atts[ 'bgcolor' ];
96 //Compile feed styles
97 $cff_feed_styles = 'style="';
98 if ( !empty($cff_feed_width) ) $cff_feed_styles .= 'width:' . $cff_feed_width . '; ';
99 if ( !empty($cff_feed_height) ) $cff_feed_styles .= 'height:' . $cff_feed_height . '; ';
100 if ( !empty($cff_feed_padding) ) $cff_feed_styles .= 'padding:' . $cff_feed_padding . '; ';
101 if ( !empty($cff_bg_color) ) $cff_feed_styles .= 'background-color:#' . $cff_bg_color . '; ';
102 $cff_feed_styles .= '"';
103 //Like box
104 $cff_like_box_position = $atts[ 'likeboxpos' ];
105 //Open links in new window?
106 $cff_open_links = $options[ 'cff_open_links' ];
107 $target = 'target="_blank"';
108 if ($cff_open_links) $target = 'target="_blank"';
109 /********** LAYOUT **********/
110 $cff_includes = $atts[ 'include' ];
111 //Look for non-plural version of string in the types string in case user specifies singular in shortcode
112 if ( stripos($cff_includes, 'text') !== false ) $cff_show_text = true;
113 if ( stripos($cff_includes, 'desc') !== false ) $cff_show_desc = true;
114 if ( stripos($cff_includes, 'date') !== false ) $cff_show_date = true;
115 if ( stripos($cff_includes, 'eventtitle') !== false ) $cff_show_event_title = true;
116 if ( stripos($cff_includes, 'eventdetail') !== false ) $cff_show_event_details = true;
117 if ( stripos($cff_includes, 'link') !== false ) $cff_show_link = true;
118 if ( stripos($cff_includes, 'like') !== false ) $cff_show_like_box = true;
119 /********** TYPOGRAPHY **********/
120 //Title
121 $cff_title_format = $atts[ 'textformat' ];
122 if (empty($cff_title_format)) $cff_title_format = 'p';
123 $cff_title_size = $atts[ 'textsize' ];
124 $cff_title_weight = $atts[ 'textweight' ];
125 $cff_title_color = $atts[ 'textcolor' ];
126 $cff_title_styles = 'style="';
127 if ( !empty($cff_title_size) && $cff_title_size != 'inherit' ) $cff_title_styles .= 'font-size:' . $cff_title_size . 'px; ';
128 if ( !empty($cff_title_weight) && $cff_title_weight != 'inherit' ) $cff_title_styles .= 'font-weight:' . $cff_title_weight . '; ';
129 if ( !empty($cff_title_color) ) $cff_title_styles .= 'color:#' . $cff_title_color . ';';
130 $cff_title_styles .= '"';
131 $cff_title_link = $atts[ 'textlink' ];
132 //Description
133 $cff_body_size = $atts[ 'descsize' ];
134 $cff_body_weight = $atts[ 'descweight' ];
135 $cff_body_color = $atts[ 'desccolor' ];
136 $cff_body_styles = 'style="';
137 if ( !empty($cff_body_size) && $cff_body_size != 'inherit' ) $cff_body_styles .= 'font-size:' . $cff_body_size . 'px; ';
138 if ( !empty($cff_body_weight) && $cff_body_weight != 'inherit' ) $cff_body_styles .= 'font-weight:' . $cff_body_weight . '; ';
139 if ( !empty($cff_body_color) ) $cff_body_styles .= 'color:#' . $cff_body_color . ';';
140 $cff_body_styles .= '"';
141 //Event Title
142 $cff_event_title_format = $atts[ 'eventtitleformat' ];
143 if (empty($cff_event_title_format)) $cff_event_title_format = 'p';
144 $cff_event_title_size = $atts[ 'eventtitlesize' ];
145 $cff_event_title_weight = $atts[ 'eventtitleweight' ];
146 $cff_event_title_color = $atts[ 'eventtitlecolor' ];
147 $cff_event_title_styles = 'style="';
148 if ( !empty($cff_event_title_size) && $cff_event_title_size != 'inherit' ) $cff_event_title_styles .= 'font-size:' . $cff_event_title_size . 'px; ';
149 if ( !empty($cff_event_title_weight) && $cff_event_title_weight != 'inherit' ) $cff_event_title_styles .= 'font-weight:' . $cff_event_title_weight . '; ';
150 if ( !empty($cff_event_title_color) ) $cff_event_title_styles .= 'color:#' . $cff_event_title_color . ';';
151 $cff_event_title_styles .= '"';
152 $cff_event_title_link = $atts[ 'eventtitlelink' ];
153
154 //Event Details
155 $cff_event_details_size = $atts[ 'eventdetailssize' ];
156 $cff_event_details_weight = $atts[ 'eventdetailsweight' ];
157 $cff_event_details_color = $atts[ 'eventdetailscolor' ];
158 $cff_event_details_styles = 'style="';
159 if ( !empty($cff_event_details_size) && $cff_event_details_size != 'inherit' ) $cff_event_details_styles .= 'font-size:' . $cff_event_details_size . 'px; ';
160 if ( !empty($cff_event_details_weight) && $cff_event_details_weight != 'inherit' ) $cff_event_details_styles .= 'font-weight:' . $cff_event_details_weight . '; ';
161 if ( !empty($cff_event_details_color) ) $cff_event_details_styles .= 'color:#' . $cff_event_details_color . ';';
162 $cff_event_details_styles .= '"';
163 //Date
164 $cff_date_size = $atts[ 'datesize' ];
165 $cff_date_weight = $atts[ 'dateweight' ];
166 $cff_date_color = $atts[ 'datecolor' ];
167 $cff_date_styles = 'style="';
168 if ( !empty($cff_date_size) && $cff_date_size != 'inherit' ) $cff_date_styles .= 'font-size:' . $cff_date_size . 'px; ';
169 if ( !empty($cff_date_weight) && $cff_date_weight != 'inherit' ) $cff_date_styles .= 'font-weight:' . $cff_date_weight . '; ';
170 if ( !empty($cff_date_color) ) $cff_date_styles .= 'color:#' . $cff_date_color . ';';
171 $cff_date_styles .= '"';
172 //Link to Facebook
173 $cff_link_size = $atts[ 'linksize' ];
174 $cff_link_weight = $atts[ 'linkweight' ];
175 $cff_link_color = $atts[ 'linkcolor' ];
176 $cff_link_styles = 'style="';
177 if ( !empty($cff_link_size) && $cff_link_size != 'inherit' ) $cff_link_styles .= 'font-size:' . $cff_link_size . 'px; ';
178 if ( !empty($cff_link_weight) && $cff_link_weight != 'inherit' ) $cff_link_styles .= 'font-weight:' . $cff_link_weight . '; ';
179 if ( !empty($cff_link_color) ) $cff_link_styles .= 'color:#' . $cff_link_color . ';';
180 $cff_link_styles .= '"';
181 /********** MISC **********/
182 //Like Box styles
183 $cff_likebox_bg_color = $atts[ 'likeboxcolor' ];
184 $cff_likebox_styles = 'style="';
185 if ( !empty($cff_likebox_bg_color) ) $cff_likebox_styles .= 'background-color:#' . $cff_likebox_bg_color . '; margin-left: 0; ';
186 $cff_likebox_styles .= '"';
187 //Separating Line
188 $cff_sep_color = $atts[ 'sepcolor' ];
189 if (empty($cff_sep_color)) $cff_sep_color = 'ddd';
190 $cff_sep_size = $atts[ 'sepsize' ];
191 if (empty($cff_sep_size)) $cff_sep_size = 0;
192 //CFF item styles
193 $cff_item_styles = 'style="';
194 $cff_item_styles .= 'border-bottom: ' . $cff_sep_size . 'px solid #' . $cff_sep_color . '; ';
195 $cff_item_styles .= '"';
196
197
198
199 //Text limits
200 $title_limit = $atts['textlength'];
201 $body_limit = $atts['desclength'];
202 //Assign the Access Token and Page ID variables
203 $access_token = get_option('cff_access_token');
204 $page_id = $atts['id'];
205 //Get show posts attribute. If not set then default to 10.
206 $show_posts = $atts['show'];
207 if ( empty($show_posts) ) {
208 $show_posts = $atts['num'];
209 if (empty($show_posts)) $show_posts = 25;
210 }
211 if ( $show_posts == 0 || $show_posts == undefined ) $show_posts = 10;
212 //Check whether the Access Token is present and valid
213 if ($access_token == '') {
214 echo 'Please enter a valid Access Token. You can do this in the Custom Facebook Feed plugin settings.<br /><br />';
215 return false;
216 }
217 //Check whether a Page ID has been defined
218 if ($page_id == '') {
219 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 />";
220 return false;
221 }
222
223 //Get the contents of the Facebook page
224 $json_object = fetchUrl('https://graph.facebook.com/' . $page_id . '/posts?access_token=' . $access_token);
225 //Interpret data with JSON
226 $FBdata = json_decode($json_object);
227 //Set like box variable
228 $like_box = '<div class="cff-likebox" ' . $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>';
229
230 //***START FEED***
231 //Create HTML
232 $content = '<div id="cff" class="';
233 if ( !empty($cff_feed_height) ) $content .= 'fixed-height ';
234 $content .= '"' . $cff_feed_styles . '>';
235 //Add like box to top of feed
236 if ($cff_like_box_position == 'top' && $cff_show_like_box) $content .= $like_box;
237 //Limit var
238 $i = 0;
239
240 foreach ($FBdata->data as $news )
241 {
242 //Explode News and Page ID's into 2 values
243 $PostID = explode("_", $news->id);
244 //Check whether it's a status (author comment or like)
245 if ( ( $news->type == 'status' && !empty($news->message) ) || $news->type !== 'status' ) {
246 //If it isn't then create the post
247 //Only create posts for the amount of posts specified
248 if ( $i == $show_posts ) break;
249 $i++;
250 //********************************//
251 //***COMPILE SECTION VARIABLES***//
252 //********************************//
253 //POST TEXT
254 $cff_post_text = '';
255 if ($cff_title_link) $cff_post_text .= '<a href="'.$news->link.'">';
256 $cff_post_text .= '<' . $cff_title_format . ' class="cff-post-text" ' . $cff_title_styles . '>';
257 if (!empty($news->story)) {
258 $story_text = $news->story;
259 if (!empty($title_limit)) {
260 if (strlen($story_text) > $title_limit) $story_text = substr($story_text, 0, $title_limit) . '...';
261 }
262 $cff_post_text .= cff_make_clickable($story_text) . ' ';
263 }
264 if (!empty($news->message)) {
265 $message_text = $news->message;
266 if (!empty($title_limit)) {
267 if (strlen($message_text) > $title_limit) $message_text = substr($message_text, 0, $title_limit) . '...';
268 }
269 $cff_post_text .= cff_make_clickable($message_text) . ' ';
270 }
271 if (!empty($news->name) && empty($news->story)) {
272 $name_text = $news->name;
273 if (!empty($title_limit)) {
274 if (strlen($name_text) > $title_limit) $name_text = substr($name_text, 0, $title_limit) . '...';
275 }
276 //Only show name as last resort if both story and message are empty
277 if ( empty($news->story) && empty($news->message) ) $cff_post_text .= cff_make_clickable($name_text);
278 }
279 $cff_post_text .= '</' . $cff_title_format . '>';
280 if ($cff_title_link) $cff_post_text .= '</a>';
281 //DESCRIPTION
282 $cff_description = '';
283 if (!empty($news->description)) {
284 $description_text = $news->description;
285 if (!empty($body_limit)) {
286 if (strlen($description_text) > $body_limit) $description_text = substr($description_text, 0, $body_limit) . '...';
287 }
288 $cff_description .= '<p '.$cff_body_styles.'>' . cff_make_clickable($description_text) . '</p>';
289 }
290 //LINK
291 $cff_shared_link = '';
292 //Display shared link
293 if ($news->type == 'link') {
294 //Display link name and description
295 if (!empty($news->description)) {
296 $cff_shared_link .= '<p class="text-link no-image"><a href="'.$news->link.'" '.$target.'>'. '<b>' . $news->name . '</b></a></p>';
297 }
298 }
299 //DATE
300 $cff_date = '<p class="cff-date" '.$cff_date_styles.'>Posted '. cff_timeSince(strtotime($news->created_time)) . ' ago</p>';
301 //EVENT
302 $cff_event = '';
303 if ($cff_show_event_title || $cff_show_event_details) {
304 //Check for media
305 if ($news->type == 'link') {
306 $story = $news->story;
307 //Check whether it's an event
308 $created_event = 'created an event.';
309 $shared_event = 'shared an event.';
310 $created_event = stripos($story, $created_event);
311 $shared_event = stripos($story, $shared_event);
312 if ( $created_event || $shared_event ){
313 //Get the event object
314 $eventID = $PostID[1];
315 if ( $shared_event ) {
316 //Get the event id from the event URL. eg: http://www.facebook.com/events/123451234512345/
317 $event_url = parse_url($news->link);
318 $url_parts = explode('/', $event_url['path']);
319 //Get the id from the parts
320 $eventID = $url_parts[count($url_parts)-2];
321 }
322 //Get the contents of the event using the WP HTTP API
323 $event_json = fetchUrl('https://graph.facebook.com/'.$eventID.'?access_token=' . $access_token);
324 //Interpret data with JSON
325 $event_object = json_decode($event_json);
326
327 //EVENT
328 //Display the event details
329 $cff_event = '<div class="details">';
330 //Show event title
331 if ($cff_show_event_title && !empty($event_object->name)) {
332 if ($cff_event_title_link) $cff_event .= '<a href="'.$news->link.'">';
333 $cff_event .= '<' . $cff_event_title_format . ' ' . $cff_event_title_styles . '>' . $event_object->name . '</' . $cff_event_title_format . '>';
334 if ($cff_event_title_link) $cff_event .= '</a>';
335 }
336 //Show event details
337 if ($cff_show_event_details){
338 if (!empty($event_object->location)) $cff_event .= '<p ' . $cff_event_details_styles . '>Where: ' . $event_object->location . '</p>';
339 if (!empty($event_object->start_time)) $cff_event .= '<p ' . $cff_event_details_styles . '>When: ' . date("F j, Y, g:i a", strtotime($event_object->start_time)) . '</p>';
340 if (!empty($event_object->description)){
341 $description = $event_object->description;
342 if (!empty($body_limit)) {
343 if (strlen($description) > $body_limit) $description = substr($description, 0, $body_limit) . '...';
344 }
345 $cff_event .= '<p ' . $cff_event_details_styles . '>' . cff_make_clickable($description) . '</p>';
346 }
347 }
348 $cff_event .= '</div><!-- end .details -->';
349 }
350 }
351 }
352 //LINK
353 //Display the link to the Facebook post or external link
354 $cff_link = '';
355 if (!empty($news->link)) {
356 $link = $news->link;
357 //Check whether it links to facebook or somewhere else
358 $facebook_str = 'facebook.com';
359 if(stripos($link, $facebook_str) !== false) {
360 $link_text = 'View on Facebook';
361 } else {
362 $link_text = 'View Link';
363 }
364 $cff_link = '<div class="meta-wrap"><a class="cff-viewpost" href="' . $link . '" title="' . $link_text . '" ' . $target . ' ' . $cff_link_styles . '>' . $link_text . '</a></div><!-- end .meta-wrap -->';
365 }
366 //**************************//
367 //***CREATE THE POST HTML***//
368 //**************************//
369 //Start the container
370 $content .= '<div class="cff-item ';
371 if ($news->type == 'link') $content .= 'link-item';
372 $content .= '" ' . $cff_item_styles . '>';
373 //POST TEXT
374 if($cff_show_text) $content .= $cff_post_text;
375 //DESCRIPTION
376 if($cff_show_desc) $content .= $cff_description;
377 //LINK
378 if($cff_show_desc) $content .= $cff_shared_link;
379
380 //EVENT
381 if($cff_show_event_title || $cff_show_event_details) $content .= $cff_event;
382 //DATE
383 if($cff_show_date) $content .= $cff_date;
384 //LINK
385 if($cff_show_link) $content .= $cff_link;
386 //End the post item
387 $content .= '</div><div class="clear"></div> <!-- end .cff-item -->';
388 } // End status check
389 } // End the loop
390 //Add the Like Box
391 if ($cff_like_box_position == 'bottom' && $cff_show_like_box) $content .= $like_box;
392 //End the feed
393 $content .= '</div><div class="clear"></div> <!-- end .Custom Facebook Feed -->';
394 //Return our feed HTML to display
395 return $content;
396 }
397 //Get JSON object of feed data
398 function fetchUrl($url){
399 //Can we use cURL?
400 if(is_callable('curl_init')){
401 $ch = curl_init();
402 curl_setopt($ch, CURLOPT_URL, $url);
403 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
404 curl_setopt($ch, CURLOPT_TIMEOUT, 20);
405 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
406 $feedData = curl_exec($ch);
407 curl_close($ch);
408 //If not then use file_get_contents
409 } elseif ( ini_get('allow_url_fopen') == 1 || ini_get('allow_url_fopen') === TRUE ) {
410 $feedData = @file_get_contents($url);
411 //Or else use the WP HTTP API
412 } else {
413 if( !class_exists( 'WP_Http' ) ) include_once( ABSPATH . WPINC. '/class-http.php' );
414 $request = new WP_Http;
415 $result = $request->request($url);
416 $feedData = $result['body'];
417 }
418
419 return $feedData;
420 }
421 //***FUNCTIONS***
422 //Make links in text clickable
423 function cff_make_url_clickable($matches) {
424 $target = 'target="_blank"';
425 $ret = '';
426 $url = $matches[2];
427
428 if ( empty($url) )
429 return $matches[0];
430 // removed trailing [.,;:] from URL
431 if ( in_array(substr($url, -1), array('.', ',', ';', ':')) === true ) {
432 $ret = substr($url, -1);
433 $url = substr($url, 0, strlen($url)-1);
434 }
435 return $matches[1] . "<a href=\"$url\" rel=\"nofollow\" ".$target.">$url</a>" . $ret;
436 }
437 function cff_make_web_ftp_clickable($matches) {
438 $target = 'target="_blank"';
439 $ret = '';
440 $dest = $matches[2];
441 $dest = 'http://' . $dest;
442
443 if ( empty($dest) )
444 return $matches[0];
445 // removed trailing [,;:] from URL
446 if ( in_array(substr($dest, -1), array('.', ',', ';', ':')) === true ) {
447 $ret = substr($dest, -1);
448 $dest = substr($dest, 0, strlen($dest)-1);
449 }
450 return $matches[1] . "<a href=\"$dest\" rel=\"nofollow\" ".$target.">$dest</a>" . $ret;
451 }
452 function cff_make_email_clickable($matches) {
453 $email = $matches[2] . '@' . $matches[3];
454 return $matches[1] . "<a href=\"mailto:$email\">$email</a>";
455 }
456 function cff_make_clickable($ret) {
457 $ret = ' ' . $ret;
458 // in testing, using arrays here was found to be faster
459 $ret = preg_replace_callback('#([\s>])([\w]+?://[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]*)#is', 'cff_make_url_clickable', $ret);
460 $ret = preg_replace_callback('#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]*)#is', 'cff_make_web_ftp_clickable', $ret);
461 $ret = preg_replace_callback('#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', 'cff_make_email_clickable', $ret);
462
463 // this one is not in an array because we need it to run last, for cleanup of accidental links within links
464 $ret = preg_replace("#(<a( [^>]+?>|>))<a [^>]+?>([^>]+?)</a></a>#i", "$1$3</a>", $ret);
465 $ret = trim($ret);
466 return $ret;
467 }
468 //Time stamp function
469 function cff_timeSince($original) {
470 // Array of time period
471 $chunks = array(
472 array(60 * 60 * 24 * 365 , 'year'),
473 array(60 * 60 * 24 * 30 , 'month'),
474 array(60 * 60 * 24 * 7, 'week'),
475 array(60 * 60 * 24 , 'day'),
476 array(60 * 60 , 'hour'),
477 array(60 , 'minute'),
478 );
479
480 // Current time
481 $today = time();
482 $since = $today - $original;
483
484 // $j saves performing the count function each time around the loop
485 for ($i = 0, $j = count($chunks); $i < $j; $i++) {
486
487 $seconds = $chunks[$i][0];
488 $name = $chunks[$i][1];
489
490 // finding the biggest chunk (if the chunk fits, break)
491 if (($count = floor($since / $seconds)) != 0) {
492 break;
493 }
494 }
495
496 $print = ($count == 1) ? '1 '.$name : "$count {$name}s";
497
498 if ($i + 1 < $j) {
499 // now getting the second item
500 $seconds2 = $chunks[$i + 1][0];
501 $name2 = $chunks[$i + 1][1];
502
503 // add second item if it's greater than 0
504 if (($count2 = floor(($since - ($seconds * $count)) / $seconds2)) != 0) {
505 $print .= ($count2 == 1) ? ', 1 '.$name2 : ", $count2 {$name2}s";
506 }
507 }
508 return $print;
509 }
510 //Enqueue stylesheet
511 add_action( 'wp_enqueue_scripts', 'cff_add_my_stylesheet' );
512 function cff_add_my_stylesheet() {
513 // Respects SSL, Style.css is relative to the current file
514 wp_register_style( 'cff', plugins_url('css/cff-style.css', __FILE__) );
515 wp_enqueue_style( 'cff' );
516 }
517 //Allows shortcodes in sidebar of theme
518 add_filter('widget_text', 'do_shortcode');
519 function cff_activate() {
520 $options = get_option('cff_style_settings');
521 //Show all parts of the feed by default on activation
522 $options[ 'cff_show_text' ] = true;
523 $options[ 'cff_show_desc' ] = true;
524 $options[ 'cff_show_date' ] = true;
525 $options[ 'cff_show_event_title' ] = true;
526 $options[ 'cff_show_event_details' ] = true;
527 $options[ 'cff_show_link' ] = true;
528 $options[ 'cff_show_like_box' ] = true;
529 $options[ 'cff_sep_size' ] = '1';
530 update_option( 'cff_style_settings', $options );
531 }
532 register_activation_hook( __FILE__, 'cff_activate' );
533 //Uninstall
534 function cff_uninstall()
535 {
536 if ( ! current_user_can( 'activate_plugins' ) )
537 return;
538 delete_option( 'cff_access_token' );
539 delete_option( 'cff_page_id' );
540 delete_option( 'cff_num_show' );
541 delete_option( 'cff_title_length' );
542 delete_option( 'cff_body_length' );
543 delete_option('cff_style_settings');
544 }
545 register_uninstall_hook( __FILE__, 'cff_uninstall' );
546 add_action( 'wp_head', 'cff_custom_css' );
547 function cff_custom_css() {
548 $options = get_option('cff_style_settings');
549 $cff_custom_css = $options[ 'cff_custom_css' ];
550 echo '<!-- Custom Facebook Feed Custom CSS -->';
551 echo "\r\n";
552 echo '<style type="text/css">';
553 echo "\r\n";
554 echo $cff_custom_css;
555 echo "\r\n";
556 echo '</style>';
557 echo "\r\n";
558 }
559 //Comment out the line below to view errors
560 error_reporting(0);
561 ?>