Esempio n. 1
0
 /**
  * Keep session alive, for example, while editing or creating an article.
  */
 function keepalive()
 {
     // Include mootools framework
     JHTMLBehavior::mootools();
     $config =& JFactory::getConfig();
     $lifetime = $config->getValue('lifetime') * 60000;
     $refreshTime = $lifetime <= 60000 ? 30000 : $lifetime - 60000;
     //refresh time is 1 minute less than the liftime assined in the configuration.php file
     $document =& JFactory::getDocument();
     $script = '';
     $script .= 'function keepAlive( ) {';
     $script .= '	var myAjax = new Ajax( "index.php", { method: "get" } ).request();';
     $script .= '}';
     $script .= ' window.addEvent("domready", function()';
     $script .= '{ keepAlive.periodical(' . $refreshTime . ' ); }';
     $script .= ');';
     $document->addScriptDeclaration($script);
     return;
 }
Esempio n. 2
0
 /**
  * Method to load the system keepalive behavior.  This will send an ascynchronous request to the
  * server via AJAX on an interval just under the session expiration lifetime so that the session
  * does not expire.
  *
  * @return  void
  *
  * @since   1.5.19
  * @static
  */
 function keepalive()
 {
     // Load the behavior framework into the document head.
     JHTMLBehavior::mootools();
     // Get the session lifetime in microseconds.
     $lifetime = JFactory::getConfig()->getValue('lifetime', 900) * 60000;
     // Set the session refresh period to one minute less than the session lifetime.
     $refreshTime = (int) ($lifetime <= 60000) ? 30000 : $lifetime - 60000;
     // Build the keepalive script.
     $script = array('function keepAlive() { new Ajax("index.php", {method: "get"}).request(); }', 'window.addEvent("domready", function() { keepAlive.periodical(' . $refreshTime . '); });');
     // Load the keepalive script into the document head.
     JFactory::getDocument()->addScriptDeclaration(implode("\n", $script));
 }