Added keep-alive function to admin panel (had been planned for some time) and a new hook, template_var_init_end
authorDan
Fri, 07 Sep 2007 16:25:16 -0400
changeset 118 0c5efda996bf
parent 117 7cfdbb2fd17a
child 119 9de392a67964
child 125 fb31c951d3a2
Added keep-alive function to admin panel (had been planned for some time) and a new hook, template_var_init_end
ajax.php
includes/clientside/static/ajax.js
includes/paths.php
includes/template.php
plugins/SpecialAdmin.php
--- a/ajax.php	Fri Sep 07 00:48:51 2007 -0400
+++ b/ajax.php	Fri Sep 07 16:25:16 2007 -0400
@@ -368,6 +368,9 @@
       echo 'success';
       
       break;
+    case 'ping':
+      echo 'pong';
+      break;
     default:
       die('Hacking attempt');
       break;
--- a/includes/clientside/static/ajax.js	Fri Sep 07 00:48:51 2007 -0400
+++ b/includes/clientside/static/ajax.js	Fri Sep 07 16:25:16 2007 -0400
@@ -1094,3 +1094,57 @@
   catHTMLBuf = false;
 }
 
+var keepalive_interval = false;
+
+function ajaxPingServer()
+{
+  ajaxGet(stdAjaxPrefix + '&_mode=ping', function()
+    {
+    });
+}
+
+function ajaxToggleKeepalive()
+{
+  if ( readCookie('admin_keepalive') == '1' )
+  {
+    createCookie('admin_keepalive', '0', 3650);
+    if ( keepalive_interval )
+      clearInterval(keepalive_interval);
+    var span = document.getElementById('keepalivestat');
+    span.firstChild.nodeValue = 'Turn on keep-alive';
+  }
+  else
+  {
+    createCookie('admin_keepalive', '1', 3650);
+    if ( !keepalive_interval )
+      keepalive_interval = setInterval('ajaxPingServer();', 600000);
+    var span = document.getElementById('keepalivestat');
+    span.firstChild.nodeValue = 'Turn off keep-alive';
+    ajaxPingServer();
+  }
+}
+
+var keepalive_onload = function()
+{
+  if ( readCookie('admin_keepalive') == '1' )
+  {
+    if ( !keepalive_interval )
+      keepalive_interval = setInterval('ajaxPingServer();', 600000);
+    var span = document.getElementById('keepalivestat');
+    span.firstChild.nodeValue = 'Turn off keep-alive';
+    ajaxPingServer();
+  }
+  else
+  {
+    if ( keepalive_interval )
+      clearInterval(keepalive_interval);
+    var span = document.getElementById('keepalivestat');
+    span.firstChild.nodeValue = 'Turn on keep-alive';
+  }
+};
+
+function aboutKeepAlive()
+{
+  new messagebox(MB_OK|MB_ICONINFORMATION, 'About the keep-alive feature', 'Keep-alive is a new Enano feature that keeps your administrative session from timing out while you are using the administration panel. This feature can be useful if you are editing a large page or doing something in the administration interface that will take longer than 15 minutes.<br /><br />For security reasons, Enano mandates that high-privilege logins last only 15 minutes, with the time being reset each time a page is loaded (or, more specifically, each time the session API is started). The consequence of this is that if you are performing an action in the administration panel that takes more than 15 minutes, your session may be terminated. The keep-alive feature attempts to relieve this by sending a "ping" to the server every 10 minutes.<br /><br />Please note that keep-alive state is determined by a cookie. Thus, if you log out and then back in as a different administrator, keep-alive will use the same setting that was used when you were logged in as the first administrative user. In the same way, if you log into the administration panel under your account from another computer, keep-alive will be set to "off".');
+}
+
--- a/includes/paths.php	Fri Sep 07 00:48:51 2007 -0400
+++ b/includes/paths.php	Fri Sep 07 16:25:16 2007 -0400
@@ -509,6 +509,9 @@
       $ret .= "      ],\n";
     }
     $ret .= "    ['Log out of admin panel', 'javascript:ajaxPage(\\'".$this->nslist['Admin']."AdminLogout\\');'],\n";
+    $ret .= "    ['<span id=\\'keepalivestat\\'>Loading keep-alive control...</span>', 'javascript:ajaxToggleKeepalive();', 
+                   ['About keep-alive', 'javascript:aboutKeepAlive();']
+                 ],\n";
     // I used this while I painstakingly wrote the Runt code that auto-expands certain nodes based on the value of a bitfield stored in a cookie. *shudders*
     // $ret .= "    ['(debug) Clear menu bitfield', 'javascript:createCookie(\\'admin_menu_state\\', \\'1\\', 365);'],\n";
     $ret .= "]\n];";
--- a/includes/template.php	Fri Sep 07 00:48:51 2007 -0400
+++ b/includes/template.php	Fri Sep 07 16:25:16 2007 -0400
@@ -762,6 +762,12 @@
     $this->tpl_bool['sidebar_left']  = ( $this->tpl_strings['SIDEBAR_LEFT']  != $min) ? true : false;
     $this->tpl_bool['sidebar_right'] = ( $this->tpl_strings['SIDEBAR_RIGHT'] != $min) ? true : false;
     $this->tpl_bool['right_sidebar'] = $this->tpl_bool['sidebar_right']; // backward compatibility
+    
+    $code = $plugins->setHook('template_var_init_end');
+    foreach ( $code as $cmd )
+    {
+      eval($cmd);
+    }
   }
   
   function header($simple = false) 
--- a/plugins/SpecialAdmin.php	Fri Sep 07 00:48:51 2007 -0400
+++ b/plugins/SpecialAdmin.php	Fri Sep 07 16:25:16 2007 -0400
@@ -2531,6 +2531,7 @@
       'icon_26' : '<?php echo scriptPath; ?>/images/icons/minusbottom.gif',// junction for opened node
       'icon_27' : '<?php echo scriptPath; ?>/images/icons/minus.gif'       // junction for last opended node
     };
+    addOnloadHook(keepalive_onload);
     <?php
     echo $paths->parseAdminTree(); // Make a Javascript array that defines the tree
     if(!isset($_GET['module'])) { echo 'addOnloadHook(_enanoAdminOnload);'; } ?>