PluginProbe
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce / 2.15.0
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce v2.15.0
2.15.0 trunk 1.0.0 1.0.1 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1.2 2.1.3 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 All 62 releases
hurrytimer / includes / Cookie_Detection.php

Cookie_Detection.php in HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce 2.15.0, at includes/Cookie_Detection.php

93 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 Hurrytimer;
4
5 use Hurrytimer\Utils\Helpers;
6
7 class Cookie_Detection
8 {
9 const COOKIE_PREFIX = '_ht_CDT-';
10 const RESET_FLAG = '_hurrytimer_reset_compaign_flag';
11
12 protected $campaignId;
13
14 public function __construct( $campaignId )
15 {
16 $this->campaignId = $campaignId;
17 }
18
19 public function updateOrCreate( $endDateTimeTS )
20 {
21 setcookie( self::cookieName( $this->campaignId ), $endDateTimeTS,
22 time() + YEAR_IN_SECONDS,
23 COOKIEPATH,
24 COOKIE_DOMAIN );
25
26 }
27
28 /**
29 * Find Campaign timer cookie.
30 *
31 *
32 * @return int|null
33 */
34 public function getCurrentUserEndDate()
35 {
36
37 $endDateTS = self::cookieName( $this->campaignId );
38
39 if ( !isset( $_COOKIE[ $endDateTS ] ) || empty( $_COOKIE[ $endDateTS ] ) ) {
40 return null;
41 }
42
43 return $_COOKIE[ $endDateTS ];
44 }
45
46 /**
47 * Cookie name with given Campaign id.
48 *
49 * @param int $compaignId
50 *
51 * @return string
52 */
53 public static function cookieName( $compaignId )
54 {
55 return self::COOKIE_PREFIX . $compaignId;
56 }
57
58 public function getCurrentUserResetToken()
59 {
60
61 $resetToken = self::cookieName( $this->campaignId ) . '_reset_token';
62
63 return empty( $_COOKIE[ $resetToken ] ) ? false : $_COOKIE[ $resetToken ];
64
65 }
66
67 public function deleteCampaignResetTokenCookie($campaignId = null)
68 {
69 $_campaignId = $campaignId ?: $this->campaignId;
70 $resetToken = self::cookieName( $_campaignId ) . '_reset_token';
71 setcookie( $resetToken, '', time() - YEAR_IN_SECONDS );
72 unset( $_COOKIE[ $resetToken ] );
73 }
74
75 public function deleteCampaignCookie( $campaignId = null )
76 {
77 $_campaignId = $campaignId ?: $this->campaignId;
78 $cookie_name = Cookie_Detection::cookieName( $_campaignId );
79 unset( $_COOKIE[ $cookie_name ] );
80 setcookie( $cookie_name, '', time() - YEAR_IN_SECONDS );
81 }
82
83 public function deleteAllCookies()
84 {
85 $campaigns = Helpers::getCampaigns();
86 foreach ( $campaigns as $campaign ) {
87 $this->deleteCampaignCookie( $campaign->ID );
88 $this->deleteCampaignResetTokenCookie($campaign->ID);
89 }
90 }
91
92 }
93