Rewrote some parts:
[mailer.git] / inc / extensions / ext-nickname.php
index b7ea4f60bd192ee37277b66421853ac1643eb3a5..d922667754b145d353564c96150ee10be52e3528 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 06/17/2004 *
- * ================                             Last change: 06/17/2004 *
+ * Mailer v0.2.1-FINAL                                Start: 06/17/2004 *
+ * ===================                          Last change: 06/17/2004 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : ext-nickname.php                                 *
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Nickname-Login und Anzeige im Anmeldeformular    *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder                           *
- * For more information visit: http://www.mxchange.org                  *
+ * 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 *
 
 // Some security stuff...
 if (!defined('__SECURITY')) {
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
-       require($INC);
-}
+       die();
+} // END - if
 
 // Version number
-EXT_SET_VERSION("0.1.9");
-
-// Version history array (add more with , "0.1" and so on)
-EXT_SET_VER_HISTORY(array("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"));
-
-switch ($EXT_LOAD_MODE)
-{
-case "register": // Do stuff when installation is running (modules.php?module=admin&action=login is called)
-       // SQL commands to run
-       ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_user_data` ADD nickname VARCHAR(255) NOT NULL DEFAULT ''");
-       ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_user_data` ADD nick_uid ENUM ('nick','uid') NOT NULL DEFAULT 'uid'");
-       ADD_SQL("INSERT INTO `{!_MYSQL_PREFIX!}_member_menu` (`action`,`what`,`title`,`sort`,`visible`,`locked`) VALUES ('main','nickname','Nicknamen','5','Y','Y')");
-       break;
-
-case "remove": // Do stuff when removing extension
-       // SQL commands to run
-       ADD_SQL("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_member_menu` WHERE `what`='nickname' LIMIT 1");
-       ADD_SQL("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE what IN ('config_nickname','list_nickname') LIMIT 2");
-       ADD_SQL("DROP TABLE IF EXISTS `{!_MYSQL_PREFIX!}_nickname_history`");
-       break;
-
-case "activate": // Do stuff when admin activates this extension
-       // SQL commands to run
-       ADD_SQL("UPDATE `{!_MYSQL_PREFIX!}_member_menu` SET `visible`='Y', `locked`='N' WHERE `what`='nickname' LIMIT 1");
-       break;
-
-case "deactivate": // Do stuff when admin deactivates this extension
-       // SQL commands to run
-       ADD_SQL("UPDATE `{!_MYSQL_PREFIX!}_member_menu` SET `visible`='N', `locked`='Y' WHERE `what`='nickname' LIMIT 1");
-       break;
-
-case "update": // Update an extension
-       switch ($EXT_VER)
-       {
-       case "0.0.1": // SQL queries for v0.0.1
-               ADD_SQL("UPDATE `{!_MYSQL_PREFIX!}_extensions` SET ext_has_css='Y' WHERE ext_name='nickname' AND ext_has_css='N' LIMIT 1");
-
-               // This update depends on sql_patches update!
-               EXT_SET_UPDATE_DEPENDS("sql_patches");
-
-               // Update notes (these will be set as task text!)
-               EXT_SET_UPDATE_NOTES("CSS-Datei kann per Adminbereich ein- und ausgeschaltet werden.");
-               break;
+setThisExtensionVersion('0.2.1');
 
-       case "0.0.3": // SQL queries for v0.0.3
-               // Update notes (these will be set as task text!)
-               EXT_SET_UPDATE_NOTES("Fehlende Abfrage im Mitlieder-Modul, on Erweiterung auch aktiviert ist.");
+// 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'));
+
+switch (getExtensionMode()) {
+       case 'setup': // Do stuff when installation is running
+               // SQL commands to run
+               // @TODO NOT NULL DEFAULT '' is bad practice, use NULL
+               addExtensionAddTableColumnSql('user_data', 'nickname', "VARCHAR(255) NOT NULL DEFAULT ''");
+               addExtensionAddTableColumnSql('user_data', 'nick_userid', "ENUM ('nick','userid') NOT NULL DEFAULT 'userid'");
+
+               // Add member menu
+               addMemberMenuSql('extras', 'nickname', 'Nicknamen', 2);
                break;
-
-       case "0.0.4": // SQL queries for v0.0.4
-               // Update notes (these will be set as task text!)
-               EXT_SET_UPDATE_NOTES("Wegen des Theme-Supportes hat sich die URL zur CSS-Datei ge&auml;ndert.");
+
+       case 'remove': // Do stuff when removing extension
+               // SQL commands to run
+               addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `what`='nickname' LIMIT 1");
+               addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `what` IN ('config_nickname','list_nickname') LIMIT 2");
+               break;
+
+       case 'activate': // Do stuff when admin activates this extension
+               // SQL commands to run
+               addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='Y',`locked`='N' WHERE `what`='nickname' LIMIT 1");
+               break;
+
+       case 'deactivate': // Do stuff when admin deactivates this extension
+               // SQL commands to run
+               addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='N',`locked`='Y' WHERE `what`='nickname' LIMIT 1");
                break;
 
-       case "0.0.5": // SQL queries for v0.0.5
-               // Update notes (these will be set as task text!)
-               EXT_SET_UPDATE_NOTES("Fehler beseitigt, wenn error_reporting=E_ALL gesetzt ist.");
-               break;
+       case 'update': // Update an extension
+               switch (getCurrentExtensionVersion()) {
+                       case '0.0.1': // SQL queries for v0.0.1
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes("Veraltetes Update entfernt.");
+                               break;
+
+                       case '0.0.3': // SQL queries for v0.0.3
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes("Fehlende Abfrage im Mitlieder-Modul, on Erweiterung auch aktiviert ist.");
+                               break;
+
+                       case '0.0.4': // SQL queries for v0.0.4
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes("Wegen des Theme-Supportes hat sich die URL zur CSS-Datei ge&auml;ndert.");
+                               break;
+
+                       case '0.0.5': // SQL queries for v0.0.5
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes("Fehler beseitigt, wenn error_reporting=E_ALL gesetzt ist.");
+                               break;
+
+                       case '0.0.6': // SQL queries for v0.0.6
+                               addConfigAddSql('nickname_len', 'TINYINT(3) UNSIGNED NOT NULL DEFAULT 5');
+                               addConfigAddSql('nickname_pattern', "VARCHAR(255) NOT NULL DEFAULT 'a-zA-Z0-9_'");
+                               addConfigAddSql('nickname_chars', "VARCHAR(255) NOT NULL DEFAULT 'a-z, A-Z, 0-9, _'");
+                               addAdminMenuSql('setup', 'config_nickname', 'Nicknamen', 'Stellen Sie minimale Nicknamenl&auml;nge, sowie erlaubte Zeichen hier ein.', 12);
 
-       case "0.0.6": // SQL queries for v0.0.6
-               ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD nickname_len TINYINT(3) UNSIGNED NOT NULL DEFAULT '5'");
-               ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD nickname_pattern VARCHAR(255) NOT NULL DEFAULT 'a-zA-Z0-9_'");
-               ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD nickname_chars VARCHAR(255) NOT NULL DEFAULT 'a-z, A-Z, 0-9, _'");
-               ADD_SQL("INSERT INTO `{!_MYSQL_PREFIX!}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('setup','config_nickname','Nicknamen','Stellen Sie minimale Nicknamenl&auml;nge, sowie erlaubte Zeichen hier ein.', 12)");
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes("Minimale L&auml;nge, sowie erlaubte Zeichen sind per Adminbereich &auml;nderbar. Setzen Sie als erlaubte Zeichen nur URL-konforme Zeichen ein!");
+                               break;
 
-               // Update notes (these will be set as task text!)
-               EXT_SET_UPDATE_NOTES("Minimale L&auml;nge, sowie erlaubte Zeichen sind per Adminbereich &auml;nderbar. Setzen Sie als erlaubte Zeichen nur URL-konforme Zeichen ein!");
-               break;
+                       case '0.0.7': // SQL queries for v0.0.7
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes("Problem mit Speicherung der Einstellungen beseitigt.");
+                               break;
 
-       case "0.0.7": // SQL queries for v0.0.7
-               // Update notes (these will be set as task text!)
-               EXT_SET_UPDATE_NOTES("Problem mit Speicherung der Einstellungen beseitigt.");
-               break;
+                       case '0.0.8': // SQL queries for v0.0.8
+                               // 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.8": // SQL queries for v0.0.8
-               // Update notes (these will be set as task text!)
-               EXT_SET_UPDATE_NOTES("Men&uuml;punkte im Gast-/Mitgliedsbereich k&ouml;nnen nicht mehr aufgerufen werden, wenn die Erweiterung deaktiviert ist.");
-               break;
+                       case '0.0.9': // SQL queries for v0.0.9
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes("Design &quot;Solid-Business&quot; eingebaut.");
+                               break;
 
-       case "0.0.9": // SQL queries for v0.0.9
-               // Update notes (these will be set as task text!)
-               EXT_SET_UPDATE_NOTES("Design &quot;Solid-Business&quot; eingebaut.");
-               break;
+                       case '0.1.0': // SQL queries for v0.2.1
+                               // 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.1.0": // SQL queries for v0.2.1
-               // Update notes (these will be set as task text!)
-               EXT_SET_UPDATE_NOTES("Seit <a href=\"#\">Patch 340</a> &uuml;berfl&uuml;ssige HTML-Tags entfernt.");
-               break;
+                       case '0.1.1': // SQL queries for v0.1.1
+                               addExtensionDropTableColumnSql('user_data', 'nick_userid');
 
-       case "0.1.1": // SQL queries for v0.1.1
-               ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_user_data` DROP nick_uid");
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes("Auswahlf&uuml;r Mitglied ob mit Nickname oder Mitglieds-Id einloggen entfernt.");
+                               break;
 
-               // Update notes (these will be set as task text!)
-               EXT_SET_UPDATE_NOTES("Auswahlf&uuml;r Mitglied ob mit Nickname oder User-ID einloggen entfernt.");
-               break;
+                       case '0.1.2': // SQL queries for v0.1.2
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes("Zum Zusenden eines neuen Passwortes kann jetzt entweder der Nickname / Mitglieds-Id <u>ODER</u> die angemeldete EMail-Adresse eingegeben werden.");
+                               break;
 
-       case "0.1.2": // SQL queries for v0.1.2
-               // Update notes (these will be set as task text!)
-               EXT_SET_UPDATE_NOTES("Zum Zusenden eines neuen Passwortes kann jetzt entweder der Nickname / User-ID <u>ODER</u> die angemeldete EMail-Adresse eingegeben werden.");
-               break;
+                       case '0.1.3': // SQL queries for v0.1.3
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes("CSS-Datei in general.css verschmolzen (Patch 435!)");
+                               break;
 
-       case "0.1.3": // SQL queries for v0.1.3
-               // Update notes (these will be set as task text!)
-               EXT_SET_UPDATE_NOTES("CSS-Datei in general.css verschmolzen (Patch 435!)");
-               break;
+                       case '0.1.4': // SQL queries for v0.1.4
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes("HTML-Code ausgelagert in Templates und SQL-Anweisungen abgesichert.");
+                               break;
 
-       case "0.1.4": // SQL queries for v0.1.4
-               // Update notes (these will be set as task text!)
-               EXT_SET_UPDATE_NOTES("HTML-Code ausgelagert in Templates und SQL-Anweisungen abgesichert.");
-               break;
+                       case '0.1.5': // SQL queries for v0.1.5
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes("Abspeichern von Einstellungen repariert.");
+                               break;
 
-       case "0.1.5": // SQL queries for v0.1.5
-               // Update notes (these will be set as task text!)
-               EXT_SET_UPDATE_NOTES("Abspeichern von Einstellungen repariert.");
-               break;
+                       case '0.1.6': // SQL queries for v0.1.6
+                               addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `action`='extras',`sort`=2 WHERE `what`='nickname' LIMIT 1");
 
-       case "0.1.6": // SQL queries for v0.1.6
-               ADD_SQL("UPDATE `{!_MYSQL_PREFIX!}_member_menu` SET `action`='extras', `sort`='2' WHERE `what`='nickname' LIMIT 1");
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes("Mitgliedsmen&uuml; komplett umgebaut.");
+                               break;
 
-               // Update notes (these will be set as task text!)
-               EXT_SET_UPDATE_NOTES("Mitgliedsmen&uuml; komplett umgebaut.");
-               break;
+                       case '0.1.7': // SQL queries for v0.1.7
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes("Mitglieder ohne Nickname sollten kein <strong>*failed*</strong> mehr sehen.");
+                               break;
+
+                       case '0.1.8': // SQL queries for v0.1.8
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes("Fehlerhinweis bei deaktivierter Erweiterung verbessert.");
+                               break;
+
+                       case '0.1.9': // SQL queries for v0.1.9
+                               addAdminMenuSql('user', 'list_nickname', 'Nickname-Historie', 'Listet alle verwendeten Nicknames der Mitglieder auf.', 12);
 
-       case "0.1.7": // SQL queries for v0.1.7
-               // Update notes (these will be set as task text!)
-               EXT_SET_UPDATE_NOTES("Mitglieder ohne Nickname sollten kein <strong>*failed*</strong> mehr sehen.");
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes("Menu&uuml;punkt f&uuml;r Nickname-History hinzugef&uuml;gt.");
+                               break;
+
+                       case '0.2.0': // SQL queries for v0.2.0
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes("Ung&uuml;ltiges Update (wegen Verallgemeinerung der <strong>nickname_history</strong>-Tabelle.");
+                               break;
+
+                       case '0.2.1': // SQL queries for v0.2.1
+                               // Remove this deprecated table
+                               addDropTableSql('nickname_history');
+
+                               // Update notes (these will be set as task text!)
+                               setExtensionUpdateNotes("Diese Tabelle kann in <strong>ext-sql_patches</strong> allgemeiner formuliert werden.");
+                               break;
+               } // END - switch
                break;
 
-       case "0.1.8": // SQL queries for v0.1.8
-               // Update notes (these will be set as task text!)
-               EXT_SET_UPDATE_NOTES("Fehlerhinweis bei deaktivierter Erweiterung verbessert.");
+       case 'modify': // When the extension got modified
                break;
 
-       case "0.1.9": // SQL queries for v0.1.9
-               ADD_SQL("INSERT INTO `{!_MYSQL_PREFIX!}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('user','list_nickname','Nickname-Historie','Listet alle verwendeten Nicknames der Mitglieder auf.', 12)");
-               ADD_SQL("DROP TABLE IF EXISTS `{!_MYSQL_PREFIX!}_nickname_history`");
-               ADD_SQL("CREATE TABLE `{!_MYSQL_PREFIX!}_nickname_history` (
-id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
-userid BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
-nickname VARCHAR(255) NOT NULL DEFAULT '',
-added TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
-last_used TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
-INDEX userid (userid),
-INDEX (last_used DESC),
-PRIMARY KEY(id)
-) TYPE=MyISAM COMMENT='History of used nicknames'");
-
-               // Update notes (these will be set as task text!)
-               EXT_SET_UPDATE_NOTES("Historie eingegebener Nicknames hinzugef&uuml;gt. Mitglied kann auf bereits verwendeter zur&uuml;ckgreifen und Liste selbst l&ouml;schen.");
+       case 'test': // For testing purposes
                break;
-       }
-       break;
 
-case "test": // For testing purposes. For details see file inc/modules/admin/what-extensions.php, arround line 305.
-       break;
+       case 'init': // Do stuff when extension is initialized
+               break;
 
-default: // Do stuff when extension is loaded
-       break;
-}
+       default: // Unknown extension mode
+               reportBug(__FILE__, __LINE__, sprintf('Unknown extension mode %s in extension %s detected.', getExtensionMode(), getCurrentExtensionName()));
+               break;
+} // END - switch
 
-//
+// [EOF]
 ?>