get html header from file
[ppastats.git] / src / html.c
index b2e9e34..965a565 100644 (file)
@@ -39,6 +39,7 @@
 static char *footer;
 static char *ppa_body;
 static char *pkg_body;
+static char *header;
 
 #define HTML_VERSION_TEMPLATE \
 "<html>\n\
@@ -81,34 +82,6 @@ src=\"js/excanvas.js\"></script><![endif]-->\n\
       </div>\n\
     </div>\n"
 
-#define HTML_HEADER \
-"<html>\n\
-       <head>\n\
-               <title>%s</title>\n\
-               <link type=\"text/css\"\n\
-                     rel=\"stylesheet\"\n\
-                     href=\
-\"http://fonts.googleapis.com/css?family=Ubuntu:regular,bold&subset=Latin\">\n\
-               <link type=\"text/css\" href=\"css/ppastats.css\"\n\
-                     rel=\"stylesheet\"/>\n\
-               <link type=\"text/css\" href=\"css/jquery.jqplot.min.css\"\n\
-                     rel=\"stylesheet\" />\n\
-<!--[if lt IE 9]><script \
-language=\"javascript\" \
-type=\"text/javascript\" \
-src=\"js/excanvas.js\"></script><![endif]-->\n\
-               <script type=\"text/javascript\"\n\
-                       src=\"js/jquery.min.js\"></script>\n\
-               <script type=\"text/javascript\"\n\
-                       src=\"js/jquery.jqplot.min.js\"></script>\n\
-               <script type=\"text/javascript\"\n\
-                       src=\"js/jqplot.dateAxisRenderer.min.js\"></script>\n\
-               <script type=\"text/javascript\"\n\
-                       src=\"js/ppastats.js\"></script>\n\
-               <script>%s</script>\n\
-       </head>\n\
-       <body>\n"
-
 static char *path_new(const char *dir, const char *file, const char *suffixe)
 {
        char *path;
@@ -127,6 +100,21 @@ static char *path_new(const char *dir, const char *file, const char *suffixe)
        return path;
 }
 
+static const char *get_header()
+{
+       const char *path;
+
+       if (!header) {
+               path = DEFAULT_WWW_DIR"/header.tpl";
+               header = file_get_content(path);
+
+               if (!header)
+                       log_err("Failed to read header template: %s", path);
+       }
+
+       return header;
+}
+
 static const char *get_footer()
 {
        const char *path;
@@ -430,6 +418,11 @@ create_html(const char *path,
 {
        FILE *f;
        const char *footer;
+       const char *header;
+
+       header = get_header();
+       if (!header)
+               return ;
 
        f = fopen(path, "w");
 
@@ -438,7 +431,7 @@ create_html(const char *path,
                return ;
        }
 
-       fprintf(f, HTML_HEADER, title, script);
+       fprintf(f, header, title, script);
        fputs(body_template, f);
 
        footer = get_footer();