AmeliaBookingButtonRendererTrait.php
2 months ago
AmeliaBookingModule.php
7 months ago
AmeliaCatalogBookingModule.php
1 month ago
AmeliaCatalogModule.php
7 months ago
AmeliaCustomerPanelModule.php
7 months ago
AmeliaEmployeePanelModule.php
7 months ago
AmeliaEventsCalendarModule.php
1 month ago
AmeliaEventsListBookingButtonModule.php
2 months ago
AmeliaEventsListModule.php
1 month ago
AmeliaEventsModule.php
7 months ago
AmeliaSearchModule.php
7 months ago
AmeliaStepBookingButtonModule.php
2 months ago
AmeliaStepBookingModule.php
1 month ago
ModuleMetadata.php
1 month ago
SharedShortcodeModule.php
1 month ago
index.php
1 month ago
index.php
234 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Divi 5 Amelia Modules Bootstrap |
| 5 | * |
| 6 | * This file loads and registers all Divi 5 Amelia modules. |
| 7 | * phpcs:disable PSR1.Files.SideEffects |
| 8 | */ |
| 9 | |
| 10 | namespace Divi5Amelia; |
| 11 | |
| 12 | use AmeliaBooking\Infrastructure\Licence\Licence; |
| 13 | |
| 14 | if (!defined('ABSPATH')) { |
| 15 | die('Direct access forbidden.'); |
| 16 | } |
| 17 | |
| 18 | // Check if Divi 5 is active before loading modules |
| 19 | function is_divi_5_active() |
| 20 | { |
| 21 | $theme = wp_get_theme(); |
| 22 | $is_divi_theme = 'Divi' === $theme->name || 'Divi' === $theme->parent_theme; |
| 23 | |
| 24 | return $is_divi_theme; |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Custom value expansion function for converting comma-separated strings to arrays |
| 29 | * Used during Divi 4 to Divi 5 conversion for multi-select fields |
| 30 | */ |
| 31 | function ameliaConvertParams($value, $context = []) |
| 32 | { |
| 33 | if (is_string($value) && $value !== '') { |
| 34 | $items = array_map('trim', explode(',', $value)); |
| 35 | return array_filter($items, function ($item) { |
| 36 | return $item !== ''; |
| 37 | }); |
| 38 | } |
| 39 | |
| 40 | if (is_array($value)) { |
| 41 | return $value; |
| 42 | } |
| 43 | |
| 44 | return []; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Convert Divi 4 yes_no_button values to Divi 5 toggle string values |
| 49 | * Keep as 'on'/'off' strings since that's what Divi Toggle component expects |
| 50 | */ |
| 51 | function ameliaConvertToggle($value, $context = []) |
| 52 | { |
| 53 | // Handle empty/null/undefined - default to 'on' (Divi 4 defaults were 'on') |
| 54 | if ($value === null || $value === '') { |
| 55 | return 'on'; |
| 56 | } |
| 57 | |
| 58 | // Already correct string format |
| 59 | if ($value === 'on' || $value === '1' || $value === 1 || $value === true || $value === 'true') { |
| 60 | return 'on'; |
| 61 | } |
| 62 | |
| 63 | if ($value === 'off' || $value === '0' || $value === 0 || $value === false || $value === 'false') { |
| 64 | return 'off'; |
| 65 | } |
| 66 | |
| 67 | // Default to 'on' for Customer Panel (matches D4 behavior) |
| 68 | return 'on'; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Convert catalog items (categories/services/packages) and automatically set catalog_view |
| 73 | * |
| 74 | * @param mixed $value The value to convert (comma-separated string or array) |
| 75 | * @param array $context Context information including field name and attributes |
| 76 | * @return array Converted array of items |
| 77 | */ |
| 78 | function ameliaConvertCatalogItems($value, $context = []) |
| 79 | { |
| 80 | $result = ameliaConvertParams($value, $context); |
| 81 | |
| 82 | // If items were selected, also update the catalog_view based on field name |
| 83 | if (!empty($result) && isset($context['attrs']) && isset($context['fieldName'])) { |
| 84 | // Determine catalog view type from field name |
| 85 | $catalogViewMap = [ |
| 86 | 'categories' => 'category', |
| 87 | 'services' => 'service', |
| 88 | 'packages' => 'package', |
| 89 | ]; |
| 90 | |
| 91 | $fieldName = $context['fieldName']; |
| 92 | if (isset($catalogViewMap[$fieldName])) { |
| 93 | if (!isset($context['attrs']['catalog_view'])) { |
| 94 | $context['attrs']['catalog_view'] = []; |
| 95 | } |
| 96 | $context['attrs']['catalog_view']['innerContent'] = [ |
| 97 | 'desktop' => ['value' => $catalogViewMap[$fieldName]] |
| 98 | ]; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | return $result; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Register custom value expansion functions for Divi conversion system |
| 107 | */ |
| 108 | add_filter('divi.moduleLibrary.conversion.valueExpansionFunctionMap', function ($functionMap) { |
| 109 | $functionMap['ameliaConvertParams'] = 'Divi5Amelia\ameliaConvertParams'; |
| 110 | $functionMap['ameliaConvertToggle'] = 'Divi5Amelia\ameliaConvertToggle'; |
| 111 | $functionMap['ameliaConvertCatalogItems'] = 'Divi5Amelia\ameliaConvertCatalogItems'; |
| 112 | |
| 113 | return $functionMap; |
| 114 | }); |
| 115 | |
| 116 | if (is_divi_5_active()) { |
| 117 | // Load Divi dependency interface before loading modules |
| 118 | $divi_dependency_interface = get_template_directory() . '/includes/builder-5/server/Framework/DependencyManagement/Interfaces/DependencyInterface.php'; |
| 119 | |
| 120 | if (!file_exists($divi_dependency_interface)) { |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | require_once $divi_dependency_interface; |
| 125 | |
| 126 | // Shared helpers used by booking button modules. |
| 127 | require_once __DIR__ . '/AmeliaBookingButtonRendererTrait.php'; |
| 128 | |
| 129 | require_once __DIR__ . '/ModuleMetadata.php'; |
| 130 | require_once __DIR__ . '/SharedShortcodeModule.php'; |
| 131 | require_once __DIR__ . '/AmeliaStepBookingModule.php'; |
| 132 | require_once __DIR__ . '/AmeliaStepBookingButtonModule.php'; |
| 133 | require_once __DIR__ . '/AmeliaBookingModule.php'; |
| 134 | require_once __DIR__ . '/AmeliaCatalogBookingModule.php'; |
| 135 | require_once __DIR__ . '/AmeliaCatalogModule.php'; |
| 136 | require_once __DIR__ . '/AmeliaEventsListModule.php'; |
| 137 | require_once __DIR__ . '/AmeliaEventsListBookingButtonModule.php'; |
| 138 | require_once __DIR__ . '/AmeliaEventsModule.php'; |
| 139 | require_once __DIR__ . '/AmeliaSearchModule.php'; |
| 140 | |
| 141 | if (Licence::$premium) { |
| 142 | require_once __DIR__ . '/AmeliaEventsCalendarModule.php'; |
| 143 | require_once __DIR__ . '/AmeliaCustomerPanelModule.php'; |
| 144 | require_once __DIR__ . '/AmeliaEmployeePanelModule.php'; |
| 145 | } |
| 146 | |
| 147 | add_action( |
| 148 | 'divi_module_library_modules_dependency_tree', |
| 149 | function ($dependency_tree) { |
| 150 | $dependency_tree->add_dependency(new AmeliaStepBookingModule()); |
| 151 | } |
| 152 | ); |
| 153 | |
| 154 | add_action( |
| 155 | 'divi_module_library_modules_dependency_tree', |
| 156 | function ($dependency_tree) { |
| 157 | $dependency_tree->add_dependency(new AmeliaStepBookingButtonModule()); |
| 158 | } |
| 159 | ); |
| 160 | |
| 161 | add_action( |
| 162 | 'divi_module_library_modules_dependency_tree', |
| 163 | function ($dependency_tree) { |
| 164 | $dependency_tree->add_dependency(new AmeliaBookingModule()); |
| 165 | } |
| 166 | ); |
| 167 | |
| 168 | add_action( |
| 169 | 'divi_module_library_modules_dependency_tree', |
| 170 | function ($dependency_tree) { |
| 171 | $dependency_tree->add_dependency(new AmeliaCatalogBookingModule()); |
| 172 | } |
| 173 | ); |
| 174 | |
| 175 | add_action( |
| 176 | 'divi_module_library_modules_dependency_tree', |
| 177 | function ($dependency_tree) { |
| 178 | $dependency_tree->add_dependency(new AmeliaCatalogModule()); |
| 179 | } |
| 180 | ); |
| 181 | |
| 182 | add_action( |
| 183 | 'divi_module_library_modules_dependency_tree', |
| 184 | function ($dependency_tree) { |
| 185 | $dependency_tree->add_dependency(new AmeliaEventsListModule()); |
| 186 | } |
| 187 | ); |
| 188 | |
| 189 | add_action( |
| 190 | 'divi_module_library_modules_dependency_tree', |
| 191 | function ($dependency_tree) { |
| 192 | $dependency_tree->add_dependency(new AmeliaEventsListBookingButtonModule()); |
| 193 | } |
| 194 | ); |
| 195 | |
| 196 | add_action( |
| 197 | 'divi_module_library_modules_dependency_tree', |
| 198 | function ($dependency_tree) { |
| 199 | $dependency_tree->add_dependency(new AmeliaEventsModule()); |
| 200 | } |
| 201 | ); |
| 202 | |
| 203 | add_action( |
| 204 | 'divi_module_library_modules_dependency_tree', |
| 205 | function ($dependency_tree) { |
| 206 | $dependency_tree->add_dependency(new AmeliaSearchModule()); |
| 207 | } |
| 208 | ); |
| 209 | |
| 210 | // Register premium modules only if license is premium |
| 211 | if (Licence::$premium) { |
| 212 | add_action( |
| 213 | 'divi_module_library_modules_dependency_tree', |
| 214 | function ($dependency_tree) { |
| 215 | $dependency_tree->add_dependency(new AmeliaEventsCalendarModule()); |
| 216 | } |
| 217 | ); |
| 218 | |
| 219 | add_action( |
| 220 | 'divi_module_library_modules_dependency_tree', |
| 221 | function ($dependency_tree) { |
| 222 | $dependency_tree->add_dependency(new AmeliaCustomerPanelModule()); |
| 223 | } |
| 224 | ); |
| 225 | |
| 226 | add_action( |
| 227 | 'divi_module_library_modules_dependency_tree', |
| 228 | function ($dependency_tree) { |
| 229 | $dependency_tree->add_dependency(new AmeliaEmployeePanelModule()); |
| 230 | } |
| 231 | ); |
| 232 | } |
| 233 | } |
| 234 |