We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin Formatting

Development and Programming

Jason Bullard's avatar
Jason Bullard
55 posts
17 years ago
Jason Bullard's avatar Jason Bullard

All,

I was wondering if anyone knew how to properly unformat the passed in data. The problem I am experiencing is that when the data is sent to my plugin it contains all sort of linebreaks and paragraph breaks and I need a way to remove them.

I know I could change the formatting on the publish page but all other stuff within the post needs to remain the same. This plugin uses allow_eecode.

If you are wondering it is a plugin for the GeSHi Syntax Highlighter. The last situation that I am having is with this. I cannot use regular php functions to remove it as if it is html code then that would defeat the entire purpose.

Any thoughts on this???

Thanks, Jason

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Why does this plugin require the use of the Allow EE Code plugin? If you’re wanting to do something inline in a formatted custom field, e.g.:

This is custom field data.

[geshi]<?php echo 'highlight me!'; ?>[/geshi]

And the rest of the content, and so on...

You should really be creating an extension, not a plugin. Then you can syntax highlight the code that’s needed before any typography is performed on the field. Incidentally, that’s what I’m doing on my personal site. Feel free to test by leaving a comment, and instead of [code][/code], use any standard geshi language: [css][/css], [php][/php], [applescript][/applescript], etc.

       
Jason Bullard's avatar
Jason Bullard
55 posts
17 years ago
Jason Bullard's avatar Jason Bullard

Basically, what I have done is taken all of the variables that you can define inside of geshi and taken them into the post. So instead of having to configure all of the code the same way or even go into each language file to set certain styles it can be performed inside the post like below:

{exp:geshi lang="php" class="test" id ="test1" header_type="GESHI_HEADER_NONE" line_num_style="GESHI_FANCY_LINE_NUMBERS" line_num_start="10" line_style1="style"}

<?php echo ('hello'); ?>

{/exp:geshi}
       
Jason Bullard's avatar
Jason Bullard
55 posts
17 years ago
Jason Bullard's avatar Jason Bullard

Hit submit before I was done. 😊

I haven’t thought about an extension and haven’t really looked into that at all. I was hoping that I could do it this way with no problems. However, I am sure that I can transfer this into an extension format as well using regex.

I first created this using preg_match_all but that eventually got too much and slowed execution. This was the best method.

I will look into the extensions as well. Thanks for the idea. 😊

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Yeah, take a look, I think you’ll be pleasantly surprised. You can still provide parameters. In the example on my site, there are a number of things you can set as defaults in the Extension settings, and can override it individually by using parameters in your [php][/php] tags, parsed easily with the assistance of $FNS->assign_parameters() (a class, a line number, etc.)

I can say equivocally that a plugin that requires the Allow EE Code plugin to work is not the best of ideas, and would certainly prevent it from being included in the Add-on Library.

       
Jason Bullard's avatar
Jason Bullard
55 posts
17 years ago
Jason Bullard's avatar Jason Bullard

What should I be looking at as far as extension hooks? Am I going to have to create one for each different section (i.e. Forums, Weblog, etc)?

Thanks for the help. This looks like it is going to much better than what it started out as.

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

One extension with two hooks can handle it all, site-wide, by using typography_parse_type_start and typography_parse_type_end. Any module or content that uses Typography will be able to be trapped and modified by your extension. You’d want to handle the parsing in the “start” hook, and replace the actual content with temporary markers so that no Typography is performed on the content in the codeblock. The “end” hook you would replace your temporary markers with the pre-parsed cached content.

       
Jason Bullard's avatar
Jason Bullard
55 posts
17 years ago
Jason Bullard's avatar Jason Bullard

Derek,

I appreciate all the help and I was hoping that you could give me an example of a trypography extension. I have tried many different things and I can only get the EE tags to be returned. I know there has to be something that I am missing. Here is the base of what I have been experimenting with.

class GeSHi
{
    var $settings        = array();
    
    var $name        = 'GeSHi Syntax Highlighter';
    var $version        = '1.0.7.20';
    var $description    = 'Allows syntax highlighting within Expression Engine';
    var $settings_exist    = 'y';
    var $docs_url        = '';
    
    /* Constructor - Extensions use this for settings */
    function GeSHi($settings = '')
    {
        $this->settings = $settings;
    }
    //END
    
    // --------------------------------
    // Settings
    // --------------------------------
    
    function settings()
    {
    }
    
    // --------------------------------
    //  Activate Extension
    // --------------------------------

    function activate_extension()
    {
        global $DB;
        
        $DB->query($DB->insert_string('exp_extensions',
        array(
            'extension_id'    => '',
            'class'            => "geshi",
            'method'        => "test",
            'hook'            => "typography_parse_type_start",
        'settings'        => "",
        'priority'        => 10,
        'version'        => $this->version,
        'enabled'        => "y"
        )
        )
        );
    }
    // END

    // --------------------------------
    //  Disable Extension
    // --------------------------------

    function disable_extension()
    {
        global $DB;

        $DB->query("DELETE FROM exp_extensions WHERE class = 'geshi'");
    }
    // END
    
    function test()
    {
        global $DSP, $DB, $FNS, $SESS, $LANG, $PREFS, $REGX, $EXT, $IN, $TMPL;
        
        return $DSP->body;
    }
    
    function trim_code($_code)
    {
        $_code = preg_replace('/^\s*\n/siU', '', $_code);
        $_code = rtrim($_code);
        
        /* Return code */
        return $_code;
    }
}
       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Why are you using $DSP->body? The Display class is only used by the control panel; regardless your method needs to accept the arguments available to the hook. In this case that’s $str, $TYPE, and $prefs.

function test($str, $TYPE, $prefs)
{
    print_r($str);
    print_r($TYPE);
    print_r($prefs);
    exit;
}

Doing that will let you see what’s available to you. $str, modified or unmodified is what you need to return. And make sure you use $EXT->last_call in case a user has other extensions installed that also hook into the Typography class.

       
Kerim Satirli's avatar
Kerim Satirli
52 posts
17 years ago
Kerim Satirli's avatar Kerim Satirli
Incidentally, that’s what I’m doing on my personal site.

out of curiosity - is there any chance that you will release this plugin?

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones
Incidentally, that’s what I’m doing on my personal site.
out of curiosity - is there any chance that you will release this plugin?

I’m using an extension on my site, and designed it specific for my site’s use. It wouldn’t be suitable for general purpose usage without rewriting a few things. It’s something I do intend to do, but with our current development projects, I have not had time to do so.

       
Kerim Satirli's avatar
Kerim Satirli
52 posts
17 years ago
Kerim Satirli's avatar Kerim Satirli

thanks for the heads up, I think that this extension would be very welcomed by many people

       
Jason Bullard's avatar
Jason Bullard
55 posts
17 years ago
Jason Bullard's avatar Jason Bullard

I do have the intention on releasing this but have been gone for the past couple of months on business. Unfortunately, I haven’t had time to touch any of it. Let me look at it again and see if it is even ready to release (or at least beta).

The only problem I see right now is that the regex used to match words will match words inside of other words and I wanted to get that fixed before releasing it. However, I can go ahead and put up a beta version here.

It may not be today but I will make sure it is up by tomorrow. 😊

       
Kerim Satirli's avatar
Kerim Satirli
52 posts
17 years ago
Kerim Satirli's avatar Kerim Satirli
I do have the intention on releasing this but have been gone for the past couple of months on business. Unfortunately, I haven’t had time to touch any of it. Let me look at it again and see if it is even ready to release (or at least beta). The only problem I see right now is that the regex used to match words will match words inside of other words and I wanted to get that fixed before releasing it. However, I can go ahead and put up a beta version here. It may not be today but I will make sure it is up by tomorrow. 😊

oh - xmas presents one has an actual need for !

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.