From 4c5f6f1bf314cbe554da264d5aedbfb80cf4d672 Mon Sep 17 00:00:00 2001
From: str4d <str4d@mail.i2p>
Date: Sun, 23 Dec 2012 01:36:44 +0000
Subject: [PATCH] Enable themes to have different I2P logos, with a default
 fallback

---
 i2p2www/pages/global/layout.html                 |   2 +-
 .../{styles/danimoth => }/images/i2plogo.png     | Bin
 i2p2www/templatevars.py                          |  15 +++++++++++++--
 3 files changed, 14 insertions(+), 3 deletions(-)
 rename i2p2www/static/{styles/danimoth => }/images/i2plogo.png (100%)

diff --git a/i2p2www/pages/global/layout.html b/i2p2www/pages/global/layout.html
index 60a23a82c..ef05ca5b8 100644
--- a/i2p2www/pages/global/layout.html
+++ b/i2p2www/pages/global/layout.html
@@ -15,7 +15,7 @@
   <body>
     <div class="hide"><a href="#content" title="Skip navigation" accesskey="2">{{ _('Skip navigation') }}</a></div>
     <div id="topbar">
-      <a id="logo" href="{{ site_url() }}"><img src="{{ url_for('static', filename='styles/' + g.theme + '/images/i2plogo.png') }}" alt="I2P Logo" title="Invisible Internet Project (I2P)" /></a>
+      <a id="logo" href="{{ site_url() }}"><img src="{{ url_for('static', filename=logo_url()) }}" alt="I2P Logo" title="Invisible Internet Project (I2P)" /></a>
       <div class="title">
         <h1>{{ self.title() }}</h1>
         {% include "global/lang.html" %}
diff --git a/i2p2www/static/styles/danimoth/images/i2plogo.png b/i2p2www/static/images/i2plogo.png
similarity index 100%
rename from i2p2www/static/styles/danimoth/images/i2plogo.png
rename to i2p2www/static/images/i2plogo.png
diff --git a/i2p2www/templatevars.py b/i2p2www/templatevars.py
index cef67d246..af48db1de 100644
--- a/i2p2www/templatevars.py
+++ b/i2p2www/templatevars.py
@@ -1,6 +1,7 @@
-from flask import g, request, url_for
+from flask import g, request, safe_join, url_for
+import os.path
 
-from i2p2www import CANONICAL_DOMAIN, CURRENT_I2P_VERSION, app
+from i2p2www import CANONICAL_DOMAIN, CURRENT_I2P_VERSION, STATIC_DIR, app
 
 I2P_TO_CLEAR = {
     'www.i2p2.i2p': 'www.i2p2.de',
@@ -79,6 +80,15 @@ def utility_processor():
         # Probably a 404 error page
         return url_for('main_index', **args)
 
+    # Shorthand for getting the logo for the current theme
+    def get_logo_for_theme():
+        logo = 'styles/' + g.theme + '/images/i2plogo.png'
+        print logo
+        print safe_join(STATIC_DIR, logo)
+        if not os.path.isfile(safe_join(STATIC_DIR, logo)):
+            logo = 'images/i2plogo.png'
+        return logo
+
     def get_current_version(string=None):
         if string:
             return string % CURRENT_I2P_VERSION
@@ -87,6 +97,7 @@ def utility_processor():
     return dict(i2pconv=convert_url_to_clearnet,
                 url_for_other_page=url_for_other_page,
                 change_theme=change_theme,
+                logo_url=get_logo_for_theme,
                 site_url=get_site_url,
                 get_url=get_url_with_lang,
                 get_flag=get_flag,
-- 
GitLab