PluginProbe ʕ •ᴥ•ʔ
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress / 4.1.5
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress v4.1.5
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 / inc / CFF_Shortcode.php
custom-facebook-feed / inc Last commit date
Admin 3 years ago Builder 3 years ago Helpers 3 years ago CFF_Autolink.php 3 years ago CFF_Blocks.php 3 years ago CFF_Cache.php 3 years ago CFF_Education.php 3 years ago CFF_Elementor_Base.php 3 years ago CFF_Elementor_Widget.php 3 years ago CFF_Error_Reporter.php 3 years ago CFF_FB_Settings.php 3 years ago CFF_Feed_Elementor_Control.php 3 years ago CFF_Feed_Locator.php 3 years ago CFF_Feed_Pro.php 3 years ago CFF_GDPR_Integrations.php 3 years ago CFF_Group_Posts.php 3 years ago CFF_HTTP_Request.php 3 years ago CFF_Oembed.php 3 years ago CFF_Parse.php 3 years ago CFF_Resizer.php 3 years ago CFF_Response.php 3 years ago CFF_Shortcode.php 3 years ago CFF_Shortcode_Display.php 3 years ago CFF_SiteHealth.php 3 years ago CFF_Utils.php 3 years ago CFF_View.php 3 years ago Custom_Facebook_Feed.php 3 years ago SB_Facebook_Data_Encryption.php 3 years ago SB_Facebook_Data_Manager.php 3 years ago
CFF_Shortcode.php
2269 lines
1 <?php
2 /**
3 * Custom Facebook Feed Main Shortcode Class
4 *
5 * @since 2.19
6 */
7
8 namespace CustomFacebookFeed;
9
10 use CustomFacebookFeed\Builder\CFF_Source;
11 use CustomFacebookFeed\SB_Facebook_Data_Encryption;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 die( '-1' );
15 }
16
17 class CFF_Shortcode extends CFF_Shortcode_Display{
18
19 /**
20 * @var Class
21 */
22 protected $fb_feed_settings;
23
24 /**
25 * @var array
26 */
27 protected $atts;
28
29 /**
30 * @var array
31 */
32 protected $options;
33
34 /**
35 * @var id
36 */
37 protected $page_id;
38
39 /**
40 * @var string
41 */
42 protected $access_token;
43
44 /**
45 * @var string
46 */
47 protected $feed_id;
48
49
50 /**
51 * Shortcode constructor
52 *
53 * @since 2.19
54 */
55 public function __construct(){
56 $this->init();
57 }
58
59
60
61 /**
62 * Init.
63 *
64 * @since 2.19
65 */
66 public function init(){
67 add_shortcode('custom-facebook-feed', array($this, 'display_cff'));
68 }
69
70
71 /**
72 * Get JSON data
73 *
74 * Returns a list of posts JSON form the FaceBook API API
75 *
76 * @since 2.19
77 * @return JSON OBJECT
78 */
79 public function get_feed_json( $graph_query, $cff_post_limit, $cff_locale, $cff_show_access_token, $cache_seconds, $cff_cache_time, $show_posts_by, $data_att_html ){
80 //Is it SSL?
81 $cff_ssl = is_ssl() ? '&return_ssl_resources=true' : '';
82 $attachments_desc = ( $this->atts['salesposts'] == 'true' ) ? '' : ',description';
83 $story_tags = ( $this->atts['storytags'] == 'true' ) ? '' : ',story_tags';
84
85 $cff_posts_json_url = 'https://graph.facebook.com/v4.0/' . $this->page_id . '/' . $graph_query . '?fields=id,updated_time,from{picture,id,name,link},message,message_tags,story'. $story_tags .',status_type,created_time,backdated_time,call_to_action,attachments{title'. $attachments_desc . ',media_type,unshimmed_url,target{id},media{source}}&access_token=' . $this->access_token . '&limit=' . $cff_post_limit . '&locale=' . $cff_locale . $cff_ssl;
86 //Create the transient name
87 //Split the Page ID in half and stick it together so we definitely have the beginning and end of it
88 $trans_page_id = substr($this->page_id, 0, 16) . substr($this->page_id, -15);
89 $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);
90 //Limit to 45 chars max
91 $transient_name = substr($transient_name, 0, 45);
92
93 $posts_json = CFF_Utils::cff_get_set_cache( $cff_posts_json_url, $transient_name, $cff_cache_time, $cache_seconds, $data_att_html, false, $this->access_token, true );
94
95 return json_decode($posts_json);
96 }
97
98
99 /**
100 * Get Graph Query & (Show only by others)
101 *
102 * Getting the FaceBook Graph Query depending on the settings
103 *
104 * @since 2.19
105 * @return array
106 */
107 public function get_graph_query($show_posts_by, $cff_is_group){
108 //Use posts? or feed?
109 $old_others_option = get_option('cff_show_others'); //Use this to help depreciate the old option
110 $show_others = $this->atts['others'];
111 $graph_query = 'posts';
112 $cff_show_only_others = false;
113 //If 'others' shortcode option is used then it overrides any other option
114 if ($show_others || $old_others_option == 'on') {
115 //Show posts by everyone
116 if ( $old_others_option == 'on' || $show_others == 'on' || $show_others == 'true' || $show_others == true || $cff_is_group ) $graph_query = 'feed';
117 //Only show posts by me
118 if ( $show_others == 'false' ) $graph_query = 'posts';
119 } else {
120 //Else use the settings page option or the 'showpostsby' shortcode option
121 //Only show posts by me
122 if ( $show_posts_by == 'me' ) $graph_query = 'posts';
123 //Show posts by everyone
124 if ( $show_posts_by == 'others' || $cff_is_group ) $graph_query = 'feed';
125 //Show posts ONLY by others
126 if ( $show_posts_by == 'onlyothers' && !$cff_is_group ) {
127 $graph_query = 'visitor_posts';
128 $cff_show_only_others = true;
129 }
130 }
131
132 return [
133 'graph_query' => $graph_query,
134 'cff_show_only_others' => $cff_show_only_others
135 ];
136
137 }
138
139
140 /**
141 * Get Posts Limit
142 *
143 * Getting the FaceBook Graph Query depending on the settings
144 *
145 * @since 2.19
146 * @return int
147 */
148 public function get_post_limit($show_posts){
149 $cff_post_limit = $this->atts['limit'];
150 if ( isset($cff_post_limit) && $cff_post_limit !== '' ) {
151 $cff_post_limit = $cff_post_limit;
152 } else {
153 if( intval($show_posts) >= 50 ) $cff_post_limit = intval(intval($show_posts) + 7);
154 if( intval($show_posts) < 50 ) $cff_post_limit = intval(intval($show_posts) + 5);
155 if( intval($show_posts) < 25 ) $cff_post_limit = intval(intval($show_posts) + 4);
156 if( intval($show_posts) < 10 ) $cff_post_limit = intval(intval($show_posts) + 3);
157 if( intval($show_posts) < 6 ) $cff_post_limit = intval(intval($show_posts) + 2);
158 if( intval($show_posts) < 2 ) $cff_post_limit = intval(intval($show_posts) + 1);
159 }
160 if( $cff_post_limit >= 100 ) $cff_post_limit = 100;
161 return $cff_post_limit;
162 }
163
164
165 function cff_get_shortcode_data_attribute_html( $feed_options ) {
166
167 //If an access token is set in the shortcode then set "use own access token" to be enabled
168 if( isset($feed_options['accesstoken']) ){
169 //Add an encryption string to protect token
170 if ( strpos($feed_options['accesstoken'], ',') !== false ) {
171 //If there are multiple tokens then just add the string after the colon to avoid having to de/reconstruct the array
172 $feed_options['accesstoken'] = str_replace(":", ":02Sb981f26534g75h091287a46p5l63", $feed_options['accesstoken']);
173 } else {
174 //Add an encryption string to protect token
175 $feed_options['accesstoken'] = substr_replace($feed_options['accesstoken'], '02Sb981f26534g75h091287a46p5l63', 25, 0);
176 }
177 $feed_options['ownaccesstoken'] = 'on';
178 }
179
180 if( !empty($feed_options) ){
181 $json_data = '{';
182 $i = 0;
183 $len = count($feed_options);
184 foreach( $feed_options as $key => $value ) {
185 if ($i == $len - 1) {
186 $json_data .= '&quot;'.$key.'&quot;: &quot;'.$value.'&quot;';
187 } else {
188 $json_data .= '&quot;'.$key.'&quot;: &quot;'.$value.'&quot;, ';
189 }
190 $i++;
191 }
192 $json_data .= '}';
193
194 return $json_data;
195 }
196
197 }
198
199 function cff_get_processed_options($feed_options){
200 $feed_id = empty( $feed_options['feed'] ) ? 'default' : intval( $feed_options['feed'] );
201 $feed_options = $this->get_settings_for_feed( $feed_options );
202
203 if ( empty( $feed_options ) ) {
204 $options = get_option('cff_style_settings');
205 $fdo = new CFF_FB_Settings($feed_options, $options);
206 $feed_options = $fdo->get_settings();
207 $feed_options['feederror'] = $feed_id;
208 return $feed_options;
209 }
210
211 $page_id = $feed_options['id'];
212 $cff_facebook_string = 'facebook.com';
213 ( stripos($page_id, $cff_facebook_string) !== false) ? $cff_page_id_url_check = true : $cff_page_id_url_check = false;
214 if ( $cff_page_id_url_check === true ) {
215 //Remove trailing slash if exists
216 $page_id = preg_replace('{/$}', '', $page_id);
217 //Get last part of url
218 $page_id = substr( $page_id, strrpos( $page_id, '/' )+1 );
219 }
220 //If the Page ID contains a query string at the end then remove it
221 if ( stripos( $page_id, '?') !== false ) $page_id = substr($page_id, 0, strrpos($page_id, '?'));
222
223 //Always remove slash from end of Page ID
224 $page_id = preg_replace('{/$}', '', $page_id);
225
226 //Update the page ID in the feed options array for use everywhere
227 $feed_options['id'] = $page_id;
228
229
230 //If an 'account' is specified then use that instead of the Page ID/token from the settings
231 $cff_account = trim($feed_options['account']);
232
233 if( !empty( $cff_account ) ){
234 $cff_connected_accounts = get_option('cff_connected_accounts');
235 if( !empty($cff_connected_accounts) ){
236
237 //Replace both single and double quotes before decoding
238 $cff_connected_accounts = str_replace('\"','"', $cff_connected_accounts);
239 $cff_connected_accounts = str_replace("\'","'", $cff_connected_accounts);
240
241 $cff_connected_accounts = json_decode( $cff_connected_accounts );
242
243 if ( isset( $cff_account ) && is_object( $cff_connected_accounts ) ) {
244 //Grab the ID and token from the connected accounts setting
245 if( isset( $cff_connected_accounts->{ $cff_account } ) ){
246 $feed_options['id'] = $cff_connected_accounts->{ $cff_account }->{'id'};
247 $feed_options['accesstoken'] = $cff_connected_accounts->{ $cff_account }->{'accesstoken'};
248 }
249
250 }
251
252 //Replace the encryption string in the Access Token
253 if (strpos($feed_options['accesstoken'], '02Sb981f26534g75h091287a46p5l63') !== false) {
254 $feed_options['accesstoken'] = str_replace("02Sb981f26534g75h091287a46p5l63","",$feed_options['accesstoken']);
255 }
256 }
257 }
258
259 //Replace the encryption string in the Access Token
260 if (strpos($feed_options['accesstoken'], '02Sb981f26534g75h091287a46p5l63') !== false) {
261 $feed_options['accesstoken'] = str_replace("02Sb981f26534g75h091287a46p5l63","",$feed_options['accesstoken']);
262 }
263 $cff_connected_accounts = get_option('cff_connected_accounts');
264 if(!empty($cff_connected_accounts)){
265 $connected_accounts = (array)json_decode(stripcslashes($cff_connected_accounts));
266 if(array_key_exists($feed_options['id'], $connected_accounts)){
267 $feed_options['pagetype'] = $connected_accounts[$feed_options['id']]->pagetype;
268 }
269 }
270
271 if ( ! empty( $feed_options['feedlayout'] ) ) {
272 if ( $feed_options['feedlayout'] === 'list' ) {
273 $feed_options['cols'] = 1;
274 $feed_options['colsmobile'] = 1;
275 $feed_options['colstablet'] = 1;
276 $feed_options['masonrycols'] = 1;
277 $feed_options['masonrycolsmobile'] = 1;
278 } elseif ( $feed_options['feedlayout'] === 'masonry' ) {
279 $feed_options['masonrycols'] = $feed_options['cols'] ;
280 $feed_options['masonrycolsmobile'] = $feed_options['colsmobile'];
281 }
282 }
283
284 return $feed_options;
285 }
286
287 /**
288 * Display.
289 * The main Shortcode display
290 *
291 * @since 2.19
292 */
293 public function display_cff($atts) {
294 do_action( 'cff_before_display_facebook' );
295 $this->options = get_option('cff_style_settings');
296 $data_att_html = $this->cff_get_shortcode_data_attribute_html( $atts );
297 $feed_id = empty( $atts['feed'] ) ? 'default' : intval( $atts['feed'] );
298 $feed_options = $this->get_settings_for_feed( $atts );
299
300 if ( empty( $feed_options ) ) {
301 $this->fb_feed_settings = new CFF_FB_Settings($atts, $this->options);
302 $this->atts = $this->fb_feed_settings->get_settings();
303 $id_and_token = $this->fb_feed_settings->get_id_and_token();
304 $this->page_id = $id_and_token['id'];
305
306 $encryption = new SB_Facebook_Data_Encryption();
307 $this->access_token = $encryption->decrypt($id_and_token['token']) ? $encryption->decrypt($id_and_token['token']) : $id_and_token['token'];
308
309 $this->atts = $this->cff_get_processed_options( $this->atts );
310
311 } else {
312 if ( ! empty( $feed_options['feedlayout'] ) ) {
313 if ( $feed_options['feedlayout'] === 'list' ) {
314 $feed_options['cols'] = 1;
315 $feed_options['colsmobile'] = 1;
316 $feed_options['colstablet'] = 1;
317 $feed_options['masonrycols'] = 1;
318 $feed_options['masonrycolsmobile'] = 1;
319 } elseif ( $feed_options['feedlayout'] === 'masonry' ) {
320 $feed_options['masonrycols'] = $feed_options['cols'] ;
321 $feed_options['masonrycolsmobile'] = $feed_options['colsmobile'];
322 }
323 }
324
325
326 $this->atts = $feed_options;
327 }
328
329 $this->cff_add_translations();
330 #var_dump($this->atts);
331
332 //Vars for the templates
333 $atts = $this->atts;
334 $options = $this->options;
335 $access_token = $this->access_token;
336 $page_id = $this->page_id;
337
338 if ( $atts['cff_enqueue_with_shortcode'] === 'on' || $atts['cff_enqueue_with_shortcode'] === 'true' ) {
339 wp_enqueue_style( 'cff' );
340 wp_enqueue_script( 'cffscripts' );
341 }
342
343 $palette = '';
344 $custom_palette_class = '';
345 $doing_custom_styles = false;
346
347 if ( ! empty( $this->atts['colorpalette'] ) ) {
348 switch ( $this->atts['colorpalette'] ) {
349 case 'dark' :
350 $palette = 'cff-dark ';
351 break;
352 case 'light' :
353 $palette = 'cff-light ';
354 break;
355 case 'custom' :
356 $doing_custom_styles = true;
357 $custom_palette_class = 'cff-palette-' . $feed_id . ' ';
358 break;
359 default:
360 $palette = '';
361 }
362 }
363
364 $this->atts['paletteclass'] = $palette . $custom_palette_class;
365
366 /********** GENERAL **********/
367 $cff_page_type = $this->atts[ 'pagetype' ];
368 ($cff_page_type == 'group') ? $cff_is_group = true : $cff_is_group = false;
369
370
371 $cff_show_author = $this->atts[ 'showauthornew' ];
372 $cff_cache_time = $this->atts[ 'cachetime' ];
373 $cff_locale = $this->atts[ 'locale' ];
374 if( empty($cff_locale) || !isset($cff_locale) || $cff_locale == '' ) $cff_locale = 'en_US';
375 if(!isset($cff_cache_time) || $cff_cache_time == '' ) $cff_cache_time = 0;
376 $cff_cache_time_unit = $this->atts[ 'cacheunit' ];
377
378 $like_box = CFF_Utils::print_template_part( 'likebox', get_defined_vars());
379
380
381 if($cff_cache_time == 'nocaching') $cff_cache_time = 0;
382
383 //Like box
384 $cff_like_box_position = $this->atts[ 'likeboxpos' ];
385 $cff_like_box_outside = CFF_Utils::check_if_on($this->atts[ 'likeboxoutside' ]);
386 //Open links in new window?
387 $target = 'target="_blank"';
388 /********** LAYOUT **********/
389 $cff_show_author = $this->check_show_section( 'author' );
390 $cff_show_text = $this->check_show_section( 'text' );
391 $cff_show_desc = $this->check_show_section( 'desc' );
392 $cff_show_shared_links = $this->check_show_section( 'sharedlink' );
393 $cff_show_date = $this->check_show_section( 'date' );
394 $cff_show_media = $this->check_show_section( 'media' );
395 $cff_show_media_link = $this->check_show_section( 'medialink' );
396 $cff_show_event_title = $this->check_show_section( 'eventtitle' );
397 $cff_show_event_details = $this->check_show_section( 'eventdetail' );
398 $cff_show_meta = $this->check_show_section( 'social' );
399 $cff_show_link = $this->check_show_section( ',link' );
400 $cff_show_like_box = isset( $this->atts['showlikebox'] ) ? CFF_Utils::check_if_on( $this->atts['showlikebox'] ) : false;
401
402 //Set free version to thumb layout by default as layout option not available on settings page
403 $cff_preset_layout = 'thumb';
404
405 //If the old shortcode option 'showauthor' is being used then apply it
406 $cff_show_author_old = $this->atts[ 'showauthor' ];
407 if( $cff_show_author_old == 'false' ) $cff_show_author = false;
408 if( $cff_show_author_old == 'true' ) $cff_show_author = true;
409
410 //See Less text
411 $cff_posttext_link_color = str_replace('#', '', $this->atts['textlinkcolor']);
412 $cff_title_link = CFF_Utils::check_if_on( $this->atts['textlink'] );
413
414 //Description Style
415 $cff_body_styles = $this->get_style_attribute( 'body_description' );
416
417 //Shared link box
418 $cff_disable_link_box = CFF_Utils::check_if_on( $this->atts['disablelinkbox'] );
419
420 $cff_link_box_styles = $cff_disable_link_box ? '' : $this->get_style_attribute( 'link_box' );
421
422 //Date
423 $cff_date_position = ( !isset( $this->atts[ 'datepos' ] ) ) ? 'below' : $this->atts[ 'datepos' ];
424
425
426 //Show Facebook link
427 $cff_link_to_timeline = $this->atts[ 'linktotimeline' ];
428
429 //Post Style settings
430 $cff_post_style = $this->atts['poststyle'];
431 $cff_post_bg_color_check = ($this->atts['postbgcolor'] !== '' && $this->atts['postbgcolor'] !== '#' && $cff_post_style != 'regular' ) ? true : false;
432 $cff_box_shadow = CFF_Utils::check_if_on( $this->atts['boxshadow'] ) && $cff_post_style == 'boxed';
433
434 //Text limits
435 $body_limit = $this->atts['desclength'];
436
437 //Get show posts attribute. If not set then default to 25
438 $show_posts = ( empty( $this->atts['num'] ) || $this->atts['num'] == 'undefined' ) ? 25 : $this->atts['num'];
439 $show_posts_number = isset( $this->atts['minnum'] ) ? $this->atts['minnum'] : $this->atts['num'];
440
441 //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
442 get_option('cff_show_access_token') ? $cff_show_access_token = true : $cff_show_access_token = false;
443
444 //Check whether a Page ID has been defined
445 if ($this->page_id == '') {
446 if ( $this->using_legacy_feed( $feed_options ) ) {
447 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 />";
448 }
449 return false;
450 }
451
452 //Is it a restricted page?
453 $cff_restricted_page = CFF_Utils::check_if_on( $this->atts['restrictedpage'] );
454
455 $show_posts_by = $this->atts['showpostsby'];
456 $graph_info = $this->get_graph_query($show_posts_by, $cff_is_group);
457 $graph_query = $graph_info['graph_query'];
458 $cff_show_only_others = $graph_info['cff_show_only_others'];
459
460
461
462
463 // If Mobile and Desktop post nums are not the same, use minnum for API requests.
464 $mobile_num = isset( $this->atts['nummobile'] ) && (int)$this->atts['nummobile'] > 0 ? (int)$this->atts['nummobile'] : 0;
465 $desk_num = $show_posts;
466 if ( $desk_num < $mobile_num ) {
467 $this->atts['minnum'] = $mobile_num;
468 }
469
470 $show_posts = isset( $this->atts['minnum'] ) ? $this->atts['minnum'] : $show_posts;
471 $cff_post_limit = $this->get_post_limit($show_posts);
472
473 //If the number of posts is set to zero then don't show any and set limit to one
474 if ( ($show_posts == '0' || $show_posts == 0) && $show_posts !== ''){
475 $show_posts = 0;
476 $cff_post_limit = 1;
477 }
478
479
480 //Calculate the cache time in seconds
481 if($cff_cache_time_unit == 'minutes') $cff_cache_time_unit = 60;
482 if($cff_cache_time_unit == 'hours') $cff_cache_time_unit = 60*60;
483 if($cff_cache_time_unit == 'days') $cff_cache_time_unit = 60*60*24;
484 $cache_seconds = $cff_cache_time * $cff_cache_time_unit;
485
486
487
488
489
490 //Misc Settings
491 $cff_nofollow = CFF_Utils::check_if_on( $this->atts['nofollow'] );
492 ( $cff_nofollow ) ? $cff_nofollow = ' rel="nofollow noopener"' : $cff_nofollow = '';
493 $cff_nofollow_referrer = ' rel="nofollow noopener noreferrer"';
494
495 //If the number of posts is set to zero then don't show any and set limit to one
496 if ( ($this->atts['num'] == '0' || $this->atts['num'] == 0) && $this->atts['num'] !== ''){
497 $show_posts = 0;
498 $cff_post_limit = 1;
499 }
500
501 //***START FEED***
502 #$defined_vars = get_defined_vars();
503 $cff_content = '';
504
505 //Create CFF container HTML
506 $cff_content .= '<div class="cff-wrapper">';
507 $cff_style_class = $this->feed_style_class_compiler();
508 $cff_insider_style = $this->get_style_attribute( 'feed_wrapper_insider' );
509 $cff_feed_height = CFF_Utils::get_css_distance( $this->atts[ 'height' ] ) ;
510 //Feed header
511 $cff_show_header = CFF_Utils::check_if_on( $this->atts['showheader'] );
512 $cff_header_outside = CFF_Utils::check_if_on( $this->atts['headeroutside'] );
513 $cff_header_type = strtolower( $this->atts['headertype'] );
514 $cff_header = CFF_Utils::print_template_part( 'header', get_defined_vars(), $this);
515
516
517
518 //Add the page header to the outside of the top of feed
519 if ($cff_show_header && $cff_header_outside) $cff_content .= $cff_header;
520
521 //Add like box to the outside of the top of feed
522 if ($cff_like_box_position == 'top' && $cff_show_like_box && $cff_like_box_outside) $cff_content .= $like_box;
523
524
525 //Get Custom Class and Compiled CSS
526
527 $custom_wrp_class = !empty($cff_feed_height) ? ' cff-wrapper-fixed-height' : '';
528
529 $cff_content .= '<div class="cff-wrapper-ctn '.$custom_wrp_class.'" '.$cff_insider_style.'>';
530 $cff_content .= '<div id="cff" ' . $cff_style_class['cff_custom_class'] . ' ' . $cff_style_class['cff_feed_styles'] . ' ' . $cff_style_class['cff_feed_attributes'] . '>';
531
532 //Add the page header to the inside of the top of feed
533 if ($cff_show_header && !$cff_header_outside) $cff_content .= $cff_header;
534
535 //Add like box to the inside of the top of feed
536 if ($cff_like_box_position == 'top' && $cff_show_like_box && !$cff_like_box_outside) $cff_content .= $like_box;
537 //Limit var
538 $i_post = 0;
539
540 //Define array for post items
541 $cff_posts_array = array();
542 //ALL POSTS
543
544 $FBdata = $this->get_feed_json( $graph_query, $cff_post_limit, $cff_locale, $cff_show_access_token, $cache_seconds, $cff_cache_time, $show_posts_by, $data_att_html );
545 if( $cff_is_group ){
546 $cff_ssl = is_ssl() ? '&return_ssl_resources=true' : '';
547 $attachments_desc = ( $this->atts['salesposts'] == 'true' ) ? '' : ',description';
548 $cff_posts_json_url = 'https://graph.facebook.com/v4.0/' . $this->page_id . '/' . $graph_query . '?fields=id,updated_time,from{picture,id,name,link},message,message_tags,story,story_tags,status_type,created_time,backdated_time,call_to_action,attachments{title'. $attachments_desc . ',media_type,unshimmed_url,target{id},media{source}}&access_token=' . $this->access_token . '&limit=' . $cff_post_limit . '&locale=' . $cff_locale . $cff_ssl;
549 $this->atts['type'] = 'links_events_videos_photos_albums_statuses_';
550 $groups_post = new CFF_Group_Posts($this->page_id, $this->atts, $cff_posts_json_url, $data_att_html, false);
551 $groups_post_result = $groups_post->init_group_posts(json_encode($FBdata), false, $show_posts_number);
552 $posts_json = $groups_post_result['posts_json'];
553 $FBdata = json_decode($posts_json);
554 }
555
556
557 global $current_user;
558 $user_id = $current_user->ID;
559
560 //Print Pretty Message Error
561 $cff_content .= CFF_Utils::print_template_part( 'error-message', get_defined_vars());
562
563 $numeric_page_id = '';
564 if( !empty($FBdata->data) ){
565 if ( ($cff_show_only_others || $show_posts_by == 'others') && count($FBdata->data) > 0 ) {
566 //Get the numeric ID of the page so can compare it to the author of each post
567 $first_post_id = explode("_", $FBdata->data[0]->id);
568 $numeric_page_id = $first_post_id[0];
569 }
570 }
571
572 $posts_wrap_box_shadow_class = $cff_box_shadow && $this->atts['feedlayout'] === 'list' ? ' cff-posts-wrap-box-shadow' : '';
573 $cff_content .= '<div class="cff-posts-wrap'.$posts_wrap_box_shadow_class.'">';
574
575 //***STARTS POSTS LOOP***
576 if( isset($FBdata->data) ){
577 if ( ! \cff_main()->cff_error_reporter->are_critical_errors()
578 && isset( $this->atts['sources'] )
579 && is_array( $this->atts['sources'] ) ) {
580 foreach ( $this->atts['sources'] as $source ) {
581 if ( ! empty( $source['error'] ) ) {
582 \CustomFacebookFeed\Builder\CFF_Source::clear_error( $source['account_id'] );
583 }
584 }
585 }
586 foreach ($FBdata->data as $news )
587 {
588 //Explode News and Page ID's into 2 values
589 $PostID = '';
590 $cff_post_id = '';
591 if( isset($news->id) ){
592 $cff_post_id = $news->id;
593 $PostID = explode("_", $cff_post_id);
594 }
595
596 //Reassign variable changes from API v3.3 update
597 $news->link = isset($news->attachments->data[0]->unshimmed_url) ? $news->attachments->data[0]->unshimmed_url : '';
598 $news->description = isset($news->attachments->data[0]->description) ? $news->attachments->data[0]->description : '';
599 $news->object_id = isset($news->attachments->data[0]->target->id) ? $news->attachments->data[0]->target->id : '';
600 $news->source = isset($news->attachments->data[0]->media->source) ? $news->attachments->data[0]->media->source : '';
601 $news->name = isset($news->attachments->data[0]->title) ? $news->attachments->data[0]->title : '';
602 $news->caption = isset($news->attachments->data[0]->title) ? $news->attachments->data[0]->title : '';
603
604 //Check the post type
605 $cff_post_type = isset($news->attachments->data[0]->media_type) ? $news->attachments->data[0]->media_type : 'status';
606
607 if ($cff_post_type == 'link') {
608 isset($news->story) ? $story = $news->story : $story = '';
609 //Check whether it's an event
610 $event_link_check = "facebook.com/events/";
611 if( isset($news->link) ){
612 $event_link_check = CFF_Utils::stripos($news->link, $event_link_check);
613 if ( $event_link_check ) $cff_post_type = 'event';
614 }
615 }
616 $cff_show_links_type = true;
617 $cff_show_event_type = true;
618 $cff_show_video_type = true;
619 $cff_show_photos_type = true;
620 $cff_show_status_type = true;
621 $cff_show_albums_type = true;
622 $cff_events_only = false;
623 //Are we showing ONLY events?
624 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;
625 //Should we show this post or not?
626 $cff_show_post = false;
627 switch ($cff_post_type) {
628 case 'link':
629 if ( $cff_show_links_type ) $cff_show_post = true;
630 break;
631 case 'event':
632 if ( $cff_show_event_type ) $cff_show_post = true;
633 break;
634 case 'video':
635 if ( $cff_show_video_type ) $cff_show_post = true;
636 break;
637 case 'swf':
638 if ( $cff_show_video_type ) $cff_show_post = true;
639 break;
640 case 'photo':
641 if ( $cff_show_photos_type ) $cff_show_post = true;
642 break;
643 case 'offer':
644 $cff_show_post = true;
645 break;
646 default:
647 //Check whether it's a status (author comment or like)
648 if ( $cff_show_status_type && !empty($news->message) ) $cff_show_post = true;
649 break;
650 }
651 //Is it a duplicate post?
652 if (!isset($prev_post_message)) $prev_post_message = '';
653 if (!isset($prev_post_link)) $prev_post_link = '';
654 if (!isset($prev_post_description)) $prev_post_description = '';
655 isset($news->message) ? $pm = $news->message : $pm = '';
656 isset($news->link) ? $pl = $news->link : $pl = '';
657 isset($news->description) ? $pd = $news->description : $pd = '';
658
659 if ( ($prev_post_message == $pm) && ($prev_post_link == $pl) && ($prev_post_description == $pd) ) $cff_show_post = false;
660
661 //Offset. If the post index ($i_post) is less than the offset then don't show the post
662 if( intval($i_post) < intval($this->atts['offset']) ){
663 $cff_show_post = false;
664 $i_post++;
665 }
666
667 //Check post type and display post if selected
668 if ( $cff_show_post ) {
669 //If it isn't then create the post
670 //Only create posts for the amount of posts specified
671 if( intval($this->atts['offset']) > 0 ){
672 //If offset is being used then stop after showing the number of posts + the offset
673 if ( $i_post == (intval($show_posts) + intval($this->atts['offset'])) ) break;
674 } else {
675 //Else just stop after the number of posts to be displayed is reached
676 if ( $i_post == $show_posts ) break;
677 }
678 $i_post++;
679 //********************************//
680 //***COMPILE SECTION VARIABLES***//
681 //********************************//
682 //Set the post link
683 isset($news->link) ? $link = htmlspecialchars($news->link) : $link = '';
684 //Is it a shared album?
685 $shared_album_string = 'shared an album:';
686 isset($news->story) ? $story = $news->story : $story = '';
687 $shared_album = CFF_Utils::stripos($story, $shared_album_string);
688 if ( $shared_album ) {
689 $link = str_replace('photo.php?','media/set/?',$link);
690 }
691 //Check the post type
692 isset($cff_post_type) ? $cff_post_type = $cff_post_type : $cff_post_type = '';
693 if ($cff_post_type == 'link') {
694 isset($news->story) ? $story = $news->story : $story = '';
695 //Check whether it's an event
696 $event_link_check = "facebook.com/events/";
697 //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
698 $event_link_check = CFF_Utils::stripos($news->link, $event_link_check);
699 $event_link_check_2 = CFF_Utils::stripos($news->link, "permalink/");
700 if ( $event_link_check && !$event_link_check_2 ) $cff_post_type = 'event';
701 }
702
703 //If it's an event then check whether the URL contains facebook.com
704 if(isset($news->link)){
705 if( CFF_Utils::stripos($news->link, "events/") && $cff_post_type == 'event' ){
706 //Facebook changed the event link from absolute to relative, and so if the link isn't absolute then add facebook.com to front
707 ( CFF_Utils::stripos($link, 'facebook.com') ) ? $link = $link : $link = 'https://facebook.com' . $link;
708 }
709 }
710
711 //Is it an album?
712 $cff_album = false;
713 if( isset($news->status_type) ){
714 if( $news->status_type == 'added_photos' ){
715 if( isset($news->attachments) ){
716 if( $news->attachments->data[0]->media_type == 'album' ) $cff_album = true;
717 }
718 }
719 }
720
721 //If there's no link provided then link to either the Facebook page or the individual status
722 if (empty($news->link)) {
723 if ($cff_link_to_timeline == true){
724 //Link to page
725 $link = 'https://facebook.com/' . $this->page_id;
726 } else {
727 //Link to status
728 $link = "https://www.facebook.com/" . $this->page_id . "/posts/" . $PostID[1];
729 }
730 }
731
732 $cff_date = CFF_Utils::print_template_part( 'item/date', get_defined_vars(), $this);
733
734
735
736
737 //Story/post text vars
738 $post_text = '';
739 $cff_story_raw = '';
740 $cff_message_raw = '';
741 $cff_name_raw = '';
742 $text_tags = '';
743 $post_text_story = '';
744 $post_text_message = '';
745
746 //STORY TAGS
747 $cff_post_tags = $this->atts[ 'posttags' ];
748
749 //Use the story
750 if (!empty($news->story)) {
751 $cff_story_raw = $news->story;
752 $post_text_story .= htmlspecialchars($cff_story_raw);
753
754
755 //Add message and story tags if there are any and the post text is the message or the story
756 if( $cff_post_tags && isset($news->story_tags) && !$cff_title_link){
757
758 $text_tags = $news->story_tags;
759
760 //Does the Post Text contain any html tags? - the & symbol is the best indicator of this
761 $cff_html_check_array = array('&lt;', '', '', '&quot;', '&amp;', '&gt;&gt;');
762
763 //always use the text replace method
764 if( CFF_Utils::cff_stripos_arr($post_text_story, $cff_html_check_array) !== false || ($cff_locale == 'el_GR' && count($news->story_tags) > 3) ) {
765
766 //Loop through the tags
767 foreach($text_tags as $message_tag ) {
768
769 ( isset($message_tag->id) ) ? $message_tag = $message_tag : $message_tag = $message_tag[0];
770
771 $tag_name = $message_tag->name;
772 $tag_link = '<a href="https://facebook.com/' . $message_tag->id . '">' . $message_tag->name . '</a>';
773
774 $post_text_story = str_replace($tag_name, $tag_link, $post_text_story);
775 }
776
777 } else {
778
779 //If it doesn't contain HTMl tags then use the offset to replace message tags
780 $message_tags_arr = array();
781
782 $tag = 0;
783 foreach($text_tags as $message_tag ) {
784 $tag++;
785 ( isset($message_tag->id) ) ? $message_tag = $message_tag : $message_tag = $message_tag[0];
786
787 isset($message_tag->type) ? $tag_type = $message_tag->type : $tag_type = '';
788
789 $message_tags_arr = CFF_Utils::cff_array_push_assoc(
790 $message_tags_arr,
791 $tag,
792 array(
793 'id' => $message_tag->id,
794 'name' => $message_tag->name,
795 'type' => isset($message_tag->type) ? $message_tag->type : '',
796 'offset' => $message_tag->offset,
797 'length' => $message_tag->length
798 )
799 );
800
801 }
802
803 //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.
804 $cff_story_tag_offsets = '';
805 $cff_story_duplicate_offset = '';
806
807 //Check if there are any duplicate offsets. If so, assign to the cff_story_duplicate_offset var.
808 for($tag = count($message_tags_arr); $tag >= 1; $tag--) {
809 $c = (string)$message_tags_arr[$tag]['offset'];
810 if( strpos( $cff_story_tag_offsets, $c ) !== false && $c !== '0' ){
811 $cff_story_duplicate_offset = $c;
812 } else {
813 $cff_story_tag_offsets .= $c . ',';
814 }
815
816 }
817
818 for($tag = count($message_tags_arr); $tag >= 1; $tag--) {
819
820 //If the name is blank (aka the story tag doesn't work properly) then don't use it
821 if( $message_tags_arr[$tag]['name'] !== '' ) {
822
823 //If it's an event tag or it has the same offset as another tag then don't display it
824 if( $message_tags_arr[$tag]['type'] == 'event' || $message_tags_arr[$tag]['offset'] == $cff_story_duplicate_offset || $message_tags_arr[$tag]['type'] == 'page' ){
825 //Don't use the story tag in this case otherwise it changes '__ created an event' to '__ created an Name Of Event'
826 //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.
827 } else {
828 $b = '<a href="https://facebook.com/' . $message_tags_arr[$tag]['id'] . '" target="_blank">' . $message_tags_arr[$tag]['name'] . '</a>';
829 $c = $message_tags_arr[$tag]['offset'];
830 $d = $message_tags_arr[$tag]['length'];
831 $post_text_story = CFF_Utils::cff_mb_substr_replace( $post_text_story, $b, $c, $d);
832 }
833
834 }
835
836 }
837
838 } // end if/else
839
840 } //END STORY TAGS
841
842 }
843
844 //POST AUTHOR
845 $cff_author = CFF_Utils::print_template_part( 'item/author', get_defined_vars(), $this);
846
847 //Get the actual post text
848 //Which content should we use?
849 //Use the message
850 if (!empty($news->message)) {
851 $cff_message_raw = $news->message;
852
853 $post_text_message = htmlspecialchars($cff_message_raw);
854
855 //MESSAGE TAGS
856 //Add message and story tags if there are any and the post text is the message or the story
857 if( $cff_post_tags && isset($news->message_tags) && !$cff_title_link){
858
859 $text_tags = $news->message_tags;
860
861 //Does the Post Text contain any html tags? - the & symbol is the best indicator of this
862 $cff_html_check_array = array('&lt;', '', '', '&quot;', '&amp;', '&gt;&gt;', '&gt;');
863
864 //always use the text replace method
865 if( CFF_Utils::cff_stripos_arr($post_text_message, $cff_html_check_array) !== false ) {
866 //Loop through the tags
867 foreach($text_tags as $message_tag ) {
868
869 ( isset($message_tag->id) ) ? $message_tag = $message_tag : $message_tag = $message_tag[0];
870
871 $tag_name = $message_tag->name;
872 $tag_link = '<a href="https://facebook.com/' . $message_tag->id . '">' . $message_tag->name . '</a>';
873
874 $post_text_message = str_replace($tag_name, $tag_link, $post_text_message);
875 }
876
877 } else {
878 //If it doesn't contain HTMl tags then use the offset to replace message tags
879 $message_tags_arr = array();
880
881 $tag = 0;
882 foreach($text_tags as $message_tag ) {
883 $tag++;
884
885 ( isset($message_tag->id) ) ? $message_tag = $message_tag : $message_tag = $message_tag[0];
886
887 $message_tags_arr = CFF_Utils::cff_array_push_assoc(
888 $message_tags_arr,
889 $tag,
890 array(
891 'id' => $message_tag->id,
892 'name' => $message_tag->name,
893 'type' => isset($message_tag->type) ? $message_tag->type : '',
894 'offset' => $message_tag->offset,
895 'length' => $message_tag->length
896 )
897 );
898 }
899
900 //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.
901 $cff_msg_tag_offsets = '';
902 $cff_msg_duplicate_offset = '';
903
904 //Check if there are any duplicate offsets. If so, assign to the cff_duplicate_offset var.
905 for($tag = count($message_tags_arr); $tag >= 1; $tag--) {
906 $c = (string)$message_tags_arr[$tag]['offset'];
907 if( strpos( $cff_msg_tag_offsets, $c ) !== false && $c !== '0' ){
908 $cff_msg_duplicate_offset = $c;
909 } else {
910 $cff_msg_tag_offsets .= $c . ',';
911 }
912 }
913
914 //Sort the array by the "offset" key as Facebook doesn't always return them in the correct order
915 usort($message_tags_arr, "CustomFacebookFeed\CFF_Utils::cffSortTags");
916
917 for($tag = count($message_tags_arr)-1; $tag >= 0; $tag--) {
918
919 //If the name is blank (aka the story tag doesn't work properly) then don't use it
920 if( $message_tags_arr[$tag]['name'] !== '' ) {
921
922 if( $message_tags_arr[$tag]['offset'] == $cff_msg_duplicate_offset ){
923 //If it has the same offset as another tag then don't display it
924 } else {
925 $b = '<a href="https://facebook.com/' . $message_tags_arr[$tag]['id'] . '">' . $message_tags_arr[$tag]['name'] . '</a>';
926 $c = $message_tags_arr[$tag]['offset'];
927 $d = $message_tags_arr[$tag]['length'];
928 $post_text_message = CFF_Utils::cff_mb_substr_replace( $post_text_message, $b, $c, $d);
929 }
930
931 }
932
933 }
934
935 } // end if/else
936
937 } //END MESSAGE TAGS
938
939 }
940
941
942 //Check to see whether it's an embedded video so that we can show the name above the post text if necessary
943 $cff_soundcloud = false;
944 $cff_is_video_embed = false;
945 if ($cff_post_type == 'video' || $cff_post_type == 'music'){
946 if( isset($news->source) && !empty($news->source) ){
947 $url = $news->source;
948 } else if ( isset($news->link) ) {
949 $url = $news->link;
950 } else {
951 $url = '';
952 }
953 //Embeddable video strings
954 $vimeo = 'vimeo';
955 $youtube = CFF_Utils::stripos($url, 'youtube');
956 $youtu = CFF_Utils::stripos($url, 'youtu');
957 $youtubeembed = CFF_Utils::stripos($url, 'youtube.com/embed');
958 $soundcloudembed = CFF_Utils::stripos($url, 'soundcloud.com');
959
960 //Check whether it's a youtube video
961 if($youtube || $youtu || $youtubeembed || (stripos($url, $vimeo) !== false)) {
962 $cff_is_video_embed = true;
963 }
964 //If it's soundcloud then add it into the shared link box at the bottom of the post
965 if( $soundcloudembed ) $cff_soundcloud = true;
966 }
967
968 //Add the story and message together
969 $post_text = '';
970
971 //DESCRIPTION
972 $cff_description = '';
973 if ( !empty($news->description) || !empty($news->caption) ) {
974 $description_text = '';
975
976 if ( !empty($news->description) ) {
977 $description_text = $news->description;
978 }
979
980 //Replace ellipsis char in description text
981 $raw_desc = $description_text;
982 $description_text = str_replace( '','...', $description_text);
983
984 //If the description is the same as the post text then don't show it
985 if( $raw_desc == $cff_story_raw || $raw_desc == $cff_message_raw || $raw_desc == $cff_name_raw ){
986 $cff_description = '';
987 } else {
988 //Add links and create HTML
989 $cff_description .= '<span class="cff-post-desc" '.$cff_body_styles.'>';
990
991 if ($cff_title_link) {
992 $cff_description_tagged = CFF_Utils::cff_wrap_span( htmlspecialchars($description_text) );
993 } else {
994 $cff_description_text = CFF_Autolink::cff_autolink( htmlspecialchars($description_text), $link_color=$cff_posttext_link_color );
995 $cff_description_tagged = CFF_Utils::cff_desc_tags($cff_description_text);
996 }
997
998 $cff_description .= $cff_description_tagged;
999 $cff_description .= ' </span>';
1000 }
1001
1002 if( $cff_post_type == 'event' || $cff_is_video_embed || $cff_soundcloud ) $cff_description = '';
1003 }
1004
1005 //Add the message
1006 if($cff_show_text) $post_text .= $post_text_message;
1007
1008 $post_text = apply_filters( 'cff_post_text', $post_text );
1009
1010 //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
1011 if ($cff_post_type == 'video'){
1012 if( !empty($cff_description) && $cff_description != '' ){
1013 if( (!empty($post_text) && $post_text != '') && !empty($cff_video_name) ) $post_text .= '<br /><br />';
1014 $post_text .= $cff_video_name;
1015 }
1016 }
1017
1018
1019 //Use the name if there's no other text, unless it's a shared link post as then it's already used as the shared link box title
1020 if ( !empty($news->name) && empty($news->message) && $cff_post_type != 'link' ) {
1021 $cff_name_raw = $news->name;
1022 $post_text = htmlspecialchars($cff_name_raw);
1023 }
1024
1025 //OFFER TEXT
1026 if ($cff_post_type == 'offer'){
1027 isset($news->story) ? $post_text = htmlspecialchars($news->story) . '<br /><br />' : $post_text = '';
1028 $post_text .= htmlspecialchars($news->name);
1029 }
1030
1031 //Add the description
1032 if( $cff_show_desc && $cff_post_type != 'offer' && $cff_post_type != 'link' ) $post_text .= $cff_description;
1033
1034 //Change the linebreak element if the text issue setting is enabled
1035 $cff_format_issue = CFF_Utils::check_if_on( $this->atts['textissue'] );
1036 $cff_linebreak_el = ( $cff_format_issue ) ? '<br />' : '<img class="cff-linebreak" />';
1037
1038 //EVENT
1039 $cff_event_has_cover_photo = false;
1040 $cff_event = '';
1041
1042
1043 //Create note
1044 if ($cff_post_type == 'note') {
1045 //Notes don't include any post text and so just replace the post text with the note content
1046 if($cff_show_text) $post_text = CFF_Utils::print_template_part( 'item/type/note', get_defined_vars(), $this);
1047 }
1048
1049 $cff_post_text = CFF_Utils::print_template_part( 'item/post-text', get_defined_vars(), $this);
1050
1051 //LINK
1052 //Display shared link
1053 $cff_shared_link = CFF_Utils::print_template_part( 'item/shared-link', get_defined_vars(), $this);
1054
1055 //Link to the Facebook post if it's a link or a video
1056 if($cff_post_type == 'link' || $cff_post_type == 'video') $link = "https://www.facebook.com/" . $this->page_id . "/posts/" . $PostID[1];
1057
1058
1059 //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
1060 if( isset($news->status_type) ){
1061 if( $news->status_type == 'shared_story' ) $link = "https://www.facebook.com/" . $cff_post_id;
1062 }
1063
1064 //Create post action links HTML
1065 $cff_link = CFF_Utils::print_template_part( 'item/post-link', get_defined_vars(), $this);
1066 /* MEDIA LINK */
1067 $cff_media_link = CFF_Utils::print_template_part( 'item/media-link', get_defined_vars(), $this);
1068 //**************************//
1069 //***CREATE THE POST HTML***//
1070 //**************************//
1071 //Start the container
1072 $cff_post_item = CFF_Utils::print_template_part( 'item/container', get_defined_vars(), $this);
1073
1074 //PUSH TO ARRAY
1075 $cff_posts_array = CFF_Utils::cff_array_push_assoc($cff_posts_array, $i_post, $cff_post_item);
1076
1077 } // End post type check
1078
1079 if (isset($news->message)) $prev_post_message = $news->message;
1080 if (isset($news->link)) $prev_post_link = $news->link;
1081 if (isset($news->description)) $prev_post_description = $news->description;
1082
1083 } // End the loop
1084 } //End isset($FBdata->data)
1085
1086 //Sort the array in reverse order (newest first)
1087 if(!$cff_is_group) ksort($cff_posts_array);
1088
1089 // End ALL POSTS
1090
1091
1092 //Output the posts array
1093 $p = 0;
1094 foreach ($cff_posts_array as $post ) {
1095 if ( $p == $show_posts ) break;
1096 $cff_content .= $post;
1097 $p++;
1098 }
1099
1100
1101 //Add the Like Box inside
1102 if ($cff_like_box_position == 'bottom' && $cff_show_like_box && !$cff_like_box_outside) $cff_content .= $like_box;
1103 /* Credit link */
1104
1105 $cff_content .= '</div>'; // End cff-posts-wrap
1106
1107 $cff_content .= CFF_Utils::print_template_part( 'credit', get_defined_vars());
1108
1109 //End the feed
1110 $cff_content .= '<input class="cff-pag-url" type="hidden" data-locatornonce="'.esc_attr( wp_create_nonce( 'cff-locator-nonce-' . get_the_ID() ) ) .'" data-cff-shortcode="'.$data_att_html.'" data-post-id="' . get_the_ID() . '" data-feed-id="'.$atts['id'].'">';
1111 $cff_content .= '</div></div><div class="cff-clear"></div>';
1112
1113 //Add the Like Box outside
1114 if ($cff_like_box_position == 'bottom' && $cff_show_like_box && $cff_like_box_outside) $cff_content .= $like_box;
1115
1116 //If the feed is loaded via Ajax then put the scripts into the shortcode itself
1117 $cff_content .= $this->ajax_loaded();
1118 $cff_content .= '</div>';
1119
1120 if ( $doing_custom_styles ) {
1121 $cff_content .= '<style type="text/css">'. "\n";
1122
1123 if ( ! empty( $this->atts['colorpalette'] )
1124 && $this->atts['colorpalette'] === 'custom' ) {
1125
1126 $wrap_selector = '#cff.' . $custom_palette_class;
1127
1128 if ( ! empty( $this->atts['custombgcolor1'] ) ) {
1129 $cff_content .= $wrap_selector . ' ' . '.cff-item,' . "\n";
1130 $cff_content .= $wrap_selector . ' ' . '.cff-item.cff-box,' . "\n";
1131 $cff_content .= $wrap_selector . ' ' . '.cff-item.cff-box:first-child,' . "\n";
1132 $cff_content .= $wrap_selector . ' ' . '.cff-album-item {' . "\n";
1133 $cff_content .= ' ' . 'background-color: ' . esc_attr( $this->atts['custombgcolor1'] ) . ';' ."\n";
1134 $cff_content .= '}' . "\n";
1135 }
1136
1137 if ( ! $cff_disable_link_box && ! empty( $this->atts['custombgcolor2'] ) ) {
1138 $cff_content .= $wrap_selector . ' ' . '.cff-view-comments,' . "\n";
1139 $cff_content .= $wrap_selector . ' ' . '.cff-load-more,' . "\n";
1140 $cff_content .= $wrap_selector . ' ' . '.cff-shared-link {' . "\n";
1141 $cff_content .= ' ' . 'background-color: ' . esc_attr( $this->atts['custombgcolor2'] ) . ';' ."\n";
1142 $cff_content .= '}' . "\n";
1143 }
1144
1145 if ( ! empty( $this->atts['textcolor1'] ) ) {
1146 $cff_content .= $wrap_selector . ' ' . '.cff-comment .cff-comment-text p,' . "\n";
1147 $cff_content .= $wrap_selector . ' ' . '.cff-album-info p,' . "\n";
1148 $cff_content .= $wrap_selector . ' ' . '.cff-story,' . "\n";
1149 $cff_content .= $wrap_selector . ' ' . '.cff-text {' . "\n";
1150 $cff_content .= ' ' . 'color: ' . esc_attr( $this->atts['textcolor1'] ) . ';' ."\n";
1151 $cff_content .= '}' . "\n";
1152 }
1153
1154 if ( ! empty( $this->atts['textcolor2'] ) ) {
1155 $cff_content .= $wrap_selector . ' ' . '.cff-comment-date,' . "\n";
1156 $cff_content .= $wrap_selector . ' ' . '.cff-text-link .cff-post-desc,' . "\n";
1157 $cff_content .= $wrap_selector . ' ' . '.cff-link-caption,' . "\n";
1158 $cff_content .= $wrap_selector . ' ' . '.cff-date {' . "\n";
1159 $cff_content .= ' ' . 'color: ' . esc_attr( $this->atts['textcolor2'] ) . ';' ."\n";
1160 $cff_content .= '}' . "\n";
1161 }
1162
1163 if ( ! empty( $this->atts['customlinkcolor'] ) ) {
1164 $cff_content .= $wrap_selector . ' ' . 'a,' . "\n";
1165 $cff_content .= $wrap_selector . ' ' . '.cff-post-links a,' . "\n";
1166 $cff_content .= $wrap_selector . ' ' . 'a {' . "\n";
1167 $cff_content .= ' ' . 'color: ' . esc_attr( $this->atts['customlinkcolor'] ) . ';' ."\n";
1168 $cff_content .= '}' . "\n";
1169 }
1170
1171 }
1172 $lightbox_selector = '#cff-lightbox-wrapper';
1173
1174 if ( ! empty( $this->atts['lightboxbgcolor'] ) ) {
1175 $cff_content .= $lightbox_selector . ' ' . '.cff-lightbox-dataContainer,' . "\n";
1176 $cff_content .= $lightbox_selector . ' ' . '.cff-lightbox-sidebar {' . "\n";
1177 $cff_content .= ' ' . 'background-color: ' . esc_attr( $this->atts['lightboxbgcolor'] ) . ';' ."\n";
1178 $cff_content .= '}' . "\n";
1179 }
1180
1181 if ( ! empty( $this->atts['lightboxtextcolor'] ) ) {
1182 $cff_content .= $lightbox_selector . ' ' . '.cff-author .cff-date,' . "\n";
1183 $cff_content .= $lightbox_selector . ' ' . '.cff-lightbox-closeContainer svg,' . "\n";
1184 $cff_content .= $lightbox_selector . ' ' . '.cff-lightbox-caption-text {' . "\n";
1185 $cff_content .= ' ' . 'color: ' . esc_attr( $this->atts['lightboxtextcolor'] ) . ';' ."\n";
1186 $cff_content .= '}' . "\n";
1187 }
1188
1189 if ( ! empty( $this->atts['lightboxlinkcolor'] ) ) {
1190 $cff_content .= $lightbox_selector . ' ' . '.cff-lightbox-caption-text a:link,' . "\n";
1191 $cff_content .= $lightbox_selector . ' ' . '.cff-lightbox-caption-text a:hover,' . "\n";
1192 $cff_content .= $lightbox_selector . ' ' . '.cff-lightbox-caption-text a:active,' . "\n";
1193 $cff_content .= $lightbox_selector . ' ' . '.cff-lightbox-caption-text a:visited,' . "\n";
1194 $cff_content .= $lightbox_selector . ' ' . '.cff-lightbox-facebook:link,' . "\n";
1195 $cff_content .= $lightbox_selector . ' ' . '.cff-lightbox-facebook:hover,' . "\n";
1196 $cff_content .= $lightbox_selector . ' ' . '.cff-lightbox-facebook:active,' . "\n";
1197 $cff_content .= $lightbox_selector . ' ' . '.cff-lightbox-facebook:visited,' . "\n";
1198 $cff_content .= $lightbox_selector . ' ' . 'a {' . "\n";
1199 $cff_content .= ' ' . 'color: ' . esc_attr( $this->atts['lightboxlinkcolor'] ) . ';' ."\n";
1200 $cff_content .= '}' . "\n";
1201 }
1202
1203 $cff_content .= '</style>';
1204
1205 }
1206
1207
1208 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>';
1209
1210 if ( isset( $_GET['sb_debug'] ) ) {
1211 $cff_content .= $this->sb_get_debug_report( $feed_options );
1212 }
1213
1214 //Return our feed HTML to display
1215 return $cff_content;
1216 }
1217
1218 /**
1219 * Get Debug Report for Feed
1220 *
1221 * @since 4.0
1222 *
1223 * @param array $feed_opitons
1224 *
1225 * @return string $output
1226 */
1227 public function sb_get_debug_report( $feed_options ) {
1228 if ( !isset( $_GET['sb_debug'] ) ) {
1229 return;
1230 }
1231 $cff_options = get_option( 'cff_style_settings' );
1232
1233 $output = '';
1234 $output .= '<p>Settings</p>';
1235 $output .= '<ul style="word-break: break-all;">';
1236
1237 $output .= '<li>Optimize Images: ';
1238 $output .= isset( $cff_options[ 'cff_disable_resize' ] ) && $cff_options[ 'cff_disable_resize' ] == 'on' ? 'Enabled' : 'Disabled';
1239 $output .= "</li>";
1240 $output .= "</li>";
1241 $output .= '<li>AJAX theme loading fix: ';
1242 $output .= isset( $cff_options[ 'cff_disable_ajax_cache' ] ) && $cff_options[ 'cff_disable_ajax_cache' ] == true ? 'Enabled' : 'Disabled';
1243 $output .= "</li>";
1244 $output .= '<li>Show Credit Link: ';
1245 $output .= isset( $cff_options['cff_format_issue'] ) && $cff_options['cff_format_issue'] == true ? 'Enabled' : 'Disabled';
1246 $output .= "</li>";
1247 $output .= '<li>Fix Text Shortening Issue: ';
1248 $output .= isset( $cff_options['cff_show_credit'] ) && $cff_options['cff_show_credit'] == true ? 'Enabled' : 'Disabled';
1249 $output .= "</li>";
1250 $output .= '<li>Admin Error Notice: ';
1251 $output .= isset( $cff_options['disable_admin_notice'] ) && $cff_options['disable_admin_notice'] == true ? 'Enabled' : 'Disabled';
1252 $output .= "</li>";
1253 $output .= '</ul>';
1254
1255 $output .= '<p>Feed Options</p>';
1256 $public_settings_keys = CFF_Shortcode::get_public_db_settings_keys();
1257
1258 $output .= '<ul style="word-break: break-all;">';
1259 foreach( $feed_options as $key => $option ) {
1260 if ( is_array( $option ) ) continue;
1261 if ( in_array( $key, $public_settings_keys, true ) ) {
1262 $output .= sprintf('<li>%s: %s</li>', esc_html( $key ), esc_html( $option ) );
1263 }
1264 }
1265 $output .= '</ul>';
1266
1267 return $output;
1268 }
1269
1270 /**
1271 * The plugin will output settings on the frontend for debugging purposes.
1272 * Safe settings to display are added here.
1273 **
1274 * @return array
1275 *
1276 * @since 4.0
1277 */
1278 public static function get_public_db_settings_keys() {
1279 $public = array(
1280 'ownaccesstoken',
1281 'id',
1282 'pagetype',
1283 'num',
1284 'limit',
1285 'others',
1286 'showpostsby',
1287 'cachetype',
1288 'cachetime',
1289 'cacheunit',
1290 'locale',
1291 'storytags',
1292 'ajax',
1293 'offset',
1294 'account',
1295 'width',
1296 'widthresp',
1297 'height',
1298 'padding',
1299 'bgcolor',
1300 'showauthor',
1301 'showauthornew',
1302 'class',
1303 'type',
1304 'gdpr',
1305 'loadiframes',
1306 'eventsource',
1307 'eventoffset',
1308 'eventimage',
1309 'pastevents',
1310 'albumsource',
1311 'showalbumtitle',
1312 'showalbumnum',
1313 'albumcols',
1314 'photosource',
1315 'photocols',
1316 'videosource',
1317 'showvideoname',
1318 'showvideodesc',
1319 'videocols',
1320 'playlist',
1321 'disablelightbox',
1322 'filter',
1323 'exfilter',
1324 'layout',
1325 'enablenarrow',
1326 'oneimage',
1327 'mediaposition' => 'above',
1328 'include',
1329 'exclude',
1330 'masonry',
1331 'masonrycols',
1332 'masonrycolsmobile',
1333 'masonryjs',
1334 'cols',
1335 'colsmobile',
1336 'colsjs',
1337 'nummobile',
1338 'poststyle',
1339 'postbgcolor',
1340 'postcorners',
1341 'boxshadow',
1342 'textformat',
1343 'textsize',
1344 'textweight',
1345 'textcolor',
1346 'textlinkcolor',
1347 'textlink',
1348 'posttags',
1349 'linkhashtags',
1350 'lightboxcomments',
1351 'authorsize',
1352 'authorcolor',
1353 'descsize',
1354 'descweight',
1355 'desccolor',
1356 'linktitleformat',
1357 'linktitlesize',
1358 'linkdescsize',
1359 'linkurlsize',
1360 'linkdesccolor',
1361 'linktitlecolor',
1362 'linkurlcolor',
1363 'linkbgcolor',
1364 'linkbordercolor',
1365 'disablelinkbox',
1366 'eventtitleformat',
1367 'eventtitlesize',
1368 'eventtitleweight',
1369 'eventtitlecolor',
1370 'eventtitlelink',
1371 'eventdatesize',
1372 'eventdateweight',
1373 'eventdatecolor',
1374 'eventdatepos',
1375 'eventdateformat',
1376 'eventdatecustom',
1377 'timezoneoffset',
1378 'cff_enqueue_with_shortcode',
1379 'eventdetailssize',
1380 'eventdetailsweight',
1381 'eventdetailscolor',
1382 'eventlinkcolor',
1383 'datepos',
1384 'datesize',
1385 'dateweight',
1386 'datecolor',
1387 'dateformat',
1388 'datecustom',
1389 'timezone',
1390 'beforedate',
1391 'afterdate',
1392 'linksize',
1393 'linkweight',
1394 'linkcolor',
1395 'viewlinktext',
1396 'linktotimeline',
1397 'buttoncolor',
1398 'buttonhovercolor',
1399 'buttontextcolor',
1400 'buttontext',
1401 'nomoretext',
1402 'iconstyle',
1403 'socialtextcolor',
1404 'socialbgcolor',
1405 'sociallinkcolor',
1406 'expandcomments',
1407 'commentsnum',
1408 'hidecommentimages',
1409 'loadcommentsjs',
1410 'salesposts',
1411 'textlength',
1412 'desclength',
1413 'showlikebox',
1414 'likeboxpos',
1415 'likeboxoutside',
1416 'likeboxcolor',
1417 'likeboxtextcolor',
1418 'likeboxwidth',
1419 'likeboxfaces',
1420 'likeboxborder',
1421 'likeboxcover',
1422 'likeboxsmallheader',
1423 'likeboxhidebtn',
1424 'credit',
1425 'textissue',
1426 'disablesvgs',
1427 'restrictedpage',
1428 'hidesupporterposts',
1429 'privategroup',
1430 'nofollow',
1431 'timelinepag',
1432 'gridpag',
1433 'disableresize',
1434 'showheader',
1435 'headertype',
1436 'headercover',
1437 'headeravatar',
1438 'headername',
1439 'headerbio',
1440 'headercoverheight',
1441 'headerlikes',
1442 'headeroutside',
1443 'headertext',
1444 'headerbg',
1445 'headerpadding',
1446 'headertextsize',
1447 'headertextweight',
1448 'headertextcolor',
1449 'headericon',
1450 'headericoncolor',
1451 'headericonsize',
1452 'headerinc',
1453 'headerexclude',
1454 'loadmore',
1455 'fulllinkimages',
1456 'linkimagesize',
1457 'postimagesize',
1458 'videoheight',
1459 'videoaction',
1460 'videoplayer',
1461 'sepcolor',
1462 'sepsize',
1463 'seemoretext',
1464 'seelesstext',
1465 'photostext',
1466 'facebooklinktext',
1467 'sharelinktext',
1468 'showfacebooklink',
1469 'showsharelink',
1470 'buyticketstext',
1471 'maptext',
1472 'interestedtext',
1473 'goingtext',
1474 'previouscommentstext',
1475 'commentonfacebooktext',
1476 'likesthistext',
1477 'likethistext',
1478 'reactedtothistext',
1479 'andtext',
1480 'othertext',
1481 'otherstext',
1482 'noeventstext',
1483 'replytext',
1484 'repliestext',
1485 'learnmoretext',
1486 'shopnowtext',
1487 'messagepage',
1488 'getdirections',
1489 'secondtext',
1490 'secondstext',
1491 'minutetext',
1492 'minutestext',
1493 'hourtext',
1494 'hourstext',
1495 'daytext',
1496 'daystext',
1497 'weektext',
1498 'weekstext',
1499 'monthtext',
1500 'monthstext',
1501 'yeartext',
1502 'yearstext',
1503 'agotext',
1504 'multifeedactive',
1505 'daterangeactive',
1506 'featuredpostactive',
1507 'albumactive',
1508 'masonryactive',
1509 'carouselactive',
1510 'reviewsactive',
1511 'from',
1512 'until',
1513 'featuredpost',
1514 'album',
1515 'daterange',
1516 'lightbox',
1517 'reviewsrated',
1518 'starsize',
1519 'hidenegative',
1520 'reviewslinktext',
1521 'reviewshidenotext',
1522 'reviewsmethod',
1523 'feedtype',
1524 'likeboxcustomwidth',
1525 'colstablet',
1526 'feedlayout',
1527 'colorpalette',
1528 'custombgcolor1',
1529 'custombgcolor2',
1530 'textcolor1',
1531 'textcolor2',
1532 'posttextcolor',
1533 'misctextcolor',
1534 'misclinkcolor',
1535 'headericonenabled',
1536 'lightboxbgcolor',
1537 'lightboxtextcolor',
1538 'lightboxlinkcolor',
1539 'beforedateenabled',
1540 'afterdateenabled',
1541 'showpoststypes',
1542 'headerbiosize',
1543 'headerbiocolor',
1544 'apipostlimit',
1545 'carouselheight',
1546 'carouseldesktop_cols',
1547 'carouselmobile_cols',
1548 'carouselnavigation',
1549 'carouselpagination',
1550 'carouselautoplay',
1551 'carouselinterval',
1552 );
1553
1554 return $public;
1555 }
1556
1557 /* NEW 3.0 Methods */
1558 /**
1559 * Whether or not this feed is meant to use the new settings
1560 * or legacy settings
1561 *
1562 * @param array $feed_options
1563 *
1564 * @return bool
1565 *
1566 * @since 4.0
1567 */
1568 public function using_legacy_feed( $feed_options ) {
1569 $cff_statuses = get_option( 'cff_statuses', array() );
1570
1571 if ( isset( $cff_statuses['support_legacy_shortcode'] )
1572 && is_array( $cff_statuses['support_legacy_shortcode'] )) {
1573 return empty( $feed_options['feed'] );
1574 }
1575
1576 if ( empty( $cff_statuses['support_legacy_shortcode'] ) ) {
1577 return false;
1578 }
1579
1580 return empty( $feed_options['feed'] );
1581 }
1582
1583 /**
1584 * If a single unique feed was detected when updating from version 3.x
1585 * to version 4.0, a shortcode without a feed specified will be defaulted
1586 * to feed=1
1587 *
1588 * @param $feed_options
1589 *
1590 * @return bool
1591 */
1592 public function is_legacy_feed_one( $feed_options ) {
1593 $cff_statuses = get_option( 'cff_statuses', array() );
1594
1595 if ( isset( $cff_statuses['support_legacy_shortcode'] )
1596 && is_array( $cff_statuses['support_legacy_shortcode'] )) {
1597 return empty( $feed_options['feed'] );
1598 }
1599
1600 return false;
1601 }
1602
1603 /**
1604 * For non-legacy feeds. Queries the new db tables to see if the feed
1605 * exists and then converts the settings to what is usable by the plugin.
1606 *
1607 * @param array $feed_options
1608 *
1609 * @return array|bool
1610 *
1611 * @since 4.0
1612 */
1613 function get_settings_for_feed( $feed_options ) {
1614 if ( ! is_array( $feed_options ) ) {
1615 $feed_options = array();
1616 }
1617
1618 if ( $this->is_legacy_feed_one( $feed_options ) ) {
1619 $feed_options['feed'] = 1;
1620 }
1621
1622 if ( ! $this->using_legacy_feed( $feed_options ) ) {
1623
1624 $feed_id = isset( $feed_options['feed'] ) ? $feed_options['feed'] : false;
1625
1626 if ( empty( $feed_id ) ) {
1627 $feed_list = \CustomFacebookFeed\Builder\CFF_Feed_Builder::get_feed_list();
1628
1629 if ( count( $feed_list ) === 1 ) {
1630 $feed_saver = new \CustomFacebookFeed\Builder\CFF_Feed_Saver( $feed_list[0]['id'] );
1631 $settings = $feed_saver->get_feed_settings();
1632 } else {
1633 if (( current_user_can('editor') || current_user_can('administrator') ) ) {
1634 echo "<span id='cff-no-id'>" . sprintf( __( "It looks like you have more than one feed. Go to %sthis page%s and enter the intended feed ID in your shortcode like this: [custom-facebook-feed feed=YOUR_FEED_ID_HERE].", 'custom-facebook-feed' ), '<a href="' . esc_url( admin_url( 'admin.php?page=cff-feed-builder' ) ) . '">', '</a>' ) . "</span><br /><br />";
1635 }
1636 return false;
1637 }
1638
1639 } else {
1640 $feed_saver = new \CustomFacebookFeed\Builder\CFF_Feed_Saver( $feed_id );
1641 $settings = $feed_saver->get_feed_settings();
1642 }
1643
1644 if ( empty( $settings ) ) {
1645 if (( current_user_can('editor') || current_user_can('administrator') ) ) {
1646 $feed_list = \CustomFacebookFeed\Builder\CFF_Feed_Builder::get_feed_list();
1647 if ( empty( $feed_list ) ) {
1648 echo "<span id='cff-no-id'>" . sprintf( __( "It looks like you haven't set up a feed yet. Try going to %sthis page%s to create one and then enter the feed id in the shortcode like this [custom-facebook-feed feed=YOUR_FEED_ID_HERE].", 'custom-facebook-feed' ), '<a href="' . esc_url( admin_url( 'admin.php?page=cff-feed-builder' ) ) . '">', '</a>' ) . "</span><br /><br />";
1649 }
1650 }
1651 return false;
1652 } elseif ( empty( $settings['sources'] ) ) {
1653 if (( current_user_can('editor') || current_user_can('administrator') ) ) {
1654 echo "<span id='cff-no-id'>" . sprintf( __( "No source found for this feed. It looks like you may have removed the account this feed was using to display posts. Go to %sthis page%s, switch to the settings tab and click the sources menu item to manage sources for this feed.", 'custom-facebook-feed' ), '<a href="' . esc_url( admin_url( 'admin.php?page=cff-feed-builder&feed_id=' . (int) $feed_id ) ) . '">', '</a>' ) . "</span><br /><br />";
1655 }
1656 return $settings;
1657 }
1658
1659
1660 if ( empty( $settings['showpoststypes'] )
1661 || $settings['showpoststypes'] === 'all' ) {
1662 $settings['type'] = 'links,events,videos,photos,albums,statuses';
1663 }
1664
1665 if ( ! empty( $settings['feedtype'] ) && $settings['feedtype'] !== 'timeline' ) {
1666 $settings['type'] = $settings['feedtype'];
1667 }
1668
1669
1670 } else {
1671 $settings = CFF_FB_Settings::get_legacy_settings( $feed_options );
1672
1673 if ( ! empty( $feed_options['type'] ) ) {
1674 $settings['feedtype'] = $feed_options['type'];
1675 $settings['type'] = $feed_options['type'];
1676
1677 } else {
1678 if ( empty( $settings['showpoststypes'] )
1679 || $settings['showpoststypes'] === 'all' ) {
1680 $settings['type'] = 'links,events,videos,photos,albums,statuses';
1681 }
1682
1683 if ( ! empty( $settings['feedtype'] ) && $settings['feedtype'] !== 'timeline' ) {
1684 $settings['type'] = $settings['feedtype'];
1685 }
1686 }
1687
1688 $default_grid = [
1689 'albums',
1690 'videos',
1691 'photos',
1692 'singlealbum'
1693 ];
1694
1695 $type_setting_array = is_array( $settings['type'] ) ? array_filter( $settings['type'] ) : array_filter( explode( ',', $settings['type'] ) );
1696
1697 $single_type = count( $type_setting_array ) === 1 ? $type_setting_array[0] : false;
1698
1699 if ( ! empty( $feed_options['album'] ) ) {
1700 $single_type = 'singlealbum';
1701 }
1702
1703 if ( $single_type ) {
1704 if ( in_array( $single_type, $default_grid ) ) {
1705 if ( empty( $feed_options['feedlayout'] ) ) {
1706 $settings['feedlayout'] = 'grid';
1707 }
1708 if ( empty( $feed_options['cols'] ) ) {
1709 $colskey = substr( $single_type, 0, -1 ) . 'cols';
1710 $options_val = isset( $settings[ $colskey ] ) ? $settings[ $colskey ] : 4;
1711 $settings['cols'] = isset( $settings[ $colskey ] ) ? $settings[ $colskey ] : $options_val;
1712 }
1713 }
1714 $settings['feedtype'] = $single_type;
1715 }
1716
1717 }
1718
1719 $cff_includes = $settings['include'];
1720 $cff_excludes = $settings['exclude'];
1721
1722 $cff_show_like_box = false;
1723 if ( is_string( $cff_includes ) ) {
1724 if ( CFF_Utils::stripos($cff_includes, 'likebox') !== false ) $cff_show_like_box = true;
1725 } elseif ( in_array( 'likebox', $cff_includes ) ) {
1726 $cff_show_like_box = true;
1727 }
1728 if ( is_string( $cff_excludes ) ) {
1729 if ( CFF_Utils::stripos($cff_excludes, 'likebox') !== false ) $cff_show_like_box = false;
1730 } elseif ( in_array( 'likebox', $cff_excludes ) ) {
1731 $cff_show_like_box = false;
1732 }
1733
1734 if ( ! isset( $feed_options['include'] ) && ! isset( $feed_options['exclude'] ) ) {
1735 if ( ! empty( $settings['showlikebox'] ) ) {
1736 $settings['showlikebox'] = $settings['showlikebox'] === false || $settings['showlikebox'] === 'off' ? false : true;
1737 } else {
1738 $settings['showlikebox'] = $cff_show_like_box;
1739 }
1740 } else {
1741 $settings['showlikebox'] = $cff_show_like_box;
1742 }
1743
1744 if ( ! $settings['showlikebox'] ) {
1745 $settings['include'] = str_replace( 'likebox,', ',', $settings['include'] );
1746 }
1747
1748 if ( ! empty( $settings['headericonenabled'] ) && $settings['headericonenabled'] === 'off' ) {
1749 $settings['headericon'] = '';
1750 }
1751
1752 if ( ! empty( $settings['apipostlimit'] )
1753 && $settings['apipostlimit'] === 'auto') {
1754 $settings['limit'] = '';
1755 }
1756
1757 if ( $settings['poststyle'] === 'regular' ) {
1758 $settings['boxshadow'] = false;
1759 }
1760
1761 if ( isset( $feed_options['ajax'] ) ) {
1762 $settings['ajax'] = $feed_options['ajax'];
1763 } else {
1764 $settings['ajax'] = get_option( 'cff_ajax', '' );
1765 }
1766 $settings['locale'] = ( isset( $feed_options['locale'] ) ) ? $feed_options['locale'] : get_option( 'cff_locale', 'en_US' );
1767
1768 // Default Timezone
1769 $defaults = array(
1770 'cff_timezone' => 'America/Chicago',
1771 'gdpr' => 'auto',
1772 'cff_show_credit' => false,
1773 'cff_format_issue' => '',
1774 'disable_admin_notice' => false
1775 );
1776 $style_options = get_option( 'cff_style_settings', $defaults );
1777 $settings['timezone'] = (isset($style_options[ 'cff_timezone' ])) ? $style_options[ 'cff_timezone' ] : $defaults[ 'cff_timezone' ];
1778 $settings['gdpr'] = (isset($style_options[ 'gdpr' ])) ? $style_options[ 'gdpr' ] : $defaults[ 'gdpr' ];
1779 $settings['credit'] = (isset($style_options[ 'cff_show_credit' ])) ? $style_options[ 'cff_show_credit' ] : $defaults[ 'cff_show_credit' ];
1780 $settings['textissue'] = (isset($style_options[ 'cff_format_issue' ])) ? $style_options[ 'cff_format_issue' ] : $defaults[ 'cff_format_issue' ];
1781 $settings['likeboxheight'] = '';
1782 $settings['disablestyles'] = isset($style_options[ 'cff_disable_styles' ]) ? $style_options[ 'cff_disable_styles' ] : '';
1783
1784 $settings['cachetime'] = isset($feed_options[ 'cachetime' ]) ? $feed_options[ 'cachetime' ] : get_option( 'cff_cache_time', '1' );
1785 $settings['cacheunit'] = isset($feed_options[ 'cacheunit' ]) ? $feed_options[ 'cacheunit' ] : get_option( 'cff_cache_time_unit', 'hours' );
1786
1787 $maybe_legacy_shortcode = $feed_options;
1788 if ( isset( $maybe_legacy_shortcode['feed'] ) ) {
1789 unset( $maybe_legacy_shortcode['feed'] );
1790 }
1791
1792 // Merge in legacy settings (shortcode only settings)
1793 if ( ! empty( $maybe_legacy_shortcode ) ) {
1794 $legacy_shortcode_settings = [
1795 'width',
1796 'widthresp',
1797 'mediaposition',
1798 'masonryjs',
1799 'colsjs',
1800 'textformat',
1801 //all text weight settings
1802 'textweight',
1803 'descweight',
1804 'eventtitleweight',
1805 'eventdateweight',
1806 'eventdetailsweight',
1807 'dateweight',
1808 'linkweight',
1809 'headertextweight',
1810 'posttags',
1811 'linkhashtags',
1812 'offset',
1813 'cff_enqueue_with_shortcode',
1814 'commentsnum',
1815 'restrictedpage',
1816 'hidesupporterposts',
1817 'privategroup',
1818 'fulllinkimages',
1819 'linkimagesize',
1820 'postimagesize',
1821 'videoheight',
1822 'videoaction',
1823 'videoplayer',
1824 'class',
1825 'padding'
1826 ];
1827
1828 foreach ( $maybe_legacy_shortcode as $maybe_legacy => $value ) {
1829 if ( in_array( $maybe_legacy, $legacy_shortcode_settings, true ) ) {
1830 $settings[ $maybe_legacy ] = $value;
1831 }
1832 }
1833
1834 if ( $settings['posttags'] === 'false' ) {
1835 $settings['posttags'] = false;
1836 }
1837
1838 if ( $settings['linkhashtags'] === 'false' ) {
1839 $settings['linkhashtags'] = false;
1840 }
1841 }
1842
1843 if ( ! CFF_Utils::cff_is_pro_version() ) {
1844 $this->page_id = $settings['id'];
1845 $encryption = new SB_Facebook_Data_Encryption();
1846 $this->access_token = $encryption->decrypt($settings['accesstoken']) ? $encryption->decrypt($settings['accesstoken']) : $settings['accesstoken'];
1847 $this->feed_id = ! empty( $feed_id ) ? $feed_id : 'default';
1848 }
1849
1850 return \CustomFacebookFeed\Builder\CFF_Post_Set::builder_to_general_settings_convert( $settings );
1851 }
1852
1853 /**********
1854 * Ported from Pro version, could use cleanup
1855 *
1856 * TODO: Remove all or part of functions not needed for free
1857 *************/
1858
1859 /**
1860 * this where you could take the feed options to get the feed data for the first set
1861 * of posts or, if the $before and $after parameters are set, get the next set of posts
1862 *
1863 * @since 3.18
1864 */
1865 static function cff_get_json_data( $feed_options, $next_urls_arr_safe, $data_att_html, $is_customizer = false ) {
1866 //Define vars
1867 $access_token = $feed_options['accesstoken'];
1868 //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
1869 $feed_options['ownaccesstoken'] ? $cff_show_access_token = true : $cff_show_access_token = true;
1870 //Reviews Access Token
1871 $page_access_token = $feed_options['pagetoken'];
1872 $cff_show_access_token = true;
1873 $page_id = trim( $feed_options['id'] );
1874 $show_posts = isset( $feed_options['minnum'] ) ? $feed_options['minnum'] : $feed_options['num'];
1875 $show_posts_number = isset( $feed_options['minnum'] ) ? $feed_options['minnum'] : $feed_options['num'];
1876
1877 $cff_post_limit = $feed_options['limit'];
1878 $cff_page_type = $feed_options[ 'pagetype' ];
1879 $show_others = $feed_options['others'];
1880 $show_posts_by = $feed_options['showpostsby'];
1881 $cff_caching_type = $feed_options['cachetype'];
1882 $cff_cache_time = $feed_options['cachetime'];
1883 $cff_cache_time_unit = $feed_options['cacheunit'];
1884 $cff_locale = $feed_options['locale'];
1885 //Post types
1886 $cff_types = $feed_options['type'];
1887 $cff_events_source = $feed_options[ 'eventsource' ];
1888 $cff_event_offset = $feed_options[ 'eventoffset' ];
1889 $cff_albums_source = $feed_options[ 'albumsource' ];
1890 $cff_photos_source = $feed_options[ 'photosource' ];
1891 $cff_videos_source = $feed_options[ 'videosource' ];
1892 //Past events
1893 $cff_past_events = $feed_options['pastevents'];
1894 //Active extensions
1895 $cff_ext_multifeed_active = $feed_options[ 'multifeedactive' ];
1896 #$cff_ext_date_active = $feed_options[ 'daterangeactive' ];
1897 $cff_ext_date_active = CFF_FB_Settings::check_active_extension( 'date_range' ) && CFF_Utils::check_if_on($feed_options['daterange']);
1898
1899 $cff_featured_post_active = $feed_options[ 'featuredpostactive' ];
1900 $cff_album_active = $feed_options[ 'albumactive' ];
1901 $cff_masonry_columns_active = false; //Deprecated
1902 $cff_carousel_active = $feed_options[ 'carouselactive' ];
1903 $cff_reviews_active = $feed_options[ 'reviewsactive' ];
1904 //Extension settings
1905 $cff_album_id = $feed_options['album'];
1906 $cff_featured_post_id = $feed_options['featuredpost'];
1907 $include_extras = isset( $feed_options['include_extras'] );
1908
1909 //Get show posts attribute. If not set then default to 25
1910 if (empty($show_posts)) $show_posts = 25;
1911 if ( $show_posts == 0 || $show_posts == 'undefined' ) $show_posts = 25;
1912
1913 //Set the page type
1914 $cff_is_group = false;
1915 if ($cff_page_type == 'group') $cff_is_group = true;
1916
1917 //Look for non-plural version of string in the types string in case user specifies singular in shortcode
1918 $cff_show_links_type = true;
1919 $cff_show_event_type = true;
1920 $cff_show_video_type = true;
1921 $cff_show_photos_type = true;
1922 $cff_show_status_type = true;
1923 $cff_show_albums_type = true;
1924
1925 $cff_events_only = false;
1926 $cff_albums_only = false;
1927 $cff_photos_only = false;
1928 $cff_videos_only = false;
1929
1930 //Is it SSL?
1931 $cff_ssl = '';
1932 if (is_ssl()) $cff_ssl = '&return_ssl_resources=true';
1933
1934 //Use posts? or feed?
1935 $graph_query = 'posts';
1936 $cff_show_only_others = false;
1937
1938 //If 'others' shortcode option is used then it overrides any other option
1939 if ($show_others) {
1940 //Show posts by everyone
1941 if ( $show_others == 'on' || $show_others == 'true' || $show_others == true || $cff_is_group ) $graph_query = 'feed';
1942 //Only show posts by me
1943 if ( $show_others == 'false' ) $graph_query = 'posts';
1944 } else {
1945 //Else use the settings page option or the 'showpostsby' shortcode option
1946 //Only show posts by me
1947 if ( $show_posts_by == 'me' ) $graph_query = 'posts';
1948 //Show posts by everyone
1949 if ( $show_posts_by == 'others' || $cff_is_group ) $graph_query = 'feed';
1950 //Show posts ONLY by others
1951 if ( $show_posts_by == 'onlyothers' && !$cff_is_group ) {
1952 $graph_query = 'visitor_posts';
1953 $cff_show_only_others = true;
1954 }
1955 }
1956
1957
1958 //Calculate the cache time in seconds
1959 if($cff_cache_time_unit == 'minutes') $cff_cache_time_unit = 60;
1960 if($cff_cache_time_unit == 'hour' || $cff_cache_time_unit == 'hours') $cff_cache_time_unit = 60*60;
1961 if($cff_cache_time_unit == 'days') $cff_cache_time_unit = 60*60*24;
1962 if ( intval( $cff_cache_time ) < 1 ) {
1963 $cff_cache_time = 1;
1964 }
1965 $cache_seconds = intval( $cff_cache_time ) * intval( $cff_cache_time_unit );
1966
1967
1968 //********************************************//
1969 //*****************GET POSTS******************//
1970 //********************************************//
1971 $FBdata_arr = array(); //Use an array to store the data for each page ID (for multifeed)
1972 $page_ids = array($page_id);
1973
1974
1975 //If the limit isn't set then set it to be 7 more than the number of posts defined
1976 if ( isset($cff_post_limit) && $cff_post_limit !== '' ) {
1977 $cff_post_limit = $cff_post_limit;
1978 } else {
1979 if( intval($show_posts) >= 50 ) $cff_post_limit = intval(intval($show_posts) + 7);
1980 if( intval($show_posts) < 50 ) $cff_post_limit = intval(intval($show_posts) + 5);
1981 if( intval($show_posts) < 25 ) $cff_post_limit = intval(intval($show_posts) + 4);
1982 if( intval($show_posts) < 10 ) $cff_post_limit = intval(intval($show_posts) + 3);
1983 if( intval($show_posts) < 6 ) $cff_post_limit = intval(intval($show_posts) + 2);
1984 if( intval($show_posts) < 2 ) $cff_post_limit = intval(intval($show_posts) + 1);
1985
1986 //If using multifeed then set the limit dynamically based on the number of pages if it isn't set
1987 if( $cff_ext_multifeed_active && count($page_ids) > 1 ){
1988 $cff_post_limit = ( ceil(intval($show_posts) / count($page_ids)) ) + 1;
1989 }
1990 }
1991 if( $cff_post_limit >= 100 ) $cff_post_limit = 100;
1992
1993 //If the number of posts is set to zero then don't show any and set limit to one
1994 if ( ($show_posts == '0' || $show_posts == 0) && $show_posts !== ''){
1995 $show_posts = 0;
1996 $cff_post_limit = 1;
1997 }
1998
1999 //If the timeline pagination method is set to use the API paging method then set the limit to be the number of posts displayed so that posts aren't skipped when loading more
2000 if( $feed_options['timelinepag'] == 'paging' ) $cff_post_limit = $show_posts;
2001
2002
2003 //Loop through page IDs
2004 foreach ( $page_ids as $page_id ) {
2005
2006 //********************************************//
2007 //********CREATE THE API REQUEST URL**********//
2008 //********************************************//
2009
2010 //ALL POSTS
2011
2012 //Add option to remove attachments description field to workaround Facebook "Unsupported Get Request" bug caused by sales posts in the API request
2013 $attachments_desc = ( $feed_options['salesposts'] == 'true' ) ? '' : ',description';
2014
2015 //Add option to remove story_tags to workaround Facebook "Unknown Error" message returned by API for certain posts
2016 $story_tags = ( $feed_options['storytags'] == 'true' ) ? '' : ',story_tags';
2017 $cff_posts_json_url = 'https://graph.facebook.com/v4.0/' . $page_id . '/' . $graph_query . '?fields=id,updated_time,from{picture,id,name,link},message,message_tags,story'. $story_tags .',picture,full_picture,status_type,created_time,backdated_time,attachments{title'. $attachments_desc .',media_type,unshimmed_url,target{id},multi_share_end_card,media{source,image},subattachments},shares,call_to_action,privacy&access_token=' . $access_token . '&limit=' . $cff_post_limit . '&locale=' . $cff_locale . $cff_ssl;
2018
2019
2020 //********************************************//
2021 //*********CREATE THE TRANSIENT NAME**********//
2022 //********************************************//
2023
2024
2025
2026 //ALL POSTS
2027 if (!$cff_events_only || ($cff_events_only && $cff_events_source == 'timeline') ){
2028
2029 //If it's a playlist then use the playlist ID instead of the Page ID
2030 $page_id_caching = $page_id;
2031 if( $feed_options['playlist'] ){
2032 $page_id_caching = $feed_options['playlist'];
2033 }
2034
2035 $trans_items_arr = array(
2036 'page_id' => $page_id_caching,
2037 'post_limit' => substr($cff_post_limit, 0, 3),
2038 'show_posts_by' => substr($show_posts_by, 0, 2),
2039 'locale' => $cff_locale
2040 );
2041
2042 $trans_arr_item_count = 1;
2043 if( $cff_featured_post_active && !empty($cff_featured_post_id) ){
2044 $trans_items_arr['featured_post'] = $cff_featured_post_id;
2045 $trans_arr_item_count++;
2046 }
2047 if($cff_albums_only) $trans_items_arr['albums_source'] = $cff_albums_source;
2048 $trans_items_arr['albums_only'] = intval($cff_albums_only);
2049 $trans_items_arr['photos_only'] = intval($cff_photos_only);
2050 $trans_items_arr['videos_only'] = intval($cff_videos_only);
2051
2052 $arr_item_max_length = floor( 28/$trans_arr_item_count ); //40 minus the 12 needed for the other 7 values shown below equals 28
2053 $arr_item_max_length_half = floor($arr_item_max_length/2);
2054
2055 $transient_name = 'cff_';
2056 foreach ($trans_items_arr as $key => $value) {
2057 if($value !== false){
2058 if( $key == 'page_id' || $key == 'featured_post' || $key == 'from' || $key == 'until' ) $transient_name .= substr($value, 0, $arr_item_max_length_half) . substr($value, $arr_item_max_length_half*-1); //-10
2059 if( $key == 'locale' ) $transient_name .= substr($value, 0, 2);
2060 if( $key == 'post_limit' || $key == 'show_posts_by' ) $transient_name .= substr($value, 0, 3);
2061 if( $key == 'albums_only' || $key == 'photos_only' || $key == 'videos_only' || $key == 'albums_source' || $key == 'reviews' ) $transient_name .= substr($value, 0, 1);
2062 }
2063 }
2064 //Make sure it's not more than 45 chars
2065 $transient_name = substr($transient_name, 0, 45);
2066
2067 //ALBUM EMBED
2068 if( $cff_album_active && !empty($cff_album_id) ) {
2069 $transient_name = 'cff_album_' . $cff_album_id . '_' . $cff_post_limit;
2070 $transient_name = substr($transient_name, 0, 45);
2071 }
2072
2073 } //END ALL POSTS
2074
2075
2076
2077 //Are there more posts to get for this ID?
2078 $cff_more_posts = true;
2079
2080 //If the cron caching is enabled then set the caching time to be long so that it doesn't expire before rechecked in the cron function
2081 if( false == 'background' ) $cache_seconds = 7 * DAY_IN_SECONDS;
2082
2083
2084 //ALL POSTS
2085 $posts_json = CFF_Utils::cff_get_set_cache($cff_posts_json_url, $transient_name, $cff_cache_time, $cache_seconds, $data_att_html, $cff_show_access_token, $access_token, true);
2086 if( $cff_is_group ){
2087 $groups_post = new CFF_Group_Posts($page_id, $feed_options, $cff_posts_json_url, $data_att_html, false);
2088 $groups_post_result = $groups_post->init_group_posts($posts_json, false, $show_posts_number);
2089 $posts_json = $groups_post_result['posts_json'];
2090 }
2091 //ALBUM EMBED
2092 if( $cff_album_active && !empty($cff_album_id) ) $album_json = $posts_json;
2093
2094 //Interpret data with JSON
2095 $FBdata = json_decode($posts_json);
2096
2097 if ( false /*$is_customizer*/ ) {
2098 //Get more data about single events since timelines don't have it
2099 $can_check_for_events = false;
2100 $event_supporting_access_tokens = array();
2101 if ( isset( $feed_options['sources'][0] ) ) {
2102 foreach ( $feed_options['sources'] as $source ) {
2103 #if ( $source['privilege'] === 'events' ) {
2104 $can_check_for_events = true;
2105 $event_supporting_access_tokens[ $source['account_id'] ] = $source['access_token'];
2106 # }
2107 }
2108 }
2109
2110
2111 if ( $can_check_for_events ) {
2112 if ( isset( $FBdata->data ) ) {
2113 $post_index = 0;
2114 foreach ( $FBdata->data as $post ) {
2115 $type = CFF_Parse::get_status_type( $post );
2116
2117 if ( $type === 'created_event' ) {
2118 $account_id = CFF_Parse::get_from_id( $post );
2119 $post_id = CFF_Parse::get_post_id( $post );
2120 $event_id = explode( '_', $post_id );
2121 $event_id = $event_id[1];
2122
2123 if ( ! empty( $event_supporting_access_tokens[ $account_id ] ) ) {
2124 $single_data = CFF_Shortcode::get_single_event_data( $event_id, $event_supporting_access_tokens[ $account_id ] );
2125 foreach( $single_data as $property => $value ) {
2126 $FBdata->data[ $post_index ]->$property = $value;
2127 }
2128
2129 }
2130 }
2131 $post_index++;
2132 }
2133 }
2134 }
2135 }
2136
2137
2138 if( $cff_more_posts ){
2139 //Add the data to the array to be returned and parsed into HTML
2140 $FBdata_arr[$page_id] = $FBdata;
2141 } else {
2142 //Add something to the array for the ID if there's no posts to prevent any PHP notices
2143 $FBdata_arr[$page_id] = 'no_more_posts';
2144 }
2145
2146 //Add the API URL to the json array so that we can grab it and add to the button if needed
2147 if( isset($FBdata_arr[$page_id]) ){
2148 if( !isset($FBdata_arr[$page_id]->api_url) && $FBdata_arr[$page_id] != 'no_more_posts' ){
2149 //Replace the actual token with the Access Token placeholder
2150 $cff_api_url = str_replace($access_token,"x_cff_hide_token_x",$cff_posts_json_url);
2151 //Add it to the json array
2152 $FBdata_arr[$page_id]->api_url = $cff_api_url;
2153 }
2154 }
2155
2156 } //End page_id loop
2157
2158 if($cff_is_group && isset($FBdata_arr[$page_id]) && $FBdata_arr[$page_id] != 'no_more_posts'){
2159 $FBdata_arr[$page_id]->is_load_cache = (isset($groups_post_result['latest_record_date'])) && $groups_post_result['latest_record_date'] !== 0 && $groups_post_result['load_from_cache'] !== false ? $groups_post_result['load_from_cache'] : false;
2160 $FBdata_arr[$page_id]->latest_record_date = $groups_post_result['latest_record_date'];
2161 }
2162 return $FBdata_arr;
2163 }
2164
2165 /**
2166 * this function breaks up the "next" url from the json data into an array of parts to load into
2167 * the html to be retrieved on click and pieced back together
2168 *
2169 * @since 3.18
2170 */
2171 static function cff_get_next_url_parts( $json_data_arr ) {
2172 $next_urls_arr_safe = '{';
2173 $next_urls_arr_safe .= '}';
2174 //If the array ends in a comma then remove the comma
2175 return $next_urls_arr_safe;
2176 }
2177
2178 public static function get_single_event_data( $eventID, $access_token ) {
2179 $encryption = new SB_Facebook_Data_Encryption();
2180
2181 //Is it SSL?
2182 $cff_ssl = '';
2183 if (is_ssl()) $cff_ssl = '&return_ssl_resources=true';
2184
2185 //Get the contents of the event
2186 $event_json_url = 'https://graph.facebook.com/v3.3/'.$eventID.'?fields=cover,place,name,owner,start_time,timezone,id,comments.summary(true){message,created_time},description&access_token=' . $access_token . $cff_ssl;
2187
2188 // Get any existing copy of our transient data
2189 $transient_name = 'cff_tle_' . $eventID;
2190 $transient_name = substr($transient_name, 0, 45);
2191
2192 if ( false === ( $event_json = $encryption->maybe_decrypt( get_transient( $transient_name ) ) ) || $event_json === null ) {
2193 //Get the contents of the Facebook page
2194 $event_json = CFF_Utils::cff_fetchUrl($event_json_url);
2195 //Cache the JSON for 180 days as the timeline event info probably isn't going to change
2196 set_transient( $transient_name, $encryption->maybe_encrypt( $event_json ) , 60 * 60 * 24 * 180 );
2197 } else {
2198 $event_json = $encryption->maybe_decrypt( get_transient( $transient_name ) );
2199 //If we can't find the transient then fall back to just getting the json from the api
2200 if ($event_json == false) $event_json = CFF_Utils::cff_fetchUrl($event_json_url);
2201 }
2202
2203 //Interpret data with JSON
2204 $event_object = json_decode($event_json);
2205
2206 $description_text = '';
2207 if( isset($event_object->name) ) $description_text .= $event_object->name . ' ';
2208 if( isset($event_object->place->location->city) ) $description_text .= $event_object->place->location->city . ' ';
2209 if( isset($event_object->place->location->country) ) $description_text .= $event_object->place->location->country . ' ';
2210 if( isset($event_object->place->location->street) ) $description_text .= $event_object->place->location->street . ' ';
2211 if( isset($event_object->place->name) ) $description_text .= $event_object->place->name . ' ';
2212 if( isset($event_object->description) ) $description_text .= $event_object->description;
2213 $event_object->description_text = $description_text;
2214
2215 return $event_object;
2216
2217 }
2218
2219 public static function add_translations( $atts ) {
2220 $translations = get_option( 'cff_style_settings', false );
2221
2222 $final_translations = [
2223 'seemoretext' => isset( $translations[ 'cff_see_more_text' ] ) ? stripslashes( esc_attr( $translations[ 'cff_see_more_text' ] ) ) : __( 'See More', 'custom-facebook-feed' ),
2224 'seelesstext' => isset( $translations[ 'cff_see_less_text' ] ) ? stripslashes( esc_attr( $translations[ 'cff_see_less_text' ] ) ) : __( 'See Less', 'custom-facebook-feed' ),
2225 'facebooklinktext' => isset( $translations[ 'cff_facebook_link_text' ] ) ? stripslashes( esc_attr( $translations[ 'cff_facebook_link_text' ] ) ) : __( 'View on Facebook', 'custom-facebook-feed' ),
2226 'sharelinktext' => isset( $translations[ 'cff_facebook_share_text' ] ) ? stripslashes( esc_attr( $translations[ 'cff_facebook_share_text' ] ) ) : __( 'Share', 'custom-facebook-feed' ),
2227
2228 'learnmoretext' => isset( $translations[ 'cff_translate_learn_more_text' ] ) ? stripslashes( esc_attr( $translations[ 'cff_translate_learn_more_text' ] ) ) : __( 'Learn More', 'custom-facebook-feed' ),
2229 'shopnowtext' => isset( $translations[ 'cff_translate_shop_now_text' ] ) ? stripslashes( esc_attr( $translations[ 'cff_translate_shop_now_text' ] ) ) : __( 'Shop Now', 'custom-facebook-feed' ),
2230 'messagepage' => isset( $translations[ 'cff_translate_message_page_text' ] ) ? stripslashes( esc_attr( $translations[ 'cff_translate_message_page_text' ] ) ) : __( 'Message Page', 'custom-facebook-feed' ),
2231 'getdirections' => isset( $translations[ 'cff_translate_get_directions_text' ] ) ? stripslashes( esc_attr( $translations[ 'cff_translate_get_directions_text' ] ) ) : __( 'Get Directions', 'custom-facebook-feed' ),
2232
2233 'secondtext' => isset( $translations[ 'cff_translate_second' ] ) ? stripslashes( esc_attr( $translations[ 'cff_translate_second' ] ) ) : 'second',
2234 'secondstext' => isset( $translations[ 'cff_translate_seconds' ] ) ? stripslashes( esc_attr( $translations[ 'cff_translate_seconds' ] ) ) : 'seconds',
2235 'minutetext' => isset( $translations[ 'cff_translate_minute' ] ) ? stripslashes( esc_attr( $translations[ 'cff_translate_minute' ] ) ) : 'minute',
2236 'minutestext' => isset( $translations[ 'cff_translate_minutes' ] ) ? stripslashes( esc_attr( $translations[ 'cff_translate_minutes' ] ) ) : 'minutes',
2237 'hourtext' => isset( $translations[ 'cff_translate_hour' ] ) ? stripslashes( esc_attr( $translations[ 'cff_translate_hour' ] ) ) : 'hour',
2238 'hourstext' => isset( $translations[ 'cff_translate_hours' ] ) ? stripslashes( esc_attr( $translations[ 'cff_translate_hours' ] ) ) : 'hours',
2239 'daytext' => isset( $translations[ 'cff_translate_day' ] ) ? stripslashes( esc_attr( $translations[ 'cff_translate_day' ] ) ) : 'day',
2240 'daystext' => isset( $translations[ 'cff_translate_days' ] ) ? stripslashes( esc_attr( $translations[ 'cff_translate_days' ] ) ) : 'days',
2241 'weektext' => isset( $translations[ 'cff_translate_week' ] ) ? stripslashes( esc_attr( $translations[ 'cff_translate_week' ] ) ) : 'week',
2242 'weekstext' => isset( $translations[ 'cff_translate_weeks' ] ) ? stripslashes( esc_attr( $translations[ 'cff_translate_weeks' ] ) ) : 'weeks',
2243 'monthtext' => isset( $translations[ 'cff_translate_month' ] ) ? stripslashes( esc_attr( $translations[ 'cff_translate_month' ] ) ) : 'month',
2244 'monthstext' => isset( $translations[ 'cff_translate_months' ] ) ? stripslashes( esc_attr( $translations[ 'cff_translate_months' ] ) ) : 'months',
2245 'yeartext' => isset( $translations[ 'cff_translate_year' ] ) ? stripslashes( esc_attr( $translations[ 'cff_translate_year' ] ) ) : 'year',
2246 'yearstext' => isset( $translations[ 'cff_translate_years' ] ) ? stripslashes( esc_attr( $translations[ 'cff_translate_years' ] ) ) : 'years',
2247 'agotext' => isset( $translations[ 'cff_translate_ago' ] ) ? stripslashes( esc_attr( $translations[ 'cff_translate_ago' ] ) ) : 'ago',
2248
2249 'phototext' => isset( $translations[ 'cff_translate_photo_text' ] ) ? stripslashes( esc_attr( $translations[ 'cff_translate_photo_text' ] ) ) : '',
2250 'videotext' => isset( $translations[ 'cff_translate_video_text' ] ) ? stripslashes( esc_attr( $translations[ 'cff_translate_video_text' ] ) ) : '',
2251 ];
2252
2253
2254 $final_translations['facebooklinktext'] = ! empty( $atts['facebooklinktext'] ) ? $atts['facebooklinktext'] : $final_translations['facebooklinktext'];
2255 $final_translations['sharelinktext'] = ! empty( $atts['sharelinktext'] ) ? $atts['sharelinktext'] : $final_translations['sharelinktext'];
2256
2257 $atts = array_merge( $atts, $final_translations );
2258
2259 return $atts;
2260
2261 }
2262
2263 function cff_add_translations() {
2264 $this->atts = CFF_Shortcode::add_translations( $this->atts );
2265 }
2266
2267
2268 }
2269