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 ----------- 3 files changed, 117 insertions(+), 38 deletions(-) (limited to 'class') 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; } -- cgit v1.2.3