[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/question/format/qti2/ -> qt_common.php (source)

   1  <?php
   2  
   3  //***********************************
   4  // qt_common.php
   5  //***********************************
   6  // This contains code common to mediagonal-modified questions
   7  //
   8  
   9  /**
  10   * gets a list of all the media files for the given course
  11   *
  12   * @param int courseid
  13   * @return array containing filenames
  14   * @calledfrom type/<typename>/editquestion.php 
  15   * @package questionbank
  16   * @subpackage importexport
  17   */
  18  function get_course_media_files($courseid) 
  19  {
  20  // this code lifted from mod/quiz/question.php and modified
  21      global $CFG;
  22      $images = null;
  23      
  24      make_upload_directory("$course->id");    // Just in case
  25      $coursefiles = get_directory_list("$CFG->dataroot/$courseid", $CFG->moddata);
  26      foreach ($coursefiles as $filename) {
  27          if (is_media_by_extension($filename)) {
  28              $images["$filename"] = $filename;
  29          }
  30      }
  31      return $images;
  32  }    
  33  
  34  /**
  35   * determines whether or not a file is an image, based on the file extension
  36   *
  37   * @param string $file the filename
  38   * @return boolean
  39   */
  40  function is_image_by_extension($file) {
  41      $extensionsregex = '/\.(gif|jpg|jpeg|jpe|png|tif|tiff|bmp|xbm|rgb|svf)$/';
  42      if (preg_match($extensionsregex, $file)) {
  43          return true;
  44      }
  45      return false;
  46  }
  47  
  48  
  49  /**
  50   * determines whether or not a file is a media file, based on the file extension
  51   *
  52   * @param string $file the filename
  53   * @return boolean
  54   */
  55  function is_media_by_extension($file) {
  56      $extensionsregex = '/\.(gif|jpg|jpeg|jpe|png|tif|tiff|bmp|xbm|rgb|svf|swf|mov|mpg|mpeg|wmf|avi|mpe|flv|mp3|ra|ram)$/';
  57      if (preg_match($extensionsregex, $file)) {
  58          return true;
  59      }
  60      return false;
  61  }
  62  
  63  /**
  64   * determines whether or not a file is a multimedia file, based on the file extension
  65   *
  66   * @param string $file the filename
  67   * @return boolean
  68   */
  69  function is_multimedia_by_extension($file) {
  70      $extensionsregex = '/\.(swf|mov|mpg|mpeg|wmf|avi|mpe|flv)$/';
  71      if (preg_match($extensionsregex, $file)) {
  72          return true;
  73      }
  74      return false;
  75  }
  76  
  77  /**
  78   * determines whether or not a file is a multimedia file of a type php can get the dimension for, based on the file extension
  79   *
  80   * @param string $file the filename
  81   * @return boolean
  82   */
  83  function is_sizable_multimedia($file) {
  84      $extensionsregex = '/\.(swf)$/';
  85      if (preg_match($extensionsregex, $file)) {
  86          return true;
  87      }
  88      return false;
  89  }
  90  
  91  /**
  92   * creates a media tag to use for choice media
  93   *
  94   * @param string $file the filename
  95   * @param string $courseid the course id
  96   * @param string $alt to specify the alt tag
  97   * @return string either an image tag, or html for an embedded object 
  98   */
  99  function get_media_tag($file, $courseid = 0, $alt = 'media file', $width = 0, $height = 0) {
 100      global $CFG;
 101  
 102      // if it's a moodle library file, it will be served through file.php
 103      if (substr(strtolower($file), 0, 7) == 'http://') {
 104          $media = $file;
 105      } else {
 106          require_once($CFG->libdir.'/filelib.php');
 107          $media = get_file_url("$courseid/$file");
 108      }
 109  
 110      $ismultimedia = false;
 111      if (!$isimage = is_image_by_extension($file)) {
 112             $ismultimedia = is_multimedia_by_extension($file);
 113      }
 114      
 115      // if there is no known width and height, try to get one
 116      if ($width == 0) {
 117           if ($isimage || is_sizable_multimedia($file)) {
 118               
 119           }
 120          
 121      } 
 122      // create either an image link or a generic link.
 123      // if the moodle multimedia filter is turned on, it'll catch multimedia content in the generic link
 124      if (is_image_by_extension($file)) {
 125          return "<img src=\"$media\" alt=\"$alt\" width=\"$width\" height=\"$height\" />";
 126      }
 127      else {
 128          require_once("$CFG->dirroot/mod/quiz/format/qti/custommediafilter.php");
 129          return custom_mediaplugin_filter('<a href="' . $media . '"></a>', $courseid, $width, $height);
 130      }
 131  }
 132  
 133  /**
 134   * determines the x and y size of the given file
 135   *
 136   * @param string $file the filename 
 137   * @return array looks like array('x'=>171, 'y'=>323), or array('x'=>0, 'y'=>0) if size can't be determined
 138   */
 139  function get_file_dimensions($file) {
 140      $imginfo = @getimagesize($file);
 141      if ($imginfo !== FALSE) {
 142          return array('x'=>$imginfo[0], 'y'=>$imginfo[1]);
 143      } else {
 144          return array('x'=> 0, 'y'=> 0);
 145      }
 146  }
 147  
 148  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7