il n'y a pas eu de leak de mot de passe ici ;)

This commit is contained in:
2019-01-28 16:25:30 +01:00
parent e2f71dd59b
commit 7a8dcd2da1
30 changed files with 254 additions and 285 deletions

20
project/assets/php/functions.php Normal file → Executable file
View File

@ -9,3 +9,23 @@ function endsWith($haystack, $needle) {
return (substr($haystack, -$length) === $needle);
}
function connect() {
$host = "127.0.0.1";
$db = "blog";
$user = "username";
$pass = "motdepasse";
$charset="utf8mb4";
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
try {
$pdo = new PDO($dsn, $user, $pass);
} catch (\PDOException $e) {
throw new \PDOException($e->getMessage(), (int)$e->getCode());
}
return $pdo;
}
function getBDD() {
}

View File

@ -2,13 +2,13 @@
require_once "functions.php";
ini_set('display_errors', 'On');
//renvoie vers le fichier css si il est demand<6E>
//renvoie vers le fichier css si il est demand<6E>
if(endsWith($_GET["page"], ".css")) {
echo file_get_contents("../css/style.css");
die;
}
//renvoie vers le fichier js si demand<6E>
//renvoie vers le fichier js si demand<6E>
if(endsWith($_GET["page"], ".js")) {
echo file_get_contents("../js/script.js");
die;
@ -22,10 +22,10 @@ if($_GET["page"] != "" && !endsWith($_GET["page"], "/") && sizeof($_GET) <= 1) {
die;
}
//enleve les / du d<>but & fin
//enleve les / du d<>but & fin
$_GET['page'] = trim($_GET['page'], '/');
// si taille sup<75>rieur <20> 1 $_getpost = element
// si taille sup<75>rieur <20> 1 $_getpost = element
if(sizeof(explode("/", $_GET["page"])) > 1) {
$_GET["post"] = explode("/", $_GET["page"])[1];
}
@ -42,13 +42,14 @@ if(strlen($_GET['page']) > 1) {
//page de test pour des functions
// A ENLEVER LORS DES COMMITS DE FIN
if($_GET["page"] == "test") {
// var_dump($_GET);
if($_GET["page"] == "/test/") {
include_once "test.php";
die;
}
/**
* D<>marrage du routage du contenu
* D<>marrage du routage du contenu
*/
include_once "router.php";
@ -60,7 +61,4 @@ include_once "pages.php";
include_once "tagHandler.php";
$pokemon = loadTags($router->search($_GET["page"])(), false);
//TODO trouver pourquoi il y a un pb avec l'UTF-8
//(actuellement forcer des compiler en "Windows 1252")
$pokemon = htmlspecialchars_decode($pokemon, ENT_HTML5);
echo $pokemon;

2
project/assets/php/pages.php Normal file → Executable file
View File

@ -1,7 +1,7 @@
<?php
include_once "router.php";
//recup<EFBFBD>ration du router
//recupération du router
$router = Router::getRouter();
//page d'accueil

4
project/assets/php/router.php Normal file → Executable file
View File

@ -12,11 +12,11 @@ class Router {
//definit le router
public function __construct() {
//TODO faire que si un router existe daj<EFBFBD> retourner le routeur existant
//TODO faire que si un router existe déjà retourner le routeur existant
Router::$router = $this;
}
//fonction static pour recuperer un router d<EFBFBD>j<EFBFBD> cr<EFBFBD><EFBFBD>
//fonction static pour recuperer un router déjà crée
public static function getRouter() {
return Router::$router;
}

77
project/assets/php/tagHandler.php Normal file → Executable file
View File

@ -35,7 +35,7 @@ class Bold extends Tag {
public function render() {
//recuperation de la balise de base (<tag type="bold">pouet</tag>)
$pok = $this->getDOM();
//recuperation du document (necessaire a la cr<63>ation de balises
//recuperation du document (necessaire a la cr<63>ation de balises
$doc = $this->getDoc();
//creation de la balise "span"
$res = $doc->createElement("span");
@ -150,6 +150,7 @@ class Includes extends Tag {
// var_dump($attr);
// var_dump(file_get_contents("../html/includes/".$attr.".html"));
$p = file_get_contents("../html/includes/".$attr.".html");
// var_dump($p);
appendHTML($el->parentNode, $p);
$el->setAttribute("style", $el->getAttribute("style"));
@ -171,7 +172,10 @@ class Svg extends Tag {
}
/**
* input <tag type="loop" for="(table)" limit="(nombre-max g<>n<EFBFBD>r<EFBFBD>)" />
* input
* <tag type="loop" for="(table)" limit="(nombre-max g<>n<EFBFBD>r<EFBFBD>)">
* <loop column="element"/>
* </tag>
* return something
*/
class Loop extends Tag {
@ -182,59 +186,40 @@ class Loop extends Tag {
$limit = (int) $el->getAttribute("limit");
//testing purpose variable
$posts = array(
array(
'title'=> "a",
'url'=> "e",
'content'=> "<p>i</p>",
'date'=> "2018-09-20"
),
array(
'title'=> "b",
'url'=> "f",
'content'=> "<p>j</p>",
'date'=> "2018-09-21"
),
array(
'title'=> "c",
'url'=> "g",
'content'=> "<p>k</p>",
'date'=> "2018-09-22"
),
array(
'title'=> "d",
'url'=> "h",
'content'=> "<p>l</p>",
'date'=> "2018-09-23"
),
array(
'title'=> "z",
'url'=> "z",
'content'=> "<p>z</p>",
'date'=> "2018-10-23"
),
);
require_once 'functions.php';
//if($limit == 0) $limit = count($posts);
$pdo = connect();
$query = $pdo->query("SELECT title, categories.name as categorie, dt as date, short as content
FROM posts
INNER JOIN categories ON categories.id=posts.categorie
ORDER BY date DESC
LIMIT 6;");
$posts = $query->fetchAll();
$parent = $el->parentNode;
//var_dump($parent);
for ($i=0; $i < $limit; $i++) {
//var_dump($i);
$pok = $el->childNodes->item(1)->cloneNode(true);
$pok = $el->childNodes->item(0)->cloneNode(true);
$parent->insertBefore($pok, $el);
$elements = $pok->getElementsByTagName("loop");
foreach ($elements as $ele) {
if($ele->getAttribute("column") == "content") {
appendHTML($ele, $posts[$i][$ele->getAttribute("column")]);
appendHTML($ele->parentNode, $posts[$i]["content"]);
} else {
$txt = $doc->createTextNode($posts[$i][$ele->getAttribute("column")]);
$ele->parentNode->insertBefore($txt, $ele);
}
}
$finder = new DomXPath($doc);
$nodes = $finder->query("//*[contains(@class, 'column-cat')]");
// var_dump($nodes);
if(sizeof($nodes) >= 1) $nodes[0]->setAttribute("class", str_replace("column-categorie", $posts[$i]["categorie"], $nodes[0]->getAttribute("class")));
}
$loop = $parent->getElementsByTagName("loop");
@ -251,7 +236,13 @@ function appendHTML(DOMNode $parent, $source) {
$html = "<html><body>";
$html .= $source;
$html .= "</body></html>";
$tmpDoc->loadHTML($html);
$tmpDoc->loadHTML('<?xml encoding="UTF-8">'.$html);
foreach ($tmpDoc->childNodes as $item)
if ($item->nodeType == XML_PI_NODE)
$tmpDoc->removeChild($item);
$tmpDoc->encoding = 'UTF-8';
foreach ($tmpDoc->getElementsByTagName('body')->item(0)->childNodes as $node) {
$importedNode = $parent->ownerDocument->importNode($node, true);
$parent->appendChild($importedNode);
@ -262,9 +253,15 @@ function appendHTML(DOMNode $parent, $source) {
function loadTags($ctnt) {
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($ctnt);
$dom->loadHTML('<?xml encoding="UTF-8">'.$ctnt);
libxml_clear_errors();
// fix UTF-8 problem
foreach ($dom->childNodes as $item)
if ($item->nodeType == XML_PI_NODE)
$dom->removeChild($item);
$dom->encoding = 'UTF-8';
$list = $dom->getElementsByTagName("tag");
$head = $dom->getElementsByTagName("head");

View File

@ -1,57 +1,11 @@
<?php
var_dump($_POST);
$target_dir = dirname(__FILE__, 3) . "/uploads/".date("Y")."/".date("m")."/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["upload"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
include_once "functions.php";
$pdo = connect();
$query = $pdo->query("SELECT title, categorie, dt as date, short as content
FROM posts
ORDER BY date DESC
LIMIT 6");
while($row = $query->fetch()) {
echo $row["title"];
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if(!is_dir($target_dir)) {
mkdir($target_dir, 0777, true);
}
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename($_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
<form action="/test/" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="i-play-pokemon-go-everyday" name="upload">
</form>
// var_dump(connect());