add conflict management

master
quenousimporte 2 months ago
parent ce1867bcf0
commit 020545feb3

@ -35,9 +35,23 @@
function savenote($title, $content)
{
global $dir;
file_put_contents($dir . '/' . $title, $content);
$path = $dir . '/' . $title;
$lastchanged = filemtime($path);
$previous = $_POST['lastchanged'];
if ( (int)$lastchanged > (int)$previous)
{
$tempcontent = file_get_contents($path);
if ($tempcontent != $content)
{
$temptitle = $title . '_' . $lastchanged;
file_put_contents($dir . '/' . $temptitle, $tempcontent);
array_unshift($_SESSION['index'], $dir . '/' . $temptitle);
echo '<div class="grey">Conflict detected. See backup: ' . $temptitle . '</div>';
}
}
file_put_contents($path, $content);
removefromindex($title);
array_unshift($_SESSION['index'], $dir . '/' . $title);
array_unshift($_SESSION['index'], $path);
}
function linksdiv($content)
@ -138,6 +152,8 @@
$content = file_get_contents($dir . '/' . $title);
}
clearstatcache();
$lastchanged = filemtime($dir . '/' . $title);
$lines = substr_count($content, "\r\n");
$words = substr_count($content, " ") + $lines;
$chars = strlen($content);

@ -6,6 +6,7 @@
<input type="submit" name="links" value="links" accesskey="l">
<input type="submit" name="stats" value="stats" accesskey="i">
<input type="submit" name="delete" value="delete" accesskey="d">
<input hidden name="lastchanged" value="<? echo $lastchanged; ?>">
<?php
if (isset($_POST['stats']))
{

Loading…
Cancel
Save