Skip to content

Commit

Permalink
MDL-50887 antivirus: Refactor adminlib to use html_writer.
Browse files Browse the repository at this point in the history
  • Loading branch information
kabalin committed Feb 29, 2016
1 parent 11362ae commit ae784f7
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -6605,45 +6605,53 @@ public function output_html($data, $query='') {
// Iterate through auth plugins and add to the display table.
$updowncount = 1;
$antiviruscount = count($activeantiviruses);
$url = "antiviruses.php?sesskey=" . sesskey();
$baseurl = new moodle_url('/admin/antiviruses.php', array('sesskey' => sesskey()));
foreach ($antivirusesavailable as $antivirus => $name) {
// Hide/show link.
$class = '';
if (in_array($antivirus, $activeantiviruses)) {
$hideshow = "<a href=\"$url&amp;action=disable&amp;antivirus=$antivirus\">";
$hideshow .= "<img src=\"" . $OUTPUT->pix_url('t/hide') . "\" class=\"iconsmall\" alt=\"disable\" /></a>";
$hideshowurl = $baseurl;
$hideshowurl->params(array('action' => 'disable', 'antivirus' => $antivirus));
$hideshowimg = html_writer::img($OUTPUT->pix_url('t/hide'), 'disable', array('class' => 'iconsmall'));
$hideshow = html_writer::link($hideshowurl, $hideshowimg);
$enabled = true;
$displayname = $name;
} else {
$hideshow = "<a href=\"$url&amp;action=enable&amp;antivirus=$antivirus\">";
$hideshow .= "<img src=\"" . $OUTPUT->pix_url('t/show') . "\" class=\"iconsmall\" alt=\"enable\" /></a>";
$hideshowurl = $baseurl;
$hideshowurl->params(array('action' => 'enable', 'antivirus' => $antivirus));
$hideshowimg = html_writer::img($OUTPUT->pix_url('t/show'), 'enable', array('class' => 'iconsmall'));
$hideshow = html_writer::link($hideshowurl, $hideshowimg);
$enabled = false;
$displayname = $name;
$class = 'dimmed_text';
}

// Up/down link (only if auth is enabled).
// Up/down link.
$updown = '';
if ($enabled) {
if ($updowncount > 1) {
$updown .= "<a href=\"$url&amp;action=up&amp;antivirus=$antivirus\">";
$updown .= "<img src=\"" . $OUTPUT->pix_url('t/up') . "\" alt=\"up\" class=\"iconsmall\" /></a>&nbsp;";
$updownurl = $baseurl;
$updownurl->params(array('action' => 'up', 'antivirus' => $antivirus));
$updownimg = html_writer::img($OUTPUT->pix_url('t/up'), 'up', array('class' => 'iconsmall'));
$updown = html_writer::link($updownurl, $updownimg);
} else {
$updown .= "<img src=\"" . $OUTPUT->pix_url('spacer') . "\" class=\"iconsmall\" alt=\"\" />&nbsp;";
$updown .= html_writer::img($OUTPUT->pix_url('spacer'), '', array('class' => 'iconsmall'));
}
if ($updowncount < $antiviruscount) {
$updown .= "<a href=\"$url&amp;action=down&amp;antivirus=$antivirus\">";
$updown .= "<img src=\"" . $OUTPUT->pix_url('t/down') . "\" alt=\"down\" class=\"iconsmall\" /></a>";
$updownurl = $baseurl;
$updownurl->params(array('action' => 'down', 'antivirus' => $antivirus));
$updownimg = html_writer::img($OUTPUT->pix_url('t/down'), 'down', array('class' => 'iconsmall'));
$updown = html_writer::link($updownurl, $updownimg);
} else {
$updown .= "<img src=\"" . $OUTPUT->pix_url('spacer') . "\" class=\"iconsmall\" alt=\"\" />";
$updown .= html_writer::img($OUTPUT->pix_url('spacer'), '', array('class' => 'iconsmall'));
}
++ $updowncount;
}

// Settings link.
if (file_exists($CFG->dirroot.'/lib/antivirus/'.$antivirus.'/settings.php')) {
$eurl = new moodle_url('/admin/settings.php', array('section' => 'antivirussettings'.$antivirus));
$settings = "<a href='$eurl'>{$txt->settings}</a>";
$settings = html_writer::link($eurl, $txt->settings);
} else {
$settings = '';
}
Expand All @@ -6661,7 +6669,7 @@ public function output_html($data, $query='') {
$table->data[] = $row;
}
$return .= html_writer::table($table);
$return .= get_string('configantivirusplugins', 'antivirus').'<br />'.get_string('tablenosave', 'admin');
$return .= get_string('configantivirusplugins', 'antivirus') . html_writer::empty_tag('br') . get_string('tablenosave', 'admin');
$return .= $OUTPUT->box_end();
return highlight($query, $return);
}
Expand Down

0 comments on commit ae784f7

Please sign in to comment.