PluginProbe ʕ •ᴥ•ʔ
Reviews Feed – Add Testimonials and Customer Reviews From Google Reviews, Yelp, TripAdvisor, and More / 2.9.0
Reviews Feed – Add Testimonials and Customer Reviews From Google Reviews, Yelp, TripAdvisor, and More v2.9.0
2.11.0 2.10.0 2.9.0 2.8.0 2.7.0 2.6.7 2.6.8 2.6.5 2.6.4 2.6.3 2.6.2 2.6.0 2.5.5 2.5.4 2.5.3 2.5.2 trunk 1.0 1.0.1 1.0.2 1.0.3 1.1 1.1.1 1.1.2 1.2.0 2.0 2.1.0 2.1.1 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5.0 2.5.1
reviews-feed / class / sbr-functions.php
reviews-feed / class Last commit date
Common 1 month ago sbr-functions.php 1 month ago
sbr-functions.php
773 lines
1 <?php
2
3 use SmashBalloon\Reviews\Common\Admin\Blocks\SB_Reviews_Blocks;
4 use SmashBalloon\Reviews\Common\Util;
5
6 if (!defined('ABSPATH')) {
7 exit; // Exit if accessed directly
8 }
9
10 function sbr_json_encode($thing)
11 {
12 if (function_exists('wp_json_encode')) {
13 return wp_json_encode($thing);
14 } else {
15 return json_encode($thing);
16 }
17 }
18
19
20 /**
21 * Reviews Currect User Capability Check
22 *
23 * @since 1.0
24 */
25 function sbr_current_user_can($cap)
26 {
27 if ($cap === 'manage_reviews_feed_options') {
28 $cap = current_user_can('manage_reviews_feed_options') ? 'manage_reviews_feed_options' : 'manage_options';
29 }
30 $cap = apply_filters('sbr_settings_pages_capability', $cap);
31
32 return current_user_can($cap);
33 }
34
35
36 /**
37 * Get the settings in the database with defaults
38 *
39 * @return array
40 */
41 function sbr_get_database_settings()
42 {
43 global $sbr_settings;
44
45 $defaults = sbr_settings_defaults();
46
47 if ($sbr_settings === null) {
48 $sbr_settings = get_option('sbr_settings', []);
49 }
50
51 // Defensive: `sbr_settings` can arrive as a non-array (raw SQL edits,
52 // broken backup/restore, migration tooling that mangled serialization).
53 // Without this guard `array_merge()` fatals and takes the whole admin
54 // down. Normalizing to an array lets SMASH-1281's migration-recovery
55 // flow re-register + repopulate on the next page load.
56 if (!is_array($sbr_settings)) {
57 $sbr_settings = [];
58 }
59
60 return array_merge($defaults, $sbr_settings);
61 }
62
63 /**
64 * Get the settings default settins
65 *
66 * @return array
67 */
68 function sbr_settings_defaults()
69 {
70 return [
71 //Template
72 'feedTemplate' => 'default',
73 //Sources
74 'sources' => [],
75 //Layout Settings
76 'layout' => 'list',
77 'verticalSpacing' => 20,
78 'horizontalSpacing' => 10,
79 'contentAlignment' => 'left',
80 'contentLength' => 320,
81 'numPostDesktop' => 10,
82 'numPostTablet' => 8,
83 'numPostMobile' => 6,
84 'gridDesktopColumns' => 3,
85 'gridTabletColumns' => 2,
86 'gridMobileColumns' => 1,
87 'masonryDesktopColumns' => 3,
88 'masonryTabletColumns' => 2,
89 'masonryMobileColumns' => 1,
90 'carouselDesktopColumns' => 3,
91 'carouselTabletColumns' => 2,
92 'carouselMobileColumns' => 1,
93 'carouselDesktopRows' => 1,
94 'carouselTabletRows' => 1,
95 'carouselMobileRows' => 1,
96 'carouselLoopType' => 'infinity',
97 'carouselIntervalTime' => 5000,
98 'carouselShowArrows' => false,
99 'carouselShowPagination' => true,
100 'carouselEnableAutoplay' => true,
101
102 //Header
103 'showHeader' => true,
104 'headerContent' => ['heading', 'button', 'averagereview'],
105 'headerPadding' => [],
106 'headerMargin' => ['bottom' => 20],
107 //Heading
108 'headerHeadingContent' => 'Reviews',
109 'headingFont' => [
110 'weight' => 700,
111 'size' => 36,
112 'height' => '100%'
113 ],
114 'headingColor' => '#141B38',
115 'headerHeadingPadding' => [],
116 'headerHeadingMargin' => ['bottom' => 10],
117 //Button
118 'headerButtonLinkTo' => 'google',
119 'headerButtonIcon' => '',
120 'headerButtonExternalLink' => '',
121 'headerButtonFont' => [
122 'weight' => 600,
123 'size' => 14,
124 'height' => '22px'
125 ],
126 'headerButtonColor' => '#ffffff',
127 'headerButtonBg' => '#ED4944',
128 'headerButtonHoverColor' => '#ffffff',
129 'headerButtonHoverBg' => '#CC3F3A',
130 'headerButtonPadding' => [
131 'top' => 8,
132 'right' => 20,
133 'bottom' => 8,
134 'left' => 12,
135 ],
136 'headerButtonMargin' => [],
137 //AverageReview
138 'headerAvReviewFont' => [
139 'weight' => 600,
140 'size' => 20,
141 'height' => '1.5em'
142 ],
143 'headerAvSubtextReviewFont' => [
144 'weight' => 400,
145 'size' => 12,
146 'height' => '1.5em'
147 ],
148 'headerAvReviewIconColor' => '#ED4944',
149 'headerAvReviewColor' => '#141B38',
150 'headerAvReviewSubtextColor' => '#434960',
151 'headerAvReviewMargin' => '',
152 'headerAvReviewPadding' => '',
153
154 //Post Style
155 'postStyle' => 'regular',
156 'boxedBackgroundColor' => '#ffffff',
157 'boxedBoxShadow' => [],
158 'boxedBorderRadius' => [],
159 'postStroke' => [],
160 'postPadding' => [
161 'bottom' => 20
162 ],
163
164 'postElements' => ['author', 'rating', 'text', 'media'],
165 'ratingIconSize' => 'small',
166 'ratingIconColor' => '#ED4944',
167 'ratingIconPadding' => [],
168 'ratingIconMargin' => [
169 'top' => 15,
170 'bottom' => 15,
171 ],
172 'paragraphFont' => [
173 'weight' => 400,
174 'size' => 16,
175 'height' => '1.5em'
176 ],
177 'paragraphColor' => '#434960',
178 'paragraphPadding' => [],
179 'paragraphMargin' => [],
180
181 'authorContent' => ['name', 'image', 'date'],
182 'authorPadding' => [],
183 'authorMargin' => [],
184
185 'authorNameFont' => [
186 'weight' => 600,
187 'size' => 14,
188 'height' => '1.5em'
189 ],
190 'authorNameColor' => '#141B38',
191 'authorNamePadding' => [],
192 'authorNameMargin' => [],
193
194 'dateFont' => [
195 'weight' => 400,
196 'size' => 13,
197 'height' => '1.5em'
198 ],
199 'dateColor' => '#434960',
200
201 'dateFormat' => '1',
202 'dateCustomFormat' => '',
203 'dateBeforeText' => '',
204 'dateAfterText' => '',
205 'datePadding' => [],
206 'dateMargin' => [],
207 'authorImageBorderRadius' => 50,
208 'authorImageMargin' => [
209 'right' => 10
210 ],
211
212 'showLoadButton' => true,
213 'loadButtonText' => 'Load More',
214 'loadButtonFont' => [
215 'weight' => 600,
216 'size' => 16,
217 'height' => '1em'
218 ],
219 'loadButtonColor' => '#141B38',
220 'loadButtonHoverColor' => '#ffffff',
221 'loadButtonBg' => '#E6E6EB',
222 'loadButtonHoverBg' => '#FE544F',
223
224 'loadButtonPadding' => [
225 'top' => 15,
226 'bottom' => 15
227 ],
228 'loadButtonMargin' => [
229 'top' => 20
230 ],
231
232 //Filters
233 'includedStarFilters' => [],
234 'includeWords' => '',
235 'excludeWords' => '',
236 'filterByImage' => false,
237 'filterByVideos' => true,
238
239 //Sort
240 'sortByDateEnabled' => true,
241 'sortByDate' => 'latest',
242
243 'sortByRatingEnabled' => false,
244 'sortByRating' => '',
245
246 'sortRandomEnabled' => false,
247
248 //ColorScheme
249 'colorScheme' => 'inherit',
250
251
252 //Moderation Mode
253 'moderationEnabled' => false,
254 'moderationType' => 'allow',
255 'moderationAllowList' => [],
256 'moderationBlockList' => [],
257
258 //Translation
259 'localization' => 'default',
260 'trustpilotLanguage' => 'all',
261
262 //Filter By Length
263 'filterCharCountMin' => 0,
264 'filterCharCountMax' => '',
265
266 //Carousel Breakpoints
267 'carouselBreakpointDesktop' => 850,
268 'carouselBreakpointTablet' => 520
269 ];
270 }
271
272
273 function sbr_plugin_settings_defaults()
274 {
275 return [
276 'localization' => '',
277 'optimize_images' => true,
278 'usagetracking' => true,
279 'enqueue_js_in_header' => false,
280 'admin_error_notices' => true,
281 'feed_issue_reports' => true,
282 'translations' => [
283 'second' => __('second', 'reviews-feed'),
284 'seconds' => __('seconds', 'reviews-feed'),
285 'minute' => __('minute', 'reviews-feed'),
286 'minutes' => __('minutes', 'reviews-feed'),
287 'hour' => __('hour', 'reviews-feed'),
288 'hours' => __('hours', 'reviews-feed'),
289 'day' => __('day', 'reviews-feed'),
290 'days' => __('days', 'reviews-feed'),
291 'week' => __('week', 'reviews-feed'),
292 'weeks' => __('weeks', 'reviews-feed'),
293 'month' => __('month', 'reviews-feed'),
294 'months' => __('months', 'reviews-feed'),
295 'year' => __('year', 'reviews-feed'),
296 'years' => __('year', 'reviews-feed'),
297 'ago' => __('ago', 'reviews-feed'),
298 'writeReview' => __('Write a Review', 'reviews-feed'),
299 'reviewsHeader' => __('Over %s Reviews', 'reviews-feed'),
300 ]
301 ];
302 }
303 function sbr_activate($network_wide)
304 {
305 global $wp_roles;
306 $wp_roles->add_cap('administrator', 'manage_reviews_feed_options');
307 }
308
309 register_activation_hook(__FILE__, 'sby_activate');
310
311
312 function sbr_get_feed_template_part($part, $settings = array())
313 {
314 $file = '';
315
316 /**
317 * Whether or not to search for custom templates in theme folder
318 *
319 * @param boolean Setting from DB or shortcode to use custom templates
320 *
321 * @since 1.0
322 */
323 $settings_custom_templates = ! empty($settings['customtemplates']) && $settings['customtemplates'];
324 $using_custom_templates_in_theme = apply_filters('sbr_use_theme_templates', $settings_custom_templates);
325 $generic_path = trailingslashit(SBR_PLUGIN_DIR) . 'templates/frontend/';
326
327 //For Templates that are different Free Or Pro
328 $special_path = $generic_path . ( Util::sbr_is_pro() ? 'pro' : 'lite' ) . '/';
329
330 if ($using_custom_templates_in_theme) {
331 $custom_header_template = locate_template('sbr/header.php', false, false);
332 $custom_item_template = locate_template('sbr/item.php', false, false);
333 $custom_footer_template = locate_template('sbr/footer.php', false, false);
334 $custom_feed_template = locate_template('sbr/feed.php', false, false);
335 } else {
336 $custom_header_template = false;
337 $custom_item_template = false;
338 $custom_footer_template = false;
339 $custom_feed_template = false;
340 }
341
342 if ($part === 'header') {
343 if ($custom_header_template) {
344 $file = $custom_header_template;
345 } else {
346 #$file = $generic_path . 'header.php';
347 $file = $special_path . 'header.php';
348 }
349 } elseif ($part === 'item') {
350 if ($custom_item_template) {
351 $file = $custom_item_template;
352 } else {
353 $file = $generic_path . 'item.php';
354 }
355 } elseif ($part === 'footer') {
356 if ($custom_footer_template) {
357 $file = $custom_footer_template;
358 } else {
359 #$file = $generic_path . 'footer.php';
360 $file = $special_path . 'footer.php';
361 }
362 } elseif ($part === 'feed') {
363 if ($custom_feed_template) {
364 $file = $custom_feed_template;
365 } else {
366 #$file = $generic_path . 'feed.php';
367 $file = $special_path . 'feed.php';
368 }
369 } elseif ($part === 'post-elements/author') {
370 if ($custom_feed_template) {
371 $file = $custom_feed_template;
372 } else {
373 #$file = $generic_path . 'post-elements/author.php';
374 $file = $special_path . 'post-elements/author.php';
375 }
376 } elseif ($part === 'post-elements/media') {
377 if ($custom_feed_template) {
378 $file = $custom_feed_template;
379 } else {
380 #$file = $generic_path . 'post-elements/media.php';
381 $file = $special_path . 'post-elements/media.php';
382 }
383 } elseif ($part === 'post-elements/rating') {
384 if ($custom_feed_template) {
385 $file = $custom_feed_template;
386 } else {
387 $file = $generic_path . 'post-elements/rating.php';
388 }
389 } elseif ($part === 'post-elements/text') {
390 if ($custom_feed_template) {
391 $file = $custom_feed_template;
392 } else {
393 $file = $generic_path . 'post-elements/text.php';
394 }
395 }
396
397 return $file;
398 }
399
400 function sbr_container_id($feed_id)
401 {
402 return 'sb-reviews-container-' . $feed_id;
403 }
404
405 function sbr_scripts_enqueue($enqueue = false)
406 {
407 //Register the script to make it available
408 $assets_url = trailingslashit(SBR_PLUGIN_URL);
409 $settings = get_option('sbr_settings', []);
410 if (!is_array($settings)) {
411 $settings = [];
412 }
413 $min = !empty($_GET['sb_debug']) ? '' : '.min';
414
415 wp_enqueue_style(
416 'sbr_styles',
417 $assets_url . 'assets/css/sbr-styles' . $min . '.css',
418 [],
419 SBRVER
420 );
421
422 if (!empty($settings['enqueue_js_in_header'])) {
423 wp_enqueue_script(
424 'sbr_scripts',
425 $assets_url . 'assets/js/sbr-feed' . $min . '.js',
426 ['jquery'],
427 SBRVER,
428 false
429 );
430 } else {
431 wp_register_script(
432 'sbr_scripts',
433 $assets_url . 'assets/js/sbr-feed' . $min . '.js',
434 ['jquery'],
435 SBRVER,
436 true
437 );
438 }
439
440 $data = array(
441 'adminAjaxUrl' => admin_url('admin-ajax.php'),
442 // Translatable strings for JS-injected accessible names and SR announcements (WCAG 3.1.2).
443 'a11y' => array(
444 /* translators: %s: number of reviews just loaded. Announced to screen readers after Load More. */
445 'reviewLoaded' => __('%s review loaded.', 'reviews-feed'),
446 /* translators: %s: number of reviews just loaded. Announced to screen readers after Load More. */
447 'reviewsLoaded' => __('%s reviews loaded.', 'reviews-feed'),
448 'allReviewsShown' => __('All reviews shown.', 'reviews-feed'),
449 'photoViewer' => __('Review photo viewer', 'reviews-feed'),
450 'previousPhoto' => __('Previous photo', 'reviews-feed'),
451 'nextPhoto' => __('Next photo', 'reviews-feed'),
452 'closePhotoViewer' => __('Close photo viewer', 'reviews-feed'),
453 'close' => __('Close', 'reviews-feed'),
454 'previous' => __('Previous', 'reviews-feed'),
455 'next' => __('Next', 'reviews-feed'),
456 'reviewerPhoto' => __('Reviewer photo', 'reviews-feed'),
457 ),
458 );
459 //Pass option to JS file
460 wp_localize_script('sbr_scripts', 'sbrOptions', $data);
461
462 if ($enqueue || SB_Reviews_Blocks::is_gb_editor()) {
463 wp_enqueue_style('sbr_styles');
464 wp_enqueue_script('sbr_scripts');
465 }
466 }
467 add_action('wp_enqueue_scripts', 'sbr_scripts_enqueue', 2);
468
469 function sbr_esc_html_with_br($text)
470 {
471 return str_replace(array( '&lt;br /&gt;', '&lt;br&gt;' ), '<br>', esc_html(nl2br($text)));
472 }
473
474 /**
475 * Neutralize WordPress shortcodes in third-party review content before output.
476 *
477 * Review data imported from connected sources (Google, Yelp, Booking.com, EDD,
478 * etc.) is rendered inside the dynamic `sbr/sbr-feed-block`. WordPress runs
479 * `do_blocks()` on `the_content` at priority 9 and `do_shortcode()` at priority
480 * 11, so any shortcode left in the rendered block markup is expanded
481 * server-side — including a shortcode an unauthenticated visitor planted in a
482 * public review (e.g. a reviewer name or review body of `[gallery ids=1]`).
483 * The escaping helpers (`esc_html()`, `wp_kses_post()`) deliberately leave the
484 * `[` and `]` characters untouched, so they do not stop this on their own.
485 *
486 * Encoding the square brackets to HEX HTML entities (`&#x5B;` / `&#x5D;`) keeps
487 * the literal text visible to the visitor (the browser renders them as `[` / `]`)
488 * while ensuring `do_shortcode()` can never match them. Apply this as the
489 * OUTERMOST wrapper around already-escaped output: `esc_html()` / `wp_kses_post()`
490 * run first on the raw text (they leave `[` and `]` alone), then this encodes the
491 * brackets last.
492 *
493 * HEX, not decimal, is mandatory here: WordPress core's `do_shortcode()` ends by
494 * calling `unescape_invalid_shortcodes()`, which runs
495 * `str_replace( array( '&#91;', '&#93;' ), array( '[', ']' ), $content )` over the
496 * processed content. That reverses the DECIMAL entities `&#91;` / `&#93;` straight
497 * back to raw `[` / `]` — re-arming the very shortcode we just neutralized (the
498 * feed renders through `do_shortcode` via the `[reviews-feed]` shortcode and again
499 * through the block + `the_content` chain, so this fires in practice). It does NOT
500 * touch the hex forms `&#x5B;` / `&#x5D;`, so those survive intact. Using decimal
501 * here is self-defeating; see SMASH-1607 follow-up (CVE-2026-10724 regression).
502 *
503 * @since 2.6.5
504 *
505 * @see https://awesomemotive.atlassian.net/browse/SMASH-1607 (CVE-2026-10724)
506 *
507 * Non-string (e.g. null) or empty input is returned unchanged, so the type is
508 * intentionally permissive — callers pass already-escaped output, but the guard
509 * keeps a stray null/empty safe rather than coercing it.
510 *
511 * @param string|null $text Already-escaped output that may contain shortcode brackets.
512 * @return string|null The text with `[` and `]` encoded to hex HTML entities (`&#x5B;` / `&#x5D;`); the input unchanged if it isn't a non-empty string.
513 */
514 function sbr_neutralize_shortcodes($text)
515 {
516 if (! is_string($text) || $text === '') {
517 return $text;
518 }
519
520 // Hex entities (not decimal): WordPress core's unescape_invalid_shortcodes()
521 // str_replaces decimal &#91;/&#93; back to [/] inside do_shortcode(), which would
522 // re-arm the shortcode. Hex forms are not reversed. See docblock + SMASH-1607.
523 return str_replace(array( '[', ']' ), array( '&#x5B;', '&#x5D;' ), $text);
524 }
525
526
527
528
529 function sbr_get_fb_connection_urls($is_settings = false)
530 {
531 $urls = array();
532 $admin_url_state = $is_settings ?
533 admin_url('admin.php?page=sbr-settings') :
534 admin_url('admin.php?page=sbr');
535 $sb_admin_email = get_option('admin_email');
536 $nonce = wp_create_nonce('cff_con');
537 $sw_flag = !empty($_GET['sw-feed']) ? true : false;
538
539 // If the admin_url isn't returned correctly then use a fallback.
540 if (
541 $admin_url_state === '/wp-admin/admin.php?page=sbr'
542 || $admin_url_state === '/wp-admin/admin.php?page=sbr&tab=configuration'
543 ) {
544 $admin_url_state = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
545 }
546
547 $urls['page'] = [
548 'connect' => SBR_FB_CONNECT_URL,
549 'wordpress_user' => $sb_admin_email,
550 'v' => 'pro',
551 'vn' => SBRVER,
552 'cff_con' => $nonce,
553 'sw_feed' => $sw_flag
554 ];
555
556 $urls['stateURL'] = $admin_url_state;
557 return $urls;
558 }
559
560 function check_license_valid()
561 {
562 $sbr_settings = get_option('sbr_settings', []);
563 return isset($sbr_settings['license_key'])
564 && !empty($sbr_settings['license_key'])
565 && isset($sbr_settings['license_status'])
566 && !empty($sbr_settings['license_status'])
567 && $sbr_settings['license_status'] !== 'invalid';
568 }
569
570 function sbr_plugin_action_links($links)
571 {
572 $settings_link = check_license_valid() ? admin_url('admin.php?page=sbr-settings') : admin_url('admin.php?page=sbr');
573 $support_link = check_license_valid() ? admin_url('admin.php?page=sbr-support') : admin_url('admin.php?page=sbr');
574 $links = array_merge(
575 array(
576 '<a href="' . esc_url($settings_link) . '">' . __('Settings', 'reviews-feed') . '</a>'
577 ),
578 $links
579 );
580
581 if (!Util::sbr_is_pro()) {
582 $links = array_merge(
583 array(
584 '<a href="https://smashballoon.com/reviews-feed/reviews-lite-upgrade/?utm_campaign=reviews-free&utm_source=plugins-page&utm_medium=upgrade-link&utm_content=UpgradeToPro" target="_blank" style="font-weight:bold; color: #50a56d;">' . __('Upgrade to Pro', 'reviews-feed') . '</a>'
585 ),
586 $links
587 );
588 } else {
589 $links = array_merge(
590 array(
591 '<a href="' . esc_url($support_link) . '">' . __('Support', 'reviews-feed') . '</a>'
592 ),
593 $links
594 );
595 }
596
597 return $links;
598 }
599 add_action('plugin_action_links_' . SBR_PLUGIN_BASENAME, 'sbr_plugin_action_links');
600
601
602 add_action('current_screen', 'sbr_check_current_screen');
603
604 function sbr_check_current_screen()
605 {
606 if (Util::currentPageIs('sbr')) {
607 add_action('admin_enqueue_scripts', 'dequeue_smash_plugins_style');
608 }
609 }
610
611 function dequeue_smash_plugins_style()
612 {
613 wp_dequeue_style('cff_custom_wp_admin_css');
614 wp_deregister_style('cff_custom_wp_admin_css');
615
616 wp_dequeue_style('feed-global-style');
617 wp_deregister_style('feed-global-style');
618
619 wp_dequeue_style('sb_instagram_admin_css');
620 wp_deregister_style('sb_instagram_admin_css');
621
622 wp_dequeue_style('ctf_admin_styles');
623 wp_deregister_style('ctf_admin_styles');
624 }
625
626 function sbr_custom_menu()
627 {
628 if (Util::sbr_is_pro() === false) {
629 $cap = current_user_can('manage_reviews_feed_options') ? 'manage_reviews_feed_options' : 'manage_options';
630 $cap = apply_filters('sbr_settings_pages_capability', $cap);
631 add_submenu_page(
632 'sbr',
633 __('Upgrade to Pro', 'reviews-feed'),
634 __('<div class="sb-pro-upgradelink-bg"></div><strong class="sb-pro-upgradelink">Upgrade to Pro</strong>', 'reviews-feed'),
635 $cap,
636 'https://smashballoon.com/reviews-feed/reviews-lite-upgrade/?utm_campaign=reviews-free&utm_source=menu-link&utm_medium=upgrade-link&utm_content=UpgradeToPro',
637 ''
638 );
639 }
640 }
641
642 add_action('admin_menu', 'sbr_custom_menu', 40);
643
644
645 function sbr_text_domain()
646 {
647 load_plugin_textdomain('reviews-feed', false, dirname(SBR_PLUGIN_BASENAME) . '/languages');
648 }
649 add_action('init', 'sbr_text_domain');
650
651 function sbr_get_current_time()
652 {
653 $current_time = time();
654
655 // where to do tests
656 //$current_time = strtotime( 'November 25, 2020' );
657
658 return $current_time;
659 }
660
661
662 function sbr_recursive_parse_args($args, $defaults)
663 {
664 $new_args = (array) $defaults;
665
666 foreach ($args as $key => $value) {
667 if (is_array($value) && isset($new_args[ $key ])) {
668 $new_args[ $key ] = sbr_recursive_parse_args($value, $new_args[ $key ]);
669 } else {
670 $new_args[ $key ] = $value;
671 }
672 }
673 return $new_args;
674 }
675
676 function sbr_doing_openssl()
677 {
678 return extension_loaded('openssl');
679 }
680
681 function sbr_encrypt_decrypt($action, $string)
682 {
683 $output = false;
684
685 $encrypt_method = "AES-256-CBC";
686 $secret_key = 'SMA$H.BA[[OON#23121';
687 $secret_iv = '1231394873342102221';
688
689 // hash
690 $key = hash('sha256', $secret_key);
691
692 // iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
693 $iv = substr(hash('sha256', $secret_iv), 0, 16);
694
695 if ($action === 'encrypt') {
696 $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
697 $output = base64_encode($output);
698 } elseif ($action === 'decrypt') {
699 $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
700 }
701
702 return $output;
703 }
704
705
706 /**
707 * Returns a list of providers that needs
708 * the bulk history update
709 *
710 * @return array
711 *
712 * @since 1.5
713 */
714 function sbr_get_bulk_providers()
715 {
716 return [
717 'google',
718 'yelp'
719 ];
720 }
721
722 /**
723 * Returns a list of providers that
724 * have media
725 *
726 * @return array
727 *
728 * @since 1.5
729 */
730 function sbr_get_media_providers()
731 {
732 return [
733 'yelp',
734 'tripadvisor',
735 'google'
736 ];
737 }
738
739 /**
740 * Returns a list of providers that doesn't
741 * have media
742 *
743 * @return array
744 *
745 * @since 1.5
746 */
747 function sbr_get_no_media_providers()
748 {
749 return [
750 'facebook',
751 'woocommerce',
752 'edd',
753 'airbnb',
754 'booking',
755 'aliexpress'
756 ];
757 }
758
759 /**
760 * Returns a list of providers that have
761 * translations / languages Possibility
762 *
763 * @return array
764 *
765 * @since 1.5
766 */
767 function sbr_get_lang_providers()
768 {
769 return [
770 'google'
771 ];
772 }
773