| 1 | ################################################################################
|
|---|
| 2 | # _objtypes.py
|
|---|
| 3 | #
|
|---|
| 4 | # This program is free software; you can redistribute it and/or
|
|---|
| 5 | # modify it under the terms of the GNU General Public License
|
|---|
| 6 | # as published by the Free Software Foundation; either version 2
|
|---|
| 7 | # of the License, or (at your option) any later version.
|
|---|
| 8 | #
|
|---|
| 9 | # This program is distributed in the hope that it will be useful,
|
|---|
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 12 | # GNU General Public License for more details.
|
|---|
| 13 | #
|
|---|
| 14 | # You should have received a copy of the GNU General Public License
|
|---|
| 15 | # along with this program; if not, write to the Free Software
|
|---|
| 16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|---|
| 17 | ################################################################################
|
|---|
| 18 |
|
|---|
| 19 | # Imports.
|
|---|
| 20 | from App.special_dtml import HTMLFile
|
|---|
| 21 | # Product Imports.
|
|---|
| 22 | import _fileutil
|
|---|
| 23 | import _globals
|
|---|
| 24 | import _zreferableitem
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 | # ------------------------------------------------------------------------------
|
|---|
| 28 | # _objtypes.getHref2Zoom:
|
|---|
| 29 | # ------------------------------------------------------------------------------
|
|---|
| 30 | def getHref2Zoom(self, img, REQUEST):
|
|---|
| 31 | m = getattr( self, 'getCustomHref2Zoom', None)
|
|---|
| 32 | if m is not None:
|
|---|
| 33 | href = m( self, img=img, REQUEST=REQUEST)
|
|---|
| 34 | else:
|
|---|
| 35 | href = img.getHref(REQUEST)
|
|---|
| 36 | return href
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | class ObjTypes:
|
|---|
| 40 |
|
|---|
| 41 | # Repetitive (Files/Images).
|
|---|
| 42 | # --------------------------
|
|---|
| 43 | f_selectRepetitive = HTMLFile('dtml/objattrs/f_select_repetitive', globals())
|
|---|
| 44 |
|
|---|
| 45 | # Autocomplete.
|
|---|
| 46 | # -------------
|
|---|
| 47 | f_selectAutocomplete = HTMLFile('dtml/objattrs/f_select_autocomplete', globals())
|
|---|
| 48 |
|
|---|
| 49 | # String, Text, Select, Multiple-Select.
|
|---|
| 50 | # --------------------------------------
|
|---|
| 51 | f_selectInput = HTMLFile('dtml/objattrs/f_select_input', globals())
|
|---|
| 52 |
|
|---|
| 53 | # Textformat.
|
|---|
| 54 | # -----------
|
|---|
| 55 | f_selectTextformat = HTMLFile('dtml/objattrs/f_select_textformat', globals())
|
|---|
| 56 |
|
|---|
| 57 | # Richtext.
|
|---|
| 58 | # ---------
|
|---|
| 59 | f_selectRichtext = HTMLFile('dtml/objattrs/f_select_richtext', globals())
|
|---|
| 60 | f_xstandard_styles = HTMLFile('dtml/objattrs/f_xstandard_styles', globals())
|
|---|
| 61 | f_xstandard_css = HTMLFile('dtml/objattrs/f_xstandard_css', globals())
|
|---|
| 62 |
|
|---|
| 63 | # Object.
|
|---|
| 64 | # -------
|
|---|
| 65 | f_selectObject = HTMLFile('dtml/objattrs/f_select_object', globals())
|
|---|
| 66 |
|
|---|
| 67 | # File.
|
|---|
| 68 | # -----
|
|---|
| 69 | f_selectFile = HTMLFile('dtml/objattrs/f_select_file', globals())
|
|---|
| 70 |
|
|---|
| 71 | # Image.
|
|---|
| 72 | # ------
|
|---|
| 73 | f_selectImage = HTMLFile('dtml/objattrs/f_select_image', globals())
|
|---|
| 74 |
|
|---|
| 75 | # Alignment.
|
|---|
| 76 | # ----------
|
|---|
| 77 | f_selectAlign = HTMLFile('dtml/objattrs/f_select_align', globals())
|
|---|
| 78 |
|
|---|
| 79 | # Colors.
|
|---|
| 80 | # -------
|
|---|
| 81 | f_selectColor = HTMLFile('dtml/objattrs/f_select_color', globals())
|
|---|
| 82 |
|
|---|
| 83 | # Character-Format.
|
|---|
| 84 | # -----------------
|
|---|
| 85 | f_selectCharformat = HTMLFile('dtml/objattrs/f_select_charformat', globals())
|
|---|
| 86 |
|
|---|
| 87 | # Displaytype.
|
|---|
| 88 | # ------------
|
|---|
| 89 | f_selectDisplaytype = HTMLFile('dtml/objattrs/f_select_displaytype', globals())
|
|---|
| 90 |
|
|---|
| 91 | ############################################################################
|
|---|
| 92 | # dctDisplaytype :
|
|---|
| 93 | #
|
|---|
| 94 | # Dictionary of display-types.
|
|---|
| 95 | ############################################################################
|
|---|
| 96 | dctDisplaytype = {
|
|---|
| 97 | '1':'left',
|
|---|
| 98 | '2':'top',
|
|---|
| 99 | '3':'bottom',
|
|---|
| 100 | '4':'right',
|
|---|
| 101 | '5':'left', # 'floatbefore'
|
|---|
| 102 | '6':'right', # 'floatafter'
|
|---|
| 103 | '7':'left', # 'behindtext'
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 | ############################################################################
|
|---|
| 108 | # ObjTypes.renderDisplaytype:
|
|---|
| 109 | #
|
|---|
| 110 | # HTML presentation of Image and Text.
|
|---|
| 111 | #
|
|---|
| 112 | # Parameters:
|
|---|
| 113 | # IN: @self <Object>
|
|---|
| 114 | # @displaytype <String>
|
|---|
| 115 | # @imgattr Object-Attribute <String>
|
|---|
| 116 | # @imghiresattr Object-Attribute (High-Resolution) <String>
|
|---|
| 117 | # @imgurl URL for Image
|
|---|
| 118 | # @imgthumb Display image as thumbnail (width limited to 365 pixel)
|
|---|
| 119 | # @imgspecial Special Attributes (for <img>-Tag, e.g. usemap)
|
|---|
| 120 | # @imgclass CSS Image-Class
|
|---|
| 121 | # @text String-Object
|
|---|
| 122 | # @textalign Text-Alignment (Left, Right, Center)
|
|---|
| 123 | # @textclass CSS Text-Class
|
|---|
| 124 | # @REQUEST Request-Object
|
|---|
| 125 | # OUT: <html> String-Object
|
|---|
| 126 | ############################################################################
|
|---|
| 127 | def renderDisplaytype(self, displaytype, \
|
|---|
| 128 | imgattr, imghiresattr, imgurl, imgthumb, imgspecial, imgclass, \
|
|---|
| 129 | text, textalign, textclass, REQUEST):
|
|---|
| 130 |
|
|---|
| 131 | align = self.getObjProperty('align',REQUEST)
|
|---|
| 132 |
|
|---|
| 133 | # Export-Format.
|
|---|
| 134 | if REQUEST.has_key('export_format'):
|
|---|
| 135 | try:
|
|---|
| 136 | export_format = int( REQUEST.get('export_format'))
|
|---|
| 137 | except:
|
|---|
| 138 | displaytype = 'export_format'
|
|---|
| 139 |
|
|---|
| 140 | # Image.
|
|---|
| 141 | # ------
|
|---|
| 142 | img = self.getObjProperty(imgattr,REQUEST)
|
|---|
| 143 | imghires = None
|
|---|
| 144 | if imghiresattr is not None:
|
|---|
| 145 | imghires = self.getObjProperty(imghiresattr,REQUEST)
|
|---|
| 146 | if imghires is not None and displaytype == 'export_format':
|
|---|
| 147 | img = imghires
|
|---|
| 148 | imgattr = imghiresattr
|
|---|
| 149 | imghires = None
|
|---|
| 150 | imghiresattr = None
|
|---|
| 151 |
|
|---|
| 152 | imgtag = ''
|
|---|
| 153 | imgzoom = ''
|
|---|
| 154 |
|
|---|
| 155 | #-- IMAGE-PROPERTIES
|
|---|
| 156 | if img is None or img.get_real_size() == 0:
|
|---|
| 157 | width = ''
|
|---|
| 158 | height = ''
|
|---|
| 159 |
|
|---|
| 160 | # Image (HiRes).
|
|---|
| 161 | # --------------
|
|---|
| 162 | if imghires is not None and imghires.get_real_size() != 0:
|
|---|
| 163 | s_url = getHref2Zoom(self,imghires,REQUEST)
|
|---|
| 164 | imgtag = ''
|
|---|
| 165 | imgtag += '<div class="caption">'
|
|---|
| 166 | imgtag += '<a href="%s"><img src="%smime_type.image_basic.gif" title="%s" border="0" align="middle" /></a> '%(s_url,self.MISC_ZMS,imghires.getContentType())
|
|---|
| 167 | imgtag += '<a href="%s">%s</a> '%(s_url,imghires.filename)
|
|---|
| 168 | imgtag += '<b>(%s)</b>'%self.getDataSizeStr(imghires.get_size())
|
|---|
| 169 | imgtag += '</div>'
|
|---|
| 170 |
|
|---|
| 171 | else:
|
|---|
| 172 | imgzoomattr = ''
|
|---|
| 173 |
|
|---|
| 174 | # Dimensions.
|
|---|
| 175 | # -----------
|
|---|
| 176 | width = ''
|
|---|
| 177 | height = ''
|
|---|
| 178 | try:
|
|---|
| 179 | max_width = self.getConfProperty('ZMSGraphic.zmi_max_width',480)
|
|---|
| 180 | i_height = int(img.height)
|
|---|
| 181 | i_width = int(img.width)
|
|---|
| 182 | if imgthumb and i_width > max_width:
|
|---|
| 183 | i_height = int(max_width*i_height/i_width)
|
|---|
| 184 | i_width = max_width
|
|---|
| 185 | imgzoomobj = img
|
|---|
| 186 | imgzoomattr = imgattr
|
|---|
| 187 | height = str(i_height)+'px'
|
|---|
| 188 | width = str(i_width)+'px'
|
|---|
| 189 | try:
|
|---|
| 190 | px2em = float(self.getConfProperty('ZMSGraphic.px2em',''))
|
|---|
| 191 | height = str(i_height/px2em)+'em'
|
|---|
| 192 | width = str(i_width/px2em)+'em'
|
|---|
| 193 | except:
|
|---|
| 194 | pass
|
|---|
| 195 | except:
|
|---|
| 196 | pass
|
|---|
| 197 |
|
|---|
| 198 | # Image (HiRes).
|
|---|
| 199 | # --------------
|
|---|
| 200 | if not (imghires is None or imghires.get_real_size() == 0):
|
|---|
| 201 | imgzoomobj = imghires
|
|---|
| 202 | imgzoomattr = imghiresattr
|
|---|
| 203 |
|
|---|
| 204 | # Assemble img-tag.
|
|---|
| 205 | imgsrc = img.getHref(REQUEST)
|
|---|
| 206 | imgtag = '<img'
|
|---|
| 207 | imgtag += ' src="%s"'%imgsrc
|
|---|
| 208 | imgtag += ' style="'
|
|---|
| 209 | if displaytype != 'export_format':
|
|---|
| 210 | if width != '':
|
|---|
| 211 | imgtag += 'width:%s;'%width
|
|---|
| 212 | if height != '':
|
|---|
| 213 | imgtag += 'height:%s;'%height
|
|---|
| 214 | imgtag += 'display:block;'
|
|---|
| 215 | imgtag += '"'
|
|---|
| 216 | if imgclass is not None and len(imgclass) > 0:
|
|---|
| 217 | imgtag += ' class="%s"'%imgclass
|
|---|
| 218 | if imgspecial is not None and len(imgspecial) > 0:
|
|---|
| 219 | imgtag += ' %s'%imgspecial
|
|---|
| 220 | imgtag += ' />'
|
|---|
| 221 |
|
|---|
| 222 | # Image-Url.
|
|---|
| 223 | # ----------
|
|---|
| 224 | if imgurl is not None and len(imgurl) > 0:
|
|---|
| 225 | imgtarget = ''
|
|---|
| 226 | if not (imgurl.startswith('/') or imgurl.startswith('.') or imgurl.startswith( REQUEST[ 'BASE0'])):
|
|---|
| 227 | imgtarget = ' target="_blank"'
|
|---|
| 228 | imgtag = '<a href="%s"%s>%s</a>'%( imgurl, imgtarget, imgtag)
|
|---|
| 229 |
|
|---|
| 230 | # Zoom (HiRes).
|
|---|
| 231 | # -------------
|
|---|
| 232 | elif len(imgzoomattr) > 0:
|
|---|
| 233 |
|
|---|
| 234 | # Zoom (SuperRes).
|
|---|
| 235 | # ----------------
|
|---|
| 236 | key = 'imgsuperres'
|
|---|
| 237 | if key in self.getObjAttrs().keys() and self.getConfProperty('ZMSGraphic.superres',0)==1:
|
|---|
| 238 | imgsuperzoomobj = self.getObjProperty(key,REQUEST)
|
|---|
| 239 | if imgsuperzoomobj is not None:
|
|---|
| 240 | s_url = getHref2Zoom(self,imgzoomobj,REQUEST)
|
|---|
| 241 | imgzoomclazz = 'zoom'
|
|---|
| 242 | imgzoomalt = '%s (%s)'%(self.getZMILangStr('BTN_ZOOM'),self.getDataSizeStr(imgzoomobj.get_size()))
|
|---|
| 243 | imgzoom += '<a href="%s" class="%s fancybox" target="_blank"><img class="%s" src="%s" title="%s" border="0" /></a>'%( s_url, imgzoomclazz, imgzoomclazz, self.spacer_gif, imgzoomalt)
|
|---|
| 244 | s_url = getHref2Zoom(self,imgsuperzoomobj,REQUEST)
|
|---|
| 245 | imgzoomclazz = 'superzoom'
|
|---|
| 246 | imgzoomalt = '%s (%s)'%(self.getZMILangStr('ATTR_SUPERRES'),imgsuperzoomobj.getDataSizeStr())
|
|---|
| 247 | imgzoom += '<a href="%s" class="%s" target="_blank"><img class="%s" src="%s" title="%s" border="0" /></a>'%( s_url, imgzoomclazz, imgzoomclazz, self.spacer_gif, imgzoomalt)
|
|---|
| 248 |
|
|---|
| 249 | # Image-Zoom.
|
|---|
| 250 | if imgzoom is not None and len(imgzoom) > 0:
|
|---|
| 251 | imgtag += imgzoom
|
|---|
| 252 | else:
|
|---|
| 253 | imgtag = '<a href="%s" class="fancybox">%s</a>'%(imgzoomobj.getHref(REQUEST),imgtag)
|
|---|
| 254 |
|
|---|
| 255 | # Build <html>-presentation.
|
|---|
| 256 | dtml = HTMLFile('dtml/objattrs/displaytype/displaytype_%s'%displaytype, globals())
|
|---|
| 257 | html = dtml(self
|
|---|
| 258 | ,ob=self
|
|---|
| 259 | ,img=imgtag
|
|---|
| 260 | ,text=text
|
|---|
| 261 | ,textalign=textalign
|
|---|
| 262 | ,textclass=textclass
|
|---|
| 263 | ,height=height
|
|---|
| 264 | ,width=width
|
|---|
| 265 | ,align=align
|
|---|
| 266 | ,float=align.find( '_FLOAT') >= 0
|
|---|
| 267 | ,REQUEST=REQUEST)
|
|---|
| 268 |
|
|---|
| 269 | # Return <html>-presentation.
|
|---|
| 270 | return html
|
|---|
| 271 |
|
|---|
| 272 | ################################################################################
|
|---|