diff --git a/src/www_files.c b/src/www_files.c index 5274d90..8886da2 100644 --- a/src/www_files.c +++ b/src/www_files.c @@ -296,8 +296,14 @@ char *www_create_link(int dir, int sub, int fid) { } char *www_files_display_listing(int dir, int sub) { static const char *sql = "select id, filename, description, size, dlcount, uploaddate from files where approved=1 ORDER BY filename"; - - stralloc page = EMPTY_STRALLOC; + struct www_tag *page = www_tag_new(NULL, ""); + struct www_tag *cur_tag; + struct www_tag *child_tag; + struct www_tag *child_child_tag; + struct www_tag *child_child_child_tag; + struct www_tag *child_child_child_child_tag; + struct www_tag *child_child_child_child_child_tag; + //stralloc page = EMPTY_STRALLOC; char pathbuf[PATH_MAX]; sqlite3 *db = NULL; sqlite3_stmt *res = NULL; @@ -312,43 +318,107 @@ char *www_files_display_listing(int dir, int sub) { struct file_sub *fsub = ptr_vector_get(&fdir->file_subs, sub); assert(fsub != NULL); - stralloc_copys(&page, "
Filename | Size | Description |
"); - stralloc_cats(&page, base_filename); - stralloc_cats(&page, " | "); + child_child_tag = www_tag_new("tr", NULL); + www_tag_add_child(child_tag, child_child_tag); + + child_child_child_tag = www_tag_new("td", NULL); + www_tag_add_attrib(child_child_child_tag, "class", "filename"); + www_tag_add_child(child_child_tag, child_child_child_tag); + + child_child_child_child_tag = www_tag_new("a", NULL); + www_tag_add_child(child_child_child_tag, child_child_child_child_tag); + + stralloc url = EMPTY_STRALLOC; + + stralloc_cats(&url, conf.www_url); + stralloc_cats(&url, "files/areas/"); + stralloc_cat_long(&url, dir); + stralloc_append1(&url, '/'); + stralloc_cat_long(&url, sub); + stralloc_append1(&url, '/'); + www_encode(&url, base_filename); + + stralloc_0(&url); + + www_tag_add_attrib(child_child_child_child_tag, "href", url.s); + free(url.s); + + child_child_child_child_child_tag = www_tag_new(NULL, base_filename); + www_tag_add_child(child_child_child_child_tag, child_child_child_child_child_tag); int size = sqlite3_column_int(res, 3); - stralloc_cats(&page, ""); + child_child_child_tag = www_tag_new("td", NULL); + www_tag_add_attrib(child_child_child_tag, "class", "filesize"); + www_tag_add_child(child_child_tag, child_child_child_tag); + int c = 'b'; if (size > 1024) { size /= 1024; @@ -362,64 +432,92 @@ char *www_files_display_listing(int dir, int sub) { size /= 1024; c = 'G'; } - stralloc_cat_long(&page, size); - stralloc_append1(&page, c); - stralloc_cats(&page, " | "); + + stralloc size_str = EMPTY_STRALLOC; + + stralloc_cat_long(&size_str, size); + stralloc_append1(&size_str, c); - stralloc_cats(&page, ""); + child_child_child_child_tag = www_tag_new(NULL, size_str.s); + www_tag_add_child(child_child_child_tag, child_child_child_child_tag); + free(size_str.s); + + child_child_child_tag = www_tag_new("td", NULL); + www_tag_add_attrib(child_child_child_tag, "class", "filedesc"); + www_tag_add_child(child_child_tag, child_child_child_tag); + char *description = strdup((char *)sqlite3_column_text(res, 2)); for (char *p = description; *p != '\0'; ++p) { if (*p == '\n') *p = '\r'; } - struct www_tag *aha_out = www_tag_new(NULL, ""); - aha(description, aha_out); - - char *aha_data = www_tag_unwravel(aha_out); - - stralloc_cats(&page, aha_data); - free(aha_data); + aha(description, child_child_child_tag); + free(description); free(filename); - - stralloc_cats(&page, " |