Topic-icon Sweepstakes Workflow with Facebook Auth Dialog Box?

Active Subscriptions:

None
A little more info...

If I clear my cookies, I'm logged out of both facebook and Joomla. I then log into facebook and view the app. I'm shown Content-A, which has a register/login button. I click that and I'm taken directly to Content-C. If I refresh, I get Content-B.

I then emptied the form database so no user IDs were in the DB. I cleared cookies, logged into facebook and went from Content-A -> Content-B -> Content C. Refresh the page and I get Content-B.

I also noticed some strange redirect issues on the site. If I tried to go to the homepage, I got redirected to Content-B. Sounds like a cache busting issue...?
The topic has been locked.
Support Specialist
14 years 3 months ago #19986 by alzander
So, it gets confusing when you refresh the page. Be aware of the following scenarios, and let me know what should happen:
1) Whole page is refreshed.
2) User navigates to other page on the site after Content-C is shown.

With the change I gave, basically, content-C will be shown the first time a user comes to a page. If they want to navigate away from that, they can. However, that also means that if they refresh the page, it won't show C (it already has).

The problem, if you want to always show C, is that there's not a good way to detect if the user is intentionally going to a new page (#2 above) or is simply hitting refresh (#1 above.. which I think would be less common).

Hope that makes sense as to why there's an issue.. but if you have a way of knowing if a user is navigating (clicking links, submitting forms, etc) vs reloading the page, we could use that to figure out what page to show.. but it can get quickly complex..

Alex
The topic has been locked.
Active Subscriptions:

None
Hmmm.... I'm a little confused about the logic of the code that (I thought) was built. Here was what I intended to have happen....

1. If the user has not Like'd our Facebook page, show Content-A

2a. If the user has Liked our page and they are logged out of Joomla, then they see the public (non-registered) version of Content-B
2b. If the user has Like our page, they are logged into Joomla, and their user ID is found in the entry form's database, then redirect to Content-C

3. If the user has Liked our page, they are logged into Joomla and their user ID is NOT found in the form's database, then redirect to Content-B

This is what I thought the function did. If this is the case, it shouldn't matter why or where the user refreshes the page, right? A page refresh could occur for different reasons... they may fill out the form incorrectly, they might come back to see who the winner is, they might come back to share the sweepstakes with their friends, or they might actually navigate to the live site to read an article. If they are in the Facebook tab / app, the code should redirect them to the right content based on their user status and if they've filled out the form or not.

On the live site, I don't need any of these redirects to occur, it'd be OK if they all happened on Facebook.

Is that possible to do? Or is that too complicated?
The topic has been locked.
Support Specialist
14 years 3 months ago #19992 by alzander
Try the code below instead. It may cause problems that I'm theoretically thinking about, but possibly not.. you'll know quickly if so :)
if ($result && ((JRequest::getCmd('option') != 'com_content') || (JRequest::getCmd('view') != 'article') || (JRequest::getInt('id') != 'XXX'))
     $uri =& JURI::getInstance(); 
    ...
Removed that session stuff I mentioned above and make sure you update XXX to the Content C article ID. This will basically check: is the result set AND the user isn't on Content C already? Ok.. redirect them to it. On that redirect, they will be on the right page, so it won't redirect again (causing the loop).

Hope that makes sense,
Alex
The topic has been locked.
Active Subscriptions:

None
Thanks Alex!! I tried this code and I keep getting a T-Variable error on the 2nd line from your last post ($uri =& JURI::getInstance) . I think there is an extra parenthesis in the first line from your last post. I tried correcting the syntax, but every time I did, the error moved to a new line or the website tried to load, but got stuck in a redirect loop.

I'm not 100% sure I understood your directions correctly. Here's what I currently have for the new section of code (XXX was replaced in all instances):
            private function setupPageTab()
    {
        $app =& JFactory::getApplication();
        $jSession =& JFactory::getSession();

        // First, check if reveal page is setup
        $pageInfo = $jSession->get('jfbcCanvasPageInfo');
        $revealPage = $this->configModel->getSetting('canvas_tab_reveal_article_id', '');
        if ($revealPage && !$pageInfo['liked'] && ((JRequest::getCmd('option') != 'com_content') || (JRequest::getCmd('view') != 'article') ||
                (JRequest::getInt('id') != $revealPage))
        )
        {
            $uri =& JURI::getInstance();
            $uri->delVar('jfbcCanvasBreakout');
            $jSession->set('jfbcCanvasOrigDestination', $uri->toString());
            $app->redirect('index.php?option=com_content&view=article&tmpl=component&id=' . $revealPage);
        }
        else

        {
            // Get Current Users Joomla ID            
            $user =& JFactory::getUser();        

            // Search Database for Joomla Users ID
            $db = JFactory::getDbo();
            $query = $db->getQuery(true);
            $query->select('user_id');
            $query->from('sweepDB');
            $query->where('user_id = ' . $user->id);
            $db->setQuery($query);
            $result = $db->loadResult();            

            // Try to Match User ID & Redirect 
            if ($result && ((JRequest::getCmd('option') != 'com_content') || (JRequest::getCmd('view') != 'article') || (JRequest::getInt('id') != 'XXX'))
                    $uri =& JURI::getInstance(); 
                { 
                    $uri =& JURI::getInstance(); 
                    $uri->delVar('jfbcCanvasBreakout'); 
                    $jSession->set('jfbcCanvasOrigDestination', $uri->toString()); 
                    $app->redirect('index.php?option=com_content&Itemid=XXX&id=XXX&lang=en&view=article');             
                }                  

            // User ID Not Found 
            else 
                {                
                $tabTemplate = $this->configModel->getSetting('canvas_tab_template'); 
                $this->setTemplate($tabTemplate); 
                } 
        }
    }
The topic has been locked.
Support Specialist
14 years 3 months ago #20006 by alzander
We're going to chalk that up to a 'my bad'. I meant to give the next line of code that was already there, but missed the { after the if statement. It should look like this:
if ($result && ((JRequest::getCmd('option') != 'com_content') || (JRequest::getCmd('view') != 'article') || (JRequest::getInt('id') != 'XXX')) 
{
     $uri =& JURI::getInstance();
     $uri->delVar('jfbcCanvasBreakout'); 
....
Hope that helps and fixes you right up,
Alex
The topic has been locked.
Active Subscriptions:

None
Thanks Alex! I did try that last night, but I get an "Unexpected { error". If I add another closing parenthesis, " ) ", to the end of your IF statement, the code will run, but it throws the entire site into a redirect loop.
The topic has been locked.
Support Specialist
14 years 3 months ago #20009 by alzander
You're correct, the extra ) should be there as well.

Did you update the 'XXX'? Basically, that code will check if the user is on the Content C page, and if not, will redirect them there. If the URL doesn't look like:
/index.php?option=com_content&view=article&id=1234
The redirect will happen. So, the reason the loop is happening is because that if statement isn't properly detecting that the user is already on the Content - C page. Hopefully, it's just the id that you're (not setting), but it may be something else we're not detecting right.

Alex
The topic has been locked.
Active Subscriptions:

None
Yep, I've made sure that the article ID is in the IF statement you wrote, and both the article ID and the ItemID are in the redirect URL.
The topic has been locked.
Support Specialist
14 years 3 months ago #20018 by alzander
Do you have something that's rewriting your URLs for you? Can you disable SEF URLs, temporarily, and test if it works? It's possible the re-write is preventing that check from working since the new URL is actually different than what you're redirecting too.

Other options would be re-arranging the JFBCSystem plugin to the first or last position (but always before the System - Cache plugin, if enabled) and see if that changes the behavior.

Alex
The topic has been locked.