From 828c4e095a6a95734627a5a415e2464122838c4d Mon Sep 17 00:00:00 2001 From: defacer Date: Tue, 11 May 2004 16:08:03 +0000 Subject: [PATCH] Preparation for Nuke blocks integration, and relaxing of requirements for block db upgrade scripts. We 're getting to a point where you can really have a directory with just a single 20-line file for your block and Moodle will do all the rest. Much like Nuke does now. That is A Good Thing! :-) --- blocks/moodleblock.class.php | 39 +++++++++++++++++++++++++++++++++++- lib/blocklib.php | 16 ++++++++------- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/blocks/moodleblock.class.php b/blocks/moodleblock.class.php index c8fbd13f25..0f66e24d13 100644 --- a/blocks/moodleblock.class.php +++ b/blocks/moodleblock.class.php @@ -2,6 +2,7 @@ define('BLOCK_TYPE_LIST', 1); define('BLOCK_TYPE_TEXT', 2); +define('BLOCK_TYPE_NUKE', 3); class MoodleBlock { var $str; @@ -59,6 +60,7 @@ class MoodleBlock { $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; @@ -162,7 +164,7 @@ class MoodleBlock { $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; } @@ -212,4 +214,39 @@ class MoodleBlock { } } +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 + } + } +} + ?> diff --git a/lib/blocklib.php b/lib/blocklib.php index 29f1c54c89..ad66a8ed43 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -419,7 +419,7 @@ function upgrade_blocks_plugins($continueto) { 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'); } @@ -439,11 +439,13 @@ function upgrade_blocks_plugins($continueto) { 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; @@ -536,7 +538,7 @@ function upgrade_blocks_plugins($continueto) { $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'); -- 2.39.5