From 4aea3cc7cd4c09a73299346f05703bb247b04f6c Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Thu, 11 Feb 2010 13:27:02 +0000 Subject: [PATCH] MDL-20204 the ultimate fix for our frames (theyare not accessbile, but anyway); instead of adding the target to each element when creating html we use yui to set the target from page footer via JS - this fixes the links and forms in all elements in pages with frametop layout --- admin/auth_config.php | 2 +- admin/enrol.php | 4 +-- admin/enrol_config.php | 2 +- admin/report/unittest/test_tables.php | 2 -- calendar/lib.php | 2 +- filter/activitynames/filter.php | 2 +- lib/javascript-static.js | 44 +++++++++++++++++---------- lib/navigationlib.php | 8 ++--- lib/outputactions.php | 17 ----------- lib/outputrenderers.php | 28 +++++------------ lib/outputrequirementslib.php | 6 +++- lib/pagelib.php | 2 +- lib/setup.php | 3 -- lib/weblib.php | 16 ---------- message/send.php | 3 +- mod/chat/view.php | 2 +- mod/data/filter.php | 2 +- mod/data/view.php | 2 +- mod/forum/lib.php | 2 +- mod/hotpot/index.php | 2 +- mod/hotpot/lib.php | 2 -- mod/quiz/view.php | 2 +- mod/scorm/locallib.php | 2 +- mod/scorm/view.php | 2 +- 24 files changed, 59 insertions(+), 100 deletions(-) diff --git a/admin/auth_config.php b/admin/auth_config.php index 261c165ee8f..201ec78b522 100644 --- a/admin/auth_config.php +++ b/admin/auth_config.php @@ -58,7 +58,7 @@ $user_fields = $authplugin->userfields; admin_externalpage_print_header(); // choose an authentication method -echo "
frametarget id=\"authmenu\" method=\"post\" action=\"auth_config.php\">\n"; +echo "\n"; echo "
\n"; echo "\n"; echo "\n"; diff --git a/admin/enrol.php b/admin/enrol.php index 32fde250920..7ec956d50ba 100644 --- a/admin/enrol.php +++ b/admin/enrol.php @@ -60,7 +60,7 @@ echo $OUTPUT->box(get_string('configenrolmentplugins', 'admin')); - echo "frametarget id=\"enrolmenu\" method=\"post\" action=\"enrol.php\">"; + echo ""; echo "
"; echo ""; @@ -113,7 +113,7 @@ $yesnooptions = array(0=>get_string('no'), 1=>get_string('yes')); - echo 'frametarget.' id="adminsettings" method="post" action="enrol.php">'; + echo ''; echo '
'; echo $OUTPUT->heading(get_string('commonsettings', 'admin')); echo ''; diff --git a/admin/enrol_config.php b/admin/enrol_config.php index c13b8ea55d1..2ad5c8f99d9 100644 --- a/admin/enrol_config.php +++ b/admin/enrol_config.php @@ -42,7 +42,7 @@ admin_externalpage_print_header(); - echo "frametarget id=\"enrolmenu\" method=\"post\" action=\"enrol_config.php\">"; + echo ""; echo "
"; echo ""; echo ""; diff --git a/admin/report/unittest/test_tables.php b/admin/report/unittest/test_tables.php index 08be23c4af1..3bfcde3113d 100644 --- a/admin/report/unittest/test_tables.php +++ b/admin/report/unittest/test_tables.php @@ -33,8 +33,6 @@ die;die;die; $CFG->release = $real_cfg->release; $CFG->version = $real_cfg->version; $CFG->config_php_settings = $real_cfg->config_php_settings; - $CFG->frametarget = $real_cfg->frametarget; - $CFG->framename = $real_cfg->framename; $CFG->debug = 0; $DB = moodle_database::get_driver_instance($CFG->dbtype, $CFG->dblibrary); diff --git a/calendar/lib.php b/calendar/lib.php index 8a46ae4f7f9..8aebe110ae8 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -1445,7 +1445,7 @@ function calendar_preferences_button() { return ''; } - return "frametarget method=\"get\" ". + return "wwwroot/calendar/preferences.php\">". "
"; } diff --git a/filter/activitynames/filter.php b/filter/activitynames/filter.php index 83583841e61..0a79203d28f 100644 --- a/filter/activitynames/filter.php +++ b/filter/activitynames/filter.php @@ -54,7 +54,7 @@ class activitynames_filter extends moodle_text_filter { $entitisedname = s($currentname); /// Avoid empty or unlinkable activity names if (!empty($title)) { - $href_tag_begin = "wwwroot/mod/$activity->mod/view.php?id=$activity->cm\" $CFG->frametarget>"; + $href_tag_begin = "wwwroot/mod/$activity->mod/view.php?id=$activity->cm\">"; $this->activitylist[] = new filterobject($currentname, $href_tag_begin, '', false, true); if ($currentname != $entitisedname) { /// If name has some entity (& " < >) add that filter too. MDL-17545 $this->activitylist[] = new filterobject($entitisedname, $href_tag_begin, '', false, true); diff --git a/lib/javascript-static.js b/lib/javascript-static.js index 767a382c540..bf93089725e 100644 --- a/lib/javascript-static.js +++ b/lib/javascript-static.js @@ -385,28 +385,40 @@ M.util.init_maximised_embed = function(Y, id) { * Attach handler to single_select */ M.util.init_select_autosubmit = function(Y, formid, selectid, nothing) { - YUI(M.yui.loader).use('node', function(Y) { - Y.on('change', function() { - if ((nothing == false && Y.Lang.isBoolean(nothing)) || Y.one('#'+selectid).get('value') != nothing) { - Y.one('#'+formid).submit(); - } - }, - '#'+selectid); - }); + YUI(M.yui.loader).use('node', function(Y) { + Y.on('change', function() { + if ((nothing == false && Y.Lang.isBoolean(nothing)) || Y.one('#'+selectid).get('value') != nothing) { + Y.one('#'+formid).submit(); + } + }, + '#'+selectid); + }); }; /** * Attach handler to url_select */ M.util.init_url_select = function(Y, formid, selectid, nothing) { - YUI(M.yui.loader).use('node', function(Y) { - Y.on('change', function() { - if ((nothing == false && Y.Lang.isBoolean(nothing)) || Y.one('#'+selectid).get('value') != nothing) { - window.location = M.cfg.wwwroot+Y.one('#'+selectid).get('value'); - } - }, - '#'+selectid); - }); + YUI(M.yui.loader).use('node', function(Y) { + Y.on('change', function() { + if ((nothing == false && Y.Lang.isBoolean(nothing)) || Y.one('#'+selectid).get('value') != nothing) { + window.location = M.cfg.wwwroot+Y.one('#'+selectid).get('value'); + } + }, + '#'+selectid); + }); +}; + +/** + * Breaks out all links to the top frame - used in frametop page layout. + */ +M.util.init_frametop = function(Y) { + Y.all('a').each(function(node) { + node.set('target', '_top'); + }); + Y.all('form').each(function(node) { + node.set('target', '_top'); + }); }; //=== old legacy JS code, hopefully to be replaced soon by M.xx.yy and YUI3 code === diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 5c97dc6a2c3..9d79e13a97d 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -432,13 +432,8 @@ class navigation_node { if ($this->hidden) { $link->add_class('dimmed'); } - - if (!empty($CFG->framename) && ($PAGE->pagelayout=='frametop' || $CFG->framename!='_top')) { - $breakoutaction = new breakout_of_frame_action(); - $link->add_action($breakoutaction); - } - $content = $OUTPUT->link($link); + } else { $span = new html_span(); $span->contents = $content; @@ -450,6 +445,7 @@ class navigation_node { } $content = $OUTPUT->span($span); } + return $content; } diff --git a/lib/outputactions.php b/lib/outputactions.php index 1408db80f36..84fcb74b645 100644 --- a/lib/outputactions.php +++ b/lib/outputactions.php @@ -158,20 +158,3 @@ class popup_action extends component_action { } } -/** - * Component action for a breaking out of a frameset for a redirection. - * - * This function simply sets a `onclick="this.target='framename'` for the link when - * it is clicked causing the page to be directed to the target rather than the just - * the frame. - */ -class breakout_of_frame_action extends component_action { - /** - * Constructor to set up the action - * Relies on parent::__construct - */ - public function __construct() { - global $CFG; - parent::__construct('click', 'frame_breakout', array('framename'=>$CFG->framename)); - } -} diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 46f55e76369..1f659ac3d9d 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -423,8 +423,7 @@ class core_renderer extends renderer_base { if (session_is_loggedinas()) { $realuser = session_get_realuser(); $fullname = fullname($realuser, true); - $realuserinfo = " [frametarget - href=\"$CFG->wwwroot/course/loginas.php?id=$course->id&return=1&sesskey=".sesskey()."\">$fullname] "; + $realuserinfo = " [wwwroot/course/loginas.php?id=$course->id&return=1&sesskey=".sesskey()."\">$fullname] "; } else { $realuserinfo = ''; } @@ -438,28 +437,27 @@ class core_renderer extends renderer_base { $context = get_context_instance(CONTEXT_COURSE, $course->id); $fullname = fullname($USER, true); - $username = "frametarget href=\"$CFG->wwwroot/user/view.php?id=$USER->id&course=$course->id\">$fullname"; + $username = "wwwroot/user/view.php?id=$USER->id&course=$course->id\">$fullname"; if (is_mnet_remote_user($USER) and $idprovider = $DB->get_record('mnet_host', array('id'=>$USER->mnethostid))) { - $username .= " from frametarget href=\"{$idprovider->wwwroot}\">{$idprovider->name}"; + $username .= " from wwwroot}\">{$idprovider->name}"; } if (isset($USER->username) && $USER->username == 'guest') { $loggedinas = $realuserinfo.get_string('loggedinasguest'). - " (frametarget href=\"$loginurl\">".get_string('login').')'; + " (".get_string('login').')'; } else if (!empty($USER->access['rsw'][$context->path])) { $rolename = ''; if ($role = $DB->get_record('role', array('id'=>$USER->access['rsw'][$context->path]))) { $rolename = ': '.format_string($role->name); } $loggedinas = get_string('loggedinas', 'moodle', $username).$rolename. - " (frametarget - href=\"$CFG->wwwroot/course/view.php?id=$course->id&switchrole=0&sesskey=".sesskey()."\">".get_string('switchrolereturn').')'; + " (wwwroot/course/view.php?id=$course->id&switchrole=0&sesskey=".sesskey()."\">".get_string('switchrolereturn').')'; } else { $loggedinas = $realuserinfo.get_string('loggedinas', 'moodle', $username).' '. - " (frametarget href=\"$CFG->wwwroot/login/logout.php?sesskey=".sesskey()."\">".get_string('logout').')'; + " (wwwroot/login/logout.php?sesskey=".sesskey()."\">".get_string('logout').')'; } } else { $loggedinas = get_string('loggedinnot', 'moodle'). - " (frametarget href=\"$loginurl\">".get_string('login').')'; + " (".get_string('login').')'; } $loggedinas = '
'.$loggedinas.'
'; @@ -905,11 +903,6 @@ class core_renderer extends renderer_base { 'style' => $link->style, 'id' => $link->id); - if (!empty($CFG->frametarget)) { - //TODO: this seems wrong, we have to use onclick hack in order to be xhtml strict... - $attributes['target'] = $CFG->framename; - } - return html_writer::tag('a', $attributes, $link->text); } @@ -961,13 +954,6 @@ class core_renderer extends renderer_base { } } - if (!empty($CFG->frametarget)) { - //TODO: this seems wrong, we have to use onclick hack in order to be xhtml strict, - // we should instead use YUI and alter all links in frame-top layout, - // that is officially the only place where we have the "breaking out of frame" problems. - $attributes['target'] = $CFG->framename; - } - return html_writer::tag('a', $attributes, $link->text); } diff --git a/lib/outputrequirementslib.php b/lib/outputrequirementslib.php index 156f435099d..9a9c68494e8 100644 --- a/lib/outputrequirementslib.php +++ b/lib/outputrequirementslib.php @@ -226,7 +226,7 @@ class page_requirements_manager { // JavaScript should always work with $CFG->httpswwwroot rather than $CFG->wwwroot. // Otherwise, in some situations, users will get warnings about insecure content - // on sercure pages from their web browser. + // on secure pages from their web browser. $this->M_cfg = array( 'wwwroot' => $CFG->httpswwwroot, // Yes, really. See above. @@ -250,6 +250,10 @@ class page_requirements_manager { $this->string_for_js('cancel', 'moodle'); $this->string_for_js('yes', 'moodle'); $this->js_init_call('M.util.init_help_icons'); + + if ($page->pagelayout === 'frametop') { + $this->js_init_call('M.util.init_frametop'); + } } /** diff --git a/lib/pagelib.php b/lib/pagelib.php index 4d695867ec1..8f2b30519df 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -1673,7 +1673,7 @@ class page_generic_activity extends page_base { $buttons = ''; if ($this->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) { - $buttons .= ''; diff --git a/lib/setup.php b/lib/setup.php index 1d4fdab7387..4f911cd8832 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -461,9 +461,6 @@ if (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) { } $CFG->os = PHP_OS; -// Set up default frame target string, based on $CFG->framename -$CFG->frametarget = frametarget(); - // Setup cache dir for Smarty and others if (!file_exists($CFG->dataroot .'/cache')) { make_upload_directory('cache'); diff --git a/lib/weblib.php b/lib/weblib.php index 030a84cfcde..89834743544 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -2989,22 +2989,6 @@ function debugging($message = '', $level = DEBUG_NORMAL, $backtrace = null) { return true; } -/** - * Returns string to add a frame attribute, if required - * - * @global object - * @return bool - */ -function frametarget() { - global $CFG; - - if (empty($CFG->framename) or ($CFG->framename == '_top')) { - return ''; - } else { - return ' target="'.$CFG->framename.'" '; - } -} - /** * Outputs a HTML comment to the browser. This is used for those hard-to-debug * pages that use bits from many different files in very confusing ways (e.g. blocks). diff --git a/message/send.php b/message/send.php index 8e20c267200..16044ba45c5 100644 --- a/message/send.php +++ b/message/send.php @@ -111,13 +111,14 @@ if (has_capability('moodle/site:sendmessage', get_context_instance(CONTEXT_SYSTE } $mform->display(); + /* TODO: frames are a nono, this has to be redesigned echo $OUTPUT->box_start('noframesjslink'); $accesslink = new html_link(); $accesslink->url = new moodle_url('/message/discussion.php', array('id'=>$userid, 'noframesjs'=>1)); $accesslink->text = get_string('noframesjs', 'message'); - $accesslink->add_action(new breakout_of_frame_action()); echo $OUTPUT->link($accesslink); echo $OUTPUT->box_end(); + */ $PAGE->requires->js_init_call('M.core_message.init_focus', array('id_message_editor')); diff --git a/mod/chat/view.php b/mod/chat/view.php index 536b8cfc344..75a29668097 100644 --- a/mod/chat/view.php +++ b/mod/chat/view.php @@ -73,7 +73,7 @@ $title = $course->shortname . ': ' . format_string($chat->name); if ($PAGE->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) { - $buttons = '
'.$OUTPUT->update_module_button($this->modulerecord->id, $this->activityname).'
frametarget.' method="get" action="view.php">
'. + $buttons .= '
'. ''. ''. '
frametarget.' method="get" action="view.php">
'. + $buttons = '
'. ''. ''. '
'; diff --git a/mod/data/filter.php b/mod/data/filter.php index 41328011366..6a81b2bf23e 100644 --- a/mod/data/filter.php +++ b/mod/data/filter.php @@ -57,7 +57,7 @@ 'frametarget.'>', + '&rid='. $datacontent->recordid .'">', '', false, true); } } // End foreach diff --git a/mod/data/view.php b/mod/data/view.php index 298ee10baa9..58056151f18 100755 --- a/mod/data/view.php +++ b/mod/data/view.php @@ -283,7 +283,7 @@ $title = $course->shortname.': ' . format_string($data->name); if ($PAGE->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) { - $buttons = '
frametarget.' method="get" action="view.php">
'. + $buttons = '
'. ''. ''. '
'; diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 9cf6c1f1eff..0ef40ca7311 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -6248,7 +6248,7 @@ function forum_update_subscriptions_button($courseid, $forumid) { $edit = "on"; } - return "
frametarget method=\"get\" action=\"$CFG->wwwroot/mod/forum/subscribers.php\">". + return "wwwroot/mod/forum/subscribers.php\">". "". "". "
"; diff --git a/mod/hotpot/index.php b/mod/hotpot/index.php index 1b88023c66b..7a37cdf2625 100644 --- a/mod/hotpot/index.php +++ b/mod/hotpot/index.php @@ -364,7 +364,7 @@ if (has_capability('moodle/course:manageactivities', $coursecontext)) { $updatebutton = '' - . '
frametarget.' method="get" action="'.$CFG->wwwroot.'/course/mod.php">' + . '' . '' . $sesskey . '' diff --git a/mod/hotpot/lib.php b/mod/hotpot/lib.php index 14ad30e560c..ac4f41bf4e8 100644 --- a/mod/hotpot/lib.php +++ b/mod/hotpot/lib.php @@ -2155,8 +2155,6 @@ class hotpot_xml_quiz extends hotpot_xml_tree { $frametarget = ' onsubmit="'."this.target='$targetframe';".'"'; } else if (! empty($CFG->framename)) { $frametarget = ' onsubmit="'."this.target='$CFG->framename';".'"'; - } else if (! empty($CFG->frametarget)) { - $frametarget = $CFG->frametarget; } else { $frametarget = ''; } diff --git a/mod/quiz/view.php b/mod/quiz/view.php index c7f0f25db26..b1569fac1e1 100644 --- a/mod/quiz/view.php +++ b/mod/quiz/view.php @@ -73,7 +73,7 @@ $title = $course->shortname . ': ' . format_string($quiz->name); if ($PAGE->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) { - $buttons = '
frametarget.' method="get" action="view.php">
'. + $buttons = '
'. ''. ''. '
'; diff --git a/mod/scorm/locallib.php b/mod/scorm/locallib.php index 4c1820fc30f..e213f1b6281 100755 --- a/mod/scorm/locallib.php +++ b/mod/scorm/locallib.php @@ -686,7 +686,7 @@ function scorm_course_format_display($user,$course) { $trackedusers = $DB->get_record('scorm_scoes_track', array('scormid'=>$scorm->id), 'count(distinct(userid)) as c'); if ($trackedusers->c > 0) { $headertext .= '