refactor: move functions to specific files

This commit is contained in:
quenousimporte 2024-10-15 12:05:46 +02:00
parent 84c63e69a3
commit 20236765ff
3 changed files with 57 additions and 57 deletions

View File

@ -3,63 +3,6 @@
date_default_timezone_set('Europe/Paris');
require 'settings.php';
function cleanstring($string)
{
return iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', strtolower($string));
}
function downloadall()
{
$zip = new ZipArchive();
$zip_name = 'bbn.zip';
$zip->open($zip_name, ZipArchive::CREATE);
foreach($_SESSION['index'] as $path)
{
if (!str_ends_with($path, '.del'))
{
$path = $path . '.md';
if (file_exists($path))
{
$zip->addFile($path, basename($path));
}
}
}
$zip->close();
header('Content-disposition: attachment; filename=' . $zip_name);
header('Content-type: application/zip');
readfile($zip_name);
unlink($zip_name);
}
function savenote($title, $content)
{
global $dir;
$path = $dir . '/' . $title;
$filename = $path . '.md';
if (file_exists($filename))
{
$lastchanged = filemtime($filename);
$previous = $_POST['lastchanged'];
if ((int)$lastchanged > (int)$previous)
{
$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($filename, $content);
removefromindex($title);
array_unshift($_SESSION['index'], $path);
}
function removefromindex($title)
{
global $dir;

View File

@ -1,6 +1,36 @@
<?php
require('common.php');
function cleanstring($string)
{
return iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', strtolower($string));
}
function downloadall()
{
$zip = new ZipArchive();
$zip_name = 'bbn.zip';
$zip->open($zip_name, ZipArchive::CREATE);
foreach($_SESSION['index'] as $path)
{
if (!str_ends_with($path, '.del'))
{
$path = $path . '.md';
if (file_exists($path))
{
$zip->addFile($path, basename($path));
}
}
}
$zip->close();
header('Content-disposition: attachment; filename=' . $zip_name);
header('Content-type: application/zip');
readfile($zip_name);
unlink($zip_name);
}
if (isset($_GET['download']))
{
downloadall();

View File

@ -1,6 +1,33 @@
<?php
require('common.php');
function savenote($title, $content)
{
global $dir;
$path = $dir . '/' . $title;
$filename = $path . '.md';
if (file_exists($filename))
{
$lastchanged = filemtime($filename);
$previous = $_POST['lastchanged'];
if ((int)$lastchanged > (int)$previous)
{
$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($filename, $content);
removefromindex($title);
array_unshift($_SESSION['index'], $path);
}
// handle save actions
if (count($_POST) > 0)
{