PluginProbe ʕ •ᴥ•ʔ
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress / 4.12.0
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress v4.12.0
4.12.0 4.10.0 4.9.0 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 / Admin / CFF_Callout.php
custom-facebook-feed / inc / Admin Last commit date
Blocks 2 weeks ago Traits 2 weeks ago CFF_About_Us.php 2 weeks ago CFF_Admin.php 2 weeks ago CFF_Admin_Notices.php 2 weeks ago CFF_Callout.php 2 weeks ago CFF_Global_Settings.php 2 weeks ago CFF_Install_Skin.php 2 weeks ago CFF_New_User.php 2 weeks ago CFF_Notifications.php 2 weeks ago CFF_Onboarding_Wizard.php 2 weeks ago CFF_Support.php 2 weeks ago CFF_Support_Tool.php 2 weeks ago CFF_Upgrader.php 2 weeks ago CFF_oEmbeds.php 2 weeks ago index.php 2 weeks ago
CFF_Callout.php
515 lines
1 <?php
2
3 /**
4 * Callouts
5 *
6 * @since X.X
7 */
8
9 namespace CustomFacebookFeed\Admin;
10
11 if (!defined('ABSPATH')) {
12 exit;
13 }
14
15 /**
16 * Summary of CFF_Callout
17 */
18 class CFF_Callout
19 {
20 /**
21 * Summary of PLUGIN_NAME
22 *
23 * @var string
24 */
25 const PLUGIN_NAME = 'facebook';
26
27 /**
28 * Summary of ASSETS_CSS
29 */
30 const ASSETS_CSS = CFF_PLUGIN_URL . 'admin/assets/css/';
31
32 /**
33 * Summary of ASSETS_JS
34 */
35 const ASSETS_JS = CFF_PLUGIN_URL . 'admin/assets/js/';
36
37 /**
38 * Summary of TWO_WEEKS_WAIT
39 *
40 * @var int
41 */
42 const TWO_WEEKS_WAIT = 1209600;
43
44 /**
45 * Summary of plugins_list
46 *
47 * @var
48 */
49 public $plugins_list;
50
51 /**
52 * Summary of should_show_callout
53 *
54 * @var
55 */
56 public $should_show_callout;
57
58 /**
59 * Summary of __construct
60 */
61 public function __construct()
62 {
63 $this->dismiss_notice();
64 $this->plugins_list = self::get_callout_plugins_list();
65 $this->should_show_callout = sizeof($this->plugins_list) !== 0 && self::should_show_callout();
66
67 add_action('wp_enqueue_scripts', [$this, 'register_assets']);
68 add_action('admin_enqueue_scripts', [$this, 'register_assets']);
69 add_action('wp_dashboard_setup', [$this, 'dashboard_widget']);
70 }
71
72 /**
73 * Summary of is_dashboad_screen
74 *
75 * @return bool
76 */
77 public function is_dashboad_screen()
78 {
79 if (is_admin()) {
80 if (!function_exists('get_current_screen')) {
81 require_once ABSPATH . '/wp-admin/includes/screen.php';
82 }
83 $screen = get_current_screen();
84 if ($screen->id === "dashboard") {
85 return true;
86 }
87 }
88 return false;
89 }
90
91
92 /**
93 * Register Callout Assets
94 *
95 * @since X.X
96 */
97 public function register_assets()
98 {
99 $should_show_dashboard = sizeof($this->plugins_list) !== 0 && $this->is_dashboad_screen();
100 if ($this->should_show_callout || $should_show_dashboard) {
101 if (is_admin()) {
102 wp_enqueue_script(
103 'callout-js',
104 self::ASSETS_JS . 'callout.js',
105 null,
106 null,
107 true
108 );
109 }
110
111 wp_enqueue_style(
112 'callout-style',
113 self::ASSETS_CSS . 'callout.css',
114 false,
115 null
116 );
117 }
118 }
119
120 /**
121 * Dimiss the Callout Notice
122 *
123 * @since X.X
124 */
125 public function dismiss_notice()
126 {
127 if (
128 !empty($_GET['sb_dismiss']) && $_GET['sb_dismiss'] === 'callout' &&
129 !empty($_GET['sb_nonce']) && wp_verify_nonce($_GET['sb_nonce'], 'sb-callout')
130 ) {
131 $callout_opt = get_option('sb_callout', []);
132 $callout_opt['dismissed'] = true;
133 /**
134 * If users dismisses the callout
135 * for the first time -> store the current time (So it will be shown after 2 weeks)
136 * 2 second time (& more than 2 weeks) -> store permanent, this way the callout will no longer be shown
137 */
138 $callout_opt['dismissed_date'] =
139 isset($callout_opt['dismissed_date']) &&
140 (
141 ($callout_opt['dismissed_date'] === 'permanent') ||
142 ($callout_opt['dismissed_date'] !== 'permanent' && intval($callout_opt['dismissed_date']) + self::TWO_WEEKS_WAIT < time())
143 )
144 ? 'permanent' : time();
145 update_option('sb_callout', $callout_opt);
146 }
147 }
148
149 /**
150 * Get Smashballoon Plugins List
151 *
152 * @return array
153 *
154 * @since X.X
155 */
156 public static function get_plugins_list()
157 {
158 return [
159 'instagram' => [
160 'plugin' => 'instagram-feed/instagram-feed.php',
161 'statuses' => 'sbi_statuses',
162 'table' => 'sbi_feeds',
163 'page' => 'sbi-feed-builder'
164 ],
165 'facebook' => [
166 'plugin' => 'custom-facebook-feed/custom-facebook-feed.php',
167 'statuses' => 'cff_statuses',
168 'table' => 'cff_feeds',
169 'page' => 'cff-feed-builder'
170 ],
171 'twitter' => [
172 'plugin' => 'custom-twitter-feeds/custom-twitter-feed.php',
173 'statuses' => 'ctf_statuses',
174 'table' => 'ctf_feeds',
175 'page' => 'ctf-feed-builder'
176 ],
177 'youtube' => [
178 'plugin' => 'feeds-for-youtube/youtube-feed.php',
179 'statuses' => 'sby_statuses',
180 'table' => 'sby_feeds',
181 'page' => 'sby-feed-builder'
182 ],
183 'reviews' => [
184 'plugin' => 'reviews-feed/sb-reviews.php',
185 'statuses' => 'sbr_statuses',
186 'table' => 'sbr_feeds',
187 'page' => 'sbr'
188 ],
189 'tiktok' => [
190 'plugin' => 'feeds-for-tiktok/feeds-for-tiktok.php',
191 'statuses' => 'sbtt_statuses',
192 'table' => 'sbtt_feeds',
193 'page' => 'sbtt'
194 ],
195 ];
196 }
197
198 /**
199 * Get Plugins List
200 * Check for SmashBalloon installed plugins (with no feeds)
201 *
202 * @return array
203 *
204 * @since X.X
205 */
206 public static function get_callout_plugins_list()
207 {
208 if (!function_exists('get_plugins')) {
209 require_once ABSPATH . 'wp-admin/includes/plugin.php';
210 }
211 $installed_plugins = get_plugins();
212 $plugins_list = self::get_plugins_list();
213
214 foreach ($plugins_list as $key => $plugin) {
215 if (isset($installed_plugins[$plugin['plugin']]) && is_plugin_active($plugin['plugin'])) {
216 $feeds_number = self::feeds_number($plugin['table']);
217 if (intval($feeds_number) === 0) {
218 $plugins_list[$key]['is_done'] = false;
219 } else {
220 $plugins_list[$key]['is_done'] = true;
221 }
222 } else {
223 unset($plugins_list[$key]);
224 }
225 }
226
227 uasort($plugins_list, function ($a, $b) {
228 if ($a['is_done'] === true && $b['is_done'] === false) {
229 return -1;
230 }
231 if ($a['is_done'] === false && $b['is_done'] === true) {
232 return 1;
233 }
234 return 0;
235 });
236 return $plugins_list;
237 }
238
239 /**
240 * SQL Query to get the number of created feeds
241 *
242 * @return int
243 *
244 * @since X.X
245 */
246 public static function feeds_number($table_name)
247 {
248 global $wpdb;
249 $feeds_table_name = $wpdb->prefix . $table_name;
250
251 // Check if table exists before querying
252 $table_exists = $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $feeds_table_name));
253 if ($table_exists !== $feeds_table_name) {
254 return 0;
255 }
256
257 $count = $wpdb->get_var("SELECT COUNT(*) FROM `" . esc_sql($feeds_table_name) . "`");
258 return $count !== null ? (int) $count : 0;
259 }
260
261 /**
262 * Get Next Plugin for Setup
263 *
264 * @return int
265 *
266 * @since X.X
267 */
268 public static function next_plugin($plugins_list)
269 {
270 $pkey = '';
271 foreach ($plugins_list as $key => $plugin) {
272 if ($plugin['is_done'] === false) {
273 $pkey = $key;
274 break;
275 }
276 }
277 return $pkey;
278 }
279
280 /**
281 * Print the Callout
282 *
283 * @since X.X
284 */
285 public static function print_callout($type = 'frontend')
286 {
287 $plugins_list = self::get_callout_plugins_list();
288 if (
289 (
290 sizeof($plugins_list) === 0
291 || !self::should_show_callout()
292 || !self::order_show_callout($type)
293 )
294 && $type !== 'dashboard'
295 ) {
296 return false;
297 }
298 $process = 0;
299 foreach ($plugins_list as $sg_plugin) {
300 if (isset($sg_plugin['is_done']) && $sg_plugin['is_done'] === true) {
301 $process += 1;
302 }
303 }
304 $process_percent = $process === 0 ? 0 : intval(100 / (sizeof($plugins_list) / $process));
305
306 // SMASH-1672: use a trusted, explicit admin base instead of letting
307 // add_query_arg() fall back to the attacker-controlled $_SERVER['REQUEST_URI'].
308 $dismiss_callout = wp_nonce_url(
309 add_query_arg( array( 'sb_dismiss' => 'callout' ), admin_url( 'index.php' ) ),
310 'sb-callout',
311 'sb_nonce'
312 );
313
314 ?>
315 <div class="sb-callout-ctn" data-type="<?php echo $type ?>">
316 <div class="sb-callout-top sb-fs">
317 <div class="sb-callout-top-heading">
318 <svg width="16" height="17" viewBox="0 0 16 17" fill="none" aria-hidden="true" focusable="false">
319 <path fill-rule="evenodd" clip-rule="evenodd" d="M7.908 0.5C11.2231 0.5 13.9095 3.82243 13.9095 7.92084C13.9095 11.7725 11.5374 14.9377 8.50226 15.3061L9.23157 16.1975L7.1529 16.3743L7.48441 15.3245C4.36702 15.0556 1.90527 11.8498 1.90527 7.92084C1.90527 3.82243 4.59293 0.5 7.908 0.5ZM9.62864 6.08918L9.3398 3.10897L7.49633 5.42022L4.85195 3.91264L5.62324 6.66616L2.82813 7.56509L5.43923 8.88209L4.40933 11.6475L7.08659 10.4207L8.41253 13.0003L9.2858 10.1197L12.1663 10.6611L10.4565 8.18805L12.6214 6.17515L9.62864 6.08918Z" fill="#FE544F"/>
320 </svg>
321 <strong>
322 <span class="sb-callout-only-visible">
323 <svg width="13" height="14" viewBox="0 0 13 14" fill="none" aria-hidden="true" focusable="false">
324 <path d="M6.49984 5.375C6.06886 5.375 5.65553 5.5462 5.35079 5.85095C5.04604 6.1557 4.87484 6.56902 4.87484 7C4.87484 7.43098 5.04604 7.8443 5.35079 8.14905C5.65553 8.4538 6.06886 8.625 6.49984 8.625C6.93081 8.625 7.34414 8.4538 7.64889 8.14905C7.95363 7.8443 8.12484 7.43098 8.12484 7C8.12484 6.56902 7.95363 6.1557 7.64889 5.85095C7.34414 5.5462 6.93081 5.375 6.49984 5.375ZM6.49984 9.70833C5.78154 9.70833 5.09267 9.42299 4.58476 8.91508C4.07685 8.40717 3.7915 7.71829 3.7915 7C3.7915 6.28171 4.07685 5.59283 4.58476 5.08492C5.09267 4.57701 5.78154 4.29167 6.49984 4.29167C7.21813 4.29167 7.90701 4.57701 8.41492 5.08492C8.92283 5.59283 9.20817 6.28171 9.20817 7C9.20817 7.71829 8.92283 8.40717 8.41492 8.91508C7.90701 9.42299 7.21813 9.70833 6.49984 9.70833ZM6.49984 2.9375C3.7915 2.9375 1.47859 4.62208 0.541504 7C1.47859 9.37792 3.7915 11.0625 6.49984 11.0625C9.20817 11.0625 11.5211 9.37792 12.4582 7C11.5211 4.62208 9.20817 2.9375 6.49984 2.9375Z" fill="#0068A0"/>
325 </svg>
326 <?php echo __('Only Visible to you', 'custom-facebook-feed') ?>
327 </span>
328 <span class="sb-fs"><?php echo __('Smash Balloon Feeds', 'custom-facebook-feed') ?></span>
329 </strong>
330 </div>
331 <a href="<?php echo esc_url( $dismiss_callout ); ?>" class="sb-callout-top-dismiss" aria-label="<?php echo esc_attr__( 'Dismiss', 'custom-facebook-feed' ); ?>"></a>
332 </div>
333 <div class="sb-callout-progress sb-fs">
334 <div
335 class="sb-callout-progress-radial"
336 style="--percent: <?php echo 100 - $process_percent; ?>"
337 >
338 <span>
339 <?php echo esc_attr($process_percent); ?>%
340 </span>
341 <svg width="71" height="71" viewBox="0 0 71 71" class="sb-progress-svg" aria-hidden="true" focusable="false">
342 <circle class="sb-progress-svg-bg"></circle>
343 <circle class="sb-progress-svg-fg"></circle>
344 </svg>
345 </div>
346 <div class="sb-callout-progress-text">
347 <strong><?php echo __('Setup is almost complete', 'custom-facebook-feed') ?></strong>
348 <span><?php echo __('Complete your Smash Balloon feed setup and increase engagement', 'custom-facebook-feed') ?></span>
349 </div>
350 </div>
351 <div class="sb-callout-plugins sb-fs">
352 <?php foreach ($plugins_list as $key => $plugin) { ?>
353 <div class="sb-callout-plugin-item sb-fs" data-done="<?php echo $plugin['is_done'] ? 'true' : 'false' ?>">
354 <div class="sb-callout-item-checkbox"></div>
355 <span>
356 <?php echo ($key === 'facebook' ? __('Create an', 'custom-facebook-feed') : __('Create a', 'custom-facebook-feed')) . ' ' . ucfirst($key) . ' ' . __('Feed', 'custom-facebook-feed') ?>
357 </span>
358 <?php if (sizeof($plugins_list) === 1) { ?>
359 <a href="<?php echo esc_url( admin_url( 'admin.php?page=' . $plugin['page'] ) ); ?>" target="_blank" rel="noopener noreferrer" class="sb-callout-item-btn">
360 <?php echo __('Go to Plugin', 'custom-facebook-feed') ?>
361 </a>
362 <?php } ?>
363 </div>
364 <?php } ?>
365 <?php
366 if (sizeof($plugins_list) > 1 && $process !== sizeof($plugins_list)) {
367 $next_p = self::next_plugin($plugins_list);
368 ?>
369 <div class="sb-callout-bottom-btns sb-fs">
370 <a href="<?php echo esc_url( admin_url( 'admin.php?page=' . $plugins_list[ $next_p ]['page'] ) ); ?>" target="_blank" rel="noopener noreferrer" class="sb-callout-item-btn">
371 <?php echo __('Go to', 'custom-facebook-feed') . ' ' . ucfirst($next_p) . ' ' . __('Plugin', 'custom-facebook-feed') ?>
372 </a>
373 <a href="<?php echo esc_url( $dismiss_callout ); ?>" class="sb-callout-item-btn sb-callout-item-btn-grey">
374 <?php echo __('Skip this step', 'custom-facebook-feed') ?>
375 </a>
376 </div>
377 <?php } ?>
378 </div>
379 </div>
380 <?php
381 }
382
383 /**
384 * Print The Callout in the Sidebar Menu
385 *
386 * @since X.X
387 */
388 public static function print_callout_ob_html($type)
389 {
390 ob_start();
391 CFF_Callout::print_callout($type);
392 return ob_get_clean();
393 }
394
395 /**
396 * Check if all the plugins are done
397 *
398 * @since X.X
399 */
400 public static function check_done_plugins($plugins_list)
401 {
402 $should_show = false;
403 foreach ($plugins_list as $s_plugin) {
404 if ($s_plugin['is_done'] === false) {
405 $should_show = true;
406 break;
407 }
408 }
409 return $should_show;
410 }
411
412 /**
413 * Check if Whether to Show The callout or nor
414 *
415 * @since X.X
416 */
417 public static function should_show_callout()
418 {
419 $plugins_list = self::get_callout_plugins_list();
420 if (
421 !isset($plugins_list[self::PLUGIN_NAME])
422 || !isset($plugins_list[self::PLUGIN_NAME]['statuses'])
423 || !self::check_done_plugins($plugins_list)
424 ) {
425 return false;
426 }
427
428 // Thrive Architect Compatibility.
429 if (isset($_GET['tve']) && $_GET['tve'] == 'true') {
430 return false;
431 }
432
433 // Current Plugin Options.
434 $plugin = $plugins_list[self::PLUGIN_NAME];
435 $plugin_statuses = get_option($plugin['statuses'], []);
436
437 if (!isset($plugin_statuses['first_install'])) {
438 return false;
439 }
440
441 // If the plugin has no feed, then we don't display the callout unless it's been 2 weeks after installation.
442 $been_2_weeks = intval($plugin_statuses['first_install']) + self::TWO_WEEKS_WAIT > time() ;
443 if ($been_2_weeks && !$plugins_list[self::PLUGIN_NAME]['is_done']) {
444 return false;
445 }
446
447 // It's been more than 3 months of the first install
448 $more_3_months = intval($plugin_statuses['first_install']) + 7889229 < time();
449 if ($more_3_months) {
450 return false;
451 }
452
453 /**
454 * These Options will be shared across all the plugins
455 * This way we can control the Callout dismissal once!
456 */
457 $callout_opt = get_option('sb_callout', []);
458 if (
459 isset($callout_opt['dismissed'], $callout_opt['dismissed_date']) &&
460 (
461 $callout_opt['dismissed_date'] === 'permanent' ||
462 (
463 $callout_opt['dismissed_date'] !== 'permanent' && intval($callout_opt['dismissed_date']) + self::TWO_WEEKS_WAIT > time()
464 )
465 )
466 ) {
467 return false;
468 }
469
470 return true;
471 }
472
473
474 /**
475 * Display Dashboard Widget
476 *
477 * @since X.X
478 */
479 public function dashboard_widget()
480 {
481 $should_show_dashboard = sizeof($this->plugins_list) !== 0 && $this->is_dashboad_screen();
482 if ($should_show_dashboard) {
483 wp_add_dashboard_widget(
484 'sb_dashboard_widget',
485 __('Smash Balloon Feeds', 'custom-facebook-feed'),
486 function () {
487 echo self::print_callout_ob_html('dashboard', false);
488 }
489 );
490 }
491 }
492
493
494 /**
495 * Check The order of Callout Feature to be shown
496 * Hide the callout feature in case of top plugin
497 * callout feature is shown
498 *
499 * @return boolean
500 */
501 public static function order_show_callout($type = '')
502 {
503 $plugin_list = self::get_callout_plugins_list();
504 $i = 0;
505 $should_show = false;
506 foreach ($plugin_list as $name => $plugin) {
507 if ($i === 0 && $name === self::PLUGIN_NAME) {
508 $should_show = true;
509 }
510 $i++;
511 }
512 return $should_show || $type !== 'side-menu';
513 }
514 }
515