summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2009-03-14 14:09:11 +0100
committerTomas Bzatek <tbzatek@users.sourceforge.net>2009-03-14 14:09:11 +0100
commit9514d8f844ada0b8a0b2450973374ee2ecd7b6b7 (patch)
tree045dd6cd66aa5609eb9524ac48803c4e5f5c7740
parentf37ddb3c6f7f903fd77935b7a7aefe11cbe00831 (diff)
downloadcataract-9514d8f844ada0b8a0b2450973374ee2ecd7b6b7.tar.xz
Support for common supportfiles root
-rw-r--r--sample/src/setup.xml7
-rw-r--r--src/gallery-utils.c5
-rw-r--r--src/gallery-utils.h2
-rw-r--r--src/generators.c42
-rw-r--r--src/setup.c3
-rw-r--r--src/setup.h1
-rw-r--r--templates/template-album.tmpl4
-rw-r--r--templates/template-index.tmpl4
-rw-r--r--templates/template-view_photo.tmpl4
9 files changed, 57 insertions, 15 deletions
diff --git a/sample/src/setup.xml b/sample/src/setup.xml
index e456a3c..53411ff 100644
--- a/sample/src/setup.xml
+++ b/sample/src/setup.xml
@@ -18,6 +18,11 @@
styles.css
scripts-general.js
]]></template_files>
+
+ <!-- use root gallery directory to store all support files -->
+ <!-- and relative paths in sub-albums -->
+ <!-- default = no (old behaviour) -->
+ <support_files_use_common_root value="yes" />
</templates>
<images>
@@ -77,6 +82,8 @@ And the second line.</add_copyright>
<!-- favicon support, the "type" attribute is optional, -->
<!-- please alter it to the right icon MIME type -->
<!-- http://www.w3.org/2005/10/howto-favicon -->
+ <!-- Please note that the <support_files_use_common_root> settings -->
+ <!-- declared earlier applies to favicons as well -->
<favicon type="image/png">apple-red.png</favicon>
</meta>
diff --git a/src/gallery-utils.c b/src/gallery-utils.c
index b7593fe..63744b9 100644
--- a/src/gallery-utils.c
+++ b/src/gallery-utils.c
@@ -151,11 +151,14 @@ copy_file (const char *src, const char *dst)
* - returns newly allocated string
*/
char *
-make_string (const char* substr, const int count)
+make_string (const char* substr, int count)
{
int i;
char *s;
+ if (count < 0)
+ count = 0;
+
s = malloc (strlen (substr) * count + 1);
for (i = 0; i < count; i++)
memcpy (s + (strlen (substr) * i), substr, strlen (substr));
diff --git a/src/gallery-utils.h b/src/gallery-utils.h
index 7972b39..3b12616 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, const int count);
+char *make_string (const char* substr, int count);
/*
* fix_entities: replace all invalid & entities with &amp;
diff --git a/src/generators.c b/src/generators.c
index 66ade6c..a755a45 100644
--- a/src/generators.c
+++ b/src/generators.c
@@ -291,7 +291,7 @@ write_html_album (TGallerySetup *setup,
replace_table_add_key (global_replace_table, "FOOTNOTE", items->footnote);
replace_table_add_key (global_replace_table, "FOOTER", setup->footer);
- /* Navigation bar */
+ /* Navigation bar (NOTE: 'int level' is used below + favicon) */
s1 = g_strdup (items->ID);
old_parent_item_index = items->parent_item_index + 1;
parent = items->parent_index;
@@ -330,6 +330,11 @@ write_html_album (TGallerySetup *setup,
replace_table_add_key (global_replace_table, "NAV_BAR", s1);
g_free (s1);
+ /* Supportfiles path */
+ s1 = make_string ("../", level - 1);
+ replace_table_add_key (global_replace_table, "TEMPLATES_PATH", setup->support_files_use_common_root ? s1 : "");
+ free (s1);
+
/* META tags */
s1 = g_strdup_printf ("\t<meta name=\"generator\" content=\"Cataract Gallery Generator v%s\" />\n", VERSION);
if (setup->meta_author || items->meta_author) {
@@ -357,11 +362,13 @@ write_html_album (TGallerySetup *setup,
s1 = s2;
}
if (setup->favicon_file && strlen (setup->favicon_file) > 0) {
+ s3 = make_string ("../", level - 1);
if (setup->favicon_type)
- s2 = g_strdup_printf ("%s\t<link rel=\"icon\" type=\"%s\" href=\"%s\" />\n", s1, setup->favicon_type, setup->favicon_file);
+ s2 = g_strdup_printf ("%s\t<link rel=\"icon\" type=\"%s\" href=\"%s%s\" />\n", s1, setup->favicon_type, setup->support_files_use_common_root ? s3 : "", setup->favicon_file);
else
- s2 = g_strdup_printf ("%s\t<link rel=\"icon\" href=\"%s\" />\n", s1, setup->favicon_file);
+ s2 = g_strdup_printf ("%s\t<link rel=\"icon\" href=\"%s%s\" />\n", s1, setup->support_files_use_common_root ? s3 : "", setup->favicon_file);
g_free (s1);
+ free (s3);
s1 = s2;
}
replace_table_add_key (global_replace_table, "CGG_META_TAGS", s1);
@@ -721,7 +728,7 @@ write_html_image (TGallerySetup *setup,
replace_table_add_key_printf (replace_table, "IMG_SRC_FULL", "%s/%s", IMG_ORIG_DIR, imgname);
replace_table_add_key (replace_table, "IMG_SRC_PRELOAD", preload_imgname ? preload_imgname : "");
- /* Navigation bar */
+ /* Navigation bar (NOTE: 'int level' is used below + favicon) */
s1 = g_strdup (imgname);
parent = parent_items;
old_parent_item_index = -1;
@@ -748,6 +755,11 @@ write_html_image (TGallerySetup *setup,
replace_table_add_key (replace_table, "NAV_BAR", s1);
g_free (s1);
+ /* Supportfiles path */
+ s1 = make_string ("../", level - 1);
+ replace_table_add_key (replace_table, "TEMPLATES_PATH", setup->support_files_use_common_root ? s1 : "");
+ 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 : "??");
@@ -814,10 +826,11 @@ write_html_image (TGallerySetup *setup,
s1 = s2;
}
if (setup->favicon_file && strlen (setup->favicon_file) > 0) {
+ s3 = make_string ("../", level - 1);
if (setup->favicon_type)
- s2 = g_strdup_printf ("%s\t<link rel=\"icon\" type=\"%s\" href=\"%s\" />\n", s1, setup->favicon_type, setup->favicon_file);
+ s2 = g_strdup_printf ("%s\t<link rel=\"icon\" type=\"%s\" href=\"%s%s\" />\n", s1, setup->favicon_type, setup->support_files_use_common_root ? s3 : "", setup->favicon_file);
else
- s2 = g_strdup_printf ("%s\t<link rel=\"icon\" href=\"%s\" />\n", s1, setup->favicon_file);
+ s2 = g_strdup_printf ("%s\t<link rel=\"icon\" href=\"%s%s\" />\n", s1, setup->support_files_use_common_root ? s3 : "", setup->favicon_file);
g_free (s1);
s1 = s2;
}
@@ -986,7 +999,22 @@ build_tree (TGallerySetup *setup,
items->parent_item_index = parent_item_index;
/* Copy support files */
- mirror_files (setup, setup->template_files, setup->real_templates_dir, dst_dir, "Copying template files: ");
+ if (! setup->support_files_use_common_root || parent_index == NULL) {
+ /* copy only if we're in root level or old-style is active */
+ mirror_files (setup, setup->template_files, setup->real_templates_dir, dst_dir, "Copying template files: ");
+
+ /* favicon */
+ if (setup->favicon_file && strlen (setup->favicon_file) > 0) {
+ if (setup->verbose) printf ("Copying favicon: %s\n", setup->favicon_file);
+ s3 = g_path_get_dirname (setup->setup_xml_path);
+ s1 = g_strconcat (s3, "/", setup->favicon_file, NULL);
+ s2 = g_strconcat (dst_dir, "/", setup->favicon_file, NULL);
+ copy_file (s1, s2);
+ g_free (s1);
+ g_free (s2);
+ g_free (s3);
+ }
+ }
/* Prepare target thumbnail directory */
thumb_dir = g_strconcat (dst_dir, "/", THUMBNAIL_DIR, NULL);
diff --git a/src/setup.c b/src/setup.c
index 68c32b5..17d8fda 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -97,6 +97,9 @@ parse_setup_xml (const char *filename, TGallerySetup *setup)
setup->template_files = g_strsplit (s, "\n", -1);
free (s);
}
+ 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->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);
diff --git a/src/setup.h b/src/setup.h
index 3d2e7cc..eb12f92 100644
--- a/src/setup.h
+++ b/src/setup.h
@@ -43,6 +43,7 @@ typedef struct {
char *template_album;
char *template_photo;
char **template_files;
+ gboolean support_files_use_common_root;
char *footer;
char *meta_author;
diff --git a/templates/template-album.tmpl b/templates/template-album.tmpl
index 616d6af..45f6273 100644
--- a/templates/template-album.tmpl
+++ b/templates/template-album.tmpl
@@ -5,8 +5,8 @@
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>$(PAGE_TITLE)</title>
<!-- $(CGG_META_TAGS) -->
- <link href="styles.css" type="text/css" rel="stylesheet" media="screen, print" />
- <script type="text/javascript" src="scripts-general.js"> </script>
+ <link href="$(TEMPLATES_PATH)styles.css" type="text/css" rel="stylesheet" media="screen, print" />
+ <script type="text/javascript" src="$(TEMPLATES_PATH)scripts-general.js"> </script>
</head>
<body>
diff --git a/templates/template-index.tmpl b/templates/template-index.tmpl
index 089e487..78baedb 100644
--- a/templates/template-index.tmpl
+++ b/templates/template-index.tmpl
@@ -5,8 +5,8 @@
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>$(PAGE_TITLE)</title>
<!-- $(CGG_META_TAGS) -->
- <link href="styles.css" type="text/css" rel="stylesheet" media="screen, print" />
- <script type="text/javascript" src="scripts-general.js"> </script>
+ <link href="$(TEMPLATES_PATH)styles.css" type="text/css" rel="stylesheet" media="screen, print" />
+ <script type="text/javascript" src="$(TEMPLATES_PATH)scripts-general.js"> </script>
</head>
<body>
diff --git a/templates/template-view_photo.tmpl b/templates/template-view_photo.tmpl
index 7c84919..96a4a73 100644
--- a/templates/template-view_photo.tmpl
+++ b/templates/template-view_photo.tmpl
@@ -5,8 +5,8 @@
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>$(PAGE_TITLE)</title>
<!-- $(CGG_META_TAGS) -->
- <link href="styles.css" type="text/css" rel="stylesheet" media="screen, print" />
- <script type="text/javascript" src="scripts-general.js"> </script>
+ <link href="$(TEMPLATES_PATH)styles.css" type="text/css" rel="stylesheet" media="screen, print" />
+ <script type="text/javascript" src="$(TEMPLATES_PATH)scripts-general.js"> </script>
</head>
<body onload="javascript: read_exif_table_cookie(); preload_image('$(IMG_SRC_PRELOAD)');">