PluginProbe ʕ •ᴥ•ʔ
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress / 2.12.1
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress v2.12.1
4.8.1 trunk 1.0 1.1 1.12.1 1.2.3 1.2.4 1.2.5 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5 1.5.1 1.5.2 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.5.1 1.6.6 1.6.6.1 1.6.6.2 1.6.6.3 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.9.0 1.9.1 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.8.1 1.9.9 1.9.9.1 1.9.9.2 1.9.9.3 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.10 2.11 2.11.1 2.12 2.12.1 2.12.2 2.12.3 2.12.4 2.13 2.14 2.14.1 2.15 2.15.1 2.16 2.16.1 2.17 2.17.1 2.18 2.18.1 2.18.2 2.18.3 2.19 2.19.1 2.19.2 2.19.3 2.2 2.2.1 2.3 2.3.1 2.3.10 2.3.2 2.3.3 2.3.4 2.3.6 2.3.7 2.3.8 2.3.9 2.4 2.4.1 2.4.1.1 2.4.1.2 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5 2.5.1 2.5.2 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.7 2.7.1 2.7.2 2.8 2.9 2.9.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.7.5 4.7.6 4.7.7
custom-facebook-feed / custom-facebook-feed.php
custom-facebook-feed Last commit date
css 6 years ago fonts 8 years ago img 6 years ago js 6 years ago README.txt 6 years ago custom-facebook-feed-admin.php 6 years ago custom-facebook-feed.php 6 years ago gpl-2.0.txt 13 years ago
custom-facebook-feed.php
2867 lines
1 <?php
2 /*
3 Plugin Name: Smash Balloon Custom Facebook Feed
4 Plugin URI: https://smashballoon.com/custom-facebook-feed
5 Description: Add completely customizable Facebook feeds to your WordPress site
6 Version: 2.12.1
7 Author: Smash Balloon
8 Author URI: http://smashballoon.com/
9 License: GPLv2 or later
10 Text Domain: custom-facebook-feed
11 */
12 /*
13 Copyright 2019 Smash Balloon LLC (email : hey@smashballoon.com)
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 */
26
27 define('CFFVER', '2.12.1');
28
29 // Db version.
30 if ( ! defined( 'CFF_DBVERSION' ) ) {
31 define( 'CFF_DBVERSION', '1.0' );
32 }
33
34 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
35 //Include admin
36 include dirname( __FILE__ ) .'/custom-facebook-feed-admin.php';
37
38 function cff_check_for_db_updates() {
39 $db_ver = get_option( 'cff_db_version', 0 );
40 if ( (float) $db_ver < 1.0 ) {
41 global $wp_roles;
42 $wp_roles->add_cap( 'administrator', 'manage_custom_facebook_feed_options' );
43 $cff_statuses_option = get_option( 'cff_statuses', array() );
44 if ( ! isset( $cff_statuses_option['first_install'] ) ) {
45 $options_set = get_option( 'cff_page_id', false );
46 if ( $options_set ) {
47 $cff_statuses_option['first_install'] = 'from_update';
48 } else {
49 $cff_statuses_option['first_install'] = time();
50 }
51 $cff_rating_notice_option = get_option( 'cff_rating_notice', false );
52 if ( $cff_rating_notice_option === 'dismissed' ) {
53 $cff_statuses_option['rating_notice_dismissed'] = time();
54 }
55 $cff_rating_notice_waiting = get_transient( 'custom_facebook_rating_notice_waiting' );
56 if ( $cff_rating_notice_waiting === false
57 && $cff_rating_notice_option === false ) {
58 $time = 2 * WEEK_IN_SECONDS;
59 set_transient( 'custom_facebook_rating_notice_waiting', 'waiting', $time );
60 update_option( 'cff_rating_notice', 'pending', false );
61 }
62 update_option( 'cff_statuses', $cff_statuses_option, false );
63 }
64 update_option( 'cff_db_version', CFF_DBVERSION );
65 }
66 }
67 add_action( 'wp_loaded', 'cff_check_for_db_updates' );
68
69
70 // Add shortcodes
71 add_shortcode('custom-facebook-feed', 'display_cff');
72 function display_cff($atts) {
73
74 //Style options
75 $options = get_option('cff_style_settings');
76 //Create the types string to set as shortcode default
77 $include_string = '';
78 if($options[ 'cff_show_author' ]) $include_string .= 'author,';
79 if($options[ 'cff_show_text' ]) $include_string .= 'text,';
80 if($options[ 'cff_show_desc' ]) $include_string .= 'desc,';
81 if($options[ 'cff_show_shared_links' ]) $include_string .= 'sharedlinks,';
82 if($options[ 'cff_show_date' ]) $include_string .= 'date,';
83 if($options[ 'cff_show_media' ]) $include_string .= 'media,';
84 if( isset($options[ 'cff_show_media_link' ]) ){ //If not set yet then show link by default
85 if($options[ 'cff_show_media_link' ]) $include_string .= 'medialink,';
86 } else {
87 $include_string .= 'medialink,';
88 }
89 if($options[ 'cff_show_event_title' ]) $include_string .= 'eventtitle,';
90 if($options[ 'cff_show_event_details' ]) $include_string .= 'eventdetails,';
91 if($options[ 'cff_show_meta' ]) $include_string .= 'social,';
92 if($options[ 'cff_show_link' ]) $include_string .= 'link,';
93 if($options[ 'cff_show_like_box' ]) $include_string .= 'likebox,';
94 //Pass in shortcode attrbutes
95 $atts = shortcode_atts(
96 array(
97 'accesstoken' => trim( get_option('cff_access_token') ),
98 'id' => get_option('cff_page_id'),
99 'pagetype' => get_option('cff_page_type'),
100 'num' => get_option('cff_num_show'),
101 'limit' => get_option('cff_post_limit'),
102 'others' => '',
103 'showpostsby' => get_option('cff_show_others'),
104 'cachetime' => get_option('cff_cache_time'),
105 'cacheunit' => get_option('cff_cache_time_unit'),
106 'locale' => get_option('cff_locale'),
107 'ajax' => get_option('cff_ajax'),
108 'offset' => '',
109 'account' => '',
110
111 //General
112 'width' => isset($options[ 'cff_feed_width' ]) ? $options[ 'cff_feed_width' ] : '',
113 'widthresp' => isset($options[ 'cff_feed_width_resp' ]) ? $options[ 'cff_feed_width_resp' ] : '',
114 'height' => isset($options[ 'cff_feed_height' ]) ? $options[ 'cff_feed_height' ] : '',
115 'padding' => isset($options[ 'cff_feed_padding' ]) ? $options[ 'cff_feed_padding' ] : '',
116 'bgcolor' => isset($options[ 'cff_bg_color' ]) ? $options[ 'cff_bg_color' ] : '',
117 'showauthor' => '',
118 'showauthornew' => isset($options[ 'cff_show_author' ]) ? $options[ 'cff_show_author' ] : '',
119 'class' => isset($options[ 'cff_class' ]) ? $options[ 'cff_class' ] : '',
120 'layout' => isset($options[ 'cff_preset_layout' ]) ? $options[ 'cff_preset_layout' ] : '',
121 'include' => $include_string,
122 'exclude' => '',
123
124 //Cols
125 'cols' => isset($options[ 'cff_cols' ]) ? $options[ 'cff_cols' ] : '',
126 'colsmobile' => isset($options[ 'cff_cols_mobile' ]) ? $options[ 'cff_cols_mobile' ] : '',
127 'colsjs' => true,
128
129 //Post Style
130 'poststyle' => isset($options[ 'cff_post_style' ]) ? $options[ 'cff_post_style' ] : '',
131 'postbgcolor' => isset($options[ 'cff_post_bg_color' ]) ? $options[ 'cff_post_bg_color' ] : '',
132 'postcorners' => isset($options[ 'cff_post_rounded' ]) ? $options[ 'cff_post_rounded' ] : '',
133 'boxshadow' => isset($options[ 'cff_box_shadow' ]) ? $options[ 'cff_box_shadow' ] : '',
134
135 //Typography
136 'textformat' => isset($options[ 'cff_title_format' ]) ? $options[ 'cff_title_format' ] : '',
137 'textsize' => isset($options[ 'cff_title_size' ]) ? $options[ 'cff_title_size' ] : '',
138 'textweight' => isset($options[ 'cff_title_weight' ]) ? $options[ 'cff_title_weight' ] : '',
139 'textcolor' => isset($options[ 'cff_title_color' ]) ? $options[ 'cff_title_color' ] : '',
140 'textlinkcolor' => isset($options[ 'cff_posttext_link_color' ]) ? $options[ 'cff_posttext_link_color' ] : '',
141 'textlink' => isset($options[ 'cff_title_link' ]) ? $options[ 'cff_title_link' ] : '',
142 'posttags' => isset($options[ 'cff_post_tags' ]) ? $options[ 'cff_post_tags' ] : '',
143 'linkhashtags' => isset($options[ 'cff_link_hashtags' ]) ? $options[ 'cff_link_hashtags' ] : '',
144
145 //Description
146 'descsize' => isset($options[ 'cff_body_size' ]) ? $options[ 'cff_body_size' ] : '',
147 'descweight' => isset($options[ 'cff_body_weight' ]) ? $options[ 'cff_body_weight' ] : '',
148 'desccolor' => isset($options[ 'cff_body_color' ]) ? $options[ 'cff_body_color' ] : '',
149 'linktitleformat' => isset($options[ 'cff_link_title_format' ]) ? $options[ 'cff_link_title_format' ] : '',
150 'linktitlesize' => isset($options[ 'cff_link_title_size' ]) ? $options[ 'cff_link_title_size' ] : '',
151 'linkdescsize' => isset($options[ 'cff_link_desc_size' ]) ? $options[ 'cff_link_desc_size' ] : '',
152 'linkurlsize' => isset($options[ 'cff_link_url_size' ]) ? $options[ 'cff_link_url_size' ] : '',
153 'linkdesccolor' => isset($options[ 'cff_link_desc_color' ]) ? $options[ 'cff_link_desc_color' ] : '',
154 'linktitlecolor' => isset($options[ 'cff_link_title_color' ]) ? $options[ 'cff_link_title_color' ] : '',
155 'linkurlcolor' => isset($options[ 'cff_link_url_color' ]) ? $options[ 'cff_link_url_color' ] : '',
156 'linkbgcolor' => isset($options[ 'cff_link_bg_color' ]) ? $options[ 'cff_link_bg_color' ] : '',
157 'linkbordercolor' => isset($options[ 'cff_link_border_color' ]) ? $options[ 'cff_link_border_color' ] : '',
158 'disablelinkbox' => isset($options[ 'cff_disable_link_box' ]) ? $options[ 'cff_disable_link_box' ] : '',
159
160 //Author
161 'authorsize' => isset($options[ 'cff_author_size' ]) ? $options[ 'cff_author_size' ] : '',
162 'authorcolor' => isset($options[ 'cff_author_color' ]) ? $options[ 'cff_author_color' ] : '',
163
164 //Event title
165 'eventtitleformat' => isset($options[ 'cff_event_title_format' ]) ? $options[ 'cff_event_title_format' ] : '',
166 'eventtitlesize' => isset($options[ 'cff_event_title_size' ]) ? $options[ 'cff_event_title_size' ] : '',
167 'eventtitleweight' => isset($options[ 'cff_event_title_weight' ]) ? $options[ 'cff_event_title_weight' ] : '',
168 'eventtitlecolor' => isset($options[ 'cff_event_title_color' ]) ? $options[ 'cff_event_title_color' ] : '',
169 'eventtitlelink' => isset($options[ 'cff_event_title_link' ]) ? $options[ 'cff_event_title_link' ] : '',
170 //Event date
171 'eventdatesize' => isset($options[ 'cff_event_date_size' ]) ? $options[ 'cff_event_date_size' ] : '',
172 'eventdateweight' => isset($options[ 'cff_event_date_weight' ]) ? $options[ 'cff_event_date_weight' ] : '',
173 'eventdatecolor' => isset($options[ 'cff_event_date_color' ]) ? $options[ 'cff_event_date_color' ] : '',
174 'eventdatepos' => isset($options[ 'cff_event_date_position' ]) ? $options[ 'cff_event_date_position' ] : '',
175 'eventdateformat' => isset($options[ 'cff_event_date_formatting' ]) ? $options[ 'cff_event_date_formatting' ] : '',
176 'eventdatecustom' => isset($options[ 'cff_event_date_custom' ]) ? $options[ 'cff_event_date_custom' ] : '',
177 //Event details
178 'eventdetailssize' => isset($options[ 'cff_event_details_size' ]) ? $options[ 'cff_event_details_size' ] : '',
179 'eventdetailsweight' => isset($options[ 'cff_event_details_weight' ]) ? $options[ 'cff_event_details_weight' ] : '',
180 'eventdetailscolor' => isset($options[ 'cff_event_details_color' ]) ? $options[ 'cff_event_details_color' ] : '',
181 'eventlinkcolor' => isset($options[ 'cff_event_link_color' ]) ? $options[ 'cff_event_link_color' ] : '',
182 //Date
183 'datepos' => isset($options[ 'cff_date_position' ]) ? $options[ 'cff_date_position' ] : '',
184 'datesize' => isset($options[ 'cff_date_size' ]) ? $options[ 'cff_date_size' ] : '',
185 'dateweight' => isset($options[ 'cff_date_weight' ]) ? $options[ 'cff_date_weight' ] : '',
186 'datecolor' => isset($options[ 'cff_date_color' ]) ? $options[ 'cff_date_color' ] : '',
187 'dateformat' => isset($options[ 'cff_date_formatting' ]) ? $options[ 'cff_date_formatting' ] : '',
188 'datecustom' => isset($options[ 'cff_date_custom' ]) ? $options[ 'cff_date_custom' ] : '',
189 'timezone' => isset($options[ 'cff_timezone' ]) ? $options[ 'cff_timezone' ] : 'America/Chicago',
190
191 //Link to Facebook
192 'linksize' => isset($options[ 'cff_link_size' ]) ? $options[ 'cff_link_size' ] : '',
193 'linkweight' => isset($options[ 'cff_link_weight' ]) ? $options[ 'cff_link_weight' ] : '',
194 'linkcolor' => isset($options[ 'cff_link_color' ]) ? $options[ 'cff_link_color' ] : '',
195 'viewlinktext' => isset($options[ 'cff_view_link_text' ]) ? $options[ 'cff_view_link_text' ] : '',
196 'linktotimeline' => isset($options[ 'cff_link_to_timeline' ]) ? $options[ 'cff_link_to_timeline' ] : '',
197 //Social
198 'iconstyle' => isset($options[ 'cff_icon_style' ]) ? $options[ 'cff_icon_style' ] : '',
199 'socialtextcolor' => isset($options[ 'cff_meta_text_color' ]) ? $options[ 'cff_meta_text_color' ] : '',
200 'socialbgcolor' => isset($options[ 'cff_meta_bg_color' ]) ? $options[ 'cff_meta_bg_color' ] : '',
201 //Misc
202 'textlength' => get_option('cff_title_length'),
203 'desclength' => get_option('cff_body_length'),
204 'likeboxpos' => isset($options[ 'cff_like_box_position' ]) ? $options[ 'cff_like_box_position' ] : '',
205 'likeboxoutside' => isset($options[ 'cff_like_box_outside' ]) ? $options[ 'cff_like_box_outside' ] : '',
206 'likeboxcolor' => isset($options[ 'cff_likebox_bg_color' ]) ? $options[ 'cff_likebox_bg_color' ] : '',
207 'likeboxtextcolor' => isset($options[ 'cff_like_box_text_color' ]) ? $options[ 'cff_like_box_text_color' ] : '',
208 'likeboxwidth' => isset($options[ 'cff_likebox_width' ]) ? $options[ 'cff_likebox_width' ] : '',
209 'likeboxheight' => isset($options[ 'cff_likebox_height' ]) ? $options[ 'cff_likebox_height' ] : '',
210 'likeboxfaces' => isset($options[ 'cff_like_box_faces' ]) ? $options[ 'cff_like_box_faces' ] : '',
211 'likeboxborder' => isset($options[ 'cff_like_box_border' ]) ? $options[ 'cff_like_box_border' ] : '',
212 'likeboxcover' => isset($options[ 'cff_like_box_cover' ]) ? $options[ 'cff_like_box_cover' ] : '',
213 'likeboxsmallheader' => isset($options[ 'cff_like_box_small_header' ]) ? $options[ 'cff_like_box_small_header' ] : '',
214 'likeboxhidebtn' => isset($options[ 'cff_like_box_hide_cta' ]) ? $options[ 'cff_like_box_hide_cta' ] : '',
215
216 'credit' => isset($options[ 'cff_show_credit' ]) ? $options[ 'cff_show_credit' ] : '',
217 'nofollow' => 'true',
218 'disablestyles' => isset($options[ 'cff_disable_styles' ]) ? $options[ 'cff_disable_styles' ] : '',
219 'textissue' => isset($options[ 'cff_format_issue' ]) ? $options[ 'cff_format_issue' ] : '',
220 'restrictedpage' => isset($options[ 'cff_restricted_page' ]) ? $options[ 'cff_restricted_page' ] : '',
221
222 //Page Header
223 'showheader' => isset($options[ 'cff_show_header' ]) ? $options[ 'cff_show_header' ] : '',
224 'headeroutside' => isset($options[ 'cff_header_outside' ]) ? $options[ 'cff_header_outside' ] : '',
225 'headertext' => isset($options[ 'cff_header_text' ]) ? $options[ 'cff_header_text' ] : '',
226 'headerbg' => isset($options[ 'cff_header_bg_color' ]) ? $options[ 'cff_header_bg_color' ] : '',
227 'headerpadding' => isset($options[ 'cff_header_padding' ]) ? $options[ 'cff_header_padding' ] : '',
228 'headertextsize' => isset($options[ 'cff_header_text_size' ]) ? $options[ 'cff_header_text_size' ] : '',
229 'headertextweight' => isset($options[ 'cff_header_text_weight' ]) ? $options[ 'cff_header_text_weight' ] : '',
230 'headertextcolor' => isset($options[ 'cff_header_text_color' ]) ? $options[ 'cff_header_text_color' ] : '',
231 'headericon' => isset($options[ 'cff_header_icon' ]) ? $options[ 'cff_header_icon' ] : '',
232 'headericoncolor' => isset($options[ 'cff_header_icon_color' ]) ? $options[ 'cff_header_icon_color' ] : '',
233 'headericonsize' => isset($options[ 'cff_header_icon_size' ]) ? $options[ 'cff_header_icon_size' ] : '',
234
235 'videoheight' => isset($options[ 'cff_video_height' ]) ? $options[ 'cff_video_height' ] : '',
236 'videoaction' => isset($options[ 'cff_video_action' ]) ? $options[ 'cff_video_action' ] : '',
237 'sepcolor' => isset($options[ 'cff_sep_color' ]) ? $options[ 'cff_sep_color' ] : '',
238 'sepsize' => isset($options[ 'cff_sep_size' ]) ? $options[ 'cff_sep_size' ] : '',
239
240 //Translate
241 'seemoretext' => isset( $options[ 'cff_see_more_text' ] ) ? stripslashes( esc_attr( $options[ 'cff_see_more_text' ] ) ) : '',
242 'seelesstext' => isset( $options[ 'cff_see_less_text' ] ) ? stripslashes( esc_attr( $options[ 'cff_see_less_text' ] ) ) : '',
243 'photostext' => isset( $options[ 'cff_translate_photos_text' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_photos_text' ] ) ) : '',
244 'phototext' => isset( $options[ 'cff_translate_photo_text' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_photo_text' ] ) ) : '',
245 'videotext' => isset( $options[ 'cff_translate_video_text' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_video_text' ] ) ) : '',
246
247 'learnmoretext' => isset( $options[ 'cff_translate_learn_more_text' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_learn_more_text' ] ) ) : '',
248 'shopnowtext' => isset( $options[ 'cff_translate_shop_now_text' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_shop_now_text' ] ) ) : '',
249 'messagepage' => isset( $options[ 'cff_translate_message_page_text' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_message_page_text' ] ) ) : '',
250
251 'facebooklinktext' => isset( $options[ 'cff_facebook_link_text' ] ) ? stripslashes( esc_attr( $options[ 'cff_facebook_link_text' ] ) ) : '',
252 'sharelinktext' => isset( $options[ 'cff_facebook_share_text' ] ) ? stripslashes( esc_attr( $options[ 'cff_facebook_share_text' ] ) ) : '',
253 'showfacebooklink' => isset($options[ 'cff_show_facebook_link' ]) ? $options[ 'cff_show_facebook_link' ] : '',
254 'showsharelink' => isset($options[ 'cff_show_facebook_share' ]) ? $options[ 'cff_show_facebook_share' ] : '',
255
256 'secondtext' => isset( $options[ 'cff_translate_second' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_second' ] ) ) : 'second',
257 'secondstext' => isset( $options[ 'cff_translate_seconds' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_seconds' ] ) ) : 'seconds',
258 'minutetext' => isset( $options[ 'cff_translate_minute' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_minute' ] ) ) : 'minute',
259 'minutestext' => isset( $options[ 'cff_translate_minutes' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_minutes' ] ) ) : 'minutes',
260 'hourtext' => isset( $options[ 'cff_translate_hour' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_hour' ] ) ) : 'hour',
261 'hourstext' => isset( $options[ 'cff_translate_hours' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_hours' ] ) ) : 'hours',
262 'daytext' => isset( $options[ 'cff_translate_day' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_day' ] ) ) : 'day',
263 'daystext' => isset( $options[ 'cff_translate_days' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_days' ] ) ) : 'days',
264 'weektext' => isset( $options[ 'cff_translate_week' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_week' ] ) ) : 'week',
265 'weekstext' => isset( $options[ 'cff_translate_weeks' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_weeks' ] ) ) : 'weeks',
266 'monthtext' => isset( $options[ 'cff_translate_month' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_month' ] ) ) : 'month',
267 'monthstext' => isset( $options[ 'cff_translate_months' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_months' ] ) ) : 'months',
268 'yeartext' => isset( $options[ 'cff_translate_year' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_year' ] ) ) : 'year',
269 'yearstext' => isset( $options[ 'cff_translate_years' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_years' ] ) ) : 'years',
270 'agotext' => isset( $options[ 'cff_translate_ago' ] ) ? stripslashes( esc_attr( $options[ 'cff_translate_ago' ] ) ) : 'ago'
271
272 ), $atts);
273
274 /********** GENERAL **********/
275 $cff_page_type = $atts[ 'pagetype' ];
276 ($cff_page_type == 'group') ? $cff_is_group = true : $cff_is_group = false;
277
278 $cff_feed_width = $atts[ 'width' ];
279 if ( is_numeric(substr($cff_feed_width, -1, 1)) ) $cff_feed_width = $cff_feed_width . 'px';
280
281 //Set to be 100% width on mobile?
282 $cff_feed_width_resp = $atts[ 'widthresp' ];
283 ( $cff_feed_width_resp == 'on' || $cff_feed_width_resp == 'true' || $cff_feed_width_resp == true ) ? $cff_feed_width_resp = true : $cff_feed_width_resp = false;
284 if( $atts[ 'widthresp' ] == 'false' ) $cff_feed_width_resp = false;
285
286 $cff_feed_height = $atts[ 'height' ];
287 if ( is_numeric(substr($cff_feed_height, -1, 1)) ) $cff_feed_height = $cff_feed_height . 'px';
288
289 $cff_feed_padding = $atts[ 'padding' ];
290 if ( is_numeric(substr($cff_feed_padding, -1, 1)) ) $cff_feed_padding = $cff_feed_padding . 'px';
291
292 $cff_bg_color = $atts[ 'bgcolor' ];
293 $cff_show_author = $atts[ 'showauthornew' ];
294 $cff_cache_time = $atts[ 'cachetime' ];
295 $cff_locale = $atts[ 'locale' ];
296 if ( empty($cff_locale) || !isset($cff_locale) || $cff_locale == '' ) $cff_locale = 'en_US';
297 if (!isset($cff_cache_time)) $cff_cache_time = '0';
298 $cff_cache_time_unit = $atts[ 'cacheunit' ];
299
300 if($cff_cache_time == 'nocaching') $cff_cache_time = 0;
301
302 $cff_class = $atts['class'];
303 //Compile feed styles
304 $cff_feed_styles = '';
305 if( !empty($cff_feed_width) || !empty($cff_feed_height) || !empty($cff_feed_padding) || (!empty($cff_bg_color) && $cff_bg_color !== '#') ) $cff_feed_styles = 'style="';
306 if ( !empty($cff_feed_width) ) $cff_feed_styles .= 'width:' . $cff_feed_width . '; ';
307 if ( !empty($cff_feed_height) ) $cff_feed_styles .= 'height:' . $cff_feed_height . '; ';
308 if ( !empty($cff_feed_padding) ) $cff_feed_styles .= 'padding:' . $cff_feed_padding . '; ';
309 if ( !empty($cff_bg_color) && $cff_bg_color !== '#' ) $cff_feed_styles .= 'background-color:#' . str_replace('#', '', $cff_bg_color) . '; ';
310 if( !empty($cff_feed_width) || !empty($cff_feed_height) || !empty($cff_feed_padding) || (!empty($cff_bg_color) && $cff_bg_color !== '#') ) $cff_feed_styles .= '"';
311 //Like box
312 $cff_like_box_position = $atts[ 'likeboxpos' ];
313 $cff_like_box_outside = $atts[ 'likeboxoutside' ];
314 //Open links in new window?
315 $target = 'target="_blank"';
316 /********** POST TYPES **********/
317 $cff_show_links_type = true;
318 $cff_show_event_type = true;
319 $cff_show_video_type = true;
320 $cff_show_photos_type = true;
321 $cff_show_status_type = true;
322 $cff_show_albums_type = true;
323 $cff_events_only = false;
324 //Are we showing ONLY events?
325 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;
326 /********** LAYOUT **********/
327 $cff_includes = $atts[ 'include' ];
328 //Look for non-plural version of string in the types string in case user specifies singular in shortcode
329 $cff_show_author = false;
330 $cff_show_text = false;
331 $cff_show_desc = false;
332 $cff_show_shared_links = false;
333 $cff_show_date = false;
334 $cff_show_media = false;
335 $cff_show_media_link = false;
336 $cff_show_event_title = false;
337 $cff_show_event_details = false;
338 $cff_show_meta = false;
339 $cff_show_link = false;
340 $cff_show_like_box = false;
341 if ( stripos($cff_includes, 'author') !== false ) $cff_show_author = true;
342 if ( stripos($cff_includes, 'text') !== false ) $cff_show_text = true;
343 if ( stripos($cff_includes, 'desc') !== false ) $cff_show_desc = true;
344 if ( stripos($cff_includes, 'sharedlink') !== false ) $cff_show_shared_links = true;
345 if ( stripos($cff_includes, 'date') !== false ) $cff_show_date = true;
346 if ( stripos($cff_includes, 'media') !== false ) $cff_show_media = true;
347 if ( stripos($cff_includes, 'medialink') !== false ) $cff_show_media_link = true;
348 if ( stripos($cff_includes, 'eventtitle') !== false ) $cff_show_event_title = true;
349 if ( stripos($cff_includes, 'eventdetail') !== false ) $cff_show_event_details = true;
350 if ( stripos($cff_includes, 'social') !== false ) $cff_show_meta = true;
351 if ( stripos($cff_includes, ',link') !== false ) $cff_show_link = true; //comma used to separate it from 'sharedlinks' - which also contains 'link' string
352 if ( stripos($cff_includes, 'like') !== false ) $cff_show_like_box = true;
353
354
355 //Exclude string
356 $cff_excludes = $atts[ 'exclude' ];
357 //Look for non-plural version of string in the types string in case user specifies singular in shortcode
358 if ( stripos($cff_excludes, 'author') !== false ) $cff_show_author = false;
359 if ( stripos($cff_excludes, 'text') !== false ) $cff_show_text = false;
360 if ( stripos($cff_excludes, 'desc') !== false ) $cff_show_desc = false;
361 if ( stripos($cff_excludes, 'sharedlink') !== false ) $cff_show_shared_links = false;
362 if ( stripos($cff_excludes, 'date') !== false ) $cff_show_date = false;
363 if ( stripos($cff_excludes, 'media') !== false ) $cff_show_media = false;
364 if ( stripos($cff_excludes, 'medialink') !== false ) $cff_show_media_link = false;
365 if ( stripos($cff_excludes, 'eventtitle') !== false ) $cff_show_event_title = false;
366 if ( stripos($cff_excludes, 'eventdetail') !== false ) $cff_show_event_details = false;
367 if ( stripos($cff_excludes, 'social') !== false ) $cff_show_meta = false;
368 if ( stripos($cff_excludes, ',link') !== false ) $cff_show_link = false; //comma used to separate it from 'sharedlinks' - which also contains 'link' string
369 if ( stripos($cff_excludes, 'like') !== false ) $cff_show_like_box = false;
370
371
372 //Set free version to thumb layout by default as layout option not available on settings page
373 $cff_preset_layout = 'thumb';
374
375 //If the old shortcode option 'showauthor' is being used then apply it
376 $cff_show_author_old = $atts[ 'showauthor' ];
377 if( $cff_show_author_old == 'false' ) $cff_show_author = false;
378 if( $cff_show_author_old == 'true' ) $cff_show_author = true;
379
380
381 /********** META **********/
382 $cff_icon_style = $atts[ 'iconstyle' ];
383 $cff_meta_text_color = $atts[ 'socialtextcolor' ];
384 $cff_meta_bg_color = $atts[ 'socialbgcolor' ];
385 $cff_meta_styles = '';
386 if ( !empty($cff_meta_text_color) || ( !empty($cff_meta_bg_color) && $cff_meta_bg_color !== '#' ) ) $cff_meta_styles = 'style="';
387 if ( !empty($cff_meta_text_color) ) $cff_meta_styles .= 'color:#' . str_replace('#', '', $cff_meta_text_color) . ';';
388 if ( !empty($cff_meta_bg_color) && $cff_meta_bg_color !== '#' ) $cff_meta_styles .= 'background-color:#' . str_replace('#', '', $cff_meta_bg_color) . ';';
389 if ( !empty($cff_meta_text_color) || ( !empty($cff_meta_bg_color) && $cff_meta_bg_color !== '#' ) ) $cff_meta_styles .= '"';
390 $cff_nocomments_text = isset($options[ 'cff_nocomments_text' ]) ? $options[ 'cff_nocomments_text' ] : '';
391 $cff_hide_comments = isset($options[ 'cff_hide_comments' ]) ? $options[ 'cff_hide_comments' ] : '';
392 if (!isset($cff_nocomments_text) || empty($cff_nocomments_text)) $cff_hide_comments = true;
393 /********** TYPOGRAPHY **********/
394 //See More text
395 $cff_see_more_text = $atts[ 'seemoretext' ];
396 $cff_see_less_text = $atts[ 'seelesstext' ];
397 //See Less text
398 //Title
399 $cff_title_format = $atts[ 'textformat' ];
400 if (empty($cff_title_format)) $cff_title_format = 'p';
401 $cff_title_size = $atts[ 'textsize' ];
402 $cff_title_weight = $atts[ 'textweight' ];
403 $cff_title_color = $atts[ 'textcolor' ];
404
405 $cff_title_styles = '';
406 if( ( !empty($cff_title_size) && $cff_title_size != 'inherit' ) || ( !empty($cff_title_weight) && $cff_title_weight != 'inherit' ) || ( !empty($cff_title_color) && $cff_title_color !== '#' ) ) $cff_title_styles = 'style="';
407 if ( !empty($cff_title_size) && $cff_title_size != 'inherit' ) $cff_title_styles .= 'font-size:' . $cff_title_size . 'px; ';
408 if ( !empty($cff_title_weight) && $cff_title_weight != 'inherit' ) $cff_title_styles .= 'font-weight:' . $cff_title_weight . '; ';
409 if ( !empty($cff_title_color) && $cff_title_color !== '#' ) $cff_title_styles .= 'color:#' . str_replace('#', '', $cff_title_color) . ';';
410 if( ( !empty($cff_title_size) && $cff_title_size != 'inherit' ) || ( !empty($cff_title_weight) && $cff_title_weight != 'inherit' ) || ( !empty($cff_title_color) && $cff_title_color !== '#' ) ) $cff_title_styles .= '"';
411
412 $cff_title_link = $atts[ 'textlink' ];
413
414 $cff_posttext_link_color = str_replace('#', '', $atts['textlinkcolor']);
415
416 ( $cff_title_link == 'on' || $cff_title_link == 'true' || $cff_title_link == true ) ? $cff_title_link = true : $cff_title_link = false;
417 if( $atts[ 'textlink' ] == 'false' ) $cff_title_link = false;
418
419 //Author
420 $cff_author_size = $atts[ 'authorsize' ];
421 $cff_author_color = $atts[ 'authorcolor' ];
422
423 $cff_author_styles = '';
424 if( ( !empty($cff_author_size) && $cff_author_size != 'inherit' ) || ( !empty($cff_author_color) && $cff_author_color !== '#' ) ) $cff_author_styles = 'style="';
425 if ( !empty($cff_author_size) && $cff_author_size != 'inherit' ) $cff_author_styles .= 'font-size:' . $cff_author_size . 'px; ';
426 if ( !empty($cff_author_color) && $cff_author_color !== '#' ) $cff_author_styles .= 'color:#' . str_replace('#', '', $cff_author_color) . ';';
427 if( ( !empty($cff_author_size) && $cff_author_size != 'inherit' ) || ( !empty($cff_author_color) && $cff_author_color !== '#' ) ) $cff_author_styles .= '"';
428
429 //Description
430 $cff_body_size = $atts[ 'descsize' ];
431 $cff_body_weight = $atts[ 'descweight' ];
432 $cff_body_color = $atts[ 'desccolor' ];
433
434 $cff_body_styles = '';
435 if( ( !empty($cff_body_size) && $cff_body_size != 'inherit' ) || ( !empty($cff_body_weight) && $cff_body_weight != 'inherit' ) || ( !empty($cff_body_color) && $cff_body_color !== '#' ) ) $cff_body_styles = 'style="';
436 if ( !empty($cff_body_size) && $cff_body_size != 'inherit' ) $cff_body_styles .= 'font-size:' . $cff_body_size . 'px; ';
437 if ( !empty($cff_body_weight) && $cff_body_weight != 'inherit' ) $cff_body_styles .= 'font-weight:' . $cff_body_weight . '; ';
438 if ( !empty($cff_body_color) && $cff_body_color !== '#' ) $cff_body_styles .= 'color:#' . str_replace('#', '', $cff_body_color) . ';';
439 if( ( !empty($cff_body_size) && $cff_body_size != 'inherit' ) || ( !empty($cff_body_weight) && $cff_body_weight != 'inherit' ) || ( !empty($cff_body_color) && $cff_body_color !== '#' ) ) $cff_body_styles .= '"';
440
441 //Shared link title
442 $cff_link_title_format = $atts[ 'linktitleformat' ];
443 if (empty($cff_link_title_format)) $cff_link_title_format = 'p';
444 $cff_link_title_size = $atts[ 'linktitlesize' ];
445 $cff_link_title_color = str_replace('#', '', $atts[ 'linktitlecolor' ]);
446 $cff_link_url_color = $atts[ 'linkurlcolor' ];
447
448 $cff_link_title_styles = '';
449 if ( !empty($cff_link_title_size) && $cff_link_title_size != 'inherit' ) $cff_link_title_styles = 'style="font-size:' . $cff_link_title_size . 'px;"';
450
451 //Shared link description
452 $cff_link_desc_size = $atts[ 'linkdescsize' ];
453 $cff_link_desc_color = $atts[ 'linkdesccolor' ];
454
455 //Shared link URL
456 $cff_link_url_size = $atts[ 'linkurlsize' ];
457 $cff_link_url_color = $atts[ 'linkurlcolor' ];
458
459 //Shared link box
460 $cff_link_bg_color = $atts[ 'linkbgcolor' ];
461 $cff_link_border_color = $atts[ 'linkbordercolor' ];
462 $cff_disable_link_box = $atts['disablelinkbox'];
463 ($cff_disable_link_box == 'true' || $cff_disable_link_box == 'on') ? $cff_disable_link_box = true : $cff_disable_link_box = false;
464
465 $cff_link_box_styles = '';
466 if( !empty($cff_link_border_color) || (!empty($cff_link_bg_color) && $cff_link_bg_color !== '#') ) $cff_link_box_styles = 'style="';
467 if ( !empty($cff_link_border_color) ) $cff_link_box_styles .= 'border: 1px solid #' . str_replace('#', '', $cff_link_border_color) . '; ';
468 if ( !empty($cff_link_bg_color) && $cff_link_bg_color !== '#' ) $cff_link_box_styles .= 'background-color: #' . str_replace('#', '', $cff_link_bg_color) . ';';
469 if( !empty($cff_link_border_color) || (!empty($cff_link_bg_color) && $cff_link_bg_color !== '#') ) $cff_link_box_styles .= '"';
470
471 //Event Title
472 $cff_event_title_format = $atts[ 'eventtitleformat' ];
473 if (empty($cff_event_title_format)) $cff_event_title_format = 'p';
474 $cff_event_title_size = $atts[ 'eventtitlesize' ];
475 $cff_event_title_weight = $atts[ 'eventtitleweight' ];
476 $cff_event_title_color = $atts[ 'eventtitlecolor' ];
477
478 $cff_event_title_styles = '';
479 if( ( !empty($cff_event_title_size) && $cff_event_title_size != 'inherit' ) || ( !empty($cff_event_title_weight) && $cff_event_title_weight != 'inherit' ) || ( !empty($cff_event_title_color) && $cff_event_title_color !== '#' ) ) $cff_event_title_styles = 'style="';
480 if ( !empty($cff_event_title_size) && $cff_event_title_size != 'inherit' ) $cff_event_title_styles .= 'font-size:' . $cff_event_title_size . 'px; ';
481 if ( !empty($cff_event_title_weight) && $cff_event_title_weight != 'inherit' ) $cff_event_title_styles .= 'font-weight:' . $cff_event_title_weight . '; ';
482 if ( !empty($cff_event_title_color) && $cff_event_title_color !== '#' ) $cff_event_title_styles .= 'color:#' . str_replace('#', '', $cff_event_title_color) . ';';
483 if( ( !empty($cff_event_title_size) && $cff_event_title_size != 'inherit' ) || ( !empty($cff_event_title_weight) && $cff_event_title_weight != 'inherit' ) || ( !empty($cff_event_title_color) && $cff_event_title_color !== '#' ) ) $cff_event_title_styles .= '"';
484
485 $cff_event_title_link = $atts[ 'eventtitlelink' ];
486 ( $cff_event_title_link == 'on' || $cff_event_title_link == 'true' || $cff_event_title_link == true ) ? $cff_event_title_link = true : $cff_event_title_link = false;
487 if( $atts[ 'eventtitlelink' ] == 'false' ) $cff_event_title_link = false;
488
489 //Event Date
490 $cff_event_date_size = $atts[ 'eventdatesize' ];
491 $cff_event_date_weight = $atts[ 'eventdateweight' ];
492 $cff_event_date_color = $atts[ 'eventdatecolor' ];
493 $cff_event_date_position = $atts[ 'eventdatepos' ];
494 $cff_event_date_formatting = $atts[ 'eventdateformat' ];
495 $cff_event_date_custom = $atts[ 'eventdatecustom' ];
496
497 $cff_event_date_styles = '';
498 if( ( !empty($cff_event_date_size) && $cff_event_date_size != 'inherit' ) || ( !empty($cff_event_date_weight) && $cff_event_date_weight != 'inherit' ) || ( !empty($cff_event_date_color) && $cff_event_date_color !== '#' ) ) $cff_event_date_styles = 'style="';
499 if ( !empty($cff_event_date_size) && $cff_event_date_size != 'inherit' ) $cff_event_date_styles .= 'font-size:' . $cff_event_date_size . 'px; ';
500 if ( !empty($cff_event_date_weight) && $cff_event_date_weight != 'inherit' ) $cff_event_date_styles .= 'font-weight:' . $cff_event_date_weight . '; ';
501 if ( !empty($cff_event_date_color) && $cff_event_date_color !== '#' ) $cff_event_date_styles .= 'color:#' . str_replace('#', '', $cff_event_date_color) . ';';
502 if( ( !empty($cff_event_date_size) && $cff_event_date_size != 'inherit' ) || ( !empty($cff_event_date_weight) && $cff_event_date_weight != 'inherit' ) || ( !empty($cff_event_date_color) && $cff_event_date_color !== '#' ) ) $cff_event_date_styles .= '"';
503
504 //Event Details
505 $cff_event_details_size = $atts[ 'eventdetailssize' ];
506 $cff_event_details_weight = $atts[ 'eventdetailsweight' ];
507 $cff_event_details_color = $atts[ 'eventdetailscolor' ];
508 $cff_event_link_color = $atts[ 'eventlinkcolor' ];
509
510 $cff_event_details_styles = '';
511 if( ( !empty($cff_event_details_size) && $cff_event_details_size != 'inherit' ) || ( !empty($cff_event_details_weight) && $cff_event_details_weight != 'inherit' ) || ( !empty($cff_event_details_color) && $cff_event_details_color !== '#' ) ) $cff_event_details_styles = 'style="';
512 if ( !empty($cff_event_details_size) && $cff_event_details_size != 'inherit' ) $cff_event_details_styles .= 'font-size:' . $cff_event_details_size . 'px; ';
513 if ( !empty($cff_event_details_weight) && $cff_event_details_weight != 'inherit' ) $cff_event_details_styles .= 'font-weight:' . $cff_event_details_weight . '; ';
514 if ( !empty($cff_event_details_color) && $cff_event_details_color !== '#' ) $cff_event_details_styles .= 'color:#' . str_replace('#', '', $cff_event_details_color) . ';';
515 if( ( !empty($cff_event_details_size) && $cff_event_details_size != 'inherit' ) || ( !empty($cff_event_details_weight) && $cff_event_details_weight != 'inherit' ) || ( !empty($cff_event_details_color) && $cff_event_details_color !== '#' ) ) $cff_event_details_styles .= '"';
516
517 //Date
518 $cff_date_position = $atts[ 'datepos' ];
519 if (!isset($cff_date_position)) $cff_date_position = 'below';
520 $cff_date_size = $atts[ 'datesize' ];
521 $cff_date_weight = $atts[ 'dateweight' ];
522 $cff_date_color = $atts[ 'datecolor' ];
523
524 $cff_date_styles = '';
525 if( ( !empty($cff_date_size) && $cff_date_size != 'inherit' ) || ( !empty($cff_date_weight) && $cff_date_weight != 'inherit' ) || ( !empty($cff_date_color) && $cff_date_color !== '#' ) ) $cff_date_styles = 'style="';
526 if ( !empty($cff_date_size) && $cff_date_size != 'inherit' ) $cff_date_styles .= 'font-size:' . $cff_date_size . 'px; ';
527 if ( !empty($cff_date_weight) && $cff_date_weight != 'inherit' ) $cff_date_styles .= 'font-weight:' . $cff_date_weight . '; ';
528 if ( !empty($cff_date_color) && $cff_date_color !== '#' ) $cff_date_styles .= 'color:#' . str_replace('#', '', $cff_date_color) . ';';
529 if( ( !empty($cff_date_size) && $cff_date_size != 'inherit' ) || ( !empty($cff_date_weight) && $cff_date_weight != 'inherit' ) || ( !empty($cff_date_color) && $cff_date_color !== '#' ) ) $cff_date_styles .= '"';
530
531 $cff_date_before = isset($options[ 'cff_date_before' ]) ? $options[ 'cff_date_before' ] : '';
532 $cff_date_after = isset($options[ 'cff_date_after' ]) ? $options[ 'cff_date_after' ] : '';
533
534 //Timezone. The post date is adjusted by the timezone offset in the cff_getdate function.
535 $cff_timezone = $atts['timezone'];
536
537 //Posted ago strings
538 $cff_date_translate_strings = array(
539 'cff_translate_second' => $atts['secondtext'],
540 'cff_translate_seconds' => $atts['secondstext'],
541 'cff_translate_minute' => $atts['minutetext'],
542 'cff_translate_minutes' => $atts['minutestext'],
543 'cff_translate_hour' => $atts['hourtext'],
544 'cff_translate_hours' => $atts['hourstext'],
545 'cff_translate_day' => $atts['daytext'],
546 'cff_translate_days' => $atts['daystext'],
547 'cff_translate_week' => $atts['weektext'],
548 'cff_translate_weeks' => $atts['weekstext'],
549 'cff_translate_month' => $atts['monthtext'],
550 'cff_translate_months' => $atts['monthstext'],
551 'cff_translate_year' => $atts['yeartext'],
552 'cff_translate_years' => $atts['yearstext'],
553 'cff_translate_ago' => $atts['agotext']
554 );
555
556 //Link to Facebook
557 $cff_link_size = $atts[ 'linksize' ];
558 $cff_link_weight = $atts[ 'linkweight' ];
559 $cff_link_color = $atts[ 'linkcolor' ];
560
561 $cff_link_styles = '';
562 if( ( !empty($cff_link_size) && $cff_link_size != 'inherit' ) || ( !empty($cff_link_weight) && $cff_link_weight != 'inherit' ) || ( !empty($cff_link_color) && $cff_link_color !== '#' ) ) $cff_link_styles = 'style="';
563 if ( !empty($cff_link_size) && $cff_link_size != 'inherit' ) $cff_link_styles .= 'font-size:' . $cff_link_size . 'px; ';
564 if ( !empty($cff_link_weight) && $cff_link_weight != 'inherit' ) $cff_link_styles .= 'font-weight:' . $cff_link_weight . '; ';
565 if ( !empty($cff_link_color) && $cff_link_color !== '#' ) $cff_link_styles .= 'color:#' . str_replace('#', '', $cff_link_color) . ';';
566 if( ( !empty($cff_link_size) && $cff_link_size != 'inherit' ) || ( !empty($cff_link_weight) && $cff_link_weight != 'inherit' ) || ( !empty($cff_link_color) && $cff_link_color !== '#' ) ) $cff_link_styles .= '"';
567
568 //Link custom text
569 $cff_facebook_link_text = $atts[ 'facebooklinktext' ];
570 $cff_facebook_share_text = $atts[ 'sharelinktext' ];
571 if ($cff_facebook_share_text == '') $cff_facebook_share_text = 'Share';
572
573
574 //Show Facebook link
575 $cff_show_facebook_link = $atts[ 'showfacebooklink' ];
576 ( $cff_show_facebook_link == 'on' || $cff_show_facebook_link == 'true' || $cff_show_facebook_link == true ) ? $cff_show_facebook_link = true : $cff_show_facebook_link = false;
577 if( $atts[ 'showfacebooklink' ] === 'false' ) $cff_show_facebook_link = false;
578
579
580 //Show Share link
581 $cff_show_facebook_share = $atts[ 'showsharelink' ];
582 ( $cff_show_facebook_share == 'on' || $cff_show_facebook_share == 'true' || $cff_show_facebook_share == true ) ? $cff_show_facebook_share = true : $cff_show_facebook_share = false;
583 if( $atts[ 'showsharelink' ] === 'false' ) $cff_show_facebook_share = false;
584
585 $cff_view_link_text = $atts[ 'viewlinktext' ];
586 $cff_link_to_timeline = $atts[ 'linktotimeline' ];
587 /********** MISC **********/
588 //Like Box styles
589 $cff_likebox_bg_color = $atts[ 'likeboxcolor' ];
590
591 $cff_like_box_text_color = $atts[ 'likeboxtextcolor' ];
592 $cff_like_box_colorscheme = 'light';
593 if ($cff_like_box_text_color == 'white') $cff_like_box_colorscheme = 'dark';
594
595 $cff_likebox_width = $atts[ 'likeboxwidth' ];
596 if ( is_numeric(substr($cff_likebox_width, -1, 1)) ) $cff_likebox_width = $cff_likebox_width . 'px';
597
598 $cff_likebox_height = $atts[ 'likeboxheight' ];
599 $cff_likebox_height = preg_replace('/px$/', '', $cff_likebox_height);
600
601 if ( !isset($cff_likebox_width) || empty($cff_likebox_width) || $cff_likebox_width == '' ) $cff_likebox_width = '100%';
602 $cff_like_box_faces = $atts[ 'likeboxfaces' ];
603 if ( !isset($cff_like_box_faces) || empty($cff_like_box_faces) ){
604 $cff_like_box_faces = 'false';
605 } else {
606 $cff_like_box_faces = 'true';
607 }
608
609 $cff_like_box_border = $atts[ 'likeboxborder' ];
610 if ($cff_like_box_border) {
611 $cff_like_box_border = 'true';
612 } else {
613 $cff_like_box_border = 'false';
614 }
615
616 $cff_like_box_cover = $atts[ 'likeboxcover' ];
617 if ($cff_like_box_cover) {
618 $cff_like_box_cover = 'false';
619 } else {
620 $cff_like_box_cover = 'true';
621 }
622
623 $cff_like_box_small_header = $atts[ 'likeboxsmallheader' ];
624 if ($cff_like_box_small_header) {
625 $cff_like_box_small_header = 'true';
626 } else {
627 $cff_like_box_small_header = 'false';
628 }
629
630 $cff_like_box_hide_cta = $atts[ 'likeboxhidebtn' ];
631 if ($cff_like_box_hide_cta) {
632 $cff_like_box_hide_cta = 'true';
633 } else {
634 $cff_like_box_hide_cta = 'false';
635 }
636
637 //Compile Like box styles
638 $cff_likebox_styles = 'style="width: ' . $cff_likebox_width . ';';
639 if ( !empty($cff_likebox_bg_color) ) $cff_likebox_styles .= ' background-color: #' . str_replace('#', '', $cff_likebox_bg_color) . ';';
640
641 //Set the left margin on the like box based on how it's being displayed
642 if ( (!empty($cff_likebox_bg_color) && $cff_likebox_bg_color != '#') || ($cff_like_box_faces == 'true' || $cff_like_box_faces == 'on') ) $cff_likebox_styles .= ' margin-left: 0px;';
643
644 $cff_likebox_styles .= '"';
645
646 //Get feed header settings
647 $cff_header_bg_color = $atts['headerbg'];
648 $cff_header_padding = $atts['headerpadding'];
649 if ( is_numeric(substr($cff_header_padding, -1, 1)) ) $cff_header_padding = $cff_header_padding . 'px';
650
651 $cff_header_text_size = $atts['headertextsize'];
652 $cff_header_text_weight = $atts['headertextweight'];
653 $cff_header_text_color = $atts['headertextcolor'];
654
655 //Compile feed header styles
656 $cff_header_styles = '';
657 if( ( !empty($cff_header_bg_color) && $cff_header_bg_color !== '#' ) || !empty($cff_header_padding) || ( !empty($cff_header_text_size) && $cff_header_text_size != 'inherit' ) || ( !empty($cff_header_text_weight) && $cff_header_text_weight != 'inherit' ) || (!empty($cff_header_text_color) && $cff_header_text_color !== '#') ) $cff_header_styles = 'style="';
658 if ( !empty($cff_header_bg_color) && $cff_header_bg_color !== '#' ) $cff_header_styles .= 'background-color: #' . str_replace('#', '', $cff_header_bg_color) . '; ';
659 if ( !empty($cff_header_padding) ) $cff_header_styles .= 'padding: ' . $cff_header_padding . '; ';
660 if ( !empty($cff_header_text_size) && $cff_header_text_size != 'inherit' ) $cff_header_styles .= 'font-size: ' . $cff_header_text_size . 'px; ';
661 if ( !empty($cff_header_text_weight) && $cff_header_text_weight != 'inherit' ) $cff_header_styles .= 'font-weight: ' . $cff_header_text_weight . '; ';
662 if ( !empty($cff_header_text_color) && $cff_header_text_color !== '#' ) $cff_header_styles .= 'color: #' . str_replace('#', '', $cff_header_text_color) . '; ';
663 if( ( !empty($cff_header_bg_color) && $cff_header_bg_color !== '#' ) || !empty($cff_header_padding) || ( !empty($cff_header_text_size) && $cff_header_text_size != 'inherit' ) || ( !empty($cff_header_text_weight) && $cff_header_text_weight != 'inherit' ) || (!empty($cff_header_text_color) && $cff_header_text_color !== '#') ) $cff_header_styles .= '"';
664
665 //Video
666 //Dimensions
667 $cff_video_width = 640;
668 $cff_video_height = $atts[ 'videoheight' ];
669
670 //Action
671 $cff_video_action = $atts[ 'videoaction' ];
672
673 //Post Style settings
674 $cff_post_style = $atts['poststyle'];
675
676 $cff_post_bg_color = str_replace('#', '', $atts['postbgcolor']);
677 $cff_post_rounded = $atts['postcorners'];
678 ( ($cff_post_bg_color !== '#' && $cff_post_bg_color !== '') && $cff_post_style != 'regular' ) ? $cff_post_bg_color_check = true : $cff_post_bg_color_check = false;
679
680 $cff_box_shadow = $atts['boxshadow'];
681 ( ($cff_box_shadow == 'true' || $cff_box_shadow == 'on') && $cff_post_style == 'boxed' ) ? $cff_box_shadow = true : $cff_box_shadow = false;
682
683 //Separating Line
684 $cff_sep_color = $atts[ 'sepcolor' ];
685 if (empty($cff_sep_color)) $cff_sep_color = 'ddd';
686 $cff_sep_size = $atts[ 'sepsize' ];
687 $cff_sep_size_check = true;
688 //If empty then set a 0px border
689 if ( empty($cff_sep_size) || $cff_sep_size == '' ) {
690 $cff_sep_size = 0;
691 //Need to set a color otherwise the CSS is invalid
692 $cff_sep_color = 'fff';
693 $cff_sep_size_check = false;
694 }
695 ($cff_sep_color !== '#' && $cff_sep_color !== '') ? $cff_sep_color_check = true : $cff_sep_color_check = false;
696
697 //CFF item styles
698 $cff_item_styles = '';
699 if( $cff_post_style == 'boxed' || $cff_post_bg_color_check ){
700 $cff_item_styles = 'style="';
701 if($cff_post_bg_color_check) $cff_item_styles .= 'background-color: #' . $cff_post_bg_color . '; ';
702 if( isset($cff_post_rounded) && $cff_post_rounded !== '0' && !empty($cff_post_rounded) ) $cff_item_styles .= '-webkit-border-radius: ' . $cff_post_rounded . 'px; -moz-border-radius: ' . $cff_post_rounded . 'px; border-radius: ' . $cff_post_rounded . 'px; ';
703 $cff_item_styles .= '"';
704 }
705 if( $cff_post_style == 'regular' && ($cff_sep_color_check || $cff_sep_size_check) ){
706 $cff_item_styles .= 'style="border-bottom: ' . $cff_sep_size . 'px solid #' . str_replace('#', '', $cff_sep_color) . ';"';
707 }
708
709 //Text limits
710 $title_limit = $atts['textlength'];
711 if (!isset($title_limit)) $title_limit = 9999;
712 $body_limit = $atts['desclength'];
713
714 //Assign the Access Token and Page ID variables
715 $access_token = $atts['accesstoken'];
716 $page_id = trim( $atts['id'] );
717
718
719
720 //If an 'account' is specified then use that instead of the Page ID/token from the settings
721 $cff_account = trim($atts['account']);
722 if( !empty( $cff_account ) ){
723 $cff_connected_accounts = get_option('cff_connected_accounts');
724 if( !empty($cff_connected_accounts) ){
725
726 $cff_connected_accounts = json_decode( str_replace('\"','"', $cff_connected_accounts) );
727
728 //Grab the ID and token from the connected accounts setting
729 $page_id = $cff_connected_accounts->{ $cff_account }->{'id'};
730 $access_token = $cff_connected_accounts->{ $cff_account }->{'accesstoken'};
731
732 //Replace the encryption string in the Access Token
733 if (strpos($access_token, '02Sb981f26534g75h091287a46p5l63') !== false) {
734 $access_token = str_replace("02Sb981f26534g75h091287a46p5l63","",$access_token);
735 }
736 }
737 }
738
739 //If user pastes their full URL into the Page ID field then strip it out
740 $cff_facebook_string = 'facebook.com';
741 $cff_page_id_url_check = stripos($page_id, $cff_facebook_string);
742
743 if ( $cff_page_id_url_check ) {
744 //Remove trailing slash if exists
745 $page_id = preg_replace('{/$}', '', $page_id);
746 //Get last part of url
747 $page_id = substr( $page_id, strrpos( $page_id, '/' )+1 );
748 }
749
750 //Masonry
751 $masonry = false;
752 $cff_cols = $atts['cols'];
753 $cff_cols_mobile = $atts['colsmobile'];
754 $cff_cols_js = $atts['colsjs'];
755
756 if( intval($cff_cols) > 1 ) $masonry = true;
757 $js_only = isset( $cff_cols_js ) ? $cff_cols_js : false;
758 if( $js_only === 'false' ) $js_only = false;
759
760 if( $masonry || $masonry == 'true' ) $atts['headeroutside'] = true;
761
762 $masonry_classes = '';
763 if( isset($masonry) ) {
764 if( $masonry === 'on' || $masonry === true || $masonry === 'true' ) {
765
766 $masonry_classes .= 'cff-masonry';
767
768 if( $cff_cols != 3 ) {
769 $masonry_classes .= sprintf( ' masonry-%s-desktop', $cff_cols );
770 }
771 if( $cff_cols_mobile == 2 ) {
772 $masonry_classes .= ' masonry-2-mobile';
773 }
774 if( ! $js_only ) {
775 $masonry_classes .= ' cff-masonry-css';
776 } else {
777 $masonry_classes .= ' cff-masonry-js';
778 }
779 }
780 }
781
782 //If the Page ID contains a query string at the end then remove it
783 if ( stripos( $page_id, '?') !== false ) $page_id = substr($page_id, 0, strrpos($page_id, '?'));
784
785 //Always remove slash from end of Page ID
786 $page_id = preg_replace('{/$}', '', $page_id);
787
788 //Get show posts attribute. If not set then default to 25
789 $show_posts = $atts['num'];
790 if (empty($show_posts)) $show_posts = 25;
791 if ( $show_posts == 'undefined' ) $show_posts = 25;
792
793 //If the 'Enter my own Access Token' box is unchecked then don't use the user's access token, even if there's one in the field
794 get_option('cff_show_access_token') ? $cff_show_access_token = true : $cff_show_access_token = false;
795
796 //Check whether a Page ID has been defined
797 if ($page_id == '') {
798 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 />";
799 return false;
800 }
801
802 //Is it a restricted page?
803 $cff_restricted_page = $atts['restrictedpage'];
804 ($cff_restricted_page == 'true' || $cff_restricted_page == 'on') ? $cff_restricted_page = true : $cff_restricted_page = false;
805
806 //Is it SSL?
807 $cff_ssl = '';
808 if (is_ssl()) $cff_ssl = '&return_ssl_resources=true';
809
810 //Use posts? or feed?
811 $old_others_option = get_option('cff_show_others'); //Use this to help depreciate the old option
812 $show_others = $atts['others'];
813 $show_posts_by = $atts['showpostsby'];
814 $graph_query = 'posts';
815 $cff_show_only_others = false;
816
817 //If 'others' shortcode option is used then it overrides any other option
818 if ($show_others || $old_others_option == 'on') {
819 //Show posts by everyone
820 if ( $old_others_option == 'on' || $show_others == 'on' || $show_others == 'true' || $show_others == true || $cff_is_group ) $graph_query = 'feed';
821
822 //Only show posts by me
823 if ( $show_others == 'false' ) $graph_query = 'posts';
824
825 } else {
826 //Else use the settings page option or the 'showpostsby' shortcode option
827
828 //Only show posts by me
829 if ( $show_posts_by == 'me' ) $graph_query = 'posts';
830
831 //Show posts by everyone
832 if ( $show_posts_by == 'others' || $cff_is_group ) $graph_query = 'feed';
833
834 //Show posts ONLY by others
835 if ( $show_posts_by == 'onlyothers' && !$cff_is_group ) {
836 $graph_query = 'visitor_posts';
837 $cff_show_only_others = true;
838 }
839 }
840
841 $cff_post_limit = $atts['limit'];
842
843 //If the limit isn't set then set it to be 7 more than the number of posts defined
844 if ( isset($cff_post_limit) && $cff_post_limit !== '' ) {
845 $cff_post_limit = $cff_post_limit;
846 } else {
847 if( intval($show_posts) >= 50 ) $cff_post_limit = intval(intval($show_posts) + 7);
848 if( intval($show_posts) < 50 ) $cff_post_limit = intval(intval($show_posts) + 5);
849 if( intval($show_posts) < 25 ) $cff_post_limit = intval(intval($show_posts) + 4);
850 if( intval($show_posts) < 10 ) $cff_post_limit = intval(intval($show_posts) + 3);
851 if( intval($show_posts) < 6 ) $cff_post_limit = intval(intval($show_posts) + 2);
852 if( intval($show_posts) < 2 ) $cff_post_limit = intval(intval($show_posts) + 1);
853 }
854 if( $cff_post_limit >= 100 ) $cff_post_limit = 100;
855
856 //If the number of posts is set to zero then don't show any and set limit to one
857 if ( ($show_posts == '0' || $show_posts == 0) && $show_posts !== ''){
858 $show_posts = 0;
859 $cff_post_limit = 1;
860 }
861
862
863 //Calculate the cache time in seconds
864 if($cff_cache_time_unit == 'minutes') $cff_cache_time_unit = 60;
865 if($cff_cache_time_unit == 'hours') $cff_cache_time_unit = 60*60;
866 if($cff_cache_time_unit == 'days') $cff_cache_time_unit = 60*60*24;
867 $cache_seconds = $cff_cache_time * $cff_cache_time_unit;
868
869 //Get like box vars
870 $cff_likebox_width = $atts[ 'likeboxwidth' ];
871 if ( !isset($cff_likebox_width) || empty($cff_likebox_width) || $cff_likebox_width == '' ) $cff_likebox_width = 300;
872
873 $like_box_page_id = explode(",", str_replace(' ', '', $page_id) );
874
875 //Like Box HTML
876 $like_box = '<';
877 //If the Like Box is at the top then change the element from a div so that it doesn't interfere with the "nth-of-type" used for grids in CSS
878 ($cff_like_box_position == 'top') ? $like_box .= 'section' : $like_box .= 'div';
879 $like_box .= ' class="cff-likebox';
880
881 if ($cff_like_box_outside) $like_box .= ' cff-outside';
882 $like_box .= ($cff_like_box_position == 'top') ? ' cff-top' : ' cff-bottom';
883 $like_box .= '" >';
884
885 //Calculate the like box height
886 $cff_likebox_height = 130;
887 if( $cff_like_box_small_header == 'true' ) $cff_likebox_height = 70;
888 if( $cff_like_box_faces == 'true' ) $cff_likebox_height = 214;
889 if( $cff_like_box_small_header == 'true' && $cff_like_box_faces == 'true' ) $cff_likebox_height = 154;
890
891 //Src is set in JS now so can be dynamic based on screen size as 'adapt_container_width' doesn't work in iframe
892 $like_box .= '<iframe src="" data-likebox-id="'.$like_box_page_id[0].'" data-likebox-width="'.$cff_likebox_width.'" data-likebox-header="'.$cff_like_box_small_header.'" data-hide-cover="'.$cff_like_box_cover.'" data-hide-cta="'.$cff_like_box_hide_cta.'" data-likebox-faces="'.$cff_like_box_faces.'" height="'.$cff_likebox_height.'" data-locale="'.$cff_locale.'" style="border:none;overflow:hidden" scrolling="no" allowTransparency="true" allow="encrypted-media" class="fb_iframe_widget"></iframe>';
893
894 $like_box .= '</';
895
896 ($cff_like_box_position == 'top') ? $like_box .= 'section' : $like_box .= 'div';
897 $like_box .= '>';
898
899 //Don't show like box if it's a group
900 if($cff_is_group) $like_box = '';
901
902
903 //Feed header
904 $cff_show_header = $atts['showheader'];
905 ($cff_show_header == 'true' || $cff_show_header == 'on') ? $cff_show_header = true : $cff_show_header = false;
906
907 $cff_header_outside = $atts['headeroutside'];
908 ($cff_header_outside == 'true' || $cff_header_outside == 'on') ? $cff_header_outside = true : $cff_header_outside = false;
909
910 $cff_header_text = stripslashes( $atts['headertext'] );
911 $cff_header_icon = $atts['headericon'];
912 $cff_header_icon_color = $atts['headericoncolor'];
913 $cff_header_icon_size = $atts['headericonsize'];
914
915 $cff_header = '<h3 class="cff-header';
916 if ($cff_header_outside) $cff_header .= ' cff-outside';
917 $cff_header .= '" ' . $cff_header_styles . '>';
918 $cff_header .= '<span class="fa fas fab fa-' . $cff_header_icon . '"';
919 if(!empty($cff_header_icon_color) || !empty($cff_header_icon_size)) $cff_header .= ' style="';
920 if(!empty($cff_header_icon_color)) $cff_header .= 'color: #' . str_replace('#', '', $cff_header_icon_color) . ';';
921 if(!empty($cff_header_icon_size)) $cff_header .= ' font-size: ' . $cff_header_icon_size . 'px;';
922 if(!empty($cff_header_icon_color) || !empty($cff_header_icon_size))$cff_header .= '"';
923 $cff_header .= ' aria-hidden="true"></span>';
924 $cff_header .= '<span class="header-text" style="height: '.$cff_header_icon_size.'px;">' . $cff_header_text . '</span>';
925 $cff_header .= '</h3>';
926
927 //Misc Settings
928 $cff_nofollow = $atts['nofollow'];
929 ( $cff_nofollow == 'on' || $cff_nofollow == 'true' || $cff_nofollow == true ) ? $cff_nofollow = true : $cff_nofollow = false;
930 if( $atts[ 'nofollow' ] == 'false' ) $cff_nofollow = false;
931 ( $cff_nofollow ) ? $cff_nofollow = ' rel="nofollow"' : $cff_nofollow = '';
932
933 //If the number of posts is set to zero then don't show any and set limit to one
934 if ( ($atts['num'] == '0' || $atts['num'] == 0) && $atts['num'] !== ''){
935 $show_posts = 0;
936 $cff_post_limit = 1;
937 }
938
939 //***START FEED***
940 $cff_content = '';
941
942 //Add the page header to the outside of the top of feed
943 if ($cff_show_header && $cff_header_outside) $cff_content .= $cff_header;
944
945 //Add like box to the outside of the top of feed
946 if ($cff_like_box_position == 'top' && $cff_show_like_box && $cff_like_box_outside) $cff_content .= $like_box;
947
948 //Create CFF container HTML
949 $cff_content .= '<div class="cff-wrapper">';
950 $cff_content .= '<div id="cff" data-char="'.$title_limit.'"';
951
952 //Disable default CSS styles?
953 $cff_disable_styles = $atts['disablestyles'];
954 ( $cff_disable_styles == 'on' || $cff_disable_styles == 'true' || $cff_disable_styles == true ) ? $cff_disable_styles = true : $cff_disable_styles = false;
955 if( $atts[ 'disablestyles' ] === 'false' ) $cff_disable_styles = false;
956
957 //If there's a class then add it here
958 if( !empty($cff_class) || !empty($cff_feed_height) || !$cff_disable_styles || $cff_feed_width_resp || !empty($masonry_classes) ) $cff_content .= ' class="';
959 if( !empty($cff_class) ) $cff_content .= $cff_class . ' ';
960 if( !empty($masonry_classes) ) $cff_content .= $masonry_classes;
961 if ( !empty($cff_feed_height) ) $cff_content .= ' cff-fixed-height ';
962 if ( $cff_feed_width_resp ) $cff_content .= ' cff-width-resp ';
963 if ( !$cff_disable_styles ) $cff_content .= ' cff-default-styles';
964 if( !empty($cff_class) || !empty($cff_feed_height) || !$cff_disable_styles || $cff_feed_width_resp ) $cff_content .= '"';
965
966 $cff_content .= ' ' . $cff_feed_styles . '>';
967
968 //Add the page header to the inside of the top of feed
969 if ($cff_show_header && !$cff_header_outside) $cff_content .= $cff_header;
970
971 //Add like box to the inside of the top of feed
972 if ($cff_like_box_position == 'top' && $cff_show_like_box && !$cff_like_box_outside) $cff_content .= $like_box;
973 //Limit var
974 $i_post = 0;
975
976 //Define array for post items
977 $cff_posts_array = array();
978
979 //ALL POSTS
980 if (!$cff_events_only){
981
982 $cff_posts_json_url = 'https://graph.facebook.com/v4.0/' . $page_id . '/' . $graph_query . '?fields=id,from{picture,id,name,link},message,message_tags,story,story_tags,status_type,created_time,backdated_time,call_to_action,attachments{title,description,media_type,unshimmed_url,target{id},media{source}}&access_token=' . $access_token . '&limit=' . $cff_post_limit . '&locale=' . $cff_locale . $cff_ssl;
983
984 if( $cff_show_access_token && strlen($access_token) > 130 ){
985 //If using a Page Access Token then set caching time to be minimum of 5 minutes
986 if( $cache_seconds < 300 || !isset($cache_seconds) ) $cache_seconds = 300;
987 } else {
988 //Temporarily set caching time to be minimum of 1 hour
989 if( $cache_seconds < 3600 || !isset($cache_seconds) ) $cache_seconds = 3600;
990
991 //Temporarily increase default caching time to be 4 hours
992 if( $cache_seconds == 3600 ) $cache_seconds = 14400;
993 }
994
995 //Don't use caching if the cache time is set to zero
996 if ($cff_cache_time != 0){
997
998 //Create the transient name
999 //Split the Page ID in half and stick it together so we definitely have the beginning and end of it
1000 $trans_page_id = substr($page_id, 0, 16) . substr($page_id, -15);
1001 $transient_name = 'cff_' . substr($graph_query, 0, 1) . '_' . $trans_page_id . substr($cff_post_limit, 0, 3) . substr($show_posts_by, 0, 2) . substr($cff_locale, 0, 2);
1002
1003 //Limit to 45 chars max
1004 $transient_name = substr($transient_name, 0, 45);
1005
1006 //Get any existing copy of our transient data
1007 if ( false === ( $posts_json = get_transient( $transient_name ) ) || $posts_json === null ) {
1008 //Get the contents of the Facebook page
1009 $posts_json = cff_fetchUrl($cff_posts_json_url);
1010
1011 //Check whether any data is returned from the API. If it isn't then don't cache the error response and instead keep checking the API on every page load until data is returned.
1012 $FBdata = json_decode($posts_json);
1013
1014 if( !empty($FBdata) ) {
1015
1016 //Error returned by API
1017 if( isset($FBdata->error) ){
1018
1019 //Cache the error JSON so doesn't keep making repeated requests
1020 //See if a backup cache exists
1021 if ( false !== get_transient( '!cff_' . $transient_name ) ) {
1022
1023 $posts_json = get_transient( '!cff_' . $transient_name );
1024
1025 //Add error message to backup cache so can be displayed at top of feed
1026 isset( $FBdata->error->message ) ? $error_message = $FBdata->error->message : $error_message = '';
1027 isset( $FBdata->error->type ) ? $error_type = $FBdata->error->type : $error_type = '';
1028 $prefix = '{';
1029 if (substr($posts_json, 0, strlen($prefix)) == $prefix) $posts_json = substr($posts_json, strlen($prefix));
1030 $posts_json = '{"cached_error": { "message": "'.$error_message.'", "type": "'.$error_type.'" }, ' . $posts_json;
1031 }
1032
1033 //Posts data returned by API
1034 } else {
1035 //If a backup should be created for this data then create one
1036 set_transient( '!cff_' . $transient_name, $posts_json, YEAR_IN_SECONDS );
1037 }
1038
1039 //Set regular cache
1040 set_transient( $transient_name, $posts_json, $cache_seconds );
1041
1042 }
1043 } else {
1044
1045 $posts_json = get_transient( $transient_name );
1046 //If we can't find the transient then fall back to just getting the json from the api
1047 if ($posts_json == false) $posts_json = cff_fetchUrl($cff_posts_json_url);
1048
1049 }
1050 } else {
1051 $posts_json = cff_fetchUrl($cff_posts_json_url);
1052 }
1053
1054
1055 //Interpret data with JSON
1056 $FBdata = json_decode($posts_json);
1057
1058 //If there's no data then show a pretty error message
1059 if( empty($FBdata->data) || isset($FBdata->cached_error) ) {
1060
1061 //Check whether it's an error in the backup cache
1062 if( isset($FBdata->cached_error) ) $FBdata->error = $FBdata->cached_error;
1063
1064 //Show custom message for the PPCA error
1065 if( isset($FBdata->error->message) && strpos($FBdata->error->message, 'Page Public Content Access') !== false ) {
1066 $FBdata->error->message = '(#10) To use "Page Public Content Access", your use of this endpoint must be reviewed and approved by Facebook.';
1067 $FBdata->error->type = $FBdata->error->code = $FBdata->error->error_subcode = NULL;
1068 }
1069
1070 $cff_content .= '<div class="cff-error-msg">';
1071 $cff_content .= '<p><b>This message is only visible to admins.</b><br />';
1072 $cff_content .= '<p>Problem displaying Facebook posts.';
1073 if( isset($FBdata->cached_error) ) $cff_content .= ' Backup cache in use.';
1074 $cff_content .= '<br/><a href="javascript:void(0);" id="cff-show-error" onclick="cffShowError()">Click to show error</a>';
1075 $cff_content .= '<script type="text/javascript">function cffShowError() { document.getElementById("cff-error-reason").style.display = "block"; document.getElementById("cff-show-error").style.display = "none"; }</script>';
1076 $cff_content .= '</p><div id="cff-error-reason">';
1077
1078 if( isset($FBdata->error->message) ) $cff_content .= '<b>Error:</b> ' . $FBdata->error->message;
1079 if( isset($FBdata->error->type) ) $cff_content .= '<br /><b>Type:</b> ' . $FBdata->error->type;
1080 if( isset($FBdata->error->error_subcode) ) $cff_content .= '<br />Subcode: ' . $FBdata->error->error_subcode;
1081
1082 if( isset($FBdata->error_msg) ) $cff_content .= '<b>Error:</b> ' . $FBdata->error_msg;
1083 if( isset($FBdata->error_code) ) $cff_content .= '<br />Code: ' . $FBdata->error_code;
1084
1085 if($FBdata == null) $cff_content .= '<b>Error:</b> Server configuration issue';
1086 if( empty($FBdata->error) && empty($FBdata->error_msg) && $FBdata !== null ) $cff_content .= '<b>Error:</b> No posts available for this Facebook ID';
1087 $cff_content .= '<br /><b>Solution:</b> <a href="https://smashballoon.com/custom-facebook-feed/docs/errors/" target="_blank">See here</a> for how to solve this error';
1088 $cff_content .= '</div></div>'; //End .cff-error-msg and #cff-error-reason
1089 //Only display errors to admins
1090 if( current_user_can( 'manage_options' ) ){
1091 $cff_content .= '<style>#cff .cff-error-msg{ display: block !important; }</style>';
1092 }
1093 }
1094
1095
1096 $numeric_page_id = '';
1097 if( !empty($FBdata->data) ){
1098 if ( ($cff_show_only_others || $show_posts_by == 'others') && count($FBdata->data) > 0 ) {
1099 //Get the numeric ID of the page so can compare it to the author of each post
1100 $first_post_id = explode("_", $FBdata->data[0]->id);
1101 $numeric_page_id = $first_post_id[0];
1102 }
1103 }
1104
1105 //***STARTS POSTS LOOP***
1106 if( isset($FBdata->data) ){
1107 foreach ($FBdata->data as $news )
1108 {
1109 //Explode News and Page ID's into 2 values
1110 $PostID = '';
1111 $cff_post_id = '';
1112 if( isset($news->id) ){
1113 $cff_post_id = $news->id;
1114 $PostID = explode("_", $cff_post_id);
1115 }
1116
1117 //Reassign variable changes from API v3.3 update
1118 $news->link = '';
1119 $news->description = '';
1120 $news->name = '';
1121 $news->caption = '';
1122 $news->source = '';
1123 $news->object_id = '';
1124 if( isset($news->attachments->data[0]->unshimmed_url) ) $news->link = $news->attachments->data[0]->unshimmed_url;
1125 if( isset($news->attachments->data[0]->description) ) $news->description = $news->attachments->data[0]->description;
1126 if( isset($news->attachments->data[0]->target->id) ) $news->object_id = $news->attachments->data[0]->target->id;
1127 if( isset($news->attachments->data[0]->media->source) ) $news->source = $news->attachments->data[0]->media->source;
1128 if( isset($news->attachments->data[0]->title) ){
1129 $news->name = $news->attachments->data[0]->title;
1130 $news->caption = $news->attachments->data[0]->title;
1131 }
1132
1133 //Check the post type
1134 $cff_post_type = 'status';
1135 if( isset($news->attachments->data[0]->media_type) ) $cff_post_type = $news->attachments->data[0]->media_type;
1136
1137 if ($cff_post_type == 'link') {
1138 isset($news->story) ? $story = $news->story : $story = '';
1139 //Check whether it's an event
1140 $event_link_check = "facebook.com/events/";
1141 if( isset($news->link) ){
1142 $event_link_check = stripos($news->link, $event_link_check);
1143 if ( $event_link_check ) $cff_post_type = 'event';
1144 }
1145 }
1146
1147 //Should we show this post or not?
1148 $cff_show_post = false;
1149 switch ($cff_post_type) {
1150 case 'link':
1151 if ( $cff_show_links_type ) $cff_show_post = true;
1152 break;
1153 case 'event':
1154 if ( $cff_show_event_type ) $cff_show_post = true;
1155 break;
1156 case 'video':
1157 if ( $cff_show_video_type ) $cff_show_post = true;
1158 break;
1159 case 'swf':
1160 if ( $cff_show_video_type ) $cff_show_post = true;
1161 break;
1162 case 'photo':
1163 if ( $cff_show_photos_type ) $cff_show_post = true;
1164 break;
1165 case 'offer':
1166 $cff_show_post = true;
1167 break;
1168 default:
1169 //Check whether it's a status (author comment or like)
1170 if ( $cff_show_status_type && !empty($news->message) ) $cff_show_post = true;
1171 break;
1172 }
1173
1174 //Is it a duplicate post?
1175 if (!isset($prev_post_message)) $prev_post_message = '';
1176 if (!isset($prev_post_link)) $prev_post_link = '';
1177 if (!isset($prev_post_description)) $prev_post_description = '';
1178 isset($news->message) ? $pm = $news->message : $pm = '';
1179 isset($news->link) ? $pl = $news->link : $pl = '';
1180 isset($news->description) ? $pd = $news->description : $pd = '';
1181
1182 if ( ($prev_post_message == $pm) && ($prev_post_link == $pl) && ($prev_post_description == $pd) ) $cff_show_post = false;
1183
1184 //Offset. If the post index ($i_post) is less than the offset then don't show the post
1185 if( intval($i_post) < intval($atts['offset']) ){
1186 $cff_show_post = false;
1187 $i_post++;
1188 }
1189
1190 //Check post type and display post if selected
1191 if ( $cff_show_post ) {
1192 //If it isn't then create the post
1193 //Only create posts for the amount of posts specified
1194 if( intval($atts['offset']) > 0 ){
1195 //If offset is being used then stop after showing the number of posts + the offset
1196 if ( $i_post == (intval($show_posts) + intval($atts['offset'])) ) break;
1197 } else {
1198 //Else just stop after the number of posts to be displayed is reached
1199 if ( $i_post == $show_posts ) break;
1200 }
1201 $i_post++;
1202 //********************************//
1203 //***COMPILE SECTION VARIABLES***//
1204 //********************************//
1205 //Set the post link
1206 isset($news->link) ? $link = htmlspecialchars($news->link) : $link = '';
1207 //Is it a shared album?
1208 $shared_album_string = 'shared an album:';
1209 isset($news->story) ? $story = $news->story : $story = '';
1210 $shared_album = stripos($story, $shared_album_string);
1211 if ( $shared_album ) {
1212 $link = str_replace('photo.php?','media/set/?',$link);
1213 }
1214
1215 //Check the post type
1216 isset($cff_post_type) ? $cff_post_type = $cff_post_type : $cff_post_type = '';
1217 if ($cff_post_type == 'link') {
1218 isset($news->story) ? $story = $news->story : $story = '';
1219 //Check whether it's an event
1220 $event_link_check = "facebook.com/events/";
1221 //Make sure URL doesn't include 'permalink' as that indicates someone else sharing a post from within an event (eg: https://www.facebook.com/events/617323338414282/permalink/617324268414189/) and the event ID is then not retrieved properly from the event URL as it's formatted like so: facebook.com/events/EVENT_ID/permalink/POST_ID
1222 $event_link_check = stripos($news->link, $event_link_check);
1223 $event_link_check_2 = stripos($news->link, "permalink/");
1224 if ( $event_link_check && !$event_link_check_2 ) $cff_post_type = 'event';
1225 }
1226
1227 //If it's an event then check whether the URL contains facebook.com
1228 if(isset($news->link)){
1229 if( stripos($news->link, "events/") && $cff_post_type == 'event' ){
1230 //Facebook changed the event link from absolute to relative, and so if the link isn't absolute then add facebook.com to front
1231 ( stripos($link, 'facebook.com') ) ? $link = $link : $link = 'https://facebook.com' . $link;
1232 }
1233 }
1234
1235 //Is it an album?
1236 $cff_album = false;
1237 if( isset($news->status_type) ){
1238 if( $news->status_type == 'added_photos' ){
1239 if( isset($news->attachments) ){
1240 if( $news->attachments->data[0]->media_type == 'album' ) $cff_album = true;
1241 }
1242 }
1243 }
1244
1245 //If there's no link provided then link to either the Facebook page or the individual status
1246 if (empty($news->link)) {
1247 if ($cff_link_to_timeline == true){
1248 //Link to page
1249 $link = 'https://facebook.com/' . $page_id;
1250 } else {
1251 //Link to status
1252 $link = "https://www.facebook.com/" . $page_id . "/posts/" . $PostID[1];
1253 }
1254 }
1255
1256 //DATE
1257 $cff_date_formatting = $atts[ 'dateformat' ];
1258 $cff_date_custom = $atts[ 'datecustom' ];
1259
1260 isset($news->created_time) ? $post_time = $news->created_time : $post_time = '';
1261 if( isset($news->backdated_time) ) $post_time = $news->backdated_time; //If the post is backdated then use that as the date instead
1262
1263 $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_translate_strings, $cff_timezone) . ' ' . $cff_date_after;
1264 if($cff_date_position == 'below' || (!$cff_show_author && $cff_date_position == 'author') ) $cff_date .= '<span class="cff-date-dot">&nbsp;&middot;&nbsp;&nbsp;</span>';
1265 $cff_date .= '</p>';
1266
1267 //Page name
1268 if( isset($news->from->name) ){
1269 $cff_author_name = $news->from->name;
1270 $cff_author_name = str_replace('"', "", $cff_author_name);
1271 } else {
1272 $cff_author_name = '';
1273 }
1274
1275 //Story/post text vars
1276 $post_text = '';
1277 $cff_post_text_type = '';
1278 $cff_story_raw = '';
1279 $cff_message_raw = '';
1280 $cff_name_raw = '';
1281 $text_tags = '';
1282 $post_text_story = '';
1283 $post_text_message = '';
1284
1285 //STORY TAGS
1286 $cff_post_tags = $atts[ 'posttags' ];
1287
1288 //Use the story
1289 if (!empty($news->story)) {
1290 $cff_story_raw = $news->story;
1291 $post_text_story .= htmlspecialchars($cff_story_raw);
1292 $cff_post_text_type = 'story';
1293
1294
1295 //Add message and story tags if there are any and the post text is the message or the story
1296 if( $cff_post_tags && isset($news->story_tags) && !$cff_title_link){
1297
1298 $text_tags = $news->story_tags;
1299
1300 //Does the Post Text contain any html tags? - the & symbol is the best indicator of this
1301 $cff_html_check_array = array('&lt;', '', '', '&quot;', '&amp;', '&gt;&gt;');
1302
1303 //always use the text replace method
1304 if( cff_stripos_arr($post_text_story, $cff_html_check_array) !== false || ($cff_locale == 'el_GR' && count($news->story_tags) > 3) ) {
1305
1306 //Loop through the tags
1307 foreach($text_tags as $message_tag ) {
1308
1309 ( isset($message_tag->id) ) ? $message_tag = $message_tag : $message_tag = $message_tag[0];
1310
1311 $tag_name = $message_tag->name;
1312 $tag_link = '<a href="https://facebook.com/' . $message_tag->id . '">' . $message_tag->name . '</a>';
1313
1314 $post_text_story = str_replace($tag_name, $tag_link, $post_text_story);
1315 }
1316
1317 } else {
1318
1319 //If it doesn't contain HTMl tags then use the offset to replace message tags
1320 $message_tags_arr = array();
1321
1322 $tag = 0;
1323 foreach($text_tags as $message_tag ) {
1324 $tag++;
1325 ( isset($message_tag->id) ) ? $message_tag = $message_tag : $message_tag = $message_tag[0];
1326
1327 isset($message_tag->type) ? $tag_type = $message_tag->type : $tag_type = '';
1328
1329 $message_tags_arr = cff_array_push_assoc(
1330 $message_tags_arr,
1331 $tag,
1332 array(
1333 'id' => $message_tag->id,
1334 'name' => $message_tag->name,
1335 'type' => isset($message_tag->type) ? $message_tag->type : '',
1336 'offset' => $message_tag->offset,
1337 'length' => $message_tag->length
1338 )
1339 );
1340
1341 }
1342
1343 //Keep track of the offsets so that if two tags have the same offset then only one is used. Need this as API 2.5 update changed the story_tag JSON format. A duplicate offset usually means '__ was with __ and 3 others'. We don't want to link the '3 others' part.
1344 $cff_story_tag_offsets = '';
1345 $cff_story_duplicate_offset = '';
1346
1347 //Check if there are any duplicate offsets. If so, assign to the cff_story_duplicate_offset var.
1348 for($tag = count($message_tags_arr); $tag >= 1; $tag--) {
1349 $c = (string)$message_tags_arr[$tag]['offset'];
1350 if( strpos( $cff_story_tag_offsets, $c ) !== false && $c !== '0' ){
1351 $cff_story_duplicate_offset = $c;
1352 } else {
1353 $cff_story_tag_offsets .= $c . ',';
1354 }
1355
1356 }
1357
1358 for($tag = count($message_tags_arr); $tag >= 1; $tag--) {
1359
1360 //If the name is blank (aka the story tag doesn't work properly) then don't use it
1361 if( $message_tags_arr[$tag]['name'] !== '' ) {
1362
1363 //If it's an event tag or it has the same offset as another tag then don't display it
1364 if( $message_tags_arr[$tag]['type'] == 'event' || $message_tags_arr[$tag]['offset'] == $cff_story_duplicate_offset || $message_tags_arr[$tag]['type'] == 'page' ){
1365 //Don't use the story tag in this case otherwise it changes '__ created an event' to '__ created an Name Of Event'
1366 //Don't use the story tag if it's a page as it causes an issue when sharing a page: Smash Balloon Dev shared a Smash Balloon.
1367 } else {
1368 $b = '<a href="https://facebook.com/' . $message_tags_arr[$tag]['id'] . '" target="_blank">' . $message_tags_arr[$tag]['name'] . '</a>';
1369 $c = $message_tags_arr[$tag]['offset'];
1370 $d = $message_tags_arr[$tag]['length'];
1371 $post_text_story = cff_mb_substr_replace( $post_text_story, $b, $c, $d);
1372 }
1373
1374 }
1375
1376 }
1377
1378 } // end if/else
1379
1380 } //END STORY TAGS
1381
1382 }
1383
1384 //POST AUTHOR
1385 $cff_author = '';
1386 if( isset($news->from->id) ){
1387
1388 $cff_author .= '<div class="cff-author">';
1389
1390 //Check if the author from ID exists, as sometimes it doesn't
1391 isset($news->from->id) ? $cff_from_id = $news->from->id : $cff_from_id = '';
1392
1393 $cff_author_link_atts = 'href="https://facebook.com/' . $cff_from_id . '" '.$target.$cff_nofollow.' '.$cff_author_styles;
1394
1395 //Link to the post if it's a visitor post as profile link no longer available
1396 $cff_author_link_el = 'a';
1397 $cff_author_link_atts = ' href="https://facebook.com/' . $cff_from_id . '" '.$target.$cff_nofollow.' '.$cff_author_styles;
1398
1399 //If no link is available then change to span
1400 if( !isset($news->from->link) ){
1401 $cff_author_link_el = 'span';
1402 $cff_author_link_atts = '';
1403 }
1404
1405 //Remove the first occurence of the author name from the story
1406 if( !empty($cff_author_name) ){
1407 $cff_author_name_pos = strpos($post_text_story, $cff_author_name);
1408 if ($cff_author_name_pos !== false) {
1409 $post_text_story = substr_replace($post_text_story, '', $cff_author_name_pos, strlen($cff_author_name));
1410 }
1411 }
1412
1413 //Author text
1414 $cff_author .= '<div class="cff-author-text">';
1415 if($cff_show_date && $cff_date_position !== 'above' && $cff_date_position !== 'below'){
1416 $cff_author .= '<p class="cff-page-name cff-author-date" '.$cff_author_styles.'><'.$cff_author_link_el.$cff_author_link_atts.'>'.$cff_author_name.'</'.$cff_author_link_el.'><span class="cff-story"> '.$post_text_story.'</span></p>';
1417 $cff_author .= $cff_date;
1418 } else {
1419 $cff_author .= '<span class="cff-page-name"><'.$cff_author_link_el.$cff_author_link_atts.'>'.$cff_author_name.'</'.$cff_author_link_el.'><span class="cff-story"> '.$post_text_story.'</span></span>';
1420 }
1421
1422 $cff_author .= '</div>';
1423
1424 //Author image
1425 isset($news->from->picture->data->url) ? $cff_author_src = $news->from->picture->data->url : $cff_author_src = '';
1426
1427 $cff_author .= '<div class="cff-author-img"><'.$cff_author_link_el.$cff_author_link_atts.'><img src="'.$cff_author_src.'" title="'.$cff_author_name.'" alt="'.$cff_author_name.'" width=40 height=40 onerror="this.style.display=\'none\'"></'.$cff_author_link_el.'></div>';
1428
1429 $cff_author .= '</div>'; //End .cff-author
1430
1431 } else {
1432
1433 $cff_author .= '<div class="cff-author cff-no-author-info">';
1434
1435 //Author text
1436 $cff_author .= '<div class="cff-author-text">';
1437 if($cff_show_date && $cff_date_position !== 'above' && $cff_date_position !== 'below'){
1438 if( !empty($post_text_story) ) $cff_author .= '<p class="cff-page-name cff-author-date"><span class="cff-story"> '.$post_text_story.'</span></p>';
1439 $cff_author .= $cff_date;
1440 } else {
1441 if( !empty($post_text_story) ) $cff_author .= '<span class="cff-page-name"><span class="cff-story"> '.$post_text_story.'</span></span>';
1442 }
1443 $cff_author .= '</div>';
1444
1445 //Author image
1446 $cff_author .= '<div class="cff-author-img"></div>';
1447 $cff_author .= '</div>'; //End .cff-author
1448
1449 }
1450
1451
1452 //POST TEXT
1453
1454 //Get the actual post text
1455 //Which content should we use?
1456 //Use the message
1457 if (!empty($news->message)) {
1458 $cff_message_raw = $news->message;
1459
1460 $post_text_message = htmlspecialchars($cff_message_raw);
1461 $cff_post_text_type = 'message';
1462
1463 //MESSAGE TAGS
1464 //Add message and story tags if there are any and the post text is the message or the story
1465 if( $cff_post_tags && isset($news->message_tags) && !$cff_title_link){
1466
1467 $text_tags = $news->message_tags;
1468
1469 //Does the Post Text contain any html tags? - the & symbol is the best indicator of this
1470 $cff_html_check_array = array('&lt;', '', '', '&quot;', '&amp;', '&gt;&gt;', '&gt;');
1471
1472 //always use the text replace method
1473 if( cff_stripos_arr($post_text_message, $cff_html_check_array) !== false ) {
1474 //Loop through the tags
1475 foreach($text_tags as $message_tag ) {
1476
1477 ( isset($message_tag->id) ) ? $message_tag = $message_tag : $message_tag = $message_tag[0];
1478
1479 $tag_name = $message_tag->name;
1480 $tag_link = '<a href="https://facebook.com/' . $message_tag->id . '">' . $message_tag->name . '</a>';
1481
1482 $post_text_message = str_replace($tag_name, $tag_link, $post_text_message);
1483 }
1484
1485 } else {
1486 //If it doesn't contain HTMl tags then use the offset to replace message tags
1487 $message_tags_arr = array();
1488
1489 $tag = 0;
1490 foreach($text_tags as $message_tag ) {
1491 $tag++;
1492
1493 ( isset($message_tag->id) ) ? $message_tag = $message_tag : $message_tag = $message_tag[0];
1494
1495 $message_tags_arr = cff_array_push_assoc(
1496 $message_tags_arr,
1497 $tag,
1498 array(
1499 'id' => $message_tag->id,
1500 'name' => $message_tag->name,
1501 'type' => isset($message_tag->type) ? $message_tag->type : '',
1502 'offset' => $message_tag->offset,
1503 'length' => $message_tag->length
1504 )
1505 );
1506 }
1507
1508 //Keep track of the offsets so that if two tags have the same offset then only one is used. Need this as API 2.5 update changed the story_tag JSON format.
1509 $cff_msg_tag_offsets = '';
1510 $cff_msg_duplicate_offset = '';
1511
1512 //Check if there are any duplicate offsets. If so, assign to the cff_duplicate_offset var.
1513 for($tag = count($message_tags_arr); $tag >= 1; $tag--) {
1514 $c = (string)$message_tags_arr[$tag]['offset'];
1515 if( strpos( $cff_msg_tag_offsets, $c ) !== false && $c !== '0' ){
1516 $cff_msg_duplicate_offset = $c;
1517 } else {
1518 $cff_msg_tag_offsets .= $c . ',';
1519 }
1520 }
1521
1522 //Sort the array by the "offset" key as Facebook doesn't always return them in the correct order
1523 usort($message_tags_arr, "cffSortTags");
1524
1525 for($tag = count($message_tags_arr)-1; $tag >= 0; $tag--) {
1526
1527 //If the name is blank (aka the story tag doesn't work properly) then don't use it
1528 if( $message_tags_arr[$tag]['name'] !== '' ) {
1529
1530 if( $message_tags_arr[$tag]['offset'] == $cff_msg_duplicate_offset ){
1531 //If it has the same offset as another tag then don't display it
1532 } else {
1533 $b = '<a href="https://facebook.com/' . $message_tags_arr[$tag]['id'] . '">' . $message_tags_arr[$tag]['name'] . '</a>';
1534 $c = $message_tags_arr[$tag]['offset'];
1535 $d = $message_tags_arr[$tag]['length'];
1536 $post_text_message = cff_mb_substr_replace( $post_text_message, $b, $c, $d);
1537 }
1538
1539 }
1540
1541 }
1542
1543 } // end if/else
1544
1545 } //END MESSAGE TAGS
1546
1547 }
1548
1549
1550 //Check to see whether it's an embedded video so that we can show the name above the post text if necessary
1551 $cff_soundcloud = false;
1552 $cff_is_video_embed = false;
1553 if ($cff_post_type == 'video' || $cff_post_type == 'music'){
1554 if( isset($news->source) && !empty($news->source) ){
1555 $url = $news->source;
1556 } else if ( isset($news->link) ) {
1557 $url = $news->link;
1558 } else {
1559 $url = '';
1560 }
1561 //Embeddable video strings
1562 $youtube = 'youtube';
1563 $youtu = 'youtu';
1564 $vimeo = 'vimeo';
1565 $youtubeembed = 'youtube.com/embed';
1566 $soundcloud = 'soundcloud.com';
1567 $swf = '.swf';
1568 //Check whether it's a youtube video
1569 $youtube = stripos($url, $youtube);
1570 $youtu = stripos($url, $youtu);
1571 $youtubeembed = stripos($url, $youtubeembed);
1572 //Check whether it's a SoundCloud embed
1573
1574 $soundcloudembed = stripos($url, $soundcloud);
1575 //Check whether it's a youtube video
1576 if($youtube || $youtu || $youtubeembed || (stripos($url, $vimeo) !== false)) {
1577 $cff_is_video_embed = true;
1578 }
1579 //If it's soundcloud then add it into the shared link box at the bottom of the post
1580 if( $soundcloudembed ) $cff_soundcloud = true;
1581
1582 $cff_video_name = '';
1583 //If the name exists and it's a non-embedded video then show the name at the top of the post text
1584 if( isset($news->name) && !$cff_is_video_embed ){
1585
1586 if (!$cff_title_link) $cff_video_name .= '<a href="'.$link.'" '.$target.$cff_nofollow.' style="color: #'.$cff_posttext_link_color.'">';
1587 $cff_video_name .= htmlspecialchars($news->name);
1588 if (!$cff_title_link) $cff_video_name .= '</a>';
1589 $cff_video_name .= '<br />';
1590
1591 //Only show the video name if there's no post text
1592 if( empty($post_text_message) || $post_text_message == '' || strlen($post_text_message) < 1 ){
1593
1594 //If there's no description then show the video name above the post text, otherwise we'll show it below
1595 if( empty($cff_description) || $cff_description == '' ) $post_text = $cff_video_name;
1596
1597 }
1598 }
1599 }
1600
1601 //Add the story and message together
1602 $post_text = '';
1603
1604 //DESCRIPTION
1605 $cff_description = '';
1606 if ( !empty($news->description) || !empty($news->caption) ) {
1607 $description_text = '';
1608
1609 if ( !empty($news->description) ) {
1610 $description_text = $news->description;
1611 }
1612
1613 //Replace ellipsis char in description text
1614 $description_text = str_replace( '','...', $description_text);
1615
1616 //If the description is the same as the post text then don't show it
1617 if( $description_text == $cff_story_raw || $description_text == $cff_message_raw || $description_text == $cff_name_raw ){
1618 $cff_description = '';
1619 } else {
1620 //Add links and create HTML
1621 $cff_description .= '<span class="cff-post-desc" '.$cff_body_styles.'>';
1622
1623 if ($cff_title_link) {
1624 $cff_description_tagged = cff_wrap_span( htmlspecialchars($description_text) );
1625 } else {
1626 $cff_description_text = cff_autolink( htmlspecialchars($description_text), $link_color=$cff_posttext_link_color );
1627 $cff_description_tagged = cff_desc_tags($cff_description_text);
1628 }
1629
1630 $cff_description .= $cff_description_tagged;
1631 $cff_description .= ' </span>';
1632 }
1633
1634 if( $cff_post_type == 'event' || $cff_is_video_embed || $cff_soundcloud ) $cff_description = '';
1635 }
1636
1637 //Add the message
1638 if($cff_show_text) $post_text .= $post_text_message;
1639
1640 //If it's a shared video post then add the video name after the post text above the video description so it's all one chunk
1641 if ($cff_post_type == 'video'){
1642 if( !empty($cff_description) && $cff_description != '' ){
1643 if( (!empty($post_text) && $post_text != '') && !empty($cff_video_name) ) $post_text .= '<br /><br />';
1644 $post_text .= $cff_video_name;
1645 }
1646 }
1647
1648
1649 //Use the name
1650 if (!empty($news->name) && empty($news->message)) {
1651 $cff_name_raw = $news->name;
1652 $post_text = htmlspecialchars($cff_name_raw);
1653 $cff_post_text_type = 'name';
1654 }
1655
1656 //OFFER TEXT
1657 if ($cff_post_type == 'offer'){
1658 isset($news->story) ? $post_text = htmlspecialchars($news->story) . '<br /><br />' : $post_text = '';
1659 $post_text .= htmlspecialchars($news->name);
1660 $cff_post_text_type = 'story';
1661 }
1662
1663 //Add the description
1664 if( $cff_show_desc && $cff_post_type != 'offer' && $cff_post_type != 'link' ) $post_text .= $cff_description;
1665
1666 //Change the linebreak element if the text issue setting is enabled
1667 $cff_format_issue = $atts['textissue'];
1668 ($cff_format_issue == 'true' || $cff_format_issue == 'on') ? $cff_format_issue = true : $cff_format_issue = false;
1669 $cff_linebreak_el = '<br />';
1670 if( $cff_format_issue ) $cff_linebreak_el = '<img class="cff-linebreak" />';
1671
1672 //EVENT
1673 $cff_event_has_cover_photo = false;
1674 $cff_event = '';
1675
1676
1677 //Create note
1678 if ($cff_post_type == 'note') {
1679
1680 // Get any existing copy of our transient data from previous versions
1681 $transient_name = 'cff_tle_' . $cff_post_id;
1682 $transient_name = substr($transient_name, 0, 45);
1683 if ( false !== ( $cff_note_json = get_transient( $transient_name ) ) ) {
1684 $cff_note_json = get_transient( $transient_name );
1685
1686 //Interpret data with JSON
1687 $cff_note_obj = json_decode($cff_note_json);
1688 $cff_note_object = $cff_note_obj->attachments->data[0];
1689 isset($cff_note_object->title) ? $cff_note_title = htmlentities($cff_note_object->title, ENT_QUOTES, 'UTF-8') : $cff_note_title = '';
1690 isset($cff_note_object->description) ? $cff_note_description = htmlentities($cff_note_object->description, ENT_QUOTES, 'UTF-8') : $cff_note_description = '';
1691 isset($cff_note_object->url) ? $cff_note_link = $cff_note_object->url : $cff_note_link = '';
1692 isset( $cff_note_object->media->image->src ) ? $cff_note_media_src = $cff_note_object->media->image->src : $cff_note_media_src = false;
1693 } else {
1694 $attachment_data = '';
1695 if(isset($news->attachments->data[0])){
1696 $attachment_data = $news->attachments->data[0];
1697 isset($attachment_data->title) ? $cff_note_title = htmlentities($attachment_data->title, ENT_QUOTES, 'UTF-8') : $cff_note_title = '';
1698 isset($attachment_data->description) ? $cff_note_description = htmlentities($attachment_data->description, ENT_QUOTES, 'UTF-8') : $cff_note_description = '';
1699 isset($attachment_data->unshimmed_url) ? $cff_note_link = $attachment_data->unshimmed_url : $cff_note_link = '';
1700 $cff_note_media_src = '';
1701 }
1702 }
1703
1704
1705 //Note details
1706 $cff_note = '<span class="cff-details">';
1707 $cff_note = '<span class="cff-note-title">'.$cff_note_title.'</span>';
1708 $cff_note .= $cff_note_description;
1709 $cff_note .= '</span>';
1710
1711 //Notes don't include any post text and so just replace the post text with the note content
1712 if($cff_show_text) $post_text = $cff_note;
1713 }
1714
1715
1716 //Create the HTML for the post text elemtent, if the post has text
1717 $cff_post_text = '';
1718
1719 if( !empty($post_text) ){
1720 $cff_post_text = '<' . $cff_title_format . ' class="cff-post-text" ' . $cff_title_styles . '>';
1721
1722 //Start HTML for post text
1723 $cff_post_text .= '<span class="cff-text" data-color="'.$cff_posttext_link_color.'">';
1724 if ($cff_title_link){
1725 //Link to the Facebook post if it's a link or a video;
1726 ($cff_post_type == 'link' || $cff_post_type == 'video') ? $text_link = "https://www.facebook.com/" . $page_id . "/posts/" . $PostID[1] : $text_link = $link;
1727
1728 $cff_post_text .= '<a class="cff-post-text-link" '.$cff_title_styles.' href="'.$text_link.'" '.$target.$cff_nofollow.'>';
1729 }
1730
1731 //Replace line breaks in text (needed for IE8 and to prevent lost line breaks in HTML minification)
1732 $post_text = preg_replace("/\r\n|\r|\n/",$cff_linebreak_el, $post_text);
1733
1734 //If the text is wrapped in a link then don't hyperlink any text within
1735 if ($cff_title_link) {
1736 //Remove links from text
1737 $result = preg_replace('/<a href=\"(.*?)\">(.*?)<\/a>/', "\\2", $post_text);
1738 //Wrap links in a span so we can break the text if it's too long
1739 $cff_post_text .= cff_wrap_span( $result ) . ' ';
1740 } else {
1741 //Don't use htmlspecialchars for post_text as it's added above so that it doesn't mess up the message_tag offsets
1742 $cff_post_text .= cff_autolink( $post_text ) . ' ';
1743 }
1744
1745 if ($cff_title_link) $cff_post_text .= '</a>';
1746 $cff_post_text .= '</span>';
1747 //'See More' link
1748 $cff_post_text .= '<span class="cff-expand">... <a href="#" style="color: #'.$cff_posttext_link_color.'"><span class="cff-more">' . $cff_see_more_text . '</span><span class="cff-less">' . $cff_see_less_text . '</span></a></span>';
1749 $cff_post_text .= '</' . $cff_title_format . '>';
1750
1751 //Facebook returns the text as "'s cover photo" for some reason, so ignore it
1752 if( $post_text == "'s cover photo" ) $cff_post_text = '';
1753 }
1754
1755 //Add a call to action button if included
1756 if( isset($news->call_to_action->value->link) ){
1757 $cff_cta_link = $news->call_to_action->value->link;
1758 //If it's not an absolute link then it means it's a relative Facebook one so prefix it with facebook.com
1759 if (strpos($cff_cta_link, 'http') === false) $cff_cta_link = 'https://facebook.com' . $cff_cta_link;
1760
1761 $cff_button_type = $news->call_to_action->type;
1762
1763 switch ($cff_button_type) {
1764 case 'SHOP_NOW':
1765 $cff_translate_shop_now_text = $atts['shopnowtext'];
1766 if (!isset($cff_translate_shop_now_text) || empty($cff_translate_shop_now_text)) $cff_translate_shop_now_text = 'Shop Now';
1767 $cff_cta_button_text = $cff_translate_shop_now_text;
1768 break;
1769 case 'MESSAGE_PAGE':
1770 $cff_translate_message_page_text = $atts['messagepage'];
1771 if (!isset($cff_translate_message_page_text) || empty($cff_translate_message_page_text)) $cff_translate_message_page_text = 'Message Page';
1772 $cff_cta_button_text = $cff_translate_message_page_text;
1773 break;
1774 case 'LEARN_MORE':
1775 $cff_translate_learn_more_text = $atts['learnmoretext'];
1776 if (!isset($cff_translate_learn_more_text) || empty($cff_translate_learn_more_text)) $cff_translate_learn_more_text = 'Learn More';
1777 $cff_cta_button_text = $cff_translate_learn_more_text;
1778 break;
1779 default:
1780 $cff_cta_button_text = ucwords(strtolower( str_replace('_',' ',$cff_button_type) ) );
1781 }
1782
1783 isset($news->call_to_action->value->app_link) ? $cff_app_link = $news->call_to_action->value->app_link : $cff_app_link = '';
1784 $cff_post_text .= '<p class="cff-cta-link" '.$cff_title_styles.'><a href="'.$cff_cta_link.'" target="_blank" data-app-link="'.$cff_app_link.'" style="color: #'.$cff_posttext_link_color.';" >'.$cff_cta_button_text.'</a></p>';
1785 }
1786
1787 //LINK
1788 $cff_shared_link = '';
1789 //Display shared link
1790 if ($cff_post_type == 'link' || $cff_soundcloud || $cff_is_video_embed) {
1791
1792 $cff_shared_link .= '<div class="cff-shared-link';
1793 if($cff_disable_link_box) $cff_shared_link .= ' cff-no-styles';
1794
1795 $cff_shared_link .= '" ';
1796
1797 if(!$cff_disable_link_box) $cff_shared_link .= $cff_link_box_styles;
1798 $cff_shared_link .= '>';
1799 $cff_link_image = '';
1800
1801 //Display link name and description
1802 $cff_shared_link .= '<div class="cff-text-link ';
1803 if (!$cff_link_image) $cff_shared_link .= 'cff-no-image';
1804 //The link title:
1805 if( isset($news->name) ) $cff_shared_link .= '"><'.$cff_link_title_format.' class="cff-link-title" '.$cff_link_title_styles.'><a href="'.$link.'" '.$target.$cff_nofollow.' style="color:#' . $cff_link_title_color . ';">'. $news->name . '</a></'.$cff_link_title_format.'>';
1806 //The link source:
1807 if( !empty($news->link) ){
1808 $cff_link_caption = htmlentities($news->link, ENT_QUOTES, 'UTF-8');
1809 $cff_link_caption_parts = explode('/', $cff_link_caption);
1810 if( isset($cff_link_caption_parts[2]) ) $cff_link_caption = $cff_link_caption_parts[2];
1811 } else {
1812 $cff_link_caption = '';
1813 }
1814
1815 //Shared link styles
1816 $cff_link_url_color_html = '';
1817 $cff_link_url_size_html = '';
1818 if( isset($cff_link_url_color) && !empty($cff_link_url_color) && $cff_link_url_color != '#' ) $cff_link_url_color_html = 'color: #'.str_replace('#', '', $cff_link_url_color).';';
1819 if( $cff_link_url_size != 'inherit' && !empty($cff_link_url_size) ) $cff_link_url_size_html = 'font-size:'.$cff_link_url_size.'px;';
1820
1821 $cff_link_styles_html = '';
1822 if( strlen($cff_link_url_color_html) > 1 || strlen($cff_link_url_size_html) > 1 ) $cff_link_styles_html = 'style="';
1823 if( strlen($cff_link_url_color_html) > 1 ) $cff_link_styles_html .= $cff_link_url_color_html;
1824 if( strlen($cff_link_url_size_html) > 1 ) $cff_link_styles_html .= $cff_link_url_size_html;
1825 if( strlen($cff_link_url_color_html) > 1 || strlen($cff_link_url_size_html) > 1 ) $cff_link_styles_html .= '"';
1826
1827 if(!empty($cff_link_caption)) $cff_shared_link .= '<p class="cff-link-caption" '.$cff_link_styles_html.'>'.$cff_link_caption.'</p>';
1828 if ($cff_show_desc) {
1829 //Truncate desc
1830 if (!empty($body_limit)) {
1831 if (strlen($description_text) > $body_limit) $description_text = substr($description_text, 0, $body_limit) . '...';
1832 }
1833
1834 //Shared link desc styles
1835 $cff_link_desc_color_html = '';
1836 $cff_link_desc_size_html = '';
1837 if( isset($cff_link_desc_color) && !empty($cff_link_desc_color) && $cff_link_desc_color != '#' ) $cff_link_desc_color_html = 'color: #'.str_replace('#', '', $cff_link_desc_color).';';
1838 if( $cff_link_desc_size != 'inherit' && !empty($cff_link_desc_size) ) $cff_link_desc_size_html = 'font-size:'.$cff_link_desc_size.'px;';
1839
1840 $cff_link_desc_styles_html = '';
1841 if( strlen($cff_link_desc_color_html) > 1 || strlen($cff_link_desc_size_html) > 1 ) $cff_link_desc_styles_html = 'style="';
1842 if( strlen($cff_link_desc_color_html) > 1 ) $cff_link_desc_styles_html .= $cff_link_desc_color_html;
1843 if( strlen($cff_link_desc_size_html) > 1 ) $cff_link_desc_styles_html .= $cff_link_desc_size_html;
1844 if( strlen($cff_link_desc_color_html) > 1 || strlen($cff_link_desc_size_html) > 1 ) $cff_link_desc_styles_html .= '"';
1845
1846 //Add links and create HTML
1847 $cff_link_description = '<span class="cff-post-desc" '.$cff_link_desc_styles_html.'>';
1848 if ($cff_title_link) {
1849 $cff_link_description .= cff_wrap_span( htmlspecialchars($description_text) );
1850 } else {
1851 $description_text = cff_autolink( htmlspecialchars($description_text), $link_color=$cff_posttext_link_color );
1852 //Replace line breaks with <br> tags
1853 $cff_link_description .= nl2br($description_text);
1854 }
1855 $cff_link_description .= ' </span>';
1856
1857
1858 if( $description_text != $cff_link_caption ) $cff_shared_link .= $cff_link_description;
1859 }
1860
1861 $cff_shared_link .= '</div></div>';
1862 }
1863
1864 /* VIDEO */
1865
1866 //Check to see whether it's an embedded video so that we can show the name above the post text if necessary
1867 $cff_is_video_embed = false;
1868 if ( $cff_post_type == 'video' && isset($news->source) ){
1869 $url = $news->source;
1870 //Embeddable video strings
1871 $youtube = 'youtube';
1872 $youtu = 'youtu';
1873 $vimeo = 'vimeo';
1874 $youtubeembed = 'youtube.com/embed';
1875 //Check whether it's a youtube video
1876 $youtube = stripos($url, $youtube);
1877 $youtu = stripos($url, $youtu);
1878 $youtubeembed = stripos($url, $youtubeembed);
1879 //Check whether it's a youtube video
1880 if($youtube || $youtu || $youtubeembed || (stripos($url, $vimeo) !== false)) {
1881 $cff_is_video_embed = true;
1882 }
1883 }
1884
1885
1886 $cff_media = '';
1887 if ($cff_post_type == 'video') {
1888 //Add the name to the description if it's a video embed
1889 if($cff_is_video_embed) {
1890 isset($news->name) ? $video_name = $news->name : $video_name = $link;
1891 isset($news->description) ? $description_text = $news->description : $description_text = '';
1892 //Add the 'cff-shared-link' class so that embedded videos display in a box
1893 $cff_description = '<div class="cff-desc-wrap cff-shared-link ';
1894 if (empty($picture)) $cff_description .= 'cff-no-image';
1895 if($cff_disable_link_box) $cff_description .= ' cff-no-styles"';
1896 if(!$cff_disable_link_box) $cff_description .= '" ' . $cff_link_box_styles;
1897 $cff_description .= '>';
1898
1899 if( isset($news->name) ) $cff_description .= '<'.$cff_link_title_format.' class="cff-link-title" '.$cff_link_title_styles.'><a href="'.$link.'" '.$target.$cff_nofollow.' style="color:#' . $cff_link_title_color . ';">'. $news->name . '</a></'.$cff_link_title_format.'>';
1900
1901 if (!empty($body_limit)) {
1902 if (strlen($description_text) > $body_limit) $description_text = substr($description_text, 0, $body_limit) . '...';
1903 }
1904
1905 $cff_description .= '<p class="cff-post-desc" '.$cff_body_styles.'><span>' . cff_autolink( htmlspecialchars($description_text) ) . '</span></p></div>';
1906 } else {
1907 isset($news->name) ? $video_name = $news->name : $video_name = $link;
1908 if( isset($news->name) ) $cff_description .= '<'.$cff_link_title_format.' class="cff-link-title" '.$cff_link_title_styles.'><a href="'.$link.'" '.$target.$cff_nofollow.' style="color:#' . $cff_link_title_color . ';">'. $news->name . '</a></'.$cff_link_title_format.'>';
1909 }
1910 }
1911
1912
1913 //Display the link to the Facebook post or external link
1914 $cff_link = '';
1915 //Default link
1916 $cff_viewpost_class = 'cff-viewpost-facebook';
1917 if ($cff_facebook_link_text == '') $cff_facebook_link_text = 'View on Facebook';
1918 $link_text = $cff_facebook_link_text;
1919
1920 //Link to the Facebook post if it's a link or a video
1921 if($cff_post_type == 'link' || $cff_post_type == 'video') $link = "https://www.facebook.com/" . $page_id . "/posts/" . $PostID[1];
1922
1923 //Social media sharing URLs
1924 $cff_share_facebook = 'https://www.facebook.com/sharer/sharer.php?u=' . urlencode($link);
1925 $cff_share_twitter = 'https://twitter.com/intent/tweet?text=' . urlencode($link);
1926 $cff_share_google = 'https://plus.google.com/share?url=' . urlencode($link);
1927 $cff_share_linkedin = 'https://www.linkedin.com/shareArticle?mini=true&amp;url=' . urlencode($link) . '&amp;title=' . rawurlencode( strip_tags($cff_post_text) );
1928 $cff_share_email = 'mailto:?subject=Facebook&amp;body=' . urlencode($link) . '%20-%20' . rawurlencode( strip_tags($cff_post_text) );
1929
1930 //If it's a shared post then change the link to use the Post ID so that it links to the shared post and not the original post that's being shared
1931 if( isset($news->status_type) ){
1932 if( $news->status_type == 'shared_story' ) $link = "https://www.facebook.com/" . $cff_post_id;
1933 }
1934
1935 //If it's an offer post then change the text
1936 if ($cff_post_type == 'offer') $link_text = 'View Offer';
1937
1938 //Create post action links HTML
1939 $cff_link = '';
1940 if($cff_show_facebook_link || $cff_show_facebook_share){
1941 $cff_link .= '<div class="cff-post-links">';
1942
1943 //View on Facebook link
1944 if($cff_show_facebook_link) $cff_link .= '<a class="' . $cff_viewpost_class . '" href="' . $link . '" title="' . $link_text . '" ' . $target . $cff_nofollow . ' ' . $cff_link_styles . '>' . $link_text . '</a>';
1945
1946 //Share link
1947 if($cff_show_facebook_share){
1948 $cff_link .= '<div class="cff-share-container">';
1949 //Only show separating dot if both links are enabled
1950 if($cff_show_facebook_link) $cff_link .= '<span class="cff-dot" ' . $cff_link_styles . '>&middot;</span>';
1951 $cff_link .= '<a class="cff-share-link" href="'.$cff_share_facebook.'" title="' . $cff_facebook_share_text . '" ' . $cff_link_styles . '>' . $cff_facebook_share_text . '</a>';
1952 $cff_link .= "<p class='cff-share-tooltip'><a href='".$cff_share_facebook."' target='_blank' class='cff-facebook-icon'><span class='fa fab fa-facebook-square' aria-hidden='true'></span><span class='cff-screenreader'>Share on Facebook</span></a><a href='".$cff_share_twitter."' target='_blank' class='cff-twitter-icon'><span class='fa fab fa-twitter' aria-hidden='true'></span><span class='cff-screenreader'>Share on Twitter</span></a><a href='".$cff_share_linkedin."' target='_blank' class='cff-linkedin-icon'><span class='fa fab fa-linkedin' aria-hidden='true'></span><span class='cff-screenreader'>Share on Linked In</span></a><a href='".$cff_share_email."' target='_blank' class='cff-email-icon'><span class='fa fa-envelope' aria-hidden='true'></span><span class='cff-screenreader'>Share by Email</span></a><span class='fa fa-play fa-rotate-90' aria-hidden='true'></span></p></div>";
1953 }
1954
1955 $cff_link .= '</div>';
1956 }
1957
1958
1959 /* MEDIA LINK */
1960 $cff_translate_photo_text = $atts['phototext'];
1961 if (!isset($cff_translate_photo_text) || empty($cff_translate_photo_text)) $cff_translate_photo_text = 'Photo';
1962 $cff_translate_video_text = $atts['videotext'];
1963 if (!isset($cff_translate_video_text) || empty($cff_translate_video_text)) $cff_translate_video_text = 'Video';
1964
1965 $cff_media_link = '';
1966
1967 if( $cff_show_media_link && ($cff_post_type == 'photo' || $cff_post_type == 'video' || $cff_album) ){
1968 $cff_media_link .= '<p class="cff-media-link"><a href="'.$link.'" '.$target.' style="color: #'.$cff_posttext_link_color.';"><span style="padding-right: 5px;" class="fa fas fa-';
1969 if($cff_post_type == 'photo' || $cff_album) $cff_media_link .= 'picture-o fa-image" aria-hidden="true"></span>'. $cff_translate_photo_text;
1970 // if($cff_post_type == 'video') $cff_media_link .= 'file-video-o';
1971 if($cff_post_type == 'video') $cff_media_link .= 'video-camera fa-video" aria-hidden="true"></span>'. $cff_translate_video_text;
1972 $cff_media_link .= '</a></p>';
1973 }
1974
1975 //**************************//
1976 //***CREATE THE POST HTML***//
1977 //**************************//
1978 //Start the container
1979 $cff_post_item = '<div class="cff-item ';
1980 $cff_post_type_class = 'cff-status-post';
1981 if ($cff_post_type == 'link') $cff_post_type_class = 'cff-link-item';
1982 if ($cff_post_type == 'event') $cff_post_type_class = 'cff-timeline-event';
1983 if ($cff_post_type == 'photo') $cff_post_type_class = 'cff-photo-post';
1984 if ($cff_post_type == 'video') $cff_post_type_class = 'cff-video-post';
1985 if ($cff_post_type == 'swf') $cff_post_type_class = 'cff-swf-post';
1986 if ($cff_post_type == 'offer') $cff_post_type_class = 'cff-offer-post';
1987 $cff_post_item .= $cff_post_type_class;
1988 if ($cff_album) $cff_post_item .= ' cff-album';
1989
1990 if ($cff_post_bg_color_check || $cff_post_style == "boxed") $cff_post_item .= ' cff-box';
1991 if( $cff_box_shadow ) $cff_post_item .= ' cff-shadow';
1992 if(isset($news->from->name)) $cff_post_item .= ' author-'. cff_to_slug($news->from->name);
1993 $cff_post_item .= '" id="cff_'. $cff_post_id .'" ' . $cff_item_styles . '>';
1994
1995 //POST AUTHOR
1996 if($cff_show_author) $cff_post_item .= $cff_author;
1997 //DATE ABOVE
1998 if ($cff_show_date && $cff_date_position == 'above') $cff_post_item .= $cff_date;
1999 //POST TEXT
2000 if($cff_show_text || $cff_show_desc) $cff_post_item .= $cff_post_text;
2001 //LINK
2002 if($cff_show_shared_links) $cff_post_item .= $cff_shared_link;
2003 //DATE BELOW
2004 if ( (!$cff_show_author && $cff_date_position == 'author') || $cff_show_date && $cff_date_position == 'below') {
2005 if($cff_show_date && $cff_post_type !== 'event') $cff_post_item .= $cff_date;
2006 }
2007 //DATE BELOW (only for Event posts)
2008 if ( (!$cff_show_author && $cff_date_position == 'author') || $cff_show_date && $cff_date_position == 'below') {
2009 if($cff_show_date && $cff_post_type == 'event') $cff_post_item .= $cff_date;
2010 }
2011
2012 //MEDIA LINK
2013 if($cff_show_media_link) $cff_post_item .= $cff_media_link;
2014 //VIEW ON FACEBOOK LINK
2015 if($cff_show_link) $cff_post_item .= $cff_link;
2016
2017 //End the post item
2018 $cff_post_item .= '</div>';
2019
2020 //PUSH TO ARRAY
2021 $cff_posts_array = cff_array_push_assoc($cff_posts_array, $i_post, $cff_post_item);
2022
2023 } // End post type check
2024
2025 if (isset($news->message)) $prev_post_message = $news->message;
2026 if (isset($news->link)) $prev_post_link = $news->link;
2027 if (isset($news->description)) $prev_post_description = $news->description;
2028
2029 } // End the loop
2030 } //End isset($FBdata->data)
2031
2032 //Sort the array in reverse order (newest first)
2033 if(!$cff_is_group) ksort($cff_posts_array);
2034
2035 } // End ALL POSTS
2036
2037
2038 //Output the posts array
2039 $p = 0;
2040 foreach ($cff_posts_array as $post ) {
2041 if ( $p == $show_posts ) break;
2042 $cff_content .= $post;
2043 $p++;
2044 }
2045
2046 //Add the Like Box inside
2047 if ($cff_like_box_position == 'bottom' && $cff_show_like_box && !$cff_like_box_outside) $cff_content .= $like_box;
2048 /* Credit link */
2049 $cff_show_credit = $atts['credit'];
2050 ($cff_show_credit == 'true' || $cff_show_credit == 'on') ? $cff_show_credit = true : $cff_show_credit = false;
2051
2052 if($cff_show_credit) $cff_content .= '<p class="cff-credit"><a href="https://smashballoon.com/custom-facebook-feed/" target="_blank" style="color: #'.$link_color=$cff_posttext_link_color.'" title="Smash Balloon Custom Facebook Feed WordPress Plugin"><img src="'.plugins_url( '/img/smashballoon-tiny.png' , __FILE__ ).'" alt="Smash Balloon Custom Facebook Feed WordPress Plugin" />The Custom Facebook Feed plugin</a></p>';
2053 //End the feed
2054 $cff_content .= '</div><div class="cff-clear"></div>';
2055 //Add the Like Box outside
2056 if ($cff_like_box_position == 'bottom' && $cff_show_like_box && $cff_like_box_outside) $cff_content .= $like_box;
2057
2058 //If the feed is loaded via Ajax then put the scripts into the shortcode itself
2059 $ajax_theme = $atts['ajax'];
2060 ( $ajax_theme == 'on' || $ajax_theme == 'true' || $ajax_theme == true ) ? $ajax_theme = true : $ajax_theme = false;
2061 if( $atts[ 'ajax' ] == 'false' ) $ajax_theme = false;
2062 if ($ajax_theme) {
2063 //Minify files?
2064 $options = get_option('cff_style_settings');
2065 isset($options[ 'cff_minify' ]) ? $cff_minify = $options[ 'cff_minify' ] : $cff_minify = '';
2066 $cff_minify ? $cff_min = '.min' : $cff_min = '';
2067
2068 $cff_link_hashtags = $atts['linkhashtags'];
2069 ($cff_link_hashtags == 'true' || $cff_link_hashtags == 'on') ? $cff_link_hashtags = 'true' : $cff_link_hashtags = 'false';
2070 if($cff_title_link == 'true' || $cff_title_link == 'on') $cff_link_hashtags = 'false';
2071 $cff_content .= '<script type="text/javascript">var cfflinkhashtags = "' . $cff_link_hashtags . '";</script>';
2072 $cff_content .= '<script type="text/javascript" src="' . plugins_url( '/js/cff-scripts'.$cff_min.'.js?ver='.CFFVER , __FILE__ ) . '"></script>';
2073 }
2074
2075 $cff_content .= '</div>';
2076
2077 if( isset( $cff_posttext_link_color ) && !empty( $cff_posttext_link_color ) ) $cff_content .= '<style>#cff .cff-post-text a{ color: #'.$cff_posttext_link_color.'; }</style>';
2078
2079 //Return our feed HTML to display
2080 return $cff_content;
2081 }
2082
2083 //***FUNCTIONS***
2084
2085 //Link @[] or \u0040[Page ID:274:Page Name] post tagging format
2086 function cff_desc_tags($description){
2087 preg_match_all( "/@\[(.*?)\]/", $description, $cff_tag_matches );
2088 $replace_strings_arr = array();
2089 foreach ( $cff_tag_matches[1] as $cff_tag_match ) {
2090 $cff_tag_parts = explode( ':', $cff_tag_match );
2091 $replace_strings_arr[] = '<a href="https://facebook.com/'.$cff_tag_parts[0].'">'.$cff_tag_parts[2].'</a>';
2092 }
2093 $cff_tag_iterator = 0;
2094 $cff_description_tagged = '';
2095 $cff_text_split = preg_split( "/@\[(.*?)\]/" , $description );
2096 foreach ( $cff_text_split as $cff_desc_split ) {
2097 if ( $cff_tag_iterator < count( $replace_strings_arr ) ) {
2098 $cff_description_tagged .= $cff_desc_split . $replace_strings_arr[ $cff_tag_iterator ];
2099 } else {
2100 $cff_description_tagged .= $cff_desc_split;
2101 }
2102 $cff_tag_iterator++;
2103 }
2104
2105 return $cff_description_tagged;
2106 }
2107 //Sort message tags by offset value
2108 function cffSortTags($a, $b) {
2109 return $a['offset'] - $b['offset'];
2110 }
2111
2112 //Get JSON object of feed data
2113 function cff_fetchUrl($url){
2114 $response = wp_remote_get($url);
2115 $feedData = wp_remote_retrieve_body( $response );
2116
2117 $feedData = apply_filters( 'cff_filter_api_data', $feedData );
2118
2119 return $feedData;
2120 }
2121
2122 //Make links into span instead when the post text is made clickable
2123 function cff_wrap_span($text) {
2124 $pattern = '#\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#';
2125 return preg_replace_callback($pattern, 'cff_wrap_span_callback', $text);
2126 }
2127 function cff_wrap_span_callback($matches) {
2128 $max_url_length = 100;
2129 $max_depth_if_over_length = 2;
2130 $ellipsis = '&hellip;';
2131 $target = 'target="_blank"';
2132 $url_full = $matches[0];
2133 $url_short = '';
2134 if (strlen($url_full) > $max_url_length) {
2135 $parts = parse_url($url_full);
2136 $url_short = $parts['scheme'] . '://' . preg_replace('/^www\./', '', $parts['host']) . '/';
2137 $path_components = explode('/', trim($parts['path'], '/'));
2138 foreach ($path_components as $dir) {
2139 $url_string_components[] = $dir . '/';
2140 }
2141 if (!empty($parts['query'])) {
2142 $url_string_components[] = '?' . $parts['query'];
2143 }
2144 if (!empty($parts['fragment'])) {
2145 $url_string_components[] = '#' . $parts['fragment'];
2146 }
2147 for ($k = 0; $k < count($url_string_components); $k++) {
2148 $curr_component = $url_string_components[$k];
2149 if ($k >= $max_depth_if_over_length || strlen($url_short) + strlen($curr_component) > $max_url_length) {
2150 if ($k == 0 && strlen($url_short) < $max_url_length) {
2151 // Always show a portion of first directory
2152 $url_short .= substr($curr_component, 0, $max_url_length - strlen($url_short));
2153 }
2154 $url_short .= $ellipsis;
2155 break;
2156 }
2157 $url_short .= $curr_component;
2158 }
2159 } else {
2160 $url_short = $url_full;
2161 }
2162 return "<span class='cff-break-word'>$url_short</span>";
2163 }
2164
2165 //Use the timezone to offset the date as all post dates are in UTC +0000
2166 function cff_set_timezone($original, $cff_timezone){
2167 $cff_date_time = new DateTime(date('m/d g:i a'), new DateTimeZone('UTC'));
2168 $cff_date_time->setTimeZone(new DateTimeZone($cff_timezone));
2169 $cff_date_time_offset = $cff_date_time->getOffset();
2170
2171 $original = $original + $cff_date_time_offset;
2172
2173 return $original;
2174 }
2175 //Time stamp function - used for posts
2176 function cff_getdate($original, $date_format, $custom_date, $cff_date_translate_strings, $cff_timezone) {
2177
2178 //Offset the date by the timezone
2179 $new_time = cff_set_timezone($original, $cff_timezone);
2180
2181 switch ($date_format) {
2182
2183 case '2':
2184 $print = date_i18n('F jS, g:i a', $new_time);
2185 break;
2186 case '3':
2187 $print = date_i18n('F jS', $new_time);
2188 break;
2189 case '4':
2190 $print = date_i18n('D F jS', $new_time);
2191 break;
2192 case '5':
2193 $print = date_i18n('l F jS', $new_time);
2194 break;
2195 case '6':
2196 $print = date_i18n('D M jS, Y', $new_time);
2197 break;
2198 case '7':
2199 $print = date_i18n('l F jS, Y', $new_time);
2200 break;
2201 case '8':
2202 $print = date_i18n('l F jS, Y - g:i a', $new_time);
2203 break;
2204 case '9':
2205 $print = date_i18n("l M jS, 'y", $new_time);
2206 break;
2207 case '10':
2208 $print = date_i18n('m.d.y', $new_time);
2209 break;
2210 case '11':
2211 $print = date_i18n('m/d/y', $new_time);
2212 break;
2213 case '12':
2214 $print = date_i18n('d.m.y', $new_time);
2215 break;
2216 case '13':
2217 $print = date_i18n('d/m/y', $new_time);
2218 break;
2219 default:
2220
2221 $cff_second = $cff_date_translate_strings['cff_translate_second'];
2222 $cff_seconds = $cff_date_translate_strings['cff_translate_seconds'];
2223 $cff_minute = $cff_date_translate_strings['cff_translate_minute'];
2224 $cff_minutes = $cff_date_translate_strings['cff_translate_minutes'];
2225 $cff_hour = $cff_date_translate_strings['cff_translate_hour'];
2226 $cff_hours = $cff_date_translate_strings['cff_translate_hours'];
2227 $cff_day = $cff_date_translate_strings['cff_translate_day'];
2228 $cff_days = $cff_date_translate_strings['cff_translate_days'];
2229 $cff_week = $cff_date_translate_strings['cff_translate_week'];
2230 $cff_weeks = $cff_date_translate_strings['cff_translate_weeks'];
2231 $cff_month = $cff_date_translate_strings['cff_translate_month'];
2232 $cff_months = $cff_date_translate_strings['cff_translate_months'];
2233 $cff_year = $cff_date_translate_strings['cff_translate_years'];
2234 $cff_years = $cff_date_translate_strings['cff_translate_years'];
2235 $cff_ago = $cff_date_translate_strings['cff_translate_ago'];
2236
2237
2238 $periods = array($cff_second, $cff_minute, $cff_hour, $cff_day, $cff_week, $cff_month, $cff_year, "decade");
2239 $periods_plural = array($cff_seconds, $cff_minutes, $cff_hours, $cff_days, $cff_weeks, $cff_months, $cff_years, "decade");
2240
2241 $lengths = array("60","60","24","7","4.35","12","10");
2242 $now = time();
2243
2244 // is it future date or past date
2245 if($now > $original) {
2246 $difference = $now - $original;
2247 $tense = $cff_ago;
2248 } else {
2249 $difference = $original - $now;
2250 $tense = $cff_ago;
2251 }
2252 for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
2253 $difference /= $lengths[$j];
2254 }
2255
2256 $difference = round($difference);
2257
2258 if($difference != 1) {
2259 $periods[$j] = $periods_plural[$j];
2260 }
2261 $print = "$difference $periods[$j] {$tense}";
2262
2263 break;
2264
2265 }
2266 if ( !empty($custom_date) ){
2267 $print = date_i18n($custom_date, $new_time);
2268 }
2269
2270 return $print;
2271 }
2272 function cff_eventdate($original, $date_format, $custom_date) {
2273 switch ($date_format) {
2274
2275 case '2':
2276 $print = date_i18n('F jS, g:ia', $original);
2277 break;
2278 case '3':
2279 $print = date_i18n('g:ia - F jS', $original);
2280 break;
2281 case '4':
2282 $print = date_i18n('g:ia, F jS', $original);
2283 break;
2284 case '5':
2285 $print = date_i18n('l F jS - g:ia', $original);
2286 break;
2287 case '6':
2288 $print = date_i18n('D M jS, Y, g:iA', $original);
2289 break;
2290 case '7':
2291 $print = date_i18n('l F jS, Y, g:iA', $original);
2292 break;
2293 case '8':
2294 $print = date_i18n('l F jS, Y - g:ia', $original);
2295 break;
2296 case '9':
2297 $print = date_i18n("l M jS, 'y", $original);
2298 break;
2299 case '10':
2300 $print = date_i18n('m.d.y - g:iA', $original);
2301 break;
2302 case '11':
2303 $print = date_i18n('m/d/y, g:ia', $original);
2304 break;
2305 case '12':
2306 $print = date_i18n('d.m.y - g:iA', $original);
2307 break;
2308 case '13':
2309 $print = date_i18n('d/m/y, g:ia', $original);
2310 break;
2311 default:
2312 $print = date_i18n('F j, Y, g:ia', $original);
2313 break;
2314 }
2315 if ( !empty($custom_date) ){
2316 $print = date_i18n($custom_date, $original);
2317 }
2318 return $print;
2319 }
2320 //Use custom stripos function if it's not available (only available in PHP 5+)
2321 if(!is_callable('stripos')){
2322 function stripos($haystack, $needle){
2323 return strpos($haystack, stristr( $haystack, $needle ));
2324 }
2325 }
2326 function cff_stripos_arr($haystack, $needle) {
2327 if(!is_array($needle)) $needle = array($needle);
2328 foreach($needle as $what) {
2329 if(($pos = stripos($haystack, ltrim($what) ))!==false) return $pos;
2330 }
2331 return false;
2332 }
2333 function cff_mb_substr_replace($string, $replacement, $start, $length=NULL) {
2334 if (is_array($string)) {
2335 $num = count($string);
2336 // $replacement
2337 $replacement = is_array($replacement) ? array_slice($replacement, 0, $num) : array_pad(array($replacement), $num, $replacement);
2338 // $start
2339 if (is_array($start)) {
2340 $start = array_slice($start, 0, $num);
2341 foreach ($start as $key => $value)
2342 $start[$key] = is_int($value) ? $value : 0;
2343 }
2344 else {
2345 $start = array_pad(array($start), $num, $start);
2346 }
2347 // $length
2348 if (!isset($length)) {
2349 $length = array_fill(0, $num, 0);
2350 }
2351 elseif (is_array($length)) {
2352 $length = array_slice($length, 0, $num);
2353 foreach ($length as $key => $value)
2354 $length[$key] = isset($value) ? (is_int($value) ? $value : $num) : 0;
2355 }
2356 else {
2357 $length = array_pad(array($length), $num, $length);
2358 }
2359 // Recursive call
2360 return array_map(__FUNCTION__, $string, $replacement, $start, $length);
2361 }
2362 preg_match_all('/./us', (string)$string, $smatches);
2363 preg_match_all('/./us', (string)$replacement, $rmatches);
2364 if ($length === NULL) $length = mb_strlen($string);
2365 array_splice($smatches[0], $start, $length, $rmatches[0]);
2366 return join($smatches[0]);
2367 }
2368
2369 //Push to assoc array
2370 function cff_array_push_assoc($array, $key, $value){
2371 $array[$key] = $value;
2372 return $array;
2373 }
2374 //Convert string to slug
2375 function cff_to_slug($string){
2376 return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string)));
2377 }
2378
2379
2380 //Allows shortcodes in theme
2381 add_filter('widget_text', 'do_shortcode');
2382
2383 //Enqueue stylesheet
2384 add_action( 'wp_enqueue_scripts', 'cff_add_my_stylesheet' );
2385 function cff_add_my_stylesheet() {
2386
2387 //Minify files?
2388 $options = get_option('cff_style_settings');
2389 isset($options[ 'cff_minify' ]) ? $cff_minify = $options[ 'cff_minify' ] : $cff_minify = '';
2390 $cff_minify ? $cff_min = '.min' : $cff_min = '';
2391
2392 // Respects SSL, Style.css is relative to the current file
2393 wp_register_style( 'cff', plugins_url('css/cff-style'.$cff_min.'.css', __FILE__), array(), CFFVER );
2394 wp_enqueue_style( 'cff' );
2395
2396 $options = get_option('cff_style_settings');
2397
2398 if( !isset( $options[ 'cff_font_source' ] ) ){
2399 wp_enqueue_style( 'sb-font-awesome', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css' );
2400 } else {
2401
2402 if( $options[ 'cff_font_source' ] == 'none' ){
2403 //Do nothing
2404 } else if( $options[ 'cff_font_source' ] == 'local' ){
2405 wp_enqueue_style( 'sb-font-awesome', plugins_url('css/font-awesome.min.css', __FILE__), array(), '4.7.0' );
2406 } else {
2407 wp_enqueue_style( 'sb-font-awesome', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css' );
2408 }
2409
2410 }
2411
2412
2413 }
2414 //Enqueue scripts
2415 add_action( 'wp_enqueue_scripts', 'cff_scripts_method' );
2416 function cff_scripts_method() {
2417
2418 //Minify files?
2419 $options = get_option('cff_style_settings');
2420 isset($options[ 'cff_minify' ]) ? $cff_minify = $options[ 'cff_minify' ] : $cff_minify = '';
2421 $cff_minify ? $cff_min = '.min' : $cff_min = '';
2422
2423 //Register the script to make it available
2424 wp_register_script( 'cffscripts', plugins_url( '/js/cff-scripts'.$cff_min.'.js' , __FILE__ ), array('jquery'), CFFVER, true );
2425 //Enqueue it to load it onto the page
2426 wp_enqueue_script('cffscripts');
2427 }
2428
2429 function cff_activate() {
2430 $options = get_option('cff_style_settings');
2431
2432 //Show all post types
2433 $options[ 'cff_show_links_type' ] = true;
2434 $options[ 'cff_show_event_type' ] = true;
2435 $options[ 'cff_show_video_type' ] = true;
2436 $options[ 'cff_show_photos_type' ] = true;
2437 $options[ 'cff_show_status_type' ] = true;
2438 $options[ 'cff_show_albums_type' ] = true;
2439 $options[ 'cff_show_author' ] = true;
2440 $options[ 'cff_show_text' ] = true;
2441 $options[ 'cff_show_desc' ] = true;
2442 $options[ 'cff_show_shared_links' ] = true;
2443 $options[ 'cff_show_date' ] = true;
2444 $options[ 'cff_show_media' ] = true;
2445 $options[ 'cff_show_media_link' ] = true;
2446 $options[ 'cff_show_event_title' ] = true;
2447 $options[ 'cff_show_event_details' ] = true;
2448 $options[ 'cff_show_meta' ] = true;
2449 $options[ 'cff_show_link' ] = true;
2450 $options[ 'cff_show_like_box' ] = true;
2451 $options[ 'cff_show_facebook_link' ] = true;
2452 $options[ 'cff_show_facebook_share' ] = true;
2453 $options[ 'cff_event_title_link' ] = true;
2454
2455 update_option( 'cff_style_settings', $options );
2456
2457 get_option('cff_show_access_token');
2458 update_option( 'cff_show_access_token', true );
2459
2460 //Run cron twice daily when plugin is first activated for new users
2461 wp_schedule_event(time(), 'twicedaily', 'cff_cron_job');
2462 }
2463 register_activation_hook( __FILE__, 'cff_activate' );
2464
2465 function cff_deactivate() {
2466 wp_clear_scheduled_hook('cff_cron_job');
2467 }
2468 register_deactivation_hook(__FILE__, 'cff_deactivate');
2469
2470 //Uninstall
2471 function cff_uninstall()
2472 {
2473 if ( ! current_user_can( 'activate_plugins' ) )
2474 return;
2475
2476 //If the user is preserving the settings then don't delete them
2477 $cff_preserve_settings = get_option('cff_preserve_settings');
2478 if($cff_preserve_settings) return;
2479
2480 //Settings
2481 delete_option( 'cff_show_access_token' );
2482 delete_option( 'cff_access_token' );
2483 delete_option( 'cff_page_id' );
2484 delete_option( 'cff_num_show' );
2485 delete_option( 'cff_post_limit' );
2486 delete_option( 'cff_show_others' );
2487 delete_option( 'cff_cache_time' );
2488 delete_option( 'cff_cache_time_unit' );
2489 delete_option( 'cff_locale' );
2490 delete_option( 'cff_ajax' );
2491 delete_option( 'cff_preserve_settings' );
2492 //Style & Layout
2493 delete_option( 'cff_title_length' );
2494 delete_option( 'cff_body_length' );
2495 delete_option('cff_style_settings');
2496 }
2497 register_uninstall_hook( __FILE__, 'cff_uninstall' );
2498 add_action( 'wp_head', 'cff_custom_css' );
2499 function cff_custom_css() {
2500 $options = get_option('cff_style_settings');
2501 isset($options[ 'cff_custom_css' ]) ? $cff_custom_css = $options[ 'cff_custom_css' ] : $cff_custom_css = '';
2502
2503 if( !empty($cff_custom_css) ) echo "\r\n";
2504 if( !empty($cff_custom_css) ) echo '<!-- Custom Facebook Feed Custom CSS -->';
2505 if( !empty($cff_custom_css) ) echo "\r\n";
2506 if( !empty($cff_custom_css) ) echo '<style type="text/css">';
2507 if( !empty($cff_custom_css) ) echo "\r\n";
2508 if( !empty($cff_custom_css) ) echo stripslashes($cff_custom_css);
2509 if( !empty($cff_custom_css) ) echo "\r\n";
2510 if( !empty($cff_custom_css) ) echo '</style>';
2511 if( !empty($cff_custom_css) ) echo "\r\n";
2512 }
2513 add_action( 'wp_footer', 'cff_js' );
2514 function cff_js() {
2515 $options = get_option('cff_style_settings');
2516 $cff_custom_js = isset($options[ 'cff_custom_js' ]) ? $options[ 'cff_custom_js' ] : '';
2517
2518 //Link hashtags?
2519 isset($options[ 'cff_link_hashtags' ]) ? $cff_link_hashtags = $options[ 'cff_link_hashtags' ] : $cff_link_hashtags = 'true';
2520 ($cff_link_hashtags == 'true' || $cff_link_hashtags == 'on') ? $cff_link_hashtags = 'true' : $cff_link_hashtags = 'false';
2521
2522 //If linking the post text then don't link the hashtags
2523 isset($options[ 'cff_title_link' ]) ? $cff_title_link = $options[ 'cff_title_link' ] : $cff_title_link = false;
2524 ($cff_title_link == 'true' || $cff_title_link == 'on') ? $cff_title_link = true : $cff_title_link = false;
2525 if ($cff_title_link) $cff_link_hashtags = 'false';
2526
2527
2528 echo '<!-- Custom Facebook Feed JS -->';
2529 echo "\r\n";
2530 echo '<script type="text/javascript">';
2531 echo "\r\n";
2532 echo 'var cfflinkhashtags = "' . $cff_link_hashtags . '";';
2533 echo "\r\n";
2534 if( !empty($cff_custom_js) ) echo "jQuery( document ).ready(function($) {";
2535 if( !empty($cff_custom_js) ) echo "\r\n";
2536 if( !empty($cff_custom_js) ) echo stripslashes($cff_custom_js);
2537 if( !empty($cff_custom_js) ) echo "\r\n";
2538 if( !empty($cff_custom_js) ) echo "});";
2539 if( !empty($cff_custom_js) ) echo "\r\n";
2540 echo '</script>';
2541 echo "\r\n";
2542 }
2543
2544
2545
2546 //AUTOLINK
2547 $GLOBALS['autolink_options'] = array(
2548
2549 # Should http:// be visibly stripped from the front
2550 # of URLs?
2551 'strip_protocols' => true,
2552
2553 );
2554
2555 ####################################################################
2556
2557 function cff_autolink($text, $link_color='', $span_tag = false, $limit=100, $tagfill='class="cff-break-word"', $auto_title = true){
2558
2559 $text = cff_autolink_do($text, $link_color, '![a-z][a-z-]+://!i', $limit, $tagfill, $auto_title, $span_tag);
2560 $text = cff_autolink_do($text, $link_color, '!(mailto|skype):!i', $limit, $tagfill, $auto_title, $span_tag);
2561 $text = cff_autolink_do($text, $link_color, '!www\\.!i', $limit, $tagfill, $auto_title, 'http://', $span_tag);
2562 return $text;
2563 }
2564
2565 ####################################################################
2566
2567 function cff_autolink_do($text, $link_color, $sub, $limit, $tagfill, $auto_title, $span_tag, $force_prefix=null){
2568
2569 $text_l = StrToLower($text);
2570 $cursor = 0;
2571 $loop = 1;
2572 $buffer = '';
2573
2574 while (($cursor < strlen($text)) && $loop){
2575
2576 $ok = 1;
2577 $matched = preg_match($sub, $text_l, $m, PREG_OFFSET_CAPTURE, $cursor);
2578
2579 if (!$matched){
2580
2581 $loop = 0;
2582 $ok = 0;
2583
2584 }else{
2585
2586 $pos = $m[0][1];
2587 $sub_len = strlen($m[0][0]);
2588
2589 $pre_hit = substr($text, $cursor, $pos-$cursor);
2590 $hit = substr($text, $pos, $sub_len);
2591 $pre = substr($text, 0, $pos);
2592 $post = substr($text, $pos + $sub_len);
2593
2594 $fail_text = $pre_hit.$hit;
2595 $fail_len = strlen($fail_text);
2596
2597 #
2598 # substring found - first check to see if we're inside a link tag already...
2599 #
2600
2601 $bits = preg_split("!</a>!i", $pre);
2602 $last_bit = array_pop($bits);
2603 if (preg_match("!<a\s!i", $last_bit)){
2604
2605 #echo "fail 1 at $cursor<br />\n";
2606
2607 $ok = 0;
2608 $cursor += $fail_len;
2609 $buffer .= $fail_text;
2610 }
2611 }
2612
2613 #
2614 # looks like a nice spot to autolink from - check the pre
2615 # to see if there was whitespace before this match
2616 #
2617
2618 if ($ok){
2619
2620 if ($pre){
2621 if (!preg_match('![\s\(\[\{>]$!s', $pre)){
2622
2623 #echo "fail 2 at $cursor ($pre)<br />\n";
2624
2625 $ok = 0;
2626 $cursor += $fail_len;
2627 $buffer .= $fail_text;
2628 }
2629 }
2630 }
2631
2632 #
2633 # we want to autolink here - find the extent of the url
2634 #
2635
2636 if ($ok){
2637 if (preg_match('/^([a-z0-9\-\.\/\-_%~!?=,:;&+*#@\(\)\$]+)/i', $post, $matches)){
2638
2639 $url = $hit.$matches[1];
2640
2641 $cursor += strlen($url) + strlen($pre_hit);
2642 $buffer .= $pre_hit;
2643
2644 $url = html_entity_decode($url);
2645
2646
2647 #
2648 # remove trailing punctuation from url
2649 #
2650
2651 while (preg_match('|[.,!;:?]$|', $url)){
2652 $url = substr($url, 0, strlen($url)-1);
2653 $cursor--;
2654 }
2655 foreach (array('()', '[]', '{}') as $pair){
2656 $o = substr($pair, 0, 1);
2657 $c = substr($pair, 1, 1);
2658 if (preg_match("!^(\\$c|^)[^\\$o]+\\$c$!", $url)){
2659 $url = substr($url, 0, strlen($url)-1);
2660 $cursor--;
2661 }
2662 }
2663
2664
2665 #
2666 # nice-i-fy url here
2667 #
2668
2669 $link_url = $url;
2670 $display_url = $url;
2671
2672 if ($force_prefix) $link_url = $force_prefix.$link_url;
2673
2674 if ($GLOBALS['autolink_options']['strip_protocols']){
2675 if (preg_match('!^(http|https)://!i', $display_url, $m)){
2676
2677 $display_url = substr($display_url, strlen($m[1])+3);
2678 }
2679 }
2680
2681 $display_url = cff_autolink_label($display_url, $limit);
2682
2683
2684 #
2685 # add the url
2686 #
2687
2688 if ($display_url != $link_url && !preg_match('@title=@msi',$tagfill) && $auto_title) {
2689
2690 $display_quoted = preg_quote($display_url, '!');
2691
2692 if (!preg_match("!^(http|https)://{$display_quoted}$!i", $link_url)){
2693
2694 $tagfill .= ' title="'.$link_url.'"';
2695 }
2696 }
2697
2698 $link_url_enc = HtmlSpecialChars($link_url);
2699 $display_url_enc = HtmlSpecialChars($display_url);
2700
2701
2702 if( substr( $link_url_enc, 0, 4 ) !== "http" ) $link_url_enc = 'http://' . $link_url_enc;
2703 $buffer .= "<a href=\"{$link_url_enc}\">{$display_url_enc}</a>";
2704
2705
2706 }else{
2707 #echo "fail 3 at $cursor<br />\n";
2708
2709 $ok = 0;
2710 $cursor += $fail_len;
2711 $buffer .= $fail_text;
2712 }
2713 }
2714
2715 }
2716
2717 #
2718 # add everything from the cursor to the end onto the buffer.
2719 #
2720
2721 $buffer .= substr($text, $cursor);
2722
2723 return $buffer;
2724 }
2725
2726 ####################################################################
2727
2728 function cff_autolink_label($text, $limit){
2729
2730 if (!$limit){ return $text; }
2731
2732 if (strlen($text) > $limit){
2733 return substr($text, 0, $limit-3).'...';
2734 }
2735
2736 return $text;
2737 }
2738
2739 ####################################################################
2740
2741 function cff_autolink_email($text, $tagfill=''){
2742
2743 $atom = '[^()<>@,;:\\\\".\\[\\]\\x00-\\x20\\x7f]+'; # from RFC822
2744
2745 #die($atom);
2746
2747 $text_l = StrToLower($text);
2748 $cursor = 0;
2749 $loop = 1;
2750 $buffer = '';
2751
2752 while(($cursor < strlen($text)) && $loop){
2753
2754 #
2755 # find an '@' symbol
2756 #
2757
2758 $ok = 1;
2759 $pos = strpos($text_l, '@', $cursor);
2760
2761 if ($pos === false){
2762
2763 $loop = 0;
2764 $ok = 0;
2765
2766 }else{
2767
2768 $pre = substr($text, $cursor, $pos-$cursor);
2769 $hit = substr($text, $pos, 1);
2770 $post = substr($text, $pos + 1);
2771
2772 $fail_text = $pre.$hit;
2773 $fail_len = strlen($fail_text);
2774
2775 #die("$pre::$hit::$post::$fail_text");
2776
2777 #
2778 # substring found - first check to see if we're inside a link tag already...
2779 #
2780
2781 $bits = preg_split("!</a>!i", $pre);
2782 $last_bit = array_pop($bits);
2783 if (preg_match("!<a\s!i", $last_bit)){
2784
2785 #echo "fail 1 at $cursor<br />\n";
2786
2787 $ok = 0;
2788 $cursor += $fail_len;
2789 $buffer .= $fail_text;
2790 }
2791 }
2792
2793 #
2794 # check backwards
2795 #
2796
2797 if ($ok){
2798 if (preg_match("!($atom(\.$atom)*)\$!", $pre, $matches)){
2799
2800 # move matched part of address into $hit
2801
2802 $len = strlen($matches[1]);
2803 $plen = strlen($pre);
2804
2805 $hit = substr($pre, $plen-$len).$hit;
2806 $pre = substr($pre, 0, $plen-$len);
2807
2808 }else{
2809
2810 #echo "fail 2 at $cursor ($pre)<br />\n";
2811
2812 $ok = 0;
2813 $cursor += $fail_len;
2814 $buffer .= $fail_text;
2815 }
2816 }
2817
2818 #
2819 # check forwards
2820 #
2821
2822 if ($ok){
2823 if (preg_match("!^($atom(\.$atom)*)!", $post, $matches)){
2824
2825 # move matched part of address into $hit
2826
2827 $len = strlen($matches[1]);
2828
2829 $hit .= substr($post, 0, $len);
2830 $post = substr($post, $len);
2831
2832 }else{
2833 #echo "fail 3 at $cursor ($post)<br />\n";
2834
2835 $ok = 0;
2836 $cursor += $fail_len;
2837 $buffer .= $fail_text;
2838 }
2839 }
2840
2841 #
2842 # commit
2843 #
2844
2845 if ($ok) {
2846
2847 $cursor += strlen($pre) + strlen($hit);
2848 $buffer .= $pre;
2849 $buffer .= "<a href=\"mailto:$hit\"$tagfill>$hit</a>";
2850
2851 }
2852
2853 }
2854
2855 #
2856 # add everything from the cursor to the end onto the buffer.
2857 #
2858
2859 $buffer .= substr($text, $cursor);
2860
2861 return $buffer;
2862 }
2863
2864 ####################################################################
2865
2866
2867 ?>