fix php warnings

This commit is contained in:
quenousimporte 2024-10-15 11:38:15 +02:00
parent 71635ab255
commit 84c63e69a3
2 changed files with 51 additions and 43 deletions

View File

@ -37,19 +37,25 @@
{ {
global $dir; global $dir;
$path = $dir . '/' . $title; $path = $dir . '/' . $title;
$lastchanged = filemtime($path . '.md'); $filename = $path . '.md';
$previous = $_POST['lastchanged'];
if ((int)$lastchanged > (int)$previous) if (file_exists($filename))
{ {
$tempcontent = file_get_contents($path . '.md'); $lastchanged = filemtime($filename);
if ($tempcontent != $content) $previous = $_POST['lastchanged'];
if ((int)$lastchanged > (int)$previous)
{ {
$temptitle = $title . '_conflict_' . $lastchanged; $tempcontent = file_get_contents($filename);
file_put_contents($dir . '/' . $temptitle . '.md', $tempcontent); if ($tempcontent != $content)
array_unshift($_SESSION['index'], $dir . '/' . $temptitle); {
$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); removefromindex($title);
array_unshift($_SESSION['index'], $path); array_unshift($_SESSION['index'], $path);
} }

View File

@ -2,51 +2,53 @@
require('common.php'); require('common.php');
// handle save actions // handle save actions
$title = $_POST['title']; if (count($_POST) > 0)
$content = $_POST['content'];
if (isset($_POST['save']) || isset($_POST['home']) || isset($_POST['download']) || isset($_POST['preview']))
{ {
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']; $previoustitle = $_POST['previoustitle'];
if ($title != $previoustitle) if ($title != $previoustitle)
{ {
rename($dir . '/' . $previoustitle . '.md', $dir . '/' . $previoustitle . '.md.del'); rename($dir . '/' . $previoustitle . '.md', $dir . '/' . $previoustitle . '.md.del');
removefromindex($previoustitle); removefromindex($previoustitle);
} }
if (isset($_POST['download'])) if (isset($_POST['download']))
{ {
downloadnote($dir . '/' . $title . '.md'); downloadnote($dir . '/' . $title . '.md');
exit; 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"); header("Location: index.php");
exit; 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 // main
$title = ''; $title = '';
$content = false; $content = false;
if (isset($_GET['new'])) if (isset($_GET['new']))