• R/O
  • SSH
  • HTTPS

ptiblogphp: Commit


Commit MetaInfo

Revision41 (tree)
Time2021-06-30 18:40:25
Authormateuszviste

Log Message

welcome message is editable online

Change Summary

Incremental Difference

--- trunk/changes.txt (revision 40)
+++ trunk/changes.txt (revision 41)
@@ -5,6 +5,7 @@
55
66 ver xxxxxxxx
77 - articles and welcome message are filtered through a markdown processor
8+ - welcome message is editable online
89 - authentication form features a cancel link
910 - format and language of timestamps are configurable
1011 - title string is properly htmlized (special characters escaped)
--- trunk/index.php (revision 40)
+++ trunk/index.php (revision 41)
@@ -200,24 +200,33 @@
200200 // dodanie nowego wpisu? (albo edycja istniejącego)
201201 if (($isadmin) && ($action === 'dodajwpis')) {
202202 if (empty($artid)) $artid = time();
203- $artfile = 'data/' . $artid . '.txt';
204- if (!is_dir('data')) {
205- if (!mkdir('data')) echo "<!-- mkdir(data) error! -->\n"; // stwórz katalog danych jeśli jeszcze nie istnieje
203+ if ($artid < 0) {
204+ $dh = fopen('welcome.txt', 'w');
205+ fwrite($dh, trim($_POST['artbody']));
206+ fclose($dh);
207+ } else {
208+ $artfile = 'data/' . $artid . '.txt';
209+ if (!is_dir('data')) {
210+ if (!mkdir('data')) echo "<!-- mkdir(data) error! -->\n"; // stwórz katalog danych jeśli jeszcze nie istnieje
211+ }
212+ $dh = fopen($artfile, 'w');
213+ fwrite($dh, trim($_POST['arttit']));
214+ fwrite($dh, "\n");
215+ fwrite($dh, trim($_POST['artbody']));
216+ fclose($dh);
217+ // empty art? (delete)
218+ if (empty(trim($_POST['arttit'])) && empty(trim($_POST['artbody'])) && empty(ListaPlikow($artid, 0))) {
219+ unlink("data/{$artid}.txt");
220+ if (is_dir("data/{$artid}")) rmdir("data/{$artid}");
221+ }
206222 }
207- $dh = fopen($artfile, 'w');
208- fwrite($dh, trim($_POST['arttit']));
209- fwrite($dh, "\n");
210- fwrite($dh, trim($_POST['artbody']));
211- fclose($dh);
212- // empty art? (delete)
213- if (empty(trim($_POST['arttit'])) && empty(trim($_POST['artbody'])) && empty(ListaPlikow($artid, 0))) {
214- unlink("data/{$artid}.txt");
215- if (is_dir("data/{$artid}")) rmdir("data/{$artid}");
216- }
217223 $action = '';
218224 }
219225
220226 if (($p == 0) && (empty($action))) {
227+ if ($isadmin) {
228+ echo "<p class=\"admintool\"><a href=\"./?action=nowywpis&amp;artid=-1&amp;p={$p}\"><img src=\"icons/edit.svg\"></a></p>\n";
229+ }
221230 markdownoutput(file_get_contents('welcome.txt'));
222231 } else if ($action === 'nowywpis') {
223232 echo "<p>Édition</p>\n";
@@ -251,9 +260,13 @@
251260 $art_title = '';
252261 $art_body = '';
253262 if (! empty($artid)) { // edycja istniejącego wpisu
254- $plik = LadujPlikLinii("data/{$artid}.txt");
255- $art_title = $plik[0];
256- $art_body = $plik[1];
263+ if ($artid < 0) {
264+ $art_body = file_get_contents('welcome.txt');
265+ } else {
266+ $plik = LadujPlikLinii("data/{$artid}.txt");
267+ $art_title = $plik[0];
268+ $art_body = $plik[1];
269+ }
257270 }
258271 echo '<form action="' . PaginationLink($p, -1) . '" method="post" class="nowywpis">' . "\n";
259272 echo "<div class=\"nowywpis\">\n";
@@ -262,8 +275,10 @@
262275 echo '<input type="hidden" id="artid" name="artid" value="' . $artid . '">' . "\n";
263276 }
264277 echo '<input type="hidden" id="action" name="action" value="dodajwpis">' . "\n";
265- echo '<input type="text" id="arttit" name="arttit" value="' . htmlentities($art_title) . '">' . "\n";
266- echo "<p>message:</p>\n";
278+ if ($artid > 0) {
279+ echo '<input type="text" id="arttit" name="arttit" value="' . htmlentities($art_title) . '">' . "\n";
280+ echo "<p>message:</p>\n";
281+ }
267282 echo '<textarea name="artbody" id="artbody" rows="20">' . "\n";
268283 echo htmlentities($art_body);
269284 echo "</textarea>\n";
Show on old repository browser