View Single Post
  #4 (permalink)  
Old 01-12-2008, 05:18 AM
AnAlienHolakres3's Avatar
AnAlienHolakres3 AnAlienHolakres3 is offline
Pligg Donor
 
Join Date: Jul 2007
Location: Prague
Posts: 119
Thanks: 7
Thanked 112 Times in 40 Posts
Send a message via ICQ to AnAlienHolakres3
Better Read More v0.2

I have experienced a great issue when users CAN add some HTML tags to story content. The problem is that if html tags are used and story content is cutted to 165 characters, there will NOT be endtags.

What does it mean practically?
Big problem. Not only page is not valid, every story content will be then bold,italic or underlined also (depends on allowed tags).

Solution:
1) Disallow HTML tags in story.
2) Use my new hardcoded update.

It is funny that original idea was pretty simple but this is quite difficult because we need alternative story content with closed html tags.

Update:
Replace original code in link.php
PHP Code:
  // if link content < 160 chars then no "MORE" link
        
if (strlen($this->content)>165){
        
$smarty->assign('long_content',true);          
        }
        
// end 
with
PHP Code:
         //*********************************************************************
        //READ MORE ADDON START
        
        // if link content < 160 chars then no "MORE" link
        
if (strlen($this->content)>165){
        
//find if text has unclosed tags
                              
        
$cutted_contentutf8_substr($this->content,0,165);
        
        
//shortest tag can be at least 3 chars long
        
for ($i=$i<strlen($cutted_content)/$i++) {     
    
       
//find html tag if previous tag position number was lower 
          
if ($gtpos <= $i*3) {         
          
$ltpos=stripos($cutted_content,"<",$i*3);
          
$gtpos=stripos($cutted_content,">",$i*3);
          }else {
           
           
$ltpos=stripos($cutted_content,"<",$ltpos+1);
           
$gtpos=stripos($cutted_content,">",$gtpos+1);  
        
            } 
            
//if tag was detected  
            
if ($ltpos>-&& $gtpos>-1){
          
          
$tag=substr($cutted_content,$ltpos+1,$gtpos-$ltpos-1);
          
// exclude empty tags and end tags    
          
if(strlen($tag)>&& substr($tag,0,1)!="/"){       
          
$count[$tag]++;
          
$tagname[]=$tag;
          }
          }else {
          
//no more tags, no more cycles needed  
          
break;   
          }  
          }
          
          
          
//check if tag has its own closetag
        
if ($tagname) {  
          
          
$origtext=$cutted_content;  
       
          foreach (
$tagname as $tagn) {
          
          
$cltag=stripos($origtext,"</$tagn>");
          if (
$cltag ==false){
            
$addclosetags[]="</$tagn>";  
            }else {
            
$origtext substr($origtext,0,$cltag).substr($origtext,$cltag+strlen("</$tagn>"));   
            }            
         }
          if (
$addclosetags){
            
$addclosetagsarray_reverse($addclosetags);
              
$updated_content=$cutted_content;        
                  foreach (
$addclosetags as $at){
                       
$updated_content .=$at;
            }
        
         
        
$smarty->assign('updated_content',$updated_content);
        
$smarty->assign('add_closetags',true);
           } 
//update v 0.2
        
}
        
$smarty->assign('long_content',true);
        
        }                                                                       
        
//READ MORE ADDON END
        //********************************************************************** 
Now open link_summary.tpl in your templates/yget/ folder and find
Code:
    {if $show_content neq 'FALSE'} ...something...{/if}
Replace it with:
Code:
{if $show_content neq 'FALSE'}
                    
                    {if $add_closetags eq true}
                    {if $pagename neq "story"} 
                    {$updated_content}
                    {else}
                    {$story_content}
                    {/if}
                    {else}
                    {$story_content}
                    {/if}
Now everything should work smoothly
__________________
=Everything that has a beginnig has an end=
=Nevere stop fighting=

Site: http://www.vselink.cz

Last edited by AnAlienHolakres3; 01-21-2008 at 04:15 AM.. Reason: Update 0.2
Reply With Quote
The Following User Says Thank You to AnAlienHolakres3 For This Useful Post: