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