]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-21198 $OUTPUT->icon() improvements
authorPetr Skoda <skodak@moodle.org>
Thu, 31 Dec 2009 10:06:56 +0000 (10:06 +0000)
committerPetr Skoda <skodak@moodle.org>
Thu, 31 Dec 2009 10:06:56 +0000 (10:06 +0000)
blog/external_blogs.php
blog/locallib.php
course/pending.php
course/report/outline/index.php
grade/lib.php
lib/navigationlib.php
lib/outputcomponents.php
lib/outputrenderers.php

index 9dc71676c5c6f8b4696e9bd82c35e725b4ae0ecd..c69f802868521d02f8313d659449d9471568407d 100644 (file)
@@ -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);
 }
index cc5384da20b895a42b2441cb7ee789fcfffeb4e8..9da02c7a83f12b8f5ccab64d908c4e212adb2aff 100644 (file)
@@ -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 .= "<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)));
                 }
             }
index 717239c206473badc8ed6d762d870cc3a7281b3a..ee534b234936d964442f7ef6ac6b07769c7002aa 100644 (file)
@@ -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);
index 1ffacc945a1f7b9a5ec3b8ece420c07650209cfd..2c9c32eb8a8f2d973d8981122f24120805991c9f 100644 (file)
             $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;
 
index 6eff54f1ecac57bb0375e64401aeee8a2c7d8a5f..d835ba9da492ce8a6a8c93d9b84a404868056dbf 100644 (file)
@@ -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';
index b0205da63ace1083e15c524d58b7d0758b24b2e0..c1e50e61951fe612a0c525771f2dddac26389a93 100644 (file)
@@ -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<span class="clearhelpbutton">%s</span>',trim($this->helpbutton),$content);
         }
index cbc5241223d06ab65eab20f772443dc89ef1953a..8572aa64437166fab7ee660ce199e43ae41145d0 100644 (file)
@@ -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();
index 949cce849791629b4db5f77ebb2f8e7e97ddc239..59df7501ce1760f4bb3ae2d5058dcfd05c2826a9 100644 (file)
@@ -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!