From 84c63e69a3a8a03f0cc4221bda1393c1f4d3a006 Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Tue, 15 Oct 2024 11:38:15 +0200 Subject: [PATCH] fix php warnings --- common.php | 24 ++++++++++++------- note.php | 70 ++++++++++++++++++++++++++++-------------------------- 2 files changed, 51 insertions(+), 43 deletions(-) diff --git a/common.php b/common.php index 510b262..be007e8 100644 --- a/common.php +++ b/common.php @@ -37,19 +37,25 @@ { global $dir; $path = $dir . '/' . $title; - $lastchanged = filemtime($path . '.md'); - $previous = $_POST['lastchanged']; - if ((int)$lastchanged > (int)$previous) + $filename = $path . '.md'; + + if (file_exists($filename)) { - $tempcontent = file_get_contents($path . '.md'); - if ($tempcontent != $content) + $lastchanged = filemtime($filename); + $previous = $_POST['lastchanged']; + if ((int)$lastchanged > (int)$previous) { - $temptitle = $title . '_conflict_' . $lastchanged; - file_put_contents($dir . '/' . $temptitle . '.md', $tempcontent); - array_unshift($_SESSION['index'], $dir . '/' . $temptitle); + $tempcontent = file_get_contents($filename); + if ($tempcontent != $content) + { + $temptitle = $title . '_conflict_' . $lastchanged; + file_put_contents($dir . '/' . $temptitle . '.md', $tempcontent); + array_unshift($_SESSION['index'], $dir . '/' . $temptitle); + } } } - file_put_contents($path . '.md', $content); + + file_put_contents($filename, $content); removefromindex($title); array_unshift($_SESSION['index'], $path); } diff --git a/note.php b/note.php index 026820c..938af67 100644 --- a/note.php +++ b/note.php @@ -2,51 +2,53 @@ require('common.php'); // handle save actions - $title = $_POST['title']; - $content = $_POST['content']; - if (isset($_POST['save']) || isset($_POST['home']) || isset($_POST['download']) || isset($_POST['preview'])) + if (count($_POST) > 0) { - savenote($title, $content); + $title = $_POST['title']; + $content = $_POST['content']; + if (isset($_POST['save']) || isset($_POST['home']) || isset($_POST['download']) || isset($_POST['preview'])) + { + savenote($title, $content); - $previoustitle = $_POST['previoustitle']; - if ($title != $previoustitle) - { - rename($dir . '/' . $previoustitle . '.md', $dir . '/' . $previoustitle . '.md.del'); - removefromindex($previoustitle); - } + $previoustitle = $_POST['previoustitle']; + if ($title != $previoustitle) + { + rename($dir . '/' . $previoustitle . '.md', $dir . '/' . $previoustitle . '.md.del'); + removefromindex($previoustitle); + } - if (isset($_POST['download'])) - { - downloadnote($dir . '/' . $title . '.md'); - exit; + if (isset($_POST['download'])) + { + downloadnote($dir . '/' . $title . '.md'); + exit; + } + else if (isset($_POST['home'])) + { + header("Location: index.php"); + exit; + } + else if (isset($_POST['preview'])) + { + header("Location: note.php?preview=true&title=" . $title); + exit; + } + else + { + header("Location: note.php?title=" . $title); + exit; + } } - else if (isset($_POST['home'])) + else if (isset($_POST['delete'])) { + rename($dir . '/' . $title . '.md', $dir . '/' . $title . '.md.del'); + removefromindex($title); + header("Location: index.php"); exit; } - else if (isset($_POST['preview'])) - { - header("Location: note.php?preview=true&title=" . $title); - exit; - } - else - { - header("Location: note.php?title=" . $title); - exit; - } - } - else if (isset($_POST['delete'])) - { - rename($dir . '/' . $title . '.md', $dir . '/' . $title . '.md.del'); - removefromindex($title); - - header("Location: index.php"); - exit; } // main - $title = ''; $content = false; if (isset($_GET['new']))