| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FireBox |
| 4 |
* @version 3.1.14 Free |
| 5 |
* |
| 6 |
* @author FirePlugins <[email protected]> |
| 7 |
* @link https://www.fireplugins.com |
| 8 |
* @copyright Copyright © 2026 FirePlugins All Rights Reserved |
| 9 |
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace FireBox\Core\Analytics\Ajax; |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) |
| 15 |
{ |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
Trait Shared |
| 20 |
{ |
| 21 |
protected function getPreviousPeriodDates($startDate, $period) |
| 22 |
{ |
| 23 |
if (!\DateTime::createFromFormat('Y/m/d 00:00:00', $startDate)) |
| 24 |
{ |
| 25 |
return false; |
| 26 |
} |
| 27 |
|
| 28 |
$newStartDate = new \DateTime($startDate); |
| 29 |
$newStartDate->sub(new \DateInterval("P{$period}D")); |
| 30 |
$newStartDateStr = $newStartDate->format('Y/m/d 00:00:00'); |
| 31 |
|
| 32 |
$period--; |
| 33 |
$newEndDate = clone $newStartDate; |
| 34 |
$newEndDate->add(new \DateInterval("P{$period}D")); |
| 35 |
$newEndDateStr = $newEndDate->format('Y/m/d 23:59:59'); |
| 36 |
|
| 37 |
return [$newStartDateStr, $newEndDateStr]; |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Determine the transient TTL to use for cached analytics data. |
| 42 |
* Only fully-past date ranges are cached. Ranges that include today are |
| 43 |
* still being collected, and caching them makes freshly tracked views and |
| 44 |
* conversions appear to be missing from the dashboard. |
| 45 |
* |
| 46 |
* @param string $end_date The end date of the range (e.g. 'Y/m/d H:i:s'). |
| 47 |
* |
| 48 |
* @return int TTL in seconds, or 0 when the range must not be cached. |
| 49 |
*/ |
| 50 |
protected function getAnalyticsCacheTtl($end_date) |
| 51 |
{ |
| 52 |
$end_date_ts = strtotime($end_date); |
| 53 |
|
| 54 |
if ($end_date_ts && $end_date_ts < strtotime('today midnight', current_time('timestamp'))) |
| 55 |
{ |
| 56 |
// Fully-past range: data is no longer being collected for it. |
| 57 |
return HOUR_IN_SECONDS; |
| 58 |
} |
| 59 |
|
| 60 |
// Range includes today: always serve live data. |
| 61 |
return 0; |
| 62 |
} |
| 63 |
} |