We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5683
    • 96 Posts
    Hello,

    this collection includes and integrates three useful plugins for mathematicians, computer scientists etc. (you can use only those plugins you really need, of course):


    • The GeSHi plugin, to highlight source code in your document;
    • The mimeTeX plugin, to insert and render LaTeX code;
    • The Textile Plus plugin, to prepare easily the page content. Based on the Textile plugin by Raymond Irving and Jens Theess.

    The textile plugin is particularly important because Rich Text Editors don’t behave well with source code, and thus are not compatible with GeSHi and mimeTeX.

    The plugins are very efficient: they are invoked only when the webpage is retrieved from the database, and then a parsed version of the page is saved in cache.

    The package has everything you need, except the mimeTeX cgi program, that you can download from their website.

    For more information about these plugins, please refer to the forum threads where they were originally posted:


    A few more words about Textile Plus: there are a couple of differences with respect to the original Textile plugin, namely:



    • it parses only the [*content*] field of your document, and only when the page is retrieved from the database (for efficiency reasons: the parsed page is saved in cache);

    • it doesn’t parse the code enclosed into <textsafe>...</textsafe> tags. This is useful to insert raw code (e.g. HTML) inside a textile document. An additional plugin provided in the package automatically inserts GeSHi and mimeTeX code that occurs in <textile> mode into <textsafe> tags, and thanks to it Textile behaves nicely with GeSHi and mimeTeX.

    Here is the plugin code; let it listen to the OnLoadWebDocument event.

    // <?
    
    /**
     *	Textile AutoSafe Plugin 0.1 for MODx
     *	by Luca Allulli, April 2006
     *
     *	Event: OnLoadWebDocument
     *
     *	License: GNU GPL
     *
     */
     
    //Begin configuration
    //End configuration 
     
    
    
    function replaceTextileCloseTagsInternal($matches) {
    	return '<textsafe>'.$matches[1].'</textsafe>';
    }
    
    function replaceTextileCloseTags($matches) {
    
    	$modvar = preg_replace_callback("#(<pre[^>]*>.*?</pre>)#s", "replaceTextileCloseTagsInternal", $matches[1]);
    	$modvar = preg_replace_callback("#(\\$\\$.*?\\$\\$)#s", "replaceTextileCloseTagsInternal", $modvar);
    	
    	return '<textile>'.$modvar.'</textile>';
    }
    
    $e = &$modx->Event;
    
    
    switch ($e->name) {
    	case "OnLoadWebDocument":
    
    		$modx->documentObject['content']=preg_replace_callback("#<textile>(.*?)</textile>#s", "replaceTextileCloseTags", $modx->documentObject['content']);
    
    		break;
    		
    	default:	// stop here
    		break;	
    }
    
    /**
     *	Textile Plus Plugin 0.1 for MODx
     *	by Luca Allulli, April 2006
     *  Based on the Textile Plugin by Raymond Irving and Jens Theess
     *
     *	Event: OnLoadWebDocument
     *
     *	License: GNU GPL
     *
     */
     
    //Begin configuration
    //End configuration 
     
    
    function replaceCodeTextileHtml($matches) {
    	global $textileSafeCode;
    	global $textileSafeCodeCount;
    	if(!isset($textileSafeCodeCount))
    		$textileSafeCodeCount=0;
    	else
    		$textileSafeCodeCount++;
    	$textileSafeCode[$textileSafeCodeCount] = $matches[1];
    	return('<TextileSafeCode_'.$textileSafeCodeCount.'>');
    }
    
    function replaceCodeTextileHtmlBack($matches) {
    	global $textileSafeCode;
    	return $textileSafeCode[$matches[1]];
    }
    
    function replaceCodeTextile($matches) {
    	global $textileParser;
    	$modtext = preg_replace_callback("#<textsafe>(.*?)</textsafe>#s", "replaceCodeTextileHtml", $matches[1]);
    	$modtext = $textileParser -> TextileThis($modtext);
    	return preg_replace_callback("#\\<TextileSafeCode_([^>]*)>#s", "replaceCodeTextileHtmlBack", $modtext);
    }
    
    $modtext = preg_replace_callback("#<textsafe>(.*?)</textsafe>#s", "replaceCodeTextileHtml", $matches[1]);
    
    include_once($modx->config["base_path"].'/assets/plugins/textile/classTextile.php');
    global $textileParser;
    $textileParser = new Textile();
    $e = &$modx->Event;
    
    
    switch ($e->name) {
    	case "OnLoadWebDocument":
    
    		$modx->documentObject['content']=preg_replace_callback("#<textile>(.*?)</textile>#s", "replaceCodeTextile", $modx->documentObject['content']);
    
    		break;
    		
    	default:	// stop here
    		break;	
    }
    
    
    
    /**
     *	GeSHi Plugin 0.4 for MODx
     *	by Luca Allulli, March 2006
     *
     *	Event: OnLoadWebDocument
     *
     *	Based on the GeSHi highlighter at http://qbnz.com/highlighter/
     *
     *	License: GNU GPL
     *
     */
    
    
    //Begin configuration
      global $defaultGeshiLang;
    	$defaultGeshiLang="java5";
    //End configuration 
     
    function replaceCodeBase($lang, $code) {
    	global $modx;
    	$path = $modx->config["base_path"].'assets/plugins/geshi/geshi/';
    	$geshi = new GeSHi($code, $lang, $path);
    	$geshi->set_header_type(GESHI_HEADER_PRE);
    	$geshi->set_tab_width(4);
    	return '<table width="100%"><tr><td>'.$geshi->parse_code().'</td></tr></table>';
    }
    
    function replaceCode($matches) {
    	global $defaultGeshiLang;
    	return replaceCodeBase($defaultGeshiLang, $matches[1]);
    }
    
    function replaceCodeLang($matches) {
    	return replaceCodeBase($matches[1], $matches[2]);
    }
    
    
    $e = &$modx->Event;
    
    
    switch ($e->name) {
    	case "OnLoadWebDocument":
    
    		include_once($modx->config["base_path"].'assets/plugins/geshi/geshi.php');
    
    		$modx->documentObject['content']=preg_replace_callback("#<pre>(.*?)</pre>#s", "replaceCode", $modx->documentObject['content']);
    
    		$modx->documentObject['content']=preg_replace_callback("#<pre language=\"([^\"]*)\">(.*?)</pre>#s", "replaceCodeLang", $modx->documentObject['content']);
    
    		break;
    		
    	default:	// stop here
    		break;	
    }
    
    
    /**
     *	mimeTeX Plugin 0.1 for MODx
     *	by Luca Allulli, April 2006
     *
     *	Event: OnLoadWebDocument
     *
     *	Download and install mimeTeX from http://www.forkosh.com/mimetex.html
     *
     *	License: GNU GPL
     *
     */
     
    //Begin configuration
    	global $mimetexPath;
    	$mimetexPath="/cgi-bin/mimetex.cgi";
    //End configuration 
     
    
    function replaceCodeMimetex($matches) {
    	global $mimetexPath;
    	return '<img src="'.$mimetexPath.'?'.$matches[1].'" align="middle" style="margin-bottom: 7px;" />';
    }
    
    
    $e = &$modx->Event;
    
    
    switch ($e->name) {
    	case "OnLoadWebDocument":
    
    		$modx->documentObject['content']=preg_replace_callback("#\\$\\$(.*?)\\$\\$#s", "replaceCodeMimetex", $modx->documentObject['content']);
    
    		break;
    		
    	default:	// stop here
    		break;	
    }
    
    // ?>
    
      • 6726
      • 7,075 Posts
      Very nice !
      Personnally, Textile Plus is the most interresting to me, I’ll give this a look !

      Thanks laugh
        .: COO - Commerce Guys - Community Driven Innovation :.


        MODx est l&#39;outil id
        • 21471
        • 42 Posts
        With the code and the file attached, it’s not

        include_once($modx->config["base_path"].'/assets/plugins/textile/textile.php');


        but

        include_once($modx->config["base_path"].'/assets/plugins/textile/classTextile.php


        2nd question : we still have to add <textile> tags in content area, right (or to do <textile>[*content*]</textile> in template) ? Otherwise textile looks not interpreted (or I missed something somewhere)
          • 5683
          • 96 Posts
          Quote from: NiCoS at Jul 04, 2006, 03:00 PM

          With the code and the file attached, it’s not

          include_once($modx->config["base_path"].'/assets/plugins/textile/textile.php');


          but

          include_once($modx->config["base_path"].'/assets/plugins/textile/classTextile.php

          Actually, the first include_once is useless: it is a leftover from copy-and-paste, from the real textile plugin to the textile_autosafe one. You can remove it completely. I’m removing it too. Thank you! smiley
          The useful include_once (classTextile.php) is still present in the textie part.

          Quote from: NiCoS at Jul 04, 2006, 03:00 PM

          2nd question : we still have to add <textile> tags in content area, right (or to do <textile>[*content*]</textile> in template) ? Otherwise textile looks not interpreted (or I missed something somewhere)
          Yes, you have to add <textile>...</textile> in the content.
          Notice that you cannot add it to the template because, in order to improve performance, this plugin is evaluated only on the content, before caching occurs (so that documents retrieved from cache don’t need to be parsed again!). If you prefer to parse the entire page, you have make a bunch of changes:

          • catch the "OnWebPagePrerender" event, instead of "OnLoadWebDocument". This involves modifying the setting in the System Event tab in the manager, and the "case" strings in all the "switch"es in the code
          • replace "$modx->documentObject[’content’]" with "$modx->documentOutput" in the code

          Instead, if you want to enable textile on the whole document content without having to type <textile>...</textile>, it should be sufficient to replace line 93:
          $modx->documentObject['content']=preg_replace_callback("#<textile>(.*?)</textile>#s", "replaceCodeTextile", $modx->documentObject['content']);
          

          with this one (not tested!)
          $modx->documentObject['content']=replaceCodeTextile(array("dummy", $modx->documentObject['content']));
          
            • 21471
            • 42 Posts
            Quote from: Commodore64 at Jul 06, 2006, 07:53 AM


            • catch the "OnWebPagePrerender" event, instead of "OnLoadWebDocument". This involves modifying the setting in the System Event tab in the manager, and the "case" strings in all the "switch"es in the code
            • replace "$modx->documentObject[’content’]" with "$modx->documentOutput" in the code

            You mean : I should replace all of "$modx->documentObject[’content’]" by "$modx->documentOutput" within textile section of the plugin. (I mean line 38 & 95 ?)
              • 5683
              • 96 Posts
              Quote from: NiCoS at Jul 12, 2006, 02:54 PM

              You mean : I should replace all of "$modx->documentObject[’content’]" by "$modx->documentOutput" within textile section of the plugin. (I mean line 38 & 95 ?)
              Yes, but not only in the textile section: in the whole plugin.
              Morover, change all occurrences of
              case "OnLoadWebDocument":

              to
              case "OnWebPagePrerender":

                • 21471
                • 42 Posts
                Ok, thanks for your answer, I’ll try tonight smiley