| @@ -8,8 +8,12 @@ | ||
| 8 | 8 | use Exception; |
| 9 | 9 | |
| 10 | 10 | class Helpers |
| 11 | 11 | { |
| 12 | + | |
| 13 | + public static $file_upload_types = ['file-up', 'advanced-file-up']; | |
| 14 | + | |
| 15 | + public static $repeated_array_type_data_fields = ['check', 'image-select']; | |
| 12 | 16 | public static function filterNullEntries($entries) |
| 13 | 17 | { |
| 14 | 18 | $filteredEntries = []; |
| 15 | 19 | foreach ($entries as $entry) { |
| @@ -222,9 +226,9 @@ | ||
| 222 | 226 | { |
| 223 | 227 | // check if the user is logged in |
| 224 | 228 | if (is_user_logged_in()) { |
| 225 | 229 | $user = wp_get_current_user(); |
| 226 | - if(in_array('administrator', $user->roles) || current_user_can('manage_bitform')){ | |
| 230 | + if (in_array('administrator', $user->roles) || current_user_can('manage_bitform')) { | |
| 227 | 231 | return true; |
| 228 | 232 | } |
| 229 | 233 | $entryModel = new FormEntryModel(); |
| 230 | 234 | $entry = $entryModel->get( |
| @@ -229,28 +233,42 @@ | ||
| 229 | 233 | $entryModel = new FormEntryModel(); |
| 230 | 234 | $entry = $entryModel->get( |
| 231 | 235 | 'id, user_id, form_id', |
| 232 | 236 | [ |
| 233 | - 'id' => $entryId, | |
| 237 | + 'id' => $entryId, | |
| 234 | 238 | 'user_id' => $user->ID |
| 235 | 239 | ] |
| 236 | 240 | ); |
| 237 | - error_log(print_r(['entry', $entry], true)); | |
| 238 | - if(!is_wp_error($entry) && !empty($entry)){ | |
| 241 | + if (!is_wp_error($entry) && !empty($entry)) { | |
| 239 | 242 | return true; |
| 240 | 243 | } |
| 241 | - } | |
| 244 | + } | |
| 242 | 245 | // check if the entry token is valid |
| 243 | 246 | if (isset($entryToken) && $entryToken) { |
| 244 | 247 | $decryptEntryId = Cryptography::decrypt($entryToken, AUTH_SALT); |
| 245 | 248 | if ($decryptEntryId === $entryId) { |
| 246 | 249 | return true; |
| 247 | - } | |
| 250 | + } | |
| 248 | 251 | } |
| 249 | 252 | |
| 250 | 253 | return false; |
| 251 | 254 | } |
| 252 | 255 | |
| 256 | + public static function validateEormEntryEditPermission($formId, $entryId) | |
| 257 | + { | |
| 258 | + if (is_user_logged_in()) { | |
| 259 | + if(current_user_can('prevent_bitform_entry_edit')){ | |
| 260 | + return false; | |
| 261 | + } | |
| 262 | + | |
| 263 | + if(current_user_can('manage_bitform')||current_user_can('bitform_entry_edit') || current_user_can('edit_post')){ | |
| 264 | + return true; | |
| 265 | + } | |
| 266 | + | |
| 267 | + } | |
| 268 | + return false; | |
| 269 | + } | |
| 270 | + | |
| 253 | 271 | public static function honeypotEncryptedToken($str) |
| 254 | 272 | { |
| 255 | 273 | $token = base64_encode(base64_encode($str)); |
| 256 | 274 | return $token; |
| @@ -274,6 +292,15 @@ | ||
| 274 | 292 | return \hash_equals( |
| 275 | 293 | \base64_encode(\hash_hmac('sha256', $identy, $secretKey, true)), |
| 276 | 294 | $token |
| 277 | 295 | ); |
| 296 | + } | |
| 297 | + | |
| 298 | + public static function checkIsIntArr($arr) | |
| 299 | + { | |
| 300 | + $filteredArray = array_filter($arr, 'is_numeric'); | |
| 301 | + $intArray = array_map('intval', $filteredArray); | |
| 302 | + $result = count($arr) === count($intArray); | |
| 303 | + | |
| 304 | + return $result; | |
| 278 | 305 | } |
| 279 | 306 | } |