]> git.cameronkatri.com Git - cgit.git/blobdiff - ui-shared.c
Add atom-support
[cgit.git] / ui-shared.c
index 8a00099fdf10bc9871742c6eb561ab450c83a2b6..37c60b25d2c8ed1e4cecba4d2bd8873884a1baef 100644 (file)
@@ -34,6 +34,21 @@ void cgit_print_error(char *msg)
        html("</div>\n");
 }
 
+char *cgit_hosturl()
+{
+       char *host, *port;
+
+       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)
@@ -353,14 +368,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);
 }
@@ -375,7 +393,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;
        }
 
@@ -425,6 +443,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("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
        html("<head>\n");
@@ -437,6 +456,18 @@ void cgit_print_docstart(struct cgit_context *ctx)
        html("<link rel='stylesheet' type='text/css' href='");
        html_attr(ctx->cfg.css);
        html("'/>\n");
+       if (ctx->cfg.favicon) {
+               html("<link rel='shortcut icon' href='");
+               html_attr(ctx->cfg.favicon);
+               html("'/>\n");
+       }
+       if (host && ctx->repo) {
+               html("<link rel='alternate' title='Atom feed' href='http://");
+               html_attr(cgit_hosturl());
+               html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path,
+                                      fmt("h=%s", ctx->qry.head)));
+               html("' type='application/atom+xml'/>");
+       }
        html("</head>\n");
        html("<body>\n");
 }
@@ -448,7 +479,7 @@ void cgit_print_docend()
                html_include(ctx.cfg.footer);
        else {
                html("<div class='footer'>generated ");
-               cgit_print_date(time(NULL), FMT_LONGDATE);
+               cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time);
                htmlf(" by cgit %s", cgit_version);
                html("</div>\n");
        }
@@ -513,7 +544,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)
@@ -567,12 +599,12 @@ void cgit_print_pageheader(struct cgit_context *ctx)
                html_txt(ctx->cfg.root_title);
        html("</td></tr>\n");
 
-       html("<tr><td class='sub'");
+       html("<tr><td class='sub'>");
        if (ctx->repo) {
-               html(" colspan='2'>");
                html_txt(ctx->repo->desc);
+               html("</td><td class='sub right'>");
+               html_txt(ctx->repo->owner);
        } else {
-               html(">");
                if (ctx->cfg.root_desc)
                        html_txt(ctx->cfg.root_desc);
                else if (ctx->cfg.index_info)