Exemplo n.º 1
0
/**
 * creates a media tag to use for choice media
 *
 * @param string $file the filename
 * @param string $courseid the course id
 * @param string $alt to specify the alt tag
 * @return string either an image tag, or html for an embedded object 
 */
function get_media_tag($file, $courseid = 0, $alt = 'media file', $width = 0, $height = 0)
{
    global $CFG;
    // if it's a moodle library file, it will be served through file.php
    if (substr(strtolower($file), 0, 7) == 'http://') {
        $media = $file;
    } else {
        require_once $CFG->libdir . '/filelib.php';
        $media = get_file_url("{$courseid}/{$file}");
    }
    $ismultimedia = false;
    if (!($isimage = is_image_by_extension($file))) {
        $ismultimedia = is_multimedia_by_extension($file);
    }
    // if there is no known width and height, try to get one
    if ($width == 0) {
        if ($isimage || is_sizable_multimedia($file)) {
        }
    }
    // create either an image link or a generic link.
    // if the moodle multimedia filter is turned on, it'll catch multimedia content in the generic link
    if (is_image_by_extension($file)) {
        return "<img src=\"{$media}\" alt=\"{$alt}\" width=\"{$width}\" height=\"{$height}\" />";
    } else {
        require_once "{$CFG->dirroot}/mod/quiz/format/qti/custommediafilter.php";
        return custom_mediaplugin_filter('<a href="' . $media . '"></a>', $courseid, $width, $height);
    }
}
 /**
  * sets mimetype, width, and height fields for the media object
  *
  * @param object $mediaobject (passed object will be changed)
  * @param string $courseid the course id
  * @param string $mediapath = null the media file url or local path (can be ommitted if this info is in $mediaobject->media)
  * @author brian@mediagonal.ch
  */
 function set_mediainfo(&$mediaobject, $courseid, $mediapath = null)
 {
     if (is_null($mediapath)) {
         if (isset($mediaobject->media)) {
             $mediapath = $mediaobject->media;
         } else {
             // can't do anything without a mediapath
             return;
         }
     }
     if (!empty($mediaobject)) {
         global $CFG;
         require_once $CFG->dirroot . '/question/format/qti2/qt_common.php';
         require_once $CFG->libdir . '/filelib.php';
         $mediaobject->mimetype = mimeinfo('type', $mediapath);
         // hw: workaround for bug (typo) in /question/format/qti2/qt_common.php
         // I opened a bugtracker because of this...
         $is_img = false;
         if (function_exists('is_image_by_extension')) {
             $is_img = is_image_by_extension($mediapath);
         } else {
             $is_img = is_image_by_extentsion($mediapath);
         }
         if ($is_img || is_sizable_multimedia($mediapath)) {
             $islocalfile = substr(strtolower($mediapath), 0, 7) == 'http://' ? false : true;
             if ($islocalfile) {
                 $mediapath = "{$CFG->dataroot}/{$courseid}/{$mediapath}";
             }
             $dimensions = get_file_dimensions($mediapath);
             $mediaobject->width = $dimensions['x'];
             $mediaobject->height = $dimensions['y'];
         }
     }
 }