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