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

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