A lot while() conditions rewritten to SQL_FETCHARRAY(), see bug #107, @TODO tags...
[mailer.git] / inc / extensions / ext-cache.php
index ad0f624a9b430eb7e167d306642b201b14557452..17a13d08f378a84d14a192ab66d643bec97e8133 100644 (file)
  ************************************************************************/
 
 // Some security stuff...
-if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])))
-{
+if (!defined('__SECURITY')) {
        $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
        require($INC);
 }
 
 // Version number
-$EXT_VERSION = "0.1.7";
-
-// Auto-set extension version
-if (empty($EXT_VER)) $EXT_VER = $EXT_VERSION;
+EXT_SET_VERSION("0.2.2");
 
 // Version history array (add more with , "0.1" and so on)
-$EXT_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");
+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", "0.2.0", "0.2.1", "0.2.2"));
 
 switch ($EXT_LOAD_MODE)
 {
-case "register": // Do stuff when installtion is running (modules.php?module=admin&action=login is called)
+case "register": // Do stuff when installation is running (modules.php?module=admin&action=login is called)
        // SQL commands to run
-       $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD cache_update bigint(20) not null default '3600'";
-       $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD cache_path varchar(255) not null default 'cache/'";
-       $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD cache_tested tinyint(1) not null default '0'";
-       $SQLs[] = "INSERT INTO "._MYSQL_PREFIX."_admin_menu (action, what, title, descr, sort) VALUES ('setup', 'config_cache', 'Cache-Einstellungen', 'Update-Interval des Caches usw. können Sie hier ändern.', 9)";
+       ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_update BIGINT(20) UNSIGNED NOT NULL DEFAULT 3600");
+       ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_path VARCHAR(255) NOT NULL DEFAULT 'cache/'");
+       ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_tested TINYINT(1) UNSIGNED NOT NULL DEFAULT 0");
+       ADD_SQL("INSERT INTO `{!_MYSQL_PREFIX!}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('setup','config_cache','Cache-Einstellungen','Update-Interval des Caches usw. können Sie hier ändern.', 9)");
        break;
 
 case "remove": // Do stuff when removing extension
        // SQL commands to run
-       $SQLs[] = "DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_admin_menu WHERE what='config_cache' OR what='cache_stats' LIMIT 2";
-       $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config DROP cache_update";
-       $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config DROP cache_path";
-       $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config DROP cache_tested";
+       ADD_SQL("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE `what`='config_cache' OR `what`='cache_stats' LIMIT 2");
+
+       // Unregister all filters
+       UNREGISTER_FILTER('extension_update', 'CACHE_DESTROY_ON_EXT_CHANGE', true, $dry_run);
+       UNREGISTER_FILTER('post_extension_installed', 'CACHE_DESTROY_ON_EXT_CHANGE', true, $dry_run);
+       UNREGISTER_FILTER('post_extension_installed', 'CACHE_PURGE_ADMIN_MENU', true, $dry_run);
+       UNREGISTER_FILTER('post_extension_run_sql', 'CACHE_DESTROY_ON_EXT_CHANGE', true, $dry_run);
+       UNREGISTER_FILTER('post_extension_run_sql', 'CACHE_PURGE_ADMIN_MENU', true, $dry_run);
+       UNREGISTER_FILTER('post_admin_added', 'CACHE_DESTROY_ON_ADMIN_CHANGE', true, $dry_run);
+       UNREGISTER_FILTER('post_admin_edited', 'CACHE_DESTROY_ON_ADMIN_CHANGE', true, $dry_run);
+       UNREGISTER_FILTER('post_admin_deleted', 'CACHE_DESTROY_ON_ADMIN_CHANGE', true, $dry_run);
+       UNREGISTER_FILTER('post_admin_reset_pass', 'CACHE_DESTROY_ON_ADMIN_CHANGE', true, $dry_run);
+       UNREGISTER_FILTER('extension_remove', 'CACHE_DESTROY_ALL', true, $dry_run);
        break;
 
 case "activate": // Do stuff when admin activates this extension
        // SQL commands to run
-       $SQLs[] = "";
+       ADD_SQL("");
        break;
 
 case "deactivate": // Do stuff when admin deactivates this extension
        // SQL commands to run
-       $SQLs[] = "";
+       ADD_SQL("");
        break;
 
 case "update": // Update an extension
@@ -81,144 +86,176 @@ case "update": // Update an extension
        {
        case "0.0.1": // SQL queries for v0.0.1
                // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Es wurde die Zeitmarke der Cache-Datei extensions.cache mit berücksichtigt. Dies hatte die Folge, dass wenn bei einem Gast die Datei aktualisiert wurde, nur aktivierte und nicht die deaktivierten mit geladen wurden. Folglich fiehlen einfach ein paar Erweiterungen aus.";
+               EXT_SET_UPDATE_NOTES("Es wurde die Zeitmarke der Cache-Datei extensions.cache mit berücksichtigt. Dies hatte die Folge, dass wenn bei einem Gast die Datei aktualisiert wurde, nur aktivierte und nicht die deaktivierten mit geladen wurden. Folglich fiehlen einfach ein paar Erweiterungen aus.");
                break;
 
        case "0.0.2": // SQL queries for v0.0.2
                // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Fehler beseitigt, wenn error_reporting=E_ALL gesetzt ist.";
+               EXT_SET_UPDATE_NOTES("Fehler beseitigt, wenn error_reporting=E_ALL gesetzt ist.");
                break;
 
        case "0.0.3": // SQL queries for v0.0.3
                // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Cache-Update repariert.";
+               EXT_SET_UPDATE_NOTES("Cache-Update repariert.");
                break;
 
        case "0.0.4": // SQL queries for v0.0.4
-               // Update notes (these will be set as task text!)
-               if (EXT_IS_ACTIVE("cache"))
-               {
+               // Is the cache extension itself there?
+               if (EXT_IS_ACTIVE("cache")) {
                        // Check for cache when extension is already installed
-                       if ($cacheInstance->cache_file("extensions", true)) $cacheInstance->cache_destroy();
-               }
-               $UPDATE_NOTES = "Spalte "keep_active" ist hinzugefügt. Cache wurde reinitialisiert.";
+                       if ($GLOBALS['cache_instance']->loadCacheFile("extensions", true)) $GLOBALS['cache_instance']->destroyCacheFile();
+               } // END - if
+
+               // Update notes (these will be set as task text!)
+               EXT_SET_UPDATE_NOTES("Spalte "keep_active" ist hinzugefügt. Cache wurde reinitialisiert.");
                break;
 
        case "0.0.5": // SQL queries for v0.0.5
                // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Registrierung der Cache-Erweiterung repariert";
+               EXT_SET_UPDATE_NOTES("Registrierung der Cache-Erweiterung repariert");
                break;
 
        case "0.0.6": // SQL queries for v0.0.6
                // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Validierung der Cache-Datei admins.cache integriert.";
+               EXT_SET_UPDATE_NOTES("Validierung der Cache-Datei admins.cache integriert.");
                break;
 
        case "0.0.7": // SQL queries for v0.0.7
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD db_hits bigint(20) not null default '0'";
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD cache_hits bigint(20) not null default '0'";
-               $SQLs[] = "INSERT INTO "._MYSQL_PREFIX."_admin_menu (action, what, title, descr, sort) VALUES ('stats', 'cache_stats', 'DB-Cache', 'Auf Cache und gesamte Datenbank registrierte Anfragen anzeigen.', 4)";
+               ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD db_hits BIGINT(20) UNSIGNED NOT NULL DEFAULT 0");
+               ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_hits BIGINT(20) UNSIGNED NOT NULL DEFAULT 0");
+               ADD_SQL("INSERT INTO `{!_MYSQL_PREFIX!}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('stats','cache_stats','DB-Cache','Auf Cache und gesamte Datenbank registrierte Anfragen anzeigen.', 4)");
 
                // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Hits auf den Cache werden gezählt.";
+               EXT_SET_UPDATE_NOTES("Hits auf den Cache werden gezählt.");
                break;
 
        case "0.0.8": // SQL queries for v0.0.8
                // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Das Umschreiben der Cache-Daten hat eine Fehlermeldung <STRONG>Falsches Passwort!</STRONG> im Admin-Bereich verursacht.";
+               EXT_SET_UPDATE_NOTES("Das Umschreiben der Cache-Daten hat eine Fehlermeldung <strong>Falsches Passwort!</strong> im Admin-Bereich verursacht.");
                break;
 
        case "0.0.9": // SQL queries for v0.0.9
                // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Interne Datenfeld-Management korregiert und Cache-Statistiken korregiert.";
+               EXT_SET_UPDATE_NOTES("Interne Datenfeld-Management korregiert und Cache-Statistiken korregiert.");
                break;
 
        case "0.1.0": // SQL queries for v0.2.1
                // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Problem mit fehlender admins-Erweiterung beseitigt.";
+               EXT_SET_UPDATE_NOTES("Problem mit fehlender admins-Erweiterung beseitigt.");
                break;
 
        case "0.1.1": // SQL queries for v0.1.1
                // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Fehler <STRONG>Division durch 0</STRONG> repariert in den DB-Cache Statistiken.";
+               EXT_SET_UPDATE_NOTES("Fehler <strong>Division durch 0</strong> repariert in den DB-Cache Statistiken.");
                break;
 
        case "0.1.2": // SQL queries for v0.1.2
                // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Die Tabelen <STRONG>"._MYSQL_PREFIX."_config</STRONG>, <STRONG>"._MYSQL_PREFIX."_refsystem</STRONG>, <STRONG>"._MYSQL_PREFIX."_refdepths</STRONG> und <STRONG>"._MYSQL_PREFIX."_mod_reg</STRONG> werden nun auch ausgelagert.";
+               EXT_SET_UPDATE_NOTES("Die Tabelen <strong>{!_MYSQL_PREFIX!}_config</strong>, <strong>{!_MYSQL_PREFIX!}_refsystem</strong>, <strong>{!_MYSQL_PREFIX!}_refdepths</strong> und <strong>{!_MYSQL_PREFIX!}_mod_reg</strong> werden nun auch ausgelagert.");
                break;
 
        case "0.1.3": // SQL queries for v0.1.3
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD cache_admins enum('Y', 'N') not null default 'Y'";
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD cache_acls enum('Y', 'N') not null default 'Y'";
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD cache_exts enum('Y', 'N') not null default 'Y'";
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD cache_config enum('Y', 'N') not null default 'Y'";
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD cache_modreg enum('Y', 'N') not null default 'Y'";
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD cache_refdepth enum('Y', 'N') not null default 'Y'";
-               $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD cache_refsys enum('Y', 'N') not null default 'Y'";
+               ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_admins ENUM('Y','N') NOT NULL DEFAULT 'Y'");
+               ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_acls ENUM('Y','N') NOT NULL DEFAULT 'Y'");
+               ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_exts ENUM('Y','N') NOT NULL DEFAULT 'Y'");
+               ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_config ENUM('Y','N') NOT NULL DEFAULT 'Y'");
+               ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_modreg ENUM('Y','N') NOT NULL DEFAULT 'Y'");
+               ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_refdepth ENUM('Y','N') NOT NULL DEFAULT 'Y'");
+               ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_refsys ENUM('Y','N') NOT NULL DEFAULT 'Y'");
 
                // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Alle cache-baren Tabellen sind nun einzelnt ein- bzw. ausschaltbar. Falls die eine oder andere ausgelagerte Tabelle also Fehler verursachen sollte, so k&ouml;nnen Sie diese hier abschalten. Beachten Sie aber bitte, dass dann mehr Abfragen an die Datenbank gestellt wird und dies bedeutend mehr Zeit braucht, als nur die Daten aus einem Datenfeld zu laden, das sich im Speicher aufh&auml;lt.";
+               EXT_SET_UPDATE_NOTES("Alle cache-baren Tabellen sind nun einzelnt ein- bzw. ausschaltbar. Falls die eine oder andere ausgelagerte Tabelle also Fehler verursachen sollte, so k&ouml;nnen Sie diese hier abschalten. Beachten Sie aber bitte, dass dann mehr Abfragen an die Datenbank gestellt wird und dies bedeutend mehr Zeit braucht, als nur die Daten aus einem Datenfeld zu laden, das sich im Speicher aufh&auml;lt.");
                break;
 
        case "0.1.4": // SQL queries for v0.1.4
                // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Fehler <STRONG>Division durch 0</STRONG> repariert in <STRONG>inc/load_cache.php</STRONG>.";
+               EXT_SET_UPDATE_NOTES("Fehler <strong>Division durch 0</strong> repariert in <strong>inc/load_cache.php</strong>.");
                break;
 
        case "0.1.5": // SQL queries for v0.1.5
                // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Weitere Fehler im System beseitigt.";
+               EXT_SET_UPDATE_NOTES("Weitere Fehler im System beseitigt.");
                break;
 
        case "0.1.6": // SQL queries for v0.1.6
                // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "Probleme w&auuml;hrend des Installationsvorganges beseitigt.";
+               EXT_SET_UPDATE_NOTES("Probleme w&auml;hrend des Installationsvorganges beseitigt.");
                break;
 
        case "0.1.7": // SQL queries for v0.1.7
                // Update notes (these will be set as task text!)
-               $UPDATE_NOTES = "CSS-Klassenname gefixt in Templates.";
+               EXT_SET_UPDATE_NOTES("CSS-Klassenname gefixt in Templates.");
+               break;
+
+       case "0.1.8": // SQL queries for v0.1.8
+               ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_themes ENUM('Y','N') NOT NULL DEFAULT 'Y'");
+
+               // Update notes (these will be set as task text!)
+               EXT_SET_UPDATE_NOTES("Daten von installierten Themes werden nun gecacht.");
+               break;
+
+       case "0.1.9": // SQL queries for v0.1.9
+               ADD_SQL("ALTER TABLE `{!_MYSQL_PREFIX!}_config` ADD cache_admin_menu ENUM('Y','N') NOT NULL DEFAULT 'N'");
+
+               // Update notes (these will be set as task text!)
+               EXT_SET_UPDATE_NOTES("Administratormen&uuml; experimentell gecacht.");
+               break;
+
+       case "0.2.0": // SQL queries for v0.2.0
+               // This update depends on sql_patches
+               EXT_SET_UPDATE_DEPENDS("sql_patches");
+
+               // Update notes (these will be set as task text!)
+               EXT_SET_UPDATE_NOTES("Die Erweiterung h&auml;ngt nun von der <strong>sql_patches</strong> ab.");
+               break;
+
+       case "0.2.1": // SQL queries for v0.2.1
+               // Register the new filter
+               REGISTER_FILTER('extension_update', 'CACHE_DESTROY_ON_EXT_CHANGE', false, true, $dry_run);
+               REGISTER_FILTER('post_extension_installed', 'CACHE_DESTROY_ON_EXT_CHANGE', false, true, $dry_run);
+               REGISTER_FILTER('post_extension_run_sql', 'CACHE_DESTROY_ON_EXT_CHANGE', false, true, $dry_run);
+               REGISTER_FILTER('post_admin_added', 'CACHE_DESTROY_ON_ADMIN_CHANGE', false, true, $dry_run);
+               REGISTER_FILTER('post_admin_edited', 'CACHE_DESTROY_ON_ADMIN_CHANGE', false, true, $dry_run);
+               REGISTER_FILTER('post_admin_deleted', 'CACHE_DESTROY_ON_ADMIN_CHANGE', false, true, $dry_run);
+               REGISTER_FILTER('post_admin_reset_pass', 'CACHE_DESTROY_ON_ADMIN_CHANGE', false, true, $dry_run);
+               REGISTER_FILTER('extension_remove', 'CACHE_DESTROY_ALL', false, true, $dry_run);
+
+               // Update notes (these will be set as task text!)
+               EXT_SET_UPDATE_NOTES("Filter f&uuml;r Erweiterungsmanagement hinzugef&uuml;gt.");
+               break;
+
+       case "0.2.2": // SQL queries for v0.2.2
+               // Register the new filter
+               REGISTER_FILTER('post_extension_installed', 'CACHE_PURGE_ADMIN_MENU', false, true, $dry_run);
+               REGISTER_FILTER('post_extension_run_sql', 'CACHE_PURGE_ADMIN_MENU', false, true, $dry_run);
+
+               // Update notes (these will be set as task text!)
+               EXT_SET_UPDATE_NOTES("Weitere Filter hinzugef&uuml;gt.");
                break;
        }
        break;
 
-default: // Do stuff when extension is loaded
-       $dummy = LOAD_CONFIG();
-
-       // Load config and destroy dummy array
-       $_CONFIG['cache_update']   = $dummy['cache_update'];   // Last time the cache files are been re-created
-       $_CONFIG['cache_path']     = $dummy['cache_path'];     // Relative path for the cache files to 'inc/'
-       $_CONFIG['cache_tested']   = $dummy['cache_tested'];   // Says if cache path is tested or not
-       $_CONFIG['db_hits']        = $dummy['db_hits'];        // Counted hits on the database (all!)
-       $_CONFIG['cache_hits']     = $dummy['cache_hits'];     // Counted hits on the cache arrays in memory
-       $_CONFIG['cache_admins']   = $dummy['cache_admins'];   // Is the table '_admins' cacheable?
-       $_CONFIG['cache_acls']     = $dummy['cache_acls'];     // Is the table '_admins_acls' cacheable?
-       $_CONFIG['cache_exts']     = $dummy['cache_exts'];     // Is the table '_extensions' cacheable?
-       $_CONFIG['cache_config']   = $dummy['cache_config'];   // Is the table '_config' cacheable?
-       $_CONFIG['cache_modreg']   = $dummy['cache_modreg'];   // Is the table '_mod_reg' cacheable?
-       $_CONFIG['cache_refdepth'] = $dummy['cache_refdepth']; // Is the table '_refdepths' cacheable?
-       $_CONFIG['cache_refsys']   = $dummy['cache_refsys'];   // Is the table '_refsystem' cacheable?
-       unset($dummy);
+case "modify": // When the extension got modified
+       break;
+
+case "test": // For testing purposes. For details see file inc/modules/admin/what-extensions.php, arround line 305.
+       break;
 
+default: // Do stuff when extension is loaded
        // Create instance on class
-       if ($cacheMode != "init")
-       {
+       if ($GLOBALS['cache_mode'] != "init") {
                // Initialize cache system only when it's needed
-               $cacheInstance = new mxchange_cache($_CONFIG['cache_update'], PATH."inc/".$_CONFIG['cache_path'], $_CONFIG['cache_tested']);
-               if ($cacheInstance->ret != "done")
-               {
+               $GLOBALS['cache_instance'] = new CacheSystem(getConfig('cache_update'), "inc/".getConfig('cache_path'), getConfig('cache_tested'));
+               if ($GLOBALS['cache_instance']->getStatus() != "done") {
                        // Failed to initialize cache sustem
-                       ADD_FATAL(__FILE__."(".__LINE__."): ".CACHE_CANNOT_INITIALIZE);
-               }
-       }
+                       addFatalMessage(__FILE__, __LINE__, "(<font color=\"#0000aa\">".__LINE__."</font>): ".getMessage('CACHE_CANNOT_INITIALIZE'));
+               } // END - if
+       } // END - if
        break;
 }
-// Language file prefix
-$EXT_LANG_PREFIX = "cache";
 
-// Extension is always active?
-$EXT_ALWAYS_ACTIVE = 'N';
+// Keep this extension always active!
+EXT_SET_ALWAYS_ACTIVE("Y");
 
 //
 ?>