/
birthdayPost.php
140 lines (126 loc) · 5.62 KB
/
birthdayPost.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
class BirthdayPost extends Post {
public function __construct($host, $user, $pass){
$body = "_[l[Shacker Birthdays:]l]_ \n";
//TODO: refactor out passwords/mysql connection details?
$connection = mysql_connect($host, $user, $pass);
$numRows = 0;
$averageAge = 0;
if ($connection !== False) {
// TODO: refactor this out too
mysql_select_db("shackdb");
// fetch birthdays first on same connection
$query = "select avg(year) as avg_year from (SELECT substring(dob,1,4) as year from birthdays having year > 1901 and year < 2005) as tb1;";
$result = mysql_query($query);
$averageAge = mysql_fetch_array($result, MYSQL_ASSOC);
$averageAge = date("Y") - floatval($averageAge["avg_year"]);
$query = "SELECT * FROM birthdays where dob like '%".date('m-d')."'";
$result = mysql_query($query);
$numRows = mysql_numrows($result);
}
if($numRows > 0) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$body .= "y{".$row["username"]."}y". self::agestring($row["dob"], $row["username"]) ."\n";
}
$body .= "\n";
$body .= "And as always, Happy Birthday, Shackers from the y{the man with the briefcase}y!!\n";
} else {
$body .= "\n";
$body .= "No birthdays today!\n";
}
$body .= "\n";
$body .= "s[The average shackage is now " . number_format($averageAge,2,'.','') . "!]s\n";
$body .= "s[Want to add your birthday? http://shack.asktherelic.com/birthday.php]s";
parent::__construct($body);
}
private function getHoroscope() {
//This external API never works
$m = date('m');
$d = date('d');
$url = "http://www.trynt.com/astrology-horoscope-api/v2/?m={$m}&d=${d}&s=&l=0&fo=php&f=0";
$result = parent::curlData($url);
$h = unserialize($result);
$h = $h["trynt"]["astrology"];
//name is name of the animal
//start date of the horoscope
//end date of the horoscope
//horoscope itself (long string)
$name = $h["name"];
$sdate = $h["start-date"];
$edate = $h["end-date"];
$horoscope = trim($h["horoscope"]["horoscope"]);
return "b[{$name}]b {$sdate} - {$edate}\n{$horoscope}\n";
}
private function agestring($age, $username) {
$ret;
if($age == "1900" || $age == "0000") {
$ret = " is a year older";
}
$year = substr($age, 0, 4);
$real_age = date('Y') - $year;
$ord_real_age = parent::ord_suf($real_age);
$firstchar = substr($username, 0, 1);
$fun = array();
array_push($fun, " better have fun turning {$real_age}");
array_push($fun, " finally hits {$real_age} today");
array_push($fun, " turns {$real_age}");
array_push($fun, " is now {$real_age}");
array_push($fun, " has can my birthday wishes for their {$ord_real_age}");
array_push($fun, " IS IN UR BIRTHDAY CAKE FOR THEIR {$ord_real_age}");
array_push($fun, " is so so old at {$real_age}");
array_push($fun, " better have a great time for their {$ord_real_age}");
array_push($fun, " happy birthday for your {$ord_real_age}");
array_push($fun, ": may you live long and prosper for your {$ord_real_age}");
array_push($fun, " needs plenty of hookers and blow for their {$ord_real_age}");
array_push($fun, " may have a present waiting for their {$ord_real_age}. Or not");
array_push($fun, " has been a virgin for {$real_age} long years");
array_push($fun, " better not have a lame {$ord_real_age}");
array_push($fun, " HAPPY BURFDAY {$real_age}");
array_push($fun, " OMGH{$firstchar}D :O");
//foreign birthdays for kicks
array_push($fun, ": Feliz Cumpleaños {$real_age}");
array_push($fun, ": Selamat Hari Jadi {$real_age}");
array_push($fun, ": Alles Gute zum Geburtstag {$real_age}");
array_push($fun, ": Buon Compleanno {$real_age}");
array_push($fun, ": Yom Huledet Same'ach {$real_age}");
array_push($fun, ": Joyeux Anniversaire Branleur");
array_push($fun, ": Suk San Wan Keut");
array_push($fun, ": Hyvaa syntymapaivaa");
array_push($fun, ": Van harte gefeliciteerd met je verjaardag");
//Specific case for extra special birthdays or choose something at random
switch(True) {
case ($real_age < 18):
$ret = " is one of the youngest here at {$real_age}";
break;
case ($real_age === 18):
$ret = " finally hits 18";
break;
case ($real_age === 21):
$ret = " turns 21. Prepare the drunk tank";
break;
case ($real_age === 25):
$ret = " can now rent a car at 25";
break;
case ($real_age === 30):
$ret = " better get some good loot for for turning 30";
break;
case ($real_age === 35):
$ret = " can now have a mid-life crisis at 35";
break;
case ($real_age === 40):
$ret = " is over the hill at 40";
break;
case ($real_age === 50):
$ret = " is old enough to be my dad at 50";
break;
case ($real_age > 50):
$ret = " is really old, but we still love them.";
break;
default:
$ret = $fun[mt_rand(0, (count($fun)-1))];
}
$ret .= " /[!]/ ";
return $ret;
}
}
?>