adding some strings
[moodle-linuxchix.git] / mod / wiki / ewiki / plugins / moodle / moodle_binary_store.php
blob0d05f959c9303dc5d4ec89aa73acc45e91a5429e
1 <?php // $Id$
3 /*
4 This plugin intercepts some of the binary handling functions to
5 store uploaded files (as is) into a dedicated directory.
6 Because the ewiki database abstraction layer was not designed to
7 hold large files (because it reads records in one chunk), you may need
8 to use this, else large files may break.
10 WARNING: this is actually a hack and not a database layer extension,
11 so it will only work with the ewiki.php script itself. The database
12 administration tools are not aware of this agreement and therefor
13 cannot (for example) backup the externally stored data files!
14 If you later choose to disable this extension, the uploaded (and thus
15 externally stored) files then cannot be accessed any longer, of course.
17 - You must load this plugin __before__ the main script, because the
18 binary stuff in ewiki.php always engages automatically.
19 - The store directory can be the same as for dbff (filenames differ).
20 - All the administration tools/ are not aware of this hack, so __you__
21 must take care, when it comes to creating backups.
25 #-- config
26 define("EWIKI_DB_STORE_DIRECTORY", "/tmp"); // where to save binary files
27 define("EWIKI_DB_STORE_MINSIZE", 0); // send smaller files into db
28 define("EWIKI_DB_STORE_MAXSIZE", 32 <<20); // 32MB max per file (but
29 // there is actually no way to upload such large files via HTTP)
31 # define("EWIKI_DB_STORE_URL", "http://example.com/wiki/files/store/");
32 // allows clients to directly access stored plain data files,
33 // without redirection through ewiki.php, RTFM
36 #-- glue
37 $ewiki_plugins["binary_store"][] = "moodle_binary_store_file";
38 $ewiki_plugins["binary_get"][] = "moodle_binary_store_get_file";
41 function moodle_binary_get_path($id, $meta, $course, $wiki, $userid, $groupid) {
42 global $CFG;
43 $entry=wiki_get_entry($wiki, $course, $userid, $groupid);
44 if(!$entry) {
45 error("Cannot get entry.");
48 $dir=make_upload_directory("$course->id/$CFG->moddata/wiki/$wiki->id/$entry->id/".$meta["section"]);
49 if(substr($id, 0, strlen(EWIKI_IDF_INTERNAL))!=EWIKI_IDF_INTERNAL) {
50 error("Binary entry does not start with ".EWIKI_IDF_INTERNAL.substr($id, 0, strlen(EWIKI_IDF_INTERNAL)));
52 $id = substr($id,strlen(EWIKI_IDF_INTERNAL));
53 $id = clean_filename($id);
55 return "$dir/$id";
59 #-- upload
60 function moodle_binary_store_file(&$filename, &$id, &$meta, $ext=".bin") {
61 # READ-Only
62 global $_FILES, $CFG, $course, $wiki, $groupid, $userid, $ewiki_title, $cm;
63 if(!$wiki->ewikiacceptbinary) {
64 error("This wiki does not accept binaries");
65 return 0;
69 $entry=wiki_get_entry($wiki, $course, $userid, $groupid);
70 if(!$entry->id) {
71 error("Cannot get entry.");
74 require_once($CFG->dirroot.'/lib/uploadlib.php');
75 $um = new upload_manager('upload',false,false,$course,false,0,true,true);
76 if ($um->process_file_uploads("$course->id/$CFG->moddata/wiki/$wiki->id/$entry->id/$ewiki_title")) {
77 $filename = ''; // this to make sure we don't keep processing in the parent function
78 if(!$id) {
79 $newfilename = $um->get_new_filename();
80 $id = EWIKI_IDF_INTERNAL.$newfilename;
82 return true;
84 error($um->print_upload_log(true));
85 return false;
90 #-- download
91 function moodle_binary_store_get_file($id, &$meta) {
92 # READ-Only
93 global $CFG, $cm, $course, $wiki, $groupid, $userid;
95 #-- check for file
96 if(!$wiki->ewikiacceptbinary) {
97 error("This wiki does not accept binaries");
98 return 0;
102 $filepath=moodle_binary_get_path($id, $meta, $course, $wiki, $userid, $groupid);
103 if (file_exists($filepath)) {
104 readfile($filepath);
105 return(true);
106 } else {
107 return(false);
109 //$dbfname = EWIKI_DB_STORE_DIRECTORY."/".rawurlencode($id);
110 //if (file_exists($dbfname)) {
111 // readfile($dbfname);
112 // return(true);
114 //else {
115 // return(false);