Skip to content
Snippets Groups Projects
Commit 9709d3a1 authored by Sofiane Lasri's avatar Sofiane Lasri
Browse files

Relecture complète du code et correction de ce dernier.

parent 29a3398a
Branches
No related tags found
No related merge requests found
Showing
with 304 additions and 141 deletions
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<PHPCodeStyleSettings>
<option name="LOWER_CASE_BOOLEAN_CONST" value="true" />
<option name="LOWER_CASE_NULL_CONST" value="true" />
<option name="ELSE_IF_STYLE" value="COMBINE" />
<option name="VARIABLE_NAMING_STYLE" value="CAMEL_CASE" />
</PHPCodeStyleSettings>
</code_scheme>
</component>
\ No newline at end of file
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="srvMinecraft" uuid="bf92c0da-066e-4fe8-abc0-c86fa43e4d90">
<driver-ref>mysql.8</driver-ref>
<synchronize>true</synchronize>
<remarks>BDD Serveur MC</remarks>
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mysql://node.sl-projects.com:3306/srvMinecraft</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PublishConfigData" autoUpload="On explicit save action" serverName="SL-Craft" remoteFilesAllowedToDisappearOnAutoupload="false" autoUploadExternalChanges="true" showEqualInSync="true">
<component name="PublishConfigData" autoUpload="On explicit save action" serverName="SL-Craft" deleteMissingItems="true" remoteFilesAllowedToDisappearOnAutoupload="false" autoUploadExternalChanges="true" showEqualInSync="true" showNewOnTargetInSync="false">
<serverData>
<paths name="SL-Craft">
<serverdata>
......
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="PROJECT_FILES" />
<option name="description" value="" />
</component>
</project>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="FunctionNamingConventionJS" enabled="true" level="WARNING" enabled_by_default="true">
<option name="m_regex" value="[a-z][A-Za-z]*" />
<option name="m_minLength" value="4" />
<option name="m_maxLength" value="32" />
</inspection_tool>
<inspection_tool class="JSClassNamingConvention" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="LocalVariableNamingConventionJS" enabled="true" level="WARNING" enabled_by_default="true">
<option name="m_regex" value="[a-z][A-Za-z]*" />
<option name="m_minLength" value="1" />
<option name="m_maxLength" value="32" />
</inspection_tool>
<inspection_tool class="ParameterNamingConventionJS" enabled="true" level="WARNING" enabled_by_default="true">
<option name="m_regex" value="[a-z][A-Za-z]*" />
<option name="m_minLength" value="1" />
<option name="m_maxLength" value="32" />
</inspection_tool>
<inspection_tool class="PhpClassNamingConventionInspection" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="PhpConstantNamingConventionInspection" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="PhpFunctionNamingConventionInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="m_regex" value="[a-z][A-Za-z\d]*" />
<option name="m_maxLength" value="24" />
</inspection_tool>
<inspection_tool class="PhpMethodNamingConventionInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="m_maxLength" value="24" />
</inspection_tool>
<inspection_tool class="PhpPropertyNamingConventionInspection" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="PhpUndefinedVariableInspection" enabled="true" level="ERROR" enabled_by_default="true">
<option name="IGNORE_INCLUDE" value="true" />
</inspection_tool>
<inspection_tool class="PhpVariableNamingConventionInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="m_regex" value="[a-z][A-Za-z\d]*" />
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/core/classes/Item.php" dialect="GenericSQL" />
<file url="file://$PROJECT_DIR$/core/classes/Shop.php" dialect="GenericSQL" />
<file url="PROJECT" dialect="MariaDB" />
</component>
</project>
\ No newline at end of file
......@@ -2,7 +2,7 @@
<project version="4">
<component name="SshConfigs">
<configs>
<sshConfig authType="PASSWORD" host="192.168.1.16" id="97adedb8-8832-47f7-a52a-6c1ae617a01a" port="22" nameFormat="DESCRIPTIVE" username="root" useOpenSSHConfig="true" />
<sshConfig authType="PASSWORD" host="node.sl-projects.com" id="97adedb8-8832-47f7-a52a-6c1ae617a01a" port="22" nameFormat="DESCRIPTIVE" username="root" useOpenSSHConfig="true" />
</configs>
</component>
</project>
\ No newline at end of file
......@@ -3,7 +3,7 @@
<component name="WebServers">
<option name="servers">
<webServer id="24631c59-2e41-4506-ad50-24435095dc45" name="SL-Craft" url="https://dev.sl-craft.fr/">
<fileTransfer rootFolder="/home/serveur-web/sl-craft-dev/" accessType="SFTP" host="192.168.1.16" port="22" sshConfigId="97adedb8-8832-47f7-a52a-6c1ae617a01a" sshConfig="root@192.168.1.16:22 password">
<fileTransfer rootFolder="/home/serveur-web/sl-craft-dev/" accessType="SFTP" host="node.sl-projects.com" port="22" sshConfigId="97adedb8-8832-47f7-a52a-6c1ae617a01a" sshConfig="root@node.sl-projects.com:22 password">
<advancedOptions>
<advancedOptions dataProtectionLevel="Private" keepAliveTimeout="0" passiveMode="true" shareSSLContext="true" />
</advancedOptions>
......
<?php
// Informations de connexion à la base de données
$config['db']['hostName'] = 'node.sl-projects.com';
$config['db']['databaseName'] = 'srvMinecraftDev';
$config['db']['userName'] = 'srvMinecraft';
$config['db']['userPassword'] = 'YIn2hTln5iMQap1W';
<?php
class Admin{
// Charger une page admin
/**
* @throws Exception
*/
public static function loadPage($alias){
if(Admin::checkAdmin()){
if($alias[0]=="backTasks" && (!empty($_POST)||!empty($_GET))){
......@@ -11,7 +14,7 @@ public static function loadPage($alias){
}else{
// On va vérifier que la page existe
if(file_exists('pages/admin/'.$alias[0].'.php')){
if(verifyUserPermission($_SESSION['userId'], "adminPanel.".$alias[0]."Access")){
if(verifyUserPermission($_SESSION['uuid'], "slcraft.website.admin.".$alias[0]."access")){
require 'pages/admin/'.$alias[0].'.php';
}else{
Admin::show403($alias[0]);
......@@ -23,7 +26,7 @@ public static function loadPage($alias){
}
}else{
// Retrour sur la page de connexion si non conneté, ou s'il n'a pas les perms
header("Location: ".genPageLink("/login"));
header("Location: /login");
}
}
......
<?php
class BddConn {
// Attribut de la classe BddConn paramètres d'encodage
static private array $tabUTF8 = array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8");
// Attribut de la classe BddConn qui recevra l'instance PDO
static private PDO $pdoDriver;
// Getter de pdo
static public function getPdo(): PDO {
return self::$pdoDriver;
}
// Fonction de connexion
static public function connect() {
// On vérifie si l'instance PDO est déjà créée
if(!isset(self::$pdoDriver)) {
// On crée une instance de PDO
// On récupère le fichier de configuration
require 'configuration.php';
// On récupère les paramètres de connexion
$hostName = $config['db']['hostName'];
$databaseName = $config['db']['databaseName'];
$userName = $config['db']['userName'];
$userPassword = $config['db']['userPassword'];
$options = self::$tabUTF8;
try {
self::$pdoDriver = new PDO("mysql:host=$hostName;dbname=$databaseName",$userName,$userPassword,$options);
self::$pdoDriver->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $error) {
echo "Erreur de connexion : " . $error->getMessage();
}
}
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@
class Client{
// Charger une page client
public static function loadPage($alias){
// Charger le fichier de la page
if($alias[0]=="backTasks" && (!empty($_POST)||!empty($_GET))){
// Si le premier alias est backTasks, on va donc charger la page backTasks
// backTasks est un alias que l'on appel pour toutes requêtes Javascript ex: vérification de l'existence d'un email dans la bdd
......
<?php
class Connexion {
/*
// attributs de la classe Connexion paramètres de connexion à la base
static private $hostname = 'localhost';
static private $database = 'marmiuton';
static private $login = 'marmiuton';
static private $password = 's6rqTiA0hNKmcgy7';
*/
// attribut de la classe Connexion paramètres d'encodage
static private $tabUTF8 = array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8");
// attribut de la classe Connexion qui recevra l'instance PDO
static private $pdo;
// getter de pdo
static public function pdo() {return self::$pdo;}
// fonction de connexion
static public function connect() {
require "core/conf/ConfigurationGenerale.php"; // Ce fichier contient les identifiants
$h = $bddHost;
$d = $bddName;
$l = $bddUsername;
$p = $bddUserPassword;
$t = self::$tabUTF8;
try {
self::$pdo = new PDO("mysql:host=$h;dbname=$d",$l,$p,$t);
self::$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo "Erreur de connexion !";
}
}
}
\ No newline at end of file
<?php
class Item{
private $label;
private $price;
private $css;
private $type;
private $id;
private $displayName;
private $enchants;
private string $label;
private string $cssClassName;
private $representation;
private string $type;
private string $displayName;
private array $enchants;
public function __construct($item){
if(is_array($item)){
$this->id = strtolower($item['type']);
/**
* @throws Exception
*/
public function __construct($itemInfos){
if(is_array($itemInfos)){
// On va vérifier qu'il s'agit bien d'un tableau contenant les infos d'un item
if(!isset($itemInfos["type"])){
throw new Exception("Ce tableau n'est pas un item");
}
$this->type = strtolower($itemInfos['type']);
if(isset($item['meta'])){
if(isset($item['meta']['display-name'])){
$displayNameJson = json_decode($item['meta']['display-name'], true);
// L'item peut avoir des caractéristiques particulières, comme des enchantements par exemple
if(isset($itemInfos['meta'])){
if(isset($itemInfos['meta']['display-name'])){
$displayNameJson = json_decode($itemInfos['meta']['display-name'], true);
$this->displayName = $displayNameJson['text'];
}else{
$this->displayName = "";
}
if(isset($item['meta']['enchants'])){
$this->enchants = $item['meta']['enchants'];
}
if(isset($itemInfos['meta']['enchants'])){
$this->enchants = $itemInfos['meta']['enchants'];
}else{
$this->enchants = [];
}
}else{
$this->id=$item;
$this->displayName = "";
$this->enchants = [];
}
$query = Connexion::pdo()->prepare("SELECT * FROM site_itemsAssoc WHERE name=?");
$query->execute(array($this->id));
}else{
// Ici on a un nom d'item
$this->type=$itemInfos;
$this->displayName = "";
$this->enchants = [];
}
// On va chercher l'item dans la table d'association des items afin de récupérer les infos
$query = BddConn::getPdo()->prepare("SELECT * FROM site_itemsAssoc WHERE name=?");
$query->execute(array($this->type));
$result= $query->fetch(PDO::FETCH_ASSOC);
$this->label = $result['label'];
$this->css = $result['css'];
$this->cssClassName = $result['css'];
$this->representation = $result['representation'];
}
public function getLabel(){
public function getLabel(): string
{
return $this->label;
}
public function getPrice(){
return $this->price;
}
public function getCss(){
return $this->css;
public function getCssClassName(): string
{
return $this->cssClassName;
}
public function getType(){
public function getType(): string
{
return $this->type;
}
public function getId(){
return $this->id;
}
public function getRepresentation(){
public function getRepresentation(): array
{
$return["texture"] = array();
if(file_exists("data/images/textures/block/".$this->id.".png")){
// On va regarder si on a une représentation pour cet item
// Ça sera plus rapide avec la représentation de sauvegardée
if(isset($this->representation) && !empty($this->representation) && isset($this->representation["type"])){
if($this->representation["type"] == "block"){
$return["type"] = "block";
$return["texture"][0] = "data/images/textures/block/".$this->type.".png";
if($this->representation["hasTop"]){
$return["texture"][1] = "data/images/textures/block/".$this->type."_top.png";
}else{
$return["texture"][1] = $return["texture"][0];
}
}else if($this->representation["type"] == "block_side"){
$return["type"] = "block";
$return["texture"][0] = "data/images/textures/block/".$this->id.".png";
if(file_exists("data/images/textures/block/".$this->id."_top.png")){
$return["texture"][1] = "data/images/textures/block/".$this->id."_top.png";
$return["texture"][0] = "data/images/textures/block/".$this->type."_side.png";
if($this->representation["hasTop"]){
$return["texture"][1] = "data/images/textures/block/".$this->type."_top.png";
}else{
$return["texture"][1] = $return["texture"][0];
}
}else if($this->representation["type"] == "item") {
$return["type"] = "item";
$return["texture"][0] = "data/images/textures/item/" . $this->type . ".png";
}else{
$return["type"] = "unknown";
$return["texture"][0] = "data/images/textures/missing.png";
}
}elseif(file_exists("data/images/textures/block/".$this->id."_side.png")){
}else{
// Sera plus long à éxecuter vu qu'on va tout vérifier
$representation = array();
if(file_exists("data/images/textures/block/".$this->type.".png")){
$return["type"] = "block";
$return["texture"][0] = "data/images/textures/block/".$this->id."_side.png";
if(file_exists("data/images/textures/block/".$this->id."_top.png")){
$return["texture"][1] = "data/images/textures/block/".$this->id."_top.png";
$representation["type"] = "block";
$return["texture"][0] = "data/images/textures/block/".$this->type.".png";
if(file_exists("data/images/textures/block/".$this->type."_top.png")){
$return["texture"][1] = "data/images/textures/block/".$this->type."_top.png";
$representation["hasTop"] = true;
}else{
$representation["hasTop"] = false;
}
}elseif(file_exists("data/images/textures/block/".$this->type."_side.png")){
$return["type"] = "block_side";
$representation["type"] = "block";
$return["texture"][0] = "data/images/textures/block/".$this->type."_side.png";
if(file_exists("data/images/textures/block/".$this->type."_top.png")){
$return["texture"][1] = "data/images/textures/block/".$this->type."_top.png";
$representation["hasTop"] = true;
}else{
$representation["hasTop"] = false;
}
}elseif(file_exists("data/images/textures/item/".$this->id.".png")){
}elseif(file_exists("data/images/textures/item/".$this->type.".png")){
$return["type"] = "item";
$return["texture"][0] = "data/images/textures/item/".$this->id.".png";
$representation["type"] = "item";
$return["texture"][0] = "data/images/textures/item/".$this->type.".png";
}else{
$return["type"] = "unknown";
$representation["type"] = "unknown";
$return["texture"][0] = "data/images/textures/missing.png";
}
if(!isset($return["texture"][1])){
$return["texture"][1] = $return["texture"][0];
}
// On va mettre à jour la représentation de l'item
$query = BddConn::getPdo()->prepare("UPDATE site_itemsAssoc SET representation=? WHERE name=?");
$query->execute(array(json_encode($representation), $this->type));
}
return $return;
}
public function getDisplayName(){
public function getDisplayName(): string
{
return $this->displayName;
}
public function getEnchants(){
public function getEnchants(): array
{
return $this->enchants;
}
}
\ No newline at end of file
<?php
class Seller{
private $uuid;
private $username;
private $skin;
private string $uuid;
private string $username;
private string $skin;
public function __construct($uuid){
$this->uuid = $uuid;
$json = file_get_contents('https://sessionserver.mojang.com/session/minecraft/profile/'.$uuid);
$profile = json_decode($json, true);
$this->username = $profile['name'];
$jsonProfileInfos = file_get_contents('https://sessionserver.mojang.com/session/minecraft/profile/'.$uuid);
$profileInfos = json_decode($jsonProfileInfos, true);
$this->username = $profileInfos['name'];
$properties = json_decode(base64_decode($profile['properties'][0]['value']), true);
$properties = json_decode(base64_decode($profileInfos['properties'][0]['value']), true);
$this->skin = $properties['textures']['SKIN']['url'];
}
public function getUuid(){
public function getUuid(): string
{
return $this->uuid;
}
public function getUsername(){
public function getUsername(): string
{
return $this->username;
}
public function getSkin(){
public function getSkin(): string
{
return $this->skin;
}
}
\ No newline at end of file
<?php
class Shop{
public static function getAllProducts(){
$itemsConfig = Connexion::pdo()->query("SELECT itemConfig FROM qs_shops")->fetchAll(PDO::FETCH_ASSOC);
public static function getAllProducts(): array
{
// On récupère tous les items des magasins
$itemsConfigsYaml = BddConn::getPdo()->query("SELECT itemConfig FROM qs_shops")->fetchAll(PDO::FETCH_ASSOC);
/*
item:
......@@ -10,35 +12,49 @@ public static function getAllProducts(){
type: WHEAT
*/
$return = array();
foreach($itemsConfig as $itemConfig){
$item = yaml_parse($itemConfig['itemConfig']);
// On va faire la liste de tous les items
$items = array();
foreach($itemsConfigsYaml as $itemConfigYaml){
// On parse le YAML
$itemConfig = yaml_parse($itemConfigYaml['itemConfig']);
$itemAleadyEntered = false;
foreach($return as $checkItem){
if(strtolower($item['item']['type']) == $checkItem->getId()){
$itemAleadyEntered = true;
$alreadyInList = false;
foreach($items as $checkItem){
if(strtolower($itemConfig['item']['type']) == $checkItem->getType()){
$alreadyInList = true;
break; // On sort de la boucle
}
}
if(!$itemAleadyEntered){
$return[] = new Item($item['item']['type']);
if(!$alreadyInList){
$items[] = new Item($itemConfig['item']['type']);
}
}
return $return;
return $items;
}
public static function getShops($search=null){
if(is_array($search)){
}else{
/**
* @throws Exception
*/
public static function getShops($search=array()): array
{
if(is_array($search)){
if(empty($search)){
// On récupère les shops
$shops = Connexion::pdo()->query("SELECT * FROM qs_external_cache NATURAL JOIN qs_shops")->fetchAll(PDO::FETCH_ASSOC);
for($i=0;$i<count($shops);$i++){
$item = yaml_parse($shops[$i]['itemConfig']);
$shops[$i]['item'] = new Item($item['item']);
$owner = json_decode($shops[$i]['owner'], true);
$shops[$i]['seller'] = new Seller($owner["owner"]);
$shops = BddConn::getPdo()->query("SELECT * FROM qs_external_cache NATURAL JOIN qs_shops")->fetchAll(PDO::FETCH_ASSOC);
for($index=0;$index<count($shops);$index++){
$itemConfig = yaml_parse($shops[$index]['itemConfig']);
$shops[$index]['item'] = new Item($itemConfig['item']);
$owner = json_decode($shops[$index]['owner'], true);
$shops[$index]['seller'] = new Seller($owner["owner"]);
}
return $shops;
}else{
// TODO: faire une recherche par critère
return array();
}
}else{
// On lance une exception car on souhaite avoir un array
throw new Exception("Search doit être un array");
}
}
}
\ No newline at end of file
<?php
// attributs de la classe Connexion paramètres de connexion à la base
$bddHost = 'node.sl-projects.com';
$bddName = 'srvMinecraft';
$bddUsername = 'srvMinecraft';
$bddUserPassword = 'YIn2hTln5iMQap1W';
// Cette variable défini le mode de reconnaissance des url
// Sur le serveur de l'IUT, on ne peut pas utiliser les alias de l'url pour détecter les pages, vu que nous ne sommes pas sur la racine du domaine
// Il faut donc fonctionner avec les paramètres de l'url.
\ No newline at end of file
......@@ -2,7 +2,7 @@
if(isset($_GET['saveSettings']) && !empty($_POST)){
foreach($_POST as $index => $value){
if(!empty($index)){
$query = Connexion::pdo()->prepare('UPDATE `m_siteSetting` SET `value` = ? WHERE `name` = ?');
$query = BddConn::getPdo()->prepare('UPDATE `m_siteSetting` SET `value` = ? WHERE `name` = ?');
$query->execute([$value, $index]);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment