aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2018-04-17 15:46:41 +0200
committervincent-peugnet <v.peugnet@free.fr>2018-04-17 15:46:41 +0200
commit5a6d7248fcbc3f88fe66f3b52d51087698c3e6ba (patch)
tree086d3542a0ec7c3b0e8aeb0ae5d62d7067409bb3
parent899a4bd60570ff9b77fabe89dd4902f09bbdeb47 (diff)
downloadwcms-5a6d7248fcbc3f88fe66f3b52d51087698c3e6ba.tar.gz
wcms-5a6d7248fcbc3f88fe66f3b52d51087698c3e6ba.zip
title intro lien
-rw-r--r--class/class.aff.php96
-rw-r--r--class/class.app.php39
-rw-r--r--class/class.art.php20
-rw-r--r--fn/fn.php18
-rw-r--r--public/css/style.css5
-rw-r--r--public/w/index.php19
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 '<span class="alert"><h4>cet article est privé</h4></span>';
@@ -46,7 +46,7 @@ class Aff
<section>
<h1><?= $art->titre() ?></h1>
<h6><?= $art->soustitre() ?></h6>
- <article><?= $art->html('html') ?></article>
+ <article><?= $app->introlien($art) ?></article>
</section>
<?php
@@ -118,7 +118,7 @@ public function head($title)
- public function home($list)
+ public function search()
{
?>
<form action="./" method="get">
@@ -127,25 +127,29 @@ public function head($title)
</form>
<?php
- if ($this->session() == 2) {
- echo '<ul>';
- foreach ($list as $item) {
- echo '<li><a href="?id=' . $item['id'] . '">' . $item['titre'] . '</a> - ' . $item['intro'];
+ }
+
+ public function tag($getlist, $tag)
+ {
+ echo '<ul>';
+ foreach ($getlist as $item) {
+ if (in_array($tag, $item->tag('array'))) {
+ echo '<li><a href="?id=' . $item->id() . '">' . $item->titre() . '</a> - ' . $item->intro();
if ($this->session() >= 2) {
- echo ' - <a href="?id=' . $item['id'] . '&edit=1">modifier</a></li>';
+ echo ' - <a href="?id=' . $item->id() . '&edit=1">modifier</a></li>';
} else {
echo '</li>';
}
}
- echo ' </ul> ';
}
+ echo ' </ul> ';
}
- public function tag($getlist, $tag)
+ public function lien($getlist, $lien)
{
echo '<ul>';
foreach ($getlist as $item) {
- if (in_array($tag, $item->tag('array'))) {
+ if (in_array($lien, $item->lien('array'))) {
echo '<li><a href="?id=' . $item->id() . '">' . $item->titre() . '</a> - ' . $item->intro();
if ($this->session() >= 2) {
echo ' - <a href="?id=' . $item->id() . '&edit=1">modifier</a></li>';
@@ -157,6 +161,76 @@ public function head($title)
echo ' </ul> ';
}
+ public function home($getlist)
+ {
+ echo '<ul>';
+ foreach ($getlist as $item) {
+ echo '<li><a href="?id=' . $item->id() . '">' . $item->titre() . '</a> - ' . $item->intro();
+ if ($this->session() >= 2) {
+ echo ' - <a href="?id=' . $item->id() . '&edit=1">modifier</a></li>';
+ } else {
+ echo '</li>';
+ }
+
+ }
+ echo ' </ul> ';
+ }
+
+ public function dump($getlist)
+ {
+ echo '<ul>';
+ foreach ($getlist as $item) {
+ echo '<li>';
+ var_dump($item);
+ echo '</li>';
+ }
+ echo ' </ul> ';
+ }
+
+ public function home2($getlist)
+ {
+ if ($this->session() >= 2) {
+ echo '<ul>';
+ foreach ($getlist as $item) {
+ $count = 0;
+
+ foreach ($getlist as $lien) {
+ if (in_array($item->id(), $lien->lien('array'))) {
+ $count++;
+ }
+ }
+ echo '<li><a href="?id=' . $item->id() . '">' . $item->titre() . '</a> - ' . $item->intro();
+ echo ' - <a href="?lien=' . $item->id() . '">' . $count . '</a> ';
+ echo ' - <a href="?id=' . $item->id() . '&edit=1">modifier</a></li>';
+ }
+ echo ' </ul> ';
+ }
+ }
+
+ public function home2table($getlist)
+ {
+ if ($this->session() >= 2) {
+ echo '<table>';
+ echo '<tr><th>titre</th><th>résumé</th><th>lien</th><th>edit</th></tr>';
+ foreach ($getlist as $item) {
+ $count = 0;
+
+ foreach ($getlist as $lien) {
+ if (in_array($item->id(), $lien->lien('array'))) {
+ $count++;
+ }
+ }
+ echo '<tr>';
+ echo '<td><a href="?id=' . $item->id() . '">' . $item->titre() . '</a></td>';
+ echo '<td>' . $item->intro() . '</td>';
+ echo '<td><a href="?lien=' . $item->id() . '">' . $count . '</a></td>';
+ echo '<td><a href="?id=' . $item->id() . '&edit=1">modifier</a></td>';
+ echo '</tr>';
+ }
+ echo ' <table> ';
+ }
+ }
+
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 '<h4>' . $_GET['tag'] . '</h4>';
- $aff->tag($app->getlister(), $_GET['tag']);
+ $aff->tag($app->getlister(['id', 'titre', 'intro', 'tag'], 'id'), $_GET['tag']);
+
+} elseif (isset($_GET['lien'])) {
+ echo '<h4>' . $_GET['lien'] . '</h4>';
+ $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 '</body>';