This commit is contained in:
2026-04-26 23:47:49 +02:00
parent 1b95f03d1e
commit b073e009d8
5288 changed files with 1112699 additions and 55536 deletions

View File

@@ -0,0 +1,50 @@
<?php
namespace Smashballoon\Framework\Utilities\PlatformTracking;
use Smashballoon\Framework\Utilities\PlatformTracking\Platforms\Bluehost;
use Smashballoon\Framework\Utilities\PlatformTracking\Platforms\Flywheel;
use Smashballoon\Framework\Utilities\PlatformTracking\Platforms\GoDadddy;
use Smashballoon\Framework\Utilities\PlatformTracking\Platforms\Kinsta;
use Smashballoon\Framework\Utilities\PlatformTracking\Platforms\SiteGround;
use Smashballoon\Framework\Utilities\PlatformTracking\Platforms\WPEngine;
/** @internal */
class PlatformTracking
{
/**
* PlatformTracking constructor.
*/
public function __construct()
{
$this->register_platforms();
}
/**
* Register the hosting platforms.
*
* @return void
*/
public function register_platforms()
{
$kinsta = new Kinsta();
$wpengine = new WPEngine();
$godaddy = new GoDadddy();
$bluehost = new Bluehost();
$flywheel = new Flywheel();
$siteground = new SiteGround();
$kinsta->register();
$wpengine->register();
$godaddy->register();
$bluehost->register();
$flywheel->register();
$siteground->register();
}
/**
* Get the current hosting platform.
*
* @return string
*/
public static function get_platform()
{
return \apply_filters('sb_hosting_platform', 'unknown');
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace Smashballoon\Framework\Utilities\PlatformTracking\Platforms;
/** @internal */
class Bluehost implements \Smashballoon\Framework\Utilities\PlatformTracking\Platforms\PlatformInterface
{
/**
* @inheritDoc
*/
public function register()
{
\add_filter('sb_hosting_platform', [$this, 'filter_sb_hosting_platform']);
}
/**
* @inheritDoc
*/
public function filter_sb_hosting_platform($platform)
{
if (\defined('BLUEHOST_PLUGIN_VERSION')) {
$platform = 'bluehost';
}
return $platform;
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace Smashballoon\Framework\Utilities\PlatformTracking\Platforms;
/** @internal */
class Flywheel implements \Smashballoon\Framework\Utilities\PlatformTracking\Platforms\PlatformInterface
{
/**
* @inheritDoc
*/
public function register()
{
\add_filter('sb_hosting_platform', [$this, 'filter_sb_hosting_platform']);
}
/**
* @inheritDoc
*/
public function filter_sb_hosting_platform($platform)
{
if (\defined('FLYWHEEL_CONFIG_DIR')) {
$platform = 'flywheel';
}
return $platform;
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace Smashballoon\Framework\Utilities\PlatformTracking\Platforms;
/** @internal */
class GoDadddy implements \Smashballoon\Framework\Utilities\PlatformTracking\Platforms\PlatformInterface
{
/**
* @inheritDoc
*/
public function register()
{
\add_filter('sb_hosting_platform', [$this, 'filter_sb_hosting_platform']);
}
/**
* @inheritDoc
*/
public function filter_sb_hosting_platform($platform)
{
if (!empty(\getenv('WPAAS_POD'))) {
$platform = 'godaddy';
}
return $platform;
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace Smashballoon\Framework\Utilities\PlatformTracking\Platforms;
/** @internal */
class Kinsta implements \Smashballoon\Framework\Utilities\PlatformTracking\Platforms\PlatformInterface
{
/**
* @inheritDoc
*/
public function register()
{
\add_filter('sb_hosting_platform', [$this, 'filter_sb_hosting_platform']);
}
/**
* @inheritDoc
*/
public function filter_sb_hosting_platform($platform)
{
if (!empty(\getenv('KINSTA_CACHE_ZONE'))) {
$platform = 'kinsta';
}
return $platform;
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace Smashballoon\Framework\Utilities\PlatformTracking\Platforms;
/** @internal */
interface PlatformInterface
{
/**
* Register the platform hooks.
*
* @return void
*/
public function register();
/**
* Filter the hosting platform.
*
* @param string $platform
*
* @return string
*/
public function filter_sb_hosting_platform($platform);
}

View File

@@ -0,0 +1,25 @@
<?php
namespace Smashballoon\Framework\Utilities\PlatformTracking\Platforms;
/** @internal */
class SiteGround implements \Smashballoon\Framework\Utilities\PlatformTracking\Platforms\PlatformInterface
{
/**
* @inheritDoc
*/
public function register()
{
\add_filter('sb_hosting_platform', [$this, 'filter_sb_hosting_platform']);
}
/**
* @inheritDoc
*/
public function filter_sb_hosting_platform($platform)
{
if (\defined('WP_CONTENT_URL') && \false !== \strpos(\WP_CONTENT_URL, 'sg-host.com')) {
$platform = 'siteground';
}
return $platform;
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace Smashballoon\Framework\Utilities\PlatformTracking\Platforms;
/** @internal */
class WPEngine implements \Smashballoon\Framework\Utilities\PlatformTracking\Platforms\PlatformInterface
{
/**
* @inheritDoc
*/
public function register()
{
\add_filter('sb_hosting_platform', [$this, 'filter_sb_hosting_platform']);
}
/**
* @inheritDoc
*/
public function filter_sb_hosting_platform($platform)
{
if (\method_exists('WpeCommon', 'get_wpe_auth_cookie_value') && !empty(\SmashBalloon\YoutubeFeed\Vendor\WpeCommon::get_wpe_auth_cookie_value())) {
$platform = 'wpengine';
}
return $platform;
}
}

View File

@@ -0,0 +1,139 @@
<?php
namespace Smashballoon\Framework\Utilities;
use Smashballoon\Framework\Utilities\PlatformTracking\PlatformTracking;
/** @internal */
class UsageTracking
{
const LIB_VERSION = '1.0.0';
const API_BASE_URL = 'https://usage.smashballoon.com/v1/';
const TRANSIENT_KEY = 'sb_%s_usage_tracking_last_send';
const TRANSIENT_EXPIRATION = 604800;
/**
* Compare feed settings to default settings and return an array of booleans.
*
* @param array $tracked_settings Array of tracked settings.
* @param array $default_settings Array of default settings.
* @param array $feed_settings Array of feed settings.
*
* @return array
*/
public static function tracked_settings_to_booleans($tracked_settings, $default_settings, $feed_settings)
{
$settings = [];
foreach ($tracked_settings as $setting) {
if (isset($default_settings[$setting]) && isset($feed_settings[$setting])) {
$settings[$setting] = $feed_settings[$setting] !== $default_settings[$setting] ? 1 : 0;
}
}
return $settings;
}
/**
* Returns an array tracked feed settings.
*
* @param array $tracked_settings Array of tracked settings.
* @param array $feed_settings Array of feed settings.
*
* @return array
*/
public static function tracked_settings_to_strings($tracked_settings, $feed_settings)
{
$settings = [];
foreach ($tracked_settings as $setting) {
if (isset($feed_settings[$setting])) {
$settings[$setting] = $feed_settings[$setting];
}
}
return $settings;
}
/**
* Send usage update to the API.
*
* @param array $data Usage tracking data.
* @param string $plugin_slug Plugin slug.
*
* @return boolean
*/
public static function send_usage_update($data, $plugin_slug)
{
$plugin_name = self::get_plugin_name_from_slug($plugin_slug);
if (empty($plugin_name)) {
return \false;
}
$last_send_transient = \get_transient(\sprintf(self::TRANSIENT_KEY, $plugin_name));
// Return if the last send was less than a week ago
if (\false !== $last_send_transient) {
return \true;
}
if (!isset($data['hosting_platform'])) {
$data['hosting_platform'] = PlatformTracking::get_platform();
}
// Filter usage tracking data
$data = \apply_filters('sb_usage_tracking_data', $data, $plugin_slug);
if (!\is_array($data) || empty($data)) {
return \false;
}
if (self::post_data($data)) {
\set_transient(self::get_transient_name($plugin_name), \time(), self::TRANSIENT_EXPIRATION);
return \true;
}
return \false;
}
/**
* Send POST request to the API.
*
* @param array $data Usage tracking data.
*
* @return boolean
*/
private static function post_data($data)
{
$response = \wp_remote_post(self::API_BASE_URL . 'checkin/', ['body' => \json_encode($data), 'timeout' => 5, 'blocking' => \true, 'sslverify' => \false, 'headers' => ['Content-Type' => 'application/json; charset=utf-8', 'user-agent' => 'SB/' . self::LIB_VERSION . '; ' . \get_bloginfo('url')]]);
if (\is_wp_error($response)) {
return \false;
}
$response_code = \wp_remote_retrieve_response_code($response);
if (200 !== $response_code) {
return \false;
}
return \true;
}
/**
* Get transient name.
*
* @param string $plugin_name Plugin name.
*
* @return string
*/
private static function get_transient_name($plugin_name)
{
return \sprintf(self::TRANSIENT_KEY, $plugin_name);
}
/**
* Get plugin name from slug.
*
* @param string $slug Plugin slug.
*
* @return string
*/
private static function get_plugin_name_from_slug($slug)
{
switch ($slug) {
case 'cff':
return 'facebook';
case 'ctf':
return 'twitter';
case 'sby':
return 'youtube';
case 'sbr':
return 'reviews';
case 'sbtt':
return 'tiktok';
case 'sbi':
return 'instagram';
default:
return '';
}
}
}

View File

@@ -0,0 +1,178 @@
<?php
namespace Smashballoon\Framework;
if (!\function_exists('Smashballoon\\Framework\\sb_doing_it_wrong')) {
/**
* Wrapper for _doing_it_wrong().
*
* @param string $function Function used.
* @param string $message Message to log.
* @param string $version Version the message was added in.
*
* @return void
* @internal
*/
function sb_doing_it_wrong($function, $message, $version)
{
// @codingStandardsIgnoreStart
$message .= ' Backtrace: ' . \wp_debug_backtrace_summary();
if (\wp_doing_ajax()) {
\do_action('doing_it_wrong_run', $function, $message, $version);
\error_log("{$function} was called incorrectly. {$message}. This message was added in version {$version}.");
} else {
\_doing_it_wrong($function, $message, $version);
}
// @codingStandardsIgnoreEnd
}
}
if (!\function_exists('Smashballoon\\Framework\\sb_locate_template')) {
/**
* Locate a template and return the path for inclusion.
*
* This is the load order:
*
* yourtheme/$template_path/$template_name
* yourtheme/$template_name
* $default_path/$template_name
*
* @param string $template_name Template name.
* @param string $template_path Template path. (default: '').
* @param string $default_path Default path. (default: '').
*
* @return string Template path.
* @internal
*/
function sb_locate_template($template_name, $template_path = '', $default_path = '')
{
if (!$template_path) {
$template_path = \apply_filters('sb_template_path', 'smashballoon/');
}
if (!$default_path) {
$default_path = \untrailingslashit(\plugin_dir_path(__DIR__)) . '/Packages/';
$default_path = \apply_filters('sb_default_template_path', $default_path);
}
// Look within passed path within the theme - this is priority.
$template = \locate_template([\trailingslashit($template_path) . $template_name, $template_name]);
// Get default template.
if (!$template) {
$template = $default_path . $template_name;
}
// Return what we found.
return \apply_filters('sb_locate_template', $template, $template_name, $template_path);
}
}
if (!\function_exists('Smashballoon\\Framework\\sb_get_template')) {
/**
* Get other templates passing attributes and including the file.
*
* @param string $template_name Template name.
* @param array $args Arguments. (default: array).
* @param string $template_path Template path. (default: '').
* @param string $default_path Default path. (default: '').
*
* @return void
* @internal
*/
function sb_get_template($template_name, $args = [], $template_path = '', $default_path = '')
{
$cache_key = \sanitize_key(\implode('-', ['template', $template_name, $template_path, $default_path]));
$template = (string) \wp_cache_get($cache_key, 'smashballoon');
if (!$template) {
$template = sb_locate_template($template_name, $template_path, $default_path);
\wp_cache_set($cache_key, $template, 'smashballoon');
}
// Allow 3rd party plugin filter template file from their plugin.
$filter_template = \apply_filters('sb_get_template', $template, $template_name, $args, $template_path, $default_path);
if ($filter_template !== $template) {
if (!\file_exists($filter_template)) {
// translators: %s template.
sb_doing_it_wrong(__FUNCTION__, \sprintf(\__('%s does not exist.', 'sb-notices'), '<code>' . $template . '</code>'), '6.2.2');
return;
}
$template = $filter_template;
}
$action_args = ['template_name' => $template_name, 'template_path' => $template_path, 'located' => $template, 'args' => $args];
if (!empty($args) && \is_array($args)) {
if (isset($args['action_args'])) {
sb_doing_it_wrong(__FUNCTION__, \__('action_args should not be overwritten when calling sb_get_template.', 'sb-notices'), '1.0.0');
unset($args['action_args']);
}
\extract($args);
}
\do_action('sb_before_template_part', $action_args['template_name'], $action_args['template_path'], $action_args['located'], $action_args['args']);
include $action_args['located'];
\do_action('sb_after_template_part', $action_args['template_name'], $action_args['template_path'], $action_args['located'], $action_args['args']);
}
}
if (!\function_exists('Smashballoon\\Framework\\sb_map_notice_hooks')) {
/**
* Map notices hooks as per plugin name.
*
* @param string $plugin_name Plugin name.
*
* @return string $plugin_hook Plugin hook.
* @internal
*/
function sb_map_notice_hooks($plugin_name)
{
$notice_hooks = ['instagram-feed' => 'sbi_admin_notices', 'instagram-feed-pro' => 'sbi_admin_notices', 'custom-facebook-feed' => 'cff_admin_notices', 'custom-facebook-feed-pro' => 'cff_admin_notices'];
$plugin_hook = isset($notice_hooks[$plugin_name]) ? $notice_hooks[$plugin_name] : 'admin_notices';
return $plugin_hook;
}
}
if (!\function_exists('Smashballoon\\Framework\\sb_get_plugin_type')) {
/**
* Check if the plugin is free or pro.
*
* @param string $plugin_name Plugin name.
*
* @return string $plugin_type Plugin type.
* @internal
*/
function sb_get_plugin_type($plugin_name)
{
$plugins = ['instagram-feed' => 'free', 'instagram-feed-pro' => 'pro', 'custom-facebook-feed' => 'free', 'custom-facebook-feed-pro' => 'pro'];
$plugin_type = isset($plugins[$plugin_name]) ? $plugins[$plugin_name] : 'free';
return $plugin_type;
}
}
if (!\function_exists('Smashballoon\\Framework\\flatten_array')) {
/**
* Flatten a multidimensional array.
*
* @param array $array Array to flatten.
*
* @return array $result Flattened array.
* @internal
*/
function flatten_array($array)
{
$result = [];
foreach ($array as $value) {
if (\is_array($value)) {
$result = \array_merge($result, flatten_array($value));
} else {
$result[] = $value;
}
}
return $result;
}
}
if (!\function_exists('Smashballoon\\Framework\\sb_get_active_plugins')) {
/**
* Get active plugins.
*
* @return array $active_plugins Active plugins.
* @internal
*/
function sb_get_active_plugins()
{
if (\is_multisite()) {
$active_plugins = \array_keys((array) \get_site_option('active_sitewide_plugins', array()));
} else {
$active_plugins = (array) \get_option('active_plugins', array());
}
return $active_plugins;
}
}