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