PluginProbe ʕ •ᴥ•ʔ
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress / trunk
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress vtrunk
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 / admin / admin-functions.php
custom-facebook-feed / admin Last commit date
assets 3 weeks ago builder 3 weeks ago templates 4 months ago views 3 weeks ago addon-functions.php 4 months ago admin-functions.php 4 months ago enqueu-script.php 4 months ago index.php 4 months ago
admin-functions.php
595 lines
1 <?php
2 if (! defined('ABSPATH')) {
3 exit; // Exit if accessed directly
4 }
5 use CustomFacebookFeed\CFF_Utils;
6 use CustomFacebookFeed\CFF_Oembed;
7 use CustomFacebookFeed\CFF_GDPR_Integrations;
8 use CustomFacebookFeed\CFF_Feed_Locator;
9 use CustomFacebookFeed\SB_Facebook_Data_Manager;
10
11 add_action('group_post_scheduler_cron', 'cff_group_cache_function');
12 function cff_group_cache_function()
13 {
14 CustomFacebookFeed\CFF_Group_Posts::cron_update_group_persistent_cache();
15 }
16
17 // Create Style page
18 /**
19 * @deprecated
20 */
21 function cff_style_page()
22 {
23 } //End Style_Page
24
25 // Create Settings page
26 /**
27 * @deprecated
28 */
29 function cff_settings_page()
30 {
31 } //End Settings_Page
32
33 /**
34 * @deprecated
35 */
36 function cff_oembeds_page()
37 {
38 }
39
40 /**
41 * @deprecated
42 */
43 function cff_social_wall_page()
44 {
45 }
46
47 function cff_lite_dismiss()
48 {
49 check_ajax_referer('cff_nonce', 'cff_nonce');
50
51 $cap = current_user_can('manage_custom_facebook_feed_options') ? 'manage_custom_facebook_feed_options' : 'manage_options';
52 $cap = apply_filters('cff_settings_pages_capability', $cap);
53 if (! current_user_can($cap)) {
54 wp_send_json_error(); // This auto-dies.
55 }
56
57 set_transient('facebook_feed_dismiss_lite', 'dismiss', 1 * WEEK_IN_SECONDS);
58
59 die();
60 }
61 add_action('wp_ajax_cff_lite_dismiss', 'cff_lite_dismiss');
62
63 // If PPCA notice is dismissed then don't show again
64 add_action('admin_init', 'cff_nag_ppca_ignore');
65 function cff_nag_ppca_ignore()
66 {
67 global $current_user;
68 $cap = current_user_can('manage_custom_facebook_feed_options') ? 'manage_custom_facebook_feed_options' : 'manage_options';
69 $cap = apply_filters('cff_settings_pages_capability', $cap);
70 if (!current_user_can($cap)) {
71 return;
72 }
73
74 $user_id = $current_user->ID;
75 if (isset($_GET['cff_nag_ppca_ignore']) && '0' == $_GET['cff_nag_ppca_ignore']) {
76 if (!empty($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'cff_nonce')) {
77 add_user_meta($user_id, 'cff_ignore_ppca_notice', 'true', true);
78 }
79 }
80 }
81
82
83 // Add a Settings link to the plugin on the Plugins page
84 $cff_plugin_file = 'custom-facebook-feed/custom-facebook-feed.php';
85 add_filter("plugin_action_links_{$cff_plugin_file}", 'cff_add_settings_link', 10, 2);
86
87 // modify the link by unshifting the array
88 function cff_add_settings_link($links, $file)
89 {
90 $pro_link = '<a href="https://smashballoondemo.com/?utm_campaign=facebook-free&utm_source=plugins-page&utm_medium=upgrade-link" target="_blank" style="font-weight: bold; color: #1da867;">' . __('Try the Pro Demo', 'custom-facebook-feed') . '</a>';
91 $cff_settings_link = '<a href="' . admin_url('admin.php?page=cff-feed-builder') . '">' . __('Settings', 'cff-feed-builder', 'custom-facebook-feed') . '</a>';
92 array_unshift($links, $pro_link, $cff_settings_link);
93
94 return $links;
95 }
96
97
98 // Delete cache
99 function cff_delete_cache()
100 {
101 global $wpdb;
102 $table_name = $wpdb->prefix . "options";
103 $wpdb->query("
104 DELETE
105 FROM $table_name
106 WHERE `option_name` LIKE ('%\_transient\_cff\_%')
107 ");
108 $wpdb->query("
109 DELETE
110 FROM $table_name
111 WHERE `option_name` LIKE ('%\_transient\_cff\_tle\_%')
112 ");
113 $wpdb->query("
114 DELETE
115 FROM $table_name
116 WHERE `option_name` LIKE ('%\_transient\_timeout\_cff\_%')
117 ");
118
119 // Clear cache of major caching plugins
120 if (isset($GLOBALS['wp_fastest_cache']) && method_exists($GLOBALS['wp_fastest_cache'], 'deleteCache')) {
121 $GLOBALS['wp_fastest_cache']->deleteCache();
122 }
123 // WP Super Cache
124 if (function_exists('wp_cache_clear_cache')) {
125 wp_cache_clear_cache();
126 }
127 // W3 Total Cache
128 if (function_exists('w3tc_flush_all')) {
129 w3tc_flush_all();
130 }
131 if (function_exists('sg_cachepress_purge_cache')) {
132 sg_cachepress_purge_cache();
133 }
134
135 // Litespeed Cache
136 if (method_exists('LiteSpeed_Cache_API', 'purge')) {
137 LiteSpeed_Cache_API::purge('esi.custom-facebook-feed');
138 }
139
140 \CustomFacebookFeed\Admin\CFF_Support_Tool::delete_expired_users();
141 }
142
143 // Cron job to clear transients
144 add_action('cff_cron_job', 'cff_cron_clear_cache');
145 function cff_cron_clear_cache()
146 {
147 // Delete all transients
148 cff_delete_cache();
149 }
150
151 // NOTICES
152 function cff_get_current_time()
153 {
154 $current_time = time();
155
156 // where to do tests
157 // $current_time = strtotime( 'November 25, 2020' );
158
159 return $current_time;
160 }
161
162 // generates the html for the admin notices
163 function cff_notices_html()
164 {
165 // reset everything for testing
166 /*
167 global $current_user;
168 $user_id = $current_user->ID;
169 delete_user_meta( $user_id, 'cff_ignore_bfcm_sale_notice' );
170 delete_user_meta( $user_id, 'cff_ignore_new_user_sale_notice' );
171 $cff_statuses_option = array( 'first_install' => strtotime( 'December 8, 2017' ) );
172 $cff_statuses_option = array( 'first_install' => time() );
173
174 update_option( 'cff_statuses', $cff_statuses_option, false );
175 delete_option( 'cff_rating_notice');
176 delete_transient( 'custom_facebook_rating_notice_waiting' );
177
178 // set_transient( 'custom_facebook_rating_notice_waiting', 'waiting', 2 * WEEK_IN_SECONDS );
179 delete_transient('custom_facebook_rating_notice_waiting');
180 update_option( 'cff_rating_notice', 'pending', false );
181 */
182 }
183
184 function cff_get_future_date($month, $year, $week, $day, $direction)
185 {
186 if ($direction > 0) {
187 $startday = 1;
188 } else {
189 $startday = date('t', mktime(0, 0, 0, $month, 1, $year));
190 }
191
192 $start = mktime(0, 0, 0, $month, $startday, $year);
193 $weekday = date('N', $start);
194
195 $offset = 0;
196 if ($direction * $day >= $direction * $weekday) {
197 $offset = -$direction * 7;
198 }
199
200 $offset += $direction * ($week * 7) + ($day - $weekday);
201 return mktime(0, 0, 0, $month, $startday + $offset, $year);
202 }
203
204 function cff_admin_hide_unrelated_notices()
205 {
206
207 // Bail if we're not on a cff screen or page.
208 if (! isset($_GET['page']) || strpos($_GET['page'], 'cff') === false) {
209 return;
210 }
211
212 // Extra banned classes and callbacks from third-party plugins.
213 $blacklist = array(
214 'classes' => array(),
215 'callbacks' => array(
216 'cffdb_admin_notice', // 'Database for cff' plugin.
217 ),
218 );
219
220 global $wp_filter;
221
222 foreach (array( 'user_admin_notices', 'admin_notices', 'all_admin_notices' ) as $notices_type) {
223 if (empty($wp_filter[ $notices_type ]->callbacks) || ! is_array($wp_filter[ $notices_type ]->callbacks)) {
224 continue;
225 }
226 foreach ($wp_filter[ $notices_type ]->callbacks as $priority => $hooks) {
227 foreach ($hooks as $name => $arr) {
228 if (is_object($arr['function']) && $arr['function'] instanceof Closure) {
229 unset($wp_filter[ $notices_type ]->callbacks[ $priority ][ $name ]);
230 continue;
231 }
232 $class = ! empty($arr['function'][0]) && is_object($arr['function'][0]) ? strtolower(get_class($arr['function'][0])) : '';
233 if (
234 ! empty($class) &&
235 strpos($class, 'cff') !== false &&
236 ! in_array($class, $blacklist['classes'], true)
237 ) {
238 continue;
239 }
240 if (
241 ! empty($name) && (
242 strpos($name, 'cff') === false ||
243 in_array($class, $blacklist['classes'], true) ||
244 in_array($name, $blacklist['callbacks'], true)
245 )
246 ) {
247 unset($wp_filter[ $notices_type ]->callbacks[ $priority ][ $name ]);
248 }
249 }
250 }
251 }
252 }
253 add_action('admin_print_scripts', 'cff_admin_hide_unrelated_notices');
254
255 /**
256 * Remove admin notices from inside our plugin screens so we can show our customized notices
257 *
258 * @since 4.0
259 */
260 add_action('in_admin_header', 'cff_remove_admin_notices');
261 function cff_remove_admin_notices()
262 {
263 $current_screen = get_current_screen();
264 $not_allowed_screens = array(
265 'facebook-feed_page_cff-feed-builder',
266 'facebook-feed_page_cff-settings',
267 'facebook-feed_page_cff-oembeds-manager',
268 'facebook-feed_page_cff-extensions-manager',
269 'facebook-feed_page_cff-about-us',
270 'facebook-feed_page_cff-support',
271 );
272
273 if (in_array($current_screen->base, $not_allowed_screens) || strpos($current_screen->base, 'cff-') !== false) {
274 remove_all_actions('admin_notices');
275 remove_all_actions('all_admin_notices');
276 }
277 }
278
279 function cff_free_add_caps()
280 {
281 global $wp_roles;
282
283 $wp_roles->add_cap('administrator', 'manage_custom_facebook_feed_options');
284 }
285 add_action('admin_init', 'cff_free_add_caps', 90);
286
287
288
289
290
291 function cff_oembed_disable()
292 {
293 check_ajax_referer('cff_nonce', 'cff_nonce');
294
295 $cap = current_user_can('manage_custom_facebook_feed_options') ? 'manage_custom_facebook_feed_options' : 'manage_options';
296 $cap = apply_filters('cff_settings_pages_capability', $cap);
297 if (! current_user_can($cap)) {
298 wp_send_json_error(); // This auto-dies.
299 }
300
301 $oembed_settings = get_option('cff_oembed_token', array());
302 $oembed_settings['access_token'] = '';
303 $oembed_settings['disabled'] = true;
304 echo '<strong>';
305 if (update_option('cff_oembed_token', $oembed_settings)) {
306 _e('Facebook oEmbeds will no longer be handled by Custom Facebook Feed.', 'custom-facebook-feed');
307 } else {
308 _e('An error occurred when trying to disable your oEmbed token.', 'custom-facebook-feed');
309 }
310 echo '</strong>';
311
312 die();
313 }
314 add_action('wp_ajax_cff_oembed_disable', 'cff_oembed_disable');
315
316
317
318 function cff_custom_cssjs_notice()
319 {
320 $cff_statuses_option = get_option('cff_statuses', array());
321 if (! empty($cff_statuses_option['custom_js_css_dismissed'])) {
322 return;
323 }
324
325 if (! empty($_GET['cff_dismiss_notice']) && $_GET['cff_dismiss_notice'] === 'customjscss') {
326 $cff_statuses_option['custom_js_css_dismissed'] = true;
327 update_option('cff_statuses', $cff_statuses_option, false);
328 return;
329 }
330 $cff_style_settings = get_option('cff_style_settings');
331
332 $custom_js_not_empty = ! empty($cff_style_settings['cff_custom_js']) && trim($cff_style_settings['cff_custom_js']) !== '';
333 $custom_css_not_empty = ! empty($cff_style_settings['cff_custom_css_read_only']) && trim($cff_style_settings['cff_custom_css_read_only']) !== '';
334
335 if (! $custom_js_not_empty && ! $custom_css_not_empty) {
336 return;
337 }
338
339 $cff_notifications = new \CustomFacebookFeed\Admin\CFF_Notifications();
340 $notifications = $cff_notifications->get();
341
342 if (! empty($notifications) && ( ! empty($_GET['page']) && strpos($_GET['page'], 'cff-') !== false )) {
343 return;
344 }
345 $close_href = add_query_arg(array( 'cff_dismiss_notice' => 'customjscss' ));
346
347 ?>
348 <div class="notice notice-warning is-dismissible cff-dismissible">
349 <p><?php if ($custom_js_not_empty) : ?>
350 <?php echo sprintf(__('You are currently using Custom CSS or JavaScript in the Custom Facebook Feed plugin, however, these settings have now been deprecated. To continue using any custom code, please go to the Custom CSS and JS settings %shere%s and follow the directions.', 'custom-facebook-feed'), '<a href="' . admin_url('admin.php?page=cff-settings&view=feeds') . '">', '</a>'); ?>
351 <?php else : ?>
352 <?php echo sprintf(__('You are currently using Custom CSS in the Custom Facebook Feed plugin, however, this setting has now been deprecated. Your CSS has been moved to the "Additional CSS" field in the WordPress Customizer %shere%s instead.', 'custom-facebook-feed'), '<a href="' . esc_url(wp_customize_url()) . '">', '</a>'); ?>
353 <?php endif; ?>
354 &nbsp;<a href="<?php echo esc_attr($close_href); ?>"><?php echo __('Dismiss', 'custom-facebook-feed'); ?></a>
355 </p>
356 </div>
357 <?php
358 }
359 add_action('admin_notices', 'cff_custom_cssjs_notice');
360 add_action('cff_admin_notices', 'cff_custom_cssjs_notice');
361
362 function cff_dismiss_custom_cssjs_notice()
363 {
364 check_ajax_referer('cff_nonce', 'cff_nonce');
365
366 $cap = current_user_can('manage_custom_facebook_feed_options') ? 'manage_custom_facebook_feed_options' : 'manage_options';
367 $cap = apply_filters('cff_settings_pages_capability', $cap);
368 // Only display notice to admins
369 if (!current_user_can($cap)) {
370 return;
371 }
372
373 $cff_statuses_option = get_option('cff_statuses', array());
374 $cff_statuses_option['custom_js_css_dismissed'] = true;
375 update_option('cff_statuses', $cff_statuses_option, false);
376 }
377 add_action('wp_ajax_cff_dismiss_custom_cssjs_notice', 'cff_dismiss_custom_cssjs_notice');
378
379
380 function cff_ppca_token_check_flag()
381 {
382 check_ajax_referer('cff_nonce', 'cff_nonce');
383
384 $cap = current_user_can('manage_custom_facebook_feed_options') ? 'manage_custom_facebook_feed_options' : 'manage_options';
385 $cap = apply_filters('cff_settings_pages_capability', $cap);
386 if (! current_user_can($cap)) {
387 wp_send_json_error(); // This auto-dies.
388 }
389
390 if (get_transient('cff_ppca_access_token_invalid')) {
391 print_r(true);
392 } else {
393 print_r(false);
394 }
395
396 die();
397 }
398 add_action('wp_ajax_cff_ppca_token_check_flag', 'cff_ppca_token_check_flag');
399
400 /**
401 * Adds CSS to the end of the customizer "Additonal CSS" setting
402 *
403 * @param $custom_css
404 *
405 * @return bool|int
406 *
407 * @since 4.0.2/4.0.7
408 */
409 function cff_transfer_css($custom_css)
410 {
411 $value = '';
412 $post = wp_get_custom_css_post(get_stylesheet());
413 if ($post) {
414 $value = $post->post_content;
415 }
416 $value .= "\n\n/* Custom Facebook Feed */\n" . $custom_css . "\n/* Custom Facebook Feed - End */";
417
418 $r = wp_update_custom_css_post(
419 $value,
420 array(
421 'stylesheet' => get_stylesheet(),
422 )
423 );
424
425 if ($r instanceof WP_Error) {
426 return false;
427 }
428 $post_id = $r->ID;
429
430 return $post_id;
431 }
432
433 /**
434 * Validates CSS to detect anything that might be harmful
435 *
436 * @param $css
437 *
438 * @return bool|WP_Error
439 *
440 * @since 4.0.2/4.0.7
441 */
442 function cff_validate_css($css)
443 {
444 $validity = new WP_Error();
445
446 if (preg_match('#</?\w+#', $css)) {
447 $validity->add('illegal_markup', __('Markup is not allowed in CSS.'));
448 }
449
450 if (! $validity->has_errors()) {
451 $validity = true;
452 }
453 return $validity;
454 }
455
456 /**
457 * Check to see if CSS has been transferred
458 *
459 * @since 4.0.2/4.0.7
460 */
461 function cff_check_custom_css()
462 {
463 $cff_style_settings = get_option('cff_style_settings', array());
464 $custom_css = isset($cff_style_settings['cff_custom_css']) ? stripslashes(trim($cff_style_settings['cff_custom_css'])) : '';
465
466 // only try once
467 if (empty($custom_css)) {
468 return;
469 }
470
471 // custom css set to nothing after trying the update once
472 $cff_style_settings['cff_custom_css_read_only'] = $custom_css;
473 $cff_style_settings['cff_custom_css'] = '';
474 update_option('cff_style_settings', $cff_style_settings);
475 if (
476 ! function_exists('wp_get_custom_css_post')
477 || ! function_exists('wp_update_custom_css_post')
478 ) {
479 return;
480 }
481
482 // make sure this is valid CSS or don't transfer
483 if (is_wp_error(cff_validate_css($custom_css))) {
484 return;
485 }
486
487 cff_transfer_css($custom_css);
488 }
489 add_action('init', 'cff_check_custom_css');
490
491 function cff_doing_openssl()
492 {
493 return extension_loaded('openssl');
494 }
495 function cff_delete_all_platform_data()
496 {
497 $manager = new SB_Facebook_Data_Manager();
498 $manager->delete_caches();
499 \cff_main()->cff_error_reporter->add_action_log('Deleted all platform data.');
500 \cff_main()->cff_error_reporter->reset_api_errors();
501 }
502
503
504 function cff_encrypt_decrypt($action, $string)
505 {
506 $output = false;
507
508 $encrypt_method = "AES-256-CBC";
509 $secret_key = 'SMA$H.BA[[OON#23121';
510 $secret_iv = '1231394873342102221';
511
512 // hash
513 $key = hash('sha256', $secret_key);
514
515 // iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
516 $iv = substr(hash('sha256', $secret_iv), 0, 16);
517
518 if ($action === 'encrypt') {
519 $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
520 $output = base64_encode($output);
521 } elseif ($action === 'decrypt') {
522 $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
523 }
524
525 return $output;
526 }
527
528 function update_connected_accounts($connected_accounts)
529 {
530 update_option('cff_connected_accounts', $connected_accounts);
531 return $connected_accounts;
532 }
533
534 /**
535 * Return a combination of legacy and new sources with new sources
536 * overriding legacy sources.
537 *
538 * @return StdClass
539 *
540 * @since 4.0
541 */
542 function get_connected_accounts_list()
543 {
544 $connected_accounts = CustomFacebookFeed\CFF_Utils::cff_get_connected_accounts_object();
545
546 if (empty($connected_accounts)) {
547 $connected_accounts = [];
548 }
549
550 $new_sources = \CustomFacebookFeed\Builder\CFF_Feed_Builder::get_source_list();
551
552 $encryption = new \CustomFacebookFeed\SB_Facebook_Data_Encryption();
553
554 foreach ($new_sources as $new_source) {
555 if (!empty($new_source['account_id'])) {
556 $account_id = $new_source['account_id'];
557 array_push(
558 $connected_accounts,
559 [
560 'id' => $account_id,
561 'accesstoken' => $encryption->decrypt($new_source['access_token']) ? $encryption->decrypt($new_source['access_token']) : $new_source['access_token'],
562 'pagetype' => $new_source['account_type'],
563 'name' => $new_source['username'],
564 'avatar' => $new_source['avatar_url']
565 ]
566 );
567 }
568 }
569
570 return $connected_accounts;
571 }
572
573
574 /**
575 * oEmbed Connection App URL
576 *
577 * @return StdClass
578 *
579 * @since 4.0
580 */
581 function cffGetOembedConnectionUrl()
582 {
583 $admin_url_state = admin_url('admin.php?page=cff-oembeds-manager');
584 $nonce = wp_create_nonce('cff_con');
585 // If the admin_url isn't returned correctly then use a fallback
586 if ($admin_url_state == '/wp-admin/admin.php?page=cff-oembeds-manager') {
587 $admin_url_state = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
588 }
589
590 return array(
591 'connect' => CFF_OEMBED_CONNECT_URL,
592 'cff_con' => $nonce,
593 'stateURL' => $admin_url_state
594 );
595 }