From c311a6955b050cf43675b4e1abd943ea3f0b68cc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B4me=20Bernigaud?= <come.bernigaud@laposte.net>
Date: Fri, 17 May 2013 13:17:23 +0200
Subject: [PATCH] Fixes: #2409 Improving theme handling

---
 contrib/smarty/plugins/function.filePath.php  |  30 ++++++++++++++++++
 .../images/{go_logo.png => fd_logo.png}       | Bin
 .../default/images/{gohome.png => home.png}   | Bin
 .../default/images/{stop.png => sign_out.png} | Bin
 ihtml/themes/default/framework.tpl            |   6 ++--
 ihtml/themes/default/headers.tpl              |   4 +--
 include/functions.inc                         |   4 +--
 7 files changed, 37 insertions(+), 7 deletions(-)
 create mode 100644 contrib/smarty/plugins/function.filePath.php
 rename html/themes/default/images/{go_logo.png => fd_logo.png} (100%)
 rename html/themes/default/images/{gohome.png => home.png} (100%)
 rename html/themes/default/images/{stop.png => sign_out.png} (100%)

diff --git a/contrib/smarty/plugins/function.filePath.php b/contrib/smarty/plugins/function.filePath.php
new file mode 100644
index 000000000..26c847b3d
--- /dev/null
+++ b/contrib/smarty/plugins/function.filePath.php
@@ -0,0 +1,30 @@
+<?php
+
+function smarty_function_filePath($params, &$smarty)
+{
+  $config = session::global_get('config');
+
+  /* Set theme */
+  if (isset ($config)) {
+    $theme = $config->get_cfg_value("theme", "default");
+  } else {
+    $theme = "default";
+  }
+
+  $filename = $params['file'];
+
+  if (file_exists("themes/$theme/$filename")) {
+    return "themes/$theme/$filename";
+  }
+  if (file_exists($smarty->template_dir."/themes/$theme/$filename")) {
+    return $smarty->template_dir."/themes/$theme/$filename";
+  }
+  if (file_exists("themes/default/$filename")) {
+    return "themes/default/$filename";
+  }
+  if (file_exists($smarty->template_dir."/themes/default/$filename")) {
+    return $smarty->template_dir."/themes/default/$filename";
+  }
+  return $filename;
+}
+?>
diff --git a/html/themes/default/images/go_logo.png b/html/themes/default/images/fd_logo.png
similarity index 100%
rename from html/themes/default/images/go_logo.png
rename to html/themes/default/images/fd_logo.png
diff --git a/html/themes/default/images/gohome.png b/html/themes/default/images/home.png
similarity index 100%
rename from html/themes/default/images/gohome.png
rename to html/themes/default/images/home.png
diff --git a/html/themes/default/images/stop.png b/html/themes/default/images/sign_out.png
similarity index 100%
rename from html/themes/default/images/stop.png
rename to html/themes/default/images/sign_out.png
diff --git a/ihtml/themes/default/framework.tpl b/ihtml/themes/default/framework.tpl
index d7842b888..b4ac31faf 100644
--- a/ihtml/themes/default/framework.tpl
+++ b/ihtml/themes/default/framework.tpl
@@ -4,13 +4,13 @@
 {$php_errors}
 <form action='main.php{$plug}' name='mainform' id='mainform' method='post' enctype='multipart/form-data'>
 <div class='setup_header'>
-  <div style="float:left;"><img src='themes/default/images/go_logo.png' class='center' alt='FusionDirectory' style="padding-left:2px; padding-right:25px;">
+  <div style="float:left;"><img src='{filePath file="images/fd_logo.png"}' class='center' alt='FusionDirectory' style="padding-left:2px; padding-right:25px;">
     <a class="maintitlebar" href='main.php?reset=1'>
-      <img src='{$go_home}' class='center' border="0" alt="Main"/>&nbsp;{t}Main{/t}
+      <img src='{filePath file="images/home.png"}' class='center' border="0" alt="Main"/>&nbsp;{t}Main{/t}
     </a>
     &nbsp;
     <a class="maintitlebar" href='logout.php?request' style="margin-left:35px;">
-      <img src='{$go_out}' class='center' border="0" alt="Sign out"/>&nbsp;{t}Sign out{/t}
+      <img src='{filePath file="images/sign_out.png"}' class='center' border="0" alt="Sign out"/>&nbsp;{t}Sign out{/t}
     </a>
     <a class="plugtop" style="margin-left:35px;">
       <img src="{$headline_image}" class="center" align="middle" alt="{t}{$headline}{/t}"/>&nbsp;
diff --git a/ihtml/themes/default/headers.tpl b/ihtml/themes/default/headers.tpl
index 24371f42c..6419fb98f 100644
--- a/ihtml/themes/default/headers.tpl
+++ b/ihtml/themes/default/headers.tpl
@@ -16,8 +16,8 @@
   <meta http-equiv="Cache-Control" content="post-check=0, pre-check=0">
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 
-  <style type="text/css">@import url('themes/default/style.css');</style>
-  <link rel="stylesheet" type="text/css" href="themes/default/printer.css" media="print">
+  <style type="text/css">@import url('{filePath file="style.css"}');</style>
+  <link rel="stylesheet" type="text/css" href="{filePath file="printer.css"}" media="print">
 
   <link rel="shortcut icon" href="favicon.ico">
 
diff --git a/include/functions.inc b/include/functions.inc
index dad444c7f..16a226102 100644
--- a/include/functions.inc
+++ b/include/functions.inc
@@ -338,9 +338,9 @@ function get_template_path($filename= '', $plugin= FALSE, $path= "")
 
   /* Set theme */
   if (isset ($config)) {
-  $theme= $config->get_cfg_value("theme", "default");
+    $theme = $config->get_cfg_value("theme", "default");
   } else {
-    $theme= "default";
+    $theme = "default";
   }
 
   /* Return path for empty filename */
-- 
GitLab