CustomFieldEntity.php
2 months ago
DynamicSegmentFilterData.php
2 months ago
DynamicSegmentFilterEntity.php
3 years ago
FeatureFlagEntity.php
3 years ago
FormEntity.php
1 week ago
LogEntity.php
3 years ago
NewsletterEntity.php
2 months ago
NewsletterLinkEntity.php
3 years ago
NewsletterOptionEntity.php
3 years ago
NewsletterOptionFieldEntity.php
1 month ago
NewsletterPostEntity.php
3 years ago
NewsletterSegmentEntity.php
3 years ago
NewsletterTemplateEntity.php
3 years ago
ScheduledTaskEntity.php
1 month ago
ScheduledTaskSubscriberEntity.php
1 year ago
SegmentEntity.php
2 months ago
SendingQueueEntity.php
2 months ago
SettingEntity.php
3 years ago
StatisticsBounceEntity.php
3 years ago
StatisticsClickEntity.php
3 years ago
StatisticsFormEntity.php
3 years ago
StatisticsNewsletterEntity.php
1 year ago
StatisticsOpenEntity.php
3 years ago
StatisticsUnsubscribeEntity.php
2 months ago
StatisticsWooCommercePurchaseEntity.php
2 years ago
StatsNotificationEntity.php
3 years ago
SubscriberCustomFieldEntity.php
3 years ago
SubscriberEntity.php
4 days ago
SubscriberIPEntity.php
3 years ago
SubscriberSegmentEntity.php
3 years ago
SubscriberTagEntity.php
4 years ago
TagEntity.php
3 years ago
UserAgentEntity.php
3 years ago
UserFlagEntity.php
3 years ago
WpPostEntity.php
2 years ago
index.php
3 years ago
UserAgentEntity.php
67 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Entities; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Doctrine\EntityTraits\AutoincrementedIdTrait; |
| 9 | use MailPoet\Doctrine\EntityTraits\CreatedAtTrait; |
| 10 | use MailPoet\Doctrine\EntityTraits\UpdatedAtTrait; |
| 11 | use MailPoetVendor\Doctrine\ORM\Mapping as ORM; |
| 12 | |
| 13 | /** |
| 14 | * @ORM\Entity() |
| 15 | * @ORM\Table(name="user_agents") |
| 16 | */ |
| 17 | class UserAgentEntity { |
| 18 | use AutoincrementedIdTrait; |
| 19 | use CreatedAtTrait; |
| 20 | use UpdatedAtTrait; |
| 21 | |
| 22 | public const USER_AGENT_TYPE_HUMAN = 0; |
| 23 | public const USER_AGENT_TYPE_MACHINE = 1; |
| 24 | |
| 25 | public const MACHINE_USER_AGENTS = [ |
| 26 | 'Mozilla/5.0', |
| 27 | ]; |
| 28 | |
| 29 | /** |
| 30 | * @ORM\Column(type="string") |
| 31 | * @var string |
| 32 | */ |
| 33 | private $hash; |
| 34 | |
| 35 | /** |
| 36 | * @ORM\Column(type="string") |
| 37 | * @var string |
| 38 | */ |
| 39 | private $userAgent; |
| 40 | |
| 41 | public function __construct( |
| 42 | string $userAgent |
| 43 | ) { |
| 44 | $this->setUserAgent($userAgent); |
| 45 | } |
| 46 | |
| 47 | public function getUserAgent(): string { |
| 48 | return $this->userAgent; |
| 49 | } |
| 50 | |
| 51 | public function setUserAgent(string $userAgent): void { |
| 52 | $this->userAgent = $userAgent; |
| 53 | $this->hash = (string)crc32($userAgent); |
| 54 | } |
| 55 | |
| 56 | public function getHash(): string { |
| 57 | return $this->hash; |
| 58 | } |
| 59 | |
| 60 | public function getUserAgentType(): int { |
| 61 | if (in_array($this->getUserAgent(), self::MACHINE_USER_AGENTS, true)) { |
| 62 | return self::USER_AGENT_TYPE_MACHINE; |
| 63 | } |
| 64 | return self::USER_AGENT_TYPE_HUMAN; |
| 65 | } |
| 66 | } |
| 67 |