summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2009-03-28 13:45:39 +0100
committerTomas Bzatek <tbzatek@users.sourceforge.net>2009-03-28 13:45:39 +0100
commitd9ff1192a7b5eb7defca68e90e06c68e9b986c94 (patch)
tree904f1ff183e50aa56f4521cac87712aa163d3cca
parent7d00adae2749556d077af1fa3f0de13a2ea8e4a2 (diff)
downloadcataract-d9ff1192a7b5eb7defca68e90e06c68e9b986c94.tar.xz
Support for custom index file name
Affects every generated HTML file (i.e. all of them would have .php extensions)
-rw-r--r--sample/src/setup.xml5
-rw-r--r--src/gallery-utils.c17
-rw-r--r--src/gallery-utils.h9
-rw-r--r--src/generators.c27
-rw-r--r--src/setup.c6
-rw-r--r--src/setup.h2
6 files changed, 49 insertions, 17 deletions
diff --git a/sample/src/setup.xml b/sample/src/setup.xml
index 2a941c7..c306b80 100644
--- a/sample/src/setup.xml
+++ b/sample/src/setup.xml
@@ -19,6 +19,11 @@
scripts-general.js
]]></template_files>
+ <!-- specify index file name to use (default = index.html) -->
+ <!-- e.g. you may want 'index.php' if your templates are server-side dynamic -->
+ <!-- filename extension is also used for separate image files -->
+ <index_file>index.html</index_file>
+
<!-- use root gallery directory to store all support files -->
<!-- and relative paths in sub-albums -->
<!-- default = no (old behaviour) -->
diff --git a/src/gallery-utils.c b/src/gallery-utils.c
index 63744b9..2958c51 100644
--- a/src/gallery-utils.c
+++ b/src/gallery-utils.c
@@ -151,7 +151,7 @@ copy_file (const char *src, const char *dst)
* - returns newly allocated string
*/
char *
-make_string (const char* substr, int count)
+make_string (const char *substr, int count)
{
int i;
char *s;
@@ -273,7 +273,7 @@ remove_tags (char **str, const char *tag_begin, const char *tag_end)
* count_dir_levels: returns number of path elements
*/
int
-count_dir_levels (const char* path)
+count_dir_levels (const char *path)
{
int i;
int level;
@@ -289,3 +289,16 @@ count_dir_levels (const char* path)
return level;
}
+
+
+/*
+ * extract_file_ext: returns pointer to filename extension
+ */
+const char *
+extract_file_ext (const char *filename)
+{
+ g_return_val_if_fail (filename != NULL, NULL);
+ g_return_val_if_fail (strlen (filename) > 0, NULL);
+
+ return strrchr (filename, '.') + 1;
+}
diff --git a/src/gallery-utils.h b/src/gallery-utils.h
index 3b12616..7e5e2c0 100644
--- a/src/gallery-utils.h
+++ b/src/gallery-utils.h
@@ -37,7 +37,7 @@ gboolean copy_file (const char *src, const char *dst);
* make_string: make string of 'substr' substrings
* - returns newly allocated string
*/
-char *make_string (const char* substr, int count);
+char *make_string (const char *substr, int count);
/*
* fix_entities: replace all invalid & entities with &amp;
@@ -55,4 +55,9 @@ void remove_tags (char **str, const char *tag_begin, const char *tag_end);
/*
* count_dir_levels: returns number of path elements
*/
-int count_dir_levels (const char* path);
+int count_dir_levels (const char *path);
+
+/*
+ * extract_file_ext: returns pointer to filename extension
+ */
+const char *extract_file_ext (const char *filename);
diff --git a/src/generators.c b/src/generators.c
index a6e0ba0..e2f9d7f 100644
--- a/src/generators.c
+++ b/src/generators.c
@@ -34,6 +34,7 @@
#define DEFAULT_DATA_DIR_MODE S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH
+#define GET_EXT(s) strrchr (s, '.')
/*
* generate_image: auxiliary function for write_html_album
@@ -304,7 +305,7 @@ write_html_album (TGallerySetup *setup,
/* Go Up string */
s3 = make_string ("../", level);
s2 = setup->use_inpage_links ? g_strdup_printf ("#i%d", old_parent_item_index) : g_strdup ("");
- replace_table_add_key_printf (global_replace_table, "GO_UP_LINK", "%sindex.html%s", s3, s2);
+ replace_table_add_key_printf (global_replace_table, "GO_UP_LINK", "%s%s%s", s3, setup->index_file_name, s2);
g_free (s2);
free (s3);
@@ -312,7 +313,7 @@ write_html_album (TGallerySetup *setup,
s3 = make_string ("../", level);
s4 = g_strdup (parent->ID);
s5 = setup->use_inpage_links ? g_strdup_printf ("#i%d", old_parent_item_index) : g_strdup ("");
- s2 = g_strdup_printf ("<a href=\"%sindex.html%s\">%s</a> &gt; %s", s3, s5, s4, s1);
+ s2 = g_strdup_printf ("<a href=\"%s%s%s\">%s</a> &gt; %s", s3, setup->index_file_name, s5, s4, s1);
free (s3);
g_free (s1);
g_free (s4);
@@ -478,8 +479,8 @@ write_html_album (TGallerySetup *setup,
else
s1 = strdup (buf_img_list_portrait);
- replace_table_add_key_printf (local_replace_table, "ALBUM_SUBPATH", "%s/index.html", item->path);
- replace_table_add_key_printf (local_replace_table, "IMG_SUBPAGE", "%s.html", img_src);
+ replace_table_add_key_printf (local_replace_table, "ALBUM_SUBPATH", "%s/%s", item->path, setup->index_file_name);
+ replace_table_add_key_printf (local_replace_table, "IMG_SUBPAGE", "%s%s", img_src, GET_EXT (setup->index_file_name));
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);
@@ -742,7 +743,7 @@ write_html_image (TGallerySetup *setup,
s3 = make_string ("../", level);
s4 = g_strdup (parent->ID);
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);
+ s2 = g_strdup_printf ("<a href=\"%s%s%s\">%s</a> &gt; %s", s3, setup->index_file_name, s5, s4, s1);
free (s3);
g_free (s1);
g_free (s4);
@@ -790,18 +791,18 @@ write_html_image (TGallerySetup *setup,
/* Next/Previous links */
if (next_item) {
s2 = g_path_get_basename ((next_item->path == NULL && next_item->preview) ? next_item->preview : next_item->path);
- replace_table_add_key_printf (replace_table, "LINK_NEXT", "%s.html", s2);
+ replace_table_add_key_printf (replace_table, "LINK_NEXT", "%s%s", s2, GET_EXT (setup->index_file_name));
g_free (s2);
}
else
- replace_table_add_key (replace_table, "LINK_NEXT", "index.html");
+ replace_table_add_key (replace_table, "LINK_NEXT", setup->index_file_name);
if (previous_item) {
s2 = g_path_get_basename ((previous_item->path == NULL && previous_item->preview) ? previous_item->preview : previous_item->path);
- replace_table_add_key_printf (replace_table, "LINK_PREV", "%s.html", s2);
+ replace_table_add_key_printf (replace_table, "LINK_PREV", "%s%s", s2, GET_EXT (setup->index_file_name));
g_free (s2);
}
else
- replace_table_add_key (replace_table, "LINK_PREV", "index.html");
+ replace_table_add_key (replace_table, "LINK_PREV", setup->index_file_name);
/* META tags */
override_title_meta = setup->use_title_as_meta && title && (strlen (title) > 0);
@@ -1084,9 +1085,9 @@ build_tree (TGallerySetup *setup,
/* default to album */
template = g_strconcat ("/", setup->template_album, NULL);
- if (setup->verbose) printf ("Writing 'index.html' ...\n");
+ if (setup->verbose) printf ("Writing '%s' ...\n", setup->index_file_name);
s1 = g_strconcat (setup->real_templates_dir, template, NULL);
- s2 = g_strconcat (dst_dir, "/index.html", NULL);
+ s2 = g_strconcat (dst_dir, "/", setup->index_file_name, NULL);
res = write_html_album (setup, s1, s2, items);
g_free (s1);
g_free (s2);
@@ -1132,10 +1133,10 @@ build_tree (TGallerySetup *setup,
}
if (item->type == INDEX_ITEM_TYPE_PICTURE) {
imgname = g_path_get_basename ((item->path == NULL && item->preview) ? item->preview : item->path);
- if (setup->verbose) printf ("Writing '%s.html' ...", imgname);
+ if (setup->verbose) printf ("Writing '%s%s' ...", imgname, GET_EXT (setup->index_file_name));
s1 = g_strconcat (setup->real_templates_dir, "/", setup->template_photo, NULL);
s2 = g_strconcat (items->base_dir, "/", (item->path == NULL && item->preview) ? item->preview : item->path, NULL);
- s3 = g_strconcat (dst_dir, "/", imgname, ".html", NULL);
+ s3 = g_strconcat (dst_dir, "/", imgname, GET_EXT (setup->index_file_name), NULL);
res = write_html_image (setup, s1, s2, s3, item, items);
g_free (s1);
g_free (s2);
diff --git a/src/setup.c b/src/setup.c
index f328196..145a5f2 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -100,6 +100,10 @@ parse_setup_xml (const char *filename, TGallerySetup *setup)
s = xml_file_get_node_attribute (xml, "/gallery_setup/templates/support_files_use_common_root", "value");
setup->support_files_use_common_root = s ? strcasecmp (s, "yes") == 0 : FALSE; /* default to FALSE */
if (s) g_free (s);
+ setup->index_file_name = xml_file_get_node_value (xml, "/gallery_setup/templates/index_file/text()");
+ if (setup->index_file_name == NULL || strlen (setup->index_file_name) == 0)
+ setup->index_file_name = strdup (DEFAULT_INDEX_FILENAME);
+
setup->thumbnail_landscape_width = xml_file_get_node_attribute_long (xml, "/gallery_setup/images/thumbnail", "landscape_w", 0);
setup->thumbnail_landscape_height = xml_file_get_node_attribute_long (xml, "/gallery_setup/images/thumbnail", "landscape_h", 0);
@@ -257,6 +261,8 @@ free_setup_data (TGallerySetup *setup)
free (setup->template_photo);
if (setup->template_files)
g_strfreev (setup->template_files);
+ if (setup->index_file_name)
+ free (setup->index_file_name);
if (setup->footer)
free (setup->footer);
if (setup->meta_author)
diff --git a/src/setup.h b/src/setup.h
index 5bc0e1a..7fb32bd 100644
--- a/src/setup.h
+++ b/src/setup.h
@@ -28,6 +28,7 @@
#define IMG_ORIG_DIR "_orig"
#define SETUP_XML "setup.xml"
+#define DEFAULT_INDEX_FILENAME "index.html"
@@ -44,6 +45,7 @@ typedef struct {
char *template_photo;
char **template_files;
gboolean support_files_use_common_root;
+ char *index_file_name;
char *footer;
char *meta_author;