|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00026 function block_html_pluginfile($course, $birecord_or_cm, $context, $filearea, $args, $forcedownload) { 00027 global $SCRIPT; 00028 00029 if ($context->contextlevel != CONTEXT_BLOCK) { 00030 send_file_not_found(); 00031 } 00032 00033 require_course_login($course); 00034 00035 if ($filearea !== 'content') { 00036 send_file_not_found(); 00037 } 00038 00039 $fs = get_file_storage(); 00040 00041 $filename = array_pop($args); 00042 $filepath = $args ? '/'.implode('/', $args).'/' : '/'; 00043 00044 if (!$file = $fs->get_file($context->id, 'block_html', 'content', 0, $filepath, $filename) or $file->is_directory()) { 00045 send_file_not_found(); 00046 } 00047 00048 if ($parentcontext = get_context_instance_by_id($birecord_or_cm->parentcontextid)) { 00049 if ($parentcontext->contextlevel == CONTEXT_USER) { 00050 // force download on all personal pages including /my/ 00051 //because we do not have reliable way to find out from where this is used 00052 $forcedownload = true; 00053 } 00054 } else { 00055 // weird, there should be parent context, better force dowload then 00056 $forcedownload = true; 00057 } 00058 00059 session_get_instance()->write_close(); 00060 send_stored_file($file, 60*60, 0, $forcedownload); 00061 } 00062 00069 function block_html_global_db_replace($search, $replace) { 00070 global $DB; 00071 00072 $instances = $DB->get_recordset('block_instances', array('blockname' => 'html')); 00073 foreach ($instances as $instance) { 00074 // TODO: intentionally hardcoded until MDL-26800 is fixed 00075 $config = unserialize(base64_decode($instance->configdata)); 00076 if (isset($config->text) and is_string($config->text)) { 00077 $config->text = str_replace($search, $replace, $config->text); 00078 $DB->set_field('block_instances', 'configdata', base64_encode(serialize($config)), array('id' => $instance->id)); 00079 } 00080 } 00081 $instances->close(); 00082 }