-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadonly.php
More file actions
executable file
·117 lines (101 loc) · 4.43 KB
/
readonly.php
File metadata and controls
executable file
·117 lines (101 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<html>
<head>
<?php include 'config.php'; ?>
<title><?php echo APP_NAME; ?> - readonly</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0" />
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<div class="container">
<?php
$notesDir = NOTES_DIR;
// List of dirs
$dirs = array_filter(glob($notesDir . '*'), 'is_dir');
$dirNames = array_map('basename', $dirs);
// Get the selected dir if not in list take the first
$getDir = preg_replace('/[^a-zA-Z0-9-_]/', '', $_GET['dir']);
if (in_array($getDir, $dirNames)) {
$selectedDir = $getDir;
} else {
$selectedDir = $dirNames[0];
}
// Get the list of notes from the selected dir
$dirPath = $notesDir . $selectedDir . "/";
$notes = array_diff(scandir($dirPath), array('..', '.'));
// Filter out non-text notes
$textFiles = array_filter($notes, function ($noteName) {
return pathinfo($noteName, PATHINFO_EXTENSION) === 'txt';
});
// Sort notes
usort($textFiles, function ($a, $b) {
return strnatcasecmp($b, $a);
});
// Print number of current txt notes
$notesCount = count($textFiles);
echo "<div class='head-container'>
<h2 class='notes-count'>$notesCount note". (($notesCount > 1) ? "s" : "") .".</h2>
<ul class='dir-list'>";
// Count all other txt notes
foreach ($dirNames as $dir) {
$allDirPath = $notesDir . $dir . "/";
$allFiles = array_diff(scandir($allDirPath), array('..', '.'));
$allTextFiles = array_filter($allFiles, function ($noteName) {
return pathinfo($noteName, PATHINFO_EXTENSION) === 'txt';
});
$notesCount = count($allTextFiles);
if ($dir !== $selectedDir) {
echo "<a href='?dir=$dir'><li>$dir <span class='count count-$dir'>$notesCount</span></li></a>";
} else {
echo "<li class=\"active\">$dir <span class='count current-count'>$notesCount</span></li>";
}
}
echo "</ul>
</div>";
?>
<div class="button-container">
<button id="newNoteBtn" class="disabled">New Note</button>
<button id="selectAllBtn" class="disabled">Select All</button>
<button id="moveSelectedBtn" class="disabled">Move Selected (<span class="selected-notes-count">0</span>)</button>
<button id="deleteSelectedBtn" class="disabled">Delete Selected (<span class="selected-notes-count">0</span>)</button>
<button id='readOnlyBtn'>edit mode</button>
</div>
<?php
// Display notes
foreach ($textFiles as $note) {
if (is_file($dirPath . $note)) {
$content = file_get_contents($dirPath . $note);
$noteName = pathinfo($note, PATHINFO_FILENAME);
$modificationDate = date("Y-m-d H:i:s", filemtime($dirPath . $note));
echo "<div class='note-container'>
<div class='note' data-file='$note'>
<div class='content'>$content</div>
<div class='note-info'>
<input type='text' class='indi-rename' placeholder='$noteName' disabled>
<span class='modification-date'>$modificationDate</span>
</div>
</div>
</div>";
}
}
?>
</div> <!-- container -->
<script>
document.querySelector('#readOnlyBtn').addEventListener('click', function() {
window.location.href = "./?dir=<?php echo $selectedDir; ?>";
});
const addEmptyDivs = (n) => {
let containerDiv = document.querySelector('.container');
let emptyDivCount = document.querySelectorAll('.container .empty').length;
for (let i = 0; i < n - emptyDivCount; i++) {
let newDiv = document.createElement('div');
newDiv.className = 'empty';
document.querySelector('.container').appendChild(newDiv);
}
};
let notesCount = document.querySelectorAll('.note-container').length;
if (notesCount <= 4 ) addEmptyDivs(5 - notesCount);
</script>
</body>
</html>