Php photo gallery TWG | JFUploader | TWG Flash upload | WFU | Forum
https://www.tinywebgallery.com/forum/

strange behavior.keepalive code in jfuploader.html.php
https://www.tinywebgallery.com/forum/viewtopic.php?f=13&t=3266
Page 1 of 1

Author:  foleox [ 7. Mar 2012, 22:48 ]
Post subject:  strange behavior.keepalive code in jfuploader.html.php

I'm trying to solve some problem with a "session expired" system message, and i came upon the subject behavior.keepalive .
Joomla uses this by ..
Code:
echo JHTML::_('behavior.keepalive');

.. I think this inserts the following code lines into the <head> by MooTools:
(some info: http://www.joomlatonight.com/joomla-tut ... -in-joomla )
Code:
function keepAlive() { new Ajax("index.php", {method: "get"}).request(); }
window.addEvent("domready", function() { keepAlive.periodical(2640000); });


Strange is this code piece, found in /components/com_jfuploader/jfuploader.html.php ..

Code:
$jConfig = new JConfig();
// we can only have a keepalive if Joomla and JFU use the same session!
if ($jConfig->session_handler != 'database') {
  echo JHTML::_('behavior.keepalive');
}
// now I overwrite the existing function.
echo '
<script type="text/javascript">
function debugError(errorString) { }

function getIDN() {
   return "'.$jfu_config['idn_url'].'/";
}

function uploadRunning(val) {
   acivateKeep = (val == "true");
   if (oldKeepAlive != null) {
     oldKeepAlive();
   }
}
var oldKeepAlive = window.keepAlive;
var acivateKeep = false;
window.keepAlive = function() {
  if (acivateKeep && (oldKeepAlive != null)) {
    oldKeepAlive();   
  }
}
</script>';


.. to me this overwrite method is a tricky way to hack / adjust some Joomla functionality.
Why isn't the MooTools way used?
And what happens if i just comment-out this code piece? (which i did in my override /templates/mytemplate/html/com_jfuploader/jfuploader.html.php)

Author:  TinyWebGallery [ 8. Mar 2012, 00:49 ]
Post subject:  Re: strange behavior.keepalive code in jfuploader.html.php

adding JHTML::_('behavior.keepalive'); would mean that the page will never time out.

I only wanted that the page does not time out during the upload (+ the normal session time)
The flash calles the uploadRunning with true during the upload. After the upload is is caling it once with false so that the session does time out then.

If you remove the extra functions the session will not time out (leaving uploadRunning empty because this is called by the flash) or if you remove the JHTML::_('behavior.keepalive'); the session will time out if a upload is longer than the session timeout (not on all browsers because some do sent a proper session cookie while other do not!).

Best, Michael

Author:  foleox [ 8. Mar 2012, 01:40 ]
Post subject:  Re: strange behavior.keepalive code in jfuploader.html.php

ok, and .. is there no other way to "..overwrite the existing function..", as done in the code?

when you say "..that the page does not time out during the upload.." what's the practical use? Why not keep things simple and just suppose that the user picks some files and clicks the upload button shortly after!? (which will happen 99% i guess). Then only the code line JHTML::_('behavior.keepalive') is sufficient. And remember, MooTools can nicely dynamically add/remove HTML parts, even JS functions etc. - this should be better coding anyhow, i think.

Author:  TinyWebGallery [ 8. Mar 2012, 11:17 ]
Post subject:  Re: strange behavior.keepalive code in jfuploader.html.php

this is not big magic. I simply wrap my function around the one Joomla creates. For everything else Joomla code would have to be modified.

It's about the upload time. At a slow line e.g. the upload takes 3 hours. If the timeout is 30 min you can access Joomla for the next 30 min after the upload finishes.
with only using JHTML::_('behavior.keepalive') the page does never time out. So if you forget your upload and someone comes to the computer the next day he can still use your login. so you can of course remove the overwriting on the function but I still think that keeping a page alive forever is not good.

So it's up to you...

Best, Michael

Page 1 of 1 All times are UTC + 1 hour [ DST ]
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/