Recent Changes - Search:

PmWiki

pmwiki.org

<?php /*>*/ 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 <AT> cs <DOT> fsu <DOT> edu) for the
 * article at: http://ww2.cs.fsu.edu/~steele/XHTML/appletObject.html(approve links)
 *
 * Modification for clickable screenshots (see "# fsmod" below) by Frank Schweickert (appletimage <AT> verbis.net)
 *   requires JavaScript, DHTML capable browser, tested with Firefox 3 and IE 6
 *   usage: (:applet clickimg="picture.gif" clickalt="alternative text" codebase=...
 *          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
 *
 * 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['Applet']['Version'] = '2008-11-27'; # fsmod

Markup('applet', 'fulltext', # we'll return conditional markup to avoid printing, so make this happen earlier # fsmod

       "/\\(:applet(\\s+.*)\\s*:\\)/e", "AppletMarkup(PSS('$1'))");

function AppletMarkup($args) {

  return Applet(ParseArgs($args, '(?>([\\w\\.]+)[:=])'));

}

function Applet($opt) {

  global $FarmPubDirUrl, $AppletRootCodebase, $AppletClassid, $AppletCabUrl,
         $AppletNotHandledFmt, $AppletParams,
         $UploadDir, $UploadUrlFmt, $UploadPrefixFmt, $AppletImageUploadLinkFmt, $AppletImageClickMeHintFmt;  # 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, "<strong>
  This browser does not have a Java Plug-in.<br />
  <a href=\"http://java.sun.com/products/plugin/downloads/index.html\">
  Get the latest Java Plug-in here.</a>

</strong>\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']);

  $codebase = @preg_replace('%^(?!http://)/?%', "$AppletRootCodebase/", $opt['codebase']);   # allow for absolute urls      # fsmod
  unset($opt['codebase']);

  $out = array();
  $out[] = "

<!--[if !IE]> Firefox and others will use outer object --> <object classid=\"java:$code\"";

  if($archive) $out[] = "        archive=\"$archive\"";
  $out[] = "        codebase=\"$codebase\"
        width=\"$width\" height=\"$height\"
        type=\"application/x-java-applet\">";
  foreach($opt as $n => $v) $out[] = "  <param name=\"$n\" value=\"$v\" />";
  $out[] = "<!--<![endif]-->
  <!-- MSIE (Microsoft Internet Explorer) will use inner object -->
  <object classid=\"$AppletClassid\"
          codebase=\"$AppletCabUrl\"
          width=\"$width\" height=\"$height\">
    <param name=\"code\" value=\"$code\" />
    <param name=\"codebase\" value=\"$codebase\" />";
  if($archive) $out[] = "    <param name=\"archive\" value=\"$archive\" />";
  foreach($opt as $n => $v) $out[] = "    <param name=\"$n\" value=\"$v\" />";
  $out[] =   "    $AppletNotHandledFmt
  </object>

<!--[if !IE]> close outer object --> </object> <!--<![endif]-->";

  1. fsmod start ###
  $img = @$opt['clickimg']; unset($opt['clickimg']);
  $alt = @$opt['clickalt']; unset($opt['clickalt']);
  if (!$img) return '<:block>'.Keep(implode("\n", $out));          # without clickimg parameter -> original behaviour, show applet

  SDV($AppletImageUploadLinkFmt, "Upload a preview image for this applet");
  SDV($AppletImageClickMeHintFmt, "Click on the image to start the applet.");

  $footer = Keep('<p>')."";
  if (!file_exists($MyUploadDir.$img)) {
  	$footer .= "?";
  	return '<:block>'.Keep(implode("\n", $out)).$footer;           # show applet plus upload link for an image
  }
  else {
    $footer .= "$AppletImageClickMeHintFmt";                   # dispay image and click-me message, on click replace this with object tag
      # remove line breaks and escape quotes in object tag for use in innerHTML="..."
      $object = ''.preg_replace('/[\s\r\n]+/',' ',str_replace('"', '\"', implode(" ", $out)));   
    return Keep('<div><img alt=\.$alt.'\' src=\.$MyUploadUrl.$img.'\' onclick=\'javascript:parentNode.innerHTML="'.$object.'"\'>').$footer.'</div>';
  }
  1. fsmod end ###

}

Edit - History - Print - Recent Changes - Search
Page last modified on November 30, 2008, at 03:59 AM