-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplugins.php
257 lines (204 loc) · 6.15 KB
/
plugins.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<?php
/**
* @package xapp
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
define('XAPP_BLOCKS', [
//Allow core wordPress blocks
'core/post-terms',
'core/block',
'core/cover',
'core/group',
'core/spacer',
//TODO: create dart widget
'core/query',
'core/post-template',
'core/post-date',
'core/post-title',
'core/query-no-results',
'core/post-content',
'core/post-featured-image',
'core/image',
'core/paragraph',
"woocommerce/product-query",
"woocommerce/product-query/product-template",
"woocommerce/product-price",
"woocommerce/product-button", //experimental
'woocommerce/product-collection',
//TODO: allow html
'core/heading',
'core/columns',
'core/column',
'core/avatar',
'xapp/screens',
'xapp/bottom-tabs',
'xapp/tabs',
'xapp/button',
'xapp/inkwell',
'xapp/appbar',
'xapp/divider',
'xapp/container',
'xapp/text-block',
'xapp/icon',
'xapp/intro-slider',
'xapp/icon-text-button',
'xapp/text-button',
'xapp/icon-button',
'xapp/rounded-button',
'xapp/full-width',
'xapp/logo',
'xapp/post-searchbar',
'xapp/tile',
'xapp/language-switcher',
'xapp/stack',
'xapp/badge',
'xapp/bottombar',
'xapp/unconstrained-box',
'xapp/list-view',
'xapp/grid-view',
'xapp/data-source',
'xapp/data-content',
'xapp/data-template',
'xapp/appbar-title',
'xapp/appbar-flexible',
'xapp/center',
'xapp/positioned',
'xapp/safe-area',
'xapp/card',
'xapp/carousel',
'xapp/button-add-to-cart',
'xapp/button-add-to-favourite'
]);
/**
* Admin
*/
require_once XAPP_IMPORT_PATH . 'admin/routes.php';
require_once XAPP_IMPORT_PATH . 'admin/xapp-register-post-type.php';
require_once XAPP_IMPORT_PATH . 'admin/xapp-routes.php';
require_once XAPP_IMPORT_PATH . 'admin/xapp-block-parser.php';
require_once XAPP_IMPORT_PATH . 'admin/xapp-blocks-controller.php';
require_once XAPP_IMPORT_PATH . 'admin/google-login/google-login.php';
require_once XAPP_IMPORT_PATH . 'admin/inc/AuthController.php';
/**
*
* Allow only follwoing blocks
*
*/
function xapp_get_image($name){
return XAPP_IMPORT_URL . 'admin/assets/images/' . $name;
}
global $pagenow, $typenow;
function xapp_isEditor() {
$post_type = isset($_GET['post']) ? sanitize_text_field($_GET['post']) : '';
$post_type_param = isset($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : '';
return (get_post_type($post_type) == XAPP_POST_TYPE) || ($post_type_param == XAPP_POST_TYPE);
}
function xapp_is_edit_page($new_edit = null)
{
global $pagenow;
//make sure we are on the backend
if (!is_admin())
return false;
if ($new_edit == "edit")
return in_array($pagenow, array('post.php',));
elseif ($new_edit == "new") //check for new post page
return in_array($pagenow, array('post-new.php'));
else //check for either new or edit
return in_array($pagenow, array('post.php', 'post-new.php'));
}
function xapp_enque_scripts()
{
global $pagenow, $typenow;
// Check if we are on the edit screen for the xapp post type
if (in_array($pagenow, array('post.php', 'post-new.php')) && $typenow == 'xapp') {
require_once XAPP_IMPORT_PATH . 'build/non-block-examples/dahsboard/index.php';
wp_enqueue_style('xapp-tailwind', XAPP_IMPORT_URL . 'build/index.css');
//Block variations
wp_enqueue_script(
'xapp-enqueue-block-variations',
XAPP_IMPORT_URL . 'admin/variations.js',
array('wp-blocks', 'wp-dom-ready', 'wp-edit-post')
);
}
// Check if we are on the xapp apps page
if ($pagenow == 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'xapp' && isset($_GET['page']) && $_GET['page'] == 'xapp-apps-page') {
wp_enqueue_style('xapp-tailwind', XAPP_IMPORT_URL . 'build/index.css');
}
}
add_action('admin_enqueue_scripts', 'xapp_enque_scripts');
/**
*
* Enqueue scripts
*/
add_action('init', function () {
register_block_type(__DIR__ . "/build/blocks/container");
});
/**
*
* Only load if xapp page
*/
if (xapp_isEditor()) {
//non-blocks -should be at top
require_once XAPP_IMPORT_PATH . 'build/non-block-examples/meta/index.php';
require_once XAPP_IMPORT_PATH . 'build/non-block-examples/dahsboard/index.php';
require_once XAPP_IMPORT_PATH . 'admin/xapp-editor-settings.php';
require_once XAPP_IMPORT_PATH . 'admin/theme-json.php';
function xapp_blocks_init()
{
$blocks = [
'screen',
'screens',
'appbar','bottombar', 'appbar-title','appbar-flexible',
'bottom-tabs',
'tabs',
'tab',
'button',
'inkwell',
'divider',
'text',
'icon',
'intro-slider',
'logo',
'post-searchbar',
'tile','language-switcher',
'stack',
'badge',
'unconstrained-box',
'icon-button',
'list-view',
'grid-view',
'data-source',
'data-content',
'data-template',
'center',
'positioned',
'safe-area',
'card',
'carousel',
'button-add-to-cart',
'button-add-to-favourite'
];
foreach ($blocks as $block) {
register_block_type(__DIR__ . "/build/blocks/{$block}");
}
}
add_action('init', 'xapp_blocks_init');
}
require_once XAPP_IMPORT_PATH . 'admin/patterns.php';
new xapp_Patterns();
/**
*
* Allow only follwoing blocks
*
*/
function xapp_allowed_block_types_when_post_provided($allowed_block_types, $editor_context)
{
global $blocks;
if (!empty($editor_context->post) && XAPP_POST_TYPE == get_post_type()) {
if (is_array($allowed_block_types))
return array_merge(XAPP_BLOCKS, $allowed_block_types);
return XAPP_BLOCKS;
}
return $allowed_block_types;
}
add_filter('allowed_block_types_all', 'xapp_allowed_block_types_when_post_provided', 1000, 2);