diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2018-03-17 19:55:22 +0100 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2018-03-17 19:55:22 +0100 |
commit | a8d40a4ac2f73da9509bde6c8337c13042cc6992 (patch) | |
tree | accc85f0fa42511a5c05eb26b08a5910f4b9e03a | |
parent | 58ae39dcd52259e280c21c9f3df8ee2e2eae1947 (diff) | |
download | wcms-a8d40a4ac2f73da9509bde6c8337c13042cc6992.tar.gz wcms-a8d40a4ac2f73da9509bde6c8337c13042cc6992.zip |
transfert
-rw-r--r-- | class/class.app.php | 101 | ||||
-rw-r--r-- | class/class.art.php | 207 | ||||
-rw-r--r-- | fn/fn.php | 14 | ||||
-rw-r--r-- | public/index.php | 25 | ||||
-rw-r--r-- | public/w/index.php | 58 |
5 files changed, 379 insertions, 26 deletions
diff --git a/class/class.app.php b/class/class.app.php index 4078c17..056e65b 100644 --- a/class/class.app.php +++ b/class/class.app.php @@ -1,30 +1,111 @@ +<h4>class.app</h4> <?php class App { - protected $bdd; + private $bdd; - public function __construct($config) + public function __construct() { - $host = $config['host']; - $dbname = $config['dbname']; - $user = $config['user']; - $password = $config['password']; + // try { + // $this->bdd = new PDO('mysql:host=' . $config['host'] . ';dbname=' . $config['dbname'] . ';charset=utf8', $config['user'], $config['password']); + // } catch (Exeption $e) { + // die('Erreur : ' . $e->getMessage()); + // } + try { - $this->bdd = new PDO('mysql:host=' . $host . ';dbname=' . $dbname . ';charset=utf8', $user, $password); + $this->bdd = new PDO('mysql:host=localhost;dbname=wcms;charset=utf8', 'root', ''); } catch (Exeption $e) { die('Erreur : ' . $e->getMessage()); } } - public function getBdd() + public function add(Art $art) + { +// tester l'existence de l'id + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + + $q = $this->bdd->prepare('INSERT INTO art(id, titre, soustitre, intro, tag, datecreation, datemodif, css, html, secure, couleurtext, couleurbkg, couleurlien) VALUES(:id, :titre, :soustitre, :intro, :tag, :datecreation, :datemodif, :css, :html, :secure, :couleurtext, :couleurbkg, :couleurlien)'); + + $q->bindValue(':id', $art->id()); + $q->bindValue(':titre', $art->titre()); + $q->bindValue(':soustitre', $art->soustitre()); + $q->bindValue(':intro', $art->intro()); + $q->bindValue(':tag', $art->tag()); + $q->bindValue(':datecreation', $now->format('Y-m-d H:i:s')); + $q->bindValue(':datemodif', $now->format('Y-m-d H:i:s')); + $q->bindValue(':css', $art->css()); + $q->bindValue(':html', $art->html()); + $q->bindValue(':secure', $art->secure()); + $q->bindValue(':couleurtext', $art->couleurtext()); + $q->bindValue(':couleurbkg', $art->couleurbkg()); + $q->bindValue(':couleurlien', $art->couleurlien()); + + $q->execute(); + } + + public function delete(Art $art) { - return $this->bdd; + $this->bdd->exec('DELETE FROM art WHERE id = ' . $art->id()); } - public function createfrombdd($id, $bdd) + public function get($id) { + $q = $this->bdd->query('SELECT * FROM art WHERE id = ' . $id); + $donnees = $q->fetch(PDO::FETCH_ASSOC); + + return new Art($donnees); + } + + public function getlist() + { + $listart = []; + + $q = $this->bdd->query('SELECT titre, soustitre, intro FROM art ORDER BY titre'); + + while ($donnees = $q->fetch(PDO::FETCH_ASSOC)) { + $listart[] = new art($donnees); + } + return $listart; } + public function count() + { + return $this->bdd->query('SELECT COUNT(*) FROM art')->fetchColumn(); + } + + // public function exist($id) + // { + // $r = $this->bdd->query('SELECT COUNT(*) AS art FROM art WHERE id = '.$id); + // return $donnees = $r->fetch(PDO::FETCH_ASSOC); + // } + + public function exist($id) + { + return $this->bdd->query('SELECT COUNT(*) FROM art WHERE id = ' . $id)->fetchColumn(); + } + + public function update(Art $art) + { + $q = $this->bdd->prepare('UPDATE art SET titre = :titre, soustitre = :soustitre, intro = :intro, tag = :tag, datecreation = :datecreation, datemodif = :datemodif, cass = :css, html = :html, secure = :secure, couleurtext = :couleurtext, couleurbkg = :couleurbkg, couleurlien = :couleurlien WHERE id = :id'); + + $q->bindValue(':id', $art->id()); + $q->bindValue(':titre', $art->titre()); + $q->bindValue(':soustitre', $art->soustitre()); + $q->bindValue(':intro', $art->intro()); + $q->bindValue(':tag', $art->tag()); + $q->bindValue(':datecreation', $art->datecreation()); + $q->bindValue(':datemodif', $art->datemodif()); + $q->bindValue(':css', $art->css()); + $q->bindValue(':html', $art->html()); + $q->bindValue(':secure', $art->secure(), PDO::PARAM_INT); + $q->bindValue(':couleurtext', $art->tag()); + $q->bindValue(':couleurbkgt', $art->couleurbkgt()); + $q->bindValue(':couleurlien', $art->couleurlien()); + + $q->execute(); + } + + } ?>
\ No newline at end of file diff --git a/class/class.art.php b/class/class.art.php index 6b126ea..a94b649 100644 --- a/class/class.art.php +++ b/class/class.art.php @@ -1,12 +1,215 @@ +<h4>class.art</h4> <?php + class Art { - public $id; + private $id; + private $titre; + private $soustitre; + private $intro; + private $tag; + private $datecreation; + private $datemodif; + private $css; + private $html; + private $secure; + private $couleurtext; + private $couleurbkg; + private $couleurlien; + + private static $len = 255; + private static $lenhtml = 65535; + private static $securemax = 2; + private static $lencouleur = 7; + + + // _____________________________________________________ F U N ____________________________________________________ + + public function __construct(array $donnees) + { + $this->hydrate($donnees); + } - public function createfrombdd($id, $bdd) + public function hydrate(array $donnees) { + foreach ($donnees as $key => $value) { + $method = 'set' . $key; + if (method_exists($this, $method)) { + $this->$method($value); + } + } } + // _____________________________________________________ G E T ____________________________________________________ + + public function id() + { + return $this->id; + } + + public function titre() + { + return $this->titre; + } + + public function soustitre() + { + return $this->soustitre; + } + + public function intro() + { + return $this->intro; + } + + public function tag() + { + return $this->tag; + } + + public function datecreation() + { + return $this->datecreation; + } + + public function datemodif() + { + return $this->datemodif; + } + + public function css() + { + return $this->css; + } + + public function html() + { + return $this->html; + } + + public function secure() + { + return $this->secure; + } + + public function couleurtext() + { + return $this->couleurtext; + } + + public function couleurbkg() + { + return $this->couleurbkg; + } + + public function couleurlien() + { + return $this->couleurlien; + } + + + + // _____________________________________________________ S E T ____________________________________________________ + + public function setid($id) + { + if (strlen($id) < self::$len and is_string($id)) { + $this->id = strip_tags(strtolower(str_replace(" ", "", $id))); + } + } + + public function settitre($titre) + { + if (strlen($titre) < self::$len and is_string($titre)) { + $this->titre = strip_tags(trim($titre)); + } + } + + public function setsoustitre($soustitre) + { + if (strlen($soustitre) < self::$len and is_string($soustitre)) { + $this->soustitre = strip_tags(trim($soustitre)); + } + } + + public function setintro($intro) + { + if (strlen($intro) < self::$len and is_string($intro)) { + $this->intro = strip_tags(trim($intro)); + } + } + + public function settag($tag) + { + if (strlen($tag) < self::$len and is_string($tag)) { + $this->tag = strip_tags(trim(strtolower($tag))); + } + } + + public function setdatecreation($datecreation) + { + if ($datecreation instanceof DateTimeImmutable) { + $this->datecreation = $datecreation; + } else { + $this->datecreation = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $datecreation, new DateTimeZone('Europe/Paris')); + } + } + + public function setdatemodif($datemodif) + { + if ($datemodif instanceof DateTimeImmutable) { + $this->datemodif = $datemodif; + } else { + $this->datemodif = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $datemodif, new DateTimeZone('Europe/Paris')); + } + } + + public function setcss($css) + { + if (strlen($css) < self::$len and is_string($css)) { + $this->css = strip_tags(trim(strtolower($css))); + } + } + + public function sethtml($html) + { + if (strlen($html) < self::$lenhtml and is_string($html)) { + $this->html = $html; + } + } + + public function setsecure($secure) + { + if ($secure >= 0 and $secure <= self::$securemax) { + $this->secure = $secure; + } + } + + public function setcouleurtext($couleurtext) + { + $couleurtext = strval($couleurtext); + if (strlen($couleurtext) < self::$lencouleur) { + $this->couleurtext = strip_tags(trim($couleurtext)); + } + } + + public function setcouleurbkg($couleurbkg) + { + $couleurbkg = strval($couleurbkg); + if (strlen($couleurbkg) < self::$lencouleur) { + $this->couleurbkg = strip_tags(trim($couleurbkg)); + } + } + + public function setcouleurlien($couleurlien) + { + $couleurlien = strval($couleurlien); + if (strlen($couleurlien) < self::$couleurlien) { + $this->couleurlien = strip_tags(trim($couleurlien)); + } + } + + } ?>
\ No newline at end of file @@ -1,6 +1,4 @@ -secure - -session +<h4>functions</h4> <?php function bddconnect($host, $bdname, $user, $password) @@ -24,5 +22,15 @@ function secure() header("location: /"); } } + +function head($title) { + ?> + <head> + <meta charset="utf8" /> + <link href="" rel="stylesheet" /> + <title><?= $title ?></title> + </head> + <?php +} ?> diff --git a/public/index.php b/public/index.php index e69de29..90df7d7 100644 --- a/public/index.php +++ b/public/index.php @@ -0,0 +1,25 @@ +<html> +<a href="/w/">w</a> +</html> + +<?php + +var_dump(__FILE__); + +$htdocs = str_replace(basename(__FILE__), __FILE__, ''); + +var_dump($htdocs); + +var_dump($_SERVER["DOCUMENT_ROOT"]); + + +set_include_path('e:/WEB/wcms'); + +echo get_include_path(); + + + +include('fn/fn.php'); + + +?>
\ No newline at end of file diff --git a/public/w/index.php b/public/w/index.php index 250a870..85c0902 100644 --- a/public/w/index.php +++ b/public/w/index.php @@ -2,24 +2,60 @@ //inw -$root = $_SERVER["DOCUMENT_ROOT"]; -require($root . '/fn.php'); -require($root . '/class/art.php'); -$config = include($root . '/config.php'); -$domaine = $config['domaine']; +set_include_path('e:/WEB/wcms'); + +require('fn/fn.php'); +require('class/class.art.php'); +require('class/class.app.php'); +$config = include('config.php'); +$app = new App(); session(); // fin de in -$app = new App($config); -$art = new Art; -$art->createfrombdd($id, $app->getBdd()); -include($root . '/head.php') +head('article'); + + +// $art = new Art([ +// 'id' => 'prout', +// 'titre' => 'Prout', +// 'soustitre' => 'mega prout !', +// 'intro' => 'bienvenue dans le mega prout', +// 'datemodif' => new DateTimeImmutable(null, timezone_open("Europe/Paris")) +// ]); + +// echo '<pre>'; +// print_r($art); +// print_r($app); +// echo '</pre>'; + +// $app->add($art); + +// echo '<p>art count :' . $app->count() . '</p>'; +// echo '<p>article exist :' . $app->exist('articlet') . '</p>'; +// var_dump($app->exist('articlet')); + +// $app->get('articlet'); + +// echo '<pre>'; +// print_r($art); +// print_r($app); +// echo '</pre>'; + +try { + $bdd = new PDO('mysql:host=localhost;dbname=wcms;charset=utf8', 'root', ''); +} catch (Exeption $e) { + die('Erreur : ' . $e->getMessage()); +} + +$q = $bdd->query('SELECT * FROM art WHERE id = articlet'); +$donnees = $q->fetch(); + +var_dump($donnees); -rpout -CURLOPT_PROXYAUT +$q = closeCursor(); |