@@ -17,7 +17,7 @@ class WpakAddon {
17
17
protected $ app_dynamic_data_callback = null ;
18
18
protected $ app_dynamic_data = null ;
19
19
20
- public function __construct ( $ name , $ slug = '' , $ platforms = ['ios ' ,'android ' ] ) {
20
+ public function __construct ( $ name , $ slug = '' , $ platforms = ['ios ' ,'android ' , ' android-cordova ' , ' android-voltbuilder ' ] ) {
21
21
$ this ->name = $ name ;
22
22
$ this ->slug = sanitize_title_with_dashes ( remove_accents ( empty ($ slug ) ? $ name : $ slug ) );
23
23
$ this ->platforms = is_array ( $ platforms ) ? $ platforms : [];
@@ -36,18 +36,18 @@ public function set_location( $addon_file ) {
36
36
}
37
37
38
38
public function add_js ( $ js_file , $ type = 'module ' , $ position = '' , $ platforms = [] ) {
39
-
39
+
40
40
$ file_type = pathinfo ( $ js_file , PATHINFO_EXTENSION );
41
41
if ( $ file_type !== 'js ' ){
42
42
return ;
43
43
}
44
-
44
+
45
45
$ full_js_file = '' ;
46
-
46
+
47
47
if ( $ type == 'theme ' && $ position === '' ){
48
48
$ position = 'after ' ;
49
49
}
50
-
50
+
51
51
if ( $ type == 'init ' ){
52
52
$ position = 'before ' ; //for now, only init+before is handled
53
53
}
@@ -62,11 +62,11 @@ public function add_js( $js_file, $type = 'module', $position = '', $platforms =
62
62
63
63
if ( file_exists ( $ full_js_file ) ) {
64
64
if ( !in_array ( $ js_file , $ this ->js_files ) ) {
65
- $ this ->js_files [] = array (
66
- 'file ' => $ js_file ,
67
- 'type ' => $ type ,
65
+ $ this ->js_files [] = array (
66
+ 'file ' => $ js_file ,
67
+ 'type ' => $ type ,
68
68
'position ' => $ position ,
69
- 'platforms ' => !empty ( $ platforms ) && is_array ( $ platforms ) ? $ platforms : [ ' android ' , ' ios ' , ' pwa ' ]
69
+ 'platforms ' => !empty ( $ platforms ) && is_array ( $ platforms ) ? $ platforms : $ this -> platforms
70
70
);
71
71
}
72
72
}
@@ -78,7 +78,7 @@ public function add_css( $css_file, $position = 'after', $platforms = [] ) {
78
78
if ( $ file_type !== 'css ' ){
79
79
return ;
80
80
}
81
-
81
+
82
82
$ full_css_file = '' ;
83
83
84
84
if ( strpos ( $ css_file , $ this ->directory ) !== false ) {
@@ -91,23 +91,23 @@ public function add_css( $css_file, $position = 'after', $platforms = [] ) {
91
91
92
92
if ( file_exists ( $ full_css_file ) ) {
93
93
if ( !in_array ( $ css_file , $ this ->css_files ) ) {
94
- $ this ->css_files [] = array (
95
- 'file ' => $ css_file ,
94
+ $ this ->css_files [] = array (
95
+ 'file ' => $ css_file ,
96
96
'type ' => 'theme ' ,
97
97
'position ' => $ position ,
98
- 'platforms ' => !empty ( $ platforms ) && is_array ( $ platforms ) ? $ platforms : [ ' android ' , ' ios ' , ' pwa ' ]
98
+ 'platforms ' => !empty ( $ platforms ) && is_array ( $ platforms ) ? $ platforms : $ this -> platforms
99
99
);
100
100
}
101
101
}
102
102
}
103
-
103
+
104
104
public function add_html ( $ html_file , $ type = 'layout ' , $ position = 'after ' , $ data = array (), $ platforms = [] ) {
105
105
106
106
$ file_type = pathinfo ( $ html_file , PATHINFO_EXTENSION );
107
107
if ( $ file_type !== 'html ' ){
108
108
return ;
109
109
}
110
-
110
+
111
111
$ full_html_file = '' ;
112
112
113
113
if ( strpos ( $ html_file , $ this ->directory ) !== false ) {
@@ -120,24 +120,24 @@ public function add_html( $html_file, $type = 'layout', $position = 'after', $da
120
120
121
121
if ( file_exists ( $ full_html_file ) ) {
122
122
if ( !in_array ( $ html_file , $ this ->html_files ) ) {
123
- $ this ->html_files [] = array (
124
- 'file ' => $ html_file ,
123
+ $ this ->html_files [] = array (
124
+ 'file ' => $ html_file ,
125
125
'type ' => $ type ,
126
126
'position ' => $ position ,
127
127
'data ' => $ data ,
128
- 'platforms ' => !empty ( $ platforms ) && is_array ( $ platforms ) ? $ platforms : [ ' android ' , ' ios ' , ' pwa ' ]
128
+ 'platforms ' => !empty ( $ platforms ) && is_array ( $ platforms ) ? $ platforms : $ this -> platforms
129
129
);
130
130
}
131
131
}
132
132
}
133
-
133
+
134
134
public function add_template ( $ template_file , $ platforms = [] ) {
135
135
136
136
$ file_type = pathinfo ( $ template_file , PATHINFO_EXTENSION );
137
137
if ( $ file_type !== 'html ' ){
138
138
return ;
139
139
}
140
-
140
+
141
141
$ full_template_file = '' ;
142
142
143
143
if ( strpos ( $ template_file , $ this ->directory ) !== false ) {
@@ -150,14 +150,14 @@ public function add_template( $template_file, $platforms = [] ) {
150
150
151
151
if ( file_exists ( $ full_template_file ) ) {
152
152
if ( !in_array ( $ template_file , $ this ->template_files ) ) {
153
- $ this ->template_files [] = array (
153
+ $ this ->template_files [] = array (
154
154
'file ' => $ template_file ,
155
- 'platforms ' => !empty ( $ platforms ) && is_array ( $ platforms ) ? $ platforms : [ ' android ' , ' ios ' , ' pwa ' ]
155
+ 'platforms ' => !empty ( $ platforms ) && is_array ( $ platforms ) ? $ platforms : $ this -> platforms
156
156
);
157
157
}
158
158
}
159
159
}
160
-
160
+
161
161
/**
162
162
* PHP files that are included only if the addon is activated
163
163
* for a given app.
@@ -167,7 +167,7 @@ public function require_php( $php_file, $platforms = [] ) {
167
167
if ( $ file_type !== 'php ' ){
168
168
return ;
169
169
}
170
-
170
+
171
171
$ full_php_file = '' ;
172
172
173
173
if ( strpos ( $ php_file , $ this ->directory ) !== false ) {
@@ -177,17 +177,17 @@ public function require_php( $php_file, $platforms = [] ) {
177
177
$ php_file = ltrim ( $ php_file , '/ \\' );
178
178
$ full_php_file = $ this ->directory . '/ ' . $ php_file ;
179
179
}
180
-
180
+
181
181
if ( file_exists ( $ full_php_file ) ) {
182
182
if ( !in_array ( $ php_file , $ this ->php_files ) ) {
183
- $ this ->php_files [] = array (
183
+ $ this ->php_files [] = array (
184
184
'file ' => $ php_file ,
185
- 'platforms ' => !empty ( $ platforms ) && is_array ( $ platforms ) ? $ platforms : [ ' android ' , ' ios ' , ' pwa ' ]
185
+ 'platforms ' => !empty ( $ platforms ) && is_array ( $ platforms ) ? $ platforms : $ this -> platforms
186
186
);
187
187
}
188
188
}
189
189
}
190
-
190
+
191
191
public function require_php_files ( $ app_id ) {
192
192
$ app_platform = WpakApps::get_app_info ( $ app_id , 'platform ' );
193
193
foreach ( $ this ->php_files as $ php_file ) {
@@ -202,14 +202,14 @@ public function require_php_files( $app_id ) {
202
202
}
203
203
204
204
/**
205
- * Set the addon callback that will retrieve additionnal addon static data
205
+ * Set the addon callback that will retrieve additionnal addon static data
206
206
* (added to config.js) specific to a given app.
207
207
* @param type $callback Should be a function that takes $app_id as argument and returns an associative array
208
208
*/
209
209
public function add_app_static_data ( $ callback ){
210
210
$ this ->app_static_data_callback = $ callback ;
211
211
}
212
-
212
+
213
213
public function set_app_static_data ( $ app_id ){
214
214
if ( $ this ->app_static_data_callback !== null && is_callable ($ this ->app_static_data_callback ) ){
215
215
$ app_data = call_user_func ( $ this ->app_static_data_callback , $ app_id );
@@ -218,16 +218,16 @@ public function set_app_static_data( $app_id ){
218
218
}
219
219
}
220
220
}
221
-
221
+
222
222
/**
223
- * Set the addon callback that will retrieve additionnal addon dynamic data
223
+ * Set the addon callback that will retrieve additionnal addon dynamic data
224
224
* (added to the synchronization web service) specific to a given app.
225
225
* @param type $callback Should be a function that takes $app_id as argument and returns an associative array
226
226
*/
227
227
public function add_app_dynamic_data ( $ callback ){
228
228
$ this ->app_dynamic_data_callback = $ callback ;
229
229
}
230
-
230
+
231
231
public function set_app_dynamic_data ( $ app_id ){
232
232
if ( $ this ->app_dynamic_data_callback !== null && is_callable ($ this ->app_dynamic_data_callback ) ){
233
233
$ app_data = call_user_func ( $ this ->app_dynamic_data_callback , $ app_id );
@@ -240,7 +240,7 @@ public function set_app_dynamic_data( $app_id ){
240
240
public function get_asset_file ( $ file_relative_to_addon ) {
241
241
242
242
$ found = false ;
243
-
243
+
244
244
$ file_type = pathinfo ( $ file_relative_to_addon , PATHINFO_EXTENSION );
245
245
if ( isset ( $ this ->{$ file_type . '_files ' } ) ) {
246
246
foreach ( $ this ->{$ file_type . '_files ' } as $ file ) {
@@ -260,7 +260,7 @@ public function get_asset_file( $file_relative_to_addon ) {
260
260
}
261
261
}
262
262
}
263
-
263
+
264
264
$ file_full_path = $ this ->directory . '/ ' . $ file_relative_to_addon ;
265
265
266
266
return $ found && file_exists ( $ file_full_path ) ? $ file_full_path : false ;
@@ -299,7 +299,7 @@ protected function filter_files_by_platform( $files, $app_id ) {
299
299
300
300
return $ filtered_files ;
301
301
}
302
-
302
+
303
303
public function get_all_files ( $ app_id , $ indexed_by_type = false ) {
304
304
$ all_files = array ();
305
305
0 commit comments