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