]> git.mxchange.org Git - mailer.git/blobdiff - inc/functions.php
More bugs resolved, thanks to profi-concept
[mailer.git] / inc / functions.php
index 6a87f258cce888a8cdc0a1836a5d528ac22922d8..b326dab09832063588ebb76fd1a328c91088a55e 100644 (file)
@@ -3013,6 +3013,23 @@ function READ_FILE ($FQFN, $sqlPrepare = false) {
        return $content;
 }
 
+// Writes content to a file
+function WRITE_FILE ($FQFN, $content) {
+       // Is the function there?
+       if (function_exists('file_put_contents')) {
+               // Write it directly
+               file_put_contents($FQFN, $content);
+       } else {
+               // Write it with fopen
+               $fp = fopen($FQFN, 'w') or mxchange_die("Cannot write file ".basename($FQFN)."!");
+               fwrite($fp, $content);
+               fclose($fp);
+
+               // Set CHMOD rights
+               chmod($FQFN, 0644);
+       }
+}
+
 // Generates an error code from given account status
 function GEN_ERROR_CODE_FROM_ACCOUNT_STATUS ($status) {
        // Default error code if unknown account status
@@ -3043,6 +3060,48 @@ function clearOutputBuffer () {
        } // END - if
 }
 
+// "Getter" for revision/version data
+function getActualVersion ($type = 0) {
+       // By default nothing is new... ;-)
+       $new = false;
+
+       // FQFN of revision file
+       $FQFN = sprintf("%sinc/cache/.revision", PATH);
+
+       // Check for revision file
+       if (!FILE_READABLE($FQFN)) {
+               // Not found, so we need to create it
+               $new = true;
+       } else {
+               // Revision file found
+               $ins_vers = explode("\n", READ_FILE($FQFN));
+
+               // Is the content valid?
+               if ((!is_array($ins_vers)) || (count($ins_vers) <= 0) || (!isset($ins_vers[$type])) || ($ins_vers[0]) == "new") {
+                       // File needs update!
+                       $new = true;
+               } else {
+                       // Revision-File has valid Data and isn't 'new' so return the Rev-Number
+                       return trim($ins_vers[$type]);
+               }
+       }
+
+       if ($new)  {
+               // no Revision-File or has no valid Data so read the Revision from the Server.
+               $version = GET_URL("check-updates3.php");
+
+               // Prepare content
+               $akt_vers[] = trim($version[10]);
+               $akt_vers[] = trim($version[9]);
+               $akt_vers[] = trim($version[8]);
+
+               // Write file
+               WRITE_FILE($FQFN, implode("\n", $akt_vers));
+
+               // Return requested content
+               return trim($akt_vers[$type]);
+       }
+}
 //////////////////////////////////////////////////
 // AUTOMATICALLY RE-GENERATED MISSING FUNCTIONS //
 //////////////////////////////////////////////////