. * @since 3.0.0 */ namespace Decalog\Plugin\Feature; use Decalog\Plugin\Core; /** * SDK utilities for DecaLog. * * Defines methods and properties for SDK introspection. * * @package Features * @author Pierre Lannoy . * @since 3.0.0 */ class SDK { /** * The components' icons. * * @since 3.1.0 * @var array $icons Maintains the icons list. */ private static $icons = []; /** * Verify if SDK is present. * * @retun boolean True if SDK is present, false otherwise. * @since 3.0.0 */ public static function is_present() { return class_exists( '\DecaLog\Engine' ); } /** * Get the self-registered components list. * * @return array The self-registered components list. * @since 3.0.0 */ public static function get_selfreg() { if ( self::is_present() ) { $result = \DecaLog\Engine::getLoggers(); foreach ( $result as $slug => $loger ) { $result[ $slug ]['slug'] = $slug; } return $result; } return []; } /** * Returns a base64 svg resource for the PHP icon. * * @param string $color Optional. Color of the icon. * @return string The svg resource as a base64. * @since 3.1.0 */ private static function get_base64_php_icon( $color = '#777BB3' ) { $source = ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; // phpcs:ignore return 'data:image/svg+xml;base64,' . base64_encode( $source ); } /** * Returns a base64 svg resource for the WordPress icon. * * @param string $color Optional. Color of the icon. * @return string The svg resource as a base64. * @since 3.1.0 */ private static function get_base64_wordpress_icon( $color = '#0073AA' ) { $source = ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; // phpcs:ignore return 'data:image/svg+xml;base64,' . base64_encode( $source ); } /** * Returns a base64 svg resource for the Jetpack icon. * * @param string $color Optional. Color of the icon. * @return string The svg resource as a base64. * @since 3.1.0 */ private static function get_base64_jetpack_icon( $color = '#00be28' ) { $source = ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; // phpcs:ignore return 'data:image/svg+xml;base64,' . base64_encode( $source ); } /** * Returns a base64 svg resource for the Stripe icon. * * @param string $color Optional. Color of the icon. * @return string The svg resource as a base64. * @since 3.1.0 */ private static function get_base64_stripe_icon( $color = '#6772e5' ) { $source = ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; // phpcs:ignore return 'data:image/svg+xml;base64,' . base64_encode( $source ); } /** * Returns a base64 svg resource for the Amelia Stripe Gateway icon. * * @param string $color1 Optional. Color 1 of the icon. * @param string $color2 Optional. Color 2 of the icon. * @param string $color3 Optional. Color 3 of the icon. * @return string The svg resource as a base64. * @since 3.1.0 */ private static function get_base64_amelia_icon( $color1 = '#2287ef', $color2 = '#47aafc', $color3 = '#045af7' ) { $source = ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; // phpcs:ignore return 'data:image/svg+xml;base64,' . base64_encode( $source ); } /** * Returns a base64 svg resource for the WooCommerce icon. * * @param string $color1 Optional. Color 1 of the icon. * @param string $color2 Optional. Color 2 of the icon. * @return string The svg resource as a base64. * @since 3.1.0 */ private static function get_base64_woo_icon( $color1 = '#7f54b3', $color2 = '#fff' ) { $source = ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; // phpcs:ignore return 'data:image/svg+xml;base64,' . base64_encode( $source ); } /** * Returns a base64 svg resource for the BuddyPress icon. * * @param string $color Optional. Color of the icon. * @return string The svg resource as a base64. * @since 3.1.0 */ private static function get_base64_buddypress_icon( $color = '#d84800' ) { $source = ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; // phpcs:ignore return 'data:image/svg+xml;base64,' . base64_encode( $source ); } /** * Returns a base64 svg resource for the bbPress icon. * * @param string $color Optional. Color of the icon. * @return string The svg resource as a base64. * @since 3.1.0 */ private static function get_base64_bbpress_icon( $color = '#4f4d4b' ) { $source = ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; // phpcs:ignore return 'data:image/svg+xml;base64,' . base64_encode( $source ); } /** * Returns a base64 svg resource for the W3TC icon. * * @param string $color1 Optional. Color 1 of the icon. * @param string $color2 Optional. Color 2 of the icon. * @param string $color3 Optional. Color 3 of the icon. * @return string The svg resource as a base64. * @since 3.1.0 */ private static function get_base64_w3tc_icon( $color1 = '#3b7e83', $color2 = '#3b7e83', $color3 = '#3b7e83' ) { $source = ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; // phpcs:ignore return 'data:image/svg+xml;base64,' . base64_encode( $source ); } /** * Returns a base64 svg resource for the Amelia Stripe Gateway icon. * * @param string $color1 Optional. Color 1 of the icon. * @param string $color2 Optional. Color 2 of the icon. * @return string The svg resource as a base64. * @since 3.1.0 */ private static function get_base64_wpcli_icon( $color1 = '#000000', $color2 = '#FFFFFF' ) { $source = ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; // phpcs:ignore return 'data:image/svg+xml;base64,' . base64_encode( $source ); } /** * Returns a base64 svg resource for the Cavalcade icon. * * @param string $color Optional. Color of the icon. * @return string The svg resource as a base64. * @since 3.1.0 */ private static function get_base64_cavalcade_icon( $color = '#C1503B' ) { $source = ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; // phpcs:ignore return 'data:image/svg+xml;base64,' . base64_encode( $source ); } /** * Returns a base64 svg resource for the MariaDB icon. * * @param string $color Optional. Color of the icon. * @return string The svg resource as a base64. * @since 3.1.0 */ private static function get_base64_db_mariadb_icon( $color = '#003545' ) { $source = ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; // phpcs:ignore return 'data:image/svg+xml;base64,' . base64_encode( $source ); } /** * Returns a base64 svg resource for the MySql icon. * * @param string $color Optional. Color of the icon. * @return string The svg resource as a base64. * @since 3.1.0 */ private static function get_base64_db_mysql_icon( $color = '#00678c' ) { $source = ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; // phpcs:ignore return 'data:image/svg+xml;base64,' . base64_encode( $source ); } /** * Returns a base64 svg resource for the postgreSQL icon. * * @param string $color1 Optional. Color 1 of the icon. * @param string $color2 Optional. Color 2 of the icon. * @param string $color3 Optional. Color 3 of the icon. * @return string The svg resource as a base64. * @since 3.1.0 */ private static function get_base64_db_postgresql_icon( $color1 = '#000000', $color2 = '#336791', $color3 = '#ffffff' ) { $source = ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; // phpcs:ignore return 'data:image/svg+xml;base64,' . base64_encode( $source ); } /** * Returns a base64 svg resource for the postgreSQL icon. * * @param string $color1 Optional. Color 1 of the icon. * @param string $color2 Optional. Color 2 of the icon. * @param string $color3 Optional. Color 3 of the icon. * @param string $color4 Optional. Color 4 of the icon. * @return string The svg resource as a base64. * @since 3.1.0 */ private static function get_base64_db_percona_icon( $color1 = '#FBB32F', $color2 = '#C11511', $color3 = '#C11411', $color4 = '#FCB42F' ) { $source = ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; // phpcs:ignore return 'data:image/svg+xml;base64,' . base64_encode( $source ); } /** * Returns a base64 svg resource for the MySql icon. * * @param string $color Optional. Color of the icon. * @return string The svg resource as a base64. * @since 3.1.0 */ private static function get_base64_redisocp_icon( $color = '#C93A31' ) { $source = ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; // phpcs:ignore return 'data:image/svg+xml;base64,' . base64_encode( $source ); } /** * Returns a base64 svg resource for the postgreSQL icon. * * @param string $color1 Optional. Color 1 of the icon. * @param string $color2 Optional. Color 2 of the icon. * @param string $color3 Optional. Color 3 of the icon. * @param string $color4 Optional. Color 4 of the icon. * @param string $color5 Optional. Color 5 of the icon. * @return string The svg resource as a base64. * @since 3.1.0 */ private static function get_base64_redisoc_icon( $color1 = '#912626', $color2 = '#C6302B', $color3 = '#621B1C', $color4 = '#9A2928', $color5 = '#ffffff' ) { $source = ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; // phpcs:ignore return 'data:image/svg+xml;base64,' . base64_encode( $source ); } /** * Returns a base64 svg resource for the WP Migrate icon. * * @param string $color1 Optional. Color 1 of the icon. * @param string $color2 Optional. Color 2 of the icon. * @param string $color3 Optional. Color 3 of the icon. * @return string The svg resource as a base64. * @since 4.1.0 */ private static function get_base64_wpmigrate_icon( $color1 = '#81BDD4', $color2 = '#04223F', $color3 = '#ffffff' ) { $source = ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; $source .= ''; // phpcs:ignore return 'data:image/svg+xml;base64,' . base64_encode( $source ); } /** * Returns a base64 svg resource for the WordPress icon. * * @return string The svg resource as a base64. * @since 3.1.0 */ private static function get_base64_blank_icon() { $source = ''; $source .= ''; // phpcs:ignore return 'data:image/svg+xml;base64,' . base64_encode( $source ); } /** * Get the (mainly) self-registered icon for a specific component. * * @param string $component The name of the component. * @param boolean $blank Optional. Return a blank icon if not found. * @return string The base64 encoded image. * @since 3.1.0 */ public static function get_icon( $component, $blank = true ) { if ( array_key_exists( $component, self::$icons ) ) { return self::$icons[ $component ]; } $result = ''; switch ( strtolower( $component ) ) { case 'wordpress': $result = self::get_base64_wordpress_icon(); break; case 'w3 total cache': $result = self::get_base64_w3tc_icon(); break; case 'php': $result = self::get_base64_php_icon(); break; case 'jetpack': $result = self::get_base64_jetpack_icon(); break; case 'decalog': $result = Core::get_base64_logo(); break; case 'amelia stripe gateway': $result = self::get_base64_amelia_icon(); break; case 'standard stripe gateway': case 'forminator stripe gateway': $result = self::get_base64_stripe_icon(); break; case 'action scheduler': case 'woocommerce': $result = self::get_base64_woo_icon(); break; case 'buddypress': $result = self::get_base64_buddypress_icon(); break; case 'bbpress': $result = self::get_base64_bbpress_icon(); break; case 'cavalcade': $result = self::get_base64_cavalcade_icon(); break; case 'wp-cli': $result = self::get_base64_wpcli_icon(); break; case 'mariadb': $result = self::get_base64_db_mariadb_icon(); break; case 'percona': $result = self::get_base64_db_percona_icon(); break; case 'postgresql': $result = self::get_base64_db_postgresql_icon(); break; case 'mysql': $result = self::get_base64_db_mysql_icon(); break; case 'redis object cache': $result = self::get_base64_redisoc_icon(); break; case 'object cache pro': $result = self::get_base64_redisocp_icon(); break; case 'wp migrate': case 'wp migrate pro': case 'wp migrate lite': $result = self::get_base64_wpmigrate_icon(); break; } if ( '' === $result ) { foreach ( self::get_selfreg() as $logger ) { if ( $logger['name'] === $component ) { $result = $logger['icon']; } } } if ( '' === $result && $blank ) { $result = self::get_base64_blank_icon(); } self::$icons[ $component ] = $result; return $result; } /** * Get the self-registered components list for display. * * @return string The output of the shortcode, ready to print. * @since 3.0.0 */ public static function sc_get_selfreg() { $result = ''; foreach ( self::get_selfreg() as $logger ) { $result .= '
'; $result .= ''; $result .= '
' . $logger['name'] . '
' . $logger['version'] . '
'; $result .= '
'; } return '
' . $result . '
'; } }