diff --git a/blocks/site_main_menu/block_site_main_menu.php b/blocks/site_main_menu/block_site_main_menu.php index d4374bc122f..bc4420cb6fe 100644 --- a/blocks/site_main_menu/block_site_main_menu.php +++ b/blocks/site_main_menu/block_site_main_menu.php @@ -41,8 +41,8 @@ class block_site_main_menu extends block_list { continue; } - list($content, $instancename) = - get_print_section_cm_text($cm, $course); + $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)); + $instancename = $cm->get_formatted_name(); if (!($url = $cm->get_url())) { $this->content->items[] = $content; @@ -60,14 +60,12 @@ class block_site_main_menu extends block_list { } /// slow & hacky editing mode + $courserenderer = $this->page->get_renderer('core', 'course'); $ismoving = ismoving($course->id); course_create_sections_if_missing($course, 0); $modinfo = get_fast_modinfo($course); $section = $modinfo->get_section_info(0); - $groupbuttons = $course->groupmode; - $groupbuttonslink = (!$course->groupmodeforce); - if ($ismoving) { $strmovehere = get_string('movehere'); $strmovefull = strip_tags(get_string('movefull', '', "'$USER->activitycopyname'")); @@ -90,15 +88,10 @@ class block_site_main_menu extends block_list { continue; } if (!$ismoving) { - if ($groupbuttons) { - if (! $mod->groupmodelink = $groupbuttonslink) { - $mod->groupmode = $course->groupmode; - } - - } else { - $mod->groupmode = false; - } - $editbuttons = '
'.make_editing_buttons($mod, true, true).'
'; + $actions = course_get_cm_edit_actions($mod, -1); + $editbuttons = html_writer::tag('div', + $courserenderer->course_section_cm_edit_actions($actions), + array('class' => 'buttons')); } else { $editbuttons = ''; } @@ -111,8 +104,8 @@ class block_site_main_menu extends block_list { ''.$strmovehere.''; $this->content->icons[] = ''; } - list($content, $instancename) = - get_print_section_cm_text($modinfo->cms[$modnumber], $course); + $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)); + $instancename = $mod->get_formatted_name(); $linkcss = $mod->visible ? '' : ' class="dimmed" '; if (!($url = $mod->get_url())) { @@ -134,7 +127,8 @@ class block_site_main_menu extends block_list { $this->content->icons[] = ''; } - $this->content->footer = print_section_add_menus($course, 0, null, true, true); + $this->content->footer = $courserenderer->course_section_add_cm_control($course, + 0, null, array('inblock' => true)); return $this->content; } diff --git a/blocks/social_activities/block_social_activities.php b/blocks/social_activities/block_social_activities.php index b98f44f9788..5e394e048b9 100644 --- a/blocks/social_activities/block_social_activities.php +++ b/blocks/social_activities/block_social_activities.php @@ -43,8 +43,8 @@ class block_social_activities extends block_list { continue; } - list($content, $instancename) = - get_print_section_cm_text($cm, $course); + $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)); + $instancename = $cm->get_formatted_name(); if (!($url = $cm->get_url())) { $this->content->items[] = $content; @@ -63,13 +63,11 @@ class block_social_activities extends block_list { /// slow & hacky editing mode + $courserenderer = $this->page->get_renderer('core', 'course'); $ismoving = ismoving($course->id); $modinfo = get_fast_modinfo($course); $section = $modinfo->get_section_info(0); - $groupbuttons = $course->groupmode; - $groupbuttonslink = (!$course->groupmodeforce); - if ($ismoving) { $strmovehere = get_string('movehere'); $strmovefull = strip_tags(get_string('movefull', '', "'$USER->activitycopyname'")); @@ -92,15 +90,9 @@ class block_social_activities extends block_list { continue; } if (!$ismoving) { - if ($groupbuttons) { - if (! $mod->groupmodelink = $groupbuttonslink) { - $mod->groupmode = $course->groupmode; - } - - } else { - $mod->groupmode = false; - } - $editbuttons = '
'.make_editing_buttons($mod, true, true); + $actions = course_get_cm_edit_actions($mod, -1); + $editbuttons = '
'. + $courserenderer->course_section_cm_edit_actions($actions); } else { $editbuttons = ''; } @@ -113,8 +105,8 @@ class block_social_activities extends block_list { ''.$strmovehere.''; $this->content->icons[] = ''; } - list($content, $instancename) = - get_print_section_cm_text($modinfo->cms[$modnumber], $course); + $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)); + $instancename = $mod->get_formatted_name(); $linkcss = $mod->visible ? '' : ' class="dimmed" '; @@ -137,7 +129,8 @@ class block_social_activities extends block_list { $this->content->icons[] = ''; } - $this->content->footer = print_section_add_menus($course, 0, null, true, true); + $this->content->footer = $courserenderer->course_section_add_cm_control($course, + 0, null, array('inblock' => true)); return $this->content; } diff --git a/course/dndupload.php b/course/dndupload.php index c4df5a8c2b8..797e6883f8e 100644 --- a/course/dndupload.php +++ b/course/dndupload.php @@ -35,5 +35,7 @@ $modulename = required_param('module', PARAM_PLUGIN); $displayname = optional_param('displayname', null, PARAM_TEXT); $contents = optional_param('contents', null, PARAM_RAW); // It will be up to each plugin to clean this data, before saving it. +$PAGE->set_url('/course/dndupload.php'); + $dndproc = new dndupload_ajax_processor($courseid, $section, $type, $modulename); $dndproc->process($displayname, $contents); diff --git a/course/dnduploadlib.php b/course/dnduploadlib.php index 26e41e8b265..ecb519bbabc 100644 --- a/course/dnduploadlib.php +++ b/course/dnduploadlib.php @@ -671,7 +671,8 @@ class dndupload_ajax_processor { * @param cm_info $mod details of the mod just created */ protected function send_response($mod) { - global $OUTPUT; + global $OUTPUT, $PAGE; + $courserenderer = $PAGE->get_renderer('core', 'course'); $resp = new stdClass(); $resp->error = self::ERROR_OK; @@ -679,7 +680,8 @@ class dndupload_ajax_processor { $resp->name = $mod->name; $resp->link = $mod->get_url()->out(); $resp->elementid = 'module-'.$mod->id; - $resp->commands = make_editing_buttons($mod, true, true, 0, $mod->sectionnum); + $actions = course_get_cm_edit_actions($mod, 0, $mod->sectionnum); + $resp->commands = ' '. $courserenderer->course_section_cm_edit_actions($actions); $resp->onclick = $mod->get_on_click(); $resp->visible = $mod->visible; diff --git a/course/externallib.php b/course/externallib.php index b5c82f469a3..3476dccb72f 100644 --- a/course/externallib.php +++ b/course/externallib.php @@ -125,7 +125,7 @@ class core_course_external extends external_api { $sectioncontents = array(); //for each module of the section - foreach ($modinfo->sections[$section->section] as $cmid) { //matching /course/lib.php:print_section() logic + foreach ($modinfo->sections[$section->section] as $cmid) { $cm = $modinfo->cms[$cmid]; // stop here if the module is not visible to the user diff --git a/course/format/renderer.php b/course/format/renderer.php index ceb3045c542..d9a7edc37a7 100644 --- a/course/format/renderer.php +++ b/course/format/renderer.php @@ -38,6 +38,20 @@ defined('MOODLE_INTERNAL') || die(); */ abstract class format_section_renderer_base extends plugin_renderer_base { + /** @var contains instance of core course renderer */ + protected $courserenderer; + + /** + * Constructor method, calls the parent constructor + * + * @param moodle_page $page + * @param string $target one of rendering target constants + */ + public function __construct(moodle_page $page, $target) { + parent::__construct($page, $target); + $this->courserenderer = $this->page->get_renderer('core', 'course'); + } + /** * Generate the starting container html for a list of sections * @return string HTML to output. @@ -587,10 +601,8 @@ abstract class format_section_renderer_base extends plugin_renderer_base { if ($thissection->summary or !empty($modinfo->sections[0]) or $PAGE->user_is_editing()) { echo $this->start_section_list(); echo $this->section_header($thissection, $course, true, $displaysection); - print_section($course, $thissection, null, null, true, "100%", false, $displaysection); - if ($PAGE->user_is_editing()) { - print_section_add_menus($course, 0, null, false, false, $displaysection); - } + echo $this->courserenderer->course_section_cm_list($course, $thissection, $displaysection); + echo $this->courserenderer->course_section_add_cm_control($course, 0, $displaysection); echo $this->section_footer(); echo $this->end_section_list(); } @@ -624,10 +636,8 @@ abstract class format_section_renderer_base extends plugin_renderer_base { $completioninfo = new completion_info($course); echo $completioninfo->display_help_icon(); - print_section($course, $thissection, null, null, true, '100%', false, $displaysection); - if ($PAGE->user_is_editing()) { - print_section_add_menus($course, $displaysection, null, false, false, $displaysection); - } + echo $this->courserenderer->course_section_cm_list($course, $thissection, $displaysection); + echo $this->courserenderer->course_section_add_cm_control($course, $displaysection, $displaysection); echo $this->section_footer(); echo $this->end_section_list(); @@ -677,10 +687,8 @@ abstract class format_section_renderer_base extends plugin_renderer_base { // 0-section is displayed a little different then the others if ($thissection->summary or !empty($modinfo->sections[0]) or $PAGE->user_is_editing()) { echo $this->section_header($thissection, $course, false, 0); - print_section($course, $thissection, null, null, true, "100%", false, 0); - if ($PAGE->user_is_editing()) { - print_section_add_menus($course, 0, null, false, false, 0); - } + echo $this->courserenderer->course_section_cm_list($course, $thissection); + echo $this->courserenderer->course_section_add_cm_control($course, 0); echo $this->section_footer(); } continue; @@ -710,10 +718,8 @@ abstract class format_section_renderer_base extends plugin_renderer_base { } else { echo $this->section_header($thissection, $course, false, 0); if ($thissection->uservisible) { - print_section($course, $thissection, null, null, true, "100%", false, 0); - if ($PAGE->user_is_editing()) { - print_section_add_menus($course, $section, null, false, false, 0); - } + echo $this->courserenderer->course_section_cm_list($course, $thissection); + echo $this->courserenderer->course_section_add_cm_control($course, $section); } echo $this->section_footer(); } @@ -727,7 +733,7 @@ abstract class format_section_renderer_base extends plugin_renderer_base { continue; } echo $this->stealth_section_header($section); - print_section($course, $thissection, null, null, true, "100%", false, 0); + echo $this->courserenderer->course_section_cm_list($course, $thissection); echo $this->stealth_section_footer(); } diff --git a/course/jumpto.php b/course/jumpto.php index c4d11ef7e11..98c4e49f794 100644 --- a/course/jumpto.php +++ b/course/jumpto.php @@ -34,7 +34,7 @@ if (!confirm_sesskey()) { print_error('confirmsesskeybad'); } -if (strpos($jump, '/') === 0) { +if (strpos($jump, '/') === 0 || strpos($jump, $CFG->wwwroot) === 0) { redirect(new moodle_url($jump)); } else { print_error('error'); diff --git a/course/lib.php b/course/lib.php index 52302409346..a7fc7cf7b66 100644 --- a/course/lib.php +++ b/course/lib.php @@ -1301,576 +1301,6 @@ function set_section_visible($courseid, $sectionnumber, $visibility) { return $resourcestotoggle; } -/** - * Obtains shared data that is used in print_section when displaying a - * course-module entry. - * - * Calls format_text or format_string as appropriate, and obtains the correct icon. - * - * This data is also used in other areas of the code. - * @param cm_info $cm Course-module data (must come from get_fast_modinfo) - * @param object $course Moodle course object - * @return array An array with the following values in this order: - * $content (optional extra content for after link), - * $instancename (text of link) - */ -function get_print_section_cm_text(cm_info $cm, $course) { - global $OUTPUT; - - // Get content from modinfo if specified. Content displays either - // in addition to the standard link (below), or replaces it if - // the link is turned off by setting ->url to null. - if (($content = $cm->get_content()) !== '') { - // Improve filter performance by preloading filter setttings for all - // activities on the course (this does nothing if called multiple - // times) - filter_preload_activities($cm->get_modinfo()); - - // Get module context - $modulecontext = context_module::instance($cm->id); - $labelformatoptions = new stdClass(); - $labelformatoptions->noclean = true; - $labelformatoptions->overflowdiv = true; - $labelformatoptions->context = $modulecontext; - $content = format_text($content, FORMAT_HTML, $labelformatoptions); - } else { - $content = ''; - } - - // Get course context - $coursecontext = context_course::instance($course->id); - $stringoptions = new stdClass; - $stringoptions->context = $coursecontext; - $instancename = format_string($cm->name, true, $stringoptions); - return array($content, $instancename); -} - -/** - * Prints a section full of activity modules - * - * @param stdClass $course The course - * @param stdClass|section_info $section The section object containing properties id and section - * @param array $mods (argument not used) - * @param array $modnamesused (argument not used) - * @param bool $absolute All links are absolute - * @param string $width Width of the container - * @param bool $hidecompletion Hide completion status - * @param int $sectionreturn The section to return to - * @return void - */ -function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false, $sectionreturn=null) { - global $CFG, $USER, $DB, $PAGE, $OUTPUT; - - static $initialised; - - static $groupbuttons; - static $groupbuttonslink; - static $isediting; - static $ismoving; - static $strmovehere; - static $strmovefull; - static $strunreadpostsone; - - if (!isset($initialised)) { - $groupbuttons = ($course->groupmode or (!$course->groupmodeforce)); - $groupbuttonslink = (!$course->groupmodeforce); - $isediting = $PAGE->user_is_editing(); - $ismoving = $isediting && ismoving($course->id); - if ($ismoving) { - $strmovehere = get_string("movehere"); - $strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'")); - } - $initialised = true; - } - - $modinfo = get_fast_modinfo($course); - $completioninfo = new completion_info($course); - - //Accessibility: replace table with list