summaryrefslogtreecommitdiff
path: root/src/generators.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/generators.c')
-rw-r--r--src/generators.c1063
1 files changed, 537 insertions, 526 deletions
diff --git a/src/generators.c b/src/generators.c
index 6728f19..9109876 100644
--- a/src/generators.c
+++ b/src/generators.c
@@ -43,13 +43,158 @@
(item->force_nofullsize || parent_items->nofullsize || setup->nofullsize))
#define BUFFER_SIZE 65536 /* line cannot be longer than this */
+#define POSITION_MARKER_FMT "i%d"
+static const gchar *
+get_index_filename (TAlbum *items, TGalleryDesignTheme *theme, TPathInfo *path_info, TIndexItem *retrieve_child)
+{
+ gchar *s;
+ TGalleryType gallery_type;
+
+ gallery_type = items->type;
+ if (retrieve_child) {
+ s = g_build_filename (path_info->src_dir, retrieve_child->path, "index.xml", NULL);
+ gallery_type = get_child_gallery_type (s);
+ g_free (s);
+ }
+
+ return (gallery_type == GALLERY_TYPE_ALBUM || theme->index_filename == NULL) ? theme->album_filename : theme->index_filename;
+}
+
+/* Calculates number of directory levels one step up (in case of complex paths) */
+static int
+get_parent_dir_level (TAlbum *items)
+{
+ TAlbum *parent;
+ TIndexItem *tmp_item;
+ int level = 0;
+
+ parent = items->parent_index;
+ if (parent) {
+ level = 1;
+ tmp_item = g_ptr_array_index (parent->items, items->parent_item_index);
+ if (tmp_item && tmp_item->path && strlen (tmp_item->path) > 0)
+ level += count_dir_levels (tmp_item->path) - 1;
+ }
+ return level;
+}
+
+/* Calculates number of directory levels to the gallery root */
+static int
+get_root_level (TAlbum *items)
+{
+ TAlbum *parent = items;
+ int level = 0;
+
+ do {
+ level += get_parent_dir_level (parent);
+ } while ((parent = parent->parent_index));
+
+ return level;
+}
+
+static int
+get_item_index (TAlbum *items, TIndexItem *item)
+{
+ int i;
+
+ for (i = 0; i < items->items->len; i++)
+ if (g_ptr_array_index (items->items, i) == item)
+ return i + 1;
+ return 0;
+}
+
+static int
+get_display_item_index (TAlbum *items, TIndexItem *item)
+{
+ TIndexItem *tmp_item;
+ int real_item_index = 0;
+ int i;
+
+ for (i = 0; i < items->items->len; i++) {
+ tmp_item = g_ptr_array_index (items->items, i);
+ if (tmp_item->type == INDEX_ITEM_TYPE_PICTURE && (! tmp_item->hidden))
+ real_item_index++;
+ if (tmp_item == item)
+ return real_item_index;
+ }
+ return 0;
+}
+
+static int
+get_display_item_count (TAlbum *items)
+{
+ TIndexItem *tmp_item;
+ int real_total_items = 0;
+ int i;
+
+ for (i = 0; i < items->items->len; i++) {
+ tmp_item = g_ptr_array_index (items->items, i);
+ if (tmp_item->type == INDEX_ITEM_TYPE_PICTURE && (! tmp_item->hidden))
+ real_total_items++;
+ }
+ return real_total_items;
+}
+
+static void
+get_item_titles (TGallerySetup *setup,
+ TIndexItem *item,
+ ExifData *exif,
+ gchar **title,
+ gchar **title_desc)
+{
+ gchar *s;
+
+ *title = g_strdup (item->title);
+ *title_desc = g_strdup (item->title_description);
+ if (setup->use_iptc_exif && *title == NULL && *title_desc == NULL && exif != NULL) {
+ *title = get_exif_data_fixed (exif, IPTC_CAPTION);
+ s = get_exif_data_fixed (exif, JPEG_COMMENT);
+ if (s) {
+ if (! *title)
+ *title = g_strdup (s);
+ else
+ *title_desc = g_strdup (s);
+ g_free (s);
+ }
+ s = get_exif_data_fixed (exif, EXIF_IMAGE_DESCRIPTION);
+ if (s) {
+ if (! *title)
+ *title = g_strdup (s);
+/* if (! *title_desc) -- disabled
+ *title_desc = g_strdup (s); */
+ g_free (s);
+ }
+ s = get_exif_data_fixed (exif, EXIF_COMMENT);
+ if (s) {
+ if (! *title)
+ *title = g_strdup (s);
+ if (! *title_desc)
+ *title_desc = g_strdup (s);
+ g_free (s);
+ }
+ /* Convert line breaks to be visible in the HTML code */
+ if (*title) {
+ str_replace (title, "\r\n", "<br />");
+ str_replace (title, "\n", "<br />");
+ }
+ if (*title_desc) {
+ str_replace (title_desc, "\r\n", "<br />");
+ str_replace (title_desc, "\n", "<br />");
+ }
+ }
+ if (*title)
+ *title = g_strstrip (*title);
+ if (*title_desc)
+ *title_desc = g_strstrip (*title_desc);
+}
+
+/* FIXME: this badly needs port to the new theming system */
static void
get_image_paths (TGallerySetup *setup,
TAlbum *items,
TIndexItem *item,
- unsigned int item_index,
TPathInfo *path_info,
TImageSize *image_size,
gchar **full_img_src,
@@ -99,7 +244,7 @@ get_image_paths (TGallerySetup *setup,
s2 = g_path_get_basename (s1);
if (full_img_src)
*full_img_src = g_build_filename (path_info->src_dir, s1, NULL);
- s3 = g_strdup_printf (THUMBNAIL_NAME_FORMAT, item_index, s2);
+ s3 = g_strdup_printf (THUMBNAIL_NAME_FORMAT, get_item_index (items, item), s2);
g_free (s2);
if (full_img_dst)
*full_img_dst = g_build_filename (path_info->dest_dir, target_image_dir, s3, NULL);
@@ -159,6 +304,43 @@ metadata_apply_overrides (ExifData *exif_data,
exif_data->thumbnail_crop_hint = get_prop_int (items, item, PROP_THUMB_CROP_HINT, CROP_HINT_UNDEFINED);
}
+static char *
+get_exif_value_cb (gchar **args, gpointer user_data)
+{
+ ExifData *exif = user_data;
+
+ if (exif == NULL)
+ return NULL;
+ g_return_val_if_fail (g_strv_length (args) != 2, NULL); /* incl. trailing NULL */
+
+ return get_exif_data (exif, *args);
+}
+
+static char *
+get_exif_value_fixed_cb (gchar **args, gpointer user_data)
+{
+ ExifData *exif = user_data;
+
+ if (exif == NULL)
+ return NULL;
+ g_return_val_if_fail (g_strv_length (args) != 2, NULL); /* incl. trailing NULL */
+
+ return get_exif_data_fixed (exif, *args);
+}
+
+static gboolean
+has_exif_key_cb (gchar **args, gpointer user_data)
+{
+ ExifData *exif = user_data;
+
+ if (exif == NULL)
+ return FALSE;
+ g_return_val_if_fail (g_strv_length (args) != 2, FALSE); /* incl. trailing NULL */
+
+ return exif_has_key (exif, *args);
+}
+
+
/*
* generate_image: generate needed image sizes
@@ -167,7 +349,6 @@ gboolean
generate_image (TGallerySetup *setup,
TAlbum *items,
TIndexItem *item,
- unsigned int item_index,
TPathInfo *path_info,
gboolean query_update)
{
@@ -195,7 +376,7 @@ generate_image (TGallerySetup *setup,
if (is_original && IS_NOFULLSIZE (item, items, setup))
continue;
- get_image_paths (setup, items, item, item_index, path_info, image_size, &img_src, &img_dst, NULL);
+ get_image_paths (setup, items, item, path_info, image_size, &img_src, &img_dst, NULL);
if (img_src == NULL || img_dst == NULL)
continue;
@@ -275,70 +456,20 @@ generate_image (TGallerySetup *setup,
}
-static const gchar *
-get_index_filename (TAlbum *items, TGalleryDesignTheme *theme, TPathInfo *path_info, TIndexItem *retrieve_child)
-{
- gchar *s;
- TGalleryType gallery_type;
-
- gallery_type = items->type;
- if (retrieve_child) {
- s = g_build_filename (path_info->src_dir, retrieve_child->path, "index.xml", NULL);
- gallery_type = get_child_gallery_type (s);
- g_free (s);
- }
-
- return (gallery_type == GALLERY_TYPE_ALBUM || theme->index_filename == NULL) ? theme->album_filename : theme->index_filename;
-}
-
-/* Calculates number of directory levels one step up (in case of complex paths) */
-static int
-get_parent_dir_level (TAlbum *items)
-{
- TAlbum *parent;
- TIndexItem *tmp_item;
- int level = 0;
-
- parent = items->parent_index;
- if (parent) {
- level = 1;
- tmp_item = g_ptr_array_index (parent->items, items->parent_item_index);
- if (tmp_item && tmp_item->path && strlen (tmp_item->path) > 0)
- level += count_dir_levels (tmp_item->path) - 1;
- }
- return level;
-}
-
-/* Calculates number of directory levels to the gallery root */
-static int
-get_root_level (TAlbum *items)
-{
- TAlbum *parent = items;
- int level = 0;
-
- do {
- level += get_parent_dir_level (parent);
- } while ((parent = parent->parent_index));
-
- return level;
-}
-
static gchar *
process_block (TGallerySetup *setup,
- ReplaceTable *local_replace_table,
- GHashTable *local_defines,
+ BlockParser *block_parser,
+ ReplaceTable *replace_table,
+ GHashTable *defines,
const gchar *str)
{
- BlockParser *local_block_parser;
gchar *s;
- replace_table_set_strip_unused_tags (local_replace_table, setup->strip_unused_tags);
- replace_table_set_defines (local_replace_table, local_defines);
- local_block_parser = block_parser_new ();
- block_parser_set_conditionals (local_block_parser, local_defines);
- s = block_parser_process (local_block_parser, str);
- block_parser_free (local_block_parser);
- replace_table_process (&s, local_replace_table);
+ replace_table_set_strip_unused_tags (replace_table, setup->strip_unused_tags);
+ replace_table_set_defines (replace_table, defines);
+ block_parser_set_conditionals (block_parser, defines);
+ s = block_parser_process (block_parser, str);
+ replace_table_process (&s, replace_table);
return s;
}
@@ -358,6 +489,7 @@ make_navbar_string (TGallerySetup *setup,
TAlbum *parent;
gboolean picture_element = (item_index >= 0);
gboolean first = TRUE;
+ BlockParser *local_block_parser;
ReplaceTable *local_replace_table;
GHashTable *local_defines;
GString *block;
@@ -367,13 +499,15 @@ make_navbar_string (TGallerySetup *setup,
/* the "current" element */
s1 = block_parser_get_data (block_parser, items->parent_index ? "NAV_BAR_CURRENT" : "NAV_BAR_CURRENT_ROOT");
if (s1) {
+ local_block_parser = block_parser_new ();
local_replace_table = replace_table_new ();
local_defines = clone_string_hash_table (defines);
replace_table_add_key (local_replace_table, "NAV_BAR_ELEM_TITLE", current_title);
- s2 = process_block (setup, local_replace_table, local_defines, s1);
+ s2 = process_block (setup, local_block_parser, local_replace_table, local_defines, s1);
g_string_prepend (block, s2);
g_free (s2);
g_free (s1);
+ block_parser_free (local_block_parser);
replace_table_free (local_replace_table);
g_hash_table_destroy (local_defines);
}
@@ -385,20 +519,22 @@ make_navbar_string (TGallerySetup *setup,
while ((parent = picture_element ? items : parent->parent_index)) {
/* NAV_BAR_FIRST takes priority and is guaranteed to be used */
s1 = block_parser_get_data (block_parser, parent->parent_index ? (first ? "NAV_BAR_LAST" : "NAV_BAR_ELEM") : "NAV_BAR_FIRST");
+ local_block_parser = block_parser_new ();
local_replace_table = replace_table_new ();
local_defines = clone_string_hash_table (defines);
s2 = make_string ("../", level);
- s3 = setup->use_inpage_links ? g_strdup_printf ("#i%d", picture_element ? item_index : old_parent_item_index) : g_strdup ("");
+ s3 = setup->use_inpage_links ? g_strdup_printf ("#" POSITION_MARKER_FMT, picture_element ? item_index : old_parent_item_index) : g_strdup ("");
replace_table_add_key_printf (local_replace_table, "NAV_BAR_ELEM_LINK", "%s%s%s", s2, get_index_filename (parent, theme, NULL, NULL), s3);
replace_table_add_key (local_replace_table, "NAV_BAR_ELEM_TITLE", parent->ID);
g_free (s2);
g_free (s3);
- s2 = process_block (setup, local_replace_table, local_defines, s1);
+ s2 = process_block (setup, local_block_parser, local_replace_table, local_defines, s1);
g_string_prepend (block, s2);
g_free (s2);
g_free (s1);
+ block_parser_free (local_block_parser);
replace_table_free (local_replace_table);
g_hash_table_destroy (local_defines);
@@ -489,115 +625,323 @@ add_meta_tags (TGallerySetup *setup,
}
static void
-get_item_titles (TGallerySetup *setup,
- TIndexItem *item,
- ExifData *exif,
- gchar **title,
- gchar **title_desc)
+add_next_prev_links (TGallerySetup *setup,
+ TPathInfo *path_info,
+ TGalleryDesignTheme *theme,
+ TAlbum *items,
+ TIndexItem *item,
+ ReplaceTable *replace_table,
+ TImageSize *image_size)
{
+ TIndexItem *previous_item = NULL;
+ TIndexItem *next_item = NULL;
+ TIndexItem *tmp_item;
+ int item_index;
+ int i;
gchar *s;
+ gchar *preload_imgname;
- *title = g_strdup (item->title);
- *title_desc = g_strdup (item->title_description);
- if (setup->use_iptc_exif && *title == NULL && *title_desc == NULL && exif != NULL) {
- *title = get_exif_data_fixed (exif, IPTC_CAPTION);
- s = get_exif_data_fixed (exif, JPEG_COMMENT);
- if (s) {
- if (! *title)
- *title = g_strdup (s);
- else
- *title_desc = g_strdup (s);
- g_free (s);
+ item_index = get_item_index (items, item);
+ for (i = item_index - 2; i >= 0; i--) {
+ tmp_item = g_ptr_array_index (items->items, i);
+ if (tmp_item != NULL && tmp_item->type == INDEX_ITEM_TYPE_PICTURE && !tmp_item->hidden) {
+ previous_item = tmp_item;
+ break;
}
- s = get_exif_data_fixed (exif, EXIF_IMAGE_DESCRIPTION);
- if (s) {
- if (! *title)
- *title = g_strdup (s);
-/* if (! *title_desc) -- disabled
- *title_desc = g_strdup (s); */
- g_free (s);
+ }
+ for (i = item_index; i < items->items->len; i++) {
+ tmp_item = g_ptr_array_index (items->items, i);
+ if (tmp_item != NULL && tmp_item->type == INDEX_ITEM_TYPE_PICTURE && !tmp_item->hidden) {
+ next_item = tmp_item;
+ break;
}
- s = get_exif_data_fixed (exif, EXIF_COMMENT);
- if (s) {
- if (! *title)
- *title = g_strdup (s);
- if (! *title_desc)
- *title_desc = g_strdup (s);
- g_free (s);
+ }
+
+ if (next_item) {
+ s = GET_ITEM_TARGET_FILENAME (next_item);
+ replace_table_add_key_printf (replace_table, "LINK_NEXT", theme->picture_filename, s);
+ g_free (s);
+ }
+ else
+ replace_table_add_key (replace_table, "LINK_NEXT", get_index_filename (items, theme, NULL, NULL));
+
+ if (previous_item) {
+ s = GET_ITEM_TARGET_FILENAME (previous_item);
+ replace_table_add_key_printf (replace_table, "LINK_PREV", theme->picture_filename, s);
+ g_free (s);
+ }
+ else
+ replace_table_add_key (replace_table, "LINK_PREV", get_index_filename (items, theme, NULL, NULL));
+
+ if (next_item != NULL && setup->preload && image_size != NULL) {
+ get_image_paths (setup, items, next_item, path_info, image_size, NULL, NULL, &preload_imgname);
+ }
+ replace_table_add_key (replace_table, "IMG_SRC_PRELOAD", preload_imgname ? preload_imgname : "");
+}
+
+static ExifData *
+get_img_exif_data (TGallerySetup *setup,
+ TPathInfo *path_info,
+ TAlbum *items,
+ TIndexItem *item,
+ TImageSize *image_size)
+{
+ ExifData *exif;
+ TImageSize *orig_image_size;
+ gchar *img_orig_src;
+ gchar *img_dst;
+ gchar *s;
+
+ /* Use external EXIF file if specified */
+ exif = NULL;
+ if (item->metadata_external_exif) {
+ s = g_path_is_absolute (item->metadata_external_exif) ? g_strdup (item->metadata_external_exif) : g_build_filename (path_info->src_dir, item->metadata_external_exif, NULL);
+ exif = read_exif (s);
+ if (exif == NULL)
+ log_error (" Error reading exif data from file %s\n", s);
+ g_free (s);
+ }
+
+ /* Get EXIF data from the original image */
+ if (exif == NULL) {
+ img_orig_src = NULL;
+ orig_image_size = lookup_image_size_for_name (setup, "original");
+ get_image_paths (setup, items, item, path_info, orig_image_size ? orig_image_size : image_size, &img_orig_src, NULL, NULL);
+ if (img_orig_src != NULL && g_access (img_orig_src, R_OK) == 0)
+ exif = read_exif (img_orig_src);
+ /* -- silently succeed
+ if (exif == NULL)
+ log_error ("write_html_image: error getting exif data from file \"%s\"\n", img_orig_src);
+ */
+ g_free (img_orig_src);
+ }
+
+ /* Try destination image instead, though it might have the metadata stripped (as in source file already) */
+ if (exif == NULL) {
+ img_dst = NULL;
+ get_image_paths (setup, items, item, path_info, image_size, NULL, &img_dst, NULL);
+ if (img_dst != NULL && g_access (img_dst, R_OK) == 0)
+ exif = read_exif (img_dst);
+ /* -- silently succeed
+ if (exif == NULL)
+ log_error ("write_html_image: error getting exif data from file \"%s\"\n", img_dst);
+ */
+ g_free (img_dst);
+ }
+
+ if (exif != NULL)
+ metadata_apply_overrides (exif, setup, path_info, items, item, image_size);
+
+ return exif;
+}
+
+/* This function fills data for the current item in the replace table and the defines hashtable */
+static void
+process_img_item (TGallerySetup *setup,
+ TPathInfo *path_info,
+ TGalleryDesignTheme *theme,
+ TAlbum *items,
+ TIndexItem *item,
+ BlockParser *block_parser,
+ ReplaceTable *replace_table,
+ GHashTable *defines,
+ TImageSize *image_size,
+ TImageSize *thumb_image_size,
+ ExifData *exif)
+{
+ unsigned long img_w, img_h;
+ unsigned long img_orig_w, img_orig_h;
+ unsigned long img_thumb_w, img_thumb_h;
+ int album_objects_count;
+ gboolean album_protected;
+ gchar *s1, *s2, *s3, *s4;
+ gchar *img_dst;
+ gchar *img_dst_page;
+ gchar *img_orig_dst;
+ gchar *img_orig_dst_page;
+ gchar *title, *title_desc;
+ TImageSize *orig_image_size;
+
+ /* FIXME: checking for image sizes essentially means thumbnails are always generated even though some pages would be fine with just textual item listing */
+
+ /* Index stuff */
+ album_protected = FALSE;
+ if (items->type == GALLERY_TYPE_INDEX) {
+ album_objects_count = 0;
+ s1 = g_build_filename (path_info->src_dir, item->path, "index.xml", NULL);
+ /* FIXME: doing additional I/O, port to global item tree */
+ get_album_info (s1, &album_objects_count, &album_protected);
+ g_free (s1);
+ replace_table_add_key_int (replace_table, "ALBUM_NUM_ITEMS", album_objects_count);
+ replace_table_add_key_printf (replace_table, "ALBUM_SUBPATH", "%s/%s", item->path, get_index_filename (items, theme, path_info, item));
+ if (album_protected && theme->index_protected_thumbnail != NULL)
+ g_hash_table_replace (defines, g_strdup ("IS_PROTECTED"), g_strdup (""));
+ }
+
+ /* Thumbnail stuff */
+ if (thumb_image_size != NULL) {
+ if (album_protected && theme->index_protected_thumbnail != NULL) {
+ s1 = setup->supplemental_files_use_common_root ? make_string ("../", get_root_level (items)) : g_strdup ("");
+ /* expecting both global and theme supplemental files are in place at this moment */
+ s2 = g_build_filename (path_info->dest_dir, s1, theme->index_protected_thumbnail, NULL);
+ s3 = g_strconcat (s1, theme->index_protected_thumbnail, NULL);
+ g_free (s1);
}
- /* Convert line breaks to be visible in the HTML code */
- if (*title) {
- str_replace (title, "\r\n", "<br />");
- str_replace (title, "\n", "<br />");
+ else {
+ get_image_paths (setup, items, item, path_info, thumb_image_size, NULL, &s2, &s3);
}
- if (*title_desc) {
- str_replace (title_desc, "\r\n", "<br />");
- str_replace (title_desc, "\n", "<br />");
+
+ img_thumb_w = img_thumb_h = 0;
+ if (s2 != NULL)
+ get_image_sizes (s2, &img_thumb_w, &img_thumb_h, setup->autorotate);
+
+ if (thumb_image_size->squared_thumb || img_thumb_w == img_thumb_h)
+ replace_table_add_key (replace_table, "THUMB_ORIENTATION", "squared");
+ else
+ replace_table_add_key (replace_table, "THUMB_ORIENTATION", (img_thumb_h > img_thumb_w) ? "portrait" : "landscape");
+
+ if (s3 != NULL) {
+ replace_table_add_key (replace_table, "IMG_SRC_THUMB", s3);
+ if (img_thumb_w > 0 && img_thumb_h > 0) {
+ replace_table_add_key_int (replace_table, "IMG_SIZE_THUMB_W", img_thumb_w);
+ replace_table_add_key_int (replace_table, "IMG_SIZE_THUMB_H", img_thumb_h);
+ }
}
+ g_free (s2);
+ g_free (s3);
+
+ s1 = GET_ITEM_TARGET_FILENAME (item);
+ replace_table_add_key_printf (replace_table, "IMG_SUBPAGE", theme->picture_filename, s1);
+ replace_table_add_key (replace_table, "IMG_FILENAME", s1);
+ g_free (s1);
+ replace_table_add_key (replace_table, "IMG_TITLE", item->title);
+ replace_table_add_key (replace_table, "IMG_DESCRIPTION", item->title_description);
}
- if (*title)
- *title = g_strstrip (*title);
- if (*title_desc)
- *title_desc = g_strstrip (*title_desc);
-}
+ /* Image stuff */
+ if (image_size != NULL) {
+ /* First calculate image paths */
+ img_dst = img_dst_page = NULL;
+ get_image_paths (setup, items, item, path_info, image_size, NULL, &img_dst, &img_dst_page);
+
+ /* Retrieve image sizes */
+ get_image_sizes (img_dst, &img_w, &img_h, setup->autorotate);
+ replace_table_add_key_int (replace_table, "IMG_SIZE_W", img_w);
+ replace_table_add_key_int (replace_table, "IMG_SIZE_H", img_h);
+ replace_table_add_key (replace_table, "IMG_SRC", img_dst_page);
+
+ /* TODO: legacy stuff, subject to removal */
+ orig_image_size = lookup_image_size_for_name (setup, "original");
+ if (orig_image_size == NULL)
+ orig_image_size = image_size;
+ if (image_size != orig_image_size && img_orig_dst != NULL && ! IS_NOFULLSIZE (item, items, setup)) {
+ img_orig_dst = img_orig_dst_page = NULL;
+ get_image_paths (setup, items, item, path_info, orig_image_size, NULL, &img_orig_dst, &img_orig_dst_page);
+ get_image_sizes (img_orig_dst, &img_orig_w, &img_orig_h, setup->autorotate);
+ g_hash_table_replace (defines, g_strdup ("HAS_FULLSIZE"), g_strdup (""));
+ replace_table_add_key_int (replace_table, "IMG_SIZE_FULLSIZE_W", img_orig_w);
+ replace_table_add_key_int (replace_table, "IMG_SIZE_FULLSIZE_H", img_orig_h);
+ replace_table_add_key (replace_table, "IMG_SRC_FULLSIZE", img_orig_dst_page);
+ g_free (img_orig_dst);
+ g_free (img_orig_dst_page);
+ }
+
+ /* Get title and description from IPTC/EXIF/JPEG if not defined */
+ get_item_titles (setup, item, exif, &title, &title_desc);
+ replace_table_add_key (replace_table, "IMG_TITLE", title);
+ replace_table_add_key (replace_table, "IMG_DESCRIPTION", title_desc);
+
+ /* Page title */
+ s1 = (title && strlen (title) > 0) ? g_strdup_printf ("%s | ", title) : NULL;
+ s2 = g_strdup_printf ("%s [%d/%d]", items->title ? items->title : items->ID, get_display_item_index (items, item), get_display_item_count (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);
+ g_free (s1);
+ g_free (s2);
+ g_free (s3);
+ g_free (s4);
+
+ g_free (title);
+ g_free (title_desc);
+
+ /* EXIF callbacks - all do handle NULL value pointer */
+ replace_table_register_function (replace_table, "get_exif_value", get_exif_value_cb, exif);
+ replace_table_register_function (replace_table, "get_exif_value_fixed", get_exif_value_fixed_cb, exif);
+ block_parser_register_function (block_parser, "has_exif_key", has_exif_key_cb, exif);
+ if (exif != NULL && exif_has_key (exif, EXIF_APERTURE) &&
+ exif_has_key (exif, EXIF_FOCAL_LENGTH) &&
+ exif_has_key (exif, EXIF_EXPOSURE))
+ g_hash_table_replace (defines, g_strdup ("HAS_EXIF"), g_strdup (""));
+
+ /* Border style */
+ s1 = get_prop_string (items, item, PROP_BORDER_STYLE, NULL);
+ if (s1)
+ g_hash_table_replace (defines, g_strdup ("BORDER_STYLE"), s1);
+
+ g_free (img_dst);
+ g_free (img_dst_page);
+ }
+
+ /* Common tags */
+ replace_table_add_key_printf (replace_table, "IMG_POS_MARKER", POSITION_MARKER_FMT, get_item_index (items, item));
+ replace_table_add_key_int (replace_table, "ITEM_INDEX", get_display_item_index (items, item));
+}
/*
- * write_html_album: process album and index template files
+ * write_html_page: process template file
*
* template_src = template file of the album/index
* dst = save generated file as
* items = array of items in the album/index
+ * item = when non-NULL, page will be written as a single picture page
*
*/
gboolean
-write_html_album (TGallerySetup *setup,
- TPathInfo *path_info,
- TGalleryDesignTheme *theme,
- const gchar *template_src,
- const gchar *dst,
- TAlbum *items)
+write_html_page (TGallerySetup *setup,
+ TPathInfo *path_info,
+ TGalleryDesignTheme *theme,
+ const gchar *template_src,
+ const gchar *dst,
+ TAlbum *items,
+ TIndexItem *item)
{
FILE *fin;
FILE *fout;
gpointer buffer;
gchar *line;
GString *block;
- gchar *templates_path;
gchar *s1, *s2, *s3;
TAlbum *parent;
- TIndexItem *item;
- TIndexItem *tmp_item;
+ TIndexItem *iter_item;
int level;
gboolean res;
int bb;
int i;
- unsigned int real_total_items;
- unsigned long img_thumb_w, img_thumb_h;
- int album_objects_count;
- gboolean album_protected;
ReplaceTable *global_replace_table;
ReplaceTable *local_replace_table;
BlockParser *block_parser;
+ BlockParser *local_block_parser;
+ GHashTable *defines;
+ GHashTable *local_defines;
TImageSize *image_size, *thumb_image_size;
- GHashTable *defines, *local_defines;
+ ExifData *exif;
+ res = TRUE;
fin = fopen (template_src, "r");
if (fin == NULL) {
- log_error ("write_html_index: error reading file \"%s\": %s\n", template_src, strerror (errno));
+ log_error ("write_html_page: error reading file \"%s\": %s\n", template_src, strerror (errno));
return FALSE;
}
fout = fopen (dst, "w");
if (fout == NULL) {
- log_error ("write_html_index: error writing to file \"%s\": %s\n", dst, strerror (errno));
+ log_error ("write_html_page: error writing to file \"%s\": %s\n", dst, strerror (errno));
fclose (fin);
return FALSE;
}
- res = TRUE;
-
defines = clone_string_hash_table (theme->defines);
global_replace_table = replace_table_new ();
replace_table_set_strip_unused_tags (global_replace_table, setup->strip_unused_tags);
@@ -605,29 +949,27 @@ write_html_album (TGallerySetup *setup,
block_parser = block_parser_new ();
block_parser_set_conditionals (block_parser, defines);
- /* Get number of real pictures in the list */
- real_total_items = 0;
- for (i = 0; i < items->items->len; i++) {
- tmp_item = g_ptr_array_index (items->items, i);
- if (tmp_item->type == INDEX_ITEM_TYPE_PICTURE && (! tmp_item->hidden))
- real_total_items++;
- }
- replace_table_add_key_int (global_replace_table, "TOTAL_ITEMS", real_total_items);
-
/* Page title */
- if (items->parent_index == NULL || setup->site_title == NULL)
- s1 = g_strdup (setup->site_title ? setup->site_title : items->ID);
- else
- s1 = g_strdup_printf ("%s | %s", items->title, setup->site_title);
- replace_table_add_key (global_replace_table, "PAGE_TITLE", s1);
- g_free (s1);
+ if (item == NULL) {
+ if (items->parent_index == NULL || setup->site_title == NULL)
+ s1 = g_strdup (setup->site_title ? setup->site_title : items->ID);
+ else
+ s1 = g_strdup_printf ("%s | %s", items->title, setup->site_title);
+ replace_table_add_key (global_replace_table, "PAGE_TITLE", s1);
+ g_free (s1);
+ } else {
+ /* Single image title is filled in by process_img_item() */
+ }
/* Simple placeholders */
replace_table_add_key (global_replace_table, "ID", items->ID);
replace_table_add_key (global_replace_table, "TITLE", items->title);
replace_table_add_key (global_replace_table, "DESCRIPTION", items->desc);
- replace_table_add_key (global_replace_table, "FOOTNOTE", items->footnote);
replace_table_add_key (global_replace_table, "FOOTER", setup->footer);
+ replace_table_add_key_int (global_replace_table, "TOTAL_ITEMS", get_display_item_count (items));
+ if (item == NULL) {
+ replace_table_add_key (global_replace_table, "FOOTNOTE", items->footnote);
+ }
/* Go Up string */
parent = items->parent_index;
@@ -642,28 +984,31 @@ write_html_album (TGallerySetup *setup,
if (! parent)
g_hash_table_replace (defines, g_strdup ("IS_ROOT"), g_strdup (""));
- /* Supportfiles path */
- level = get_root_level (items);
- templates_path = setup->supplemental_files_use_common_root ? make_string ("../", level) : g_strdup ("");
-
/* META tags */
add_meta_tags (setup, items, global_replace_table, NULL);
-
add_support_tags (setup, items, global_replace_table);
/* Theming */
- /* TODO: "image_size" will be used for album themes showing pictures inpage */
- image_size = lookup_image_size_for_name (setup, theme->album_image_size);
- thumb_image_size = lookup_image_size_for_name (setup, items->type == GALLERY_TYPE_ALBUM ? theme->album_thumb_size : theme->index_thumb_size);
- g_assert (thumb_image_size != NULL);
+ image_size = NULL;
+ thumb_image_size = NULL;
+ if (item != NULL) {
+ image_size = lookup_image_size_for_name (setup, theme->picture_image_size);
+ } else {
+ if (items->type == GALLERY_TYPE_ALBUM)
+ image_size = lookup_image_size_for_name (setup, theme->album_image_size);
+ thumb_image_size = lookup_image_size_for_name (setup, items->type == GALLERY_TYPE_ALBUM ? theme->album_thumb_size : theme->index_thumb_size);
+ }
+
+ /* Previous and next links, next image preload */
+ if (item != NULL)
+ add_next_prev_links (setup, path_info, theme, items, item, global_replace_table, image_size);
/* Setup block parser */
block_parser_register_key (block_parser, "IMG_LIST", "IMG_LIST");
- block_parser_register_key (block_parser, "IMG_LIST_LANDSCAPE", NULL);
- block_parser_register_key (block_parser, "IMG_LIST_PORTRAIT", NULL);
- block_parser_register_key (block_parser, "IMG_LIST_SQUARED", NULL);
+ block_parser_register_key (block_parser, "LIST_PICTURE", NULL);
block_parser_register_key (block_parser, "LIST_SEPARATOR", NULL);
block_parser_register_key (block_parser, "LIST_INTERSPACE", NULL);
+ block_parser_register_key (block_parser, "SINGLE_PICTURE", "SINGLE_PICTURE");
block_parser_register_key (block_parser, "NAV_BAR", "NAV_BAR");
block_parser_register_key (block_parser, "NAV_BAR_FIRST", NULL);
block_parser_register_key (block_parser, "NAV_BAR_ELEM", NULL);
@@ -678,95 +1023,54 @@ write_html_album (TGallerySetup *setup,
line = block_parser_process (block_parser, buffer);
if (block_parser_has_unused_data (block_parser, "IMG_LIST")) {
- block = g_string_new ("");
-
/* Now we have all block placeholders read, generate the items: */
+ block = g_string_new ("");
for (i = 0; i < items->items->len; i++) {
- item = g_ptr_array_index (items->items, i);
- if (item == NULL) {
- log_error ("write_html_index: error getting item %d\n", i);
+ iter_item = g_ptr_array_index (items->items, i);
+ if (iter_item == NULL) {
+ log_error ("write_html_page: error getting item %d\n", i);
continue;
}
+ local_block_parser = block_parser_new ();
local_replace_table = replace_table_new ();
local_defines = clone_string_hash_table (defines);
s1 = NULL;
+ exif = NULL;
- switch (item->type) {
+ switch (iter_item->type) {
case INDEX_ITEM_TYPE_PICTURE:
- /* Skip HTML code generation if it's a hidden item */
- if (! item->hidden) {
- album_protected = FALSE;
- album_objects_count = 0;
- if (items->type == GALLERY_TYPE_INDEX) {
- s3 = g_build_filename (path_info->src_dir, item->path, "index.xml", NULL);
- /* FIXME: doing additional I/O, port to global item tree */
- get_album_info (s3, &album_objects_count, &album_protected);
- g_free (s3);
- replace_table_add_key_int (local_replace_table, "ALBUM_NUM_ITEMS", album_objects_count);
- replace_table_add_key_printf (local_replace_table, "ALBUM_SUBPATH", "%s/%s", item->path, get_index_filename (items, theme, path_info, item));
- }
-
- img_thumb_w = img_thumb_h = 0;
- if (album_protected && theme->album_protected_thumbnail != NULL) {
- g_hash_table_replace (local_defines, g_strdup ("IS_PROTECTED"), g_strdup (""));
- /* expecting both global and theme supplemental files are in place at this moment */
- s2 = g_build_filename (path_info->dest_dir, templates_path, theme->album_protected_thumbnail, NULL);
- s3 = g_strconcat (templates_path, theme->album_protected_thumbnail, NULL);
- }
- else {
- get_image_paths (setup, items, item, i, path_info, thumb_image_size, NULL, &s2, &s3);
- }
-
- if (s2 != NULL)
- get_image_sizes (s2, &img_thumb_w, &img_thumb_h, setup->autorotate);
-
- if (thumb_image_size->squared_thumb || img_thumb_w == img_thumb_h)
- s1 = "IMG_LIST_SQUARED";
- else
- s1 = (img_thumb_h > img_thumb_w) ? "IMG_LIST_PORTRAIT" : "IMG_LIST_LANDSCAPE";
-
- s1 = block_parser_get_data (block_parser, s1);
- if (s3 != NULL) {
- replace_table_add_key (local_replace_table, "IMG_THUMBNAIL", s3);
- if (img_thumb_w > 0 && img_thumb_h > 0) {
- replace_table_add_key_int (local_replace_table, "IMG_SIZE_THUMB_W", img_thumb_w);
- replace_table_add_key_int (local_replace_table, "IMG_SIZE_THUMB_H", img_thumb_h);
- }
- }
- g_free (s2);
- g_free (s3);
-
- s2 = GET_ITEM_TARGET_FILENAME (item);
- replace_table_add_key_printf (local_replace_table, "IMG_SUBPAGE", theme->picture_filename, s2);
- replace_table_add_key (local_replace_table, "IMG_FILENAME", s2);
- g_free (s2);
- replace_table_add_key (local_replace_table, "IMG_TITLE", item->title);
- replace_table_add_key (local_replace_table, "IMG_DESCRIPTION", item->title_description);
- replace_table_add_key_printf (local_replace_table, "IMG_LIST_ID", "i%d", i + 1);
+ if (! iter_item->hidden) {
+ s1 = block_parser_get_data (block_parser, "LIST_PICTURE");
+ if (image_size != NULL)
+ exif = get_img_exif_data (setup, path_info, items, iter_item, image_size);
+ process_img_item (setup, path_info, theme, items, iter_item, local_block_parser, local_replace_table, local_defines, image_size, thumb_image_size, exif);
}
break;
case INDEX_ITEM_TYPE_SEPARATOR:
s1 = block_parser_get_data (block_parser, "LIST_SEPARATOR");
- replace_table_add_key (local_replace_table, "LIST_SEPARATOR_TITLE", item->title);
+ replace_table_add_key (local_replace_table, "LIST_SEPARATOR_TITLE", iter_item->title);
break;
case INDEX_ITEM_TYPE_INTERSPACE:
s1 = block_parser_get_data (block_parser, "LIST_INTERSPACE");
- replace_table_add_key (local_replace_table, "LIST_INTERSPACE_TITLE", item->title);
+ replace_table_add_key (local_replace_table, "LIST_INTERSPACE_TITLE", iter_item->title);
break;
}
if (s1) {
- s2 = process_block (setup, local_replace_table, local_defines, s1);
+ s2 = process_block (setup, local_block_parser, local_replace_table, local_defines, s1);
g_string_append (block, s2);
g_free (s2);
g_free (s1);
}
+ exif_data_free (exif);
+ block_parser_free (local_block_parser);
replace_table_free (local_replace_table);
g_hash_table_destroy (local_defines);
}
+
s1 = g_string_free (block, FALSE);
replace_table_process (&s1, global_replace_table);
replace_table_add_key (global_replace_table, "IMG_LIST", s1);
@@ -775,8 +1079,26 @@ write_html_album (TGallerySetup *setup,
block_parser_set_as_used (block_parser, "IMG_LIST");
}
+ if (block_parser_has_unused_data (block_parser, "SINGLE_PICTURE")) {
+ local_block_parser = block_parser_new ();
+ exif = NULL;
+ if (image_size != NULL)
+ exif = get_img_exif_data (setup, path_info, items, item, image_size);
+ process_img_item (setup, path_info, theme, items, item, local_block_parser, global_replace_table, defines, image_size, thumb_image_size, exif);
+ s1 = block_parser_get_data (block_parser, "SINGLE_PICTURE");
+ s2 = process_block (setup, local_block_parser, global_replace_table, defines, s1);
+ replace_table_process (&s2, global_replace_table);
+ replace_table_add_key (global_replace_table, "SINGLE_PICTURE", s2);
+ exif_data_free (exif);
+ block_parser_free (local_block_parser);
+ g_free (s1);
+ g_free (s2);
+ }
+
if (block_parser_has_unused_data (block_parser, "NAV_BAR")) {
- s1 = make_navbar_string (setup, theme, block_parser, defines, items, -1, items->ID);
+ s2 = item != NULL ? GET_ITEM_TARGET_FILENAME (item) : NULL;
+ s1 = make_navbar_string (setup, theme, block_parser, defines, items, item ? get_item_index (items, item) : -1, s2 ? s2 : items->ID);
+ g_free (s2);
replace_table_process (&s1, global_replace_table);
replace_table_add_key (global_replace_table, "NAV_BAR", s1);
g_free (s1);
@@ -790,7 +1112,7 @@ write_html_album (TGallerySetup *setup,
bb = fputs (line, fout);
g_free (line);
if (bb < 0) {
- log_error ("write_html_index: error writing to file \"%s\": %s\n", dst, strerror (errno));
+ log_error ("write_html_page: error writing to file \"%s\": %s\n", dst, strerror (errno));
res = FALSE;
break;
}
@@ -802,317 +1124,6 @@ write_html_album (TGallerySetup *setup,
g_hash_table_destroy (defines);
replace_table_free (global_replace_table);
block_parser_free (block_parser);
- g_free (templates_path);
- return res;
-}
-
-static char *
-get_exif_value_cb (gchar **args, gpointer user_data)
-{
- ExifData *exif = user_data;
-
- if (exif == NULL)
- return NULL;
- g_return_val_if_fail (g_strv_length (args) != 2, NULL); /* incl. trailing NULL */
-
- return get_exif_data (exif, *args);
-}
-
-static char *
-get_exif_value_fixed_cb (gchar **args, gpointer user_data)
-{
- ExifData *exif = user_data;
-
- if (exif == NULL)
- return NULL;
- g_return_val_if_fail (g_strv_length (args) != 2, NULL); /* incl. trailing NULL */
-
- return get_exif_data_fixed (exif, *args);
-}
-
-static gboolean
-has_exif_key_cb (gchar **args, gpointer user_data)
-{
- ExifData *exif = user_data;
-
- if (exif == NULL)
- return FALSE;
- g_return_val_if_fail (g_strv_length (args) != 2, FALSE); /* incl. trailing NULL */
-
- return exif_has_key (exif, *args);
-}
-
-
-/*
- * write_html_image: process single image template file
- *
- * template_src = template file of the album/index
- * dst = save generated file as
- * item = data for the current item
- * parent_items = array of items in the album, to determine our position and make links to previous/next image
- *
- */
-gboolean
-write_html_image (TGallerySetup *setup,
- TPathInfo *path_info,
- TGalleryDesignTheme *theme,
- const gchar *template_src,
- const gchar *dst,
- TIndexItem *item,
- TAlbum *parent_items)
-{
- FILE *fin;
- FILE *fout;
- gpointer buffer;
- gchar *img_dst;
- gchar *img_dst_page;
- gchar *img_orig_src;
- gchar *img_orig_dst;
- gchar *img_orig_dst_page;
- ExifData *exif;
- unsigned long img_w, img_h;
- unsigned long img_orig_w, img_orig_h;
- unsigned int item_index, next_item_index, real_item_index, real_total_items;
- TIndexItem *previous_item;
- TIndexItem *next_item;
- TIndexItem *tmp_item;
- int i;
- gchar *line;
- gchar *s1, *s2, *s3, *s4;
- gchar *imgname, *preload_imgname;
- gchar *title, *title_desc;
- gboolean res;
- int bb;
- gboolean image_fullsize;
- gboolean theme_size_is_original;
- ReplaceTable *replace_table;
- BlockParser *block_parser;
- TImageSize *image_size;
- GHashTable *defines;
-
-
- fin = fopen (template_src, "r");
- if (fin == NULL) {
- log_error ("write_html_image: error reading file \"%s\": %s\n", template_src, strerror (errno));
- return FALSE;
- }
- fout = fopen (dst, "w");
- if (fout == NULL) {
- log_error ("write_html_image: error writing to file \"%s\": %s\n", dst, strerror (errno));
- fclose (fin);
- return FALSE;
- }
-
- img_orig_src = NULL;
- img_orig_dst = NULL;
- img_orig_dst_page = NULL;
- preload_imgname = NULL;
- res = TRUE;
-
- defines = clone_string_hash_table (theme->defines);
- replace_table = replace_table_new ();
- replace_table_set_strip_unused_tags (replace_table, setup->strip_unused_tags);
- replace_table_set_defines (replace_table, defines);
- block_parser = block_parser_new ();
- block_parser_set_conditionals (block_parser, defines);
-
- /* Get our index in the album */
- item_index = 0;
- real_item_index = 0;
- real_total_items = 0;
- for (i = 0; i < parent_items->items->len; i++) {
- tmp_item = g_ptr_array_index (parent_items->items, i);
- if (tmp_item->type == INDEX_ITEM_TYPE_PICTURE) {
- if (! item_index) real_item_index++;
- real_total_items++;
- }
- if (tmp_item == item)
- item_index = i + 1;
- }
-
- /* Get previous and next items */
- previous_item = NULL;
- next_item = NULL;
- next_item_index = 0;
- for (i = item_index - 2; i >= 0 && (previous_item == NULL || previous_item->type != INDEX_ITEM_TYPE_PICTURE); i--)
- previous_item = g_ptr_array_index (parent_items->items, i);
- if (previous_item && previous_item->type != INDEX_ITEM_TYPE_PICTURE)
- previous_item = NULL;
- for (i = item_index; i < parent_items->items->len && (next_item == NULL || next_item->type != INDEX_ITEM_TYPE_PICTURE); i++) {
- next_item = g_ptr_array_index (parent_items->items, i);
- next_item_index = i;
- }
- if (next_item && next_item->type != INDEX_ITEM_TYPE_PICTURE) {
- next_item = NULL;
- next_item_index = 0;
- }
-
- /* If currently processed picture size is original, disable fullsize tags */
- theme_size_is_original = g_ascii_strcasecmp (theme->picture_image_size, "original") == 0;
- /* Original size is needed for several things, like EXIF and IPTC metadata */
- image_size = lookup_image_size_for_name (setup, "original");
- get_image_paths (setup, parent_items, item, item_index, path_info, image_size, &img_orig_src, &img_orig_dst, &img_orig_dst_page);
- image_size = lookup_image_size_for_name (setup, theme->picture_image_size);
- get_image_paths (setup, parent_items, item, item_index, path_info, image_size, NULL, &img_dst, &img_dst_page);
- imgname = g_path_get_basename (img_dst);
- if (next_item && setup->preload)
- get_image_paths (setup, parent_items, next_item, next_item_index, path_info, image_size, NULL, NULL, &preload_imgname);
-
- /* Use external EXIF file if specified */
- exif = NULL;
- if (item->metadata_external_exif) {
- s1 = g_path_is_absolute (item->metadata_external_exif) ? g_strdup (item->metadata_external_exif) : g_build_filename (path_info->src_dir, item->metadata_external_exif, NULL);
- exif = read_exif (s1);
- if (exif == NULL)
- log_error (" Error reading exif data from file %s\n", s1);
- g_free (s1);
- }
- /* Get EXIF data from the original image */
- if (exif == NULL && img_orig_src) {
- if (g_access (img_orig_src, R_OK) == 0)
- exif = read_exif (img_orig_src);
- /* -- silently succeed
- if (exif == NULL)
- log_error ("write_html_image: error getting exif data from file \"%s\"\n", img_orig_src);
- */
- }
- /* Try destination image instead, though it might have the metadata stripped (as in source file already) */
- if (exif == NULL) {
- if (g_access (img_dst, R_OK) == 0)
- exif = read_exif (img_dst);
- /* -- silently succeed
- if (exif == NULL)
- log_error ("write_html_image: error getting exif data from file \"%s\"\n", img_dst);
- */
- }
- if (exif != NULL)
- metadata_apply_overrides (exif, setup, path_info, parent_items, item, image_size);
- /* Test for basic EXIF keys presence */
- if (exif != NULL && exif_has_key (exif, EXIF_APERTURE) &&
- exif_has_key (exif, EXIF_FOCAL_LENGTH) &&
- exif_has_key (exif, EXIF_EXPOSURE))
- g_hash_table_replace (defines, g_strdup ("HAS_EXIF"), g_strdup (""));
-
- /* Retrieve image sizes of preview and original image */
- get_image_sizes (img_dst, &img_w, &img_h, setup->autorotate);
- image_fullsize = ! theme_size_is_original && img_orig_dst != NULL && ! IS_NOFULLSIZE (item, parent_items, setup);
- if (image_fullsize) {
- get_image_sizes (img_orig_dst, &img_orig_w, &img_orig_h, setup->autorotate);
- g_hash_table_replace (defines, g_strdup ("HAS_FULLSIZE"), g_strdup (""));
- }
-
- /* Get title and description from IPTC/EXIF/JPEG if not defined */
- get_item_titles (setup, item, exif, &title, &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);
- g_free (s1);
- g_free (s2);
- 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_W", img_w);
- replace_table_add_key_int (replace_table, "IMG_SIZE_H", img_h);
- replace_table_add_key (replace_table, "IMG_SRC", img_dst_page);
- replace_table_add_key (replace_table, "IMG_SRC_PRELOAD", preload_imgname ? preload_imgname : "");
- if (image_fullsize) {
- 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);
- replace_table_add_key (replace_table, "IMG_SRC_FULL", img_orig_dst_page);
- }
-
- replace_table_register_function (replace_table, "get_exif_value", get_exif_value_cb, exif);
- replace_table_register_function (replace_table, "get_exif_value_fixed", get_exif_value_fixed_cb, exif);
- block_parser_register_function (block_parser, "has_exif_key", has_exif_key_cb, exif);
-
- /* Border style */
- s1 = get_prop_string (parent_items, item, PROP_BORDER_STYLE, NULL);
- if (s1)
- g_hash_table_replace (defines, g_strdup ("BORDER_STYLE"), s1);
-
- /* Next/Previous links */
- if (next_item) {
- s2 = GET_ITEM_TARGET_FILENAME (next_item);
- replace_table_add_key_printf (replace_table, "LINK_NEXT", theme->picture_filename, s2);
- g_free (s2);
- }
- else
- replace_table_add_key (replace_table, "LINK_NEXT", get_index_filename (parent_items, theme, NULL, NULL));
- if (previous_item) {
- s2 = GET_ITEM_TARGET_FILENAME (previous_item);
- replace_table_add_key_printf (replace_table, "LINK_PREV", theme->picture_filename, s2);
- g_free (s2);
- }
- else
- replace_table_add_key (replace_table, "LINK_PREV", get_index_filename (parent_items, theme, NULL, NULL));
-
- /* META tags */
- add_meta_tags (setup, parent_items, replace_table, title);
-
- add_support_tags (setup, parent_items, replace_table);
-
- /* Setup block parser */
- block_parser_register_key (block_parser, "NAV_BAR", "NAV_BAR");
- block_parser_register_key (block_parser, "NAV_BAR_FIRST", NULL);
- block_parser_register_key (block_parser, "NAV_BAR_ELEM", NULL);
- block_parser_register_key (block_parser, "NAV_BAR_LAST", NULL);
- block_parser_register_key (block_parser, "NAV_BAR_CURRENT", NULL);
- block_parser_register_key (block_parser, "NAV_BAR_CURRENT_ROOT", NULL);
-
-
- /* Read through the template and replace placeholders with real data */
- buffer = g_malloc0 (BUFFER_SIZE);
- while (fgets (buffer, BUFFER_SIZE, fin)) {
- line = block_parser_process (block_parser, buffer);
-
- if (block_parser_has_unused_data (block_parser, "NAV_BAR")) {
- s1 = make_navbar_string (setup, theme, block_parser, defines, parent_items, item_index, imgname);
- replace_table_process (&s1, replace_table);
- replace_table_add_key (replace_table, "NAV_BAR", s1);
- g_free (s1);
- block_parser_set_as_used (block_parser, "NAV_BAR");
- }
-
- /* Replace all known tags */
- replace_table_process (&line, replace_table);
-
- /* Write to file */
- bb = fputs (line, fout);
- g_free (line);
- if (bb < 0) {
- log_error ("write_html_image: error writing to file \"%s\": %s\n", dst, strerror (errno));
- res = FALSE;
- break;
- }
- }
-
- fclose (fout);
- fclose (fin);
- g_free (buffer);
- g_free (title);
- g_free (title_desc);
- g_free (img_dst);
- g_free (img_dst_page);
- g_free (img_orig_src);
- g_free (img_orig_dst);
- g_free (img_orig_dst_page);
- g_free (imgname);
- g_free (preload_imgname);
- g_hash_table_destroy (defines);
- exif_data_free (exif);
- replace_table_free (replace_table);
- block_parser_free (block_parser);
return res;
}