Attachment 'EmbedObject-1.5.3-3.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     MoinMoin - EmbedObject Macro
   4 
   5     PURPOSE:
   6         This macro is used to Embed an Object into a wiki page. Optional size of the object
   7         could be adjusted. Further keywords are dependent on the kind of application
   8 
   9     CALLING SEQUENCE:
  10         [[EmbedObject(attachment[,width=width][,height=heigt])]]
  11 
  12     SUPPORTED MIMETYPES:
  13          application/x-shockwave-flash 
  14          image/svg+xml      
  15          application/pdf
  16          audio/mpeg
  17          application/vision
  18                 
  19     INPUTS:
  20         attachment: image name of attachment
  21 
  22     KEYWORD PARAMETERS:
  23         width: width of the embedded image, default is 100% of window
  24         height: height of the embedded image, default is 100% of window
  25 
  26         application/x-shockwave-flash:
  27           play: true is default
  28           loop: true is default
  29           quality: high is default (medium,low)
  30 
  31     EXAMPLE:
  32         [[EmbedObject]]
  33         [[EmbedObject(example.swf)]]
  34         [[EmbedObject(example.pdf]]
  35         [[EmbedObject(example.svg]]
  36         [[EmbedObject(example.mp3]]
  37         [[EmbedObject(example.vss]]
  38          
  39         [[EmbedObject(example.swf,width=637,height=392)]]
  40         [[EmbedObject(SlideShow/example.swf,width=637,height=392)]]
  41         [[EmbedObject(SlideShow/example.swf,width=637,height=392,play=false)]]
  42         [[EmbedObject(SlideShow/example.swf,width=637,height=392,play=false,loop=false)]]
  43         [[EmbedObject(SlideShow/example.swf,width=637,height=392,play=false,loop=low)]]
  44 
  45  
  46     PROCEDURE:
  47         This routine requires attachment enabled. If the attachment isn't downloaded at all
  48         the attachment line is shown.
  49         If you give only one size argument e.g. width only the other one is calculated
  50 
  51         By the swftools it is possible to get the swf size returned. I don't know if it is 
  52         possible to get sizes for svg, pdf and others detected too, that's the reason why 
  53         I haven't added it by now.
  54 
  55         Please add needed mimetypes as objects.
  56 
  57         It must be in "MoinMoin/macro"
  58 
  59         Please remove the version number from the file name!
  60 
  61     MODIFICATION HISTORY:
  62         @copyright: 2006 by Reimar Bauer (R.Bauer@fz-juelich.de)      
  63         initial version: 1.5.0-1
  64         svg was added from AndrewArmstrong
  65         2006-05-04 TomSi: added mp3 support
  66         2006-05-09 RB code refactored, fixed a taintfilename bug
  67         2006-06-29 visio from OwenJones added but not tested,
  68                           RB code reviewed, taintfile removed
  69 """
  70 import os, mimetypes
  71 from MoinMoin import wikiutil
  72 from MoinMoin.action import AttachFile
  73 
  74 def execute(macro, args):
  75     request = macro.request
  76     _ = request.getText
  77     formatter = macro.formatter
  78     if args:
  79         args = args.split(',')
  80         args = [arg.strip() for arg in args]
  81     else:
  82         args = []
  83 
  84     argc = len(args)
  85     kw_count = 0
  86     kw = {}
  87     kw["width"] = "100%"
  88     kw["height"] = "100%"
  89     kw["play"] = "true"
  90     kw["loop"] = "true"
  91     kw["quality"] = "high"
  92 
  93     for arg in args :
  94         if '=' in arg:
  95             kw_count += 1
  96             key, value = arg.split('=', 1)
  97             kw[str(key)] = wikiutil.escape(value, quote=1)
  98     argc -= kw_count
  99 
 100     if not argc:
 101        msg = 'Not enough arguments to EmbedObject macro! Try [[EmbedObject(attachment [,width=width] [,height=heigt])]]'
 102        return "%s%s%s" % (formatter.sysmsg(1), formatter.text(msg), formatter.sysmsg(0))
 103     else:
 104         target = args[0]
 105 
 106     #target = wikiutil.taintfilename(target)
 107     pagename, attname = AttachFile.absoluteName(target, formatter.page.page_name)
 108     attachment_fname = AttachFile.getFilename(request, pagename, attname)
 109 
 110     if not os.path.exists(attachment_fname):
 111         linktext = _('Upload new attachment "%(filename)s"')
 112         return wikiutil.link_tag(request,
 113             ('%s?action=AttachFile&rename=%s' % (
 114             wikiutil.quoteWikinameURL(pagename),
 115             wikiutil.url_quote_plus(attname))),
 116             linktext % {'filename': attname})
 117 
 118     url = AttachFile.getAttachUrl(pagename,attname,request)
 119     mime_type, enc = mimetypes.guess_type(attname)
 120     if mime_type == "application/x-shockwave-flash":
 121         return '''
 122 <OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 
 123 WIDTH="%(width)s"
 124 HEIGHT="%(height)s"
 125 CODEBASE="http://active.macromedia.com/flash5/cabs/swflash.cab#version=6,0,23,0">
 126 <PARAM NAME="MOVIE" VALUE="%(file)s">
 127 <PARAM NAME="PLAY" VALUE="%(play)s">
 128 <PARAM NAME="LOOP" VALUE="%(loop)s">
 129 <PARAM NAME="QUALITY" VALUE="%(quality)s">
 130 <EMBED SRC="%(file)s" WIDTH="%(width)s" HEIGHT="%(height)s"
 131 PLAY="%(play)s" ALIGN="" LOOP="%(loop)s" QUALITY="%(quality)s"
 132 TYPE="application/x-shockwave-flash"
 133 PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
 134 </EMBED>
 135 </OBJECT>''' % {
 136 "width": kw["width"],
 137 "height": kw["height"],
 138 "play": kw["play"],
 139 "loop": kw["loop"],
 140 "quality": kw["quality"],
 141 "file": url}
 142     elif mime_type == "image/svg+xml": 
 143         return '''
 144 <OBJECT CLASSID="" 
 145 WIDTH="%(width)s"
 146 HEIGHT="%(height)s"
 147 CODEBASE="http://purl.org/dc/dcmitype/StillImage">
 148 <EMBED SRC="%(file)s" WIDTH="%(width)s" HEIGHT="%(height)s"
 149 TYPE="image/svg+xml">
 150 </EMBED>
 151 </OBJECT>''' % {
 152 "width": kw["width"],
 153 "height": kw["height"],
 154 "file": url}
 155     elif mime_type == "application/pdf":
 156         return '''
 157 <OBJECT CLASSID=""
 158 WIDTH="%(width)s"
 159 HEIGHT="%(height)s"
 160 CODEBASE="http://www.adobe.com">
 161 <EMBED SRC="%(file)s" WIDTH="%(width)s" HEIGHT="%(height)s"
 162 TYPE="application/pdf">
 163 </EMBED>
 164 </OBJECT>''' % {
 165 "width": kw["width"],
 166 "height": kw["height"],
 167 "file": url}
 168     elif mime_type == "audio/mpeg":
 169         return '''
 170 <OBJECT CLASSID=""
 171 WIDTH="%(width)s"
 172 HEIGHT="%(height)s"
 173 <EMBED SRC="%(file)s" HEIGHT="0" REPEAT="TRUE" AUTOSTART="TRUE" WIDTH="0" OP="TRUE"
 174 TYPE="audio/mpeg">
 175 </EMBED>
 176 </OBJECT>''' % {
 177 "width": kw["width"],
 178 "height": kw["height"],
 179 "file": url}
 180     elif mime_type == "application/vision":
 181         return  '''
 182 <OBJECT CLASSID="CLSID:279D6C9A-652E-4833-BEFC-312CA8887857" 
 183 CODEBASE="http://www.microsoft.com/technet/prodtechnol/office/visio2003/depvisvw.mspx"
 184 ID="viewer1" WIDTH="%(width)s" HEIGHT="%(height)s"> <PARAM NAME="CurrentPageIndex" VALUE="0"> 
 185 <PARAM NAME="Zoom" VALUE="-1"> <PARAM NAME = "SRC" 
 186 VALUE = "%(file)s">Your browser cannot display Visio</OBJECT>''' % {
 187 "width":  kw['width'],
 188 "height":  kw['height'], 
 189  "file":url}
 190     else:
 191         msg = 'Not supported mimetype %(mimetype)s ' % {"mimetype":mime_type}
 192         return "%s%s%s" % (macro.formatter.sysmsg(1),
 193                    macro.formatter.text(msg),
 194                    macro.formatter.sysmsg(0))

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2006-01-01 08:08:12, 5.2 KB) [[attachment:EO-1.5.0-1.py]]
  • [get | view] (2006-05-09 18:06:19, 5.5 KB) [[attachment:EO-1.5.3-2.py]]
  • [get | view] (2006-06-29 20:40:09, 6.4 KB) [[attachment:EmbedObject-1.5.3-3.py]]
  • [get | view] (2006-01-12 01:08:52, 80.1 KB) [[attachment:Map.swf]]
  • [get | view] (2006-05-09 20:26:24, 21.8 KB) [[attachment:example.pdf]]
  • [get | view] (2007-07-19 06:46:08, 89.3 KB) [[attachment:mini1.swf]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.