| 1 | <?xml version="1.0" encoding="UTF-8"?>
|
|---|
| 2 | <list>
|
|---|
| 3 | <item type="dictionary">
|
|---|
| 4 | <dictionary>
|
|---|
| 5 | <item key="type"><![CDATA[filter]]></item>
|
|---|
| 6 | <item key="value" type="dictionary">
|
|---|
| 7 | <dictionary>
|
|---|
| 8 | <item key="acquired" type="int">0</item>
|
|---|
| 9 | <item key="content_type"><![CDATA[application/epub+zip]]></item>
|
|---|
| 10 | <item key="description"/>
|
|---|
| 11 | <item key="format"><![CDATA[export]]></item>
|
|---|
| 12 | <item key="id"><![CDATA[epub]]></item>
|
|---|
| 13 | <item key="meta_types" type="list">
|
|---|
| 14 | <list>
|
|---|
| 15 | <item><![CDATA[ZMS]]></item>
|
|---|
| 16 | </list>
|
|---|
| 17 | </item>
|
|---|
| 18 | <item key="name"><![CDATA[Epub]]></item>
|
|---|
| 19 | <item key="processes" type="list">
|
|---|
| 20 | <list>
|
|---|
| 21 | <item type="dictionary">
|
|---|
| 22 | <dictionary>
|
|---|
| 23 | <item key="file" type="file">
|
|---|
| 24 |
|
|---|
| 25 | <data content_type="text/css" filename="style.css" type="file"><![CDATA[body {
|
|---|
| 26 | font-family: Arial, Helvetica, sans-serif;
|
|---|
| 27 | }]]></data>
|
|---|
| 28 | </item>
|
|---|
| 29 | <item key="id"><![CDATA[epub_process]]></item>
|
|---|
| 30 | </dictionary>
|
|---|
| 31 | </item>
|
|---|
| 32 | </list>
|
|---|
| 33 | </item>
|
|---|
| 34 | <item key="roles" type="list">
|
|---|
| 35 | <list>
|
|---|
| 36 | <item><![CDATA[ZMSAdministrator]]></item>
|
|---|
| 37 | </list>
|
|---|
| 38 | </item>
|
|---|
| 39 | </dictionary>
|
|---|
| 40 | </item>
|
|---|
| 41 | </dictionary>
|
|---|
| 42 | </item>
|
|---|
| 43 | <item type="dictionary">
|
|---|
| 44 | <dictionary>
|
|---|
| 45 | <item key="type"><![CDATA[process]]></item>
|
|---|
| 46 | <item key="value" type="dictionary">
|
|---|
| 47 | <dictionary>
|
|---|
| 48 | <item key="acquired" type="int">0</item>
|
|---|
| 49 | <item key="command"><![CDATA[## Script (Python) "epub_process"
|
|---|
| 50 | ##bind container=container
|
|---|
| 51 | ##bind context=context
|
|---|
| 52 | ##bind namespace=
|
|---|
| 53 | ##bind script=script
|
|---|
| 54 | ##bind subpath=traverse_subpath
|
|---|
| 55 | ##parameters=self, REQUEST
|
|---|
| 56 | ##title=Epub-Process
|
|---|
| 57 | ##
|
|---|
| 58 | ## Warnings:
|
|---|
| 59 | ## Prints, but never reads 'printed' variable.
|
|---|
| 60 | ##
|
|---|
| 61 | # --// BO epub_process //--
|
|---|
| 62 |
|
|---|
| 63 | context.f_standard_html_request( context, REQUEST)
|
|---|
| 64 |
|
|---|
| 65 | tempfolder = REQUEST['ZMS_FILTER_CUR_DIR']
|
|---|
| 66 | print tempfolder
|
|---|
| 67 |
|
|---|
| 68 | base_url = context.absolute_url()[len(REQUEST['BASE0']):]+'/'
|
|---|
| 69 | c = 0
|
|---|
| 70 | items = []
|
|---|
| 71 | imgs = []
|
|---|
| 72 | for ob in [context]+context.filteredTreeNodes( REQUEST, context.PAGES):
|
|---|
| 73 | id = 'main%i'%len(items)
|
|---|
| 74 | href = id+'.xhtml'
|
|---|
| 75 | filepath = '%s/%s'%(tempfolder,href)
|
|---|
| 76 | print ob.absolute_url(), filepath
|
|---|
| 77 | xml = []
|
|---|
| 78 | xml.append(ob.getXmlHeader())
|
|---|
| 79 | xml.append('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">')
|
|---|
| 80 | xml.append('<head>')
|
|---|
| 81 | xml.append('<link rel="stylesheet" type="text/css" href="css/style.css" />')
|
|---|
| 82 | xml.append('</head>')
|
|---|
| 83 | xml.append('<body>')
|
|---|
| 84 | bodyContent = ob.getBodyContent( REQUEST).replace(base_url,'')
|
|---|
| 85 | for img in bodyContent.split('<img'):
|
|---|
| 86 | src = img[img.find(' src="'):]
|
|---|
| 87 | src = src[src.find('"')+1:]
|
|---|
| 88 | src = src[:src.find('"')]
|
|---|
| 89 | if src and src not in imgs:
|
|---|
| 90 | imgs.append(src)
|
|---|
| 91 | xml.append(bodyContent)
|
|---|
| 92 | xml.append('</body>')
|
|---|
| 93 | xml.append('</html>')
|
|---|
| 94 | context.writeStdout('[epub_process]: %s'%filepath)
|
|---|
| 95 | context.localfs_write( filepath, '\n'.join(xml))
|
|---|
| 96 | items.append({'id':id,'href':href,'titlealt':ob.getTitlealt(REQUEST),'level':ob.getLevel(),})
|
|---|
| 97 |
|
|---|
| 98 | # Generate toc.ncx (Table of Contents)
|
|---|
| 99 | xml = []
|
|---|
| 100 | xml.append(context.getXmlHeader())
|
|---|
| 101 | xml.append('<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN" "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">')
|
|---|
| 102 | xml.append('<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1" xml:lang="de-DE">')
|
|---|
| 103 | xml.append('<head>')
|
|---|
| 104 | xml.append('<meta name="dc:Title" content="%s"/>'%(context.getTitle(REQUEST)))
|
|---|
| 105 | xml.append('<meta name="dtb:uid" content="id_%s"/>'%(context.id_quote(context.getTitle(REQUEST))))
|
|---|
| 106 | xml.append('</head>')
|
|---|
| 107 | xml.append('<docTitle>')
|
|---|
| 108 | xml.append('<text>%s</text>'%(context.getTitle(REQUEST)))
|
|---|
| 109 | xml.append('</docTitle>')
|
|---|
| 110 | xml.append('<navMap>')
|
|---|
| 111 | start_level = context.getLevel()
|
|---|
| 112 | last_level = start_level - 1
|
|---|
| 113 | for x in range(len(items)):
|
|---|
| 114 | level = items[x]['level']
|
|---|
| 115 | # Customize your deepest content Level
|
|---|
| 116 | if level <= 12:
|
|---|
| 117 | xml.extend(map(lambda x: '</navPoint>', range(last_level-level+1)))
|
|---|
| 118 | xml.append('<navPoint playOrder="%i" id="%s">\n'%(x+1,items[x]['id']))
|
|---|
| 119 | xml.append('<navLabel>')
|
|---|
| 120 | xml.append('<text>%s</text>\n'%(items[x]['titlealt']))
|
|---|
| 121 | xml.append('</navLabel>')
|
|---|
| 122 | xml.append('<content src="%s"/>\n'%(items[x]['href']))
|
|---|
| 123 |
|
|---|
| 124 | last_level = level
|
|---|
| 125 | xml.extend(map(lambda x: '</navPoint>', range(last_level-start_level+1)))
|
|---|
| 126 | xml.append('</navMap>')
|
|---|
| 127 | xml.append('</ncx>')
|
|---|
| 128 | filepath = '%s/toc.ncx'%(tempfolder)
|
|---|
| 129 | context.writeStdout( '[epub_process]: %s'%filepath)
|
|---|
| 130 | context.localfs_write( filepath, '\n'.join(xml))
|
|---|
| 131 |
|
|---|
| 132 | # Generate content.opf
|
|---|
| 133 | xml = []
|
|---|
| 134 | xml.append(context.getXmlHeader())
|
|---|
| 135 | xml.append('<package version="2.0" unique-identifier="PrimaryID" xmlns="http://www.idpf.org/2007/opf">')
|
|---|
| 136 | xml.append('<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">')
|
|---|
| 137 | xml.append('<dc:title>%s</dc:title>'%(context.getTitle(REQUEST)))
|
|---|
| 138 | xml.append('<dc:identifier id="dcidid" opf:scheme="URI">%s</dc:identifier>'%(context.absolute_url()))
|
|---|
| 139 | for key in context.getObjAttrs().keys():
|
|---|
| 140 | dc_key = None
|
|---|
| 141 | if key.startswith('attr_dc_'):
|
|---|
| 142 | dc_key = 'dc:'+key[len('attr_dc_'):]
|
|---|
| 143 | if key.startswith('dc_'):
|
|---|
| 144 | dc_key = 'dc:'+key[len('dc_'):]
|
|---|
| 145 | if dc_key:
|
|---|
| 146 | value = context.getObjProperty(key,REQUEST)
|
|---|
| 147 | if value:
|
|---|
| 148 | context.writeStdout( '[epub_process]: %s'%dc_key)
|
|---|
| 149 | obj_attr = context.getObjAttr( key)
|
|---|
| 150 | xml.append('<%s>%s</%s>'%(dc_key,str(value),dc_key))
|
|---|
| 151 | xml.append('</metadata>')
|
|---|
| 152 | xml.append('<manifest>')
|
|---|
| 153 | xml.append('<!-- Content Documents -->')
|
|---|
| 154 | xml.append('\n'.join(map(lambda x: '<item id="%s" href="%s" media-type="application/xhtml+xml"/>'%(x['id'],x['href']), items)))
|
|---|
| 155 | xml.append('<!-- Table of Contents -->')
|
|---|
| 156 | xml.append('<item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/>')
|
|---|
| 157 | xml.append('<!-- CSS Style Sheets -->')
|
|---|
| 158 | xml.append('<item id="style-css" href="css/style.css" media-type="text/css"/>')
|
|---|
| 159 | xml.append('<!-- Images -->')
|
|---|
| 160 | for src in imgs:
|
|---|
| 161 | id = src
|
|---|
| 162 | id = id[:id.rfind('/')]
|
|---|
| 163 | id = id[id.rfind('/')+1:]
|
|---|
| 164 | ext = src[src.rfind('.')+1:]
|
|---|
| 165 | media_type = {'gif':'image/gif','jpg':'image/jpeg','png':'image/png',}[ext]
|
|---|
| 166 | xml.append('<item id="%s-%s" href="%s" media-type="%s"/>'%(id,ext,src,media_type))
|
|---|
| 167 | xml.append('</manifest>')
|
|---|
| 168 | xml.append('<spine toc="ncx">')
|
|---|
| 169 | xml.append('\n'.join(map(lambda x: '<itemref idref="%s" linear="yes"/>'%(x['id']), items)))
|
|---|
| 170 | xml.append('</spine>')
|
|---|
| 171 | xml.append('</package>')
|
|---|
| 172 | filepath = '%s/content.opf'%(tempfolder)
|
|---|
| 173 | context.writeStdout( '[epub_process]: %s'%filepath)
|
|---|
| 174 | context.localfs_write( filepath, '\n'.join(xml))
|
|---|
| 175 |
|
|---|
| 176 | # Generate container.xml
|
|---|
| 177 | xml = []
|
|---|
| 178 | xml.append(context.getXmlHeader())
|
|---|
| 179 | xml.append('<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">')
|
|---|
| 180 | xml.append('<rootfiles>')
|
|---|
| 181 | xml.append('<rootfile full-path="content.opf" media-type="application/oebps-package+xml"/>')
|
|---|
| 182 | xml.append('</rootfiles>')
|
|---|
| 183 | xml.append('</container>')
|
|---|
| 184 | filepath = '%s/META-INF/container.xml'%(tempfolder)
|
|---|
| 185 | context.writeStdout( '[epub_process]: %s'%filepath)
|
|---|
| 186 | context.localfs_write( filepath, '\n'.join(xml))
|
|---|
| 187 |
|
|---|
| 188 | # Convert transition to css.
|
|---|
| 189 | css = REQUEST['ZMS_FILTER_TRANS'].getData()
|
|---|
| 190 | filepath = '%s/css/style.css'%(tempfolder)
|
|---|
| 191 | context.writeStdout( '[epub_process]: %s'%filepath)
|
|---|
| 192 | context.localfs_write( filepath, css)
|
|---|
| 193 |
|
|---|
| 194 | # Build zip-archive
|
|---|
| 195 | zip = context.buildZipArchive( tempfolder+'/*')
|
|---|
| 196 | context.writeStdout( '[epub_process]: %i bytes'%len(zip))
|
|---|
| 197 | context.localfs_write( REQUEST.get('ZMS_FILTER_OUT'), zip)
|
|---|
| 198 | return zip
|
|---|
| 199 |
|
|---|
| 200 | # --// EO epub_process //--
|
|---|
| 201 | ]]>
|
|---|
| 202 | </item>
|
|---|
| 203 | <item key="id"><![CDATA[epub_process]]></item>
|
|---|
| 204 | <item key="name"><![CDATA[Epub-Process]]></item>
|
|---|
| 205 | <item key="type"><![CDATA[Script (Python)]]></item>
|
|---|
| 206 | </dictionary>
|
|---|
| 207 | </item>
|
|---|
| 208 | </dictionary>
|
|---|
| 209 | </item>
|
|---|
| 210 | </list> |
|---|