PluginProbe
The Innovative Form Builder – IvyForms / 0.4
The Innovative Form Builder – IvyForms v0.4
1.5.1 1.5 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 All 27 releases
ivyforms / backend / src / Repository / Entry / EntryHelper.php

EntryHelper.php in The Innovative Form Builder – IvyForms 0.4, at backend/src/Repository/Entry/EntryHelper.php

82 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\Repository\Entry;
4
5 use IvyForms\Entity\Entry\Entry;
6
7 class EntryHelper
8 {
9 /**
10 * Get the client IP address.
11 *
12 * @return string|null
13 */
14 public static function getClientIpAddress(): ?string
15 {
16 $ip = filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP);
17 return $ip ?: null;
18 }
19
20 /**
21 * Get the user agent string.
22 *
23 * @return string
24 */
25 public static function getUserAgent(): string
26 {
27 $userAgent = filter_input(INPUT_SERVER, 'HTTP_USER_AGENT');
28 return $userAgent ?: '';
29 }
30
31 /**
32 * Get the source URL.
33 *
34 * @return string|null
35 */
36 public static function getSourceURL(): ?string
37 {
38 $sourceURL = filter_input(INPUT_SERVER, 'HTTP_REFERER');
39 return $sourceURL ?: '';
40 }
41
42 /**
43 * Get the browser name from the user agent string.
44 *
45 * @param string $userAgent
46 * @return string
47 */
48 public static function getBrowserName(string $userAgent): string
49 {
50 if (str_contains($userAgent, 'Firefox')) {
51 return 'Mozilla Firefox';
52 } elseif (str_contains($userAgent, 'Chrome') && !str_contains($userAgent, 'Edg')) {
53 return 'Google Chrome';
54 } elseif (str_contains($userAgent, 'Safari') && !str_contains($userAgent, 'Chrome')) {
55 return 'Apple Safari';
56 } elseif (str_contains($userAgent, 'Edg')) {
57 return 'Microsoft Edge';
58 } elseif (str_contains($userAgent, 'MSIE') || str_contains($userAgent, 'Trident')) {
59 return 'Internet Explorer';
60 }
61 return 'Unknown';
62 }
63
64 /**
65 * Build entry data array for form submissions.
66 *
67 * @param int $formId
68 * @return array<string, mixed>
69 */
70 public static function buildEntryData(int $formId): array
71 {
72 return [
73 'formId' => $formId,
74 'userId' => get_current_user_id() ?: null,
75 'status' => Entry::DEFAULT_STATUS,
76 'ipAddress' => self::getClientIpAddress(),
77 'userAgent' => self::getUserAgent(),
78 'sourceURL' => self::getSourceURL(),
79 ];
80 }
81 }
82