danwolfgang
Nov 3 2003, 08:38 AM
I'm trying to differentiate offsite links with a little icon and having them go into a new window. But I'm only having some luck--the macro works only half of the time!
I've tried several people's approaches, all working off of the MTMacro plugin. My code:
CODE
<MTMacroDefine name="links" ctag="a"><MTIfMatches expr="[MTMacroAttr name='href']" pattern="m/.+/"><MTMacroAttr name="class" value="local"></MTIfMatches><MTIfMatches expr="[MTMacroAttr name='href']" pattern="m/^http:/"><MTMacroAttr name="class" value="offsite"></MTIfMatches><MTIfMatches expr="[MTMacroAttr name='href']" pattern="m/^http:\/\/www.danandsherree.com/"><MTMacroAttr name="class" value="local"></MTIfMatches><MTMacroTag rebuild="1"><MTMacroContent><MTIfMatches expr="[MTMacroAttr name='class']" pattern="m/^offsite/"> <img src="/remote.gif" width=11 height=11 border=0></MTIfMatches></a></MTMacroDefine>
This sits in a template module and is called with MTInclude and MTEntryBody apply_macros="1".
You can see the result
here. Links to my website don't have an icon (which is correct). Offsite links vary--like "Movable Type" with an icon (correct) but "Webalizer Quick Help" is missing the icon. I've looked at the posts and I'm lost; I can't see the difference. Can anybody help?
danwolfgang
Nov 3 2003, 04:01 PM
Another annoying thing seems to be that some posts get butchered with this macro running on it. I'm lost. Help?
girlie
Nov 3 2003, 04:09 PM
This code from
Kalsey seemed to work for me, with one exception.
CODE
<MTMacroDefine name="links" ctag="a">
<MTIfMatches expr="[MTMacroAttr name='href']" pattern="m|^http:|">
<MTMacroAttr name="target" value="_blank"> <MTMacroAttr name="class" value="offsite"> </MTIfMatches>
<MTIfMatches expr="[MTMacroAttr name='href']" pattern="m|^http://.*.yoursite.com|">
<MTMacroAttr name="target" value="_top"> <MTMacroAttr name="class" value=""> </MTIfMatches>
<MTMacroTag rebuild="1"><MTMacroContent></a> </MTMacroDefine>
The exception was the link found in
this entry to the Regex plugin. I have no idea why the icon isn't showing up there - a space is though.
And it looks like it put a comma between "Regex" and "plugin". Hmmmm.
girlie
Nov 3 2003, 04:12 PM
Darnit, now I want to know why it's doing that.

There's one link in Kalsey's own entry doing the exact same thing.
girlie
Nov 3 2003, 04:27 PM
Okay, I got it to appear by rewriting the sentence.
But I'm not sure what the reason behind the weirdness was - I rewrote the sentence several different ways before I got it to work. Hmmmm.
girlie
Nov 3 2003, 05:20 PM
Browser bug.
danwolfgang
Nov 3 2003, 06:37 PM
I've seen similar weirdness with similar results: rewriting the word/sentence/post seems to fix it--sometimes. Sometimes I have to rewrite several times.
Well, at least I'm not the only one seeing it!
Dan
girlie
Nov 3 2003, 06:41 PM
The bug occurs in IE when the link runs across two lines - Adam confirmed it for me.
danwolfgang
Nov 4 2003, 06:09 AM
Actually, the problem you see isn't the same as the problem I see. My problem is that some hyperlinks don't get recognized as "offsite." They don't get the "offsite" class added to the anchor, nor do they get the target="_blank" attribute. That is, of course, not a browser issue.
Dan
girlie
Nov 4 2003, 03:31 PM
Is the problem with the code I posted, or the code you posted?
danwolfgang
Nov 4 2003, 05:21 PM
It happens with both pieces of code. Actually, for better or worse, it works the same with either piece of code.
Because the code works for others I'm guessing it's something with my installation, other code or server. After all, those are the only other options! I just can't figure out what it could be.
girlie
Nov 4 2003, 06:18 PM
Well - it determines what's not "offsite" by looking for the URL you have where it says "yoursite.com". It's a text pattern match, so I'm not sure why your server would have an impact on that.
I only see one link on your URL where it didn't add the offsite class - that was the one for Webalizer, and I noticed in the source code you wrote with a capital
A in the
a href tag:
CODE
<A href="http://www.mrunix.net/webalizer/webalizer_help.html">Webalizer Quick Help</A>
All the other links where you used
A instead of
a were onsite links.
Try changing it to a lowercase
a and see what happens.
danwolfgang
Nov 4 2003, 07:36 PM
QUOTE (girlie @ Nov 5 2003, 02:18 AM)
Try changing it to a lowercase a and see what happens.
Yes, I believe you were right.
From
http://www.movabletype.org/resources/archi...entiating.shtml:
CODE
<MTMacroDefine ctag="a" no_case="1"><MTIfMatches expr="[MTMacroAttr name='href']" pattern="m/.+/"><MTMacroAttr name="class" value="local"></MTIfMatches><MTIfMatches expr="[MTMacroAttr name='href']" pattern="m/^(ftp|http|nttp|mailto):/"><MTMacroAttr name="class" value="offsite"></MTIfMatches><MTIfMatches expr="[MTMacroAttr name='href']" pattern="m|danandsherree\.com|"><MTMacroAttr name="class" value="local"></MTIfMatches><MTMacroTag rebuild="1"><MTMacroContent></a><MTIfMatches expr="[MTMacroAttr name='class']" value="offsite"> <img src="/remote.gif" width="11" height="11" /></MTIfMatches></MTMacroDefine>
Works for me, and I suspected it was simply because of the 'no_case="1"' attribute; that was, of course, easily verified. It seems to work correctly for the Webalizer link and the few other problematic spots.
Thanks for the help!
kadyellebee
Nov 4 2003, 10:22 PM
Ahhhh, that makes sense - thanks for coming back and telling us that about the capitilization, Girlie - I was going crazy last night trying to figure out what the difference was in the example links!!!!!

Kristine
fliptophead
Feb 25 2004, 02:09 PM
I'm having issues with the Macro plugin. Here's the error I get:
CODE
An error occurred:
Can't locate bradchoate/macros.pm in @INC (@INC contains: /usr/lib/perl5/5.6.1/i386-linux /usr/lib/perl5/5.6.1 /usr/lib/perl5/site_perl/5.6.1/i386-linux /usr/lib/perl5/site_perl/5.6.1 /usr/lib/perl5/site_perl/5.6.0/i386-linux /usr/lib/perl5/site_perl/5.6.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.6.1/i386-linux /usr/lib/perl5/vendor_perl/5.6.1 /usr/lib/perl5/vendor_perl . /usr/local/apache1.3.26-2/ /usr/local/apache1.3.26-2/lib/perl) at plugins/macros.pl line 41.
Any idea what I'm doing wrong?
nolageek
Feb 25 2004, 02:20 PM
This has nothing to do with the macro plugin, but this is how I do it on
nolagay.com using CSS . Try this in your style sheet. Works excellent for me, in all of the browsers I've tried it in:
CODE
a[href^="mailto:"] {
background: transparent url('/path/to/images/aemail.gif') 100% 50% no-repeat;
padding-right: 10px;
}
a[href^="http:"] {
background: transparent url('/path/to/images/aoutside.gif') 100% 50% no-repeat;
padding-right: 10px;
}
a[href^="http://yourdomain.com"],
a[href^="http://www.yourdomain.com"] {
background: inherit;
padding-right: 0px;
}
The images can be found here:
aemailaoutside
fliptophead
Feb 25 2004, 02:31 PM
That's an interesting way of doing that. I like it and I'll definitely be using it.
I was mainly using MTMacro to open my outside links in a new window. Any ideas on how to do that?
kadyellebee
Feb 25 2004, 05:23 PM
fliptophead, I replied to your question in another thread; please don't post the same issue in multiple places! Thanks.
nolageek
Feb 25 2004, 07:18 PM
QUOTE (fliptophead @ Feb 25 2004, 05:31 PM)
That's an interesting way of doing that. I like it and I'll definitely be using it.
I was mainly using MTMacro to open my outside links in a new window. Any ideas on how to do that?
I see. After I read
30 days to a more accessible weblog I stopped opening new windows. Day 16 is the rationalle and I think it's a good argument against it. YMMV. I know there's a good way to do this so people can select whether the want outside links to pop up or not. cant remember the javascript though. Ill see if i can find it!
kadyellebee
Feb 25 2004, 07:23 PM
I bet that nolageek is talking about
randomwalks' open in new window checkbox.

Kristine
garylapointe
Feb 26 2004, 06:48 AM
If it's your own site the link is for, couldn't you just leave off the "http://yousite.com/mt/blog/" and just make it "/mt/blog/"? You'd still have to parse a little but you'd just have to find a "http" in the file?
Gary
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.