diff --git a/index.php b/index.php index 991d1f2..9ca227d 100644 --- a/index.php +++ b/index.php @@ -3,9 +3,9 @@ <?php - if (isset($_GET['openaction'])) + if (isset($_GET['action']) && $_GET['action'] == 'open') { - echo $_GET['userdata']; + echo $_GET['param']; } ?> @@ -23,13 +23,8 @@ font-family: inherit; font-size: inherit; } - .title { - width: 100%; - border: none; - outline: none; - font-family: inherit; - font-size: inherit; - font-weight: bold; + .grey { + color: lightgrey; } @@ -44,8 +39,6 @@ exit; } - echo '
home

'; - $action = ''; if (isset($_POST['action'])) $action = $_POST['action']; else if (isset($_GET['action'])) $action = $_GET['action']; @@ -53,11 +46,19 @@ $param = ''; if (isset($_GET['param'])) $param = $_GET['param']; + $content = ''; if ($action == 'save') { $title = $_POST['title']; $content = $_POST['content']; file_put_contents($dir . '/' . $title, $content); + + $previoustitle = $_POST['previoustitle']; + if ($title != $previoustitle) + { + rename($dir . '/' . $previoustitle, $dir . '/' . $previoustitle . '.del'); + } + $action = 'open'; $param = $title; } @@ -69,47 +70,82 @@ if ($action == 'open') { + $now = date("Y-m-d H.i.s", time()); if (!$param) { - $param = date("Y-m-d H.i.s", time()); + $param = $now; } - $content = ''; if (!file_exists($dir . '/' . $param)) { - file_put_contents($dir . '/' . $param, $content); + file_put_contents($dir . '/' . $param, ''); } - else + else if (!$content) { $content = file_get_contents($dir . '/' . $param); } - $nblines = max(20, substr_count($content, "\r\n") + 1) * 2; + $lines = substr_count($content, "\r\n") + 1; + $words = $lines + substr_count($content, " "); + $rows = max(20, $lines) + 10; + $length = strlen($content); echo '
+ home +

-

- +
+
'; + + $links = array(); + if (preg_match_all('/\[\[(.*)\]\]/', $content, $links, PREG_SET_ORDER) + || preg_match_all('/http(.*)[ \r]/', $content, $links, PREG_SET_ORDER)) + { + echo '
Internal links:
'; + foreach($links as $link) + { + echo '
+ ' . $link[1] . ' +
'; + } + echo '
'; + } + $links = array(); + if (preg_match_all('/http(.*)[ \r]/', $content, $links, PREG_SET_ORDER)) + { + echo '
External links:
'; + foreach($links as $link) + { + echo '
+ http' . $link[1] . ' +
'; + } + echo '
'; + } + + echo '' . $param . ' - ' . $now . ' - ' . $length . 'c - ' . $words . 'w - ' . $lines . 'l '; } else { echo '
- + home +
'; echo '
'; @@ -122,19 +158,43 @@ foreach($files as $path) { + $tags = ''; $name = basename($path); - if (!str_ends_with($name, '.del') - && ($action != 'filter' || str_contains($name, $param))) + if (!str_ends_with($name, '.del') && ($action != 'filter' || str_contains($name, $param))) { - if ($action == 'search') + if ($action == 'search' || $action == 'tags') { $content = file_get_contents($path); - if (!str_contains($content, $param)) + + if (($action == 'search' && !str_contains($content, $param)) || + ($action == 'tags' && !preg_match('/tags:.*' . $param . '/', $content))) { continue; } } - echo '
' . $name .'
'; + echo '
' . $name .''; + if ($action == 'tags') + { + $tags = array(); + $hastags = preg_match_all('/tags:(.*)/', $content, $tags, PREG_SET_ORDER); + if ($hastags) + { + $tagslist = explode(',', $tags[0][1]); + echo ' '; + foreach ($tagslist as $tag) + { + $tag = trim($tag); + echo('' . $tag . ' '); + } + echo ''; + } + } + else if ($action == 'search') + { + $pos = strpos($content, $param); + echo ' ' . $param . '' . substr($content, $pos + strlen($param), 42) . ''; + } + echo'
'; } } echo '
';