-
Notifications
You must be signed in to change notification settings - Fork 0
/
halloweencountdown.php
89 lines (66 loc) · 2.41 KB
/
halloweencountdown.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
if (!defined('_TB_VERSION_')) {
exit;
}
/**
* Halloween Countdown
*/
class HalloweenCountdown extends Module
{
public function __construct()
{
$this->name = 'halloweencountdown';
$this->tab = 'front_office_features';
$this->version = '1.0.0';
$this->author = 'Michael Rouse';
$this->need_instance = 0;
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Halloween Countdown');
$this->description = $this->l('Displays a halloween countdown in your footer');
$this->tb_versions_compliancy = '> 1.0.0';
$this->tb_min_version = '1.0.0';
$this->ps_versions_compliancy = ['min' => '1.6', 'max' => '1.6.99.99'];
}
/**
* Renders the display in the footer
*/
public function hookDisplayFooter()
{
$todaysDate = date_create(date("Y/m/d"));
$nextHalloween = date_create(date("Y/10/31", (date("m") > 10) ? strtotime('+1 year') : strtotime('+0 minute')));
$isHalloween = date("m/d") == "10/31";
$dateDiff = date_diff($todaysDate, $nextHalloween);
$daysUntilHalloween = $dateDiff->format('%a');
$daysWord = ($daysUntilHalloween > 1) ? "days" : "day";
$daysWord = $this->l($daysWord);
$halloweenCountdown = "{$daysUntilHalloween} {$daysWord} " . $this->l("until Halloween!");
if ($isHalloween)
$halloweenCountdown = $this->l("Happy Halloween!");
$isHalfway = $daysUntilHalloween == 183;
if ($isHalloween)
$halloweenCountdown = $this->l("Halfway to Halloween!");
$spookyEmojiList = ['🎃','👻','🦇','🧛♂️','💀','🧟♂️','🕷','🕸','⚰️'];
$spookyEmoji = $spookyEmojiList[array_rand($spookyEmojiList)];
$this->smarty->assign([
'days_until_halloween' => $daysUntilHalloween,
'halloween_countdown' => $halloweenCountdown,
'is_halloween' => $isHalloween,
'is_halfway_to_halloween' => $isHalfway,
'spooky_emoji' => $spookyEmoji
]);
return $this->display(__FILE__, 'halloweenCountdown.tpl');
}
public function install()
{
if (!parent::install()) {
return false;
}
$this->registerHook('displayFooter');
return true;
}
public function uninstall()
{
return parent::uninstall();
}
}