From da71112bed537b092a6ac3f79500369dcd66e7e7 Mon Sep 17 00:00:00 2001 From: defacer Date: Tue, 1 Feb 2005 06:24:28 +0000 Subject: [PATCH] Refining the way that blocks work: now you don't have to know anything about what editing the blocks adds to your URL. blocklib will take care of that internally. --- course/view.php | 13 ++----------- lib/blocklib.php | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/course/view.php b/course/view.php index 759b637472..b77102b314 100644 --- a/course/view.php +++ b/course/view.php @@ -9,8 +9,6 @@ $id = optional_param('id', 0, PARAM_INT); $name = optional_param('name'); $blockaction = optional_param('blockaction'); - $instanceid = optional_param('instanceid', 0, PARAM_INT); - $blockid = optional_param('blockid', 0, PARAM_INT); if (empty($id) && empty($name)) { error("Must specify course id or short name"); @@ -65,15 +63,8 @@ set_section_visible($course->id, $show, '1'); } - if (!empty($blockaction) && confirm_sesskey()) { - if (!empty($blockid)) { - blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), intval($blockid)); - - } - else if (!empty($instanceid)) { - $instance = blocks_find_instance($instanceid, $pageblocks); - blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance); - } + if (!empty($blockaction)) { + blocks_execute_url_action($PAGE, $pageblocks); // This re-query could be eliminated by judicious programming in blocks_execute_action(), // but I 'm not sure if it's worth the complexity increase... $pageblocks = blocks_get_by_page($PAGE); diff --git a/lib/blocklib.php b/lib/blocklib.php index 3938d9b716..ea0201bb92 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -478,6 +478,27 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid) redirect($page->url_get_full()); } +// You can use this to get the blocks to respond to URL actions without much hassle +function blocks_execute_url_action(&$PAGE, &$pageblocks) { + $blockaction = optional_param('blockaction'); + + if (empty($blockaction) || !confirm_sesskey()) { + return; + } + + $instanceid = optional_param('instanceid', 0, PARAM_INT); + $blockid = optional_param('blockid', 0, PARAM_INT); + + if (!empty($blockid)) { + blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $blockid); + + } + else if (!empty($instanceid)) { + $instance = blocks_find_instance($instanceid, $pageblocks); + blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance); + } +} + // This shouldn't be used externally at all, it's here for use by blocks_execute_action() // in order to reduce code repetition. function blocks_execute_repositioning(&$instance, $newpos, $newweight) { -- 2.39.5