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