Plugin Formatting
Posted: 28 August 2007 09:01 AM   [ Ignore ]  
Grad Student
Rank
Total Posts:  79
Joined  02-18-2007

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

Profile
 
 
Posted: 28 August 2007 09:49 AM   [ Ignore ]   [ # 1 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  11303
Joined  06-03-2002

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.

 Signature 
Profile
MSG
 
 
Posted: 28 August 2007 10:11 AM   [ Ignore ]   [ # 2 ]  
Grad Student
Rank
Total Posts:  79
Joined  02-18-2007

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} 
Profile
 
 
Posted: 28 August 2007 10:13 AM   [ Ignore ]   [ # 3 ]  
Grad Student
Rank
Total Posts:  79
Joined  02-18-2007

Hit submit before I was done.  smile

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.  smile

Profile
 
 
Posted: 28 August 2007 10:42 AM   [ Ignore ]   [ # 4 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  11303
Joined  06-03-2002

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.

 Signature 
Profile
MSG
 
 
Posted: 28 August 2007 11:34 AM   [ Ignore ]   [ # 5 ]  
Grad Student
Rank
Total Posts:  79
Joined  02-18-2007

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.

Profile
 
 
Posted: 28 August 2007 11:42 AM   [ Ignore ]   [ # 6 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  11303
Joined  06-03-2002

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.

 Signature 
Profile
MSG
 
 
Posted: 30 August 2007 02:39 AM   [ Ignore ]   [ # 7 ]  
Grad Student
Rank
Total Posts:  79
Joined  02-18-2007

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;
    
}
Profile
 
 
Posted: 30 August 2007 07:35 AM   [ Ignore ]   [ # 8 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  11303
Joined  06-03-2002

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.

 Signature 
Profile
MSG
 
 
Posted: 22 December 2007 06:14 AM   [ Ignore ]   [ # 9 ]  
Grad Student
Rank
Total Posts:  68
Joined  07-06-2007
Derek Jones - 28 August 2007 01:49 PM

Incidentally, that’s what I’m doing on my personal site.

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

Profile
 
 
Posted: 22 December 2007 12:28 PM   [ Ignore ]   [ # 10 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  11303
Joined  06-03-2002
Kerim Satirli - 22 December 2007 11:14 AM
Derek Jones - 28 August 2007 01:49 PM

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.

 Signature 
Profile
MSG
 
 
Posted: 22 December 2007 12:34 PM   [ Ignore ]   [ # 11 ]  
Grad Student
Rank
Total Posts:  68
Joined  07-06-2007

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

Profile
 
 
Posted: 22 December 2007 12:48 PM   [ Ignore ]   [ # 12 ]  
Grad Student
Rank
Total Posts:  79
Joined  02-18-2007

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.  smile

Profile
 
 
Posted: 22 December 2007 12:56 PM   [ Ignore ]   [ # 13 ]  
Grad Student
Rank
Total Posts:  68
Joined  07-06-2007
Jason Bullard - 22 December 2007 05:48 PM

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.  smile

oh - xmas presents one has an actual need for !

Profile