]> git.cameronkatri.com Git - cgit.git/blobdiff - ui-shared.c
Add atom-support
[cgit.git] / ui-shared.c
index d08ede90b8125a63d1b553c8c78b02e18dd133e8..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)
@@ -114,7 +129,7 @@ char *cgit_currurl()
                return fmt("%s/", ctx.cfg.virtual_root);
 }
 
-static void site_url(char *page, char *search)
+static void site_url(char *page, char *search, int ofs)
 {
        char *delim = "?";
 
@@ -133,11 +148,16 @@ static void site_url(char *page, char *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)
+                     char *search, int ofs)
 {
        html("<a");
        if (title) {
@@ -151,12 +171,18 @@ static void site_link(char *page, char *name, char *title, char *class,
                html("'");
        }
        html(" href='");
-       site_url(page, search);
+       site_url(page, search, ofs);
        html("'>");
        html_txt(name);
        html("</a>");
 }
 
+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)
 {
@@ -342,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);
 }
@@ -364,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;
        }
 
@@ -414,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");
@@ -426,13 +456,34 @@ 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");
 }
 
 void cgit_print_docend()
 {
-       html("</div>\n</body>\n</html>\n");
+       html("</div>");
+       if (ctx.cfg.footer)
+               html_include(ctx.cfg.footer);
+       else {
+               html("<div class='footer'>generated ");
+               cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time);
+               htmlf(" by cgit %s", cgit_version);
+               html("</div>\n");
+       }
+       html("</body>\n</html>\n");
 }
 
 int print_branch_option(const char *refname, const unsigned char *sha1,
@@ -493,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)
@@ -531,10 +583,10 @@ void cgit_print_pageheader(struct cgit_context *ctx)
 
        html("<td class='main'>");
        if (ctx->repo) {
+               cgit_index_link("index", NULL, NULL, NULL, 0);
+               html(" : ");
                reporevlink(NULL, ctx->repo->name, NULL, hc(cmd, "summary"),
                            ctx->qry.head, NULL, NULL);
-               html(" : ");
-               html_txt(ctx->qry.page);
                html("</td><td class='form'>");
                html("<form method='get' action=''>\n");
                add_hidden_formfields(0, 1, ctx->qry.page);
@@ -547,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)
@@ -596,9 +648,10 @@ void cgit_print_pageheader(struct cgit_context *ctx)
                html("<input type='submit' value='search'/>\n");
                html("</form>\n");
        } else {
-               site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL);
+               site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL, 0);
                if (ctx->cfg.root_readme)
-                       site_link("about", "about", NULL, hc(cmd, "about"), NULL);
+                       site_link("about", "about", NULL, hc(cmd, "about"),
+                                 NULL, 0);
                html("</td><td class='form'>");
                html("<form method='get' action='");
                html_attr(cgit_rooturl());