From acc42674db6482ee6d432c4a9c174ed7dfcea063 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Thu, 24 May 2018 19:03:42 +0200 Subject: W 2.2 --- class/class.aff.php | 439 ---------------------------------------- class/class.app.php | 247 ----------------------- class/class.art.php | 363 --------------------------------- class/class.media.php | 122 ----------- class/class.w.aff.php | 524 ++++++++++++++++++++++++++++++++++++++++++++++++ class/class.w.app.php | 251 +++++++++++++++++++++++ class/class.w.art.php | 363 +++++++++++++++++++++++++++++++++ class/class.w.media.php | 122 +++++++++++ 8 files changed, 1260 insertions(+), 1171 deletions(-) delete mode 100644 class/class.aff.php delete mode 100644 class/class.app.php delete mode 100644 class/class.art.php delete mode 100644 class/class.media.php create mode 100644 class/class.w.aff.php create mode 100644 class/class.w.app.php create mode 100644 class/class.w.art.php create mode 100644 class/class.w.media.php (limited to 'class') diff --git a/class/class.aff.php b/class/class.aff.php deleted file mode 100644 index 3ae4662..0000000 --- a/class/class.aff.php +++ /dev/null @@ -1,439 +0,0 @@ -setsession($session); - } - - public function lecture(Art $art, App $app) - { - echo '
'; - if ($art->secure() == 1) { - echo '

cet article est privé

'; - } - if ($art->secure() == 2) { - echo "

cet article n'est pas publié

"; - } - - if ($this->session() >= $art->secure()) { - ?> - -
-
-

titre() ?>

-
soustitre() ?>
-
-
html($app) ?>
-
- '; - } - - public function edit(Art $art, $list) - { - if ($this->session() >= self::$edit) { - - ?> -
-
-
-
- Infos - - - - - - - - - - -
-
- CSS - - - - - - - - - - - - -
-
- Contenu - -
- - -
-
- - - -
-
- - -
-
- - - '; - ?> - - - - - - - - - -
-
- - - - - - - <?= $title ?> - - - -
- - -
- '; - echo ' '; - echo '
'; - } - - public function lien($getlist, $lien) - { - echo '
'; - echo ' '; - echo '
'; - } - - public function home($getlist) - { - echo ' '; - } - - public function dump($getlist) - { - echo ' '; - } - - public function home2($getlist) - { - echo '
'; - if ($this->session() >= 2) { - echo ' '; - } - echo '
'; - } - - public function home2table($getlist) - { - echo '
'; - echo '
'; - echo '

W

'; - $this->search(); - if ($this->session() >= 2) { - echo '

Home

'; - echo ''; - echo ''; - foreach ($getlist as $item) { - $liento = 0; - $lienfrom = 0; - - foreach ($getlist as $lien) { - if (in_array($item->id(), $lien->lien('array'))) { - $liento++; - } - } - foreach ($item->lien('array') as $count) { - $lienfrom++; - } - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
titrerésumélien fromlien todernière modifdate de créationedit
' . $item->titre() . '' . $item->intro() . '' . $lienfrom . '' . $liento . '' . $item->datemodif('hrdi') . '' . $item->datecreation('hrdi') . 'modifier
'; - } - echo '
'; - echo '
'; - } - - public function aside($list) - { - if ($this->session() >= 2) { - echo ' '; - } - } - - public function nav($app) - { - ?> - - session() >= 2) { - - ?> -
- Add Media -

Ajouter un media

-
- - - - -
-
- = 0) { - $session = intval($session); - $this->session = $session; - } -} - - //______________________________________________________ G E T _________________________________________________ - -public function session() -{ - return $this->session; -} - - -} - - - -?> \ No newline at end of file diff --git a/class/class.app.php b/class/class.app.php deleted file mode 100644 index 8ca1b1f..0000000 --- a/class/class.app.php +++ /dev/null @@ -1,247 +0,0 @@ -admin = $config['admin']; - $this->secure = $config['secure']; - - 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()); - } - } - - public function add(Art $art) - { - - if ($this->exist($art->id())) { - echo '

cet id existe deja

'; - } else { - - $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, couleurlienblank, lien, template) VALUES(:id, :titre, :soustitre, :intro, :tag, :datecreation, :datemodif, :css, :html, :secure, :couleurtext, :couleurbkg, :couleurlien, :couleurlienblank, :lien, :template)'); - - $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('string')); - $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->md()); - $q->bindValue(':secure', $art->secure()); - $q->bindValue(':couleurtext', $art->couleurtext()); - $q->bindValue(':couleurbkg', $art->couleurbkg()); - $q->bindValue(':couleurlien', $art->couleurlien()); - $q->bindValue(':couleurlienblank', $art->couleurlienblank()); - $q->bindValue(':lien', $art->lien('string')); - $q->bindValue(':template', $art->template()); - - $q->execute(); - } - } - - public function delete(Art $art) - { - $req = $this->bdd->prepare('DELETE FROM art WHERE id = :id '); - $req->execute(array('id' => $art->id())); - $req->closeCursor(); - } - - public function get($id) - { - $req = $this->bdd->prepare('SELECT * FROM art WHERE id = :id '); - $req->execute(array('id' => $id)); - $donnees = $req->fetch(PDO::FETCH_ASSOC); - - return new Art($donnees); - - $req->closeCursor(); - - } - - public function getlister(array $selection = ['id', 'titre'], $tri = 'id', $desc = 'ASC') - { - $list = []; - $option = ['datecreation', 'titre', 'id', 'intro', 'datemodif']; - if (is_array($selection) && is_string($tri) && strlen($tri) < 16 && is_string($desc) && strlen($desc) < 5 && in_array($tri, $option)) { - - $selection = implode(", ", $selection); - - $select = 'SELECT ' . $selection . ' FROM art ORDER BY ' . $tri . ' ' . $desc; - $req = $this->bdd->query($select); - while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) { - $list[] = new Art($donnees); - } - return $list; - } - } - - public function lister() - { - $req = $this->bdd->query(' SELECT * FROM art ORDER BY id '); - $donnees = $req->fetchAll(PDO::FETCH_ASSOC); - return $donnees; - - $req->closeCursor(); - - } - - public function count() - { - return $this->bdd->query(' SELECT COUNT(*) FROM art ')->fetchColumn(); - } - - public function exist($id) - { - $req = $this->bdd->prepare(' SELECT COUNT(*) FROM art WHERE id = :id '); - $req->execute(array('id' => $id)); - $donnees = $req->fetch(PDO::FETCH_ASSOC); - - return (bool)$donnees['COUNT(*)']; - } - - public function update(Art $art) - { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - $art->updatelien(); - - $q = $this->bdd->prepare('UPDATE art SET titre = :titre, soustitre = :soustitre, intro = :intro, tag = :tag, datecreation = :datecreation, datemodif = :datemodif, css = :css, html = :html, secure = :secure, couleurtext = :couleurtext, couleurbkg = :couleurbkg, couleurlien = :couleurlien, couleurlienblank = :couleurlienblank, lien = :lien, template = :template 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('string')); - $q->bindValue(':datecreation', $art->datecreation('string')); - $q->bindValue(':datemodif', $now->format('Y-m-d H:i:s')); - $q->bindValue(':css', $art->css()); - $q->bindValue(':html', $art->md()); - $q->bindValue(':secure', $art->secure()); - $q->bindValue(':couleurtext', $art->couleurtext()); - $q->bindValue(':couleurbkg', $art->couleurbkg()); - $q->bindValue(':couleurlien', $art->couleurlien()); - $q->bindValue(':couleurlienblank', $art->couleurlienblank()); - $q->bindValue(':lien', $art->lien('string')); - $q->bindValue(':template', $art->template()); - - $q->execute(); - } - - - - -// __________________________________________ M E D ________________________________________________________ - - public function addmedia(array $file, $maxsize, $id) - { - $maxsize = 2 ** 40; - $id = strtolower(strip_tags($id)); - if (isset($file) and $file['media']['error'] == 0 and $file['media']['size'] < $maxsize) { - $infosfichier = pathinfo($file['media']['name']); - $extension_upload = $infosfichier['extension']; - $extensions_autorisees = array('jpeg', 'jpg', 'JPG', 'png', 'gif', 'mp3', 'mp4', 'mov', 'wav', 'flac'); - if (in_array($extension_upload, $extensions_autorisees)) { - if (!file_exists('../media/' . $id . '.' . $extension_upload)) { - - $extension_upload = strtolower($extension_upload); - $uploadok = move_uploaded_file($file['media']['tmp_name'], '../media/' . $id . '.' . $extension_upload); - if ($uploadok) { - header('Location: ./?message=uploadok'); - } else { - header('Location: ./?message=uploaderror'); - } - } else { - header('Location: ./?message=filealreadyexist'); - - } - } - } else { - header('Location: ./?message=filetoobig'); - - } - } - - - public function getmedia($entry) - { - $fileinfo = pathinfo($entry); - - $filepath = $fileinfo['dirname'] . '.' . $fileinfo['extension']; - - list($width, $height, $type, $attr) = getimagesize($filepath); - - echo 'filepath : ' . $filepath; - - $donnes = array( - 'id' => str_replace('.' . $fileinfo['extension'], '', $fileinfo['filename']), - 'path' => $fileinfo['dirname'], - 'extension' => $fileinfo['extension'] - ); - - - - return new Art($donnees); - - } - - public function getlistermedia($dir) - { - if ($handle = opendir($dir)) { - $list = []; - while (false !== ($entry = readdir($handle))) { - if ($entry != "." && $entry != "..") { - $fileinfo = pathinfo($entry); - - $filepath = $dir . $fileinfo['filename'] . '.' . $fileinfo['extension']; - - list($width, $height, $type, $attr) = getimagesize($filepath); - $filesize = filesize($filepath); - - $donnees = array( - 'id' => str_replace('.' . $fileinfo['extension'], '', $fileinfo['filename']), - 'path' => $fileinfo['dirname'], - 'extension' => $fileinfo['extension'], - 'size' => $filesize, - 'width' => $width, - 'height' => $height - ); - - $list[] = new Media($donnees); - - } - } - return $list; - } - - return $list; - - } - - - //_________________________________________________________ S E S ________________________________________________________ - - public function login($pass) - { - if (strip_tags($pass) == $this->admin) { - return $level = 2; - } elseif (strip_tags($pass) == $this->secure) { - return $level = 1; - } - } - - public function logout() - { - return $level = 0; - } - -} -?> \ No newline at end of file diff --git a/class/class.art.php b/class/class.art.php deleted file mode 100644 index 2b67611..0000000 --- a/class/class.art.php +++ /dev/null @@ -1,363 +0,0 @@ -hydrate($donnees); - } - - public function hydrate(array $donnees) - { - foreach ($donnees as $key => $value) { - $method = 'set' . $key; - - if (method_exists($this, $method)) { - $this->$method($value); - } - } - } - - public function reset() - { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - - $this->settitre($this->id()); - $this->setsoustitre($this->id()); - $this->setintro('resumé'); - $this->settag('sans tag,'); - $this->setdatecreation($now); - $this->setcss('section {} -a:hover {}'); - $this->sethtml('contenu'); - $this->setsecure(2); - $this->setcouleurtext('#000000'); - $this->setcouleurbkg('#FFFFFF'); - $this->setcouleurlien('#000000'); - $this->setcouleurlienblank('#000000'); - $this->setlien(''); - $this->settemplate(''); - } - - public function updatelien() - { - $this->lien = search($this->md(), self::DEBUT, self::FIN); - - } - - // _____________________________________________________ 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($option) - { - if ($option == 'string') { - $tag = implode(", ", $this->tag); - } elseif ($option == 'array') { - $tag = $this->tag; - } - return $tag; - } - - public function datecreation($option) - { - if ($option == 'string') { - return $this->datecreation->format('Y-m-d H:i:s'); - } elseif ($option == 'date') { - return $this->datecreation; - } elseif ($option == 'hrdi') { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - return hrdi($this->datecreation->diff($now)); - } - } - - - public function datemodif($option) - { - if ($option == 'string') { - return $this->datemodif->format('Y-m-d H:i:s'); - } elseif ($option == 'date') { - return $this->datemodif; - } elseif ($option == 'hrdi') { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - return hrdi($this->datemodif->diff($now)); - } - } - - public function css() - { - return $this->css; - } - - public function csstemplate(App $app) - { - $data = []; - $temp = ''; - if (!empty($this->template())) { - if ($app->exist($this->template()) and !in_array($this->template(), $data)) { - $template = $app->get($this->template()); - $temp = $temp . $template->css($app); - $data[] = $template->id(); - - } - - } - return $temp . $this->css; - } - - public function md() - { - return $this->html; - } - - public function html(App $app) - { - $html = Markdown::defaultTransform($this->html); - - foreach ($this->lien('array') as $id) { - $title = "Cet article n'existe pas encore"; - foreach ($app->getlister(['id', 'intro'], 'id') as $item) { - if ($item->id() == $id) { - $title = $item->intro(); - } - } - $lien = 'href="?id=' . $id . '"'; - $titlelien = ' title="' . $title . '" ' . $lien; - $html = str_replace($lien, $titlelien, $html); - } - - $html = str_replace('href="http', ' class="external" target="_blank" href="http', $html); - $html = str_replace('src="/', 'src="../media/', $html); - $html = str_replace('
', $html); - return $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; - } - - public function couleurlienblank() - { - return $this->couleurlienblank; - } - - public function lien($option) - { - if ($option == 'string') { - $lien = implode(", ", $this->lien); - } elseif ($option == 'array') { - $lien = $this->lien; - } - return $lien; - - } - - public function template() - { - return $this->template; - } - - - - - // _____________________________________________________ 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)) { - $tag = strip_tags(trim(strtolower($tag))); - $taglist = explode(", ", $tag); - $this->tag = $taglist; - } - } - - 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::LENHTML 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 = intval($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::LENCOULEUR) { - $this->couleurlien = strip_tags(trim($couleurlien)); - } - } - - public function setcouleurlienblank($couleurlienblank) - { - $couleurlienblank = strval($couleurlienblank); - if (strlen($couleurlienblank) <= self::LENCOULEUR) { - $this->couleurlienblank = strip_tags(trim($couleurlienblank)); - } - } - - public function setlien($lien) - { - if (!empty($lien) && strlen($lien) < self::LEN && is_string($lien)) { - $lien = strip_tags(trim(strtolower($lien))); - $lienlist = explode(", ", $lien); - $this->lien = $lienlist; - } else { - $this->lien = []; - } - } - - public function settemplate($template) - { - $template = strip_tags($template); - if (strlen($template) == 0) { - $template = 'NULL'; - } - $this->template = $template; - } - - -} - - -?> \ No newline at end of file diff --git a/class/class.media.php b/class/class.media.php deleted file mode 100644 index e5056c9..0000000 --- a/class/class.media.php +++ /dev/null @@ -1,122 +0,0 @@ -hydrate($donnees); - } - - 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 path() - { - return $this->path; - } - - public function extension() - { - return $this->extension; - } - - public function type() - { - return $this->type; - } - - public function size() - { - return $this->size; - } - - public function width() - { - return $this->width; - } - - public function height() - { - return $this->height; - } - -// ___________________________________________________ S E T __________________________________________________ - - public function setid($id) - { - if (strlen($id) < 40 and is_string($id)) { - $this->id = strip_tags(strtolower($id)); - } - } - - public function setpath($path) - { - if (strlen($path) < 40 and is_string($path)) { - $this->path = strip_tags(strtolower($path)); - } - } - - public function setextension($extension) - { - if (strlen($extension) < 7 and is_string($extension)) { - $this->extension = strip_tags(strtolower($extension)); - } - } - - public function setsize($size) - { - if (40 and is_int($size)) { - $this->size = strip_tags(strtolower($size)); - } - } - - public function setwidth($width) - { - if (is_int($width)) { - $this->width = strip_tags(strtolower($width)); - } - } - - public function setheight($height) - { - if (is_int($height)) { - $this->height = strip_tags(strtolower($height)); - } - } - - - - - -} - -?> \ No newline at end of file diff --git a/class/class.w.aff.php b/class/class.w.aff.php new file mode 100644 index 0000000..888736a --- /dev/null +++ b/class/class.w.aff.php @@ -0,0 +1,524 @@ +setsession($session); + } + + public function lecture(Art $art, App $app) + { + echo '
'; + if ($art->secure() == 1) { + echo '

cet article est privé

'; + } + if ($art->secure() == 2) { + echo "

cet article n'est pas publié

"; + } + + if ($this->session() >= $art->secure()) { + ?> + +
+
+

titre() ?>

+
soustitre() ?>
+
+
html($app) ?>
+
+ '; + } + + public function edit(Art $art, $list) + { + if ($this->session() >= self::$edit) { + + ?> +
+
+
+
+ Infos + + + + + + + + + + +
+
+ CSS + + + + + + + + + + + + +
+
+ Contenu + +
+ + +
+
+ + + +
+
+ + +
+
+ + + '; + ?> + + + + + + + + + +
+
+ + + + + + + + <?= $title ?> + + + + + + + + + + + <?= $pre ?> <?= $art->titre() ?> + + + +
+ + +
+ '; + echo '
    '; + foreach ($getlist as $item) { + if (in_array($tag, $item->tag('array'))) { + echo '
  • ' . $item->titre() . ' - ' . $item->intro(); + if ($this->session() >= 2) { + echo ' - modifier
  • '; + } else { + echo ''; + } + } + } + echo '
'; + echo '
'; + } + + public function lien($getlist, $lien) + { + echo '
'; + echo '
    '; + foreach ($getlist as $item) { + if (in_array($lien, $item->lien('array'))) { + echo '
  • ' . $item->titre() . ' - ' . $item->intro(); + if ($this->session() >= 2) { + echo ' - modifier
  • '; + } else { + echo ''; + } + } + } + echo '
'; + echo '
'; + } + + public function home($getlist) + { + echo ' '; + } + + public function dump($getlist) + { + echo ' '; + } + + public function home2($getlist) + { + echo '
'; + if ($this->session() >= 2) { + echo '
    '; + foreach ($getlist as $item) { + $count = 0; + + foreach ($getlist as $lien) { + if (in_array($item->id(), $lien->lien('array'))) { + $count++; + } + } + echo '
  • ' . $item->titre() . ' - ' . $item->intro(); + echo ' - ' . $count . ' '; + echo ' - modifier
  • '; + } + echo '
'; + } + echo '
'; + } + + public function home2table($getlist) + { + echo '
'; + echo '
'; + echo '

W

'; + $this->search(); + if ($this->session() >= 2) { + echo '

Home

'; + echo ''; + echo ''; + foreach ($getlist as $item) { + $liento = 0; + $lienfrom = 0; + + foreach ($getlist as $lien) { + if (in_array($item->id(), $lien->lien('array'))) { + $liento++; + } + } + foreach ($item->lien('array') as $count) { + $lienfrom++; + } + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
titrerésumélien fromlien todernière modifdate de créationedit
' . $item->titre() . '' . $item->intro() . '' . $lienfrom . '' . $liento . '' . $item->datemodif('hrdi') . '' . $item->datecreation('hrdi') . 'modifier
'; + } + echo '
'; + echo '
'; + } + + public function aside($list) + { + if ($this->session() >= 2) { + echo ' '; + } + } + + public function nav($app) + { + echo ' + '; + echo '
'; + + $this->addmedia(); + $this->medialist(); + + echo '
'; + echo ''; + + } + + public function addmedia() + { + if ($this->session() >= 2) { + + ?> +
+ Add Media +
+ + + + +
+
+ '; + echo 'Media List'; + + echo '
'; + + echo '
'; + + echo '
    '; + + foreach ($app->getlistermedia($dir) as $item) { + echo '
  • '; + ?> + + + + + id() . '.' . $item->extension(); + + echo ''; + + echo ''; + echo 'width = ' . $item->width() . ' px'; + echo '
    '; + echo 'height = ' . $item->height() . ' px'; + echo '
    '; + echo 'filesize = ' . readablesize($item->size()); + echo '
    '; + + echo ''; + echo '
    '; + + + echo '' . $item->id() . ''; + echo '
    '; + + echo '
  • '; + } + + echo '
'; + + ?> + + + +
+ + + + '; + echo ''; + + + } + + + + //______________________________________________________ S E T _________________________________________________ + + public function setsession($session) + { + if ($session <= 2 and $session >= 0) { + $session = intval($session); + $this->session = $session; + } + } + + //______________________________________________________ G E T _________________________________________________ + + public function session() + { + return $this->session; + } + + +} + + + +?> \ No newline at end of file diff --git a/class/class.w.app.php b/class/class.w.app.php new file mode 100644 index 0000000..d668c2b --- /dev/null +++ b/class/class.w.app.php @@ -0,0 +1,251 @@ +admin = $config['admin']; + $this->secure = $config['secure']; + + 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()); + } + } + + public function add(Art $art) + { + + if ($this->exist($art->id())) { + echo '

cet id existe deja

'; + } else { + + $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, couleurlienblank, lien, template) VALUES(:id, :titre, :soustitre, :intro, :tag, :datecreation, :datemodif, :css, :html, :secure, :couleurtext, :couleurbkg, :couleurlien, :couleurlienblank, :lien, :template)'); + + $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('string')); + $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->md()); + $q->bindValue(':secure', $art->secure()); + $q->bindValue(':couleurtext', $art->couleurtext()); + $q->bindValue(':couleurbkg', $art->couleurbkg()); + $q->bindValue(':couleurlien', $art->couleurlien()); + $q->bindValue(':couleurlienblank', $art->couleurlienblank()); + $q->bindValue(':lien', $art->lien('string')); + $q->bindValue(':template', $art->template()); + + $q->execute(); + } + } + + public function delete(Art $art) + { + $req = $this->bdd->prepare('DELETE FROM art WHERE id = :id '); + $req->execute(array('id' => $art->id())); + $req->closeCursor(); + } + + public function get($id) + { + $req = $this->bdd->prepare('SELECT * FROM art WHERE id = :id '); + $req->execute(array('id' => $id)); + $donnees = $req->fetch(PDO::FETCH_ASSOC); + + return new Art($donnees); + + $req->closeCursor(); + + } + + public function getlister(array $selection = ['id', 'titre'], $tri = 'id', $desc = 'ASC') + { + $list = []; + $option = ['datecreation', 'titre', 'id', 'intro', 'datemodif']; + if (is_array($selection) && is_string($tri) && strlen($tri) < 16 && is_string($desc) && strlen($desc) < 5 && in_array($tri, $option)) { + + $selection = implode(", ", $selection); + + $select = 'SELECT ' . $selection . ' FROM art ORDER BY ' . $tri . ' ' . $desc; + $req = $this->bdd->query($select); + while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) { + $list[] = new Art($donnees); + } + return $list; + } + } + + public function lister() + { + $req = $this->bdd->query(' SELECT * FROM art ORDER BY id '); + $donnees = $req->fetchAll(PDO::FETCH_ASSOC); + return $donnees; + + $req->closeCursor(); + + } + + public function count() + { + return $this->bdd->query(' SELECT COUNT(*) FROM art ')->fetchColumn(); + } + + public function exist($id) + { + $req = $this->bdd->prepare(' SELECT COUNT(*) FROM art WHERE id = :id '); + $req->execute(array('id' => $id)); + $donnees = $req->fetch(PDO::FETCH_ASSOC); + + return (bool)$donnees['COUNT(*)']; + } + + public function update(Art $art) + { + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + $art->updatelien(); + + $q = $this->bdd->prepare('UPDATE art SET titre = :titre, soustitre = :soustitre, intro = :intro, tag = :tag, datecreation = :datecreation, datemodif = :datemodif, css = :css, html = :html, secure = :secure, couleurtext = :couleurtext, couleurbkg = :couleurbkg, couleurlien = :couleurlien, couleurlienblank = :couleurlienblank, lien = :lien, template = :template 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('string')); + $q->bindValue(':datecreation', $art->datecreation('string')); + $q->bindValue(':datemodif', $now->format('Y-m-d H:i:s')); + $q->bindValue(':css', $art->css()); + $q->bindValue(':html', $art->md()); + $q->bindValue(':secure', $art->secure()); + $q->bindValue(':couleurtext', $art->couleurtext()); + $q->bindValue(':couleurbkg', $art->couleurbkg()); + $q->bindValue(':couleurlien', $art->couleurlien()); + $q->bindValue(':couleurlienblank', $art->couleurlienblank()); + $q->bindValue(':lien', $art->lien('string')); + $q->bindValue(':template', $art->template()); + + $q->execute(); + } + + + + +// __________________________________________ M E D ________________________________________________________ + + public function addmedia(array $file, $maxsize, $id) + { + $message = 'runing'; + $maxsize = 2 ** 40; + $id = strtolower(strip_tags($id)); + $id = str_replace(' ', '_', $id); + if (isset($file) and $file['media']['error'] == 0 and $file['media']['size'] < $maxsize) { + $infosfichier = pathinfo($file['media']['name']); + $extension_upload = $infosfichier['extension']; + $extensions_autorisees = array('jpeg', 'jpg', 'JPG', 'png', 'gif', 'mp3', 'mp4', 'mov', 'wav', 'flac'); + if (in_array($extension_upload, $extensions_autorisees)) { + if (!file_exists('../media/' . $id . '.' . $extension_upload)) { + + $extension_upload = strtolower($extension_upload); + $uploadok = move_uploaded_file($file['media']['tmp_name'], '../media/' . $id . '.' . $extension_upload); + if ($uploadok) { + $message = 'uploadok'; + } else { + $message = 'uploadokerror'; + } + } else { + $message = 'filealreadyexist'; + + } + } + } else { + $message = 'filetoobig'; + + } + + return $message; + } + + + public function getmedia($entry) + { + $fileinfo = pathinfo($entry); + + $filepath = $fileinfo['dirname'] . '.' . $fileinfo['extension']; + + list($width, $height, $type, $attr) = getimagesize($filepath); + + echo 'filepath : ' . $filepath; + + $donnes = array( + 'id' => str_replace('.' . $fileinfo['extension'], '', $fileinfo['filename']), + 'path' => $fileinfo['dirname'], + 'extension' => $fileinfo['extension'] + ); + + + + return new Art($donnees); + + } + + public function getlistermedia($dir) + { + if ($handle = opendir($dir)) { + $list = []; + while (false !== ($entry = readdir($handle))) { + if ($entry != "." && $entry != "..") { + $fileinfo = pathinfo($entry); + + $filepath = $dir . $fileinfo['filename'] . '.' . $fileinfo['extension']; + + list($width, $height, $type, $attr) = getimagesize($filepath); + $filesize = filesize($filepath); + + $donnees = array( + 'id' => str_replace('.' . $fileinfo['extension'], '', $fileinfo['filename']), + 'path' => $fileinfo['dirname'], + 'extension' => $fileinfo['extension'], + 'size' => $filesize, + 'width' => $width, + 'height' => $height + ); + + $list[] = new Media($donnees); + + } + } + return $list; + } + + return $list; + + } + + + //_________________________________________________________ S E S ________________________________________________________ + + public function login($pass) + { + if (strip_tags($pass) == $this->admin) { + return $level = 2; + } elseif (strip_tags($pass) == $this->secure) { + return $level = 1; + } + } + + public function logout() + { + return $level = 0; + } + +} +?> \ No newline at end of file diff --git a/class/class.w.art.php b/class/class.w.art.php new file mode 100644 index 0000000..2b67611 --- /dev/null +++ b/class/class.w.art.php @@ -0,0 +1,363 @@ +hydrate($donnees); + } + + public function hydrate(array $donnees) + { + foreach ($donnees as $key => $value) { + $method = 'set' . $key; + + if (method_exists($this, $method)) { + $this->$method($value); + } + } + } + + public function reset() + { + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + + $this->settitre($this->id()); + $this->setsoustitre($this->id()); + $this->setintro('resumé'); + $this->settag('sans tag,'); + $this->setdatecreation($now); + $this->setcss('section {} +a:hover {}'); + $this->sethtml('contenu'); + $this->setsecure(2); + $this->setcouleurtext('#000000'); + $this->setcouleurbkg('#FFFFFF'); + $this->setcouleurlien('#000000'); + $this->setcouleurlienblank('#000000'); + $this->setlien(''); + $this->settemplate(''); + } + + public function updatelien() + { + $this->lien = search($this->md(), self::DEBUT, self::FIN); + + } + + // _____________________________________________________ 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($option) + { + if ($option == 'string') { + $tag = implode(", ", $this->tag); + } elseif ($option == 'array') { + $tag = $this->tag; + } + return $tag; + } + + public function datecreation($option) + { + if ($option == 'string') { + return $this->datecreation->format('Y-m-d H:i:s'); + } elseif ($option == 'date') { + return $this->datecreation; + } elseif ($option == 'hrdi') { + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + return hrdi($this->datecreation->diff($now)); + } + } + + + public function datemodif($option) + { + if ($option == 'string') { + return $this->datemodif->format('Y-m-d H:i:s'); + } elseif ($option == 'date') { + return $this->datemodif; + } elseif ($option == 'hrdi') { + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + return hrdi($this->datemodif->diff($now)); + } + } + + public function css() + { + return $this->css; + } + + public function csstemplate(App $app) + { + $data = []; + $temp = ''; + if (!empty($this->template())) { + if ($app->exist($this->template()) and !in_array($this->template(), $data)) { + $template = $app->get($this->template()); + $temp = $temp . $template->css($app); + $data[] = $template->id(); + + } + + } + return $temp . $this->css; + } + + public function md() + { + return $this->html; + } + + public function html(App $app) + { + $html = Markdown::defaultTransform($this->html); + + foreach ($this->lien('array') as $id) { + $title = "Cet article n'existe pas encore"; + foreach ($app->getlister(['id', 'intro'], 'id') as $item) { + if ($item->id() == $id) { + $title = $item->intro(); + } + } + $lien = 'href="?id=' . $id . '"'; + $titlelien = ' title="' . $title . '" ' . $lien; + $html = str_replace($lien, $titlelien, $html); + } + + $html = str_replace('href="http', ' class="external" target="_blank" href="http', $html); + $html = str_replace('src="/', 'src="../media/', $html); + $html = str_replace('
', $html); + return $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; + } + + public function couleurlienblank() + { + return $this->couleurlienblank; + } + + public function lien($option) + { + if ($option == 'string') { + $lien = implode(", ", $this->lien); + } elseif ($option == 'array') { + $lien = $this->lien; + } + return $lien; + + } + + public function template() + { + return $this->template; + } + + + + + // _____________________________________________________ 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)) { + $tag = strip_tags(trim(strtolower($tag))); + $taglist = explode(", ", $tag); + $this->tag = $taglist; + } + } + + 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::LENHTML 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 = intval($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::LENCOULEUR) { + $this->couleurlien = strip_tags(trim($couleurlien)); + } + } + + public function setcouleurlienblank($couleurlienblank) + { + $couleurlienblank = strval($couleurlienblank); + if (strlen($couleurlienblank) <= self::LENCOULEUR) { + $this->couleurlienblank = strip_tags(trim($couleurlienblank)); + } + } + + public function setlien($lien) + { + if (!empty($lien) && strlen($lien) < self::LEN && is_string($lien)) { + $lien = strip_tags(trim(strtolower($lien))); + $lienlist = explode(", ", $lien); + $this->lien = $lienlist; + } else { + $this->lien = []; + } + } + + public function settemplate($template) + { + $template = strip_tags($template); + if (strlen($template) == 0) { + $template = 'NULL'; + } + $this->template = $template; + } + + +} + + +?> \ No newline at end of file diff --git a/class/class.w.media.php b/class/class.w.media.php new file mode 100644 index 0000000..e5056c9 --- /dev/null +++ b/class/class.w.media.php @@ -0,0 +1,122 @@ +hydrate($donnees); + } + + 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 path() + { + return $this->path; + } + + public function extension() + { + return $this->extension; + } + + public function type() + { + return $this->type; + } + + public function size() + { + return $this->size; + } + + public function width() + { + return $this->width; + } + + public function height() + { + return $this->height; + } + +// ___________________________________________________ S E T __________________________________________________ + + public function setid($id) + { + if (strlen($id) < 40 and is_string($id)) { + $this->id = strip_tags(strtolower($id)); + } + } + + public function setpath($path) + { + if (strlen($path) < 40 and is_string($path)) { + $this->path = strip_tags(strtolower($path)); + } + } + + public function setextension($extension) + { + if (strlen($extension) < 7 and is_string($extension)) { + $this->extension = strip_tags(strtolower($extension)); + } + } + + public function setsize($size) + { + if (40 and is_int($size)) { + $this->size = strip_tags(strtolower($size)); + } + } + + public function setwidth($width) + { + if (is_int($width)) { + $this->width = strip_tags(strtolower($width)); + } + } + + public function setheight($height) + { + if (is_int($height)) { + $this->height = strip_tags(strtolower($height)); + } + } + + + + + +} + +?> \ No newline at end of file -- cgit v1.2.3