Welcome to Geeklog, Anonymous Friday, March 29 2024 @ 01:40 am EDT

Geeklog Forums

Multiple [code ] blocks fix


jim

Anonymous
In response to ' Only one [code ] meta-tag allowed' (bug #621992) I modified COM_checkHTML to allow multiple [code ] blocks in a post. I've shown my code below. You can also see it in action in my story about the mod.

/**
* Makes an ID based on current date/time
*
* This function COM_creates a 17 digit sid for stories based on the 14 digit date
* and a 3 digit random number that was seeded with the number of microseconds
* (.000001th of a second) since the last full second. NOTE: this is now used for more than
* just stories!
*
* 10/13/2002 4:19AM jim AT jimweller.net added handling for mulitple  meta-tags
*
* @return	string	$sid  Story ID
*
*/

function COM_checkHTML( $str ) 
{
    global $_CONF;
	
    $str = stripslashes($str);

    // Get rid of any newline characters
    $str = preg_replace( "/\n/", '', $str );
    
    // Replace any $ with $ (HTML equiv)
    $str = str_replace( '$', '$', $str );
    
   

    // loop through consecutive  meta tags
    $start_pos = strpos( strtolower( $str ), '' );
    $end_pos = 0;
    while ( ! ( $start_pos === false ) )
    {
        $end_pos = strpos( strtolower( $str ), '
', $end_pos ); $end_pos += 7; // to account for the length of the tag $orig_pre_string = substr( $str, $start_pos, $end_pos - $start_pos ); $new_pre_string = str_replace( '', '', $orig_pre_string ); $new_pre_string = str_replace( '', '>', $new_pre_string ); $new_pre_string = str_replace( '
', '', $new_pre_string );
        $new_pre_string = str_replace( '
', '', $new_pre_string );
        $new_pre_string = str_replace( '</code></pre>', '', $new_pre_string );
        $new_pre_string = str_replace( '
', '', $new_pre_string ); $new_pre_string = nl2br( $new_pre_string ); $str = str_replace( $orig_pre_string, '
' . $new_pre_string . '
', $str ); $start_pos = strpos( strtolower( $str ), '
', $end_pos );
    } // ends while loop

    if( !SEC_hasRights( 'story.edit' ) || empty ( $_CONF['adminhtml'] ))
    {
        $str = strip_tags( $str, $_CONF['allowablehtml'] );
    }
    else
    {
        $str = strip_tags( $str, $_CONF['adminhtml'] );
    }

    return COM_killJS( $str );
}
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany

... or you could have taken my fix from CVS ;-)

bye, Dirk

 Quote

jim

Anonymous
I could have....Mine has less ops, but you get points for iterative intelligence w/ the do/while instead of while/do. Good to see that you moved all the dirt itno COM_handleCode. I think that is going to change as people find special cases that don't work. I just checked your CVS. To avoid this duplication of work I'm going to setup a dummy site http://geek.jimweller.net that is current CVS checkouts. I'm going to email you about getting CVS write access.
 Quote

jim

Anonymous
Notice how the article I submitted to you renders screwed up now? That's becuase &#091: and &#093: get converted to [ and ] in the text input box when you review the story. Then when you submit them they are real [ and ] again. Then you encounted the nesting problem with the parser. My work around was of course to edit in a text editor and then repaste everytime I did a preview/save.
 Quote

All times are EDT. The time is now 01:40 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content