User 25563e9c48
09-01-2006 06:40:21
I'm trying to create a filter for our LMS (Moodle) to render mol/csmol/xyz/rxn files through a hyperlink. I followed the follwing procedures:
1. copied the marvin binary files (4.0.3) to http://localhost/marvin
2.generated a filter file 'filter.php' at the appropriate location in my moodle directory with the following codes:
<?php // $id$
/// This is the filtering function itself. It accepts the
/// courseid and the text to be filtered (in HTML form).
function marvin_filter($courseid, $text) {
global $CFG, $PHP_SELF, $filter_marvin_has_initialized;
// hoping that marvin is initialized only once
// we convert our full URL to a relative URL.
// Otherwise it displays a warning message and refuses to run!
$u = $CFG->wwwroot;
if(preg_match('|https?://.*?/|', $u)){
$relurl = preg_replace('|https?://.*?/|', '', $u);
}else{
$relurl = ''; // This will typically be the case if Moodle is the web root
}
$numdirs = substr_count($PHP_SELF, '/') - 1;
if($numdirs==0){
$relurl = './' . $relurl;
}else{
$relurl = str_repeat('../', $numdirs) . $relurl;
}
$search = '/<a(.*?)href=\"([^\"]+\.(mol|csmol|rxn))\"([^>]*)>(.*?)<\/a>/is';
$replace = '<script type="text/javascript">;
msketch_param("mol", "load \\2.mol");
msketch_end();
</script><a href="\\2" title="Download the molecular data file">Download</a>';
$newtext = preg_replace($search, $replace, $text);
// Download is to test whether the mol file is read or not.
// loading marvin.js to load only once in a page and use the same for all hyper links!
if(($newtext != $text) && !isset($filter_marvin_has_initialized)){
$filter_marvin_has_initialized = true;
$newtext = '<script type="text/javascript" src="' . $relurl . 'http://puchemistry.org/marvin/marvin.js"></script>'
. '<script type="text/javascript">
msketch_begin("http://puchemistry.org/marvin/","250", "250");
msketch_param("detach", "hide");
msketch_param("menubar", "false");
msketch_param("reactionErrorVisible", "false");
msketch_param("autoScale", "true");
</script>'
. $newtext;
}
return $newtext;
}
?>
However, when I create a hyperlink for a mol/csmol/rxn file, I get a blank applet with all features enabled. I could not load my hyperlinked file at all. I could not figure out my mistake in my code.
Can somebody help me in this regard?
Thank you for your support
1. copied the marvin binary files (4.0.3) to http://localhost/marvin
2.generated a filter file 'filter.php' at the appropriate location in my moodle directory with the following codes:
<?php // $id$
/// This is the filtering function itself. It accepts the
/// courseid and the text to be filtered (in HTML form).
function marvin_filter($courseid, $text) {
global $CFG, $PHP_SELF, $filter_marvin_has_initialized;
// hoping that marvin is initialized only once
// we convert our full URL to a relative URL.
// Otherwise it displays a warning message and refuses to run!
$u = $CFG->wwwroot;
if(preg_match('|https?://.*?/|', $u)){
$relurl = preg_replace('|https?://.*?/|', '', $u);
}else{
$relurl = ''; // This will typically be the case if Moodle is the web root
}
$numdirs = substr_count($PHP_SELF, '/') - 1;
if($numdirs==0){
$relurl = './' . $relurl;
}else{
$relurl = str_repeat('../', $numdirs) . $relurl;
}
$search = '/<a(.*?)href=\"([^\"]+\.(mol|csmol|rxn))\"([^>]*)>(.*?)<\/a>/is';
$replace = '<script type="text/javascript">;
msketch_param("mol", "load \\2.mol");
msketch_end();
</script><a href="\\2" title="Download the molecular data file">Download</a>';
$newtext = preg_replace($search, $replace, $text);
// Download is to test whether the mol file is read or not.
// loading marvin.js to load only once in a page and use the same for all hyper links!
if(($newtext != $text) && !isset($filter_marvin_has_initialized)){
$filter_marvin_has_initialized = true;
$newtext = '<script type="text/javascript" src="' . $relurl . 'http://puchemistry.org/marvin/marvin.js"></script>'
. '<script type="text/javascript">
msketch_begin("http://puchemistry.org/marvin/","250", "250");
msketch_param("detach", "hide");
msketch_param("menubar", "false");
msketch_param("reactionErrorVisible", "false");
msketch_param("autoScale", "true");
</script>'
. $newtext;
}
return $newtext;
}
?>
However, when I create a hyperlink for a mol/csmol/rxn file, I get a blank applet with all features enabled. I could not load my hyperlinked file at all. I could not figure out my mistake in my code.
Can somebody help me in this regard?
Thank you for your support