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