break up long url text using wordwrap()

udijw - March 12, 2007 - 18:57
Project:Go - url redirects
Version:HEAD
Component:Code
Category:feature request
Priority:minor
Assigned:spiderman
Status:won't fix
Description

currently the target URL is displayed in one line. sometimes this target URL is long and it "disturbs" the format of the page.
can the target URLs span multiple lines?
thanks

#1

BioALIEN - August 23, 2007 - 10:35
Version:4.7.x-1.x-dev» 5.x-1.3

As the 4.7.x branch has been dropped, I am moving this to 5.x as the issue is still valid.

#2

spiderman - October 29, 2007 - 17:51
Assigned to:Anonymous» spiderman

definitely a valid point- i've seen this one in my own testing, and it's a pain. i think a decent approach to this would be to wrap the link text in a call to wordwrap().

we could then give the admin control over the configurable parameters "width", "break" to define a maximum length of the text and what character to break it with (a space might be sufficient, in some cases). the "cut" flag might also be useful, to select mid-word character break.

if people agree with this approach, i definitely volunteer to roll a patch for this one :)

#3

spiderman - November 3, 2007 - 17:36
Title:statistics format» break up long url text using wordwrap()
Status:active» needs review

attached is a patch against the latest gotwo.module (1.5.2.3) which adds three admin settings for enabling word wrapping, setting wrap width, and selecting the character to wrap with (space or newline). the implementation in __gotwo_filter is then a few simple lines to call wordwrap() before writing out the final tag.

feedback on the general approach as well as the specifics of the patch are greatly appreciated :)

AttachmentSize
gotwo.127103.patch 1.82 KB

#4

hass - December 30, 2007 - 00:22

Why are we not using CSS here? Maybe we make the URL hidden and a mouse over will show the complete URL as tool tip.

#5

BioALIEN - December 30, 2007 - 02:30

IMHO, wordwrap() introduces extra code for little gain. I think the tool tip idea is brilliant. Very simple and gets the job done. +1

#6

hass - February 24, 2008 - 13:30

We could also reuse this core function...

<?php
/**
* It is possible to adjust the width of columns generated by the
* statistics module.
*/
function _statistics_link($path, $width = 35) {
 
$title = drupal_get_path_alias($path);
 
$title = truncate_utf8($title, $width, FALSE, TRUE);
  return
l($title, $path);
}
?>

what ends in "http://www.example.com/verylongurl...".

#7

BioALIEN - February 27, 2008 - 20:59

hass, that's a brilliant find. I feel stupid for not finding this sooner! Let's keep it consistent with core so +1 from me!

#8

hass - February 28, 2008 - 00:14

2 possible ways... make gotwo depend on statistics module and reuse the same function, or duplicate code... I think duplicating here gives us something more... not sure if everyone using gotwo like to activate statistics. :-)

#9

BioALIEN - February 29, 2008 - 02:47

I am using statistics module. While its safe to assume whoever is interested in gotwo.module will also be interested in stats in general, due to the strain statistics.module places on the database, I don't think it's wise to make this module depend on it.

As a result, I think it's easier and more flexible to just duplicate the code. However, I still like the idea of showing the full URL as a tooltip in addition to using _statistics_link()

#10

hass - February 29, 2008 - 07:58
Status:needs review» needs work

#11

spiderman - March 4, 2008 - 03:17
Status:needs work» needs review

ok i like the idea of using truncate_utf8() to allow for just shortening long urls, but i think the point of the original request was not to cut off the text, but just make it possible to wrap.

i've re-rolled this patch so the admin settings provide an option: either use wordwrap() to split long text up, or use truncate_utf8() to provide shortening of urls to a specified length. attached is the new patch for review. thoughts on this approach?

AttachmentSize
gotwo.127103-2.patch 2.3 KB

#12

hass - August 18, 2009 - 21:15
Version:5.x-1.3» HEAD
Status:needs review» needs work

Feel free to post a patch with a user friendly version, without any extra settings, for e.g. like #6, otherwise close at latest in 3 months.

#13

hass - October 20, 2009 - 17:54
Status:needs work» won't fix
 
 

Drupal is a registered trademark of Dries Buytaert.