From: Mischa POSLAWSKY Date: Wed, 16 Dec 2020 12:49:14 +0000 (+0100) Subject: page: retain conditional login elements in editor X-Git-Tag: v5.0~10 X-Git-Url: http://git.shiar.net/minimedit.git/commitdiff_plain/229b6a2dc688e92570dd7f8b766adec3e1ee01ed page: retain conditional login elements in editor Fix losing logout parts on save. --- diff --git a/article.inc.php b/article.inc.php index 8600658..36639f2 100644 --- a/article.inc.php +++ b/article.inc.php @@ -220,8 +220,13 @@ class ArchiveArticle # keep either login or logout parts depending on user level global $User; - $hideclass = $User && property_exists($User, 'login') && $User->login ? 'logout' : 'login'; - $doc = preg_replace('{\s*<([a-z]+) class="'.$hideclass.'">.*?}s', '', $doc); + $userexists = $User && property_exists($User, 'login') && $User->login; + if (! ($userexists and $User->admin("edit {$this->link}")) ) { + # remove matching elements until first corresponding closing tag + $hideclass = $userexists ? 'logout' : 'login'; + $tagmatch = '<([a-z]+) class="'.$hideclass.'"[^>]*>'; + $doc = preg_replace("{\s*{$tagmatch}.*?}s", '', $doc); + } return preg_replace_callback( '{ \[\[ ([^] ]+) ([^]]*) \]\] }x', diff --git a/edit/page.js b/edit/page.js index 35497c1..ccc1115 100644 --- a/edit/page.js +++ b/edit/page.js @@ -128,6 +128,8 @@ CKEDITOR.on('instanceCreated', function (event) { { name: 'Attributie', element: 'em', attributes: { 'class': 'right' } }, { name: 'Quote', element: 'q' }, { name: 'Gemarkeerd', element: 'span', styles: { 'background-color': 'Yellow' } }, + { name: 'Ingelogd', element: 'span', attributes: { 'class': 'login' } }, + { name: 'Uitgelogd', element: 'span', attributes: { 'class': 'logout' } }, { name: 'Kadertekst', element: 'aside' }, { name: 'Uitgelijnd', element: 'div', attributes: { 'class': 'right' } },