diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2018-07-31 18:29:53 +0200 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2018-07-31 18:29:53 +0200 |
commit | e9b2ca7c06875069fa03379258625490872cc33d (patch) | |
tree | 3af763a303f07c75d63ca9801c98e58fa9052628 /class | |
parent | c36f25e76f40c6fdd6e02f92713d9c1241ed0a79 (diff) | |
download | wcms-e9b2ca7c06875069fa03379258625490872cc33d.tar.gz wcms-e9b2ca7c06875069fa03379258625490872cc33d.zip |
W 2.4 graphic update table sort engine update
Diffstat (limited to 'class')
-rw-r--r-- | class/class.w.aff.php | 417 | ||||
-rw-r--r-- | class/class.w.app.php | 158 | ||||
-rw-r--r-- | class/class.w.art.php | 94 | ||||
-rw-r--r-- | class/class.w.opt.php | 207 |
4 files changed, 660 insertions, 216 deletions
diff --git a/class/class.w.aff.php b/class/class.w.aff.php index cacec99..9f1177a 100644 --- a/class/class.w.aff.php +++ b/class/class.w.aff.php @@ -58,12 +58,11 @@ class Aff public function lecture(Art $art, App $app) { - echo '<div class="lecture">'; if ($art->secure() == 1) { - echo '<span class="alert"><h4>cet article est privé</h4></span>'; + echo '<span class="alert">This article is private</span>'; } if ($art->secure() == 2) { - echo "<span class=\"alert\"><h4>cet article n'est pas publié</h4></span>"; + echo "<span class=\"alert\">This article is not published yet</span>"; } if ($app->session() >= $art->secure()) { @@ -85,17 +84,14 @@ class Aff } <?= $art->csstemplate($app) ?> </style> - <section> <header> <h1><?= $art->titre() ?></h1> <h6><?= $art->soustitre() ?></h6> </header> <article><?= $art->html($app) ?></article> - </section> <?php } - echo '</div>'; } public function edit(Art $art, App $app, $list) @@ -103,45 +99,50 @@ class Aff if ($app->session() >= self::$edit) { ?> - <div class="edit"> - <section> - <form action="?id=<?= $art->id() ?>" method="post"> - <details close> + + <form action="?id=<?= $art->id() ?>" method="post" id="artedit"> + <textarea style="background-color: <?= $art->couleurbkg() ?>; color: <?= $art->couleurtext() ?>;" name="html" id="html" spellcheck="true" autofocus><?= $art->md(); ?></textarea> + + + <details id="editinfo" close> <summary>Infos</summary> - <label for="titre">Titre :</label> - <input type="text" name="titre" id="titre" value="<?= $art->titre(); ?>"> - <label for="soustitre">Sous-titre :</label> - <input type="text" name="soustitre" id="soustitre" value="<?= $art->soustitre(); ?>"> - <label for="intro">Introduction :</label> - <input type="text" name="intro" id="intro" value="<?= $art->intro(); ?>"> - <label for="tag">Tag(s) :</label> - <input type="text" name="tag" id="tag" value="<?= $art->tag('string'); ?>"> - <label for="secure">Niveau de sécurité :</label> - <select name="secure" id="secure"> - <option value="0" <?= $art->secure() == 0 ? 'selected' : '' ?>>0</option> - <option value="1" <?= $art->secure() == 1 ? 'selected' : '' ?>>1</option> - <option value="2" <?= $art->secure() == 2 ? 'selected' : '' ?>>2</option> - </select> + <fieldset> + <label for="titre">Titre :</label> + <input type="text" name="titre" id="titre" value="<?= $art->titre(); ?>"> + <label for="soustitre">Sous-titre :</label> + <input type="text" name="soustitre" id="soustitre" value="<?= $art->soustitre(); ?>"> + <label for="intro">Introduction :</label> + <input type="text" name="intro" id="intro" value="<?= $art->intro(); ?>"> + <label for="tag">Tag(s) :</label> + <input type="text" name="tag" id="tag" value="<?= $art->tag('string'); ?>"> + <label for="secure">Niveau de sécurité :</label> + <select name="secure" id="secure"> + <option value="0" <?= $art->secure() == 0 ? 'selected' : '' ?>>0</option> + <option value="1" <?= $art->secure() == 1 ? 'selected' : '' ?>>1</option> + <option value="2" <?= $art->secure() == 2 ? 'selected' : '' ?>>2</option> + </select> + </fieldset> </details> - <details close> + <details id="editcss" close> <summary>CSS</summary> + <fieldset> <label for="template">Template :</label> - <select name="template" id="template"> - <?php - if ($art->template() == 'NULL') { - echo '<option value="" selected >Sans template</option>'; - } else { - echo '<option value="" >sans template</option>'; - } - foreach ($list as $item) { - - if ($item->id() == $art->template()) { - echo '<option value="' . $item->id() . '" selected >' . $item->titre() . '</option>'; - } else { - echo '<option value="' . $item->id() . '">' . $item->titre() . '</option>'; - } - } - ?> + <select name="template" id="template"> + <?php + if ($art->template() == 'NULL') { + echo '<option value="" selected >Sans template</option>'; + } else { + echo '<option value="" >sans template</option>'; + } + foreach ($list as $item) { + + if ($item->id() == $art->template()) { + echo '<option value="' . $item->id() . '" selected >' . $item->titre() . '</option>'; + } else { + echo '<option value="' . $item->id() . '">' . $item->titre() . '</option>'; + } + } + ?> </select> <label for="css">Styles CSS :</label> <textarea name="css" id="css"><?= $art->css(); ?></textarea> @@ -153,20 +154,17 @@ class Aff <input type="color" name="couleurlien" value="<?= $art->couleurlien() ?>" id="couleurlien"> <label for="couleurlienblank">Couleur des liens externes :</label> <input type="color" name="couleurlienblank" value="<?= $art->couleurlienblank() ?>" id="couleurlienblank"> + </fieldset> </details> - <details open> - <summary>Contenu</summary> - <textarea name="html" id="html" ><?= $art->md(); ?></textarea> - </details> + <input type="hidden" name="datecreation" value="<?= $art->datecreation('string'); ?>"> <input type="hidden" name="id" value="<?= $art->id() ?>"> - </section> - <div class="submit"> - <input type="submit" name="action" value="update"> - <input type="submit" name="action" value="delete" onclick="confirmSubmit(event, 'Suppression de cet article')"> - </form> + </form> + <div id="submit"> + <input type="submit" name="action" value="update" accesskey="s" onclick="document.getElementById('artedit').submit();" form="artedit"> + <input type="submit" name="action" value="delete" onclick="confirmSubmit(event, 'Suppression de cet article', 'artedit')" form="artedit"> </div> - </div> + <?php @@ -174,30 +172,34 @@ class Aff } + + public function copy(Art $art, $list) { ?> - <div class="copy"> - <form action="?id=<?= $art->id() ?>&edit=1" method="post"> - <input type="hidden" name="action" value="copy"> - <input type="hidden" name="id" value="<?= $art->id() ?>"> - <select name="copy"> - <?php - foreach ($list as $item) { - echo '<option value="' . $item->id() . '">' . $item->titre() . '</option>'; - } - echo '</select>'; - ?> - <label for="checkcss">CSS</label> - <input type="checkbox" id="checkcss" name="css" value="true"> - <label for="checkcolor">Color</label> - <input type="checkbox" id="checkcolor" name="color" value="true"> - <label for="checkhtml">HTML</label> - <input type="checkbox" id="checkhtml" name="html" value="true"> - <label for="checktemplate">template</label> - <input type="checkbox" id="checktemplate" name="template" value="true"> - <input type="submit" value="copy" onclick="confirmSubmit(event, 'Ecraser ces valeurs')"> - </form> + <div id="copy"> + <form action="?id=<?= $art->id() ?>&edit=1" method="post"> + <fieldset> + <input type="hidden" name="action" value="copy"> + <input type="hidden" name="id" value="<?= $art->id() ?>"> + <select name="copy" required> + <?php + foreach ($list as $item) { + echo '<option value="' . $item->id() . '">' . $item->id() . '</option>'; + } + echo '</select>'; + ?> + <label for="checkcss">CSS</label> + <input type="checkbox" id="checkcss" name="css" value="true"> + <label for="checkcolor">Color</label> + <input type="checkbox" id="checkcolor" name="color" value="true"> + <label for="checkhtml">HTML</label> + <input type="checkbox" id="checkhtml" name="html" value="true"> + <label for="checktemplate">template</label> + <input type="checkbox" id="checktemplate" name="template" value="true"> + <input type="submit" value="copy" onclick="confirmSubmit(event, 'Ecraser ces valeurs')"> + </fieldset> + </form> </div> <?php @@ -228,8 +230,7 @@ public function arthead(Art $art, $cssread = '', $edit = 0) <meta name="viewport" content="width=device-width" /> <link rel="shortcut icon" href="../media/logo.png" type="image/x-icon"> <link href="/css/stylebase.css" rel="stylesheet" /> - <link href="/css/stylew.css" rel="stylesheet" /> - <?= $edit == 0 ? '<link href="/css/lecture/' . $cssread . '" rel="stylesheet" />' : '' ?> + <?= $edit == 0 ? '<link href="/css/lecture/' . $cssread . '" rel="stylesheet" />' : '<link href="/css/styleedit.css" rel="stylesheet" />' ?> <title><?= $edit == 1 ? '✏' : '' ?> <?= $art->titre() ?></title> <script src="../rsc/js/app.js"></script> </head> @@ -243,132 +244,206 @@ public function arthead(Art $art, $cssread = '', $edit = 0) public function search() { ?> + <div id="search"> <form action="./" method="get"> <input type="text" name="id" id="id" placeholder="identifiant article" required> <input type="submit" value="accéder"> - </form> - <?php + </form> + </div> + <?php - } +} - public function tag($getlist, $tag, $app) - { - echo '<div class="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 ($app->session() >= $app::EDITOR) { - echo ' - <a href="?id=' . $item->id() . '&edit=1">modifier</a></li>'; - } else { - echo '</li>'; - } +public function tag($getlist, $tag, $app) +{ + echo '<div class="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 ($app->session() >= $app::EDITOR) { + echo ' - <a href="?id=' . $item->id() . '&edit=1">modifier</a></li>'; + } else { + echo '</li>'; } } - echo ' </ul> '; - echo ' </div> '; } + echo ' </ul> '; + echo ' </div> '; +} - public function lien($getlist, $lien, App $app) - { - echo '<div class="lien">'; - echo '<ul>'; - foreach ($getlist as $item) { - if (in_array($lien, $item->lien('array'))) { - echo '<li><a href="?id=' . $item->id() . '">' . $item->titre() . '</a> - ' . $item->intro(); - if ($app->session() >= $app::EDITOR) { - echo ' - <a href="?id=' . $item->id() . '&edit=1">modifier</a> - <a href="?lien=' . $item->id() . '">liens</a></li>'; - } else { - echo '</li>'; - } +public function lien($getlist, $lien, App $app) +{ + echo '<div class="lien">'; + echo '<ul>'; + foreach ($getlist as $item) { + if (in_array($lien, $item->lien('array'))) { + echo '<li><a href="?id=' . $item->id() . '">' . $item->titre() . '</a> - ' . $item->intro(); + if ($app->session() >= $app::EDITOR) { + echo ' - <a href="?id=' . $item->id() . '&edit=1">modifier</a> - <a href="?lien=' . $item->id() . '">liens</a></li>'; + } else { + echo '</li>'; } } - echo ' </ul> '; - echo ' </div> '; } + echo ' </ul> '; + echo ' </div> '; +} - public function dump($getlist) - { - echo '<ul>'; +public function dump($getlist) +{ + echo '<ul>'; + foreach ($getlist as $item) { + echo '<li>'; + var_dump($item); + echo '</li>'; + } + echo ' </ul> '; +} + +public function header() +{ + echo '<header>'; + $this->search(); + echo '</header>'; +} + + +public function home2table(App $app, $getlist) +{ + + + if ($app->session() >= $app::EDITOR) { + echo '<table id="home2table">'; + echo '<tr><th>title</th><th>tag</th><th>summary</th><th>↘ to</th><th>↗ from</th><th>last modification</th><th>date of creation</th><th>privacy</th><th>⚙ edit</th></tr>'; foreach ($getlist as $item) { - echo '<li>'; - var_dump($item); - echo '</li>'; + echo '<tr>'; + echo '<td><a href="?id=' . $item->id() . '">' . $item->titre() . '</a></td>'; + echo '<td>' . $item->tag('sort') . '</td>'; + echo '<td>' . $item->intro() . '</td>'; + echo '<td><a href="?lien=' . $item->id() . '">' . $item->liento('sort') . '</a></td>'; + echo '<td>' . $item->lien('sort') . '</td>'; + echo '<td>' . $item->datemodif('hrdi') . '</td>'; + echo '<td>' . $item->datecreation('hrdi') . '</td>'; + echo '<td>' . $item->secure('string') . '</td>'; + echo '<td><a href="?id=' . $item->id() . '&edit=1">edit</a></td>'; + echo '</tr>'; } - echo ' </ul> '; + echo ' </table> '; } +} +public function option(App $app, Opt $opt) +{ + if ($app->session() >= $app::EDITOR) { + echo '<div id="options"><form action="./" method="get" >'; - public function home2table(App $app, $getlist) - { - echo '<div class="home">'; - echo '<section>'; - echo '<h1>W</h1>'; - $this->search(); - if ($app->session() >= $app::EDITOR) { - echo '<h1>Home</h1>'; - echo '<table>'; - echo '<tr><th><a href="./?tri=titre">titre</a></th><th>résumé</th><th>lien from</th><th>lien to</th><th><a href="./?tri=datemodif&desc=DESC">dernière modif</a></th><th><a href="./?tri=datecreation&desc=DESC">date de création</a></th><th>edit</th></tr>'; - 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 '<tr>'; - echo '<td><a href="?id=' . $item->id() . '">' . $item->titre() . '</a></td>'; - echo '<td>' . $item->intro() . '</td>'; - echo '<td>' . $lienfrom . '</td>'; - echo '<td><a href="?lien=' . $item->id() . '">' . $liento . '</a></td>'; - echo '<td>' . $item->datemodif('hrdi') . '</td>'; - echo '<td>' . $item->datecreation('hrdi') . '</td>'; - echo '<td><a href="?id=' . $item->id() . '&edit=1">modifier</a></td>'; - echo '</tr>'; - } - echo ' </table> '; + + $this->optiontag($opt); + $this->optionprivacy($opt); + $this->optionsort($opt); + + + + + echo '<input type=submit value="show">'; + + echo '</form></div>'; + + } + +} + +public function optiontag(Opt $opt) +{ + + echo '<fieldset><legend>Tag</legend><ul>'; + foreach ($opt->taglist() as $tagor => $count) { + if (in_array($tagor, $opt->tagor())) { + echo '<li><input type="checkbox" name="tagor[]" id="' . $tagor . '" value="' . $tagor . '" checked /><label for="' . $tagor . '">' . $tagor . ' (' . $count . ')</label></li>'; + } else { + echo '<li><input type="checkbox" name="tagor[]" id="' . $tagor . '" value="' . $tagor . '" /><label for="' . $tagor . '">' . $tagor . ' (' . $count . ')</label></li>'; } - echo '</section>'; - echo ' </div> '; } + echo '</ul></fieldset>'; - public function aside(App $app) - { - if ($app->session() >= $app::EDITOR) { - echo '<aside><ul>'; - foreach ($app->lister() as $item) { - echo '<li><a href="?id=' . $item['id'] . '&edit=1">' . $item['titre'] . '</a> - <code>[' . $item['titre'] . '](?id=' . $item['id'] . ')</code>'; +} +public function optionprivacy(Opt $opt) +{ + echo '<fieldset><legend>Privacity</legend><ul>'; + echo '<li><input type="radio" id="4" name="secure" value="4" ' . ($opt->secure() == 4 ? "checked" : "") . ' /><label for="4">all</label></li>'; + echo '<li><input type="radio" id="2" name="secure" value="2" ' . ($opt->secure() == 2 ? "checked" : "") . ' /><label for="2">not published</label></li>'; + echo '<li><input type="radio" id="1" name="secure" value="1" ' . ($opt->secure() == 1 ? "checked" : "") . ' /><label for="1">private</label></li>'; + echo '<li><input type="radio" id="0" name="secure" value="0" ' . ($opt->secure() == 0 ? "checked" : "") . ' /><label for="0">public</label></li>'; + echo '</ul></fieldset>'; +} - } - echo ' </ul></aside> '; +public function optionsort(Opt $opt) +{ + echo '<fieldset><legend>Sort</legend>'; + echo '<select name="sortby" id="sortby">'; + foreach ($opt->col('array') as $key => $col) { + echo '<option value="' . $col . '" ' . ($opt->sortby() == $col ? "selected" : "") . '>' . $col . '</option>'; + } + echo '</select>'; + echo '<input type="radio" id="asc" name="order" value="1" ' . ($opt->order() == '1' ? "checked" : "") . ' /><label for="asc">ascending</label>'; + echo '<input type="radio" id="desc" name="order" value="-1" ' . ($opt->order() == '-1' ? "checked" : "") . ' /><label for="desc">descending</label>'; + + echo '</fieldset>'; + +} + +public function map(App $app, $url) +{ + echo '<div class="home"><section>'; + + $map = ""; + $link = ""; + foreach ($app->getlister(['id', 'lien']) as $item) { + foreach ($item->lien('array') as $lien) { + $map = $map . ' </br> ' . $item->id() . ' --> ' . $lien; } + $link = $link . '</br>click ' . $item->id() . ' "' . $url . '/w/?id=' . $item->id() . '"'; } + echo $map; + echo $link; - public function nav($app) - { - echo '<nav>'; - echo $app->session(); - echo '</br>'; + echo '</div></section>'; +} - echo '<a class="button" href="?">home</a>'; +public function aside(App $app) +{ + if ($app->session() >= $app::EDITOR) { + echo '<div id="linklist">Links<div id="roll"><ul>'; + foreach ($app->lister() as $item) { + echo '<li><a href="?id=' . $item['id'] . '&edit=1">' . $item['titre'] . '</a> - <input type="text" value="[' . $item['titre'] . '](?id=' . $item['id'] . ')">'; - if ($app->session() == $app::FREE) { - if (isset($_GET['id'])) { - echo '<form action="./?id=' . $_GET['id'] . '" method="post">'; - } else { - echo '<form action="." method="post">'; - } - ?> + + } + echo ' </ul></div></div> '; + } +} + +public function nav($app) +{ + echo '<nav>'; + echo $app->session(); + echo '<div id="menu">'; + + echo '<a class="button" href="?">home</a>'; + + if ($app->session() == $app::FREE) { + if (isset($_GET['id'])) { + echo '<form action="./?id=' . $_GET['id'] . '" method="post">'; + } else { + echo '<form action="." method="post">'; + } + ?> <input type="hidden" name="action" value="login"> - <input type="password" name="pass" id="pass" placeholder="password"> + <input type="password" name="pass" id="loginpass" placeholder="password"> <input type="submit" value="login"> </form> <?php @@ -402,7 +477,11 @@ public function search() } } + + + ?> + </div> </nav> <?php diff --git a/class/class.w.app.php b/class/class.w.app.php index d178b52..efb8986 100644 --- a/class/class.w.app.php +++ b/class/class.w.app.php @@ -142,15 +142,54 @@ class App } - public function getlister(array $selection = ['id', 'titre'], $tri = 'id', $desc = 'ASC') + + + public function update(Art $art) { + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + $art->updatelien(); + + $q = $this->bdd->prepare('UPDATE ' . $this->arttable . ' 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(); + } + + + + + //____________________________________________ L S T ______________________________ + + + + public function getlister(array $selection = ['id'], array $opt = []) + { + $default = ['tri' => 'id', 'desc' => 'DESC']; + $opt = array_update($default, $opt); + $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)) { + $option = ['datecreation', 'titre', 'id', 'intro', 'datemodif', 'tag', 'secure']; + if (is_array($selection) && is_string($opt['tri']) && strlen($opt['tri']) < 16 && is_string($opt['desc']) && strlen($opt['desc']) < 5 && in_array($opt['tri'], $option)) { $selection = implode(", ", $selection); - $select = 'SELECT ' . $selection . ' FROM ' . $this->arttable . ' ORDER BY ' . $tri . ' ' . $desc; + $select = 'SELECT ' . $selection . ' FROM ' . $this->arttable . ' ORDER BY ' . $opt['tri'] . ' ' . $opt['desc']; $req = $this->bdd->query($select); while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) { $list[] = new Art($donnees); @@ -159,13 +198,95 @@ class App } } + + + + + + public function getlisteropt(Opt $opt) + { + + + $artlist = []; + + $select = 'SELECT ' . $opt->col('string') . ' FROM ' . $this->arttable; + $req = $this->bdd->query($select); + while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) { + $artlist[] = new Art($donnees); + } + return $artlist; + + } + + public function listcalclien(&$artlist) + { + foreach ($artlist as $art) { + $art->calcliento($artlist); + } + } + + public function artcompare($art1, $art2, $method = 'id', $order = 1) + { + $result = ($art1->$method('sort') <=> $art2->$method('sort')); + return $result * $order; + + } + + public function buildsorter($sortby, $order) + { + return function ($art1, $art2) use ($sortby, $order) { + $result = $this->artcompare($art1, $art2, $sortby, $order); + return $result; + }; + } + + + + public function artlistsort(&$artlist, $sortby, $order = 1) + { + return usort($artlist, $this->buildsorter($sortby, $order)); + } + + + + + + + public function filtertagor(array $artlist, array $tagchecked) + { + + $filteredlist = []; + foreach ($artlist as $art) { + if (!empty(array_intersect($art->tag('array'), $tagchecked))) { + $filteredlist[] = $art->id(); + } elseif (empty($tagchecked)) { + $filteredlist[] = $art->id(); + } + } + return $filteredlist; + } + + public function filtersecure(array $artlist, $secure) + { + $filteredlist = []; + foreach ($artlist as $art) { + if ($art->secure() == intval($secure)) { + $filteredlist[] = $art->id(); + } elseif (intval($secure) >= 4) { + $filteredlist[] = $art->id(); + } + } + return $filteredlist; + } + + public function lister() { $req = $this->bdd->query(' SELECT * FROM ' . $this->arttable . ' ORDER BY id '); $donnees = $req->fetchAll(PDO::FETCH_ASSOC); + $req->closeCursor(); return $donnees; - $req->closeCursor(); } @@ -183,32 +304,9 @@ class App return (bool)$donnees['COUNT(*)']; } - public function update(Art $art) - { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - $art->updatelien(); - - $q = $this->bdd->prepare('UPDATE ' . $this->arttable . ' 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()); + + // __________________________________________ T A B L E ________________________________________________________ - $q->execute(); - } public function tableexist($dbname, $tablename) { diff --git a/class/class.w.art.php b/class/class.w.art.php index 9640470..d757e0d 100644 --- a/class/class.w.art.php +++ b/class/class.w.art.php @@ -20,6 +20,7 @@ class Art private $couleurlien; private $couleurlienblank; private $lien; + private $liento; private $template; const LEN = 255; @@ -59,8 +60,7 @@ class Art $this->setintro('resumé'); $this->settag('sans tag,'); $this->setdatecreation($now); - $this->setcss('section {} -a:hover {}'); + $this->setcss(''); $this->sethtml('contenu'); $this->setsecure(2); $this->setcouleurtext('#000000'); @@ -74,27 +74,50 @@ a:hover {}'); public function updatelien() { $this->lien = search($this->md(), self::DEBUT, self::FIN); + } + public static function classvarlist() + { + $classvarlist = []; + foreach (get_class_vars(__class__) as $var => $default) { + $classvarlist[] = $var; + } + return ['artvarlist' => $classvarlist]; } + + + + public function calcliento($getlist) + { + $liento = []; + foreach ($getlist as $lien) { + if (in_array($this->id(), $lien->lien('array'))) { + $liento[] = $lien->id(); + } + } + $this->setliento($liento); + } + + // _____________________________________________________ G E T ____________________________________________________ - public function id() + public function id($type = 'string') { return $this->id; } - public function titre() + public function titre($type = 'string') { return $this->titre; } - public function soustitre() + public function soustitre($type = 'string') { return $this->soustitre; } - public function intro() + public function intro($type = 'string') { return $this->intro; } @@ -102,18 +125,19 @@ a:hover {}'); public function tag($option) { if ($option == 'string') { - $tag = implode(", ", $this->tag); + return implode(", ", $this->tag); } elseif ($option == 'array') { - $tag = $this->tag; + return $this->tag; + } elseif ($option == 'sort') { + return count($this->tag); } - return $tag; } public function datecreation($option) { if ($option == 'string') { return $this->datecreation->format('Y-m-d H:i:s'); - } elseif ($option == 'date') { + } elseif ($option == 'date' || $option == 'sort') { return $this->datecreation; } elseif ($option == 'hrdi') { $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); @@ -126,7 +150,7 @@ a:hover {}'); { if ($option == 'string') { return $this->datemodif->format('Y-m-d H:i:s'); - } elseif ($option == 'date') { + } elseif ($option == 'date' || $option == 'sort') { return $this->datemodif; } elseif ($option == 'hrdi') { $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); @@ -134,7 +158,7 @@ a:hover {}'); } } - public function css() + public function css($type = 'string') { return $this->css; } @@ -166,7 +190,7 @@ a:hover {}'); foreach ($this->lien('array') as $id) { $title = "Cet article n'existe pas encore"; - foreach ($app->getlister(['id', 'intro'], 'id') as $item) { + foreach ($app->getlister(['id', 'intro']) as $item) { if ($item->id() == $id) { $title = $item->intro(); } @@ -185,9 +209,16 @@ a:hover {}'); } - public function secure() + public function secure($type = 'int') { - return $this->secure; + if ($type == 'string') { + if ($this->secure == 0) $secure = 'public'; + if ($this->secure == 1) $secure = 'private'; + if ($this->secure == 2) $secure = 'not published'; + return $secure; + } else { + return $this->secure; + } } public function couleurtext() @@ -216,12 +247,27 @@ a:hover {}'); $lien = implode(", ", $this->lien); } elseif ($option == 'array') { $lien = $this->lien; + } elseif ($option == 'sort') { + return count($this->lien); } return $lien; } - public function template() + public function liento($option) + { + if ($option == 'string') { + $liento = implode(", ", $this->liento); + } elseif ($option == 'array') { + $liento = $this->liento; + } elseif ($option == 'sort') { + return count($this->liento); + } + return $liento; + + } + + public function template($type = 'string') { return $this->template; } @@ -229,6 +275,7 @@ a:hover {}'); + // _____________________________________________________ S E T ____________________________________________________ public function setid($id) @@ -263,7 +310,11 @@ a:hover {}'); { if (strlen($tag) < self::LEN and is_string($tag)) { $tag = strip_tags(trim(strtolower($tag))); - $taglist = explode(", ", $tag); + $tag = str_replace('*', '', $tag); + $tag = str_replace(' ', '', $tag); + + $taglist = explode(",", $tag); + $taglist = array_filter($taglist); $this->tag = $taglist; } } @@ -350,6 +401,15 @@ a:hover {}'); } } + public function setliento($liento) + { + if (is_array($liento)) { + $this->liento = $liento; + } + + + } + public function settemplate($template) { $template = strip_tags($template); diff --git a/class/class.w.opt.php b/class/class.w.opt.php new file mode 100644 index 0000000..76b3905 --- /dev/null +++ b/class/class.w.opt.php @@ -0,0 +1,207 @@ +<?php +class Opt +{ + private $sortby = 'id'; + private $order = '1'; + private $tagor = []; + private $secure = 4; + private $liento = ['min' => '0', 'max' => '0']; + private $lienfrom = ['min' => '0', 'max' => '0']; + private $col = ['id']; + private $taglist = []; + + private $artvarlist; + + public function __construct(array $donnees = []) + { + $this->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() + { + $varlist = get_class_vars(__class__); + + foreach ($varlist as $var => $default) { + $method = 'set' . $var; + $this->$method($default); + } + } + + public function dump() + { + var_dump($this); + } + + + + + + // _______________________________________________ G E T _______________________________________________ + + public function sortby() + { + return $this->sortby; + } + + public function order() + { + return $this->order; + } + + public function secure() + { + return $this->secure; + } + + public function tagor($type = 'array') + { + return $this->tagor; + } + + public function liento($type = 'array') + { + return $this->liento; + } + + public function lienfrom($type = 'array') + { + return $this->lienfrom; + } + + public function col($type = 'array') + { + if ($type == 'string') { + return implode(', ', $this->col); + } else { + return ($this->col); + } + } + + public function artvarlist() + { + return $this->artvarlist; + } + + public function taglist() + { + return $this->taglist; + } + + + // __________________________________________________ S E T _____________________________________________ + + public function setsortby($sortby) + { + if (is_string($sortby) && in_array($sortby, $this->artvarlist())) { + $this->sortby = strtolower(strip_tags($sortby)); + } + } + + public function setorder($order) + { + $order = intval($order); + if (in_array($order, [-1, 0, 1])) { + $this->order = $order; + } + } + + public function settagor($tagor) + { + if (is_array($tagor)) { + // $tagorlist = []; + // foreach ($tagor as $tag) { + // if (array_key_exists($tag, $this->taglist())) { + // $tagorlist[] = $tag; + // } + // } + $this->tagor = $tagor; + } + } + + public function setsecure($secure) + { + if ($secure >= 0 && $secure <= 5) { + $this->secure = intval($secure); + } + } + + public function setliento($n0, $n1) + { + $stock = [intval($n1), intval($n2)]; + $sorted = asort($stock); + $this->liento = ['min' => $stock[0], 'max' => $stock[1]]; + } + + public function setlienfrom($n0, $n1) + { + $stock = [intval($n1), intval($n2)]; + $sorted = asort($stock); + $this->lienfrom = ['min' => $stock[0], 'max' => $stock[1]]; + } + + public function setlientomin($min) + { + $this->liento['min'] = intval($min); + } + + public function setlientomax($max) + { + $this->liento['max'] = intval($max); + } + + public function setlienfrommin($min) + { + $this->lienfrom['min'] = intval($min); + } + + public function setlienfrommax($max) + { + $this->lienfrom['max'] = intval($max); + } + + public function setcol($col) + { + if (is_array($col)) { + $this->col = array_intersect($this->artvarlist(), $col); + } + } + + public function setartvarlist(array $artvarlist) + { + $this->artvarlist = $artvarlist; + } + + public function settaglist(array $artlist) + { + $taglist = []; + foreach ($artlist as $art) { + foreach ($art->tag('array') as $tag) { + if (!array_key_exists($tag, $taglist)) { + $taglist[$tag] = 1; + } else { + $taglist[$tag]++; + } + } + } + $taglistsorted = arsort($taglist); + $this->taglist = $taglist; + } + +} + + + + +?>
\ No newline at end of file |