diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2018-10-25 20:25:05 +0200 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2018-10-25 20:25:05 +0200 |
commit | a91c916248f967da2d4218b575e665242b7c975b (patch) | |
tree | 3c767e9b7b62161253aef2d93030f4b38fd47d49 /w | |
parent | 7b2e48276b2a3ceff83c906d38077f8d0479c3df (diff) | |
download | wcms-a91c916248f967da2d4218b575e665242b7c975b.tar.gz wcms-a91c916248f967da2d4218b575e665242b7c975b.zip |
phoenixreborn\'NWY
Diffstat (limited to 'w')
-rw-r--r-- | w/class/aff.php (renamed from w/class/class.w.aff.php) | 259 | ||||
-rw-r--r-- | w/class/app.php (renamed from w/class/class.w.app.php) | 189 | ||||
-rw-r--r-- | w/class/application.php | 36 | ||||
-rw-r--r-- | w/class/art.php (renamed from w/class/class.w.art.php) | 5 | ||||
-rw-r--r-- | w/class/art2.php (renamed from w/class/class.w.art2.php) | 356 | ||||
-rw-r--r-- | w/class/config.php (renamed from w/class/class.w.config.php) | 0 | ||||
-rw-r--r-- | w/class/controller.php | 57 | ||||
-rw-r--r-- | w/class/controlleradmin.php | 23 | ||||
-rw-r--r-- | w/class/controllerart.php | 90 | ||||
-rw-r--r-- | w/class/controllerdb.php | 42 | ||||
-rw-r--r-- | w/class/controllerhome.php | 57 | ||||
-rw-r--r-- | w/class/controllermedia.php | 38 | ||||
-rw-r--r-- | w/class/media.php (renamed from w/class/class.w.media.php) | 0 | ||||
-rw-r--r-- | w/class/model.php | 17 | ||||
-rw-r--r-- | w/class/modelart.php | 283 | ||||
-rw-r--r-- | w/class/modelartlist.php | 159 | ||||
-rw-r--r-- | w/class/modelconfig.php | 39 | ||||
-rw-r--r-- | w/class/modeldb.php | 133 | ||||
-rw-r--r-- | w/class/modelhome.php | 59 | ||||
-rw-r--r-- | w/class/modelmassedit.php | 0 | ||||
-rw-r--r-- | w/class/modelmedia.php | 98 | ||||
-rw-r--r-- | w/class/modeluser.php | 63 | ||||
-rw-r--r-- | w/class/opt.php (renamed from w/class/class.w.opt.php) | 36 | ||||
-rw-r--r-- | w/class/quickcss.php (renamed from w/class/class.w.quickcss.php) | 0 | ||||
-rw-r--r-- | w/class/record.php (renamed from w/class/class.w.record.php) | 0 | ||||
-rw-r--r-- | w/class/route.php | 84 | ||||
-rw-r--r-- | w/class/router.php | 63 | ||||
-rw-r--r-- | w/class/user.php | 37 | ||||
-rw-r--r-- | w/class/w.article.php (renamed from w/controller/w.article.php) | 5 | ||||
-rw-r--r-- | w/class/w.home.php (renamed from w/controller/w.home.php) | 8 | ||||
-rw-r--r-- | w/class/w.menu.php (renamed from w/controller/w.menu.php) | 0 | ||||
-rw-r--r-- | w/fn/w.fn.php | 4 | ||||
-rw-r--r-- | w/view/templates/base.php | 10 | ||||
-rw-r--r-- | w/view/templates/media.php | 4 | ||||
-rw-r--r-- | w/view/templates/nav.php | 42 | ||||
-rw-r--r-- | w/view/templates/read.php | 20 | ||||
-rw-r--r-- | w/view/templates/reader.php | 38 | ||||
-rw-r--r-- | w/w.index.php (renamed from w/w.router.php) | 87 |
38 files changed, 1888 insertions, 553 deletions
diff --git a/w/class/class.w.aff.php b/w/class/aff.php index adb8b61..6f9f07e 100644 --- a/w/class/class.w.aff.php +++ b/w/class/aff.php @@ -3,20 +3,6 @@ class Aff { - private $session; - - private static $edit = 2; - - - // ________________________________________________ C O N S T R U C T ______________________________________________ - - - public function __construct($session = 0) - { - $this->setsession($session); - } - - // ____________________________________________________ C O N F I G ______________________________________________ @@ -56,58 +42,25 @@ class Aff // ____________________________________________________ F U N ______________________________________________ - public function lecture(Art $art, App $app) - { - if ($art->secure() == 1) { - echo '<span class="alert">This article is private</span>'; - } - if ($art->secure() == 2) { - echo "<span class=\"alert\">This article is not published yet</span>"; - } - if ($app->session() >= $art->secure()) { - ?> - <style type="text/css"> - body{ - background: <?= $art->couleurbkg() ?>; - } - section { - color: <?= $art->couleurtext() ?>; - } - - a { - color: <?= $art->couleurlien() ?>; - } - - section a.external { - color: <?= $art->couleurlienblank() ?>; - } - <?= $art->csstemplate($app) ?> - </style> - <header> - <h1><?= $art->titre() ?></h1> - <h6><?= $art->soustitre() ?></h6> - </header> - <article><?= $art->html($app) ?></article> - <?php + + - } - } - public function edit(Art $art, App $app, $list, $fontsize, $imagelist) + public function edit(Art2 $art, App $app, $list, $fontsize, $imagelist) { - if ($app->session() >= self::$edit) { + if ($app->session() >= $app::EDITOR) { ?> <form action="?id=<?= $art->id() ?>" method="post" id="artedit"> - + <?php echo '<style>textarea{font-size: ' . $fontsize . '}</style>'; - $tablist = ['html' => $art->md(), 'css' => $art->css(), 'aside' => 'NOT WORKING', 'footer' => 'NOT WORKING']; + $tablist = ['section' => $art->md(), 'css' => $art->css(), 'aside' => $art->aside(), 'footer' => $art->footer()]; - $this->tabs($tablist, 'html'); + $this->tabs($tablist, 'section'); ?> @@ -127,12 +80,10 @@ class Aff <details id="editinfo" open> <summary>Infos</summary> <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="title">title :</label> + <input type="text" name="title" id="title" value="<?= $art->title(); ?>"> + <label for="description">Description :</label> + <input type="text" name="description" id="description" value="<?= $art->description(); ?>"> <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> @@ -152,9 +103,9 @@ class Aff foreach ($list as $item) { if ($item->id() == $art->template()) { - echo '<option value="' . $item->id() . '" selected >' . $item->titre() . '</option>'; + echo '<option value="' . $item->id() . '" selected >' . $item->title() . '</option>'; } else { - echo '<option value="' . $item->id() . '">' . $item->titre() . '</option>'; + echo '<option value="' . $item->id() . '">' . $item->title() . '</option>'; } } ?> @@ -166,88 +117,16 @@ class Aff <fieldset> <h3>Template options</h3> <p>NOT WORKING</p> - <ul> - <?php - - $templatelist = ['header' => 0, 'section' => 0, 'nav' => 0, 'aside' => 0, 'footer' => 0, 'quickcss' => 1, 'css' => 1]; - - foreach ($templatelist as $template => $check) { - if ($check == 1) { - echo '<li><input type="checkbox" name="template' . $template . '" id="template' . $template . '" checked><label for="template' . $template . '">' . $template . '</label></li>'; - } else { - echo '<li><input type="checkbox" name="template' . $template . '" id="template' . $template . '"><label for="template' . $template . '">' . $template . '</label></li>'; - } - } - ?> - </ul> </fieldset> </details> <details id="editcss" open> <summary>Quick CSS</summary> - <fieldset> - - <?php - $colorlist = ['text' => $art->couleurtext(), 'lien' => $art->couleurlien(), 'lienblank' => $art->couleurlienblank(), 'bkg' => $art->couleurbkg()]; - foreach ($colorlist as $element => $color) { - echo '<label for="couleur' . $element . '">Couleur du ' . $element . ' :</label><input type="color" name="couleur' . $element . '" value="' . $color . '" id="couleur' . $element . '">'; - } - - - - ?> - - <label for="bkgimage">NOT WORKING</label> - <select name="bkgimage" id="bkgimage"> - <?php - - $artbkgimage = "NULL"; - - if ($artbkgimage == 'NULL') { - echo '<option value="" selected >No background image</option>'; - } else { - echo '<option value="" >No background image</option>'; - } - foreach ($imagelist as $image) { - if ($image->id() == $artbkgimage) { - echo '<option value="' . $image->id() . '.' . $image->extension() . '" selected >' . $image->id() . '.' . $image->extension() . '</option>'; - } else { - echo '<option value="' . $image->id() . '.' . $image->extension() . '">' . $image->id() . '.' . $image->extension() . '</option>'; - } - } - ?> - </select> - - </fieldset> + </details> <details> <summary>Help</summary> <div id="help"> - <h2>Help !</h2> - <p>To save your article, press the HOME, UPDATE, or DISPLAY buttons. You can use the keyboard shortcuts as well.</p> - <pre><span class="i">ALT + W</span> : home</pre> - <pre><span class="i">ALT + X</span> : update</pre> - <pre><span class="i">ALT + C</span> : display</pre> - <h3>Markdown</h3> - <p>The html section use <a href="https://daringfireball.net/projects/markdown/syntax" target="_blank">Markdown encoding</a>. Actualy, W is using Michel Fortin's <a href="https://michelf.ca/projects/php-markdown/extra/" target="_blank">Markdown Extra</a>.</p> - <h3>Links</h3> - <pre>[text](=<span class="i">article_id</span>)</pre> - <p>where article_id is the article's id you want to point to.</p> - <h3>Images</h3> - <pre>[altimage](/<span class="i">img_id.extension</span>)</pre> - <p>Where img_id is the id of your image and its extension.</p> - <h3>Shortcuts</h3> - <pre>%TITLE%</pre> - <p>Show the title of your article.</p> - <pre>%DESCRIPTION%</pre> - <p>Show the description (intro) of your article.</p> - <pre>%SUMMARY%</pre> - <p>Generate a <strong>summary</strong>, the list of all your head titles using #, ##, ###...</p> - <pre>%%<span class="i">tag_name</span>%%</pre> - <p>Generate a <strong>menu</strong>, a list of links to all articles under this tag.</p> - <p>vv</p> - <p>vv</p> - <p>vv</p> - <p></p> + <?= $this->editorhelp() ?> </div> </details> @@ -288,39 +167,40 @@ public function tabs($tablist, $opentab) echo '</div>'; } - - -public function copy(Art $art, $list) +public function editorhelp() { ?> - <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, 'Erase values')"> - </fieldset> - </form> - </div> + <h2>Help !</h2> + <p>To save your article, press the HOME, UPDATE, or DISPLAY buttons. You can use the keyboard shortcuts as well.</p> + <pre><span class="i">ALT + W</span> : home</pre> + <pre><span class="i">ALT + X</span> : update</pre> + <pre><span class="i">ALT + C</span> : display</pre> + <h3>Markdown</h3> + <p>The html section use <a href="https://daringfireball.net/projects/markdown/syntax" target="_blank">Markdown encoding</a>. Actualy, W is using Michel Fortin's <a href="https://michelf.ca/projects/php-markdown/extra/" target="_blank">Markdown Extra</a>.</p> + <h3>Links</h3> + <pre>[text](=<span class="i">article_id</span>)</pre> + <p>where article_id is the article's id you want to point to.</p> + <h3>Images</h3> + <pre>[altimage](/<span class="i">img_id.extension</span>)</pre> + <p>Where img_id is the id of your image and its extension.</p> + <h3>Shortcuts</h3> + <pre>%TITLE%</pre> + <p>Show the title of your article.</p> + <pre>%DESCRIPTION%</pre> + <p>Show the description of your article.</p> + <pre>%SUMMARY%</pre> + <p>Generate a <strong>summary</strong>, the list of all your head titles using #, ##, ###...</p> + <pre>%%<span class="i">tag_name</span>%%</pre> + <p>Generate a <strong>menu</strong>, a list of links to all articles under this tag.</p> + <p>vv</p> + <p>vv</p> + <p>vv</p> + <p></p> <?php - } + + public function head($title, $tool, $color4) { ?> @@ -342,17 +222,17 @@ public function head($title, $tool, $color4) } -public function arthead(Art $art, $globalcss, $edit = 0) +public function arthead(Art2 $art, $globalcss, $edit = 0) { ?> <head> <meta charset="utf8" /> - <meta name="description" content="<?= $art->intro() ?>" /> + <meta name="description" content="<?= $art->description() ?>" /> <meta name="viewport" content="width=device-width" /> <link rel="shortcut icon" href="./media/logo.png" type="image/x-icon"> <link href="./rsc/css/stylebase.css" rel="stylesheet" /> <?= $edit == 0 ? '<link href="' . $globalcss . '" rel="stylesheet" />' : '<link href="./rsc/css/styleedit.css" rel="stylesheet" />' ?> - <title><?= $edit == 1 ? '✏' : '' ?> <?= $art->titre() ?></title> + <title><?= $edit == 1 ? '✏' : '' ?> <?= $art->title() ?></title> <script src="./rsc/js/app.js"></script> </head> <?php @@ -398,7 +278,7 @@ public function tag($getlist, $tag, $app) 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(); + echo '<li><a href="?id=' . $item->id() . '">' . $item->title() . '</a> - ' . $item->description(); if ($app->session() >= $app::EDITOR) { echo ' - <a href="?id=' . $item->id() . '&edit=1">modifier</a></li>'; } else { @@ -410,15 +290,15 @@ public function tag($getlist, $tag, $app) echo ' </div> '; } -public function lien($getlist, $lien, App $app) +public function linkfrom($getlist, $linkfrom, App $app) { - echo '<div class="lien">'; + echo '<div class="linkfrom">'; 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 (in_array($linkfrom, $item->linkfrom('array'))) { + echo '<li><a href="?id=' . $item->id() . '">' . $item->title() . '</a> - ' . $item->description(); if ($app->session() >= $app::EDITOR) { - echo ' - <a href="?id=' . $item->id() . '&edit=1">modifier</a> - <a href="?lien=' . $item->id() . '">liens</a></li>'; + echo ' - <a href="?id=' . $item->id() . '&edit=1">modifier</a> - <a href="?linkfrom=' . $item->id() . '">linkfroms</a></li>'; } else { echo '</li>'; } @@ -428,8 +308,6 @@ public function lien($getlist, $lien, App $app) echo ' </div> '; } - - public function dump($getlist) { echo '<ul>'; @@ -492,11 +370,11 @@ public function home2table(App $app, $getlist, $masslist) foreach ($getlist as $item) { echo '<tr>'; echo '<td><input type="checkbox" name="id[]" value=' . $item->id() . '></td>'; - echo '<td><a href="?id=' . $item->id() . '&edit=1">' . $item->titre() . '</a></td>'; + echo '<td><a href="?id=' . $item->id() . '&edit=1">' . $item->title() . '</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->description() . '</td>'; + echo '<td><a href="?linkfrom=' . $item->id() . '">' . $item->linkto('sort') . '</a></td>'; + echo '<td>' . $item->linkfrom('sort') . '</td>'; echo '<td>' . $item->datemodif('hrdi') . '</td>'; echo '<td>' . $item->datecreation('hrdi') . '</td>'; echo '<td>' . $item->secure('string') . '</td>'; @@ -682,7 +560,7 @@ 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'] . ')">'; + echo '<li><a href="?id=' . $item['id'] . '&edit=1">' . $item['title'] . '</a> - <input type="text" value="[' . $item['title'] . '](?id=' . $item['id'] . ')">'; } @@ -1133,27 +1011,6 @@ public function nav($app) } - - - -//______________________________________________________ S E T _________________________________________________ - - public function setsession($session) - { - if ($session <= 100 and $session >= 0) { - $session = intval($session); - $this->session = $session; - } - } - - //______________________________________________________ G E T _________________________________________________ - - public function session() - { - return $this->session; - } - - } diff --git a/w/class/class.w.app.php b/w/class/app.php index 922740b..b791846 100644 --- a/w/class/class.w.app.php +++ b/w/class/app.php @@ -118,47 +118,16 @@ class App // ___________________________________________ A R T ____________________________________ - public function add(Art $art) - { - - if ($this->exist($art->id())) { - echo '<h4>cet id existe deja</h4>'; - } else { - - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - $request = 'INSERT INTO ' . $this->arttable . '(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 = $this->bdd->prepare($request); - - $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 add2(Art2 $art) + public function add(Art2 $art) { if ($this->exist($art->id())) { echo '<span class="alert">idalreadyexist</span>'; } else { + var_dump($art); + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); $request = 'INSERT INTO ' . $this->arttable . '(id, title, description, tag, date, datecreation, datemodif, daterender, css, quickcss, javascript, html, header, section, nav, aside, footer, render, secure, invitepassword, interface, linkfrom, template, affcount, editcount) @@ -175,11 +144,11 @@ class App $q->bindValue(':datemodif', $now->format('Y-m-d H:i:s')); $q->bindValue(':daterender', $now->format('Y-m-d H:i:s')); $q->bindValue(':css', $art->css()); - $q->bindValue(':quickcss', $art->quickcss('string')); + $q->bindValue(':quickcss', $art->quickcss('json')); $q->bindValue(':javascript', $art->javascript()); $q->bindValue(':html', $art->html()); $q->bindValue(':header', $art->header()); - $q->bindValue(':section', $art->section()); + $q->bindValue(':section', $art->md()); $q->bindValue(':nav', $art->nav()); $q->bindValue(':aside', $art->aside()); $q->bindValue(':footer', $art->footer()); @@ -187,8 +156,8 @@ class App $q->bindValue(':secure', $art->secure()); $q->bindValue(':invitepassword', $art->invitepassword()); $q->bindValue(':interface', $art->interface()); - $q->bindValue(':linkfrom', $art->linkfrom('string')); - $q->bindValue(':template', $art->template('string')); + $q->bindValue(':linkfrom', $art->linkfrom('json')); + $q->bindValue(':template', $art->template('json')); $q->bindValue(':affcount', $art->affcount()); $q->bindValue(':editcount', $art->editcount()); @@ -196,7 +165,7 @@ class App } } - public function delete(Art $art) + public function delete(Art2 $art) { $req = $this->bdd->prepare('DELETE FROM ' . $this->arttable . ' WHERE id = :id '); $req->execute(array('id' => $art->id())); @@ -209,7 +178,7 @@ class App $req->execute(array('id' => $id)); $donnees = $req->fetch(PDO::FETCH_ASSOC); - return new Art($donnees); + return new Art2($donnees); $req->closeCursor(); @@ -217,38 +186,15 @@ class App - public function update(Art $art) - { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - - $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(); - } - public function update2(Art2 $art) + public function update(Art2 $art) { $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - $request = 'UPDATE ' . $this->arttable . '(id, title, description, tag, date, datecreation, datemodif, daterender, css, quickcss, javascript, html, header, section, nav, aside, footer, render, secure, invitepassword, interface, linkfrom, template, affcount, editcount) - VALUES(:id, :title, :description, :tag, :date, :datecreation, :datemodif, :daterender, :css, :quickcss, :javascript, :html, :header, :section, :nav, :aside, :footer, :render, :secure, :invitepassword, :interface, :linkfrom, :template, :affcount, :editcount) WHERE id = :id'; + //$request = 'UPDATE ' . $this->arttable . '(id, title, description, tag, date, datecreation, datemodif, daterender, css, quickcss, javascript, html, header, section, nav, aside, footer, render, secure, invitepassword, interface, linkfrom, template, affcount, editcount) VALUES(:id, :title, :description, :tag, :date, :datecreation, :datemodif, :daterender, :css, :quickcss, :javascript, :html, :header, :section, :nav, :aside, :footer, :render, :secure, :invitepassword, :interface, :linkfrom, :template, :affcount, :editcount) WHERE id = :id'; + + $request = 'UPDATE ' . $this->arttable . ' SET id = :id, title = :title, description = :description, tag = :tag, date = :date, datecreation = :datecreation, datemodif = :datemodif, daterender = :daterender, css = :css, quickcss = :quickcss, javascript = :javascript, html = :html, header = :header, section = :section, nav = :nav, aside = :aside, footer = :footer, render = :footer, secure = :secure, invitepassword = :invitepassword, interface = :interface, linkfrom = :linkfrom, template = :template, affcount = :affcount, editcount = :editcount WHERE id = :id'; $q = $this->bdd->prepare($request); @@ -261,11 +207,11 @@ class App $q->bindValue(':datemodif', $now->format('Y-m-d H:i:s')); $q->bindValue(':daterender', $now->format('Y-m-d H:i:s')); $q->bindValue(':css', $art->css()); - $q->bindValue(':quickcss', $art->quickcss('string')); + $q->bindValue(':quickcss', $art->quickcss('json')); $q->bindValue(':javascript', $art->javascript()); $q->bindValue(':html', $art->html()); $q->bindValue(':header', $art->header()); - $q->bindValue(':section', $art->section()); + $q->bindValue(':section', $art->md()); $q->bindValue(':nav', $art->nav()); $q->bindValue(':aside', $art->aside()); $q->bindValue(':footer', $art->footer()); @@ -273,14 +219,24 @@ class App $q->bindValue(':secure', $art->secure()); $q->bindValue(':invitepassword', $art->invitepassword()); $q->bindValue(':interface', $art->interface()); - $q->bindValue(':linkfrom', $art->linkfrom('string')); - $q->bindValue(':template', $art->template('string')); + $q->bindValue(':linkfrom', $art->linkfrom('json')); + $q->bindValue(':template', $art->template('json')); $q->bindValue(':affcount', $art->affcount()); $q->bindValue(':editcount', $art->editcount()); $q->execute(); } + public function exist($id) + { + $req = $this->bdd->prepare(' SELECT COUNT(*) FROM ' . $this->arttable . ' WHERE id = :id '); + $req->execute(array('id' => $id)); + $donnees = $req->fetch(PDO::FETCH_ASSOC); + + return (bool)$donnees['COUNT(*)']; + } + + @@ -296,7 +252,7 @@ class App $opt = array_update($default, $opt); $list = []; - $option = ['datecreation', 'titre', 'id', 'intro', 'datemodif', 'tag', 'secure']; + $option = ['datecreation', 'title', 'id', 'description', '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); @@ -304,7 +260,7 @@ class App $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); + $list[] = new Art2($donnees); } return $list; } @@ -323,16 +279,16 @@ class App $select = 'SELECT ' . $opt->col('string') . ' FROM ' . $this->arttable; $req = $this->bdd->query($select); while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) { - $artlist[] = new Art($donnees); + $artlist[] = new Art2($donnees); } return $artlist; } - public function listcalclien(&$artlist) + public function listcalclinkfrom(&$artlist) { foreach ($artlist as $art) { - $art->calcliento($artlist); + $art->calclinkto($artlist); } } @@ -434,14 +390,6 @@ class App return $this->bdd->query(' SELECT COUNT(*) FROM ' . $this->arttable . ' ')->fetchColumn(); } - public function exist($id) - { - $req = $this->bdd->prepare(' SELECT COUNT(*) FROM ' . $this->arttable . ' WHERE id = :id '); - $req->execute(array('id' => $id)); - $donnees = $req->fetch(PDO::FETCH_ASSOC); - - return (bool)$donnees['COUNT(*)']; - } // __________________________________________ T A B L E ________________________________________________________ @@ -485,41 +433,6 @@ class App } - public function addtable($dbname, $tablename) - { - - if (!$this->tableexist($dbname, $tablename)) { - - $table = "CREATE TABLE `$tablename` ( - `id` varchar(255) NOT NULL DEFAULT 'art', - `titre` varchar(255) NOT NULL DEFAULT 'titre', - `soustitre` varchar(255) NOT NULL DEFAULT 'soustitre', - `intro` varchar(255) NOT NULL DEFAULT 'intro', - `tag` varchar(255) NOT NULL DEFAULT 'sans tag,', - `datecreation` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - `datemodif` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - `css` text, - `html` text, - `secure` int(1) NOT NULL DEFAULT '0', - `couleurtext` varchar(7) NOT NULL DEFAULT '#000000', - `couleurbkg` varchar(7) NOT NULL DEFAULT '#ffffff', - `couleurlien` varchar(7) NOT NULL DEFAULT '#2a3599', - `couleurlienblank` varchar(7) NOT NULL DEFAULT '#2a8e99', - `lien` varchar(255) DEFAULT NULL, - `template` varchar(255) DEFAULT NULL - )"; - - $alter = "ALTER TABLE `$tablename` - ADD PRIMARY KEY (`id`)"; - - $req = $this->bdd->query($table); - $req = $this->bdd->query($alter); - - return 'tablecreated'; - } else { - return 'tablealreadyexist'; - } - } @@ -667,32 +580,6 @@ class App - //_________________________________________________________ A D M ________________________________________________________ - - - - public function dirlist($dir, $extension) - { - if ($handle = opendir($dir)) { - $list = []; - while (false !== ($entry = readdir($handle))) { - if ($entry != "." && $entry != ".." && pathinfo($entry)['extension'] == $extension) { - - $list[] = $entry; - - } - } - return $list; - } - } - - public function downloadtable() - { - - } - - - // ________________________________________________________ M A P ________________________________________________________ @@ -705,16 +592,16 @@ class App $style = ""; foreach ($getlister as $item) { if($item->secure() == 2) { - $style = $style . $lb . $item->id() . '{' . $item->titre() . '}'; + $style = $style . $lb . $item->id() . '{' . $item->title() . '}'; } elseif ($item->secure() == 1) { - $style = $style . $lb . $item->id() . '(' . $item->titre() . ')'; + $style = $style . $lb . $item->id() . '(' . $item->title() . ')'; } else { - $style = $style . $lb . $item->id() . '((' . $item->titre() . '))'; + $style = $style . $lb . $item->id() . '((' . $item->title() . '))'; } - foreach ($item->lien('array') as $lien) { - $map = $map . $lb . $item->id() . ' --> ' . $lien; - $link = $link . $lb . 'click ' . $lien . ' "./?id=' . $lien . '"'; + foreach ($item->linkfrom('array') as $linkfrom) { + $map = $map . $lb . $item->id() . ' --> ' . $linkfrom; + $link = $link . $lb . 'click ' . $linkfrom . ' "./?id=' . $linkfrom . '"'; } $link = $link . $lb . 'click ' . $item->id() . ' "./?id=' . $item->id() . '"'; diff --git a/w/class/application.php b/w/class/application.php new file mode 100644 index 0000000..77599d5 --- /dev/null +++ b/w/class/application.php @@ -0,0 +1,36 @@ +<?php + + +class Application +{ + + protected $config; + + + public function __construct() + { + $this->setconfig(); + + } + + + public function setconfig() + { + $this->config = Modelconfig::readconfig(); + } + + + + +} + + + + + + + + + + +?>
\ No newline at end of file diff --git a/w/class/class.w.art.php b/w/class/art.php index 001b29d..a4c93eb 100644 --- a/w/class/class.w.art.php +++ b/w/class/art.php @@ -133,6 +133,11 @@ class Art } } + public function templaterender() + { + + } + // _____________________________________________________ G E T ____________________________________________________ diff --git a/w/class/class.w.art2.php b/w/class/art2.php index feee0ca..88c0321 100644 --- a/w/class/class.w.art2.php +++ b/w/class/art2.php @@ -3,7 +3,7 @@ use Michelf\MarkdownExtra; -class Art +class Art2 { private $id; private $title; @@ -27,18 +27,19 @@ class Art private $invitepassword; private $interface; private $linkfrom; + private $linkto; private $template; private $affcount; private $editcount; - private $linkto; const LEN = 255; - const LENHTML = 20000; + const LENTEXT = 20000; const SECUREMAX = 2; const LENCOULEUR = 7; const DEBUT = '(?id='; const FIN = ')'; + const TABS = ['section', 'css', 'header', 'html', 'nav', 'aside', 'footer', 'javascript']; @@ -82,7 +83,9 @@ class Art $this->setnav(''); $this->setaside(''); $this->setfooter(''); + $this->setrender(''); $this->setsecure(2); + $this->setinvitepassword('invitepassword'); $this->setinterface('section'); $this->setlinkfrom([]); $this->settemplate([]); @@ -90,7 +93,7 @@ class Art $this->seteditcount(0); } - public function updatelien() + public function updatelinkfrom() { $this->linkfrom = []; $this->linkfrom = array_unique(search($this->md(true), self::DEBUT, self::FIN)); @@ -109,15 +112,17 @@ class Art - public function calcliento($getlist) + public function calclinkto($getlist) { - $liento = []; - foreach ($getlist as $lien) { - if (in_array($this->id(), $lien->lien('array'))) { - $liento[] = $lien->id(); + $linkto = []; + if(!empty($getlist)) { + foreach ($getlist as $link) { + if (in_array($this->id(), $link->linkfrom('array'))) { + $linkto[] = $link->id(); + } } + $this->setlinkto($linkto); } - $this->setliento($liento); } @@ -134,10 +139,10 @@ class Art foreach ($taglist as $tag => $artlist) { $replace = '<ul>'; foreach ($artlist as $art) { - $replace .= '<li><a href="?id=' . $art->id() . '" title="' . $art->intro() . '">' . $art->titre() . '</a></li>'; + $replace .= '<li><a href="?id=' . $art->id() . '" title="' . $art->description() . '">' . $art->title() . '</a></li>'; } $replace .= '</ul>'; - $this->html = str_replace('%%' . $tag . '%%', $replace, $this->html); + $this->section = str_replace('%%' . $tag . '%%', $replace, $this->section); } } @@ -145,13 +150,23 @@ class Art { foreach ($taglist as $tag => $artlist) { foreach ($artlist as $art) { - if (!in_array($art->id(), $this->lien('array')) && $art->id() != $this->id()) { - $this->lien[] = $art->id(); + if (!in_array($art->id(), $this->linkfrom('array')) && $art->id() != $this->id()) { + $this->linkfrom[] = $art->id(); } } } } + public function templaterender(array $vars) + { + $datas = []; + foreach($vars as $var) { + if (method_exists($this, $var)) + $datas[$var] = $this->$var(); + } + return $datas; + } + // _____________________________________________________ G E T ____________________________________________________ @@ -235,34 +250,16 @@ class Art return $this->css; } - public function quickcss($option = 'json') + public function quickcss($type = 'json') { - if ($option == 'json') { + if ($type == 'json') { return json_encode($this->quickcss); - } elseif ($option == 'array') { + } elseif ($type == 'array') { return $this->quickcss; - } elseif ($option == 'string') { - $string = ''; - foreach ($this->quickcss as $key => $css) { - $string .= PHP_EOL . $key . ' {'; - foreach ($css as $param => $value) { - if(is_int($value)) { - $string .= PHP_EOL . ' ' . $param . ': ' . $value . 'px;'; - } else { - $string .= PHP_EOL . ' ' . $param . ': ' . $value . ';'; - } - } - $string .= PHP_EOL . '}' . PHP_EOL; - } - return $string; } } - public function cssprint() - { - return $cssprint; - } - + public function csstemplate(App $app) { $data = []; @@ -280,22 +277,43 @@ class Art return $cssprint; } + + public function javascript($type = 'string') + { + return $this->javascript; + } + + public function html($type = 'string') + { + return $this->html; + } + + public function header($type = 'string') + { + return $this->header; + } + public function md($expand = false) { if ($expand == true) { - $md = str_replace('](=', '](?id=', $this->html); + $md = str_replace('](=', '](?id=', $this->section); } else { - $md = $this->html; + $md = $this->section; } return $md; } - public function html(App $app) + public function section() + { + return $this->section; + } + + public function section888(App $app) { // %%%% TITLE & DESCIPTION - $html = str_replace('%TITLE%', $this->titre(), $this->html); - $html = str_replace('%DESCRIPTION%', $this->intro(), $html); + $section = str_replace('%TITLE%', $this->title(), $this->section); + $section = str_replace('%DESCRIPTION%', $this->description(), $section); $parser = new MarkdownExtra; @@ -303,41 +321,61 @@ class Art $parser->header_id_func = function ($header) { return preg_replace('/[^\w]/', '', strtolower($header)); }; - $html = $parser->transform($html); + $section = $parser->transform($section); // replace = > ?id= - $html = str_replace('href="=', 'href="?id=', $html); + $section = str_replace('href="=', 'href="?id=', $section); // infobulles tooltip - foreach ($this->lien('array') as $id) { + foreach ($this->linkfrom('array') as $id) { $title = "Cet article n'existe pas encore"; - foreach ($app->getlister(['id', 'intro']) as $item) { + foreach ($app->getlister(['id', 'description']) as $item) { if ($item->id() == $id) { - $title = $item->intro(); + $title = $item->description(); } } - $lien = 'href="?id=' . $id . '"'; - $titlelien = ' title="' . $title . '" ' . $lien; - $html = str_replace($lien, $titlelien, $html); + $linkfrom = 'href="?id=' . $id . '"'; + $titlelinkfrom = ' title="' . $title . '" ' . $linkfrom; + $section = str_replace($linkfrom, $titlelinkfrom, $section); } - if (!empty(strstr($html, '%SUMMARY%'))) { + if (!empty(strstr($section, '%SUMMARY%'))) { - $html = str_replace('%SUMMARY%', sumparser($html), $html); + $section = str_replace('%SUMMARY%', sumparser($section), $section); } - $html = str_replace('href="./media/', ' class="file" target="_blank" href="./media/', $html); - $html = str_replace('href="http', ' class="external" target="_blank" href="http', $html); - $html = str_replace('<img src="/', '<img src="./media/', $html); - $html = str_replace('<iframe', '<div class="iframe"><div class="container"><iframe class="video" ', $html); - $html = str_replace('</iframe>', '</iframe></div></div>', $html); - return $html; + $section = str_replace('href="./media/', ' class="file" target="_blank" href="./media/', $section); + $section = str_replace('href="http', ' class="external" target="_blank" href="http', $section); + $section = str_replace('<img src="/', '<img src="./media/', $section); + $section = str_replace('<iframe', '<div class="iframe"><div class="container"><iframe class="video" ', $section); + $section = str_replace('</iframe>', '</iframe></div></div>', $section); + return $section; + + + } + + public function nav($type="string") + { + return $this->nav; + } + + public function aside($type="string") + { + return $this->aside; + } + public function footer($type="string") + { + return $this->footer; + } + public function render($type = 'string') + { + return $this->render; } public function secure($type = 'int') @@ -352,55 +390,59 @@ class Art } } - public function couleurtext() + public function invitepassword($type = 'int') { - return $this->couleurtext; + return $this->invitepassword; } - public function couleurbkg() + public function interface($type = 'secton') { - return $this->couleurbkg; + return $this->interface; } - public function couleurlien() + public function linkfrom($option = 'json') { - return $this->couleurlien; - } + if ($option == 'json') { + $linkfrom = json_encode($this->linkfrom); + } elseif ($option == 'array') { + $linkfrom = $this->linkfrom; + } elseif ($option == 'sort') { + return count($this->linkfrom); + } + return $linkfrom; - public function couleurlienblank() - { - return $this->couleurlienblank; } - public function lien($option) + public function linkto($option) { if ($option == 'string') { - $lien = implode(", ", $this->lien); + $linkto = implode(", ", $this->linkto); } elseif ($option == 'array') { - $lien = $this->lien; + $linkto = $this->linkto; } elseif ($option == 'sort') { - return count($this->lien); + return count($this->linkto); } - return $lien; + return $linkto; } - public function liento($option) + public function template($type = 'json') { - if ($option == 'string') { - $liento = implode(", ", $this->liento); - } elseif ($option == 'array') { - $liento = $this->liento; - } elseif ($option == 'sort') { - return count($this->liento); + if($type == 'json') { + return json_encode($this->template); + } elseif ($type = 'array') { + return $this->template; } - return $liento; + } + public function affcount($type = 'int') + { + return $this->affcount; } - public function template($type = 'string') + public function editcount($type = 'int') { - return $this->template; + return $this->editcount; } @@ -416,24 +458,17 @@ class Art } } - public function settitre($titre) + public function settitle($title) { - if (strlen($titre) < self::LEN and is_string($titre)) { - $this->titre = strip_tags(trim($titre)); + if (strlen($title) < self::LEN and is_string($title)) { + $this->title = strip_tags(trim($title)); } } - public function setsoustitre($soustitre) + public function setdescription($description) { - 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)); + if (strlen($description) < self::LEN and is_string($description)) { + $this->description = strip_tags(trim($description)); } } @@ -491,79 +526,117 @@ class Art } } + + public function setcss($css) + { + if (strlen($css) < self::LENTEXT and is_string($css)) { + $this->css = strip_tags(trim(strtolower($css))); + } + } + + public function setquickcss($quickcss) { - + if(is_string($quickcss)) { + $quickcss = json_decode($quickcss, true); + } + if(is_array($quickcss)) { + $this->quickcss = $quickcss; + } } - public function setcss($css) + public function setjavascript($javascript) { - if (strlen($css) < self::LENHTML and is_string($css)) { - $this->css = strip_tags(trim(strtolower($css))); + if(strlen($javascript < self::LENTEXT && is_string($javascript))) { + $this->javascript = $javascript; } } + public function sethtml($html) { - if (strlen($html) < self::LENHTML and is_string($html)) { + if(strlen($html < self::LENTEXT && is_string($html))) { $this->html = $html; } } - public function setsecure($secure) + public function setheader($header) { - if ($secure >= 0 and $secure <= self::SECUREMAX) { - $this->secure = intval($secure); + if(strlen($header < self::LENTEXT && is_string($header))) { + $this->header = $header; + } + } + + public function setsection($section) + { + if (strlen($section) < self::LENTEXT and is_string($section)) { + $this->section = $section; + } + } + + public function setnav($nav) + { + if (strlen($nav) < self::LENTEXT and is_string($nav)) { + $this->nav = $nav; + } + } + + public function setaside($aside) + { + if (strlen($aside) < self::LENTEXT and is_string($aside)) { + $this->aside = $aside; } } - public function setcouleurtext($couleurtext) + public function setfooter($footer) { - $couleurtext = strval($couleurtext); - if (strlen($couleurtext) <= self::LENCOULEUR) { - $this->couleurtext = strip_tags(trim($couleurtext)); + if (strlen($footer) < self::LENTEXT and is_string($footer)) { + $this->footer = $footer; } } - public function setcouleurbkg($couleurbkg) + public function setrender($render) + { + $this->render = $render; + } + + public function setsecure($secure) { - $couleurbkg = strval($couleurbkg); - if (strlen($couleurbkg) <= self::LENCOULEUR) { - $this->couleurbkg = strip_tags(trim($couleurbkg)); + if ($secure >= 0 and $secure <= self::SECUREMAX) { + $this->secure = intval($secure); } } - public function setcouleurlien($couleurlien) + public function setinvitepassword($invitepassword) { - $couleurlien = strval($couleurlien); - if (strlen($couleurlien) <= self::LENCOULEUR) { - $this->couleurlien = strip_tags(trim($couleurlien)); + if(is_string($invitepassword) && strlen($invitepassword) < self::LEN) { + $this->invitepassword = $invitepassword; } } - public function setcouleurlienblank($couleurlienblank) + public function setinterface($interface) { - $couleurlienblank = strval($couleurlienblank); - if (strlen($couleurlienblank) <= self::LENCOULEUR) { - $this->couleurlienblank = strip_tags(trim($couleurlienblank)); + if(in_array($interface, self::TABS)) + { + $this->interface = $interface; } } - public function setlien($lien) + public function setlinkfrom($linkfrom) { - if (!empty($lien) && strlen($lien) < self::LEN && is_string($lien)) { - $lien = strip_tags(trim(strtolower($lien))); - $lienlist = explode(", ", $lien); - $this->lien = $lienlist; + if (!empty($linkfrom) && strlen($linkfrom) < self::LEN && is_string($linkfrom)) { + $linkfrom = strip_tags(trim(strtolower($linkfrom))); + $linkfromlist = explode(", ", $linkfrom); + $this->linkfrom = $linkfromlist; } else { - $this->lien = []; + $this->linkfrom = []; } } - public function setliento($liento) + public function setlinkto($linkto) { - if (is_array($liento)) { - $this->liento = $liento; + if (is_array($linkto)) { + $this->linkto = $linkto; } @@ -571,11 +644,30 @@ class Art public function settemplate($template) { - $template = strip_tags($template); - if (strlen($template) == 0) { - $template = 'NULL'; + if(is_string($template)) { + $template = json_decode($template, true); + } + if(is_array($template)) { + $this->template = $template; } - $this->template = $template; + } + + public function setaffcount($affcount) + { + if(is_int($affcount)) { + $this->affcount = $affcount; + } elseif(is_numeric($affcount)) { + $this->affcount = intval($affcount); + } + } + + public function seteditcount($editcount) + { + if(is_int($editcount)) { + $this->editcount = $editcount; + } elseif(is_numeric($editcount)) { + $this->editcount = intval($editcount); + } } diff --git a/w/class/class.w.config.php b/w/class/config.php index 3b4cde0..3b4cde0 100644 --- a/w/class/class.w.config.php +++ b/w/class/config.php diff --git a/w/class/controller.php b/w/class/controller.php new file mode 100644 index 0000000..6eab6e4 --- /dev/null +++ b/w/class/controller.php @@ -0,0 +1,57 @@ +<?php + +class Controller extends Application +{ + + protected $user; + protected $usermanager; + protected $templates; + + public function __construct() { + parent::__construct(); + $this->setuser(); + $this->settemplate(); + } + + + + public function setuser() + { + $this->usermanager = new Modeluser; + $this->user = $this->usermanager->readsession(); + } + + public function settemplate() + { + $this->templates = new League\Plates\Engine(Model::TEMPLATES_DIR); + } + + public function useriseditor() + { + if ($this->user->level() >= $this->usermanager::EDITOR) { + echo '<h3>Editor access</h3>'; + return true; + } else { + echo '<h3>Not enought rights to see more...</h3>'; + return false; + } + } + + + + + + public function redirect($url) + { + header('Location: ' . $url); + } + + + +} + + + + + +?>
\ No newline at end of file diff --git a/w/class/controlleradmin.php b/w/class/controlleradmin.php new file mode 100644 index 0000000..da7d926 --- /dev/null +++ b/w/class/controlleradmin.php @@ -0,0 +1,23 @@ +<?php + +class Controlleradmin extends Controllerdb +{ + + public function addtable() + { + + } + + + + public function duplicatetable() + { + + } + +} + + + + +?>
\ No newline at end of file diff --git a/w/class/controllerart.php b/w/class/controllerart.php new file mode 100644 index 0000000..8754a20 --- /dev/null +++ b/w/class/controllerart.php @@ -0,0 +1,90 @@ +<?php + +class Controllerart extends Controllerdb +{ + /** @var Art2 */ + protected $art; + + + public function __construct($id) { + parent::__construct(); + + + //echo '<h1>Article</h1>'; + //echo $id; + + $this->art = new Art2(['id' => $id]); + } + + public function importart() + { + if($this->artmanager->exist($this->art->id())) { + $this->art = $this->artmanager->get($this->art); + //var_dump($this->art); + $this->art->autotaglistupdate($this->artmanager->taglist($this->artmanager->getlister(['id', 'title', 'description', 'tag']), $this->art->autotaglist())); + + return true; + } else { + echo '<h3>Article does not exist yet.</h3>'; + return false; + } + } + + public function read() + { + + if($this->importart()) { + if($this->user->level() >= $this->art->secure()) { + $datas = $this->art->templaterender(['id', 'title', 'description', 'javascript', 'html', 'header', 'nav', 'aside', 'section', 'footer']); + echo $this->templates->render('reader', $datas); + } else { + echo '<h3>Not enought right to see the article</h3>'; + } + + } + + + } + + public function edit() + { + echo '<h2>Edit</h2>'; + if($this->importart()) { + // vue edit art + } + + } + + public function add() + { + echo '<h2>Add</h2>'; + + + $this->art->reset(); + $this->artmanager->add($this->art); + } + + public function delete() + { + echo '<h2>Delete</h2>'; + $this->artmanager->delete($this->art); + } + + public function update($id, $redir= "home") + { + echo '<h2>Update</h2>'; + + $this->art = new Art2($_POST); + $this->art->updatelinkfrom(); + $this->art->autotaglistcalc($this->artmanager->taglist($this->artmanagergetlister(['id', 'title', 'tag']), $this->art->autotaglist())); + $this->artmanager->update($this->art); + + + + } +} + + + + +?>
\ No newline at end of file diff --git a/w/class/controllerdb.php b/w/class/controllerdb.php new file mode 100644 index 0000000..5d75d39 --- /dev/null +++ b/w/class/controllerdb.php @@ -0,0 +1,42 @@ +<?php + +class Controllerdb extends Controller +{ + + protected $artmanager; + + public function __construct() { + parent::__construct(); + + + $this->artmanager = new Modelart(); + + } + + + + // if (isset($_POST['actiondb'])) { + // $app->setbdd($config); + + // switch ($_POST['actiondb']) { + + // case 'addtable': + // if (isset($_POST['tablename'])) { + // $message = Modeldb::addtable($config->dbname(), $_POST['tablename']); + // header('Location: ./?aff=admin&message=' . $message); + // } + // break; + + // case 'duplicatetable': + // $message = Modeldb::tableduplicate($config->dbname(), $_POST['arttable'], $_POST['tablename']); + // header('Location: ./?aff=admin&message=' . $message); + // break; + + // } + // } +} + + + + +?>
\ No newline at end of file diff --git a/w/class/controllerhome.php b/w/class/controllerhome.php new file mode 100644 index 0000000..ecbc3c7 --- /dev/null +++ b/w/class/controllerhome.php @@ -0,0 +1,57 @@ +<?php + +class Controllerhome extends Controllerdb +{ + + protected $modelhome; + + public function __construct() { + parent::__construct(); + $this->modelhome = new Modelhome; + } + + + + + public function desktop() + { + echo '<h1>Desktop</h1>'; + + echo '<h2>Menu Bar</h2>'; + + $this->table2(); + } + + public function table2() + { + if ($this->useriseditor()) { + $datas = $this->modelhome->table2(); + + var_dump($datas); + + } + + } + + public function massedit() + { + echo '<h2>Mass Edit</h2>'; + + } + + + + + + + +} + + + + + + + + +?>
\ No newline at end of file diff --git a/w/class/controllermedia.php b/w/class/controllermedia.php new file mode 100644 index 0000000..8557e74 --- /dev/null +++ b/w/class/controllermedia.php @@ -0,0 +1,38 @@ +<?php + +class Controllermedia extends Controller +{ + protected $medialist; + protected $mediamanager; + + public function __construct() { + parent::__construct(); + + $this->mediamanager = new Modelmedia; + + } + + public function desktop() + { + + if($this->useriseditor()) { + + + echo $this->templates->render('media', ['interface' => 'desktop']); + + } + } + + public function addmedia() + { + echo $this->templates->render('media', ['interface' => 'addmedia']); + + //$message = $this->mediamanager->addmedia($_FILES, 2 ** 24, $_POST['id']); + + } + + +} + + +?>
\ No newline at end of file diff --git a/w/class/class.w.media.php b/w/class/media.php index 2d27be7..2d27be7 100644 --- a/w/class/class.w.media.php +++ b/w/class/media.php diff --git a/w/class/model.php b/w/class/model.php new file mode 100644 index 0000000..8ff7478 --- /dev/null +++ b/w/class/model.php @@ -0,0 +1,17 @@ +<?php +class Model extends Application +{ + + const CONFIG_FILE = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'w.config.json'; + const GLOBAL_CSS_DIR = '.' . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . 'global' . DIRECTORY_SEPARATOR . 'global.css'; + const MEDIA_DIR = '.' . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR; + const TEMPLATES_DIR = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'templates'; + const MEDIA_EXTENSIONS = array('jpeg', 'jpg', 'JPG', 'png', 'gif', 'mp3', 'mp4', 'mov', 'wav', 'flac', 'pdf'); + const MEDIA_TYPES = ['image', 'video', 'sound', 'other']; + + public function __construct() { + parent::__construct(); + } + + +} diff --git a/w/class/modelart.php b/w/class/modelart.php new file mode 100644 index 0000000..9763a53 --- /dev/null +++ b/w/class/modelart.php @@ -0,0 +1,283 @@ +<?php +class Modelart extends Modeldb +{ + + + public function __construct() { + parent::__construct(); + } + + + + public function exist($id) + { + + $req = $this->bdd->prepare(' SELECT COUNT(*) FROM ' . $this->config->arttable() . ' WHERE id = :id '); + $req->execute(array('id' => $id)); + $donnees = $req->fetch(PDO::FETCH_ASSOC); + + return (bool)$donnees['COUNT(*)']; + } + + + + + + public function add(Art2 $art) + { + + if ($this->exist($art->id())) { + echo '<span class="alert">idalreadyexist</span>'; + } else { + + var_dump($art); + + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + + $request = 'INSERT INTO ' . $this->config->arttable() . '(id, title, description, tag, date, datecreation, datemodif, daterender, css, quickcss, javascript, html, header, section, nav, aside, footer, render, secure, invitepassword, interface, linkfrom, template, affcount, editcount) + VALUES(:id, :title, :description, :tag, :date, :datecreation, :datemodif, :daterender, :css, :quickcss, :javascript, :html, :header, :section, :nav, :aside, :footer, :render, :secure, :invitepassword, :interface, :linkfrom, :template, :affcount, :editcount)'; + + $q = $this->bdd->prepare($request); + + $q->bindValue(':id', $art->id()); + $q->bindValue(':title', $art->title()); + $q->bindValue(':description', $art->description()); + $q->bindValue(':tag', $art->tag('string')); + $q->bindValue(':date', $now->format('Y-m-d H:i:s')); + $q->bindValue(':datecreation', $now->format('Y-m-d H:i:s')); + $q->bindValue(':datemodif', $now->format('Y-m-d H:i:s')); + $q->bindValue(':daterender', $now->format('Y-m-d H:i:s')); + $q->bindValue(':css', $art->css()); + $q->bindValue(':quickcss', $art->quickcss('json')); + $q->bindValue(':javascript', $art->javascript()); + $q->bindValue(':html', $art->html()); + $q->bindValue(':header', $art->header()); + $q->bindValue(':section', $art->md()); + $q->bindValue(':nav', $art->nav()); + $q->bindValue(':aside', $art->aside()); + $q->bindValue(':footer', $art->footer()); + $q->bindValue(':render', $art->render()); + $q->bindValue(':secure', $art->secure()); + $q->bindValue(':invitepassword', $art->invitepassword()); + $q->bindValue(':interface', $art->interface()); + $q->bindValue(':linkfrom', $art->linkfrom('json')); + $q->bindValue(':template', $art->template('json')); + $q->bindValue(':affcount', $art->affcount()); + $q->bindValue(':editcount', $art->editcount()); + + $q->execute(); + } + } + + + public function delete(Art2 $art) + { + $req = $this->bdd->prepare('DELETE FROM ' . $this->config->arttable() . ' WHERE id = :id '); + $req->execute(array('id' => $art->id())); + $req->closeCursor(); + } + + public function get(Art2 $art) + { + + $req = $this->bdd->prepare('SELECT * FROM ' . $this->config->arttable() . ' WHERE id = :id '); + $req->execute(array('id' => $art->id())); + $donnees = $req->fetch(PDO::FETCH_ASSOC); + + return new Art2($donnees); + + $req->closeCursor(); + + } + + + + + + public function update(Art2 $art) + { + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + + //$request = 'UPDATE ' . $this->arttable . '(id, title, description, tag, date, datecreation, datemodif, daterender, css, quickcss, javascript, html, header, section, nav, aside, footer, render, secure, invitepassword, interface, linkfrom, template, affcount, editcount) VALUES(:id, :title, :description, :tag, :date, :datecreation, :datemodif, :daterender, :css, :quickcss, :javascript, :html, :header, :section, :nav, :aside, :footer, :render, :secure, :invitepassword, :interface, :linkfrom, :template, :affcount, :editcount) WHERE id = :id'; + + $request = 'UPDATE ' . $this->arttable . ' SET id = :id, title = :title, description = :description, tag = :tag, date = :date, datecreation = :datecreation, datemodif = :datemodif, daterender = :daterender, css = :css, quickcss = :quickcss, javascript = :javascript, html = :html, header = :header, section = :section, nav = :nav, aside = :aside, footer = :footer, render = :footer, secure = :secure, invitepassword = :invitepassword, interface = :interface, linkfrom = :linkfrom, template = :template, affcount = :affcount, editcount = :editcount WHERE id = :id'; + + $q = $this->bdd->prepare($request); + + $q->bindValue(':id', $art->id()); + $q->bindValue(':title', $art->title()); + $q->bindValue(':description', $art->description()); + $q->bindValue(':tag', $art->tag('string')); + $q->bindValue(':date', $now->format('Y-m-d H:i:s')); + $q->bindValue(':datecreation', $now->format('Y-m-d H:i:s')); + $q->bindValue(':datemodif', $now->format('Y-m-d H:i:s')); + $q->bindValue(':daterender', $now->format('Y-m-d H:i:s')); + $q->bindValue(':css', $art->css()); + $q->bindValue(':quickcss', $art->quickcss('json')); + $q->bindValue(':javascript', $art->javascript()); + $q->bindValue(':html', $art->html()); + $q->bindValue(':header', $art->header()); + $q->bindValue(':section', $art->md()); + $q->bindValue(':nav', $art->nav()); + $q->bindValue(':aside', $art->aside()); + $q->bindValue(':footer', $art->footer()); + $q->bindValue(':render', $art->render()); + $q->bindValue(':secure', $art->secure()); + $q->bindValue(':invitepassword', $art->invitepassword()); + $q->bindValue(':interface', $art->interface()); + $q->bindValue(':linkfrom', $art->linkfrom('json')); + $q->bindValue(':template', $art->template('json')); + $q->bindValue(':affcount', $art->affcount()); + $q->bindValue(':editcount', $art->editcount()); + + $q->execute(); + } + + + public function getlister(array $selection = ['id'], array $opt = []) + { + // give an array using SELECTION columns and sort and desc OPTIONS + + $default = ['tri' => 'id', 'desc' => 'DESC']; + $opt = array_update($default, $opt); + + $list = []; + $option = ['datecreation', 'title', 'id', 'description', '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->config->arttable() . ' ORDER BY ' . $opt['tri'] . ' ' . $opt['desc']; + $req = $this->bdd->query($select); + while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) { + $list[] = new Art2($donnees); + } + return $list; + } + } + + + + + + + public function getlisteropt(Opt $opt) + { + + $artlist = []; + + $select = 'SELECT ' . $opt->col('string') . ' FROM ' . $this->config->arttable(); + $req = $this->bdd->query($select); + while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) { + $artlist[] = new Art2($donnees); + } + return $artlist; + + } + + public function listcalclinkfrom(&$artlist) + { + foreach ($artlist as $art) { + $art->calclinkto($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 filtertagfilter(array $artlist, array $tagchecked, $tagcompare = 'OR') + { + + $filteredlist = []; + foreach ($artlist as $art) { + if (empty($tagchecked)) { + $filteredlist[] = $art->id(); + } else { + $inter = (array_intersect($art->tag('array'), $tagchecked)); + if ($tagcompare == 'OR') { + if (!empty($inter)) { + $filteredlist[] = $art->id(); + } + } elseif ($tagcompare == 'AND') { + if (!array_diff($tagchecked, $art->tag('array'))) { + $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; + + } + + public function tag(array $artlist, $tagchecked) + { + $artcheckedlist = []; + foreach ($artlist as $art) { + if (in_array($tagchecked, $art->tag('array'))) { + $artcheckedlist[] = $art; + } + } + return $artcheckedlist; + } + + public function taglist(array $artlist, array $tagcheckedlist) + { + $taglist = []; + foreach ($tagcheckedlist as $tag) { + $taglist[$tag] = $this->tag($artlist, $tag); + } + return $taglist; + } + + public function count() + { + return $this->bdd->query(' SELECT COUNT(*) FROM ' . $this->arttable . ' ')->fetchColumn(); + } + +} diff --git a/w/class/modelartlist.php b/w/class/modelartlist.php new file mode 100644 index 0000000..acbdce5 --- /dev/null +++ b/w/class/modelartlist.php @@ -0,0 +1,159 @@ +<?php + +class Modelartlist extends Modeldb +{ + + + public function getlister(array $selection = ['id'], array $opt = []) + { + // give an array using SELECTION columns and sort and desc OPTIONS + + $default = ['tri' => 'id', 'desc' => 'DESC']; + $opt = array_update($default, $opt); + + $list = []; + $option = ['datecreation', 'title', 'id', 'description', '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 ' . $opt['tri'] . ' ' . $opt['desc']; + $req = $this->bdd->query($select); + while ($donnees = $req->fetch(PDO::FETCH_ASSOC)) { + $list[] = new Art2($donnees); + } + return $list; + } + } + + + + + + + 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 Art2($donnees); + } + return $artlist; + + } + + public function listcalclinkfrom(&$artlist) + { + foreach ($artlist as $art) { + $art->calclinkto($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 filtertagfilter(array $artlist, array $tagchecked, $tagcompare = 'OR') + { + + $filteredlist = []; + foreach ($artlist as $art) { + if (empty($tagchecked)) { + $filteredlist[] = $art->id(); + } else { + $inter = (array_intersect($art->tag('array'), $tagchecked)); + if ($tagcompare == 'OR') { + if (!empty($inter)) { + $filteredlist[] = $art->id(); + } + } elseif ($tagcompare == 'AND') { + if (!array_diff($tagchecked, $art->tag('array'))) { + $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; + + } + + public function tag(array $artlist, $tagchecked) + { + $artcheckedlist = []; + foreach ($artlist as $art) { + if (in_array($tagchecked, $art->tag('array'))) { + $artcheckedlist[] = $art; + } + } + return $artcheckedlist; + } + + public function taglist(array $artlist, array $tagcheckedlist) + { + $taglist = []; + foreach ($tagcheckedlist as $tag) { + $taglist[$tag] = $this->tag($artlist, $tag); + } + return $taglist; + } + + public function count() + { + return $this->bdd->query(' SELECT COUNT(*) FROM ' . $this->arttable . ' ')->fetchColumn(); + } + +} + + + + + +?>
\ No newline at end of file diff --git a/w/class/modelconfig.php b/w/class/modelconfig.php new file mode 100644 index 0000000..748edb1 --- /dev/null +++ b/w/class/modelconfig.php @@ -0,0 +1,39 @@ +<?php + +class Modelconfig extends Model +{ + public function readconfig() + { + if (file_exists(self::CONFIG_FILE)) { + $current = file_get_contents(self::CONFIG_FILE); + $donnees = json_decode($current, true); + return new Config($donnees); + } else { + return 0; + } + + } + + public function createconfig(array $donnees) + { + return new Config($donnees); + } + + + public function savejson(string $json) + { + file_put_contents(self::CONFIG_FILE, $json); + } + + + + +} + + + + + + + +?>
\ No newline at end of file diff --git a/w/class/modeldb.php b/w/class/modeldb.php new file mode 100644 index 0000000..7814acd --- /dev/null +++ b/w/class/modeldb.php @@ -0,0 +1,133 @@ +<?php +class Modeldb extends Model +{ + protected $bdd; + protected $arttable; + + public function __construct() { + parent::__construct(); + $this->setbdd(); + } + + + + public function setbdd() + { + $caught = true; + + try { + $this->bdd = new PDO('mysql:host=' . $this->config->host() . ';dbname=' . $this->config->dbname() . ';charset=utf8', $this->config->user(), $this->config->password(), array(PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT)); + //$this->bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } catch (PDOException $e) { + $caught = false; + echo '<h1>Error 500, database offline</h1>'; + if ($this->session() >= self::EDITOR) { + echo '<p>Error : ' . $e->getMessage() . '</p>'; + if ($this->session() == self::ADMIN) { + echo '<p>Go to the <a href="?aff=admin">Admin Panel</a> to edit your database credentials</p>'; + } else { + echo '<p>Logout and and come back with an <strong>admin password</strong> to edit the database connexions settings.</p>'; + } + } else { + echo '<p><a href=".">Homepage for admin login</a> (connect on the top right side)</p>'; + } + exit; + } + + return $caught; + + } + + public function settable(Config $config) + { + if (!empty($config->arttable())) { + $this->arttable = $config->arttable(); + } else { + echo '<h1>Table Error</h1>'; + + if ($this->session() >= self::EDITOR) { + if ($this->session() == self::ADMIN) { + echo '<p>Go to the <a href="?aff=admin">Admin Panel</a> to select or add an Article table</p>'; + } else { + echo '<p>Logout and and come back with an <strong>admin password</strong> to edit table settings.</p>'; + } + } else { + echo '<p><a href=".">Homepage for admin login</a> (connect on the top right side)</p>'; + } + $caught = false; + exit; + } + } + + public function bddinit(Config $config) + { + $test = $this->setbdd($config); + if ($test) { + $this->settable($config); + } + } + + + + public function tableexist($dbname, $tablename) + { + + $req = $this->bdd->prepare('SELECT COUNT(*) + FROM information_schema.tables + WHERE table_schema = :dbname AND + table_name like :tablename'); + $req->execute(array( + 'dbname' => $dbname, + 'tablename' => $tablename + )); + $donnees = $req->fetch(PDO::FETCH_ASSOC); + $req->closeCursor(); + $exist = intval($donnees['COUNT(*)']); + return $exist; + + + + + } + + public function tablelist($dbname) + { + $request = 'SHOW TABLES IN ' . $dbname; + $req = $this->bdd->query($request); + $donnees = $req->fetchAll(PDO::FETCH_ASSOC); + $req->closeCursor(); + + $arttables = []; + foreach ($donnees as $table) { + $arttables[] = $table['Tables_in_' . $dbname]; + } + return $arttables; + + + } + + + + + + public function tableduplicate($dbname, $arttable, $tablename) + { + $arttable = strip_tags($arttable); + $tablename = str_clean($tablename); + if ($this->tableexist($dbname, $arttable) && !$this->tableexist($dbname, $tablename)) { + $duplicate = " CREATE TABLE `$tablename` LIKE `$arttable`;"; + $alter = "ALTER TABLE `$tablename` ADD PRIMARY KEY (`id`);"; + $insert = "INSERT `$tablename` SELECT * FROM `$arttable`;"; + + + $req = $this->bdd->query($duplicate . $alter . $insert); + + return 'tableduplicated'; + } else { + return 'tablealreadyexist'; + } + } + + + +} diff --git a/w/class/modelhome.php b/w/class/modelhome.php new file mode 100644 index 0000000..660352f --- /dev/null +++ b/w/class/modelhome.php @@ -0,0 +1,59 @@ +<?php + +class Modelhome extends Modeldb +{ + public function table2() + { + $artmanager = new Modelart; + + $opt = new Opt(Art2::classvarlist()); + $opt->setcol(['id', 'tag', 'linkfrom', 'contenu', 'description', 'title', 'datemodif', 'datecreation', 'secure']); + $table = $artmanager->getlisteropt($opt); + $artmanager->listcalclinkfrom($table); + $opt->settaglist($table); + $opt->submit(); + + + $opt->setcol(['id', 'tag', 'linkfrom', 'contenu', 'description', 'title', 'datemodif', 'datecreation', 'secure', 'linkto']); + + + //$aff->option($app, $opt); + + echo '<h3>Options</h3>'; + + + $filtertagfilter = $artmanager->filtertagfilter($table, $opt->tagfilter(), $opt->tagcompare()); + $filtersecure = $artmanager->filtersecure($table, $opt->secure()); + + $filter = array_intersect($filtertagfilter, $filtersecure); + $table2 = []; + $table2invert = []; + foreach ($table as $art) { + if (in_array($art->id(), $filter)) { + $table2[] = $art; + } else { + $table2invert[] = $art; + } + + + } + + if (!empty($opt->invert())) { + $table2 = $table2invert; + } + + $artmanager->artlistsort($table2, $opt->sortby(), $opt->order()); + + + return $table2; + } +} + + + + + + + + +?>
\ No newline at end of file diff --git a/w/class/modelmassedit.php b/w/class/modelmassedit.php new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/w/class/modelmassedit.php diff --git a/w/class/modelmedia.php b/w/class/modelmedia.php new file mode 100644 index 0000000..9f61609 --- /dev/null +++ b/w/class/modelmedia.php @@ -0,0 +1,98 @@ +<?php + +class Modelmedia extends Model +{ + public function __construct() { + + } + + public function addmedia(array $file, $maxsize = 2 ** 24, $id) + { + $message = 'runing'; + $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 = $this::MEDIA_EXTENSIONS; + if (in_array($extension_upload, $extensions_autorisees)) { + if (!file_exists($this::MEDIA_DIR . $id . '.' . $extension_upload)) { + + $extension_upload = strtolower($extension_upload); + $uploadok = move_uploaded_file($file['media']['tmp_name'], $this::MEDIA_DIR . $id . '.' . $extension_upload); + if ($uploadok) { + $message = 'uploadok'; + } else { + $message = 'uploaderror'; + } + } else { + $message = 'filealreadyexist'; + + } + } + } else { + $message = 'filetoobig'; + + } + + return $message; + } + + + public function getmedia($entry, $dir) + { + $fileinfo = pathinfo($entry); + + $filepath = $fileinfo['dirname'] . '.' . $fileinfo['extension']; + + $donnees = array( + 'id' => str_replace('.' . $fileinfo['extension'], '', $fileinfo['filename']), + 'path' => $dir, + 'extension' => $fileinfo['extension'] + ); + + + + return new Media($donnees); + + } + + public function getlistermedia($dir, $type = "all") + { + if ($handle = opendir($dir)) { + $list = []; + while (false !== ($entry = readdir($handle))) { + if ($entry != "." && $entry != "..") { + + $media = $this->getmedia($entry, $dir); + + + $media->analyse(); + + if (in_array($type, self::MEDIA_TYPES)) { + if ($media->type() == $type) { + $list[] = $media; + } + } else { + $list[] = $media; + } + + + } + } + return $list; + } + + return $list; + + } + + + + +} + + + + +?>
\ No newline at end of file diff --git a/w/class/modeluser.php b/w/class/modeluser.php new file mode 100644 index 0000000..adce383 --- /dev/null +++ b/w/class/modeluser.php @@ -0,0 +1,63 @@ +<?php + + +class Modeluser extends Model +{ + const ADMIN = 10; + const EDITOR = 3; + const INVITE = 2; + const READ = 1; + const FREE = 0; + + public function __construct() + { + parent::__construct(); + } + + public function writesession(User $user) + { + $_SESSION['user'] = (array) $user; + } + + public function readsession() + { + $userdatas = []; + if(array_key_exists('user', $_SESSION)) { + $userdatas = $_SESSION['user']; + } + $user = new User($userdatas); + return $user; + } + + public function login($pass) + { + $user = new User(['level' => $this->passlevel($pass)]); + return $user; + } + + public function passlevel($pass) + { + if (strip_tags($pass) == $this->config->admin()) { + return $level = self::ADMIN; + } elseif (strip_tags($pass) == $this->config->read()) { + return $level = self::READ; + } elseif (strip_tags($pass) == $this->config->editor()) { + return $level = self::EDITOR; + } elseif (strip_tags($pass) == $this->config->invite()) { + return $level = self::INVITE; + } + } + + public function logout() + { + $user = new User(['level' => 0]); + return $user; + } +} + + + + + + +?>
\ No newline at end of file diff --git a/w/class/class.w.opt.php b/w/class/opt.php index 7164cb7..f1cb4df 100644 --- a/w/class/class.w.opt.php +++ b/w/class/opt.php @@ -6,8 +6,8 @@ class Opt private $tagfilter = []; private $tagcompare = 'OR'; private $secure = 4; - private $liento = ['min' => '0', 'max' => '0']; - private $lienfrom = ['min' => '0', 'max' => '0']; + private $linkto = ['min' => '0', 'max' => '0']; + private $linkfrom = ['min' => '0', 'max' => '0']; private $col = ['id']; private $taglist = []; private $invert = 0; @@ -115,14 +115,14 @@ class Opt return $this->tagcompare; } - public function liento($type = 'array') + public function linkto($type = 'array') { - return $this->liento; + return $this->linkto; } - public function lienfrom($type = 'array') + public function linkfrom($type = 'array') { - return $this->lienfrom; + return $this->linkfrom; } public function col($type = 'array') @@ -194,34 +194,34 @@ class Opt } } - public function setliento($range) + public function setlinkto($range) { - $this->liento = $range; + $this->linkto = $range; } - public function setlienfrom($range) + public function setlinkfrom($range) { - $this->lienfrom = $range; + $this->linkfrom = $range; } - public function setlientomin($min) + public function setlinktomin($min) { - $this->liento['min'] = intval($min); + $this->linkto['min'] = intval($min); } - public function setlientomax($max) + public function setlinktomax($max) { - $this->liento['max'] = intval($max); + $this->linkto['max'] = intval($max); } - public function setlienfrommin($min) + public function setlinkfrommin($min) { - $this->lienfrom['min'] = intval($min); + $this->linkfrom['min'] = intval($min); } - public function setlienfrommax($max) + public function setlinkfrommax($max) { - $this->lienfrom['max'] = intval($max); + $this->linkfrom['max'] = intval($max); } public function setcol($col) diff --git a/w/class/class.w.quickcss.php b/w/class/quickcss.php index dc7dbac..dc7dbac 100644 --- a/w/class/class.w.quickcss.php +++ b/w/class/quickcss.php diff --git a/w/class/class.w.record.php b/w/class/record.php index e488383..e488383 100644 --- a/w/class/class.w.record.php +++ b/w/class/record.php diff --git a/w/class/route.php b/w/class/route.php new file mode 100644 index 0000000..cc2fe59 --- /dev/null +++ b/w/class/route.php @@ -0,0 +1,84 @@ +<?php + +class Route +{ + protected $id = null; + protected $aff = null; + protected $action = null; + protected $redirect = null; + + const AFF = ['read', 'edit', 'admin', 'media']; + + public function __construct($vars) + { + $this->hydrate($vars); + } + + public function hydrate($vars) + { + foreach ($vars as $var => $value) { + $method = 'set' . $var; + if (method_exists($this, $method)) { + $this->$method($value); + } + } + } + + public function toarray() + { + $array = []; + if (!empty($this->id)) { + $array[] = 'art'; + } + if (!empty($this->aff)) { + $array[] = 'aff='.$this->aff; + } + if (!empty($this->action)) { + $array[] = 'action=' . $this->action; + } + if (!empty($this->redirect)) { + $array[] = $this->redirect; + } + + + return $array; + } + + function tostring() + { + return implode(' ', $this->toarray()); + } + + + + public function setid($id) + { + $this->id = $id; + } + + public function setaff($aff) + { + $this->aff = $aff; + + } + + public function setaction($action) + { + $this->action = $action; + } + + public function setredirect($redirect) + { + $this->redirect = $redirect; + } + + public function id() + { + return $this->id; + } +} + + + + +?>
\ No newline at end of file diff --git a/w/class/router.php b/w/class/router.php new file mode 100644 index 0000000..4d9d718 --- /dev/null +++ b/w/class/router.php @@ -0,0 +1,63 @@ +<?php + + +class Router +{ + protected $route; + + const ROUTES = [ + 'art' => ['art', 'read'], + 'art aff=read' => ['art', 'read'], + 'art aff=edit' => ['art', 'edit'], + 'art action=update home' => ['art', 'update', 'home'], + 'art action=add' => ['art', 'add'], + 'art action=delete' => ['art', 'delete'], + 'aff=home action=massedit', + 'aff=home' => ['home', 'desktop'], + '' => ['home', 'desktop'], + 'aff=home action=massedit' => ['home', 'massedit'], + 'action=massedit' => ['home', 'massedit'], + 'art action=login' => ['art', 'login'], + 'home action=login' => ['home', 'login'], + 'action=login' => ['home', 'login'], + 'aff=media' => ['media', 'desktop'], + 'aff=media action=addmedia' => ['media', 'addmedia'], + ]; + + public function __construct() { + if($this->matchroute()) { + $this->callmethod(); + } else { + echo '<h1>404 Error</h1>'; + } + } + + public function matchroute() + { + $this->route = new route($_GET); + $match = array_key_exists($this->route->tostring(), self::ROUTES); + return $match; + + } + + public function callmethod() + { + $method = self::ROUTES[$this->route->tostring()]; + + $class = 'controller' . $method[0]; + $function = $method[1]; + $controller = new $class($this->route->artid()); + $params = array_slice($method, 2); + $controller->$function(...$params); + } + + + +} + + + + + + +?>
\ No newline at end of file diff --git a/w/class/user.php b/w/class/user.php new file mode 100644 index 0000000..3ed831d --- /dev/null +++ b/w/class/user.php @@ -0,0 +1,37 @@ +<?php + +class User +{ + protected $level = 0; + + public function __construct($datas = []) { + if(!empty($datas)) { + $this->hydrate($datas); + } + } + + public function hydrate(array $datas = []) + { + foreach ($datas as $key => $value) { + $method = 'set' . $key; + + if (method_exists($this, $method)) { + $this->$method($value); + } + } + } + + public function setlevel($level) + { + $this->level = $level; + } + + public function level() + { + return $this->level; + } +} + + + +?>
\ No newline at end of file diff --git a/w/controller/w.article.php b/w/class/w.article.php index 307caa4..2476353 100644 --- a/w/controller/w.article.php +++ b/w/class/w.article.php @@ -6,15 +6,14 @@ if ($app->exist($_GET['id'])) { if (isset($_GET['edit']) and $_GET['edit'] == 1 and $app->session() >= $app::EDITOR) { echo '<section class=edit>'; - $aff->edit($art, $app, $app->getlister(['id', 'titre']), $config->fontsize(), $app->getlistermedia($app::MEDIA_DIR, 'image')); - //$aff->copy($art, $app->getlister(['id', 'titre'])); + $aff->edit($art, $app, $app->getlister(['id', 'title']), $config->fontsize(), $app->getlistermedia($app::MEDIA_DIR, 'image')); $aff->aside($app); echo '</section>'; } else { echo '<section class="lecture">'; - $art->autotaglistupdate($app->taglist($app->getlister(['id', 'titre', 'intro', 'tag']), $art->autotaglist())); + $art->autotaglistupdate($app->taglist($app->getlister(['id', 'title', 'description', 'tag']), $art->autotaglist())); $aff->lecture($art, $app); diff --git a/w/controller/w.home.php b/w/class/w.home.php index 3094d03..8ba8b44 100644 --- a/w/controller/w.home.php +++ b/w/class/w.home.php @@ -10,10 +10,10 @@ if ($app->session() >= $app::EDITOR) { $app->bddinit($config); - $opt = new Opt(Art::classvarlist()); - $opt->setcol(['id', 'tag', 'lien', 'contenu', 'intro', 'titre', 'datemodif', 'datecreation', 'secure']); + $opt = new Opt(Art2::classvarlist()); + $opt->setcol(['id', 'tag', 'linkfrom', 'contenu', 'description', 'title', 'datemodif', 'datecreation', 'secure']); $table = $app->getlisteropt($opt); - $app->listcalclien($table); + $app->listcalclinkfrom($table); $opt->settaglist($table); $opt->submit(); @@ -27,7 +27,7 @@ if ($app->session() >= $app::EDITOR) { - $opt->setcol(['id', 'tag', 'lien', 'contenu', 'intro', 'titre', 'datemodif', 'datecreation', 'secure', 'liento']); + $opt->setcol(['id', 'tag', 'linkfrom', 'contenu', 'description', 'title', 'datemodif', 'datecreation', 'secure', 'linkto']); $aff->option($app, $opt); diff --git a/w/controller/w.menu.php b/w/class/w.menu.php index 8e89ed1..8e89ed1 100644 --- a/w/controller/w.menu.php +++ b/w/class/w.menu.php diff --git a/w/fn/w.fn.php b/w/fn/w.fn.php index 72c98c1..fe3ea48 100644 --- a/w/fn/w.fn.php +++ b/w/fn/w.fn.php @@ -9,10 +9,6 @@ function bddconnect($host, $bdname, $user, $password) return $bdd; } -function my_autoloader($class) -{ - require(__DIR__.'/../class/class.w.' . strtolower($class) . '.php'); -} function secure() { diff --git a/w/view/templates/base.php b/w/view/templates/base.php new file mode 100644 index 0000000..aaca8e1 --- /dev/null +++ b/w/view/templates/base.php @@ -0,0 +1,10 @@ +<html> +<head> + <title><?=$this->e($title)?></title> +</head> +<body> + +<?=$this->section('content')?> + +</body> +</html>
\ No newline at end of file diff --git a/w/view/templates/media.php b/w/view/templates/media.php new file mode 100644 index 0000000..8b189d5 --- /dev/null +++ b/w/view/templates/media.php @@ -0,0 +1,4 @@ +<?php $this->layout('base', ['title' => 'Media']) ?> + +<h1>Media</h1> +<p>Hello, <?=$this->e($interface)?></p>
\ No newline at end of file diff --git a/w/view/templates/nav.php b/w/view/templates/nav.php new file mode 100644 index 0000000..e731673 --- /dev/null +++ b/w/view/templates/nav.php @@ -0,0 +1,42 @@ +<div class="menu"> + <?= $this->e($level) ?> + <div id="dropmenu"> + + <a class="button" href="?">home</a> + + <!-- id if level == 0 --> + <form action="./?action=login<?= isset($this->e($id)) ? '&id=' . $this->e($id) : '' ?>" method="post"> + <input type="password" name="pass" id="loginpass" placeholder="password"> + <input type="submit" value="login"> + </form> + + + <!-- id if level > 0 --> + <form action="./?action=logout<?= isset($this->e($id)) ? '&id=' . $this->e($id) : '' ?>" method="post"> + <input type="submit" value="logout"> + </form> + + + <!-- display / edit --> + + + if ($app->session() >= $app::EDITOR && isset($_GET['id']) && $app->exist($_GET['id'])) { + if (isset($_GET['edit']) && $_GET['edit'] == 1) { + echo '<a class="button" href="?id=' . $_GET['id'] . '" target="_blank">display</a>'; + } else { + echo '<a class="button" href="?id=' . $_GET['id'] . '&edit=1" >edit</a>'; + } + } + if ($app->session() >= $app::EDITOR) { + echo '<a class="button" href="?aff=media" >Media</a>'; + echo '<a class="button" href="?aff=record" >Record</a>'; + if ($app->session() >= $app::ADMIN) { + echo '<a class="button" href="?aff=admin" >Admin</a>'; + } + } + + + + +</div> +</dav>
\ No newline at end of file diff --git a/w/view/templates/read.php b/w/view/templates/read.php new file mode 100644 index 0000000..4d9a58f --- /dev/null +++ b/w/view/templates/read.php @@ -0,0 +1,20 @@ +<html> + + + +<head> + <meta charset="utf8" /> + <meta name="description" content="<?= $art->description() ?>" /> + <meta name="viewport" content="width=device-width" /> + <link rel="shortcut icon" href="./media/logo.png" type="image/x-icon"> + <link href="<?= $globalcss ?>" rel="stylesheet" /> + <?= $edit == 0 ? '<link href="' . $globalcss . '" rel="stylesheet" />' : '<link href="./rsc/css/styleedit.css" rel="stylesheet" />' ?> + <title><?= $edit == 1 ? '✏' : '' ?> <?= $art->title() ?></title> + <script src="./rsc/js/app.js"></script> +</head> + +<?= $html ?> + + + +</html>
\ No newline at end of file diff --git a/w/view/templates/reader.php b/w/view/templates/reader.php new file mode 100644 index 0000000..7561ae3 --- /dev/null +++ b/w/view/templates/reader.php @@ -0,0 +1,38 @@ +<html> +<head> + <meta charset="utf8" /> + <meta name="description" content="<?=$this->e($description)?>" /> + <link href="<?=$this->e($id)?>quickcss" rel="stylesheet" /> + <link href="<?=$this->e($id)?>" rel="stylesheet" /> + <title><?=$this->e($title)?></title> + +</head> + +<script> +<?=$this->e($javascript)?> +</script> + +<body> + +<header> +<?=$this->e($header)?> +</header> + +<nav> +<?=$this->e($nav)?> +</nav> + +<aside> +<?=$this->e($aside)?> +</aside> + +<section> +<?=$this->e($section)?> +</section> + +<footer> +<?=$this->e($footer)?> +</footer> + +</body> +</html>
\ No newline at end of file diff --git a/w/w.router.php b/w/w.index.php index e1c7b62..a2f0ea7 100644 --- a/w/w.router.php +++ b/w/w.index.php @@ -2,18 +2,43 @@ // _____________________________________________________ R E Q U I R E ________________________________________________________________ + + session_start(); require(__DIR__.'/fn/w.fn.php'); + +function class_autoloader($class) +{ + require(__DIR__. DIRECTORY_SEPARATOR . 'class'. DIRECTORY_SEPARATOR . strtolower($class) . '.php'); +} + + + + + require(__DIR__.'/../vendor/autoload.php'); -spl_autoload_register('my_autoloader'); +spl_autoload_register('class_autoloader'); + +$_SESSION['user'] = ['level' => 10]; + + +$router = new Router; + + + + + + +exit; + // ________________________________________________________ I N S T A L _________________________________________________ $app = new App(); @@ -53,6 +78,12 @@ $app->setsession($session); // _______________________________________________________ A C T I O N __________________________________________________________________ +$router = new Router; + + + + + if (isset($_POST['action'])) { switch ($_POST['action']) { @@ -107,7 +138,7 @@ if (isset($_POST['action'])) { case 'new': if (isset($_GET['id'])) { - $art = new Art($_GET); + $art = new Art2($_GET); $art->reset(); $app->add($art); header('Location: ?id=' . $_GET['id'] . '&edit=1'); @@ -116,9 +147,9 @@ if (isset($_POST['action'])) { case 'update': if ($app->exist($_GET['id'])) { - $art = new Art($_POST); - $art->updatelien(); - $art->autotaglistcalc($app->taglist($app->getlister(['id', 'titre', 'tag']), $art->autotaglist())); + $art = new Art2($_POST); + $art->updatelinkfrom(); + $art->autotaglistcalc($app->taglist($app->getlister(['id', 'title', 'tag']), $art->autotaglist())); $app->update($art); if($config->fontsize() != $_POST['fontsize']) { $config->setfontsize($_POST['fontsize']); @@ -130,9 +161,9 @@ if (isset($_POST['action'])) { case 'display': if ($app->exist($_GET['id'])) { - $art = new Art($_POST); - $art->updatelien(); - $art->autotaglistcalc($app->taglist($app->getlister(['id', 'titre', 'tag']), $art->autotaglist())); + $art = new Art2($_POST); + $art->updatelinkfrom(); + $art->autotaglistcalc($app->taglist($app->getlister(['id', 'title', 'tag']), $art->autotaglist())); $app->update($art); if($config->fontsize() != $_POST['fontsize']) { $config->setfontsize($_POST['fontsize']); @@ -144,9 +175,9 @@ if (isset($_POST['action'])) { case 'home': if ($app->exist($_GET['id'])) { - $art = new Art($_POST); - $art->updatelien(); - $art->autotaglistcalc($app->taglist($app->getlister(['id', 'titre', 'tag']), $art->autotaglist())); + $art = new Art2($_POST); + $art->updatelinkfrom(); + $art->autotaglistcalc($app->taglist($app->getlister(['id', 'title', 'tag']), $art->autotaglist())); $app->update($art); if($config->fontsize() != $_POST['fontsize']) { $config->setfontsize($_POST['fontsize']); @@ -156,33 +187,9 @@ if (isset($_POST['action'])) { } break; - case 'copy': - if ($app->exist($_GET['id'])) { - $copy = $app->get($_POST['copy']); - $art = $app->get($_POST['id']); - if (!empty($_POST['css'])) { - $art->setcss($copy->css()); - } - if (!empty($_POST['color'])) { - $art->setcouleurtext($copy->couleurtext()); - $art->setcouleurbkg($copy->couleurbkg()); - $art->setcouleurlien($copy->couleurlien()); - $art->setcouleurlienblank($copy->couleurlienblank()); - } - if (!empty($_POST['html'])) { - $art->sethtml($copy->md()); - } - if (!empty($_POST['template'])) { - $art->settemplate($copy->template()); - } - $app->update($art); - header('Location: ?id=' . $art->id() . '&edit=1'); - } - break; - case 'delete': if ($app->exist($_GET['id'])) { - $art = new Art($_POST); + $art = new Art2($_POST); $app->delete($art); header('Location: ?id=' . $art->id()); } @@ -343,11 +350,11 @@ if (array_key_exists('id', $_GET)) { } elseif (array_key_exists('tag', $_GET)) { $app->bddinit($config); echo '<h4>' . $_GET['tag'] . '</h4>'; - $aff->tag($app->getlister(['id', 'titre', 'intro', 'tag']), $_GET['tag'], $app); -} elseif (array_key_exists('lien', $_GET)) { + $aff->tag($app->getlister(['id', 'title', 'description', 'tag']), $_GET['tag'], $app); +} elseif (array_key_exists('linkfrom', $_GET)) { $app->bddinit($config); - echo '<h4><a href="?id=' . $_GET['lien'] . '">' . $_GET['lien'] . '</a></h4>'; - $aff->lien($app->getlister(['id', 'titre', 'intro', 'lien']), $_GET['lien'], $app); + echo '<h4><a href="?id=' . $_GET['linkfrom'] . '">' . $_GET['linkfrom'] . '</a></h4>'; + $aff->linkfrom($app->getlister(['id', 'title', 'description', 'linkfrom']), $_GET['linkfrom'], $app); } elseif (array_key_exists('aff', $_GET)) { include(__DIR__.'/controller/w.menu.php'); } else { |