Skip to content

Commit

Permalink
v1.0 - PHPDocumentor comments
Browse files Browse the repository at this point in the history
+ Added PHPDocumentor styled comments to all core classes.
+ Added method for checking whether or not a SteamUser is VIP.
* Users::Get() has been deprecated, and no longer queries the database.
* Users::Register() no longer dies upon failure to register, instead returning false.
  • Loading branch information
r59q committed Nov 18, 2018
1 parent e9a27d0 commit 97f6a16
Show file tree
Hide file tree
Showing 10 changed files with 654 additions and 261 deletions.
540 changes: 302 additions & 238 deletions .idea/workspace.xml

Large diffs are not rendered by default.

41 changes: 38 additions & 3 deletions classes/Database.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
<?php
require_once 'Settings.php';

/**
* Class Database handles SQL queries and the database connection.
*
* Upon running the constructor, settings from settings.json will be
* read and used to establish a connection to the database.
* Please ensure the settings are correct in settings.json.
* This condenses regular SQL queries into a single static
* function called Query( $sql )
*
* @author Andreas M. Henriksen <AndreasHenriksen@yahoo.dk>
*/
class Database {

public static $connection;
public static $settings;
public static $steamKey;
public static
$connection,
$settings,
$steamKey;

/**
* Grabs the settings from settings.json and establishes a connection to the database.
*/
function __construct()
{
global $steamauth;
Expand All @@ -17,6 +32,16 @@ function __construct()
self::$connection = $this->Connection();
}

/**
* Queries the database returning the result.
*
* Uses the previously established connection to query the database.
* Note that you must have run the constructor, in order for
* this to work.
*
* @param string $query - The SQL statement.
* @return mysqli_result
*/
public static function Query($query) {
$result = mysqli_query(self::$connection,$query);
if (!$result) {
Expand All @@ -25,11 +50,21 @@ public static function Query($query) {
return $result;
}

/**
* Returns the database part of the settings in settings.json as array.
*
* @return array - Database settings.
*/
function Settings(){
// Return settings from 'Settings' class
return Settings::GetSettings()['database'];
}

/**
* Establishes a MySQL connection.
*
* @return mysqli - MySQL connection.
*/
function Connection() {
// Connect with settings fetched in the constructor
return new mysqli(
Expand Down
21 changes: 21 additions & 0 deletions classes/Modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,22 @@
* Time: 14:01
*/

/**
* Class 'Modules' handles snippets of HTML.
*
* Handles loading of HTML snippets that are located in
* '/modules/'. Using Modules::Load(string $module)
* you can load 'index.php' file in '/modules/$module/'
*
* @author Andreas M. Henriksen <AndreasHenriksen@yahoo.dk>
*/
class Modules {

/**
* Includes file 'index.php' in '/modules/$module/'
*
* @param string $module - The name of the module.
*/
public static function Load($module) {
if (self::Exists($module)) {
include "modules/$module/index.php";
Expand All @@ -15,6 +30,12 @@ public static function Load($module) {
}
}

/**
* Checks whether or not the module specified exists in '/modules/'
*
* @param string $module - The name of the module.
* @return bool - Returns true if the module in question exists.
*/
public static function Exists($module) {
if (file_exists("modules/$module/index.php")) {
return true;
Expand Down
35 changes: 32 additions & 3 deletions classes/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,24 @@
* Time: 12:25
*/


/**
* Class 'Page' loads the correct HTML code from '/templates/'
*
* Upon constructing it will load decide what page we are on using
* $_GET['p'] and loads the appropriate template for said page.
*
* @author Andreas M. Henriksen <AndreasHenriksen>
*/
class Page {

private $pageString;

/**
* Constructs the page, loading the template.
*
* First it grabs the page string using $_GET['p']. Then
* loads the template.
*/
function __construct()
{
// Set internal variables
Expand All @@ -20,6 +33,9 @@ function __construct()
$this->LoadTemplate();
}

/**
* Includes the template from '/templates/'
*/
function LoadTemplate() {
$loc = $this->TemplateLocation();
if (file_exists($loc)) {
Expand All @@ -29,21 +45,34 @@ function LoadTemplate() {
}
}

/**
* The location of the template for this page.
*
* @return string - Returns the location of the template.
*/
function TemplateLocation() {
$str = $this->pageString;
return "templates/$str.php";
}

/**
* Uses $_GET['p'] to grab the page index. If none are set return 'home'.
*
* @return string - The page index.
*/
function SetPageString() {
if (!isset($_GET['p'])) {
return "home";
}
return $_GET['p'];
}

/**
* Returns the current page index set by the constructor.
*
* @return string - The page index.
*/
public function PageString() {
return $this->pageString;
}


}
18 changes: 17 additions & 1 deletion classes/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@
* Time: 11:23
*/


/**
* Class 'Settings' decodes json file 'settings.json'.
*
* @author Andreas M. Henriksen <AndreasHenriksen@yahoo.dk>
*/
class Settings {

/**
* Loads settings from 'settings.json' and decodes it.
*
* @return array - Settings
*/
public static function GetSettings() {
// Read JSON file
$json = file_get_contents('settings.json');
Expand All @@ -20,6 +29,13 @@ public static function GetSettings() {
return $json_data;
}

/**
* Loads settings from 'settings.json' and decodes it.
*
* Also takes the directory location into account.
*
* @return array - Settings
*/
public static function GetSettingsDir($dir) {
// Read JSON file
$json = file_get_contents($dir.'settings.json');
Expand Down
50 changes: 43 additions & 7 deletions classes/SteamUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
*/

/**
* Class SteamUser
* Class 'SteamUser' contains Steam data on an individual user.
*
* By constructing this class with a 64-bit Steam Community ID,
* a range of variables are set. These are set by the Steam API.
* see 'https://developer.valvesoftware.com/wiki/Steam_Web_API#GetPlayerSummaries_.28v0002.29'
* It also checks whether or not this user has been registered
* in the local database.
*
* @author Andreas M. Henriksen <AndreasHenriksen@yahoo.dk>
*/
class SteamUser {

Expand All @@ -29,10 +37,21 @@ class SteamUser {
public $profileState;
public $registered;

/**
* Constructs a SteamUser object.
*
* Using the Steam Community ID to grab data from Steam API
* and sets them internally for ease of use. Also queries
* the database to check whether or not the user has been
* registered on the website. The user does not have to be
* registered in local database for this to work.
*
* @param string $steamid_64 - The 64-bit Steam Community ID. MUST BE STRING!
*/
function __construct($steamid_64) {
$this->steamid64 = $steamid_64;
$this->steamid = Users::SteamID($steamid_64);
$this->steamid32 = Users::SteamID32($this->steamid);
$this->steamid64 = $steamid_64;
$this->steamid = Users::SteamID($steamid_64);
$this->steamid32 = Users::SteamID32($this->steamid);

$steamApiData = Users::GrabSteamData($steamid_64);

Expand All @@ -58,12 +77,21 @@ function __construct($steamid_64) {

}

/**
* Registers this user to our own database of users.
*/
public function Register() {
if (!Users::Registered($this->steamid64)) {
Users::Register($this->steamid64);
}
}

/**
* Check whether or not this SteamUser has donated and, if so, how much.
*
* @return float|bool - Returns float if the user has donated before.
* float represents how much user has donated. Returns false if none.
*/
public function IsDonor() {

// Set SQL statement
Expand All @@ -88,7 +116,15 @@ public function IsDonor() {
return false;
}




/**
* Check whether or not this user has VIP status.
*
* @return bool - Returns true if this user has VIP status.
*/
public function IsVIP() {
if (Users::IsVIP($this->steamid64)){
return true;
}
return false;
}
}
Loading

0 comments on commit 97f6a16

Please sign in to comment.