Topic-icon Dynamic requests ?

Support Specialist
14 years 3 months ago #19124 by alzander
Replied by alzander on topic Dynamic requests ?
mtk and I are working on a solution. Unfortunately, we had some server issues last week that demanded our immediate attention, and slowed down some investigation work (like this). The functionality is scoped out, and something we're planning to implement more thoroughly in the 4.2 release, but think we can get you a rough code snippet that will do what you're looking for this week.

Thanks for your patience,
Alex
The topic has been locked.
Support Specialist
14 years 3 months ago #19197 by alzander
Replied by alzander on topic Dynamic requests ?
Jean Claude,
We think we've come up with something that should work for your needs. We've done some very quick testing, but you'll need to test... a lot. This is something we're planning on elaborating more on in 4.2, but would love to hear your feedback on it right now. It's requires a minor changes to a few files and one database update. Hopefully, it's not too overwhelming..

First off, please do this on a development site, or backup your site first

Then, you'll need to run the following query on your database. This will add a new column to the notification table to store the destination url for each request:
ALTER TABLE `YYY_jfbconnect_notification` ADD COLUMN `destination_url` VARCHAR(200);

/components/com_jfbconnect/includes/jfbconnect.js
Around line 203, add the 2nd line:
data = jfbcRequests[jfbcReqId]; <-- This line is already here
            jfbc.request.destinationUrl = data.destinationUrl; <-- add this
Around line 221, change the query line to the following (adds the destinationUrl portion at the end):
var query = 'option=com_jfbconnect&controller=request&task=requestSent&requestId=' + rId + toQuery + '&jfbcId=' + jfbc.request.currentId + '&destinationUrl=' + jfbc.request.destinationUrl;

/components/com_jfbconnect/controllers/request.php
At line 39, add:
$data['destination_url'] = JRequest::getString('destinationUrl');

/administrator/components/com_jfbconnect/tables/jfbconnectnotification.php
At line 21, add:
var $destination_url = null;

/components/com_jfbconnect/models/notification.php
Look for the getRedirect function at the bottom of this file and just replace with all the code below:
function getRedirect()
    {
        $query = "SELECT n.destination_url nDestinationUrl, r.destination_url rDestinationUrl, breakout_canvas FROM #__jfbconnect_request r INNER JOIN #__jfbconnect_notification n ON r.id = n.jfbc_request_id " .
                " WHERE n.fb_request_id IN (" . implode(', ', $this->_fbRequestIds) . ") ORDER BY n.created DESC LIMIT 1";
        $this->_db->setQuery($query);
        $data = $this->_db->loadObject();

        $redirectInfo = new stdClass();
        $redirectInfo->breakout_canvas = $data->breakout_canvas;
        if ($data->nDestinationUrl)
            $redirectInfo->destination_url = $data->nDestinationUrl;
        else
            $redirectInfo->destination_url = $data->rDestinationUrl;

        return $redirectInfo;
    }

Whew. We don't normally spit out so much code and would just tell you to wait for the next release. We understand you're probably in a rush, and we'd love the feedback though.

Please let us know how it goes, and good luck,
Alex
The topic has been locked.
Active Subscriptions:

None
14 years 3 months ago #19201 by activha
Replied by activha on topic Dynamic requests ?
Hello Alex

Good news is that we did not break anything and that JFBC is still working correctly :-)

Bad news is that it does not seem to work, we have the destination url set up as indicated in post #1 but the {$refid} tag which is converted by PAP javascript dynamically to the correct id when the page is shown is not recorded in the DB.

Could you precise what does the new code exactly ?

on a request already set up before the modified code, I have noticed that even if the FB user clicks on the sent request, the status stays to 0 in our DB and destination URL field is set to NULL

on a new request set up after the modified code, the status stays also to 0 even if the FB user clicks on the request and the destination field is empty in the notification table.

Jean Claude
The topic has been locked.
Support Specialist
14 years 3 months ago #19212 by alzander
Replied by alzander on topic Dynamic requests ?
Jean Claude,
This change won't affect requests sent previously, so don't even test those. They are likely just broken.

To test, make sure that you've cleared your browser cache and any Joomla cache you have setup. There was a Javascript change above, and it sounds like that's not taking effect. That javascript is what sends the destination_url back to JFBConnect to store with each notification that is sent, and then is used later when the user accepts the request.

As for notifications not being marked as Read, that's due to a Facebook bug. About a week after we introduced Requests in JFBConnect, Facebook made a change to how Requests work. Now, we are unable to get the Facebook User ID of who accepted the Request if they haven't already authenticated your application. If we can't get the User ID, we can't look up the specific Request the user is accepting. If we can't look up the Request, we can't mark it as read. The bug report with Facebook is below. Feel free to click the "Does this repro describe your issue?" link to 'vote' for the issue to be fixed sooner:
developers.facebook.com/bugs/23947683611...aafbf058525356190250

Hope that helps with more info,
Alex
The topic has been locked.
Active Subscriptions:

None
14 years 3 months ago #19252 by activha
Replied by activha on topic Dynamic requests ?

alzander wrote: There was a Javascript change above, and it sounds like that's not taking effect. That javascript is what sends the destination_url back to JFBConnect to store with each notification that is sent, and then is used later when the user accepts the request.

OK I found out the problem with a javascript error in firebug :
"NetworkError: 403 Forbidden - activ-ha.com/index.php?option=com_jfbcon...d=191207190978996&to[]=100000660409261&jfbcId=3&destinationUrl=http://activ-ha.com/monsite/testest"

Don't know how to solve it though. Would it be possible to solve it with urlencode somewhere ?

As for the bug in Facebook requests, I clicked the bug report also !

Jean Claude
The topic has been locked.
Support Specialist
14 years 3 months ago #19293 by alzander
Replied by alzander on topic Dynamic requests ?
Try the following changes. In the jfbconnect.js file, change the line above to:
var query = 'option=com_jfbconnect&controller=request&task=requestSent&requestId=' + rId + toQuery + '&jfbcId=' + jfbc.request.currentId + '&destinationUrl=' + encodeURIComponent(jfbc.request.destinationUrl);
That adds the encoding to the URL which will help with the error.

Then, in /components/com_jfbconnect/controllers/request.php, we'll need to decode it before saving it. Change that line to:
$destination_url = JRequest::getString('destinationUrl');
$data['destination_url'] = urldecode($destination_url);

In the database, you should see the same 'pretty' URL, but the Javascript should fail now. This will only work on new requests. Old ones will be broken.

Let me know how that goes,
Alex
The topic has been locked.
Active Subscriptions:

None
14 years 3 months ago #19317 by activha
Replied by activha on topic Dynamic requests ?
Alex
Thanks this is working nicely now !

We have began to test a little and have two questions :

- the requests do not work within the Facebook iPhone application though they work well on the website. Facebook app shows a message "unable to redirect" and if we configure a mobile landing page in the FB settings the redirection is only made to this landing page and not to the page requested. Can you solve this problem as a lot of people use Facebook app from iPhone now ?

- is this possible to make a request with a blank url, thus only using the dynamic requests from the front end from the pages where the button/tag is set ?

Thanks
Jean Claude
The topic has been locked.
Support Specialist
14 years 3 months ago #19357 by alzander
Replied by alzander on topic Dynamic requests ?
We'll have to investigate the iPhone thing. Not sure why that isn't working. Can you let me know if you're seeing the "Unable to redirect" message after the Request is sent by a user to his friends, or if it's when a user accepts a Request sent to him. Couldn't quite tell how you were testing.

As for the Request with a blank URL, that shouldn't be too difficult, but let me look into the best way to do it. There's multiple places where we could insert the current URL, but want to make sure we choose the optimal place. I could see doing that in the 4.2 release as a feature as well as the other stuff you've requested here.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
14 years 3 months ago #19513 by activha
Replied by activha on topic Dynamic requests ?

alzander wrote: We'll have to investigate the iPhone thing. Not sure why that isn't working. Can you let me know if you're seeing the "Unable to redirect" message after the Request is sent by a user to his friends, or if it's when a user accepts a Request sent to him. Couldn't quite tell how you were testing.


This occurs when the user clicks on the request sent to him in FB notifications. When this happens on an iPhone, the message unable to redirect is shown if no mobile page has been defined in FB settings. If a mobile page has been defined in FB settings, then this mobile page is reached and not the url specified in the request
The topic has been locked.