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.

 

Set Cookie with MetaMod?

Set Cookie with MetaMod?

Is there a way to have MetaMod set a cookie? Read a cookie?

Here's what I'm trying to do:

-- Jreviews (reviewsforjoomla.com) uses a rather odd system - some Jreviews query results, such as "advanced search" and other "lists" are actually controlled by JReviews and have distinct URL's which can be parsed and used by MetaMod. For example, my listings all have my custom "jr_city" field appended, so my URL's contain the phrase "/tag/city/new-york" making it very easy for MetaMod to show modules based on the city contained in the URL.

-- However, when the user clicks on a Jreviews listing and is taken to a Listing entry, the URL looks very different. Here's an example: component/content/article/304-restaurants/561595-leonardis-pizza. Quite clearly, the page is being generated by com_component, not com_jreviews. I wrote the Jreviews programmer and confirmed this.

-- So, that leaves me with a dilemma: If a user just left a page showing cities in New York by clicking on a business IN New York, all my New York modules will disappear. Why? Because MetaMod is reading the URL to decide which modules to present. No city name, no module.

-- My idea is this: If each time MetaMod displays a module for a particular city it ALSO writes a cookie to the user's system with the city information, it would then be possible to retrieve the cookie on the listing page and display the correct city modules.

Possible? If so, can someone lead me in the right direction? I'm not married to the "cookie" idea - if there's a better way of achieving this goal, I'm quite interested in hearing it!

aboutimage
Beginner Modder
ranks
useravatar
Offline
7 Posts
Administrator has disabled public posting

Re: Set Cookie with MetaMod?

Not one to rest on my laurels, I came up with a solution:

IN ONE METAMOD MODULE:

if ( $core_genius->check("uri contains tag/city/idaho-falls") ) {
   setcookie("yp_location", "idaho-falls", time()+600);  /* expire in 10 minutes */
   return ###;   /*Replace ### with module number
}


IN A SECOND METAMOD MODULE: (on another page that needs to check for the cookie)

if ($_COOKIE["TestCookie"] == "idaho-falls") {
   return ###;  /*Replace ### with module number
}

This works, I've tested and confirmed. This is only partial code, of course. The full code would include more modules to show.

With all that said and done, I just realized it's only a half-solution. There are so many things a user could do to inadvertently negate the cookie. They could stay on the page for longer than the expiration time. They could save a favorite and come directly to their favorite listing. Lots of things could bypass the cookie solution, so I am going to look at the possibility of using HTTP Referrers instead. Once tested (if confirmed) I will post my findings here.

aboutimage
Beginner Modder
ranks
useravatar
Offline
7 Posts
Administrator has disabled public posting

Re: Set Cookie with MetaMod?

JReviews uses the following URL format when displaying "click2search" data based upon city name:

www.mysitename.com/tag/city/city-name

And it uses this format when displaying individual listings:

www.mysitename.com/component/content/article

So, if we write a bit of code to check for both, we can control (mostly) which modules show up and when. Here is my crude code to accomplish this:

if ( $core_genius->check("uri contains tag/city/") ) {                                                     /*If the current page is a click2search page (by city)
            if ( $core_genius->check("uri contains tag/city/city1") ) return XXX;             /*Replace city1 with actual city name, Replace XXX with desired module ID
     elseif ( $core_genius->check("uri contains tag/city/city2") ) return XXX;             /*Repeat as necessary

} elseif ( $core_genius->check("uri contains component/content/article") ) {           /*If the current page is a Jreviews listing
            if ( $core_genius->check("referrer contains tag/city/city1") ) return XXX;     /*Display the correct module based on the URL contents of the preceding page
     elseif ( $core_genius->check("referrer contains tag/city/city2") ) return XXX;     /*Repeat as necessary

}

This works pretty well. It has a couple flaws, the most obvious being that if you click on a listing and from that page directly click on another listing, it breaks the referrer code.

The best solution for this JReviews problem would be to directly read the Jreviews database for the currently displayed record and simply check the contents of the "city" field. I haven't figured out how to do that yet. When I do, I'll post here.

aboutimage
Beginner Modder
ranks
useravatar
Offline
7 Posts
Administrator has disabled public posting

Re: Set Cookie with MetaMod?

Hi, I wonder if you could fill in a few details for me - this is an interesting problem!

I don't know JReviews at all. How does it relate to articles?
- Are the reviews somehow linked to a particular standard Joomla article?
- when you go to a page like tag/city/cityname, are you viewing a single review, or a single article (that perhaps has reviews attached to it), or what?

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

Re: Set Cookie with MetaMod?

metamodguy wrote:

I don't know JReviews at all. How does it relate to articles?
- Are the reviews somehow linked to a particular standard Joomla article?
- when you go to a page like tag/city/cityname, are you viewing a single review, or a single article (that perhaps has reviews attached to it), or what?

I'm not a deep-level coder, so some of my answers to your questions may not be technically adept... but here's what I know:

- Jreviews does link to a standard Joomla article, though it appears to store nothing there but the listing description and title. All the other fields are stored in its own Jreviews dB. They do appear to be linked by the ID.

- pages with url's like tag/city/cityname are the result of what Jreviews calls "click2search" - most field types can be set as click2search. When set, a user viewing a listing containing a click2search field will see them highlighted as a clickable link, which in turn generates a query showing ALL entries matching that field. In my own setup, I'm using a field called jr_city to store my city data. Click2Search data (lists of records matching a criteria) use the tag/field/fielddata structure for URL's. However, when you select one of the records from query list, the resultant URL contains the component/content/article URL format.

You're welcome to have a look if you like. I'll create a login for you and PM it to you if you like. It's under development and I'm not at liberty to post it publicly.

aboutimage
Beginner Modder
ranks
useravatar
Offline
7 Posts
Administrator has disabled public posting

Re: Set Cookie with MetaMod?

Hi aboutimage,

Thanks for the additional info - that helped.

I remembered that I wrote Alejandro from JReviews some time ago and he let me have access to an evaluation copy of JReviews (big thanks to him for that). Therefore I have been able to work on this a bit more for you and have a recipe to try.

Here's how to get the value of a certain JReviews field when you are on a "normal" article page that's controlled by JReviews:

if ( $option == "com_content" and $view == "article" ) {
  $db->setQuery( "select jr_city from #__jreviews_content where contentid = " . (int)$id );
  $jr_city = $db->loadResult();
  if ( $jr_city == 'New York' ) return XXX; // replace XXX with module id to display for products with a jr_city of New York
}

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

Re: Set Cookie with MetaMod?

I can't WAIT to try this! Thanks so much, and I'll get you some feedback in the next 48 hours or so.

aboutimage
Beginner Modder
ranks
useravatar
Offline
7 Posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1684
Total Polls:
6
Total Posts:
5940
Posts this week:
1
User Info:
 
Total Users:
5162
Newest User:
david30x73
Members Online:
0
Guests Online:
147

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