");
SDV($displayDrawingEditFmt, "");
// css style for drawing caption
#$HTMLStylesFmt[] = ".pmwikidraweditlink { font-size:70%; font-weight:bold; }\n";
// Add extra colors to the fill/color menus.
#$drawingExtraColors = "Aquamarine=#70DB93,New Tan=EBC79E,Sea Green=238E68,Motorola Blue=#3ff";
// -----------------------------------------------------------------------------------------------------------------
//-------------------- Globally executed code --------------------
// Work out which version of PmWiki we're looking at :)
preg_match('/.*-(\\d+)/',$Version,$match);
$pmwikiver = $match[1];
if($pmwikiver <= 1) {
echo "PmWikiDraw no longer supports PmWiki1, please upgrade to PmWiki2. Thanks.";
exit();
}
// Add in our required file extensions and associate the new markup.
SDVA($UploadExts, array('gif' => 'image/gif', 'draw' => 'text/plain', 'map' => 'text/plain'));
Markup('drawing','inline', "/\\(:drawing\\s*(\\w[-.\\w]*\\w)\\s*:\\)/", "drawing");
SDV($HandleActions['imagehistory'],'HandleImageHistory');
SDV($HandleActions['postDrawing'], 'HandlePostDrawing');
// Modify global variables based on the current action type.
if ($action=='editimage')
{ $editImage = true; }
else
{ $editImage = false; }
if($action=='print' || $action=='publish' || $action=='editimage' || $action=='edit') {
// Hide the edit & history links when printing/publishing/editing
$displayDrawingEditFmt = "";
$displayDrawingHistoryFmt = "";
}
if (!$EnableDrawingVersioning)
{ $displayDrawingHistoryFmt = ""; }
// ------------------- Handle the drawing markup --------------------------------
function drawing($m) {
$str = $m[1];
global $action, $group, $pagename, $ScriptUrl, $UploadPrefixFmt;
global $UploadUrlFmt, $UploadDir, $editImage, $displayDrawingEditFmt, $EnableDrawingDebug;
global $drawing, $editImageUrl, $drawingExtraColors, $EnableDrawingVersioning;
global $pubdirurl, $PmWikiDrawPubUrl, $showHistoryUrl, $displayDrawingHistoryFmt;
global $FmtV, $GCount, $drawingCompatibilityMode, $scripturl;
global $EnableUpload;
global $Now;
$drawing = $str;
$output = "";
if($EnableUpload != 1) { // Helpful hint to make sure people turn on uploads!
$output.= "Please note your administrator *NEEDS* to enable uploads before you can save your drawings. ";
}
// expand to full URL (incl http://) if url is relative:
if (!preg_match('/^http:/',$ScriptUrl))
{ $scripturl = "http://".$_SERVER['HTTP_HOST'] . $ScriptUrl; }
else
{ $scripturl = $ScriptUrl; }
// expand to full URL (incl http://) if url is relative:
if (!preg_match('/^http:/',$PmWikiDrawPubUrl))
{ $pubdirurl = "http://".$_SERVER['HTTP_HOST'] . $PmWikiDrawPubUrl; }
else
{ $pubdirurl = $PmWikiDrawPubUrl; }
// Work out the uploads path, both as a url and as an absolute path on the disk.
$uploadsUrl = FmtPageName("$UploadUrlFmt$UploadPrefixFmt", $pagename)."/";
// expand to full URL (incl http://) if url is relative:
if (!preg_match('/^http:/',$uploadsUrl))
{ $uploadsUrl = "http://".$_SERVER['HTTP_HOST'] . $uploadsUrl; }
$uploadsPath = FmtPageName("$UploadDir$UploadPrefixFmt",$pagename)."/";
if ( isset($_GET['image']) )
{ $imageToEdit = $_GET['image']; }
$currentlyExists = file_exists($uploadsPath.$drawing.".gif");
$mapCurrentlyExists = file_exists($uploadsPath.$drawing.".map");
$editImageUrl = $scripturl.'?pagename='.$pagename.'&action=editimage&image='.$drawing;
$showHistoryUrl = $scripturl.'?pagename='.$pagename.'&action=imagehistory&image='.$drawing;
if ($mapCurrentlyExists && $editImage == false) {
// Add the map :)
$filename = $uploadsPath.$drawing.".map";
$fp = fopen($filename, "r");
$contents = fread($fp, filesize($filename));
fclose($fp);
// $contents = str_replace("%BUILDEDITLINK%", $editImageUrl, $contents);
####CJ: I still can't get this to work, any ideas Knut?
// if($pmwikiver >1) {
// $FmtV['$scripturl'] = $scripturl;
// $FmtV['$editImageUrl'] = $editImageUrl;
// }
// else {
$GCount = 0;
// }
// Translate all global pmwiki $variables included in map
$contents = FmtPageName($contents,$pagename);
// Write the MAP into the outgoing HTML code.
$output .= "\n".$contents."\n";
}
if ($currentlyExists ) {
$output .= '';
// Mechanism to ensure that our urls get properly added into the variables that
// FmtPagename references.
####CJ: I still can't get this to work, any ideas Knut?
// if($pmwikiver >1) {
// $FmtV['$editImageUrl'] = $editImageUrl;
// $FmtV['$showHistoryUrl'] = $showHistoryUrl;
// $FmtV['$pubdirurl'] = $pubdirurl;
// $FmtV['$scripturl'] = $scripturl;
// }
// else {
$GCount = 0;
// }
$output .= FmtPagename($displayDrawingEditFmt,$pagename);
$output .= FmtPagename($displayDrawingHistoryFmt, $pagename);
/* KAL: debugging only:
DEBUG(htmlentities($editImageUrl),1);
DEBUG(htmlentities($displayDrawingEditFmt),1);
DEBUG(htmlentities(FmtPagename($displayDrawingEditFmt,$pagename)),1);
DEBUG(htmlentities($displayDrawingHistoryFmt),1);
DEBUG(htmlentities(FmtPagename($displayDrawingHistoryFmt, $pagename)),1);
/* */
}
else
{ $output .= FmtPageName('$[Create Image]('.$drawing.')'."\n",$pagename); }
if ($editImage == true && isset($imageToEdit) && $imageToEdit == $drawing) {
#### CJ: Hmm this might be an issue, as we can't determine whether a user
#### is *allowed* to edit a picture until the point they save it we might end up
#### creating version files when there's no need to, or more to the point, shouldn't
#### do as we'll be creating new files taking up space when its impossible for the user
#### to modify the drawing anyway?
#### Possible work arounds:
#### 1) Always modify a 'tmp' drawing file and have the applet return to this page with
#### a particular action 'postDrawingEdit' for example. And at this point check if the
#### tmp file was modified i.e. diff between the 'original' and the 'tmp' if so then do
#### versioning and redirect to 'browse' on the current page.
#### 2) Too tired.. there must be others..ideas ?
// copy of drawing file(s) for versioning
if($EnableDrawingVersioning == true) {
$drawfileprefix = $uploadsPath.$drawing;
if (file_exists("$drawfileprefix.draw")) {
$drawfilelastchanged = filemtime("$drawfileprefix.draw");
$drawbackupfileprefix = "$drawfileprefix,$drawfilelastchanged";
if (!file_exists("$drawbackupfileprefix.draw")) {
// backupfile does not exist
// Copy drawing source file
if (!@copy("$drawfileprefix.draw", "$drawbackupfileprefix.draw"))
{ $output .= "
failed to create backup $drawfileprefix.draw to $drawbackupfileprefix.draw
\n"; }
else
{ $output .= "
backuped ".basename("$drawfileprefix.draw")." to ".basename("$drawbackupfileprefix.draw")."
\n"; }
### KAL: TODO: if copy-ok-messages not wanted, possibly en/disable display of msg by variable ?
### copy messages will only be displayed under then image when in image-edit-mode
### KAL: TODO: check if needed to copy all files of drawing
// Copy the map-file
if (!@copy("$drawfileprefix.map", "$drawbackupfileprefix.map"))
{ $output .= "
failed to backup $drawfileprefix.map to $drawbackupfileprefix.map
\n"; }
else
{ $output .= "
backuped ".basename("$drawfileprefix.map")." to ".basename("$drawbackupfileprefix.map")."
\n"; }
// Copy the gif file (better for displaying old versions)
if (!@copy("$drawfileprefix.gif", "$drawbackupfileprefix.gif"))
{ $output .= "
failed to backup $drawfileprefix.gif to $drawbackupfileprefix.gif
\n"; }
else
{ $output .= "
backuped ".basename("$drawfileprefix.gif")." to ".basename("$drawbackupfileprefix.gif")."
\n"; }
### versioning the draw-file and gif-file could be enough, versions could be displayed via (:attachlist:) or via an own
### directive that allows display (then possibly better version map and gif too) and / or editing / recovery of older versions
}
/* for debugging only: (add # in front of this statement to activate !
$output .= "
";
/* */
}
}
// Build the applet string.
// if( $drawingCompatibilityMode == false) {
$output .= ''."\n";
// }
// else { // Compatibility mode...painful...
// // In theory, IE should see the OBJECt and run that, but Mozilla should see the comment and run the embed... in theory....
// $output .= '