From 79d928cd42c32122edd47d1a450fb0c4ced3de2f Mon Sep 17 00:00:00 2001 From: raylu Date: Wed, 18 Jul 2012 01:45:55 -0700 Subject: fix lots of warnings, whitespace --- do.php | 83 +++++++++++++++++++++++++------------------------ globe.php | 10 +++--- includes/datas.php | 4 +-- includes/header.php | 12 ++++---- includes/maps.php | 34 ++++++++++++--------- index.php | 80 +++++++++++++++++++++++------------------------- pages/cp.php | 4 +-- pages/home.php | 22 +++++++------ pages/leaderboard.php | 85 ++++++++++++++++++++++++++------------------------- pages/login.php | 6 ++-- pages/tutorial.php | 7 ++--- 11 files changed, 176 insertions(+), 171 deletions(-) diff --git a/do.php b/do.php index a2f25d7..2bf6bb9 100644 --- a/do.php +++ b/do.php @@ -7,19 +7,19 @@ include "includes/datas.php"; //Auto login; include_once("globe.php"); -if ($_SESSION['accepted'] <> 1) - if ($_COOKIE['doLogin'] == 'yes') +if (!isset($_SESSION['accepted']) || $_SESSION['accepted'] <> 1) + if (isset($_COOKIE['doLogin']) && $_COOKIE['doLogin'] == 'yes') CookieLogin(); // encode array $json to JSON string - -if ($_GET['act'] == "getmap") { + +if (isset($_GET['act']) && $_GET['act'] == "getmap") { $map = GenerateMapByCode($_GET['mapcode']); - + $solution = formSolution($_GET['solution']); - + $solvedmap = MergeMapSolution($map, $solution); if ($solvedmap == -1) { $json['error'][] = "INVALID WALL POSITIONS"; @@ -29,21 +29,21 @@ if ($_GET['act'] == "getmap") { } } -if ($_GET['checkachieve'] == 'true' AND $_SESSION['accepted'] == 1) { +if (isset($_GET['checkachieve']) && $_GET['checkachieve'] == 'true' && $_SESSION['accepted'] == 1) { $json['notification'] = true; - + $userID = $_SESSION['userID']; - + //Located in includes/datas.php $note = getNotified($userID); - + if ($note !== false) $json['notificationtext'] = $note; } if ($_GET['r'] == 'getscores') { $mapID = $_GET['mapid'] + 0; - if (!is_int($mapID)) + if (!is_int($mapID)) return; $topscores = topScores($mapID, 30); $json['scores'] = $topscores; @@ -58,7 +58,7 @@ if ($_GET['r'] == 'getsol') { if (!is_int($mapID)) return; $userID = $_SESSION['userID']; - + if ($_SESSION['accepted'] == 1) $json = getSolution($userID, $mapID); if (isset($_SESSION[$mapID.'sol']) AND $mysolution == '') { @@ -66,7 +66,7 @@ if ($_GET['r'] == 'getsol') { $json['moves'] = $_SESSION[$mapID.'moves']; } $json['mapid'] = $mapID; - + $encoded = json_encode($json); die($encoded); } @@ -76,36 +76,36 @@ if ($_GET['r'] == 'getsol') { if ($_GET['r'] == 'getpath') { //Join the partial-solution from the map, and the solution sent. - //Could be used to validate maps in for challenges where + //Could be used to validate maps in for challenges where // getting the map code from the database is not an option //$tmp = GenerateMapByCode($_GET['mapcode']); //$tmp = seperateMapSolution($tmp); //$solution = formSolution($_GET['solution'].$tmp); - + // Enables the ability to discover an exact duplicate solution. $solution = formSolution($_GET['solution']); - //valid mapID? + //valid mapID? $mapID = $_GET[mapid] + 0; if (!is_int($mapID)) return; - + //the first 10 ID's reserved for challenges & tutorial. if ($mapID > 10) $mapcode = getMapCode($mapID); - else + else $mapcode = $_GET['mapcode']; - + //mygrid will be the map, with the solution applied. $map = GenerateMapByCode($mapcode); $mygrid = MergeMapSolution($map, $solution); - + //Route the path $json = routePath($mygrid, $start); - + $moves = $json['moves']; $json['mapid'] = $mapID; - + //What could go wrong? if ($json['blocked']) { //$json['error'][] = "blocked"; @@ -133,10 +133,10 @@ if ($_GET['r'] == 'getpath') { FROM `solutions` WHERE `userID` = '$userID' AND `mapID` = '$mapID' - ) as q1 + ) as q1 ON 1 WHERE - `mapID` = '$mapID' AND + `mapID` = '$mapID' AND `userID` = users.ID ORDER BY `moves` DESC, `dateModified` ASC LIMIT 1"; @@ -150,18 +150,18 @@ if ($_GET['r'] == 'getpath') { $json['best'] = 0; $json['bestby'] = 'no one'; } - + // --------- RUSH THE PATH BACK TO THE USER ignore_user_abort(true); $encoded = json_encode($json); header("Connection: close"); - header("Content-Length: " . mb_strlen($encoded)); + header("Content-Length: " . mb_strlen($encoded)); echo $encoded; flush(); - + // --------- CONTINUE EXECUTION - - + + // --------- USER NOT LOGGED IN? if ($_SESSION['accepted'] !== 1) { if ($moves >= ($_SESSION[$mapID.'moves'] + 0)) { @@ -171,27 +171,27 @@ if ($_GET['r'] == 'getpath') { return; } // --------- USER LOGGED IN - + //Challenge/Tutorial? if ($mapID <= 10 AND $_GET['isChallenge'] = 'true') { //echo "running function".$_GET['challengeID']; applyChallengeAchievements($userID, $_GET['challengeID'], $mapID, $solution, $moves); return; } - + //Is the map still valid to score on? if (!isCurrentMap($mapID)) return; // --------- UPDATE SCORES - + $checkcp = false; $checkcm = false; - + //Is there an existing record? if ($myMoves > 0) { if ($myMoves < $moves) { - $sql = "UPDATE `solutions` + $sql = "UPDATE `solutions` SET `moves` = '$moves' , `dateModified` = NOW() , `solution` = '$solution' @@ -201,13 +201,12 @@ if ($_GET['r'] == 'getpath') { $checkcp = true; //Update the solution only, if it's the same score. } elseif ($myMoves == $moves) { - $sql = "UPDATE `solutions` + $sql = "UPDATE `solutions` SET `moves` = '$moves' , `solution` = '$solution' WHERE `userID` = '$userID' AND `mapID` = '$mapID'"; mysql_query($sql); - } //Create a new record. } else { @@ -217,7 +216,7 @@ if ($_GET['r'] == 'getpath') { $checkcm = true; $checkcp = true; } - + // --------- APPLY ACHIEVEMENTS if ($checkcp) @@ -231,7 +230,7 @@ if ($_GET['r'] == 'getpath') { // no need w/ rush-sending. //$encoded = json_encode($json); //echo $encoded; - + // --------- END } @@ -243,9 +242,9 @@ function isCurrentMap($mapID) { `mapID` = '$mapID' "; $result = mysql_query($sql) or die(mysql_error()); - if (mysql_num_rows($result) == 0) + if (mysql_num_rows($result) == 0) return false; - else + else return true; } @@ -271,7 +270,7 @@ function ValidateMap($mygrid) { $json['error'][] = 'Division by 912 trillion!'; $json['error'][] = 'Cant count that high.'; - + $json['error'][] = "I forgot what I was doing!"; $json['error'][] = "Lost track of time, and gaveup!"; @@ -280,4 +279,4 @@ die($encoded); -?> \ No newline at end of file +?> diff --git a/globe.php b/globe.php index 051603d..3470e78 100644 --- a/globe.php +++ b/globe.php @@ -1,5 +1,7 @@ \ No newline at end of file +?> diff --git a/includes/datas.php b/includes/datas.php index 5d901ee..c445ca1 100644 --- a/includes/datas.php +++ b/includes/datas.php @@ -26,9 +26,9 @@ function topScores($mapid, $top = 5, $bottom = 0) { ORDER BY solutions.moves DESC, solutions.dateModified ASC LIMIT $bottom, $top "; - $result = mysql_query($sql); + $result = mysql_query($sql) or die(mysql_error()); $utime = date("g:i A (T)"); - $output .= ""; + $output = "
"; $output .= ""; $output .= ""; $output .= ""; diff --git a/includes/header.php b/includes/header.php index d718588..887aa41 100644 --- a/includes/header.php +++ b/includes/header.php @@ -1,6 +1,7 @@ @@ -25,7 +26,7 @@ function htmlHeader($css = array(), $title = 'Pathery', $desc = '') { for(e=0;e'; - $page = $_GET['page']; - if ($page == '') - $page = 'home'; + $page = isset($_GET['page']) ? $_GET['page'] : 'home'; foreach ($links as $key => $value) { if ($page == $key) $selected = " selected"; @@ -103,7 +103,7 @@ function topbar($links) { } echo "
"; - if ($_SESSION['accepted'] == 1) { + if ($accepted) { echo "Logged in as $_SESSION[displayName]
"; if ($_SESSION['displayName'] == 'noname') echo "Update your name | "; diff --git a/includes/maps.php b/includes/maps.php index 4618ff8..16aa35c 100644 --- a/includes/maps.php +++ b/includes/maps.php @@ -109,7 +109,7 @@ function DisplayMap($mapMatrix, $idprefix = 1, $style = 'normal', $speed = NULL) $jsonmap = str_replace("'", "\'", json_encode($mapdata)); //This works in chrome, not sure about others. - $preloaddiv .= " + $preloaddiv = "
@@ -134,16 +134,20 @@ function DisplayMap($mapMatrix, $idprefix = 1, $style = 'normal', $speed = NULL)
RankBadge
$maptable
"; - - - $prefSpeed = $_COOKIE['pref_speed']; - $speedOption['Slow'] = 1; - $speedOption['Med'] = 2; - $speedOption['Fast'] = 3; - $speedOption['Ultra'] = 4; - if (!in_array($prefSpeed, $speedOption)) + + + if (isset($_COOKIE['pref_speed'])) { + $prefSpeed = $_COOKIE['pref_speed']; + $speedOption['Slow'] = 1; + $speedOption['Med'] = 2; + $speedOption['Fast'] = 3; + $speedOption['Ultra'] = 4; + if (!in_array($prefSpeed, $speedOption)) + $prefSpeed = '2'; + } else $prefSpeed = '2'; + $rOption = ''; foreach ($speedOption as $key => $value) { $rOption .= "