99d4cd47a61c188f82d8f1723be43b0a04af083f
[mailer.git] / inc / extensions / ext-cache.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 10/11/2004 *
4  * ================                             Last change: 10/11/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : ext-cache.php                                    *
8  * -------------------------------------------------------------------- *
9  * Short description : Caching system for SQL tables on hard disc       *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Caching-System zum Auslagern von SQL-Tabellen    *
12  *                     auf der Festplatte des Servers                   *
13  * -------------------------------------------------------------------- *
14  *                                                                      *
15  * -------------------------------------------------------------------- *
16  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
17  * For more information visit: http://www.mxchange.org                  *
18  *                                                                      *
19  * This program is free software; you can redistribute it and/or modify *
20  * it under the terms of the GNU General Public License as published by *
21  * the Free Software Foundation; either version 2 of the License, or    *
22  * (at your option) any later version.                                  *
23  *                                                                      *
24  * This program is distributed in the hope that it will be useful,      *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
27  * GNU General Public License for more details.                         *
28  *                                                                      *
29  * You should have received a copy of the GNU General Public License    *
30  * along with this program; if not, write to the Free Software          *
31  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
32  * MA  02110-1301  USA                                                  *
33  ************************************************************************/
34
35 // Some security stuff...
36 if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])))
37 {
38         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
39         require($INC);
40 }
41
42 // Version number
43 $EXT_VERSION = "0.1.7";
44
45 // Auto-set extension version
46 if (empty($EXT_VER)) $EXT_VER = $EXT_VERSION;
47
48 // Version history array (add more with , "0.1" and so on)
49 $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");
50
51 switch ($EXT_LOAD_MODE)
52 {
53 case "register": // Do stuff when installtion is running (modules.php?module=admin&action=login is called)
54         // SQL commands to run
55         $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD cache_update bigint(20) not null default '3600'";
56         $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD cache_path varchar(255) not null default 'cache/'";
57         $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD cache_tested tinyint(1) not null default '0'";
58         $SQLs[] = "INSERT INTO "._MYSQL_PREFIX."_admin_menu (action, what, title, descr, sort) VALUES ('setup', 'config_cache', 'Cache-Einstellungen', 'Update-Interval des Caches usw. k&ouml;nnen Sie hier &auml;ndern.', 9)";
59         break;
60
61 case "remove": // Do stuff when removing extension
62         // SQL commands to run
63         $SQLs[] = "DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_admin_menu WHERE what='config_cache' OR what='cache_stats' LIMIT 2";
64         $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config DROP cache_update";
65         $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config DROP cache_path";
66         $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config DROP cache_tested";
67         break;
68
69 case "activate": // Do stuff when admin activates this extension
70         // SQL commands to run
71         $SQLs[] = "";
72         break;
73
74 case "deactivate": // Do stuff when admin deactivates this extension
75         // SQL commands to run
76         $SQLs[] = "";
77         break;
78
79 case "update": // Update an extension
80         switch ($EXT_VER)
81         {
82         case "0.0.1": // SQL queries for v0.0.1
83                 // Update notes (these will be set as task text!)
84                 $UPDATE_NOTES = "Es wurde die Zeitmarke der Cache-Datei extensions.cache mit ber&uuml;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.";
85                 break;
86
87         case "0.0.2": // SQL queries for v0.0.2
88                 // Update notes (these will be set as task text!)
89                 $UPDATE_NOTES = "Fehler beseitigt, wenn error_reporting=E_ALL gesetzt ist.";
90                 break;
91
92         case "0.0.3": // SQL queries for v0.0.3
93                 // Update notes (these will be set as task text!)
94                 $UPDATE_NOTES = "Cache-Update repariert.";
95                 break;
96
97         case "0.0.4": // SQL queries for v0.0.4
98                 // Update notes (these will be set as task text!)
99                 if (EXT_IS_ACTIVE("cache"))
100                 {
101                         // Check for cache when extension is already installed
102                         if ($CACHE->cache_file("extensions", true)) $CACHE->cache_destroy();
103                 }
104                 $UPDATE_NOTES = "Spalte &quot;keep_active&quot; ist hinzugef&uuml;gt. Cache wurde reinitialisiert.";
105                 break;
106
107         case "0.0.5": // SQL queries for v0.0.5
108                 // Update notes (these will be set as task text!)
109                 $UPDATE_NOTES = "Registrierung der Cache-Erweiterung repariert";
110                 break;
111
112         case "0.0.6": // SQL queries for v0.0.6
113                 // Update notes (these will be set as task text!)
114                 $UPDATE_NOTES = "Validierung der Cache-Datei admins.cache integriert.";
115                 break;
116
117         case "0.0.7": // SQL queries for v0.0.7
118                 $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD db_hits bigint(20) not null default '0'";
119                 $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD cache_hits bigint(20) not null default '0'";
120                 $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)";
121
122                 // Update notes (these will be set as task text!)
123                 $UPDATE_NOTES = "Hits auf den Cache werden gez&auml;hlt.";
124                 break;
125
126         case "0.0.8": // SQL queries for v0.0.8
127                 // Update notes (these will be set as task text!)
128                 $UPDATE_NOTES = "Das Umschreiben der Cache-Daten hat eine Fehlermeldung <STRONG>Falsches Passwort!</STRONG> im Admin-Bereich verursacht.";
129                 break;
130
131         case "0.0.9": // SQL queries for v0.0.9
132                 // Update notes (these will be set as task text!)
133                 $UPDATE_NOTES = "Interne Datenfeld-Management korregiert und Cache-Statistiken korregiert.";
134                 break;
135
136         case "0.1.0": // SQL queries for v0.2.1
137                 // Update notes (these will be set as task text!)
138                 $UPDATE_NOTES = "Problem mit fehlender admins-Erweiterung beseitigt.";
139                 break;
140
141         case "0.1.1": // SQL queries for v0.1.1
142                 // Update notes (these will be set as task text!)
143                 $UPDATE_NOTES = "Fehler <STRONG>Division durch 0</STRONG> repariert in den DB-Cache Statistiken.";
144                 break;
145
146         case "0.1.2": // SQL queries for v0.1.2
147                 // Update notes (these will be set as task text!)
148                 $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.";
149                 break;
150
151         case "0.1.3": // SQL queries for v0.1.3
152                 $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD cache_admins enum('Y', 'N') not null default 'Y'";
153                 $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD cache_acls enum('Y', 'N') not null default 'Y'";
154                 $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD cache_exts enum('Y', 'N') not null default 'Y'";
155                 $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD cache_config enum('Y', 'N') not null default 'Y'";
156                 $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD cache_modreg enum('Y', 'N') not null default 'Y'";
157                 $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD cache_refdepth enum('Y', 'N') not null default 'Y'";
158                 $SQLs[] = "ALTER TABLE "._MYSQL_PREFIX."_config ADD cache_refsys enum('Y', 'N') not null default 'Y'";
159
160                 // Update notes (these will be set as task text!)
161                 $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.";
162                 break;
163
164         case "0.1.4": // SQL queries for v0.1.4
165                 // Update notes (these will be set as task text!)
166                 $UPDATE_NOTES = "Fehler <STRONG>Division durch 0</STRONG> repariert in <STRONG>inc/load_cache.php</STRONG>.";
167                 break;
168
169         case "0.1.5": // SQL queries for v0.1.5
170                 // Update notes (these will be set as task text!)
171                 $UPDATE_NOTES = "Weitere Fehler im System beseitigt.";
172                 break;
173
174         case "0.1.6": // SQL queries for v0.1.6
175                 // Update notes (these will be set as task text!)
176                 $UPDATE_NOTES = "Probleme w&auuml;hrend des Installationsvorganges beseitigt.";
177                 break;
178
179         case "0.1.7": // SQL queries for v0.1.7
180                 // Update notes (these will be set as task text!)
181                 $UPDATE_NOTES = "CSS-Klassenname gefixt in Templates.";
182                 break;
183         }
184         break;
185
186 default: // Do stuff when extension is loaded
187         $DUMMY = LOAD_CONFIG("0");
188
189         // Load config and destroy dummy array
190         $_CONFIG['cache_update']   = $DUMMY['cache_update'];   // Last time the cache files are been re-created
191         $_CONFIG['cache_path']     = $DUMMY['cache_path'];     // Relative path for the cache files to 'inc/'
192         $_CONFIG['cache_tested']   = $DUMMY['cache_tested'];   // Says if cache path is tested or not
193         $_CONFIG['db_hits']        = $DUMMY['db_hits'];        // Counted hits on the database (all!)
194         $_CONFIG['cache_hits']     = $DUMMY['cache_hits'];     // Counted hits on the cache arrays in memory
195         $_CONFIG['cache_admins']   = $DUMMY['cache_admins'];   // Is the table '_admins' cacheable?
196         $_CONFIG['cache_acls']     = $DUMMY['cache_acls'];     // Is the table '_admins_acls' cacheable?
197         $_CONFIG['cache_exts']     = $DUMMY['cache_exts'];     // Is the table '_extensions' cacheable?
198         $_CONFIG['cache_config']   = $DUMMY['cache_config'];   // Is the table '_config' cacheable?
199         $_CONFIG['cache_modreg']   = $DUMMY['cache_modreg'];   // Is the table '_mod_reg' cacheable?
200         $_CONFIG['cache_refdepth'] = $DUMMY['cache_refdepth']; // Is the table '_refdepths' cacheable?
201         $_CONFIG['cache_refsys']   = $DUMMY['cache_refsys'];   // Is the table '_refsystem' cacheable?
202         unset($DUMMY);
203
204         // Create instance on class
205         if ($CACHE_FILE != "init")
206         {
207                 // Initialize cache system only when it's needed
208                 $CACHE = new mxchange_cache($_CONFIG['cache_update'], PATH."inc/".$_CONFIG['cache_path'], $_CONFIG['cache_tested']);
209                 if ($CACHE->ret != "done")
210                 {
211                         // Failed to initialize cache sustem
212                         ADD_FATAL(__FILE__."(".__LINE__."): ".CACHE_CANNOT_INITIALIZE);
213                 }
214         }
215         break;
216 }
217 // Language file prefix
218 $EXT_LANG_PREFIX = "cache";
219
220 // Extension is always active?
221 $EXT_ALWAYS_ACTIVE = 'N';
222
223 //
224 ?>