From f74276ad4a38479c8a5f7ccf065ab576cf2d192d Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 5 Oct 2017 01:04:11 +0200 Subject: [PATCH] nieuws: dynamic article system Copied from lijtweg site v2.4-25-g7cfaa2f8d4 (2017-10-05). Simple js to create pages in /nieuws/year/month/day-title.html and overview to concatenate them chronologically. --- nieuws.inc.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ nieuws.php | 19 +++++++++++++++++++ nieuws/edit.js | 18 ++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 nieuws.inc.php create mode 100644 nieuws.php create mode 100644 nieuws/edit.js diff --git a/nieuws.inc.php b/nieuws.inc.php new file mode 100644 index 0000000..ca16b4a --- /dev/null +++ b/nieuws.inc.php @@ -0,0 +1,44 @@ +%s %s %s', + intval($day), $monthname[intval($month)], $year); +} + +function shownewsarticle($url, $link = TRUE, $title = NULL) +{ + $html = ob_get_clean(); + $date = shownewsdate($url); + ob_start(); + print $title ?: '\1'; + print '[[1]]'; + + $title = sprintf( + $link ? '

%s

' : '

%s

', + getoutput([1 => ' '.$date.'']), + preg_replace('/\.html$/', '', $url) + ); + return preg_replace('{

(.*?)

}', $title, $html); +} + +function shownews($root, $limit = 5) +{ + foreach (array_reverse(glob("$root/*/*.html")) as $url) { + print "
"; + ob_start(); + include $url; + print shownewsarticle($url); + print "
\n\n"; + + if (--$limit <= 0) break; + } +} diff --git a/nieuws.php b/nieuws.php new file mode 100644 index 0000000..157986c --- /dev/null +++ b/nieuws.php @@ -0,0 +1,19 @@ +Nieuwsarchief\n\n"; + +print '
'."\n\n"; +shownews($Page, 20); +print "
\n\n"; + +if (!empty($User['admin'])) { + print ''."\n"; +} diff --git a/nieuws/edit.js b/nieuws/edit.js new file mode 100644 index 0000000..13ca8da --- /dev/null +++ b/nieuws/edit.js @@ -0,0 +1,18 @@ +var editlink = document.createElement('a'); +editlink.className = 'nav'; +editlink.appendChild(document.createTextNode('Nieuw artikel')); +editlink.onclick = function () { + var today = new Date().toJSON().slice(0, 10); + var input = prompt('Artikelnaam (plaatsingsdatum en paginatitel)', today + ' '); + if (!input) return false; + if (!/^\d{4}-\d\d-\d\d[- :]+\S/.test(input)) { + alert('Artikelnaam moet beginnen met een datum in de vorm jaar-mm-dd.'); + return false; + } + var url = input.toLowerCase().replace(/[^a-z0-9]+/g, ' ').trim() + .replace(/ /g, '-').replace('-', '/'); + var title = encodeURIComponent(input.substr(11).trim()); + window.location = '/nieuws/'+url+'?edit='+title+'#edit'; + return false; +}; +document.getElementById('news').appendChild(editlink); -- 2.30.0