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