Snitz™ Forums 2000
https://forum.snitz.com/forumTopic/Posts/57507?pagenum=1
05 November 2025, 01:59
Topic
sr_erick
Clipped URL's?
14 March 2005, 20:53
I've done some searching and came up with nothing. Has anyone made any mods to clip the URL in the format string functions?
Like if there is a super long URL like this:
if RTrim(Len(strLink)) > 60 then strLinks = Left(strLink, 40) & "..." end if %> <a href="<% =strLink %>"><% =strLinks %></a><
Shaggy
15 March 2005, 07:05
Gimme a bit and I'll try and come up with something over lunch (GMT). Seem to remember someone doing this before but I can't find it now.
<
Shaggy
15 March 2005, 08:27
MarcelG
15 March 2005, 08:34
Great!!! Time to experiment!<
Shaggy
15 March 2005, 08:47
*sits patiently awaiting the bug reports! *
<
MarcelG
15 March 2005, 09:38
Well, I'm getting this error :
Microsoft JScript compilation error '800a03ea'
Syntax error
/forum/inc_func_common.asp, line 1836
iMLength = <%intMaxLinkLength%>; -----------^
I've changed that line to this:
Code:
iMLength = intMaxLinkLength;
After posting this url: http://ridiculoouslylongurl.com.netridiculoouslylongurl.com.netridiculoouslylongurl.com.netridiculoouslylongurl.com.netridiculoouslylongurl.com.net/ it displays it as this: http://ridiculoously...longurl.com.netridiculoouslylongurl.com.netridiculoouslylongurl.com.netridiculoouslylongurl.com.netridiculo So...it doesn't really works as designed.<
Shaggy
15 March 2005, 10:41
Is that with or without the [url] tag? Figured the changes to edit_hrefs wouldn't work sraight off! Looks like the problem's being cused by this:
sLink.substring((iLLength-iHLength),iHLength)
Can't figure out why, though.
<
MarcelG
15 March 2005, 10:51
I didn't use the URL tag.
I just posted that URL, without any tags around it.<
Shaggy
15 March 2005, 11:03
Well, it's definitely that snippet above, then. Don't know why, even if it started trimming the right hand side from the wrong character (iLLength-iHLength), it should still only show iHLength characters from that point.
<
MarcelG
15 September 2005, 05:32
If I may be so bold, I'd like to bump this topic once again....
I've noticed that FireFox seems to have some problems with wrapping long urls.
In IE the url is wrapped at characters such as -, but in FireFox it's not...resulting in some odd looking layout.<
Astralis
24 September 2005, 01:53
I think this would be excellent. Long URLs are a pain when they stretch the page.<
tribaliztic
04 November 2005, 09:12
Well.. I got the same error as MarcelG,
This link: http://www.autoblog.com/entry/1234000873066126/ became: http://www.a...utoblog.com/entry/1234000873066126/
it actually became LONGER after being processed =) <
golfmann
06 November 2005, 07:52
I converted a format button (actually the teletype add on one) to put THIS code when clicked:
You then paste the long url in at the left ", manually, and can change 'Link' to any word, color, etc..
COULD it be possible to COMBINE these and instead of trimming at x number of spaces, place the url string inside this between the url=" "'s?
So IF under the length it's normal, over is that above, putting the word link, click here or whatever in there with the actual link embedded behind it?
just a thought... <
Shaggy
07 November 2005, 10:25
Been looking and looking and looking at this and still can't see where it's tripping up. All I can suggest is that ye try replacing my edited edit_hrefs function with the following:
I changed the blue bold part.
It's not working entirely as suspected though.
I tried to post these links, with the value for intMaxLinkLength set to 25.
www.1.com www.12.com www.123.com www.1234.com www.12345.com www.123456.com www.1234567.com www.12345678.com www.123456789.com www.1234567890.com www.12345678901.com www.123456789012.com www.1234567890123.com www.12345678901234.com www.123456789012345.com www.1234567890123456.com www.12345678901234567.com www.123456789012345678.com www.1234567890123456789.com www.12345678901234567890.com They come out like this:
www.1.com
www.12.com
www.123.com
www.1234.com
www.12345.com
www.123456.com
www.1234567.com
www.12345678.com
www.123456789.com
www.1234567890.com
www.12345678...678901.com
www.12345678...789012.com
www.12345678...890123.com
www.12345678...901234.com
www.12345678...012345.com
www.12345678...123456.com
www.12345678...234567.com
www.12345678...345678.com
www.12345678...456789.com
www.12345678...901234567890.com
The links are pointing to the correct URL though, but it seems as if they're broken up, even though the link is shorter than 20 charachters.<
Shaggy
07 November 2005, 11:02
*conflustered* If it works then great But I don't see how that can work; the first argument in the substring function should be the first character you want to display. You've got iLLength in there which should, therefore, start your substring from the last character of the URI.
*still conflustered! *
<
MarcelG
07 November 2005, 11:03
Err...I've updated my reply...<
MarcelG
07 November 2005, 15:23
Shaggy,
there's something more wrong with this code, something I didn't expect.
Here's an example (made with screenshots) The input:
The output: <
MarcelG
07 November 2005, 15:57
BTW ; just checked phpBB ; they don't clip the urls proof BTW ; I think I found out what's not working with your script Shaggy ;
sOutput is not just the links, but also all the text around/after/before it, I guess per line or so.
So, if you're going to say that sLink = sOutput if sOutput is shorter than let's say 40 chars, sLink not only is the original link, but also the text after it.
I've been looking for the similar functionality in phpBB, but I haven't found it there. Now trying to find out whether or not Invision Power Board has it....some reverse engineering is in place here. <
AnonJr
07 November 2005, 16:12
lol. Where to next? what about just trimming it down to the domain? or just add the elips after 25 charachters.
www.reallylongurl/bla/bla/bla.asp
www.reallylongurl/bla/bl...
and keep them pointing to the same url? It might not look as cool, but it would probably simplify things for the time being.<
Ay, that was just to test what was being passed through the sLink argument of the function, you can paste the rest of the code back in. Now that we know that it is just the URI that gets passed through, we can eliminate that as the cause of our problems.
<
MarcelG
08 November 2005, 09:18
Originally posted by Shaggy Ay, that was just to test what was being passed through the sLink argument of the function, you can paste the rest of the code back in. Now that we know that it is just the URI that gets passed through, we can eliminate that as the cause of our problems.
But why is the part 'dus' added to the slink value if the link is shorter than the max length? as you can see in the screenshot, it's inserted into slink and not in the $1 part.... I just found out that vBulletin has the functionality to cut off long urls, built in: http://www.vbulletin.com/forum/showthread.php?p=1008045#post1008045
Anyone have access to the source, to reverse engineer it ? <
imweazel
08 November 2005, 10:36
Originally posted by Shaggy Been looking and looking and looking at this and still can't see where it's tripping up. All I can suggest is that ye try replacing my edited edit_hrefs function with the following:
Code:
MarcelG removed this code to preserve readable formatting (sorry)
If that doesn't work then maybe we should try looking at acheiving this with Gary's RegExp based edit_hrefs function.
Try changing the line to: if(iLLength>=iMLength&&iType!=4)sLink=sOutput.substring(0,iHLength)+"..."+sOutput.substring((iLLength-iHLength),iLLength);
I think you want the end of the substring to be iLLength instead of iHLength. I believe Marcel is correct that text after the URL is being included, so this is not a complete fix.<
tribaliztic
09 November 2005, 03:24
Text after the link is underlined together with the link when mousover. The link still work though.
I'll try your code now imweazel =) <
tribaliztic
09 November 2005, 03:32
Strange..
The link length is OK now (wohoo!) but it's something weird if there is text after the link, se here:
what's in the topic: http://www.gotlandrace.se/tabort/before.jpg what's displayed: http://www.gotlandrace.se/tabort/after.jpg <
MarcelG
09 November 2005, 04:56
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.<
tribaliztic
09 November 2005, 05:00
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 =) <
MarcelG
09 November 2005, 05:03
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.<
tribaliztic
09 November 2005, 05:12
aah.. but it cuts the link correctly otherwise, so it's a step forward =) <
MarcelG
09 November 2005, 08:24
Okay, how do I parse the $1 that exists in the replace-part through this function:
Code:
// 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.
Code:
function edit_hrefs(sURL, iType) { sOutput = new String(sURL);
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 =) <
imweazel
09 November 2005, 13:59
Excellent! works for me too. Thanks MarcelG and collegue. I was stumped as to how to get rid of the trailing string.
<
MarcelG
09 November 2005, 14:31
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)
<
golfmann
09 November 2005, 22:40
Great stuff Marcel....
This has been bugging me for YEARS!!!
REAL close to a final fix I think.<
tribaliztic
10 November 2005, 02:23
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..
<
MarcelG
10 November 2005, 04:02
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... <
tribaliztic
10 November 2005, 04:17
isn't the edit_hrefs used in the [url]-stuff then?
<
MarcelG
10 November 2005, 04:40
yep, it is used there.
I've found a partial fix.
Replace the function truncString with this one:
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)<
tribaliztic
10 November 2005, 05:15
Hm.. could you post your original thruncstring? Mine is much longer than your new one =) <
MarcelG
10 November 2005, 06:09
The two functions at the bottom of inc_func_common.asp:
In other words, the urls are parsed through the function twice....<
Shaggy
10 November 2005, 08:25
Sorry for the absence, emergency at work.
Marcel, what it looks like is happening there is that the link gets passed through the ReplaceURLs function when using the [url] tag, constructing the anchor tag and truncating the display text, if need be. Then, for some reason, that outputted code is being picked up by the chkURLs function and tries to pass both ocurrences of the URI through edit_hrefs.
<
tribaliztic
10 November 2005, 08:26
hmm... now let's just find out here =) <
MarcelG
10 November 2005, 09:14
Originally posted by Shaggy Sorry for the absence, emergency at work.
Marcel, what it looks like is happening there is that the link gets passed through the ReplaceURLs function when using the [url] tag, constructing the anchor tag and truncating the display text, if need be. Then, for some reason, that outputted code is being picked up by the chkURLs function and tries to pass both ocurrences of the URI through edit_hrefs.
No apologies necessary ! I know what you mean I have the same idea....still a bit boggled by the ReplaceURLs function....I think we need to do some modifaction there...<
tribaliztic
10 November 2005, 09:16
You guys have to look over your priorities... ;) <
MarcelG
10 November 2005, 18:41
guys, the bug we're experiencing is not a side effect of this mod ; it's in the basecode for some time already, even here at Snitz.
Have a look at this topic: http://forum.snitz.com/forum/topic.asp?TOPIC_ID=60139 Quote it to see which forumcode I used for which URL.
Then, have a look at the output HTML...
I've filed a bugreport in the dev section for this.<
tribaliztic
11 November 2005, 03:10
I hope HuwR's answer can help =) Wouldn't it be possible to redirect these urls so it's not parsed twice?
<
MarcelG
11 November 2005, 05:05
I've proposed a fix that needs to be doublechecked.<
tribaliztic
11 November 2005, 06:03
Wohoo!
Nice work (I hope.. ;)) <
Shaggy
11 November 2005, 06:31
Good man, Marcel That was going to be my next suggestion; beat me to it.
<
MarcelG
11 November 2005, 07:25
Well, I guess we just have to wait untill we hear about the final bugfix for Snitz, to assure that our nifty mod is compatible with basecode snitz.<
Podge
11 November 2005, 07:33
What was the suggested fix?<
Shaggy
11 November 2005, 08:09
Looks like it hasn't been moderated yet. I threw in a suggestion as well to check that the 4 characters succeeding the URI in ChkURLs are not </a> before calling the edit_hrefs function.
<
MarcelG
11 November 2005, 09:12
Originally posted by Podge What was the suggested fix?
Mine was this one: http://www.oxle.com/topic.asp?TOPIC_ID=3292#31149 (it's dutch, but I think you know what I mean).
E.g., checking for _blank"> prior to parsing it though the function.<
tribaliztic
11 November 2005, 09:12
Can't we try that anyways? =) <
Shaggy
11 November 2005, 09:15
Great minds, 'ey, Marcel?! <
MarcelG
11 November 2005, 10:14
lol, well, with me coming in from the left, and you attacking from the right, we scared the hell out of this bug! Fredrik, if you want to you can adapt that method, however, for the sake of controlled mod development I think it is wise to still consider it a béta.
I'm not sure if my piece of code does what it should do.
One of the drawbacks of that method is that you can create phising links with Snitz, so perhaps we need to add something on top of it to prevent that. With a phising URL I mean a URL that looks like the one, but points to another. In HTML looking like this:
But, perhaps I'm taking this 'issue' too far, because with any forumpackage you can create these phising urls with a method like this one: http://www.safetarget.com
Simply add some useless forumcode in the http:// and www part; invisible to the viewer, but visible to the function that stops skips the url from parsing.
<
tribaliztic
11 November 2005, 10:17
Ok, ok.. I'm in no hurry =) <
RArch
06 December 2005, 17:14
Any update on this?
Some of my users just love to post long ebay links in my forum...
<
tribaliztic
07 December 2005, 02:53
We're waiting for answers in this thread http://forum.snitz.com/forum/topic.asp?TOPIC_ID=60140 <
tribaliztic
02 February 2006, 08:52
Any news? =)<
tribaliztic
03 April 2006, 09:06
bumpetibump...
<
MarcelG
20 April 2006, 09:59
I've wrapped up the changes I made as a 'mod' : See here for instructions.<
RArch
20 April 2006, 15:33
Thanks for that MarcelG works a treat with SHN beta v9 too.
<
Eric Coleman
29 July 2006, 14:43
In the file inc_func_common.asp, find the function FormatStr,
paste the following code immediately ABOVE the bottom 3 lines of the function, the bottom 3 lines I'm talking about are
FormatStr = fString on Error goto 0 end function
Here is the code to paste,
Code:
Dim c, n, m, j, k, i, fString2
c = 60 'max text length to display for a URL n = 0 m = 0 i = 0 Do i = m + 1 n = InStr(n + 1, fstring, "<a", 1) If n = 0 Then Exit Do m = InStr(n + 1, fstring, "</a", 1) If m = 0 Then Exit Do j = InStrRev(fstring, ">", m, 1) If j > n Then j = j + 1 k = Mid(fstring, j, m - j) If Len(k) > c Then fstring2 = fstring2 & Mid(fstring, i, j - i) & Left(k, c - 3) & "..." m = m - 1 Else fstring2 = fstring2 & Mid(fstring, i, m - i) m = m - 1 End If Else fstring2 = fstring2 & Mid(fstring, i, m - i) m = m - 1 End If Loop If i > 0 Then fstring2 = fstring2 & Mid(fstring, i, Len(fstring) - i + 1) End If fString = fString2
How does this work? The forum doesn't convert the URL bb tags to html untill it's displayed for the user, generally through topic.asp. This section of code parses the HTML after the forum converts the "URL" tags to "A" tags.
If you want to test this code before going live with it, simply surround the code with an
Code:
If mlev = 4 Then
End If
block, so that only administrators can see the results. I've tested this with lots of broken HTML to find bugs, but please test it for yourself.<
MarcelG
30 July 2006, 06:15
Eric,
You're doing this for all instances of <a and </a ?
What about urls like these ? <a href="http://www.whatversite.com/image.jpg"><img src="http://www.whatversite.com/thumb.jpg"></a> ?
You don't want to shorten those....<
Eric Coleman
30 July 2006, 11:02
You're right. I forgot to check for stuff like that since I generally don't allow images to be posted on my forum. here is an updated version. There is currently only 1 bug that I'm aware of.
The addition of the "..." doesn't cross html boundaries. For example, if clipping to 10 characters, the following would happen, "123456789<i>0</i>abcd" gets converted to "1234567...<i></i>" instead of "1234567..<i>.</i>" This really isn't that important since text is being stripped away and the original formatting, if any, will be messed up.
As before, In the file inc_func_common.asp, find the function FormatStr,
paste the following code immediately ABOVE the bottom 3 lines of the function, the bottom 3 lines I'm talking about are
FormatStr = fString on Error goto 0 end function
Code:
Dim c c = 60 'max text length to display for a URL
Dim n, m, j, k, i, x, y, z, w, v Dim oReg, oMatches, oMatch Set oReg = New regExp n = 0 m = 0 i = 0 'fstring2 = fstring c = c - 3 if c < 0 then c = 3 Do i = m + 1 n = InStr(n + 1, fstring, "<a", 1) If n = 0 Then Exit Do m = InStr(n + 1, fstring, "</a", 1) If m = 0 Then Exit Do 'j = InStrRev(fstring, ">", m, 1) j = InStr(n + 1, fstring, ">", 1) If j > n And j < m Then j = j + 1 k = Mid(fstring, j, m - j) If Len(k) > c Then 'k is a string that needs to be replaced.
oReg.Pattern = "<[^>]*>" oReg.Global = True oReg.MultiLine = True Set oMatches = oReg.Execute(k) x = 1 w = 0 z = "" y = "" v = False For Each oMatch In oMatches y = Mid(k, x, (oMatch.FirstIndex + 1) - x) x = oMatch.FirstIndex + 1 + oMatch.Length w = w + Len(y) If v = False Then If w <= c Then z = z & y & oMatch.Value Else 'w > c y = Left(y, c - (w - Len(y))) & "..." z = z & y & oMatch.Value v = True End If Else z = z & oMatch.Value End If Next If v = False Then y = Mid(k, x, Len(k) + 1 - x) w = w + Len(y) If w > c Then y = Left(y, c - (w - Len(y))) & "..." End If z = z & y End If
'fstring2 = fstring2 & Mid(fstring, i, j - i) & Left(k, c - 3) & "..." fstring2 = fstring2 & Mid(fstring, i, j - i) & z m = m - 1 Else fstring2 = fstring2 & Mid(fstring, i, m - i) m = m - 1 End If Else fstring2 = fstring2 & Mid(fstring, i, m - i) m = m - 1 End If '<a </a Loop If i > 0 Then fstring2 = fstring2 & Mid(fstring, i, Len(fstring) - i + 1) End If fstring = fstring2
<
SiSL
22 December 2008, 01:44
Now reviving that one...
Any new brainstorming?
I tried vB style, yet ofcourse, VBscript does not allow conditional regEx statements to shortcut this.<
MarcelG
22 December 2008, 03:21
SiSL, please refresh my memory ; what needs to be done in this thread/mod? I'm using the clipped URL's mod for years already, and I cannot say I'm missing something....? <
SiSL
22 December 2008, 07:32
If I remember... There was something to solve with forums url handling... Multi linking?<