<?php

/**
 * Copyright (c) 2021, 2024, 5 Mode
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither Open Gallery nor the names of its contributors 
 *       may be used to endorse or promote products derived from this software 
 *       without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * gallery.funny
 * 
 * Gallery Index page.
 *
 * @author Daniele Bonini <my25mb@2aol.com>
 * @copyrights (c) 2021, 2024, 5 Mode
 * @license https://opensource.org/licenses/BSD-3-Clause 
 */

require "../../../Private/core/init.inc";

//use OpenGallery\OpenGallery\Err;
//use OpenGallery\OpenGallery\GalleryUtil;


//Err::setRedirectHandlers("/");


if (filter_input(INPUT_SERVER, "HTTP_HOST") === "takeyou.to") {?>
  <script>
  window.open("http://5mode.com/err-404.html","_self");
  </script>
<?PHP 
  exit(1);
} 


// VARIABLES AND FUNCTION DECLARATION

define('GALLERY_NAME', "Indexbooks");
define('GALLERY_TITLE', "List");
define('GALLERY_DESC', "GNUBOOK List");
define('GALLERY_KEYWORDS', "Link,Index");

define('LANDINGPAGE', "gnubook.org");
define('LANDINGPAGE_BGCOLOR', "#F1ECEC");
define('LANDINGPAGE_COLOR', "#000000");
define('LANDINGPAGE_BOLD', "yes");

settype($aGalleryIndx, "array");


// PARAMETERS VALIDATION AND NORMALIZATION

//requestMethod
$requestMethod = (string)filter_input(INPUT_SERVER, "REQUEST_METHOD");
//if ($requestMethod != "GET") {
//  Err::trigger_error1(ERR::ERR_REQMETHOD, "The page has been initiated by an invalid REQUEST_METHOD: " . $requestMethod, __FILE__, __LINE__);  
//}

//print
//$print = substr((bool)filter_input1(INPUT_GET, "print", FILTER_SANITIZE_BOOLEAN), 0 , 1);

$cgFlag = (int)filter_input(INPUT_POST, "cgf");
if ($cgFlag === (98989898989 - (int)(date("YmdH") . left(date("i"), 1)))) {
  $cgFlagCheck = true; 
} else {
  $cgFlagCheck = false;
} 

$cg1 = (int)filter_input(INPUT_POST, "cg1");
$cg2 = (int)filter_input(INPUT_POST, "cg2");
$cgr = (int)filter_input(INPUT_POST, "cgr");
if ($cg1 === 0 || $cg2 === 0 || $cgr === 0) {
  $cgCheck = false; 
} else {
  if (($cg1 + $cg2) === $cgr) {
    $cgCheck = true;
  } else {
    $cgCheck = false;
  }
} 

// DEBUG
// echo "cg1=" . $cg1. "<br>";
// echo "cg2=" . $cg2. "<br>";
// echo "cgr=" . $cgr. "<br>";
// echo "cgFlag=" . $cgFlag. "<br>";
// if ($cgFlagCheck) {
//   echo "cgFlagCheck=" . "true" . "<br>";
// } else {
//   echo "cgFlagCheck=" . "false" . "<br>";
// }  
// if ($cgCheck) {
//   echo "cgCheck=" . "true" . "<br>";
// } else {
//   echo "cgCheck=" . "false" . "<br>";
// }  

?>

<!DOCTYPE html>
<html lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
	
  <meta charset="UTF-8"/>
  
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
  
<!--
<?php echo APP_LICENSE; ?>
-->
  
  <title>GNUBOOK: <?php echo GALLERY_TITLE; ?></title>
	
  <link rel="shortcut icon" href="favicon.ico?v=<?php echo time() ?>" />
  
  <meta name="description" content="<?php echo GALLERY_DESC; ?>"/>
  <meta name="keywords" content="<?php echo GALLERY_KEYWORDS; ?>"/>
  <meta name="robots" content="index,follow"/>
  <meta name="author" content="the <?php echo APP_NAME;?> contributors"/> 

  <script src="/js/jquery-3.6.0.min.js" type="text/javascript"></script>
  
  <link href="/css/style.css" type="text/css" rel="stylesheet">

  <style>
     body {
       background: url('/res/bg3.jpg');
       background-size: cover;
       background-color: #000000;
       background-position: 0 0;
       background-repeat: no-repeat;
     }
     a {
       color: green;
     }
     a:focus {
       color: green;
     }
     a:hover {
       color: green;
     }
     a:visited {
       color: green;
     }
     .bbb {
      color:#7bca2e;
      font-weight: 900;
    }
    .originLabel {
      font-weight:900;
    }
    #footerCont {
      position: relative;
      top: +34.5px;
      left:-15px;
      width: 111%; 
      height:50px;  
      border: 1px solid #C2DBF2; 
      padding: 7px; 
      opacity: 0.6;
      background: #b2dba1;
      color:#000000; 
      font-family: Sans;
      font-size: 12px; 
      text-align: center; 
      z-index: 99998;
      display:none;
    }
    #footer {
      position: relative;
      top: 15px;
      left: -20px;
      float: right;
      width: fit-content; 
      height: 21px;
      border: 0px solid #C2DBF2; 
      padding: 2px; 
      opacity: 0.7;
      background: #000f1f;
      color: #FFFFFF;
      font-family: Sans;
      font-size: 12px; 
      font-weight: 400;
      text-align: right; 
      z-index: 99999;
      vertical-align:middle;
    }
    #originsDisplay {
      float: right;
      position:relative;
      top:-30px; 
      width:200px;
      height:80px;
      text-align:left;
      margin-right:42px;
      display:inline;
    }

    @media screen and (max-width: 650px) {
      #video {
        display:none;
      }     
    }

  </style>

</head>

<body style="background-color: #000000; color: #FFFFFF">

  <div class="body-area">

  <div class="content-area">
    
    <div class="box" align="center">

      <br><br>

<?php if (!$cgFlagCheck || !$cgCheck) { ?>

    <form id="frmcg" name="frmcg" action="." method="post" target="_self">
      <div stype="font-family: arial,verdana, sans serif;">
          &nbsp;&nbsp;&nbsp;<span style="font-size:13px">5 Mode Recaptcha:</span><br>
          &nbsp;&nbsp;&nbsp;<input id="cg1" name="cg1" type="number" maxlength="1" style="width:36px">&nbsp;&plus;&nbsp;<input id="cg2" name="cg2" type="number" maxlength="1" style="width:36px">&nbsp;&equals;&nbsp;<input id="cg2" name="cgr" type="number" maxlength="1" style="width:36px"></br></br>
          &nbsp;&nbsp;&nbsp;<input type="submit" value="Go" stype="font-size: 12px;">    
      </div>  
      <input id="cgf" name="cgf" type="hidden" value="<?php echo(98989898989 - (int)(date("YmdH") . left(date("i"),1)));?>">
    </form> 
      
<?php } else { ?>


  <div id="originsDisplay">
      <br>
       &nbsp;<span class="originLabel">Coding:</span>&nbsp;Italy&nbsp;<br>
       &nbsp;<span class="originLabel">Server:</span>&nbsp;Finland&nbsp;<br>
       &nbsp;<span class="originLabel"><a href="http://metrica.yandex.com" class="bbb" style="color:#7bca2e;" target="_top">Metrics</a>:</span>&nbsp;Russia&nbsp;<br>
      <br>
  </div>
 
      
  <?php

    // BEGIN Links

    //$iGalleries = GalleryUtil::readGalleryIndex($aGalleryIndx, GalleryUtil::LINK_GALLERY);

    $aGalleryIndx = [
              0 => [
                  'virtualPath' => 'gnubook',
                  'link' => 'https://gnubook.org/gnubook'
                ]   
             ];

    $iGalleries = count($aGalleryIndx);

    if ($iGalleries === 0) {

      echo "Empty";

      ?>

  <?php  

    } else {

     echo "<p>";  

      echo "<img src='/res/logoos.png' style='width:280px;height:280px;margin-left:22px;float:left;'>"; 

      echo '<iframe id="video" style="width:350px; height:350px; clear:both; margin-left:5%;" src="https://www.youtube.com/embed/5qF_qbaWt3Q?autoplay=1&loop=1&controls=0"; title="Linkin Park - Waiting For The end" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>';

      echo "</p>";  

      echo "<div style='clear:both;'><br><br></div>";

      echo "<H3 style='clear:both;float:left;background:#000000;'>&nbsp;&nbsp;&nbsp;gnubook list:&nbsp;&nbsp;&nbsp;</H3>";
      
      //echo "<ul style='float:left; width:100%'>";
      
      echo "<br><br><br><br><br>";
      
      echo "<table border='0' style='width:95%;margin:auto; margin-left:20px; border:3px solid #FFFFFF;'>";

     $aBgs = ["#f2f2f2","#001832"];
     $aColors = ["#000000","#ffffff"];
     //$aBgs = ["#f2f2f2","#9ff99f"];
      
      $odd = false;    
      foreach ($aGalleryIndx as $gallery) { 
        
        if ($gallery['virtualPath'] !== "Index" && $gallery['virtualPath'] !== "Indexfoss") { ?>
              
        <tr><td style='height:35px;text-align:left;padding-left:5px;border-bottom:1px dashed lightgray;background:<?PHP echo($aBgs[$odd]);?>;color:#000000;white-space:nowrap;'><a href="<?PHP echo $gallery['link']; ?>"><?php echo $gallery['virtualPath']; ?></a></td><td style="width:150px;border-bottom:1px dashed lightgray;background:<?PHP echo($aBgs[$odd]);?>;color:<?PHP echo($aColors[$odd]);?>;text-align:center;">=&gt;</td><td style="border-bottom:1px dashed lightgray;padding-left:5px;background:<?PHP echo($aBgs[$odd]);?>;color:<?PHP echo($aColors[$odd]);?>;white-space:nowrap;"><?PHP echo $gallery['link']; ?></td></tr>

        <?PHP    

         $odd=!$odd;
           
        } 
 
      }

      echo "</table>";

      echo "<div style='clear:all; width:100%;'>&nbsp;</div>";
    }

    // END Link

    ?>

<br><br>

<div id="footerCont">&nbsp;</div>
<div id="footer">&nbsp;&nbsp;<a href="https://5mode.com/dd.html" class="aaa" target="_top">Disclaimer</a>.&nbsp;&nbsp;A <a href="http://5mode.com/EN" class="aaa" target="_top">5 Mode</a> project and <a href="http://demo.5mode.com" target="_top" class="aaa">WYSIWYG</a> system. - CC&nbsp;&nbsp;</div>

<br><br><br>


<?php } ?>


   </div>
  
  </div>  
  
  </div>


<!-- Yandex.Metrika counter -->
<script type="text/javascript" >
   (function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
   m[i].l=1*new Date();k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)})
   (window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");

   ym(97668368, "init", {
        clickmap:true,
        trackLinks:true,
        accurateTrackBounce:true
   });
</script>
<noscript><div><img src="https://mc.yandex.ru/watch/97668368" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
<!-- /Yandex.Metrika counter -->

</body>
</html>
