<?php
//vim :set ts=2 sw=2 expandtab enc=utf-8
/**
* Supa helper plugin
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Christoph Linder
*/
// must be run within Dokuwiki
//if(!defined('DOKU_INC')) die();
//require_once(DOKU_INC.'inc/plugin.php');
/**
*/
class helper_plugin_supa extends DokuWiki_Plugin {
//function helper_plugin_supa(){
//}
function getInfo() {
return array(
'name' => 'Supa',
'author' => 'Christoph Linder',
'email' => 'hide@address.com',
'date' => '2010-01-23',
'desc' => 'Easy upload of images from the clipboard (e.g. screenshots) to the media library',
'url' => 'http://www.sourceforge.net/projects/supa'
);
}
function getMethods() {
$result = array();
$result[] = array(
'name' => 'decodeScreenshotFile',
'desc' => 'Decodes an uploaded screenshot file so that it is compatible to the "normal" file upload mechanism. Note: parameter &file is a ref to an entry in the $FILES superglobal!',
'params' => array( '&file' => 'array',
'&id' => 'string' ),
'return' => "boolean: success or failure"
);
$result[] = array(
'name' => 'html_supa_applet',
'desc' => 'Paint the Supa applet and the upload controls on the media manager window.',
'params' => array( 'ns' => 'string',
'auth' => 'numeric' )
);
return $result;
}
//FIXME: do not pass the $_FILES array but separate values
//FIXME: move this to action.php?
function decodeScreenshotFile( &$upload_file, &$id ) {
$filename = $upload_file['tmp_name'];
// read entire source file
$fh = fopen( $filename, 'r' );
$data = fread( $fh, filesize( $filename ) );
fclose( $fh );
// write decoded data to destination file
$decoded = base64_decode( $data );
if( !$decoded ) {
msg( "Err: ".$lang['err_decoding'], -1 );
return false;
}
$fh = fopen( $filename, "w" );
fwrite( $fh, $decoded );
fclose( $fh );
// change info of the uploaded file to the decoded values
clearstatcache();
$upload_file['type'] = 'image/png';
$upload_file['size'] = filesize( $filename );
//echo "sizeeeee: ".filesize( $filename );
$upload_file['name'] = preg_replace( '/\.supascreenshot$/i', '', $upload_file['name'] );
$id = preg_replace( '/\.supascreenshot$/i', '', $id );
return true;
}
/*
function clean( $var ) {
return trim( $var, "\n\r" );
}
*/
function html_supa_applet( $ns, $auth ) {
global $xyzzy;
$xyzzy = "x";
$ext = 'png'; // $this->getConf('imagecodec');
$supa_classpath = DOKU_BASE."lib/plugins/supa/lib/Supa.jar";
$default_filename = "screenshot-".date("Y-m-d_H-i-s"). "." .$ext;
?>
<div id="supa__upload" style="display:none">
<div class="upload">
<button id="supa__pastebutton" type="button"><?= $this->getLang('label_paste_image') ?></button><br/>
<div style="border: 1px solid black;">
<applet name="Supa__Applet"
archive="<?=DOKU_BASE."lib/plugins/supa/lib/Supa.jar"?>"
code="de.christophlinder.supa.SupaApplet"
width="<?=$this->getConf( 'previewwidth' )?>"
height="<?=$this->getConf( 'previewheight' )?>">
<param name="imagecodec" value="png"/>
<param name="previewscaler" value="<?=$this->getConf('previewscaler')?>"/>
<param name="encoding" value="base64"/>
<?=$this->getLang('txt_no_java')?>
</applet>
</div>
<br/>
<input id="supa__sectok" type="hidden" value="<?=getSecurityToken()?>"/>
<label for="supa__ns"><?=$this->getLang('prompt_namespace')?>:</label><input id="supa__ns" value="<?=hsc($ns)?>"/><span title="<?=$this->getLang('txt_required_hint')?>"><?=$this->getLang('txt_required')?></span><br/>
<label for="supa__filename"><?= $this->getLang('prompt_filename')?>:</label><input id="supa__filename" value="<?=$default_filename?>"/><span title="<?=$this->getLang('txt_required_hint')?>"><?=$this->getLang('txt_required')?></span><br/>
<button id="supa__uploadbutton" type="button"><?= $this->getLang('txt_upload_image') ?></button><br/>
</div>
</div>
<?php
}
}