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