]> 91.132.146.200 Git - scientia.git/commitdiff
better navigation
authorBanana <mail@bananas-playground.net>
Sat, 12 Nov 2022 11:38:10 +0000 (12:38 +0100)
committerBanana <mail@bananas-playground.net>
Sat, 12 Nov 2022 11:38:10 +0000 (12:38 +0100)
CHANGELOG
TODO [new file with mode: 0644]
VERSION
documentation/scientia.sql.txt
webroot/index.php
webroot/lib/entry.class.php
webroot/view/entry/entry.html
webroot/view/entry/entry.php
webroot/view/list/list.html
webroot/view/list/list.php

index c43ba020914d5d4d2297b4f9f331a396160c3cf6..d1ddeba5eb1e3bd26ed42100952515db348e44f3 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,2 @@
-0.5 Lykos -
-       + Initial beta release
-       + Some PHP syntax stuff
+1.0 Lykos -
+       + Initial release
diff --git a/TODO b/TODO
new file mode 100644 (file)
index 0000000..ebea391
--- /dev/null
+++ b/TODO
@@ -0,0 +1,2 @@
+- i18n
+- ignorewords
diff --git a/VERSION b/VERSION
index acf27ca11d896dff584dc8778ac4aab668d6e30a..39039671ecc870a890378e86ba8c30553066827c 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.5 - Lykos
+1.0 - Lykos
index d31a677d20d772680b8f951d26e9edb04929e175..3c1ab7311a16d2e042bfb3bd384d36a49b54c3b1 100644 (file)
@@ -6,5 +6,6 @@ CREATE TABLE `sc_entry` (
   `body` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
   `words` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
   PRIMARY KEY (`ident`) USING BTREE,
-  KEY `date` (`date`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
+  KEY `date` (`date`),
+  FULLTEXT KEY `words` (`words`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
index acf49c04f72759d289cdd0a5245eeaa4a4691c07..18682a63a7409afb1d7c1253261eeeff751932ff 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * scientia
  *
- * Copyright 2021 Johannes Keßler
+ * Copyright 2022 Johannes Keßler
  *
  * https://www.bananas-playground.net/projekt/scientia/
  *
@@ -20,7 +20,7 @@ mb_internal_encoding('UTF-8');
 ini_set('error_reporting',-1); // E_ALL & E_STRICT
 
 ## check request
-$_urlToParse = filter_var($_SERVER['QUERY_STRING'],FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
+$_urlToParse = filter_var($_SERVER['QUERY_STRING'],FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW);
 if(!empty($_urlToParse)) {
        # see http://de2.php.net/manual/en/regexp.reference.unicode.php
        if(preg_match('/[\p{C}\p{M}\p{Sc}\p{Sk}\p{So}\p{Zl}\p{Zp}]/u',$_urlToParse) === 1) {
@@ -71,15 +71,15 @@ $TemplateData = array();
 
 if(isset($_GET['y']) && Summoner::validate($_GET['y'], 'digit')) {
        $_year = trim($_GET['y']);
-       $_requestDateProvided .= 'y';
+       $_requestDateProvided .= 'Y';
 }
 if(isset($_GET['m']) && Summoner::validate($_GET['m'], 'digit')) {
        $_month = trim($_GET['m']);
-       $_requestDateProvided .= 'm';
+       $_requestDateProvided .= '-m';
 }
 if(isset($_GET['d']) && Summoner::validate($_GET['d'], 'digit')) {
        $_day = trim($_GET['d']);
-       $_requestDateProvided .= 'd';
+       $_requestDateProvided .= '-d';
 }
 if(isset($_GET['p']) && Summoner::validate($_GET['p'], 'nospace') && $_GET['p'] == "new") {
        $_view = 'entry';
index 8ff1e9adc804a36bbc914bb610b312e435ab6c3e..e6ce324f135d44b0609360d772aee663277b50b1 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * scientia
  *
- * Copyright 2021 Johannes Keßler
+ * Copyright 2022 Johannes Keßler
  *
  * https://www.bananas-playground.net/projekt/scientia/
  *
@@ -26,7 +26,7 @@ class Entry {
         *
         * @var mysqli
         */
-       private $_DB;
+       private mysqli $_DB;
 
        /**
         * Entry constructor.
@@ -129,6 +129,31 @@ class Entry {
                return $ret;
        }
 
+       /**
+        * Delete given id from _entry table
+        *
+        * @param string $id
+        * @return bool
+        */
+       public function delete(string $id): bool {
+               $ret = false;
+
+               if(!empty($id)) {
+                       $queryStr = "DELETE FROM `".DB_PREFIX."_entry`
+                                                       WHERE `ident` = '".$this->_DB->real_escape_string($id)."'";
+                       if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true));
+                       try {
+                               $this->_DB->query($queryStr);
+                               $ret = true;
+                       }
+                       catch(Exception $e) {
+                               error_log("[ERROR] ".__METHOD__." catch: ".$e->getMessage());
+                       }
+               }
+
+               return $ret;
+       }
+
        /**
         * Create unique words from the given data
         *
index 0e956c04fdb8703d1051445d452b82a17d5b57e5..021e14656f5023b7cd6064f09f09c7948913eb36 100644 (file)
@@ -4,11 +4,18 @@
 <form method="post">
        <textarea rows="25" placeholder="write here" name="fdata[entry]"><?php echo Summoner::ifset($TemplateData['data'],'body'); ?></textarea>
        <input type="submit" name="submitForm" value="Save">
-
+       <input type="checkbox" name="deleteEntry" value="yes" /> <small style="color: indianred">Delete Entry</small>
 </form>
 <p>
-<?php if(!empty($TemplateData['data'])) { ?>
-<a href="<?php echo PATH_WEBROOT; ?>/new">New</a><br />
+<a href="<?php echo PATH_WEBROOT; ?>">Home</a>
+<?php if(!empty($TemplateData['data'])) {
+       echo ' | ';
+       $_link = '';
+       foreach($TemplateData['data']['breadcrumb'] as $be) {
+               $_link .= '/'.$be;
+               echo '<a href="'.PATH_WEBROOT.$_link.'">'.$be.'</a> | ';
+       }
+?>
+       <a href="<?php echo PATH_WEBROOT; ?>/new">New</a>
 <?php } ?>
-<a href="<?php echo PATH_WEBROOT; ?>"><- back</a>
 </p>
index 61fac29e9fcf95ea84796e97eb747649fc90c98e..704b56a734173ef46b0f3f18accf951a44c485dd 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * scientia
  *
- * Copyright 2021 Johannes Keßler
+ * Copyright 2022 Johannes Keßler
  *
  * https://www.bananas-playground.net/projekt/scientia/
  *
@@ -21,6 +21,7 @@ $Entry = new Entry($DB);
 $TemplateData['data'] = array();
 if(!empty($_id)) {
        $TemplateData['data'] = $Entry->load($_year,$_month,$_day,$_id);
+       $TemplateData['data']['breadcrumb'] = array($_year,$_month,$_day);
 }
 
 if(isset($_POST['submitForm']) && isset($_POST['fdata'])) {
@@ -28,7 +29,11 @@ if(isset($_POST['submitForm']) && isset($_POST['fdata'])) {
        if(isset($fdata['entry']) && Summoner::validate($fdata['entry'])) {
                $_dataToSave = trim($fdata['entry']);
 
-               if(!empty($_id)) {
+               if(!empty($_id) && isset($_POST['deleteEntry']) && $_POST['deleteEntry'] == "yes") {
+                       $do = $Entry->delete($_id);
+                       $_r = '/';
+               }
+               elseif(!empty($_id)) {
                        $do = $Entry->update($_dataToSave,$_id);
                        $_r = '/'.$_year.'/'.$_month.'/'.$_day.'/'.$_id;
                }
index 020835e8f2730ca7afe488c0566dfe9357268d65..20e44361aea16baa47721b40c2478eb20c2784c1 100644 (file)
@@ -1,13 +1,17 @@
 <p>
-       <a href="<?php echo PATH_WEBROOT; ?>/new">New</a>
+       <a href="<?php echo PATH_WEBROOT; ?>/">Home</a> | <a href="<?php echo PATH_WEBROOT; ?>/new">New</a>
 </p>
 <?php if(!empty($TemplateData['entries'])) { ?>
 <?php
-       foreach($TemplateData['entries'] as $gk=>$g) {
-               echo $gk;
+       foreach($TemplateData['entries'] as $k=>$v) {
+               $_link = '';
+               foreach($v['breadcrumb'] as $be) {
+                       $_link .= '/'.$be;
+                       echo '<a href="'.PATH_WEBROOT.$_link.'">'.$be.'</a> ';
+               }
 ?>
 <ul>
-       <?php foreach($g as $e) { ?>
+       <?php foreach($v['e'] as $e) { ?>
        <li><a href="<?php echo PATH_WEBROOT; ?>/<?php echo $e['link']; ?>"><?php echo $e['ident']; ?></a> <?php echo $e['date']; ?> <?php echo htmlspecialchars($e['body'],ENT_HTML5); ?></li>
        <?php } ?>
 </ul>
index 9e06806a5ce6269995bf99506c82b23df214a1e9..eee4c82ec41ea2d1ddd4fb678aedf2cd649d8553 100644 (file)
@@ -23,34 +23,38 @@ $queryLimit = " LIMIT 100";
 // why?
 // mysql knows the dates and validates them. There is no 2020-02-31
 // the single date infos come from index.php
-$groupByFormat = $_year;
+$_groupByFormat = $_year;
+$breadcrumb = array('Y');
 if(!empty($_requestDateProvided)) {
        $_intervalStart = '';
        $_intervalEnd = '';
 
-       if($_requestDateProvided === 'ymd') {
+       if($_requestDateProvided === 'Y-m-d') {
                $queryLimit = "";
-               $groupByFormat = $_year.'-'.$_month.'-'.$_day;
-               $_intervalStart = $groupByFormat;
-               $_intervalEnd = $groupByFormat;
-
+               $_groupByFormat = $_year.'-'.$_month.'-'.$_day;
+               $_intervalStart = $_groupByFormat;
+               $_intervalEnd = $_groupByFormat;
+               $breadcrumb = array('Y','m','d');
        }
-       elseif ($_requestDateProvided === 'ym') {
+       elseif ($_requestDateProvided === 'Y-m') {
                $queryLimit = "";
-               $groupByFormat = $_year.'-'.$_month;
-               $_intervalStart = $groupByFormat.'-01';
+               $_groupByFormat = $_year.'-'.$_month;
+               $_intervalStart = $_groupByFormat.'-01';
                $_tDate = new DateTime( $_intervalStart );
                $_monthDays = $_tDate->format( 't' );
-               $_intervalEnd = $groupByFormat.'-'.$_monthDays;
+               $_intervalEnd = $_groupByFormat.'-'.$_monthDays;
+               $breadcrumb = array('Y','m');
        }
-       elseif ($_requestDateProvided === 'y') {
-               $_intervalStart = $groupByFormat.'-01-01';
-               $_intervalEnd = $groupByFormat.'-12-31';
+       elseif ($_requestDateProvided === 'Y') {
+               $_intervalStart = $_groupByFormat.'-01-01';
+               $_intervalEnd = $_groupByFormat.'-12-31';
        }
 
        if(!empty($_intervalStart) && !empty($_intervalEnd)) {
                $queryStr .= " WHERE `date` >= '".$_intervalStart."' AND `date` <= '".$_intervalEnd."'";
        }
+} else {
+       $_requestDateProvided = 'Y';
 }
 
 $queryStr .= " ORDER BY `created` DESC";
@@ -62,8 +66,13 @@ try {
        if($query !== false && $query->num_rows > 0) {
                while(($result = $query->fetch_assoc()) != false) {
                        $_d = new DateTime($result['date']);
-                       $TemplateData['entries'][$_d->format($groupByFormat)][$result['ident']] = $result;
-                       $TemplateData['entries'][$_d->format($groupByFormat)][$result['ident']]['link'] = str_replace('-','/',$result['date']).'/'.$result['ident'];
+                       $_breadcrumb = array();
+                       foreach($breadcrumb as $_b) {
+                               $_breadcrumb[] = $_d->format($_b);
+                       }
+                       $TemplateData['entries'][$_d->format($_requestDateProvided)]['breadcrumb'] = $_breadcrumb;
+                       $TemplateData['entries'][$_d->format($_requestDateProvided)]['e'][$result['ident']] = $result;
+                       $TemplateData['entries'][$_d->format($_requestDateProvided)]['e'][$result['ident']]['link'] = str_replace('-','/',$result['date']).'/'.$result['ident'];
                }
        }
 }