Author |
Topic |
MarcelG
Retired Support Moderator
Netherlands
2625 Posts |
Posted - 09 November 2005 : 04:56:48
|
Tribaliztic ; that was exactly what I was experiencing. I guess the problem lies in the fact that we use sOutput as the input for sLink, however, sOutput is the entire post, and not just the part that makes the URL. Perhaps we need to do a 2-step-approach ; first convert all the URLs to a href's, and after that, find all the URLs enclosed by > < (shown in bold blue below) and shorten them, if they exceed a certain length. Example: <a href="http://www.thisisthelongestlinkicouldthinkof.com">http://www.thisisthelongestlinkicouldthinkof.com</a>
So, first the function edit_hrefs which creates the line above. fter that the function 'shorten_href_names' which takes the blue part, and shortens that one to this: <a href="http://www.thisisthelongestlinkicouldthinkof.com">http://www.thisisth...of.com</a> Just a thought.< |
portfolio - linkshrinker - oxle - twitter |
Edited by - MarcelG on 09 November 2005 04:59:57 |
|
|
tribaliztic
Senior Member
Sweden
1532 Posts |
Posted - 09 November 2005 : 05:00:38
|
It takes the last line and includes that in the url, not the text that's directly after the link...
This is over my head, I can't be of any help here so I'll leave this for you brainiacs to figure out =) Shaggy had a nice solution to my other thread (http://forum.snitz.com/forum/topic.asp?TOPIC_ID=60076), so I'll stick with that one 'til this is fixed. Thanks again for letting me have some of your time folks =) < |
/Tribaliztic - www.gotlandrace.se -
|
Edited by - tribaliztic on 09 November 2005 05:01:02 |
|
|
MarcelG
Retired Support Moderator
Netherlands
2625 Posts |
Posted - 09 November 2005 : 05:03:51
|
quote: Originally posted by tribaliztic
It takes the last line and includes that in the url, not the text that's directly after the link...
I thikn that it takes the last x characters of the entire post, and puts that in the URL. If you'd remove the blabla3 part of your post, it would include blabla2.< |
portfolio - linkshrinker - oxle - twitter |
|
|
tribaliztic
Senior Member
Sweden
1532 Posts |
Posted - 09 November 2005 : 05:12:08
|
aah.. but it cuts the link correctly otherwise, so it's a step forward =) < |
/Tribaliztic - www.gotlandrace.se -
|
|
|
MarcelG
Retired Support Moderator
Netherlands
2625 Posts |
Posted - 09 November 2005 : 08:24:28
|
Okay, how do I parse the $1 that exists in the replace-part through this function:
// sTruncUrlName = url
// aLength = number of starting chars to show
// bLength = number of closing chars to show
function truncString(sTruncUrlName1, aLength, bLength) {
sTruncUrlName = new String(sTruncUrlName1);
if (sTruncUrlName.length > (aLength+bLength+5)) {
aString = sTruncUrlName.substring(0, aLength);
bString = sTruncUrlName.substring(sOutput.length-bLength, sOutput.length);
sTruncUrlName= aString+"..."+bString;
}
return sTruncUrlName;
} I tried this, but it doesn't work.
function edit_hrefs(sURL, iType) {
sOutput = new String(sURL);
if (iType == 1) {
sOutput = sOutput.replace(/\b(http\:\/\/[\w+\.]+[\w+\.\:\/\@\_\?\=\&\-\'\#\%\~\;\,\$\!\+\*]+)/gi,
"<a href=\"$1\" target=\"_blank\">+truncString($1, 20, 5)+<\/a>");
} else if (iType == 2) {
sOutput = sOutput.replace(/\b(https\:\/\/[\w+\.]+[\w+\.\:\/\@\_\?\=\&\-\'\#\%\~\;\,\$\!\+\*]+)/gi,
"<a href=\"$1\" target=\"_blank\">+truncString($1, 20, 5)+<\/a>");
} else if (iType == 3) {
sOutput = sOutput.replace(/\b(www\.[\w+\.\:\/\@\_\?\=\&\-\'\#\%\~\;\,\$\!\+\*]+)/gi,
"<a href=\"http://$1\" target=\"_blank\">+truncString($1, 20, 5)+<\/a>");
} else if (iType == 4) {
sOutput = sOutput.replace(/\b([\w+\-\'\#\%\.\_\,\$\!\+\*]+@[\w+\.?\-\'\#\%\~\_\.\;\,\$\!\+\*]+\.[\w+\.?\-\'\#\%\~\_\.\;\,\$\!\+\*]+)/gi,
"<a href=\"mailto\:$1\">$1<\/a>");
} else if (iType == 5) {
sOutput = sOutput.replace(/\b(ftp\:\/\/[\w+\.]+[\w+\.\:\/\@\_\?\=\&\-\'\#\%\~\;\,\$\!\+\*]+)/gi,
"<a href=\"$1\" target=\"_blank\">+truncString($1, 20, 5)+<\/a>");
} else if (iType == 6) {
sOutput = sOutput.replace(/\b(file\:\/\/\/[\w+\:\/\\]+[\w+\/\w+\.\:\/\\\@\_\?\=\&\-\'\#\%\~\;\,\$\!\+\*]+)/gi,
"<a href=\"$1\" target=\"_blank\">+truncString($1, 20, 5)+<\/a>");
}
return sOutput;
} < |
portfolio - linkshrinker - oxle - twitter |
|
|
tribaliztic
Senior Member
Sweden
1532 Posts |
Posted - 09 November 2005 : 08:45:22
|
Oh Shaggy, where art thou? ;) < |
/Tribaliztic - www.gotlandrace.se -
|
|
|
MarcelG
Retired Support Moderator
Netherlands
2625 Posts |
Posted - 09 November 2005 : 10:50:47
|
Here's something my collegue came up with ; It IS working, however, it hasn't been tested intensively. Go ahead and give it a try.
<script language="javascript1.2" runat="server">
function truncString(sOutput, sOutput2,aLength, bLength) {
if (sOutput2.length > (aLength+bLength+3)) {
aString = sOutput2.substring(0, aLength);
bString = sOutput2.substring(sOutput2.length-bLength, sOutput2.length);
sOutput = "<a href='"+sOutput+"' target='_blank'>"+aString+"..."+bString+"</a>"
}
else
{
sOutput = "<a href='"+sOutput+"' target='_blank'>"+sOutput2+"</a>"
}
return sOutput;
}
function edit_hrefs(sURL, iType) {
sOutput = new String(sURL);
if (iType == 1) {
sOutput = sOutput.replace(/\b(http\:\/\/[\w+\.]+[\w+\.\:\/\@\_\?\=\&\-\'\#\%\~\;\,\$\!\+\*]+)/gi,
function($1) { return truncString($1, $1, 30, 8); });
} else if (iType == 2) {
sOutput = sOutput.replace(/\b(https\:\/\/[\w+\.]+[\w+\.\:\/\@\_\?\=\&\-\'\#\%\~\;\,\$\!\+\*]+)/gi,
function($1) { return truncString($1, $1, 30, 8); });
} else if (iType == 3) {
sOutput = sOutput.replace(/\b(www\.[\w+\.\:\/\@\_\?\=\&\-\'\#\%\~\;\,\$\!\+\*]+)/gi,
function($1) { return truncString("http://"+$1,$1, 30, 8); });
} else if (iType == 4) {
sOutput = sOutput.replace(/\b([\w+\-\'\#\%\.\_\,\$\!\+\*]+@[\w+\.?\-\'\#\%\~\_\.\;\,\$\!\+\*]+\.[\w+\.?\-\'\#\%\~\_\.\;\,\$\!\+\*]+)/gi,
"<a href=\"mailto\:$1\">$1<\/a>");
} else if (iType == 5) {
sOutput = sOutput.replace(/\b(ftp\:\/\/[\w+\.]+[\w+\.\:\/\@\_\?\=\&\-\'\#\%\~\;\,\$\!\+\*]+)/gi,
function($1) { return truncString($1, $1, 30, 8); });
} else if (iType == 6) {
sOutput = sOutput.replace(/\b(file\:\/\/\/[\w+\:\/\\]+[\w+\/\w+\.\:\/\\\@\_\?\=\&\-\'\#\%\~\;\,\$\!\+\*]+)/gi,
function($1) { return truncString($1, $1, 30, 8); });
}
return sOutput;
}
</script>
(removed first bug)< |
portfolio - linkshrinker - oxle - twitter |
Edited by - MarcelG on 09 November 2005 10:55:04 |
|
|
tribaliztic
Senior Member
Sweden
1532 Posts |
Posted - 09 November 2005 : 10:58:38
|
Cool! It's working! I've tested it some on my forum and it seems to ignore text after the link. Now I have to decide if this is better than replacing the link with a short text like "click here". I think I'll stick with this =) Please say thank you to your collegue MarcelG =) < |
/Tribaliztic - www.gotlandrace.se -
|
|
|
imweazel
Starting Member
49 Posts |
Posted - 09 November 2005 : 13:59:38
|
Excellent! works for me too. Thanks MarcelG and collegue. I was stumped as to how to get rid of the trailing string.
< |
|
|
MarcelG
Retired Support Moderator
Netherlands
2625 Posts |
|
golfmann
Junior Member
United States
450 Posts |
Posted - 09 November 2005 : 22:40:07
|
Great stuff Marcel.... This has been bugging me for YEARS!!!
REAL close to a final fix I think.< |
|
|
tribaliztic
Senior Member
Sweden
1532 Posts |
Posted - 10 November 2005 : 02:23:34
|
quote: Originally posted by MarcelG
Found a bug. Scenario : someone posts an url using the [url][/url] tags around it.... Demo: http://www.oxle.com/topic.asp?TOPIC_ID=3296 (login demo/demo)
bah =)
Well, put your collegue to work on this now, hehe.. < |
/Tribaliztic - www.gotlandrace.se -
|
|
|
MarcelG
Retired Support Moderator
Netherlands
2625 Posts |
Posted - 10 November 2005 : 04:02:51
|
Well, I don't yet quite understand why the [url][/url] part isn't working....I haven't updated anything in the ReplaceURLs function, just the edit_hrefs function... < |
portfolio - linkshrinker - oxle - twitter |
|
|
tribaliztic
Senior Member
Sweden
1532 Posts |
Posted - 10 November 2005 : 04:17:20
|
isn't the edit_hrefs used in the [url]-stuff then? < |
/Tribaliztic - www.gotlandrace.se -
|
|
|
MarcelG
Retired Support Moderator
Netherlands
2625 Posts |
Posted - 10 November 2005 : 04:40:17
|
yep, it is used there.
I've found a partial fix.
Replace the function truncString with this one:
function truncString(sOutput, sOutput2,aLength, bLength) {
if (sOutput2.length > (aLength+bLength+3)) {
aString = sOutput2.substring(0, aLength);
bString = sOutput2.substring(sOutput2.length-bLength, sOutput2.length);
sOutput = "<a href=\""+sOutput+"\" target=\"_blank\">"+aString+"..."+bString+"</a>"
}
else
{
sOutput = "<a href=\""+sOutput+"\" target=\"_blank\">"+sOutput2+"</a>"
}
return sOutput;
}
The short [url][/url] work now. Long [url][/url] still don't work. Example: www.blablablablablablablabla.com/testlink/testlink.html results in: www.blablablablablablablabla.c...ink.html (so, ok) But, this: [url]www.blablablablablablablabla.com/testlink/testlink.html[/url] results in: www.blablablablablablablabla.c...ink.html (so not ok)< |
portfolio - linkshrinker - oxle - twitter |
Edited by - MarcelG on 10 November 2005 04:43:14 |
|
|
Topic |
|
|
|