| 1 |
<?php |
| 2 |
|
| 3 |
//Exit if directly acess |
| 4 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 5 |
|
| 6 |
if(!class_exists('BlockspareInit')){ |
| 7 |
class BlockspareInit{ |
| 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 |
{ |
| 22 |
self::$instance = new self(); |
| 23 |
} |
| 24 |
return self::$instance; |
| 25 |
} |
| 26 |
public function __construct() |
| 27 |
{ |
| 28 |
add_action('init', array($this, 'blockspare_blocks_block_assets' )); |
| 29 |
add_action('enqueue_block_editor_assets', array($this,'blockspare_create_block')); |
| 30 |
add_action('wp_enqueue_scripts', array($this,'blockspare_load_scripts')); |
| 31 |
add_action('plugins_loaded', array($this,'blockspare_blocks_loader')); |
| 32 |
add_action( 'rest_api_init', array($this,'blockspare_blocks_register_api_endpoints' )); |
| 33 |
} |
| 34 |
|
| 35 |
function blockspare_blocks_block_assets(){ |
| 36 |
wp_enqueue_style( |
| 37 |
'blockspare-blocks-fontawesome-front', |
| 38 |
plugins_url('src/assets/fontawesome/css/all.css', dirname(__FILE__)), |
| 39 |
array(), |
| 40 |
filemtime(plugin_dir_path(__FILE__) . 'assets/fontawesome/css/all.css') |
| 41 |
); |
| 42 |
// Load the compiled styles. |
| 43 |
wp_enqueue_style( |
| 44 |
'blockspare-frontend-block-style-css', |
| 45 |
plugins_url('dist/style-blocks.css', dirname(__FILE__)), |
| 46 |
array() |
| 47 |
); |
| 48 |
|
| 49 |
|
| 50 |
wp_enqueue_style('slick-css', BLOCKSPARE_PLUGIN_URL . 'src/assets/slick/css/slick.css', array(), '', 'all'); |
| 51 |
} |
| 52 |
|
| 53 |
function blockspare_load_scripts(){ |
| 54 |
$min = (SCRIPT_DEBUG == true) ? '' : '.min'; |
| 55 |
wp_enqueue_script('slick-js', BLOCKSPARE_PLUGIN_URL . 'src/assets/slick/js/slick.js', array('jquery'), '', true); |
| 56 |
wp_register_script('countup', BLOCKSPARE_PLUGIN_URL . 'src/assets/js/countup/jquery.counterup' . $min . '.js', array('waypoint'), true); |
| 57 |
wp_enqueue_script('waypoint', BLOCKSPARE_PLUGIN_URL . 'src/assets/js/countup/waypoints.min.js', array('jquery'), '', true); |
| 58 |
wp_enqueue_script('jquery-masonry'); |
| 59 |
wp_enqueue_script('blockspare-script', BLOCKSPARE_PLUGIN_URL . 'src/assets/js/frontend.js', array('jquery', 'waypoint', 'countup'), '', true); |
| 60 |
wp_enqueue_script('blockspare-tabs', BLOCKSPARE_PLUGIN_URL . 'src/assets/js/tabs.js', array('jquery'), '', true); |
| 61 |
} |
| 62 |
|
| 63 |
function blockspare_create_block(){ |
| 64 |
|
| 65 |
$script_dep_path = BLOCKSPARE_BASE_DIR . 'dist/blocks.asset.php'; |
| 66 |
$script_info = file_exists($script_dep_path) ? include $script_dep_path : array( |
| 67 |
'dependencies' => array() , |
| 68 |
'version' => BLOCKSPARE_VERSION, |
| 69 |
); |
| 70 |
if (version_compare(get_bloginfo('version') , '5.8', '<')) |
| 71 |
{ |
| 72 |
$script_dep = array_merge($script_info['dependencies'],array( |
| 73 |
'wp-blocks', |
| 74 |
'wp-i18n', |
| 75 |
'wp-element', |
| 76 |
'wp-components', |
| 77 |
'wp-editor', |
| 78 |
'wp-api-fetch' |
| 79 |
)); |
| 80 |
} |
| 81 |
else |
| 82 |
{ |
| 83 |
$script_dep = $script_info['dependencies']; |
| 84 |
} |
| 85 |
|
| 86 |
wp_enqueue_script('blockspare-blocks-block-js', // Handle. |
| 87 |
BLOCKSPARE_PLUGIN_URL . 'dist/blocks.js', $script_dep, // Dependencies, defined above. |
| 88 |
$script_info['version'], // AFT_PRICING_TABLE_VERSION. |
| 89 |
true |
| 90 |
// Enqueue the script in the footer. |
| 91 |
); |
| 92 |
|
| 93 |
if (is_admin()) : |
| 94 |
wp_enqueue_style( |
| 95 |
'blockspare-block-edit-style', |
| 96 |
BLOCKSPARE_PLUGIN_URL . 'dist/blocks.css', |
| 97 |
array('wp-edit-blocks') |
| 98 |
); |
| 99 |
endif; |
| 100 |
|
| 101 |
|
| 102 |
$blockspare_priview_img_url = BLOCKSPARE_PLUGIN_URL . 'src/assets/blockspare-placeholder-img.jpg'; |
| 103 |
$blockspare_food_img_url = BLOCKSPARE_PLUGIN_URL . 'src/assets/blockspare-placeholder-img-square.jpg'; |
| 104 |
|
| 105 |
$taxonomies = get_categories(); |
| 106 |
$txnm = array(); |
| 107 |
|
| 108 |
foreach( $taxonomies as $type ) { |
| 109 |
|
| 110 |
|
| 111 |
$txnm[] = array( |
| 112 |
'label' => $type->name, |
| 113 |
'value' => $type->term_id, |
| 114 |
); |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
wp_localize_script( |
| 119 |
'blockspare-blocks-block-js', |
| 120 |
'blockspare_globals', |
| 121 |
array( |
| 122 |
'srcUrl' => untrailingslashit(plugins_url('/', BLOCKSPARE_BASE_DIR . '/dist/')), |
| 123 |
'rest_url' => esc_url(rest_url()), |
| 124 |
'img' => $blockspare_priview_img_url, |
| 125 |
'menu_img_url' => $blockspare_food_img_url, |
| 126 |
'postTypes' => $this->aft_get_post_types(), |
| 127 |
'taxonomies' => $this->aft_get_taxonomies(), |
| 128 |
'postQueryEndpoint'=>'aft/v1/post-query', |
| 129 |
'config' => '', |
| 130 |
'configuration' => '', |
| 131 |
'settings' => '', |
| 132 |
) |
| 133 |
); |
| 134 |
} |
| 135 |
|
| 136 |
function aft_get_post_types(){ |
| 137 |
$args = array( |
| 138 |
'public' => true, |
| 139 |
'show_in_rest' => true, |
| 140 |
); |
| 141 |
$post_types = get_post_types( $args, 'objects' ); |
| 142 |
$output = array(); |
| 143 |
foreach ( $post_types as $post_type ) { |
| 144 |
|
| 145 |
if ( 'attachment' == $post_type->name ) { |
| 146 |
continue; |
| 147 |
} |
| 148 |
$output[] = array( |
| 149 |
'value' => $post_type->name, |
| 150 |
'label' => $post_type->label, |
| 151 |
); |
| 152 |
} |
| 153 |
|
| 154 |
return apply_filters( 'aft_blocks_post_types', $output ); |
| 155 |
} |
| 156 |
|
| 157 |
function aft_get_taxonomies() { |
| 158 |
$post_types = $this->aft_get_post_types(); |
| 159 |
$output = array(); |
| 160 |
foreach ( $post_types as $key => $post_type ) { |
| 161 |
$taxonomies = get_object_taxonomies( $post_type['value'], 'objects' ); |
| 162 |
$taxs = array(); |
| 163 |
foreach ( $taxonomies as $term_slug => $term ) { |
| 164 |
if ( ! $term->public || ! $term->show_ui ) { |
| 165 |
continue; |
| 166 |
} |
| 167 |
$taxs[ $term_slug ] = $term; |
| 168 |
$terms = get_terms( $term_slug ); |
| 169 |
$term_items = array(); |
| 170 |
if ( ! empty( $terms ) ) { |
| 171 |
foreach ( $terms as $term_key => $term_item ) { |
| 172 |
$term_items[] = array( |
| 173 |
'value' => $term_item->term_id, |
| 174 |
'label' => $term_item->name, |
| 175 |
); |
| 176 |
} |
| 177 |
$output[ $post_type['value'] ]['terms'][ $term_slug ] = $term_items; |
| 178 |
} |
| 179 |
} |
| 180 |
$output[ $post_type['value'] ]['taxonomy'] = $taxs; |
| 181 |
} |
| 182 |
|
| 183 |
return apply_filters( 'aft_blocks_taxonomies', $output ); |
| 184 |
} |
| 185 |
|
| 186 |
function blockspare_blocks_loader(){ |
| 187 |
|
| 188 |
//Load Gutenberg Block php Files |
| 189 |
include(BLOCKSPARE_PLUGIN_DIR . '/src/blocks/social-sharing/index.php'); |
| 190 |
include(BLOCKSPARE_PLUGIN_DIR . '/src/blocks/latest-posts-grid/index.php'); |
| 191 |
include(BLOCKSPARE_PLUGIN_DIR . '/src/blocks/latest-posts-list/index.php'); |
| 192 |
|
| 193 |
include(BLOCKSPARE_PLUGIN_DIR . '/src/blocks/latest-posts-express-grid/index.php'); |
| 194 |
|
| 195 |
|
| 196 |
include(BLOCKSPARE_PLUGIN_DIR . '/src/blocks/latest-posts-carousel-grid/index.php'); |
| 197 |
include(BLOCKSPARE_PLUGIN_DIR . '/src/blocks/latest-posts-slider/index.php'); |
| 198 |
|
| 199 |
include(BLOCKSPARE_PLUGIN_DIR . '/src/blocks/banner-1/index.php'); |
| 200 |
include(BLOCKSPARE_PLUGIN_DIR . '/src/blocks/banner-2/index.php'); |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
include(BLOCKSPARE_PLUGIN_DIR . 'src/inc/block-posts-config/class-post-rest-api.php'); |
| 207 |
include(BLOCKSPARE_PLUGIN_DIR . 'src/inc/block-posts-config/tax-category.php'); |
| 208 |
include(BLOCKSPARE_PLUGIN_DIR . 'src/inc/block-posts-config/class-bs-post.php'); |
| 209 |
include(BLOCKSPARE_PLUGIN_DIR . 'src/blocks/utils/post-banner/frontend-render/post-banner-config.php'); |
| 210 |
include(BLOCKSPARE_PLUGIN_DIR . 'src/blocks/utils/post-banner/frontend-render/post-banner-style.php'); |
| 211 |
} |
| 212 |
|
| 213 |
function blockspare_blocks_register_api_endpoints(){ |
| 214 |
|
| 215 |
$posts_controller = new Aft_Post_Rest_Controller(); |
| 216 |
$posts_controller->register_routes(); |
| 217 |
|
| 218 |
|
| 219 |
} |
| 220 |
|
| 221 |
} |
| 222 |
BlockspareInit::get_instance(); |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
|