From 9278c9e40c23a49843aa404afc32c1835d9dc188 Mon Sep 17 00:00:00 2001 From: Garvin Hicking Date: Mon, 16 Mar 2015 14:12:43 +0100 Subject: [PATCH] * Allow templatechooser plugin to read a custom "blacklist.txt" within its directory, that can blacklist certain themes from being selected. --- docs/NEWS | 4 +++ .../serendipity_event_templatechooser.php | 29 +++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/docs/NEWS b/docs/NEWS index ba651c4d..4defa847 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -53,6 +53,10 @@ Version 2.1 () Version 2.0.2 () ------------------------------------------------------------------------ + * Allow templatechooser plugin to read a custom "blacklist.txt" + within its directory, that can blacklist certain themes from + being selected. + * Allow serendipity_setCookie() function to set custom expiry. * Adapt .htaccess profile of "mod_rewrite for 1&1 and problematic diff --git a/plugins/serendipity_event_templatechooser/serendipity_event_templatechooser.php b/plugins/serendipity_event_templatechooser/serendipity_event_templatechooser.php index d0a0659e..bbd40078 100644 --- a/plugins/serendipity_event_templatechooser/serendipity_event_templatechooser.php +++ b/plugins/serendipity_event_templatechooser/serendipity_event_templatechooser.php @@ -14,7 +14,7 @@ class serendipity_event_templatechooser extends serendipity_event $propbag->add('description', PLUGIN_EVENT_TEMPLATECHOOSER_DESC); $propbag->add('stackable', false); $propbag->add('author', 'Evan Nemerson'); - $propbag->add('version', '1.4'); + $propbag->add('version', '1.5'); $propbag->add('requirements', array( 'serendipity' => '0.8', 'smarty' => '2.6.7', @@ -47,8 +47,31 @@ class serendipity_event_templatechooser extends serendipity_event } if (isset($_REQUEST['user_template']) && (in_array($_REQUEST['user_template'], serendipity_fetchTemplates())) ) { - $_SESSION['serendipityUseTemplate'] = $_REQUEST['user_template']; - serendipity_setCookie('user_template', $_REQUEST['user_template'], false); + + # Specific themes can be blacklisted for viewing. Enter the names of those, one per line. + $blacklisted = $has_blacklist = false; + + if (file_exists(dirname(__FILE__) . '/blacklist.txt')) { + $_blacklist = explode("\n", file_get_contents(dirname(__FILE__) . '/blacklist.txt')); + $blacklist = array(); + $has_blacklist = true; + foreach($_blacklist AS $idx => $blackline) { + $blackline = trim($blackline); + if (empty($blackline)) continue; + if ($blackline[0] == '#') continue; + $blacklist[$blackline] = true; + if (preg_match('/' . preg_quote($blackline) . '$/i', $_REQUEST['user_template'])) { + header('X-Theme-Blacklisted: ' . urlencode($blackline)); + $blacklisted = true; + } + } + } + + if (!$blacklisted) { + $_SESSION['serendipityUseTemplate'] = $_REQUEST['user_template']; + # When blacklisting occurs, the cookie to remember template selection will be removed by closing the browser. + serendipity_setCookie('user_template', $_REQUEST['user_template'], false, ($has_blacklist ? 0 : false)); + } } // If the requested template is the same as the current default template,