Recent Topics

1 Mar 06, 2009 02:55    

A bit of guidance in the right direction please?

I want to take the custom profiles plugin from AstonishMe and make it be a renderer that only does Avatars and SigFiles. The goal being not to have a div with an avatar, but to have the avatar appear to be a rightmargin'd image inside the beginning of the actual post content. The sig-line would still be it's own div at the end of the post, looking kinda like how our sig files appear here in these forums.

I've done a renderer or two that replaces bits in the post_content with something else. Smilies do that, as does the videoplug plugin or my creative commons plugin. The thing is this time there won't be anything in the body of the post to convert. My goal is a renderer that always renders and includes the avatar/sigfile IF the user has bothered to upload and select one (or write one). AstonishMe's profile plugin is an awesome starting point because it knows to do something or nothing based on if the user has an avatar or a sig file.

But how do I make a renderer work on the very first P tag if there isn't anything in the post_content to find and replace?

2 Mar 06, 2009 03:56

$data = 'yourcode goes here' . $data

3 Mar 06, 2009 04:03

Hey cool I just thought of that one! I was sorta working through "if I count P tags then render only once and replace P with P-avatar" and blah blah blah. But hey why not just have a super-low priority number then prepend content with an avatar and append content with a sigfile.

That means I thought of something a RSP came up with. SWEEEEEET!

4 Mar 06, 2009 04:07

The idea is that the RenderItemAsHtml work after the post is sent. This way you'll prepend your code. But I guess you want to replace the first <p> with <p><span> 'yourcode goes here' </span>.

You'd want a preg_replace for that. Let me see:

$data = preg_replace( '~<p>~', '<p><span>yourcode goes here</span>', $data, 1 );


The 1 makes it perform only once.

Make sure your plugin is loaded after the auto_p thingy.

Good luck

5 Mar 06, 2009 04:49

Okay cool. Details like that are why I add lots of $this->msg to stuff I'm working on. And quite a few print_r( $whatever ) too :)

Wasn't exactly sure when RenderItemAsHtml kicked in either. So with it AFTER the auto-P does it's thing then yeah I'll have to replace the first P tag. Didn't have any idea I could do it with a "1" in the preg_replace though. I'd have done a foreach or a while or something cumbersome like that.

Afwas wrote:

Make sure your plugin is loaded after the auto_p thingy.

Ah but now I'm confused. Do I understand correctly that if I have my thing render first then I don't need to preg_replace? In other words auto-P, if it followed my lame knock-off, would simply wrap my avatar image in a P tag along with the first actual paragraph of text?

OTOH if I let auto-P go first then I can ensure getting my avatar thing after the first P tag ... even when the post starts with a list or a block quote or anything other than a P tag. hmmm... See this is why really smart stuff is better left to either Really Smart People or those with momentary inspirations of genius.

6 Mar 06, 2009 05:38

EdB wrote:

Afwas wrote:

Make sure your plugin is loaded after the auto_p thingy.

Ah but now I'm confused. Do I understand correctly that if I have my thing render first then I don't need to preg_replace? In other words auto-P, if it followed my lame knock-off, would simply wrap my avatar image in a P tag along with the first actual paragraph of text?

OTOH if I let auto-P go first then I can ensure getting my avatar thing after the first P tag ... even when the post starts with a list or a block quote or anything other than a P tag. hmmm... See this is why really smart stuff is better left to either Really Smart People or those with momentary inspirations of genius.

Not really.
It's not smart.

It's the one way or the other. But the easiest way is let auto_p do it's job then you can be fairly sure either the user or auto_ has added <p>. Then you do your stuff.
Only if you knew that every user would use auto_p you could get away with the easy answer.

Most of them around work exclusively with the auto_p. Just want you not to have the obvious question answered: 'Why doesn't it work on my blog'.
It won't work if you add the avatar before you add the <p>.

--F

pre_dump( substr($params['data'], 0, 20))


returns the first 20 characters for debug.

7 Mar 06, 2009 07:10

if( strpos( $params['data'], '<p' ) !== false )
{
	$params['data'] = preg_replace( '~(<p.+?>)~', '$1'.'your data here', $params['data'], 1);
}
else
{
	$params['data'] = 'your data here'.$params['data'];
}

¥

8 Mar 06, 2009 12:50

Okay cool. I just now realized after sleeping on it that I had to put the GetExtraEvents hook back in since two of them are still used. So in a controlled environment (test installation) it actually works. For me I had figured on forcing auto-P to always and not really adding this to my list of distributed plugins. Cuz really it's just a watered down version of AM Profiles. Extending someone else's work is one thing. Watering someone else's work down then adding a neat bell is ... not cool. But hey might as well do the best I can with it eh? Then zip it up and let ¥åßßå have it to see if maybe he wants to do something with it.

I have this funny feeling doing avatars first might make "an image as a post" look fairly silly eh? Thus it needs to go later and let auto-P exist ... and have some sort of fallback if there are no P tags in the post.

I would have gone with preg_replacing <p> instead of <p ... > because like I said I was thinking of only one application for it. Mine :) With laundry going I gotta wait for my shower, so I'll spend that time trying to get 'er smarter and smarter. Fun stuff! Beats the heck out of *constantly* working on that monster plugin I finally mostly finished.

9 Mar 06, 2009 19:00

Selfish arse, I dunno why we bother helping you :roll:

¥

10 Mar 06, 2009 22:36

¥åßßå wrote:

Selfish arse, I dunno why we bother helping you :roll:

¥

So's I can clean up your code and give it back to you :D

11 Mar 06, 2009 23:48

And actually I'll be a tad more serious than normal: I asked fplanque how he felt about me basically hacking the quicktags toolbar plugin into something for comments before releasing that into the wilds. So I'll do the same thing with this one.

¥åßßå I'm pretty well done with taking a portion of this plugin and making it be something very similar. Given that I'm not doing very much of my own (a few extra settings - of course, and it plays nice in blog posts), I'll leave it up to you if I release it as if it was mine, or zip it up and let you decide which parts ever see the light of day. Naturally if I zip it up your plugin will be referenced as THE source material and that all I did was made it be a little bit more inline with my needs.

12 Mar 07, 2009 07:40

Release it, more choice is always better ;)

¥

13 Mar 07, 2009 08:27

hi EdB,

I took the idea and essential parts of code from a ¥åßßå plugin and turned that into the Sorted Bloglist plugin. Both plugins live happily side by side. Mine is easier to set up. ¥åßßå's has more options.

Similar happened to me. Ian Lewis had issues using my jQuery Lightbox plugin together with his Gallery2. I offered him he could take all code he wanted for his plugin or simply extend my plugin. He didn't end up do either but this message is not about that.

All our plugins are licensed through GPL2 meaning that you can use the code under some conditions that you seem to meet. Feel free to release the plugin.

Good luck

14 Mar 07, 2009 10:06

@Afwas: yeah I know, but to my mind it's much nicer to talk to the author up front ya know? Like, if I said "hey I used your code to make something kinda similar but different and want to give it away" instead of just doing it then pointing out it is open source so get over it? Maybe that's just me though. Everyone who's ever asked me got "go for it" in reply, and the one person who didn't kinda tweaked my shorts that the only mention I got was a link on their blog post. Open source and all, and I know full well what I give away isn't mine, but still... :-/

Cool. Soon there shall be a plugin named ... Killer Bees!


Form is loading...