Skip to content

Commit

Permalink
MDL-21198 $OUTPUT->icon() improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Dec 31, 2009
1 parent 173bb44 commit b527063
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 49 deletions.
10 changes: 3 additions & 7 deletions blog/external_blogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,9 @@

foreach ($blogs as $blog) {
if ($blog->failedlastsync) {
$validicon = html_image::make($OUTPUT->pix_url('i/cross_red_big'));
$validicon->alt = get_string('feedisinvalid', 'blog');
$validicon->title = get_string('feedisinvalid', 'blog');
$validicon = $OUTPUT->image('i/cross_red_big', array('alt'=>get_string('feedisinvalid', 'blog'), 'title'=>get_string('feedisinvalid', 'blog')));
} else {
$validicon = html_image::make($OUTPUT->pix_url('i/tick_green_big'));
$validicon->alt = get_string('feedisvalid', 'blog');
$validicon->title = get_string('feedisvalid', 'blog');
$validicon = $OUTPUT->image('i/tick_green_big', array('alt'=>get_string('feedisvalid', 'blog'), 'title'=>get_string('feedisvalid', 'blog')));
}

$editicon = new moodle_action_icon;
Expand All @@ -95,7 +91,7 @@
$deleteicon->image->alt = get_string('deleteexternalblog', 'blog');
$deleteicon->add_confirm_action(get_string('externalblogdeleteconfirm', 'blog'));
$icons = $OUTPUT->action_icon($editicon) . $OUTPUT->action_icon($deleteicon);
$table->data[] = html_table_row::make(array($blog->name, $blog->url, userdate($blog->timefetched), $OUTPUT->image($validicon), $icons));
$table->data[] = html_table_row::make(array($blog->name, $blog->url, userdate($blog->timefetched), $validicon, $icons));
}
echo $OUTPUT->table($table);
}
Expand Down
11 changes: 3 additions & 8 deletions blog/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,7 @@ public function print_attachments($return=false) {
$icon = substr(mimeinfo_from_type("icon", $mimetype), 0, -4);
$type = mimeinfo_from_type("type", $mimetype);

$image = new html_image();
$image->src = $OUTPUT->pix_url("/f/$icon");
$image->add_class('icon');
$image->alt = $filename;
$image = $OUTPUT->image("/f/$icon", array('alt'=>$filename, 'class'=>'icon'));

if ($return == "html") {
$output .= $OUTPUT->link(html_link::make($ffurl, $OUTPUT->image($image)));
Expand All @@ -512,12 +509,10 @@ public function print_attachments($return=false) {

} else {
if (in_array($type, array('image/gif', 'image/jpeg', 'image/png'))) { // Image attachments don't get printed as links
$image = new html_image();
$image->src = $ffurl;
$image->alt = $filename;
$image = $OUTPUT->image($ffurl, array('alt'=>$filename));
$imagereturn .= "<br />" . $OUTPUT->image($image);
} else {
$imagereturn .= $OUTPUT->link(html_link::make($ffurl, $OUTPUT->image($image)));
$imagereturn .= $OUTPUT->link(html_link::make($ffurl, $image));
$imagereturn .= filter_text($OUTPUT->link(html_link::make($ffurl, $filename)));
}
}
Expand Down
6 changes: 1 addition & 5 deletions course/pending.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@
$strrequireskey = get_string('requireskey');

// Loop over requested courses.
$keyicon = new html_image();
$keyicon->src = $OUTPUT->pix_url('i/key');
$keyicon->alt = $strrequireskey;
$keyicon->add_class('icon');
$keyicon = $OUTPUT->image($keyicon);
$keyicon = $OUTPUT->image('i/key', array('alt'=>$strrequireskey, 'class'=>'icon'));

foreach ($pending as $course) {
$course = new course_request($course);
Expand Down
6 changes: 2 additions & 4 deletions course/report/outline/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,14 @@
$activitycell = new html_table_cell();
$activitycell->add_class('activity');

$activityicon = html_image::make($OUTPUT->pix_url('icon', $cm->modname));
$activityicon->add_class('icon');
$activityicon->alt = $modulename;
$activityicon = $OUTPUT->image($OUTPUT->pix_url('icon', $cm->modname), array('alt'=>$modulename, 'class'=>'icon'));

$activitylink = html_link::make("$CFG->wwwroot/mod/$cm->modname/view.php?id=$cm->id", format_string($cm->name));
if (!$cm->visible) {
$activitylink->add_class('dimmed');
}

$activitycell->text = $OUTPUT->image($activityicon) . $OUTPUT->link($activitylink);
$activitycell->text = $activityicon . $OUTPUT->link($activitylink);

$reportrow->cells[] = $activitycell;

Expand Down
6 changes: 1 addition & 5 deletions grade/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1552,11 +1552,7 @@ public function get_locking_icon($element, $gpr) {
$strparamobj->itemname = $element['object']->grade_item->itemname;
$strnonunlockable = get_string('nonunlockableverbose', 'grades', $strparamobj);

$lockicon = new html_image();
$lockicon->image->src = $OUTPUT->pix_url('t/unlock_gray');
$lockicon->image->alt = s($strnonunlockable);
$lockicon->image->title = s($strnonunlockable);
$lockicon->image->add_class('iconsmall');
$action = $OUTPUT->image('t/unlock_gray', array('alt'=>$strnonunlockable, 'title'=>$strnonunlockable, 'class'=>'iconsmall'));
$action = $OUTPUT->image($lockicon);
} else if ($element['object']->is_locked()) {
$icon = 'unlock';
Expand Down
5 changes: 2 additions & 3 deletions lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,8 @@ public function content($shorttext=false) {
}

if ($this->icon!==null) {
$icon = new html_image();
$icon->src = $this->icon;
$content = $OUTPUT->image($icon).' '.$content;
$icon = $OUTPUT->image($this->icon, array('alt'=>'', 'class'=>'icon'));
$content = $icon.$content; // use CSS for spacing of icons
} else if ($this->helpbutton!==null) {
$content = sprintf('%s<span class="clearhelpbutton">%s</span>',trim($this->helpbutton),$content);
}
Expand Down
11 changes: 1 addition & 10 deletions lib/outputcomponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -1424,15 +1424,6 @@ public function prepare(renderer_base $output, moodle_page $page, $target) {
$this->alt = HTML_ATTR_EMPTY;
}
}

/**
* Shortcut for initialising a html_image.
*
* @param mixed $url The URL to the image (string or moodle_url)
*/
public static function make($src) {
return new html_image($src);
}
}


Expand Down Expand Up @@ -2060,7 +2051,7 @@ public function __construct($helppage, $text, $component='moodle', $linktext=fal

$this->helppage = $helppage;
$this->text = $text;
$this->component = $module;
$this->component = $component;
$this->linktext = $linktext;

$this->link = new html_link();
Expand Down
20 changes: 13 additions & 7 deletions lib/outputrenderers.php
Original file line number Diff line number Diff line change
Expand Up @@ -1240,32 +1240,38 @@ public function spacer(array $options = null) {
/**
* Creates and returns an image.
*
* @param html_image|moodle_url|string $image_or_url image or url of the image
* @param html_image|moodle_url|string $image_or_url image or url of the image,
* it is also possible to use short pix name for core images
* @param array $options image attributes such as title, id, alt, widht, height
*
* @return string HTML fragment
*/
public function image($image_or_url, array $options = null) {
if ($image_or_url === false) {
return false;
if (empty($image_or_url)) {
throw new coding_exception('Empty $image_or_url value in $OUTPTU->image()');
}

if ($image_or_url instanceof html_image) {
$image = clone($image_or_url);
} else {
$image = new html_image($image_or_url, $options);
if (strpos($image_or_url, 'http')) {
$url = new moodle_url($image_or_url);
} else {
$url = $this->pix_url($image_or_url, 'moodle');
}
$image = new html_image($url, $options);
}

$image->prepare($this, $this->page, $this->target);

$this->prepare_event_handlers($image);

$attributes = array('class' => $image->get_classes_string(),
'src' => prepare_url($image->src),
'alt' => $image->alt,
'src' => prepare_url($image->src),
'alt' => $image->alt,
'style' => $image->style,
'title' => $image->title,
'id' => $image->id);
'id' => $image->id);

// do not use prepare_legacy_width_and_height() here,
// xhtml strict allows width&height and inline styles break theming too!
Expand Down

0 comments on commit b527063

Please sign in to comment.