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