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.

 

Recipe "show module just the first time" conflicts with one of my rule

Recipe "show module just the first time" conflicts with one of my rule

Hi Stephen, I am using the recipe "Show a module just once, for any user (cookied)" but I think the first line of command I have in the module might conflict. I have enabled the debug mode in the module but nothing prints.

Here's the code:

CODE 1 - Module 1 wrote:


$mainframe =& JFactory::getApplication();
$template =& $mainframe->getTemplate();
if ($template == "metal_jan2011") return "378";

/* on this template, use these modules */

$c = JRequest::getInt('SeenIt', 0, 'cookie');
if ($c) return;

/* if cookie was set, don't show anything, else... */

setcookie( 'SeenIt', 1, time()+60*60*24*365*10, '/' );
return 378;

/* return module 378, but only the first time */

Behavior: The module still show up after the first time.


More information: I intend to use this rule first in that module, then use a second module with the second rule "Don’t show the module on the first page they visit, but show it on every subsequent page and visit" to put the content (video) in another position at the bottom (and resided to smaller).


Here's the second code I intend to use, but once again i think the first line of code might conflict:

CODE 2 - Module 2 wrote:


$mainframe =& JFactory::getApplication();
$template =& $mainframe->getTemplate();
if ($template == "metal_jan2011") return "284";

/* on this template, use these modules */

$c = JRequest::getInt('SeenIt', 0, 'cookie');
if ($c) return 284;

/* if cookie was set, show module 284 */

setcookie( 'SeenIt', 1, time()+60*60*24*365*10, '/' );
return;

/* don't return anything the first time. */

Cheers, Alex.

atherrien
Modder Extraordinaire
ranks
useravatar
Offline
140 Posts
Administrator has disabled public posting

Re: Recipe "show module just the first time" conflicts with one of my rule

Ok I got something on the debug.

Code:



Page Identification
The PHP code below may be used to help MetaMod to identify the exact page that you are viewing. For help using this feature, please click here.
if (
$option == 'com_content'
and $view == 'frontpage'
and $Itemid == '1'
and JRequest::getVar('limit') == 8 /*!*/
and JRequest::getVar('layout') == 'default' /*!*/
and JRequest::getVar('lang') == 'en'
) return XXX; /* replace XXX with the module ID or position to display */
Note: lines starting with "and" and ending with /*!*/ contain rules that may be optional. You may wish to leave them out.
MetaMod debug info:
$option: com_content
$view: frontpage
$id:
$Itemid: 1
$timezone: default
$language: en-us
$language_code: en
$language_region: us
Including modules: 378

atherrien
Modder Extraordinaire
ranks
useravatar
Offline
140 Posts
Administrator has disabled public posting

Re: Recipe "show module just the first time" conflicts with one of my rule

There is an additional issue to this rule:

The rule "Don’t show the module on the first page they visit, but show it on every subsequent page and visit" will make the module show on every template without considering the first rule which commands the module to show only on a specific template.

atherrien
Modder Extraordinaire
ranks
useravatar
Offline
140 Posts
Administrator has disabled public posting

Re: Recipe "show module just the first time" conflicts with one of my rule

Ok, instead of this:

Code:

$mainframe =& JFactory::getApplication();

$template =& $mainframe->getTemplate();
if ($template == "metal_jan2011") return "378";

/* on this template, use these modules */

$c = JRequest::getInt('SeenIt', 0, 'cookie');
if ($c) return;

/* if cookie was set, don't show anything, else... */

setcookie( 'SeenIt', 1, time()+60*60*24*365*10, '/' );
return 378;

/* return module 378, but only the first time */

Try this:

Code:

/* only do anything in this rule if we're on the right template */


$mainframe =& JFactory::getApplication();
$template =& $mainframe->getTemplate();
if ($template == "metal_jan2011") {

  $c = JRequest::getInt('SeenIt', 0, 'cookie');
  /* if cookie was set, don't show a module.
     set a flag for the other module to tell it to display.
   */
  if ($c) {
    define("SHOW_SMALL_MODULE",true);
    return;
  }

  /* otherwise, set cookie */
  setcookie( 'SeenIt', 1, time()+60*60*24*365*10, '/' );

  /* and return the correct module */
  return 378;
}

And for the other MetaMod that shows things on subsequent page views:

Code:

/* only do anything in this rule if flagged by the

  other MetaMod.
*/

if ( defined("SHOW_SMALL_MODULE") ) return 284;

So what we have here is the 1st MetaMod doing all the hard work, deciding if it's the right template and whether it's the 1st time the page was displayed, or a subsequent time. Then in the second MetaMod we just pick up whether or not to display the small video.

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
3312 Posts
User info in posts
Administrator has disabled public posting

Re: Recipe "show module just the first time" conflicts with one of my rule

It works but I get this error message for the second module (the small resized video at the bottom even though the command is successful and it shows up)       

Code:


* Error loading Modules:

Your debug in metamodpro doesn't retrieve any further information, here's the only info I can get from it once enabled:

Code:


Page Identification
The PHP code below may be used to help MetaMod to identify the exact page that you are viewing. For help using this feature, please click here.
if (
$option == 'com_content'
and $view == 'frontpage'
and $Itemid == '1'
and JRequest::getVar('limit') == 8 /*!*/
and JRequest::getVar('layout') == 'default' /*!*/
and JRequest::getVar('lang') == 'en'
) return XXX; /* replace XXX with the module ID or position to display */
Note: lines starting with "and" and ending with /*!*/ contain rules that may be optional. You may wish to leave them out.
MetaMod debug info:
$option: com_content
$view: frontpage
$id:
$Itemid: 1
$timezone: default
$language: en-us
$language_code: en
$language_region: us
Including modules: 284

atherrien
Modder Extraordinaire
ranks
useravatar
Offline
140 Posts
Administrator has disabled public posting

Re: Recipe "show module just the first time" conflicts with one of my rule

I turned off joomla's debug mode AND all the new video module containing the latest mods (+ their own debug mode) and still the error persist.

Code:


* Error loading Modules:

atherrien
Modder Extraordinaire
ranks
useravatar
Offline
140 Posts
Administrator has disabled public posting

Re: Recipe "show module just the first time" conflicts with one of my rule

More information: The error message shows up only when the offline mode in joomla general configuration is disabled.

atherrien
Modder Extraordinaire
ranks
useravatar
Offline
140 Posts
Administrator has disabled public posting

Re: Recipe "show module just the first time" conflicts with one of my rule

There's a conflict when I repeat the same principle for another set of video module for another template "http://www.guitarweb3.com/?landing=4":

Problem : There's seems to be a conflict in the newly defined variable in the first module :

Code:


define("SHOW_SMALL_MODULE",true);

So I edited the code to:

Code:


define("SHOW_SMALL_MODULE2",true);

It only solves half of the conflict. The small video use to show up in the wrong template, so that is solved with the newly defined variable "SHOW_SMALL_MODULE2", but now the first module doesn't disappear after the first page. It stays even after refreshing the page.

atherrien
Modder Extraordinaire
ranks
useravatar
Offline
140 Posts
Administrator has disabled public posting

Re: Recipe "show module just the first time" conflicts with one of my rule

Here's what I tried, it doesn't work but you'll get the idea (remember that this is for a different template, the first attempt on the other template worked fine):

First module:

Code:


/* only do anything in this rule if we're on the right template */

$mainframe =& JFactory::getApplication();

$template =& $mainframe->getTemplate();

if ($template == "flamencofusion_internationnal_jan2011") {



  $c = JRequest::getInt('SeenIt2', 0, 'cookie2');

  /* if cookie2 was set, don't show a module.

     set a flag for the other module to tell it to display.

   */

  if ($c) {

    define("SHOW_SMALL_MODULE2",true);

    return;

  }



  /* otherwise, set cookie */

  setcookie( 'SeenIt2', 1, time()+60*60*24*365*10, '/' );



  /* and return the correct module */

  return 298;

}

Second module:

Code:



/* only do anything in this rule if flagged by the

  other MetaMod.

*/



if ( defined("SHOW_SMALL_MODULE2") ) return 380;

Result: The first module never disappears / and the second module never shows.

atherrien
Modder Extraordinaire
ranks
useravatar
Offline
140 Posts
Administrator has disabled public posting

Re: Recipe "show module just the first time" conflicts with one of my rule

OK I GOT IT! I solved all the conflicts by defining different variable and cookies as shown above. It made the module error disappear even though I tested the site online.

And for your information, I was testing the rules on one template and looking at the wrong one for the results. 2 of my template are very similar that's why... my mistake.

All issue were fixed. Thanks again. Still waiting for the mod to get a 5th variable for metatemplate though.

Cheers,
Alex.

atherrien
Modder Extraordinaire
ranks
useravatar
Offline
140 Posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1667
Total Polls:
6
Total Posts:
5909
Total Posts Today:
1
User Info:
 
Total Users:
10075
Newest User:
rsker57
Members Online:
0
Guests Online:
247

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