Advertisement
Guest User

Template

a guest
Mar 26th, 2015
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.17 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <head>
  5.     <title>Hackit test</title>
  6.     <link rel="stylesheet" href="http://getbootstrap.com/dist/css/bootstrap.min.css">
  7.     <link rel="stylesheet" href="http://prismjs.com/themes/prism.css">
  8.     <link rel="stylesheet" href="https://bootswatch.com/slate/bootstrap.min.css">
  9.     <link rel="stylesheet" href="http://fortawesome.github.io/Font-Awesome/assets/font-awesome/css/font-awesome.css">
  10.     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
  11.    
  12.     <style>
  13.     .red   { color: #F33    }
  14.     .green { color: #62C462 }
  15.     .blue  { color: #39C    }
  16.     </style>
  17. </head>
  18.  
  19. <body>
  20.     <div class="container theme-showcase" role="main">
  21.         <div class="container-fluid text-center" style="min-height:300px;padding-top:10px;">
  22.    
  23.         <!-- :::::::::::::::::==== GAME STARTS HERE ====::::::::::::::::: -->
  24.  
  25. <?php
  26.     define("DS",   DIRECTORY_SEPARATOR      );
  27.     define("ROOT", $_SERVER['DOCUMENT_ROOT']);
  28.     session_start();
  29.    
  30.    
  31.     /******** Submit below this line ********/
  32.    
  33.         // changed a bit for testing
  34.         class HackitX {// implements Hackit
  35.         //{
  36.             private $level = '';
  37.             public $author = ''; //You can enter your name here if you want
  38.             public function __construct(){$this->level = basename(__FILE__, '.php');} //so you can use $this->level to get the level id
  39.  
  40.             public function getName()        { return 'My test level';      } //The name will be displayed in the level table
  41.             public function getDescription() { return 'A work in progress'; } //This will be displayed when the level is started
  42.             public function getTags()        { return 'PHP';                } //Describe what technology you used. Comma,seperated
  43.            
  44.            
  45.             private function setTimeLimit($time) {  //Add a time limit to the level, use with getTimeLimit for status
  46.                 //USAGE: $this->setTimeLimit(30); //null
  47.                 $_SESSION['levels'][$this->level]['starttime'] = time();
  48.                 $_SESSION['levels'][$this->level]['maxtime']   = $time;
  49.                 $_SESSION['levels'][$this->level]['timerset']  = true;
  50.             }
  51.            
  52.             private function getTimeLimit() {  //return the active state of the time limit, the expired state, and the max time
  53.                 //USAGE: $this->getTimeLimit()->isExpired //bool
  54.                 $isExpired = false;
  55.                 $isActive  = false;
  56.                 $maxTime   = 0;
  57.                
  58.                 if (
  59.                     array_key_exists('timerset', $_SESSION['levels'][$this->level]) &&
  60.                     $_SESSION['levels'][$this->level]['timerset'] === true
  61.                 ) {
  62.                     $isActive = true;
  63.                     $maxTime  = $_SESSION['levels'][$this->level]['maxtime'];
  64.                    
  65.                     if (time() - $_SESSION['levels'][$this->level]['starttime'] >= $maxTime)
  66.                         $isExpired = true;
  67.                    
  68.                 }
  69.                
  70.                 return (object)[
  71.                     "isActive"  => $isActive,
  72.                     "isExpired" => $isExpired,
  73.                     "maxTime"   => $maxTime
  74.                 ];
  75.             } //Remember to include the time limit information in your render() !
  76.            
  77.            
  78.             //shortcuts to set and check the password
  79.             // $this->setLevelPassword("tooeasy") //null
  80.             // $this->getLevelPassword()          //"tooeasy"
  81.            
  82.             private function setLevelPassword($password) {
  83.                 $_SESSION['levels'][$this->level]['password'] = $password;
  84.             }
  85.            
  86.             private function getLevelPassword() {
  87.                 if (! array_key_exists('password', $_SESSION['levels'][$this->level]) ) return false;
  88.                
  89.                 return $_SESSION['levels'][$this->level]['password'];
  90.             }
  91.            
  92.            
  93.             /******** Modify below this line ********/
  94.            
  95.            
  96.        
  97.        /**
  98.         *
  99.         * This method is called to check if the
  100.         * level has been solved. if it returns
  101.         * true, it's solved
  102.         *
  103.         * @return      bool
  104.         *
  105.         */
  106.             public function isSolved() {
  107.             /*
  108.                 //EX: if the time limit is active
  109.                 //and has not expired
  110.                 //or is not active
  111.                 //and the password is correct
  112.                 // -> return true
  113.                
  114.                 $timer = $this->getTimeLimit();
  115.                 if (
  116.                     (
  117.                      (
  118.                         $timer->isActive  === true  &&
  119.                         $timer->isExpired === false
  120.                      ) || (
  121.                         $timer->isActive  === false
  122.                      )
  123.                     ) &&
  124.                     array_key_exists('pw', $_REQUEST) &&
  125.                     $_REQUEST['pw'] === $this->getLevelPassword()
  126.                 ) return true;
  127.                
  128.                 return false;
  129.             */
  130.            
  131.            
  132.             }
  133.            
  134.            
  135.        /**
  136.         *
  137.         * The prepare method is called before
  138.         * rendering the level. You can define
  139.         * the password for this level, start
  140.         * timers.. everything you want!
  141.         *
  142.         * @return      NULL
  143.         *
  144.         */
  145.             public function prepare() {
  146.             /*
  147.                 //EX: Make sure we have an array for this level's data in $_SESSION
  148.                 if (
  149.                     (!array_key_exists( $this->level, $_SESSION['levels'] ))  ||
  150.                     gettype($_SESSION['levels'][$this->level]) != "array"
  151.                 ) $_SESSION['levels'][$this->level] = [];
  152.                    
  153.                    
  154.                    
  155.                 // If you want to set a time limit (ex 30 seconds):
  156.                
  157.                 $timer = $this->getTimeLimit();
  158.                 if (
  159.                     $timer->isActive  === false ||
  160.                     $timer->isExpired === true
  161.                 ) {
  162.                     $this->setTimeLimit(30);
  163.                    
  164.                    
  165.                     // ---=== do your randomizing stuff here ===--- //
  166.                    
  167.                     $secret = mt_rand(0, 100);
  168.                     $this->setLevelPassword("password" . $secret);
  169.                 }
  170.                
  171.                
  172.             */                
  173.                
  174.                
  175.             }
  176.            
  177.            
  178.        /**
  179.         *
  180.         * The render method is called last and
  181.         * returns the HTML code that will be
  182.         * displayed on the level. You can use
  183.         * variables defined in the prepare
  184.         * method since render is called last
  185.         *
  186.         * @return      NULL
  187.         *
  188.         */
  189.             public function render() {
  190.                 return '
  191.                <div>Subtitle or description</div>
  192.                <p>You have <span class="green">30 seconds</span> to solve this level</p>
  193.                <!-- Your stuff here -->
  194.                <input type="password" id="pw" />
  195.                <input type="button" onclick="checkPW()" value="GO" />
  196.                <script>
  197.                function checkPW() {
  198.                    el = document.getElementById("pw");
  199.                    document.location.href = "?pw=" + el.value;
  200.                }
  201.                <!-- if the level time limit is active, print out some JS to refresh the page -->
  202.                ' . ( $this->getTimeLimit()->isActive ? "setTimeout(checkPW, " . $this->getTimeLimit()->maxTime * 1000 . ");" : "" ). '    
  203.                </script>';
  204.             }
  205.                
  206.         }
  207.     /******** Modify above this line ********/
  208.     /******** Submit above this line ********/
  209.    
  210.    
  211.    
  212.     $hackit = new HackitX();
  213.    
  214.     $hackit->prepare();
  215.     if ($hackit->isSolved() === false) {
  216.         if (array_key_exists('pw', $_REQUEST) && !empty($_REQUEST['pw']) ) echo '
  217.        <div class="alert alert-dismissable alert-danger">
  218.            <button type="button" class="close" data-dismiss="alert">×</button>
  219.            <p>Wrong password</p>
  220.        </div>
  221.        ';
  222.        
  223.         echo '<h1>Test level</h1>';
  224.         if ( !empty($hackit->author) ) echo "By $hackit->author";
  225.         echo "<br><br>";
  226.         echo $hackit->render();
  227.     } else echo '
  228.        <div class="alert alert-dismissable alert-success">
  229.            <button type="button" class="close" data-dismiss="alert">×</button>
  230.            <p>
  231.                <h2>Test level solved!</h2>
  232.            </p>
  233.        </div>
  234.        <a href="?">Replay this level</a>
  235.    ';
  236. ?>
  237.  
  238.         <!-- ::::::::::::::::::==== GAME ENDS HERE ====:::::::::::::::::: -->
  239.  
  240.  
  241.         </div>
  242.     </div>
  243.    
  244.     <script src="http://getbootstrap.com/dist/js/bootstrap.min.js"></script>
  245.     <script src="http://prismjs.com/prism.js"></script>
  246.    
  247.     <script>document.onkeydown=function(){if(window.event.keyCode=='13'){checkPW();}} //submit on enter </script>
  248. </body>
  249.  
  250. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement