...

View Full Version : Disable Function id $ =1



ajloun
08-28-2009, 08:59 AM
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.


function SmartCensor($content){
if ($send != 1)
{
return false;
}


the 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($badword, 0, 1) == "[" && substr($badword, ($len - 1), 1) == "]") {
$content = preg_replace("@".substr($badword, 1, ($len - 2))."@i", substr($rep, 0, (strlen($rep) - 2)), $content);
continue;
}

$badwordpreg=preg_split('//', $badword, -1, PREG_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;
}

Phil Jackson
08-28-2009, 09:07 AM
function SmartCensor($content){
if ($send != 1)
{
return false;
}
else
{
return $content;
}
}

ajloun
08-28-2009, 09:20 AM
Thx Phill but that stoped even the Comment from shown up , the Comment statment looks like this.


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.

Fatal error: Call to undefined function SmartCensor()

any idea

Phil Jackson
08-28-2009, 09:23 AM
<?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($badword, 0, 1) == "[" && substr($badword, ($len - 1), 1) == "]") {
$content = preg_replace("@".substr($badword, 1, ($len - 2))."@i", substr($rep, 0, (strlen($rep) - 2)), $content);
continue;
}

$badwordpreg=preg_split('//', $badword, -1, PREG_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);
?>

ajloun
08-28-2009, 09:42 AM
thx again Phil.. Better Result this time ..

Now on the top of the code u edited to me.

$send=0;


it dont seem to make any different the Value whatever u put the function still working. So i removed it .. and Changed

if ($send == 1)
to

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

$send=0;

Phil Jackson
08-28-2009, 09:47 AM
if ($send === 1)

Phil Jackson
08-28-2009, 09:48 AM
soory not talkative im in a rush to shoot out.

Fou-Lu
08-28-2009, 09:48 AM
$send is not within the scope of function.
Alter the function parameters to accept the $send variable. Do not opt for globalization:


function SmartCensor($content, $send = 0)
{
....


Change the $send to 0 or 1 for whatever default you want it to use.

Phil Jackson
08-28-2009, 09:55 AM
why not opt for globalization? surely more flexible

if ($send === 1)
works fine and truly believe it is a suitable use.

Fou-Lu
08-28-2009, 10:05 AM
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:


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.

ajloun
08-28-2009, 10:21 AM
Fou , You are Amazing this Exactly wht i needed


$send = 0;
function SmartCensor($content)
{
global $send;
if ($send === 1)

but as i'm new wht is so bad of useing global

Fou-Lu
08-28-2009, 10:25 AM
Fou , You are Amazing this Exactly wht i needed


$send = 0;
function SmartCensor($content)
{
global $send;
if ($send === 1)


No, I strongly discourage globalization.
Use this instead:


function SmartCensor($content, $send = 0)
{
if ($send === 1)
....
}


// than when calling, these are valid:
$send = 1;
print smartCensor($content);
print smartCensor($content, $send);

ajloun
08-28-2009, 10:36 AM
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

Fou-Lu
08-28-2009, 10:48 AM
You're welcome.
This is much more portable, now you don't need to be worried about any particular variables in the calling scope.

ajloun
08-28-2009, 11:04 AM
Thx Man .. One Problem Left . Now How to edit this Statment to include $send with Comment.


$message['comment'] = $myts->makeTareaData4Show(SmartCensor($myrow['comment']),0);

This Shows Up the Comment ..

Fou-Lu
08-28-2009, 11:58 AM
$message['comment'] = $myts->makeTareaData4Show(SmartCensor($myrow['comment'], 1),0);


Or you can use a variable and set that to 0 or 1.

Phil Jackson
08-28-2009, 01:04 PM
sorry, im back. After walking to the bus stop i realised what i said and it was rubish, Fou-Lu is correct.

ajloun
08-28-2009, 09:47 PM
$message['comment'] = $myts->makeTareaData4Show(SmartCensor($myrow['comment'], 1),0);


Or you can use a variable and set that to 0 or 1.

Sorry For delay answering .. That worked Great ... Thank You and All



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum