From b1db3c901802e15ff76512805d992cc7e9b4c9ad Mon Sep 17 00:00:00 2001 From: gbateson Date: Fri, 7 Oct 2005 01:56:33 +0000 Subject: [PATCH] add get_file_contents for php<4.2, use get_file_contents($filepath) instead of fread($fp, filesize($filepath)) --- mod/hotpot/lib.php | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/mod/hotpot/lib.php b/mod/hotpot/lib.php index cdadc95dd4c..baf8d3aae47 100644 --- a/mod/hotpot/lib.php +++ b/mod/hotpot/lib.php @@ -569,11 +569,8 @@ function hotpot_get_titles_and_next_ex(&$hp, $filepath, $get_next=false) { $hp->exercisesubtitle = ''; $hp->nextexercise = ''; - // open the quiz file - if ($fp = @fopen($filepath, 'r')) { - - $source = fread($fp, filesize($filepath)); - fclose($fp); + // read the quiz file source + if ($source = file_get_contents($filepath)) { $next = ''; $title = ''; @@ -1392,7 +1389,7 @@ class hotpot_xml_quiz extends hotpot_xml_tree { // read the file, if required if ($this->read_file) { - if (!file_exists($this->filepath) || !$fp = fopen($this->filepath, 'r')) { + if (!file_exists($this->filepath) || !is_readable($this->filepath)) { $this->error = get_string('error_couldnotopensourcefile', 'hotpot', $this->filepath); if ($this->report_errors) { error($this->error, $this->course_homeurl); @@ -1400,9 +1397,8 @@ class hotpot_xml_quiz extends hotpot_xml_tree { return; } - // read in the XML source and close the file - $this->source = fread($fp, filesize($this->filepath)); - fclose($fp); + // read in the XML source + $this->source = file_get_contents($this->filepath); // convert relative URLs to absolute URLs if ($this->convert_urls) { @@ -1429,16 +1425,6 @@ class hotpot_xml_quiz extends hotpot_xml_tree { $replace = "hotpot_convert_navbutton_url('".$this->get_baseurl()."','".$this->reference."','\\1','".$this->course."')"; $this->source = preg_replace($search, $replace, $this->source); - // remove leading ]*> - // remove leading ]*> - // remove leading - - // prepend initial tag if required (JCloze HP5) - //if (preg_match('|\s*$|i', $this->source) && !preg_match('|^]*>|i', $this->source)) { - // $this->source = ''.$this->source; - //} - - } else { if ($this->parse_xml) { @@ -2121,6 +2107,16 @@ function hotpot_string_id($str) { return $id; } +if (!function_exists('file_get_contents')) { + // add this function for php version<4.3 + function file_get_contents($filepath) { + $contents = file($filepath); + if (is_array($contents)) { + $contents = implode('', $contents); + } + return $contents; + } +} if (!function_exists('html_entity_decode')) { // add this function for php version<4.3 function html_entity_decode($str) {