PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 1.91.6
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v1.91.6
2.1.0 2.0.15 2.0.12 2.0.10 2.0.4 2.0.1 2.0.0 1.95.3 1.95.2 1.95 1.91.6 trunk 1.11 1.12 1.13 1.20 1.21 1.22 1.23 1.30 1.31 1.32 1.35 1.40 1.41 All 42 releases
fluent-boards / app / Functions / helpers.php

helpers.php in FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration 1.91.6, at app/Functions/helpers.php

280 lines 7.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use FluentBoards\App\App;
4
5 // $app is available
6
7 if (!function_exists('fluentBoards')) {
8 function fluentBoards($module = null)
9 {
10 return App::getInstance($module);
11 }
12 }
13
14 if (!function_exists('FluentBoardsApi')) {
15 function FluentBoardsApi($key = null)
16 {
17 $api = fluentBoards('api');
18 return is_null($key) ? $api : $api->{$key};
19 }
20 }
21
22 if (!function_exists('fluent_boards_user_avatar')) {
23 function fluent_boards_user_avatar($email, $name = '')
24 {
25 $user = get_user_by('email', $email);
26
27 if($user) {
28 $has_custom_avatar = get_user_meta($user->ID, 'wp_user_avatar', true);
29 if ($has_custom_avatar) {
30 $custom_avatar_attachment = get_post($has_custom_avatar);
31 if ($custom_avatar_attachment) {
32 $avatar_url = wp_get_attachment_url($has_custom_avatar);
33 return apply_filters('fluent_boards/get_avatar', $avatar_url, $email);
34 }
35 }
36 $avatar_url = get_avatar_url($user->ID, array('size' => 128));
37 return apply_filters('fluent_boards/get_avatar', $avatar_url, $email);
38 }
39
40 $hash = md5(strtolower(trim($email)));
41 /**
42 * Gravatar URL by Email
43 *
44 * @return string $gravatar url of the gravatar image
45 */
46 $fallback = '';
47 if ($name) {
48 $fallback = '&d=https%3A%2F%2Fui-avatars.com%2Fapi%2F' . urlencode($name) . '/128';
49 }
50
51 return apply_filters('fluent_boards/get_avatar',
52 "https://www.gravatar.com/avatar/{$hash}?s=128" . $fallback,
53 $email
54 );
55 }
56 }
57
58 if (!function_exists('fluent_boards_mix')) {
59 function fluent_boards_mix($path, $manifestDirectory = '')
60 {
61 return fluentBoards('url.assets') . ltrim($path, '/');
62 }
63 }
64
65 if (!function_exists('FluentBoardsAssetUrl')) {
66 function FluentBoardsAssetUrl($path = null)
67 {
68 $assetUrl = fluentBoards('url.assets');
69
70 return $path ? ($assetUrl . $path) : $assetUrl;
71 }
72 }
73
74 if (!function_exists('fluent_boards_page_url')) {
75 function fluent_boards_page_url(): ?string
76 {
77 return apply_filters('fluent_boards/app_url', admin_url('admin.php?page=fluent-boards#/'));
78 }
79 }
80
81 function fluent_boards_get_pref_settings($cached = true)
82 {
83 static $pref = null;
84
85 if ($cached && $pref) {
86 return $pref;
87 }
88
89 $settings = [
90 'timeTracking' => [
91 'enabled' => 'no',
92 'all_boards' => 'yes',
93 'selected_boards' => []
94 ],
95 'frontend' => [
96 'enabled' => 'no',
97 'slug' => 'projects',
98 'render_type' => 'standalone',
99 'page_id' => ''
100 ],
101 'menu_settings' => [
102 'in_fluent_crm' => 'no',
103 'menu_position' => 3
104 ],
105 'recurring_task' => [
106 'enabled' => 'no',
107 'all_boards' => 'yes',
108 'selected_boards' => []
109 ],
110 ];
111
112 $storedSettings = get_option('fluent_boards_modules', []);
113 if ($storedSettings && is_array($storedSettings)) {
114 $settings = wp_parse_args($storedSettings, $settings);
115 }
116
117 $pref = $settings;
118
119 return $settings;
120 }
121
122 if (!function_exists('fluent_boards_site_logo')) {
123 function fluent_boards_site_logo()
124 {
125 $logo_url = '';
126 if (function_exists('get_custom_logo') && has_custom_logo()) {
127 $custom_logo_id = get_theme_mod('custom_logo');
128 $logo = wp_get_attachment_image_src($custom_logo_id, 'full');
129 if ($logo) {
130 $logo_url = $logo[0];
131 }
132 }
133 return apply_filters('fluent_boards/site_logo', $logo_url);
134 }
135 }
136
137 function fluent_boards_get_option($key, $default = null)
138 {
139 $exit = \FluentBoards\App\Models\Meta::where('object_type', 'option')
140 ->where('key', $key)
141 ->first();
142
143 if ($exit) {
144 return $exit->value;
145 }
146
147 return $default;
148 }
149
150 function fluent_boards_update_option($key, $value)
151 {
152 $exit = \FluentBoards\App\Models\Meta::where('object_type', 'option')
153 ->where('key', $key)
154 ->first();
155
156 if ($exit) {
157 $exit->value = $value;
158 $exit->save();
159 } else {
160 $exit = \FluentBoards\App\Models\Meta::create([
161 'object_type' => 'option',
162 'key' => $key,
163 'value' => $value
164 ]);
165 }
166
167 return $exit;
168 }
169
170
171 function fluentBoardsDb()
172 {
173 return fluentBoards('db');
174 }
175
176 /**
177 * Retrieves features configuration.
178 *
179 * @deprecated 1.90 Use fluent_boards_get_features_config() instead.
180 */
181 function fbsGetFeaturesConfig()
182 {
183 _deprecated_function(__FUNCTION__, '1.90', 'fluent_boards_get_features_config');
184 return fluent_boards_get_features_config();
185 }
186
187 function fluent_boards_get_features_config()
188 {
189 $features = fluent_boards_get_option('_fbs_features', []);
190
191 $defaults = [
192 'cloud_storage' => 'no',
193 // more advanced features/config can be added here
194 ];
195
196 if (defined('FLUENT_BOARDS_CLOUD_STORAGE') && FLUENT_BOARDS_CLOUD_STORAGE) {
197 $features['cloud_storage'] = 'yes';
198 }
199
200 return wp_parse_args($features, $defaults);
201 }
202
203 /**
204 * Updates an option value.
205 *
206 * @deprecated 1.90 Use fluent_boards_get_option() instead.
207 */
208 function fbsGetOption($key, $default = null)
209 {
210 _deprecated_function(__FUNCTION__, '1.90', 'fluent_boards_get_option');
211 return fluent_boards_get_option($key, $default);
212 }
213
214 /**
215 * Updates an option value.
216 *
217 * @deprecated 1.90 Use fluent_boards_update_option() instead.
218 */
219 function fbsUpdateOption($key, $value)
220 {
221 _deprecated_function(__FUNCTION__, '1.90', 'fluent_boards_update_option');
222 return fluent_boards_update_option($key, $value);
223 }
224
225
226 function fluentboardsCsvMimes()
227 {
228 /**
229 * Board Import CSV Mimes
230 *
231 * @return array array of CSV mimes
232 */
233 return apply_filters('fluent_boards_csv_mimes', [
234 'text/csv',
235 'text/plain',
236 'application/csv',
237 'text/comma-separated-values',
238 'application/excel',
239 'application/vnd.ms-excel',
240 'application/vnd.msexcel',
241 'text/anytext',
242 'application/octet-stream',
243 'application/txt'
244 ]);
245 }
246
247 function fluent_boards_string_to_bool($value)
248 {
249 // Normalize known string values to booleans
250 $trueFalseMap = [
251 'yes' => true,
252 'no' => false,
253 'true' => true,
254 'false' => false,
255 '1' => true,
256 '0' => false,
257 true => true,
258 false => false,
259 ];
260
261 // Allow modification of the map
262 $trueFalseMap = apply_filters('fluent_boards/true_false_convert', $trueFalseMap);
263
264 // Handle array input recursively
265 if (is_array($value)) {
266 return array_map('fluent_boards_string_to_bool', $value);
267 }
268
269 // Normalize string input
270 $key = is_string($value) ? strtolower(trim($value)) : $value;
271
272 // Match normalized value against map
273 if (array_key_exists($key, $trueFalseMap)) {
274 return $trueFalseMap[$key];
275 }
276
277 // Fallback: return original value if not recognized
278 return $value;
279 }
280