PluginProbe
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress / 1.9.5
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress v1.9.5
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
1,923 lines 90.6 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.9.5
7 Author: Smash Balloon
8 Author URI: http://smashballoon.com/
9 License: GPLv2 or later
10 */
11 /*
12 Copyright 2013 Smash Balloon LLC (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
28 // Add shortcodes
29 add_shortcode('custom-facebook-feed', 'display_cff');
30 function display_cff($atts) {
31
32 //Style options
33 $options = get_option('cff_style_settings');
34 //Create the types string to set as shortcode default
35 $include_string = '';
36 if($options[ 'cff_show_author' ]) $include_string .= 'author,';
37 if($options[ 'cff_show_text' ]) $include_string .= 'text,';
38 if($options[ 'cff_show_desc' ]) $include_string .= 'desc,';
39 if($options[ 'cff_show_shared_links' ]) $include_string .= 'sharedlinks,';
40 if($options[ 'cff_show_date' ]) $include_string .= 'date,';
41 if($options[ 'cff_show_media' ]) $include_string .= 'media,';
42 if($options[ 'cff_show_event_title' ]) $include_string .= 'eventtitle,';
43 if($options[ 'cff_show_event_details' ]) $include_string .= 'eventdetails,';
44 if($options[ 'cff_show_meta' ]) $include_string .= 'social,';
45 if($options[ 'cff_show_link' ]) $include_string .= 'link,';
46 if($options[ 'cff_show_like_box' ]) $include_string .= 'likebox,';
47 //Pass in shortcode attrbutes
48 $atts = shortcode_atts(
49 array(
50 'accesstoken' => trim( get_option('cff_access_token') ),
51 'id' => get_option('cff_page_id'),
52 'pagetype' => get_option('cff_page_type'),
53 'num' => get_option('cff_num_show'),
54 'limit' => get_option('cff_post_limit'),
55 'others' => '',
56 'showpostsby' => get_option('cff_show_others'),
57 'cachetime' => get_option('cff_cache_time'),
58 'cacheunit' => get_option('cff_cache_time_unit'),
59 'locale' => get_option('cff_locale'),
60 'ajax' => get_option('cff_ajax'),
61 'width' => isset($options[ 'cff_feed_width' ]) ? $options[ 'cff_feed_width' ] : '',
62 'height' => isset($options[ 'cff_feed_height' ]) ? $options[ 'cff_feed_height' ] : '',
63 'padding' => isset($options[ 'cff_feed_padding' ]) ? $options[ 'cff_feed_padding' ] : '',
64 'bgcolor' => isset($options[ 'cff_bg_color' ]) ? $options[ 'cff_bg_color' ] : '',
65 'showauthor' => '',
66 'showauthornew' => isset($options[ 'cff_show_author' ]) ? $options[ 'cff_show_author' ] : '',
67 'class' => isset($options[ 'cff_class' ]) ? $options[ 'cff_class' ] : '',
68 'layout' => isset($options[ 'cff_preset_layout' ]) ? $options[ 'cff_preset_layout' ] : '',
69 'include' => $include_string,
70 'exclude' => '',
71 //Typography
72 'textformat' => isset($options[ 'cff_title_format' ]) ? $options[ 'cff_title_format' ] : '',
73 'textsize' => isset($options[ 'cff_title_size' ]) ? $options[ 'cff_title_size' ] : '',
74 'textweight' => isset($options[ 'cff_title_weight' ]) ? $options[ 'cff_title_weight' ] : '',
75 'textcolor' => isset($options[ 'cff_title_color' ]) ? $options[ 'cff_title_color' ] : '',
76 'textlinkcolor' => isset($options[ 'cff_posttext_link_color' ]) ? $options[ 'cff_posttext_link_color' ] : '',
77 'textlink' => isset($options[ 'cff_title_link' ]) ? $options[ 'cff_title_link' ] : '',
78 'posttags' => isset($options[ 'cff_post_tags' ]) ? $options[ 'cff_post_tags' ] : '',
79 //Description
80 'descsize' => isset($options[ 'cff_body_size' ]) ? $options[ 'cff_body_size' ] : '',
81 'descweight' => isset($options[ 'cff_body_weight' ]) ? $options[ 'cff_body_weight' ] : '',
82 'desccolor' => isset($options[ 'cff_body_color' ]) ? $options[ 'cff_body_color' ] : '',
83 'linktitleformat' => isset($options[ 'cff_link_title_format' ]) ? $options[ 'cff_link_title_format' ] : '',
84 'linktitlesize' => isset($options[ 'cff_link_title_size' ]) ? $options[ 'cff_link_title_size' ] : '',
85 'linktitlecolor' => isset($options[ 'cff_link_title_color' ]) ? $options[ 'cff_link_title_color' ] : '',
86 'linkurlcolor' => isset($options[ 'cff_link_url_color' ]) ? $options[ 'cff_link_url_color' ] : '',
87 'linkbgcolor' => isset($options[ 'cff_link_bg_color' ]) ? $options[ 'cff_link_bg_color' ] : '',
88 'linkbordercolor' => isset($options[ 'cff_link_border_color' ]) ? $options[ 'cff_link_border_color' ] : '',
89 'disablelinkbox' => isset($options[ 'cff_disable_link_box' ]) ? $options[ 'cff_disable_link_box' ] : '',
90
91 //Author
92 'authorsize' => isset($options[ 'cff_author_size' ]) ? $options[ 'cff_author_size' ] : '',
93 'authorcolor' => isset($options[ 'cff_author_color' ]) ? $options[ 'cff_author_color' ] : '',
94
95 //Event title
96 'eventtitleformat' => isset($options[ 'cff_event_title_format' ]) ? $options[ 'cff_event_title_format' ] : '',
97 'eventtitlesize' => isset($options[ 'cff_event_title_size' ]) ? $options[ 'cff_event_title_size' ] : '',
98 'eventtitleweight' => isset($options[ 'cff_event_title_weight' ]) ? $options[ 'cff_event_title_weight' ] : '',
99 'eventtitlecolor' => isset($options[ 'cff_event_title_color' ]) ? $options[ 'cff_event_title_color' ] : '',
100 'eventtitlelink' => isset($options[ 'cff_event_title_link' ]) ? $options[ 'cff_event_title_link' ] : '',
101 //Event date
102 'eventdatesize' => isset($options[ 'cff_event_date_size' ]) ? $options[ 'cff_event_date_size' ] : '',
103 'eventdateweight' => isset($options[ 'cff_event_date_weight' ]) ? $options[ 'cff_event_date_weight' ] : '',
104 'eventdatecolor' => isset($options[ 'cff_event_date_color' ]) ? $options[ 'cff_event_date_color' ] : '',
105 'eventdatepos' => isset($options[ 'cff_event_date_position' ]) ? $options[ 'cff_event_date_position' ] : '',
106 'eventdateformat' => isset($options[ 'cff_event_date_formatting' ]) ? $options[ 'cff_event_date_formatting' ] : '',
107 'eventdatecustom' => isset($options[ 'cff_event_date_custom' ]) ? $options[ 'cff_event_date_custom' ] : '',
108 //Event details
109 'eventdetailssize' => isset($options[ 'cff_event_details_size' ]) ? $options[ 'cff_event_details_size' ] : '',
110 'eventdetailsweight' => isset($options[ 'cff_event_details_weight' ]) ? $options[ 'cff_event_details_weight' ] : '',
111 'eventdetailscolor' => isset($options[ 'cff_event_details_color' ]) ? $options[ 'cff_event_details_color' ] : '',
112 'eventlinkcolor' => isset($options[ 'cff_event_link_color' ]) ? $options[ 'cff_event_link_color' ] : '',
113 //Date
114 'datepos' => isset($options[ 'cff_date_position' ]) ? $options[ 'cff_date_position' ] : '',
115 'datesize' => isset($options[ 'cff_date_size' ]) ? $options[ 'cff_date_size' ] : '',
116 'dateweight' => isset($options[ 'cff_date_weight' ]) ? $options[ 'cff_date_weight' ] : '',
117 'datecolor' => isset($options[ 'cff_date_color' ]) ? $options[ 'cff_date_color' ] : '',
118 'dateformat' => isset($options[ 'cff_date_formatting' ]) ? $options[ 'cff_date_formatting' ] : '',
119 'datecustom' => isset($options[ 'cff_date_custom' ]) ? $options[ 'cff_date_custom' ] : '',
120 'timezone' => isset($options[ 'cff_timezone' ]) ? $options[ 'cff_timezone' ] : 'America/Chicago',
121
122 //Link to Facebook
123 'linksize' => isset($options[ 'cff_link_size' ]) ? $options[ 'cff_link_size' ] : '',
124 'linkweight' => isset($options[ 'cff_link_weight' ]) ? $options[ 'cff_link_weight' ] : '',
125 'linkcolor' => isset($options[ 'cff_link_color' ]) ? $options[ 'cff_link_color' ] : '',
126 'viewlinktext' => isset($options[ 'cff_view_link_text' ]) ? $options[ 'cff_view_link_text' ] : '',
127 'linktotimeline' => isset($options[ 'cff_link_to_timeline' ]) ? $options[ 'cff_link_to_timeline' ] : '',
128 //Social
129 'iconstyle' => isset($options[ 'cff_icon_style' ]) ? $options[ 'cff_icon_style' ] : '',
130 'socialtextcolor' => isset($options[ 'cff_meta_text_color' ]) ? $options[ 'cff_meta_text_color' ] : '',
131 'socialbgcolor' => isset($options[ 'cff_meta_bg_color' ]) ? $options[ 'cff_meta_bg_color' ] : '',
132 //Misc
133 'textlength' => get_option('cff_title_length'),
134 'desclength' => get_option('cff_body_length'),
135 'likeboxpos' => isset($options[ 'cff_like_box_position' ]) ? $options[ 'cff_like_box_position' ] : '',
136 'likeboxoutside' => isset($options[ 'cff_like_box_outside' ]) ? $options[ 'cff_like_box_outside' ] : '',
137 'likeboxcolor' => isset($options[ 'cff_likebox_bg_color' ]) ? $options[ 'cff_likebox_bg_color' ] : '',
138 'likeboxtextcolor' => isset($options[ 'cff_like_box_text_color' ]) ? $options[ 'cff_like_box_text_color' ] : '',
139 'likeboxwidth' => isset($options[ 'cff_likebox_width' ]) ? $options[ 'cff_likebox_width' ] : '',
140 'likeboxheight' => isset($options[ 'cff_likebox_height' ]) ? $options[ 'cff_likebox_height' ] : '',
141 'likeboxfaces' => isset($options[ 'cff_like_box_faces' ]) ? $options[ 'cff_like_box_faces' ] : '',
142 'likeboxborder' => isset($options[ 'cff_like_box_border' ]) ? $options[ 'cff_like_box_border' ] : '',
143
144 //Page Header
145 'showheader' => isset($options[ 'cff_show_header' ]) ? $options[ 'cff_show_header' ] : '',
146 'headeroutside' => isset($options[ 'cff_header_outside' ]) ? $options[ 'cff_header_outside' ] : '',
147 'headertext' => isset($options[ 'cff_header_text' ]) ? $options[ 'cff_header_text' ] : '',
148 'headerbg' => isset($options[ 'cff_header_bg_color' ]) ? $options[ 'cff_header_bg_color' ] : '',
149 'headerpadding' => isset($options[ 'cff_header_padding' ]) ? $options[ 'cff_header_padding' ] : '',
150 'headertextsize' => isset($options[ 'cff_header_text_size' ]) ? $options[ 'cff_header_text_size' ] : '',
151 'headertextweight' => isset($options[ 'cff_header_text_weight' ]) ? $options[ 'cff_header_text_weight' ] : '',
152 'headertextcolor' => isset($options[ 'cff_header_text_color' ]) ? $options[ 'cff_header_text_color' ] : '',
153 'headericon' => isset($options[ 'cff_header_icon' ]) ? $options[ 'cff_header_icon' ] : '',
154 'headericoncolor' => isset($options[ 'cff_header_icon_color' ]) ? $options[ 'cff_header_icon_color' ] : '',
155 'headericonsize' => isset($options[ 'cff_header_icon_size' ]) ? $options[ 'cff_header_icon_size' ] : '',
156
157 'videoheight' => isset($options[ 'cff_video_height' ]) ? $options[ 'cff_video_height' ] : '',
158 'videoaction' => isset($options[ 'cff_video_action' ]) ? $options[ 'cff_video_action' ] : '',
159 'sepcolor' => isset($options[ 'cff_sep_color' ]) ? $options[ 'cff_sep_color' ] : '',
160 'sepsize' => isset($options[ 'cff_sep_size' ]) ? $options[ 'cff_sep_size' ] : '',
161
162 //Translate
163 'seemoretext' => isset($options[ 'cff_see_more_text' ]) ? $options[ 'cff_see_more_text' ] : '',
164 'seelesstext' => isset($options[ 'cff_see_less_text' ]) ? $options[ 'cff_see_less_text' ] : '',
165 'facebooklinktext' => isset($options[ 'cff_facebook_link_text' ]) ? $options[ 'cff_facebook_link_text' ] : '',
166 'photostext' => isset($options[ 'cff_translate_photos_text' ]) ? $options[ 'cff_translate_photos_text' ] : ''
167 ), $atts);
168 /********** GENERAL **********/
169 $cff_page_type = $atts[ 'pagetype' ];
170 ($cff_page_type == 'group') ? $cff_is_group = true : $cff_is_group = false;
171
172 $cff_feed_width = $atts['width'];
173 $cff_feed_height = $atts[ 'height' ];
174 $cff_feed_padding = $atts[ 'padding' ];
175 $cff_bg_color = $atts[ 'bgcolor' ];
176 $cff_show_author = $atts[ 'showauthornew' ];
177 $cff_cache_time = $atts[ 'cachetime' ];
178 $cff_locale = $atts[ 'locale' ];
179 if ( empty($cff_locale) || !isset($cff_locale) || $cff_locale == '' ) $cff_locale = 'en_US';
180 if (!isset($cff_cache_time)) $cff_cache_time = 0;
181 $cff_cache_time_unit = $atts[ 'cacheunit' ];
182 $cff_class = $atts['class'];
183 //Compile feed styles
184 $cff_feed_styles = 'style="';
185 if ( !empty($cff_feed_width) ) $cff_feed_styles .= 'width:' . $cff_feed_width . '; ';
186 if ( !empty($cff_feed_height) ) $cff_feed_styles .= 'height:' . $cff_feed_height . '; ';
187 if ( !empty($cff_feed_padding) ) $cff_feed_styles .= 'padding:' . $cff_feed_padding . '; ';
188 if ( !empty($cff_bg_color) ) $cff_feed_styles .= 'background-color:#' . str_replace('#', '', $cff_bg_color) . '; ';
189 $cff_feed_styles .= '"';
190 //Like box
191 $cff_like_box_position = $atts[ 'likeboxpos' ];
192 $cff_like_box_outside = $atts[ 'likeboxoutside' ];
193 //Open links in new window?
194 $target = 'target="_blank"';
195 /********** POST TYPES **********/
196 $cff_show_links_type = true;
197 $cff_show_event_type = true;
198 $cff_show_video_type = true;
199 $cff_show_photos_type = true;
200 $cff_show_status_type = true;
201 $cff_events_only = false;
202 //Are we showing ONLY events?
203 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;
204 /********** LAYOUT **********/
205 $cff_includes = $atts[ 'include' ];
206 //Look for non-plural version of string in the types string in case user specifies singular in shortcode
207 $cff_show_author = false;
208 $cff_show_text = false;
209 $cff_show_desc = false;
210 $cff_show_shared_links = false;
211 $cff_show_date = false;
212 $cff_show_media = false;
213 $cff_show_event_title = false;
214 $cff_show_event_details = false;
215 $cff_show_meta = false;
216 $cff_show_link = false;
217 $cff_show_like_box = false;
218 if ( stripos($cff_includes, 'author') !== false ) $cff_show_author = true;
219 if ( stripos($cff_includes, 'text') !== false ) $cff_show_text = true;
220 if ( stripos($cff_includes, 'desc') !== false ) $cff_show_desc = true;
221 if ( stripos($cff_includes, 'sharedlink') !== false ) $cff_show_shared_links = true;
222 if ( stripos($cff_includes, 'date') !== false ) $cff_show_date = true;
223 if ( stripos($cff_includes, 'media') !== false ) $cff_show_media = true;
224 if ( stripos($cff_includes, 'eventtitle') !== false ) $cff_show_event_title = true;
225 if ( stripos($cff_includes, 'eventdetail') !== false ) $cff_show_event_details = true;
226 if ( stripos($cff_includes, 'social') !== false ) $cff_show_meta = true;
227 if ( stripos($cff_includes, ',link') !== false ) $cff_show_link = true; //comma used to separate it from 'sharedlinks' - which also contains 'link' string
228 if ( stripos($cff_includes, 'like') !== false ) $cff_show_like_box = true;
229
230
231 //Exclude string
232 $cff_excludes = $atts[ 'exclude' ];
233 //Look for non-plural version of string in the types string in case user specifies singular in shortcode
234 if ( stripos($cff_excludes, 'author') !== false ) $cff_show_author = false;
235 if ( stripos($cff_excludes, 'text') !== false ) $cff_show_text = false;
236 if ( stripos($cff_excludes, 'desc') !== false ) $cff_show_desc = false;
237 if ( stripos($cff_excludes, 'sharedlink') !== false ) $cff_show_shared_links = false;
238 if ( stripos($cff_excludes, 'date') !== false ) $cff_show_date = false;
239 if ( stripos($cff_excludes, 'media') !== false ) $cff_show_media = false;
240 if ( stripos($cff_excludes, 'eventtitle') !== false ) $cff_show_event_title = false;
241 if ( stripos($cff_excludes, 'eventdetail') !== false ) $cff_show_event_details = false;
242 if ( stripos($cff_excludes, 'social') !== false ) $cff_show_meta = false;
243 if ( stripos($cff_excludes, ',link') !== false ) $cff_show_link = false; //comma used to separate it from 'sharedlinks' - which also contains 'link' string
244 if ( stripos($cff_excludes, 'like') !== false ) $cff_show_like_box = false;
245
246
247 //Set free version to thumb layout by default as layout option not available on settings page
248 $cff_preset_layout = 'thumb';
249
250 //If the old shortcode option 'showauthor' is being used then apply it
251 $cff_show_author_old = $atts[ 'showauthor' ];
252 if( $cff_show_author_old == 'false' ) $cff_show_author = false;
253 if( $cff_show_author_old == 'true' ) $cff_show_author = true;
254
255
256 /********** META **********/
257 $cff_icon_style = $atts[ 'iconstyle' ];
258 $cff_meta_text_color = $atts[ 'socialtextcolor' ];
259 $cff_meta_bg_color = $atts[ 'socialbgcolor' ];
260 $cff_meta_styles = 'style="';
261 if ( !empty($cff_meta_text_color) ) $cff_meta_styles .= 'color:#' . str_replace('#', '', $cff_meta_text_color) . ';';
262 if ( !empty($cff_meta_bg_color) ) $cff_meta_styles .= 'background-color:#' . str_replace('#', '', $cff_meta_bg_color) . ';';
263 $cff_meta_styles .= '"';
264 $cff_nocomments_text = isset($options[ 'cff_nocomments_text' ]) ? $options[ 'cff_nocomments_text' ] : '';
265 $cff_hide_comments = isset($options[ 'cff_hide_comments' ]) ? $options[ 'cff_hide_comments' ] : '';
266 if (!isset($cff_nocomments_text) || empty($cff_nocomments_text)) $cff_hide_comments = true;
267 /********** TYPOGRAPHY **********/
268 //See More text
269 $cff_see_more_text = $atts[ 'seemoretext' ];
270 $cff_see_less_text = $atts[ 'seelesstext' ];
271 //See Less text
272 //Title
273 $cff_title_format = $atts[ 'textformat' ];
274 if (empty($cff_title_format)) $cff_title_format = 'p';
275 $cff_title_size = $atts[ 'textsize' ];
276 $cff_title_weight = $atts[ 'textweight' ];
277 $cff_title_color = $atts[ 'textcolor' ];
278 $cff_title_styles = 'style="';
279 if ( !empty($cff_title_size) && $cff_title_size != 'inherit' ) $cff_title_styles .= 'font-size:' . $cff_title_size . 'px; ';
280 if ( !empty($cff_title_weight) && $cff_title_weight != 'inherit' ) $cff_title_styles .= 'font-weight:' . $cff_title_weight . '; ';
281 if ( !empty($cff_title_color) ) $cff_title_styles .= 'color:#' . str_replace('#', '', $cff_title_color) . ';';
282 $cff_title_styles .= '"';
283 $cff_title_link = $atts[ 'textlink' ];
284
285 ( $cff_title_link == 'on' || $cff_title_link == 'true' || $cff_title_link == true ) ? $cff_title_link = true : $cff_title_link = false;
286 if( $atts[ 'textlink' ] == 'false' ) $cff_title_link = false;
287
288 //Author
289 $cff_author_size = $atts[ 'authorsize' ];
290 $cff_author_color = $atts[ 'authorcolor' ];
291 $cff_author_styles = 'style="';
292 if ( !empty($cff_author_size) && $cff_author_size != 'inherit' ) $cff_author_styles .= 'font-size:' . $cff_author_size . 'px; ';
293 if ( !empty($cff_author_color) ) $cff_author_styles .= 'color:#' . str_replace('#', '', $cff_author_color) . ';';
294 $cff_author_styles .= '"';
295
296 //Description
297 $cff_body_size = $atts[ 'descsize' ];
298 $cff_body_weight = $atts[ 'descweight' ];
299 $cff_body_color = $atts[ 'desccolor' ];
300 $cff_body_styles = 'style="';
301 if ( !empty($cff_body_size) && $cff_body_size != 'inherit' ) $cff_body_styles .= 'font-size:' . $cff_body_size . 'px; ';
302 if ( !empty($cff_body_weight) && $cff_body_weight != 'inherit' ) $cff_body_styles .= 'font-weight:' . $cff_body_weight . '; ';
303 if ( !empty($cff_body_color) ) $cff_body_styles .= 'color:#' . str_replace('#', '', $cff_body_color) . ';';
304 $cff_body_styles .= '"';
305
306 //Shared link title
307 $cff_link_title_format = $atts[ 'linktitleformat' ];
308 if (empty($cff_link_title_format)) $cff_link_title_format = 'p';
309 $cff_link_title_size = $atts[ 'linktitlesize' ];
310 $cff_link_title_color = $atts[ 'linktitlecolor' ];
311 $cff_link_url_color = $atts[ 'linkurlcolor' ];
312
313 $cff_link_title_styles = 'style="';
314 if ( !empty($cff_link_title_size) && $cff_link_title_size != 'inherit' ) $cff_link_title_styles .= 'font-size:' . $cff_link_title_size . 'px;';
315 $cff_link_title_styles .= '"';
316
317 //Shared link box
318 $cff_link_bg_color = $atts[ 'linkbgcolor' ];
319 $cff_link_border_color = $atts[ 'linkbordercolor' ];
320 $cff_disable_link_box = $atts['disablelinkbox'];
321 ($cff_disable_link_box == 'true' || $cff_disable_link_box == 'on') ? $cff_disable_link_box = true : $cff_disable_link_box = false;
322
323 $cff_link_box_styles = 'style="';
324 if ( !empty($cff_link_border_color) ) $cff_link_box_styles .= 'border: 1px solid #' . str_replace('#', '', $cff_link_border_color) . '; ';
325 if ( !empty($cff_link_bg_color) ) $cff_link_box_styles .= 'background-color: #' . str_replace('#', '', $cff_link_bg_color) . ';';
326 $cff_link_box_styles .= '"';
327
328 //Event Title
329 $cff_event_title_format = $atts[ 'eventtitleformat' ];
330 if (empty($cff_event_title_format)) $cff_event_title_format = 'p';
331 $cff_event_title_size = $atts[ 'eventtitlesize' ];
332 $cff_event_title_weight = $atts[ 'eventtitleweight' ];
333 $cff_event_title_color = $atts[ 'eventtitlecolor' ];
334 $cff_event_title_styles = 'style="';
335 if ( !empty($cff_event_title_size) && $cff_event_title_size != 'inherit' ) $cff_event_title_styles .= 'font-size:' . $cff_event_title_size . 'px; ';
336 if ( !empty($cff_event_title_weight) && $cff_event_title_weight != 'inherit' ) $cff_event_title_styles .= 'font-weight:' . $cff_event_title_weight . '; ';
337 if ( !empty($cff_event_title_color) ) $cff_event_title_styles .= 'color:#' . str_replace('#', '', $cff_event_title_color) . ';';
338 $cff_event_title_styles .= '"';
339 $cff_event_title_link = $atts[ 'eventtitlelink' ];
340 //Event Date
341 $cff_event_date_size = $atts[ 'eventdatesize' ];
342 $cff_event_date_weight = $atts[ 'eventdateweight' ];
343 $cff_event_date_color = $atts[ 'eventdatecolor' ];
344 $cff_event_date_position = $atts[ 'eventdatepos' ];
345 $cff_event_date_formatting = $atts[ 'eventdateformat' ];
346 $cff_event_date_custom = $atts[ 'eventdatecustom' ];
347 $cff_event_date_styles = 'style="';
348 if ( !empty($cff_event_date_size) && $cff_event_date_size != 'inherit' ) $cff_event_date_styles .= 'font-size:' . $cff_event_date_size . 'px; ';
349 if ( !empty($cff_event_date_weight) && $cff_event_date_weight != 'inherit' ) $cff_event_date_styles .= 'font-weight:' . $cff_event_date_weight . '; ';
350 if ( !empty($cff_event_date_color) ) $cff_event_date_styles .= 'color:#' . str_replace('#', '', $cff_event_date_color) . ';';
351 $cff_event_date_styles .= '"';
352 //Event Details
353 $cff_event_details_size = $atts[ 'eventdetailssize' ];
354 $cff_event_details_weight = $atts[ 'eventdetailsweight' ];
355 $cff_event_details_color = $atts[ 'eventdetailscolor' ];
356 $cff_event_link_color = $atts[ 'eventlinkcolor' ];
357 $cff_event_details_styles = 'style="';
358 if ( !empty($cff_event_details_size) && $cff_event_details_size != 'inherit' ) $cff_event_details_styles .= 'font-size:' . $cff_event_details_size . 'px; ';
359 if ( !empty($cff_event_details_weight) && $cff_event_details_weight != 'inherit' ) $cff_event_details_styles .= 'font-weight:' . $cff_event_details_weight . '; ';
360 if ( !empty($cff_event_details_color) ) $cff_event_details_styles .= 'color:#' . str_replace('#', '', $cff_event_details_color) . ';';
361 $cff_event_details_styles .= '"';
362 //Date
363 $cff_date_position = $atts[ 'datepos' ];
364 if (!isset($cff_date_position)) $cff_date_position = 'below';
365 $cff_date_size = $atts[ 'datesize' ];
366 $cff_date_weight = $atts[ 'dateweight' ];
367 $cff_date_color = $atts[ 'datecolor' ];
368 $cff_date_styles = 'style="';
369 if ( !empty($cff_date_size) && $cff_date_size != 'inherit' ) $cff_date_styles .= 'font-size:' . $cff_date_size . 'px; ';
370 if ( !empty($cff_date_weight) && $cff_date_weight != 'inherit' ) $cff_date_styles .= 'font-weight:' . $cff_date_weight . '; ';
371 if ( !empty($cff_date_color) ) $cff_date_styles .= 'color:#' . str_replace('#', '', $cff_date_color) . ';';
372 $cff_date_styles .= '"';
373 $cff_date_before = isset($options[ 'cff_date_before' ]) ? $options[ 'cff_date_before' ] : '';
374 $cff_date_after = isset($options[ 'cff_date_after' ]) ? $options[ 'cff_date_after' ] : '';
375 //Set user's timezone based on setting
376 $cff_timezone = $atts['timezone'];
377 $cff_orig_timezone = date_default_timezone_get();
378 date_default_timezone_set($cff_timezone);
379 //Link to Facebook
380 $cff_link_size = $atts[ 'linksize' ];
381 $cff_link_weight = $atts[ 'linkweight' ];
382 $cff_link_color = $atts[ 'linkcolor' ];
383 $cff_link_styles = 'style="';
384 if ( !empty($cff_link_size) && $cff_link_size != 'inherit' ) $cff_link_styles .= 'font-size:' . $cff_link_size . 'px; ';
385 if ( !empty($cff_link_weight) && $cff_link_weight != 'inherit' ) $cff_link_styles .= 'font-weight:' . $cff_link_weight . '; ';
386 if ( !empty($cff_link_color) ) $cff_link_styles .= 'color:#' . str_replace('#', '', $cff_link_color) . ';';
387 $cff_link_styles .= '"';
388 $cff_facebook_link_text = $atts[ 'facebooklinktext' ];
389 $cff_view_link_text = $atts[ 'viewlinktext' ];
390 $cff_link_to_timeline = $atts[ 'linktotimeline' ];
391 /********** MISC **********/
392 //Like Box styles
393 $cff_likebox_bg_color = $atts[ 'likeboxcolor' ];
394
395 $cff_like_box_text_color = $atts[ 'likeboxtextcolor' ];
396 $cff_like_box_colorscheme = 'light';
397 if ($cff_like_box_text_color == 'white') $cff_like_box_colorscheme = 'dark';
398
399 $cff_likebox_width = $atts[ 'likeboxwidth' ];
400 $cff_likebox_height = $atts[ 'likeboxheight' ];
401 $cff_likebox_height = preg_replace('/px$/', '', $cff_likebox_height);
402
403 if ( !isset($cff_likebox_width) || empty($cff_likebox_width) || $cff_likebox_width == '' ) $cff_likebox_width = '100%';
404 $cff_like_box_faces = $atts[ 'likeboxfaces' ];
405 if ( !isset($cff_like_box_faces) || empty($cff_like_box_faces) ) $cff_like_box_faces = 'false';
406 $cff_like_box_border = $atts[ 'likeboxborder' ];
407 if ($cff_like_box_border) {
408 $cff_like_box_border = 'true';
409 } else {
410 $cff_like_box_border = 'false';
411 }
412
413 //Compile Like box styles
414 $cff_likebox_styles = 'style="width: ' . $cff_likebox_width . ';';
415 if ( !empty($cff_likebox_bg_color) ) $cff_likebox_styles .= ' background-color: #' . str_replace('#', '', $cff_likebox_bg_color) . ';';
416 if ( empty($cff_likebox_bg_color) && $cff_like_box_faces == 'false' ) $cff_likebox_styles .= ' margin-left: -10px;';
417 $cff_likebox_styles .= '"';
418
419 //Get feed header settings
420 $cff_header_bg_color = $atts['headerbg'];
421 $cff_header_padding = $atts['headerpadding'];
422 $cff_header_text_size = $atts['headertextsize'];
423 $cff_header_text_weight = $atts['headertextweight'];
424 $cff_header_text_color = $atts['headertextcolor'];
425
426 //Compile feed header styles
427 $cff_header_styles = 'style="';
428 if ( !empty($cff_header_bg_color) ) $cff_header_styles .= 'background-color: #' . str_replace('#', '', $cff_header_bg_color) . ';';
429 if ( !empty($cff_header_padding) ) $cff_header_styles .= ' padding: ' . $cff_header_padding . ';';
430 if ( !empty($cff_header_text_size) ) $cff_header_styles .= ' font-size: ' . $cff_header_text_size . 'px;';
431 if ( !empty($cff_header_text_weight) ) $cff_header_styles .= ' font-weight: ' . $cff_header_text_weight . ';';
432 if ( !empty($cff_header_text_color) ) $cff_header_styles .= ' color: #' . str_replace('#', '', $cff_header_text_color) . ';';
433 $cff_header_styles .= '"';
434
435 //Video
436 //Dimensions
437 $cff_video_width = 640;
438 $cff_video_height = $atts[ 'videoheight' ];
439
440 //Action
441 $cff_video_action = $atts[ 'videoaction' ];
442 //Separating Line
443 $cff_sep_color = $atts[ 'sepcolor' ];
444 if (empty($cff_sep_color)) $cff_sep_color = 'ddd';
445 $cff_sep_size = $atts[ 'sepsize' ];
446 //If empty then set a 0px border
447 if ( empty($cff_sep_size) || $cff_sep_size == '' ) {
448 $cff_sep_size = 0;
449 //Need to set a color otherwise the CSS is invalid
450 $cff_sep_color = 'fff';
451 }
452 //CFF item styles
453 $cff_item_styles = 'style="';
454 $cff_item_styles .= 'border-bottom: ' . $cff_sep_size . 'px solid #' . str_replace('#', '', $cff_sep_color) . '; ';
455 $cff_item_styles .= '"';
456
457 //Text limits
458 $title_limit = $atts['textlength'];
459 if (!isset($title_limit)) $title_limit = 9999;
460 $body_limit = $atts['desclength'];
461 //Assign the Access Token and Page ID variables
462 $access_token = $atts['accesstoken'];
463 $page_id = trim( $atts['id'] );
464
465 //If user pastes their full URL into the Page ID field then strip it out
466 $cff_facebook_string = 'facebook.com';
467 $cff_page_id_url_check = stripos($page_id, $cff_facebook_string);
468
469 if ( $cff_page_id_url_check ) {
470 //Remove trailing slash if exists
471 $page_id = preg_replace('{/$}', '', $page_id);
472 //Get last part of url
473 $page_id = substr( $page_id, strrpos( $page_id, '/' )+1 );
474 }
475
476 //If the Page ID contains a query string at the end then remove it
477 if ( stripos( $page_id, '?') !== false ) $page_id = substr($page_id, 0, strrpos($page_id, '?'));
478
479 //Get show posts attribute. If not set then default to 25
480 $show_posts = $atts['num'];
481 if (empty($show_posts)) $show_posts = 25;
482 if ( $show_posts == 0 || $show_posts == 'undefined' ) $show_posts = 25;
483 //If there's no Access Token then use the default
484 if ($access_token == '') $access_token = '1436737606570258|MGh1BX4_b_D9HzJtKe702cwMRPI';
485 //Check whether a Page ID has been defined
486 if ($page_id == '') {
487 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=YOUR_PAGE_ID_HERE].<br /><br />";
488 return false;
489 }
490
491
492 //Is it SSL?
493 $cff_ssl = '';
494 if (is_ssl()) $cff_ssl = '&return_ssl_resources=true';
495
496 //Use posts? or feed?
497 $old_others_option = get_option('cff_show_others'); //Use this to help depreciate the old option
498 $show_others = $atts['others'];
499 $show_posts_by = $atts['showpostsby'];
500 $graph_query = 'posts';
501 $cff_show_only_others = false;
502
503 //If 'others' shortcode option is used then it overrides any other option
504 if ($show_others || $old_others_option == 'on') {
505 //Show posts by everyone
506 if ( $old_others_option == 'on' || $show_others == 'on' || $show_others == 'true' || $show_others == true || $cff_is_group ) $graph_query = 'feed';
507
508 //Only show posts by me
509 if ( $show_others == 'false' ) $graph_query = 'posts';
510
511 } else {
512 //Else use the settings page option or the 'showpostsby' shortcode option
513
514 //Only show posts by me
515 if ( $show_posts_by == 'me' ) $graph_query = 'posts';
516
517 //Show posts by everyone
518 if ( $show_posts_by == 'others' || $cff_is_group ) $graph_query = 'feed';
519
520 //Show posts ONLY by others
521 if ( $show_posts_by == 'onlyothers' && !$cff_is_group ) {
522 $graph_query = 'feed';
523 $cff_show_only_others = true;
524 }
525
526 }
527
528
529 //If the limit isn't set then set it to be 5 more than the number of posts defined
530 if ( isset($atts['limit']) && $atts['limit'] !== '' ) {
531 $cff_post_limit = $atts['limit'];
532 } else {
533 $cff_post_limit = intval(intval($show_posts) + 7);
534 }
535
536
537 //Calculate the cache time in seconds
538 if($cff_cache_time_unit == 'minutes') $cff_cache_time_unit = 60;
539 if($cff_cache_time_unit == 'hours') $cff_cache_time_unit = 60*60;
540 if($cff_cache_time_unit == 'days') $cff_cache_time_unit = 60*60*24;
541 $cache_seconds = $cff_cache_time * $cff_cache_time_unit;
542
543 //Get like box vars
544 $cff_likebox_width = $atts[ 'likeboxwidth' ];
545 if ( !isset($cff_likebox_width) || empty($cff_likebox_width) || $cff_likebox_width == '' ) $cff_likebox_width = 300;
546 $cff_like_box_faces = $atts[ 'likeboxfaces' ];
547 if ( !isset($cff_like_box_faces) || empty($cff_like_box_faces) ) $cff_like_box_faces = 'false';
548
549 //Set like box variable
550 $like_box = '<div class="cff-likebox';
551 if ($cff_like_box_outside) $like_box .= ' cff-outside';
552 $like_box .= ($cff_like_box_position == 'top') ? ' top' : ' bottom';
553 $like_box .= '" ' . $cff_likebox_styles . '><script src="https://connect.facebook.net/' . $cff_locale . '/all.js#xfbml=1"></script><fb:like-box href="http://www.facebook.com/' . $page_id . '" show_faces="'.$cff_like_box_faces.'" stream="false" header="false" colorscheme="'. $cff_like_box_colorscheme .'" show_border="'. $cff_like_box_border .'" data-height="'.$cff_likebox_height.'"></fb:like-box></div>';
554 //Don't show like box if it's a group
555 if($cff_is_group) $like_box = '';
556
557
558 //Feed header
559 $cff_show_header = $atts['showheader'];
560 ($cff_show_header == 'true' || $cff_show_header == 'on') ? $cff_show_header = true : $cff_show_header = false;
561
562 $cff_header_outside = $atts['headeroutside'];
563 ($cff_header_outside == 'true' || $cff_header_outside == 'on') ? $cff_header_outside = true : $cff_header_outside = false;
564
565 $cff_header_text = $atts['headertext'];
566 $cff_header_icon = $atts['headericon'];
567 $cff_header_icon_color = $atts['headericoncolor'];
568 $cff_header_icon_size = $atts['headericonsize'];
569
570 $cff_header = '<h3 class="cff-header';
571 if ($cff_header_outside) $cff_header .= ' cff-outside';
572 $cff_header .= '"' . $cff_header_styles . '>';
573 $cff_header .= '<i class="fa fa-' . $cff_header_icon . '"';
574 if(!empty($cff_header_icon_color) || !empty($cff_header_icon_size)) $cff_header .= ' style="';
575 if(!empty($cff_header_icon_color)) $cff_header .= 'color: #' . str_replace('#', '', $cff_header_icon_color) . ';';
576 if(!empty($cff_header_icon_size)) $cff_header .= ' font-size: ' . $cff_header_icon_size . 'px;';
577 if(!empty($cff_header_icon_color) || !empty($cff_header_icon_size))$cff_header .= '"';
578 $cff_header .= '></i>';
579 $cff_header .= '<span class="header-text" style="height: '.$cff_header_icon_size.'px;">' . $cff_header_text . '</span>';
580 $cff_header .= '</h3>';
581
582
583 //***START FEED***
584 $cff_content = '';
585
586 //Add the page header to the outside of the top of feed
587 if ($cff_show_header && $cff_header_outside) $cff_content .= $cff_header;
588
589 //Add like box to the outside of the top of feed
590 if ($cff_like_box_position == 'top' && $cff_show_like_box && $cff_like_box_outside) $cff_content .= $like_box;
591
592 //Create CFF container HTML
593 $cff_content .= '<div id="cff" rel="'.$title_limit.'" class="';
594 if( !empty($cff_class) ) $cff_content .= $cff_class . ' ';
595 if ( !empty($cff_feed_height) ) $cff_content .= 'cff-fixed-height ';
596 $cff_content .= '" ' . $cff_feed_styles . '>';
597
598 //Add the page header to the inside of the top of feed
599 if ($cff_show_header && !$cff_header_outside) $cff_content .= $cff_header;
600
601 //Add like box to the inside of the top of feed
602 if ($cff_like_box_position == 'top' && $cff_show_like_box && !$cff_like_box_outside) $cff_content .= $like_box;
603 //Limit var
604 $i = 0;
605
606 //Define array for post items
607 $cff_posts_array = array();
608
609 //ALL POSTS
610 if (!$cff_events_only){
611
612 $cff_posts_json_url = 'https://graph.facebook.com/' . $page_id . '/' . $graph_query . '?access_token=' . $access_token . '&limit=' . $cff_post_limit . '&locale=' . $cff_locale . $cff_ssl;
613
614 //Don't use caching if the cache time is set to zero
615 if ($cff_cache_time != 0){
616 // Get any existing copy of our transient data
617 $transient_name = 'cff_'. $graph_query .'_json_' . $page_id;
618 if ( false === ( $posts_json = get_transient( $transient_name ) ) || $posts_json === null ) {
619 //Get the contents of the Facebook page
620 $posts_json = cff_fetchUrl($cff_posts_json_url);
621 //Cache the JSON
622 set_transient( $transient_name, $posts_json, $cache_seconds );
623 } else {
624 $posts_json = get_transient( $transient_name );
625 //If we can't find the transient then fall back to just getting the json from the api
626 if ($posts_json == false) $posts_json = cff_fetchUrl($cff_posts_json_url);
627 }
628 } else {
629 $posts_json = cff_fetchUrl($cff_posts_json_url);
630 }
631
632
633
634 //Interpret data with JSON
635 $FBdata = json_decode($posts_json);
636 //***STARTS POSTS LOOP***
637 foreach ($FBdata->data as $news )
638 {
639 //Explode News and Page ID's into 2 values
640 $PostID = explode("_", $news->id);
641 //Check the post type
642 $cff_post_type = $news->type;
643 if ($cff_post_type == 'link') {
644 isset($news->story) ? $story = $news->story : $story = '';
645 //Check whether it's an event
646 $event_link_check = "facebook.com/events/";
647 $event_link_check = stripos($news->link, $event_link_check);
648 if ( $event_link_check ) $cff_post_type = 'event';
649 }
650 //Should we show this post or not?
651 $cff_show_post = false;
652 switch ($cff_post_type) {
653 case 'link':
654 if ( $cff_show_links_type ) $cff_show_post = true;
655 break;
656 case 'event':
657 if ( $cff_show_event_type ) $cff_show_post = true;
658 break;
659 case 'video':
660 if ( $cff_show_video_type ) $cff_show_post = true;
661 break;
662 case 'swf':
663 if ( $cff_show_video_type ) $cff_show_post = true;
664 break;
665 case 'photo':
666 if ( $cff_show_photos_type ) $cff_show_post = true;
667 break;
668 case 'offer':
669 $cff_show_post = true;
670 break;
671 case 'status':
672 //Check whether it's a status (author comment or like)
673 if ( $cff_show_status_type && !empty($news->message) ) $cff_show_post = true;
674 break;
675 }
676
677
678 //ONLY show posts by others
679 if ( $cff_show_only_others ) {
680 //Get the numeric ID of the page
681 $page_object = cff_fetchUrl('https://graph.facebook.com/' . $page_id);
682 $page_object = json_decode($page_object);
683 $numeric_page_id = $page_object->id;
684
685 //If the post author's ID is the same as the page ID then don't show the post
686 if ( $numeric_page_id == $news->from->id ) $cff_show_post = false;
687 }
688
689
690 //Is it a duplicate post?
691 if (!isset($prev_post_message)) $prev_post_message = '';
692 if (!isset($prev_post_link)) $prev_post_link = '';
693 if (!isset($prev_post_description)) $prev_post_description = '';
694 isset($news->message) ? $pm = $news->message : $pm = '';
695 isset($news->link) ? $pl = $news->link : $pl = '';
696 isset($news->description) ? $pd = $news->description : $pd = '';
697
698 if ( ($prev_post_message == $pm) && ($prev_post_link == $pl) && ($prev_post_description == $pd) ) $cff_show_post = false;
699
700 //Check post type and display post if selected
701 if ( $cff_show_post ) {
702 //If it isn't then create the post
703 //Only create posts for the amount of posts specified
704 if ( $i == $show_posts ) break;
705 $i++;
706 //********************************//
707 //***COMPILE SECTION VARIABLES***//
708 //********************************//
709 //Set the post link
710 isset($news->link) ? $link = htmlspecialchars($news->link) : $link = '';
711 //Is it a shared album?
712 $shared_album_string = 'shared an album:';
713 isset($news->story) ? $story = $news->story : $story = '';
714 $shared_album = stripos($story, $shared_album_string);
715 if ( $shared_album ) {
716 $link = str_replace('photo.php?','media/set/?',$link);
717 }
718
719 //Is it an album?
720 $cff_album = false;
721 $album_string = 'relevant_count=';
722 $relevant_count = stripos($link, $album_string);
723
724 if ( $relevant_count ) {
725 //If relevant_count is larger than 1 then there are multiple photos
726 $relevant_count = explode('relevant_count=', $link);
727 $num_photos = intval($relevant_count[1]);
728 if ( $num_photos > 1 ) {
729 $cff_album = true;
730
731 //Link to the album instead of the photo
732 $album_link = str_replace('photo.php?','media/set/?',$link);
733 $link = "https://www.facebook.com/" . $page_id . "/posts/" . $PostID[1];
734 }
735 }
736
737 //If there's no link provided then link to either the Facebook page or the individual status
738 if (empty($news->link)) {
739 if ($cff_link_to_timeline == true){
740 //Link to page
741 $link = 'http://facebook.com/' . $page_id;
742 } else {
743 //Link to status
744 $link = "https://www.facebook.com/" . $page_id . "/posts/" . $PostID[1];
745 }
746 }
747
748 //POST AUTHOR
749 $cff_author = '<div class="cff-author"><a href="https://facebook.com/' . $news->from->id . '" '.$target.' title="'.$news->from->name.' on Facebook" '.$cff_author_styles.'>';
750
751 //Set the author image as a variable. If it already exists then don't query the api for it again.
752 $cff_author_img_var = '$cff_author_img_' . $news->from->id;
753 if ( !isset($$cff_author_img_var) ) $$cff_author_img_var = 'https://graph.facebook.com/' . $news->from->id . '/picture?type=square';
754 $cff_author .= '<img src="'.$$cff_author_img_var.'" title="'.$news->from->name.'" alt="'.$news->from->name.'" width=50 height=50>';
755 $cff_author .= '<span class="cff-page-name">'.$news->from->name.'</span>';
756 $cff_author .= '</a></div>';
757
758 //POST TEXT
759 $cff_translate_photos_text = $atts['photostext'];
760 if (!isset($cff_translate_photos_text) || empty($cff_translate_photos_text)) $cff_translate_photos_text = 'photos';
761 $cff_post_text = '<' . $cff_title_format . ' class="cff-post-text" ' . $cff_title_styles . '>';
762 $cff_post_text .= '<span class="cff-text">';
763 if ($cff_title_link) $cff_post_text .= '<a class="cff-post-text-link" href="'.$link.'" '.$target.'>';
764 //Which content should we use?
765 $cff_post_text_type = '';
766 //Use the story
767 if (!empty($news->story)) {
768 $post_text = htmlspecialchars($news->story);
769 $cff_post_text_type = 'story';
770 }
771 //Use the message
772 if (!empty($news->message)) {
773 $post_text = htmlspecialchars($news->message);
774 $cff_post_text_type = 'message';
775 }
776 //Use the name
777 if (!empty($news->name) && empty($news->story) && empty($news->message)) {
778 $post_text = htmlspecialchars($news->name);
779 $cff_post_text_type = 'name';
780 }
781 if ($cff_album) {
782 if (!empty($news->name)) {
783 $post_text = htmlspecialchars($news->name);
784 $cff_post_text_type = 'name';
785 }
786 if (!empty($news->message) && empty($news->name)) {
787 $post_text = htmlspecialchars($news->message);
788 $cff_post_text_type = 'message';
789 }
790 $post_text .= ' (' . $num_photos . ' '.$cff_translate_photos_text.')';
791 }
792
793
794 //MESSAGE TAGS
795 $cff_post_tags = $atts[ 'posttags' ];
796 //If the post tags option doesn't exist yet (ie. on plugin update) then set them as true
797 if ( !array_key_exists( 'cff_post_tags', $options ) ) $cff_post_tags = true;
798 //Add message and story tags if there are any and the post text is the message or the story
799 if( $cff_post_tags && ( isset($news->message_tags) || isset($news->story_tags) ) && ($cff_post_text_type == 'message' || $cff_post_text_type == 'story') && !$cff_title_link){
800 //Use message_tags or story_tags?
801 ( isset($news->message_tags) )? $text_tags = $news->message_tags : $text_tags = $news->story_tags;
802
803 //If message tags and message is being used as the post text, or same with story. This stops story tags being used to replace the message inadvertently.
804 if( ( $cff_post_text_type == 'message' && isset($news->message_tags) ) || ( $cff_post_text_type == 'story' && !isset($news->message_tags) ) ) {
805
806 //Does the Post Text contain any html tags? - the & symbol is the best indicator of this
807 $cff_html_check_array = array('&lt;', '', '', '&quot;', '&amp;');
808
809 //always use the text replace method
810 if( stripos_arr($post_text, $cff_html_check_array) !== false ) {
811 //Loop through the tags
812 foreach($text_tags as $message_tag ) {
813 $tag_name = $message_tag[0]->name;
814 $tag_link = '<a href="http://facebook.com/' . $message_tag[0]->id . '" style="color: #'.str_replace('#', '', $atts['textlinkcolor']).';" target="_blank">' . $message_tag[0]->name . '</a>';
815
816 $post_text = str_replace($tag_name, $tag_link, $post_text);
817 }
818
819 } else {
820 //If it doesn't contain HTMl tags then use the offset to replace message tags
821 $message_tags_arr = array();
822
823 $i = 0;
824 foreach($text_tags as $message_tag ) {
825 $i++;
826 $message_tags_arr = array_push_assoc(
827 $message_tags_arr,
828 $i,
829 array(
830 'id' => $message_tag[0]->id,
831 'name' => $message_tag[0]->name,
832 'type' => $message_tag[0]->type,
833 'offset' => $message_tag[0]->offset,
834 'length' => $message_tag[0]->length
835 )
836 );
837 }
838
839 for($i = count($message_tags_arr); $i >= 1; $i--) {
840
841 $b = '<a href="http://facebook.com/' . $message_tags_arr[$i]['id'] . '" style="color: #'.str_replace('#', '', $atts['textlinkcolor']).';" target="_blank">' . $message_tags_arr[$i]['name'] . '</a>';
842 $c = $message_tags_arr[$i]['offset'];
843 $d = $message_tags_arr[$i]['length'];
844
845 $post_text = mb_substr_replace( $post_text, $b, $c, $d);
846
847 }
848
849 } // end if/else
850
851 } // end message check
852
853 } //END MESSAGE TAGS
854
855 //Replace line breaks in text (needed for IE8)
856 $post_text = preg_replace("/\r\n|\r|\n/",'<br/>', $post_text);
857
858 //If the text is wrapped in a link then don't hyperlink any text within
859 if ($cff_title_link) {
860 //Wrap links in a span so we can break the text if it's too long
861 $cff_post_text .= cff_wrap_span( $post_text ) . ' ';
862 } else {
863 //Don't use htmlspecialchars for post_text as it's added above so that it doesn't mess up the message_tag offsets
864 $cff_post_text .= cff_autolink( $post_text, $link_color=str_replace('#', '', $atts['textlinkcolor']) ) . ' ';
865 }
866
867 if ($cff_title_link) $cff_post_text .= '</a>';
868 $cff_post_text .= '</span>';
869 //'See More' link
870 $cff_post_text .= '<span class="cff-expand">... <a href="#" style="color: #'.str_replace('#', '', $atts['textlinkcolor']).'"><span class="cff-more">' . $cff_see_more_text . '</span><span class="cff-less">' . $cff_see_less_text . '</span></a></span>';
871 $cff_post_text .= '</' . $cff_title_format . '>';
872
873 //DESCRIPTION
874 $cff_description = '';
875 //Use the description if it's available and the post type isn't set to offer (offer description isn't useful)
876 if ( ( !empty($news->description) || !empty($news->caption) ) && $cff_post_type != 'offer') {
877
878 $description_text = '';
879 if ( !empty($news->description) ) {
880 $description_text = $news->description;
881 } else {
882 $description_text = $news->caption;
883 }
884
885 if (!empty($body_limit)) {
886 if (strlen($description_text) > $body_limit) $description_text = substr($description_text, 0, $body_limit) . '...';
887 }
888 $cff_description .= '<p class="cff-post-desc" '.$cff_body_styles.'><span>' . cff_autolink( htmlspecialchars($description_text) ) . '</span></p>';
889
890 //If the post text and description/caption are the same then don't show the description
891 if($post_text == $description_text) $cff_description = '';
892
893 }
894
895 //LINK
896 $cff_shared_link = '';
897 //Display shared link
898 if ($cff_post_type == 'link') {
899 $cff_shared_link .= '<div class="cff-shared-link';
900 if($cff_disable_link_box) $cff_shared_link .= ' cff-no-styles"';
901 if(!$cff_disable_link_box) $cff_shared_link .= '" ' . $cff_link_box_styles;
902 $cff_shared_link .= '>';
903
904 //Display link name and description
905 if (!empty($news->description)) {
906 $cff_shared_link .= '<div class="cff-text-link ';
907 $cff_shared_link .= 'cff-no-image';
908 //The link title:
909 $cff_shared_link .= '"><'.$cff_link_title_format.' class="cff-link-title" '.$cff_link_title_styles.'><a href="'.$link.'" '.$target.' style="color:#' . str_replace('#', '', $cff_link_title_color) . ';">'. $news->name . '</a></'.$cff_link_title_format.'>';
910 //The link source:
911 if(!empty($news->caption)) $cff_shared_link .= '<p class="cff-link-caption" style="color:#' . str_replace('#', '', $cff_link_url_color) . ';">'.$news->caption.'</p>';
912 if ($cff_show_desc) {
913 $cff_shared_link .= $cff_description;
914 }
915 $cff_shared_link .= '</div>';
916 }
917
918 $cff_shared_link .= '</div>';
919 }
920
921 //DATE
922 $cff_date_formatting = $atts[ 'dateformat' ];
923 $cff_date_custom = $atts[ 'datecustom' ];
924
925 $post_time = $news->created_time;
926 $cff_date = '<p class="cff-date" '.$cff_date_styles.'>'. $cff_date_before . ' ' . cff_getdate(strtotime($post_time), $cff_date_formatting, $cff_date_custom) . ' ' . $cff_date_after . '</p>';
927 //EVENT
928 $cff_event = '';
929 if ($cff_show_event_title || $cff_show_event_details) {
930 //Check for media
931 if ($cff_post_type == 'event') {
932
933 //Get the event id from the event URL. eg: http://www.facebook.com/events/123451234512345/
934 $event_url = parse_url($link);
935 $url_parts = explode('/', $event_url['path']);
936 //Get the id from the parts
937 $eventID = $url_parts[count($url_parts)-2];
938
939 //Get the contents of the event using the WP HTTP API
940 $event_json_url = 'https://graph.facebook.com/'.$eventID.'?access_token=' . $access_token . $cff_ssl;
941
942 //Don't use caching if the cache time is set to zero
943 if ($cff_cache_time != 0){
944 // Get any existing copy of our transient data
945 $transient_name = 'cff_timeline_event_json_' . $eventID;
946 if ( false === ( $event_json = get_transient( $transient_name ) ) || $event_json === null ) {
947 //Get the contents of the Facebook page
948 $event_json = cff_fetchUrl($event_json_url);
949 //Cache the JSON
950 set_transient( $transient_name, $event_json, $cache_seconds );
951 } else {
952 $event_json = get_transient( $transient_name );
953 //If we can't find the transient then fall back to just getting the json from the api
954 if ($event_json == false) $event_json = cff_fetchUrl($event_json_url);
955 }
956 } else {
957 $event_json = cff_fetchUrl($event_json_url);
958 }
959
960 //Interpret data with JSON
961 $event_object = json_decode($event_json);
962 //Event date
963 isset( $event_object->start_time ) ? $event_time = $event_object->start_time : $event_time = '';
964 //If timezone migration is enabled then remove last 5 characters
965 if ( strlen($event_time) == 24 ) $event_time = substr($event_time, 0, -5);
966 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>';
967 //EVENT
968 //Display the event details
969 $cff_event .= '<div class="cff-details">';
970 //show event date above title
971 if ($cff_event_date_position == 'above') $cff_event .= $cff_event_date;
972 //Show event title
973 if ($cff_show_event_title && !empty($event_object->name)) {
974 if ($cff_event_title_link) $cff_event .= '<a href="'.$link.'">';
975 $cff_event .= '<' . $cff_event_title_format . ' ' . $cff_event_title_styles . '>' . $event_object->name . '</' . $cff_event_title_format . '>';
976 if ($cff_event_title_link) $cff_event .= '</a>';
977 }
978 //show event date below title
979 if ($cff_event_date_position !== 'above') $cff_event .= $cff_event_date;
980 //Show event details
981 if ($cff_show_event_details){
982 //Location
983 if (!empty($event_object->location)) $cff_event .= '<p class="cff-where" ' . $cff_event_details_styles . '>' . $event_object->location . '</p>';
984 //Description
985 if (!empty($event_object->description)){
986 $description = $event_object->description;
987 if (!empty($body_limit)) {
988 if (strlen($description) > $body_limit) $description = substr($description, 0, $body_limit) . '...';
989 }
990 $cff_event .= '<p class="cff-info" ' . $cff_event_details_styles . '>' . cff_autolink($description, $link_color=str_replace('#', '', $cff_event_link_color) ) . '</p>';
991 }
992 }
993 $cff_event .= '</div>';
994
995 }
996 }
997
998 /* VIDEO */
999 $cff_is_video_embed = false;
1000 $cff_media = '';
1001 if ($news->type == 'video') {
1002 $cff_is_video_embed = true;
1003 //Add the name to the description if it's a video embed
1004 if($cff_is_video_embed) {
1005 isset($news->name) ? $video_name = $news->name : $video_name = $link;
1006 isset($news->description) ? $description_text = $news->description : $description_text = '';
1007 $cff_description = '<div class="cff-desc-wrap cff-shared-link ';
1008 if (empty($picture)) $cff_description .= 'cff-no-image';
1009 if($cff_disable_link_box) $cff_description .= ' cff-no-styles"';
1010 if(!$cff_disable_link_box) $cff_description .= '" ' . $cff_link_box_styles;
1011 $cff_description .= '>';
1012
1013 if( isset($news->name) ) $cff_description .= '<'.$cff_link_title_format.' class="cff-link-title" '.$cff_link_title_styles.'><a href="'.$link.'" '.$target.' style="color:#' . str_replace('#', '', $cff_link_title_color) . ';">'. $news->name . '</a></'.$cff_link_title_format.'>';
1014
1015 if (!empty($body_limit)) {
1016 if (strlen($description_text) > $body_limit) $description_text = substr($description_text, 0, $body_limit) . '...';
1017 }
1018
1019 $cff_description .= '<p class="cff-post-desc" '.$cff_body_styles.'><span>' . cff_autolink( htmlspecialchars($description_text) ) . '</span></p></div>';
1020 }
1021 }
1022
1023
1024 //Display the link to the Facebook post or external link
1025 $cff_link = '';
1026 //Default link
1027 $cff_viewpost_class = 'cff-viewpost-facebook';
1028 if ($cff_facebook_link_text == '') $cff_facebook_link_text = 'View on Facebook';
1029 $link_text = $cff_facebook_link_text;
1030
1031 //Link to the Facebook post if it's a link or a video
1032 if($cff_post_type == 'link' || $cff_post_type == 'video') $link = "https://www.facebook.com/" . $page_id . "/posts/" . $PostID[1];
1033
1034 if ($cff_post_type == 'offer') $link_text = 'View Offer';
1035 $cff_link = '<a class="' . $cff_viewpost_class . '" href="' . $link . '" title="' . $link_text . '" ' . $target . ' ' . $cff_link_styles . '>' . $link_text . '</a>';
1036
1037
1038 //**************************//
1039 //***CREATE THE POST HTML***//
1040 //**************************//
1041 //Start the container
1042 $cff_post_item = '<div class="cff-item ';
1043 if ($cff_post_type == 'link') $cff_post_item .= 'cff-link-item';
1044 if ($cff_post_type == 'event') $cff_post_item .= 'cff-timeline-event';
1045 if ($cff_post_type == 'photo') $cff_post_item .= 'cff-photo-post';
1046 if ($cff_post_type == 'video') $cff_post_item .= 'cff-video-post';
1047 if ($cff_post_type == 'swf') $cff_post_item .= 'cff-swf-post';
1048 if ($cff_post_type == 'status') $cff_post_item .= 'cff-status-post';
1049 if ($cff_post_type == 'offer') $cff_post_item .= 'cff-offer-post';
1050 if ($cff_album) $cff_post_item .= ' cff-album';
1051 $cff_post_item .= ' author-'. to_slug($news->from->name) .'" id="'. $news->id .'" ' . $cff_item_styles . '>';
1052
1053 //POST AUTHOR
1054 if($cff_show_author) $cff_post_item .= $cff_author;
1055 //DATE ABOVE
1056 if ($cff_show_date && $cff_date_position == 'above') $cff_post_item .= $cff_date;
1057 //POST TEXT
1058 if($cff_show_text) $cff_post_item .= $cff_post_text;
1059 //DESCRIPTION
1060 if($cff_show_desc && $cff_post_type != 'offer' && $cff_post_type != 'link') $cff_post_item .= $cff_description;
1061 //LINK
1062 if($cff_show_shared_links) $cff_post_item .= $cff_shared_link;
1063 //DATE BELOW
1064 if ($cff_show_date && $cff_date_position == 'below') $cff_post_item .= $cff_date;
1065 //EVENT
1066 if($cff_show_event_title || $cff_show_event_details) $cff_post_item .= $cff_event;
1067 //VIEW ON FACEBOOK LINK
1068 if($cff_show_link) $cff_post_item .= $cff_link;
1069
1070 //End the post item
1071 $cff_post_item .= '</div>';
1072
1073 //PUSH TO ARRAY
1074 $cff_posts_array = array_push_assoc($cff_posts_array, strtotime($post_time), $cff_post_item);
1075
1076 } // End post type check
1077
1078 if (isset($news->message)) $prev_post_message = $news->message;
1079 if (isset($news->link)) $prev_post_link = $news->link;
1080 if (isset($news->description)) $prev_post_description = $news->description;
1081
1082 } // End the loop
1083
1084 //Sort the array in reverse order (newest first)
1085 krsort($cff_posts_array);
1086
1087 } // End ALL POSTS
1088
1089
1090 //Output the posts array
1091 $p = 0;
1092 foreach ($cff_posts_array as $post ) {
1093 if ( $p == $show_posts ) break;
1094 $cff_content .= $post;
1095 $p++;
1096 }
1097
1098 //Reset the timezone
1099 date_default_timezone_set( $cff_orig_timezone );
1100 //Add the Like Box inside
1101 if ($cff_like_box_position == 'bottom' && $cff_show_like_box && !$cff_like_box_outside) $cff_content .= $like_box;
1102 //End the feed
1103 $cff_content .= '</div><div class="cff-clear"></div>';
1104 //Add the Like Box outside
1105 if ($cff_like_box_position == 'bottom' && $cff_show_like_box && $cff_like_box_outside) $cff_content .= $like_box;
1106
1107 //If the feed is loaded via Ajax then put the scripts into the shortcode itself
1108 $ajax_theme = $atts['ajax'];
1109 ( $ajax_theme == 'on' || $ajax_theme == 'true' || $ajax_theme == true ) ? $ajax_theme = true : $ajax_theme = false;
1110 if( $atts[ 'ajax' ] == 'false' ) $ajax_theme = false;
1111 if ($ajax_theme) $cff_content .= '<script type="text/javascript" src="' . plugins_url( '/js/cff-scripts.js?8' , __FILE__ ) . '"></script>';
1112
1113 //Return our feed HTML to display
1114 return $cff_content;
1115 }
1116
1117 //***FUNCTIONS***
1118
1119 //Get JSON object of feed data
1120 function cff_fetchUrl($url){
1121 //Can we use cURL?
1122 if(is_callable('curl_init')){
1123 $ch = curl_init();
1124 curl_setopt($ch, CURLOPT_URL, $url);
1125 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1126 curl_setopt($ch, CURLOPT_TIMEOUT, 20);
1127 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1128 $feedData = curl_exec($ch);
1129 curl_close($ch);
1130 //If not then use file_get_contents
1131 } elseif ( ini_get('allow_url_fopen') == 1 || ini_get('allow_url_fopen') === TRUE ) {
1132 $feedData = @file_get_contents($url);
1133 //Or else use the WP HTTP API
1134 } else {
1135 if( !class_exists( 'WP_Http' ) ) include_once( ABSPATH . WPINC. '/class-http.php' );
1136 $request = new WP_Http;
1137 $result = $request->request($url);
1138 $feedData = $result['body'];
1139 }
1140
1141 return $feedData;
1142 }
1143
1144 //Make links into span instead when the post text is made clickable
1145 function cff_wrap_span($text) {
1146 $pattern = '#\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#';
1147 return preg_replace_callback($pattern, 'cff_wrap_span_callback', $text);
1148 }
1149 function cff_wrap_span_callback($matches) {
1150 $max_url_length = 100;
1151 $max_depth_if_over_length = 2;
1152 $ellipsis = '&hellip;';
1153 $target = 'target="_blank"';
1154 $url_full = $matches[0];
1155 $url_short = '';
1156 if (strlen($url_full) > $max_url_length) {
1157 $parts = parse_url($url_full);
1158 $url_short = $parts['scheme'] . '://' . preg_replace('/^www\./', '', $parts['host']) . '/';
1159 $path_components = explode('/', trim($parts['path'], '/'));
1160 foreach ($path_components as $dir) {
1161 $url_string_components[] = $dir . '/';
1162 }
1163 if (!empty($parts['query'])) {
1164 $url_string_components[] = '?' . $parts['query'];
1165 }
1166 if (!empty($parts['fragment'])) {
1167 $url_string_components[] = '#' . $parts['fragment'];
1168 }
1169 for ($k = 0; $k < count($url_string_components); $k++) {
1170 $curr_component = $url_string_components[$k];
1171 if ($k >= $max_depth_if_over_length || strlen($url_short) + strlen($curr_component) > $max_url_length) {
1172 if ($k == 0 && strlen($url_short) < $max_url_length) {
1173 // Always show a portion of first directory
1174 $url_short .= substr($curr_component, 0, $max_url_length - strlen($url_short));
1175 }
1176 $url_short .= $ellipsis;
1177 break;
1178 }
1179 $url_short .= $curr_component;
1180 }
1181 } else {
1182 $url_short = $url_full;
1183 }
1184 return "<span class='cff-break-word'>$url_short</span>";
1185 }
1186
1187 //2013-04-28T21:06:56+0000
1188 //Time stamp function - used for posts
1189 function cff_getdate($original, $date_format, $custom_date) {
1190 switch ($date_format) {
1191
1192 case '2':
1193 $print = date_i18n('F jS, g:i a', $original);
1194 break;
1195 case '3':
1196 $print = date_i18n('F jS', $original);
1197 break;
1198 case '4':
1199 $print = date_i18n('D F jS', $original);
1200 break;
1201 case '5':
1202 $print = date_i18n('l F jS', $original);
1203 break;
1204 case '6':
1205 $print = date_i18n('D M jS, Y', $original);
1206 break;
1207 case '7':
1208 $print = date_i18n('l F jS, Y', $original);
1209 break;
1210 case '8':
1211 $print = date_i18n('l F jS, Y - g:i a', $original);
1212 break;
1213 case '9':
1214 $print = date_i18n("l M jS, 'y", $original);
1215 break;
1216 case '10':
1217 $print = date_i18n('m.d.y', $original);
1218 break;
1219 case '11':
1220 $print = date_i18n('m/d/y', $original);
1221 break;
1222 case '12':
1223 $print = date_i18n('d.m.y', $original);
1224 break;
1225 case '13':
1226 $print = date_i18n('d/m/y', $original);
1227 break;
1228 default:
1229
1230 $options = get_option('cff_style_settings');
1231
1232 $cff_second = isset($options['cff_translate_second']) ? $options['cff_translate_second'] : '';
1233 if ( empty($cff_second) ) $cff_second = 'second';
1234
1235 $cff_seconds = isset($options['cff_translate_seconds']) ? $options['cff_translate_seconds'] : '';
1236 if ( empty($cff_seconds) ) $cff_seconds = 'seconds';
1237
1238 $cff_minute = isset($options['cff_translate_minute']) ? $options['cff_translate_minute'] : '';
1239 if ( empty($cff_minute) ) $cff_minute = 'minute';
1240
1241 $cff_minutes = isset($options['cff_translate_minutes']) ? $options['cff_translate_minutes'] : '';
1242 if ( empty($cff_minutes) ) $cff_minutes = 'minutes';
1243
1244 $cff_hour = isset($options['cff_translate_hour']) ? $options['cff_translate_hour'] : '';
1245 if ( empty($cff_hour) ) $cff_hour = 'hour';
1246
1247 $cff_hours = isset($options['cff_translate_hours']) ? $options['cff_translate_hours'] : '';
1248 if ( empty($cff_hours) ) $cff_hours = 'hours';
1249
1250 $cff_day = isset($options['cff_translate_day']) ? $options['cff_translate_day'] : '';
1251 if ( empty($cff_day) ) $cff_day = 'day';
1252
1253 $cff_days = isset($options['cff_translate_days']) ? $options['cff_translate_days'] : '';
1254 if ( empty($cff_days) ) $cff_days = 'days';
1255
1256 $cff_week = isset($options['cff_translate_week']) ? $options['cff_translate_week'] : '';
1257 if ( empty($cff_week) ) $cff_week = 'week';
1258
1259 $cff_weeks = isset($options['cff_translate_weeks']) ? $options['cff_translate_weeks'] : '';
1260 if ( empty($cff_weeks) ) $cff_weeks = 'weeks';
1261
1262 $cff_month = isset($options['cff_translate_month']) ? $options['cff_translate_month'] : '';
1263 if ( empty($cff_month) ) $cff_month = 'month';
1264
1265 $cff_months = isset($options['cff_translate_months']) ? $options['cff_translate_months'] : '';
1266 if ( empty($cff_months) ) $cff_months = 'months';
1267
1268 $cff_year = isset($options['cff_translate_year']) ? $options['cff_translate_year'] : '';
1269 if ( empty($cff_year) ) $cff_year = 'year';
1270
1271 $cff_years = isset($options['cff_translate_years']) ? $options['cff_translate_years'] : '';
1272 if ( empty($cff_years) ) $cff_years = 'years';
1273
1274 $cff_ago = isset($options['cff_translate_ago']) ? $options['cff_translate_ago'] : '';
1275 if ( empty($cff_ago) ) $cff_ago = 'ago';
1276
1277
1278 $periods = array($cff_second, $cff_minute, $cff_hour, $cff_day, $cff_week, $cff_month, $cff_year, "decade");
1279 $periods_plural = array($cff_seconds, $cff_minutes, $cff_hours, $cff_days, $cff_weeks, $cff_months, $cff_years, "decade");
1280
1281 $lengths = array("60","60","24","7","4.35","12","10");
1282 $now = time();
1283
1284 // is it future date or past date
1285 if($now > $original) {
1286 $difference = $now - $original;
1287 $tense = $cff_ago;
1288 } else {
1289 $difference = $original - $now;
1290 $tense = $cff_ago;
1291 }
1292 for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
1293 $difference /= $lengths[$j];
1294 }
1295
1296 $difference = round($difference);
1297
1298 if($difference != 1) {
1299 $periods[$j] = $periods_plural[$j];
1300 }
1301 $print = "$difference $periods[$j] {$tense}";
1302
1303 break;
1304
1305 }
1306 if ( !empty($custom_date) ){
1307 $print = date_i18n($custom_date, $original);
1308 }
1309
1310 return $print;
1311 }
1312 function cff_eventdate($original, $date_format, $custom_date) {
1313 switch ($date_format) {
1314
1315 case '2':
1316 $print = date_i18n('F jS, g:ia', $original);
1317 break;
1318 case '3':
1319 $print = date_i18n('g:ia - F jS', $original);
1320 break;
1321 case '4':
1322 $print = date_i18n('g:ia, F jS', $original);
1323 break;
1324 case '5':
1325 $print = date_i18n('l F jS - g:ia', $original);
1326 break;
1327 case '6':
1328 $print = date_i18n('D M jS, Y, g:iA', $original);
1329 break;
1330 case '7':
1331 $print = date_i18n('l F jS, Y, g:iA', $original);
1332 break;
1333 case '8':
1334 $print = date_i18n('l F jS, Y - g:ia', $original);
1335 break;
1336 case '9':
1337 $print = date_i18n("l M jS, 'y", $original);
1338 break;
1339 case '10':
1340 $print = date_i18n('m.d.y - g:iA', $original);
1341 break;
1342 case '11':
1343 $print = date_i18n('m/d/y, g:ia', $original);
1344 break;
1345 case '12':
1346 $print = date_i18n('d.m.y - g:iA', $original);
1347 break;
1348 case '13':
1349 $print = date_i18n('d/m/y, g:ia', $original);
1350 break;
1351 default:
1352 $print = date_i18n('F j, Y, g:ia', $original);
1353 break;
1354 }
1355 if ( !empty($custom_date) ){
1356 $print = date_i18n($custom_date, $original);
1357 }
1358 return $print;
1359 }
1360 //Time stamp function - used for comments
1361 function cff_timesince($original) {
1362
1363 $options = get_option('cff_style_settings');
1364
1365 $cff_second = isset($options['cff_translate_second']) ? $options['cff_translate_second'] : '';
1366 if ( empty($cff_second) ) $cff_second = 'second';
1367
1368 $cff_seconds = isset($options['cff_translate_seconds']) ? $options['cff_translate_seconds'] : '';
1369 if ( empty($cff_seconds) ) $cff_seconds = 'seconds';
1370
1371 $cff_minute = isset($options['cff_translate_minute']) ? $options['cff_translate_minute'] : '';
1372 if ( empty($cff_minute) ) $cff_minute = 'minute';
1373
1374 $cff_minutes = isset($options['cff_translate_minutes']) ? $options['cff_translate_minutes'] : '';
1375 if ( empty($cff_minutes) ) $cff_minutes = 'minutes';
1376
1377 $cff_hour = isset($options['cff_translate_hour']) ? $options['cff_translate_hour'] : '';
1378 if ( empty($cff_hour) ) $cff_hour = 'hour';
1379
1380 $cff_hours = isset($options['cff_translate_hours']) ? $options['cff_translate_hours'] : '';
1381 if ( empty($cff_hours) ) $cff_hours = 'hours';
1382
1383 $cff_day = isset($options['cff_translate_day']) ? $options['cff_translate_day'] : '';
1384 if ( empty($cff_day) ) $cff_day = 'day';
1385
1386 $cff_days = isset($options['cff_translate_days']) ? $options['cff_translate_days'] : '';
1387 if ( empty($cff_days) ) $cff_days = 'days';
1388
1389 $cff_week = isset($options['cff_translate_week']) ? $options['cff_translate_week'] : '';
1390 if ( empty($cff_week) ) $cff_week = 'week';
1391
1392 $cff_weeks = isset($options['cff_translate_weeks']) ? $options['cff_translate_weeks'] : '';
1393 if ( empty($cff_weeks) ) $cff_weeks = 'weeks';
1394
1395 $cff_month = isset($options['cff_translate_month']) ? $options['cff_translate_month'] : '';
1396 if ( empty($cff_month) ) $cff_month = 'month';
1397
1398 $cff_months = isset($options['cff_translate_months']) ? $options['cff_translate_months'] : '';
1399 if ( empty($cff_months) ) $cff_months = 'months';
1400
1401 $cff_year = isset($options['cff_translate_year']) ? $options['cff_translate_year'] : '';
1402 if ( empty($cff_year) ) $cff_year = 'year';
1403
1404 $cff_years = isset($options['cff_translate_years']) ? $options['cff_translate_years'] : '';
1405 if ( empty($cff_years) ) $cff_years = 'years';
1406
1407 $cff_ago = isset($options['cff_translate_ago']) ? $options['cff_translate_ago'] : '';
1408 if ( empty($cff_ago) ) $cff_ago = 'ago';
1409
1410
1411 $periods = array($cff_second, $cff_minute, $cff_hour, $cff_day, $cff_week, $cff_month, $cff_year, "decade");
1412 $periods_plural = array($cff_seconds, $cff_minutes, $cff_hours, $cff_days, $cff_weeks, $cff_months, $cff_years, "decade");
1413
1414 $lengths = array("60","60","24","7","4.35","12","10");
1415 $now = time();
1416
1417 // is it future date or past date
1418 if($now > $original) {
1419 $difference = $now - $original;
1420 $tense = $cff_ago;
1421 } else {
1422 $difference = $original - $now;
1423 $tense = $cff_ago;
1424 }
1425 for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
1426 $difference /= $lengths[$j];
1427 }
1428
1429 $difference = round($difference);
1430
1431 if($difference != 1) {
1432 $periods[$j] = $periods_plural[$j];
1433 }
1434 return "$difference $periods[$j] {$tense}";
1435
1436 }
1437 //Use custom stripos function if it's not available (only available in PHP 5+)
1438 if(!is_callable('stripos')){
1439 function stripos($haystack, $needle){
1440 return strpos($haystack, stristr( $haystack, $needle ));
1441 }
1442 }
1443 function stripos_arr($haystack, $needle) {
1444 if(!is_array($needle)) $needle = array($needle);
1445 foreach($needle as $what) {
1446 if(($pos = stripos($haystack, ltrim($what) ))!==false) return $pos;
1447 }
1448 return false;
1449 }
1450 function mb_substr_replace($string, $replacement, $start, $length=NULL) {
1451 if (is_array($string)) {
1452 $num = count($string);
1453 // $replacement
1454 $replacement = is_array($replacement) ? array_slice($replacement, 0, $num) : array_pad(array($replacement), $num, $replacement);
1455 // $start
1456 if (is_array($start)) {
1457 $start = array_slice($start, 0, $num);
1458 foreach ($start as $key => $value)
1459 $start[$key] = is_int($value) ? $value : 0;
1460 }
1461 else {
1462 $start = array_pad(array($start), $num, $start);
1463 }
1464 // $length
1465 if (!isset($length)) {
1466 $length = array_fill(0, $num, 0);
1467 }
1468 elseif (is_array($length)) {
1469 $length = array_slice($length, 0, $num);
1470 foreach ($length as $key => $value)
1471 $length[$key] = isset($value) ? (is_int($value) ? $value : $num) : 0;
1472 }
1473 else {
1474 $length = array_pad(array($length), $num, $length);
1475 }
1476 // Recursive call
1477 return array_map(__FUNCTION__, $string, $replacement, $start, $length);
1478 }
1479 preg_match_all('/./us', (string)$string, $smatches);
1480 preg_match_all('/./us', (string)$replacement, $rmatches);
1481 if ($length === NULL) $length = mb_strlen($string);
1482 array_splice($smatches[0], $start, $length, $rmatches[0]);
1483 return join($smatches[0]);
1484 }
1485
1486 //Push to assoc array
1487 function array_push_assoc($array, $key, $value){
1488 $array[$key] = $value;
1489 return $array;
1490 }
1491 //Convert string to slug
1492 function to_slug($string){
1493 return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string)));
1494 }
1495
1496 // remove_filter( 'the_content', 'wpautop' );
1497 // add_filter( 'the_content', 'wpautop', 99 );
1498
1499
1500 //Allows shortcodes in theme
1501 add_filter('widget_text', 'do_shortcode');
1502
1503 //Enqueue stylesheet
1504 add_action( 'wp_enqueue_scripts', 'cff_add_my_stylesheet' );
1505 function cff_add_my_stylesheet() {
1506 // Respects SSL, Style.css is relative to the current file
1507 wp_register_style( 'cff', plugins_url('css/cff-style.css?6', __FILE__) );
1508 wp_enqueue_style( 'cff' );
1509 wp_enqueue_style( 'cff-font-awesome', '//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css', array(), '4.0.3' );
1510 }
1511 //Enqueue scripts
1512 add_action( 'wp_enqueue_scripts', 'cff_scripts_method' );
1513 function cff_scripts_method() {
1514 //Register the script to make it available
1515 wp_register_script( 'cffscripts', plugins_url( '/js/cff-scripts.js?6' , __FILE__ ), array('jquery'), '1.8', true );
1516 //Enqueue it to load it onto the page
1517 wp_enqueue_script('cffscripts');
1518 }
1519
1520 // function cff_activate() {
1521 // $options = get_option('cff_style_settings');
1522 // $options[ 'cff_show_links_type' ] = true;
1523 // $options[ 'cff_show_event_type' ] = true;
1524 // $options[ 'cff_show_video_type' ] = true;
1525 // $options[ 'cff_show_photos_type' ] = true;
1526 // $options[ 'cff_show_status_type' ] = true;
1527 // $options[ 'cff_show_author' ] = true;
1528 // $options[ 'cff_show_text' ] = true;
1529 // $options[ 'cff_show_desc' ] = true;
1530 // $options[ 'cff_show_shared_links' ] = true;
1531 // $options[ 'cff_show_date' ] = true;
1532 // $options[ 'cff_show_media' ] = true;
1533 // $options[ 'cff_show_event_title' ] = true;
1534 // $options[ 'cff_show_event_details' ] = true;
1535 // $options[ 'cff_show_meta' ] = true;
1536 // $options[ 'cff_show_link' ] = true;
1537 // $options[ 'cff_show_like_box' ] = true;
1538 // update_option( 'cff_style_settings', $options );
1539 // }
1540 // register_activation_hook( __FILE__, 'cff_activate' );
1541 //Uninstall
1542 function cff_uninstall()
1543 {
1544 if ( ! current_user_can( 'activate_plugins' ) )
1545 return;
1546 //Settings
1547 delete_option( 'cff_access_token' );
1548 delete_option( 'cff_page_id' );
1549 delete_option( 'cff_num_show' );
1550 delete_option( 'cff_post_limit' );
1551 delete_option( 'cff_show_others' );
1552 delete_option('cff_cache_time');
1553 delete_option('cff_cache_time_unit');
1554 delete_option( 'cff_locale' );
1555 //Style & Layout
1556 delete_option( 'cff_title_length' );
1557 delete_option( 'cff_body_length' );
1558 delete_option('cff_style_settings');
1559 }
1560 register_uninstall_hook( __FILE__, 'cff_uninstall' );
1561 add_action( 'wp_head', 'cff_custom_css' );
1562 function cff_custom_css() {
1563 $options = get_option('cff_style_settings');
1564 isset($options[ 'cff_custom_css' ]) ? $cff_custom_css = $options[ 'cff_custom_css' ] : $cff_custom_css = '';
1565
1566 if( !empty($cff_custom_css) ) echo "\r\n";
1567 if( !empty($cff_custom_css) ) echo '<!-- Custom Facebook Feed Custom CSS -->';
1568 if( !empty($cff_custom_css) ) echo "\r\n";
1569 if( !empty($cff_custom_css) ) echo '<style type="text/css">';
1570 if( !empty($cff_custom_css) ) echo "\r\n";
1571 if( !empty($cff_custom_css) ) echo stripslashes($cff_custom_css);
1572 if( !empty($cff_custom_css) ) echo "\r\n";
1573 if( !empty($cff_custom_css) ) echo '</style>';
1574 if( !empty($cff_custom_css) ) echo "\r\n";
1575 }
1576 add_action( 'wp_footer', 'cff_js' );
1577 function cff_js() {
1578 $options = get_option('cff_style_settings');
1579 $cff_custom_js = isset($options[ 'cff_custom_js' ]) ? $options[ 'cff_custom_js' ] : '';
1580
1581 if( !empty($cff_custom_js) ) echo "\r\n";
1582 if( !empty($cff_custom_js) ) echo '<!-- Custom Facebook Feed JS -->';
1583 if( !empty($cff_custom_js) ) echo "\r\n";
1584 if( !empty($cff_custom_js) ) echo '<script type="text/javascript">';
1585 if( !empty($cff_custom_js) ) echo "\r\n";
1586 if( !empty($cff_custom_js) ) echo "jQuery( document ).ready(function($) {";
1587 if( !empty($cff_custom_js) ) echo "\r\n";
1588 if( !empty($cff_custom_js) ) echo stripslashes($cff_custom_js);
1589 if( !empty($cff_custom_js) ) echo "\r\n";
1590 if( !empty($cff_custom_js) ) echo "});";
1591 if( !empty($cff_custom_js) ) echo "\r\n";
1592 if( !empty($cff_custom_js) ) echo '</script>';
1593 if( !empty($cff_custom_js) ) echo "\r\n";
1594 }
1595
1596
1597
1598 //AUTOLINK
1599 $GLOBALS['autolink_options'] = array(
1600
1601 # Should http:// be visibly stripped from the front
1602 # of URLs?
1603 'strip_protocols' => true,
1604
1605 );
1606
1607 ####################################################################
1608
1609 function cff_autolink($text, $link_color='', $span_tag = false, $limit=100, $tagfill='class="cff-break-word"', $auto_title = true){
1610
1611 $text = cff_autolink_do($text, '![a-z][a-z-]+://!i', $limit, $tagfill, $auto_title, $span_tag, $link_color);
1612 $text = cff_autolink_do($text, '!(mailto|skype):!i', $limit, $tagfill, $auto_title, $span_tag, $link_color);
1613 $text = cff_autolink_do($text, '!www\\.!i', $limit, $tagfill, $auto_title, 'http://', $span_tag, $link_color);
1614 return $text;
1615 }
1616
1617 ####################################################################
1618
1619 function cff_autolink_do($text, $sub, $limit, $tagfill, $auto_title, $span_tag, $link_color, $force_prefix=null){
1620
1621 $text_l = StrToLower($text);
1622 $cursor = 0;
1623 $loop = 1;
1624 $buffer = '';
1625
1626 while (($cursor < strlen($text)) && $loop){
1627
1628 $ok = 1;
1629 $matched = preg_match($sub, $text_l, $m, PREG_OFFSET_CAPTURE, $cursor);
1630
1631 if (!$matched){
1632
1633 $loop = 0;
1634 $ok = 0;
1635
1636 }else{
1637
1638 $pos = $m[0][1];
1639 $sub_len = strlen($m[0][0]);
1640
1641 $pre_hit = substr($text, $cursor, $pos-$cursor);
1642 $hit = substr($text, $pos, $sub_len);
1643 $pre = substr($text, 0, $pos);
1644 $post = substr($text, $pos + $sub_len);
1645
1646 $fail_text = $pre_hit.$hit;
1647 $fail_len = strlen($fail_text);
1648
1649 #
1650 # substring found - first check to see if we're inside a link tag already...
1651 #
1652
1653 $bits = preg_split("!</a>!i", $pre);
1654 $last_bit = array_pop($bits);
1655 if (preg_match("!<a\s!i", $last_bit)){
1656
1657 #echo "fail 1 at $cursor<br />\n";
1658
1659 $ok = 0;
1660 $cursor += $fail_len;
1661 $buffer .= $fail_text;
1662 }
1663 }
1664
1665 #
1666 # looks like a nice spot to autolink from - check the pre
1667 # to see if there was whitespace before this match
1668 #
1669
1670 if ($ok){
1671
1672 if ($pre){
1673 if (!preg_match('![\s\(\[\{>]$!s', $pre)){
1674
1675 #echo "fail 2 at $cursor ($pre)<br />\n";
1676
1677 $ok = 0;
1678 $cursor += $fail_len;
1679 $buffer .= $fail_text;
1680 }
1681 }
1682 }
1683
1684 #
1685 # we want to autolink here - find the extent of the url
1686 #
1687
1688 if ($ok){
1689 if (preg_match('/^([a-z0-9\-\.\/\-_%~!?=,:;&+*#@\(\)\$]+)/i', $post, $matches)){
1690
1691 $url = $hit.$matches[1];
1692
1693 $cursor += strlen($url) + strlen($pre_hit);
1694 $buffer .= $pre_hit;
1695
1696 $url = html_entity_decode($url);
1697
1698
1699 #
1700 # remove trailing punctuation from url
1701 #
1702
1703 while (preg_match('|[.,!;:?]$|', $url)){
1704 $url = substr($url, 0, strlen($url)-1);
1705 $cursor--;
1706 }
1707 foreach (array('()', '[]', '{}') as $pair){
1708 $o = substr($pair, 0, 1);
1709 $c = substr($pair, 1, 1);
1710 if (preg_match("!^(\\$c|^)[^\\$o]+\\$c$!", $url)){
1711 $url = substr($url, 0, strlen($url)-1);
1712 $cursor--;
1713 }
1714 }
1715
1716
1717 #
1718 # nice-i-fy url here
1719 #
1720
1721 $link_url = $url;
1722 $display_url = $url;
1723
1724 if ($force_prefix) $link_url = $force_prefix.$link_url;
1725
1726 if ($GLOBALS['autolink_options']['strip_protocols']){
1727 if (preg_match('!^(http|https)://!i', $display_url, $m)){
1728
1729 $display_url = substr($display_url, strlen($m[1])+3);
1730 }
1731 }
1732
1733 $display_url = cff_autolink_label($display_url, $limit);
1734
1735
1736 #
1737 # add the url
1738 #
1739
1740 if ($display_url != $link_url && !preg_match('@title=@msi',$tagfill) && $auto_title) {
1741
1742 $display_quoted = preg_quote($display_url, '!');
1743
1744 if (!preg_match("!^(http|https)://{$display_quoted}$!i", $link_url)){
1745
1746 $tagfill .= ' title="'.$link_url.'"';
1747 }
1748 }
1749
1750 $link_url_enc = HtmlSpecialChars($link_url);
1751 $display_url_enc = HtmlSpecialChars($display_url);
1752
1753 if($span_tag == true){
1754 $buffer .= "<span $tagfill>{$display_url_enc}</span>";
1755 } else {
1756 $buffer .= "<a target='_blank' style='color: #".$link_color."' href=\"{$link_url_enc}\"$tagfill>{$display_url_enc}</a>";
1757 }
1758
1759
1760 }else{
1761 #echo "fail 3 at $cursor<br />\n";
1762
1763 $ok = 0;
1764 $cursor += $fail_len;
1765 $buffer .= $fail_text;
1766 }
1767 }
1768
1769 }
1770
1771 #
1772 # add everything from the cursor to the end onto the buffer.
1773 #
1774
1775 $buffer .= substr($text, $cursor);
1776
1777 return $buffer;
1778 }
1779
1780 ####################################################################
1781
1782 function cff_autolink_label($text, $limit){
1783
1784 if (!$limit){ return $text; }
1785
1786 if (strlen($text) > $limit){
1787 return substr($text, 0, $limit-3).'...';
1788 }
1789
1790 return $text;
1791 }
1792
1793 ####################################################################
1794
1795 function cff_autolink_email($text, $tagfill=''){
1796
1797 $atom = '[^()<>@,;:\\\\".\\[\\]\\x00-\\x20\\x7f]+'; # from RFC822
1798
1799 #die($atom);
1800
1801 $text_l = StrToLower($text);
1802 $cursor = 0;
1803 $loop = 1;
1804 $buffer = '';
1805
1806 while(($cursor < strlen($text)) && $loop){
1807
1808 #
1809 # find an '@' symbol
1810 #
1811
1812 $ok = 1;
1813 $pos = strpos($text_l, '@', $cursor);
1814
1815 if ($pos === false){
1816
1817 $loop = 0;
1818 $ok = 0;
1819
1820 }else{
1821
1822 $pre = substr($text, $cursor, $pos-$cursor);
1823 $hit = substr($text, $pos, 1);
1824 $post = substr($text, $pos + 1);
1825
1826 $fail_text = $pre.$hit;
1827 $fail_len = strlen($fail_text);
1828
1829 #die("$pre::$hit::$post::$fail_text");
1830
1831 #
1832 # substring found - first check to see if we're inside a link tag already...
1833 #
1834
1835 $bits = preg_split("!</a>!i", $pre);
1836 $last_bit = array_pop($bits);
1837 if (preg_match("!<a\s!i", $last_bit)){
1838
1839 #echo "fail 1 at $cursor<br />\n";
1840
1841 $ok = 0;
1842 $cursor += $fail_len;
1843 $buffer .= $fail_text;
1844 }
1845 }
1846
1847 #
1848 # check backwards
1849 #
1850
1851 if ($ok){
1852 if (preg_match("!($atom(\.$atom)*)\$!", $pre, $matches)){
1853
1854 # move matched part of address into $hit
1855
1856 $len = strlen($matches[1]);
1857 $plen = strlen($pre);
1858
1859 $hit = substr($pre, $plen-$len).$hit;
1860 $pre = substr($pre, 0, $plen-$len);
1861
1862 }else{
1863
1864 #echo "fail 2 at $cursor ($pre)<br />\n";
1865
1866 $ok = 0;
1867 $cursor += $fail_len;
1868 $buffer .= $fail_text;
1869 }
1870 }
1871
1872 #
1873 # check forwards
1874 #
1875
1876 if ($ok){
1877 if (preg_match("!^($atom(\.$atom)*)!", $post, $matches)){
1878
1879 # move matched part of address into $hit
1880
1881 $len = strlen($matches[1]);
1882
1883 $hit .= substr($post, 0, $len);
1884 $post = substr($post, $len);
1885
1886 }else{
1887 #echo "fail 3 at $cursor ($post)<br />\n";
1888
1889 $ok = 0;
1890 $cursor += $fail_len;
1891 $buffer .= $fail_text;
1892 }
1893 }
1894
1895 #
1896 # commit
1897 #
1898
1899 if ($ok) {
1900
1901 $cursor += strlen($pre) + strlen($hit);
1902 $buffer .= $pre;
1903 $buffer .= "<a href=\"mailto:$hit\"$tagfill>$hit</a>";
1904
1905 }
1906
1907 }
1908
1909 #
1910 # add everything from the cursor to the end onto the buffer.
1911 #
1912
1913 $buffer .= substr($text, $cursor);
1914
1915 return $buffer;
1916 }
1917
1918 ####################################################################
1919
1920
1921 //Comment out the line below to view errors
1922 // error_reporting(0);
1923 ?>