*/ if (! defined ( 'NL' )) define ( 'NL', "\n" ); if (! defined ( 'DOKU_INC' )) define ( 'DOKU_INC', dirname ( __FILE__ ) . '/../../' ); if (! defined ( 'DOKU_PLUGIN' )) define ( 'DOKU_PLUGIN', DOKU_INC . 'lib/plugins/' ); require_once (DOKU_PLUGIN . 'syntax.php'); require_once (DOKU_INC . 'inc/media.php'); require_once (DOKU_INC . 'inc/auth.php'); require_once (DOKU_INC . 'inc/infoutils.php'); class syntax_plugin_fileshare_Fileshare extends DokuWiki_Syntax_Plugin { /** * @return string Syntax mode type */ public function getType() { return 'container'; } /** * @return string Paragraph type */ public function getPType() { return 'normal'; } /** * @return int Sort order - Low numbers go before high numbers */ public function getSort() { return 280; } /** * Connect lookup pattern to lexer. * * @param string $mode Parser mode */ public function connectTo($mode) { $this->Lexer->addSpecialPattern ( '\{\{FileSharing\}\}', $mode, 'plugin_fileshare_Fileshare' ); $this->Lexer->addSpecialPattern ( '\{\{FileSharing>.+\}\}', $mode, 'plugin_fileshare_Fileshare' ); } /** * Handle matches of the fileshare syntax * * @param string $match The match of the syntax * @param int $state The state of the handler * @param int $pos The position in the document * @param Doku_Handler $handler The handler * @return array Data for the renderer */ public function handle($match, $state, $pos, Doku_Handler $handler){ $pos = strpos($match, "{{FileSharing>"); if($pos !== FALSE){ $data = explode("|",preg_replace("/{{FileSharing>(.*?)}}/","\\1",$match)); return $data; } $data = array (); return $data; } /** * Render xhtml output or metadata * * @param string $mode Renderer mode (supported modes: xhtml) * @param Doku_Renderer $renderer The renderer * @param array $data The data from the handler() function * @return bool If rendering was successful. */ public function render($mode, Doku_Renderer $renderer, $data) { //if ($_FILES ['upload'] ['tmp_name']) { if(isset($_FILES['upload']) ){ $dir = $_POST ['ns']; $tmp_name = $_FILES ['upload'] ['tmp_name']; // basename() kann Directory-Traversal-Angriffe verhindern; // weitere Validierung/Bereinigung des Dateinamens kann angebracht sein $name = basename ( $_FILES ['upload'] ['name'] ); if ( move_uploaded_file ( $tmp_name, $dir . '/' . $name )=== FALSE) { $lastError = error_get_last(); $err = $lastError ? "Error: ".$lastError["message"]." on line ".$lastError["line"] : ""; $renderer->doc .= 'Fehler beim Upload! '.$err; } } if($mode != 'xhtml') return false; $renderer->nocache(); if(empty($data)){ $givenDir=''; } else{ $givenDir= current($data); } $this->renderForm ( $givenDir, $renderer ); return true; } private function renderForm($dir, $renderer) { global $ID; $archivRootDir = $this->getConf ( 'archivRootDir' ); if(!isset($archivRootDir) || trim($archivRootDir)===''){ $renderer->doc .= 'Please set the root dir to archive files in the admin section!'; } else { $fileDir = $archivRootDir; if(isset($dir) && trim($dir)!==''){ $fileDir =$fileDir. '/' . $dir; } $this->createDir ( $fileDir, $renderer ); $renderer->doc .= '
' . NL; $html .= $form->getForm (); $html .= '