Changes for page PDF Viewer Macro
Last modified by Victor Zhang on 16:25, 15/12/2019
edited by Victor Zhang
on 16:25, 15/12/2019
on 16:25, 15/12/2019
edited by Victor Zhang
on 16:25, 15/12/2019
on 16:25, 15/12/2019
Change comment: Install extension [org.xwiki.contrib:xwiki-macro-pdfviewer/1.6.3]
Summary
-
Attachments (1 modified, 0 added, 0 removed)
-
Objects (3 modified, 2 added, 0 removed)
Details
- pdfviewer.zip
-
- Size
-
... ... @@ -1,1 +1,1 @@ 1 -2600 3071 +2600418 - Content
- XWiki.WikiMacroClass[0]
-
- Macro code
-
... ... @@ -2,24 +2,64 @@ 2 2 #set($width = $context.macro.params.width) 3 3 #set($height = $context.macro.params.height) 4 4 #set($file = $context.macro.params.file) 5 +#set($docname = $context.macro.params.document) 6 +#set($asAuthor = $context.macro.params.asauthor && ($context.macro.params.asauthor == "true" || $context.macro.params.asauthor == "yes" || $context.macro.params.asauthor == "1")) 5 5 #if(!$file) 6 - NopdfURL provided8 + {{error}}$services.localization.render('pdfviewer.error.nofile'){{/error}} 7 7 #else 8 -#if($file.startsWith("http")) 9 - #set($url = $file) 10 -#else 11 - #set($url = $doc.getAttachmentURL($file)) 10 + #if($file.startsWith("http://") || $file.startsWith("https://")) 11 + #set($url = $file) 12 + #else 13 + #if("$!docname" != "") 14 + #set($document = $xwiki.getDocument($docname)) 15 + #else 16 + #set($document = $doc) 17 + #end 18 + #set($attachment = $document.getAttachment($file)) 19 + #set($url = $NULL) 20 + #if($attachment) 21 + #set($url = $document.getAttachmentURL($file)) 22 + #elseif ($asAuthor && $xwiki.hasProgrammingRights() && $xwiki.exists('XWiki.PDFViewerService')) 23 + #set($document = $xwiki.getDocumentAsAuthor($docname)) 24 + #set($attachment = $document.getAttachment($file)) 25 + #if($attachment) 26 + #set($digestFactory = $services.component.getInstance('org.xwiki.crypto.DigestFactory', 'SHA-1')) 27 + #set($encoder = $services.component.getInstance('org.xwiki.crypto.BinaryStringEncoder', 'URLBase64')) 28 + #if ($digestFactory && $encoder) 29 + #set($contentAuthor = $services.model.serialize($doc.contentAuthorReference, 'default')) 30 + #set($digest = $digestFactory.instance) 31 + #set($is = $digest.getInputStream($attachment.contentInputStream)) 32 + #set($discard = $digest.getInputStream($attachment.contentInputStream).skip(1000)) 33 + #set($discard = $is.close()) 34 + #if ($xcontext.userReference) 35 + #set($discard = $digest.update($services.model.serialize($xcontext.userReference, 'default').getBytes('UTF-8'))) 36 + #end 37 + #set($discard = $digest.update($contentAuthor.getBytes('UTF-8'))) 38 + #set($digest = $encoder.encode($digest.digest)) 39 + #set($url = $xwiki.getDocument("XWiki.PDFViewerService").getExternalURL('get', "reference=$escapetool.url($services.model.serialize($document.documentReference, 'default'))&filename=$escapetool.url($attachment.filename)&user=$escapetool.url($contentAuthor)&key=$digest")) 40 + #end 41 + #end 42 + #end 43 + #end 44 + #if ($url) 45 + #set($url = $escapetool.url($url)) 46 + #set($pdfviewerurl = $xwiki.getDocument("XWiki.PDFViewerMacro").getAttachmentURL("pdfviewer.zip")) 47 + ## Attachment URL have query parameters for cache issue. 48 + #set($pdfviewerurl = $pdfviewerurl.split("\?")[0]) 49 + {{html clean=false}} 50 + <div> 51 + <!--[if lt IE 10]> 52 + <div class="box warningmessage">PDF Viewer : Not compatible with IE < 10</div> 53 + <![endif]--> 54 + <![if !(lt IE 10)]> 55 + <iframe src="${pdfviewerurl}/pdf-viewer/web/viewer.html?file=${url}#locale=${context.language}" width="${width}" height="${height}"></iframe> 56 + <![endif]--> 57 + </div> 58 + {{/html}} 59 + #elseif (!$document || $document.isNew()) 60 + {{error}}$services.localization.render('pdfviewer.error.nodocument', [$escapetool.html($escapetool.html($docname))]){{/error}} 61 + #else 62 + {{error}}$services.localization.render('pdfviewer.error.noattachment', [$escapetool.html($file), $escapetool.html($services.model.serialize($document.documentReference, 'default'))]){{/error}} 63 + #end 12 12 #end 13 -#set($url = $escapetool.url($url)) 14 -#set($pdfviewerurl = $xwiki.getDocument("XWiki.PDFViewerMacro").getAttachmentURL("pdfviewer.zip")) 15 -{{html clean=false}} 16 - <!--[if lt IE 10]> 17 - <div class="box warningmessage">PDF Viewer : Not compatible with IE < 10</div> 18 - <![endif]--> 19 - <![if !(lt IE 10)]> 20 - <iframe src="${pdfviewerurl}/pdf-viewer/web/viewer.html?file=${url}#locale=${context.language}" width="${width}" height="${height}"&></iframe> 21 - <![endif]--> 22 - </script> 23 -{{/html}} 24 -#end 25 25 {{/velocity}}
- XWiki.WikiMacroParameterClass[1]
-
- Parameter default value
-
... ... @@ -1,1 +1,0 @@ 1 -100% - Parameter description
-
... ... @@ -1,0 +1,1 @@ 1 +Reference of the document containing the file (not used if file is a URL) - Parameter name
-
... ... @@ -1,1 +1,1 @@ 1 - width1 +document
- XWiki.WikiMacroParameterClass[2]
-
- Parameter default value
-
... ... @@ -1,1 +1,1 @@ 1 -100 01 +100% - Parameter name
-
... ... @@ -1,1 +1,1 @@ 1 - height1 +width
- XWiki.WikiMacroParameterClass[3]
-
- Parameter default value
-
... ... @@ -1,0 +1,1 @@ 1 +1000 - Parameter name
-
... ... @@ -1,0 +1,1 @@ 1 +height
- XWiki.WikiMacroParameterClass[4]
-
- Parameter default value
-
... ... @@ -1,0 +1,1 @@ 1 +0 - Parameter description
-
... ... @@ -1,0 +1,1 @@ 1 +If this value is true (or 1 or yes) and the user has no access to the document to which the PDF file is attached, the PDF file could still be viewed on behalf of the author of the document containing the macro (if that author has access to the containing document obviously). - Parameter name
-
... ... @@ -1,0 +1,1 @@ 1 +asauthor