summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2009-02-19 22:50:50 +0100
committerTomas Bzatek <tbzatek@users.sourceforge.net>2009-02-19 22:50:50 +0100
commita985af97b7a1e208ea0379308cc0e03db28787dc (patch)
tree37f9b73217fb2312dda89879617b449d671fc010
parent2330399247af870aa4a20db27011f86bd977b436 (diff)
downloadcataract-a985af97b7a1e208ea0379308cc0e03db28787dc.tar.xz
Introduce tag replace table, part I.
-rw-r--r--Makefile3
-rw-r--r--generators-replace-table.c140
-rw-r--r--generators-replace-table.h53
-rw-r--r--generators.c419
4 files changed, 363 insertions, 252 deletions
diff --git a/Makefile b/Makefile
index 5ce991c..930e25d 100644
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,7 @@ CPP = g++
CFLAGS = -I. -I/usr/include -Wall -fPIC -g \
-D__DEBUG__ -D__DEBUG_ALL__x
-OBJECTS=gallery-utils.o jpeg-utils.o xml-parser.o setup.o items.o generators.o cgg.o
+OBJECTS=gallery-utils.o jpeg-utils.o xml-parser.o setup.o items.o generators.o generators-replace-table.o cgg.o
EXIV2_CFLAGS_EXTRA=`pkg-config --max-version=0.17.1 exiv2 || echo -D_EXIV2_NEW_API`
@@ -29,6 +29,7 @@ setup.o: setup.c setup.h
xml-parser.o: xml-parser.c xml-parser.h
items.o: items.c items.h
generators.o: generators.c generators.h
+generators-replace-table.o: generators-replace-table.c generators-replace-table.h
check::
@pkg-config --cflags libxml-2.0 glib-2.0 exiv2 > /dev/null || exit 1
diff --git a/generators-replace-table.c b/generators-replace-table.c
new file mode 100644
index 0000000..562f9af
--- /dev/null
+++ b/generators-replace-table.c
@@ -0,0 +1,140 @@
+/* Cataract - Static web photo gallery generator
+ * Copyright (C) 2008 Tomas Bzatek <tbzatek@users.sourceforge.net>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <glib.h>
+
+#include "generators-replace-table.h"
+#include "gallery-utils.h"
+
+
+
+
+
+static void
+replace_table_destroy_notify (gpointer data)
+{
+ g_print ("replace_table_destroy_notify: %s\n", (gchar *) data);
+
+ if ((gchar *) data)
+ g_free ((gchar *) data);
+}
+
+ReplaceTable *
+replace_table_new ()
+{
+ return (ReplaceTable *) g_hash_table_new_full (g_str_hash, g_str_equal, replace_table_destroy_notify, replace_table_destroy_notify);
+}
+
+void
+replace_table_free (ReplaceTable *table)
+{
+ g_return_if_fail (table != NULL);
+
+ g_hash_table_destroy (table);
+}
+
+
+/*
+ * replace_table_add_key: add tag/value pair to replace
+ *
+ * tag, value will be referenced inside
+ *
+ */
+void
+replace_table_add_key (ReplaceTable *table, const gchar *tag, const gchar *value)
+{
+ g_return_if_fail (table != NULL);
+
+ if (tag != NULL && value != NULL)
+ g_hash_table_replace (table, g_strdup (tag), g_strdup (value));
+}
+
+void
+replace_table_add_key_int (ReplaceTable *table, const gchar *tag, gint value)
+{
+ g_return_if_fail (table != NULL);
+
+ if (tag != NULL)
+ g_hash_table_replace (table, g_strdup (tag), g_strdup_printf ("%d", value));
+}
+
+
+
+static void
+replace_table_process_value (gpointer key, gpointer value, gpointer user_data)
+{
+ gchar **buffer = user_data;
+ gchar *tag;
+ gchar *tag_value;
+
+ g_return_if_fail (key != NULL);
+ g_return_if_fail (value != NULL);
+ g_return_if_fail (user_data != NULL);
+
+// g_print ("replace_table_print: key = '%s', value = '%s'\n", (gchar *) key, (gchar *) value);
+
+ /* replace <!-- $(xxx) --> tags */
+ tag = g_strdup_printf ("<!-- $(%s) -->", (gchar *) key);
+ tag_value = g_strdup ((gchar *) value);
+ /* TODO: do something with tag_value? */
+/* fix_entities (&s1); */
+/* s1 = g_markup_escape_text (s4, -1); */
+ while (strstr (*buffer, tag)) {
+ str_replace (buffer, tag, tag_value, NULL);
+ }
+ g_free (tag_value);
+ g_free (tag);
+
+ /* replace $(xxx) tags */
+ tag = g_strdup_printf ("$(%s)", (gchar *) key);
+ tag_value = g_strdup ((gchar *) value);
+ /* TODO: do something with tag_value? */
+/* fix_entities (&s1); */
+/* s1 = g_markup_escape_text (s4, -1); */
+/* remove all tags as we're tag value */
+ while (strstr (*buffer, tag)) {
+ str_replace (buffer, tag, tag_value, NULL);
+ }
+ g_free (tag_value);
+ g_free (tag);
+}
+
+/*
+ * replace_table_process: process buffer and replace all tags filled in the replace table
+ *
+ * - reallocates source buffer
+ *
+ */
+void
+replace_table_process (gchar **buffer, ReplaceTable *table)
+{
+ g_return_if_fail (table != NULL);
+
+ g_hash_table_foreach (table, replace_table_process_value, buffer);
+
+/*
+ gchar *val = g_hash_table_lookup (table, "TAG");
+ g_print ("replace_table_process: val = '%s'\n", val);
+*/
+}
diff --git a/generators-replace-table.h b/generators-replace-table.h
new file mode 100644
index 0000000..5646e5b
--- /dev/null
+++ b/generators-replace-table.h
@@ -0,0 +1,53 @@
+/* Cataract - Static web photo gallery generator
+ * Copyright (C) 2009 Tomas Bzatek <tbzatek@users.sourceforge.net>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <glib.h>
+
+
+typedef GHashTable ReplaceTable;
+
+/*
+ * write_html_album: process album and index template files
+ *
+ * template_src = template file of the album/index
+ * dst = save generated file as
+ * items = array of items in the album/index
+ *
+ */
+ReplaceTable *replace_table_new ();
+
+void replace_table_free (ReplaceTable *table);
+
+
+/*
+ * replace_table_add_key: add tag/value pair to replace
+ *
+ * tag, value will be referenced inside
+ *
+ */
+void replace_table_add_key (ReplaceTable *table, const gchar *tag, const gchar *value);
+void replace_table_add_key_int (ReplaceTable *table, const gchar *tag, gint value);
+
+/*
+ * replace_table_process: process buffer and replace all tags filled in the replace table
+ *
+ * - reallocates source buffer
+ *
+ */
+void replace_table_process (gchar **buffer, ReplaceTable *table);
+
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;
}