*/ if (!defined('PmWiki')) exit(); /* * applet - Embed java applets into PmWiki 2.0 pages * Copyright 2005-2007 by D.Faure (dfaure@cpan.org) * Thanks to Shayne Steele (steele cs fsu edu) for the * article at: http://ww2.cs.fsu.edu/~steele/XHTML/appletObject.html * * Modifications for clickable screenshots and alignment on page (see "# fsmod" below) by Frank Schweickert (appletimage verbis.net) * requires JavaScript, DHTML capable browser, tested with Firefox 3 and IE 7 * usage: (:applet clickimg="picture.gif" clickalt="alternative text" clickcaption="caption beneath applet/image" clickalign="[left|center|right]" codebase=... * optional in config.php: $AppletImageUploadLinkFmt - title of an upload link beneath the running applet, for as long as no image has been uploaded yet. * $AppletImageClickMeHintFmt - text beneath the still image to indicate that a mouse click will start the applet * $AppletImageDefaultAlign - [left|center|right] alignment of the applet/image when parameter clickalign is omitted * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * See http://www.pmwiki.org/wiki/Cookbook/Applet for info. */ $RecipeInfo['AppletImage']['Version'] = '2008-12-13'; # fsmod Markup('applet', '([\\w\\.]+)[:=])')); } function Applet($opt) { global $FarmPubDirUrl, $AppletRootCodebase, $AppletClassid, $AppletCabUrl, $AppletNotHandledFmt, $AppletParams, $UploadDir, $UploadUrlFmt, $UploadPrefixFmt, # fsmod $AppletImageUploadLinkFmt, $AppletImageClickMeHintFmt, $AppletImageDefaultAlign; # fsmod $pagename = ResolvePageName($pagename); # determine image upload directory # fsmod $Group = PageVar($pagename, '$Group'); # fsmod eval("\$MyUploadDir = \"$UploadDir$UploadPrefixFmt/\";"); # fsmod eval("\$MyUploadUrl = \"$UploadUrlFmt$UploadPrefixFmt/\";"); # fsmod SDV($AppletRootCodebase, "$FarmPubDirUrl/applets"); SDV($AppletClassid, "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"); SDV($AppletCabUrl, "http://java.sun.com/update/1.5.0/jinstall-1_5_0-windows-i586.cab"); SDV($AppletNotHandledFmt, " This browser does not have a Java Plug-in.
Get the latest Java Plug-in here.
\n"); $opt = array_merge((array)$AppletParams, (array)$opt); unset($opt['#'], $opt['-'], $opt['+'], $opt['']); $code = @$opt['code']; unset($opt['code']); $archive = @$opt['archive']; unset($opt['archive']); $width = @$opt['width']; unset($opt['width']); $height = @$opt['height']; unset($opt['height']); $name = @$opt['name']; unset($opt['name']); # e.g. for scriptable applets # fsmod $id = @$opt['id']; unset($opt['id']); # fsmod $codebase = @preg_replace('%^(?!http://)/?%', "$AppletRootCodebase/", $opt['codebase']); # fsmod allow for absolute urls unset($opt['codebase']); $img = @$opt['clickimg']; unset($opt['clickimg']); # fsmod $alt = @$opt['clickalt']; unset($opt['clickalt']); # fsmod $caption = @$opt['clickcaption']; unset($opt['clickcaption']); # fsmod $align = @$opt['clickalign']; unset($opt['clickalign']); # fsmod if (!$align) @$align = $AppletImageDefaultAlign; # fsmod if (!preg_match("/(left|center|right)/",$align)) $align=""; # fsmod # fsmod $out = array(); $out[] = " "; foreach($opt as $n => $v) $out[] = " "; $out[] = " "; if($archive) $out[] = " "; foreach($opt as $n => $v) $out[] = " "; $out[] = " $AppletNotHandledFmt "; ### fsmod start ### SDV($AppletImageUploadLinkFmt, "'-Upload a preview image for this applet-'"); SDV($AppletImageClickMeHintFmt, "Click on the image to start the applet."); if ($img && file_exists($MyUploadDir.$img)) { if (isset($_GET['action'])) $ret = "\n".$MyUploadUrl.$img."\"$alt\"|$caption"; # show plain image for non-browse action (e.g. print, edit preview,...) else { # e.g. print action, display clickable image $object = ''.preg_replace('/[\s\r\n]+/',' ',str_replace('"', '\"', implode(" ", $out))); # remove line breaks and escape quotes in object tag for use in innerHTML="..." $ret=Keep('\''.$alt.'\''); if ($AppletImageClickMeHintFmt) $ret .= Keep("

").$AppletImageClickMeHintFmt.Keep("

"); $ret = Keep("
").$ret.Keep("
"); # the innerHTML of this
is to be replaced by $object if ($caption) $ret .= Keep("

").$caption.Keep("

"); } } else { # either clickimage property or image file missing $ret = Keep("<:block>".implode("\n", $out)); # when image file is missing show running applet if ($img && !file_exists($MyUploadDir.$img) && $AppletImageUploadLinkFmt && !isset($_GET['action'])) $ret.=Keep("

")."[[(Attach:)$img | $AppletImageUploadLinkFmt]]".Keep("

"); # (in on-line view) an upload link for an image if ($caption) $ret .= Keep("

").$caption.Keep("

"); } if ($align) $ret = Keep("
").$ret.Keep("
"); return $ret; #### fsmod end ### }