bbPress

Simple, Fast, Elegant

bbPress support forums » Themes

Limit long words

(13 posts)
  • Started 11 months ago by Beaver6813
  • Latest reply from ganzua
  • This topic is not resolved
  1. Hey Guys,

    We're currently having some problems with longish words flowing out of the design, all normal words get text wrapped when they reach the end however long url's or lines don't, any ideas how to resolve?

    http://www.bblocked.org/forums/topic/10?replies=2

    An example can be seen there, that url would even go into the background if i hadn't shortened it, any ideas guys?

    Posted 11 months ago #
  2. bobbyh
    Member

    Yeah, the easy fix for this is adding:

    .post {overflow: hidden; }

    Posted 11 months ago #
  3. Yes but that won't wrap the word down or shorten it, it'll just cut it off... any other solutions?

    Posted 11 months ago #
  4. You could try this:

    .post {overflow: scroll; }

    Should scroll the extra content... I think that's what they are doing here, or something like that.

    Posted 11 months ago #
  5. bobbyh
    Member

    It sounds like you're looking for something like the proprietary word-wrap CSS property which works in IE browsers only, as far as I know.

    .post {word-wrap: break-word; }

    Posted 11 months ago #
  6. You want

    .post { overflow: auto; }

    which isn't actually the automatic setting - but it's the one that automatically adds a scrollbar if the post is too wide. Like multiline code here, it'll add the scrollbar only if needed. Also handy for images.

    And lol at everyone suggesting something else. :P

    Posted 11 months ago #
  7. oh right, auto... duh! (slaps forehead)

    Posted 11 months ago #
  8. Are you interested in a plugin that will force spaces into long urls?

    Posted 11 months ago #
  9. Ahhh that auto worked a treat ;-) I've used the break-word as well for IE so it doesn't even need to scroll when words are too long, in FF it just scrolls. Although a plugin to shorten long url's words etc might be quite cool, like:
    http://www.ilovebbpress.com/bla/blab/blalblba/indexnop/123
    to
    http://www.ilovebbpress.com/bla.../123

    If I get time next week I might make one... but don't quote me on that :-P

    Thanks guys for the help!

    Posted 11 months ago #
  10. Don't re-invent the wheel. WP-Chunk
    or Sam Ingle's Link Truncator for Wordpress can be hacked to support bbpress in under 5 minutes. There are probably others too.

    Posted 11 months ago #
  11. Here you are... ported from wp-chunk (literally only had to change the filter names)

    <?php
    /*
    Plugin Name: bb-chunk
    Description: Shortens the display of urls so they won't break your site theme. Ported from wp-chunk 2.0 ( http://www.village-idiot.org/archives/2006/06/29/wp-chunk/ )
    Author: The How-To Geek
    Author URI: http://www.howtogeek.com
    Version: 0.1
    */
    
    function make_chunky($ret)
    {
    
    	// pad it with a space
    	$ret = ' ' . $ret;
    	$ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "$1<a href='$2' rel='nofollow'>$2</a>", $ret);
    	$ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "$1<a href='http://$2' rel='nofollow'>$2</a>", $ret);
    	//chunk those long urls
    	chunk_url($ret);
    	$ret = preg_replace("#(\s)([a-z0-9\-_.]+)@([^,< \n\r]+)#i", "$1<a href=\"mailto:$2@$3\">$2@$3</a>", $ret);
    	// Remove our padding..
    	$ret = substr($ret, 1);
    	return($ret);
    }
    
    function chunk_url(&$ret)
    {
    
       $links = explode('<a', $ret);
       $countlinks = count($links);
       for ($i = 0; $i < $countlinks; $i++)
       {
          $link = $links[$i];
    
          $link = (preg_match('#(.*)(href=")#is', $link)) ? '<a' . $link : $link;
    
          $begin = strpos($link, '>') + 1;
          $end = strpos($link, '<', $begin);
          $length = $end - $begin;
          $urlname = substr($link, $begin, $length);
    
          /**
           * We chunk urls that are longer than 50 characters. Just change
           * '50' to a value that suits your taste. We are not chunking the link
           * text unless if begins with 'http://', 'ftp://', or 'www.'
           */
    	$chunked = (strlen($urlname) > 50 && preg_match('#^(http://|ftp://|www\.)#is', $urlname)) ? substr_replace($urlname, '.....', 30, -10) : $urlname;
    	$ret = str_replace('>' . $urlname . '<', '>' . $chunked . '<', $ret); 
    
       }
    } 
    
    remove_filter('post_text', 'make_clickable');
    add_filter('post_text', 'make_chunky');
    ?>
    Posted 11 months ago #
  12. Actually, seems to have flaky behavior unless you remove this line:

    remove_filter('post_text', 'make_clickable');

    Seems to work pretty well otherwise.

    Posted 11 months ago #
  13. Whenever I try to activate this plugin I get this error message;

    Plugin could not be activated; it produced a Fatal Error.

    Posted 10 months ago #

RSS feed for this topic

Reply

You must log in to post.

Code is Poetry.