$cached_code, 'i18n' => array( 'videoLoadError' => __('Napaka pri nalaganju videa. Poskusite znova.', 'aboutbuzz-stories-embed'), 'alreadyLiked' => __('Že ste označili kot uporabno', 'aboutbuzz-stories-embed'), 'voteError' => __('Napaka pri glasovanju. Poskusite znova.', 'aboutbuzz-stories-embed'), 'voteErrorPrefix' => __('Napaka pri glasovanju:', 'aboutbuzz-stories-embed'), ), ) ); } add_action('wp_enqueue_scripts', 'aboutbuzz_enqueue_assets'); // === Admin Menu === function aboutbuzz_activation_menu() { add_options_page( 'AboutBuzz Activation', 'AboutBuzz Activation', 'manage_options', 'aboutbuzz-activation', 'aboutbuzz_activation_page' ); } add_action('admin_menu', 'aboutbuzz_activation_menu'); function aboutbuzz_activation_page() { if (!current_user_can('manage_options')) { wp_die('Unauthorized user'); } ?>

AboutBuzz Activation

For setup or help, please contact info@aboutbuzz.com and visit aboutbuzz.com.

If you are subscribed to an AboutBuzz plan, you will find your setup instructions directly inside your client dashboard area on AboutBuzz.com.

Loading...' ); } function aboutbuzz_is_mobile() { return wp_is_mobile() || (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/Mobile|Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i', sanitize_text_field(wp_unslash($_SERVER['HTTP_USER_AGENT'])))); } function aboutbuzz_get_user_identifier() { $user_id = get_current_user_id(); if ($user_id) { return 'user_' . $user_id; } $ip = isset($_SERVER['REMOTE_ADDR']) ? sanitize_text_field(wp_unslash($_SERVER['REMOTE_ADDR'])) : 'unknown'; return 'anon_' . md5($ip . NONCE_SALT); } function aboutbuzz_get_detailed_error($response_code, $response_body) { switch ($response_code) { case 401: return 'Invalid secret code. Please check your activation settings.'; case 403: return 'Access forbidden. Your secret code may be expired.'; case 404: return 'Brand not found. Please check your activation code.'; case 429: // Hide rate limit details from end users; caller can decide to render nothing. return ''; case 500: return 'Server error. Please try again later.'; default: $data = json_decode($response_body, true); if (isset($data['message'])) { return 'API Error: ' . $data['message']; } return 'Unknown API error (Code: ' . $response_code . ')'; } } // === Shortcode - Uses ONLY /v1/stories/by-code === function aboutbuzz_smart_brand_stories_shortcode($atts) { $atts = shortcode_atts(['code' => ''], $atts); $activation_code = !empty($atts['code']) ? sanitize_text_field($atts['code']) : ''; if (empty($activation_code)) { return '
Activation code required in shortcode: [aboutbuzz_reviews code="ABZ-XXXX-XXXX"]
'; } if (strlen($activation_code) > 255) { return '
Invalid activation code format.
'; } // Cache activation code once so that analytics (CTA tracking) // can still work on pages where the widget is hidden. if (!empty($activation_code)) { update_option('aboutbuzz_activation_code_cache', $activation_code); } // Always fetch fresh data so changes in the AboutBuzz dashboard // (reordering, enabling/disabling videos) are reflected immediately. $api_rate_limit_key = 'aboutbuzz_api_rate_' . aboutbuzz_get_user_identifier(); $api_rate_count = get_transient($api_rate_limit_key); if ($api_rate_count && $api_rate_count >= 20) { // Local safety limit hit – just don’t render the widget instead of // showing an error to visitors. return ''; } $response = wp_remote_post('https://aboutbuzz.com/wp-json/aboutbuzz/v1/stories/by-code', [ 'timeout' => 10, 'headers' => [ 'Content-Type' => 'application/json', 'User-Agent' => 'AboutBuzz-WordPress-Plugin/1.9.1', 'Accept' => 'application/json', ], 'body' => wp_json_encode(['code' => $activation_code]), 'sslverify' => true, ]); $new_api_count = $api_rate_count ? $api_rate_count + 1 : 1; set_transient($api_rate_limit_key, $new_api_count, 3600); if (is_wp_error($response)) { return '
Error fetching stories.
'; } $response_code = wp_remote_retrieve_response_code($response); $response_body = wp_remote_retrieve_body($response); if ($response_code !== 200) { // For rate limiting (429), or when the helper returns an empty string, // previously we hid the widget. Surface a friendly notice instead so // the UI doesn't disappear when an IP hits the limit. $error_message = aboutbuzz_get_detailed_error($response_code, $response_body); if ($response_code === 429) { $error_message = 'Rate limit reached. Please try again in a few minutes.'; } if ($error_message === '') { $error_message = 'Unable to load reviews right now. Please try again soon.'; } return '
' . esc_html($error_message) . '
'; } $data = json_decode($response_body, true); if (json_last_error() !== JSON_ERROR_NONE || !is_array($data)) { return '
Invalid response format.
'; } $sanitized_posts = []; foreach ($data as $story) { if (!is_array($story) || empty($story['id'])) { continue; } // Prefer API-provided values; fall back to sensible defaults. $video_url = $story['content'] ?? $story['link'] ?? ''; $rating = intval($story['acf']['rating'] ?? $story['meta']['rating'][0] ?? 5); $vote_count = intval($story['acf']['vote_count'] ?? $story['meta']['vote_count'][0] ?? 0); $watermark = $story['acf']['watermark_video'] ?? $story['meta']['watermark_video'][0] ?? ''; $sanitized_posts[] = [ 'ID' => intval($story['id']), 'post_title' => sanitize_text_field($story['title'] ?? ''), 'meta' => [ 'story' => [esc_url_raw($video_url)], 'rating' => [$rating], 'vote_count' => [$vote_count], 'watermark_video' => [esc_url_raw(is_array($watermark) ? ($watermark[0] ?? '') : $watermark)], ], 'acf' => [ 'watermark_video' => esc_url_raw(is_array($watermark) ? ($watermark[0] ?? '') : $watermark), 'story' => esc_url_raw($video_url), 'rating' => $rating, 'vote_count' => $vote_count, ], ]; } if (empty($sanitized_posts)) { return '
' . esc_html__('Ni video ocen', 'aboutbuzz-stories-embed') . '
'; } $total_rating = 0; $rating_count = 0; foreach ($sanitized_posts as $post) { $rating = $post['meta']['rating'][0] ?? $post['acf']['rating'] ?? 0; if ($rating > 0) { $total_rating += $rating; $rating_count++; } } $average_rating = $rating_count > 0 ? round($total_rating / $rating_count, 2) : 0; $widget_nonce = wp_create_nonce('aboutbuzz_widget_' . md5($activation_code)); $video_count = count($sanitized_posts); $has_many_videos = $video_count >= 4 ? ' aboutbutzz-has-many-videos' : ''; ob_start(); ?>
<?php echo esc_attr(sprintf(__('Predogled videa za %s', 'aboutbuzz-stories-embed'), $post['post_title'])); ?> <?php echo esc_attr(sprintf(__('Predogled videa za %s', 'aboutbuzz-stories-embed'), $post['post_title'])); ?>
Play
<?php echo esc_attr(sprintf(__('Predogled videa za %s', 'aboutbuzz-stories-embed'), $post['post_title'])); ?> <?php echo esc_attr(sprintf(__('Predogled videa za %s', 'aboutbuzz-stories-embed'), $post['post_title'])); ?>
Play
'; } ?>
Check
400)); } $nonce = sanitize_text_field(wp_unslash($_POST['nonce'])); $post_id = intval(wp_unslash($_POST['post_id'])); // Get activation code from cached option to verify nonce $activation_code = get_option('aboutbuzz_activation_code_cache', ''); if (empty($activation_code)) { wp_die('Plugin not configured', 'Error', array('response' => 403)); } if (!wp_verify_nonce($nonce, 'aboutbuzz_widget_' . md5($activation_code))) { wp_die('Security check failed'); } $user_id = aboutbuzz_get_user_identifier(); $like_key = 'aboutbuzz_liked_' . $post_id . '_' . $user_id; if (get_transient($like_key)) { wp_send_json_error(['message' => 'Already liked']); return; } $rate_limit_key = 'aboutbuzz_like_rate_' . $user_id; $rate_count = get_transient($rate_limit_key); if ($rate_count && $rate_count >= 5) { wp_send_json_error(['message' => 'Too many likes']); return; } $new_rate_count = $rate_count ? $rate_count + 1 : 1; set_transient($rate_limit_key, $new_rate_count, 3600); $secret_code = get_option('aboutbuzz_activation_code_cache', ''); if (empty($secret_code)) { wp_send_json_error(['message' => 'Plugin not configured. Please use the shortcode first.']); return; } $response = wp_remote_post('https://aboutbuzz.com/wp-json/aboutbuzz/v1/like/', [ 'timeout' => 8, 'headers' => [ 'Content-Type' => 'application/json', 'User-Agent' => 'AboutBuzz-WordPress-Plugin/1.9.1' ], 'body' => wp_json_encode([ 'code' => sanitize_text_field($secret_code), 'post_id' => $post_id ]) ]); if (is_wp_error($response)) { wp_send_json_error(['message' => 'API error']); return; } $response_code = wp_remote_retrieve_response_code($response); $response_body = wp_remote_retrieve_body($response); if ($response_code !== 200) { wp_send_json_error(['message' => 'API error']); return; } $data = json_decode($response_body, true); if (!$data || !isset($data['success']) || !$data['success']) { wp_send_json_error(['message' => 'API error']); return; } set_transient($like_key, true, 86400); wp_send_json_success([ 'vote_count' => intval($data['vote_count'] ?? 0) ]); } add_action('wp_ajax_aboutbuzz_like_post', 'aboutbuzz_like_post'); add_action('wp_ajax_nopriv_aboutbuzz_like_post', 'aboutbuzz_like_post'); // === Uninstall Hook === register_uninstall_hook(__FILE__, 'aboutbuzz_uninstall'); function aboutbuzz_uninstall() { try { delete_option('aboutbuzz_secret_code'); delete_option('aboutbuzz_activation_code_cache'); $transient_keys = [ 'aboutbuzz_validation_', 'aboutbuzz_rate_limit_', 'aboutbuzz_cache_', 'aboutbuzz_stories_bycode_' ]; foreach ($transient_keys as $key) { wp_cache_delete($key, 'transient'); } wp_cache_flush(); } catch (Exception $e) { // Silent fail } } // === Plugin Activation Hook === register_activation_hook(__FILE__, 'aboutbuzz_activate'); function aboutbuzz_activate() { if (version_compare(PHP_VERSION, '7.4', '<')) { deactivate_plugins(plugin_basename(__FILE__)); wp_die('This plugin requires PHP 7.4 or higher.'); } add_option('aboutbuzz_secret_code', ''); wp_cache_flush(); } // === Plugin Deactivation Hook === register_deactivation_hook(__FILE__, 'aboutbuzz_deactivate'); function aboutbuzz_deactivate() { $transient_keys = [ 'aboutbuzz_validation_', 'aboutbuzz_rate_limit_', 'aboutbuzz_cache_', 'aboutbuzz_stories_bycode_' ]; foreach ($transient_keys as $key) { wp_cache_delete($key, 'transient'); } wp_cache_flush(); }