32 |
|
ext::String path(env.get("PATH_INFO")); |
33 |
|
Matcher matcher; |
34 |
|
|
35 |
< |
if (path == "/daily/") daily(); else if (path == "/random/") |
35 |
> |
if (path == matcher("^/daily/(\\d{4}-\\d{2}-\\d{2})?$")) |
36 |
|
{ |
37 |
< |
random(); |
37 |
> |
daily(matcher.size() > 1 ? matcher[1] : ""); |
38 |
> |
} |
39 |
> |
else if (path == matcher("^/random/(\\d+)?$")) |
40 |
> |
{ |
41 |
> |
random(matcher.size() > 1 ? matcher[1] : ""); |
42 |
|
} |
43 |
|
else if (path == matcher("^/(" + this->matcher + ")$")) |
44 |
|
{ |
131 |
|
while (query.good()); |
132 |
|
} |
133 |
|
|
134 |
< |
void FeepingCreaturism::daily() |
134 |
> |
void FeepingCreaturism::daily(const ext::String& date) |
135 |
|
{ |
136 |
|
std::time_t when(std::time(NULL)); |
137 |
< |
std::tm* now(std::localtime(&when)); |
137 |
> |
std::tm* day(std::localtime(&when)); |
138 |
> |
|
139 |
> |
day->tm_sec = 0; |
140 |
> |
day->tm_min = 0; |
141 |
> |
day->tm_hour = 0; |
142 |
|
|
143 |
< |
now->tm_sec = 0; |
136 |
< |
now->tm_min = 0; |
137 |
< |
now->tm_hour = 0; |
143 |
> |
if (!date.IsEmpty()) ::strptime(date.NullTerminate(), "%Y-%m-%d", day); |
144 |
|
|
145 |
< |
std::time_t difference(mktime(now) / 86400); |
145 |
> |
std::time_t difference(mktime(day) / 86400); |
146 |
|
std::vector<ext::String> jargon(this->jargon.begin(), this->jargon.end()); |
147 |
|
ext::String entry(jargon.size() ? jargon[difference % jargon.size()] : ""); |
148 |
|
|
149 |
|
select(entry); |
150 |
|
} |
151 |
|
|
152 |
< |
void FeepingCreaturism::random() |
152 |
> |
void FeepingCreaturism::random(const ext::String& number) |
153 |
|
{ |
154 |
|
::srandomdev(); |
155 |
|
|
156 |
|
std::vector<ext::String> jargon(this->jargon.begin(), this->jargon.end()); |
157 |
< |
ext::String entry(jargon.size() ? jargon[::random() % jargon.size()] : ""); |
157 |
> |
std::vector<ext::String>::size_type random(number.IsEmpty() ? ::random() : |
158 |
> |
lexical_cast<std::vector<ext::String>::size_type>(number)); |
159 |
> |
|
160 |
> |
assert(random >= 0); |
161 |
> |
assert(random % jargon.size() < jargon.size()); |
162 |
> |
|
163 |
> |
ext::String entry(jargon.size() ? jargon[random % jargon.size()] : ""); |
164 |
|
|
165 |
|
select(entry); |
166 |
|
} |
171 |
|
{ |
172 |
|
api::Cout << "Content-Type: text/html; charset=UTF-8\r\n\r\n"; |
173 |
|
|
174 |
< |
_M::iterator include(cgi.find("include")); |
174 |
> |
Jargon jargon(path + "/" + selection, cgi.find("include") != cgi.end() |
175 |
> |
&& lexical_cast<bool>(ext::String(cgi.find("include")->second)), |
176 |
> |
cgi.find("relative") != cgi.end() |
177 |
> |
? ext::String(cgi.find("relative")->second) : ext::String()); |
178 |
|
|
179 |
< |
if (include != cgi.end()) |
165 |
< |
{ |
166 |
< |
Jargon jargon(path + "/" + selection, |
167 |
< |
lexical_cast<bool>(include->second)); |
168 |
< |
|
169 |
< |
api::Cout << jargon; |
170 |
< |
} |
171 |
< |
else |
172 |
< |
{ |
173 |
< |
Jargon jargon(path + "/" + selection); |
174 |
< |
|
175 |
< |
api::Cout << jargon; |
176 |
< |
} |
179 |
> |
api::Cout << jargon; |
180 |
|
} |
181 |
|
else |
182 |
|
{ |