@@ -70,6 +70,13 @@ class snippets {
70
70
'gif ' ,
71
71
];
72
72
73
+ /**
74
+ * Constant for identifying builtin snippets.
75
+ *
76
+ * @var string
77
+ */
78
+ const SOURCE_BUILTIN = 'theme_boost_union ' ;
79
+
73
80
/**
74
81
* Gets the snippet file based on the meta information.
75
82
*
@@ -83,7 +90,7 @@ public static function get_snippet_file($path, $source): string|null {
83
90
84
91
// Get the snippet file based on the different sources.
85
92
// Builtin CSS Snippets.
86
- if ($ source === ' theme_boost_union ' ) {
93
+ if ($ source === self :: SOURCE_BUILTIN ) {
87
94
// Compose the file path.
88
95
$ file = $ CFG ->dirroot . self ::BUILTIN_SNIPPETS_BASE_PATH . $ path ;
89
96
@@ -151,7 +158,7 @@ public static function get_snippet_preview_url($path, $source): string|null {
151
158
152
159
// Get the snippet file based on the different sources.
153
160
// Builtin CSS Snippets.
154
- if ($ source === ' theme_boost_union ' ) {
161
+ if ($ source === self :: SOURCE_BUILTIN ) {
155
162
$ url = self ::get_builtin_snippet_preview_url ($ path , $ source );
156
163
// Other snippet sources (which are currently not supported).
157
164
} else {
@@ -264,14 +271,24 @@ public static function compose_snippets_data($snippetrecordset): array {
264
271
public static function get_enabled_snippet_scss (): string {
265
272
global $ DB ;
266
273
274
+ // Prepare WHERE clause based on the enabled sources.
275
+ $ whereparts = self ::get_enabled_sources ();
276
+ if (count ($ whereparts ) == 0 ) {
277
+ // If no sources are enabled, we do not want to use any snippets.
278
+ // We do this by restricting the query to an impossible source.
279
+ $ whereparts [] = 'impossible ' ;
280
+ }
281
+ list ($ insql , $ inparams ) = $ DB ->get_in_or_equal ($ whereparts , SQL_PARAMS_NAMED );
282
+
267
283
// Compose SQL base query.
268
284
$ sql = "SELECT *
269
285
FROM {theme_boost_union_snippets} s
270
- WHERE enabled = '1'
271
- ORDER BY sortorder " ;
286
+ WHERE enabled = '1' AND source " .$ insql .
287
+ " ORDER BY sortorder " ;
288
+ $ sqlparams = $ inparams ;
272
289
273
290
// Get records.
274
- $ data = $ DB ->get_recordset_sql ($ sql );
291
+ $ data = $ DB ->get_recordset_sql ($ sql, $ sqlparams );
275
292
276
293
// Initialize SCSS code.
277
294
$ scss = '' ;
@@ -368,6 +385,24 @@ private static function get_builtin_snippet_paths(): array {
368
385
}
369
386
}
370
387
388
+ /**
389
+ * Get the enabled snippet sources.
390
+ *
391
+ * @return array
392
+ */
393
+ public static function get_enabled_sources (): array {
394
+ // Initialize sources array.
395
+ $ sources = [];
396
+
397
+ // If builtin snippets are enabled.
398
+ if (get_config ('theme_boost_union ' , 'enablebuiltinsnippets ' ) == THEME_BOOST_UNION_SETTING_SELECT_YES ) {
399
+ $ sources [] = self ::SOURCE_BUILTIN ;
400
+ }
401
+
402
+ // Return.
403
+ return $ sources ;
404
+ }
405
+
371
406
/**
372
407
* Make sure that the builtin snippets are in the database.
373
408
*
@@ -382,7 +417,7 @@ public static function add_builtin_snippets(): void {
382
417
// Get builtin snippets which are known in the database.
383
418
$ snippets = $ DB ->get_records (
384
419
'theme_boost_union_snippets ' ,
385
- ['source ' => ' theme_boost_union ' ],
420
+ ['source ' => self :: SOURCE_BUILTIN ],
386
421
'sortorder DESC ' ,
387
422
'id,path,sortorder '
388
423
);
@@ -406,7 +441,7 @@ public static function add_builtin_snippets(): void {
406
441
'theme_boost_union_snippets ' ,
407
442
[
408
443
'path ' => $ path ,
409
- 'source ' => ' theme_boost_union ' ,
444
+ 'source ' => self :: SOURCE_BUILTIN ,
410
445
'sortorder ' => $ sortorder + 1 ,
411
446
]
412
447
);
0 commit comments