1
|
|
|
<?php |
2
|
|
|
namespace Flynt; |
3
|
|
|
|
4
|
|
|
use Flynt\Defaults; |
5
|
|
|
use Flynt\BuildConstructionPlan; |
6
|
|
|
use Flynt\Render; |
7
|
|
|
use Flynt\ComponentManager; |
8
|
|
|
|
9
|
|
|
function initDefaults() |
10
|
|
|
{ |
11
|
|
|
Defaults::init(); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
function registerComponent($componentName, $componentPath = null) |
15
|
|
|
{ |
16
|
|
|
$componentManager = ComponentManager::getInstance(); |
17
|
|
|
$componentManager->registerComponent($componentName, $componentPath); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
function registerComponentsFromPath($componentBasePath) |
21
|
|
|
{ |
22
|
|
|
foreach (glob("{$componentBasePath}/*", GLOB_ONLYDIR) as $componentPath) { |
23
|
|
|
$componentName = basename($componentPath); |
24
|
|
|
registerComponent($componentName, $componentPath); |
25
|
|
|
} |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
function renderComponent($componentName, $data) |
29
|
|
|
{ |
30
|
|
|
// var_dump($componentName, $data);die(); |
31
|
|
|
$data = apply_filters( |
32
|
|
|
'Flynt/addComponentData', |
33
|
|
|
$data, |
34
|
|
|
$componentName |
35
|
|
|
); |
36
|
|
|
$output = apply_filters( |
37
|
|
|
'Flynt/renderComponent', |
38
|
|
|
null, |
39
|
|
|
$componentName, |
40
|
|
|
$data |
41
|
|
|
); |
42
|
|
|
|
43
|
|
|
return is_null($output) ? '' : $output; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
add_filter('Flynt/renderComponent', function ($output, $componentName, $data) { |
47
|
|
|
return apply_filters( |
48
|
|
|
"Flynt/renderComponent?name={$componentName}", |
49
|
|
|
$output, |
50
|
|
|
$componentName, |
51
|
|
|
$data |
52
|
|
|
); |
53
|
|
|
}, 10, 3); |
54
|
|
|
|
55
|
|
|
add_filter('Flynt/addComponentData', function ($data, $componentName) { |
56
|
|
|
return apply_filters( |
57
|
|
|
"Flynt/addComponentData?name={$componentName}", |
58
|
|
|
$data, |
59
|
|
|
$componentName |
60
|
|
|
); |
61
|
|
|
}, 10, 2); |
62
|
|
|
|
63
|
|
|
function registerFields($scope, $fields, $type = null) |
64
|
|
|
{ |
65
|
|
|
if (empty($type)) { |
66
|
|
|
global $flyntCurrentFieldType; |
67
|
|
|
$type = $flyntCurrentFieldType ?? 'Components'; |
68
|
|
|
} |
69
|
|
|
foreach ($fields as $key => $fieldData) { |
70
|
|
|
$key = ucfirst($key); |
71
|
|
|
add_filter("Flynt/{$type}/{$scope}/Fields/{$key}", function () use ($fieldData) { |
72
|
|
|
return $fieldData; |
73
|
|
|
}); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|