deliver "png" or "gif" as plugin icons depending on the requesting browser
the URL /test shows the request headers
This commit is contained in:
parent
db18700161
commit
fa56f5c3b3
|
@ -49,10 +49,10 @@ class CryptoBoxPlugin:
|
||||||
|
|
||||||
|
|
||||||
## default icon of this plugin (relative path)
|
## default icon of this plugin (relative path)
|
||||||
default_icon_filename = "plugin_icon.gif"
|
default_icon_filename = "plugin_icon"
|
||||||
|
|
||||||
## fallback icon file (in the common plugin directory)
|
## fallback icon file (in the common plugin directory)
|
||||||
fallback_icon_filename = "plugin_icon_unknown.gif"
|
fallback_icon_filename = "plugin_icon_unknown"
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, cbox, plugin_dir, site_class=None):
|
def __init__(self, cbox, plugin_dir, site_class=None):
|
||||||
|
@ -156,16 +156,36 @@ class CryptoBoxPlugin:
|
||||||
'**kargs' is necessary, as a 'weblang' attribute may be specified (and ignored)
|
'**kargs' is necessary, as a 'weblang' attribute may be specified (and ignored)
|
||||||
"""
|
"""
|
||||||
import re
|
import re
|
||||||
|
icon_ext = self.__get_default_icon_extension()
|
||||||
if (image is None) or (not re.match(r'[\w\-\.]*$', image)):
|
if (image is None) or (not re.match(r'[\w\-\.]*$', image)):
|
||||||
plugin_icon_file = os.path.join(self.plugin_dir, self.default_icon_filename)
|
plugin_icon_file = os.path.join(self.plugin_dir,
|
||||||
|
"%s.%s" % (self.default_icon_filename, icon_ext))
|
||||||
else:
|
else:
|
||||||
plugin_icon_file = os.path.join(self.plugin_dir, image)
|
plugin_icon_file = os.path.join(self.plugin_dir, image)
|
||||||
|
## check if we can find the fallback plugin icon in one of the
|
||||||
|
## plugin directories
|
||||||
if not os.access(plugin_icon_file, os.R_OK):
|
if not os.access(plugin_icon_file, os.R_OK):
|
||||||
for ppath in self.cbox.prefs["Locations"]["PluginDir"]:
|
for ppath in self.cbox.prefs["Locations"]["PluginDir"]:
|
||||||
plugin_icon_file = os.path.join(ppath, self.fallback_icon_filename)
|
plugin_icon_file = os.path.join(ppath,
|
||||||
|
"%s.%s" % (self.fallback_icon_filename, icon_ext))
|
||||||
if plugin_icon_file:
|
if plugin_icon_file:
|
||||||
break
|
break
|
||||||
return cherrypy.lib.cptools.serveFile(plugin_icon_file)
|
return cherrypy.lib.cptools.serveFile(plugin_icon_file)
|
||||||
|
|
||||||
|
|
||||||
|
def __get_default_icon_extension(self):
|
||||||
|
"""Return 'png' or 'gif' depending on the 'User-Agent' request header
|
||||||
|
|
||||||
|
This is useful, as IE 5.5/6.0 does not render transparent png graphics properly
|
||||||
|
Internet Explorer 5.5/6.0: return 'gif'
|
||||||
|
everything else: return 'png'
|
||||||
|
"""
|
||||||
|
if ("User-Agent" in cherrypy.request.headers) and \
|
||||||
|
((cherrypy.request.headers["User-Agent"].find("MSIE 5.5;") != -1) or \
|
||||||
|
(cherrypy.request.headers["User-Agent"].find("MSIE 6.0;") != -1)):
|
||||||
|
return "gif"
|
||||||
|
else:
|
||||||
|
return "png"
|
||||||
|
|
||||||
|
|
||||||
def get_template_filename(self, template_name):
|
def get_template_filename(self, template_name):
|
||||||
|
|
|
@ -395,7 +395,11 @@ class WebInterfaceSites:
|
||||||
self.__reset_dataset()
|
self.__reset_dataset()
|
||||||
self.__set_web_lang(weblang)
|
self.__set_web_lang(weblang)
|
||||||
self.__check_environment()
|
self.__check_environment()
|
||||||
return "test passed"
|
result = "<html><head><title>Test</title><body><ul>"
|
||||||
|
for key in cherrypy.request.headers:
|
||||||
|
result += "<li>%s - %s</li>" % (str(key), str(cherrypy.request.headers[key]))
|
||||||
|
result += "</ul></body></html>"
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
|
|
Loading…
Reference in a new issue