Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts

    Disable Function id $ =1

    Hello Again . HUh

    this time , I need help to Disable the Bad word Censor function Below i need it if $send=1; to Not work

    i tried this But stopped even the comment from showing up.

    PHP Code:
    function SmartCensor($content){
    if (
    $send != 1)
    {
        return 
    false;

    the code

    PHP Code:
    $send=0;

     function 
    SmartCensor($content){

        
    $words_list=@file(XOOPS_ROOT_PATH.'/modules/ehdaa/censorwords.txt');
        
    $search=array('a','b','i','l','o','p','s');
        
    $replace=array('(?:a|\@|\*)','(?:b|8|3|\*)','(?:i|1|l|\!|\*)','(?:l|1|i|\!|\*)','(?:o|0|\*)','(?:p|\?|\*)','(?:s|\$|\*)');
        foreach(
    $words_list as $badword){
            
    $badword=rtrim($badword);

            
    $len=strlen($badword);
        if(
    $len <= 0)
            continue;
            
    $rep='';
            for(
    $i=0$i $len$i++){
                
    $rep.='*';
            }

            
    // Check to see if this word has brackets around it. If it is bracked, censor it in a simple form.
            
    if (substr($badword01) == "[" && substr($badword, ($len 1), 1) == "]") {
                
    $content preg_replace("@".substr($badword1, ($len 2))."@i"substr($rep0, (strlen($rep) - 2)), $content);
                continue;
            }

            
    $badwordpreg=preg_split('//'$badword, -1PREG_SPLIT_NO_EMPTY);
            
    $badwordpreg=str_replace($search$replace$badwordpreg);
            
    $badword='';
            for(
    $i=0$i count($badwordpreg); $i++){
                
    $badword.=$badwordpreg[$i];
                if(
    $i != (count($badwordpreg)-1)) $badword.='(.{0,5})';
            }
            
    $badword="/$badword/i";
            
    $content=preg_replace($badword$rep$content);
        }
        return 
    $content;


  • #2
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    PHP Code:
    function SmartCensor($content){
    if (
    $send != 1

        return 
    false

    else
    {
    return 
    $content;
    }


  • #3
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    Thx Phill but that stoped even the Comment from shown up , the Comment statment looks like this.

    PHP Code:
    echo SmartCensor($comment); 
    i guess need to change it too acording to $send value too or els i will get this error when $send not set 1.
    PHP Code:
    Fatal errorCall to undefined function SmartCensor() 
    any idea

  • #4
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    PHP Code:

    <?php

    $send
    =0

     function 
    SmartCensor($content$send){ 
        if (
    $send == 1
        { 
            return 
    $content
        }
        else
        {
            
    $words_list=@file(XOOPS_ROOT_PATH.'/modules/ehdaa/censorwords.txt'); 
            
    $search=array('a','b','i','l','o','p','s'); 
            
    $replace=array('(?:a|\@|\*)','(?:b|8|3|\*)','(?:i|1|l|\!|\*)','(?:l|1|i|\!|\*)','(?:o|0|\*)','(?:p|\?|\*)','(?:s|\$|\*)'); 
            foreach(
    $words_list as $badword){ 
                
    $badword=rtrim($badword); 
        
                
    $len=strlen($badword); 
            if(
    $len <= 0
                continue; 
                
    $rep=''
                for(
    $i=0$i $len$i++){ 
                    
    $rep.='*'
                } 
        
                
    // Check to see if this word has brackets around it. If it is bracked, censor it in a simple form. 
                
    if (substr($badword01) == "[" && substr($badword, ($len 1), 1) == "]") { 
                    
    $content preg_replace("@".substr($badword1, ($len 2))."@i"substr($rep0, (strlen($rep) - 2)), $content); 
                    continue; 
                } 
        
                
    $badwordpreg=preg_split('//'$badword, -1PREG_SPLIT_NO_EMPTY); 
                
    $badwordpreg=str_replace($search$replace$badwordpreg); 
                
    $badword=''
                for(
    $i=0$i count($badwordpreg); $i++){ 
                    
    $badword.=$badwordpreg[$i]; 
                    if(
    $i != (count($badwordpreg)-1)) $badword.='(.{0,5})'
                } 
                
    $badword="/$badword/i"
                
    $content=preg_replace($badword$rep$content); 
            } 
            return 
    $content
        }
    }
    $comment "i like @ss-tronauts";
    echo 
    SmartCensor($comment$send);  
    ?>
    Last edited by Phil Jackson; 08-28-2009 at 09:30 AM.

  • Users who have thanked Phil Jackson for this post:

    ajloun (08-28-2009)

  • #5
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    thx again Phil.. Better Result this time ..

    Now on the top of the code u edited to me.
    PHP Code:
    $send=0
    it dont seem to make any different the Value whatever u put the function still working. So i removed it .. and Changed
    PHP Code:
    if ($send == 1
    to
    PHP Code:
    if ($send == 0
    That Disabled the function so , to Enable it i change it back to 1 and to disable 0 ..
    But it dont respond to the value in
    PHP Code:
    $send=0

  • #6
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    PHP Code:
    if ($send === 1

  • #7
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    soory not talkative im in a rush to shoot out.

  • Users who have thanked Phil Jackson for this post:

    ajloun (08-28-2009)

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    $send is not within the scope of function.
    Alter the function parameters to accept the $send variable. Do not opt for globalization:
    PHP Code:
    function SmartCensor($content$send 0)
    {
    .... 
    Change the $send to 0 or 1 for whatever default you want it to use.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    ajloun (08-28-2009)

  • #9
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    why not opt for globalization? surely more flexible
    PHP Code:
    if ($send === 1
    works fine and truly believe it is a suitable use.

  • Users who have thanked Phil Jackson for this post:

    ajloun (08-28-2009)

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Globalization is less flexible.
    Using global variables eliminates the ability to reuse code, and creates a potential danger with public access to a variable by reference. Globalization should only be used when a callback requires a specific parameter list that cannot be overridden.

    I'm not certain you understand what I mean by globalization though. The if statement is still a requirement, but you're options are as follows:
    PHP Code:
    function SmartCensor($content$send 0

        if (
    $send === 1)
    ....

    // OR
    $send 0;
    function 
    SmartCensor($content)
    {
        global 
    $send;
        if (
    $send === 1
    Where the globalized function should be avoided where possible.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    ajloun (08-28-2009)

  • #11
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    Fou , You are Amazing this Exactly wht i needed

    PHP Code:
    $send 0
    function 
    SmartCensor($content

        global 
    $send
        if (
    $send === 1
    but as i'm new wht is so bad of useing global
    Last edited by ajloun; 08-28-2009 at 10:24 AM.

  • #12
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by onasre View Post
    Fou , You are Amazing this Exactly wht i needed

    PHP Code:
    $send 0
    function 
    SmartCensor($content

        global 
    $send
        if (
    $send === 1

    No, I strongly discourage globalization.
    Use this instead:
    PHP Code:
    function SmartCensor($content$send 0)
    {
        if (
    $send === 1)
        ....
    }


    // than when calling, these are valid:
    $send 1;
    print 
    smartCensor($content);
    print 
    smartCensor($content$send); 
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    ajloun (08-28-2009)

  • #13
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    function SmartCensor($content, $send = 0)
    {
    if ($send === 1)
    ....
    }


    // than when calling, these are valid:
    $send = 1;
    print smartCensor($content);
    print smartCensor($content, $send);
    This even Worked Much Better ... Thank You Man

  • #14
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You're welcome.
    This is much more portable, now you don't need to be worried about any particular variables in the calling scope.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #15
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    Thx Man .. One Problem Left . Now How to edit this Statment to include $send with Comment.

    PHP Code:
    $message['comment'] = $myts->makeTareaData4Show(SmartCensor($myrow['comment']),0); 
    This Shows Up the Comment ..


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •