From: Petr Skoda Date: Thu, 31 Dec 2009 10:06:56 +0000 (+0000) Subject: MDL-21198 $OUTPUT->icon() improvements X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=b52706307c51b920869fb4dd3a2d6a52b68b03d1;p=moodle.git MDL-21198 $OUTPUT->icon() improvements --- diff --git a/blog/external_blogs.php b/blog/external_blogs.php index 9dc71676c5..c69f802868 100644 --- a/blog/external_blogs.php +++ b/blog/external_blogs.php @@ -73,13 +73,9 @@ if (!empty($blogs)) { 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; @@ -95,7 +91,7 @@ if (!empty($blogs)) { $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); } diff --git a/blog/locallib.php b/blog/locallib.php index cc5384da20..9da02c7a83 100644 --- a/blog/locallib.php +++ b/blog/locallib.php @@ -498,10 +498,7 @@ class blog_entry { $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))); @@ -512,12 +509,10 @@ class blog_entry { } 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 .= "
" . $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))); } } diff --git a/course/pending.php b/course/pending.php index 717239c206..ee534b2349 100644 --- a/course/pending.php +++ b/course/pending.php @@ -106,11 +106,7 @@ if (empty($pending)) { $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); diff --git a/course/report/outline/index.php b/course/report/outline/index.php index 1ffacc945a..2c9c32eb8a 100644 --- a/course/report/outline/index.php +++ b/course/report/outline/index.php @@ -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; diff --git a/grade/lib.php b/grade/lib.php index 6eff54f1ec..d835ba9da4 100644 --- a/grade/lib.php +++ b/grade/lib.php @@ -1552,11 +1552,7 @@ class grade_structure { $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'; diff --git a/lib/navigationlib.php b/lib/navigationlib.php index b0205da63a..c1e50e6195 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -411,9 +411,8 @@ class navigation_node { } 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%s',trim($this->helpbutton),$content); } diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index cbc5241223..8572aa6443 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -1424,15 +1424,6 @@ class html_image extends labelled_html_component { $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); - } } @@ -2060,7 +2051,7 @@ class help_icon extends html_image { $this->helppage = $helppage; $this->text = $text; - $this->component = $module; + $this->component = $component; $this->linktext = $linktext; $this->link = new html_link(); diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 949cce8497..59df7501ce 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -1240,20 +1240,26 @@ class core_renderer extends renderer_base { /** * 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); @@ -1261,11 +1267,11 @@ class core_renderer extends renderer_base { $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!