X-Git-Url: https://gitweb.ps.run/ps-cgit/blobdiff_plain/f135569b2be3fb1816f802f9a162b3743b735d1c..a30453a5d3f6db4d6e055da2112343e054e7e7d5:/ui-shared.c diff --git a/ui-shared.c b/ui-shared.c index 7287956..c23bc75 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -34,6 +34,26 @@ void cgit_print_error(char *msg) html("\n"); } +char *cgit_hosturl() +{ + char *host, *port; + + host = getenv("HTTP_HOST"); + if (host) { + host = xstrdup(host); + } else { + host = getenv("SERVER_NAME"); + if (!host) + return NULL; + port = getenv("SERVER_PORT"); + if (port && atoi(port) != 80) + host = xstrdup(fmt("%s:%d", host, atoi(port))); + else + host = xstrdup(host); + } + return host; +} + char *cgit_rooturl() { if (ctx.cfg.virtual_root) @@ -114,6 +134,60 @@ char *cgit_currurl() return fmt("%s/", ctx.cfg.virtual_root); } +static void site_url(char *page, char *search, int ofs) +{ + char *delim = "?"; + + if (ctx.cfg.virtual_root) { + html_attr(ctx.cfg.virtual_root); + if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') + html("/"); + } else + html(ctx.cfg.script_name); + + if (page) { + htmlf("?p=%s", page); + delim = "&"; + } + if (search) { + html(delim); + html("q="); + html_attr(search); + delim = "&"; + } + if (ofs) { + html(delim); + htmlf("ofs=%d", ofs); + } +} + +static void site_link(char *page, char *name, char *title, char *class, + char *search, int ofs) +{ + html(""); + html_txt(name); + html(""); +} + +void cgit_index_link(char *name, char *title, char *class, char *pattern, + int ofs) +{ + site_link(NULL, name, title, class, pattern, ofs); +} + static char *repolink(char *title, char *class, char *page, char *head, char *path) { @@ -189,6 +263,12 @@ void cgit_tree_link(char *name, char *title, char *class, char *head, reporevlink("tree", name, title, class, head, rev, path); } +void cgit_plain_link(char *name, char *title, char *class, char *head, + char *rev, char *path) +{ + reporevlink("plain", name, title, class, head, rev, path); +} + void cgit_log_link(char *name, char *title, char *class, char *head, char *rev, char *path, int ofs, char *grep, char *pattern) { @@ -299,14 +379,17 @@ void cgit_object_link(struct object *obj) html_link_close(); } -void cgit_print_date(time_t secs, char *format) +void cgit_print_date(time_t secs, char *format, int local_time) { char buf[64]; struct tm *time; if (!secs) return; - time = gmtime(&secs); + if(local_time) + time = localtime(&secs); + else + time = gmtime(&secs); strftime(buf, sizeof(buf)-1, format, time); html_txt(buf); } @@ -321,7 +404,7 @@ void cgit_print_age(time_t t, time_t max_relative, char *format) secs = now - t; if (secs > max_relative && max_relative >= 0) { - cgit_print_date(t, format); + cgit_print_date(t, format, ctx.cfg.local_time); return; } @@ -361,6 +444,8 @@ void cgit_print_http_headers(struct cgit_context *ctx) ctx->page.charset); else if (ctx->page.mimetype) htmlf("Content-Type: %s\n", ctx->page.mimetype); + if (ctx->page.size) + htmlf("Content-Length: %ld\n", ctx->page.size); if (ctx->page.filename) htmlf("Content-Disposition: inline; filename=\"%s\"\n", ctx->page.filename); @@ -371,6 +456,7 @@ void cgit_print_http_headers(struct cgit_context *ctx) void cgit_print_docstart(struct cgit_context *ctx) { + char *host = cgit_hosturl(); html(cgit_doctype); html("\n"); html("\n"); @@ -383,13 +469,34 @@ void cgit_print_docstart(struct cgit_context *ctx) html("\n"); + if (ctx->cfg.favicon) { + html("\n"); + } + if (host && ctx->repo) { + html(""); + } html("\n"); html("\n"); } void cgit_print_docend() { - html("\n\n\n\n\n"); + html(""); + if (ctx.cfg.footer) + html_include(ctx.cfg.footer); + else { + html("\n"); + } + html("\n\n"); } int print_branch_option(const char *refname, const unsigned char *sha1, @@ -450,7 +557,8 @@ void add_hidden_formfields(int incl_head, int incl_search, char *page) html_hidden("url", url); } - if (incl_head && strcmp(ctx.qry.head, ctx.repo->defbranch)) + if (incl_head && ctx.qry.head && ctx.repo->defbranch && + strcmp(ctx.qry.head, ctx.repo->defbranch)) html_hidden("h", ctx.qry.head); if (ctx.qry.sha1) @@ -478,23 +586,44 @@ void cgit_print_pageheader(struct cgit_context *ctx) html("\n"); html("\n"); html("\n"); + html("' alt='cgit logo'/>\n"); + html("\n"); + html("\n"); - html("\n"); + html(""); + html_txt(ctx->repo->owner); + } else { + if (ctx->cfg.root_desc) + html_txt(ctx->cfg.root_desc); + else if (ctx->cfg.index_info) + html_include(ctx->cfg.index_info); + } + html("\n"); html("
\n"); if (ctx->repo) { @@ -510,12 +639,41 @@ void cgit_print_pageheader(struct cgit_context *ctx) ctx->qry.head, ctx->qry.sha1); cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head, ctx->qry.sha1, ctx->qry.sha2, NULL); - cgit_patch_link("patch", NULL, hc(cmd, "patch"), ctx->qry.head, - ctx->qry.sha1); + if (ctx->repo->readme) + reporevlink("about", "about", NULL, + hc(cmd, "about"), ctx->qry.head, NULL, + NULL); + html(""); + html("
\n"); + add_hidden_formfields(1, 0, "log"); + html("\n"); + html("\n"); + html("\n"); + html("
\n"); } else { - html(""); + html("
index\n"); + html("'>\n"); + html("\n"); + html("\n"); + html("
"); } html("
\n"); html("
");