PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 1.95.3
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v1.95.3
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 1.45 All 41 releases
fluent-boards / app / Functions / helpers.php

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

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