]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/cache_functions.php
Reset rewritten, SQL fixed, zeros are now numeric
[mailer.git] / inc / libs / cache_functions.php
index 2e42b1dd9537a8e8b94efbeb0cd33422213e0659..1394c129b3e4ddd1c81da5cb87086fc49ab5be9e 100644 (file)
@@ -57,35 +57,27 @@ class mxchange_cache
                $this->cache_path=$path;
 
                // Check if path exists
-               if ((file_exists($path)) && (is_dir($path)) && (!$tested))
-               {
+               if ((is_dir($path)) && (!$tested)) {
                        // Check if we can create a file inside the path
                        @touch($path."dummy.tmp", 'w');
-                       if (file_exists($path."dummy.tmp"))
-                       {
+                       if (FILE_READABLE($path."dummy.tmp")) {
                                // Yes, we can do. So let's remove it
-                               unlink($path."dummy.tmp");
+                               @unlink($path."dummy.tmp");
 
                                // Is there a .htaccess file?
-                               if (file_exists($path.".htaccess"))
-                               {
+                               if (FILE_READABLE($path.".htaccess")) {
                                        // Update database that we have tested it
-                                       $result = SQL_QUERY("UPDATE "._MYSQL_PREFIX."_config SET cache_tested='1' WHERE config=0 LIMIT 1", __FILE__, __LINE__);
-                                       $this->ret="done";
+                                       UPDATE_CONFIG("cache_tested", 1);
 
                                        // All done!
                                        return "done";
-                               }
-                               else
-                               {
+                               } else {
                                        // Stop! Set a .htaccess file first
                                        $this->ret="htaccess";
                                        return "htaccess";
                                }
                        }
-               }
-               elseif ($tested)
-               {
+               } elseif ($tested) {
                        // System already tested
                        $this->ret="done";
                        return "done";
@@ -96,8 +88,7 @@ class mxchange_cache
                return "failed";
        }
 
-       function cache_file($file, $ignore_ctime=false)
-       {
+       function cache_file($file, $ignore_ctime=false) {
                global $INC;
                // Construct FQFN (full qualified file name)
                $inc = $this->cache_path.$file.".cache";
@@ -106,37 +97,33 @@ class mxchange_cache
                $this->cache_inc = $inc;
 
                // Check if file exists
-               $status = (file_exists($inc) && (is_readable($inc)) && (is_writeable($inc)));
-               if ($status)
-               {
+               $status = (FILE_READABLE($inc) && (is_writeable($inc)));
+               if ($status) {
                        // Yes, it does. So let's get it's last changed date/time
                        $ctime = filectime($inc);
-               }
-               else
-               {
+               } else {
                        // No, it doesn't. Zero date/time
-                       $ctime = "0";
+                       $ctime = 0;
                }
 
                // Remember change date/time in class
                $this->cache_ctime = $ctime;
 
                // Is the cache file outdated?
-               if (((time() - $ctime) >= $this->update_interval) && (!$ignore_ctime))
-               {
+               if (((time() - $ctime) >= $this->update_interval) && (!$ignore_ctime)) {
                        // Ok, we need an update!
                        $status = false;
                }
+
+               // Return status
                return $status;
        }
 
-       function cache_init($array)
-       {
+       function cache_init($array) {
                // This will destory an existing cache file!
-               if ($this->ret == "done")
-               {
+               if ($this->ret == "done") {
                        // Create file
-                       if (file_exists($this->cache_inc)) @chmod($this->cache_inc, 0666);
+                       if (FILE_READABLE($this->cache_inc)) @chmod($this->cache_inc, 0666);
                        $fp = @fopen($this->cache_inc, 'w') or mxchange_die("Cannot write to cache ".$this->cache_inc." !");
 
                        // Begin of cache file
@@ -144,18 +131,31 @@ class mxchange_cache
 
                        // Remember file pointer
                        $this->cache_pointer = $fp;
-               }
-               else
-               {
+               } else {
                        // Cannot create file
                        ADD_FATAL(__FILE__."(".__LINE__."): ".CACHE_PROBLEMS_DETECTED);
                }
        }
 
-       function add_row($data) {
+       function add_row ($data) {
+               global $cacheArray;
+
                if (is_resource($this->cache_pointer)) {
                        // Write every array element to cache file
-                       foreach ($data as $k=>$v) {
+                       foreach ($data as $k => $v) {
+                               // Write global cache array for immediate access
+                               if ((substr($k, 0, 4) == "ext_") && (isset($data['ext_name'])) && (isset($data['ext_id']))) {
+                                       if ($k != "ext_name") {
+                                               $cacheArray['extensions'][$k][$data['ext_name']] = $v;
+                                       } else {
+                                               $cacheArray['extensions'][$k][$data['ext_id']] = $v;
+                                       }
+                                       if (($k == "ext_keep") && ($v == "Y")) {
+                                               $cacheArray['active_extensions'][$data['ext_name']] = $v;
+                                       } // END - if
+                               } // END - if
+
+                               // Write cache line to file
                                @fwrite($this->cache_pointer, "\$data['".$k."'][] = \"".$v."\";\n");
                        }
                } else {
@@ -174,7 +174,7 @@ class mxchange_cache
                        @fclose($this->cache_pointer);
 
                        // Set rights
-                       if (file_exists($this->cache_inc)) @chmod($this->cache_inc, 0666);
+                       if (FILE_READABLE($this->cache_inc)) @chmod($this->cache_inc, 0666);
 
                        // Remove pointer
                        unset($this->cache_pointer);
@@ -188,8 +188,7 @@ class mxchange_cache
 
        function cache_load()
        {
-               if ((file_exists($this->cache_inc)) && (is_readable($this->cache_inc)))
-               {
+               if (FILE_READABLE($this->cache_inc)) {
                        // Prepare temporary array
                        $data = array();
 
@@ -215,11 +214,11 @@ class mxchange_cache
 
        function cache_destroy()
        {
-               if (file_exists($this->cache_inc))
+               if (FILE_READABLE($this->cache_inc))
                {
                        // Remove cache file from system
                        @unlink($this->cache_inc);
-                       if (!file_exists($this->cache_inc))
+                       if (!FILE_READABLE($this->cache_inc))
                        {
                                // Close cache automatically (we don't need it anymore!)
                                $this->cache_close();
@@ -240,7 +239,7 @@ class mxchange_cache
        function cache_remove($search, $data, $array)
        {
                global $ARRAY;
-               if ((file_exists($this->cache_inc)) && (is_writeable($this->cache_inc)))
+               if ((FILE_READABLE($this->cache_inc)) && (is_writeable($this->cache_inc)))
                {
                        // Load cache into dummy array
                        $dummy = $this->cache_load();
@@ -259,22 +258,22 @@ class mxchange_cache
                                // Flush array to cache file
                                $fp = fopen($this->cache_inc, 'w');
                                fwrite($fp, "\$ARRAY = \"".$ARRAY."\";\n");
-                               foreach ($dummy as $k=>$v)
+                               foreach ($dummy as $k => $v)
                                {
                                        if (is_array($v))
                                        {
                                                // Multi line(s) found
                                                $LINE = "";
-                                               foreach($v as $k2=>$v2)
+                                               foreach($v as $k2 => $v2)
                                                {
                                                        // Put every array element in a row...
-                                                       $LINE .= "\$cacheInstance['".$k."'][] = \"".$v2."\";\n";
+                                                       $LINE .= "\$data['".$k."'][] = \"".$v2."\";\n";
                                                }
                                        }
                                        else
                                        {
                                                // Single line found
-                                               $LINE = "\$cacheInstance['".$k."'] = \"".$v."\";\n";
+                                               $LINE = "\$data['".$k."'] = \"".$v."\";\n";
                                        }
 
                                        // Write line(s)
@@ -295,7 +294,7 @@ class mxchange_cache
        function cache_replace($search, $replace, $search_key, $array)
        {
                global $ARRAY;
-               if ((file_exists($this->cache_inc)) && (is_writeable($this->cache_inc)))
+               if ((FILE_READABLE($this->cache_inc)) && (is_writeable($this->cache_inc)))
                {
                        // Load cache into dummy array
                        $dummy = $this->cache_load();
@@ -309,7 +308,7 @@ class mxchange_cache
                                {
                                        $key = $search_key;
                                        // Key (hopefully) found?
-                                       foreach ($dummy as $a=>$v)
+                                       foreach ($dummy as $a => $v)
                                        {
                                                // So we can update all entries
                                                if ($a == $search)
@@ -322,22 +321,22 @@ class mxchange_cache
                                        // Flush array to cache file
                                        $fp = fopen($this->cache_inc, 'w');
                                        fwrite($fp, "\$dummy = \"".$ARRAY."\";\n");
-                                       foreach ($dummy as $k=>$v)
+                                       foreach ($dummy as $k => $v)
                                        {
                                                if (is_array($v))
                                                {
                                                        // Multi line(s) found
                                                        $LINE = "";
-                                                       foreach($v as $k2=>$v2)
+                                                       foreach($v as $k2 => $v2)
                                                        {
                                                                // Put every array element in a row...
-                                                               $LINE .= "\$cacheInstance['".$k."'][] = \"".$v2."\";\n";
+                                                               $LINE .= "\$data['".$k."'][] = \"".$v2."\";\n";
                                                        }
                                                }
                                                else
                                                {
                                                        // Single line found
-                                                       $LINE = "\$cacheInstance['".$k."'] = \"".$v."\";\n";
+                                                       $LINE = "\$data['".$k."'] = \"".$v."\";\n";
                                                }
 
                                                // Write line(s)