diff options
| -rw-r--r-- | html.c | 66 |
1 files changed, 48 insertions, 18 deletions
| @@ -218,10 +218,10 @@ xs_str *html_msg_icon(xs_str *os, const xs_dict *msg) | |||
| 218 | } | 218 | } |
| 219 | 219 | ||
| 220 | 220 | ||
| 221 | xs_str *html_user_header(snac *snac, xs_str *s, int local) | 221 | xs_str *html_base_header(xs_str *s) |
| 222 | /* creates the HTML header */ | ||
| 223 | { | 222 | { |
| 224 | char *p, *v; | 223 | xs_list *p; |
| 224 | xs_str *v; | ||
| 225 | 225 | ||
| 226 | s = xs_str_cat(s, "<!DOCTYPE html>\n<html>\n<head>\n"); | 226 | s = xs_str_cat(s, "<!DOCTYPE html>\n<html>\n<head>\n"); |
| 227 | s = xs_str_cat(s, "<meta name=\"viewport\" " | 227 | s = xs_str_cat(s, "<meta name=\"viewport\" " |
| @@ -236,6 +236,25 @@ xs_str *html_user_header(snac *snac, xs_str *s, int local) | |||
| 236 | s = xs_str_cat(s, s1); | 236 | s = xs_str_cat(s, s1); |
| 237 | } | 237 | } |
| 238 | 238 | ||
| 239 | return s; | ||
| 240 | } | ||
| 241 | |||
| 242 | |||
| 243 | xs_str *html_instance_header(xs_str *s) | ||
| 244 | { | ||
| 245 | s = html_base_header(s); | ||
| 246 | |||
| 247 | s = xs_str_cat(s, "</head>\n<body>\n"); | ||
| 248 | |||
| 249 | return s; | ||
| 250 | } | ||
| 251 | |||
| 252 | |||
| 253 | xs_str *html_user_header(snac *snac, xs_str *s, int local) | ||
| 254 | /* creates the HTML header */ | ||
| 255 | { | ||
| 256 | s = html_base_header(s); | ||
| 257 | |||
| 239 | /* add the user CSS */ | 258 | /* add the user CSS */ |
| 240 | { | 259 | { |
| 241 | xs *css = NULL; | 260 | xs *css = NULL; |
| @@ -1345,7 +1364,7 @@ xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local, | |||
| 1345 | } | 1364 | } |
| 1346 | 1365 | ||
| 1347 | 1366 | ||
| 1348 | xs_str *html_user_footer(xs_str *s) | 1367 | xs_str *html_footer(xs_str *s) |
| 1349 | { | 1368 | { |
| 1350 | xs *s1 = xs_fmt( | 1369 | xs *s1 = xs_fmt( |
| 1351 | "<div class=\"snac-footer\">\n" | 1370 | "<div class=\"snac-footer\">\n" |
| @@ -1361,7 +1380,7 @@ xs_str *html_user_footer(xs_str *s) | |||
| 1361 | } | 1380 | } |
| 1362 | 1381 | ||
| 1363 | 1382 | ||
| 1364 | xs_str *html_timeline(snac *snac, const xs_list *list, int local, int skip, int show, int show_more) | 1383 | xs_str *html_timeline(snac *user, const xs_list *list, int local, int skip, int show, int show_more) |
| 1365 | /* returns the HTML for the timeline */ | 1384 | /* returns the HTML for the timeline */ |
| 1366 | { | 1385 | { |
| 1367 | xs_str *s = xs_str_new(NULL); | 1386 | xs_str *s = xs_str_new(NULL); |
| @@ -1369,26 +1388,35 @@ xs_str *html_timeline(snac *snac, const xs_list *list, int local, int skip, int | |||
| 1369 | char *v; | 1388 | char *v; |
| 1370 | double t = ftime(); | 1389 | double t = ftime(); |
| 1371 | 1390 | ||
| 1372 | s = html_user_header(snac, s, local); | 1391 | if (user) |
| 1392 | s = html_user_header(user, s, local); | ||
| 1393 | else | ||
| 1394 | s = html_instance_header(s); | ||
| 1373 | 1395 | ||
| 1374 | if (!local) | 1396 | if (user && !local) |
| 1375 | s = html_top_controls(snac, s); | 1397 | s = html_top_controls(user, s); |
| 1376 | 1398 | ||
| 1377 | s = xs_str_cat(s, "<a name=\"snac-posts\"></a>\n"); | 1399 | s = xs_str_cat(s, "<a name=\"snac-posts\"></a>\n"); |
| 1378 | s = xs_str_cat(s, "<div class=\"snac-posts\">\n"); | 1400 | s = xs_str_cat(s, "<div class=\"snac-posts\">\n"); |
| 1379 | 1401 | ||
| 1380 | while (xs_list_iter(&p, &v)) { | 1402 | while (xs_list_iter(&p, &v)) { |
| 1381 | xs *msg = NULL; | 1403 | xs *msg = NULL; |
| 1404 | int status; | ||
| 1382 | 1405 | ||
| 1383 | if (!valid_status(timeline_get_by_md5(snac, v, &msg))) | 1406 | if (user) |
| 1407 | status = timeline_get_by_md5(user, v, &msg); | ||
| 1408 | else | ||
| 1409 | status = object_get_by_md5(v, &msg); | ||
| 1410 | |||
| 1411 | if (!valid_status(status)) | ||
| 1384 | continue; | 1412 | continue; |
| 1385 | 1413 | ||
| 1386 | s = html_entry(snac, s, msg, local, 0, v, 0); | 1414 | s = html_entry(user, s, msg, local, 0, v, 0); |
| 1387 | } | 1415 | } |
| 1388 | 1416 | ||
| 1389 | s = xs_str_cat(s, "</div>\n"); | 1417 | s = xs_str_cat(s, "</div>\n"); |
| 1390 | 1418 | ||
| 1391 | if (local) { | 1419 | if (user && local) { |
| 1392 | xs *s1 = xs_fmt( | 1420 | xs *s1 = xs_fmt( |
| 1393 | "<div class=\"snac-history\">\n" | 1421 | "<div class=\"snac-history\">\n" |
| 1394 | "<p class=\"snac-history-title\">%s</p><ul>\n", | 1422 | "<p class=\"snac-history-title\">%s</p><ul>\n", |
| @@ -1397,7 +1425,7 @@ xs_str *html_timeline(snac *snac, const xs_list *list, int local, int skip, int | |||
| 1397 | 1425 | ||
| 1398 | s = xs_str_cat(s, s1); | 1426 | s = xs_str_cat(s, s1); |
| 1399 | 1427 | ||
| 1400 | xs *list = history_list(snac); | 1428 | xs *list = history_list(user); |
| 1401 | char *p, *v; | 1429 | char *p, *v; |
| 1402 | 1430 | ||
| 1403 | p = list; | 1431 | p = list; |
| @@ -1405,7 +1433,7 @@ xs_str *html_timeline(snac *snac, const xs_list *list, int local, int skip, int | |||
| 1405 | xs *fn = xs_replace(v, ".html", ""); | 1433 | xs *fn = xs_replace(v, ".html", ""); |
| 1406 | xs *s1 = xs_fmt( | 1434 | xs *s1 = xs_fmt( |
| 1407 | "<li><a href=\"%s/h/%s\">%s</a></li>\n", | 1435 | "<li><a href=\"%s/h/%s\">%s</a></li>\n", |
| 1408 | snac->actor, v, fn); | 1436 | user->actor, v, fn); |
| 1409 | 1437 | ||
| 1410 | s = xs_str_cat(s, s1); | 1438 | s = xs_str_cat(s, s1); |
| 1411 | } | 1439 | } |
| @@ -1419,19 +1447,21 @@ xs_str *html_timeline(snac *snac, const xs_list *list, int local, int skip, int | |||
| 1419 | } | 1447 | } |
| 1420 | 1448 | ||
| 1421 | if (show_more) { | 1449 | if (show_more) { |
| 1450 | const char *base_url = user ? user->actor : srv_baseurl; | ||
| 1451 | |||
| 1422 | xs *s1 = xs_fmt( | 1452 | xs *s1 = xs_fmt( |
| 1423 | "<p>" | 1453 | "<p>" |
| 1424 | "<a href=\"%s%s\" name=\"snac-more\">%s</a> - " | 1454 | "<a href=\"%s%s\" name=\"snac-more\">%s</a> - " |
| 1425 | "<a href=\"%s%s?skip=%d&show=%d\" name=\"snac-more\">%s</a>" | 1455 | "<a href=\"%s%s?skip=%d&show=%d\" name=\"snac-more\">%s</a>" |
| 1426 | "</p>\n", | 1456 | "</p>\n", |
| 1427 | snac->actor, local ? "" : "/admin", L("Back to top"), | 1457 | base_url, local ? "" : "/admin", L("Back to top"), |
| 1428 | snac->actor, local ? "" : "/admin", skip + show, show, L("Older entries...") | 1458 | base_url, local ? "" : "/admin", skip + show, show, L("Older entries...") |
| 1429 | ); | 1459 | ); |
| 1430 | 1460 | ||
| 1431 | s = xs_str_cat(s, s1); | 1461 | s = xs_str_cat(s, s1); |
| 1432 | } | 1462 | } |
| 1433 | 1463 | ||
| 1434 | s = html_user_footer(s); | 1464 | s = html_footer(s); |
| 1435 | 1465 | ||
| 1436 | s = xs_str_cat(s, "</body>\n</html>\n"); | 1466 | s = xs_str_cat(s, "</body>\n</html>\n"); |
| 1437 | 1467 | ||
| @@ -1567,7 +1597,7 @@ xs_str *html_people(snac *snac) | |||
| 1567 | 1597 | ||
| 1568 | s = html_people_list(snac, s, wers, L("People that follow you"), "e"); | 1598 | s = html_people_list(snac, s, wers, L("People that follow you"), "e"); |
| 1569 | 1599 | ||
| 1570 | s = html_user_footer(s); | 1600 | s = html_footer(s); |
| 1571 | 1601 | ||
| 1572 | s = xs_str_cat(s, "</body>\n</html>\n"); | 1602 | s = xs_str_cat(s, "</body>\n</html>\n"); |
| 1573 | 1603 | ||
| @@ -1684,7 +1714,7 @@ xs_str *html_notifications(snac *snac) | |||
| 1684 | else | 1714 | else |
| 1685 | s = xs_str_cat(s, "</div>\n"); | 1715 | s = xs_str_cat(s, "</div>\n"); |
| 1686 | 1716 | ||
| 1687 | s = html_user_footer(s); | 1717 | s = html_footer(s); |
| 1688 | 1718 | ||
| 1689 | s = xs_str_cat(s, "</body>\n</html>\n"); | 1719 | s = xs_str_cat(s, "</body>\n</html>\n"); |
| 1690 | 1720 | ||