-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
191 lines (169 loc) · 7.65 KB
/
index.php
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php
require dirname(__FILE__)."/app.php";
$errors = Config::check();
$pads = array();
$limit = 100;
if(isset($_GET['limit']) && $_GET['limit'] == -1) {
$limit = false;
} elseif(isset($_GET['limit']) && preg_match('/^[0-9]+$/', $_GET['limit'])) {
$limit = $_GET['limit'];
}
$q = (isset($_GET['q']) && trim($_GET['q'])) ? $_GET['q'] : null;
$pads = array_slice(PadClient::search($q), 0, $limit);
$openPad = null;
if(isset($_GET['id'])) {
$openPad = $_GET['id'];
}
?>
<!DOCTYPE html>
<html lang="fr_FR">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="icon" href="favicon.ico" />
<link rel="stylesheet" href="vendor/bootstrap.min.css">
</head>
<body>
<div class="container pt-3">
<?php if(count($errors)): ?>
<div class="alert alert-danger" role="alert">
<?php foreach($errors as $error): ?>
<?php echo $error ?><br />
<?php endforeach; ?>
</div>
<?php endif; ?>
<button type="button" class="btn btn-outline-primary float-right" data-toggle="modal" data-target="#modalArchive">Ajouter un pad</button>
<h2>Historique des pads <button type="button" class="btn btn-outline-dark btn-sm dropdown-toggle" data-toggle="modal" data-target="#modalClone">Git Clone</button></h2>
<form method="GET" class="mt-3">
<div class="input-group position-relative">
<input type="search" autofocus="autofocus" name="q" placeholder="Recherche sur le titre" class="form-control" value="<?php echo $q ?>" autocomplete="off" />
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="submit">Rechercher</button>
</div>
<?php if($q): ?>
<a href="?q=" class="small float-right position-absolute"style="z-index: 3; right: 120px; top: 8px;">Annuler la recherche</a>
<?php endif; ?>
</div>
</form>
<table class="table table-bordered table-striped table-sm mt-3">
<thead>
<tr>
<th style="width: 0;">Date</th>
<th class="col-6">Titre</th>
<th>Pad</th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach($pads as $pad): ?>
<tr>
<td><?php echo $pad->getDate()->format('d/m/Y'); ?></td>
<td><?php echo htmlspecialchars($pad->getTitle()) ?></td>
<td><a href="<?php echo $pad->getUrl(); ?>"><?php echo $pad->getUrl(); ?></a></td>
<td class="text-center"><a class="openModalViewer" data-identifiant="<?php echo $pad->getId(); ?>" href="viewer.php?id=<?php echo $pad->getId(); ?>">Voir</></td>
</tr>
<?php endforeach; ?>
<?php if($limit !== false): ?>
<tr><td colspan="6"><center><a href="?limit=<?php echo $limit + 100 ?>">Voir plus de résultats</a></center></td></tr>
<?php endif; ?>
</tbody>
</table>
</div>
<div id="modalViewer" class="modal">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
</div>
</div>
</div>
<div id="modalArchive" class="modal">
<div class="modal-dialog modal-md" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
Ajouter un pad
</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form id="form_archive" method="GET" action="archive.php">
<input type="hidden" name="run" value="1" />
<div class="form-group">
<label for="url">Saisissez l'url du pad :</label>
<input type="url" required="required" class="form-control" id="url" name="url" placeholder="https://..." autofocus="autofocus" autocomplete="off" / >
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Annuler</button>
<button type="submit" form="form_archive" class="btn btn-primary">Valider</button>
</div>
</div>
</div>
</div>
<div id="modalClone" class="modal">
<div class="modal-dialog modal-md" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
Récupérer le dépôt contenant les pads
</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">git clone</span>
</div>
<input type="text" readonly="readonly" class="form-control bg-white" value="<?php echo Config::getBaseUrlGit() ?>">
</div>
</div>
</div>
</div>
</div>
<footer class="text-center text-muted mt-4 mb-2 opacity-75">
<small>Logiciel libre <span class="d-none d-md-inline">sous license AGPL-3.0 </span>: <a href="https://github.com/24eme/histopad">voir le code source</a></small>
</footer>
<script src="vendor/jquery.min.js"></script>
<script src="vendor/popper.min.js"></script>
<script src="vendor/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
setTimeout(function() {
const xhttp = new XMLHttpRequest();
xhttp.open("GET", 'run.php');
xhttp.send();
}, 2000);
<?php if($openPad): ?>
$('#modalViewer .modal-content').load("viewer.php?id=<?php echo $openPad ?>", function() {
$('#modalViewer').modal();
});
<?php endif; ?>
$('.openModalViewer').on('click', function(e) {
history.pushState(null, null, window.location.pathname+"?id="+$(this).attr('data-identifiant'));
$('#modalViewer .modal-content').load($(this).attr('href'), function() {
$('#modalViewer').modal();
});
e.preventDefault();
});
$('#modalViewer').on('hide.bs.modal', function (e) {
history.pushState(null, null, window.location.pathname);
})
$('#modalArchive').on('shown.bs.modal', function (e) {
$('#modalArchive [autofocus="autofocus"]').focus();
})
$('#modalArchive').on('hide.bs.modal', function (e) {
$('#modalArchive input[name="url"]').val("");
})
$('#modalClone').on('shown.bs.modal', function (e) {
$('#modalClone input').focus();
$('#modalClone input').select();
})
});
</script>
</body>
</html>