[EDIT]- I meant to mention that along with this plugin you will also need to turn off the :
Admin->Weblog Administration->Weblog Management->Edit Preferences->Weblog Posting Preferences-Automatically turn URLs and email addresses into links?
in order for this plugin to work correctly.
Hiya,
Another one for anyone who’s interested!
This plugin was created due to a need that Jan had over in this thread.
If you ever have users / clients entering links into fields but have no control over whether or not they are adding in the http:// bit or not then if you try to make a link with one that doesn’t have the http:// bit then you will end up with a totally messed up link as ExpressionEngine will rightly put your site link in front of it. Not very nice at all! 😊
So that’s why I made this plugin.
Neat Link - UsageYou can also use custom fields instead of hard-coding the values which is really what the plugin is all about! 😊{exp:neat_link link_title="Title for link" link_text="Yahoo.com" link="www.yahoo.com" target="_blank"}
Note that the custom fields {link_title}, {link_text} and {link} all need to have their formatting set to none or this plugin will not work Other custom parameters that you can pass to the plugin are as follows : class=”flashy-css-style” rel=”external” id=”my-css-id” You can specify one or all of these. None of the parameters above are required though. Obviously you probably wouldn’t use the id and class at the same time though! 😊{exp:neat_link link_title="{link_title}" link_text="{link_text}" link="{link}" target="_blank"}
Anyway hope it helps some people out.
Best wishes,
Mark
Nice one mark.
Why thank you kind sir! 😊
Nothing quite as fantastic as the work that you are doing at the moment but I am learning at least. I need to neat-en up the code-base in this plugin as I’m sure there are neater ways of writing some of what I have done in there.
Best wishes,
Mark
I’m sure there are neater ways of writing some of what I have done in there.
You could use some shorthand like:
$id = $TMPL->fetch_param('id') ? "id='" . $TMPL->fetch_param('id') . "'" : '';
$class = $TMPL->fetch_param('class') ? "class='" . $TMPL->fetch_param('class') . "'" : '';
$rel = $TMPL->fetch_param('id') ? "rel='" . $TMPL->fetch_param('rel') . "'" : '';
to set the default values 😊
There’s always one isn’t there 😉 😊 😉
Thanks Leevi. I had seen this type of coding before in plugins but never really understand it so was going to look it up. I know what it is doing but I just think that the ? and other such stuff confuses me.
Don’t suppose you would be kind enough just to talk me through what it means syllable by syllable as it were?
Thanks.
Best wishes,
Mark
Mark! Awesome work w/ Neat Link. I modified it a bit to make it a tad more flexible. The first time I went to test it it didn’t work, because someone (okay okay, it was me) had entered in a website like this: expressionengine.com
So I changed the plugin like this and it worked great.
if (substr($url, 0, 4) != "http"){
$url = "http://" . $url;
}
That seems to catch more instances of a link, be it expressionengine.com, www. expressionengine.com or http://expressionengine.com. What do you think?
HI there Brian,
Absolutely makes sense! 😉
Thanks for picking up on that deliberate error that I made 😉 😉
Sorry I didn’t even think about URLs without the www when I made this so your modification is definitely a much needed one. I have now updated the plugin to have your code instead and have re-uploaded it to the first post. If you open up the plugin you will see some thanks to yourself in the update list 😉
Best wishes,
Mark
Brilliant!
The reason I happened to notice is the exact first time I tested the plugin it was on a url that happened to not have the www in there.
I have another change for you that I made, probably another deliberate error…
I changed this:
$rel = $TMPL->fetch_param('id') ? "rel='" . $TMPL->fetch_param('rel') . "'" : '';
to this:
$rel = $TMPL->fetch_param('rel') ? "rel='" . $TMPL->fetch_param('rel') . "'" : '';
I had some specific “rel” needs for my links, and so I wanted that as its own parameter.
Also I noticed the pi_version is still at 1.0.1.
All really MINOR stuff. I’m just the nitpicky guy who tweaks all your awesome ninja work. Thanks for the plugin!
Oops.
Sorry about that. Must have made a typo on that one. Have now updated the plugin with the correct item in there. Was meant to work but I must have rushed and not tested thoroughly enough so sorry about that.
No worries on picking. I like the fact that people are using these things and letting me know how to improve them. A nice community spirit is always a good thing 😊
Thanks again.
Best wishes,
Mark
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.