From 5a6d7248fcbc3f88fe66f3b52d51087698c3e6ba Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Tue, 17 Apr 2018 15:46:41 +0200 Subject: title intro lien --- class/class.aff.php | 96 ++++++++++++++++++++++++++++++++++++++++++++++------ class/class.app.php | 39 +++++++++++++++++---- class/class.art.php | 20 ----------- fn/fn.php | 18 ++++++++++ public/css/style.css | 5 +++ public/w/index.php | 19 ++++++++--- 6 files changed, 154 insertions(+), 43 deletions(-) diff --git a/class/class.aff.php b/class/class.aff.php index 3ccfd59..c822a91 100644 --- a/class/class.aff.php +++ b/class/class.aff.php @@ -15,7 +15,7 @@ class Aff $this->setsession($session); } - public function lecture(Art $art) + public function lecture(Art $art, App $app) { if ($art->secure() == 1) { echo '

cet article est privé

'; @@ -46,7 +46,7 @@ class Aff

titre() ?>

soustitre() ?>
-
html('html') ?>
+
introlien($art) ?>
@@ -127,25 +127,29 @@ public function head($title)
session() == 2) { - echo ' '; } - public function tag($getlist, $tag) + public function lien($getlist, $lien) { echo ' '; } + public function home($getlist) + { + echo ' '; + } + + public function dump($getlist) + { + echo ' '; + } + + public function home2($getlist) + { + if ($this->session() >= 2) { + echo ' '; + } + } + + public function home2table($getlist) + { + if ($this->session() >= 2) { + echo ''; + echo ''; + foreach ($getlist as $item) { + $count = 0; + + foreach ($getlist as $lien) { + if (in_array($item->id(), $lien->lien('array'))) { + $count++; + } + } + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } + echo '
titrerésumélienedit
' . $item->titre() . '' . $item->intro() . '' . $count . 'modifier
'; + } + } + public function aside($list) { if ($this->session() >= 2) { diff --git a/class/class.app.php b/class/class.app.php index 5891cae..961e51c 100644 --- a/class/class.app.php +++ b/class/class.app.php @@ -67,20 +67,25 @@ class App } - public function getlister() + public function getlister(array $selection, $tri) { $list = []; + if (is_array($selection) && is_string($tri) && strlen($tri) < 12) { - $req = $this->bdd->query('SELECT * FROM art ORDER BY id'); - while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) { - $list[] = new Art($donnees); + $selection = implode(", ", $selection); + + $select = 'SELECT ' . $selection . ' FROM art ORDER BY ' . $tri; + $req = $this->bdd->query($select); + while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) { + $list[] = new Art($donnees); + } + return $list; } - return $list; } public function lister() { - $req = $this->bdd->query('SELECT * FROM art ORDER BY id'); + $req = $this->bdd->query(' SELECT * FROM art ORDER BY id '); $donnees = $req->fetchAll(PDO::FETCH_ASSOC); return $donnees; @@ -102,12 +107,32 @@ class App return (bool)$donnees['COUNT(*)']; } + public function introlien(Art $art) + { + $html = $art->html('html'); + foreach ($art->lien('array') as $id) { + $title = ''; + foreach ($this->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); + } + return $html; + } + 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 WHERE id = :id'); + var_dump($now); + + $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 WHERE id = :id'); $q->bindValue(':id', $art->id()); $q->bindValue(':titre', $art->titre()); diff --git a/class/class.art.php b/class/class.art.php index 0e87b6c..cc383d0 100644 --- a/class/class.art.php +++ b/class/class.art.php @@ -68,24 +68,6 @@ a:hover {}'); public function updatelien() { - function search($haystack, $debut, $fin) - { - $list = []; - - $indexdebut = strpos($haystack, $debut); - if ($indexdebut !== false) { - $indexdebut += strlen($debut); - $indexfin = strpos($haystack, $fin, $indexdebut); - if ($indexfin !== false) { - //$indexfin -= strlen($fin); - array_push($list, substr($haystack, $indexdebut, $indexfin - $indexdebut)); - $haystack = substr($haystack, $indexfin); - $list = array_merge($list, search($haystack, $debut, $fin)); - } - } - return $list; - - } $this->lien = search($this->html('md'), self::DEBUT, self::FIN); } @@ -153,8 +135,6 @@ a:hover {}'); } elseif ($option == 'html') { $html = Markdown::defaultTransform($this->html); $htmla = str_replace('href="http', ' class="external" target="_blank" href="http', $html); - - $htmla = str_replace('class="b"', ' target="_blank" ', $htmla); $htmlmedia = str_replace('src="/', 'src="../media/', $htmla); return $htmlmedia; } diff --git a/fn/fn.php b/fn/fn.php index 79007ef..b075d57 100644 --- a/fn/fn.php +++ b/fn/fn.php @@ -34,5 +34,23 @@ function head($title) } +function search($haystack, $debut, $fin) +{ + $list = []; + + $indexdebut = strpos($haystack, $debut); + if ($indexdebut !== false) { + $indexdebut += strlen($debut); + $indexfin = strpos($haystack, $fin, $indexdebut); + if ($indexfin !== false) { + array_push($list, substr($haystack, $indexdebut, $indexfin - $indexdebut)); + $haystack = substr($haystack, $indexfin); + $list = array_merge($list, search($haystack, $debut, $fin)); + } + } + return $list; + +} + ?> diff --git a/public/css/style.css b/public/css/style.css index 325a0ae..7fb75c0 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -75,6 +75,11 @@ section input, textarea, select { border-style: unset; } +article { + position: relative; + z-index: 100; +} + #html{ height: 1000px; } diff --git a/public/w/index.php b/public/w/index.php index 0a153b0..9c4ee32 100644 --- a/public/w/index.php +++ b/public/w/index.php @@ -34,7 +34,7 @@ if (isset($_POST['action'])) { if ($app->exist($_GET['id'])) { $art = new Art($_POST); $app->update($art); - header('Location: ?id=' . $art->id() . '&edit=1'); + //header('Location: ?id=' . $art->id() . '&edit=1'); } break; @@ -94,7 +94,6 @@ $aff->nav($app); if (isset($_GET['id'])) { - if ($app->exist($_GET['id'])) { $art = $app->get($_GET['id']); @@ -103,7 +102,7 @@ if (isset($_GET['id'])) { $aff->edit($art); $aff->aside($app->lister()); } else { - $aff->lecture($art); + $aff->lecture($art, $app); } } else { @@ -126,10 +125,20 @@ if (isset($_GET['id'])) { } } elseif (isset($_GET['tag'])) { echo '

' . $_GET['tag'] . '

'; - $aff->tag($app->getlister(), $_GET['tag']); + $aff->tag($app->getlister(['id', 'titre', 'intro', 'tag'], 'id'), $_GET['tag']); + +} elseif (isset($_GET['lien'])) { + echo '

' . $_GET['lien'] . '

'; + $aff->lien($app->getlister(['id', 'titre', 'intro', 'lien'], 'id'), $_GET['lien']); } else { - $aff->home($app->lister()); + if (isset($_GET['tri'])) { + $tri = strip_tags($_GET['tri']); + } else { + $tri = 'id'; + } + $aff->search(); + $aff->home2table($app->getlister(['id', 'titre', 'intro', 'lien'], $tri)); } echo ''; -- cgit v1.2.3