1 | <?php |
||
26 | class Give_Email_Access { |
||
27 | |||
28 | /** |
||
29 | * Token exists |
||
30 | * |
||
31 | * @since 1.0 |
||
32 | * @access public |
||
33 | * |
||
34 | * @var bool |
||
35 | */ |
||
36 | public $token_exists = false; |
||
37 | |||
38 | /** |
||
39 | * Token email |
||
40 | * |
||
41 | * @since 1.0 |
||
42 | * @access public |
||
43 | * |
||
44 | * @var bool |
||
45 | */ |
||
46 | public $token_email = false; |
||
47 | |||
48 | /** |
||
49 | * Token |
||
50 | * |
||
51 | * @since 1.0 |
||
52 | * @access public |
||
53 | * |
||
54 | * @var bool |
||
55 | */ |
||
56 | public $token = false; |
||
57 | |||
58 | /** |
||
59 | * Error |
||
60 | * |
||
61 | * @since 1.0 |
||
62 | * @access public |
||
63 | * |
||
64 | * @var string |
||
65 | */ |
||
66 | public $error = ''; |
||
67 | |||
68 | /** |
||
69 | * Verify throttle |
||
70 | * |
||
71 | * @since 1.0 |
||
72 | * @access public |
||
73 | * |
||
74 | * @var |
||
75 | */ |
||
76 | public $verify_throttle; |
||
77 | |||
78 | /** |
||
79 | * Limit throttle |
||
80 | * |
||
81 | * @since 1.8.17 |
||
82 | * @access public |
||
83 | * |
||
84 | * @var |
||
85 | */ |
||
86 | public $limit_throttle; |
||
87 | |||
88 | /** |
||
89 | * Verify expiration |
||
90 | * |
||
91 | * @since 1.0 |
||
92 | * @access private |
||
93 | * |
||
94 | * @var string |
||
95 | */ |
||
96 | private $token_expiration; |
||
97 | |||
98 | /** |
||
99 | * Class Constructor |
||
100 | * |
||
101 | * Set up the Give Email Access Class. |
||
102 | * |
||
103 | * @since 1.0 |
||
104 | * @access public |
||
105 | */ |
||
106 | public function __construct() { |
||
111 | |||
112 | /** |
||
113 | * Init |
||
114 | * |
||
115 | * Register defaults and filters |
||
116 | * |
||
117 | * @since 1.0 |
||
118 | * @access public |
||
119 | * |
||
120 | * @return void |
||
121 | */ |
||
122 | public function init() { |
||
150 | |||
151 | /** |
||
152 | * Prevent email spamming. |
||
153 | * |
||
154 | * @param int $donor_id Donor ID. |
||
155 | * |
||
156 | * @since 1.0 |
||
157 | * @access public |
||
158 | * |
||
159 | * @return bool |
||
160 | */ |
||
161 | public function can_send_email( $donor_id ) { |
||
162 | |||
163 | $donor = Give()->donors->get_donor_by( 'id', $donor_id ); |
||
164 | |||
165 | if ( is_object( $donor ) ) { |
||
166 | |||
167 | $email_throttle_count = (int) give_get_meta( $donor_id, '_give_email_throttle_count', true ); |
||
168 | |||
169 | $cache_key = "give_cache_email_throttle_limit_exhausted_{$donor_id}"; |
||
170 | if ( |
||
171 | $email_throttle_count < $this->limit_throttle && |
||
172 | true !== Give_Cache::get( $cache_key ) |
||
173 | ) { |
||
174 | give_update_meta( $donor_id, '_give_email_throttle_count', $email_throttle_count + 1 ); |
||
175 | } else { |
||
176 | give_update_meta( $donor_id, '_give_email_throttle_count', 0 ); |
||
177 | Give_Cache::set( $cache_key, true, $this->verify_throttle ); |
||
178 | return false; |
||
179 | } |
||
|
|||
180 | |||
181 | } |
||
182 | |||
183 | return true; |
||
184 | } |
||
185 | |||
186 | /** |
||
187 | * Send the user's token |
||
188 | * |
||
189 | * @param int $donor_id Donor id. |
||
190 | * @param string $email Donor email. |
||
191 | * |
||
192 | * @since 1.0 |
||
193 | * @access public |
||
194 | * |
||
195 | * @return bool |
||
196 | */ |
||
197 | public function send_email( $donor_id, $email ) { |
||
200 | |||
201 | /** |
||
202 | * Has the user authenticated? |
||
203 | * |
||
204 | * @since 1.0 |
||
205 | * @access public |
||
206 | * |
||
207 | * @return bool |
||
208 | */ |
||
209 | public function check_for_token() { |
||
237 | |||
238 | /** |
||
239 | * Is this a valid token? |
||
240 | * |
||
241 | * @since 1.0 |
||
242 | * @access public |
||
243 | * |
||
244 | * @param $token string The token. |
||
245 | * |
||
246 | * @return bool |
||
247 | */ |
||
248 | public function is_valid_token( $token ) { |
||
273 | |||
274 | /** |
||
275 | * Add the verify key to DB |
||
276 | * |
||
277 | * @param int $donor_id Donor id. |
||
278 | * @param string $email Donor email. |
||
279 | * @param string $verify_key The verification key. |
||
280 | * |
||
281 | * @since 1.0 |
||
282 | * @access public |
||
283 | * |
||
284 | * @return void |
||
285 | */ |
||
286 | public function set_verify_key( $donor_id, $email, $verify_key ) { |
||
308 | |||
309 | /** |
||
310 | * Is this a valid verify key? |
||
311 | * |
||
312 | * @since 1.0 |
||
313 | * @access public |
||
314 | * |
||
315 | * @param $token string The token. |
||
316 | * |
||
317 | * @return bool |
||
318 | */ |
||
319 | public function is_valid_verify_key( $token ) { |
||
344 | |||
345 | /** |
||
346 | * Users donations args |
||
347 | * |
||
348 | * Force Give to find donations by email, not user ID. |
||
349 | * |
||
350 | * @since 1.0 |
||
351 | * @access public |
||
352 | * |
||
353 | * @param $args array User Donations arguments. |
||
354 | * |
||
355 | * @return mixed |
||
356 | */ |
||
357 | public function users_donations_args( $args ) { |
||
362 | |||
363 | /** |
||
364 | * Create required columns |
||
365 | * |
||
366 | * Create the necessary columns for email access |
||
367 | * |
||
368 | * @since 1.0 |
||
369 | * @access public |
||
370 | * |
||
371 | * @return void |
||
372 | */ |
||
373 | public function create_columns() { |
||
380 | |||
381 | } |
||
382 |