Shorten URLs

Register an Account
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 07-09-2007, 08:13 AM
Constant Pligger
 
Join Date: Apr 2007
Posts: 1,042
I have a problem with long URLs in the commments and story texts (http://forums.pligg.com/general-help...ry-text.html): They end in the middle of the sidebar.

Is it possible to shorten their display like it is here in preview mode: some 20 characters and three dots ?


P.S.: If I would know how to code the story-id (http://forums.pligg.com/suggestions/...ment-link.html) some of my problems would disappear. :-)
Reply With Quote
  #2 (permalink)  
Old 07-16-2007, 11:08 AM
Constant Pligger
 
Join Date: Apr 2007
Posts: 1,042
Anyone interested?
Reply With Quote
  #3 (permalink)  
Old 07-16-2007, 12:29 PM
Constant Pligger
 
Join Date: Apr 2007
Posts: 1,042
Could this code be helpful apart from the missing dots at the end?

<?php

$text = preg_replace('@http://((\S{1,20})\S+)@','<a href="http://\\1" target="_blank">\\2</a>',$text);

?>
Reply With Quote
  #4 (permalink)  
Old 07-16-2007, 04:49 PM
Constant Pligger
 
Join Date: Apr 2007
Posts: 1,042
I´ve found a wordpress plugin called shrinkylink (void *). Maybe it can be used with little adaption.
Reply With Quote
  #5 (permalink)  
Old 07-17-2007, 06:28 PM
Constant Pligger
 
Join Date: Apr 2007
Posts: 1,042
Another solution would be wrapping. See on the browser side (FF): https://addons.mozilla.org/de/firefox/addon/2547
Reply With Quote
  #6 (permalink)  
Old 07-17-2007, 07:04 PM
Pligg Developer/Admin
Pligg Version: 0
Pligg Template: none
 
Join Date: Jun 2006
Location: Muncie, Indiana
Posts: 3,215
Here is a function that will shorten text to a certain amount of characters

PHP Code:
function ShortenText($text) {
    
$chars 20;

  
$text $text." ";
  
$text substr($text,0,$chars);
  
$text substr($text,0,strrpos($text,' '));
  
$text $text."...";

  return 
$text;
  }        
    
?> 
Sample usage:

Code:
$sampleText = 'This is some sample text. This is some sample text'

ShortenText(sampleText);
Output:
Code:
This is some sample ...
Basically you pass whatever you want into the ShortText function and it will only display 20 chars and three periods on the end.

BTW, I have lost my touch for PHP since I program in ASP.NET all day so it may not be perfect.
Reply With Quote
  #7 (permalink)  
Old 07-18-2007, 02:30 AM
Constant Pligger
 
Join Date: Apr 2007
Posts: 1,042
Thank you kbeeveer46,

but I have no clue where to call that function. In text_to_html (http://forums.pligg.com/general-help...tory-text.html) ?
Reply With Quote
  #8 (permalink)  
Old 07-28-2007, 10:33 AM
Constant Pligger
 
Join Date: Apr 2007
Posts: 1,042
Anyone interested?
Reply With Quote
  #9 (permalink)  
Old 09-02-2007, 10:35 PM
AshDigg's Avatar
Mayor of PliggVille/Coder
 
Join Date: Dec 2005
Posts: 1,515
This will truncate the story titles. Still working on something for the comments. Click on the 'text changed' links to see the changes that need to be made.
Reply With Quote
  #10 (permalink)  
Old 09-04-2007, 05:47 AM
Constant Pligger
 
Join Date: Apr 2007
Posts: 1,042
Thank you, I guess you missed a '' at line 17 of sidebarstories.php.

I not sure wheter I got you right: I have a problem with long URLs in the description of a story and in comments, respectively. This has also consequences to the sidebar display of those URL links.

I´ve encountered another severe problem: Large comments lead to a size at comment management that pushes the check box for deletion under the sidebars, i.e. they´re without a function. Could you please fix that?

Another question: Is revision 1237 related to this problem (http://forums.pligg.com/bug-report/7...sidebar.html)?
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Friendly URL's for stories And (error - Oops, what you're looking for isn't here!) roor Questions and Comments 6 07-12-2009 01:54 PM
Change outgoing URLs to to actual URLs swese44 Questions and Comments 3 07-27-2008 02:08 PM
Has anyone got Friendly Urls (Url Method 2) working? revolver Questions and Comments 11 05-08-2008 01:32 AM
Seo Friendly Urls - Urlmethod 2 canadianguy33 Questions and Comments 15 05-12-2007 10:57 PM
Simplified Friendly Urls idea revolver Questions and Comments 0 11-07-2006 02:20 PM


Pligg Modules and Pligg Templates from Pligg Pro Find support on the Pligg CMS Forum - 24 hours a day! Make a donation to support Pligg CMS development