<?php if (!defined('PmWiki')) exit (); /* copyright 2010, Adam Overton borrowing from code by Peter Bowers: http://www.pmwiki.org/wiki/Cookbook/ViewPDF and from quicktime.php by Patrick R. Michaud and Sebastian Siedentopf (IMAP stuff) This file is distributed under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. GoogleViewer supports PDF documents, PowerPoint presentations, and TIFF files. They may be hosted on your own wiki website, or on GoogleDocs, or elsewhere on the web. It is not necessary to have a Google account to use the viewer services. To install, include the recipe in config.php: include_once("$FarmD/cookbook/GoogleViewer.php"); The most basic syntax is: (:googleviewer myfile.pdf:) The filename can be provided in several formats: * (:googleviewer http://blah.com/myfile.pdf:) - view a file hosted on an external site, using a full url * (:googleviewer testfile.pdf:) - view a file in the current group * (:googleviewer Group./testfile.pdf:) OR (:googleviewer Group/testfile.pdf:) - view a file in another group on the same wiki 3 optional parameters are available: (:googleviewer myfile.pdf width=... height=... style=...:) * width - (default: 600) - can include as a pixel-value (i.e. width="500"), or as a fluid percentage value (i.e. width="100%") * height - (default: 780) - only seems to respond intuitively to a pixel-value: i.e. height="600" * style - css style information can be provided, i.e. style="border:5px dotted red;" To define different wiki-wide default values, declare something like this in config.php before including the recipe: $GoogleViewerDefaults['width'] = '100%'; $GoogleViewerDefaults['height'] = '1000'; For more info on Google Viewer, visit http://docs.google.com/viewer Versions: * 2010-01-23c - fixed bug that prevented recipe from working for users with per-page-uploads ($UploadFileFmt = '$Group/$Name'; the globals $group and $UploadUrlFmt are no longer needed for this recipe * 2010-01-23 - initial release */ # Version date $RecipeInfo['GoogleViewer']['Version'] = '2010-01-23c'; SDVA($GoogleViewerDefaults, array( 'width' => '600' ,'height' => '780' ,'style' => 'border: none;' )); Markup('googleviewer', 'inline', '/\(:googleviewer\s+(\S*)\s*(.*?):\)/ie', 'googleviewer($pagename, "$1", "$2")'); function googleviewer($pagename, $filename, $args) { #global $UploadUrlFmt, $GoogleViewerDefaults, $group, $UploadFileFmt, $UploadDir; global $GoogleViewerDefaults, $UploadFileFmt, $UploadDir; if(substr($filename,0,4) != 'http') { # filenames with no group specified: if(!strpos($filename,"/")) { $filepath = FmtPageName("$UploadFileFmt/".$filename, $pagename); #echo "/ - $filepath<br />"; # filenames with group./filename or group/name/filename specified } else { $filepath = FmtPageName("$UploadDir/".str_replace('./','/',$filename), $pagename); #echo "./ - $filepath<br />"; } $fileurl = LinkUpload($pagename, "Attach:", $filename, "Attach:".$filename, "Attach:".$filename, "\$LinkUrl"); #echo $fileurl; if (!file_exists($filepath)) return Keep("<i>file doesn't exist!!</i> - $fileurl"); } else { $fileurl = $filename; } #echo $fileurl; # uses GoogleViewerDefaults, unless supplied by user $args = array_merge($GoogleViewerDefaults, ParseArgs($args)); #echo "arglist=".print_r($args,true)."<br>\n"; $url = '<iframe src="http://docs.google.com/viewer?url='.$fileurl.'&embedded=true" width="'.$args['width'].'" height="'.$args['height'].'" style="'.$args['style'].'"></iframe>'; return Keep($url); }