From cfd146aefad6133bae9ee2e150fc642841497cdd Mon Sep 17 00:00:00 2001 From: mjollnir_ Date: Mon, 8 Nov 2004 05:32:18 +0000 Subject: [PATCH] Wiki integration with upload class. Changes in two upload forms and in moodle_binary_store.php - moodle_binary_store_file These patches are maintained in an publicly accessible Arch repository, see: http://lists.eduforge.org/cgi-bin/archzoom.cgi/arch-eduforge@catalyst.net.nz--2004-MIRROR/moodle--eduforge--1.3.3 Index of arch patches in this commit: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-363 Penny Leach wiki integration with upload class. arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-364 Penny Leach fixed lost submit button from last wiki upload patch, also fixed bug related to generating db id for attached files Full logs: Revision: moodle--eduforge--1.3.3--patch-363 Archive: arch-eduforge@catalyst.net.nz--2004 Creator: Penny Leach Date: Mon Nov 8 11:18:08 NZDT 2004 Standard-date: 2004-11-07 22:18:08 GMT Modified-files: mod/wiki/ewiki/ewiki.php mod/wiki/ewiki/plugins/moodle/downloads.php mod/wiki/ewiki/plugins/moodle/moodle_binary_store.php New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-363 Summary: wiki integration with upload class. Keywords: Revision: moodle--eduforge--1.3.3--patch-364 Archive: arch-eduforge@catalyst.net.nz--2004 Creator: Penny Leach Date: Mon Nov 8 16:01:29 NZDT 2004 Standard-date: 2004-11-08 03:01:29 GMT Modified-files: mod/wiki/ewiki/plugins/moodle/downloads.php mod/wiki/ewiki/plugins/moodle/moodle_binary_store.php New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-364 Summary: fixed lost submit button from last wiki upload patch, also fixed bug related to generating db id for attached files Keywords: --- mod/wiki/ewiki/ewiki.php | 1 + mod/wiki/ewiki/plugins/moodle/downloads.php | 14 ++--- .../plugins/moodle/moodle_binary_store.php | 55 ++++--------------- 3 files changed, 18 insertions(+), 52 deletions(-) diff --git a/mod/wiki/ewiki/ewiki.php b/mod/wiki/ewiki/ewiki.php index 235c21b4f5..e22181c50b 100644 --- a/mod/wiki/ewiki/ewiki.php +++ b/mod/wiki/ewiki/ewiki.php @@ -1591,6 +1591,7 @@ function ewiki_page_edit_form_final_imgupload(&$o, &$id, &$data, &$action) { . '
' + . '' . '' : "") . '' diff --git a/mod/wiki/ewiki/plugins/moodle/downloads.php b/mod/wiki/ewiki/plugins/moodle/downloads.php index c6819674ea..43ca502a6b 100644 --- a/mod/wiki/ewiki/plugins/moodle/downloads.php +++ b/mod/wiki/ewiki/plugins/moodle/downloads.php @@ -92,7 +92,7 @@ $ewiki_t["de"]["DWNL_ENTRY_FORMAT"] = function ewiki_page_fileupload($id, $data, $action, $def_sec="") { - global $ewiki_upload_sections, $ewiki_plugins; + global $CFG, $ewiki_upload_sections, $ewiki_plugins; $o = ewiki_make_title($id, $id, 2); @@ -104,12 +104,12 @@ function ewiki_page_fileupload($id, $data, $action, $def_sec="") { $o .= '
'. '' . - ''.ewiki_t("file").'


' . - '

'; - - $o .= '' . ewiki_t("comment") . '


'; - + '" method="POST" enctype="multipart/form-data">' ; + require_once($CFG->dirroot.'/lib/uploadlib.php'); + $o .= upload_print_form_fragment(1,array(EWIKI_UP_UPLOAD),array(ewiki_t("file")),false,null,0,0,true); + $o .= '

' + .'' . ewiki_t("comment") . '


'; + if (empty($ewiki_upload_sections[$def_sec])) { $ewiki_upload_sections[$def_sec] = $def_sec; } diff --git a/mod/wiki/ewiki/plugins/moodle/moodle_binary_store.php b/mod/wiki/ewiki/plugins/moodle/moodle_binary_store.php index ec70c5d09a..6352ed4d26 100644 --- a/mod/wiki/ewiki/plugins/moodle/moodle_binary_store.php +++ b/mod/wiki/ewiki/plugins/moodle/moodle_binary_store.php @@ -65,60 +65,25 @@ function moodle_binary_store_file(&$filename, &$id, &$meta, $ext=".bin") { return 0; } - $maxbytes = get_max_upload_file_size(); $entry=wiki_get_entry($wiki, $course, $userid, $groupid); if(!$entry->id) { error("Cannot get entry."); } - $newfile = $_FILES["upload"]; - if(!$id) { - $newfilename = clean_filename($newfile['name']); - $id = EWIKI_IDF_INTERNAL.$newfilename; - } - $dir=make_upload_directory("$course->id/$CFG->moddata/wiki/$wiki->id/$entry->id/$ewiki_title"); - if ($maxbytes and $newfile['size'] > $maxbytes) { - return 0; - } - if (! $newfilename) { - notify("This file had a weird filename and couldn't be uploaded"); - } else { - if (move_uploaded_file($filename, "$dir/$newfilename")) { - chmod("$dir/$newfilename", $CFG->directorypermissions); - $meta["binary_store"]=$ewiki_title; - $filename=""; - return true; - } else { - notify("An error happened while saving the file on the server"); - return false; + require_once($CFG->dirroot.'/lib/uploadlib.php'); + $um = new upload_manager('upload',false,false,$course,false,0,true,true); + if ($um->process_file_uploads("$course->id/$CFG->moddata/wiki/$wiki->id/$entry->id/$ewiki_title")) { + $filename = ''; // this to make sure we don't keep processing in the parent function + if(!$id) { + $newfilename = $um->get_new_filename(); + $id = EWIKI_IDF_INTERNAL.$newfilename; } + return true; } + error($um->print_upload_log(true)); return false; - - -/* if (($meta["size"] >= EWIKI_DB_STORE_MINSIZE) && ($meta["size"] <= EWIKI_DB_STORE_MAXSIZE)) { - - #-- generate internal://md5sum - if (empty($id)) { - $md5sum = md5_file($filename); - $id = EWIKI_IDF_INTERNAL . $md5sum . ".$ext"; - ewiki_log("generated md5sum '$md5sum' from file content"); - } - - #-- move file to dest. location - $dbfname = EWIKI_DB_STORE_DIRECTORY."/".rawurlencode($id); - if (@rename($filename, $dbfname) || copy($filename, $dbfname) && unlink($filename)) { - $filename = ""; - $meta["binary_store"] = 1; - return(true); - } - else { - ewiki_log("file store error with '$dbfname'", 0); - } - } - - return(false);*/ + } -- 2.39.5