Back to index

moin  1.9.0~rc2
AnyWikiDraw.php
Go to the documentation of this file.
00001 <?php
00002  # Embeds the AnyWikiDraw Plugin from the AnyWikiDraw project
00003  # (http://sourceforge.net/projects/anywikidraw) 
00004  # 
00005  # This plugin/Cookbook script can be fairly destructive, so
00006  # be careful, anything and everything that does or could go
00007  # wrong is your problem not mine, sorry! (I've not had any problems
00008  # myself, but as it accesses files on your system, it may go horribly
00009  # wrong, who knows!)
00010  #
00011  # docs see http://www.pmwiki.org/wiki/Cookbook/PmWikiDraw
00012  #
00013  # @version $Id: AnyWikiDraw.php 107 2009-06-15 19:33:05Z rawcoder $
00014  # @author Werner Randelshofer
00015  #
00016  # This script is mostly a copy of the pmwikdraw.php script by Ciaran Jessup and Knut Albol
00017  #
00018 
00019 // Security check.
00020 if (!defined('PmWiki')) exit(); 
00021  
00022 //---------------- Global Configuration Variables ----------------
00023 SDV($PmWikiDrawPubUrl, $PubDirUrl);
00024 $CookbookDirURL = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'].'/../cookbook';
00025 SDV($EnableDrawingDebug, false);
00026 SDV($EnableDrawingVersioning , false); 
00027 SDV($EnableDrawingRecentChanges, false);
00028 SDV($drawingExtraColors, ""); 
00029 SDV($drawingCompatibilityMode, false);
00030 SDV($displayDrawingHistoryFmt, "<a class='pmwikidrawlink' href='\$showHistoryUrl' title='$[Image history]'><img src='\$pubdirurl/drawing/news.gif'/></a>");
00031 SDV($displayDrawingEditFmt, "<a class='pmwikidrawlink' href='\$editImageUrl' title='$[Edit Image]'><img src='".$CookbookDirURL."/AnyWikiDraw/edit.gif'/></a>");
00032 
00033 // css style for drawing caption
00034 #$HTMLStylesFmt[] = ".pmwikidraweditlink { font-size:70%; font-weight:bold; }\n"; 
00035 
00036 // Add extra colors to the fill/color menus.
00037 #$drawingExtraColors = "Aquamarine=#70DB93,New Tan=EBC79E,Sea Green=238E68,Motorola Blue=#3ff"; 
00038 // -----------------------------------------------------------------------------------------------------------------
00039 
00040 //-------------------- Globally executed code --------------------
00041 
00042 // Work out which version of PmWiki we're looking at :)
00043 preg_match('/.*-(\\d+)/',$Version,$match);
00044 $pmwikiver = $match[1];
00045 if($pmwikiver <= 1) {
00046      echo "PmWikiDraw no longer supports PmWiki1, please upgrade to PmWiki2. Thanks.";
00047        exit();
00048 }
00049 
00050 // Add in our required file extensions and associate the new markup. 
00051 SDVA($UploadExts,  array(
00052        'gif' => 'image/gif', 
00053        'draw' => 'text/plain', 
00054        'map' => 'text/plain',
00055        'png' => 'image/png', 
00056        'jpg' => 'image/jpeg', 
00057        'jpeg' => 'image/jpeg', 
00058        'svg' => 'image/svg+xml'
00059 ));
00060 Markup('drawing','inline', "/\\(:drawing\\s*(\\w[-.\\w]*\\w)\\s*(?:|\\s*(\\d+))*\\s*:\\)/e", "drawing('$1')");
00061 SDV($HandleActions['imagehistory'],'HandleImageHistory');
00062 SDV($HandleActions['postDrawing'], 'HandlePostDrawing');
00063 
00064 // Modify global variables based on the current action type.
00065 if ($action=='editimage')
00066   { $editImage = true; } 
00067 else 
00068   { $editImage = false; }
00069 
00070 if($action=='print' || $action=='publish' || $action=='editimage' || $action=='edit') { 
00071         // Hide the edit & history links when printing/publishing/editing
00072        $displayDrawingEditFmt = ""; 
00073        $displayDrawingHistoryFmt = "";
00074 } 
00075 
00076 if (!$EnableDrawingVersioning)
00077   { $displayDrawingHistoryFmt = ""; }
00078 
00079 // ------------------- Handle the drawing markup --------------------------------
00080 function drawing($str) {
00081   global $EnableUpload;
00082   
00083   $output = "";
00084 
00085   if($EnableUpload != 1) { // Helpful hint to make sure people turn on uploads!
00086      $output.= "<b>Please note your administrator *NEEDS* to enable uploads before you can save your drawings.</b><br/>";
00087   } 
00088 
00089 
00090   $drawing = $str;
00091   $pos = strrpos($drawing, '.');
00092   $filenameExtension = ($pos == false) ? '' : strtolower(substr($drawing, $pos + 1));
00093   if (in_array($filenameExtension, array('','draw'))) {
00094     $output .= drawing_draw($str);
00095   } else {
00096     $output .= drawing_any($str);
00097   }
00098   return Keep($output);
00099 }
00100 
00101 // ------------------- Handle the drawing markup for all file formats except .draw --------------------------------
00102 function drawing_any($str) {
00103   global $action, $group, $pagename, $ScriptUrl, $UploadPrefixFmt;
00104   global $UploadUrlFmt, $UploadDir, $editImage, $displayDrawingEditFmt, $EnableDrawingDebug; 
00105   global $drawing, $editImageUrl, $drawingExtraColors, $EnableDrawingVersioning;
00106   global $pubdirurl, $PmWikiDrawPubUrl, $showHistoryUrl, $displayDrawingHistoryFmt;
00107   global $FmtV, $GCount, $drawingCompatibilityMode, $scripturl;
00108   global $Now;
00109 
00110   $CookbookDirURL = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'].'/../cookbook';
00111 
00112 
00113 
00114   $drawing = $str;
00115   
00116   $output = "";
00117 
00118   // expand to full URL (incl http://) if url is relative:
00119   if (!preg_match('/^http:/',$ScriptUrl)) 
00120     { $scripturl = "http://".$_SERVER['HTTP_HOST'] . $ScriptUrl; }
00121   else 
00122     { $scripturl = $ScriptUrl; }
00123 
00124  
00125   // expand to full URL (incl http://) if url is relative:
00126   if (!preg_match('/^http:/',$PmWikiDrawPubUrl)) 
00127     { $pubdirurl = "http://".$_SERVER['HTTP_HOST'] . $PmWikiDrawPubUrl; }
00128   else 
00129     { $pubdirurl = $PmWikiDrawPubUrl; }
00130 
00131   // Work out the uploads path, both as a url and as an absolute path on the disk.
00132   $uploadsUrl = FmtPageName("$UploadUrlFmt$UploadPrefixFmt", $pagename)."/";
00133 
00134   // expand to full URL (incl http://) if url is relative:
00135   if (!preg_match('/^http:/',$uploadsUrl)) 
00136     { $uploadsUrl = "http://".$_SERVER['HTTP_HOST'] . $uploadsUrl; }
00137   
00138   $uploadsPath = FmtPageName("$UploadDir$UploadPrefixFmt",$pagename)."/"; //Change for tegan, different urls used for direct-downloads...
00139   if( $EnableDirectDownload != 1 )
00140   {
00141        $uploadsUrl= "$scripturl?n=$pagename&action=download&upname=";
00142   }
00143 
00144   if ( isset($_GET['image']) )
00145     { $imageToEdit = $_GET['image']; }
00146        
00147   $pos = strrpos($drawing, '.');
00148   $filenameExtension = ($pos == false) ? '' : strtolower(substr($drawing, $pos + 1));
00149   $renderedDrawing = in_array($filenameExtension, array('png','jpg','jpeg')) ?
00150     $drawing : $drawing.".png";
00151   
00152   $currentlyExists = file_exists($uploadsPath.$drawing);
00153   $renderedCurrentlyExists = file_exists($uploadsPath.$renderedDrawing);
00154   $mapCurrentlyExists = file_exists($uploadsPath.$drawing.".map");
00155 
00156 
00157   $editImageUrl = $scripturl.'?pagename='.$pagename.'&action=editimage&image='.$drawing;
00158   $showHistoryUrl = $scripturl.'?pagename='.$pagename.'&action=imagehistory&image='.$drawing;
00159   
00160   
00161   if ($editImage == false || !isset($imageToEdit) || $imageToEdit != $drawing) {
00162          if ($mapCurrentlyExists) {
00163               $filename = $uploadsPath.$drawing.".map";
00164               $fp = fopen($filename, "r");
00165               $contents = fread($fp, filesize($filename));
00166               fclose($fp);
00167               $GCount = 0;  
00168               
00169               // Translate all global pmwiki $variables included in map
00170               $contents = FmtPageName($contents,$pagename); 
00171               
00172               // Write the MAP into the outgoing HTML code.
00173               $output .= "\n".$contents."\n";
00174          }
00175        
00176          if ($currentlyExists) {
00177               $output .= '<img ';
00178               
00179               if ($mapCurrentlyExists ) {
00180                 $output .= ' usemap="#'.$drawing.'" ';
00181               }
00182        
00183               $output .= ' class="pmwikidrawing" ';
00184               $output .= ' src="'.$uploadsUrl.$renderedDrawing.'"/>';
00185        
00186        // Mechanism to ensure that our urls get properly added into the variables that
00187        // FmtPagename references.
00188 ####CJ: I still can't get this to work, any ideas Knut?
00189 //     if($pmwikiver >1) {
00190 //            $FmtV['$editImageUrl'] = $editImageUrl;
00191 //            $FmtV['$showHistoryUrl'] = $showHistoryUrl;
00192 //            $FmtV['$pubdirurl'] = $pubdirurl;
00193 //            $FmtV['$scripturl'] = $scripturl;
00194 //     }
00195 //     else {
00196               $GCount = 0;  
00197 //     }  
00198 
00199               $output .= FmtPagename($displayDrawingEditFmt,$pagename); 
00200               $output .= FmtPagename($displayDrawingHistoryFmt, $pagename);
00201          }
00202          else 
00203               { $output .= FmtPageName('<a href="'.$editImageUrl.'">$[Create Image]('.$drawing.')</a>'."\n",$pagename); }
00204        }
00205 
00206   if ($editImage == true && isset($imageToEdit) && $imageToEdit == $drawing) {
00207 
00208        #### CJ: Hmm this might be an issue, as we can't determine whether a user
00209        #### is *allowed* to edit a picture until the point they save it we might end up 
00210        #### creating version files when there's no need to, or more to the point, shouldn't
00211        #### do as we'll be creating new files taking up space when its impossible for the user
00212        #### to modify the drawing anyway?
00213        #### Possible work arounds:
00214        ####    1) Always modify a 'tmp' drawing file and have the applet return to this page with
00215        ####       a particular action 'postDrawingEdit' for example.  And at this point check if the 
00216        ####       tmp file was modified i.e. diff between the 'original' and the 'tmp' if so then do 
00217        ####       versioning and redirect to 'browse' on the current page.
00218        ####    2) Too tired.. there must be others..ideas ?
00219        
00220     
00221     // copy of drawing file(s) for versioning
00222     if($EnableDrawingVersioning == true)  {
00223       $drawfileprefix = $uploadsPath.$drawing;
00224       
00225       if (file_exists("$drawfileprefix.draw")) {
00226         
00227         $drawfilelastchanged  = filemtime("$drawfileprefix.draw");
00228         $drawbackupfileprefix = "$drawfileprefix,$drawfilelastchanged";
00229         
00230         if (!file_exists("$drawbackupfileprefix.draw")) {
00231           // backupfile does not exist
00232           
00233           // Copy drawing source file
00234           if (!@copy("$drawfileprefix.draw", "$drawbackupfileprefix.draw"))
00235             { $output .= "<pre class='error'>failed to create backup $drawfileprefix.draw to $drawbackupfileprefix.draw</pre>\n"; }
00236           else
00237             { $output .= "<pre class='msg'>backuped ".basename("$drawfileprefix.draw")." to ".basename("$drawbackupfileprefix.draw")."</pre>\n"; }
00238   
00239           ### KAL: TODO: if copy-ok-messages not wanted, possibly en/disable display of msg by variable ?
00240           ###            copy messages will only be displayed under then image when in image-edit-mode
00241           ### KAL: TODO: check if needed to copy all files of drawing
00242           
00243           // Copy the map-file
00244           if (!@copy("$drawfileprefix.map", "$drawbackupfileprefix.map"))
00245             { $output .= "<pre class='error'>failed to backup $drawfileprefix.map  to $drawbackupfileprefix.map</pre>\n"; }
00246           else
00247             { $output .= "<pre class='msg'>backuped ".basename("$drawfileprefix.map")."  to ".basename("$drawbackupfileprefix.map")."</pre>\n"; }
00248             
00249           // Copy the gif file (better for displaying old versions)
00250           if (!@copy("$drawfileprefix.gif", "$drawbackupfileprefix.gif"))
00251             { $output .= "<pre class='error'>failed to backup $drawfileprefix.gif  to $drawbackupfileprefix.gif</pre>\n"; }
00252           else
00253             { $output .= "<pre class='msg'>backuped ".basename("$drawfileprefix.gif")."  to ".basename("$drawbackupfileprefix.gif")."</pre>\n"; }
00254   
00255           ### versioning the draw-file and gif-file could be enough, versions could be displayed via (:attachlist:) or via an own
00256           ### directive that allows display (then possibly better version map and gif too) and / or editing / recovery of older versions
00257         }
00258       }
00259     }    
00260      // Build the applet string.
00261       // create applet tag for image formats supported by the new applet
00262       $output .= '<applet code="org.anywikidraw.pmwiki.PmWikiDrawingApplet.class" ';
00263       $output .= 'archive="'.$CookbookDirURL.'/AnyWikiDraw/AnyWikiDrawForPmWiki.jar" ';
00264       $output .= 'width="600" height="480">'."\n";
00265 
00266       // The following parameters are used to tell AnyWikiDraw how to communicate with PmWiki:
00267 
00268       if ($currentlyExists) {
00269           $output .= '<param name="DrawingURL" value="'.$uploadsUrl.$drawing.'"/>'."\n";
00270       }
00271       $output .= '<param name="DrawingName" value="'.$drawing.'"/>'."\n";
00272       $output .= '<param name="DrawingWidth" value="'."400".'"/>'."\n";
00273       $output .= '<param name="DrawingHeight" value="'."240".'"/>'."\n";
00274       $output .= '<param name="PageName" value="'.$pagename.'"/>'."\n";
00275       $output .= '<param name="PageURL" value="'.$scripturl.'/'.$pagename.'"/>'."\n";
00276       $output .= '<param name="DrawingRevision" value="'.$Now.'"/>'."\n";
00277       $output .= '<param name="UploadURL" value="'.$scripturl.'"/>'."\n";
00278       $output .= '<param name="UploadAction" value="postDrawing"/>'."\n";
00279 
00280       // The following parameters are used to configure the drawing applet:
00281       // TODO : get the language of the user and set it here
00282       //$output .= '<param name="Locale" value="'.$wgUser->getOption('language','en').'"/>'."\n";
00283            
00284       // The following parameters are used to configure Sun's Java Plug-In:
00285 
00286       $output .= '<param name="codebase_lookup" value="false"/>'."\n";
00287       $output .= '<param name="classloader_cache" value="false"/>'."\n";
00288       $output .= '<param name="java_arguments" value="-Djnlp.packEnabled=true"/>'."\n";
00289       $output .= '<param name="image" value="lib/Splash.gif"/>'."\n";
00290       $output .= '<param name="boxborder" value="false"/>'."\n";
00291       $output .= '<param name="centerimage" value="true"/>'."\n";
00292 
00293       $output .= '</applet>'."\n";
00294   }
00295  
00296   return $output;
00297 }
00298 // ------------------- Handle the drawing markup for the .draw file format --------------------------------
00299 function drawing_draw($str) {
00300   global $action, $group, $pagename, $ScriptUrl, $UploadPrefixFmt;
00301   global $UploadUrlFmt, $UploadDir, $editImage, $displayDrawingEditFmt, $EnableDrawingDebug; 
00302   global $drawing, $editImageUrl, $drawingExtraColors, $EnableDrawingVersioning;
00303   global $pubdirurl, $PmWikiDrawPubUrl, $showHistoryUrl, $displayDrawingHistoryFmt;
00304   global $FmtV, $GCount, $drawingCompatibilityMode, $scripturl;
00305   global $Now;
00306 
00307   $drawing = $str;
00308   
00309   $output = "";
00310 
00311   // expand to full URL (incl http://) if url is relative:
00312   if (!preg_match('/^http:/',$ScriptUrl)) 
00313     { $scripturl = "http://".$_SERVER['HTTP_HOST'] . $ScriptUrl; }
00314   else 
00315     { $scripturl = $ScriptUrl; }
00316 
00317  
00318   // expand to full URL (incl http://) if url is relative:
00319   if (!preg_match('/^http:/',$PmWikiDrawPubUrl)) 
00320     { $pubdirurl = "http://".$_SERVER['HTTP_HOST'] . $PmWikiDrawPubUrl; }
00321   else 
00322     { $pubdirurl = $PmWikiDrawPubUrl; }
00323 
00324   // Work out the uploads path, both as a url and as an absolute path on the disk.
00325   $uploadsUrl = FmtPageName("$UploadUrlFmt$UploadPrefixFmt", $pagename)."/";
00326 
00327   // expand to full URL (incl http://) if url is relative:
00328   if (!preg_match('/^http:/',$uploadsUrl)) 
00329     { $uploadsUrl = "http://".$_SERVER['HTTP_HOST'] . $uploadsUrl; }
00330   
00331   $uploadsPath = FmtPageName("$UploadDir$UploadPrefixFmt",$pagename)."/";
00332 
00333   //Change for tegan, different urls used for direct-downloads...
00334   if( $EnableDirectDownload != 1 )
00335   {
00336        $uploadsUrl= "$scripturl?n=$pagename&action=download&upname=";
00337   }
00338 
00339   if ( isset($_GET['image']) )
00340     { $imageToEdit = $_GET['image']; }
00341        
00342   $currentlyExists = file_exists($uploadsPath.$drawing.".gif");
00343   $mapCurrentlyExists = file_exists($uploadsPath.$drawing.".map");
00344 
00345 
00346   $editImageUrl = $scripturl.'?pagename='.$pagename.'&action=editimage&image='.$drawing;
00347   $showHistoryUrl = $scripturl.'?pagename='.$pagename.'&action=imagehistory&image='.$drawing;
00348   
00349   if ($mapCurrentlyExists && $editImage == false) {
00350     // Add the map :)
00351     $filename = $uploadsPath.$drawing.".map";
00352     $fp = fopen($filename, "r");
00353     $contents = fread($fp, filesize($filename));
00354     fclose($fp);
00355 //    $contents = str_replace("%BUILDEDITLINK%", $editImageUrl, $contents);
00356 
00357 ####CJ: I still can't get this to work, any ideas Knut?
00358 //     if($pmwikiver >1) {
00359 //            $FmtV['$scripturl'] = $scripturl;
00360 //            $FmtV['$editImageUrl'] = $editImageUrl;
00361 //     }
00362 //     else {
00363               $GCount = 0;  
00364 //     }  
00365        
00366     // Translate all global pmwiki $variables included in map
00367     $contents = FmtPageName($contents,$pagename); 
00368        
00369     // Write the MAP into the outgoing HTML code.
00370     $output .= "\n".$contents."\n";
00371   }
00372 
00373   if ($currentlyExists ) {
00374     $output .= '<img ';
00375     
00376        if ($mapCurrentlyExists ) {
00377       $output .= ' usemap="#'.$drawing.'" ';
00378        }
00379 
00380        // Put a nice red border around the current image we're editing.
00381        if($editImage == true && isset($imageToEdit) && $imageToEdit == $drawing) {
00382       $output .= ' style="border:4px solid red;" alt="Image being edited" class="pmwikidrawing_editing"';
00383        }
00384        else {
00385         $output .= ' class="pmwikidrawing" ';
00386        }
00387 
00388     $output .= ' src="'.$uploadsUrl.$drawing.'.gif"/>';
00389        
00390        // Mechanism to ensure that our urls get properly added into the variables that
00391        // FmtPagename references.
00392 ####CJ: I still can't get this to work, any ideas Knut?
00393 //     if($pmwikiver >1) {
00394 //            $FmtV['$editImageUrl'] = $editImageUrl;
00395 //            $FmtV['$showHistoryUrl'] = $showHistoryUrl;
00396 //            $FmtV['$pubdirurl'] = $pubdirurl;
00397 //            $FmtV['$scripturl'] = $scripturl;
00398 //     }
00399 //     else {
00400               $GCount = 0;  
00401 //     }  
00402 
00403     $output .= FmtPagename($displayDrawingEditFmt,$pagename); 
00404     $output .= FmtPagename($displayDrawingHistoryFmt, $pagename);
00405 
00406     /* KAL: debugging only:
00407     DEBUG(htmlentities($editImageUrl),1);
00408     DEBUG(htmlentities($displayDrawingEditFmt),1);
00409     DEBUG(htmlentities(FmtPagename($displayDrawingEditFmt,$pagename)),1);
00410     DEBUG(htmlentities($displayDrawingHistoryFmt),1);
00411     DEBUG(htmlentities(FmtPagename($displayDrawingHistoryFmt, $pagename)),1);
00412     /* */
00413   }
00414   else 
00415     { $output .= FmtPageName('<a href="'.$editImageUrl.'">$[Create Image]('.$drawing.')</a>'."\n",$pagename); }
00416 
00417   if ($editImage == true && isset($imageToEdit) && $imageToEdit == $drawing) {
00418 
00419        #### CJ: Hmm this might be an issue, as we can't determine whether a user
00420        #### is *allowed* to edit a picture until the point they save it we might end up 
00421        #### creating version files when there's no need to, or more to the point, shouldn't
00422        #### do as we'll be creating new files taking up space when its impossible for the user
00423        #### to modify the drawing anyway?
00424        #### Possible work arounds:
00425        ####    1) Always modify a 'tmp' drawing file and have the applet return to this page with
00426        ####       a particular action 'postDrawingEdit' for example.  And at this point check if the 
00427        ####       tmp file was modified i.e. diff between the 'original' and the 'tmp' if so then do 
00428        ####       versioning and redirect to 'browse' on the current page.
00429        ####    2) Too tired.. there must be others..ideas ?
00430        
00431     
00432     // copy of drawing file(s) for versioning
00433     if($EnableDrawingVersioning == true)  {
00434       $drawfileprefix = $uploadsPath.$drawing;
00435       
00436       if (file_exists("$drawfileprefix.draw")) {
00437         
00438         $drawfilelastchanged  = filemtime("$drawfileprefix.draw");
00439         $drawbackupfileprefix = "$drawfileprefix,$drawfilelastchanged";
00440         
00441         if (!file_exists("$drawbackupfileprefix.draw")) {
00442           // backupfile does not exist
00443           
00444           // Copy drawing source file
00445           if (!@copy("$drawfileprefix.draw", "$drawbackupfileprefix.draw"))
00446             { $output .= "<pre class='error'>failed to create backup $drawfileprefix.draw to $drawbackupfileprefix.draw</pre>\n"; }
00447           else
00448             { $output .= "<pre class='msg'>backuped ".basename("$drawfileprefix.draw")." to ".basename("$drawbackupfileprefix.draw")."</pre>\n"; }
00449   
00450           ### KAL: TODO: if copy-ok-messages not wanted, possibly en/disable display of msg by variable ?
00451           ###            copy messages will only be displayed under then image when in image-edit-mode
00452           ### KAL: TODO: check if needed to copy all files of drawing
00453           
00454           // Copy the map-file
00455           if (!@copy("$drawfileprefix.map", "$drawbackupfileprefix.map"))
00456             { $output .= "<pre class='error'>failed to backup $drawfileprefix.map  to $drawbackupfileprefix.map</pre>\n"; }
00457           else
00458             { $output .= "<pre class='msg'>backuped ".basename("$drawfileprefix.map")."  to ".basename("$drawbackupfileprefix.map")."</pre>\n"; }
00459             
00460           // Copy the gif file (better for displaying old versions)
00461           if (!@copy("$drawfileprefix.gif", "$drawbackupfileprefix.gif"))
00462             { $output .= "<pre class='error'>failed to backup $drawfileprefix.gif  to $drawbackupfileprefix.gif</pre>\n"; }
00463           else
00464             { $output .= "<pre class='msg'>backuped ".basename("$drawfileprefix.gif")."  to ".basename("$drawbackupfileprefix.gif")."</pre>\n"; }
00465   
00466           ### versioning the draw-file and gif-file could be enough, versions could be displayed via (:attachlist:) or via an own
00467           ### directive that allows display (then possibly better version map and gif too) and / or editing / recovery of older versions
00468         }
00469      
00470         /* for debugging only: (add # in front of this statement to activate !
00471         $output .= "<pre class='debug'>";
00472         $output .= "drawfileprefix=$drawfileprefix\n";
00473         $output .= "drawbackupfileprefix=$drawbackupfileprefix\n";
00474         $output .= "drawfilelastchanged=$drawfilelastchanged\n";
00475         $output .= "</pre>";
00476         /* */
00477       }
00478     }    
00479      // Build the applet string.
00480      $CookbookDirURL = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'].'/../cookbook';
00481 //     if( $drawingCompatibilityMode == false) {
00482       $output .= '<applet code="com.wombatinvasion.pmwikidraw.PmWikiDraw.class" ';
00483       $output .= 'archive="'.$CookbookDirURL.'/AnyWikiDraw/draw/PmWikiDraw.jar" width="0" height="0">'."\n";
00484       $output .= '<param name="drawingname" value="'.$drawing.'"/>'."\n";
00485       $output .= '<param name="wikiurl" value="'.$scripturl.'"/>'."\n";
00486       $output .= '<param name="pagename" value="'.$pagename.'"/>'."\n";  
00487       $output .= '<param name="resourcesurl" value="'.$pubdirurl.'/drawing/"/>'."\n";
00488       $output .= '<param name="drawingbasetime" value="'.$Now.'"/>'."\n";
00489       $output .= '<param name="drawingloadpath" value="'.$uploadsUrl.$drawing.'.draw"/>'."\n";
00490 
00491       // Configurable parameters.
00492       if( $EnableDrawingDebug == true) 
00493         { $output .= '<param name="debug" value="true"/>'."\n"; }
00494 
00495       if ( $drawingExtraColors != "") 
00496         { $output .= '<param name="extracolors" value="'.$drawingExtraColors.'"/>'."\n"; }
00497       $output .= '</applet>'."\n";
00498   //  }
00499 //    else { // Compatibility mode...painful...
00500 //      // In theory, IE should see the OBJECt and run that, but Mozilla should see the comment and run the embed... in theory....
00501 //      $output .= '<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="0" height="0" align="baseline" codebase="http://javaweb.eng/plugin/jre-1_3-win.exe#Version=1,3,0,0">'."\n";
00502 //      $output .= '  <PARAM NAME="code" VALUE="CH.ifa.draw.twiki.TWikiDraw.class">'."\n";
00503 //      $output .= '  <PARAM NAME="archive" VALUE="'.$pubdirurl.'/drawing/PmWikiDraw.jar"/>'."\n";
00504 //      $output .= '  <PARAM NAME="type" VALUE="application/x-java-applet;version=1.3" />'."\n";
00505 //     $output .= '  <param name="drawingname" value="'.$drawing.'"/>'."\n";
00506 //      $output .= '  <param name="wikiurl" value="'.$scripturl.'"/>'."\n";
00507 //      $output .= '  <param name="pagename" value="'.$pagename.'"/>'."\n";  
00508 //      $output .= '  <param name="resourcesurl" value="'.$pubdirurl.'/drawing/"/>'."\n";
00509 //      $output .= '  <param name="drawingloadpath" value="'.$uploadsUrl.$drawing.'.draw"/>'."\n";
00510 //      $output .= '  <COMMENT>'."\n";  // This fella should be picked up by mozilla/netscape et al.
00511 //      $output .= '    <EMBED type                  ="application/x-java-applet;version=1.3" width="0" height="0"'."\n";
00512 //      $output .= '                  align                  ="baseline" code="CH.ifa.draw.twiki.TWikiDraw.class"'."\n";
00513 //      $output .= '                  drawingname     ="'.$drawing.'"'."\n";
00514 //      $output .= '                  wikiurl               ="'.$scripturl.'"'."\n";
00515  //     $output .= '                  pagename          ="'.$pagename.'"'."\n";
00516  //     $output .= '                  resourcesurl      ="'.$pubdirurl.'/drawing/"'."\n";
00517  //     $output .= '                  drawingloadpath ="'.$uploadsUrl.$drawing.'.draw"'."\n";
00518  //     $output .= '                  archive               ="'.$pubdirurl.'/drawing/PmWikiDraw.jar"'."\n";
00519  //     $output .= '     >'."\n";
00520   //    $output .= '    <NOEMBED></COMMENT>'."\n";
00521    //   $output .= '         No JDK 1.3 support for APPLET!! (Fall back to 1.1 Put original pmwikidraw applet here and swap the other two to use the most recent one)'."\n";
00522    //   $output .='     </NOEMBED>'."\n";
00523    //   $output .='   </EMBED>'."\n";
00524     //  $output .= '</OBJECT>'."\n";
00525     //}
00526   }
00527  
00528   return $output;
00529 }
00530 // ------------ Revision history code. ---------------
00531 // Handle Image History
00532 function HandleImageHistory($pagename) {
00533   global $HandleDiffFmt,$PageStartFmt,$PageDiffFmt,$PageEndFmt;
00534   Lock(1);
00535 
00536   if ( isset($_GET['image']) )
00537     { $imageToSeeHistory = $_GET['image']; }
00538 
00539   $page = ReadPage($pagename,'');
00540   if (!$page) { Abort("?cannot diff $pagename"); }
00541 //  SDV($HandleDiffFmt,array(&$PageStartFmt,
00542 //    &$PageDiffFmt,'function:PrintDiff',
00543 //    &$PageEndFmt));
00544 
00545   SDV($HandleDiffFmt,array(&$PageStartFmt,
00546     &$PageDiffFmt,"image history of $imageToSeeHistory",
00547     &$PageEndFmt));
00548 
00549   PrintFmt($pagename,$HandleDiffFmt);
00550 }
00551 
00552 // ---------------------------------------------------
00553 function HandlePostEditImage($pagename) {
00554   global $PageUrl;
00555   Redirect($pagename,"\$PageUrl");
00556 }
00557 
00558 // ---------------------------------------------------
00559 function HandlePostEditImage2($pagename) {
00560     global $RecentChangesFmt, $IsPagePosted, $EnableDrawingRecentChanges;
00561 
00562     if ( $EnableDrawingRecentChanges == true && isset($_GET['image']) ){ 
00563       $imageModified = $_GET['image']; 
00564       $RecentChangesFmt = array(
00565        'Main.AllRecentChanges' => 
00566        '* [[$Group/$Name]]  Drawing - '.$imageModified.' modified . . . $CurrentTime',
00567        '$Group.RecentChanges' =>
00568        '* [[$Group/$Name]]  Drawing - '.$imageModified.' modified . . . $CurrentTime');     
00569       $IsPagePosted = true;
00570        $x = "";
00571        $y="";
00572       PostRecentChanges($pagename, $x,$y);
00573       $IsPagePosted = false;
00574    }
00575    HandlePostEditImage($pagename);
00576 }
00577 
00578 
00579 function HandlePostDrawing($pagename) {
00580        global $UploadVerifyFunction,$UploadFileFmt,$LastModFile, $Now;
00581        global $RecentChangesFmt, $IsPagePosted, $EnableDrawingRecentChanges;
00582        
00583        if ($_POST['drawingbasetime']) {
00584               HandlePostDrawing_draw($pagename);
00585        } else {
00586               HandlePostDrawing_any($pagename);
00587        }
00588 }
00589 
00593 function HandlePostDrawing_any($pagename) {
00594        global $UploadVerifyFunction,$UploadFileFmt,$LastModFile, $Now;
00595        global $RecentChangesFmt, $IsPagePosted, $EnableDrawingRecentChanges;
00596        
00597   $page = RetrieveAuthPage($pagename,'upload');
00598   if (!$page) Abort("?cannot upload to $pagename");
00599   $uploadImage = $_FILES['RenderedImageData'];
00600   $uploadDrawing = $_FILES['DrawingData'];
00601   $uploadMap = $_FILES['ImageMapData'];
00602 
00603   $drawingBaseTime = $_POST['DrawingRevision'];  // The time the user began editing this drawing.
00604   $imageupname=$uploadImage['name'];
00605   $drawingupname=$uploadDrawing['name'];
00606   $mapupname=$uploadMap['name'];
00607 
00608   $imageupname = MakeUploadName($pagename,$imageupname);
00609   $drawingupname = MakeUploadName($pagename,$drawingupname);
00610   $mapupname = MakeUploadName($pagename,$mapupname);
00611   $imageFilePath = FmtPageName("$UploadFileFmt/$imageupname",$pagename);
00612   $drawingFilePath = FmtPageName("$UploadFileFmt/$drawingupname",$pagename);
00613   $mapFilePath = FmtPageName("$UploadFileFmt/$mapupname",$pagename);
00614 
00615   if( file_exists($drawingFilePath) ) {
00616        // Only worth checking timestamps if a drawing actually currently exists!
00617     if ( filemtime( $drawingFilePath ) > $drawingBaseTime ) {
00618               // Assign a new timestamp to the client... hopefully this time they'll be ok... 
00619               header("PmWikiDraw-DrawingChanged: $Now");
00620               exit;
00621     }
00622   } 
00623 
00624   // If we've got to here then we can assume its safe to overwrite the current file
00625   // Note: we should do the history archival/recent changes stuff here.
00626     if ( $EnableDrawingRecentChanges == true && isset($_POST['drawingname']) ){ 
00627       $imageModified = $_POST['drawingname']; 
00628       $RecentChangesFmt = array(
00629        'Main.AllRecentChanges' => 
00630        '* [[$Group/$Name]]  Drawing - '.$imageModified.' modified . . . $CurrentTime',
00631        '$Group.RecentChanges' =>
00632        '* [[$Group/$Name]]  Drawing - '.$imageModified.' modified . . . $CurrentTime');     
00633       $IsPagePosted = true;
00634        $x = "";
00635        $y="";
00636       PostRecentChanges($pagename, $x,$y);
00637       $IsPagePosted = false;
00638    }
00639     
00640   error_log('HandlePostDrawing we got here:'.$uploadDrawing);
00641   $filedir = preg_replace('#/[^/]*$#','',$imageFilePath);
00642   mkdirp($filedir);
00643   if (!move_uploaded_file($uploadImage['tmp_name'],$imageFilePath)) { 
00644     // Rendered image is optional, we don't need to abort here 
00645     //Abort("?cannot move uploaded image to $imageFilePath"); return;
00646   }
00647   fixperms($imageFilePath,0444);
00648   if ($LastModFile) { touch($LastModFile); fixperms($LastModFile); }
00649 
00650   $filedir = preg_replace('#/[^/]*$#','',$drawingFilePath);
00651   if (!move_uploaded_file($uploadDrawing['tmp_name'],$drawingFilePath))
00652     { Abort("?cannot move uploaded drawing to $drawingFilePath"); return; }
00653   fixperms($drawingFilePath,0444);
00654   if ($LastModFile) { touch($LastModFile); fixperms($LastModFile); }
00655 
00656   $filedir = preg_replace('#/[^/]*$#','',$mapFilePath);
00657   mkdirp($filedir);
00658   if (!move_uploaded_file($uploadMap['tmp_name'],$mapFilePath)) { 
00659     // Image map is optional, we don't need to abort here
00660     //Abort("?cannot move uploaded map to $mapFilePath"); return; 
00661   }
00662   fixperms($mapFilePath,0444);
00663   if ($LastModFile) { touch($LastModFile); fixperms($LastModFile); }
00664 
00665   // Sets the drawingBaseTime header for incremental save support.
00666   header( "PmWikiDraw-DrawingBaseTime: ".filemtime( $drawingFilePath ) );
00667 }
00671 function HandlePostDrawing_draw($pagename) {
00672   global $UploadVerifyFunction,$UploadFileFmt,$LastModFile, $Now;
00673   global $RecentChangesFmt, $IsPagePosted, $EnableDrawingRecentChanges;
00674 
00675   $page = RetrieveAuthPage($pagename,'upload');
00676   if (!$page) Abort("?cannot upload to $pagename");
00677   $uploadImage = $_FILES['uploadImage'];
00678   $uploadDrawing = $_FILES['uploadDrawing'];
00679   $uploadMap = $_FILES['uploadMap'];
00680 
00681   $drawingBaseTime = $_POST['drawingbasetime'];  // The time the user began editing this drawing.
00682   $imageupname=$uploadImage['name'];
00683   $drawingupname=$uploadDrawing['name'];
00684   $mapupname=$uploadMap['name'];
00685 
00686   $imageupname = MakeUploadName($pagename,$imageupname);
00687   $drawingupname = MakeUploadName($pagename,$drawingupname);
00688   $mapupname = MakeUploadName($pagename,$mapupname);
00689   $imageFilePath = FmtPageName("$UploadFileFmt/$imageupname",$pagename);
00690   $drawingFilePath = FmtPageName("$UploadFileFmt/$drawingupname",$pagename);
00691   $mapFilePath = FmtPageName("$UploadFileFmt/$mapupname",$pagename);
00692 
00693   if( file_exists($drawingFilePath) ) {
00694        // Only worth checking timestamps if a drawing actually currently exists!
00695     if ( filemtime( $drawingFilePath ) > $drawingBaseTime ) {
00696               // Assign a new timestamp to the client... hopefully this time they'll be ok... 
00697               header("PmWikiDraw-DrawingChanged: $Now");
00698               exit;
00699     }
00700   } 
00701 
00702   // If we've got to here then we can assume its safe to overwrite the current file
00703   // Note: we should do the history archival/recent changes stuff here.
00704     if ( $EnableDrawingRecentChanges == true && isset($_POST['drawingname']) ){ 
00705       $imageModified = $_POST['drawingname']; 
00706       $RecentChangesFmt = array(
00707        'Main.AllRecentChanges' => 
00708        '* [[$Group/$Name]]  Drawing - '.$imageModified.' modified . . . $CurrentTime',
00709        '$Group.RecentChanges' =>
00710        '* [[$Group/$Name]]  Drawing - '.$imageModified.' modified . . . $CurrentTime');     
00711       $IsPagePosted = true;
00712        $x = "";
00713        $y="";
00714       PostRecentChanges($pagename, $x,$y);
00715       $IsPagePosted = false;
00716    }
00717     
00718   $filedir = preg_replace('#/[^/]*$#','',$imageFilePath);
00719   mkdirp($filedir);
00720   if (!move_uploaded_file($uploadImage['tmp_name'],$imageFilePath))
00721     { Abort("?cannot move uploaded image to $imageFilePath"); return; }
00722   fixperms($imageFilePath,0444);
00723   if ($LastModFile) { touch($LastModFile); fixperms($LastModFile); }
00724 
00725   $filedir = preg_replace('#/[^/]*$#','',$drawingFilePath);
00726   mkdirp($filedir);
00727   if (!move_uploaded_file($uploadDrawing['tmp_name'],$drawingFilePath))
00728     { Abort("?cannot move uploaded drawing to $drawingFilePath"); return; }
00729   fixperms($drawingFilePath,0444);
00730   if ($LastModFile) { touch($LastModFile); fixperms($LastModFile); }
00731 
00732   $filedir = preg_replace('#/[^/]*$#','',$mapFilePath);
00733   mkdirp($filedir);
00734   if (!move_uploaded_file($uploadMap['tmp_name'],$mapFilePath))
00735     { Abort("?cannot move uploaded map to $mapFilePath"); return; }
00736   fixperms($mapFilePath,0444);
00737   if ($LastModFile) { touch($LastModFile); fixperms($LastModFile); }
00738 
00739   // Sets the drawingBaseTime header for incremental save support.
00740   header( "PmWikiDraw-DrawingBaseTime: ".filemtime( $drawingFilePath ) );
00741   
00742   exit();
00743 }
00744 ?>