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

61 lines
1.6 KiB
C
Raw Normal View History

2016-08-21 15:02:18 +10:00
#if defined(ENABLE_WWW)
#include <time.h>
#include <stdlib.h>
#include <string.h>
2016-08-21 15:02:18 +10:00
#include "bbs.h"
extern struct bbs_config conf;
char *www_last10() {
size_t n = 0;
stralloc page = EMPTY_STRALLOC;
2016-08-21 15:02:18 +10:00
struct last10_callers callers[10];
2018-10-18 21:03:52 +10:00
char last10_path[PATH_MAX];
2016-08-21 15:02:18 +10:00
2018-10-18 21:03:52 +10:00
snprintf(last10_path, PATH_MAX, "%s/last10v2.dat", conf.bbs_path);
FILE *fptr = fopen(last10_path, "rb");
2016-08-21 15:02:18 +10:00
if (fptr != NULL) {
for (; n < 10; ++n)
if (fread(&callers[n], sizeof(callers[n]), 1, fptr) != 1)
2016-08-21 15:02:18 +10: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 12:09:50 +10:00
}
stralloc_cats(&page, "</div>\n");
2016-08-21 15:02:18 +10:00
}
stralloc_cats(&page, "</div>\n");
stralloc_0(&page);
return page.s;
2016-08-21 15:02:18 +10:00
}
#endif