splash cookie management updated
[brisk.git] / web / index_rd_ifra.php
index 7d4f493..6e59fb4 100644 (file)
@@ -130,6 +130,7 @@ function blocking_error($is_unrecoverable)
   return (sprintf(($is_unrecoverable ? 'hstm.stop(); ' : '').'window.onbeforeunload = null; window.onunload = null; document.location.assign("index.php");'));
 }
 
+// FIXME TO SUPPORT iframe
 function page_sync($sess, $page, $table_idx, $table_token)
 {
   GLOBAL $is_page_streaming;
@@ -145,14 +146,14 @@ function page_sync($sess, $page, $table_idx, $table_token)
 
 
 
-function maincheck(&$room, &$user, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_subst, &$new_step)
+function maincheck(&$room, &$user, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_subst, &$new_step, $splashdate)
 {
     GLOBAL $G_lang, $mlang_indrd, $is_page_streaming;
     // GLOBAL $first_loop;
     GLOBAL $G_with_splash, $G_splash_content, $G_splash_interval, $G_splash_idx;
     GLOBAL $G_splash_w, $G_splash_h, $G_splash_timeout;
     $CO_splashdate = "CO_splashdate".$G_splash_idx;
-    GLOBAL $$CO_splashdate;
+    $$CO_splashdate = $splashdate;
     
     GLOBAL $S_load_stat;
 
@@ -491,6 +492,33 @@ function maincheck(&$room, &$user, $cur_stat, $cur_subst, $cur_step, &$new_stat,
     return ($ret);
 }
 
+function index_rd_ifra_fini($is_unrecoverable)
+{
+    GLOBAL $G_four_rnd_string;
+
+    // IF IFRAME THEN:
+    $body = "";
+    $body .= sprintf("<html>
+<head>
+<script type=\"text/javascript\" src=\"commons.js\"></script>
+<script type=\"text/javascript\" src=\"xynt-http-streaming-ifra.js\"></script>
+<script type=\"text/javascript\">
+var http_streaming = \"ready\";");
+    $body .= sprintf("
+window.onload = function () { if (http_streaming != \"ready\") { http_streaming.reload(); } };
+</script>
+</head>
+<body>");
+    $body .= sprintf("<!-- \n%s -->\n", $G_four_rnd_string);
+    $body .= sprintf("<script id='hs%d' type='text/javascript'><!--
+push(\"%s\");
+// -->
+</script>", 0, escpush(blocking_error($is_unrecoverable)) );
+    // ELSE IF XHR THEN:
+    // return (blocking_error($is_unrecoverable));
+    return ($body);
+}
+
 /*
  *  MAIN
  */
@@ -505,6 +533,8 @@ function index_rd_ifra_init(&$room, &$user, &$header_out, &$body, $get, $post, $
 {
     GLOBAL $G_four_rnd_string;
 
+    $curtime = time();
+
     $is_page_streaming = FALSE; // (webservers_exceeded() || stristr($HTTP_USER_AGENT, "Mozilla/5.0 (Windows NT 6.1; rv:5.0)") || stristr($HTTP_USER_AGENT, "MSIE") || stristr($HTTP_USER_AGENT, "CHROME") ? TRUE : FALSE);
 
     $header_out['Cache-Control'] = 'no-cache, must-revalidate';     // HTTP/1.1
@@ -522,7 +552,7 @@ function index_rd_ifra_init(&$room, &$user, &$header_out, &$body, $get, $post, $
     if (($step  = gpcs_var('step', $get, $post, $cookie)) === FALSE) 
         unset($step);
     
-    $user->rd_data_set(time() + STREAM_TIMEOUT, $stat, $subst, $step, $from);
+    $user->rd_data_set($curtime, $stat, $subst, $step, $from);
 
     $body .= sprintf("<html>
 <head>
@@ -530,9 +560,8 @@ function index_rd_ifra_init(&$room, &$user, &$header_out, &$body, $get, $post, $
 <script type=\"text/javascript\" src=\"xynt-http-streaming-ifra.js\"></script>
 <script type=\"text/javascript\">
 var http_streaming = \"ready\";");
-    if (isset($st)) {
-        $body .= sprintf("last_clean = %d;\n", $st);
-    }
+    if ($user->rd_scristp > 0)
+        $body .= sprintf("last_clean = %d;\n", ($user->rd_scristp-1));
     $body .= sprintf("
 window.onload = function () { if (http_streaming != \"ready\") { http_streaming.reload(); } };
 </script> 
@@ -543,9 +572,15 @@ window.onload = function () { if (http_streaming != \"ready\") { http_streaming.
     return TRUE;
 }
 
-function index_rd_ifra_main(&$room, &$user, &$body)
+function index_rd_ifra_main(&$room, &$user, &$body, $get, $post, $cookie)
 {
-    GLOBAL $is_page_streaming;
+    GLOBAL $is_page_streaming, $G_splash_idx;
+    // FIXME: only to test fwrite
+    // GLOBAL $G_four_rnd_string;
+
+    $CO_splashdate = "CO_splashdate".$G_splash_idx;
+    if (($splashdate = gpcs_var("$CO_splashdate", $get, $post, $cookie)) === FALSE)
+        $splashdate = ""; 
 
     $is_page_streaming = FALSE;
     log_rd2("FROM OUTSIDE - STAT: ".$user->rd_stat." SUBST: ".$user->rd_subst." STEP: ".$user->rd_step." FROM: ".$user->rd_from. "IS_PAGE:" . $is_page_streaming);
@@ -560,7 +595,7 @@ function index_rd_ifra_main(&$room, &$user, &$body)
         $old_stat  = $user->rd_stat;
         $old_subst = $user->rd_subst;
         $old_step  = $user->rd_step;
-        if (($ret = maincheck($room, $user, $old_stat, $old_subst, $old_step, $user->rd_stat, $user->rd_subst, $user->rd_step)) != FALSE) {
+        if (($ret = maincheck($room, $user, $old_stat, $old_subst, $old_step, $user->rd_stat, $user->rd_subst, $user->rd_step, $splashdate)) != FALSE) {
             // $no_data = FALSE;
             if (0 == 1) {
                 echo '@BEGIN@';
@@ -568,6 +603,11 @@ function index_rd_ifra_main(&$room, &$user, &$body)
                 echo "$ret";
                 echo ' @END@'; 
             }
+
+            // FIXME only to test fwrite
+            // for ($u = 0 ; $u < 10 ; $u++) {
+            //    $body .= sprintf("<!-- \n%s -->\n", $G_four_rnd_string);
+            // }
             $body .= sprintf("<script id='hs%d' type='text/javascript'><!--
 push(\"%s\");
 // -->
@@ -614,4 +654,13 @@ push(\"%s\");
 
     return TRUE;
 }
+
+function index_rd_ifra_keepalive(&$user)
+{
+    return (sprintf("<script id='hs%d' type='text/javascript'><!--
+push(null);
+// -->
+</script>", $user->rd_scristp++));
+
+}
 ?>