PluginProbe
The Innovative Form Builder – IvyForms / 0.8
The Innovative Form Builder – IvyForms v0.8
1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 1.2 1.3
ivyforms / backend / src / Services / Menu / MenuService.php

MenuService.php in The Innovative Form Builder – IvyForms 0.8, at backend/src/Services/Menu/MenuService.php

178 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\Services\Menu;
4
5 // phpcs:disable PSR1.Files.SideEffects
6 if (!defined('ABSPATH')) {
7 exit; // Exit if accessed directly
8 }
9
10 use IvyForms\Routes\Routes;
11 use IvyForms\Services\Settings\SettingsService;
12 use IvyForms\Services\Translations\BackendStrings;
13
14 /**
15 * Renders menu pages
16 */
17 class MenuService
18 {
19 /**
20 * Submenu page render function
21 * @param string $page
22 */
23 public function render(string $page): void
24 {
25 $page = trim($page);
26 $scriptId = IVYFORMS_DEV ? 'ivyforms_scripts_dev_vite' : 'ivyforms_script_index'; // @phpstan-ignore-line
27 $scriptSrc = IVYFORMS_DEV ? // @phpstan-ignore-line
28 'http://localhost:5173/src/assets/js/admin/admin.ts' :
29 IVYFORMS_URL . 'frontend/dist/admin.js';
30 $styleSrc = IVYFORMS_DEV ? '' : IVYFORMS_URL . 'frontend/dist/index.css';// @phpstan-ignore-line
31 $scriptVersion = IVYFORMS_DEV ? null : IVYFORMS_VERSION;// @phpstan-ignore-line
32
33 wp_enqueue_script(
34 $scriptId,
35 $scriptSrc,
36 [],
37 $scriptVersion,
38 true
39 );
40
41 // TODO: Check including fonts on build
42 // @phpstan-ignore-next-line
43 if ($styleSrc) {
44 wp_enqueue_style(
45 'ivyforms_style_admin',
46 IVYFORMS_URL . 'frontend/dist/admin.css',
47 [],
48 $scriptVersion
49 );
50 wp_enqueue_style(
51 'ivyforms_style_index',
52 $styleSrc,
53 [],
54 $scriptVersion
55 );
56 // wp_enqueue_style(
57 // 'ivyforms_font_roboto_regular_woff2',
58 // IVYFORMS_URL . 'frontend/dist/Roboto-Regular.woff2',
59 // [],
60 // $scriptVersion
61 // );
62 // wp_enqueue_style(
63 // 'ivyforms_font_roboto_regular_woff',
64 // IVYFORMS_URL . 'frontend/dist/Roboto-Regular.woff',
65 // [],
66 // $scriptVersion
67 // );
68 // wp_enqueue_style(
69 // 'ivyforms_font_roboto_medium_woff2',
70 // IVYFORMS_URL . 'frontend/dist/Roboto-Medium.woff2',
71 // [],
72 // $scriptVersion
73 // );
74 // wp_enqueue_style(
75 // 'ivyforms_font_roboto_medium_woff',
76 // IVYFORMS_URL . 'frontend/dist/Roboto-Medium.woff',
77 // [],
78 // $scriptVersion
79 // );
80 // wp_enqueue_style(
81 // 'ivyforms_font_roboto_bold_woff2',
82 // IVYFORMS_URL . 'frontend/dist/Roboto-Bold.woff2',
83 // [],
84 // $scriptVersion
85 // );
86 // wp_enqueue_style(
87 // 'ivyforms_font_roboto_bold_woff',
88 // IVYFORMS_URL . 'frontend/dist/Roboto-Bold.woff',
89 // [],
90 // $scriptVersion
91 // );
92 }
93
94 // Localize scripts
95 $settingsStorage = new SettingsService();
96
97 wp_localize_script(
98 $scriptId,
99 'wpIvySettings',
100 $settingsStorage->getFrontendSettings()
101 );
102
103 $backendLabels = array_merge(
104 BackendStrings::getNewFormStrings(),
105 BackendStrings::getSettingsFormBuilderStrings(),
106 BackendStrings::getResultsFormBuilderStrings(),
107 BackendStrings::getEmptyStatesStrings(),
108 BackendStrings::getEntityFormStrings(),
109 BackendStrings::getAllFormsStrings(),
110 BackendStrings::getDashboardStrings(),
111 BackendStrings::getCommonStrings(),
112 BackendStrings::getComponentsStrings(),
113 BackendStrings::getEntriesStrings(),
114 BackendStrings::getIntegrationsStrings(),
115 BackendStrings::getExceptionStrings(),
116 BackendStrings::getTemplateStrings(),
117 BackendStrings::getSettingsStrings(),
118 BackendStrings::getSecurityStrings(),
119 BackendStrings::getProUpgradeDialogStrings(),
120 BackendStrings::getChangelogStrings()
121 );
122
123 /**
124 * Filter backend labels before localizing
125 * Allows Pro version to merge additional strings
126 *
127 * @since 0.1.0
128 * @param array $backendLabels Array of backend label strings
129 */
130 $backendLabels = apply_filters('ivyforms/admin/backend_labels', $backendLabels);
131
132 wp_localize_script(
133 $scriptId,
134 'wpIvyLabels',
135 $backendLabels
136 );
137
138 wp_localize_script(
139 $scriptId,
140 'wpIvyUrls',
141 [
142 'pluginURL' => IVYFORMS_URL,
143 'siteURL' => esc_url_raw(site_url()),
144 ]
145 );
146 wp_localize_script(
147 $scriptId,
148 'wpIvyApiSettings',
149 [
150 'root' => esc_url_raw(rest_url()),
151 'nonce' => wp_create_nonce('wp_rest'),
152 'namespace' => Routes::$routeNamespace,
153 ]
154 );
155 wp_localize_script(
156 $scriptId,
157 'wpIvyDateFormat',
158 [
159 'dateFormat' => get_option('date_format'),
160 'timeFormat' => get_option('time_format'),
161 'dateTimeFormat' => get_option('date_format') . ' ' . get_option('time_format'),
162 'locale' => get_locale(),
163 ]
164 );
165
166 /**
167 * Hook to enqueue additional scripts and styles in admin area
168 * @since 0.1.0
169 *
170 * Arguments:
171 * - string $scriptId The main script handle ID (for dependencies)
172 */
173 do_action('ivyforms/admin/enqueue_scripts', $scriptId);
174
175 include IVYFORMS_PATH . '/view/backend/view.php';
176 }
177 }
178