You are here

function hotpot_convert_relative_url in Quiz 6.5

Same name and namespace in other branches
  1. 6.6 includes/moodle/question/format/hotpot/format.php \hotpot_convert_relative_url()

File

includes/moodle/question/format/hotpot/format.php, line 701

Code

function hotpot_convert_relative_url($baseurl, $filename, $opentag, $url, $closetag, $stripslashes = true) {
  if ($stripslashes) {
    $opentag = stripslashes($opentag);
    $url = stripslashes($url);
    $closetag = stripslashes($closetag);
  }

  // catch <PARAM name="FlashVars" value="TheSound=soundfile.mp3">
  //    ampersands can appear as "&", "&amp;" or "&amp;#x0026;amp;"
  if (preg_match('|^' . '\\w+=[^&]+' . '(' . '&((amp;#x0026;)?amp;)?' . '\\w+=[^&]+)*' . '$|', $url)) {
    $query = $url;
    $url = '';
    $fragment = '';

    // parse the $url into $matches
    //    [1] path
    //    [2] query string, if any
    //    [3] anchor fragment, if any
  }
  else {
    if (preg_match('|^' . '([^?]*)' . '((?:\\?[^#]*)?)' . '((?:#.*)?)' . '$|', $url, $matches)) {
      $url = $matches[1];
      $query = $matches[2];
      $fragment = $matches[3];

      // there appears to be no query or fragment in this url
    }
    else {
      $query = '';
      $fragment = '';
    }
  }
  if ($url) {
    $url = hotpot_convert_url($baseurl, $filename, $url, false);
  }
  if ($query) {
    $search = '#' . '(file|src|thesound)=' . "([^&]+)" . '#ise';
    $replace = "'\\1='.hotpot_convert_url('" . $baseurl . "','" . $filename . "','\\2')";
    $query = preg_replace($search, $replace, $query);
  }
  $url = $opentag . $url . $query . $fragment . $closetag;
  return $url;
}