Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

how to make operator "does contain" and "does not contain" ?

how to make operator "does contain" and "does not contain" ?

hello Stephen

I would like customize a recipe for show/hide a module according to value inside CB fields. For that I used your CB recipe example and I made this:

$user_id = $db->getEscaped((int)($user->id));

if ($user_id > 0) {
$query = "select * from #__comprofiler  where user_id = '$user_id';";
$db->setQuery( $query );
$row     = $db->loadObject();
/* you can now get hold of state, phone, fax, website,
  * location, or whatever else they enter. All optional fields
  * like this get prefixed with "cb_"cb_googlespam
  */
$email = $row->email;
$gmail = $row->cb_gmail;
// etc... add more variables depending on what fields are set up in CB.

// your rules: use any of the following and customize as required.
if ($email == gmail) return 120;
if ($gmail == 0) return 120;
}


This recipe work well for field "cb_gmail" because the check is made using == that mean the operator "equal".

Now I would like make also a check with the email field with a operator "does contain" but it seem is not possible in PHP. I make some search on the web and it seem with CGI is possible to use =~ who is equivalent to "does contain". I tested by putting this operator in the recipe but this don't work...



In fact my final goal is to show a specific module only with this setup:

1) The field cb_gmail is equal to 0
2) The field email "does contain" the word gmail
3) The field cb_gmail is equal to 0 AND The field email "does not contain" the word gmail


In fact I want setup this trick because Google have the tendencies to put sometime email sent from my domain in the Spam box of Gmail user. This is of course annoying for me and for user, reason why I want display a warning module telling to users to take appropriate measure (like create a filter for never put email coming from my domain inside spam box) for avoid this problem. I do not spam my users and I don't make any mass emailing..but I don't know why Google treat my message like spam even if my server is well configured and not blacklisted. I followed all Google advices about this concern but no change. All others provide like Yahoo, Hotmail or any others treat normally my email...Is just a Gmail problem...

The recipe I try to setup is because if a user register to my site with his Gmail email address, the warning module will be displayed with inside some explanations and a short tutorial for create a filter in Gmail. If the user setup this filter, no more reason to display the warning module. So I created a single CB checkbox field for allow users to hide the warning module. This checkbox field is displayed inside CB user edit profile (with the help of CB conditional field properties) only if gmail address is detected inside Email field.

The problem is maybe a user instead to create a Gmail filter and after hide the warning module, he will prefer maybe change email address for provide a non Gmail address. In that case my single checkbox will disapear and user will not able to tick the checkbox for hide the warning module became useless. This is why I need to setup the variable described in the point 3... I'm not totally sure of my setup but normally it should work.

Do you see?? Hope you understand..my english is not very rich...

Unfortunately I'm not a coder and don't have any PHP knowledges... :-(

Have you a solution for that please??

Many thank for help

cheers

dotcom22
Junior Modder
ranks
useravatar
Offline
21 Posts
Administrator has disabled public posting

Re: how to make operator "does contain" and "does not contain" ?

hi dotcom22,

That's a great question!

Actually it's quite easy in PHP to do a "contains" search.

I see your 3 conditions. I assume that you want to module to display if any one of the conditions is met. In that case, try the following PHP code:

Code:

$user_id = $db->getEscaped((int)($user->id));

if ($user_id > 0) {
$query = "select * from #__comprofiler  where user_id = '$user_id';";
$db->setQuery( $query );
$row     = $db->loadObject();
/* you can now get hold of state, phone, fax, website,
  * location, or whatever else they enter. All optional fields
  * like this get prefixed with "cb_"cb_googlespam
  */
$email = strtolower($row->email);
$gmail = $row->cb_gmail;

if ($gmail == 0) return 120;
if (strpos($email, 'gmail') !== false) return 120;

To me it looks like your 3rd condition is not necessary, because whenever $gmail == 0, the 1st condition will be met regardless of whether the email contains "gmail".

Note: in the last line, the "!==" is not a mistake. It should be exactly as written above.

Hope that helps,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: how to make operator "does contain" and "does not contain" ?

hello Stephen

Thank for your reply...

I tried your code but unfortunately no luck... No matter if I change email address with another without "gmail" inside or if I tick the checkbox cb_googlespam who must add a value 1 instead 0...The module is always displayed...

here the exact code I paste in Metamod:

$user_id = $db->getEscaped((int)($user->id));
if ($user_id > 0) {
$query = "select * from #__comprofiler  where user_id = '$user_id';";
$db->setQuery( $query );
$row     = $db->loadObject();
/* you can now get hold of state, phone, fax, website,
  * location, or whatever else they enter. All optional fields
  * like this get prefixed with "cb_"cb_googlespam
  */
$email = strtolower($row->email);
$gmail = $row->cb_googlespam;

if ($gmail == 0) return 120;
if (strpos($email, 'gmail') !== false) return 120;
}

I checked my CB fields "email" and "cb_googlespam" is the correct name field... The module is also correct and have the ID 120...

any suggestion please?

dotcom22
Junior Modder
ranks
useravatar
Offline
21 Posts
Administrator has disabled public posting

Re: how to make operator "does contain" and "does not contain" ?

hello again Stephen

I'm sorry in fact your code work well but only partially... I made many test but is difficult to understand when it work or not. However I identified where is the issue.

Here my actual setup:

- Metamod is set to be module with Registered Access level
- Metamod is set to "all users" for the variable Show Quick module(s)
- Metamod contain this code:

$user_id = $db->getEscaped((int)($user->id));

if ($user_id > 0) {
$query = "select * from #__comprofiler  where user_id = '$user_id';";
$db->setQuery( $query );
$row     = $db->loadObject();
/* you can now get hold of state, phone, fax, website,
  * location, or whatever else they enter. All optional fields
  * like this get prefixed with "cb_" (see below).
  */
$gmail = $row->cb_googlespam;
$email = strtolower($row->email);


// your rules: use any of the following and customise as required.
if ($gmail == 0) return 120;
if (strpos($email, 'gmail') !== false) return 120;
}


Now when I say this work partially is only in the follow case:

If a user is detected to use a Gmail address the module ID 120 is displayed. If user decide to change Email with a non Gmail adress and WITHOUT tick the checkbox cb_googlespam, the module is always displayed when my goal was to hidden.

If user change Email with a non Gmail adress AND tick before the checkbox cb_googlespam, no problem the module is well hidden.

So the problem is only when user change email without tick before the checkbox. Like I explained the fact to change Email address with a non Gmail address will hide the checkbox (due to the CB conditional field setting I set for Email field), so the user will not able to tick this checkbox.

What is necessary also is to set a third rule in Metamod code like something:

if the field Email Does not contain "gmail" AND if the cb_googlespam is equal to "0" then hide the module ID 120.

Do you see??

thank for your patience.

cheers

dotcom22
Junior Modder
ranks
useravatar
Offline
21 Posts
Administrator has disabled public posting

Re: how to make operator "does contain" and "does not contain" ?

Yes, I see at last! Thanks for the explanation. Your original 3 rules could be written like this:

Either:

1) The field email "does contain" the word gmail, OR
2) The field cb_gmail is equal to 0 AND The field email "does not contain" the word gmail

And I'd code it like this:

Code:

$user_id = $db->getEscaped((int)($user->id));

if ($user_id > 0) {
  $query = "select * from #__comprofiler  where user_id = '$user_id';";
  $db->setQuery( $query );
  $row     = $db->loadObject();
  /* you can now get hold of state, phone, fax, website,
   * location, or whatever else they enter. All optional fields
   * like this get prefixed with "cb_" (see below).
   */
  $gmail = $row->cb_googlespam;
  $email = strtolower($row->email);

  if (strpos($email, 'gmail') !== false) return 120; // rule 1
  // now we already know that email does not contain "gmail"...
  if ($gmail == 0) return 120; // rule 2.
}

I hope it works this time smile

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: how to make operator "does contain" and "does not contain" ?

I tried this new code but no luck... The module is always displayed...

In fact if I'm not wrong the code is the same than the old one except variable is ordered/inversed..

I read the default explanation in the CB rule here:

http://www.metamodpro.com/metamod/recip … lder-pages

..and you say by putting && is equivalent to AND and I surprised to not see this symbol for make the "AND" in the rule...

So is not necessary to make also a rule similar to:

if (strpos($email 'gmail' !== false && $gmail == 0) return 120; // rule 3

??

I tried this rule but of course I get an error because the syntax is wrong...

Damned...I'm lost here... :-(

dotcom22
Junior Modder
ranks
useravatar
Offline
21 Posts
Administrator has disabled public posting

Re: how to make operator "does contain" and "does not contain" ?

My example was correct for what you described: there was no need for an "and", because the 2nd rule was only reached if the 1st rule failed, so this was like an implicit "and".

Try the following as a debugging step, to see what it thinks the values are. Try it with different values of the e-mail address (with and without gmail), and the checkbox.

Code:

$user_id = $db->getEscaped((int)($user->id));

if ($user_id > 0) {
  $query = "select * from #__comprofiler  where user_id = '$user_id';";
  $db->setQuery( $query );
  $row     = $db->loadObject();
  $gmail = $row->cb_googlespam;
  $email = strtolower($row->email);
  $contains = (strpos($email, 'gmail') !== false);

  if ($contains) echo "The e-mail address contains 'gmail'<br>";
  else echo "The e-mail address does not contain 'gmail'<br>";

  if ($gmail == 0) echo "googlespam box was not checked<br>";
  else echo "googlespam box was checked<br>";
}

Does this report the right things according to the e-mail address and box combinations?

Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: how to make operator "does contain" and "does not contain" ?

So I enabled Advanced Debug with your code and I tried all possible combination with/without gmail and checkbox checked/unchecked.... In all case the result is:

The e-mail address does not contain 'gmail'
googlespam box was not checked

It is strange... I don't know why...

any clue?

thank

dotcom22
Junior Modder
ranks
useravatar
Offline
21 Posts
Administrator has disabled public posting

Re: how to make operator "does contain" and "does not contain" ?

Just a thought... is the database prefix on your site actually jos_  ?
Please double check this and change it in the recipe above.

There's a problem on this forum that if you use the string "# __" (with no space between the # and the underscores) then it converts it to "jos_" in your post! So the recipe above should really have "# __comprofiler" (with no space) instead of "jos_comprofiler".

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: how to make operator "does contain" and "does not contain" ?

Of course!! I totally forgot about database prefix..sorry. On my site is not JOS... However I tried to put my own prefix but no change. I tried to put also like you suggest # with underscore without space and "comprofiler" but always no luck. If Email field does not contain "gmail" and if the checkbox is not checked, the module is always displayed..

I removed the CB Conditional on the Email field (the one who permit to show the checkbox if Email field contain "gmail") for see if this was the cause of the issue but no change.

So at this point I don't know what to do more. But here a problem still present because if the Email field does NOT contain "gmail" and if the checkbox is NOT checked that mean the code don't take care to the Email rule and take care only about the checkbox rule... because when I uncheck the checkbox no matter if Email contain or not "gmail"...the module is always displayed..

Have you some more suggestions?

In fact I use "mysqli" instead "mysql" as a Database Type... Maybe this can be the problem?? I don't think so...

thank again

dotcom22
Junior Modder
ranks
useravatar
Offline
21 Posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1679
Total Polls:
6
Total Posts:
5914
Total Posts Today:
1
User Info:
 
Total Users:
10816
Newest User:
sakmy567q
Members Online:
0
Guests Online:
72

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked