Index: src/index.php
===================================================================
--- src/index.php	(revision 91f444e35f48e6479ee4261ccd8f66ba20dc4073)
+++ src/index.php	(revision e29373cc0849216e12923fe53b380956a3e625ad)
@@ -1,3 +1,9 @@
 <?php
+
+// declare(strict_types=1);
+
+use hu\jmk\rtwi\Request;
+
+require_once("hu/jmk/AutoLoader.php");
 
 function myrealpath( $path, $home, $cwd ) {
@@ -544,8 +550,7 @@
 }
 
-error_reporting( E_ALL );
-error_reporting( E_ALL ^ E_NOTICE );
-
-set_time_limit( 10 );
+error_reporting(E_ALL^E_NOTICE);
+
+set_time_limit(10);
 
 // setting default
@@ -557,13 +562,12 @@
 
 // set language from cookie if exists
-if ( !isset( $_SESSION["rtwi_language"] ) ) {
+if (!isset($_SESSION["rtwi_language"])) {
 	$_SESSION["rtwi_language"] = isset( $_COOKIE["rtwi_language"] ) ? $_COOKIE["rtwi_language"] : $config["lang"];
 }
 
-
 // including neccessary files
-require_once( "includes/classes/xmlrpc_handler.inc.php" );
-require_once( "includes/messages.{$_SESSION["rtwi_language"]}.inc.php" );
-require_once( "includes/tools/functions.time.inc.php" );
+require_once("includes/classes/xmlrpc_handler.inc.php");
+require_once("includes/messages.{$_SESSION["rtwi_language"]}.inc.php");
+require_once("includes/tools/functions.time.inc.php");
 
 $callnum = 0;
@@ -583,72 +587,5 @@
 );
 
-// getting request values
-if ( isset( $_REQUEST["format"] ) ) {
-	$format = $_REQUEST["format"];
-} else {
-	$format = "";
-}
-
-if ( isset( $_REQUEST["mod"] ) ) {
-	$mod = $_REQUEST["mod"];
-} else {
-	$mod = "";
-}
-
-if ( isset( $_REQUEST["hash"] ) ) {
-	$hash = $_REQUEST["hash"];
-} else {
-	$hash = "";
-}
-
-if ( isset( $_REQUEST["page"] ) ) {
-	switch ( $_REQUEST["page"] ) {
-		case "transfers" : {
-			$page = "transfers";
-			break;
-		}
-		case "chunks" : {
-			$page = "chunks";
-			break;
-		}
-		case "trackers" : {
-			$page = "trackers";
-			break;
-		}
-		case "files" : {
-			$page = "files";
-			break;
-		}
-		case "peers" : {
-			$page = "peers";
-			break;
-		}
-		default : {
-			$page = "info";
-			break;
-		}
-	}
-} else {
-	$page = "info";
-}
-
-if ( isset( $_REQUEST["id"] ) ) {
-	$id = $_REQUEST["id"];
-	settype( $id, "int" );
-} else {
-	$id = -1;
-}
-
-if ( isset( $_REQUEST["path"] ) ) {
-	$path = $_REQUEST["path"];
-} else {
-	$path = "";
-}
-
-if ( isset( $_REQUEST["ajax"] ) && $_REQUEST["ajax"] === "true" && $config["ajax"] === "1" ) {
-	$ajax = true;
-} else {
-	$ajax = false;
-}
+$request = new Request($_REQUEST);
 
 // checking if user is logged in
@@ -684,5 +621,5 @@
 } else {
 	// show login page if not logged in
-	$mod = "login";
+	$request->setMod(Request::MOD_LOGIN);
 }
 
@@ -693,8 +630,8 @@
 $root = $xml->appendChild( $xml->createElement( "root" ) );
 
-$root->appendChild( $xml->createElement( "mod", $mod ) );
-$root->appendChild( $xml->createElement( "hash", $hash ) );
-$root->appendChild( $xml->createElement( "page", $page ) );
-$root->appendChild( $xml->createElement( "id", $id ) );
+$root->appendChild($xml->createElement("mod", $request->getMod()));
+$root->appendChild($xml->createElement("hash", $request->hasHash() ? $request->getHash() : ""));
+$root->appendChild($xml->createElement("page", $request->getPage()));
+$root->appendChild( $xml->createElement( "id", $request->getId() ) );
 $root->appendChild( $xml->createElement( "burl", $config["base"] ) );
 $root->appendChild( $xml->createElement( "url", $config["index"] ) );
@@ -723,12 +660,12 @@
 
 // deciding what to do
-if ( $ajax === true ) {
+if ($request->isAjax() && $config["ajax"] === 1) {
 	$layout_file = "layout.ajax.index.xsl";
 } else {
 	$layout_file = "layout.main.index.xsl";
 }
-if ( ( isset( $xmlrpc ) && ( $xmlrpc->geterrorsnum() == 0 ) ) || ( $mod == "login" ) ) {
-	switch ( $mod ) {
-		case "login" : { // login
+if ( ( isset( $xmlrpc ) && ( $xmlrpc->geterrorsnum() == 0 ) ) || ( $request->getMod() == Request::MOD_LOGIN ) ) {
+	switch ($request->getMod()) {
+		case Request::MOD_LOGIN : { // login
 			// adding language select
 			if ( $config["language"] ) {
@@ -740,5 +677,5 @@
 			break;
 		}
-		case "serverinfo" : { // server info
+		case Request::MOD_SERVERINFO : { // server info
 			// creating torrents node
 			$tnode = $root->appendChild( $xml->createElement( "torrents" ) );
@@ -807,5 +744,5 @@
 			break;
 		}
-		case "addtorrent" : { // add a new torrent
+		case Request::MOD_ADDTORRENT : { // add a new torrent
 			// getting download directory
 			if ( !$xmlrpc->setmrequest( array( "directory.default", "system.cwd" ) ) || !$xmlrpc->call() || !$xmlrpc->parse() ) {
@@ -860,5 +797,5 @@
 			break;
 		}
-		case "torrent" : { // torrent
+		case Request::MOD_TORRENT : { // torrent
 			// creating torrents node
 			$tnode = $root->appendChild( $xml->createElement( "torrents" ) );
@@ -880,5 +817,5 @@
 
 			// retrieving download info
-			if ( !$xmlrpc->setrequest( "d.multicall2", array_merge( array( $hash, $_SESSION["rtwi_view"] ), $xmlrpc_methods["d"] ) ) || !$xmlrpc->call() || !$xmlrpc->parse() ) {
+			if ( !$xmlrpc->setrequest( "d.multicall2", array_merge( array( $request->getHash(), $_SESSION["rtwi_view"] ), $xmlrpc_methods["d"] ) ) || !$xmlrpc->call() || !$xmlrpc->parse() ) {
 				$_SESSION["rtwi_err"] = $xmlrpc->geterrors();
 				break;
@@ -899,5 +836,5 @@
 
 				// if hash matches save the download data
-				if ( $d_responses[$i]["d.hash="] == $hash ) {
+				if ( $d_responses[$i]["d.hash="] == $request->getHash() ) {
 					$torrent = $d_responses[$i];
 				}
@@ -910,5 +847,5 @@
 				prepare_downloadlist_responses( $torrent, $message, $config["home_path"], $si_responses["system.cwd"] );
 				// decide what to do
-				switch ( $page ) {
+				switch ($request->getPage()) {
 					case "peers" : { // peer list page
 						// create peer nodes
@@ -1068,6 +1005,6 @@
 			$node->setAttribute( "value", $si_responses["upload_rate_value"] );
 
-			// decide what to send back to the browser
-			if ( $ajax === true ) {
+      // decide what to send back to the browser
+			if ($request->isAjax() && $config["ajax"] === 1) {
 				$layout_file = "layout.ajax.index.xsl";
 			} else {
@@ -1077,5 +1014,5 @@
 			break;
 		}
-		case "getfile" : { // download a file
+		case Request::MOD_GETFILE : { // download a file
 			// checking if users are allowed to download
 			if ( !$config["download"] ) {
@@ -1083,5 +1020,5 @@
 				header( "location: {$url["index"]}" );
 				exit;
-			} elseif ( $id < 0 ) { // checking if the file id is given and is valid
+			} elseif (!$request->hasId()) { // checking if the file id is given and is valid
 				$_SESSION["rtwi_err"] = "noidfound";
 				header( "location: {$url["index"]}" );
@@ -1103,7 +1040,7 @@
 
 				// checking if we've found the torrent
-				if ( in_array( $hash, $torrents ) ) {
+				if ( in_array( $request->getHash(), $torrents ) ) {
 					// getting the filename
-					if ( !$xmlrpc->setmrequest( $xmlrpc_methods["g"], array( "${hash}:f${id}" ) ) || !$xmlrpc->call() || !$xmlrpc->parse() ) {
+					if ( !$xmlrpc->setmrequest( $xmlrpc_methods["g"], array( "${hash}:f" . $request->getId() ) ) || !$xmlrpc->call() || !$xmlrpc->parse() ) {
 						$_SESSION["rtwi_err"] = $xmlrpc->geterrors();
 						break;
@@ -1194,7 +1131,7 @@
 	}
 } elseif ( isset( $xmlrpc ) ) {
-	$_SESSION["rtwi_err"] = $xmlrpc->geterrors();
-
-	if ( $ajax === true ) {
+  $_SESSION["rtwi_err"] = $xmlrpc->geterrors();
+
+	if ($request->isAjax() && $config["ajax"] === 1) {
 		$layout_file = "layout.ajax.index.xsl";
 	} else {
@@ -1206,6 +1143,5 @@
 		addlanguages( $xml, $root, $root, $languages );
 	}
-
-	if ( $ajax === true ) {
+	if ($request->isAjax() && $config["ajax"] === 1) {
 		$layout_file = "layout.ajax.index.xsl";
 	} else {
@@ -1234,14 +1170,14 @@
 
 // setting referrer
-if ( $ajax === false && $mod != "getfile" ) {
+if ((!$request->isAjax() || $config["ajax"] !== 1) && $request->getMod() != Request::MOD_GETFILE) {
 	$_SESSION["rtwi_lastpage"] = $_SERVER["REQUEST_URI"];
 }
 
 // displaying the page
-if ( $mod != "getfile" ) {
-	if ( $format == "xml" ) {
+if ($request->getMod() != Request::MOD_GETFILE) {
+	if ($request->getFormat() == Request::FORMAT_XML) {
 		print $xml->SaveXML();
 	} else {
-		require_once( "includes/classes/xsl_handler.inc.php" );
+    require_once( "includes/classes/xsl_handler.inc.php" );
 		$page = new page_handler( $config["site_theme"], $layout_file, $xml );
 		$page->parse();
Index: src/input.php
===================================================================
--- src/input.php	(revision 91f444e35f48e6479ee4261ccd8f66ba20dc4073)
+++ src/input.php	(revision e29373cc0849216e12923fe53b380956a3e625ad)
@@ -1,3 +1,5 @@
 <?php
+
+// declare(strict_types=1);
 
 function myrealpath( $path, $home, $cwd ) {
@@ -15,8 +17,7 @@
 }
 
-error_reporting( E_ALL );
-error_reporting( E_ALL ^ E_NOTICE );
-
-set_time_limit( 10 );
+error_reporting(E_ALL^E_NOTICE);
+
+set_time_limit(10);
 
 session_start();
