Sliced Typography Plugin
Posted: 24 August 2005 10:40 PM   [ Ignore ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1338
Joined  02-12-2003

Because it is something I wanted, and because someone else made a post about it, I made a small plugin that allows you to circumvent the XHTML formatting on a per case basis within an entry. 

Once I’ve had some time to test it more I’ll submit it to the plugin database.  But for those who need it or would like to test it a bit here it is:

Sliced Typography Plugin

If you try it out let me know how it works and if you have any trouble or find a bug.

I’m also working on a version that does the same thing for Textile since that is what the other person was wanting.  However, I’m having some trouble getting anything back from the Textile Plugin (which I am passing the text from my plugin using the require function.  I send it a string and get nothing in return.  Someone named Dean Allen is given credit for the plugin but I thought I remember it being Paul who made the EE version?  Anyway I would love it if someone who knew the plugin better would be able to give me a hand.

Jamie

Profile
 
 
Posted: 24 August 2005 10:42 PM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  33269
Joined  05-14-2004

Dean Allen created Textile (and textpattern, and a few other cool things) in the first place; Paul (I think) was the one that made it work as a plugin with EE.

 Signature 
Profile
MSG
 
 
Posted: 24 August 2005 10:50 PM   [ Ignore ]   [ # 2 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1338
Joined  02-12-2003

Thanks LisaJill,  I maybe bug him (Paul) through an email if he doesn’t notice this thread sometime before I have time to work on this again.  smile

Jamie

Profile
 
 
Posted: 25 August 2005 03:31 AM   [ Ignore ]   [ # 3 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7509
Joined  08-05-2002

I noticed your thread but I cannot recall if I wrote that Textile plugin for EE or not.  It’s all so fuzzy from way back then.  I’d have to see what you are doing with your plugin to figure out why you are getting nothing returned.

 Signature 
Profile
 
 
Posted: 25 August 2005 03:56 AM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  499
Joined  09-16-2004

Thanks guys for looking into this - I’m the guy Jamie mentioned who’s using Textile formatting but also have a need for Jamie’s plugin to override formatting within an entry.

Good luck, I wish I had the scripting knowledge to be able to pitch in and help : (

Dave

 Signature 

Definition // Simply effective websites - web design based in Hull and East Yorkshire

Profile
 
 
Posted: 25 August 2005 11:26 AM   [ Ignore ]   [ # 5 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1338
Joined  02-12-2003

Paul,

Here is the current version of the Textile version:

Sliced Textile Plugin

Basically I just go through the tagdata and split it up into an array using {slice} and {/slice} as deliminators.  I then send the array values through the textile plugin or not depending whether they were inside or outside of the slice tags. 

I’ve commented the source on the plugin so hopefully the actual details will be fairly clear.

Jamie

Profile
 
 
Posted: 25 August 2005 11:38 AM   [ Ignore ]   [ # 6 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  9853
Joined  06-19-2002

As I recall, Dean Allen (or someone else) had made a PHP class for the Textile processing and I think Paul just took that and built the EE Plugin out of/based on it.  Anyway, just FYI.

 Signature 

Chris Curtis
chriscurtis.org

Profile
 
 
Posted: 25 August 2005 11:46 AM   [ Ignore ]   [ # 7 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7509
Joined  08-05-2002

Looking at your plugin code right now (have not tested).  I am a bit confused why you have functions inside of functions like you do.

 Signature 
Profile
 
 
Posted: 25 August 2005 12:02 PM   [ Ignore ]   [ # 8 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1338
Joined  02-12-2003

Because I’m completely new to programming?  smile  That is just the way that worked for me while doing it.  The one that uses the XHTML function instead of Textile does everything the same way.  And does work (or seems to anyway).  Should the functions all be seperate?

Jamie

Profile
 
 
Posted: 25 August 2005 12:06 PM   [ Ignore ]   [ # 9 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7509
Joined  08-05-2002

Definitely should be separate.  There are ways of calling functions within functions:

class Woohoo{

     
function Woohoo($str = '')
     
{
          $str
= $this->process_str($str);
     
}
     
// End function

     
function process_str($str = '')
     
{
           $str
= str_replace('yahoo', 'woohoo', $str);
           return
$str;
     
}
     
// End function

}
// End class

 Signature 
Profile
 
 
Posted: 25 August 2005 12:20 PM   [ Ignore ]   [ # 10 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1338
Joined  02-12-2003

Ok I’ve made those changes.  The order of functions in the code don’t matter correct?

Sorry I’m subjecting you to a PHP lesson.  :(

Profile
 
 
Posted: 25 August 2005 12:35 PM   [ Ignore ]   [ # 11 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1338
Joined  02-12-2003

Well the new version with the functions moved does exactly the same thing as the first one.  The link I gave above should lead to the new version now so you can see what I’ve done.

Jamie

Profile
 
 
Posted: 25 August 2005 01:15 PM   [ Ignore ]   [ # 12 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7509
Joined  08-05-2002

Do you have error reporting turned on for whatever site you are using for testing?  I am getting a PHP error for an unset variable in one of the functions.  I fixed that in plugin but now there is a problem where the {/slice} is being outputted.  I think I will have to take a closer look at your code.

 Signature 
Profile
 
 
Posted: 25 August 2005 02:32 PM   [ Ignore ]   [ # 13 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1338
Joined  02-12-2003

Paul read through the one you attached to the email.  You are right, that is all I was trying to do.  Due to my inexperience I was going about it in a somewhat convoluted way.  Work has picked up for the moment but I will look at what you sent me in more detail this evening (it looks a lot more efficient then how I was going about it).  Thanks again for all of the help.

Oh, and I didn’t have error reporting on.  Should have.

Jamie

Profile
 
 
Posted: 25 August 2005 04:05 PM   [ Ignore ]   [ # 14 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7509
Joined  08-05-2002

Yours was a perfectly valid direction for it, but PHP does greg searches incredibly fast so if there is that option I try to use those.  In some cases though, they lack the ability to do recursive searching (say for nested conditionals), so you have to use something like you had.  A good example of where I used it is the assign_conditional_variables() function in the Functions class.  Let me know if you have any questions about what I did.

 Signature 
Profile
 
 
Posted: 26 August 2005 01:26 AM   [ Ignore ]   [ # 15 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1338
Joined  02-12-2003

Paul,

I looked through it all and have made a few changes to get things working exactly like I wanted.  I think I understand everything you have done in the Plugin except the very end (the important part):

for($i=0, $s = sizeof($x); $i < $s; ++$i)
{
if (trim($x[$i]) == '') continue;

$TEXT->Textile($x[$i]);
$str = str_replace($x[$i], $TEXT->return_data, $str);
}

$this
->return_data = trim(str_replace(array('{slice}', '{/slice}'), '', $str));

I understand that in the for () you are cycling through all of the entries in the array by incrementing the value of $i until it matches the number of entries in the array.  Then you are checking to see if the entry is empty with the if (I like this since it is quite a bit easier than trying to remove the empty entries like I was doing.  If it isn’t empty you run it through the Textile plugin and assign the return data from Textile to $str.

What I don’t understand in this is how the value of $str is being given all the data instead of just the last array entry in the group.  And how is telling whether to send it through Textile or not?  The way I understand it it looks like everything should be sent through but obviously it doesn’t because the plugin works as expected…  So that part has me lost.

Also I’m looking at the end it looks like you are sending an array back to EE.  I didn’t think this was possible… 

Finally your regular expression lost me as well.  I used:

/(\{(\/)?slice\})/

and you used:

/\{slice\}.*?\{\/slice\}/is

Mine I understand obviously since I made it but yours seems to do the same thing somehow…

Ok I’m done with my barrage of questions now.  Thanks again.  And I’m glad to hear that the way I was going about it originally was actually somewhat valid.  smile

Jamie

Profile
 
 
Posted: 26 August 2005 10:54 AM   [ Ignore ]   [ # 16 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7509
Joined  08-05-2002

Ah, yes, I did not really comment the code at all, did I?

$TEXT = new Textile;

// We don't want to process anything between {slice} and
// {/slice}, so what do we do?  We break up the entire string
// into an array using that tag pair.  This effectively removes all
// all instances of that tag pair from the string and leaves us with
// an array of the content we want to run through the Textile plugin
//
//  $str = "Here is my {slice}string{/slice} of coolness";
//
//  The above becomes this:
//
//  $x['0'] = "Here is my ";
//  $x['1'] = " of coolness";
//
// With the {slice} variable pair and its content removed
// Cool, no?

$x = preg_split("/\{slice\}.*?\{\/slice\}/is", $str);

// Now we run the parts of the array through the Textile plugin.
// The Textile() function does not return any data directly.  Instead it
// puts  the processed text in the $TEXT->return_data variable.  So,
// when the processing is done we replace the original string in the
// sentence with the Textile'd string.

for($i=0, $s = sizeof($x); $i < $s; ++$i)
{
if (trim($x[$i]) == '') continue;

$TEXT->Textile($x[$i]);
$str = str_replace($x[$i], $TEXT->return_data, $str);
}

// We have processed all of the array members and so all of the content
// that should be Textile'd has been processed and replaced in the
// original string.  So, now we simply have to remove the {slice}
// tags and we're done.

$this->return_data = trim(str_replace(array('{slice}', '{/slice}'), '', $str));

 Signature 
Profile
 
 
Posted: 26 August 2005 11:38 AM   [ Ignore ]   [ # 17 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1338
Joined  02-12-2003

Ok I get it now.  That is really slick simply replacing the original chunks of the string with the new ones instead of building a new string like I was doing.  Very cool. 

Thanks again.  I learned quite a few new things from this.

Jamie

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 66386 Total Logged-in Users: 55
Total Topics: 84710 Total Anonymous Users: 20
Total Replies: 454672 Total Guests: 196
Total Posts: 539382    
Members ( View Memberlist )