PluginProbe
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites / 3.1.4
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites v3.1.4
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 3.1.4, at inc/init.php

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