diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2018-10-18 01:08:46 +0200 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2018-10-18 01:08:46 +0200 |
commit | 7b2e48276b2a3ceff83c906d38077f8d0479c3df (patch) | |
tree | 0fc26bb1cbae5a30583292fbfb2b752fb623a94d | |
parent | 65796d4a2349e71ca05f5f298d6f94ff792d88b2 (diff) | |
download | wcms-7b2e48276b2a3ceff83c906d38077f8d0479c3df.tar.gz wcms-7b2e48276b2a3ceff83c906d38077f8d0479c3df.zip |
2.92 new architecture + quickcss class
-rw-r--r-- | .gitignore | 6 | ||||
-rw-r--r-- | public/index.php | 11 | ||||
-rw-r--r-- | public/test.php | 277 | ||||
-rw-r--r-- | public/test2.php | 84 | ||||
-rw-r--r-- | public/w/index.php | 359 | ||||
-rw-r--r-- | public/w/rsc/css/styleadmin.css (renamed from public/w/css/styleadmin.css) | 0 | ||||
-rw-r--r-- | public/w/rsc/css/stylebase.css (renamed from public/w/css/stylebase.css) | 0 | ||||
-rw-r--r-- | public/w/rsc/css/styleedit.css (renamed from public/w/css/styleedit.css) | 0 | ||||
-rw-r--r-- | public/w/rsc/css/stylehome.css (renamed from public/w/css/stylehome.css) | 0 | ||||
-rw-r--r-- | public/w/rsc/css/styleinfo.css (renamed from public/w/css/styleinfo.css) | 0 | ||||
-rw-r--r-- | public/w/rsc/css/stylemedia.css (renamed from public/w/css/stylemedia.css) | 0 | ||||
-rw-r--r-- | public/w/rsc/css/stylerecord.css (renamed from public/w/css/stylerecord.css) | 0 | ||||
-rw-r--r-- | w/class/class.w.aff.php (renamed from class/class.w.aff.php) | 67 | ||||
-rw-r--r-- | w/class/class.w.app.php (renamed from class/class.w.app.php) | 130 | ||||
-rw-r--r-- | w/class/class.w.art.php (renamed from class/class.w.art.php) | 0 | ||||
-rw-r--r-- | w/class/class.w.art2.php | 585 | ||||
-rw-r--r-- | w/class/class.w.config.php (renamed from class/class.w.config.php) | 11 | ||||
-rw-r--r-- | w/class/class.w.media.php (renamed from class/class.w.media.php) | 0 | ||||
-rw-r--r-- | w/class/class.w.opt.php (renamed from class/class.w.opt.php) | 0 | ||||
-rw-r--r-- | w/class/class.w.quickcss.php | 291 | ||||
-rw-r--r-- | w/class/class.w.record.php (renamed from class/class.w.record.php) | 0 | ||||
-rw-r--r-- | w/controller/w.article.php (renamed from public/w/article.php) | 0 | ||||
-rw-r--r-- | w/controller/w.home.php (renamed from public/w/home.php) | 0 | ||||
-rw-r--r-- | w/controller/w.menu.php (renamed from public/w/menu.php) | 0 | ||||
-rw-r--r-- | w/fn/w.fn.php (renamed from fn/fn.w.php) | 2 | ||||
-rw-r--r-- | w/w.router.php | 359 |
26 files changed, 1602 insertions, 580 deletions
@@ -1,6 +1,8 @@ vendor/* .vscode/* -config.w.json +w/w.config.json error_log public/w/media/* -public/w/css/read/* +public/w/css/* +public/w/js/* +public/index.html diff --git a/public/index.php b/public/index.php deleted file mode 100644 index ab7ff55..0000000 --- a/public/index.php +++ /dev/null @@ -1,11 +0,0 @@ -<html> -<h1>Vincent Peugnet</h1> -<a href="/w/"><h2>W</h2></a> - -<h2>@</h2> -<a href="mailto:v.peugnet@free.fr">v.peugnet@free.fr</a> - -<h1>📐</h1> - - -</html>
\ No newline at end of file diff --git a/public/test.php b/public/test.php index 6e5e835..aee0004 100644 --- a/public/test.php +++ b/public/test.php @@ -1,119 +1,186 @@ <?php -$text = 'gfgdfgdfgdsggggggggggggg -dfgdsfgdh -dh - -gh -g -hg -fhhhhhhhhhhhhhhhhhhgfghfghfgh - -fhfgfgdfgdfgdsggggggggggggg -dfgdsfgdh -dh - -gh -g -hg -fhhhhhhhhhhhhhhhhhhgfghfghfgh - -fhf<h3 id="titre2laguerre">tiTre2:laguerre</h3> dqs fdddddddfdfdsfs fdsfdksdfjnsdjkhsf lkfljkfhjldshsf fsdf -fdgfgdfgdfgdsggggggggggggg -dfgdsfgdh -dh - -gh -g -hg -fhhhhhhhhhhhhhhhhhhgfghfghfgh -<p> -fhfgfgdfgdfgdsggggggggggggg -dfgdsfgdh</p> -dh</br>dh</br>dh</br>dh</br>dh</br>dh</br>dh</br>dh</br>dh</br> - -gh<p> -g -hg</p> -fhhhhhhhhhhhhhhhhhhgfghfghfgh -gh -g -hg -fhhhhhhhhhhhhhhhhhhgfghfghfgh -<p> -fhfgfgdfgdfgdsggggggggggggg -dfgdsfgdh</p> -dh</br>dh</br>dh</br>dh</br>dh</br>dh</br>dh</br>dh</br>dh</br> - -gh<p> -g -hg</p> -fhhhhhhhhhhhhhhhhhhgfghfghfgh -gh -<h1 id="yolo">YOLO</h1> -<h2 id="ptout">PROUT</h2> -<h2 id="lol">LOLDELAMORT</h2> -hg -fhhhhhhhhhhhhhhhhhhgfghfghfgh - -<p> -fhfgfgdfgdfgdsggggggggggggg -dfgdsfgdh</p> -dh</br>dh</br>dh</br>dh</br>dh</br>dh</br>dh</br>dh</br>dh</br> - -gh<p> -g -hg</p> -fhhhhhhhhhhhhhhhhhhgfghfghfgh - -fhf -g -hffffgggggggggggggggggggggggggggggggggggggdsf <h3>titre 3- les hommes </h3> la fin'; - - -function sumparser($text) -{ - preg_match_all('#<h([1-6]) id="(\w+)">(.+)</h[1-6]>#iU', $text, $out); - - var_dump($out); - - $sum = []; - foreach ($out[2] as $key => $value) { - $sum[$value][$out[1][$key]] = $out[3][$key]; + + +require('../w/class/class.w.quickcss.php'); + +$quick = new Quickcss; + + + +var_dump($quick); + + + + +$color = ['color', 'background-color', 'border-color']; +$size = ['width', 'height', 'margin', 'padding', 'border-width']; +$font = ['font-size']; +$unique = ['background-image', 'opacity', 'border-style', 'text-align']; +$params = array_merge($color, $size, $font, $unique); + + + + + + +// $presets = ['body' => ['font-size' => 'px']]; +// $quickcss = ['section' => ['color' => '#a74545', 'font-size' => '32px'], 'p' => ['background-color' => '#458da7', 'width' => '7px']]; + +$presets = []; +$quickcss = []; + +if (isset($_POST['quickcss'])) { + $quickcss = $_POST['quickcss']; +} + +if (isset($_POST['presets'])) { + $presets = $_POST['presets']; +} + + +if (isset($_POST['active'])) { + $active = $_POST['active']; + echo '<h3>active</h3>'; + var_dump($active); + $intersect = array_intersect_key($quickcss, $active); + + foreach ($intersect as $element => $css) { + $intersect[$element] = array_intersect_key($quickcss[$element], $active[$element]); } + + echo '<h3>intersect</h3>'; + var_dump($intersect); + + $quickcss = $intersect; + + +} + + +if (!empty($_POST['new']['element']) && !empty($_POST['new']['param']) && in_array($_POST['new']['param'], $params)) { + $new = array($_POST['new']['element'] => array($_POST['new']['param'] => '')); + var_dump($new); + + $quickcss = array_merge_recursive($quickcss, $new); +} + + + + +echo '<h3>quickcss</h3>'; + +var_dump($quickcss); + +echo '<h3>presets</h3>'; - var_dump($sum); - - $sumstring = ''; - $last = 0; - foreach ($sum as $title => $list) { - foreach ($list as $h => $link) { - if($h > $last) { - for ($i = 1; $i <= ($h - $last); $i++) { - $sumstring .= '<ul>'; - } - $sumstring .= '<li><a href="#'.$title.'">'.$link.'</a></li>' ; - } elseif ($h < $last) { - for ($i = 1; $i <= ($last - $h); $i++) { - $sumstring .= '</ul>'; - } - $sumstring .= '<li><a href="#'.$title.'">'.$link.'</a></li>' ; - } elseif ($h = $last) { - $sumstring .= '<li><a href="#'.$title.'">'.$link.'</a></li>' ; - } - $last = $h; +var_dump($presets); + +foreach ($presets as $element => $preset) { + foreach ($preset as $param => $unit) { + if (array_key_exists($element, $quickcss) && array_key_exists($param, $quickcss[$element])) { + $quickcss[$element][$param] .= $unit; } } - for ($i = 1; $i <= ($last); $i++) { - $sumstring .= '</ul>'; +} + + +$jsonquickcss = json_encode($quickcss); + +var_dump($jsonquickcss); + +$string = ''; +foreach ($quickcss as $key => $css) { + $string .= PHP_EOL . $key . ' {'; + foreach ($css as $param => $value) { + + $string .= PHP_EOL . ' ' . $param . ': ' . $value . ';'; + + } + $string .= PHP_EOL . '}' . PHP_EOL; +} + +var_dump($string); + + + + +echo '<form action="test.php" method="post">'; + +foreach ($quickcss as $element => $css) { + echo '<h3>' . $element . '</h3>'; + foreach ($css as $param => $value) { + + echo '<input type="checkbox" name="active[' . $element . '][' . $param . ']" checked>'; + + if (in_array($param, $color)) { + echo '<label for="quickcss[' . $element . '][' . $param . ']">' . $param . '</label>'; + echo '<input type="color" name="quickcss[' . $element . '][' . $param . ']" value="' . $quickcss[$element][$param] . '" id="quickcss[' . $element . '][' . $param . ']">'; + } + + if (in_array($param, $size)) { + echo '<label for="quickcss[' . $element . '][' . $param . ']">' . $param . '</label>'; + echo '<input type="number" name="quickcss[' . $element . '][' . $param . ']" value="' . intval($quickcss[$element][$param]) . '" id="quickcss[' . $element . '][' . $param . ']">'; + + $unit = preg_replace('/\d/', '', $quickcss[$element][$param]); + ?> + <select name="presets[<?= $element ?>][<?= $param ?>]" > + <option value="px" <?= $unit == 'px' ? 'selected' : '' ?>>px</option> + <option value="%" <?= $unit == '%' ? 'selected' : '' ?>>%</option> + </select> + <?php + + } + + if (in_array($param, $font)) { + echo '<label for="quickcss[' . $element . '][' . $param . ']">' . $param . '</label>'; + echo '<input type="number" name="quickcss[' . $element . '][' . $param . ']" value="' . intval($quickcss[$element][$param]) . '" id="quickcss[' . $element . '][' . $param . ']">'; + + $unit = preg_replace('/\d/', '', $quickcss[$element][$param]); + ?> + <select name="presets[<?= $element ?>][<?= $param ?>]" > + <option value="px" <?= $unit == 'px' ? 'selected' : '' ?>>px</option> + <option value="em" <?= $unit == 'em' ? 'selected' : '' ?>>em</option> + </select> + <?php + + } } - return $sumstring; } +echo '<h1>Add element</h1>'; + +echo '<input type="text" name="new[element]">'; +echo '<select name="new[param]">'; +foreach ($params as $param) { + echo '<option value="' . $param . '">' . $param . '</option>'; +} +echo '</select>'; + +echo '</br><input type="submit" value="submit">'; + +echo '</form>'; + +?> + + + + +<style> + +<?= $string ?> + + +</style> +<section> + <h4>Yolo babyzesssssss</h4> + <p> + Note that the values of array need to be valid keys, i.e. they need to be either integer or string. A warning will be emitted if a value has the wrong type, and the key/value pair in question will not be included in the result. -echo $sumstring; +If a value has several occurrences, the latest key will be used as its value, and all others will be lost. + </p> -echo $text.'</br>';
\ No newline at end of file +</section>
\ No newline at end of file diff --git a/public/test2.php b/public/test2.php new file mode 100644 index 0000000..a0cbafa --- /dev/null +++ b/public/test2.php @@ -0,0 +1,84 @@ +<?php +session_start(); + + + + +?> + + +<html> + +<div class="prot"> + +<?php + +require('../w/class/class.w.quickcss.php'); + +$quick = new Quickcss($_POST); + +//$quick->setjson($_SESSION['css']); + +$quick->calc(); + +$quick->form('test2.php'); + +$_SESSION['css'] = $quick->tojson(); + + +?> + +</div> + + + + + +<style> + +form { + position: fixed; + right: 0; + top: 0; + width: 250px; + height: 100%; + overflow: scroll; + background-color: #d8d8d8; + border: 1px solid black; + +} + +.quickinput { + width: 100%; + background-color: #755454; + display: inline-flex; +} + +input, select{ + width: -webkit-fill-available; +} + + +<?= $quick->tocss() ?> + +</style> + +<body> +<span class="u">BODY</span> + <section> + <span class="u">SECTION</span> + <h1><span class="u">H1</span>Bonjour tout le monde</h1> + + <p><span class="u">P</span>Des bails de oufs qui toueeeett</p> + + <article> + <span class="u">ARTICLE</span> + <h2><span class="u">H2</span>YOLO</h2> + <p><span class="u">P</span> Des bails noirs très noir....</p> + </article> + + + </section> +</body> + +</html> diff --git a/public/w/index.php b/public/w/index.php index a5b3e03..bc5047e 100644 --- a/public/w/index.php +++ b/public/w/index.php @@ -1,362 +1,5 @@ <?php -// _____________________________________________________ R E Q U I R E ________________________________________________________________ - -session_start(); - - - -require('../../vendor/autoload.php'); -require('../../fn/fn.w.php'); - -spl_autoload_register('my_autoloader'); - - - - -// ________________________________________________________ I N S T A L _________________________________________________ - -$app = new App(); -$aff = new Aff(); - - -$config = $app->readconfig(); -if (!$config) { - $message = 'config_file_error'; - echo $message; - if (isset($_POST['config']) && $_POST['config'] == 'create') { - $config = $app->createconfig($_POST); - $app->savejson($config->tojson()); - header('Location: ./'); - - } else { - $aff->configform(); - } - exit; -} - - -// _________________________________________________________ S E S ___________________________________________________________ - - -if (!isset($_SESSION['level'])) { - $session = 0; -} else { - $session = $_SESSION['level']; -} - -$app->setsession($session); - - - - -// _______________________________________________________ A C T I O N __________________________________________________________________ - - -if (isset($_POST['action'])) { - switch ($_POST['action']) { - - case 'login': - $_SESSION['level'] = $app->login($_POST['pass'], $config); - if (isset($_GET['id'])) { - header('Location: ?id=' . $_GET['id']); - } else { - header('Location: ./'); - } - break; - - case 'logout': - $_SESSION['level'] = $app->logout(); - if (isset($_GET['id'])) { - header('Location: ?id=' . $_GET['id']); - } else { - header('Location: ./'); - } - break; - - case 'addmedia': - $message = $app->addmedia($_FILES, 2 ** 24, $_POST['id']); - header('Location: ./?aff=media&message=' . $message); - break; - - case 'addcss': - $message = $app->addcss($_FILES, 2 ** 24, $_POST['id']); - header('Location: ./?aff=admin&message=' . $message); - break; - - case 'editcss': - file_put_contents($app::CSS_READ_DIR . $config->cssread(), $_POST['editcss']); - header('Location: ./?aff=admin'); - break; - - case 'editconfig': - $config->hydrate($_POST); - $app->savejson($config->tojson()); - header('Location: ./?aff=admin'); - break; - - - } -} - - - -// _____________________________________________________ D A T A B A S E __________________________________________________________________ - -if (isset($_POST['action'])) { - $app->bddinit($config); - - switch ($_POST['action']) { - - case 'new': - if (isset($_GET['id'])) { - $art = new Art($_GET); - $art->reset(); - $app->add($art); - header('Location: ?id=' . $_GET['id'] . '&edit=1'); - } - break; - - case 'update': - if ($app->exist($_GET['id'])) { - $art = new Art($_POST); - $art->updatelien(); - $art->autotaglistcalc($app->taglist($app->getlister(['id', 'titre', 'tag']), $art->autotaglist())); - $app->update($art); - if($config->fontsize() != $_POST['fontsize']) { - $config->setfontsize($_POST['fontsize']); - $app->savejson($config->tojson()); - } - header('Location: ?id=' . $art->id() . '&edit=1&message='.$art->id().'_saved'); - } - break; - - case 'display': - if ($app->exist($_GET['id'])) { - $art = new Art($_POST); - $art->updatelien(); - $art->autotaglistcalc($app->taglist($app->getlister(['id', 'titre', 'tag']), $art->autotaglist())); - $app->update($art); - if($config->fontsize() != $_POST['fontsize']) { - $config->setfontsize($_POST['fontsize']); - $app->savejson($config->tojson()); - } - header('Location: ?id=' . $art->id().'&message='.$art->id().'_saved'); - } - break; - - case 'home': - if ($app->exist($_GET['id'])) { - $art = new Art($_POST); - $art->updatelien(); - $art->autotaglistcalc($app->taglist($app->getlister(['id', 'titre', 'tag']), $art->autotaglist())); - $app->update($art); - if($config->fontsize() != $_POST['fontsize']) { - $config->setfontsize($_POST['fontsize']); - $app->savejson($config->tojson()); - } - header('Location: ./?message='.$art->id().'_saved'); - } - 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); - $app->delete($art); - header('Location: ?id=' . $art->id()); - } - break; - - case 'massedit': - if (isset($_POST['id'])) { - foreach ($_POST['id'] as $id) { - if ($app->exist($id)) { - $art = $app->get($id); - - switch ($_POST['massaction']) { - case 'do': - switch ($_POST['massedit']) { - case 'delete': - $app->delete($art); - break; - - case 'erasetag': - $art->settag(''); - $app->update($art); - break; - - case 'erasetemplate': - $art->settemplate(''); - $app->update($art); - break; - - case 'not published': - $art->setsecure(2); - $app->update($art); - break; - - case 'private': - $art->setsecure(1); - $app->update($art); - break; - - case 'public': - $art->setsecure(0); - $app->update($art); - break; - } - break; - - case 'set template': - if (isset($_POST['masstemplate'])) { - $art->settemplate($_POST['masstemplate']); - $app->update($art); - } - break; - - case 'add tag': - if (isset($_POST['targettag'])) { - $art = $app->get($id); - $tagstring = strip_tags(trim(strtolower($_POST['targettag']))); - $taglist = str_replace(' ', '', $tagstring); - $taglist = explode(",", $taglist); - foreach ($taglist as $tag) { - if (!in_array($tag, $art->tag('array'))) { - $newtaglist = $art->tag('array'); - array_push($newtaglist, $tag); - $art->settag($newtaglist); - } - } - $app->update($art); - } - break; - - } - - - - - } - header('Location: ./'); - } - break; - } - } -} - - - - - -if (isset($_POST['actiondb'])) { - $app->setbdd($config); - - switch ($_POST['actiondb']) { - - case 'addtable': - if (isset($_POST['tablename'])) { - $message = $app->addtable($config->dbname(), $_POST['tablename']); - header('Location: ./?aff=admin&message=' . $message); - } - break; - - case 'duplicatetable': - $message = $app->tableduplicate($config->dbname(), $_POST['arttable'], $_POST['tablename']); - header('Location: ./?aff=admin&message=' . $message); - break; - - } -} - - - - -// _______________________________________________________ H E A D _____________________________________________________________ - -if (isset($_GET['id'])) { - $app->bddinit($config); - if ($app->exist($_GET['id'])) { - $art = $app->get($_GET['id']); - if (!isset($_GET['edit'])) { - $_GET['edit'] = 0; - } - $aff->arthead($art, $app::CSS_READ_DIR, $config->cssread(), $_GET['edit']); - } else { - // $aff->head($_GET['id'], '', 'white'); - $aff->noarthead($_GET['id'], $app::CSS_READ_DIR, $config->cssread()); - - } -} elseif (isset($_GET['aff'])) { - $aff->head($_GET['aff'], $_GET['aff'], $config->color4()); -} else { - $aff->head('home', 'home', $config->color4()); -} - - - - - - - -// _____________________________________________________ A L E R T _______________________________________________________________ - -if (isset($_GET['message'])) { - echo '<span class="alert">' . $_GET['message'] . '</span>'; -} - - - - - - - - -// ______________________________________________________ B O D Y _______________________________________________________________ - - -$aff->nav($app); - -if (array_key_exists('id', $_GET)) { - $app->bddinit($config); - include('article.php'); -} 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)) { - $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); -} elseif (array_key_exists('aff', $_GET)) { - include('menu.php'); -} else { - include('home.php'); -} - - +require('../../w/w.router.php'); ?>
\ No newline at end of file diff --git a/public/w/css/styleadmin.css b/public/w/rsc/css/styleadmin.css index a3fcc5c..a3fcc5c 100644 --- a/public/w/css/styleadmin.css +++ b/public/w/rsc/css/styleadmin.css diff --git a/public/w/css/stylebase.css b/public/w/rsc/css/stylebase.css index 017b075..017b075 100644 --- a/public/w/css/stylebase.css +++ b/public/w/rsc/css/stylebase.css diff --git a/public/w/css/styleedit.css b/public/w/rsc/css/styleedit.css index fe6745f..fe6745f 100644 --- a/public/w/css/styleedit.css +++ b/public/w/rsc/css/styleedit.css diff --git a/public/w/css/stylehome.css b/public/w/rsc/css/stylehome.css index 98822f0..98822f0 100644 --- a/public/w/css/stylehome.css +++ b/public/w/rsc/css/stylehome.css diff --git a/public/w/css/styleinfo.css b/public/w/rsc/css/styleinfo.css index a3fcc5c..a3fcc5c 100644 --- a/public/w/css/styleinfo.css +++ b/public/w/rsc/css/styleinfo.css diff --git a/public/w/css/stylemedia.css b/public/w/rsc/css/stylemedia.css index d721a9b..d721a9b 100644 --- a/public/w/css/stylemedia.css +++ b/public/w/rsc/css/stylemedia.css diff --git a/public/w/css/stylerecord.css b/public/w/rsc/css/stylerecord.css index 409bcd4..409bcd4 100644 --- a/public/w/css/stylerecord.css +++ b/public/w/rsc/css/stylerecord.css diff --git a/class/class.w.aff.php b/w/class/class.w.aff.php index e716630..adb8b61 100644 --- a/class/class.w.aff.php +++ b/w/class/class.w.aff.php @@ -223,25 +223,27 @@ class Aff <summary>Help</summary> <div id="help"> <h2>Help !</h2> - <p>To save your article, clic on the HOME, UPDATE, or DISPLAY buttons. You can use the keyboard shortcuts as well.</p> + <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 Markdown encoding : <a href="https://daringfireball.net/projects/markdown/syntax" target="_blank">synthax</a>. But the following strategies are specific to W.</p> + <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>Tricks</h3> + <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 list of links to all articles under this tag.</p> + <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> @@ -326,8 +328,8 @@ public function head($title, $tool, $color4) <meta charset="utf8" /> <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/style<?= $tool ?>.css" rel="stylesheet" /> + <link href="./rsc/css/stylebase.css" rel="stylesheet" /> + <link href="./rsc/css/style<?= $tool ?>.css" rel="stylesheet" /> <style> :root { --color4: <?= $color4 ?>; @@ -340,7 +342,7 @@ public function head($title, $tool, $color4) } -public function arthead(Art $art, $cssdir, $cssread = '', $edit = 0) +public function arthead(Art $art, $globalcss, $edit = 0) { ?> <head> @@ -348,8 +350,8 @@ public function arthead(Art $art, $cssdir, $cssread = '', $edit = 0) <meta name="description" content="<?= $art->intro() ?>" /> <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" /> - <?= $edit == 0 ? '<link href="' . $cssdir . $cssread . '" rel="stylesheet" />' : '<link href="./css/styleedit.css" rel="stylesheet" />' ?> + <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> <script src="./rsc/js/app.js"></script> </head> @@ -357,7 +359,7 @@ public function arthead(Art $art, $cssdir, $cssread = '', $edit = 0) } -public function noarthead($id, $cssdir, $cssread = '') +public function noarthead($id, $globalcss) { ?> <head> @@ -365,8 +367,8 @@ public function noarthead($id, $cssdir, $cssread = '') <meta name="description" content="This article does not exist yet." /> <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="<?= $cssdir . $cssread ?>" rel="stylesheet" /> + <link href="./rsc/css/stylebase.css" rel="stylesheet" /> + <link href="<?= $globalcss ?>" rel="stylesheet" /> <title>❓ <?= $id ?></title> <script src="./rsc/js/app.js"></script> </head> @@ -619,8 +621,9 @@ public function mapheader() <?php foreach ($curves as $curve) { ?> - <option value="<?= $curve ?>" <?= $selectcurve == $curve ? 'selected' : ''?>><?= $curve ?></option> + <option value="<?= $curve ?>" <?= $selectcurve == $curve ? 'selected' : '' ?>><?= $curve ?></option> <?php + } ?> </select> @@ -629,8 +632,9 @@ public function mapheader() <?php foreach ($orients as $orient) { ?> - <option value="<?= $orient ?>" <?= $selectorient == $orient ? 'selected' : ''?>><?= $orient ?></option> + <option value="<?= $orient ?>" <?= $selectorient == $orient ? 'selected' : '' ?>><?= $orient ?></option> <?php + } ?> </select> @@ -912,33 +916,13 @@ public function nav($app) ?> <article> <h2>CSS</h2> - <p>Current global css : <strong><?= $config->cssread() ?></strong></p> - <details colse> - <summary>Default CSS</summary> - - <p>This CSS will apply to all your articles.</p> - - <form action="?aff=admin" method="post" > - <input type="hidden" name="action" value="editconfig"> - <select name="cssread" required> - <?php - foreach ($app->dirlist($app::CSS_READ_DIR, 'css') as $item) { - if ($item == $config->cssread()) { - echo '<option value="' . $item . '" " selected >' . $item . '</option>'; - } else { - echo '<option value="' . $item . '">' . $item . '</option>'; - } - } - ?> - </select> - <input type="submit" value="choose"> - </form> - </details> + <p>CSS file :</p> + <p><code> <?= $app::GLOBAL_CSS_DIR ?></code></p> <?php - $cssfile = $app::CSS_READ_DIR . $config->cssread(); + $cssfile = $app::GLOBAL_CSS_DIR; if (is_file($cssfile)) { $cssread = file_get_contents($cssfile); echo '<details>'; @@ -952,15 +936,6 @@ public function nav($app) } ?> - <details close> - <summary>Add CSS file</summary> - <form action="./" method="post" enctype="multipart/form-data"> - <input type="hidden" name="action" value="addcss"> - <input type="file" accept=".css" name="css" required> - <input type="text" name="id" id="" placeholder="filename" required> - <input type="submit" value="submit"> - </form> - </details> </article> <?php diff --git a/class/class.w.app.php b/w/class/class.w.app.php index 91d0a41..922740b 100644 --- a/class/class.w.app.php +++ b/w/class/class.w.app.php @@ -6,9 +6,8 @@ class App private $arttable; - const CONFIG_FILE = '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'config.w.json'; - const CSS_READ_DIR = '.' . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . 'read' . DIRECTORY_SEPARATOR; - const SQL_READ_DIR = '.' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'sql' . DIRECTORY_SEPARATOR; + 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 MEDIA_EXTENSIONS = array('jpeg', 'jpg', 'JPG', 'png', 'gif', 'mp3', 'mp4', 'mov', 'wav', 'flac', 'pdf'); const MEDIA_TYPES = ['image', 'video', 'sound', 'other']; @@ -153,6 +152,50 @@ class App } } + public function add2(Art2 $art) + { + + if ($this->exist($art->id())) { + echo '<span class="alert">idalreadyexist</span>'; + } else { + + $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) + 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('string')); + $q->bindValue(':javascript', $art->javascript()); + $q->bindValue(':html', $art->html()); + $q->bindValue(':header', $art->header()); + $q->bindValue(':section', $art->section()); + $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('string')); + $q->bindValue(':template', $art->template('string')); + $q->bindValue(':affcount', $art->affcount()); + $q->bindValue(':editcount', $art->editcount()); + + $q->execute(); + } + } + public function delete(Art $art) { $req = $this->bdd->prepare('DELETE FROM ' . $this->arttable . ' WHERE id = :id '); @@ -200,6 +243,44 @@ class App $q->execute(); } + public function update2(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'; + + $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('string')); + $q->bindValue(':javascript', $art->javascript()); + $q->bindValue(':html', $art->html()); + $q->bindValue(':header', $art->header()); + $q->bindValue(':section', $art->section()); + $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('string')); + $q->bindValue(':template', $art->template('string')); + $q->bindValue(':affcount', $art->affcount()); + $q->bindValue(':editcount', $art->editcount()); + + $q->execute(); + } + @@ -588,50 +669,7 @@ class App //_________________________________________________________ A D M ________________________________________________________ - // public function changecss($lecturecss) - // { - // if (file_exists(self::CONFIG_FILE)) { - // $current = file_get_contents(self::CONFIG_FILE); - // $current = str_replace($this->lecturecss(), $lecturecss, $current); - // file_put_contents(self::CONFIG_FILE, $current); - // return 'css_change_ok'; - // } else { - // return 'css_change_error'; - // } - // } - - public function addcss(array $file, $maxsize = 2 ** 24, $id) - { - $message = 'runing'; - $id = strtolower(strip_tags($id)); - $id = str_replace(' ', '_', $id); - if (isset($file) and $file['css']['error'] == 0 and $file['css']['size'] < $maxsize) { - $infosfichier = pathinfo($file['css']['name']); - $extension_upload = $infosfichier['extension']; - $extensions_autorisees = array('css'); - if (in_array($extension_upload, $extensions_autorisees)) { - if (!file_exists($this::CSS_READ_DIR . $id . '.' . $extension_upload)) { - - $extension_upload = strtolower($extension_upload); - $uploadok = move_uploaded_file($file['css']['tmp_name'], $this::CSS_READ_DIR . $id . '.' . $extension_upload); - if ($uploadok) { - $message = 'uploadok'; - } else { - $message = 'uploaderror'; - } - } else { - $message = 'filealreadyexist'; - - } - } - } else { - $message = 'filetoobig'; - - } - return $message; - - } public function dirlist($dir, $extension) { diff --git a/class/class.w.art.php b/w/class/class.w.art.php index 001b29d..001b29d 100644 --- a/class/class.w.art.php +++ b/w/class/class.w.art.php diff --git a/w/class/class.w.art2.php b/w/class/class.w.art2.php new file mode 100644 index 0000000..feee0ca --- /dev/null +++ b/w/class/class.w.art2.php @@ -0,0 +1,585 @@ +<?php + +use Michelf\MarkdownExtra; + + +class Art +{ + private $id; + private $title; + private $description; + private $tag; + private $date; + private $datecreation; + private $datemodif; + private $daterender; + private $css; + private $quickcss; + private $javascript; + private $html; + private $header; + private $section; + private $nav; + private $aside; + private $footer; + private $render; + private $secure; + private $invitepassword; + private $interface; + private $linkfrom; + private $template; + private $affcount; + private $editcount; + + private $linkto; + + const LEN = 255; + const LENHTML = 20000; + const SECUREMAX = 2; + const LENCOULEUR = 7; + const DEBUT = '(?id='; + const FIN = ')'; + + + + +// _____________________________________________________ F U N ____________________________________________________ + + 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() + { + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + + $this->settitle($this->id()); + $this->setdescription(''); + $this->settag([]); + $this->setdate($now); + $this->setdatecreation($now); + $this->setdatecreation($now); + $this->setdatemodif($now); + $this->setdaterender($now); + $this->setcss(''); + $this->setquickcss([]); + $this->setjavascript(''); + $this->sethtml(''); + $this->setheader(''); + $this->setsection(''); + $this->setnav(''); + $this->setaside(''); + $this->setfooter(''); + $this->setsecure(2); + $this->setinterface('section'); + $this->setlinkfrom([]); + $this->settemplate([]); + $this->setaffcount(0); + $this->seteditcount(0); + } + + public function updatelien() + { + $this->linkfrom = []; + $this->linkfrom = array_unique(search($this->md(true), 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); + } + + + public function autotaglist() + { + $pattern = "/%%(\w*)%%/"; + preg_match_all($pattern, $this->md(), $out); + return $out[1]; + + } + + public function autotaglistupdate($taglist) + { + 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 .= '</ul>'; + $this->html = str_replace('%%' . $tag . '%%', $replace, $this->html); + } + } + + public function autotaglistcalc($taglist) + { + 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(); + } + } + } + } + + + // _____________________________________________________ G E T ____________________________________________________ + + public function id($type = 'string') + { + return $this->id; + } + + public function title($type = 'string') + { + return $this->title; + } + + public function description($type = 'string') + { + return $this->description; + } + + public function tag($option) + { + if ($option == 'string') { + return implode(", ", $this->tag); + } elseif ($option == 'array') { + return $this->tag; + } elseif ($option == 'sort') { + return count($this->tag); + } + } + + public function date($option) + { + if ($option == 'string') { + return $this->date->format('Y-m-d H:i:s'); + } elseif ($option == 'date' || $option == 'sort') { + return $this->date; + } elseif ($option == 'hrdi') { + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + return hrdi($this->date->diff($now)); + } + } + + public function datecreation($option) + { + if ($option == 'string') { + return $this->datecreation->format('Y-m-d H:i:s'); + } elseif ($option == 'date' || $option == 'sort') { + return $this->datecreation; + } elseif ($option == 'hrdi') { + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + return hrdi($this->datecreation->diff($now)); + } + } + + + public function datemodif($option) + { + if ($option == 'string') { + return $this->datemodif->format('Y-m-d H:i:s'); + } elseif ($option == 'date' || $option == 'sort') { + return $this->datemodif; + } elseif ($option == 'hrdi') { + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + return hrdi($this->datemodif->diff($now)); + } + } + + public function daterender($option) + { + if ($option == 'string') { + return $this->daterender->format('Y-m-d H:i:s'); + } elseif ($option == 'date' || $option == 'sort') { + return $this->daterender; + } elseif ($option == 'hrdi') { + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + return hrdi($this->daterender->diff($now)); + } + } + + public function css($type = 'string') + { + return $this->css; + } + + public function quickcss($option = 'json') + { + if ($option == 'json') { + return json_encode($this->quickcss); + } elseif ($option == '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 = []; + $temp = ''; + if (!empty($this->template())) { + if ($app->exist($this->template()) and !in_array($this->template(), $data)) { + $template = $app->get($this->template()); + $temp = $temp . $template->css($app); + $data[] = $template->id(); + + } + + } + $cssprint = str_replace('url(/', 'url(' . $app::MEDIA_DIR, $temp . $this->css); + return $cssprint; + } + + public function md($expand = false) + { + if ($expand == true) { + $md = str_replace('](=', '](?id=', $this->html); + } else { + $md = $this->html; + } + return $md; + } + + public function html(App $app) + { + + // %%%% TITLE & DESCIPTION + $html = str_replace('%TITLE%', $this->titre(), $this->html); + $html = str_replace('%DESCRIPTION%', $this->intro(), $html); + + $parser = new MarkdownExtra; + + // id in headers + $parser->header_id_func = function ($header) { + return preg_replace('/[^\w]/', '', strtolower($header)); + }; + $html = $parser->transform($html); + + // replace = > ?id= + $html = str_replace('href="=', 'href="?id=', $html); + + + // infobulles tooltip + foreach ($this->lien('array') as $id) { + $title = "Cet article n'existe pas encore"; + foreach ($app->getlister(['id', 'intro']) as $item) { + if ($item->id() == $id) { + $title = $item->intro(); + } + } + $lien = 'href="?id=' . $id . '"'; + $titlelien = ' title="' . $title . '" ' . $lien; + $html = str_replace($lien, $titlelien, $html); + } + + if (!empty(strstr($html, '%SUMMARY%'))) { + + + + $html = str_replace('%SUMMARY%', sumparser($html), $html); + } + + + $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; + + + } + + public function secure($type = 'int') + { + 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() + { + return $this->couleurtext; + } + + public function couleurbkg() + { + return $this->couleurbkg; + } + + public function couleurlien() + { + return $this->couleurlien; + } + + public function couleurlienblank() + { + return $this->couleurlienblank; + } + + public function lien($option) + { + if ($option == 'string') { + $lien = implode(", ", $this->lien); + } elseif ($option == 'array') { + $lien = $this->lien; + } elseif ($option == 'sort') { + return count($this->lien); + } + return $lien; + + } + + 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; + } + + + + + + // _____________________________________________________ S E T ____________________________________________________ + + public function setid($id) + { + if (strlen($id) < self::LEN and is_string($id)) { + $this->id = strip_tags(strtolower(str_replace(" ", "", $id))); + } + } + + public function settitre($titre) + { + if (strlen($titre) < self::LEN and is_string($titre)) { + $this->titre = strip_tags(trim($titre)); + } + } + + public function setsoustitre($soustitre) + { + 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)); + } + } + + public function settag($tag) + { + if (is_string($tag)) { + + if (strlen($tag) < self::LEN and is_string($tag)) { + $tag = strip_tags(trim(strtolower($tag))); + $tag = str_replace('*', '', $tag); + $tag = str_replace(' ', '', $tag); + + $taglist = explode(",", $tag); + $taglist = array_filter($taglist); + $this->tag = $taglist; + } + } elseif (is_array($tag)) { + $this->tag = $tag; + } + } + + public function setdate($date) + { + if ($date instanceof DateTimeImmutable) { + $this->date = $date; + } else { + $this->date = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $date, new DateTimeZone('Europe/Paris')); + } + } + + public function setdatecreation($datecreation) + { + if ($datecreation instanceof DateTimeImmutable) { + $this->datecreation = $datecreation; + } else { + $this->datecreation = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $datecreation, new DateTimeZone('Europe/Paris')); + } + } + + public function setdatemodif($datemodif) + { + if ($datemodif instanceof DateTimeImmutable) { + $this->datemodif = $datemodif; + } else { + $this->datemodif = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $datemodif, new DateTimeZone('Europe/Paris')); + } + } + + public function setdaterender($daterender) + { + if ($daterender instanceof DateTimeImmutable) { + $this->daterender = $daterender; + } else { + $this->daterender = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $daterender, new DateTimeZone('Europe/Paris')); + } + } + + public function setquickcss($quickcss) + { + + } + + public function setcss($css) + { + if (strlen($css) < self::LENHTML and is_string($css)) { + $this->css = strip_tags(trim(strtolower($css))); + } + } + + public function sethtml($html) + { + if (strlen($html) < self::LENHTML and is_string($html)) { + $this->html = $html; + } + } + + public function setsecure($secure) + { + if ($secure >= 0 and $secure <= self::SECUREMAX) { + $this->secure = intval($secure); + } + } + + public function setcouleurtext($couleurtext) + { + $couleurtext = strval($couleurtext); + if (strlen($couleurtext) <= self::LENCOULEUR) { + $this->couleurtext = strip_tags(trim($couleurtext)); + } + } + + public function setcouleurbkg($couleurbkg) + { + $couleurbkg = strval($couleurbkg); + if (strlen($couleurbkg) <= self::LENCOULEUR) { + $this->couleurbkg = strip_tags(trim($couleurbkg)); + } + } + + public function setcouleurlien($couleurlien) + { + $couleurlien = strval($couleurlien); + if (strlen($couleurlien) <= self::LENCOULEUR) { + $this->couleurlien = strip_tags(trim($couleurlien)); + } + } + + public function setcouleurlienblank($couleurlienblank) + { + $couleurlienblank = strval($couleurlienblank); + if (strlen($couleurlienblank) <= self::LENCOULEUR) { + $this->couleurlienblank = strip_tags(trim($couleurlienblank)); + } + } + + public function setlien($lien) + { + if (!empty($lien) && strlen($lien) < self::LEN && is_string($lien)) { + $lien = strip_tags(trim(strtolower($lien))); + $lienlist = explode(", ", $lien); + $this->lien = $lienlist; + } else { + $this->lien = []; + } + } + + public function setliento($liento) + { + if (is_array($liento)) { + $this->liento = $liento; + } + + + } + + public function settemplate($template) + { + $template = strip_tags($template); + if (strlen($template) == 0) { + $template = 'NULL'; + } + $this->template = $template; + } + + +} + + +?>
\ No newline at end of file diff --git a/class/class.w.config.php b/w/class/class.w.config.php index 68b0987..3b4cde0 100644 --- a/class/class.w.config.php +++ b/w/class/class.w.config.php @@ -14,7 +14,6 @@ class Config private $editor; private $invite; private $read; - private $cssread; private $color4; private $fontsize = 6; @@ -96,11 +95,6 @@ class Config return $this->read; } - public function cssread() - { - return $this->cssread; - } - public function color4() { return $this->color4; @@ -165,11 +159,6 @@ class Config $this->read = strip_tags($read); } - public function setcssread($cssread) - { - $this->cssread = strip_tags($cssread); - } - public function setcolor4($color4) { if(strlen($color4) <= 8) { diff --git a/class/class.w.media.php b/w/class/class.w.media.php index 2d27be7..2d27be7 100644 --- a/class/class.w.media.php +++ b/w/class/class.w.media.php diff --git a/class/class.w.opt.php b/w/class/class.w.opt.php index 7164cb7..7164cb7 100644 --- a/class/class.w.opt.php +++ b/w/class/class.w.opt.php diff --git a/w/class/class.w.quickcss.php b/w/class/class.w.quickcss.php new file mode 100644 index 0000000..dc7dbac --- /dev/null +++ b/w/class/class.w.quickcss.php @@ -0,0 +1,291 @@ +<?php + +class Quickcss +{ + + + private $active = []; + private $values = []; + private $units = []; + private $new = []; + private $jsoncss = []; + + private $quickcss = []; + + const COLOR = ['color', 'background-color', 'border-color', 'text-decoration-color']; + const SIZE = ['width', 'height', 'margin', 'padding', 'border-radius', 'border-width', 'left', 'right', 'top', 'bottom']; + const UNIQUE = ['background-image', 'opacity', 'font-size']; + + const OPTIONS = [ + 'text-align' => ['left', 'right', 'center', 'justify'], + 'border-style' => ['solid', 'double', 'outset', 'ridge'], + 'font-family' => ['serif', 'sans-serif', 'monospace', 'cursive', 'fantasy'], + 'text-decoration-line' => ['none', 'underline', 'overline', 'line-through', 'underline overline'], + 'display' => ['none', ] + ]; + + + private static function getselect() + { + return array_keys(self::OPTIONS); + } + + private static function getparams() + { + $params = array_merge(self::COLOR, self::SIZE, self::getselect(), self::UNIQUE); + sort($params, SORT_STRING ); + return $params; + } + + public function __construct($data) + { + $this->hydrate($data); } + + public function hydrate($data) + { + foreach ($data as $key => $value) { + $method = 'set' . $key; + + if (method_exists($this, $method)) { + $this->$method($value); + } + } + } + + public function calc() + { + $quickcss = $this->intersect($this->values,$this->active); + $quickcss = $this->merge($quickcss, $this->new); + $quickcss = $this->addunits($quickcss, $this->units); + $quickcss = $this->merge($this->jsoncss, $quickcss); + + $this->quickcss = $quickcss; + } + + + + // _________________________________________ P O S T __________________________________________________ + + public function setvalues($data) + { + if(is_array($data)) { + $this->values = $data; + } + } + + public function setunits($data) + { + if(is_array($data)) { + $this->units = $data; + } + } + + public function setactive($data) + { + if(is_array($data)) { + $this->active = $data; + } + } + + public function setnew($data) + { + if (!empty($data['element']) && !empty($data['param']) && in_array($data['param'], self::getparams())) { + $new = array($data['element'] => array($data['param'] => '')); + $this->new = $new; + } + } + + + public function setjson($jsoncss) + { + if(!empty($jsoncss) && is_string($jsoncss)) { + $jsoncss = json_decode($jsoncss); + if(is_array($jsoncss)) { + $this->jsoncss = $jsoncss; + } else { + $this->jsoncss = []; + } + } + } + + + // _______________________________________ C A L C ___________________________________________________ + + public function intersect($values, $active) + { + $intersect = array_intersect_key($values, $active); + + foreach ($intersect as $element => $css) { + $intersect[$element] = array_intersect_key($values[$element], $active[$element]); + } + return $intersect; + } + + public function merge($quickcss, $new) + { + $quickcss = array_merge_recursive($quickcss, $new); + return $quickcss; + } + + public function addunits($quickcss, $units) + { + foreach ($units as $element => $css) { + foreach ($css as $param => $unit) { + if (array_key_exists($element, $quickcss) && array_key_exists($param, $quickcss[$element])) { + $quickcss[$element][$param] = $quickcss[$element][$param] . $unit; + } + } + } + return $quickcss; + } + + + + // __________________________________________ C O M _________________________________________ + + public function tocss() + { + $string = ''; + foreach ($this->quickcss as $element => $css) { + $string .= PHP_EOL . $element . ' {'; + foreach ($css as $param => $value) { + $string .= PHP_EOL . ' ' . $param . ': ' . $value . ';'; + } + $string .= PHP_EOL . '}' . PHP_EOL; + } + return $string; + } + + public function tojson() + { + return json_encode($this->quickcss); + } + + + + + // _____________________________________________ F O R M ____________________________________________ + + public function form($action) + { + echo '<form action="' . $action . '" method="post">'; + echo '</br><input type="submit" value="submit">'; + $this->inputs($this->quickcss); + echo '</br><input type="submit" value="submit">'; + echo '</form>'; + + } + + public function inputs($quickcss) + { + echo '<h1>Add element</h1>'; + + echo '<input type="text" name="new[element]" list="used">'; + echo '<datalist id="used">'; + foreach (array_keys($quickcss) as $element) { + echo '<option value ="'.$element.'">'; + } + echo '</datalist>'; + + echo '<select name="new[param]">'; + foreach (self::getparams() as $param) { + echo '<option value="' . $param . '">' . $param . '</option>'; + } + echo '</select>'; + + foreach ($quickcss as $element => $css) { + echo '<h3>' . $element . '</h3>'; + foreach ($css as $param => $value) { + + echo '<div class="quicklabel">'; + echo '<input type="checkbox" name="active[' . $element . '][' . $param . ']" id="active[' . $element . '][' . $param . ']" checked>'; + echo '<label for="active[' . $element . '][' . $param . ']">' . $param . '</label>'; + echo '</div>'; + + echo '<div class="quickinput">'; + + if (in_array($param, self::COLOR)) { + echo '<input type="color" name="values[' . $element . '][' . $param . ']" value="' . $quickcss[$element][$param] . '" id="values[' . $element . '][' . $param . ']">'; + } + + if (in_array($param, self::SIZE)) { + $this->sizeinput($element, $param, $value); + } + + if (in_array($param, self::getselect())) { + $this->selectinput($element, $param, $value); + } + + if (in_array($param, self::UNIQUE)) { + $method = str_replace('-', '', $param) . 'input'; + if (method_exists($this, $method)) { + $this->$method($element, $param, $value); + } + } + + echo '</div>'; + } + } + + + } + + + + + + + // ____________________________________ I N P U T __________________________________ + + public function sizeinput($element, $param, $value) + { + echo '<input type="number" name="values[' . $element . '][' . $param . ']" value="' . intval($value) . '" id="values[' . $element . '][' . $param . ']">'; + + $unit = preg_replace('/\d/', '', $value); + ?> + <select name="units[<?= $element ?>][<?= $param ?>]" > + <option value="px" <?= $unit == 'px' ? 'selected' : '' ?>>px</option> + <option value="%" <?= $unit == '%' ? 'selected' : '' ?>>%</option> + </select> + <?php + + } + + public function fontsizeinput($element, $param, $value) + { + echo '<input type="number" name="values[' . $element . '][' . $param . ']" value="' . intval($value) . '" id="values[' . $element . '][' . $param . ']">'; + + $unit = preg_replace('/\d/', '', $value); + ?> + <select name="units[<?= $element ?>][<?= $param ?>]" > + <option value="px" <?= $unit == 'px' ? 'selected' : '' ?>>px</option> + <option value="em" <?= $unit == 'em' ? 'selected' : '' ?>>em</option> + </select> + <?php + + } + + public function opacityinput($element, $param, $value) + { + echo '<input type="number" name="values[' . $element . '][' . $param . ']" value="' . $value . '" id="values[' . $element . '][' . $param . ']" step="0.1" min="0" max="1">'; + } + + public function selectinput($element, $param, $value) + { + echo '<select name="values[' . $element . '][' . $param . ']">'; + foreach (self::OPTIONS[$param] as $option) { + if($option == $value) { + echo '<option value="'.$option.'" selected>'.$option.'</option>'; + } else { + echo '<option value="'.$option.'">'.$option.'</option>'; + } + } + echo '</select>'; + } + + +} + + + +?>
\ No newline at end of file diff --git a/class/class.w.record.php b/w/class/class.w.record.php index e488383..e488383 100644 --- a/class/class.w.record.php +++ b/w/class/class.w.record.php diff --git a/public/w/article.php b/w/controller/w.article.php index 307caa4..307caa4 100644 --- a/public/w/article.php +++ b/w/controller/w.article.php diff --git a/public/w/home.php b/w/controller/w.home.php index 3094d03..3094d03 100644 --- a/public/w/home.php +++ b/w/controller/w.home.php diff --git a/public/w/menu.php b/w/controller/w.menu.php index 8e89ed1..8e89ed1 100644 --- a/public/w/menu.php +++ b/w/controller/w.menu.php diff --git a/fn/fn.w.php b/w/fn/w.fn.php index 6f63a07..72c98c1 100644 --- a/fn/fn.w.php +++ b/w/fn/w.fn.php @@ -11,7 +11,7 @@ function bddconnect($host, $bdname, $user, $password) function my_autoloader($class) { - require('../../class/class.w.' . strtolower($class) . '.php'); + require(__DIR__.'/../class/class.w.' . strtolower($class) . '.php'); } function secure() diff --git a/w/w.router.php b/w/w.router.php new file mode 100644 index 0000000..e1c7b62 --- /dev/null +++ b/w/w.router.php @@ -0,0 +1,359 @@ +<?php + +// _____________________________________________________ R E Q U I R E ________________________________________________________________ + +session_start(); + + + +require(__DIR__.'/fn/w.fn.php'); +require(__DIR__.'/../vendor/autoload.php'); + +spl_autoload_register('my_autoloader'); + + + + +// ________________________________________________________ I N S T A L _________________________________________________ + +$app = new App(); +$aff = new Aff(); + + +$config = $app->readconfig(); +if (!$config) { + $message = 'config_file_error'; + echo $message; + if (isset($_POST['config']) && $_POST['config'] == 'create') { + $config = $app->createconfig($_POST); + $app->savejson($config->tojson()); + header('Location: ./'); + + } else { + $aff->configform(); + } + exit; +} + + +// _________________________________________________________ S E S ___________________________________________________________ + + +if (!isset($_SESSION['level'])) { + $session = 0; +} else { + $session = $_SESSION['level']; +} + +$app->setsession($session); + + + + +// _______________________________________________________ A C T I O N __________________________________________________________________ + + +if (isset($_POST['action'])) { + switch ($_POST['action']) { + + case 'login': + $_SESSION['level'] = $app->login($_POST['pass'], $config); + if (isset($_GET['id'])) { + header('Location: ?id=' . $_GET['id']); + } else { + header('Location: ./'); + } + break; + + case 'logout': + $_SESSION['level'] = $app->logout(); + if (isset($_GET['id'])) { + header('Location: ?id=' . $_GET['id']); + } else { + header('Location: ./'); + } + break; + + case 'addmedia': + $message = $app->addmedia($_FILES, 2 ** 24, $_POST['id']); + header('Location: ./?aff=media&message=' . $message); + break; + + + + case 'editcss': + file_put_contents($app::GLOBAL_CSS_DIR, $_POST['editcss']); + header('Location: ./?aff=admin'); + break; + + case 'editconfig': + $config->hydrate($_POST); + $app->savejson($config->tojson()); + header('Location: ./?aff=admin'); + break; + + + } +} + + + +// _____________________________________________________ D A T A B A S E __________________________________________________________________ + +if (isset($_POST['action'])) { + $app->bddinit($config); + + switch ($_POST['action']) { + + case 'new': + if (isset($_GET['id'])) { + $art = new Art($_GET); + $art->reset(); + $app->add($art); + header('Location: ?id=' . $_GET['id'] . '&edit=1'); + } + break; + + case 'update': + if ($app->exist($_GET['id'])) { + $art = new Art($_POST); + $art->updatelien(); + $art->autotaglistcalc($app->taglist($app->getlister(['id', 'titre', 'tag']), $art->autotaglist())); + $app->update($art); + if($config->fontsize() != $_POST['fontsize']) { + $config->setfontsize($_POST['fontsize']); + $app->savejson($config->tojson()); + } + header('Location: ?id=' . $art->id() . '&edit=1&message='.$art->id().'_saved'); + } + break; + + case 'display': + if ($app->exist($_GET['id'])) { + $art = new Art($_POST); + $art->updatelien(); + $art->autotaglistcalc($app->taglist($app->getlister(['id', 'titre', 'tag']), $art->autotaglist())); + $app->update($art); + if($config->fontsize() != $_POST['fontsize']) { + $config->setfontsize($_POST['fontsize']); + $app->savejson($config->tojson()); + } + header('Location: ?id=' . $art->id().'&message='.$art->id().'_saved'); + } + break; + + case 'home': + if ($app->exist($_GET['id'])) { + $art = new Art($_POST); + $art->updatelien(); + $art->autotaglistcalc($app->taglist($app->getlister(['id', 'titre', 'tag']), $art->autotaglist())); + $app->update($art); + if($config->fontsize() != $_POST['fontsize']) { + $config->setfontsize($_POST['fontsize']); + $app->savejson($config->tojson()); + } + header('Location: ./?message='.$art->id().'_saved'); + } + 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); + $app->delete($art); + header('Location: ?id=' . $art->id()); + } + break; + + case 'massedit': + if (isset($_POST['id'])) { + foreach ($_POST['id'] as $id) { + if ($app->exist($id)) { + $art = $app->get($id); + + switch ($_POST['massaction']) { + case 'do': + switch ($_POST['massedit']) { + case 'delete': + $app->delete($art); + break; + + case 'erasetag': + $art->settag(''); + $app->update($art); + break; + + case 'erasetemplate': + $art->settemplate(''); + $app->update($art); + break; + + case 'not published': + $art->setsecure(2); + $app->update($art); + break; + + case 'private': + $art->setsecure(1); + $app->update($art); + break; + + case 'public': + $art->setsecure(0); + $app->update($art); + break; + } + break; + + case 'set template': + if (isset($_POST['masstemplate'])) { + $art->settemplate($_POST['masstemplate']); + $app->update($art); + } + break; + + case 'add tag': + if (isset($_POST['targettag'])) { + $art = $app->get($id); + $tagstring = strip_tags(trim(strtolower($_POST['targettag']))); + $taglist = str_replace(' ', '', $tagstring); + $taglist = explode(",", $taglist); + foreach ($taglist as $tag) { + if (!in_array($tag, $art->tag('array'))) { + $newtaglist = $art->tag('array'); + array_push($newtaglist, $tag); + $art->settag($newtaglist); + } + } + $app->update($art); + } + break; + + } + + + + + } + header('Location: ./'); + } + break; + } + } +} + + + + + +if (isset($_POST['actiondb'])) { + $app->setbdd($config); + + switch ($_POST['actiondb']) { + + case 'addtable': + if (isset($_POST['tablename'])) { + $message = $app->addtable($config->dbname(), $_POST['tablename']); + header('Location: ./?aff=admin&message=' . $message); + } + break; + + case 'duplicatetable': + $message = $app->tableduplicate($config->dbname(), $_POST['arttable'], $_POST['tablename']); + header('Location: ./?aff=admin&message=' . $message); + break; + + } +} + + + + +// _______________________________________________________ H E A D _____________________________________________________________ + +if (isset($_GET['id'])) { + $app->bddinit($config); + if ($app->exist($_GET['id'])) { + $art = $app->get($_GET['id']); + if (!isset($_GET['edit'])) { + $_GET['edit'] = 0; + } + $aff->arthead($art, $app::GLOBAL_CSS_DIR, $_GET['edit']); + } else { + // $aff->head($_GET['id'], '', 'white'); + $aff->noarthead($_GET['id'], $app::GLOBAL_CSS_DIR); + + } +} elseif (isset($_GET['aff'])) { + $aff->head($_GET['aff'], $_GET['aff'], $config->color4()); +} else { + $aff->head('home', 'home', $config->color4()); +} + + + + + + + +// _____________________________________________________ A L E R T _______________________________________________________________ + +if (isset($_GET['message'])) { + echo '<span class="alert">' . $_GET['message'] . '</span>'; +} + + + + + + + + +// ______________________________________________________ B O D Y _______________________________________________________________ + + +$aff->nav($app); + +if (array_key_exists('id', $_GET)) { + $app->bddinit($config); + include(__DIR__.'/controller/w.article.php'); +} 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)) { + $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); +} elseif (array_key_exists('aff', $_GET)) { + include(__DIR__.'/controller/w.menu.php'); +} else { + include(__DIR__.'/controller/w.home.php'); +} + + + +?>
\ No newline at end of file |