foreach ($blogs as $blog) {
if ($blog->failedlastsync) {
- $validicon = $OUTPUT->image('i/cross_red_big', array('alt'=>get_string('feedisinvalid', 'blog'), 'title'=>get_string('feedisinvalid', 'blog')));
+ $validicon = $OUTPUT->pix_icon('i/cross_red_big', get_string('feedisinvalid', 'blog'));
} else {
- $validicon = $OUTPUT->image('i/tick_green_big', array('alt'=>get_string('feedisvalid', 'blog'), 'title'=>get_string('feedisvalid', 'blog')));
+ $validicon = $OUTPUT->pix_icon('i/tick_green_big', get_string('feedisvalid', 'blog'));
}
$editurl = new moodle_url('/blog/external_blog_edit.php', array('id' => $blog->id));
$icon = substr(mimeinfo_from_type("icon", $mimetype), 0, -4);
$type = mimeinfo_from_type("type", $mimetype);
- $image = $OUTPUT->image("/f/$icon", array('alt'=>$filename, 'class'=>'icon'));
+ $image = $OUTPUT->pix_icon("/f/$icon", $filename, 'moodle', array('class'=>'icon'));
if ($return == "html") {
- $output .= html_writer::link($ffurl, $OUTPUT->image($image));
+ $output .= html_writer::link($ffurl, $image);
$output .= html_writer::link($ffurl, $filename);
} else if ($return == "text") {
} else {
if (in_array($type, array('image/gif', 'image/jpeg', 'image/png'))) { // Image attachments don't get printed as links
- $image = $OUTPUT->image($ffurl, array('alt'=>$filename));
- $imagereturn .= "<br />" . $OUTPUT->image($image);
+ $imagereturn .= "<br />" . $OUTPUT->pix_icon($ffurl, $filename);
} else {
$imagereturn .= html_writer::link($ffurl, $image);
$imagereturn .= filter_text(html_writer::link($ffurl, $filename));
$strrequireskey = get_string('requireskey');
// Loop over requested courses.
- $keyicon = $OUTPUT->image('i/key', array('alt'=>$strrequireskey, 'class'=>'icon'));
+ $keyicon = $OUTPUT->pix_icon('i/key', $strrequireskey, 'moodle', array('class'=>'icon'));
foreach ($pending as $course) {
$course = new course_request($course);
$activitycell = new html_table_cell();
$activitycell->add_class('activity');
- $activityicon = $OUTPUT->image($OUTPUT->pix_url('icon', $cm->modname), array('alt'=>$modulename, 'class'=>'icon'));
+ $activityicon = $OUTPUT->pix_icon('icon', $modulename, $cm->modname, array('class'=>'icon'));
$attributes = array();
if (!$cm->visible) {
$strparamobj->itemname = $element['object']->grade_item->itemname;
$strnonunlockable = get_string('nonunlockableverbose', 'grades', $strparamobj);
- $action = $OUTPUT->image('t/unlock_gray', array('alt'=>$strnonunlockable, 'title'=>$strnonunlockable, 'class'=>'iconsmall'));
+ $action = $OUTPUT->pix_icon('t/unlock_gray', $strnonunlockable);
} else if ($element['object']->is_locked()) {
$type = 'unlock';
*
*/
function print_png() {
- throw new coding_exception('print_png() has been deprecated since Moodle 2.0. Please use $OUTPUT->image() instead.');
+ throw new coding_exception('print_png() has been deprecated since Moodle 2.0. Please use $OUTPUT->pix_icon() instead.');
}
}
if ($this->icon!==null) {
- $icon = $OUTPUT->image($this->icon, array('alt'=>'', 'class'=>'icon'));
+ $icon = $OUTPUT->pix_icon($this->icon, '', 'moodle', array('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);
}
+/**
+ * Data structure representing an icon.
+ *
+ * @copyright 2010 Petr Skoda
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @since Moodle 2.0
+ */
+class pix_icon implements renderable {
+ var $pix;
+ var $component;
+ var $attributes = array();
+
+ /**
+ * Constructor
+ * @param string $pix short icon name
+ * @param string $component component name
+ * @param array $attributes html attributes
+ */
+ public function __construct($pix, $alt, $component='moodle', array $attributes = null) {
+ $this->icon = $pix;
+ $this->compondent = $component;
+ $this->attributes = (array)$attributes;
+
+ $this->attributes['alt'] = $alt;
+ if (empty($this->attributes['class'])) {
+ $this->attributes['class'] = 'smallicon';
+ }
+ if (!isset($this->attributes['title'])) {
+ $this->attributes['title'] = $this->attributes['alt'];
+ }
+ }
+}
+
+
/**
* Data structure representing a simple form with only one button.
*
public function doc_link($path, $text) {
global $CFG;
- $options = array('class'=>'iconhelp', 'alt'=>$text);
- $url = new moodle_url(get_docs_url($path));
+ $icon = $this->pix_icon('docs', $text, 'moodle', array('class'=>'iconhelp'));
- $icon = $this->image('docs', $options);
+ $url = new moodle_url(get_docs_url($path));
$link = new html_link($url, $icon.$text);
return $this->link($link);
}
+ /**
+ * Render icon
+ * @param string $pix short pix name
+ * @param string $alt mandatory alt attribute
+ * @param strin $component standard compoennt name like 'moodle', 'mod_form', etc.
+ * @param array $attributes htm lattributes
+ * @return string HTML fragment
+ */
+ public function pix_icon($pix, $alt, $component='moodle', array $attributes = null) {
+ $icon = new pix_icon($pix, $alt, $component, $attributes);
+ return $this->render($icon);
+ }
+
+ /**
+ * Render icon
+ * @param pix_icon $icon
+ * @return string HTML fragment
+ */
+ public function render_icon(pix_icon $icon) {
+ $attributes = $icon->attributes;
+ $attributes['src'] = $this->pix_url($icon->pix, $icon->component);
+ return html_writer::empty_tag('img', $atrributes);
+ }
+
/**
* Given a moodle_action_icon object, outputs an image linking to an action (URL or AJAX).
*
}
// Build the icon.
- $image = $OUTPUT->image($OUTPUT->pix_url('t/preview'), array('class'=>'iconsmall', 'alt'=>$strpreviewquestion));
+ $image = $OUTPUT->pix_icon('t/preview', $strpreviewquestion);
$link = new html_link($CFG->wwwroot."/question/preview.php?id=$question->id&quizid=$quiz->id", $image, array('title' => $strpreviewquestion));
parse_str(QUESTION_PREVIEW_POPUP_OPTIONS, $options);
global $OUTPUT;
if (question_has_capability_on($question, 'use')) {
// Build the icon.
- $image = $OUTPUT->image($OUTPUT->pix_url('t/preview'), array('class'=>'iconsmall', 'alt'=>$this->strpreview));
+ $image = $OUTPUT->pix_icon('t/preview', $this->strpreview);
$link = new html_link($this->qbank->preview_question_url($question->id), $image, array('title' => $this->strpreview));
parse_str(QUESTION_PREVIEW_POPUP_OPTIONS, $options);