from Products.PageTemplates.PageTemplateFile import PageTemplateFile from Products.PageTemplates.PageTemplate import PageTemplate from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate import xml.dom.minidom from OFS.Folder import Folder from xml_helpers import getText import os import re import string import urllib from Globals import package_home def getString(self,key,default=''): try: return self.REQUEST[key] except: return default class zogiLib_navTemplate(ZopePageTemplate): """pageTemplate Objekt""" meta_type="zogiLib_navTemplate" _default_content_fn = os.path.join(package_home(globals()), 'zpt/zogiLib_NavTemplateDefault.zpt') manage_options=ZopePageTemplate.manage_options+( {'label':'Copy to Filesystem','action':'copyContent'}, ) def getPath(self): """get path""" return getPath(self,'thumbtemplate.templ') ## def changeECHO_pageTemplateWeightForm(self): ## """change""" ## pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_pageTemplateWeight.zpt').__of__(self) ## return pt() ## def changeECHO_pageTemplateWeight(self,weight,content_type,RESPONSE=None): ## """change""" ## self.weight=weight ## self.content_type=content_type ## if RESPONSE is not None: ## RESPONSE.redirect('manage_main') def copyContent(self): """copycontent to path""" return "copied to:"+copyContent(self,'thumbtemplate.templ') def manage_addZogiLib_NavTemplateForm(self): """Form for adding""" pt=PageTemplateFile('Products/ECHO_content/zpt/AddZogilib_NavTemplate.zpt').__of__(self) return pt() def manage_addZogiLib_NavTemplate(self, id,title=None, text=None, REQUEST=None, submit=None): "Add a Page Template with optional file content." id = str(id) if REQUEST is None: self._setObject(id, zogilib_NavTemplate(id, text)) ob = getattr(self, id) if title: ob.pt_setTitle(title) return ob else: file = REQUEST.form.get('file') headers = getattr(file, 'headers', None) if headers is None or not file.filename: zpt = zogilib_NavTemplate(id) else: zpt = zogilib_NavTemplate(id, file, headers.get('content_type')) self._setObject(id, zpt) ob = getattr(self, id) try: u = self.DestinationURL() except AttributeError: u = REQUEST['URL1'] if submit == " Add and Edit ": u = "%s/%s" % (u, quote(id)) REQUEST.RESPONSE.redirect(u+'/manage_main') return '' def readNavTemp(fileName): """navtemp""" print "HI reading",fileName if os.path.exists(fileName+"/index.meta"): dom=xml.dom.minidom.parse(fileName+"/index.meta") else: return None print "dom",dom try: navTag=getText(dom.getElementsByTagName('zogilibtemplate')[0].childNodes) except: navTag=None return navTag class zogiLib(Folder): """StandardElement""" meta_type="zogiLib" def generateImageFolder(self): """images ablegen""" self.manage_addFolder('images') for image in os.listdir("../lib/python/Products/zogiLib/images"): fn=file("../lib/python/Products/zogiLib/images/"+image) print fn self.images.manage_addImage(image,fn) def __init__(self, id,title,zogilibBaseUrl, localFileBase): """init""" self.id=id self.title=title self.zogilibBaseUrl=zogilibBaseUrl self.localFileBase=localFileBase self._setObject('topTemplate',zogiLib_navTemplate(id='topTemplate')) self.generateImageFolder() manage_options = Folder.manage_options+( {'label':'Main Config','action':'changeZogiLibForm'}, ) def navigation_js(self): """Javascript""" return file("../lib/python/Products/zogiLib/js/navigation.js").read() def generateTopJavaScript(self): """generate script""" ret="""var baseUrl = '%s'; """% self.REQUEST['URL0'] ret+="""newParameter('fn', '%s', '', 1); newParameter('pn', '%s', '1', 1); newParameter('ws', '%s', '1.0', 1); newParameter('mo', '%s', '', 1); newParameter('mk', '%s', '', 3); newParameter('wx', '%s', '0.0', 2); newParameter('wy', '%s', '0.0', 2); newParameter('ww', '%s', '1.0', 2); newParameter('wh', '%s', '1.0', 2); newParameter('pt', '%s', '%s', 9); newParameter('brgt', '%s', '0.0', 1); newParameter('cont', '%s', '0.0', 1); newParameter('rot', '%s', '0.0', 1); newParameter('rgba', '%s', '', 1); newParameter('rgbm', '%s', '', 1); newParameter('ddpix', '%s', '', 9); newParameter('ddpiy', '%s', '', 9);"""%(getString(self,'fn'), getString(self,'pn',1), getString(self,'ws',1.0), getString(self,'mo',''), getString(self,'mk',''), getString(self,'wx',0.0), getString(self,'wy',0.0), getString(self,'ww',1.0), getString(self,'wh',1.0), getString(self,'pt',100),getString(self,'pt',100), getString(self,'brgt',0.0), getString(self,'cont',0.0), getString(self,'rot',0.0), getString(self,'rgba','0/0/0'), getString(self,'rgbm','0/0/0'), getString(self,'ddpix',0.0), getString(self,'ddpiy',0.0) ) ret+=""" var wwidth, wheight; if (self.innerHeight) // all except Explorer { wwidth = self.innerWidth; wheight = self.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode { wwidth = document.documentElement.clientWidth; wheight = document.documentElement.clientHeight; } else if (document.body) // other Explorers { wwidth = document.body.clientWidth; wheight = document.body.clientHeight; } """ return ret def generateScalerImg(self,requestString): """generate Scaler Tag""" retStr=self.zogilibBaseUrl+requestString jS=""""""%retStr return jS def changeZogiLibForm(self): """Main configuration""" pt=PageTemplateFile('Products/zogiLib/zpt/changeZogiLibForm.zpt').__of__(self) return pt() def changeZogiLib(self,title,zogilibBaseUrl, localFileBase,RESPONSE=None): """change it""" self.title=title self.zogilibBaseUrl=zogilibBaseUrl self.localFileBase=localFileBase if RESPONSE is not None: RESPONSE.redirect('manage_main') def nav_html(self,fileName): """navigations frame""" # suche nach index.meta mit zogilib thumb info templ=readNavTemp(self.localFileBase+"/"+fileName) if not templ: templ=readNavTemp(self.localFileBase+"/"+fileName.split("/")[0]) if not templ: return self.topTemplate.document_src() return urllib.urlopen(templ).read() def index_html(self): """main action""" pt=PageTemplateFile('Products/zogiLib/zpt/zogiLibMain.zpt').__of__(self) return pt() def storeQuery(self): """storeQuery in session""" self.REQUEST.SESSION['query']={} for fm in self.REQUEST.form.keys(): self.REQUEST.SESSION['query'][fm]=self.REQUEST.form[fm] def setParam(self,pn=None,ws=None,rot=None): """gotopage""" ret="" if pn: self.REQUEST.SESSION['query']['pn']=pn if ws: self.REQUEST.SESSION['query']['ws']=ws if rot: self.REQUEST.SESSION['query']['rot']=rot for param in self.REQUEST.SESSION['query'].keys(): ret+=param+"="+str(self.REQUEST.SESSION['query'][param])+"&" self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret) def mirrorPage(self,mi): """mirror""" ret="" try: splitted=self.REQUEST.SESSION['query']['mo'].split(',') except: splitted=[] if mi=="h": if 'hmir' in splitted: splitted.remove('hmir') else: splitted.append('hmir') if mi=="v": if 'vmir' in splitted: splitted.remove('vmir') else: splitted.append('vmir') self.REQUEST.SESSION['query']['mo']=string.join(splitted,",") for param in self.REQUEST.SESSION['query'].keys(): ret+=param+"="+str(self.REQUEST.SESSION['query'][param])+"&" self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret) def decode(self,strR): """decode &""" print re.sub('\&','\&',strR) return re.sub('\&','\&',strR) def wholePage(self): """zoom out""" ret="" self.REQUEST.SESSION['query']['ww']=1 self.REQUEST.SESSION['query']['wh']=1 self.REQUEST.SESSION['query']['wx']=0 self.REQUEST.SESSION['query']['wy']=0 for param in self.REQUEST.SESSION['query'].keys(): ret+=param+"="+str(self.REQUEST.SESSION['query'][param])+"&" self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret) def prevPage(self,pn=None): """next page""" ret="" if pn and pn>0: pn=str(int(pn)-1) self.REQUEST.form['pn']=pn print "hi",self.REQUEST.form.keys() for param in self.REQUEST.form.keys(): print param ret+=param+"="+str(self.REQUEST.form[param])+"&" self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret) def nextPage(self,pn=None): """next page""" ret="" try: pn=str(int(pn)+1) except: pn=str(2) self.REQUEST.form['pn']=pn print "hi",self.REQUEST.form.keys() for param in self.REQUEST.form.keys(): print param ret+=param+"="+str(self.REQUEST.form[param])+"&" self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+ret) def manage_addZogiLibForm(self): """interface for adding zogilib""" pt=PageTemplateFile('Products/zogiLib/zpt/addZogiLibForm').__of__(self) return pt() def manage_addZogiLib(self,id,title,zogilibBaseUrl, localFileBase,RESPONSE=None): """add dgilib""" newObj=zogiLib(id,title,zogilibBaseUrl, localFileBase) self.Destination()._setObject(id,newObj) if RESPONSE is not None: RESPONSE.redirect('manage_main')