summaryrefslogtreecommitdiff
path: root/generators.c
diff options
context:
space:
mode:
Diffstat (limited to 'generators.c')
-rw-r--r--generators.c419
1 files changed, 168 insertions, 251 deletions
diff --git a/generators.c b/generators.c
index 356c434..8ac90db 100644
--- a/generators.c
+++ b/generators.c
@@ -29,6 +29,7 @@
#include "items.h"
#include "jpeg-utils.h"
#include "gallery-utils.h"
+#include "generators-replace-table.h"
/*
@@ -625,6 +626,7 @@ write_html_image (TGallerySetup *setup,
int level, old_parent_item_index;
gboolean override_title_meta;
gboolean image_fullsize;
+ ReplaceTable *replace_table;
fin = fopen (template_src, "r");
@@ -642,6 +644,8 @@ write_html_image (TGallerySetup *setup,
buffer = malloc (BUFFER_SIZE);
preload_imgname = NULL;
+ replace_table = replace_table_new ();
+
/* Get our index in the album */
item_index = 0;
real_item_index = 0;
@@ -695,6 +699,164 @@ write_html_image (TGallerySetup *setup,
if (image_fullsize)
get_image_sizes (orig_dst, &img_orig_w, &img_orig_h);
+ /* Get title and description from IPTC/EXIF/JPEG if not defined */
+ title = g_strdup (item->title);
+ title_desc = g_strdup (item->title_description);
+ if (setup->use_iptc_exif && title == NULL && title_desc == NULL) {
+ if (exif->iptc_caption)
+ title = g_strdup (exif->iptc_caption);
+ if (exif->jpeg_comment) {
+ if (! title)
+ title = g_strdup (exif->jpeg_comment);
+ else
+ title_desc = g_strdup (exif->jpeg_comment);
+ }
+ if (exif->exif_imgdesc) {
+ if (! title)
+ title = g_strdup (exif->exif_imgdesc);
+/* if (! title_desc) -- disabled
+ title_desc = g_strdup (exif->exif_imgdesc); */
+ }
+ if (exif->exif_usercomment) {
+ if (! title)
+ title = g_strdup (exif->exif_usercomment);
+ if (! title_desc)
+ title_desc = g_strdup (exif->exif_usercomment);
+ }
+ /* Convert line breaks to be visible in the HTML code */
+ if (title) {
+ str_replace (&title, "\r\n", "<br />", NULL);
+ str_replace (&title, "\n", "<br />", NULL);
+ }
+ if (title_desc) {
+ str_replace (&title_desc, "\r\n", "<br />", NULL);
+ str_replace (&title_desc, "\n", "<br />", NULL);
+ }
+ }
+ if (title) title = g_strstrip (title);
+ if (title_desc) title_desc = g_strstrip (title_desc);
+
+ /* Page title */
+ s1 = (title && strlen (title) > 0) ? g_strdup_printf("%s | ", title) : NULL;
+ s2 = g_strdup_printf ("%s [%d/%d]", parent_items->title ? parent_items->title : parent_items->ID, real_item_index, real_total_items);
+ s3 = setup->site_title ? g_strdup_printf(" | %s", setup->site_title) : NULL;
+ s4 = g_strconcat (s1 ? s1 : "", s2, s3 ? s3 : "", NULL);
+ replace_table_add_key (replace_table, "PAGE_TITLE", s4);
+ if (s1) g_free (s1);
+ if (s2) g_free (s2);
+ if (s3) g_free (s3);
+ g_free (s4);
+
+ /* Simple placeholders */
+ replace_table_add_key (replace_table, "FILE_NAME", imgname);
+ replace_table_add_key (replace_table, "TITLE", title);
+ replace_table_add_key (replace_table, "DESCRIPTION", title_desc);
+ replace_table_add_key (replace_table, "FOOTER", setup->footer);
+ replace_table_add_key_int (replace_table, "TOTAL_ITEMS", real_total_items);
+ replace_table_add_key_int (replace_table, "FILE_NO", real_item_index);
+ replace_table_add_key_int (replace_table, "IMG_SIZE_BIG_W", img_big_w);
+ replace_table_add_key_int (replace_table, "IMG_SIZE_BIG_H", img_big_h);
+ replace_table_add_key_int (replace_table, "IMG_SIZE_ORIG_W", img_orig_w);
+ replace_table_add_key_int (replace_table, "IMG_SIZE_ORIG_H", img_orig_h);
+ s1 = g_strdup_printf ("%s/%s", IMG_BIG_DIR, imgname);
+ replace_table_add_key (replace_table, "IMG_SRC_BIG", s1);
+ g_free (s1);
+ s1 = g_strdup_printf ("%s/%s", IMG_ORIG_DIR, imgname);
+ replace_table_add_key (replace_table, "IMG_SRC_FULL", s1);
+ g_free (s1);
+ replace_table_add_key (replace_table, "IMG_SRC_PRELOAD", preload_imgname ? preload_imgname : "");
+
+ /* Navigation bar */
+ s1 = g_strdup (imgname);
+ parent = parent_items;
+ level = 0;
+ while (parent) {
+ s3 = make_string ("../", level);
+ s4 = g_strdup (parent->ID);
+ /* TODO: check */
+ fix_entities (&s4);
+ s5 = setup->use_inpage_links ? g_strdup_printf ("#i%d", parent == parent_items ? item_index : old_parent_item_index) : g_strdup ("");
+ s2 = g_strdup_printf ("<a href=\"%sindex.html%s\">%s</a> &gt; %s", s3, s5, s4, s1);
+ free (s3);
+ g_free (s1);
+ g_free (s4);
+ g_free (s5);
+ s1 = s2;
+ old_parent_item_index = parent->parent_item_index + 1;
+ parent = parent->parent_index;
+ level++;
+ }
+ replace_table_add_key (replace_table, "NAV_BAR", s1);
+ g_free (s1);
+
+ /* EXIF values */
+ replace_table_add_key (replace_table, "EXIF_ISO", exif->iso ? exif->iso : "??");
+ replace_table_add_key (replace_table, "EXIF_TIME", exif->exposure ? exif->exposure : "??");
+ replace_table_add_key (replace_table, "EXIF_APERTURE", exif->aperture ? exif->aperture : "??");
+ replace_table_add_key (replace_table, "EXIF_FOCAL_LENGTH", exif->focal_length ? exif->focal_length : "??");
+ replace_table_add_key (replace_table, "EXIF_FLASH", exif->flash ? exif->flash : "??");
+ replace_table_add_key (replace_table, "EXIF_DATE", exif->datetime ? exif->datetime : "??");
+ replace_table_add_key (replace_table, "EXIF_CAMERA_MODEL", exif->camera_model ? exif->camera_model : "??");
+ s1 = g_strdup_printf ("(%s)", exif->focal_length_35mm);
+ replace_table_add_key (replace_table, "EXIF_FOCAL_35", exif->focal_length_35mm ? s1 : "");
+ g_free (s1);
+
+ /* Border style */
+ s1 = item->border_style;
+ if (s1 == NULL)
+ s1 = parent_items->border_style;
+ if (s1 == NULL)
+ s1 = setup->border_style;
+ if (s1 == NULL)
+ s1 = "border_single";
+ replace_table_add_key (replace_table, "IMG_BORDER_STYLE", s1);
+
+ /* Next/Previous links */
+ if (next_item) {
+ s2 = g_path_get_basename ((next_item->path == NULL && next_item->preview) ? next_item->preview : next_item->path);
+ s1 = g_strconcat (s2, ".html", NULL);
+ replace_table_add_key (replace_table, "LINK_NEXT", s1);
+ g_free (s1);
+ g_free (s2);
+ }
+ else
+ replace_table_add_key (replace_table, "LINK_NEXT", "index.html");
+ if (previous_item) {
+ s2 = g_path_get_basename ((previous_item->path == NULL && previous_item->preview) ? previous_item->preview : previous_item->path);
+ s1 = g_strconcat (s2, ".html", NULL);
+ replace_table_add_key (replace_table, "LINK_PREV", s1);
+ g_free (s1);
+ g_free (s2);
+ }
+ else
+ replace_table_add_key (replace_table, "LINK_PREV", "index.html");
+
+ /* META tags */
+ override_title_meta = setup->use_title_as_meta && title && (strlen (title) > 0);
+ s1 = g_strdup_printf ("\t<meta name=\"generator\" content=\"Cataract Gallery Generator v%s\" />\n", APP_VERSION);
+ if (setup->meta_author || parent_items->meta_author) {
+ s2 = g_strdup_printf ("%s\t<meta name=\"author\" content=\"%s\" />\n", s1,
+ parent_items->meta_author ? parent_items->meta_author : setup->meta_author);
+ g_free (s1);
+ s1 = s2;
+ }
+ if (setup->meta_description || parent_items->meta_description || override_title_meta) {
+ s3 = override_title_meta ? g_markup_escape_text (title, -1) : NULL;
+ s2 = g_strdup_printf ("%s\t<meta name=\"description\" content=\"%s\" />\n", s1,
+ override_title_meta ? s3 : (parent_items->meta_description ? parent_items->meta_description : setup->meta_description));
+ g_free (s1);
+ if (s3) g_free (s3);
+ s1 = s2;
+ }
+ if ((setup->meta_keywords || parent_items->meta_keywords) && (! override_title_meta)) {
+ s2 = g_strdup_printf ("%s\t<meta name=\"keywords\" content=\"%s\" />\n", s1,
+ parent_items->meta_keywords ? parent_items->meta_keywords : setup->meta_keywords);
+ g_free (s1);
+ s1 = s2;
+ }
+ replace_table_add_key (replace_table, "CGG_META_TAGS", s1);
+ g_free (s1);
+
/* Read through the template and replace placeholders with real data */
while (! feof (fin)) {
@@ -703,7 +865,6 @@ write_html_image (TGallerySetup *setup,
break;
b = strdup (buffer);
-
/* Block placeholders */
if (strstr (buffer, "<!-- $(BEGIN_IMG_FULLSIZE_LINK) -->")) {
in_img_fullsize_link = TRUE;
@@ -723,255 +884,10 @@ write_html_image (TGallerySetup *setup,
continue;
}
- /* Get title and description from IPTC/EXIF/JPEG if not defined */
- title = g_strdup (item->title);
- title_desc = g_strdup (item->title_description);
- if (setup->use_iptc_exif && title == NULL && title_desc == NULL) {
- if (exif->iptc_caption)
- title = g_strdup (exif->iptc_caption);
- if (exif->jpeg_comment) {
- if (! title)
- title = g_strdup (exif->jpeg_comment);
- else
- title_desc = g_strdup (exif->jpeg_comment);
- }
- if (exif->exif_imgdesc) {
- if (! title)
- title = g_strdup (exif->exif_imgdesc);
-/* if (! title_desc) -- disabled
- title_desc = g_strdup (exif->exif_imgdesc); */
- }
- if (exif->exif_usercomment) {
- if (! title)
- title = g_strdup (exif->exif_usercomment);
- if (! title_desc)
- title_desc = g_strdup (exif->exif_usercomment);
- }
- /* Convert line breaks to be visible in the HTML code */
- if (title) {
- str_replace (&title, "\r\n", "<br />", NULL);
- str_replace (&title, "\n", "<br />", NULL);
- }
- if (title_desc) {
- str_replace (&title_desc, "\r\n", "<br />", NULL);
- str_replace (&title_desc, "\n", "<br />", NULL);
- }
- }
- if (title) title = g_strstrip (title);
- if (title_desc) title_desc = g_strstrip (title_desc);
-
- /* Page title */
- if (strstr (b, "<!-- $(PAGE_TITLE) -->")) {
- s1 = (title && strlen (title) > 0) ? g_strdup_printf("%s | ", title) : NULL;
- s2 = g_strdup_printf ("%s [%d/%d]", parent_items->title ? parent_items->title : parent_items->ID, real_item_index, real_total_items);
- s3 = setup->site_title ? g_strdup_printf(" | %s", setup->site_title) : NULL;
- s4 = g_strconcat (s1 ? s1 : "", s2, s3 ? s3 : "", NULL);
- if (s1) g_free (s1);
- if (s2) g_free (s2);
- if (s3) g_free (s3);
- s1 = g_markup_escape_text (s4, -1);
- str_replace (&b, "<!-- $(PAGE_TITLE) -->", s1, NULL);
- g_free (s4);
- g_free (s1);
- }
- /* Simple placeholders */
- if (strstr (b, "<!-- $(FILE_NAME) -->"))
- str_replace (&b, "<!-- $(FILE_NAME) -->", imgname, NULL);
- if (strstr (b, "<!-- $(TITLE) -->") && title) {
- s1 = g_strdup (title);
- fix_entities (&s1);
- str_replace (&b, "<!-- $(TITLE) -->", s1, NULL);
- g_free (s1);
- }
- if (strstr (b, "<!-- $(DESCRIPTION) -->") && title_desc) {
- s1 = g_strdup (title_desc);
- fix_entities (&s1);
- str_replace (&b, "<!-- $(DESCRIPTION) -->", s1, NULL);
- g_free (s1);
- }
- if (strstr (b, "<!-- $(TOTAL_ITEMS) -->")) {
- s1 = g_strdup_printf ("%d", real_total_items);
- str_replace (&b, "<!-- $(TOTAL_ITEMS) -->", s1, NULL);
- g_free (s1);
- }
- if (strstr (b, "<!-- $(FILE_NO) -->")) {
- s1 = g_strdup_printf ("%d", real_item_index);
- str_replace(&b, "<!-- $(FILE_NO) -->", s1, NULL);
- g_free (s1);
- }
- if (strstr (b, "<!-- $(NAV_BAR) -->")) {
- s1 = g_strdup (imgname);
- parent = parent_items;
- level = 0;
- while (parent) {
- s3 = make_string ("../", level);
- s4 = g_strdup (parent->ID);
- fix_entities (&s4);
- s5 = setup->use_inpage_links ? g_strdup_printf ("#i%d", parent == parent_items ? item_index : old_parent_item_index) : g_strdup ("");
- s2 = g_strdup_printf ("<a href=\"%sindex.html%s\">%s</a> &gt; %s", s3, s5, s4, s1);
- free (s3);
- g_free (s1);
- g_free (s4);
- g_free (s5);
- s1 = s2;
- old_parent_item_index = parent->parent_item_index + 1;
- parent = parent->parent_index;
- level++;
- }
- str_replace (&b, "<!-- $(NAV_BAR) -->", s1, NULL);
- g_free (s1);
- }
- if (strstr (b, "<!-- $(IMG_SRC_BIG) -->")) {
- s1 = g_strconcat (IMG_BIG_DIR, "/", imgname, NULL);
- str_replace (&b, "<!-- $(IMG_SRC_BIG) -->", s1, NULL);
- g_free (s1);
- }
- if (strstr (b, "<!-- $(IMG_SRC_FULL) -->")) {
- s1 = g_strconcat (IMG_ORIG_DIR, "/", imgname, NULL);
- str_replace (&b, "<!-- $(IMG_SRC_FULL) -->", s1, NULL);
- g_free (s1);
- }
- if (strstr (b, "<!-- $(IMG_SIZE_BIG_W) -->")) {
- s1 = g_strdup_printf ("%lu", img_big_w);
- str_replace (&b, "<!-- $(IMG_SIZE_BIG_W) -->", s1, NULL);
- g_free (s1);
- }
- if (strstr (b, "<!-- $(IMG_SIZE_BIG_H) -->")) {
- s1 = g_strdup_printf ("%lu", img_big_h);
- str_replace (&b, "<!-- $(IMG_SIZE_BIG_H) -->", s1, NULL);
- g_free (s1);
- }
- if (strstr (b, "<!-- $(IMG_SIZE_ORIG_W) -->")) {
- s1 = g_strdup_printf ("%lu", img_orig_w);
- str_replace (&b, "<!-- $(IMG_SIZE_ORIG_W) -->", s1, NULL);
- g_free (s1);
- }
- if (strstr (b, "<!-- $(IMG_SIZE_ORIG_H) -->")) {
- s1 = g_strdup_printf ("%lu", img_orig_h);
- str_replace (&b, "<!-- $(IMG_SIZE_ORIG_H) -->", s1, NULL);
- g_free (s1);
- }
- if (strstr (b, "<!-- $(IMG_BORDER_STYLE) -->")) {
- s1 = item->border_style;
- if (s1 == NULL)
- s1 = parent_items->border_style;
- if (s1 == NULL)
- s1 = setup->border_style;
- if (s1 == NULL)
- s1 = "border_single";
- str_replace (&b, "<!-- $(IMG_BORDER_STYLE) -->", s1, NULL);
- }
- if (strstr (b, "$(IMG_SRC_PRELOAD)"))
- str_replace (&b, "$(IMG_SRC_PRELOAD)", preload_imgname ? preload_imgname : "", NULL);
-
- if (strstr (b, "<!-- $(EXIF_ISO) -->")) {
- if (exif->iso)
- str_replace (&b, "<!-- $(EXIF_ISO) -->", exif->iso, NULL);
- else
- str_replace (&b, "<!-- $(EXIF_ISO) -->", "??", NULL);
- }
- if (strstr (b, "<!-- $(EXIF_TIME) -->")) {
- if (exif->exposure)
- str_replace (&b, "<!-- $(EXIF_TIME) -->", exif->exposure, NULL);
- else
- str_replace (&b, "<!-- $(EXIF_TIME) -->", "??", NULL);
- }
- if (strstr (b, "<!-- $(EXIF_APERTURE) -->")) {
- if (exif->aperture)
- str_replace (&b, "<!-- $(EXIF_APERTURE) -->", exif->aperture, NULL);
- else
- str_replace (&b, "<!-- $(EXIF_APERTURE) -->", "??", NULL);
- }
- if (strstr (b, "<!-- $(EXIF_FOCAL_LENGTH) -->")) {
- if (exif->focal_length)
- str_replace (&b, "<!-- $(EXIF_FOCAL_LENGTH) -->", exif->focal_length, NULL);
- else
- str_replace (&b, "<!-- $(EXIF_FOCAL_LENGTH) -->", "??", NULL);
- }
- if (strstr (b, "<!-- $(EXIF_FLASH) -->")) {
- if (exif->flash)
- str_replace (&b, "<!-- $(EXIF_FLASH) -->", exif->flash, NULL);
- else
- str_replace (&b, "<!-- $(EXIF_FLASH) -->", "??", NULL);
- }
- if (strstr (b, "<!-- $(EXIF_DATE) -->")) {
- if (exif->datetime)
- str_replace (&b, "<!-- $(EXIF_DATE) -->", exif->datetime, NULL);
- else
- str_replace (&b, "<!-- $(EXIF_DATE) -->", "??", NULL);
- }
- if (strstr (b, "<!-- $(EXIF_CAMERA_MODEL) -->")) {
- if (exif->camera_model)
- str_replace (&b, "<!-- $(EXIF_CAMERA_MODEL) -->", exif->camera_model, NULL);
- else
- str_replace (&b, "<!-- $(EXIF_CAMERA_MODEL) -->", "??", NULL);
- }
- if (strstr (b, "<!-- $(EXIF_FOCAL_35) -->")) {
- if (exif->focal_length_35mm) {
- s1 = g_strconcat ("(", exif->focal_length_35mm, ")", NULL);
- str_replace (&b, "<!-- $(EXIF_FOCAL_35) -->", s1, NULL);
- g_free (s1);
- }
- else
- str_replace (&b, "<!-- $(EXIF_FOCAL_35) -->", "", NULL);
- }
-
- if (strstr (b, "<!-- $(LINK_NEXT) -->")) {
- if (next_item) {
- s2 = g_path_get_basename ((next_item->path == NULL && next_item->preview) ? next_item->preview : next_item->path);
- s1 = g_strconcat (s2, ".html", NULL);
- str_replace (&b, "<!-- $(LINK_NEXT) -->", s1, NULL);
- g_free (s1);
- g_free (s2);
- }
- else
- str_replace (&b, "<!-- $(LINK_NEXT) -->", "index.html", NULL);
- }
- if (strstr(b, "<!-- $(LINK_PREV) -->")) {
- if (previous_item) {
- s2 = g_path_get_basename ((previous_item->path == NULL && previous_item->preview) ? previous_item->preview : previous_item->path);
- s1 = g_strconcat (s2, ".html", NULL);
- str_replace (&b, "<!-- $(LINK_PREV) -->", s1, NULL);
- g_free (s1);
- g_free (s2);
- }
- else
- str_replace (&b, "<!-- $(LINK_PREV) -->", "index.html", NULL);
- }
-
- if (strstr (b, "<!-- $(FOOTER) -->") && setup->footer) {
- s1 = g_strdup (setup->footer);
- fix_entities (&s1);
- str_replace (&b, "<!-- $(FOOTER) -->", s1, NULL);
- g_free (s1);
- }
- if (strstr (b, "<!-- $(CGG_META_TAGS) -->")) {
- override_title_meta = setup->use_title_as_meta && title && (strlen (title) > 0);
- s1 = g_strdup_printf ("\t<meta name=\"generator\" content=\"Cataract Gallery Generator v%s\" />\n", APP_VERSION);
- if (setup->meta_author || parent_items->meta_author) {
- s2 = g_strdup_printf ("%s\t<meta name=\"author\" content=\"%s\" />\n", s1,
- parent_items->meta_author ? parent_items->meta_author : setup->meta_author);
- g_free (s1);
- s1 = s2;
- }
- if (setup->meta_description || parent_items->meta_description || override_title_meta) {
- s3 = override_title_meta ? g_markup_escape_text (title, -1) : NULL;
- s2 = g_strdup_printf ("%s\t<meta name=\"description\" content=\"%s\" />\n", s1,
- override_title_meta ? s3 : (parent_items->meta_description ? parent_items->meta_description : setup->meta_description));
- g_free (s1);
- if (s3) g_free (s3);
- s1 = s2;
- }
- if ((setup->meta_keywords || parent_items->meta_keywords) && (! override_title_meta)) {
- s2 = g_strdup_printf ("%s\t<meta name=\"keywords\" content=\"%s\" />\n", s1,
- parent_items->meta_keywords ? parent_items->meta_keywords : setup->meta_keywords);
- g_free (s1);
- s1 = s2;
- }
- str_replace (&b, "<!-- $(CGG_META_TAGS) -->", s1, NULL);
- g_free (s1);
- }
+ /* Replace all known tags */
+ replace_table_process (&b, replace_table);
+ /* Write to file */
if (! fputs (b, fout)) {
fprintf (stderr, "write_html_image: error writing to file \"%s\": %s\n", dst, strerror (errno));
res = FALSE;
@@ -979,12 +895,12 @@ write_html_image (TGallerySetup *setup,
break;
}
free (b);
- if (title) g_free (title);
- if (title_desc) g_free (title_desc);
}
fclose (fout);
fclose (fin);
+ if (title) g_free (title);
+ if (title_desc) g_free (title_desc);
free (buffer);
free (big_dst);
free (orig_dst);
@@ -993,6 +909,7 @@ write_html_image (TGallerySetup *setup,
if (preload_imgname)
g_free (preload_imgname);
free_exif_data (exif);
+ replace_table_free (replace_table);
return res;
}