Improvements to www_tree and move over last 10
This commit is contained in:
parent
fc590d9608
commit
71b465eba2
@ -9,7 +9,6 @@
|
|||||||
extern struct bbs_config conf;
|
extern struct bbs_config conf;
|
||||||
|
|
||||||
char *www_blog() {
|
char *www_blog() {
|
||||||
//stralloc page = EMPTY_STRALLOC;
|
|
||||||
struct ptr_vector entries = blog_load();
|
struct ptr_vector entries = blog_load();
|
||||||
struct www_tag *page;
|
struct www_tag *page;
|
||||||
struct www_tag *cur_tag;
|
struct www_tag *cur_tag;
|
||||||
|
@ -4,15 +4,22 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "www_tree.h"
|
||||||
#include "bbs.h"
|
#include "bbs.h"
|
||||||
|
|
||||||
extern struct bbs_config conf;
|
extern struct bbs_config conf;
|
||||||
|
|
||||||
char *www_last10() {
|
char *www_last10() {
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
stralloc page = EMPTY_STRALLOC;
|
//stralloc page = EMPTY_STRALLOC;
|
||||||
struct last10_callers callers[10];
|
struct last10_callers callers[10];
|
||||||
char last10_path[PATH_MAX];
|
char last10_path[PATH_MAX];
|
||||||
|
struct www_tag *page;
|
||||||
|
struct www_tag *cur_tag;
|
||||||
|
struct www_tag *child_tag;
|
||||||
|
struct www_tag *child_child_tag;
|
||||||
|
struct www_tag *child_child_child_tag;
|
||||||
|
|
||||||
|
|
||||||
snprintf(last10_path, PATH_MAX, "%s/last10v2.dat", conf.bbs_path);
|
snprintf(last10_path, PATH_MAX, "%s/last10v2.dat", conf.bbs_path);
|
||||||
|
|
||||||
@ -24,37 +31,77 @@ char *www_last10() {
|
|||||||
fclose(fptr);
|
fclose(fptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
stralloc_copys(&page, "<div class=\"content-header\"><h2>Last 10 Callers</h2></div>\n");
|
page = www_tag_new(NULL, "");
|
||||||
stralloc_cats(&page, "<div class=\"div-table\">\n");
|
cur_tag = www_tag_new("div", NULL);
|
||||||
|
www_tag_add_attrib(cur_tag, "class", "content-header");
|
||||||
|
www_tag_add_child(page, cur_tag);
|
||||||
|
|
||||||
|
child_tag = www_tag_new("h2", NULL);
|
||||||
|
www_tag_add_child(cur_tag, child_tag);
|
||||||
|
|
||||||
|
child_child_tag = www_tag_new(NULL, "Last 10 Callers");
|
||||||
|
www_tag_add_child(child_tag, child_child_tag);
|
||||||
|
|
||||||
|
cur_tag = www_tag_new("div", NULL);
|
||||||
|
www_tag_add_attrib(cur_tag, "class", "div-table");
|
||||||
|
www_tag_add_child(page, cur_tag);
|
||||||
|
|
||||||
for (size_t i = 0; i < n; ++i) {
|
for (size_t i = 0; i < n; ++i) {
|
||||||
struct tm called;
|
struct tm called;
|
||||||
char buffer[32];
|
char buffer[32];
|
||||||
|
|
||||||
stralloc_cats(&page, "<div class=\"last10-row\"><div class=\"last10-name\">");
|
child_tag = www_tag_new("div", NULL);
|
||||||
stralloc_cats(&page, callers[i].name);
|
www_tag_add_attrib(child_tag, "class", "last10-row");
|
||||||
stralloc_cats(&page, "</div><div class=\"last10-location\">");
|
www_tag_add_child(cur_tag, child_tag);
|
||||||
stralloc_cats(&page, callers[i].location);
|
|
||||||
stralloc_cats(&page, "</div>");
|
child_child_tag = www_tag_new("div", NULL);
|
||||||
stralloc_cats(&page, "<div class=\"last10-date\">");
|
www_tag_add_attrib(child_child_tag, "class", "last10-name");
|
||||||
|
www_tag_add_child(child_tag, child_child_tag);
|
||||||
|
|
||||||
|
child_child_child_tag = www_tag_new(NULL, callers[i].name);
|
||||||
|
www_tag_add_child(child_child_tag, child_child_child_tag);
|
||||||
|
|
||||||
|
|
||||||
|
child_child_tag = www_tag_new("div", NULL);
|
||||||
|
www_tag_add_attrib(child_child_tag, "class", "last10-location");
|
||||||
|
www_tag_add_child(child_tag, child_child_tag);
|
||||||
|
|
||||||
|
child_child_child_tag = www_tag_new(NULL, callers[i].location);
|
||||||
|
www_tag_add_child(child_child_tag, child_child_child_tag);
|
||||||
|
|
||||||
|
child_child_tag = www_tag_new("div", NULL);
|
||||||
|
www_tag_add_attrib(child_child_tag, "class", "last10-date");
|
||||||
|
www_tag_add_child(child_tag, child_child_tag);
|
||||||
|
|
||||||
localtime_r(&callers[i].time, &called);
|
localtime_r(&callers[i].time, &called);
|
||||||
if (conf.date_style == 1)
|
if (conf.date_style == 1)
|
||||||
strftime(buffer, sizeof buffer, "%H:%M %m-%d-%y", &called);
|
strftime(buffer, sizeof buffer, "%H:%M %m-%d-%y", &called);
|
||||||
else
|
else
|
||||||
strftime(buffer, sizeof buffer, "%H:%M %d-%m-%y", &called);
|
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>");
|
|
||||||
}
|
|
||||||
stralloc_cats(&page, "</div>\n");
|
|
||||||
}
|
|
||||||
stralloc_cats(&page, "</div>\n");
|
|
||||||
stralloc_0(&page);
|
|
||||||
|
|
||||||
return page.s;
|
child_child_child_tag = www_tag_new(NULL, buffer);
|
||||||
|
www_tag_add_child(child_child_tag, child_child_child_tag);
|
||||||
|
|
||||||
|
if (callers[i].calls == 1) {
|
||||||
|
child_child_tag = www_tag_new("div", NULL);
|
||||||
|
www_tag_add_attrib(child_child_tag, "class", "last10-new");
|
||||||
|
www_tag_add_child(child_tag, child_child_tag);
|
||||||
|
|
||||||
|
|
||||||
|
stralloc url = EMPTY_STRALLOC;
|
||||||
|
|
||||||
|
stralloc_copys(&url, conf.www_url);
|
||||||
|
stralloc_cats(&url, "static/newuser.png");
|
||||||
|
stralloc_0(&url);
|
||||||
|
|
||||||
|
child_child_child_tag = www_tag_new("img", NULL);
|
||||||
|
www_tag_add_attrib(child_child_child_tag, "src", url.s);
|
||||||
|
free(url.s);
|
||||||
|
www_tag_add_child(child_child_tag, child_child_child_tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return www_tag_unwravel(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -59,44 +59,63 @@ void www_tag_add_child(struct www_tag *tag, struct www_tag *child) {
|
|||||||
|
|
||||||
char *www_tag_unwravel(struct www_tag *tag) {
|
char *www_tag_unwravel(struct www_tag *tag) {
|
||||||
stralloc thedata = EMPTY_STRALLOC;
|
stralloc thedata = EMPTY_STRALLOC;
|
||||||
|
int children = tag->children.len;
|
||||||
while (tag->children.len > 0) {
|
while (tag->children.len > 0) {
|
||||||
struct www_tag *child = ptr_vector_del(&tag->children, 0);
|
struct www_tag *child = ptr_vector_del(&tag->children, 0);
|
||||||
if (child->tag != NULL) {
|
if (child->children.len > 0) {
|
||||||
stralloc_append1(&thedata, '<');
|
if (child->tag != NULL) {
|
||||||
stralloc_cats(&thedata, child->tag);
|
stralloc_append1(&thedata, '<');
|
||||||
for (int i = 0; i < child->attribs.len; i++) {
|
stralloc_cats(&thedata, child->tag);
|
||||||
stralloc_append1(&thedata, ' ');
|
for (int i = 0; i < child->attribs.len; i++) {
|
||||||
stralloc_cats(&thedata, (char *)ptr_vector_get(&child->attribs, i));
|
stralloc_append1(&thedata, ' ');
|
||||||
stralloc_append1(&thedata, '=');
|
stralloc_cats(&thedata, (char *)ptr_vector_get(&child->attribs, i));
|
||||||
stralloc_append1(&thedata, '\"');
|
stralloc_append1(&thedata, '=');
|
||||||
stralloc_cats(&thedata, (char *)ptr_vector_get(&child->values, i));
|
stralloc_append1(&thedata, '\"');
|
||||||
stralloc_append1(&thedata, '\"');
|
stralloc_cats(&thedata, (char *)ptr_vector_get(&child->values, i));
|
||||||
|
stralloc_append1(&thedata, '\"');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
stralloc_append1(&thedata, '>');
|
||||||
}
|
}
|
||||||
|
char *data = www_tag_unwravel(child);
|
||||||
|
stralloc_cats(&thedata, data);
|
||||||
|
free(data);
|
||||||
|
|
||||||
|
if (child->tag != NULL) {
|
||||||
stralloc_append1(&thedata, '>');
|
stralloc_cats(&thedata, "</");
|
||||||
}
|
stralloc_cats(&thedata, child->tag);
|
||||||
char *data = www_tag_unwravel(child);
|
stralloc_append1(&thedata, '>');
|
||||||
stralloc_cats(&thedata, data);
|
ptr_vector_apply(&child->attribs, free);
|
||||||
free(data);
|
destroy_ptr_vector(&child->attribs);
|
||||||
|
ptr_vector_apply(&child->values, free);
|
||||||
if (child->tag != NULL) {
|
destroy_ptr_vector(&child->values);
|
||||||
stralloc_cats(&thedata, "</");
|
}
|
||||||
stralloc_cats(&thedata, child->tag);
|
} else {
|
||||||
stralloc_append1(&thedata, '>');
|
if (child->tag != NULL) {
|
||||||
ptr_vector_apply(&child->attribs, free);
|
stralloc_append1(&thedata, '<');
|
||||||
destroy_ptr_vector(&child->attribs);
|
stralloc_cats(&thedata, child->tag);
|
||||||
ptr_vector_apply(&child->values, free);
|
for (int i = 0; i < child->attribs.len; i++) {
|
||||||
destroy_ptr_vector(&child->values);
|
stralloc_append1(&thedata, ' ');
|
||||||
|
stralloc_cats(&thedata, (char *)ptr_vector_get(&child->attribs, i));
|
||||||
|
stralloc_append1(&thedata, '=');
|
||||||
|
stralloc_append1(&thedata, '\"');
|
||||||
|
stralloc_cats(&thedata, (char *)ptr_vector_get(&child->values, i));
|
||||||
|
stralloc_append1(&thedata, '\"');
|
||||||
|
}
|
||||||
|
stralloc_cats(&thedata, " />");
|
||||||
|
ptr_vector_apply(&child->attribs, free);
|
||||||
|
destroy_ptr_vector(&child->attribs);
|
||||||
|
ptr_vector_apply(&child->values, free);
|
||||||
|
destroy_ptr_vector(&child->values);
|
||||||
|
} else {
|
||||||
|
stralloc_cats(&thedata, child->data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
destroy_ptr_vector(&child->children);
|
destroy_ptr_vector(&child->children);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag->data != NULL) {
|
|
||||||
stralloc_cats(&thedata, tag->data);
|
|
||||||
}
|
|
||||||
stralloc_0(&thedata);
|
stralloc_0(&thedata);
|
||||||
|
|
||||||
return thedata.s;
|
return thedata.s;
|
||||||
|
Reference in New Issue
Block a user