Skip to content

Commit

Permalink
MDL-20204 the ultimate fix for our frames (theyare not accessbile, bu…
Browse files Browse the repository at this point in the history
…t 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
  • Loading branch information
skodak committed Feb 11, 2010
1 parent ae6b463 commit 4aea3cc
Show file tree
Hide file tree
Showing 24 changed files with 59 additions and 100 deletions.
2 changes: 1 addition & 1 deletion admin/auth_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
admin_externalpage_print_header();

// choose an authentication method
echo "<form $CFG->frametarget id=\"authmenu\" method=\"post\" action=\"auth_config.php\">\n";
echo "<form id=\"authmenu\" method=\"post\" action=\"auth_config.php\">\n";
echo "<div>\n";
echo "<input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />\n";
echo "<input type=\"hidden\" name=\"auth\" value=\"".$auth."\" />\n";
Expand Down
4 changes: 2 additions & 2 deletions admin/enrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

echo $OUTPUT->box(get_string('configenrolmentplugins', 'admin'));

echo "<form $CFG->frametarget id=\"enrolmenu\" method=\"post\" action=\"enrol.php\">";
echo "<form id=\"enrolmenu\" method=\"post\" action=\"enrol.php\">";
echo "<div>";
echo "<input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />";

Expand Down Expand Up @@ -113,7 +113,7 @@

$yesnooptions = array(0=>get_string('no'), 1=>get_string('yes'));

echo '<form '.$CFG->frametarget.' id="adminsettings" method="post" action="enrol.php">';
echo '<form id="adminsettings" method="post" action="enrol.php">';
echo '<div class="settingsform clearfix">';
echo $OUTPUT->heading(get_string('commonsettings', 'admin'));
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
Expand Down
2 changes: 1 addition & 1 deletion admin/enrol_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

admin_externalpage_print_header();

echo "<form $CFG->frametarget id=\"enrolmenu\" method=\"post\" action=\"enrol_config.php\">";
echo "<form id=\"enrolmenu\" method=\"post\" action=\"enrol_config.php\">";
echo "<div>";
echo "<input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />";
echo "<input type=\"hidden\" name=\"enrol\" value=\"".$enrol."\" />";
Expand Down
2 changes: 0 additions & 2 deletions admin/report/unittest/test_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
$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);
Expand Down
2 changes: 1 addition & 1 deletion calendar/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,7 @@ function calendar_preferences_button() {
return '';
}

return "<form $CFG->frametarget method=\"get\" ".
return "<form method=\"get\" ".
" action=\"$CFG->wwwroot/calendar/preferences.php\">".
"<div><input type=\"submit\" value=\"".get_string("preferences", "calendar")." ...\" /></div></form>";
}
Expand Down
2 changes: 1 addition & 1 deletion filter/activitynames/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function filter($text) {
$entitisedname = s($currentname);
/// Avoid empty or unlinkable activity names
if (!empty($title)) {
$href_tag_begin = "<a class=\"autolink\" title=\"$title\" href=\"$CFG->wwwroot/mod/$activity->mod/view.php?id=$activity->cm\" $CFG->frametarget>";
$href_tag_begin = "<a class=\"autolink\" title=\"$title\" href=\"$CFG->wwwroot/mod/$activity->mod/view.php?id=$activity->cm\">";
$this->activitylist[] = new filterobject($currentname, $href_tag_begin, '</a>', false, true);
if ($currentname != $entitisedname) { /// If name has some entity (&amp; &quot; &lt; &gt;) add that filter too. MDL-17545
$this->activitylist[] = new filterobject($entitisedname, $href_tag_begin, '</a>', false, true);
Expand Down
44 changes: 28 additions & 16 deletions lib/javascript-static.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===
Expand Down
8 changes: 2 additions & 6 deletions lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,8 @@ public function content($shorttext=false) {
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;
Expand All @@ -450,6 +445,7 @@ public function content($shorttext=false) {
}
$content = $OUTPUT->span($span);
}

return $content;
}

Expand Down
17 changes: 0 additions & 17 deletions lib/outputactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,3 @@ public function get_js_options() {
}
}

/**
* 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));
}
}
28 changes: 7 additions & 21 deletions lib/outputrenderers.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,7 @@ public function login_info() {
if (session_is_loggedinas()) {
$realuser = session_get_realuser();
$fullname = fullname($realuser, true);
$realuserinfo = " [<a $CFG->frametarget
href=\"$CFG->wwwroot/course/loginas.php?id=$course->id&amp;return=1&amp;sesskey=".sesskey()."\">$fullname</a>] ";
$realuserinfo = " [<a href=\"$CFG->wwwroot/course/loginas.php?id=$course->id&amp;return=1&amp;sesskey=".sesskey()."\">$fullname</a>] ";
} else {
$realuserinfo = '';
}
Expand All @@ -438,28 +437,27 @@ public function login_info() {
$context = get_context_instance(CONTEXT_COURSE, $course->id);

$fullname = fullname($USER, true);
$username = "<a $CFG->frametarget href=\"$CFG->wwwroot/user/view.php?id=$USER->id&amp;course=$course->id\">$fullname</a>";
$username = "<a href=\"$CFG->wwwroot/user/view.php?id=$USER->id&amp;course=$course->id\">$fullname</a>";
if (is_mnet_remote_user($USER) and $idprovider = $DB->get_record('mnet_host', array('id'=>$USER->mnethostid))) {
$username .= " from <a $CFG->frametarget href=\"{$idprovider->wwwroot}\">{$idprovider->name}</a>";
$username .= " from <a href=\"{$idprovider->wwwroot}\">{$idprovider->name}</a>";
}
if (isset($USER->username) && $USER->username == 'guest') {
$loggedinas = $realuserinfo.get_string('loggedinasguest').
" (<a $CFG->frametarget href=\"$loginurl\">".get_string('login').'</a>)';
" (<a href=\"$loginurl\">".get_string('login').'</a>)';
} 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.
" (<a $CFG->frametarget
href=\"$CFG->wwwroot/course/view.php?id=$course->id&amp;switchrole=0&amp;sesskey=".sesskey()."\">".get_string('switchrolereturn').'</a>)';
" (<a href=\"$CFG->wwwroot/course/view.php?id=$course->id&amp;switchrole=0&amp;sesskey=".sesskey()."\">".get_string('switchrolereturn').'</a>)';
} else {
$loggedinas = $realuserinfo.get_string('loggedinas', 'moodle', $username).' '.
" (<a $CFG->frametarget href=\"$CFG->wwwroot/login/logout.php?sesskey=".sesskey()."\">".get_string('logout').'</a>)';
" (<a href=\"$CFG->wwwroot/login/logout.php?sesskey=".sesskey()."\">".get_string('logout').'</a>)';
}
} else {
$loggedinas = get_string('loggedinnot', 'moodle').
" (<a $CFG->frametarget href=\"$loginurl\">".get_string('login').'</a>)';
" (<a href=\"$loginurl\">".get_string('login').'</a>)';
}

$loggedinas = '<div class="logininfo">'.$loggedinas.'</div>';
Expand Down Expand Up @@ -905,11 +903,6 @@ public function link($link_or_url, $text = null, array $options = null) {
'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);
}

Expand Down Expand Up @@ -961,13 +954,6 @@ protected function render_action_link(action_link $link) {
}
}

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);
}

Expand Down
6 changes: 5 additions & 1 deletion lib/outputrequirementslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ protected function init_requirements_data(moodle_page $page, core_renderer $rend

// 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.
Expand All @@ -250,6 +250,10 @@ protected function init_requirements_data(moodle_page $page, core_renderer $rend
$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');
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/pagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1673,7 +1673,7 @@ function print_header($title, $morenavlinks = NULL, $bodytags = '', $meta = '')

$buttons = '<table><tr><td>'.$OUTPUT->update_module_button($this->modulerecord->id, $this->activityname).'</td>';
if ($this->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) {
$buttons .= '<td><form '.$CFG->frametarget.' method="get" action="view.php"><div>'.
$buttons .= '<td><form method="get" action="view.php"><div>'.
'<input type="hidden" name="id" value="'.$this->modulerecord->id.'" />'.
'<input type="hidden" name="edit" value="'.($this->user_is_editing()?'off':'on').'" />'.
'<input type="submit" value="'.get_string($this->user_is_editing()?'blockseditoff':'blocksediton').'" /></div></form></td>';
Expand Down
3 changes: 0 additions & 3 deletions lib/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,6 @@
}
$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');
Expand Down
16 changes: 0 additions & 16 deletions lib/weblib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
3 changes: 2 additions & 1 deletion message/send.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,14 @@
}

$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'));

Expand Down
2 changes: 1 addition & 1 deletion mod/chat/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
$title = $course->shortname . ': ' . format_string($chat->name);

if ($PAGE->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) {
$buttons = '<table><tr><td><form '.$CFG->frametarget.' method="get" action="view.php"><div>'.
$buttons = '<table><tr><td><form method="get" action="view.php"><div>'.
'<input type="hidden" name="id" value="'.$cm->id.'" />'.
'<input type="hidden" name="edit" value="'.($PAGE->user_is_editing()?'off':'on').'" />'.
'<input type="submit" value="'.get_string($PAGE->user_is_editing()?'blockseditoff':'blocksediton').'" /></div></form></td></tr></table>';
Expand Down
2 changes: 1 addition & 1 deletion mod/data/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function data_filter($courseid, $text) {
'<a class="data autolink" title="'.
$strippedcontent.'" href="'.
$CFG->wwwroot.'/mod/data/view.php?d='. $datacontent->dataid .
'&amp;rid='. $datacontent->recordid .'" '.$CFG->frametarget.'>',
'&amp;rid='. $datacontent->recordid .'">',
'</a>', false, true);
}
} // End foreach
Expand Down
2 changes: 1 addition & 1 deletion mod/data/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@
$title = $course->shortname.': ' . format_string($data->name);

if ($PAGE->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) {
$buttons = '<table><tr><td><form '.$CFG->frametarget.' method="get" action="view.php"><div>'.
$buttons = '<table><tr><td><form method="get" action="view.php"><div>'.
'<input type="hidden" name="id" value="'.$cm->id.'" />'.
'<input type="hidden" name="edit" value="'.($PAGE->user_is_editing()?'off':'on').'" />'.
'<input type="submit" value="'.get_string($PAGE->user_is_editing()?'blockseditoff':'blocksediton').'" /></div></form></td></tr></table>';
Expand Down
2 changes: 1 addition & 1 deletion mod/forum/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -6248,7 +6248,7 @@ function forum_update_subscriptions_button($courseid, $forumid) {
$edit = "on";
}

return "<form $CFG->frametarget method=\"get\" action=\"$CFG->wwwroot/mod/forum/subscribers.php\">".
return "<form method=\"get\" action=\"$CFG->wwwroot/mod/forum/subscribers.php\">".
"<input type=\"hidden\" name=\"id\" value=\"$forumid\" />".
"<input type=\"hidden\" name=\"edit\" value=\"$edit\" />".
"<input type=\"submit\" value=\"$string\" /></form>";
Expand Down
2 changes: 1 addition & 1 deletion mod/hotpot/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@

if (has_capability('moodle/course:manageactivities', $coursecontext)) {
$updatebutton = ''
. '<form '.$CFG->frametarget.' method="get" action="'.$CFG->wwwroot.'/course/mod.php">'
. '<form method="get" action="'.$CFG->wwwroot.'/course/mod.php">'
. '<input type="hidden" name="update" value="'.$hotpot->coursemodule.'" />'
. $sesskey
. '<input type="submit" value="'.$strupdate.'" />'
Expand Down
2 changes: 0 additions & 2 deletions mod/hotpot/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2155,8 +2155,6 @@ function insert_form($startblock, $endblock, $form_id, $form_fields, $keep_conte
$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 = '';
}
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
$title = $course->shortname . ': ' . format_string($quiz->name);

if ($PAGE->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) {
$buttons = '<table><tr><td><form '.$CFG->frametarget.' method="get" action="view.php"><div>'.
$buttons = '<table><tr><td><form method="get" action="view.php"><div>'.
'<input type="hidden" name="id" value="'.$cm->id.'" />'.
'<input type="hidden" name="edit" value="'.($PAGE->user_is_editing()?'off':'on').'" />'.
'<input type="submit" value="'.get_string($PAGE->user_is_editing()?'blockseditoff':'blocksediton').'" /></div></form></td></tr></table>';
Expand Down
2 changes: 1 addition & 1 deletion mod/scorm/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 .= '<td class="reportlink">'.
'<a '.$CFG->frametarget.'" href="'.$CFG->wwwroot.'/mod/scorm/report.php?id='.$cm->id.'">'.
'<a href="'.$CFG->wwwroot.'/mod/scorm/report.php?id='.$cm->id.'">'.
get_string('viewallreports','scorm',$trackedusers->c).'</a>';
} else {
$headertext .= '<td class="reportlink">'.get_string('noreports','scorm');
Expand Down
2 changes: 1 addition & 1 deletion mod/scorm/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

$trackedusers = scorm_get_count_users($scorm->id, $cm->groupingid);
if ($trackedusers > 0) {
echo "<div class=\"reportlink\"><a $CFG->frametarget href=\"report.php?id=$cm->id\"> ".get_string('viewalluserreports','scorm',$trackedusers).'</a></div>';
echo "<div class=\"reportlink\"><a href=\"report.php?id=$cm->id\"> ".get_string('viewalluserreports','scorm',$trackedusers).'</a></div>';
} else {
echo '<div class="reportlink">'.get_string('noreports','scorm').'</div>';
}
Expand Down

0 comments on commit 4aea3cc

Please sign in to comment.