From: skodak Date: Thu, 13 Aug 2009 20:49:07 +0000 (+0000) Subject: MDL-20068 new Page module, includes migrate from old mod/resource; remaining issues... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=1ad9ff57ffa447bbb51ad43c0c0f492b6d1166d6;p=moodle.git MDL-20068 new Page module, includes migrate from old mod/resource; remaining issues to be listed in tracker as sub-tasks --- diff --git a/lang/en_utf8/page.php b/lang/en_utf8/page.php new file mode 100644 index 0000000000..983c7c1b26 --- /dev/null +++ b/lang/en_utf8/page.php @@ -0,0 +1,24 @@ +. + +/** + * Page module capability definition + * + * @package mod-page + * @copyright 2009 Petr Skoda (http://skodak.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$mod_page_capabilities = array( +/* TODO: review public portfolio API first! + 'mod/page:portfolioexport' => array( + + 'captype' => 'read', + 'contextlevel' => CONTEXT_MODULE, + 'legacy' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + ) + ), +*/ +); diff --git a/mod/page/db/install.php b/mod/page/db/install.php new file mode 100644 index 0000000000..15a37f932e --- /dev/null +++ b/mod/page/db/install.php @@ -0,0 +1,53 @@ +. + +/** + * Page module post install function + * + * This file replaces: + * - STATEMENTS section in db/install.xml + * - lib.php/modulename_install() post installation hook + * - partially defaults.php + * + * @package mod-page + * @copyright 2009 Petr Skoda (http://skodak.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +function xmldb_page_install() { + global $CFG; + + // Install logging support + update_log_display_entry('page', 'view', 'page', 'name'); + update_log_display_entry('page', 'view all', 'page', 'name'); + update_log_display_entry('page', 'update', 'page', 'name'); + update_log_display_entry('page', 'add', 'page', 'name'); + + // Upgrade from old resource module type if needed + require_once("$CFG->dirroot/mod/page/db/upgradelib.php"); + page_20_migrate(); + +} + +function xmldb_page_install_recovery() { + global $CFG; + + // Upgrade from old resource module type if needed + require_once("$CFG->dirroot/mod/page/db/upgradelib.php"); + page_20_migrate(); + +} diff --git a/mod/page/db/install.xml b/mod/page/db/install.xml new file mode 100644 index 0000000000..14ee007e6c --- /dev/null +++ b/mod/page/db/install.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
\ No newline at end of file diff --git a/mod/page/db/upgrade.php b/mod/page/db/upgrade.php new file mode 100644 index 0000000000..2235e05b4f --- /dev/null +++ b/mod/page/db/upgrade.php @@ -0,0 +1,55 @@ +. + +/** + * Page module upgrade code + * + * This file keeps track of upgrades to + * the resource module + * + * Sometimes, changes between versions involve + * alterations to database structures and other + * major things that may break installations. + * + * The upgrade function in this file will attempt + * to perform all the necessary actions to upgrade + * your older installtion to the current version. + * + * If there's something it cannot do itself, it + * will tell you what you need to do. + * + * The commands in here will all be database-neutral, + * using the methods of database_manager class + * + * Please do not forget to use upgrade_set_timeout() + * before any action that may take longer time to finish. + * + * @package mod-page + * @copyright 2009 Petr Skoda (http://skodak.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +function xmldb_page_upgrade($oldversion) { + global $CFG, $DB; + require_once("$CFG->dirroot/mod/page/db/upgradelib.php"); + + $dbman = $DB->get_manager(); + $result = true; + + + return $result; +} diff --git a/mod/page/db/upgradelib.php b/mod/page/db/upgradelib.php new file mode 100644 index 0000000000..8ad91a9f64 --- /dev/null +++ b/mod/page/db/upgradelib.php @@ -0,0 +1,133 @@ +. + +/** + * Folder module upgrade related helper functions + * + * @package mod-page + * @copyright 2009 Petr Skoda (http://skodak.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * Migrate page module data from 1.9 resource_old table to new page table + * @return void + */ +function page_20_migrate() { + global $CFG, $DB; + require_once("$CFG->libdir/filelib.php"); + require_once("$CFG->libdir/resourcelib.php"); + require_once("$CFG->dirroot/course/lib.php"); + + if (!file_exists("$CFG->dirroot/mod/resource/db/upgradelib.php")) { + // bad luck, somebody deleted resource module + return; + } + + require_once("$CFG->dirroot/mod/resource/db/upgradelib.php"); + + // create resource_old table and copy resource table there if needed + if (!resource_20_prepare_migration()) { + // no modules or fresh install + return; + } + + $fs = get_file_storage(); + + if ($candidates = $DB->get_recordset('resource_old', array('type'=>'html', 'migrated'=>0))) { + foreach ($candidates as $candidate) { + page_20_migrate_candidate($candidate, $fs, FORMAT_HTML); + } + $candidates->close(); + } + + if ($candidates = $DB->get_recordset('resource_old', array('type'=>'text', 'migrated'=>0))) { + foreach ($candidates as $candidate) { + page_20_migrate_candidate($candidate, $fs, $candidate->reference); + } + $candidates->close(); + } + + // clear all course modinfo caches + rebuild_course_cache(0, true); + +} + +function page_20_migrate_candidate($candidate, $fs, $format) { + global $CFG, $DB; + upgrade_set_timeout(); + + $page = new object(); + $page->course = $candidate->course; + $page->name = $candidate->name; + $page->intro = $candidate->intro; + $page->introformat = $candidate->introformat; + $page->content = $candidate->alltext; + $page->contentformat = $format; + $page->revision = 1; + $page->timemodified = time(); + + // convert links to old course files - let the automigration do the actual job + $usedfiles = array("$CFG->wwwroot/file.php/$page->course/", "$CFG->wwwroot/file.php?file=/$page->course/"); + $page->content = str_ireplace($usedfiles, '@@PLUGINFILE@@/', $page->content); + if (strpos($page->content, '@@PLUGINFILE@@/') === false) { + $page->legacyfiles = RESOURCELIB_LEGACYFILES_NO; + } else { + $page->legacyfiles = RESOURCELIB_LEGACYFILES_ACTIVE; + } + + $options = array('printheading'=>0, 'printintro'=>0); + if ($candidate->popup) { + $page->display = RESOURCELIB_DISPLAY_POPUP; + if ($candidate->popup) { + $rawoptions = explode(',', $candidate->popup); + foreach ($rawoptions as $rawoption) { + list($name, $value) = explode('=', trim($rawoption), 2); + if ($value > 0 and ($name == 'width' or $name == 'height')) { + $options['popup'.$name] = $value; + continue; + } + } + } + } else { + $page->display = RESOURCELIB_DISPLAY_OPEN; + } + $page->displayoptions = serialize($options); + + $page = resource_migrate_to_module('page', $candidate, $page); + + // now try to migrate files from site files + // noite: this can not work for html pages or files with other relatively linked files :-( + $siteid = get_site()->id; + if (preg_match_all("|$CFG->wwwroot/file.php(\?file=)?/$siteid(/[^\s'\"&\?#]+)|", $page->content, $matches)) { + $context = get_context_instance(CONTEXT_MODULE, $candidate->cmid); + $sitecontext = get_context_instance(CONTEXT_COURSE, $siteid); + $file_record = array('contextid'=>$context->id, 'filearea'=>'page_content', 'itemid'=>0); + $fs = get_file_storage(); + foreach ($matches[2] as $i=>$sitefile) { + if (!$file = $fs->get_file_by_hash(sha1($sitecontext->id.'course_content0'.$sitefile))) { + continue; + } + try { + $fs->create_file_from_storedfile($file_record, $file); + $page->content = str_replace($matches[0][$i], '@@PLUGINFILE@@'.$sitefile, $page->content); + } catch (Exception $x) { + } + } + $DB->update_record('page', $page); + } +} diff --git a/mod/page/icon.gif b/mod/page/icon.gif new file mode 100644 index 0000000000..745ef3462c Binary files /dev/null and b/mod/page/icon.gif differ diff --git a/mod/page/index.php b/mod/page/index.php new file mode 100644 index 0000000000..081c9a8c31 --- /dev/null +++ b/mod/page/index.php @@ -0,0 +1,98 @@ +. + +/** + * List of all pages in course + * + * @package mod-page + * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require('../../config.php'); + +$id = required_param('id', PARAM_INT); // course id + +$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); + +require_course_login($course, true); + +add_to_log($course->id, 'page', 'view all', "index.php?id=$course->id", ''); + +$strpage = get_string('modulename', 'page'); +$strpages = get_string('modulenameplural', 'page'); +$strweek = get_string('week'); +$strtopic = get_string('topic'); +$strname = get_string('name'); +$strintro = get_string('moduleintro'); +$strlastmodified = get_string('lastmodified'); + +$PAGE->set_url('mod/page/index.php', array('id' => $course->id)); +$PAGE->set_title($course->shortname.': '.$strpages); +$PAGE->set_heading($course->fullname); +$navlinks = array(array('name' => $strpages, 'link' => '', 'type' => 'activityinstance')); +echo $OUTPUT->header(build_navigation($navlinks), navmenu($course)); + +if (!$pages = get_all_instances_in_course('page', $course)) { + notice(get_string('thereareno', 'moodle', $strpages), "$CFG->wwwroot/course/view.php?id=$course->id"); + exit; +} + +$table = new html_table(); +$table->set_classes(array('generaltable', 'mod_index')); + +if ($course->format == 'weeks') { + $table->head = array ($strweek, $strname, $strintro); + $table->align = array ('center', 'left', 'left'); +} else if ($course->format == 'topics') { + $table->head = array ($strtopic, $strname, $strintro); + $table->align = array ('center', 'left', 'left'); +} else { + $table->head = array ($strlastmodified, $strname, $strintro); + $table->align = array ('left', 'left', 'left'); +} + +$modinfo = get_fast_modinfo($course); +$currentsection = ''; +foreach ($pages as $page) { + $cm = $modinfo->cms[$page->coursemodule]; + if ($course->format == 'weeks' or $course->format == 'topics') { + $printsection = ''; + if ($page->section !== $currentsection) { + if ($page->section) { + $printsection = $page->section; + } + if ($currentsection !== '') { + $table->data[] = 'hr'; + } + $currentsection = $page->section; + } + } else { + $printsection = ''.userdate($page->timemodified).""; + } + + $class = $page->visible ? '' : 'class="dimmed"'; // hidden modules are dimmed + + $table->data[] = array ( + $printsection, + "id\">".format_string($page->name)."", + format_module_intro('page', $page, $cm->id)); +} + +echo $OUTPUT->table($table); + +echo $OUTPUT->footer(); diff --git a/mod/page/lib.php b/mod/page/lib.php new file mode 100644 index 0000000000..01fb5a6889 --- /dev/null +++ b/mod/page/lib.php @@ -0,0 +1,380 @@ +. + +/** + * @package mod-page + * @copyright 2009 Petr Skoda (http://skodak.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * List of features supported in Page module + * @param string $feature FEATURE_xx constant for requested feature + * @return mixed True if module supports feature, false if not, null if doesn't know + */ +function page_supports($feature) { + switch($feature) { + case FEATURE_MOD_ARCHETYPE: return MOD_ARCHETYPE_RESOURCE; + case FEATURE_GROUPS: return false; + case FEATURE_GROUPINGS: return false; + case FEATURE_GROUPMEMBERSONLY: return true; + case FEATURE_MOD_INTRO: return true; + case FEATURE_COMPLETION_TRACKS_VIEWS: return true; + case FEATURE_GRADE_HAS_GRADE: return false; + case FEATURE_GRADE_OUTCOMES: return false; + + default: return null; + } +} + +/** + * Returns all other caps used in module + * @return array + */ +function page_get_extra_capabilities() { + return array('moodle/site:accessallgroups'); +} + +/** + * This function is used by the reset_course_userdata function in moodlelib. + * @param $data the data submitted from the reset course. + * @return array status array + */ +function page_reset_userdata($data) { + return array(); +} + +/** + * List of view style log actions + * @return array + */ +function page_get_view_actions() { + return array('view','view all'); +} + +/** + * List of update style log actions + * @return array + */ +function page_get_post_actions() { + return array('update', 'add'); +} + +/** + * Add page instance. + * @param object $data + * @param object $mform + * @return int new resoruce instance id + */ +function page_add_instance($data, $mform) { + global $CFG, $DB; + require_once("$CFG->libdir/resourcelib.php"); + + $cmid = $data->coursemodule; + $draftitemid = $data->page['itemid']; + + $data->timemodified = time(); + $displayoptions = array(); + if ($data->display == RESOURCELIB_DISPLAY_POPUP) { + $displayoptions['popupwidth'] = $data->popupwidth; + $displayoptions['popupheight'] = $data->popupheight; + } + $displayoptions['printheading'] = $data->printheading; + $displayoptions['printintro'] = $data->printintro; + $data->displayoptions = serialize($displayoptions); + + $data->content = $data->page['text']; + $data->contentformat = $data->page['format']; + + $data->id = $DB->insert_record('page', $data); + + // we need to use context now, so we need to make sure all needed info is already in db + $DB->set_field('course_modules', 'instance', $data->id, array('id'=>$cmid)); + $context = get_context_instance(CONTEXT_MODULE, $cmid); + + if ($draftitemid) { + $data->content = file_save_draft_area_files($draftitemid, $context->id, 'page_content', 0, page_get_editor_options($context), $data->content); + $DB->update_record('page', $data); + } + + return $data->id; +} + +/** + * Update page instance. + * @param object $data + * @param object $mform + * @return bool true + */ +function page_update_instance($data, $mform) { + global $CFG, $DB; + require_once("$CFG->libdir/resourcelib.php"); + + $cmid = $data->coursemodule; + $draftitemid = $data->page['itemid']; + + $data->timemodified = time(); + $data->id = $data->instance; + $data->revision++; + + $displayoptions = array(); + if ($data->display == RESOURCELIB_DISPLAY_POPUP) { + $displayoptions['popupwidth'] = $data->popupwidth; + $displayoptions['popupheight'] = $data->popupheight; + } + $displayoptions['printheading'] = $data->printheading; + $displayoptions['printintro'] = $data->printintro; + $data->displayoptions = serialize($displayoptions); + + $data->content = $data->page['text']; + $data->contentformat = $data->page['format']; + + $DB->update_record('page', $data); + + $context = get_context_instance(CONTEXT_MODULE, $cmid); + if ($draftitemid) { + $data->content = file_save_draft_area_files($draftitemid, $context->id, 'page_content', 0, page_get_editor_options($context), $data->content); + $DB->update_record('page', $data); + } + + return true; +} + +/** + * Delete page instance. + * @param int $id + * @return bool true + */ +function page_delete_instance($id) { + global $DB; + + if (!$page = $DB->get_record('page', array('id'=>$id))) { + return false; + } + + // note: all context files are deleted automatically + + $DB->delete_records('page', array('id'=>$page->id)); + + return true; +} + +/** + * Return use outline + * @param object $course + * @param object $user + * @param object $mod + * @param object $page + * @return object|null + */ +function page_user_outline($course, $user, $mod, $page) { + global $DB; + + if ($logs = $DB->get_records('log', array('userid'=>$user->id, 'module'=>'page', + 'action'=>'view', 'info'=>$page->id), 'time ASC')) { + + $numviews = count($logs); + $lastlog = array_pop($logs); + + $result = new object(); + $result->info = get_string('numviews', '', $numviews); + $result->time = $lastlog->time; + + return $result; + } + return NULL; +} + +/** + * Return use complete + * @param object $course + * @param object $user + * @param object $mod + * @param object $page + */ +function page_user_complete($course, $user, $mod, $page) { + global $CFG, $DB; + + if ($logs = $DB->get_records('log', array('userid'=>$user->id, 'module'=>'page', + 'action'=>'view', 'info'=>$page->id), 'time ASC')) { + $numviews = count($logs); + $lastlog = array_pop($logs); + + $strmostrecently = get_string('mostrecently'); + $strnumviews = get_string('numviews', '', $numviews); + + echo "$strnumviews - $strmostrecently ".userdate($lastlog->time); + + } else { + print_string('neverseen', 'page'); + } +} + +/** + * Returns the users with data in one page + * + * @param int $pageid + * @return bool false + */ +function page_get_participants($pageid) { + return false; +} + +/** + * Given a course_module object, this function returns any + * "extra" information that may be needed when printing + * this activity in a course listing. + * + * See {@link get_array_of_activities()} in course/lib.php + * + * @param object $coursemodule + * @return object info + */ +function page_get_coursemodule_info($coursemodule) { + global $CFG, $DB; + require_once("$CFG->libdir/resourcelib.php"); + + if (!$page = $DB->get_record('page', array('id'=>$coursemodule->instance), 'id, name, display, displayoptions')) { + return NULL; + } + + if ($page->display != RESOURCELIB_DISPLAY_POPUP) { + return null; + } + + $info = new object(); + $info->name = $page->name; + + $fullurl = "$CFG->wwwroot/mod/page/view.php?id=$coursemodule->id&inpopup=1"; + $options = empty($page->displayoptions) ? array() : unserialize($page->displayoptions); + $width = empty($options['popupwidth']) ? 620 : $options['popupwidth']; + $height = empty($options['popupheight']) ? 450 : $options['popupheight']; + $wh = "width=$width,height=$height,toolbar=no,location=no,menubar=no,copyhistory=no,status=no,directories=no,scrollbars=yes,resizable=yes"; + $info->extra = urlencode("onclick=\"window.open('$fullurl', '', '$wh'); return false;\""); + + return $info; +} + + +/** + * Lists all browsable file areas + * @param object $course + * @param object $cm + * @param object $context + * @return array + */ +function page_get_file_areas($course, $cm, $context) { + $areas = array(); + if (has_capability('moodle/course:managefiles', $context)) { + $areas['page_content'] = get_string('pagecontent', 'page'); + } + return $areas; +} + +/** + * File browsing support for page module ontent area. + * @param object $browser + * @param object $areas + * @param object $course + * @param object $cm + * @param object $context + * @param string $filearea + * @param int $itemid + * @param string $filepath + * @param string $filename + * @return object file_info instance or null if not found + */ +function page_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) { + global $CFG; + + $canwrite = has_capability('moodle/course:managefiles', $context); + + $fs = get_file_storage(); + + if ($filearea === 'page_content') { + $filepath = is_null($filepath) ? '/' : $filepath; + $filename = is_null($filename) ? '.' : $filename; + + $urlbase = $CFG->wwwroot.'/pluginfile.php'; + if (!$storedfile = $fs->get_file($context->id, $filearea, 0, $filepath, $filename)) { + if ($filepath === '/' and $filename === '.') { + $storedfile = new virtual_root_file($context->id, $filearea, 0); + } else { + // not found + return null; + } + } + require_once("$CFG->dirroot/mod/page/locallib.php"); + return new page_content_file_info($browser, $context, $storedfile, $urlbase, $areas[$filearea], true, true, $canwrite, false); + } + + // note: page_intro handled in file_browser automatically + + return null; +} + +/** + * Serves the page files. + * @param object $course + * @param object $cminfo + * @param object $context + * @param string $filearea + * @param array $args + * @param bool $forcedownload + * @return bool false if file not found, does not return if found - justsend the file + */ +function page_pluginfile($course, $cminfo, $context, $filearea, $args, $forcedownload) { + global $CFG, $DB; + require_once("$CFG->libdir/resourcelib.php"); + + if (!$cminfo->uservisible) { + return false; + } + + if ($filearea !== 'page_content') { + // intro is handled automatically in pluginfile.php + return false; + } + + if (!$cm = get_coursemodule_from_instance('page', $cminfo->instance, $course->id)) { + return false; + } + + require_course_login($course, true, $cm); + + array_shift($args); // ignore revision - designed to prevent caching problems only + + $fs = get_file_storage(); + $relativepath = '/'.implode('/', $args); + $fullpath = $context->id.$filearea.'0'.$relativepath; + if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { + $page = $DB->get_record('page', array('id'=>$cminfo->instance), 'id, legacyfiles', MUST_EXIST); + if ($page->legacyfiles != RESOURCELIB_LEGACYFILES_ACTIVE) { + return false; + } + require_once("$CFG->dirroot/mod/resource/db/upgradelib.php"); + if (!$file = resource_try_file_migration($relativepath, $cminfo->id, $cminfo->course, 'page_content', 0)) { + return false; + } + //file migrate - update flag + $page->legacyfileslast = time(); + $DB->update_record('page', $page); + } + + // finally send the file + send_stored_file($file, 86400, 0, $forcedownload); +} diff --git a/mod/page/locallib.php b/mod/page/locallib.php new file mode 100644 index 0000000000..bbca137e11 --- /dev/null +++ b/mod/page/locallib.php @@ -0,0 +1,51 @@ +. + +/** + * Private page module utility functions + * + * @package mod-page + * @copyright 2009 Petr Skoda (http://skodak.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once("$CFG->libdir/filelib.php"); +require_once("$CFG->libdir/resourcelib.php"); +require_once("$CFG->dirroot/mod/page/lib.php"); + + +/** + * File browsing support class + */ +class page_content_file_info extends file_info_stored { + public function get_parent() { + if ($this->lf->get_filepath() === '/' and $this->lf->get_filename() === '.') { + return $this->browser->get_file_info($this->context); + } + return parent::get_parent(); + } + public function get_visible_name() { + if ($this->lf->get_filepath() === '/' and $this->lf->get_filename() === '.') { + return $this->topvisiblename; + } + return parent::get_visible_name(); + } +} + +function page_get_editor_options($context) { + return array('subdirs'=>1, 'maxbytes'=>0, 'maxfiles'=>-1, 'changeformat'=>1, 'context'=>$context, 'noclean'=>1, 'trusttext'=>0); +} \ No newline at end of file diff --git a/mod/page/mod_form.php b/mod/page/mod_form.php new file mode 100644 index 0000000000..b7dd2b359a --- /dev/null +++ b/mod/page/mod_form.php @@ -0,0 +1,140 @@ +. + +/** + * Page configuration form + * + * @package mod-page + * @copyright 2009 Petr Skoda (http://skodak.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once($CFG->dirroot.'/course/moodleform_mod.php'); +require_once($CFG->dirroot.'/mod/page/locallib.php'); +require_once($CFG->libdir.'/filelib.php'); + +class mod_page_mod_form extends moodleform_mod { + function definition() { + global $CFG, $DB; + $mform =& $this->_form; + + $config = get_config('page'); + + //------------------------------------------------------- + $mform->addElement('header', 'general', get_string('general', 'form')); + $mform->addElement('text', 'name', get_string('name'), array('size'=>'48')); + if (!empty($CFG->formatstringstriptags)) { + $mform->setType('name', PARAM_TEXT); + } else { + $mform->setType('name', PARAM_CLEAN); + } + $mform->addRule('name', null, 'required', null, 'client'); + $this->add_intro_editor($config->requiremodintro); + + //------------------------------------------------------- + $mform->addElement('header', 'contentsection', get_string('contentheader', 'page')); + $mform->addElement('editor', 'page', get_string('content', 'page'), null, page_get_editor_options($this->context)); + $mform->addElement('static', 'note', '', '(TODO: The format switching is not implemented yet, sorry...)'); + + //------------------------------------------------------- + $mform->addElement('header', 'optionssection', get_string('optionsheader', 'page')); + + if ($this->current->instance) { + $options = resourcelib_get_displayoptions(explode(',', $config->displayoptions), $this->current->display); + } else { + $options = resourcelib_get_displayoptions(explode(',', $config->displayoptions)); + } + if (count($options) == 1) { + $mform->addElement('hidden', 'display'); + reset($options); + $mform->setDefault('display', key($options)); + } else { + $mform->addElement('select', 'display', get_string('displayselect', 'page'), $options); + $mform->setDefault('display', $config->display); + $mform->setAdvanced('display', $config->display_adv); + } + + if (array_key_exists(RESOURCELIB_DISPLAY_POPUP, $options)) { + $mform->addElement('text', 'popupwidth', get_string('popupwidth', 'page'), array('size'=>3)); + if (count($options) > 1) { + $mform->disabledIf('popupwidth', 'display', 'noteq', RESOURCELIB_DISPLAY_POPUP); + } + $mform->setType('popupwidth', PARAM_INT); + $mform->setDefault('popupwidth', $config->popupwidth); + $mform->setAdvanced('popupwidth', $config->popupwidth_adv); + + $mform->addElement('text', 'popupheight', get_string('popupheight', 'page'), array('size'=>3)); + if (count($options) > 1) { + $mform->disabledIf('popupheight', 'display', 'noteq', RESOURCELIB_DISPLAY_POPUP); + } + $mform->setType('popupheight', PARAM_INT); + $mform->setDefault('popupheight', $config->popupheight); + $mform->setAdvanced('popupheight', $config->popupheight_adv); + } + + $mform->addElement('advcheckbox', 'printheading', get_string('printheading', 'page')); + $mform->setDefault('printheading', $config->printheading); + $mform->setAdvanced('printintro', $config->printheading_adv); + $mform->addElement('advcheckbox', 'printintro', get_string('printintro', 'page')); + $mform->setDefault('printintro', $config->printintro); + $mform->setAdvanced('printintro', $config->printintro_adv); + + // add legacy files flag only if used + if (isset($this->current->legacyfiles) and $this->current->legacyfiles != RESOURCELIB_LEGACYFILES_NO) { + $options = array(RESOURCE_LEGACYYFILES_DONE => get_string('legacyfilesdone', 'page'), + RESOURCELIB_LEGACYFILES_ACTIVE => get_string('legacyfilesactive', 'page')); + $mform->addElement('select', 'legacyfiles', get_string('legacyfiles', 'page'), $options); + $mform->setAdvanced('legacyfiles', 1); + } + + //------------------------------------------------------- + $this->standard_coursemodule_elements(); + + //------------------------------------------------------- + $this->add_action_buttons(); + + //------------------------------------------------------- + $mform->addElement('hidden', 'revision'); + $mform->setType('revision', PARAM_INT); + $mform->setDefault('revision', 1); + } + + function data_preprocessing(&$default_values) { + if ($this->current->instance) { + $draftitemid = file_get_submitted_draft_itemid('page'); + $default_values['page']['format'] = $default_values['contentformat']; + $default_values['page']['text'] = file_prepare_draft_area($draftitemid, $this->context->id, 'page_content', 0, page_get_editor_options($this->context), $default_values['content']); + $default_values['page']['itemid'] = $draftitemid; + } + if (!empty($default_values['displayoptions'])) { + $displayoptions = unserialize($default_values['displayoptions']); + if (isset($displayoptions['printintro'])) { + $default_values['printintro'] = $displayoptions['printintro']; + } + if (isset($displayoptions['printheading'])) { + $default_values['printheading'] = $displayoptions['printheading']; + } + if (!empty($displayoptions['popupwidth'])) { + $default_values['popupwidth'] = $displayoptions['popupwidth']; + } + if (!empty($displayoptions['popupheight'])) { + $default_values['popupheight'] = $displayoptions['popupheight']; + } + } + } +} + diff --git a/mod/page/readme.txt b/mod/page/readme.txt new file mode 100644 index 0000000000..462638ca7b --- /dev/null +++ b/mod/page/readme.txt @@ -0,0 +1,30 @@ +This file is part of Moodle - http://moodle.org/ + +Moodle is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Moodle is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Moodle. If not, see . + +copyright 2009 Petr Skoda (http://skodak.org) +license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + + +Page module +============= + +Page module is a successor to original 'html' and 'text' type plugins of Resource module. + + +TODO: + * reimplement portfolio support (?) + * implement format switching in formslib editor element (skodak) + * new backup/restore (Eloy) + * old restore support (Eloy) diff --git a/mod/page/settings.php b/mod/page/settings.php new file mode 100644 index 0000000000..da93ceee89 --- /dev/null +++ b/mod/page/settings.php @@ -0,0 +1,57 @@ +. + +/** + * Page module admin settings and defaults + * + * @package mod-page + * @copyright 2009 Petr Skoda (http://skodak.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +if ($ADMIN->fulltree) { + require_once("$CFG->libdir/resourcelib.php"); + + $displayoptions = resourcelib_get_displayoptions(array(RESOURCELIB_DISPLAY_OPEN, RESOURCELIB_DISPLAY_POPUP)); + $defaultdisplayoptions = array(RESOURCELIB_DISPLAY_OPEN); + + //--- general settings ----------------------------------------------------------------------------------- + $settings->add(new admin_setting_configcheckbox('page/requiremodintro', + get_string('requiremodintro', 'admin'), get_string('configrequiremodintro', 'admin'), 1)); + $settings->add(new admin_setting_configmultiselect('page/displayoptions', + get_string('displayoptions', 'page'), get_string('configdisplayoptions', 'page'), + $defaultdisplayoptions, $displayoptions)); + + //--- modedit defaults ----------------------------------------------------------------------------------- + $settings->add(new admin_setting_heading('pagemodeditdefaults', get_string('modeditdefaults', 'admin'), get_string('condifmodeditdefaults', 'admin'))); + + $settings->add(new admin_setting_configcheckbox_with_advanced('page/printheading', + get_string('printheading', 'page'), get_string('printheadingexplain', 'page'), + array('value'=>1, 'adv'=>false))); + $settings->add(new admin_setting_configcheckbox_with_advanced('page/printintro', + get_string('printintro', 'page'), get_string('printintroexplain', 'page'), + array('value'=>0, 'adv'=>false))); + $settings->add(new admin_setting_configselect_with_advanced('page/display', + get_string('displayselect', 'page'), get_string('displayselectexplain', 'page'), + array('value'=>RESOURCELIB_DISPLAY_OPEN, 'adv'=>true), $displayoptions)); + $settings->add(new admin_setting_configtext_with_advanced('page/popupwidth', + get_string('popupwidth', 'page'), get_string('popupwidthexplain', 'page'), + array('value'=>620, 'adv'=>true), PARAM_INT, 7)); + $settings->add(new admin_setting_configtext_with_advanced('page/popupheight', + get_string('popupheight', 'page'), get_string('popupheightexplain', 'page'), + array('value'=>450, 'adv'=>true), PARAM_INT, 7)); +} diff --git a/mod/page/version.php b/mod/page/version.php new file mode 100644 index 0000000000..ea02913f48 --- /dev/null +++ b/mod/page/version.php @@ -0,0 +1,29 @@ +. + +/** + * Page module version information + * + * @package mod-page + * @copyright 2009 Petr Skoda (http://skodak.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$module->version = 2009080500; +$module->requires = 2009073101; // Requires this Moodle version +$module->cron = 0; + diff --git a/mod/page/view.php b/mod/page/view.php new file mode 100644 index 0000000000..bd23036c68 --- /dev/null +++ b/mod/page/view.php @@ -0,0 +1,97 @@ +. + +/** + * Page module version information + * + * @package mod-page + * @copyright 2009 Petr Skoda (http://skodak.org) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require('../../config.php'); +require_once($CFG->dirroot.'/mod/page/locallib.php'); + +$id = optional_param('id', 0, PARAM_INT); // Course Module ID +$p = optional_param('p', 0, PARAM_INT); // Page instance ID +$inpopup = optional_param('inpopup', 0, PARAM_BOOL); + +if ($p) { + if (!$page = $DB->get_record('page', array('id'=>$p))) { + page_redirect_if_migrated($r, 0); + print_error('invalidaccessparameter'); + } + $cm = get_coursemodule_from_instance('page', $page->id, $page->course, false, MUST_EXIST); + +} else { + if (!$cm = get_coursemodule_from_id('page', $id)) { + page_redirect_if_migrated(0, $id); + print_error('invalidcoursemodule'); + } + $page = $DB->get_record('page', array('id'=>$cm->instance), '*', MUST_EXIST); +} + +$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST); + +require_course_login($course, true, $cm); +$context = get_context_instance(CONTEXT_MODULE, $cm->id); + +add_to_log($course->id, 'page', 'view', 'view.php?id='.$cm->id, $page->id, $cm->id); + +$PAGE->set_url('mod/page/view.php', array('id' => $cm->id)); + +$options = empty($page->displayoptions) ? array() : unserialize($page->displayoptions); + +if ($inpopup and $page->display == RESOURCELIB_DISPLAY_POPUP) { + $PAGE->set_generaltype('popup'); + $PAGE->set_title($course->shortname.': '.$page->name); + if (!empty($options['printheading'])) { + $PAGE->set_heading($page->name); + } else { + $PAGE->set_heading(''); + } + echo $OUTPUT->header(); + +} else { + $PAGE->set_title($course->shortname.': '.$page->name); + $PAGE->set_heading($course->fullname); + $PAGE->set_activity_record($page); + $PAGE->set_button(update_module_button($cm->id, '', get_string('modulename', 'page'))); + echo $OUTPUT->header(build_navigation('', $cm), navmenu($course, $cm)); + + if (!empty($options['printheading'])) { + echo $OUTPUT->heading(format_string($page->name), 2, 'main', 'pageheading'); + } +} + +if (!empty($options['printintro'])) { + if (trim(strip_tags($page->intro))) { + echo $OUTPUT->box_start('mod_introbox', 'pageintro'); + echo format_module_intro('page', $page, $cm->id); + echo $OUTPUT->box_end(); + } +} + +$content = file_rewrite_pluginfile_urls($page->content, 'pluginfile.php', $context->id, 'page_content', $page->revision); +$formatoptions = (object)array('noclean'=>true); +$content = format_text($content, $page->contentformat, $formatoptions, $course->id); +echo $OUTPUT->box($content, "generalbox center clearfix"); + +$strlastmodified = get_string("lastmodified"); +echo "
$strlastmodified: ".userdate($page->timemodified)."
"; + +echo $OUTPUT->footer();