31
Anonymous
Re: xoopsCodeDecode
  • 2009/1/7 16:04

  • Anonymous

  • Posts: 0

  • Since:


Thanks ghia .. this option will remove all tags but I need to remove plain text too.

Example:
"<img src=123.jpg />This is sample".
Result:
"<img src=123.jpg />"



32
Anonymous
Re: xoopsCodeDecode
  • 2009/1/7 16:15

  • Anonymous

  • Posts: 0

  • Since:


I'm using news_truncate_tagsafe too, can I use it to hid plain text with display images ?

33
trabis
Re: xoopsCodeDecode
  • 2009/1/7 18:50

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Instead of getting everything but the images and then delete them, why don´t you try to get just the image with preg_match?
I´m using the following code to get images added with bbcode:
if ($item['image'] == '') {
            
$patterns = array();
            
$idx = array();
            
$patterns[0] = "/[img(.*)]([^"()?&'<>]*)[/img]/sU";
            $idx[0] = 2;

            foreach ($patterns as $key => $pattern) {
                $matches = array();
                preg_match($pattern, $item['
description'], $matches);
                $image = @$matches[$idx[$key]];
                if ($image != ''){
                    $item['
image'] = $image;
                }
                unset($matches);
            }
            unset($patterns);
            unset($idx);
        }


Bad, bad xoops!
Quote:
$patterns[0] = "/\[img(.*)]([^\"\(\)\?\&'<>]*)\[\/img\]/sU";


So all you have to do is get a pattern for the images in html.
I hope Ghia can help you with this cause my knowledge of regex is zero.

34
ghia
Re: xoopsCodeDecode
  • 2009/1/8 2:30

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Quote:
$patterns[0] = "/<img[^<>]+>/sU";

35
Anonymous
Re: xoopsCodeDecode
  • 2009/1/8 12:38

  • Anonymous

  • Posts: 0

  • Since:


Thanks

I'm intresting to know how news_truncate_tagsafe function can count the plain text without tags ? at the above code, if I set $letters = 100 for example, just 10-15 letters will appear because news_truncate_tagsafe count img tag as part of article text.

36
trabis
Re: xoopsCodeDecode
  • 2009/1/8 13:41

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Well, I will need that for mytabs to!
My ideia is to replace image with for something like [XXX], then use the truncate feature, and then replace [XXX] with the image again!
Or thinking better, you can use the code provided by ghia to get the image code, then you get the length of the image code, then you use truncate 100+length.

37
ghia
Re: xoopsCodeDecode
  • 2009/1/8 14:20

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Truncate a text to a length without counting tags and not breaking words and suitable for UTF.
function truncate_text($Text$Limit
{
    
$len strlen($Text);
    if (
strlen($Text) <= $Limit) return $Text;
    
$Cnt 0;
    
$DoCnt 1;
    
$InUTF 0;
    for (
$i 0$i$len$i++)
    {
        if (
$Text{$i} == '<'$DoCnt 0;
        if (
$DoCnt 0)
        {
            
$ord_c ord($Text{$i});
            if ((
$ord_c 0xE0) == 0xC0)
            {
                
$InUTF 2;
            }
            if ((
$ord_c 0xF0) == 0xE0)
            {
                
$InUTF 3;
            }
            if ((
$ord_c 0xF8) == 0xF0)
            {
                
$InUTF 4;
            }
            if ((
$ord_c 0xFC) == 0xF8)
            {
                
$InUTF 5;
            }
            if ((
$ord_c 0xFE) == 0xFC)
            {
                
$InUTF 6;
            }
        }
        if (
$InUTF 0)
        {
             
$InUTF--; 
             if (
$InUTF 0)
             {
                  
$DoCnt 0
             }
             else
             {
                  
$DoCnt 1
             }
         } 
        if (
$DoCnt == 1)
        {
            
$Cnt++;
        }
        if (
$Text{$i} == '>'$DoCnt 1;
        
$Result .= $Text{$i};
        if (
$Cnt >= $Limit && $Text{$i} == ' ') break;
    }
    return 
$Result '...';
}
To try!

38
Anonymous
Re: xoopsCodeDecode
  • 2009/1/8 15:32

  • Anonymous

  • Posts: 0

  • Since:


Quote:
Or thinking better, you can use the code provided by ghia to get the image code, then you get the length of the image code, then you use truncate 100+length.

Length of the image code is not fixed .. using some attributes and name of image file will effect this lenght.

Ghia .. I test your function and it useful but when I set text lenght to zero, I got whole text.


39
Anonymous
Re: xoopsCodeDecode
  • 2009/1/8 17:48

  • Anonymous

  • Posts: 0

  • Since:


I think herve can fix this issue ( since latestnews based on his news module ) by improving news_truncate_tagsafe with ghia's idea or by adding story image hack then we can use image as separated item.

40
trabis
Re: xoopsCodeDecode
  • 2009/1/8 19:06

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Quote:

Mowaffak wrote:
Length of the image code is not fixed .. using some attributes and name of image file will effect this lenght.


I know, that is why you use strlen($imagetag)



Login

Username:
Password:

Lost Password? Register now!

Who's Online

67 user(s) are online (41 user(s) are browsing Support Forums)


Members: 0


Guests: 67


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits