/** * Provide NULL and legacy file.php uses decoding */ public function process_cdata($cdata) { global $CFG; if ($cdata === '$@NULL@$') { // Some cases we know we can skip complete processing return null; } else { if ($cdata === '') { return ''; } else { if (is_numeric($cdata)) { return $cdata; } else { if (strlen($cdata) < 32) { // Impossible to have one link in 32cc return $cdata; // (http://10.0.0.1/file.php/1/1.jpg, http://10.0.0.1/mod/url/view.php?id=) } else { if (strpos($cdata, '$@FILEPHP@$') === false) { // No $@FILEPHP@$, nothing to convert return $cdata; } } } } } // Decode file.php calls $search = array("\$@FILEPHP@\$"); $replace = array(moodle_url::make_legacyfile_url($this->courseid, null)); $result = str_replace($search, $replace, $cdata); // Now $@SLASH@$ and $@FORCEDOWNLOAD@$ MDL-18799 $search = array('$@SLASH@$', '$@FORCEDOWNLOAD@$'); if ($CFG->slasharguments) { $replace = array('/', '?forcedownload=1'); } else { $replace = array('%2F', '&forcedownload=1'); } return str_replace($search, $replace, $result); }
function line_replace($line) { // return line after various formatting replacements // have been made - order is vital to stop them interfering with each other global $CFG; // ---- (at least) means a <hr /> // MARKDOWN: no change so leave // is this a list line (starts with * # ; :) if (preg_match("/^([*]+|[#]+|[;]+|[:]+) /i", $line)) { $line = $this->do_list($line); } // typographic conventions // MARKDOWN: no equiv. so convert to entity as before // $line = str_replace( "--", "—", $line ); // $line = str_replace( " - ", " – ", $line ); $line = str_replace("...", " … ", $line); $line = str_replace("(R)", "®", $line); $line = str_replace("(r)", "®", $line); $line = str_replace("(TM)", "™", $line); $line = str_replace("(tm)", "™", $line); $line = str_replace("(C)", "©", $line); $line = str_replace("1/4", "¼", $line); $line = str_replace("1/2", "½", $line); $line = str_replace("3/4", "¾", $line); $line = preg_replace("/([[:digit:]]+[[:space:]]*)x([[:space:]]*[[:digit:]]+)/i", "\\1×\\2", $line); // (digits) x (digits) - multiply // do formatting tags // NOTE: The / replacement *has* to be first, or it will screw the // HTML tags that are added by the other ones // MARKDOWN: only bold and italic change, rest are just HTML $line = $this->do_replace_markdown($line, "\\*", "**"); $line = $this->do_replace_markdown($line, "/", "*"); $line = $this->do_replace($line, "\\+", "ins"); // $line = $this->do_replace( $line, "-", "del" ); $line = $this->do_replace_sub($line, "~", "sub"); $line = $this->do_replace_sub($line, "\\^", "sup"); $line = $this->do_replace($line, "%", "code"); $line = $this->do_replace($line, "@", "cite"); // convert urls into proper link with optional link text URL(text) // MARDOWN: HTML conversion should work fine $line = preg_replace("/([[:space:]]|^)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])\\(([^)]+)\\)/i", "\\1[\\5](\\2://\\3\\4)", $line); $line = preg_replace("/([[:space:]])www\\.([^[:space:]]*)([[:alnum:]#?/&=])\\(([^)]+)\\)/i", "\\1[\\5](http://www.\\2\\3)", $line); // make urls (with and without httpd) into proper links $line = preg_replace("/([[:space:]]|^)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])/i", "\\1<\\2://\\3\\4>", $line); $line = preg_replace("/([[:space:]])www\\.([^[:space:]]*)([[:alnum:]#?/&=])/i", "\\1<http://www.\\2\\3\\>", $line); // make email addresses into mailtos.... // MARKDOWN doesn't quite support this, so do as html $line = preg_replace("/([[:space:]]|^)([[:alnum:]._-]+@[[:alnum:]._-]+)\\(([^)]+)\\)/i", "\\1<a href=\"mailto:\\2\">\\3</a>", $line); // !# at the beginning of any lines means a heading // MARKDOWN: value (1-6) becomes number of hashes if (preg_match("/^!([1-6]) (.*)\$/i", $line, $regs)) { $depth = substr($line, 1, 1); $out = substr('##########', 0, $depth); $line = preg_replace("/^!([1-6]) (.*)\$/i", "{$out} \\2", $line); } // acronym handing, example HTML(Hypertext Markyp Language) // MARKDOWN: no equiv. so just leave as HTML $line = preg_replace("/([A-Z]+)\\(([^)]+)\\)/", "<acronym title=\"\\2\">\\1</acronym>", $line); // Replace resource link >>##(Description Text) // MARKDOWN: change to MD web link style $line = preg_replace("/ ([a-zA-Z]+):([0-9]+)\\(([^)]+)\\)/i", " [\\3](" . $CFG->wwwroot . "/mod/\\1/view.php?id=\\2) ", $line); $coursefileurl = array(moodle_url::make_legacyfile_url($this->courseid, null)); // Replace picture resource link $line = preg_replace("#/([a-zA-Z0-9./_-]+)(png|gif|jpg)\\(([^)]+)\\)#i", "![\\3](" . $coursefileurl . "/\\1\\2)", $line); // Replace file resource link $line = preg_replace("#file:/([[:alnum:]/._-]+)\\(([^)]+)\\)#i", "[\\2](" . $coursefileurl . "/\\1)", $line); return $line; }