From 1ba8d9449de1b6fea32e88d581fb7c121b0522b1 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Roland=20H=C3=A4der?= <roland@mxchange.org>
Date: Fri, 31 May 2013 07:49:02 +0000
Subject: [PATCH] Rewrote many parts: - "Generic" filter splitted up and move
 to html_mail_filter.php as this filter will only work with ext-html_mail
 installed - ext-holiday does now register a filter on user_exclusion_sql
 which allows to remove some "static" if() blocks - Other minor fixes

---
 .gitattributes                            |   3 +
 inc/daily/daily_birthday.php              |  10 +-
 inc/extensions/ext-holiday.php            | 125 +---------------
 inc/extensions/ext-html_mail.php          |   4 +
 inc/extensions/holiday/.htaccess          |   1 +
 inc/extensions/holiday/mode-update.php    | 170 ++++++++++++++++++++++
 inc/filter-functions.php                  |   7 +-
 inc/filter/holiday_filter.php             |  62 ++++++++
 inc/filter/html_mail_filter.php           |  14 ++
 inc/filters.php                           |  19 ---
 inc/libs/task_functions.php               |   9 +-
 inc/mails/beg_mails.php                   |  12 +-
 inc/mails/bonus_mails.php                 |  12 +-
 inc/mails/doubler_mails.php               |  14 +-
 inc/modules/admin/what-list_autopurge.php |   7 +-
 inc/modules/admin/what-list_user.php      |   4 +-
 inc/modules/member/what-html_mail.php     |   6 +-
 inc/modules/member/what-order.php         |   6 +-
 inc/monthly/monthly_beg.php               |   9 +-
 inc/monthly/monthly_bonus.php             |   6 -
 inc/mysql-manager.php                     |   5 -
 inc/purge/purge-inact.php                 |  10 +-
 22 files changed, 280 insertions(+), 235 deletions(-)
 create mode 100644 inc/extensions/holiday/.htaccess
 create mode 100644 inc/extensions/holiday/mode-update.php
 create mode 100644 inc/filter/holiday_filter.php

diff --git a/.gitattributes b/.gitattributes
index 4da017eb54..10b9228454 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -258,6 +258,8 @@ inc/extensions/ext-yacy.php svneol=native#text/plain
 inc/extensions/ext-yoomedia.php svneol=native#text/plain
 inc/extensions/forced/.htaccess svneol=native#text/plain
 inc/extensions/forced/mode-setup.php svneol=native#text/plain
+inc/extensions/holiday/.htaccess svneol=native#text/plain
+inc/extensions/holiday/mode-update.php svneol=native#text/plain
 inc/extensions/network/.htaccess svneol=native#text/plain
 inc/extensions/network/mode-setup.php svneol=native#text/plain
 inc/extensions/order/.htaccess svneol=native#text/plain
@@ -303,6 +305,7 @@ inc/filter/coupon_filter.php svneol=native#text/plain
 inc/filter/doubler_filter.php svneol=native#text/plain
 inc/filter/earning_filter.php svneol=native#text/plain
 inc/filter/forced_filter.php svneol=native#text/plain
+inc/filter/holiday_filter.php svneol=native#text/plain
 inc/filter/html_mail_filter.php svneol=native#text/plain
 inc/filter/mediadata_filter.php svneol=native#text/plain
 inc/filter/menu_filter.php svneol=native#text/plain
diff --git a/inc/daily/daily_birthday.php b/inc/daily/daily_birthday.php
index 81aeb519b1..60e5984d2e 100644
--- a/inc/daily/daily_birthday.php
+++ b/inc/daily/daily_birthday.php
@@ -60,17 +60,11 @@ $lastOnline = '';
 $excludeSql = '';
 
 // Shall I include only active members?
+// @TODO Move this out to an extension
 if ((getConfig('birthday_active')  == 'Y') && (isExtensionActive('autopurge')) && ((getApInactiveSince() > 0))) {
 	$excludeSql = ' AND (UNIX_TIMESTAMP() - `d`.`last_online`) < {?ap_inactive_since?}';
 } // END - if
 
-// Is ext-holiday installed?
-// @TODO Rewrite these if() blocks to a filter
-if (isExtensionActive('holiday')) {
-	// Exclude those as well
-	$excludeSql .= " AND `d`.`holiday_active`='N'";
-} // END - if
-
 // Only confirmed members shall receive birthday mails...
 $result_birthday = sqlQueryEscaped("SELECT
 	`d`.`userid`,
@@ -80,7 +74,7 @@ FROM
 	`{?_MYSQL_PREFIX?}_user_data` AS `d`
 WHERE
 	`d`.`status`='CONFIRMED'
-	" . runFilterChain('user_exclusion_sql', $excludeSql) . " AND
+	" . runFilterChain('user_exclusion_sql', ' ' . $excludeSql) . " AND
 	`d`.`birth_day`=%s AND
 	`d`.`birth_month`=%s AND
 	`d`.`birthday_sent` < (UNIX_TIMESTAMP() - ({?ONE_DAY?} * 364))
diff --git a/inc/extensions/ext-holiday.php b/inc/extensions/ext-holiday.php
index e5fe2acff3..d97d1cea2d 100644
--- a/inc/extensions/ext-holiday.php
+++ b/inc/extensions/ext-holiday.php
@@ -41,10 +41,10 @@ if (!defined('__SECURITY')) {
 } // END - if
 
 // Version number
-setThisExtensionVersion('0.2.1');
+setThisExtensionVersion('0.2.2');
 
 // Version history array (add more with , '0.0.1' and so on)
-setExtensionVersionHistory(array('0.0.0', '0.0.1', '0.0.2', '0.0.3', '0.0.4', '0.0.5', '0.0.6', '0.0.7', '0.0.8', '0.0.9', '0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6', '0.1.7', '0.1.8', '0.1.9', '0.2.0', '0.2.1'));
+setExtensionVersionHistory(array('0.0.0', '0.0.1', '0.0.2', '0.0.3', '0.0.4', '0.0.5', '0.0.6', '0.0.7', '0.0.8', '0.0.9', '0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6', '0.1.7', '0.1.8', '0.1.9', '0.2.0', '0.2.1', '0.2.2'));
 
 switch (getExtensionMode()) {
 	case 'setup': // Do stuff when installation is running
@@ -83,6 +83,9 @@ INDEX (`userid`)",
 		addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='holiday' LIMIT 4");
 		addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_max_receive` WHERE `value`=0 LIMIT 1");
 		addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_max_receive` (`value`, `comment`) VALUES (0,'Urlaub')");
+
+		// Unregister filter
+		unregisterFilter(__FILE__, __LINE__, 'user_exclusion_sql', 'HOLIDAY_USER_EXCLUSION_SQL', TRUE, isExtensionDryRun());
 		break;
 
 	case 'activate': // Do stuff when admin activates this extension
@@ -96,124 +99,6 @@ INDEX (`userid`)",
 		break;
 
 	case 'update': // Update an extension
-		switch (getCurrentExtensionVersion())
-		{
-			case '0.0.2': // SQL queries for v0.0.2
-				// Update notes (these will be set as task text!)
-				setExtensionUpdateNotes("Fehlende Abfrage im Mitlieder-Modul, on Erweiterung auch aktiviert ist.");
-				break;
-
-			case '0.0.3': // SQL queries for v0.0.3
-				// Update notes (these will be set as task text!)
-				setExtensionUpdateNotes("Fehler beseitigt, wenn error_reporting=E_ALL gesetzt ist.");
-				break;
-
-			case '0.0.4': // SQL queries for v0.0.4
-				// Update notes (these will be set as task text!)
-				setExtensionUpdateNotes("Problem mit Speicherung der Einstellungen beseitigt.");
-				break;
-
-			case '0.0.5': // SQL queries for v0.0.5
-				// Update notes (these will be set as task text!)
-				setExtensionUpdateNotes("Men&uuml;punkte im Gast-/Mitgliedsbereich k&ouml;nnen nicht mehr aufgerufen werden, wenn die Erweiterung deaktiviert ist.");
-				break;
-
-			case '0.0.6': // SQL queries for v0.0.6
-				// Update notes (these will be set as task text!)
-				setExtensionUpdateNotes("Seit <strong>Patch 340</strong> &uuml;berfl&uuml;ssige HTML-Tags entfernt.");
-				break;
-
-			case '0.0.7': // SQL queries for v0.0.7
-				// Update notes (these will be set as task text!)
-				setExtensionUpdateNotes("IP-Nummer und Browserbezeichnung wird in Admin-Mails eingesetzt.");
-				break;
-
-			case '0.0.8': // SQL queries for v0.0.8
-				// Update notes (these will be set as task text!)
-				setExtensionUpdateNotes("Link zum Mitgliedsprofil in Funktion <u>generateUserProfileLink()</u> ausgelagert.");
-				break;
-
-			case '0.0.9': // SQL queries for v0.0.9
-				// Update notes (these will be set as task text!)
-				setExtensionUpdateNotes("W&ouml;rter <strong>{?mt_word?}</strong>, <strong>{?mt_word2?}</strong> und <strong>{?mt_word3?}</strong> sind austauschbar.");
-				break;
-
-			case '0.1.0': // SQL queries for v0.2.1
-				// Update notes (these will be set as task text!)
-				setExtensionUpdateNotes("Sicherheitsupdate: SQL-Anweisungen gesch&uuml;tzt.");
-				break;
-
-			case '0.1.1': // SQL queries for v0.1.1
-				// Update notes (these will be set as task text!)
-				setExtensionUpdateNotes("Abspeichern von Einstellungen repariert.");
-				break;
-
-			case '0.1.2': // SQL queries for v0.1.2
-				// Update notes (these will be set as task text!)
-				setExtensionUpdateNotes("Abspeichern der Urlaubsanfrage korregiert.");
-				break;
-
-			case '0.1.3': // SQL queries for v0.1.3
-				addExtensionAddTableColumnSql('user_data', 'holiday_active', "ENUM('Y','N') NOT NULL DEFAULT 'N'");
-				addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_max_receive` WHERE `value`=0 LIMIT 1");
-				addConfigAddSql('holiday_lock', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT ' . (getOneDay() * 2));
-
-				// Update notes (these will be set as task text!)
-				setExtensionUpdateNotes("Die Mitgliedaccounts werden nicht mehr gesperrt, sondern nur auf <strong>Urlaub</strong> geschaltet. Lassen Sie sich nicht davon verwirren, dass sie &quot;freigegeben&quot; sind!");
-				break;
-
-			case '0.1.4': // SQL queries for v0.1.4
-				addConfigAddSql('holiday_mode', "ENUM('DIRECT','RESET') NOT NULL DEFAULT 'RESET'");
-
-				// Update notes (these will be set as task text!)
-				setExtensionUpdateNotes("Urlaubsschaltung wird erst Abends um 00:00 Uhr aktiv und nicht durch die Beantragung. Dies kann nun auch auf direkte Umstellung eingestellt werden.");
-				break;
-
-			case '0.1.5': // SQL queries for v0.1.5
-				// Update notes (these will be set as task text!)
-				setExtensionUpdateNotes("Sicherheitsupdate f&uuml;r die Include-Befehle.");
-				break;
-
-			case '0.1.6': // SQL queries for v0.1.6
-				addExtensionAddTableColumnSql('user_data', 'holiday_activated', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
-
-				// Update notes (these will be set as task text!)
-				setExtensionUpdateNotes("Fehlende Tabellenspalte hinzugef&uuml;gt.");
-				break;
-
-			case '0.1.7': // SQL queries for v0.1.7
-				// Update notes (these will be set as task text!)
-				setExtensionUpdateNotes("if-Anweisungen auf Funktion <strong>empty()</strong> umgestellt.");
-				break;
-
-			case '0.1.8': // SQL queries for v0.1.8
-				addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu_las` (`la_id`, `la_action`, `la_what`) VALUES ('member', '', 'list_holiday')");
-				addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu_las` (`la_id`, `la_action`, `la_what`) VALUES ('member', '', 'del_holiday')");
-				addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu_las` (`la_id`, `la_action`, `la_what`) VALUES ('config', '', 'config_holiday')");
-
-				// Update notes (these will be set as task text!)
-				setExtensionUpdateNotes("Erweiterung in's neue Men&uuml;system integriert.");
-				break;
-
-			case '0.1.9': // SQL queries for v0.1.9
-				addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `action`='account',`title`='In Urlaub',`sort`=2 WHERE `what`='holiday' LIMIT 1");
-
-				// Update notes (these will be set as task text!)
-				setExtensionUpdateNotes("Mitgliedsmen&uuml; komplett umgebaut.");
-				break;
-
-			case '0.2.0': // SQL queries for v0.2.0
-				addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_admin_menu` SET `title`='Urlaubsmanagement' WHERE `action`='holiday' AND (`what`='' OR `what` IS NULL) LIMIT 1");
-
-				// Update notes (these will be set as task text!)
-				setExtensionUpdateNotes("Mitgliedsmen&uuml; komplett umgebaut.");
-				break;
-
-			case '0.2.1': // SQL queries for v0.2.1
-				// Update notes (these will be set as task text!)
-				setExtensionUpdateNotes("Fehlerhinweis bei deaktivierter Erweiterung verbessert.");
-				break;
-		} // END - switch
 		break;
 
 	case 'modify': // When the extension got modified
diff --git a/inc/extensions/ext-html_mail.php b/inc/extensions/ext-html_mail.php
index 53eb0ab7ca..5867318127 100644
--- a/inc/extensions/ext-html_mail.php
+++ b/inc/extensions/ext-html_mail.php
@@ -53,6 +53,9 @@ switch (getExtensionMode()) {
 		addExtensionAddTableColumnSql('bonus', 'html_msg', "ENUM('Y','N') NOT NULL DEFAULT 'N'");
 		addExtensionAddTableColumnSql('pool', 'html_msg', "ENUM('Y','N') NOT NULL DEFAULT 'N'");
 		addMemberMenuSql('main', 'html_mail', 'HTML-Empfang', 3);
+
+		// Register filter here
+		registerFilter(__FILE__, __LINE__, 'exclude_users', 'HTML_INCLUDE_USERS', FALSE, TRUE, isExtensionDryRun());
 		break;
 
 	case 'remove': // Do stuff when removing extension
@@ -61,6 +64,7 @@ switch (getExtensionMode()) {
 
 		// Remove filter(s)
 		unregisterFilter(__FILE__, __LINE__, 'pre_mail_order', 'MAIL_ORDER_GENERIC_CHECK_URL', TRUE, isExtensionDryRun());
+		unregisterFilter(__FILE__, __LINE__, 'exclude_users', 'HTML_INCLUDE_USERS', TRUE, isExtensionDryRun());
 		break;
 
 	case 'activate': // Do stuff when admin activates this extension
diff --git a/inc/extensions/holiday/.htaccess b/inc/extensions/holiday/.htaccess
new file mode 100644
index 0000000000..3a42882788
--- /dev/null
+++ b/inc/extensions/holiday/.htaccess
@@ -0,0 +1 @@
+Deny from all
diff --git a/inc/extensions/holiday/mode-update.php b/inc/extensions/holiday/mode-update.php
new file mode 100644
index 0000000000..f1fa9c46a6
--- /dev/null
+++ b/inc/extensions/holiday/mode-update.php
@@ -0,0 +1,170 @@
+<?php
+/************************************************************************
+ * Mailer v0.2.1-FINAL                                Start: 06/17/2004 *
+ * ===================                          Last change: 01/13/2006 *
+ *                                                                      *
+ * -------------------------------------------------------------------- *
+ * File              : mode-update.php                                  *
+ * -------------------------------------------------------------------- *
+ * Short description : Holiday requests from members                    *
+ * -------------------------------------------------------------------- *
+ * Kurzbeschreibung  : Ferienantraege von Mitgliedern                   *
+ * -------------------------------------------------------------------- *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
+ * -------------------------------------------------------------------- *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
+ * For more information visit: http://mxchange.org                      *
+ *                                                                      *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or    *
+ * (at your option) any later version.                                  *
+ *                                                                      *
+ * This program is distributed in the hope that it will be useful,      *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
+ * GNU General Public License for more details.                         *
+ *                                                                      *
+ * You should have received a copy of the GNU General Public License    *
+ * along with this program; if not, write to the Free Software          *
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
+ * MA  02110-1301  USA                                                  *
+ ************************************************************************/
+
+// Some security stuff...
+if (!defined('__SECURITY')) {
+	die();
+} // END - if
+
+		switch (getCurrentExtensionVersion()) {
+			case '0.0.2': // SQL queries for v0.0.2
+				// Update notes (these will be set as task text!)
+				setExtensionUpdateNotes("Fehlende Abfrage im Mitlieder-Modul, on Erweiterung auch aktiviert ist.");
+				break;
+
+			case '0.0.3': // SQL queries for v0.0.3
+				// Update notes (these will be set as task text!)
+				setExtensionUpdateNotes("Fehler beseitigt, wenn error_reporting=E_ALL gesetzt ist.");
+				break;
+
+			case '0.0.4': // SQL queries for v0.0.4
+				// Update notes (these will be set as task text!)
+				setExtensionUpdateNotes("Problem mit Speicherung der Einstellungen beseitigt.");
+				break;
+
+			case '0.0.5': // SQL queries for v0.0.5
+				// Update notes (these will be set as task text!)
+				setExtensionUpdateNotes("Men&uuml;punkte im Gast-/Mitgliedsbereich k&ouml;nnen nicht mehr aufgerufen werden, wenn die Erweiterung deaktiviert ist.");
+				break;
+
+			case '0.0.6': // SQL queries for v0.0.6
+				// Update notes (these will be set as task text!)
+				setExtensionUpdateNotes("Seit <strong>Patch 340</strong> &uuml;berfl&uuml;ssige HTML-Tags entfernt.");
+				break;
+
+			case '0.0.7': // SQL queries for v0.0.7
+				// Update notes (these will be set as task text!)
+				setExtensionUpdateNotes("IP-Nummer und Browserbezeichnung wird in Admin-Mails eingesetzt.");
+				break;
+
+			case '0.0.8': // SQL queries for v0.0.8
+				// Update notes (these will be set as task text!)
+				setExtensionUpdateNotes("Link zum Mitgliedsprofil in Funktion <u>generateUserProfileLink()</u> ausgelagert.");
+				break;
+
+			case '0.0.9': // SQL queries for v0.0.9
+				// Update notes (these will be set as task text!)
+				setExtensionUpdateNotes("W&ouml;rter <strong>{?mt_word?}</strong>, <strong>{?mt_word2?}</strong> und <strong>{?mt_word3?}</strong> sind austauschbar.");
+				break;
+
+			case '0.1.0': // SQL queries for v0.1.0
+				// Update notes (these will be set as task text!)
+				setExtensionUpdateNotes("Sicherheitsupdate: SQL-Anweisungen gesch&uuml;tzt.");
+				break;
+
+			case '0.1.1': // SQL queries for v0.1.1
+				// Update notes (these will be set as task text!)
+				setExtensionUpdateNotes("Abspeichern von Einstellungen repariert.");
+				break;
+
+			case '0.1.2': // SQL queries for v0.1.2
+				// Update notes (these will be set as task text!)
+				setExtensionUpdateNotes("Abspeichern der Urlaubsanfrage korregiert.");
+				break;
+
+			case '0.1.3': // SQL queries for v0.1.3
+				addExtensionAddTableColumnSql('user_data', 'holiday_active', "ENUM('Y','N') NOT NULL DEFAULT 'N'");
+				addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_max_receive` WHERE `value`=0 LIMIT 1");
+				addConfigAddSql('holiday_lock', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT ' . (getOneDay() * 2));
+
+				// Update notes (these will be set as task text!)
+				setExtensionUpdateNotes("Die Mitgliedaccounts werden nicht mehr gesperrt, sondern nur auf <strong>Urlaub</strong> geschaltet. Lassen Sie sich nicht davon verwirren, dass sie &quot;freigegeben&quot; sind!");
+				break;
+
+			case '0.1.4': // SQL queries for v0.1.4
+				addConfigAddSql('holiday_mode', "ENUM('DIRECT','RESET') NOT NULL DEFAULT 'RESET'");
+
+				// Update notes (these will be set as task text!)
+				setExtensionUpdateNotes("Urlaubsschaltung wird erst Abends um 00:00 Uhr aktiv und nicht durch die Beantragung. Dies kann nun auch auf direkte Umstellung eingestellt werden.");
+				break;
+
+			case '0.1.5': // SQL queries for v0.1.5
+				// Update notes (these will be set as task text!)
+				setExtensionUpdateNotes("Sicherheitsupdate f&uuml;r die Include-Befehle.");
+				break;
+
+			case '0.1.6': // SQL queries for v0.1.6
+				addExtensionAddTableColumnSql('user_data', 'holiday_activated', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
+
+				// Update notes (these will be set as task text!)
+				setExtensionUpdateNotes("Fehlende Tabellenspalte hinzugef&uuml;gt.");
+				break;
+
+			case '0.1.7': // SQL queries for v0.1.7
+				// Update notes (these will be set as task text!)
+				setExtensionUpdateNotes("if-Anweisungen auf Funktion <strong>empty()</strong> umgestellt.");
+				break;
+
+			case '0.1.8': // SQL queries for v0.1.8
+				addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu_las` (`la_id`, `la_action`, `la_what`) VALUES ('member', '', 'list_holiday')");
+				addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu_las` (`la_id`, `la_action`, `la_what`) VALUES ('member', '', 'del_holiday')");
+				addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_admin_menu_las` (`la_id`, `la_action`, `la_what`) VALUES ('config', '', 'config_holiday')");
+
+				// Update notes (these will be set as task text!)
+				setExtensionUpdateNotes("Erweiterung in's neue Men&uuml;system integriert.");
+				break;
+
+			case '0.1.9': // SQL queries for v0.1.9
+				addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `action`='account',`title`='In Urlaub',`sort`=2 WHERE `what`='holiday' LIMIT 1");
+
+				// Update notes (these will be set as task text!)
+				setExtensionUpdateNotes("Mitgliedsmen&uuml; komplett umgebaut.");
+				break;
+
+			case '0.2.0': // SQL queries for v0.2.0
+				addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_admin_menu` SET `title`='Urlaubsmanagement' WHERE `action`='holiday' AND (`what`='' OR `what` IS NULL) LIMIT 1");
+
+				// Update notes (these will be set as task text!)
+				setExtensionUpdateNotes("Mitgliedsmen&uuml; komplett umgebaut.");
+				break;
+
+			case '0.2.1': // SQL queries for v0.2.1
+				// Update notes (these will be set as task text!)
+				setExtensionUpdateNotes("Fehlerhinweis bei deaktivierter Erweiterung verbessert.");
+				break;
+
+			case '0.2.2': // SQL queries for v0.2.2
+				// Register filter
+				registerFilter(__FILE__, __LINE__, 'user_exclusion_sql', 'HOLIDAY_USER_EXCLUSION_SQL', FALSE, TRUE, isExtensionDryRun());
+
+				// Update notes (these will be set as task text!)
+				setExtensionUpdateNotes("Filter registriert f&uuml;r Mitglied-Ausschluss, die in Urlaub sind.");
+				break;
+		} // END - switch
+
+// [EOF]
+?>
diff --git a/inc/filter-functions.php b/inc/filter-functions.php
index e217428394..4e19d0980a 100644
--- a/inc/filter-functions.php
+++ b/inc/filter-functions.php
@@ -193,9 +193,6 @@ ORDER BY
 	// Remove extension
 	registerFilter(__FUNCTION__, __LINE__, 'extension_remove', 'REMOVE_EXTENSION');
 
-	// Exclude some users
-	registerFilter(__FUNCTION__, __LINE__, 'exclude_users', 'HTML_INCLUDE_USERS');
-
 	// Handling of fatal errors
 	registerFilter(__FUNCTION__, __LINE__, 'handle_fatal_errors', 'HANDLE_FATAL_ERRORS');
 
@@ -237,7 +234,7 @@ function registerFilter ($file, $line, $filterName, $filterFunction, $silentAbor
 		// In installation phase we always want to abort
 		if (($silentAbort === FALSE) || (isInstaller())) {
 			// Add fatal message
-			reportBug(__FUNCTION__, __LINE__, sprintf("Filter chain %s has already filter function %s registered! file=%s,L=%s,force=%d", $filterName, $filterFunction, basename($file), $line, intval($force)));
+			reportBug(__FUNCTION__, __LINE__, sprintf('Filter chain %s has already filter function %s registered! file=%s,L=%s,force=%d', $filterName, $filterFunction, basename($file), $line, intval($force)));
 		} // END - if
 
 		// Abort here
@@ -249,7 +246,7 @@ function registerFilter ($file, $line, $filterName, $filterFunction, $silentAbor
 		// Is the function there?
 		if (!function_exists($filterFunction)) {
 			// Then abort here
-			logDebugMessage(__FUNCTION__, __LINE__, sprintf("Filter function %s could not be added to filter chain %s. file=%s,L=%s,force=%d", $filterFunction, $filterName, basename($file), $line, intval($force)));
+			logDebugMessage(__FUNCTION__, __LINE__, sprintf('Filter function %s could not be added to filter chain %s. file=%s,L=%s,force=%d', $filterFunction, $filterName, basename($file), $line, intval($force)));
 			return FALSE;
 		} // END - if
 
diff --git a/inc/filter/holiday_filter.php b/inc/filter/holiday_filter.php
new file mode 100644
index 0000000000..ce44eecebe
--- /dev/null
+++ b/inc/filter/holiday_filter.php
@@ -0,0 +1,62 @@
+<?php
+/************************************************************************
+ * Mailer v0.2.1-FINAL                                Start: 06/02/2011 *
+ * ===================                          Last change: 06/02/2011 *
+ *                                                                      *
+ * -------------------------------------------------------------------- *
+ * File              : _filter.php                                      *
+ * -------------------------------------------------------------------- *
+ * Short description : Filters for ext-                                 *
+ * -------------------------------------------------------------------- *
+ * Kurzbeschreibung  : Filter fuer ext-                                 *
+ * -------------------------------------------------------------------- *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
+ * -------------------------------------------------------------------- *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
+ * For more information visit: http://mxchange.org                      *
+ *                                                                      *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or    *
+ * (at your option) any later version.                                  *
+ *                                                                      *
+ * This program is distributed in the hope that it will be useful,      *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
+ * GNU General Public License for more details.                         *
+ *                                                                      *
+ * You should have received a copy of the GNU General Public License    *
+ * along with this program; if not, write to the Free Software          *
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
+ * MA  02110-1301  USA                                                  *
+ ************************************************************************/
+
+// Some security stuff...
+if (!defined('__SECURITY')) {
+	die();
+} // END - if
+
+// Filter for excluding holiday users in WHERE statements
+function FILTER_HOLIDAY_USER_EXCLUSION_SQL ($sql) {
+	//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called! - sql(' . strlen($sql) . ')=' . $sql);
+
+	// Add it, as of this filter is registered only with ext-user >= 0.5.0
+	if (empty($sql)) {
+		// Add WHERE
+		$sql = " WHERE `holiday_active` = 'N'";
+	} else {
+		// Add AND
+		$sql .= " AND `holiday_active` = 'N'";
+	}
+
+	// Return the data for next filter
+	//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done! - sql(' . strlen($sql) . ')=' . $sql);
+	return $sql;
+}
+
+// [EOF]
+?>
diff --git a/inc/filter/html_mail_filter.php b/inc/filter/html_mail_filter.php
index 3ed2794483..cfa86894e9 100644
--- a/inc/filter/html_mail_filter.php
+++ b/inc/filter/html_mail_filter.php
@@ -64,5 +64,19 @@ function FILTER_CHECK_HTML_MAIL_ORDER ($filterData) {
 	return $filterData;
 }
 
+// Prepares an SQL statement part for HTML mail
+function FILTER_HTML_INCLUDE_USERS ($mode) {
+	// Exclude no users by default
+	$MORE = '';
+
+	// HTML mail?
+	if ($mode == 'html') {
+		$MORE = " AND `html`='Y'";
+	} // END - if
+
+	// Return result
+	return $MORE;
+}
+
 // [EOF]
 ?>
diff --git a/inc/filters.php b/inc/filters.php
index 7fba80252b..239d9048c1 100644
--- a/inc/filters.php
+++ b/inc/filters.php
@@ -711,25 +711,6 @@ function FILTER_FLUSH_OUTPUT () {
 	outputHtml();
 }
 
-// Prepares an SQL statement part for HTML mail and/or holiday dependency
-function FILTER_HTML_INCLUDE_USERS ($mode) {
-	// Exclude no users by default
-	$MORE = '';
-
-	// HTML mail?
-	if ($mode == 'html') {
-		$MORE = " AND `html`='Y'";
-	} // END - if
-
-	if (isExtensionInstalledAndNewer('holiday', '0.1.3')) {
-		// Add something for the holiday extension
-		$MORE .= " AND `holiday_active`='N'";
-	} // END - if
-
-	// Return result
-	return $MORE;
-}
-
 // Filter for determining what/action/module
 function FILTER_DETERMINE_WHAT_ACTION () {
 	// In installation phase we don't have what/action
diff --git a/inc/libs/task_functions.php b/inc/libs/task_functions.php
index d7eda64402..016fe18678 100644
--- a/inc/libs/task_functions.php
+++ b/inc/libs/task_functions.php
@@ -257,13 +257,6 @@ function outputAdvancedOverview (&$result_main) {
 			$userExclusionSql .= ' AND `d`.`userid` NOT IN (' . implode(', ', $excludedUserids) . ')';
 		} // END - if
 
-		// Check for more extensions
-		// @TODO This can be rewritten to filter
-		if (isExtensionInstalledAndNewer('holiday', '0.1.3')) {
-			// Recent ext-holiday found
-			$userExclusionSql .= " AND `d`.`holiday_active`='N'";
-		} // END - if
-
 		// Check for all accounts
 		addSql("SELECT
 	`d`.`userid`,
@@ -276,7 +269,7 @@ WHERE
 	(UNIX_TIMESTAMP() - `d`.`joined`) >= {?ap_inactive_since?} AND
 	(UNIX_TIMESTAMP() - `d`.`last_online`) >= {?ap_inactive_since?} AND
 	(UNIX_TIMESTAMP() - `d`.`ap_notified`) >= {?ap_inactive_since?}
-	" . runFilterChain('user_exclusion_sql', $userExclusionSql) . "
+	" . runFilterChain('user_exclusion_sql', ' ' . $userExclusionSql) . "
 ORDER BY
 	`d`.`userid` ASC");
 		$WHATs[]  = 'list_autopurge';
diff --git a/inc/mails/beg_mails.php b/inc/mails/beg_mails.php
index a773063f8e..d319f3e8f9 100644
--- a/inc/mails/beg_mails.php
+++ b/inc/mails/beg_mails.php
@@ -77,18 +77,8 @@ switch (getBegRallye()) {
 } // END - switch
 
 if (!empty($sql)) {
-	// Init additional WHERE statement
-	$whereStatement = '';
-
-	// Is ext-holiday installed?
-	// @TODO Rewrite these if() blocks to a filter
-	if (isExtensionActive('holiday')) {
-		// Exclude those as well
-		$whereStatement .= " AND `d`.`holiday_active`='N'";
-	} // END - if
-
 	// The SQL command needs to be finisched here (only confirmed accounts!)
-	$sql .= ')' . $whereStatement . runFilterChain('user_exclusion_sql', " AND `d`.`status`='CONFIRMED'") . ' ORDER BY `d`.`last_online` ASC';
+	$sql .= ')' . runFilterChain('user_exclusion_sql', " AND `d`.`status`='CONFIRMED'") . ' ORDER BY `d`.`last_online` ASC';
 
 	// No IP locking setuped by default
 	$content['ip_locker'] = '{--BEG_NO_LIMITATION--}';
diff --git a/inc/mails/bonus_mails.php b/inc/mails/bonus_mails.php
index 24b10ea547..e036bebcff 100644
--- a/inc/mails/bonus_mails.php
+++ b/inc/mails/bonus_mails.php
@@ -77,18 +77,8 @@ switch (getBonusActive()) {
 } // END - switch
 
 if (!empty($sql)) {
-	// Init additional WHERE statement
-	$whereStatement = '';
-
-	// Is ext-holiday installed?
-	// @TODO Rewrite these if() blocks to a filter
-	if (isExtensionActive('holiday')) {
-		// Exclude those as well
-		$whereStatement .= " AND `d`.`holiday_active`='N'";
-	} // END - if
-
 	// The SQL command needs to be finisched here (only confirmed accounts!)
-	$sql .= ')' . $whereStatement . runFilterChain('user_exclusion_sql', " AND `d`.`status`='CONFIRMED'") . ' ORDER BY `d`.`last_online` ASC';
+	$sql .= ')' . runFilterChain('user_exclusion_sql', " AND `d`.`status`='CONFIRMED'") . ' ORDER BY `d`.`last_online` ASC';
 
 	// Normal notification mails or bonus mails?
 	$sentBonusMails = ((getBonusNotifyPoints() > 0) && ($mode == 'enable') && (isExtensionActive('bonus')));
diff --git a/inc/mails/doubler_mails.php b/inc/mails/doubler_mails.php
index 1783c69cb1..f2fc13cceb 100644
--- a/inc/mails/doubler_mails.php
+++ b/inc/mails/doubler_mails.php
@@ -68,16 +68,6 @@ unsetPostRequestElement('DOUBLER_USERID');
 setSession('DOUBLER_USERID', '');
 if (empty($GLOBALS['local_doubler_userid'])) $GLOBALS['local_doubler_userid'] = '0';
 
-// Init additional WHERE statement
-$whereStatement = ' ';
-
-// Is ext-holiday installed?
-// @TODO Rewrite these if() blocks to a filter
-if (isExtensionActive('holiday')) {
-	// Exclude those as well
-	$whereStatement .= " AND `d`.`holiday_active`='N'";
-} // END - if
-
 // Check for doubles which we can pay out
 $result_total = sqlQueryEscaped("SELECT
 	COUNT(`do`.`id`) AS `cnt`,
@@ -89,7 +79,7 @@ ON
 	`do`.`userid`=`d`.`userid`
 WHERE
 	`d`.`status`='CONFIRMED'
-	" . runFilterChain('user_exclusion_sql', $whereStatement) . " AND
+	" . runFilterChain('user_exclusion_sql', ' ' . $whereStatement) . " AND
 	`do`.`points` <= %s AND
 	`do`.`points` >= ({?doubler_min?} * 2) AND
 	`do`.`completed`='N' AND
@@ -121,7 +111,7 @@ ON
 	`do`.`userid`=`d`.`userid`
 WHERE
 	`d`.`status`='CONFIRMED'
-	" . runFilterChain('user_exclusion_sql', $whereStatement) . " AND
+	" . runFilterChain('user_exclusion_sql', ' ' . $whereStatement) . " AND
 	`do`.`points` <= %s AND
 	`do`.`points` >= ({?doubler_min?} * 2) AND
 	`do`.`completed`='N' AND
diff --git a/inc/modules/admin/what-list_autopurge.php b/inc/modules/admin/what-list_autopurge.php
index d35b1b4d9f..c9fba992b4 100644
--- a/inc/modules/admin/what-list_autopurge.php
+++ b/inc/modules/admin/what-list_autopurge.php
@@ -51,11 +51,6 @@ if (isFilledArray($excludedUserids)) {
 	$userExcludeSql = ' AND `d`.`userid` NOT IN (' . implode(', ', $excludedUserids) . ')';
 } // END - if
 
-// @TODO Rewrite this as a filter
-if (isExtensionInstalledAndNewer('holiday', '0.1.3')) {
-	$userExclusionSql .= " AND `d`.`holiday_active`='N'";
-} // END - if
-
 // Check for all accounts
 $result = sqlQuery("SELECT
 	`d`.`userid`,
@@ -73,7 +68,7 @@ WHERE
 	(UNIX_TIMESTAMP() - `d`.`joined`) >= {?ap_inactive_since?} AND
 	(UNIX_TIMESTAMP() - `d`.`last_online`) >= {?ap_inactive_since?} AND
 	(UNIX_TIMESTAMP() - `d`.`ap_notified`) >= {?ap_inactive_since?}
-	" . runFilterChain('user_exclusion_sql', $userExcludeSql) . "
+	" . runFilterChain('user_exclusion_sql', ' ' . $userExcludeSql) . "
 ORDER BY
 	`d`.`userid` ASC", __FILE__, __LINE__);
 
diff --git a/inc/modules/admin/what-list_user.php b/inc/modules/admin/what-list_user.php
index c10c443ab3..b722627dac 100644
--- a/inc/modules/admin/what-list_user.php
+++ b/inc/modules/admin/what-list_user.php
@@ -199,7 +199,7 @@ LIMIT 1',
 		}
 
 		// Exclude other users
-		$whereStatement = runFilterChain('user_exclusion_sql', $whereStatement);
+		$whereStatement = runFilterChain('user_exclusion_sql', ' ' . $whereStatement);
 	} elseif (isGetRequestElementSet('do')) {
 		// Choose what we need to list
 		switch (getRequestElement('do')) {
@@ -236,7 +236,7 @@ LIMIT 1',
 		// If it is not 'testers', add exclusion SQL
 		if (getRequestElement('do') != 'testers') {
 			// Exclude tester users
-			$whereStatement = runFilterChain('user_exclusion_sql', $whereStatement);
+			$whereStatement = runFilterChain('user_exclusion_sql', ' ' . $whereStatement);
 		} // END - if
 	} // END - if
 
diff --git a/inc/modules/member/what-html_mail.php b/inc/modules/member/what-html_mail.php
index 6d6327ecd8..0f0b21de63 100644
--- a/inc/modules/member/what-html_mail.php
+++ b/inc/modules/member/what-html_mail.php
@@ -54,7 +54,11 @@ if ((!isExtensionActive('html_mail')) && (!isAdmin())) {
 if (isFormSent()) {
 	// Save settings
 	sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `html`='%s' WHERE `userid`=%s LIMIT 1",
-		array(postRequestElement('html'), getMemberId()), __FILE__, __LINE__);
+		array(
+			postRequestElement('html'),
+			getMemberId()
+		), __FILE__, __LINE__
+	);
 	displayMessage('{--MEMBER_SETTINGS_SAVED--}');
 } else {
 	// Prepare it
diff --git a/inc/modules/member/what-order.php b/inc/modules/member/what-order.php
index cc8fdf4216..b064c4cb7a 100644
--- a/inc/modules/member/what-order.php
+++ b/inc/modules/member/what-order.php
@@ -315,14 +315,10 @@ ORDER BY
 
 			// Enable HTML checking
 			// @TODO Rewrite this to a filter
-			$HTML = ''; $HOL_STRING = '';
+			$HTML = '';
 			if ((isExtensionActive('html_mail')) && (postRequestElement('html') == 'Y')) {
 				$HTML = " AND `html`='Y'";
 			} // END - if
-			if (isExtensionInstalledAndNewer('holiday', '0.1.3')) {
-				// Extension's version is fine
-				$HOL_STRING = " AND `holiday_active`='N'";
-			} // END - if
 
 			// ... and begin loading stuff
 			while ($categoriesContent = sqlFetchArray($result_cats)) {
diff --git a/inc/monthly/monthly_beg.php b/inc/monthly/monthly_beg.php
index 79f50ac9fc..16cb2762d7 100644
--- a/inc/monthly/monthly_beg.php
+++ b/inc/monthly/monthly_beg.php
@@ -67,12 +67,6 @@ if ((getBegRanks() > 0) && (!isCssOutputMode())) {
 		$whereStatement .= ' AND (UNIX_TIMESTAMP() - `d`.`last_online`) < {?ap_inactive_since?}';
 	} // END - if
 
-	// Is ext-holiday installed?
-	if (isExtensionActive('holiday')) {
-		// Exclude those as well
-		$whereStatement .= " AND `d`.`holiday_active`='N'";
-	} // END - if
-
 	// SQL string to check for accounts
 	$result_main = sqlQuery("SELECT
 	`d`.`userid`,
@@ -81,8 +75,7 @@ FROM
 	`{?_MYSQL_PREFIX?}_user_data` AS `d`
 WHERE
 	`d`.`status`='CONFIRMED'
-	" . $whereStatement . "
-	" . runFilterChain('user_exclusion_sql', ' ') . " AND
+	" . runFilterChain('user_exclusion_sql', $whereStatement) . " AND
 	`d`.`beg_points` > 0
 ORDER BY
 	`d`.`beg_points` DESC,
diff --git a/inc/monthly/monthly_bonus.php b/inc/monthly/monthly_bonus.php
index a0f5cec2f6..b4bbfe0d83 100644
--- a/inc/monthly/monthly_bonus.php
+++ b/inc/monthly/monthly_bonus.php
@@ -60,12 +60,6 @@ if ((getBonusRanks() > 0) && (!isCssOutputMode())) {
 		$whereStatement .= ' AND (UNIX_TIMESTAMP() - `d`.`last_online`) < {?ap_inactive_since?}';
 	} // END - if
 
-	// Is ext-holiday installed?
-	if (isExtensionActive('holiday')) {
-		// Exclude those as well
-		$whereStatement .= " AND `d`.`holiday_active`='N'";
-	} // END - if
-
 	// Add more bonus points here by running a filter
 	$add = runFilterChain('add_bonus_points_user_columns', '');
 
diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php
index b98aea3993..da948fbee8 100644
--- a/inc/mysql-manager.php
+++ b/inc/mysql-manager.php
@@ -1791,11 +1791,6 @@ function generateReceiverList ($categoryId, $receiver, $mode = '') {
 		$addWhere .= " AND `d`.`holiday_active`='N'";
 	} // END - if
 
-	// Include only HTML recipients?
-	if ((isExtensionActive('html_mail')) && ($mode == 'html')) {
-		$addWhere .= " AND `d`.`html`='Y'";
-	} // END - if
-
 	// Run query
 	$result = sqlQueryEscaped("SELECT
 	`d`.`userid`
diff --git a/inc/purge/purge-inact.php b/inc/purge/purge-inact.php
index a137f2ebb6..b92e90cb5f 100644
--- a/inc/purge/purge-inact.php
+++ b/inc/purge/purge-inact.php
@@ -59,12 +59,6 @@ if (isAutopurgeInactiveEnabled()) {
 		$excludeSql = ' AND `userid` NOT IN (' . implode(', ', $excludedUserids) . ')';
 	} // END - if
 
-	// Check for new holiday extension
-	if (isExtensionInstalledAndNewer('holiday', '0.1.3')) {
-		// Include only users with no active holiday
-		$excludeSql .= " AND `holiday_active`='N'";
-	} // END - if
-
 	// Check for all accounts
 	$result_inactive = sqlQuery("SELECT
 	`userid`,
@@ -77,7 +71,7 @@ WHERE
 	(UNIX_TIMESTAMP() - `joined`) >= {?ap_inactive_since?} AND
 	(UNIX_TIMESTAMP() - `last_online`) >= {?ap_inactive_since?} AND
 	(UNIX_TIMESTAMP() - `ap_notified`) >= {?ap_inactive_since?}
-	" . runFilterChain('user_exclusion_sql', $excludeSql) . "
+	" . runFilterChain('user_exclusion_sql', ' ' . $excludeSql) . "
 ORDER BY
 	`userid` ASC", __FILE__, __LINE__);
 
@@ -130,7 +124,7 @@ FROM
 	`{?_MYSQL_PREFIX?}_user_data`
 WHERE
 	`status`='CONFIRMED'
-	" . runFilterChain('user_exclusion_sql', $excludeSql) . " AND
+	" . runFilterChain('user_exclusion_sql', ' ' . $excludeSql) . " AND
 	(UNIX_TIMESTAMP() - `joined`) >= {?ap_inactive_since?} AND
 	(UNIX_TIMESTAMP() - `last_online`) >= {?ap_inactive_since?} AND
 	(UNIX_TIMESTAMP() - `ap_notified`) >= {?ap_inactive_time?} AND
-- 
2.39.5