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