| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Plugin Name: bBlocks |
| 5 |
* Description: Gutenberg Blocks Collection and Page Builder. |
| 6 |
* Version: 2.0.43 |
| 7 |
* Author: bPlugins |
| 8 |
* Author URI: https://bplugins.com |
| 9 |
* License: GPLv3 |
| 10 |
* License URI: https://www.gnu.org/licenses/gpl-3.0.txt |
| 11 |
* Text Domain: b-blocks |
| 12 |
*/ |
| 13 |
// ABS PATH |
| 14 |
if ( !defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
if ( function_exists( 'b_blocks_fs' ) ) { |
| 18 |
register_activation_hook( __FILE__, function () { |
| 19 |
if ( is_plugin_active( 'b-blocks/plugin.php' ) ) { |
| 20 |
deactivate_plugins( 'b-blocks/plugin.php' ); |
| 21 |
} |
| 22 |
if ( is_plugin_active( 'b-blocks-pro/plugin.php' ) ) { |
| 23 |
deactivate_plugins( 'b-blocks-pro/plugin.php' ); |
| 24 |
} |
| 25 |
} ); |
| 26 |
} else { |
| 27 |
// Constant |
| 28 |
define( 'B_BLOCKS_VERSION', ( isset( $_SERVER['HTTP_HOST'] ) && ('localhost' === $_SERVER['HTTP_HOST'] || 'muradwahid.local' === $_SERVER['HTTP_HOST']) ? time() : '2.0.43' ) ); |
| 29 |
define( 'B_BLOCKS_DIR_PATH', plugin_dir_path( __FILE__ ) ); |
| 30 |
define( 'B_BLOCKS_DIR_URL', plugin_dir_url( __FILE__ ) ); |
| 31 |
define( 'B_BLOCKS_HAS_PRO', 'b-blocks-pro/plugin.php' === plugin_basename( __FILE__ ) ); |
| 32 |
define( 'B_BLOCKS_BUILD', B_BLOCKS_DIR_URL . 'build/' ); |
| 33 |
define( 'B_BLOCKS_ASSETS', B_BLOCKS_DIR_URL . 'assets/' ); |
| 34 |
if ( !function_exists( 'b_blocks_fs' ) ) { |
| 35 |
// Create a helper function for easy SDK access. |
| 36 |
function b_blocks_fs() { |
| 37 |
global $b_blocks_fs; |
| 38 |
if ( !isset( $b_blocks_fs ) ) { |
| 39 |
// Include Freemius SDK. |
| 40 |
require_once dirname( __FILE__ ) . '/freemius/start.php'; |
| 41 |
$b_blocks_fs = fs_dynamic_init( array( |
| 42 |
'id' => '12845', |
| 43 |
'slug' => 'b-blocks', |
| 44 |
'premium_slug' => 'b-blocks-pro', |
| 45 |
'type' => 'plugin', |
| 46 |
'public_key' => 'pk_d6426b344df4918bc066a7a0b4719', |
| 47 |
'is_premium' => false, |
| 48 |
'premium_suffix' => 'Pro', |
| 49 |
'has_addons' => false, |
| 50 |
'has_paid_plans' => true, |
| 51 |
'trial' => array( |
| 52 |
'days' => 7, |
| 53 |
'is_require_payment' => true, |
| 54 |
), |
| 55 |
'menu' => array( |
| 56 |
'slug' => 'b-blocks', |
| 57 |
'first-path' => 'admin.php?page=b-blocks', |
| 58 |
'contact' => false, |
| 59 |
'support' => false, |
| 60 |
), |
| 61 |
'is_live' => true, |
| 62 |
'is_org_compliant' => true, |
| 63 |
) ); |
| 64 |
} |
| 65 |
return $b_blocks_fs; |
| 66 |
} |
| 67 |
|
| 68 |
// Init Freemius. |
| 69 |
b_blocks_fs(); |
| 70 |
// Signal that SDK was initiated. |
| 71 |
do_action( 'b_blocks_fs_loaded' ); |
| 72 |
} |
| 73 |
// Generate Styles |
| 74 |
class BBlocksStyleGenerator { |
| 75 |
public static $styles = []; |
| 76 |
|
| 77 |
public static function addStyle( $selector, $styles ) { |
| 78 |
if ( array_key_exists( $selector, self::$styles ) ) { |
| 79 |
self::$styles[$selector] = wp_parse_args( self::$styles[$selector], $styles ); |
| 80 |
} else { |
| 81 |
self::$styles[$selector] = $styles; |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
public static function renderStyle() { |
| 86 |
$output = ''; |
| 87 |
foreach ( self::$styles as $selector => $style ) { |
| 88 |
$new = ''; |
| 89 |
foreach ( $style as $property => $value ) { |
| 90 |
if ( $value == '' ) { |
| 91 |
$new .= "{$property} ;"; |
| 92 |
} else { |
| 93 |
$new .= " {$property}: {$value};"; |
| 94 |
} |
| 95 |
} |
| 96 |
$output .= "{$selector} { {$new} }"; |
| 97 |
} |
| 98 |
return $output; |
| 99 |
} |
| 100 |
|
| 101 |
} |
| 102 |
|
| 103 |
// Require files |
| 104 |
require_once B_BLOCKS_DIR_PATH . 'includes/Dashboard.php'; |
| 105 |
require_once B_BLOCKS_DIR_PATH . 'includes/EnqueueScripts.php'; |
| 106 |
require_once B_BLOCKS_DIR_PATH . 'includes/Utils.php'; |
| 107 |
require_once B_BLOCKS_DIR_PATH . 'includes/GetCSS.php'; |
| 108 |
require_once B_BLOCKS_DIR_PATH . 'includes/Ajax.php'; |
| 109 |
require_once B_BLOCKS_DIR_PATH . 'includes/posts/Posts.php'; |
| 110 |
require_once B_BLOCKS_DIR_PATH . 'includes/Templates/Templates.php'; |
| 111 |
require_once B_BLOCKS_DIR_PATH . 'includes/blocks/LoginForm.php'; |
| 112 |
require_once B_BLOCKS_DIR_PATH . 'includes/blocks/cursor.php'; |
| 113 |
require_once B_BLOCKS_DIR_PATH . 'includes/Ai.php'; |
| 114 |
require_once B_BLOCKS_DIR_PATH . 'includes/ApiKeys.php'; |
| 115 |
require_once B_BLOCKS_DIR_PATH . 'includes/blocks/form/FormHandler.php'; |
| 116 |
// License Activation |
| 117 |
if ( file_exists( B_BLOCKS_DIR_PATH . 'includes/LicenseActivation.php' ) && B_BLOCKS_HAS_PRO ) { |
| 118 |
require_once B_BLOCKS_DIR_PATH . 'includes/LicenseActivation.php'; |
| 119 |
} |
| 120 |
class BBlocks { |
| 121 |
protected static $_instance = null; |
| 122 |
|
| 123 |
function __construct() { |
| 124 |
add_action( 'init', [$this, 'onInit'] ); |
| 125 |
add_action( 'wp_ajax_bBlocksPipeChecker', [$this, 'bBlocksPipeChecker'] ); |
| 126 |
add_action( 'wp_ajax_nopriv_bBlocksPipeChecker', [$this, 'bBlocksPipeChecker'] ); |
| 127 |
add_action( 'admin_init', [$this, 'registerSettings'] ); |
| 128 |
add_action( 'rest_api_init', [$this, 'registerSettings'] ); |
| 129 |
add_filter( 'block_categories_all', [$this, 'registerCategories'] ); |
| 130 |
add_filter( 'upload_mimes', [$this, 'uploadMimes'] ); |
| 131 |
add_filter( |
| 132 |
'wp_check_filetype_and_ext', |
| 133 |
[$this, 'wpCheckFiletypeAndExt'], |
| 134 |
10, |
| 135 |
5 |
| 136 |
); |
| 137 |
add_action( 'wp_ajax_b-blocks-enable-svg-mime-type', [$this, 'enableSvgMimeType'] ); |
| 138 |
add_filter( |
| 139 |
'plugin_row_meta', |
| 140 |
[$this, 'pluginRowMeta'], |
| 141 |
10, |
| 142 |
2 |
| 143 |
); |
| 144 |
} |
| 145 |
|
| 146 |
function pluginRowMeta( $plugin_meta, $plugin_file ) { |
| 147 |
if ( strpos( $plugin_file, 'b-blocks' ) !== false && time() < strtotime( '2025-12-06' ) ) { |
| 148 |
$new_links = array( |
| 149 |
'deal' => "<a href='https://bblockswp.com/pricing/?from=plugins.php' target='_blank' style='font-weight: 600; color: #ff7a00;'>🎉 Black Friday Sale - Get up to 40% OFF Now!</a>", |
| 150 |
); |
| 151 |
$plugin_meta = array_merge( $plugin_meta, $new_links ); |
| 152 |
} |
| 153 |
return $plugin_meta; |
| 154 |
} |
| 155 |
|
| 156 |
public static function instance() { |
| 157 |
if ( self::$_instance === null ) { |
| 158 |
self::$_instance = new self(); |
| 159 |
} |
| 160 |
return self::$_instance; |
| 161 |
} |
| 162 |
|
| 163 |
function bBlocksPipeChecker() { |
| 164 |
$nonce = sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ?? null ) ); |
| 165 |
if ( !wp_verify_nonce( $nonce, 'wp_ajax' ) ) { |
| 166 |
wp_send_json_error( 'Invalid Request' ); |
| 167 |
} |
| 168 |
wp_send_json_success( [ |
| 169 |
'isPipe' => BBlocks\Inc\Utils::isPro(), |
| 170 |
] ); |
| 171 |
} |
| 172 |
|
| 173 |
function onInit() { |
| 174 |
$disabledBlocks = get_option( 'bBlocksDisabledBlocks', [] ); |
| 175 |
$disabledBlocks = ( is_array( $disabledBlocks ) ? $disabledBlocks : [] ); |
| 176 |
$premiumBlocks = ( BBlocks\Inc\Utils::isPro() ? [] : [ |
| 177 |
'b-blocks/logo-slider', |
| 178 |
'b-blocks/content-ticker', |
| 179 |
'b-blocks/image-hotspot', |
| 180 |
'b-blocks/stacked-cards' |
| 181 |
] ); |
| 182 |
// Add dependent blocks |
| 183 |
if ( in_array( 'b-blocks/row', $disabledBlocks ) && !in_array( 'b-blocks/column', $disabledBlocks ) ) { |
| 184 |
$disabledBlocks[] = 'b-blocks/column'; |
| 185 |
} |
| 186 |
if ( in_array( 'b-blocks/services', $disabledBlocks ) && !in_array( 'b-blocks/service', $disabledBlocks ) ) { |
| 187 |
$disabledBlocks[] = 'b-blocks/service'; |
| 188 |
} |
| 189 |
$blocks = [ |
| 190 |
'alert', |
| 191 |
'advanced-image', |
| 192 |
'animated-text', |
| 193 |
'advanced-tabs', |
| 194 |
'button', |
| 195 |
'button-group', |
| 196 |
'breadcrumb', |
| 197 |
'cards', |
| 198 |
'chart', |
| 199 |
'column', |
| 200 |
'container', |
| 201 |
'content-ticker', |
| 202 |
'countdown', |
| 203 |
'counters', |
| 204 |
'data-table', |
| 205 |
'table-head', |
| 206 |
'table-body', |
| 207 |
'table-row', |
| 208 |
'table-cell', |
| 209 |
'table-footer', |
| 210 |
'carousel', |
| 211 |
'carousel-slide', |
| 212 |
'dual-color-heading', |
| 213 |
'emoji-stack-separator', |
| 214 |
'facebook-embed', |
| 215 |
'facebook-page', |
| 216 |
'feature-boxes', |
| 217 |
'flip-boxes', |
| 218 |
'gif', |
| 219 |
'form-builder', |
| 220 |
'html', |
| 221 |
'icon-box', |
| 222 |
'image-comparison', |
| 223 |
'image-gallery', |
| 224 |
'image-hotspot', |
| 225 |
'image-scroller', |
| 226 |
'info-box', |
| 227 |
'input-field', |
| 228 |
'logo-slider', |
| 229 |
'lottie-player', |
| 230 |
'list', |
| 231 |
'mailto', |
| 232 |
// 'mega-menu', |
| 233 |
// 'mega-menu-item', |
| 234 |
'navigation', |
| 235 |
'news-ticker', |
| 236 |
'posts', |
| 237 |
'price-lists', |
| 238 |
'pricing-table', |
| 239 |
'qr-code', |
| 240 |
'row', |
| 241 |
'section-heading', |
| 242 |
'skill-bar', |
| 243 |
'service', |
| 244 |
'services', |
| 245 |
'shape-divider', |
| 246 |
'slider', |
| 247 |
'scroll-to-top', |
| 248 |
'social-share', |
| 249 |
'whatsapp-chat', |
| 250 |
'star-rating', |
| 251 |
'stacked-cards', |
| 252 |
'svg-draw', |
| 253 |
'table-of-content', |
| 254 |
'td-viewer', |
| 255 |
'team-members', |
| 256 |
'testimonials', |
| 257 |
'toggle-content', |
| 258 |
'accordion-block', |
| 259 |
'video', |
| 260 |
'text-path', |
| 261 |
]; |
| 262 |
foreach ( $blocks as $block ) { |
| 263 |
if ( !in_array( "b-blocks/{$block}", $disabledBlocks ) && !in_array( "b-blocks/{$block}", $premiumBlocks ) ) { |
| 264 |
register_block_type( __DIR__ . "/build/{$block}" ); |
| 265 |
wp_deregister_script( "b-blocks-{$block}-editor-script" ); |
| 266 |
} |
| 267 |
} |
| 268 |
} |
| 269 |
|
| 270 |
function registerSettings() { |
| 271 |
register_setting( 'bBlocksUtils', 'bBlocksUtils', [ |
| 272 |
'show_in_rest' => [ |
| 273 |
'name' => 'bBlocksUtils', |
| 274 |
'schema' => [ |
| 275 |
'type' => 'string', |
| 276 |
], |
| 277 |
], |
| 278 |
'type' => 'string', |
| 279 |
'default' => wp_json_encode( [ |
| 280 |
'nonce' => wp_create_nonce( 'wp_ajax' ), |
| 281 |
] ), |
| 282 |
'sanitize_callback' => 'sanitize_text_field', |
| 283 |
] ); |
| 284 |
} |
| 285 |
|
| 286 |
function registerCategories( $categories ) { |
| 287 |
return array_merge( [[ |
| 288 |
'slug' => 'bBlocks', |
| 289 |
'title' => __( 'bBlocks', 'b-blocks' ), |
| 290 |
]], $categories ); |
| 291 |
} |
| 292 |
|
| 293 |
// Register categories |
| 294 |
//Allow some additional file types for upload |
| 295 |
function uploadMimes( $mimes ) { |
| 296 |
$mimes['glb'] = 'model/gltf-binary'; |
| 297 |
// 3D Viewer |
| 298 |
$mimes['gltf'] = 'model/gltf-binary'; |
| 299 |
// 3D Viewer |
| 300 |
$mimes['json'] = 'application/json'; |
| 301 |
// Lottie Player |
| 302 |
$mimes['lottie'] = 'application/json'; |
| 303 |
// Lottie Player |
| 304 |
if ( get_transient( 'b-blocks-enable-svg-mime-type' ) === 'true' ) { |
| 305 |
$mimes['svg'] = 'image/svg+xml'; |
| 306 |
} |
| 307 |
return $mimes; |
| 308 |
} |
| 309 |
|
| 310 |
function wpCheckFiletypeAndExt( |
| 311 |
$data, |
| 312 |
$file, |
| 313 |
$filename, |
| 314 |
$mimes, |
| 315 |
$real_mime = null |
| 316 |
) { |
| 317 |
// If file extension is 2 or more |
| 318 |
$f_sp = explode( '.', $filename ); |
| 319 |
$f_exp_count = count( $f_sp ); |
| 320 |
if ( $f_exp_count <= 1 ) { |
| 321 |
return $data; |
| 322 |
} else { |
| 323 |
$f_name = $f_sp[0]; |
| 324 |
$ext = $f_sp[$f_exp_count - 1]; |
| 325 |
} |
| 326 |
if ( $ext == 'glb' || $ext == 'gltf' ) { |
| 327 |
// 3D Viewer |
| 328 |
$type = 'model/gltf-binary'; |
| 329 |
$proper_filename = ''; |
| 330 |
return compact( 'ext', 'type', 'proper_filename' ); |
| 331 |
} else { |
| 332 |
if ( $ext == 'json' || $ext === 'lottie' ) { |
| 333 |
// Lottie Player |
| 334 |
$type = 'application/json'; |
| 335 |
$proper_filename = ''; |
| 336 |
return compact( 'ext', 'type', 'proper_filename' ); |
| 337 |
} else { |
| 338 |
return $data; |
| 339 |
} |
| 340 |
} |
| 341 |
} |
| 342 |
|
| 343 |
public function enableSvgMimeType() { |
| 344 |
if ( !wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ?? null ) ), 'wp_ajax' ) ) { |
| 345 |
wp_send_json_error(); |
| 346 |
} |
| 347 |
set_transient( 'b-blocks-enable-svg-mime-type', 'true', 80 ); |
| 348 |
wp_send_json_success(); |
| 349 |
} |
| 350 |
|
| 351 |
} |
| 352 |
|
| 353 |
BBlocks::instance(); |
| 354 |
} |