Viewing structure through hyperlink filter

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

ChemAxon 7c2d26e5cf

09-01-2006 19:44:11

I am not a PHP expert and this PHP code is not clear for me.


Can you send me the source of the generated HTML code? (Select the "View->Page Source" menu item in the browser when the page is loaded then save the source into a file.)


It would be more helpful.


Probably there may be an error in the generating of the JavaScript code. The molecule source should be encoded if you insert it into a JavaScript code.


The following example demonstrates how you can do it: http://www.chemaxon.com/marvin/doc/dev/example-sketch3.2.html

User 25563e9c48

10-01-2006 17:35:37

Thanks for your suggestion. Yes I made a mistake and it now corrected. However, the structure is rendered in IE6 and not in opera. In opera a blank applet gets loaded and later it gives an error





java.io.IOException:file format not recognized #0





The same mol file or csmol files load correctly in IE6. The following is the part of the script that loads:





==============================================


<div class="clearer">&nbsp;</div>


<!-- END OF HEADER -->


<div id="content">


<table align="center" class="generalbox" border="0" cellpadding="20" cellspacing="0"><tr><td class="generalboxcontent"><script type="text/javascript" src="http://puchemistry.org/marvin/marvin.js"></script><p>This is testing<script type="text/javascript">;


msketch_begin("http://puchemistry.org/marvin","250", "250");


msketch_param("detach", "hide");


msketch_param("menubar", "false");


msketch_param("autoScale", "true");


msketch_param("reactionErrorVisible", "false");


msketch_param("mol", "http://puchemistry.org/course/file.php/15/mols-2d/dimethyl-octadien.csmol");


msketch_param("csmol","http://puchemistry.org/course/file.php/15/mols-2d/dimethyl-octadien.csmol");


msketch_param("rxn","http://puchemistry.org/course/file.php/15/mols-2d/dimethyl-octadien.csmol");


msketch_end();


</script></p><p /><p>1<script type="text/javascript">;


msketch_begin("http://puchemistry.org/marvin","250", "250");


msketch_param("detach", "hide");


msketch_param("menubar", "false");


msketch_param("autoScale", "true");


msketch_param("reactionErrorVisible", "false");


msketch_param("mol", "http://puchemistry.org/course/file.php/15/psilocybin.mol");


msketch_param("csmol","http://puchemistry.org/course/file.php/15/psilocybin.mol");


msketch_param("rxn","http://puchemistry.org/course/file.php/15/psilocybin.mol");


msketch_end();


</script></p></td></tr></table><center><p><font size="1">Last modified: Tuesday, 10 January 2006, 10:51 PM</font></p></center><br>


<br>


===========================================





Thanks for support

ChemAxon 7c2d26e5cf

10-01-2006 21:31:42

I have tried your example. Your molecules may be wrong. If your molecules are substituted with other ones in the example, both applets run fine.


By the way, there are not "csmol" and "rxn" parameters in Marvin.


Code:
msketch_begin("http://puchemistry.org/marvin","250", "250");


msketch_param("detach", "hide");


msketch_param("menubar", "false");


msketch_param("autoScale", "true");


msketch_param("reactionErrorVisible", "false");


//msketch_param("mol", "http://puchemistry.org/course/file.php/15/mols-2d/dimethyl-octadien.csmol");


msketch_param("mol","http://www.chemaxon.com/marvin/mols-2d/caffeine.csmol");


//msketch_param("csmol","http://puchemistry.org/course/file.php/15/mols-2d/dimethyl-octadien.csmol");


//msketch_param("rxn","http://puchemistry.org/course/file.php/15/mols-2d/dimethyl-octadien.csmol");


msketch_end();


</script></p><p /><p>1<script type="text/javascript">;


msketch_begin("http://puchemistry.org/marvin","250", "250");


msketch_param("detach", "hide");


msketch_param("menubar", "false");


msketch_param("autoScale", "true");


msketch_param("reactionErrorVisible", "false");


//msketch_param("mol", "http://puchemistry.org/course/file.php/15/psilocybin.mol");


msketch_param("mol","http://www.chemaxon.com/marvin/mols-2d/caffeine.mol");


//msketch_param("csmol","http://puchemistry.org/course/file.php/15/psilocybin.mol");


//msketch_param("rxn","http://puchemistry.org/course/file.php/15/psilocybin.mol");


msketch_end();

User 25563e9c48

11-01-2006 02:01:43

Thankyou Tamas,





I removed the unwanted entries. Still in OPERA browser I could not render my molecule in the applet. I copied fresh files also. The following the html code:





================


<div id="content">


<table align="center" class="generalbox" border="0" cellpadding="20" cellspacing="0"><tr><td class="generalboxcontent"><script type="text/javascript" src="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("autoScale", "true");


msketch_param("reactionErrorVisible", "false");


msketch_param("mol", "http://puchemistry.org/course/file.php/15/mols-2d/esterification.rxn");


msketch_end();


</script><a href="http://puchemistry.org/course/file.php/15/mols-2d/esterification.rxn" title="Download the molecular data file">Download</a></td></tr></table>


==========================================


The same settings work perfectly in IE6 on windows. However, I found that when I change to


msketch_param("mol","http://puchemistry.org/marvin/mols-2d/esterification.rxn");


the applet loads the file correctly in opera. Any suggestion?

User 25563e9c48

12-01-2006 01:51:22

Thanks for your support





I found the problem due to browser. I was trying with opera v9 beta mistakenly. I'll post the filter after incorporating all features in to that