Reset rewritten, SQL fixed, zeros are now numeric
[mailer.git] / inc / libs / cache_functions.php
index 711dc5955401120849bdca078293477bcb5edcff..1394c129b3e4ddd1c81da5cb87086fc49ab5be9e 100644 (file)
@@ -57,16 +57,15 @@ 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");
 
                                // Is there a .htaccess file?
-                               if (file_exists($path.".htaccess")) {
+                               if (FILE_READABLE($path.".htaccess")) {
                                        // Update database that we have tested it
                                        UPDATE_CONFIG("cache_tested", 1);
 
@@ -89,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";
@@ -99,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
@@ -137,9 +131,7 @@ class mxchange_cache
 
                        // Remember file pointer
                        $this->cache_pointer = $fp;
-               }
-               else
-               {
+               } else {
                        // Cannot create file
                        ADD_FATAL(__FILE__."(".__LINE__."): ".CACHE_PROBLEMS_DETECTED);
                }
@@ -182,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);
@@ -196,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();
 
@@ -223,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();
@@ -248,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();
@@ -267,13 +258,13 @@ 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 .= "\$data['".$k."'][] = \"".$v2."\";\n";
@@ -303,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();
@@ -317,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)
@@ -330,13 +321,13 @@ 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 .= "\$data['".$k."'][] = \"".$v2."\";\n";