| 1 |
<?php |
| 2 |
//Exit if directly acess |
| 3 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 4 |
|
| 5 |
if (!class_exists('BlockspareInit')) { |
| 6 |
class BlockspareInit |
| 7 |
{ |
| 8 |
/** |
| 9 |
* Member Variable |
| 10 |
* |
| 11 |
* @var instance |
| 12 |
*/ |
| 13 |
private static $instance; |
| 14 |
|
| 15 |
/** |
| 16 |
* Initiator |
| 17 |
*/ |
| 18 |
public static function get_instance() |
| 19 |
{ |
| 20 |
if (!isset(self::$instance)) { |
| 21 |
self::$instance = new self(); |
| 22 |
} |
| 23 |
return self::$instance; |
| 24 |
} |
| 25 |
public function __construct() |
| 26 |
{ |
| 27 |
add_action('init', array($this, 'blockspare_blocks_block_assets')); |
| 28 |
add_action('enqueue_block_editor_assets', array($this, 'blockspare_create_block')); |
| 29 |
if (version_compare(get_bloginfo('version'), '5.8', '<')) { |
| 30 |
add_action('wp_enqueue_scripts', array($this, 'blockspare_load_scripts')); |
| 31 |
} else { |
| 32 |
add_action('enqueue_block_assets', array($this, 'blockspare_load_scripts'), 1); |
| 33 |
} |
| 34 |
add_action('plugins_loaded', array($this, 'blockspare_blocks_loader')); |
| 35 |
add_action('rest_api_init', array($this, 'blockspare_blocks_register_api_endpoints')); |
| 36 |
} |
| 37 |
|
| 38 |
public function blockspare_blocks_block_assets() |
| 39 |
{ |
| 40 |
// wp_register_style( |
| 41 |
// 'fontawesome', |
| 42 |
// plugins_url('assets/fontawesome/css/all.css', dirname(__FILE__)), |
| 43 |
// array() |
| 44 |
|
| 45 |
// ); |
| 46 |
// // Load the compiled styles. |
| 47 |
// wp_enqueue_style( |
| 48 |
// 'blockspare-frontend-block-style-css', |
| 49 |
// plugins_url('dist/style-blocks.css', dirname(__FILE__)), |
| 50 |
// array() |
| 51 |
// ); |
| 52 |
|
| 53 |
|
| 54 |
// wp_register_style('slick', BLOCKSPARE_PLUGIN_URL . 'assets/slick/css/slick.css', array(), '', 'all'); |
| 55 |
// if (is_admin()) { |
| 56 |
// wp_enqueue_style('slick'); |
| 57 |
// } |
| 58 |
|
| 59 |
register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/accordion'); |
| 60 |
register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/button'); |
| 61 |
register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/call-to-action'); |
| 62 |
register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/content-box'); |
| 63 |
register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/container'); |
| 64 |
register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/counter'); |
| 65 |
register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/icon-set'); |
| 66 |
register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/image-carousel'); |
| 67 |
register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/linear-progressbar'); |
| 68 |
register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/list'); |
| 69 |
register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/logos'); |
| 70 |
register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/image-masonry'); |
| 71 |
register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/notice-bar'); |
| 72 |
register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/price-list'); |
| 73 |
register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/pricing-table'); |
| 74 |
register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/social-links'); |
| 75 |
register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/section-header'); |
| 76 |
register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/services'); |
| 77 |
register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/image-slider'); |
| 78 |
register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/star-ratings'); |
| 79 |
register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/testimonial'); |
| 80 |
register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/user-profile'); |
| 81 |
register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/shape-divider'); |
| 82 |
register_block_type(BLOCKSPARE_PLUGIN_DIR . 'dist/blocks/empty-section'); |
| 83 |
|
| 84 |
include BLOCKSPARE_PLUGIN_DIR . '/admin/notice-setup.php'; |
| 85 |
include BLOCKSPARE_PLUGIN_DIR . '/admin/notice-upgrade.php'; |
| 86 |
} |
| 87 |
|
| 88 |
public function blockspare_load_scripts() |
| 89 |
{ |
| 90 |
|
| 91 |
wp_register_style( |
| 92 |
'fontawesome', |
| 93 |
plugins_url('assets/fontawesome/css/all.css', dirname(__FILE__)), |
| 94 |
array() |
| 95 |
|
| 96 |
); |
| 97 |
// Load the compiled styles. |
| 98 |
wp_enqueue_style( |
| 99 |
'blockspare-frontend-block-style-css', |
| 100 |
plugins_url('dist/style-blocks.css', dirname(__FILE__)), |
| 101 |
array() |
| 102 |
); |
| 103 |
|
| 104 |
wp_enqueue_style( |
| 105 |
'blockspare-frontend-banner-style-css', |
| 106 |
plugins_url('dist/style-banner_group.css', dirname(__FILE__)), |
| 107 |
array() |
| 108 |
); |
| 109 |
|
| 110 |
|
| 111 |
wp_register_style('slick', BLOCKSPARE_PLUGIN_URL . 'assets/slick/css/slick.css', array(), '', 'all'); |
| 112 |
if (is_admin()) { |
| 113 |
wp_enqueue_style('slick'); |
| 114 |
} |
| 115 |
|
| 116 |
wp_enqueue_style('fontawesome'); |
| 117 |
$min = (SCRIPT_DEBUG == true) ? '' : '.min'; |
| 118 |
wp_register_script('slick', BLOCKSPARE_PLUGIN_URL . 'assets/slick/js/slick.js', array('jquery'), '', true); |
| 119 |
if (has_blocks() || has_block('blockspare/blockspare-carousel') || has_block('blockspare/blockspare-slider') || has_block('blockspare/latest-posts-block-carousel-grid') || has_block('blockspare/blockspare-posts-block-slider')) { |
| 120 |
wp_enqueue_script('slick'); |
| 121 |
wp_enqueue_style('slick'); |
| 122 |
} |
| 123 |
|
| 124 |
wp_register_script('countup', BLOCKSPARE_PLUGIN_URL . 'assets/js/countup/jquery.counterup.min.js', array('waypoint'), true); |
| 125 |
wp_enqueue_script('waypoint', BLOCKSPARE_PLUGIN_URL . 'assets/js/countup/waypoints.min.js', array('jquery'), '', true); |
| 126 |
|
| 127 |
if (has_blocks() || has_block('blockspare/blockspare-masonry')) { |
| 128 |
wp_enqueue_script('jquery-masonry'); |
| 129 |
} |
| 130 |
wp_enqueue_script('blockspare-animation', BLOCKSPARE_PLUGIN_URL . 'dist/block_animation.js', array(), '', true); |
| 131 |
wp_enqueue_script('blockspare-script', BLOCKSPARE_PLUGIN_URL . 'dist/block_frontend.js', array('jquery', 'waypoint', 'countup'), '', true); |
| 132 |
if (has_blocks() || has_block('blockspare/blockspare-tabs')) { |
| 133 |
|
| 134 |
wp_enqueue_script('blockspare-tabs', BLOCKSPARE_PLUGIN_URL . 'dist/block_tabs.js', array('jquery'), '', true); |
| 135 |
} |
| 136 |
wp_register_script('blockspare-pagination-js', BLOCKSPARE_PLUGIN_URL . 'dist/block_pagination.js', array(), '', true); |
| 137 |
wp_localize_script('blockspare-pagination-js', 'blocsparePagination', array( |
| 138 |
'ajaxurl' => admin_url('admin-ajax.php'), |
| 139 |
'nonce' => wp_create_nonce('blockspare-load-more-nonce'), |
| 140 |
)); |
| 141 |
} |
| 142 |
|
| 143 |
public function blockspare_create_block() |
| 144 |
{ |
| 145 |
|
| 146 |
$script_dep_path = BLOCKSPARE_BASE_DIR . 'dist/blocks.asset.php'; |
| 147 |
$script_info = file_exists($script_dep_path) ? include $script_dep_path : array( |
| 148 |
'dependencies' => array(), |
| 149 |
'version' => BLOCKSPARE_VERSION, |
| 150 |
); |
| 151 |
if (version_compare(get_bloginfo('version'), '5.8', '<')) { |
| 152 |
$script_dep = array_merge($script_info['dependencies'], array( |
| 153 |
'wp-blocks', |
| 154 |
'wp-i18n', |
| 155 |
'wp-element', |
| 156 |
'wp-components', |
| 157 |
'wp-editor', |
| 158 |
'wp-api-fetch', |
| 159 |
)); |
| 160 |
} else { |
| 161 |
$script_dep = $script_info['dependencies']; |
| 162 |
} |
| 163 |
|
| 164 |
wp_enqueue_script( |
| 165 |
'blockspare-blocks-block-js', // Handle. |
| 166 |
BLOCKSPARE_PLUGIN_URL . 'dist/blocks.js', |
| 167 |
$script_dep, // Dependencies, defined above. |
| 168 |
$script_info['version'], // AFT_PRICING_TABLE_VERSION. |
| 169 |
true |
| 170 |
// Enqueue the script in the footer. |
| 171 |
); |
| 172 |
|
| 173 |
wp_enqueue_script( |
| 174 |
'blockspare-banner-group-js', // Handle. |
| 175 |
BLOCKSPARE_PLUGIN_URL . 'dist/banner_group.js', |
| 176 |
$script_dep, // Dependencies, defined above. |
| 177 |
$script_info['version'], // AFT_PRICING_TABLE_VERSION. |
| 178 |
true |
| 179 |
// Enqueue the script in the footer. |
| 180 |
); |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
if (is_admin()): |
| 185 |
wp_enqueue_style('fontawesome'); |
| 186 |
wp_enqueue_style( |
| 187 |
'blockspare-block-edit-style', |
| 188 |
BLOCKSPARE_PLUGIN_URL . 'dist/blocks.css', |
| 189 |
array('wp-edit-blocks') |
| 190 |
); |
| 191 |
wp_enqueue_style( |
| 192 |
'blockspare-banner-edit-style', |
| 193 |
BLOCKSPARE_PLUGIN_URL . 'dist/banner_group.css', |
| 194 |
array('wp-edit-blocks') |
| 195 |
); |
| 196 |
|
| 197 |
wp_enqueue_script('blockspare-design-btn', BLOCKSPARE_PLUGIN_URL . 'dist/block_design_btn.js', array('blockspare-blocks-block-js'), $script_info['version'], true); |
| 198 |
wp_enqueue_script('blockspare-design', BLOCKSPARE_PLUGIN_URL . 'dist/block_design.js', array('blockspare-blocks-block-js'), $script_info['version'], true); |
| 199 |
wp_enqueue_style('blockspare-design', BLOCKSPARE_PLUGIN_URL . 'dist/block_design.css', array('blockspare-block-edit-style')); |
| 200 |
endif; |
| 201 |
|
| 202 |
$blockspare_priview_img_url = BLOCKSPARE_PLUGIN_URL . 'assets/blockspare-placeholder-img.jpg'; |
| 203 |
$blockspare_food_img_url = BLOCKSPARE_PLUGIN_URL . 'assets/blockspare-placeholder-img-square.jpg'; |
| 204 |
$blockspare_dashboard_logo = BLOCKSPARE_PLUGIN_URL . 'assets/images/blockspare-logo.png'; |
| 205 |
$taxonomies = get_categories(); |
| 206 |
$txnm = array(); |
| 207 |
|
| 208 |
foreach ($taxonomies as $type) { |
| 209 |
|
| 210 |
$txnm[] = array( |
| 211 |
'label' => $type->name, |
| 212 |
'value' => $type->term_id, |
| 213 |
); |
| 214 |
} |
| 215 |
|
| 216 |
$date = wp_kses_post(date_i18n(get_option('date_format'))); |
| 217 |
$open_design = false; |
| 218 |
if (isset($_GET['blockspare_show_intro'])) { |
| 219 |
if ($_GET['blockspare_show_intro'] == 'true') { |
| 220 |
$open_design = true; |
| 221 |
} |
| 222 |
} |
| 223 |
$date_format = date_i18n(get_option('date_format'), current_time('timestamp')); |
| 224 |
|
| 225 |
$blockData = ''; |
| 226 |
if (isset($_GET['blockspare_create_block'])) { |
| 227 |
$blockName = $_GET['blockspare_create_block']; |
| 228 |
$blocks_lists = array(); |
| 229 |
|
| 230 |
$filterdata = apply_filters('blockspare_template_library', $blocks_lists); |
| 231 |
|
| 232 |
foreach ($filterdata as $block) { |
| 233 |
if (isset($block['key']) && $block['key'] === $blockName) { |
| 234 |
// Found the block with the desired key, retrieve the content |
| 235 |
$blockData = $block['content']; |
| 236 |
break; // Stop looping once the desired block is found |
| 237 |
} |
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
global $pagenow; |
| 242 |
$loadscripton = true; |
| 243 |
if ($pagenow !== 'widgets.php' && !is_customize_preview()) { |
| 244 |
$loadscripton = false; |
| 245 |
} |
| 246 |
//$blockspare_current_wp_version = '6.5'; |
| 247 |
$blockspare_current_wp_version = get_bloginfo('version'); |
| 248 |
|
| 249 |
wp_localize_script( |
| 250 |
'blockspare-blocks-block-js', |
| 251 |
'blockspare_globals', |
| 252 |
array( |
| 253 |
'srcUrl' => untrailingslashit(plugins_url('/', BLOCKSPARE_BASE_DIR . '/dist/')), |
| 254 |
'rest_url' => esc_url(rest_url()), |
| 255 |
'img' => $blockspare_priview_img_url, |
| 256 |
'homeUrl' => home_url(), |
| 257 |
'blogUrl' => get_site_url(), |
| 258 |
'menu_img_url' => $blockspare_food_img_url, |
| 259 |
'logo' => $blockspare_dashboard_logo, |
| 260 |
'postTypes' => $this->aft_get_post_types(), |
| 261 |
'taxonomies' => $this->aft_get_taxonomies(), |
| 262 |
'postQueryEndpoint' => 'aft/v1/post-query', |
| 263 |
'config' => '', |
| 264 |
'configuration' => '', |
| 265 |
'settings' => '', |
| 266 |
'bs_date' => $date, |
| 267 |
"imagePath" => "https://raw.githubusercontent.com/afthemes/blockspare-demo-data/master/blocks/", |
| 268 |
"open_design" => $open_design, |
| 269 |
'date_format ' => $date_format, |
| 270 |
'blockData' => $blockData, |
| 271 |
'template_link' => admin_url('edit.php?post_type=bs_templates'), |
| 272 |
'newTemlateUrl' => admin_url('post-new.php?post_type=bs_templates&blockspare_create_block&blockspare_show_intro=true'), |
| 273 |
'loadscripton' => $loadscripton, |
| 274 |
'wpversion' => (version_compare($blockspare_current_wp_version, '6.6') >= 0) ? 'true' : 'false', |
| 275 |
) |
| 276 |
); |
| 277 |
} |
| 278 |
|
| 279 |
public function aft_get_post_types() |
| 280 |
{ |
| 281 |
$args = array( |
| 282 |
'public' => true, |
| 283 |
'show_in_rest' => true, |
| 284 |
); |
| 285 |
$post_types = get_post_types($args, 'objects'); |
| 286 |
$output = array(); |
| 287 |
foreach ($post_types as $post_type) { |
| 288 |
|
| 289 |
if ('attachment' == $post_type->name) { |
| 290 |
continue; |
| 291 |
} |
| 292 |
$output[] = array( |
| 293 |
'value' => $post_type->name, |
| 294 |
'label' => $post_type->label, |
| 295 |
); |
| 296 |
} |
| 297 |
|
| 298 |
return apply_filters('aft_blocks_post_types', $output); |
| 299 |
} |
| 300 |
|
| 301 |
public function aft_get_taxonomies() |
| 302 |
{ |
| 303 |
$post_types = $this->aft_get_post_types(); |
| 304 |
$output = array(); |
| 305 |
foreach ($post_types as $key => $post_type) { |
| 306 |
$taxonomies = get_object_taxonomies($post_type['value'], 'objects'); |
| 307 |
$taxs = array(); |
| 308 |
foreach ($taxonomies as $term_slug => $term) { |
| 309 |
if (!$term->public || !$term->show_ui) { |
| 310 |
continue; |
| 311 |
} |
| 312 |
$taxs[$term_slug] = $term; |
| 313 |
$terms = get_terms($term_slug); |
| 314 |
$term_items = array(); |
| 315 |
if (!empty($terms)) { |
| 316 |
foreach ($terms as $term_key => $term_item) { |
| 317 |
$term_items[] = array( |
| 318 |
'value' => $term_item->term_id, |
| 319 |
'label' => $term_item->name, |
| 320 |
); |
| 321 |
} |
| 322 |
$output[$post_type['value']]['terms'][$term_slug] = $term_items; |
| 323 |
} |
| 324 |
} |
| 325 |
$output[$post_type['value']]['taxonomy'] = $taxs; |
| 326 |
} |
| 327 |
|
| 328 |
return apply_filters('aft_blocks_taxonomies', $output); |
| 329 |
} |
| 330 |
|
| 331 |
public function blockspare_blocks_loader() |
| 332 |
{ |
| 333 |
|
| 334 |
if (PHP_VERSION_ID >= 50600) { |
| 335 |
require_once BLOCKSPARE_PLUGIN_DIR . 'inc/layout/class-image-importer.php'; |
| 336 |
require_once BLOCKSPARE_PLUGIN_DIR . 'inc/layout/functions.php'; |
| 337 |
require_once BLOCKSPARE_PLUGIN_DIR . 'inc/layout/registry.php'; |
| 338 |
require_once BLOCKSPARE_PLUGIN_DIR . 'inc/layout/components.php'; |
| 339 |
|
| 340 |
/** |
| 341 |
* REST API Endpoints for Layouts. |
| 342 |
*/ |
| 343 |
require_once BLOCKSPARE_PLUGIN_DIR . 'inc/layout/endpoints.php'; |
| 344 |
require_once BLOCKSPARE_PLUGIN_DIR . 'inc/layout/save-templates.php'; |
| 345 |
|
| 346 |
/** |
| 347 |
* Import Pattern |
| 348 |
*/ |
| 349 |
|
| 350 |
// require_once BLOCKSPARE_PLUGIN_DIR . 'inc/pattern/pattern.php'; |
| 351 |
} |
| 352 |
|
| 353 |
//Load Gutenberg Block php Files |
| 354 |
include BLOCKSPARE_PLUGIN_DIR . 'inc/other-block/date-time/index.php'; |
| 355 |
include BLOCKSPARE_PLUGIN_DIR . '/inc/other-block/social-sharing/index.php'; |
| 356 |
include BLOCKSPARE_PLUGIN_DIR . '/inc/latest-post-block/posts-grid/index.php'; |
| 357 |
include BLOCKSPARE_PLUGIN_DIR . '/inc/latest-post-block/posts-list/index.php'; |
| 358 |
|
| 359 |
include BLOCKSPARE_PLUGIN_DIR . '/inc/latest-post-block/posts-express-grid/index.php'; |
| 360 |
include BLOCKSPARE_PLUGIN_DIR . '/inc/latest-post-block/posts-express-grid/post-content.php'; |
| 361 |
|
| 362 |
include BLOCKSPARE_PLUGIN_DIR . '/inc/latest-post-block/posts-carousel-grid/index.php'; |
| 363 |
include BLOCKSPARE_PLUGIN_DIR . '/inc/latest-post-block/posts-slider/index.php'; |
| 364 |
|
| 365 |
include BLOCKSPARE_PLUGIN_DIR . '/inc/post-banner/banner-1/index.php'; |
| 366 |
include BLOCKSPARE_PLUGIN_DIR . '/inc/post-banner/banner-2/index.php'; |
| 367 |
include BLOCKSPARE_PLUGIN_DIR . '/inc/post-banner/banner-9/index.php'; |
| 368 |
include BLOCKSPARE_PLUGIN_DIR . 'inc/block-posts-config/ajax-pagination.php'; |
| 369 |
include BLOCKSPARE_PLUGIN_DIR . 'inc/block-posts-config/class-post-rest-api.php'; |
| 370 |
include BLOCKSPARE_PLUGIN_DIR . 'inc/block-posts-config/class-multiauthor-backend.php'; |
| 371 |
include BLOCKSPARE_PLUGIN_DIR . 'inc/block-posts-config/class-multiauthor-frontend.php'; |
| 372 |
include BLOCKSPARE_PLUGIN_DIR . 'inc/block-posts-config/tax-category.php'; |
| 373 |
include BLOCKSPARE_PLUGIN_DIR . 'inc/block-posts-config/class-bs-post.php'; |
| 374 |
include BLOCKSPARE_PLUGIN_DIR . 'inc/block-banner/frontend-render/post-banner-config.php'; |
| 375 |
include BLOCKSPARE_PLUGIN_DIR . 'inc/block-banner/frontend-render/post-banner-style.php'; |
| 376 |
include BLOCKSPARE_PLUGIN_DIR . 'inc/other-block/search/index.php'; |
| 377 |
include BLOCKSPARE_PLUGIN_DIR . 'inc/latest-post-block/posts-flash/index.php'; |
| 378 |
include BLOCKSPARE_PLUGIN_DIR . 'inc/other-block/popular-tags/index.php'; |
| 379 |
include BLOCKSPARE_PLUGIN_DIR . 'inc/page-templates/module.php'; |
| 380 |
include BLOCKSPARE_PLUGIN_DIR . 'inc/block-banner/frontend-render/post-category-style.php'; |
| 381 |
} |
| 382 |
|
| 383 |
public function blockspare_blocks_register_api_endpoints() |
| 384 |
{ |
| 385 |
|
| 386 |
$posts_controller = new Aft_Post_Rest_Controller(); |
| 387 |
$posts_controller->register_routes(); |
| 388 |
} |
| 389 |
} |
| 390 |
BlockspareInit::get_instance(); |
| 391 |
} |
| 392 |
|