function question_find_file_links_from_html in Quiz 6.5
Same name and namespace in other branches
- 6.6 includes/moodle/lib/questionlib.php \question_find_file_links_from_html()
File
- includes/
moodle/ lib/ questionlib.php, line 2252
Code
function question_find_file_links_from_html($html, $courseid) {
global $CFG;
$baseurl = question_file_links_base_url($courseid);
$searchfor = '!' . '(<\\s*(a|img)\\s[^>]*(href|src)\\s*=\\s*")' . $baseurl . '([^"]*)"' . '|' . '(<\\s*(a|img)\\s[^>]*(href|src)\\s*=\\s*\')' . $baseurl . '([^\']*)\'' . '!i';
$matches = array();
$no = preg_match_all($searchfor, $html, $matches);
if ($no) {
$rawurls = array_filter(array_merge($matches[5], $matches[10]));
//array_filter removes empty elements
//remove any links that point somewhere they shouldn't
foreach (array_keys($rawurls) as $rawurlkey) {
if (!($cleanedurl = question_url_check($rawurls[$rawurlkey]))) {
unset($rawurls[$rawurlkey]);
}
else {
$rawurls[$rawurlkey] = $cleanedurl;
}
}
$urls = array_flip($rawurls);
// array_flip removes duplicate files
// and when we merge arrays will continue to automatically remove duplicates
}
else {
$urls = array();
}
return $urls;
}