chore: run formatter tools against PHP code

Run formatting tools against the PHP source code to meet PSR12 standards

The tools used to format the code (for anyone interested in validating
the changes are:
* [PHP-CS-FIXER](https://github.com/FriendsOfPHP/PHP-CS-Fixer)
* [PHPCS](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Fixing-Errors-Automatically)
This commit is contained in:
Robb Currall 2021-08-05 10:56:41 -04:00
parent e0626c7cac
commit db8b1d49c1
No known key found for this signature in database
GPG Key ID: 12405B4513213DB0
30 changed files with 1438 additions and 1560 deletions

View File

@ -1,4 +1,5 @@
<?php
define('TILESPATH', 'tiles/');
$path = $_SERVER['PATH_INFO'];
@ -9,13 +10,13 @@ if (!file_exists($fname)) {
$fname = "images/blank.png";
}
$fp = fopen($fname, 'rb');
if (strstr($path, ".png"))
if (strstr($path, ".png")) {
header("Content-Type: image/png");
else
} else {
header("Content-Type: image/jpeg");
}
header("Content-Length: " . filesize($fname));
fpassthru($fp);
exit;
?>

View File

@ -1,8 +1,8 @@
<?php
require_once('MySQL_funcs.php');
require_once 'MySQL_funcs.php';
if ($loginenabled) {
$rslt = getStandaloneFile('dynmap_access.php');
eval($rslt);
}
?>

View File

@ -1,16 +1,16 @@
<?php
ob_start();
require_once('MySQL_funcs.php');
include('MySQL_config.php');
include('MySQL_access.php');
require_once 'MySQL_funcs.php';
require 'MySQL_config.php';
require 'MySQL_access.php';
ob_end_clean();
session_start();
if (isset($_SESSION['userid'])) {
$userid = $_SESSION['userid'];
}
else {
} else {
$userid = '-guest-';
}
@ -27,11 +27,9 @@ $json = json_decode($content);
if (!$loginenabled) {
echo $content;
}
else if($json->loginrequired && !$loggedin) {
} elseif ($json->loginrequired && !$loggedin) {
echo "{ \"error\": \"login-required\" }";
}
else {
} else {
$uid = '[' . strtolower($userid) . ']';
$json->loggedin = $loggedin;
$wcnt = count($json->worlds);
@ -42,12 +40,10 @@ else {
$ss = stristr($worldaccess[$w->name], $uid);
if ($ss !== false) {
$newworlds[] = $w;
}
else {
} else {
$w = null;
}
}
else {
} else {
$newworlds[] = $w;
}
if ($w != null) {
@ -60,8 +56,7 @@ else {
if ($ss !== false) {
$newmaps[] = $m;
}
}
else {
} else {
$newmaps[] = $m;
}
}
@ -73,6 +68,3 @@ else {
echo json_encode($json);
}
cleanupDb();
?>

View File

@ -1,13 +1,15 @@
<?php
function cleanupDb() {
function cleanupDb()
{
if (isset($db)) {
$db->close();
$db = NULL;
$db = null;
}
}
function abortDb($errormsg) {
function abortDb($errormsg)
{
header('HTTP/1.0 500 Error');
echo "<h1>500 Error</h1>";
echo $errormsg;
@ -15,7 +17,8 @@ function abortDb($errormsg) {
exit;
}
function initDbIfNeeded() {
function initDbIfNeeded()
{
global $db, $dbhost, $dbuserid, $dbpassword, $dbname, $dbport;
$pos = strpos($dbname, '?');
@ -32,7 +35,8 @@ function initDbIfNeeded() {
}
}
function getStandaloneFileByServerId($fname, $sid) {
function getStandaloneFileByServerId($fname, $sid)
{
global $db, $dbprefix;
initDbIfNeeded();
@ -43,15 +47,15 @@ function getStandaloneFileByServerId($fname, $sid) {
$stmt->bind_result($content);
if ($stmt->fetch()) {
$rslt = $content;
}
else {
$rslt = NULL;
} else {
$rslt = null;
}
$stmt->close();
return $rslt;
}
function getStandaloneFile($fname) {
function getStandaloneFile($fname)
{
global $serverid;
if (!isset($serverid)) {
@ -63,7 +67,8 @@ function getStandaloneFile($fname) {
return getStandaloneFileByServerId($fname, $serverid);
}
function updateStandaloneFileByServerId($fname, $sid, $content) {
function updateStandaloneFileByServerId($fname, $sid, $content)
{
global $db, $dbprefix;
initDbIfNeeded();
@ -77,7 +82,8 @@ function updateStandaloneFileByServerId($fname, $sid, $content) {
return $res;
}
function updateStandaloneFile($fname, $content) {
function updateStandaloneFile($fname, $content)
{
global $serverid;
if (!isset($serverid)) {
@ -89,7 +95,8 @@ function updateStandaloneFile($fname, $content) {
return updateStandaloneFileByServerId($fname, $serverid, $content);
}
function insertStandaloneFileByServerId($fname, $sid, $content) {
function insertStandaloneFileByServerId($fname, $sid, $content)
{
global $db, $dbprefix;
initDbIfNeeded();
@ -100,7 +107,8 @@ function insertStandaloneFileByServerId($fname, $sid, $content) {
return $res;
}
function insertStandaloneFile($fname, $content) {
function insertStandaloneFile($fname, $content)
{
global $serverid;
if (!isset($serverid)) {
@ -111,5 +119,3 @@ function insertStandaloneFile($fname, $content) {
}
return insertStandaloneFileByServerId($fname, $serverid, $content);
}
?>

View File

@ -1,8 +1,8 @@
<?php
require_once('MySQL_funcs.php');
require_once 'MySQL_funcs.php';
if ($loginenabled) {
$rslt = getStandaloneFile("dynmap_login.php");
eval($rslt);
}
?>

View File

@ -1,16 +1,16 @@
<?php
ob_start();
require_once('MySQL_funcs.php');
include('MySQL_config.php');
include('MySQL_getlogin.php');
require_once 'MySQL_funcs.php';
require 'MySQL_config.php';
require 'MySQL_getlogin.php';
ob_end_clean();
session_start();
if (isset($_POST['j_username'])) {
$userid = $_POST['j_username'];
}
else {
} else {
$userid = '-guest-';
}
$good = false;
@ -18,8 +18,7 @@ $good = false;
if (strcmp($userid, '-guest-')) {
if (isset($_POST['j_password'])) {
$password = $_POST['j_password'];
}
else {
} else {
$password = '';
}
$ctx = hash_init('sha256');
@ -30,12 +29,10 @@ if(strcmp($userid, '-guest-')) {
if (strcasecmp($hash, $pwdhash[$useridlc]) == 0) {
$_SESSION['userid'] = $userid;
$good = true;
}
else {
} else {
$_SESSION['userid'] = '-guest-';
}
}
else {
} else {
$_SESSION['userid'] = '-guest-';
$good = true;
}
@ -49,11 +46,12 @@ if(!empty($lines)) {
$changed = false;
for ($i = 1; $i < $cnt; $i++) {
list($uid, $pc, $hsh) = explode('=', rtrim($lines[$i]));
if($uid == $useridlc) continue;
if ($uid == $useridlc) {
continue;
}
if (array_key_exists($uid, $pendingreg)) {
$newlines[] = $uid . '=' . $pc . '=' . $hsh;
}
else {
} else {
$changed = true;
}
}
@ -64,12 +62,8 @@ if(!empty($lines)) {
if ($good) {
echo "{ \"result\": \"success\" }";
}
else {
} else {
echo "{ \"result\": \"loginfailed\" }";
}
cleanupDb();
?>

View File

@ -1,16 +1,16 @@
<?php
ob_start();
require_once('MySQL_funcs.php');
include('MySQL_config.php');
include('MySQL_access.php');
require_once 'MySQL_funcs.php';
require 'MySQL_config.php';
require 'MySQL_access.php';
ob_end_clean();
session_start();
if (isset($_SESSION['userid'])) {
$userid = $_SESSION['userid'];
}
else {
} else {
$userid = '-guest-';
}
@ -49,14 +49,11 @@ if ($parts[0] == "faces") {
$ft = 0;
if ($parts[1] == "8x8") {
$ft = 0;
}
else if ($parts[1] == '16x16') {
} elseif ($parts[1] == '16x16') {
$ft = 1;
}
else if ($parts[1] == '32x32') {
} elseif ($parts[1] == '32x32') {
$ft = 2;
}
else if ($parts[1] == 'body') {
} elseif ($parts[1] == 'body') {
$ft = 3;
}
$pn = explode(".", $parts[2]);
@ -67,12 +64,10 @@ if ($parts[0] == "faces") {
if ($stmt->fetch()) {
header('Content-Type: image/png');
echo $timage;
}
else {
} else {
header('Location: ../images/blank.png');
}
}
else { // _markers_
} else { // _markers_
$in = explode(".", $parts[1]);
$name = implode(".", array_slice($in, 0, count($in) - 1));
$ext = $in[count($in) - 1];
@ -85,12 +80,10 @@ else { // _markers_
header('Content-Type: application/json');
if ($stmt->fetch()) {
echo $timage;
}
else {
} else {
echo "{ }";
}
}
else {
} else {
$stmt = $db->prepare('SELECT Image from ' . $dbprefix . 'MarkerIcons WHERE IconName=?');
$stmt->bind_param('s', $name);
$res = $stmt->execute();
@ -98,8 +91,7 @@ else { // _markers_
if ($stmt->fetch()) {
header('Content-Type: image/png');
echo $timage;
}
else {
} else {
header('Location: ../images/blank.png');
}
}
@ -110,4 +102,3 @@ $stmt->close();
cleanupDb();
exit;
?>

View File

@ -1,22 +1,21 @@
<?php
ob_start();
require_once('MySQL_funcs.php');
include('MySQL_config.php');
require('MySQL_getlogin.php');
require_once 'MySQL_funcs.php';
require 'MySQL_config.php';
require 'MySQL_getlogin.php';
ob_end_clean();
session_start();
if (isset($_POST['j_password'])) {
$password = $_POST['j_password'];
}
else {
} else {
$password = '';
}
if (isset($_POST['j_verify_password'])) {
$verify = $_POST['j_verify_password'];
}
else {
} else {
$verify = '';
}
if (strcmp($password, $verify)) {
@ -26,14 +25,12 @@ if(strcmp($password, $verify)) {
if (isset($_POST['j_username'])) {
$userid = $_POST['j_username'];
}
else {
} else {
$userid = '-guest-';
}
if (isset($_POST['j_passcode'])) {
$passcode = $_POST['j_passcode'];
}
else {
} else {
$passcode = '';
}
$good = false;
@ -58,8 +55,7 @@ if(strcmp($useridlc, '-guest-')) {
if (isset($content)) {
$lines = explode('\n', $content);
$isnew = false;
}
else {
} else {
$lines = array();
$isnew = true;
}
@ -67,7 +63,9 @@ if(strcmp($useridlc, '-guest-')) {
$cnt = count($lines) - 1;
for ($i = 1; $i < $cnt; $i++) {
list($uid, $pc, $hsh) = explode('=', rtrim($lines[$i]));
if($uid == $useridlc) continue;
if ($uid == $useridlc) {
continue;
}
if (array_key_exists($uid, $pendingreg)) {
$newlines[] = $uid . '=' . $pc . '=' . $hsh;
}
@ -76,8 +74,7 @@ if(strcmp($useridlc, '-guest-')) {
$newlines[] = $useridlc . '=' . $passcode . '=' . $hash;
if ($isnew) {
insertStandaloneFile('dynmap_reg.php', implode("\n", $newlines));
}
else {
} else {
updateStandaloneFile('dynmap_reg.php', implode("\n", $newlines));
}
}
@ -85,10 +82,7 @@ if(strcmp($useridlc, '-guest-')) {
}
if ($good) {
echo "{ \"result\": \"success\" }";
}
else {
} else {
echo "{ \"result\": \"registerfailed\" }";
}
cleanupDb();
?>

View File

@ -1,7 +1,8 @@
<?php
ob_start();
require_once('MySQL_funcs.php');
include('MySQL_config.php');
require_once 'MySQL_funcs.php';
require 'MySQL_config.php';
ob_end_clean();
session_start();
@ -10,18 +11,17 @@ $content = getStandaloneFile('dynmap_config.json');
if (isset($content)) {
$config = json_decode($content, true);
$msginterval = $config['webchat-interval'];
}
else {
} else {
$msginterval = 2000;
}
if(isset($_SESSION['lastchat']))
if (isset($_SESSION['lastchat'])) {
$lastchat = $_SESSION['lastchat'];
else
} else {
$lastchat = 0;
}
if($_SERVER['REQUEST_METHOD'] == 'POST' && $lastchat < time())
{
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $lastchat < time()) {
$micro = microtime(true);
$timestamp = round($micro * 1000.0);
@ -34,8 +34,9 @@ if($_SERVER['REQUEST_METHOD'] == 'POST' && $lastchat < time())
$data->userid = $uid;
}
}
if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$data->ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
$content = getStandaloneFile('dynmap_webchat.json');
$gotold = false;
if (isset($content)) {
@ -43,33 +44,26 @@ if($_SERVER['REQUEST_METHOD'] == 'POST' && $lastchat < time())
$gotold = true;
}
if(!empty($old_messages))
{
foreach($old_messages as $message)
{
if(($timestamp - $config['updaterate'] - 10000) < $message['timestamp'])
if (!empty($old_messages)) {
foreach ($old_messages as $message) {
if (($timestamp - $config['updaterate'] - 10000) < $message['timestamp']) {
$new_messages[] = $message;
}
}
}
$new_messages[] = $data;
if ($gotold) {
updateStandaloneFile('dynmap_webchat.json', json_encode($new_messages));
}
else {
} else {
insertStandaloneFile('dynmap_webchat.json', json_encode($new_messages));
}
$_SESSION['lastchat'] = time() + $msginterval;
echo "{ \"error\" : \"none\" }";
}
elseif($_SERVER['REQUEST_METHOD'] == 'POST' && $lastchat > time())
{
} elseif ($_SERVER['REQUEST_METHOD'] == 'POST' && $lastchat > time()) {
header('HTTP/1.1 403 Forbidden');
}
else {
} else {
echo "{ \"error\" : \"none\" }";
}
cleanupDb();
?>

View File

@ -1,16 +1,16 @@
<?php
ob_start();
require_once('MySQL_funcs.php');
include('MySQL_config.php');
include('MySQL_access.php');
require_once 'MySQL_funcs.php';
require 'MySQL_config.php';
require 'MySQL_access.php';
ob_end_clean();
session_start();
if (isset($_SESSION['userid'])) {
$userid = $_SESSION['userid'];
}
else {
} else {
$userid = '-guest-';
}
@ -70,13 +70,11 @@ if (count($fparts) == 3) { // zoom_x_y
$zoom = strlen($fparts[0]);
$x = intval($fparts[1]);
$y = intval($fparts[2]);
}
else if (count($fparts) == 2) { // x_y
} elseif (count($fparts) == 2) { // x_y
$zoom = 0;
$x = intval($fparts[0]);
$y = intval($fparts[1]);
}
else {
} else {
header('Location: ../images/blank.png');
cleanupDb();
exit;
@ -90,15 +88,13 @@ $stmt->bind_result($timage, $format, $thash, $tlast);
if ($stmt->fetch()) {
if ($format == 0) {
header('Content-Type: image/png');
}
else {
} else {
header('Content-Type: image/jpeg');
}
header('ETag: \'' . $thash . '\'');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $tlast / 1000) . ' GMT');
echo $timage;
}
else {
} else {
header('Location: ../images/blank.png');
}
@ -106,4 +102,3 @@ $stmt->close();
cleanupDb();
exit;
?>

View File

@ -1,8 +1,9 @@
<?php
ob_start();
require_once('MySQL_funcs.php');
include('MySQL_config.php');
include('MySQL_access.php');
require_once 'MySQL_funcs.php';
require 'MySQL_config.php';
require 'MySQL_access.php';
ob_end_clean();
$world = $_REQUEST['world'];
@ -11,8 +12,7 @@ session_start();
if (isset($_SESSION['userid'])) {
$userid = $_SESSION['userid'];
}
else {
} else {
$userid = '-guest-';
}
@ -28,10 +28,11 @@ if(strpos($world, '/') || strpos($world, '\\')) {
return;
}
if ($loginenabled)
if ($loginenabled) {
$fname = 'updates_' . $world . '.php';
else
} else {
$fname = 'updates_' . $world . '.json';
}
$useridlc = strtolower($userid);
$uid = '[' . $useridlc . ']';
@ -61,11 +62,9 @@ if (!isset($content)) {
if (!$loginenabled) {
echo $content;
}
else if(isset($json->loginrequired) && $json->loginrequired && !$loggedin) {
} elseif (isset($json->loginrequired) && $json->loginrequired && !$loggedin) {
echo "{ \"error\": \"login-required\" }";
}
else {
} else {
$json = json_decode($content);
$json->loggedin = $loggedin;
if (isset($json->protected) && $json->protected) {
@ -83,8 +82,7 @@ else {
$p->z = 0.0;
}
}
}
else {
} else {
$pcnt = count($json->players);
for ($i = 0; $i < $pcnt; $i++) {
$p = $json->players[$i];
@ -101,7 +99,3 @@ else {
echo json_encode($json);
}
cleanupDb();
?>

View File

@ -1,9 +1,9 @@
<?php
require_once('PostgreSQL_funcs.php');
require_once 'PostgreSQL_funcs.php';
if ($loginenabled) {
$rslt = getStandaloneFile('dynmap_access.php');
var_dump($rslt);
eval($rslt);
}
?>

View File

@ -1,16 +1,16 @@
<?php
ob_start();
require_once('PostgreSQL_funcs.php');
include('PostgreSQL_config.php');
include('PostgreSQL_access.php');
require_once 'PostgreSQL_funcs.php';
require 'PostgreSQL_config.php';
require 'PostgreSQL_access.php';
ob_end_clean();
session_start();
if (isset($_SESSION['userid'])) {
$userid = $_SESSION['userid'];
}
else {
} else {
$userid = '-guest-';
}
@ -27,11 +27,9 @@ $json = json_decode($content);
if (!$loginenabled) {
echo $content;
}
else if($json->loginrequired && !$loggedin) {
} elseif ($json->loginrequired && !$loggedin) {
echo "{ \"error\": \"login-required\" }";
}
else {
} else {
$uid = '[' . strtolower($userid) . ']';
$json->loggedin = $loggedin;
$wcnt = count($json->worlds);
@ -42,12 +40,10 @@ else {
$ss = stristr($worldaccess[$w->name], $uid);
if ($ss !== false) {
$newworlds[] = $w;
}
else {
} else {
$w = null;
}
}
else {
} else {
$newworlds[] = $w;
}
if ($w != null) {
@ -60,8 +56,7 @@ else {
if ($ss !== false) {
$newmaps[] = $m;
}
}
else {
} else {
$newmaps[] = $m;
}
}
@ -73,6 +68,3 @@ else {
echo json_encode($json);
}
cleanupDb();
?>

View File

@ -1,13 +1,15 @@
<?php
function cleanupDb() {
function cleanupDb()
{
if (isset($db)) {
$db->close();
$db = NULL;
$db = null;
}
}
function abortDb($errormsg) {
function abortDb($errormsg)
{
header('HTTP/1.0 500 Error');
echo "<h1>500 Error</h1>";
echo $errormsg;
@ -15,7 +17,8 @@ function abortDb($errormsg) {
exit;
}
function initDbIfNeeded() {
function initDbIfNeeded()
{
global $db, $dbhost, $dbuserid, $dbpassword, $dbname, $dbport;
$pos = strpos($dbname, '?');
@ -34,7 +37,8 @@ function initDbIfNeeded() {
}
function getStandaloneFileByServerId($fname, $sid) {
function getStandaloneFileByServerId($fname, $sid)
{
global $db, $dbprefix;
initDbIfNeeded();
@ -45,15 +49,15 @@ function getStandaloneFileByServerId($fname, $sid) {
$content = $stmt->fetch(PDO::FETCH_BOTH);
if ($res && $content) {
$rslt = stream_get_contents($content[0]); //stupid streams...
}
else {
$rslt = NULL;
} else {
$rslt = null;
}
$stmt->closeCursor();
return $rslt;
}
function getStandaloneFile($fname) {
function getStandaloneFile($fname)
{
global $serverid;
if (!isset($serverid)) {
@ -65,7 +69,8 @@ function getStandaloneFile($fname) {
return getStandaloneFileByServerId($fname, $serverid);
}
function updateStandaloneFileByServerId($fname, $sid, $content) {
function updateStandaloneFileByServerId($fname, $sid, $content)
{
global $db, $dbprefix;
initDbIfNeeded();
@ -81,7 +86,8 @@ function updateStandaloneFileByServerId($fname, $sid, $content) {
return $res;
}
function updateStandaloneFile($fname, $content) {
function updateStandaloneFile($fname, $content)
{
global $serverid;
if (!isset($serverid)) {
@ -93,7 +99,8 @@ function updateStandaloneFile($fname, $content) {
return updateStandaloneFileByServerId($fname, $serverid, $content);
}
function insertStandaloneFileByServerId($fname, $sid, $content) {
function insertStandaloneFileByServerId($fname, $sid, $content)
{
global $db, $dbprefix;
initDbIfNeeded();
@ -103,7 +110,8 @@ function insertStandaloneFileByServerId($fname, $sid, $content) {
return $res;
}
function insertStandaloneFile($fname, $content) {
function insertStandaloneFile($fname, $content)
{
global $serverid;
if (!isset($serverid)) {
@ -114,5 +122,3 @@ function insertStandaloneFile($fname, $content) {
}
return insertStandaloneFileByServerId($fname, $serverid, $content);
}
?>

View File

@ -1,8 +1,8 @@
<?php
require_once('PostgreSQL_funcs.php');
require_once 'PostgreSQL_funcs.php';
if ($loginenabled) {
$rslt = getStandaloneFile("dynmap_login.php");
eval($rslt);
}
?>

View File

@ -1,16 +1,16 @@
<?php
ob_start();
require_once('PostgreSQL_funcs.php');
include('PostgreSQL_config.php');
include('PostgreSQL_getlogin.php');
require_once 'PostgreSQL_funcs.php';
require 'PostgreSQL_config.php';
require 'PostgreSQL_getlogin.php';
ob_end_clean();
session_start();
if (isset($_POST['j_username'])) {
$userid = $_POST['j_username'];
}
else {
} else {
$userid = '-guest-';
}
$good = false;
@ -18,8 +18,7 @@ $good = false;
if (strcmp($userid, '-guest-')) {
if (isset($_POST['j_password'])) {
$password = $_POST['j_password'];
}
else {
} else {
$password = '';
}
$ctx = hash_init('sha256');
@ -30,12 +29,10 @@ if(strcmp($userid, '-guest-')) {
if (strcasecmp($hash, $pwdhash[$useridlc]) == 0) {
$_SESSION['userid'] = $userid;
$good = true;
}
else {
} else {
$_SESSION['userid'] = '-guest-';
}
}
else {
} else {
$_SESSION['userid'] = '-guest-';
$good = true;
}
@ -49,11 +46,12 @@ if(!empty($lines)) {
$changed = false;
for ($i = 1; $i < $cnt; $i++) {
list($uid, $pc, $hsh) = explode('=', rtrim($lines[$i]));
if($uid == $useridlc) continue;
if ($uid == $useridlc) {
continue;
}
if (array_key_exists($uid, $pendingreg)) {
$newlines[] = $uid . '=' . $pc . '=' . $hsh;
}
else {
} else {
$changed = true;
}
}
@ -64,12 +62,8 @@ if(!empty($lines)) {
if ($good) {
echo "{ \"result\": \"success\" }";
}
else {
} else {
echo "{ \"result\": \"loginfailed\" }";
}
cleanupDb();
?>

View File

@ -1,16 +1,16 @@
<?php
ob_start();
require_once('PostgreSQL_funcs.php');
include('PostgreSQL_config.php');
include('PostgreSQL_access.php');
require_once 'PostgreSQL_funcs.php';
require 'PostgreSQL_config.php';
require 'PostgreSQL_access.php';
ob_end_clean();
session_start();
if (isset($_SESSION['userid'])) {
$userid = $_SESSION['userid'];
}
else {
} else {
$userid = '-guest-';
}
@ -49,14 +49,11 @@ if ($parts[0] == "faces") {
$ft = 0;
if ($parts[1] == "8x8") {
$ft = 0;
}
else if ($parts[1] == '16x16') {
} elseif ($parts[1] == '16x16') {
$ft = 1;
}
else if ($parts[1] == '32x32') {
} elseif ($parts[1] == '32x32') {
$ft = 2;
}
else if ($parts[1] == 'body') {
} elseif ($parts[1] == 'body') {
$ft = 3;
}
$pn = explode(".", $parts[2]);
@ -66,12 +63,10 @@ if ($parts[0] == "faces") {
if ($res && $timage) {
header('Content-Type: image/png');
echo stream_get_contents($timage[0]);
}
else {
} else {
header('Location: ../images/blank.png');
}
}
else { // _markers_
} else { // _markers_
$in = explode(".", $parts[1]);
$name = implode(".", array_slice($in, 0, count($in) - 1));
$ext = $in[count($in) - 1];
@ -83,20 +78,17 @@ else { // _markers_
header('Content-Type: application/json');
if ($res && $timage) {
echo stream_get_contents($timage[0]); //PDO returns arrays, even for single colums, and bytea is returned as stream.
}
else {
} else {
echo "{ }";
}
}
else {
} else {
$stmt = $db->prepare('SELECT Image from ' . $dbprefix . 'MarkerIcons WHERE IconName=?');
$res = $stmt->execute(array($name));
$timage = $stmt->fetch();
if ($res && $timage) {
header('Content-Type: image/png');
echo stream_get_contents($timage[0]);
}
else {
} else {
header('Location: ../images/blank.png');
}
}
@ -107,4 +99,3 @@ $stmt->closeCursor();
cleanupDb();
exit;
?>

View File

@ -1,7 +1,8 @@
<?php
ob_start();
require_once('PostgreSQL_funcs.php');
include('PostgreSQL_config.php');
require_once 'PostgreSQL_funcs.php';
require 'PostgreSQL_config.php';
ob_end_clean();
session_start();
@ -10,18 +11,17 @@ $content = getStandaloneFile('dynmap_config.json');
if (isset($content)) {
$config = json_decode($content, true);
$msginterval = $config['webchat-interval'];
}
else {
} else {
$msginterval = 2000;
}
if(isset($_SESSION['lastchat']))
if (isset($_SESSION['lastchat'])) {
$lastchat = $_SESSION['lastchat'];
else
} else {
$lastchat = 0;
}
if($_SERVER['REQUEST_METHOD'] == 'POST' && $lastchat < time())
{
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $lastchat < time()) {
$micro = microtime(true);
$timestamp = round($micro * 1000.0);
@ -34,8 +34,9 @@ if($_SERVER['REQUEST_METHOD'] == 'POST' && $lastchat < time())
$data->userid = $uid;
}
}
if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$data->ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
$content = getStandaloneFile('dynmap_webchat.json');
$gotold = false;
if (isset($content)) {
@ -43,33 +44,26 @@ if($_SERVER['REQUEST_METHOD'] == 'POST' && $lastchat < time())
$gotold = true;
}
if(!empty($old_messages))
{
foreach($old_messages as $message)
{
if(($timestamp - $config['updaterate'] - 10000) < $message['timestamp'])
if (!empty($old_messages)) {
foreach ($old_messages as $message) {
if (($timestamp - $config['updaterate'] - 10000) < $message['timestamp']) {
$new_messages[] = $message;
}
}
}
$new_messages[] = $data;
if ($gotold) {
updateStandaloneFile('dynmap_webchat.json', json_encode($new_messages));
}
else {
} else {
insertStandaloneFile('dynmap_webchat.json', json_encode($new_messages));
}
$_SESSION['lastchat'] = time() + $msginterval;
echo "{ \"error\" : \"none\" }";
}
elseif($_SERVER['REQUEST_METHOD'] == 'POST' && $lastchat > time())
{
} elseif ($_SERVER['REQUEST_METHOD'] == 'POST' && $lastchat > time()) {
header('HTTP/1.1 403 Forbidden');
}
else {
} else {
echo "{ \"error\" : \"none\" }";
}
cleanupDb();
?>

View File

@ -1,16 +1,16 @@
<?php
ob_start();
require_once('PostgreSQL_funcs.php');
include('PostgreSQL_config.php');
include('PostgreSQL_access.php');
require_once 'PostgreSQL_funcs.php';
require 'PostgreSQL_config.php';
require 'PostgreSQL_access.php';
ob_end_clean();
session_start();
if (isset($_SESSION['userid'])) {
$userid = $_SESSION['userid'];
}
else {
} else {
$userid = '-guest-';
}
@ -70,13 +70,11 @@ if (count($fparts) == 3) { // zoom_x_y
$zoom = strlen($fparts[0]);
$x = intval($fparts[1]);
$y = intval($fparts[2]);
}
else if (count($fparts) == 2) { // x_y
} elseif (count($fparts) == 2) { // x_y
$zoom = 0;
$x = intval($fparts[0]);
$y = intval($fparts[1]);
}
else {
} else {
header('Location: ../images/blank.png');
cleanupDb();
exit;
@ -95,15 +93,13 @@ list($timage, $format, $thash, $tlast) = $stmt->fetch();
if ($res && $timage) {
if ($format == 0) {
header('Content-Type: image/png');
}
else {
} else {
header('Content-Type: image/jpeg');
}
header('ETag: \'' . $thash . '\'');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $tlast / 1000) . ' GMT');
echo stream_get_contents($timage);
}
else {
} else {
header('Location: ../images/blank.png');
}
@ -111,4 +107,3 @@ $stmt->closeCursor();
cleanupDb();
exit;
?>

View File

@ -1,8 +1,9 @@
<?php
ob_start();
require_once('PostgreSQL_funcs.php');
include('PostgreSQL_config.php');
include('PostgreSQL_access.php');
require_once 'PostgreSQL_funcs.php';
require 'PostgreSQL_config.php';
require 'PostgreSQL_access.php';
ob_end_clean();
$world = $_REQUEST['world'];
@ -11,8 +12,7 @@ session_start();
if (isset($_SESSION['userid'])) {
$userid = $_SESSION['userid'];
}
else {
} else {
$userid = '-guest-';
}
@ -28,10 +28,11 @@ if(strpos($world, '/') || strpos($world, '\\') || empty($world)) {
return;
}
if ($loginenabled)
if ($loginenabled) {
$fname = 'updates_' . $world . '.php';
else
} else {
$fname = 'updates_' . $world . '.json';
}
$useridlc = strtolower($userid);
$uid = '[' . $useridlc . ']';
@ -61,11 +62,9 @@ if (!isset($content)) {
if (!$loginenabled) {
echo $content;
}
else if(isset($json->loginrequired) && $json->loginrequired && !$loggedin) {
} elseif (isset($json->loginrequired) && $json->loginrequired && !$loggedin) {
echo "{ \"error\": \"login-required\" }";
}
else {
} else {
$json = json_decode($content);
$json->loggedin = $loggedin;
if (isset($json->protected) && $json->protected) {
@ -83,8 +82,7 @@ else {
$p->z = 0.0;
}
}
}
else {
} else {
$pcnt = count($json->players);
for ($i = 0; $i < $pcnt; $i++) {
$p = $json->players[$i];
@ -101,7 +99,3 @@ else {
echo json_encode($json);
}
cleanupDb();
?>

View File

@ -1,14 +1,14 @@
<?php
ob_start();
include('dynmap_access.php');
require 'dynmap_access.php';
ob_end_clean();
session_start();
if (isset($_SESSION['userid'])) {
$userid = $_SESSION['userid'];
}
else {
} else {
$userid = '-guest-';
}
@ -46,14 +46,11 @@ if ($parts[0] == "faces") {
$ft = 0;
if ($parts[1] == "8x8") {
$ft = 0;
}
else if ($parts[1] == '16x16') {
} elseif ($parts[1] == '16x16') {
$ft = 1;
}
else if ($parts[1] == '32x32') {
} elseif ($parts[1] == '32x32') {
$ft = 2;
}
else if ($parts[1] == 'body') {
} elseif ($parts[1] == 'body') {
$ft = 3;
}
$pn = explode(".", $parts[2]);
@ -65,13 +62,11 @@ if ($parts[0] == "faces") {
if (isset($row[0])) {
header('Content-Type: image/png');
echo $row[0];
}
else {
} else {
header('Location: ../images/blank.png');
exit;
}
}
else { // _markers_
} else { // _markers_
$in = explode(".", $parts[1]);
$name = implode(".", array_slice($in, 0, count($in) - 1));
$ext = $in[count($in) - 1];
@ -84,12 +79,10 @@ else { // _markers_
header('Content-Type: application/json');
if (isset($row[0])) {
echo $row[0];
}
else {
} else {
echo "{ }";
}
}
else {
} else {
$stmt = $db->prepare('SELECT Image from MarkerIcons WHERE IconName=:in');
$stmt->bindValue(":in", $name, SQLITE3_TEXT);
$res = $stmt->execute();
@ -97,8 +90,7 @@ else { // _markers_
if (isset($row[0])) {
header('Content-Type: image/png');
echo $row[0];
}
else {
} else {
header('Location: ../images/blank.png');
exit;
}
@ -111,4 +103,3 @@ $db->close();
exit;
?>

View File

@ -1,14 +1,14 @@
<?php
ob_start();
include('dynmap_access.php');
require 'dynmap_access.php';
ob_end_clean();
session_start();
if (isset($_SESSION['userid'])) {
$userid = $_SESSION['userid'];
}
else {
} else {
$userid = '-guest-';
}
@ -65,13 +65,11 @@ if (count($fparts) == 3) { // zoom_x_y
$zoom = strlen($fparts[0]);
$x = intval($fparts[1]);
$y = intval($fparts[2]);
}
else if (count($fparts) == 2) { // x_y
} elseif (count($fparts) == 2) { // x_y
$zoom = 0;
$x = intval($fparts[0]);
$y = intval($fparts[1]);
}
else {
} else {
header('Location: ../images/blank.png');
exit;
}
@ -91,8 +89,7 @@ if (isset($row[1])) {
$format = $row[1];
if ($format == 0) {
header('Content-Type: image/png');
}
else {
} else {
header('Content-Type: image/jpeg');
}
header('ETag: \'' . $row[2] . '\'');
@ -104,8 +101,7 @@ if (isset($row[1])) {
}
header('Content-Length: ' . strlen($v));
echo $v;
}
else {
} else {
header('Location: ../images/blank.png');
}
@ -114,4 +110,3 @@ $stmt->close();
$db->close();
exit;
?>

View File

@ -1,14 +1,14 @@
<?php
ob_start();
include('dynmap_access.php');
require 'dynmap_access.php';
ob_end_clean();
session_start();
if (isset($_SESSION['userid'])) {
$userid = $_SESSION['userid'];
}
else {
} else {
$userid = '-guest-';
}
@ -26,8 +26,7 @@ header('Content-type: text/plain; charset=utf-8');
if ($json->loginrequired && !$loggedin) {
echo "{ \"error\": \"login-required\" }";
}
else {
} else {
$uid = '[' . strtolower($userid) . ']';
$json->loggedin = $loggedin;
$wcnt = count($json->worlds);
@ -37,12 +36,10 @@ else {
$ss = stristr($worldaccess[$w->name], $uid);
if ($ss !== false) {
$newworlds[] = $w;
}
else {
} else {
$w = null;
}
}
else {
} else {
$newworlds[] = $w;
}
if ($w != null) {
@ -55,8 +52,7 @@ else {
if ($ss !== false) {
$newmaps[] = $m;
}
}
else {
} else {
$newmaps[] = $m;
}
}
@ -67,8 +63,3 @@ else {
echo json_encode($json);
}
?>

View File

@ -1,14 +1,14 @@
<?php
ob_start();
include('dynmap_login.php');
require 'dynmap_login.php';
ob_end_clean();
session_start();
if (isset($_POST['j_username'])) {
$userid = $_POST['j_username'];
}
else {
} else {
$userid = '-guest-';
}
$good = false;
@ -16,8 +16,7 @@ $good = false;
if (strcmp($userid, '-guest-')) {
if (isset($_POST['j_password'])) {
$password = $_POST['j_password'];
}
else {
} else {
$password = '';
}
$ctx = hash_init('sha256');
@ -28,39 +27,38 @@ if(strcmp($userid, '-guest-')) {
if (strcasecmp($hash, $pwdhash[$useridlc]) == 0) {
$_SESSION['userid'] = $userid;
$good = true;
}
else {
} else {
$_SESSION['userid'] = '-guest-';
}
}
else {
} else {
$_SESSION['userid'] = '-guest-';
$good = true;
}
/* Prune pending registrations, if needed */
$newlines[] = '<?php /*';
if(is_readable('dynmap_reg.php'))
if (is_readable('dynmap_reg.php')) {
$lines = file('dynmap_reg.php');
else
} else {
$lines = array();
}
if (!empty($lines)) {
$cnt = count($lines) - 1;
$changed = false;
for ($i = 1; $i < $cnt; $i++) {
list($uid, $pc, $hsh) = explode('=', rtrim($lines[$i]));
if($uid == $useridlc) continue;
if ($uid == $useridlc) {
continue;
}
if (array_key_exists($uid, $pendingreg)) {
$newlines[] = $uid . '=' . $pc . '=' . $hsh;
}
else {
} else {
$changed = true;
}
}
if ($changed) {
if (count($newlines) < 2) { /* Nothing? */
unlink('dynmap_reg.php');
}
else {
} else {
$newlines[] = '*/ ?>';
file_put_contents('dynmap_reg.php', implode("\n", $newlines));
}
@ -69,10 +67,6 @@ if(!empty($lines)) {
if ($good) {
echo "{ \"result\": \"success\" }";
}
else {
} else {
echo "{ \"result\": \"loginfailed\" }";
}
?>

View File

@ -1,6 +1,7 @@
<?php
ob_start();
include('dynmap_access.php');
require 'dynmap_access.php';
ob_end_clean();
if (!isset($markerspath)) {
@ -14,8 +15,7 @@ session_start();
if (isset($_SESSION['userid'])) {
$userid = $_SESSION['userid'];
}
else {
} else {
$userid = '-guest-';
}
@ -48,8 +48,7 @@ $uid = '[' . strtolower($userid) . ']';
if (!is_readable($fname)) {
if (strstr($path, ".jpg") || strstr($path, ".png")) {
$fname = "../images/blank.png";
}
else {
} else {
header('HTTP/1.0 404 Not Found');
echo "<h1>404 Not Found</h1>";
echo "Not found: " . $path;
@ -57,15 +56,15 @@ if (!is_readable($fname)) {
}
}
$fp = fopen($fname, 'rb');
if (strstr($path, ".png"))
if (strstr($path, ".png")) {
header("Content-Type: image/png");
else if (strstr($path, ".jpg"))
} elseif (strstr($path, ".jpg")) {
header("Content-Type: image/jpeg");
else
} else {
header("Content-Type: application/text");
}
header("Content-Length: " . filesize($fname));
fpassthru($fp);
exit;
?>

View File

@ -1,20 +1,19 @@
<?php
ob_start();
require('dynmap_login.php');
require 'dynmap_login.php';
ob_end_clean();
session_start();
if (isset($_POST['j_password'])) {
$password = $_POST['j_password'];
}
else {
} else {
$password = '';
}
if (isset($_POST['j_verify_password'])) {
$verify = $_POST['j_verify_password'];
}
else {
} else {
$verify = '';
}
if (strcmp($password, $verify)) {
@ -24,14 +23,12 @@ if(strcmp($password, $verify)) {
if (isset($_POST['j_username'])) {
$userid = $_POST['j_username'];
}
else {
} else {
$userid = '-guest-';
}
if (isset($_POST['j_passcode'])) {
$passcode = $_POST['j_passcode'];
}
else {
} else {
$passcode = '';
}
$good = false;
@ -58,7 +55,9 @@ if(strcmp($useridlc, '-guest-')) {
$cnt = count($lines) - 1;
for ($i = 1; $i < $cnt; $i++) {
list($uid, $pc, $hsh) = explode('=', rtrim($lines[$i]));
if($uid == $useridlc) continue;
if ($uid == $useridlc) {
continue;
}
if (array_key_exists($uid, $pendingreg)) {
$newlines[] = $uid . '=' . $pc . '=' . $hsh;
}
@ -72,9 +71,6 @@ if(strcmp($useridlc, '-guest-')) {
}
if ($good) {
echo "{ \"result\": \"success\" }";
}
else {
} else {
echo "{ \"result\": \"registerfailed\" }";
}
?>

View File

@ -1,28 +1,27 @@
<?php
session_start();
if (is_readable('dynmap_config.json')) {
$config = json_decode(file_get_contents('dynmap_config.json'), true);
$msginterval = $config['webchat-interval'];
}
else if(is_readable('dynmap_config.php')) {
} elseif (is_readable('dynmap_config.php')) {
$lines = file('dynmap_config.php');
array_shift($lines);
array_pop($lines);
$config = json_decode(implode(' ', $lines), true);
$msginterval = $config['webchat-interval'];
}
else {
} else {
$msginterval = 2000;
}
if(isset($_SESSION['lastchat']))
if (isset($_SESSION['lastchat'])) {
$lastchat = $_SESSION['lastchat'];
else
} else {
$lastchat = 0;
}
if($_SERVER['REQUEST_METHOD'] == 'POST' && $lastchat < time())
{
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $lastchat < time()) {
$micro = microtime(true);
$timestamp = round($micro * 1000.0);
@ -35,29 +34,25 @@ if($_SERVER['REQUEST_METHOD'] == 'POST' && $lastchat < time())
$data->userid = $uid;
}
}
if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$data->ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
if (is_readable('dynmap_webchat.json')) {
$old_messages = json_decode(file_get_contents('dynmap_webchat.json'), true);
}
if(!empty($old_messages))
{
foreach($old_messages as $message)
{
if(($timestamp - $config['updaterate'] - 10000) < $message['timestamp'])
if (!empty($old_messages)) {
foreach ($old_messages as $message) {
if (($timestamp - $config['updaterate'] - 10000) < $message['timestamp']) {
$new_messages[] = $message;
}
}
}
$new_messages[] = $data;
file_put_contents('dynmap_webchat.json', json_encode($new_messages));
$_SESSION['lastchat'] = time() + $msginterval;
echo "{ \"error\" : \"none\" }";
}
elseif($_SERVER['REQUEST_METHOD'] == 'POST' && $lastchat > time())
{
} elseif ($_SERVER['REQUEST_METHOD'] == 'POST' && $lastchat > time()) {
header('HTTP/1.1 403 Forbidden');
}
else {
} else {
echo "{ \"error\" : \"none\" }";
}
?>

View File

@ -1,6 +1,7 @@
<?php
ob_start();
include('dynmap_access.php');
require 'dynmap_access.php';
ob_end_clean();
if (!isset($tilespath)) {
@ -14,8 +15,7 @@ session_start();
if (isset($_SESSION['userid'])) {
$userid = $_SESSION['userid'];
}
else {
} else {
$userid = '-guest-';
}
@ -64,22 +64,21 @@ if(count($parts) > 2) {
if (!is_readable($fname)) {
if (strstr($path, ".jpg") || strstr($path, ".png")) {
$fname = "../images/blank.png";
}
else {
} else {
echo "{ \"result\": \"bad-tile\" }";
exit;
}
}
$fp = fopen($fname, 'rb');
if (strstr($path, ".png"))
if (strstr($path, ".png")) {
header("Content-Type: image/png");
else if (strstr($path, ".jpg"))
} elseif (strstr($path, ".jpg")) {
header("Content-Type: image/jpeg");
else
} else {
header("Content-Type: application/text");
}
header("Content-Length: " . filesize($fname));
fpassthru($fp);
exit;
?>

View File

@ -1,7 +1,7 @@
<?php
ob_start();
include('dynmap_access.php');
require 'dynmap_access.php';
ob_end_clean();
$world = $_REQUEST['world'];
@ -10,8 +10,7 @@ session_start();
if (isset($_SESSION['userid'])) {
$userid = $_SESSION['userid'];
}
else {
} else {
$userid = '-guest-';
}
@ -27,10 +26,11 @@ if(strpos($world, '/') || strpos($world, '\\')) {
return;
}
if(isset($webpath))
if (isset($webpath)) {
$fname = $webpath . '/standalone/updates_' . $world . '.php';
else
} else {
$fname = 'updates_' . $world . '.php';
}
if (!is_readable($fname)) {
header('HTTP/1.0 404 Not Found');
@ -60,8 +60,7 @@ $json = json_decode(implode(' ',$lines));
if (isset($json->loginrequired) && $json->loginrequired && !$loggedin) {
echo "{ \"error\": \"login-required\" }";
}
else {
} else {
$json->loggedin = $loggedin;
if (isset($json->protected) && $json->protected) {
$ss = stristr($seeallmarkers, $uid);
@ -78,8 +77,7 @@ else {
$p->z = 0.0;
}
}
}
else {
} else {
$pcnt = count($json->players);
for ($i = 0; $i < $pcnt; $i++) {
$p = $json->players[$i];
@ -95,8 +93,3 @@ else {
}
echo json_encode($json);
}
?>

View File

@ -59,5 +59,3 @@ foreach ( $header_text as $header ) {
}
print $contents;
?>