We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34162
    • 1 Posts
    Ok first off this snippet works mostly but there is an issue with it. You have to add extra spaces to all the snippet calls or else modx strips them all out.

    I kind of dont understand this issue. I’m I’m trying to simply display data wh ywould it all be stripped out?

    You can see the snippet in action here:

    http://www.liquidthemes.com/theme-testing/wordpress-themes/greentrack.web

    and take note how all the snippet calls have extra spaces in them to allow them ot be left alone. I tried after the highliting to take the spaces back out but most of the snippets are still stripped out the funny thing is modx still leaves some of them alone.

    anyway maybe others looking at this can find a way arround the issue
    # DisplayTemplateCode - MODx - 2005-08-15
    # Created By: Brook Humphrey - [email protected]
    # Usage: [[DisplayTemplateCode?template=TemplateName]]
    #   If no tempalte is given then it will pull the template for the current page
    
    $output = "";
    
    # grab template from db.
    # If no template name is passed, use current page
    
    $table = $etomite->dbConfig['dbase'].".".$etomite->dbConfig['table_prefix'];
    
    if (!isset($template)) {
    
    $template = $etomite->documentObject['template'];
    $sql = "SELECT * FROM ".$table."site_templates WHERE id = ".$template;
    
    } else {
    
    $sql = "SELECT * FROM ".$table."site_templates WHERE templatename LIKE '%".$template."%'";
    
    }
    
    $result = $etomite->dbQuery($sql);
    $rowCount = $etomite->recordCount($result);
    
    if ( $rowCount!=1 ) $etomite->messageQuit("Incorrect number of templates returned from database", $sql);
    
    $row = $etomite->fetchRow($result);
    $documentSource = $row['content'];
    $documentSource = str_replace("[(", "[ (", $documentSource);
    $documentSource = str_replace("[[", "[ [", $documentSource);
    $documentSource = str_replace("[*", "[ *", $documentSource);
    $documentSource = str_replace("[~", "[ ~", $documentSource);
    $documentSource = str_replace("[^", "[ ^", $documentSource);
    
    # If template code is not found, display message
    if($documentSource == "") {
        $output = "Error -- " . $template . " is either an invalid name or is empty.";
    }
    # If template code exists, process it for display
    else {
        # Add PHP Begin and End tags and use highlight_string() to colorize the code
        $output = highlight_string("<?php\n\n".chr(13).$documentSource."\n\n?>", true);
    
        # Create an array containing the lines of code
        $temp = explode(chr(13), $output);
    
        # Calculate how many lines of code we have
        $limit = count($temp);
    
        # Open a fieldset to hold the snippet code or error message
        $output = "<fieldset><legend>$template</legend><font color='#000000'>";
    
        # Loop through array of formatted code, scrapping the first and last lines which have the PHP Begin and End tags
        for ($y = 1; $y < $limit-1; $y++) $output .= $temp[$y];
    
        # Insert some padding and close the fieldset
        $output .= "</font><br /><br /></fieldset>";
        #$output = str_replace("[ (", "[(", $output);
        #$output = str_replace("[ [", "[[", $output);
        #$output = str_replace("[ *", "[*", $output);
        #$output = str_replace("[ ~", "[~", $output);
        #$output = str_replace("[ ^", "[^", $output);
    }
    
    return $output;
    # END of Code


    oh and sorry it still says etomite but I know it’s working like it is and dont want to mess it up by changing a bunch of things right before i post it here without testing.
      • 18397
      • 3,250 Posts
      Try this to see what GeSHi - Generic Syntax Highlighter looks like for ModxCMS.com. GeSHi is better for HTML than the php highlighting because it is configurable. Here is the demo URL:

      http://qbnz.com/highlighter/demo.php?id=15784&lang=html4strict

      Plus it is ultra simple to use (per this demo on their site):
      // Simple GeSHi demo
      
      // Include the GeSHi library
      include('geshi.php');
      
      // Make a new GeSHi object, with the source, language and path set
      $source = 'echo "hello, world!";
      // weeeeee!!!!';
      $language = 'php';
      $path = 'geshi/';
      
      $geshi = new GeSHi($source, $language, $path);
      
      // and simply dump the code!
      echo $geshi->parse_code();
      
        • 34162
        • 1 Posts
        yes I’m aware of what geishi is. I actually had a mod installed on my phpbb cite that uses it but I found it to be a little to big and unwieldy. I don’t really care about he highlighting right now as there are other issues with modx that need to be dealt with. I may add something else later on for that part of it but it will most likely not be gieshi.
        • Bugs should be filed in the bug reporter... no guarantees they’ll ever get otherwise addressed. wink
            Ryan Thrash, MODX Co-Founder
            Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
            • 32963
            • 1,732 Posts
            Quote from: webmedic at Aug 16, 2005, 05:38 AM

            Ok first off this snippet works mostly but there is an issue with it. You have to add extra spaces to all the snippet calls or else modx strips them all out.

            Ok, this is by design. MODx will proccess those tags as if they where snippets.

            Use the HTML entities to replace some of the backets "["

            $source = str_replace('[','[',$source)
              xWisdom
              www.xwisdomhtml.com
              The fear of the Lord is the beginning of wisdom:
              MODx Co-Founder - Create and do more with less.
              • 34162
              • 1 Posts
              thanks I dont know why I didn’t think of that but what about when they copy and past for the page I bet they get the html entities and still have to modify the temaplte to get it to work.

              I’ll try it and let you know.

              I borrowed some code from another snippet and hopefully I will have a new version to show shortly that will also pull the css files and images and dispay them all for others to see. At least for now it works and is easy without having to codea whole downloads plugin just for this.