X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fwrapper-functions.php;h=3cb81135295da53ba448a3553550f630b3826509;hb=2e97d61e89008db1194cf2b2957036966c946e06;hp=ce8ad1099950f6b4eed1ddf32f921f1c9eac0dce;hpb=6a5589c1a7793b19dbce958053d6fea41eaee533;p=mailer.git diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php index ce8ad10999..3cb8113529 100644 --- a/inc/wrapper-functions.php +++ b/inc/wrapper-functions.php @@ -46,19 +46,19 @@ function readFromFile ($FQFN) { if (!isFileReadable($FQFN)) { // This should not happen reportBug(__FUNCTION__, __LINE__, 'File ' . basename($FQFN) . ' is not readable!'); - } elseif (!isset($GLOBALS['file_content'][$FQFN])) { - // Load the file - if (function_exists('file_get_contents')) { - // Use new function - $GLOBALS['file_content'][$FQFN] = file_get_contents($FQFN); - } else { - // Fall-back to implode-file chain - $GLOBALS['file_content'][$FQFN] = implode('', file($FQFN)); - } } // END - if + // Load the file + if (function_exists('file_get_contents')) { + // Use new function + $fileContent = file_get_contents($FQFN); + } else { + // Fall-back to implode-file chain + $fileContent = implode('', file($FQFN)); + } + // Return the content - return $GLOBALS['file_content'][$FQFN]; + return $fileContent; } // Writes content to a file @@ -66,7 +66,7 @@ function writeToFile ($FQFN, $content, $aquireLock = FALSE) { // Is the file writeable? if ((isFileReadable($FQFN)) && (!is_writeable($FQFN)) && (!changeMode($FQFN, 0644))) { // Not writeable! - logDebugMessage(__FUNCTION__, __LINE__, sprintf("File %s not writeable.", basename($FQFN))); + logDebugMessage(__FUNCTION__, __LINE__, sprintf("File %s not writeable or cannot change CHMOD to 0644.", basename($FQFN))); // Failed! :( return FALSE; @@ -74,7 +74,6 @@ function writeToFile ($FQFN, $content, $aquireLock = FALSE) { // By default all is failed... $GLOBALS['file_readable'][$FQFN] = FALSE; - unset($GLOBALS['file_content'][$FQFN]); $return = FALSE; // Is the function there? @@ -89,7 +88,8 @@ function writeToFile ($FQFN, $content, $aquireLock = FALSE) { } } else { // Write it with fopen - $fp = fopen($FQFN, 'w') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($FQFN) . '!'); + $fp = fopen($FQFN, 'w') + or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($FQFN) . '!'); // Aquire a lock? if ($aquireLock === TRUE) { @@ -108,9 +108,6 @@ function writeToFile ($FQFN, $content, $aquireLock = FALSE) { if ($return !== FALSE) { // Mark it as readable $GLOBALS['file_readable'][$FQFN] = TRUE; - - // Remember content in cache - $GLOBALS['file_content'][$FQFN] = $content; } // END - if // Return status @@ -123,10 +120,7 @@ function clearOutputBuffer () { if (isset($GLOBALS[__FUNCTION__])) { // This function is called twice reportBug(__FUNCTION__, __LINE__, 'Double call of ' . __FUNCTION__ . ' may cause more trouble.'); - } // END - if - - // Trigger an error on failure - if ((ob_get_length() > 0) && (!ob_end_clean())) { + } elseif ((ob_get_length() > 0) && (!ob_end_clean())) { // Failed! reportBug(__FUNCTION__, __LINE__, 'Failed to clean output buffer.'); } // END - if @@ -762,35 +756,35 @@ function redirectToDereferedUrl ($url) { } // Wrapper function for checking if extension is installed and newer or same version -function isExtensionInstalledAndNewer ($ext_name, $version) { +function isExtensionInstalledAndNewer ($ext_name, $ext_ver) { // Is an cache entry found? - if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) { + if (!isset($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])) { // Determine it - $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (getExtensionVersion($ext_name) >= $version)); + $GLOBALS[__FUNCTION__][$ext_name][$ext_ver] = ((isExtensionInstalled($ext_name)) && (version_compare(getExtensionVersion($ext_name), $ext_ver, '>=') === TRUE)); } else { // Cache hits should be incremented twice incrementStatsEntry('cache_hits', 2); } // Return it - //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=>' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version])); - return $GLOBALS[__FUNCTION__][$ext_name][$version]; + //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '=>' . $ext_ver . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])); + return $GLOBALS[__FUNCTION__][$ext_name][$ext_ver]; } // Wrapper function for checking if extension is installed and older than given version -function isExtensionInstalledAndOlder ($ext_name, $version) { +function isExtensionInstalledAndOlder ($ext_name, $ext_ver) { // Is an cache entry found? - if (!isset($GLOBALS[__FUNCTION__][$ext_name][$version])) { + if (!isset($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])) { // Determine it - $GLOBALS[__FUNCTION__][$ext_name][$version] = ((isExtensionInstalled($ext_name)) && (isExtensionOlder($ext_name, $version))); + $GLOBALS[__FUNCTION__][$ext_name][$ext_ver] = ((isExtensionInstalled($ext_name)) && (isExtensionOlder($ext_name, $ext_ver))); } else { // Cache hits should be incremented twice incrementStatsEntry('cache_hits', 2); } // Return it - //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '<' . $version . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$version])); - return $GLOBALS[__FUNCTION__][$ext_name][$version]; + //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . $ext_name . '<' . $ext_ver . ':' . intval($GLOBALS[__FUNCTION__][$ext_name][$ext_ver])); + return $GLOBALS[__FUNCTION__][$ext_name][$ext_ver]; } // Set username