user is_auth() is_cert() methods added
[brisk.git] / web / index.php
index c11a22d..6e45cb0 100644 (file)
@@ -237,19 +237,7 @@ function poll_dom() {
     return '';
 }
 
-function carousel_top()
-{
-    $what = rand(1,2);
-    if ($what == 1) {
-        $rn = rand(1, 3);
-        return (sprintf('<a target="_blank" href="http://shop.alternativeoutput.it"><img class="nobo" style="display: inline; border: 1px solid #808080;" alt="il negozio virtuale di Brisk" title="il negozio virtuale di Brisk" src="img/briskshop%d.gif"></a>', $rn));
-        }
-    else {
-        return (sprintf('<a target="_blank" href="http://www.alternativeoutput.it/briskblog"><img class="nobo" alt="il nuovo blog di Brisk" title="il nuovo blog di Brisk" style="display: inline; border: 1px solid #808080;" src="img/briskblog_bannersmall.png"></a>'));
-    }
-}
-
-function index_main(&$room, $transp_type, &$header_out, $addr, $get, $post, $cookie)
+function index_main(&$brisk, $transp_type, &$header_out, $remote_addr_full, $get, $post, $cookie)
 {
     GLOBAL $G_with_donors, $G_donors_cur, $G_donors_all;
     GLOBAL $G_with_topbanner, $G_topbanner, $G_is_local;
@@ -270,8 +258,10 @@ function index_main(&$room, $transp_type, &$header_out, $addr, $get, $post, $coo
     if (($table_token = gpcs_var('table_idx', $get, $post, $cookie)) === FALSE)
         unset ($table_token);
 
+    $remote_addr = addrtoipv4($remote_addr_full);
+
     // Use of proxies isn't allowed.
-    if (!$G_is_local && is_proxy($addr)) {
+    if (!$G_is_local && is_proxy($remote_addr)) {
         return FALSE;
     }
 
@@ -283,16 +273,17 @@ function index_main(&$room, $transp_type, &$header_out, $addr, $get, $post, $coo
 
   if (isset($BRISK_SHOWHTML) == FALSE) {
       $is_table = FALSE;
-      log_main("lock Room");
+      log_main("lock Brisk");
       $curtime = time();
 
       /* Actions */
 
       if (validate_sess($sess)) {
           log_main("pre garbage_manager UNO");
-          $room->garbage_manager(TRUE);
+          $brisk->garbage_manager(TRUE);
           log_main("post garbage_manager");
-          if (($user = &$room->get_user($sess, &$idx)) != FALSE) {
+          if (($user = &$brisk->get_user($sess, &$idx)) != FALSE) {
+              $brisk->sess_cur_set($user->sess);
               log_main("user stat: ".$user->stat);
               if ($user->stat == "table") {
                   $cookies = new Cookies();
@@ -309,22 +300,30 @@ function index_main(&$room, $transp_type, &$header_out, $addr, $get, $post, $coo
       if ($ACTION == "login" && isset($name)) {
           log_main("pre garbage_manager DUE");
 
-          if (isset($pass_private) == FALSE) {
+          if (isset($pass_private) == FALSE || $pass_private == "") {
               $pass_private = FALSE;
+
+              $banned = FALSE;
+              if ($brisk->ban_check($remote_addr)) {
+                  // TODO: find a way to add a nonblocking sleep(5) here
+                  $banned = TRUE;
+                  $idx = -1;
+              }
           }
 
-          $room->garbage_manager(TRUE);
+          $brisk->garbage_manager(TRUE);
           /* try login */
 
-          $ipv4addr = addrtoipv4($addr);
-          if (($user = $room->add_user(&$sess, &$idx, $name, $pass_private, $ipv4addr, $cookie)) != FALSE) {
+          if ($banned == FALSE &&
+              ($user = $brisk->add_user(&$sess, &$idx, $name, $pass_private, $remote_addr, $cookie)) != FALSE) {
+              $brisk->sess_cur_set($user->sess);
               $ACTION = "room";
               if ($idx < 0) {
                   $idx = -$idx - 1;
                   $is_login = TRUE;
               }
 
-              log_legal($curtime, $ipv4addr, $user, "STAT:LOGIN", '');
+              log_legal($curtime, $remote_addr, $user, "STAT:LOGIN", '');
 
               // recovery lost game
               if ($user->stat == "table") {
@@ -337,7 +336,7 @@ function index_main(&$room, $transp_type, &$header_out, $addr, $get, $post, $coo
               }
 
               // setcookie ("sess", "", time() + 180);      
-              $room->standup_update(&$user);
+              $brisk->standup_update(&$user);
           }
           else {
               /* Login Rendering */
@@ -382,8 +381,8 @@ function index_main(&$room, $transp_type, &$header_out, $addr, $get, $post, $coo
       $tables .= '<div class="room_tab">';
       $tables .= '<table class="room_tab">';
       for ($ii = 0 ; $ii < TABLES_N ; $ii++) {
-          if ($user->flags & USER_FLAG_AUTH)
-        $i = $ii;
+          if ($user->is_auth())
+              $i = $ii;
           else
               $i = TABLES_N - $ii - 1;
 
@@ -478,9 +477,12 @@ function index_main(&$room, $transp_type, &$header_out, $addr, $get, $post, $coo
   
   
   
-  
-  
-  $brisk_donate = file_get_contents(FTOK_PATH."/brisk_donate.txt");
+  /* NOTE: Brisk donate or donate fake if local */
+  if (!$G_is_local)
+      $brisk_donate = file_get_contents(FTOK_PATH."/brisk_donate.txt");
+  else
+      $brisk_donate = '<div style="background-color: #ff0; height: 27px; margin-top: 4px;">BRISK_DONATE</div>';
+
   if ($brisk_donate == FALSE)
       $brisk_donate = "";
   
@@ -814,7 +816,7 @@ google_color_url = "000000";
           // MLANG garantisci
           .$mlang_room['tit_splash'][$G_lang].
           '</a><br>
-'.($user->flags & USER_FLAG_AUTH ? '
+'.($user->is_auth() ? '
 <a href="#" title="'
           // MLANG garantisci per un tuo conoscente
           .$mlang_room['prefs_desc'][$G_lang].'"
@@ -855,13 +857,15 @@ supported by:<br>
 '.$altout_support_big.'
 </div>
 <a style="/* position: absolute; top: 40px; left: 6px;" */ target="_blank" href="http://it-it.facebook.com/group.php?gid=59742820791"><img class="nobo" id="btn_facebook" src="img/facebook_btn.png" title="unisciti al gruppo \'quelli della brisk\'"></a>
-<br>
-<div id="proflashext" class="proflashext"><div id="proflash" class="proflash">
-</div><br><br></div>
+' . ( /* NOTE: here facebook or fake facebook */
+! $G_is_local ?
+'<div class="fb-like" style="margin-top: 4px;" data-href="https://www.facebook.com/pages/Brisk-briscola-chiamata-in-salsa-ajax/716026558416911" data-share="false" data-send="true" data-width="70" data-show-faces="false" data-colorscheme="dark" layout="button_count"></div>
+' : '<div style="margin-top: 4px; height: 20px; background-color: #00f;">FACEBOOK HERE</div>
+' ) . '<div id="proflashext" class="proflashext"><div id="proflash" class="proflash"></div></div>
+<img id="stm_stat" class="nobo" style="margin-top: 4px;" src="img/line-status_b.png">
 %s
 %s
-<br>
-<img id="stm_stat" class="nobo" src="img/line-status_b.png"></div>';
+</div>';
     
   /* Templates. */
   if ($ACTION == 'login') {
@@ -893,13 +897,15 @@ supported by:<br>
    var g_lng = "<? echo $G_lng; ?>";
    var g_tables_n = <? echo TABLES_N; ?>;
    var g_tables_auth_n = <? echo TABLES_AUTH_N; ?>;
+   var g_tables_cert_n = <? echo TABLES_CERT_N; ?>;
    var g_prefs, g_prefs_new = null;
    var g_listen;
    var g_withflash = false;
    var g_is_spawn = 0;
+   var g_nd = null;
+   var g_brow = null;
    var gst  = new globst();
    var topbanner_sfx, topbanner_dx;
-   var g_brow = null;
    var xstm = null;
    var sess = "not_connected";
    var spo_slide, sup_slide;
@@ -937,8 +943,27 @@ supported by:<br>
    //-->
 </SCRIPT>
 </head>
+<?php
+    if (!$G_is_local) {
+?>
 <!-- if myconsole <body onunload="deconsole();"> -->
+<body xmlns:fb="http://ogp.me/ns/fb#">
+<div id="fb-root"></div>
+<script>(function(d, s, id) {
+  var js, fjs = d.getElementsByTagName(s)[0];
+  if (d.getElementById(id)) return;
+  js = d.createElement(s); js.id = id;
+  js.src = "//connect.facebook.net/it_IT/all.js#xfbml=1";
+  fjs.parentNode.insertBefore(js, fjs);
+}(document, 'script', 'facebook-jssdk'));</script>
+<?php
+    }
+    else {
+?>
 <body>
+<?php
+  }
+?>
 <?php
     printf($brisk_header_form);
     printf("<table class=\"floaty\"><tr><td class=\"floatyleft\">\n");
@@ -950,9 +975,6 @@ supported by:<br>
 
    if ($G_with_sidebanner) {
      printf("%s", $G_sidebanner);
-     if ($G_with_sidebanner2) {
-       printf("<br>");
-     }
    }
 
 
@@ -963,7 +985,7 @@ supported by:<br>
 ?> 
 
 <!--  =========== tables ===========  -->
-<?php 
+<?php
 
 /* MLANG: "Digita il tuo nickname per accedere ai tavoli della briscola.", "entra", "Se non hai ancora una password, lascia il campo in bianco ed entra." ,"(se usi firefox e qualcosa non funziona prova a ricaricare la pagina con Ctrl + F5)" */
 echo "$body"; ?>
@@ -1034,19 +1056,21 @@ echo "$body"; ?>
    var g_lng = "<? echo $G_lng; ?>";
    var g_tables_n = <? echo TABLES_N; ?>;
    var g_tables_auth_n = <? echo TABLES_AUTH_N; ?>;
+   var g_tables_cert_n = <? echo TABLES_CERT_N; ?>;
    var g_prefs, g_prefs_new = null;
    var g_listen;
+   var g_is_spawn = 0;
+   var g_withflash = false;
+   var g_imgct = 0;
+   var g_imgtot = g_preload_img_arr.length;
+   var g_brow = null;
+   var g_nd = null;
    var tra = null;
    var stat = "";
    var subst = "";
    var gst  = new globst();
-   var g_is_spawn = 0; 
    var topbanner_sfx, topbanner_dx;
    // var nonunload = false;
-   var g_withflash = false;
-   var g_imgct = 0;
-   var g_imgtot = g_preload_img_arr.length;
-   var g_brow = null;
    var spo_slide, sup_slide;
 
    window.onload = function() {
@@ -1080,7 +1104,7 @@ else {
 
 ?>
      sess = "<?php echo "$sess"; ?>";
-xstm = new xynt_streaming(window, "<?php echo "$transp_type"; ?>", 80, 2, null /* console */, gst, 'index_php', 'sess', sess, $('sandbox'), 'index_rd_ifra.php', function(com){eval(com);});
+xstm = new xynt_streaming(window, "<?php echo "$transp_type"; ?>", 80, 2, null /* console */, gst, 'index_php', 'sess', sess, $('sandbox'), 'index_rd.php', function(com){eval(com);});
      xstm.hbit_set(heartbit);
      tra = new train($('room_tit'));
      window.onunload = onunload_cb;
@@ -1111,17 +1135,31 @@ if ($is_login) {
    //-->
 </SCRIPT>
 </head>
+<?php
+    if (!$G_is_local) {
+?>
 <!-- if myconsole <body onunload="deconsole();"> -->
+<body xmlns:fb="http://ogp.me/ns/fb#">
+<div id="fb-root"></div>
+<script>(function(d, s, id) {
+  var js, fjs = d.getElementsByTagName(s)[0];
+  if (d.getElementById(id)) return;
+  js = d.createElement(s); js.id = id;
+  js.src = "//connect.facebook.net/it_IT/all.js#xfbml=1";
+  fjs.parentNode.insertBefore(js, fjs);
+}(document, 'script', 'facebook-jssdk'));</script>
+<?php
+    }
+    else {
+?>
 <body>
+<?php
+  }
+?>
 <?php
    printf($brisk_header_form);
    printf("<table class=\"floaty\"><tr><td class=\"floatyleft\">\n");
-   /*   printf($brisk_vertical_menu, '<input type="button" class="button" name="xhelp"  value="Help." onclick="act_help();"><br><!-- <br><input type="button" class="button" name="xabout"  value="About." onclick="act_about();">--><br><br><br>',
-          $brisk_donate);
-   printf($brisk_vertical_menu, '<input type="button" class="button" name="xhelp"  value="Help." onclick="act_help();"><br><!-- <br><input type="button" class="button" name="xabout"  value="About." onclick="act_about();">--><br>',
-          $brisk_donate);*/
-   printf($brisk_vertical_menu, '<!-- <br><input type="button" class="button" name="xabout"  value="About." onclick="act_about();">--><br>',
-          $brisk_donate);
+   printf($brisk_vertical_menu, '', $brisk_donate);
 
 
    if ($G_with_sidebanner xor $G_with_sidebanner2) {
@@ -1130,9 +1168,6 @@ if ($is_login) {
 
    if ($G_with_sidebanner) {
      printf("%s", $G_sidebanner);
-     if ($G_with_sidebanner2) {
-       printf("<br>");
-     }
    }