define('BLOCK_TYPE_LIST', 1);
define('BLOCK_TYPE_TEXT', 2);
+define('BLOCK_TYPE_NUKE', 3);
class MoodleBlock {
var $str;
$this->get_content();
switch($this->content_type) {
+ case BLOCK_TYPE_NUKE:
case BLOCK_TYPE_TEXT:
if(empty($this->content->text) && empty($this->content->footer)) {
break;
$errors[] = 'title_not_set';
$correct = false;
}
- if(!in_array($this->get_content_type(), array(BLOCK_TYPE_LIST, BLOCK_TYPE_TEXT))) {
+ if(!in_array($this->get_content_type(), array(BLOCK_TYPE_LIST, BLOCK_TYPE_TEXT, BLOCK_TYPE_NUKE))) {
$errors[] = 'invalid_content_type';
$correct = false;
}
}
}
+class MoodleBlock_Nuke extends MoodleBlock {
+ function get_content() {
+
+ // This whole thing begs to be written for PHP >= 4.3.0
+ // using glob();
+
+ global $CFG;
+ $dir = $CFG->dirroot.'/blocks/'.$this->name().'/nuke/';
+ if($dh = @opendir($dir)) {
+ while (($file = readdir($dh)) !== false) {
+ $regs = array();
+ if(ereg('^block\-(.*)\.php$', $file, $regs)) {
+ $old = $_SERVER['PHP_SELF'];
+ $_SERVER['PHP_SELF'] = 'index.php';
+
+ // Do our best to suppress any spurious output
+ ob_start();
+ @include($dir.$file);
+ ob_end_clean();
+
+ // We should have $content set now
+ $_SERVER['PHP_SELF'] = $old;
+ if(!isset($content)) {
+ return NULL;
+ }
+ return $this->content->text = $content;
+ }
+ }
+ }
+ else {
+ // nuke subdirectory does not exist
+ }
+ }
+}
+
?>
error("No blocks installed!");
}
- @include_once($CFG->dirroot."/blocks/moodleblock.class.php");
+ include_once($CFG->dirroot."/blocks/moodleblock.class.php");
if(!class_exists('moodleblock')) {
error('Class MoodleBlock is not defined or file not found for /blocks/moodleblock.class.php');
}
continue;
}
- if ( is_readable("$fullblock/db/$CFG->dbtype.php")) {
- include_once("$fullblock/db/$CFG->dbtype.php"); # defines upgrading function
- } else {
- $notices[] ="Block $blockname: $fullblock/db/$CFG->dbtype.php was not readable";
- continue;
+ if ( is_dir("$fullblock/db/")) {
+ if ( is_readable("$fullblock/db/$CFG->dbtype.php")) {
+ include_once("$fullblock/db/$CFG->dbtype.php"); # defines upgrading function
+ } else {
+ $notices[] ="Block $blockname: $fullblock/db/$CFG->dbtype.php was not readable";
+ continue;
+ }
}
$classname = 'CourseBlock_'.$blockname;
$updated_blocks = true;
$db->debug = true;
set_time_limit(0); // To allow slow databases to complete the long SQL
- if (modify_database("$fullblock/db/$CFG->dbtype.sql")) {
+ if (!is_dir("$fullblock/db/") || modify_database("$fullblock/db/$CFG->dbtype.sql")) {
$db->debug = false;
if ($block->id = insert_record('blocks', $block)) {
notify(get_string('blocksuccess', '', $blocktitle), 'green');