static private function encode_links_helper($content, $name, $path) {
        global $CFG;
        // We want to convert both http and https links.
        $root = $CFG->wwwroot;
        $httpsroot = str_replace('http://', 'https://', $root);
        $httproot = str_replace('https://', 'http://', $root);

        $httpsbase = preg_quote($httpsroot . $path, '/');
        $httpbase = preg_quote($httproot . $path, '/');

        $return = preg_replace('/(' . $httpsbase . ')([0-9]+)/', '$@' . $name . '*$2@$', $content);
        $return = preg_replace('/(' . $httpbase . ')([0-9]+)/', '$@' . $name . '*$2@$', $return);

        return $return;
    }