Pogledajte određenu poruku
Staro 13. 03. 2008.   #6
Ilija Studen
Direktor Kombinata
Invented the damn thing
 
Avatar Ilija Studen
 
Datum učlanjenja: 07.06.2005
Poruke: 2.669
Hvala: 44
119 "Hvala" u 64 poruka
Ilija Studen će postati "faca" uskoroIlija Studen će postati "faca" uskoro
Default

Ovo su Smarty modifikatori koje koristimo, ali mislim da ćeš se snaći da ih preradiš u ono što tebi treba. Koristi clickable funkciju.

PHP kôd:
/**
* Make links in a text clickable
*
* @param string $text
* @return string
*/
function smarty_modifier_clickable($text) {
  
$text ' '.$text;

  
$text preg_replace('#([\s\(\)])(https?|ftp|news){1}://([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^"\s\(\)<\[]*)?)#ie''\'$1\'.smarty_modifier_linkify(\'$2://$3\')'$text);
  
$text preg_replace('#([\s\(\)])(www|ftp)\.(([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^"\s\(\)<\[]*)?)#ie''\'$1\'.smarty_modifier_linkify(\'$2.$3\', \'$2.$3\')'$text);

  return 
substr($text1);
// smarty_modifier_clickable

/**
 * Convert a $value to a valid link while making sure that it does not get too long
 *
 * @param string $value
 * @param string $text
 * @param string $rel
 * @return string
 */
function smarty_modifier_linkify($value$text null$rel 'nofollow') {
  
$full_url str_replace(array(' ''\'''`''"'), array('%20'''''''), $value);
  
    if(
strpos($value'www.') === 0) {               // If it starts with www, we add http://
        
$full_url 'http://'.$full_url;
    } elseif (
strpos($value'ftp.') === 0) {     // Else if it starts with ftp, we add ftp://
        
$full_url 'ftp://'.$full_url;
  } elseif (!
preg_match('#^([a-z0-9]{3,6})://#'$value$bah)) {  // Else if it doesn't start with abcdef://, we add http://
        
$full_url 'http://'.$full_url;
  } 
// if

    // Ok, not very pretty :-)
    
$text = ($text == '' || $text == $value) ? ((strlen($value) > 55) ? substr($value39).' &hellip; '.substr($value, -10) : $value) : stripslashes($text);
    
    if(
$rel) {
      
$rel " rel=\"$rel\"";
    } 
// if
    
    
return "<a href=\"$full_url\"$rel>$text</a>";
// smarty_modifier_linkify 
Ilija Studen je offline   Odgovorite uz citat
3 članova zahvaljuje Ilija Studen za poruku: