]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/cache_functions.php
Bug fixed in referal system:
[mailer.git] / inc / libs / cache_functions.php
index f3496a5ccb4f152aed76f2fac9e2d2c510583ad8..a3b1d0a15e77831db0bf6c1d430869a2d2f426d6 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);
 }
+
 // Caching class
 class mxchange_cache
 {
@@ -52,11 +52,14 @@ class mxchange_cache
 
        // Constructor
        function mxchange_cache($interval, $path, $tested) {
+               // Failed is the default
+               $this->ret = "failed";
+
                // Remember interval in class
-               $this->update_interval=$interval;
+               $this->update_interval = $interval;
 
                // Remeber path
-               $this->cache_path=$path;
+               $this->cache_path = $path;
 
                // Check if path exists
                if ((is_dir($path)) && (!$tested)) {
@@ -72,22 +75,16 @@ class mxchange_cache
                                        UPDATE_CONFIG("cache_tested", 1);
 
                                        // All done!
-                                       return "done";
+                                       $this->ret = "done";
                                } else {
                                        // Stop! Set a .htaccess file first
-                                       $this->ret="htaccess";
-                                       return "htaccess";
+                                       $this->ret = "htaccess";
                                }
                        }
                } elseif ($tested) {
                        // System already tested
-                       $this->ret="done";
-                       return "done";
+                       $this->ret = "done";
                }
-
-               // Something goes wrong here!
-               $this->ret="failed";
-               return "failed";
        }
 
        function cache_file($file, $ignore_ctime=false) {
@@ -135,7 +132,7 @@ class mxchange_cache
                        $this->cache_pointer = $fp;
                } else {
                        // Cannot create file
-                       ADD_FATAL(__FILE__."(".__LINE__."): ".CACHE_PROBLEMS_DETECTED);
+                       ADD_FATAL(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_PROBLEMS_DETECTED);
                }
        }
 
@@ -155,14 +152,17 @@ class mxchange_cache
                                        if (($k == "ext_keep") && ($v == "Y")) {
                                                $cacheArray['active_extensions'][$data['ext_name']] = $v;
                                        } // END - if
-                               } // END - if
+                               } elseif (is_array($v)) {
+                                       // Serialize and BASE64-encode the array
+                                       $v = base64_encode(serialize($v));
+                               }
 
                                // Write cache line to file
                                @fwrite($this->cache_pointer, $this->add_raw_row($k, $v));
                        }
                } else {
                        // Cannot create file
-                       ADD_FATAL(__FILE__."(".__LINE__."): ".CACHE_PROBLEMS_DETECTED);
+                       ADD_FATAL(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_PROBLEMS_DETECTED);
                }
        }
 
@@ -184,7 +184,7 @@ class mxchange_cache
                else
                {
                        // Cannot create file
-                       ADD_FATAL(__FILE__."(".__LINE__."): ".CACHE_PROBLEMS_DETECTED);
+                       ADD_FATAL(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_PROBLEMS_DETECTED);
                }
        }
 
@@ -193,6 +193,7 @@ class mxchange_cache
                if (FILE_READABLE($this->cache_inc)) {
                        // Prepare temporary array
                        $data = array();
+                       $cache_version = null;
 
                        // Load cache file
                        $this->cache_data = implode("", file($this->cache_inc));
@@ -205,7 +206,7 @@ class mxchange_cache
                                $this->cache_data = $data;
 
                                // Cache version found?
-                               if (isset($cache_version)) {
+                               if ((isset($cache_version)) && (is_array($cache_version))) {
                                        // Remember it as well...
                                        $this->cache_version = $cache_version;
                                } // END - if
@@ -218,31 +219,26 @@ class mxchange_cache
                        }
                } else {
                        // Cache file not found or not readable
-                       ADD_FATAL(__FILE__."(".__LINE__."): ".CACHE_CANNOT_LOAD_1.$this->cache_inc.CACHE_CANNOT_LOAD_2);
+                       ADD_FATAL(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_CANNOT_LOAD_1.$this->cache_inc.CACHE_CANNOT_LOAD_2);
                }
        }
 
-       function cache_destroy()
-       {
-               if (FILE_READABLE($this->cache_inc))
-               {
+       // Destroy an existing cache file
+       function cache_destroy() {
+               // Is the cache file there?
+               if (FILE_READABLE($this->cache_inc)) {
                        // Remove cache file from system
                        @unlink($this->cache_inc);
-                       if (!FILE_READABLE($this->cache_inc))
-                       {
+                       if (!FILE_READABLE($this->cache_inc)) {
                                // Close cache automatically (we don't need it anymore!)
                                $this->cache_close();
-                       }
-                       else
-                       {
+                       } else {
                                // Not removed!
-                               ADD_FATAL(__FILE__."(".__LINE__."): ".CACHE_CANNOT_UNLINK_1.$this->cache_inc.CACHE_CANNOT_UNLINK_2);
+                               ADD_FATAL(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_CANNOT_UNLINK_1.$this->cache_inc.CACHE_CANNOT_UNLINK_2);
                        }
-               }
-               else
-               {
+               } else {
                        // Does not exist!
-                       ADD_FATAL(__FILE__."(".__LINE__."): ".CACHE_CANNOT_UNLINK_1.$this->cache_inc.CACHE_CANNOT_UNLINK_2);
+                       ADD_FATAL(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_CANNOT_UNLINK_1.$this->cache_inc.CACHE_CANNOT_UNLINK_2);
                }
        }
 
@@ -287,7 +283,7 @@ class mxchange_cache
                        }
                } else {
                        // Cannot write to cache!
-                       ADD_FATAL(__FILE__."(".__LINE__."): ".CACHE_PROBLEMS_DETECTED);
+                       ADD_FATAL(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_PROBLEMS_DETECTED);
                }
        }
 
@@ -340,7 +336,7 @@ class mxchange_cache
                        }
                } else {
                        // Cannot write to cache!
-                       ADD_FATAL(__FILE__."(".__LINE__."): ".CACHE_PROBLEMS_DETECTED);
+                       ADD_FATAL(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_PROBLEMS_DETECTED);
                }
        }
 
@@ -351,10 +347,10 @@ class mxchange_cache
                        $ext_ver = GET_EXT_VERSION($ext_name);
 
                        // Write cache line to file
-                       @fwrite($this->cache_pointer, "\$cache_version = \"".$ext_ver."\";\n");
+                       @fwrite($this->cache_pointer, "\$cache_version['".$ext_name."'] = \"".$ext_ver."\";\n");
                } else {
                        // Cannot create file
-                       ADD_FATAL(__FILE__."(".__LINE__."): ".CACHE_PROBLEMS_DETECTED);
+                       ADD_FATAL(__FILE__."(<font color=\"#0000aa\">".__LINE__."</font>): ".CACHE_PROBLEMS_DETECTED);
                }
        }
 
@@ -367,7 +363,7 @@ class mxchange_cache
 
                //* DEBUG: */ echo __METHOD__.": ext_name={$ext_name},ext_ver={$ext_ver},cache_version={$this->cache_version}<br />\n";
                // Compare both
-               return ($ext_ver == $this->cache_version);
+               return ((isset($this->cache_version[$ext_name])) && ($this->cache_version[$ext_name] == $ext_ver));
        }
 
        function add_raw_row ($key, $value) {
@@ -375,7 +371,7 @@ class mxchange_cache
                $line = "";
 
                // String or non-string? ;-)
-               if (is_string($value)) {
+               if ((is_string($value)) || (is_null($value))) {
                        // String...
                        $line = "\$data['".$key."'][] = \"".$value."\";\n";
                } else {
@@ -386,6 +382,10 @@ class mxchange_cache
                // Return line
                return $line;
        }
+
+       function getStatus () {
+               return $this->ret;
+       }
 }
 //
 ?>