1 |
<?php
|
2 |
//********************************************************************************
|
3 |
//Copyright (C) 2007 David T. Ashley
|
4 |
//********************************************************************************
|
5 |
//This program or source file is free software; you can redistribute it and/or
|
6 |
//modify it under the terms of the GNU Lesser General Public License as published
|
7 |
//by the Free Software Foundation; either version 2 of the License, or (at your
|
8 |
//option) any later version.
|
9 |
//
|
10 |
//This program or source file is distributed in the hope that it will
|
11 |
//be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
//GNU General Public License for more details.
|
14 |
//
|
15 |
//You may have received a copy of the GNU Lesser General Public License
|
16 |
//along with this program; if not, write to the Free Software
|
17 |
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18 |
//********************************************************************************
|
19 |
//
|
20 |
//Obtains a data snapshot used for outputting web page
|
21 |
//statistics at the end of a page. This should be the first
|
22 |
//function call made. The data format is not proprietary (i.e.
|
23 |
//the caller is conceptually free to pick it apart).
|
24 |
//
|
25 |
function STDFORMAT_page_begin_snapshot()
|
26 |
{
|
27 |
$rv['time_rv'] = time();
|
28 |
$rv['getrusage_rv'] = getrusage();
|
29 |
return($rv);
|
30 |
}
|
31 |
|
32 |
//Returns the complete top portion of a web page as a string,
|
33 |
//formatted with newlines for human readability.
|
34 |
//
|
35 |
function STDFORMAT_page_top($in_snapshot,
|
36 |
$in_htmldeclaredtitle,
|
37 |
$in_htmlselfdonetitle,
|
38 |
$in_background,
|
39 |
$in_link,
|
40 |
$in_vlink,
|
41 |
$in_alink)
|
42 |
{
|
43 |
$rv = "<html>\n";
|
44 |
$rv .= "<head>\n";
|
45 |
$rv .= "<title>" . $in_htmldeclaredtitle . "</title>\n";
|
46 |
$rv .= "</head>\n";
|
47 |
$rv .= STDFORMAT_body_tag($in_background, $in_link, $in_vlink, $in_alink) . "\n";
|
48 |
$rv .= STDFORMAT_default_font_tag() . "\n";
|
49 |
$rv .= "<p align=\"center\">\n";
|
50 |
$rv .= "<font size=\"5\">\n";
|
51 |
$rv .= "<b>" . $in_htmlselfdonetitle . "</b>\n";
|
52 |
$rv .= "</font>\n";
|
53 |
$rv .= "</p>\n";
|
54 |
$rv .= STDFORMAT_hline_thin() . "\n";
|
55 |
|
56 |
return($rv);
|
57 |
}
|
58 |
|
59 |
|
60 |
//Returns the Google AdSense bottom banner that appears on most pages. All
|
61 |
//HTML is balanced and no other material is provided.
|
62 |
//
|
63 |
function STDFORMAT_advertising_bottom()
|
64 |
{
|
65 |
$rv = "<p align=\"center\">\n"
|
66 |
.
|
67 |
"<table border=\"0\" width=\"80%\">\n"
|
68 |
.
|
69 |
"<tr>\n"
|
70 |
.
|
71 |
"<td align=\"left\">\n"
|
72 |
.
|
73 |
"<script type=\"text/javascript\"><!--\n"
|
74 |
.
|
75 |
"google_ad_client = \"pub-0968676922395080\";\n"
|
76 |
.
|
77 |
"/* UCULIB, Left Bottom */\n"
|
78 |
.
|
79 |
"google_ad_slot = \"7493291831\";\n"
|
80 |
.
|
81 |
"google_ad_width = 300;\n"
|
82 |
.
|
83 |
"google_ad_height = 250;\n"
|
84 |
.
|
85 |
"//-->\n"
|
86 |
.
|
87 |
"</script>\n"
|
88 |
.
|
89 |
"<script type=\"text/javascript\"\n"
|
90 |
.
|
91 |
"src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">\n"
|
92 |
.
|
93 |
"</script>\n"
|
94 |
.
|
95 |
"</td>\n"
|
96 |
.
|
97 |
"<td align=\"center\">\n"
|
98 |
.
|
99 |
"<script type=\"text/javascript\"><!--\n"
|
100 |
.
|
101 |
"google_ad_client = \"pub-0968676922395080\";\n"
|
102 |
.
|
103 |
"/* UCULIB, Center Bottom */\n"
|
104 |
.
|
105 |
"google_ad_slot = \"1148830860\";\n"
|
106 |
.
|
107 |
"google_ad_width = 300;\n"
|
108 |
.
|
109 |
"google_ad_height = 250;\n"
|
110 |
.
|
111 |
"//-->\n"
|
112 |
.
|
113 |
"</script>\n"
|
114 |
.
|
115 |
"<script type=\"text/javascript\"\n"
|
116 |
.
|
117 |
"src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">\n"
|
118 |
.
|
119 |
"</script>\n"
|
120 |
.
|
121 |
"</td>\n"
|
122 |
.
|
123 |
"<td align=\"right\">\n"
|
124 |
.
|
125 |
"<script type=\"text/javascript\"><!--\n"
|
126 |
.
|
127 |
"google_ad_client = \"pub-0968676922395080\";\n"
|
128 |
.
|
129 |
"/* UCULIB, Right Bottom */\n"
|
130 |
.
|
131 |
"google_ad_slot = \"7526152668\";\n"
|
132 |
.
|
133 |
"google_ad_width = 300;\n"
|
134 |
.
|
135 |
"google_ad_height = 250;\n"
|
136 |
.
|
137 |
"//-->\n"
|
138 |
.
|
139 |
"</script>\n"
|
140 |
.
|
141 |
"<script type=\"text/javascript\"\n"
|
142 |
.
|
143 |
"src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">\n"
|
144 |
.
|
145 |
"</script>\n"
|
146 |
.
|
147 |
"</td>\n"
|
148 |
.
|
149 |
"</tr>\n"
|
150 |
.
|
151 |
"</table>\n"
|
152 |
.
|
153 |
"</p>\n"
|
154 |
;
|
155 |
return($rv);
|
156 |
}
|
157 |
|
158 |
|
159 |
//Returns the complete bottom portion of a web page. This starts
|
160 |
//from the horizontal line delineating the footer and moves downward.
|
161 |
//Newlines are included for human-friendly reading.
|
162 |
//
|
163 |
function STDFORMAT_page_bottom($in_snapshot)
|
164 |
{
|
165 |
//Make the second call to get more resource usage data, which will be
|
166 |
//used to display system and user time consumed.
|
167 |
$ru2 = getrusage();
|
168 |
|
169 |
$rv = STDFORMAT_std_footer($in_snapshot['time_rv'], $ru2, $in_snapshot['getrusage_rv']);
|
170 |
|
171 |
$rv .= "</font>\n";
|
172 |
$rv .= "</body>\n";
|
173 |
$rv .= "</html>\n";
|
174 |
return($rv);
|
175 |
}
|
176 |
|
177 |
//Returns the HTML for the standard footer of a web page, including top
|
178 |
//and bottom horizontal lines. All HTML is balanced. Newlines
|
179 |
//are provided for human readability of the HTML.
|
180 |
//
|
181 |
function STDFORMAT_std_footer($in_time, $in_ru2, $in_ru1)
|
182 |
{
|
183 |
$rv = STDFORMAT_hline_thin() . "\n";
|
184 |
$rv .= "<font size=\"2\">\n";
|
185 |
$rv .= "<p align=\"center\" style=\"margin-top:0; margin-bottom:0\">\n";
|
186 |
$rv = $rv . STDFORMAT_std_footer_text($in_time, $in_ru2, $in_ru1);
|
187 |
$rv .= "</p>\n";
|
188 |
$rv .= "</font>\n";
|
189 |
$rv .= STDFORMAT_hline_thick() . "\n";
|
190 |
return($rv);
|
191 |
}
|
192 |
|
193 |
//Returns the HTML for the text occurring in the standard footer of a web page,
|
194 |
//with no newlines or preceding horizontal lines or following horizontal lines.
|
195 |
//No HTML formatting codes are used.
|
196 |
//
|
197 |
function STDFORMAT_std_footer_text($in_time, $in_ru2, $in_ru1)
|
198 |
{
|
199 |
//Figure out the total, system, and user time to generate.
|
200 |
STDFORMAT_getrusagediff($in_ru2, $in_ru1, $out_totaltime, $out_systime, $out_usertime);
|
201 |
|
202 |
$rv = "This web page was obtained from the server at ";
|
203 |
$rv .= date("H:i:s", $in_time)
|
204 |
. " on "
|
205 |
. date("l, ", $in_time)
|
206 |
. date("F j, Y", $in_time)
|
207 |
. " (UTC " . date("O", $in_time)
|
208 |
. ", server time), and required approximately " . $out_totaltime . "s CPU time (" . $out_systime . "s system, "
|
209 |
. $out_usertime . "s user) to generate. ";
|
210 |
$rv .= "Please contact <a href=\"mailto:"
|
211 |
. STDFORMAT_webmaster_email()
|
212 |
. "\">" . STDFORMAT_webmaster_name() . "</a> with any feedback about this "
|
213 |
. "web page.\n";
|
214 |
return($rv);
|
215 |
}
|
216 |
|
217 |
//Returns the <body> HTML tag for a standard web page, which includes the
|
218 |
//link colors (on demand) and specification of the background to
|
219 |
//use. No newline is included.
|
220 |
//
|
221 |
//The caller may optionally override the background and may also
|
222 |
//optionally override the link, vlink, and alink specification.
|
223 |
//For these specifications:
|
224 |
// "" means use the default.
|
225 |
// FALSE means don't specify them in the body.
|
226 |
// Any other value means use that instead.
|
227 |
//
|
228 |
function STDFORMAT_body_tag($in_background, $in_link, $in_vlink, $in_alink)
|
229 |
{
|
230 |
$rv = "<body";
|
231 |
|
232 |
if ($in_background === "")
|
233 |
{
|
234 |
//Default
|
235 |
//
|
236 |
$rv .= " background=\"/bkgnds/bk_garlic.jpg\"";
|
237 |
}
|
238 |
else if ($in_background !== FALSE)
|
239 |
{
|
240 |
//Use the passed specification instead.
|
241 |
$rv .= (" background=\"" . $in_background . "\"");
|
242 |
}
|
243 |
else
|
244 |
{
|
245 |
//Don't include it.
|
246 |
}
|
247 |
|
248 |
if ($in_link === "")
|
249 |
{
|
250 |
//Default
|
251 |
//
|
252 |
$rv .= " link=\"#4040C0\"";
|
253 |
}
|
254 |
else if ($in_link !== FALSE)
|
255 |
{
|
256 |
//Use the passed specification instead.
|
257 |
$rv .= (" link=\"" . $in_link . "\"");
|
258 |
}
|
259 |
else
|
260 |
{
|
261 |
//Don't include it.
|
262 |
}
|
263 |
|
264 |
if ($in_vlink === "")
|
265 |
{
|
266 |
//Default
|
267 |
//
|
268 |
$rv .= " vlink=\"#4040C0\"";
|
269 |
}
|
270 |
else if ($in_vlink !== FALSE)
|
271 |
{
|
272 |
//Use the passed specification instead.
|
273 |
$rv .= (" vlink=\"" . $in_vlink . "\"");
|
274 |
}
|
275 |
else
|
276 |
{
|
277 |
//Don't include it.
|
278 |
}
|
279 |
|
280 |
if ($in_alink === "")
|
281 |
{
|
282 |
//Default
|
283 |
//
|
284 |
$rv .= " alink=\"#4040C0\"";
|
285 |
}
|
286 |
else if ($in_alink !== FALSE)
|
287 |
{
|
288 |
//Use the passed specification instead.
|
289 |
$rv .= (" alink=\"" . $in_alink . "\"");
|
290 |
}
|
291 |
else
|
292 |
{
|
293 |
//Don't include it.
|
294 |
}
|
295 |
|
296 |
$rv .= ">";
|
297 |
|
298 |
return($rv);
|
299 |
}
|
300 |
|
301 |
//Returns the system time and user time, as strings in seconds,
|
302 |
//corresponding to the difference between the first getrusage()
|
303 |
//call and the second getrusage() call.
|
304 |
//
|
305 |
function STDFORMAT_getrusagediff($in_ru_second, $in_ru_first, &$out_totaltime, &$out_systime, &$out_usertime)
|
306 |
{
|
307 |
//echo "\n";
|
308 |
//echo print_r($in_ru_first);
|
309 |
//echo "\n";
|
310 |
//echo print_r($in_ru_second);
|
311 |
//echo "\n";
|
312 |
|
313 |
//System time.
|
314 |
//
|
315 |
if ($in_ru_second['ru_stime.tv_usec'] >= $in_ru_first['ru_stime.tv_usec'])
|
316 |
{
|
317 |
//Can do a straight subtract with no borrow.
|
318 |
$systime_secs = $in_ru_second['ru_stime.tv_sec'] - $in_ru_first['ru_stime.tv_sec'];
|
319 |
$systime_usecs = $in_ru_second['ru_stime.tv_usec'] - $in_ru_first['ru_stime.tv_usec'];
|
320 |
}
|
321 |
else
|
322 |
{
|
323 |
//Need a borrow.
|
324 |
$systime_secs = $in_ru_second['ru_stime.tv_sec'] - $in_ru_first['ru_stime.tv_sec'] - 1;
|
325 |
$systime_usecs = 1000000 + $in_ru_second['ru_stime.tv_usec'] - $in_ru_first['ru_stime.tv_usec'];
|
326 |
}
|
327 |
|
328 |
$system_time_string = (string)$systime_usecs;
|
329 |
while (strlen($system_time_string) < 6)
|
330 |
{
|
331 |
$system_time_string = "0" . $system_time_string;
|
332 |
}
|
333 |
|
334 |
$system_time_string = (string)$systime_secs . "." . $system_time_string;
|
335 |
|
336 |
//User time.
|
337 |
//
|
338 |
if ($in_ru_second['ru_utime.tv_usec'] >= $in_ru_first['ru_utime.tv_usec'])
|
339 |
{
|
340 |
//Can do a straight subtract with no borrow.
|
341 |
$usertime_secs = $in_ru_second['ru_utime.tv_sec'] - $in_ru_first['ru_utime.tv_sec'];
|
342 |
$usertime_usecs = $in_ru_second['ru_utime.tv_usec'] - $in_ru_first['ru_utime.tv_usec'];
|
343 |
}
|
344 |
else
|
345 |
{
|
346 |
//Need a borrow.
|
347 |
$usertime_secs = $in_ru_second['ru_utime.tv_sec'] - $in_ru_first['ru_utime.tv_sec'] - 1;
|
348 |
$usertime_usecs = 1000000 + $in_ru_second['ru_utime.tv_usec'] - $in_ru_first['ru_utime.tv_usec'];
|
349 |
}
|
350 |
|
351 |
$user_time_string = (string)$usertime_usecs;
|
352 |
while (strlen($user_time_string) < 6)
|
353 |
{
|
354 |
$user_time_string = "0" . $user_time_string;
|
355 |
}
|
356 |
|
357 |
$user_time_string = (string)$usertime_secs . "." . $user_time_string;
|
358 |
|
359 |
//Total time.
|
360 |
//
|
361 |
$totaltime_usecs = $systime_usecs + $usertime_usecs;
|
362 |
$totaltime_secs = $systime_secs + $usertime_secs;
|
363 |
if ($totaltime_usecs >= 1000000)
|
364 |
{
|
365 |
$totaltime_usecs -= 1000000;
|
366 |
$totaltime_secs += 1;
|
367 |
}
|
368 |
|
369 |
$total_time_string = (string)$totaltime_usecs;
|
370 |
while (strlen($total_time_string) < 6)
|
371 |
{
|
372 |
$total_time_string = "0" . $total_time_string;
|
373 |
}
|
374 |
|
375 |
$total_time_string = (string)$totaltime_secs . "." . $total_time_string;
|
376 |
|
377 |
|
378 |
$out_totaltime = $total_time_string;
|
379 |
$out_systime = $system_time_string;
|
380 |
$out_usertime = $user_time_string;
|
381 |
}
|
382 |
|
383 |
//Returns the HTML for a thin horizontal line, with no terminating newline or
|
384 |
//similar.
|
385 |
//
|
386 |
function STDFORMAT_hline_thin()
|
387 |
{
|
388 |
return("<hr size=\"1\" style=\"color:#404040\">");
|
389 |
}
|
390 |
|
391 |
//Returns the HTML for a thick horizontal line, with no terminating newline or
|
392 |
//similar.
|
393 |
//
|
394 |
function STDFORMAT_hline_thick()
|
395 |
{
|
396 |
return("<hr size=\"4\" style=\"color:#404040\">");
|
397 |
}
|
398 |
|
399 |
//Returns the <font> tag corresponding to the desired default font,
|
400 |
//with no newline.
|
401 |
//
|
402 |
function STDFORMAT_default_font_tag()
|
403 |
{
|
404 |
return("<font face=\"arial\">");
|
405 |
}
|
406 |
|
407 |
//Returns the webmaster name as a string, with no terminating newlines
|
408 |
//or similar.
|
409 |
//
|
410 |
function STDFORMAT_webmaster_name()
|
411 |
{
|
412 |
return("David T. Ashley");
|
413 |
}
|
414 |
|
415 |
//Returns the webmaster e-mail address as a string, with no terminating newlines
|
416 |
//or similar.
|
417 |
//
|
418 |
function STDFORMAT_webmaster_email()
|
419 |
{
|
420 |
return("dashley@gmail.com");
|
421 |
}
|
422 |
?>
|