Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include("database.php");
- //select two random images from fs
- $dir = 'images';
- $files = glob($dir . '/*.*');
- $file1 = array_rand($files);
- $file2 = array_rand($files);
- while($file2 == $file1) {
- $file2 = array_rand($files);
- }
- $imageLink1 = $files[$file1];
- $imageLink2 = $files[$file2];
- $imageLink1 = substr($imageLink1, strlen($dir) + 1);
- $imageLink2 = substr($imageLink2, strlen($dir) + 1);
- $firstImage = $db->query("SELECT * FROM images WHERE image_name LIKE '$imageLink1'");
- if($firstImage->num_rows == 0) {
- //new image. set new row
- $db->query("INSERT INTO images (image_name) VALUES ('$imageLink1')");
- $db->query("UPDATE images SET image_show = image_show + 1 WHERE image_name LIKE '$imageLink1'");
- $click1 = 0;
- $show1 = 1;
- $percentage1 = 0;
- } else {
- $db->query("UPDATE images SET image_show = image_show + 1 WHERE image_name LIKE '$imageLink1'");
- $row = $firstImage->fetch_assoc();
- $click1 = $row["image_clicked"];
- $show1 = $row["image_show"] + 1;
- if($row["image_show"] > 0) {
- $percentage1 = round($click1 / $show1 * 100, 2);
- } else {
- $percentage1 = 0;
- }
- }
- $secondImage = $db->query("SELECT * FROM images WHERE image_name LIKE '$imageLink2'");
- if($secondImage->num_rows == 0) {
- //new image. set new row
- $db->query("INSERT INTO images (image_name) VALUES ('$imageLink2')");
- $db->query("UPDATE images SET image_show = image_show + 1 WHERE image_name LIKE '$imageLink2'");
- $click2 = 0;
- $show2 = 1;
- $percentage2 = 0;
- } else {
- $db->query("UPDATE images SET image_show = image_show + 1 WHERE image_name LIKE '$imageLink2'");
- $row = $secondImage->fetch_assoc();
- $click2 = $row["image_clicked"];
- $show2 = $row["image_show"] + 1;
- if($row["image_show"] > 0) {
- $percentage2 = round($click2 / $show2 * 100, 2);
- } else {
- $percentage2 = 0;
- }
- }
- ?>
- <html>
- <head>
- <title>Facemash</title>
- <link href="homepage.css" rel="stylesheet" type="text/css">
- </head>
- <script type="text/javascript">
- //NProgress.start();
- function clickImage(target) {
- NProgress.start();
- target.parent().addClass("clicked");
- var data = {
- image: target.attr("data-title")
- };
- $.post("save.php", data, function(response) {
- NProgress.done();
- $(".image img").off();
- //$(".ricarica").show();
- window.location.reload();
- });
- }
- $(document).ready( function() {
- $(".image img").click( function(e) {
- clickImage($(e.currentTarget));
- });
- $(".ricarica button").click( function() {
- window.location.reload();
- });
- $(document).keydown(function(e) {
- switch(e.which) {
- case 37: clickImage($(".left-arrow"));
- break;
- case 39: clickImage($(".right-arrow"));
- break;
- default: return;
- }
- e.preventDefault(); // prevent the default action (scroll / move caret)
- });
- //NProgress.done();
- });
- </script>
- </head>
- <body>
- <nav class="menuwrap">
- <div class="header">FACEMASH</div>
- </nav>
- <div class="container">
- <div class="image-container">
- <div class="image">
- <h2 class="image-title"><?php echo $imageLink1; ?></h2>
- <img class="left-arrow" src="images/<?php echo $imageLink1; ?>" data-title="<?php echo $imageLink1; ?>"/>
- <div class="info">
- <p>Won : <?php echo $click1; ?> Lost : <?php echo $show1; ?></p>
- </div>
- </div>
- <div class="image">
- <h2 class="image-title"><?php echo $imageLink2; ?></h2>
- <img class="right-arrow" src="images/<?php echo $imageLink2; ?>" data-title="<?php echo $imageLink2; ?>"/>
- <div class="info">
- <p>Won : <?php echo $click2; ?> Lost : <?php echo $show2; ?></p>
- </div>
- </div>
- <div class="clearfix"></div>
- </div>
- <div class="ricarica">
- <button class="btn btn-primary">Mostrami altre immagini!</button>
- </div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment