PluginProbe
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites / 2.1.2
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites v2.1.2
4.1.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.1.2 2.5.0 2.5.3 2.6.1 All 38 releases
blockspare / inc / init.php

init.php in BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites 2.1.2, at inc/init.php

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