This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
magicka/src/www_last10.c

58 lines
1.5 KiB
C
Raw Normal View History

2016-08-21 05:02:18 +00:00
#if defined(ENABLE_WWW)
#include <time.h>
#include <stdlib.h>
#include <string.h>
2016-08-21 05:02:18 +00:00
#include "bbs.h"
extern struct bbs_config conf;
char *www_last10() {
size_t n = 0;
stralloc page = EMPTY_STRALLOC;
2016-08-21 05:02:18 +00:00
struct last10_callers callers[10];
2018-02-25 06:25:53 +00:00
FILE *fptr = fopen("last10v2.dat", "rb");
2016-08-21 05:02:18 +00:00
if (fptr != NULL) {
for ( ; n < 10; ++n)
if (fread(&callers[n], sizeof(callers[n]), 1, fptr) != sizeof(callers[n]))
2016-08-21 05:02:18 +00:00
break;
fclose(fptr);
}
stralloc_copys(&page, "<div class=\"content-header\"><h2>Last 10 Callers</h2></div>\n");
stralloc_cats(&page, "<div class=\"div-table\">\n");
for (size_t i = 0; i < n; ++i) {
struct tm called;
char buffer[32];
stralloc_cats(&page, "<div class=\"last10-row\"><div class=\"last10-name\">");
stralloc_cats(&page, callers[i].name);
stralloc_cats(&page, "</div><div class=\"last10-location\">");
stralloc_cats(&page, callers[i].location);
stralloc_cats(&page, "</div>");
stralloc_cats(&page, "<div class=\"last10-date\">");
localtime_r(&callers[i].time, &called);
if (conf.date_style == 1)
strftime(buffer, sizeof buffer, "%H:%M %m-%d-%y", &called);
else
strftime(buffer, sizeof buffer, "%H:%M %d-%m-%y", &called);
stralloc_cats(&page, buffer);
stralloc_cats(&page, "</div>\n");
if (callers[i].calls == 1) {
stralloc_cats(&page, "<div class=\"last10-new\"><img src=\"");
stralloc_cats(&page, conf.www_url);
stralloc_cats(&page, "static/newuser.png\" /></div>");
2017-10-03 02:09:50 +00:00
}
stralloc_cats(&page, "</div>\n");
2016-08-21 05:02:18 +00:00
}
stralloc_cats(&page, "</div>\n");
stralloc_0(&page);
return page.s;
2016-08-21 05:02:18 +00:00
}
#endif