X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fwrapper-functions.php;h=60fccd2839885a52905aa0d3061e090bb1ade3ec;hb=b6a6d0a2c0a0f274b937eb75c413db8fa9b44f9c;hp=dbc24d16796050d6e84cd70f73d72a078014ead9;hpb=def1c791b52a6b8b5891539387525c3736f3c24c;p=mailer.git diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php index dbc24d1679..60fccd2839 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 @@ -172,7 +166,7 @@ function merge_array ($array1, $array2, $keepIndex = FALSE) { // Maintain index of array2? if ($keepIndex === TRUE) { - // Keep index of array2, array_merge() rewrites $key=2 to $key=0 ! :( + // Keep index of array2, array_merge() rewrites e.g. $key=1 to $key=0, $key=2 to $key=1 ! :( foreach ($array2 as $key => $value) { // Add it $array1[$key] = $value; @@ -214,12 +208,12 @@ function isDirectory ($FQFN) { } // "Getter" for the real remote IP number -function detectRealIpAddress () { +function detectRealIpAddress ($alwaysReal = FALSE) { // Get remote ip from environment $remoteAddr = determineRealRemoteAddress(); // Is removeip installed? - if (isExtensionActive('removeip')) { + if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) { // Then anonymize it $remoteAddr = getAnonymousRemoteAddress($remoteAddr); } // END - if @@ -229,12 +223,12 @@ function detectRealIpAddress () { } // "Getter" for remote IP number -function detectRemoteAddr () { +function detectRemoteAddr ($alwaysReal = FALSE) { // Get remote ip from environment $remoteAddr = determineRealRemoteAddress(TRUE); // Is removeip installed? - if (isExtensionActive('removeip')) { + if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) { // Then anonymize it $remoteAddr = getAnonymousRemoteAddress($remoteAddr); } // END - if @@ -244,12 +238,12 @@ function detectRemoteAddr () { } // "Getter" for remote hostname -function detectRemoteHostname () { +function detectRemoteHostname ($alwaysReal = FALSE) { // Get remote ip from environment $remoteHost = getenv('REMOTE_HOST'); // Is removeip installed? - if (isExtensionActive('removeip')) { + if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) { // Then anonymize it $remoteHost = getAnonymousRemoteHost($remoteHost); } // END - if @@ -274,12 +268,12 @@ function detectUserAgent ($alwaysReal = FALSE) { } // "Getter" for referer -function detectReferer () { +function detectReferer ($alwaysReal = FALSE) { // Get remote ip from environment $referer = getenv('HTTP_REFERER'); // Is removeip installed? - if (isExtensionActive('removeip')) { + if ((isExtensionActive('removeip')) && ($alwaysReal === TRUE)) { // Then anonymize it $referer = getAnonymousReferer($referer); } // END - if @@ -332,7 +326,7 @@ function isInstalling () { // Determine whether we are installing if (!isset($GLOBALS['__mailer_installing'])) { // Check URL (css.php/js.php need this) - $GLOBALS['__mailer_installing'] = isGetRequestElementSet('installing'); + $GLOBALS['__mailer_installing'] = (isGetRequestElementSet('installing') || ((isGetRequestElementSet('level')) && (getRequestElement('level') == 'install'))); } // END - if // Return result @@ -349,9 +343,9 @@ function isInstalled () { // First is config ( ( - isConfigEntrySet('MXCHANGE_INSTALLED') + isConfigEntrySet('MAILER_INSTALLED') ) && ( - getConfig('MXCHANGE_INSTALLED') == 'Y' + getConfig('MAILER_INSTALLED') == 'Y' ) ) ) || ( @@ -449,6 +443,18 @@ function isDebugRegularExpressionEnabled () { return $GLOBALS[__FUNCTION__]; } +// Checks whether debugging of build mails is enabled +function isDebugBuildMailsEnabled () { + // Is cache set? + if (!isset($GLOBALS[__FUNCTION__])) { + // Simply check it + $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_BUILD_MAILS')) && (getConfig('DEBUG_BUILD_MAILS') == 'Y')); + } // END - if + + // Return it + return $GLOBALS[__FUNCTION__]; +} + // Checks whether the cache instance is valid function isCacheInstanceValid () { // Is there cache? @@ -597,7 +603,7 @@ function setWhatFromConfig ($configEntry) { } // Checks whether what is set and optionally aborts on miss -function isWhatSet ($strict = false) { +function isWhatSet ($strict = FALSE) { // Check for it $isset = (isset($GLOBALS['__what']) && (!empty($GLOBALS['__what']))); @@ -632,7 +638,7 @@ function setAction ($newAction) { } // Checks whether action is set and optionally aborts on miss -function isActionSet ($strict = false) { +function isActionSet ($strict = FALSE) { // Check for it $isset = ((isset($GLOBALS['__action'])) && (!empty($GLOBALS['__action']))); @@ -667,8 +673,29 @@ function setModule ($newModule) { $GLOBALS['__module'] = strtolower($newModule); } +// Wrapper to get extra module names +function getExtraModule () { + // Default is 'NULL' + $extra = 'NULL'; + + // Is 'tab/step' set? + if (isPostRequestElementSet('tab')) { + // Use this + $extra = 'tab=' . postRequestElement('tab'); + } elseif (isPostRequestElementSet('step')) { + // Use this + $extra = 'step=' . postRequestElement('step'); + } elseif ((isActionSet()) && (isWhatSet())) { + // Use 'action/what' + $extra = 'action=' . getAction() . ':what=' . getWhat(); + } + + // Return it + return $extra; +} + // Checks whether module is set and optionally aborts on miss -function isModuleSet ($strict = false) { +function isModuleSet ($strict = FALSE) { // Check for it $isset = ((isset($GLOBALS['__module'])) && (!empty($GLOBALS['__module']))); @@ -701,13 +728,13 @@ function getScriptOutputMode () { } // Setter for 'output_mode' value -function setOutputMode ($newOutputMode) { +function setScriptOutputMode ($newOutputMode) { //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'output_mode=' . $newOutputMode); $GLOBALS['__output_mode'] = (int) $newOutputMode; } // Checks whether output_mode is set and optionally aborts on miss -function isOutputModeSet ($strict = false) { +function isOutputModeSet ($strict = FALSE) { // Check for it $isset = (isset($GLOBALS['__output_mode'])); @@ -762,35 +789,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)) && (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]; } // Set username @@ -1170,7 +1197,7 @@ function sendRawRedirect ($url) { $GLOBALS['__output'] = ''; // To make redirects working (no content type), output mode must be raw - setOutputMode(-1); + setScriptOutputMode(-1); // Send helping header setHttpStatus('302 Found'); @@ -1297,7 +1324,7 @@ function isValidUserId ($userid) { // Is there cache? if (!isset($GLOBALS[__FUNCTION__][$userid])) { // Check it out - $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid > 0)); + $GLOBALS[__FUNCTION__][$userid] = ((!is_null($userid)) && (!empty($userid)) && ($userid != 'NULL') && ($userid > 0)); } // END - if // Return cache @@ -1345,7 +1372,7 @@ function getDateTimeFromRepository () { function getYear ($timestamp = NULL) { // Is it cached? if (!isset($GLOBALS[__FUNCTION__][$timestamp])) { - // null is time() + // If NULL is set, use time() if (is_null($timestamp)) { $timestamp = time(); } // END - if @@ -1362,7 +1389,7 @@ function getYear ($timestamp = NULL) { function getMonth ($timestamp = NULL) { // Is it cached? if (!isset($GLOBALS[__FUNCTION__][$timestamp])) { - // If null is set, use time() + // If NULL is set, use time() if (is_null($timestamp)) { // Use time() which is current timestamp $timestamp = time(); @@ -1598,7 +1625,7 @@ function isRandomReferralIdEnabled () { // Is there cache? if (!isset($GLOBALS[__FUNCTION__])) { // Determine it - $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getConfig('select_user_zero_refid') == 'Y')); + $GLOBALS[__FUNCTION__] = ((isExtensionInstalledAndNewer('user', '0.3.4')) && (getSelectUserZeroRefid() == 'Y')); } // END - if // Return cache @@ -1665,6 +1692,18 @@ function getCachePath () { return $GLOBALS[__FUNCTION__]; } +// "Getter" for WRITE_FOOTER +function getWriteFooter () { + // Is there cache? + if (!isset($GLOBALS[__FUNCTION__])) { + // Determine it + $GLOBALS[__FUNCTION__] = getConfig('WRITE_FOOTER'); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__]; +} + // "Getter" for secret_key function getSecretKey () { // Is there cache? @@ -1952,79 +1991,6 @@ function getUserMinConfirmed () { // Return cache return $GLOBALS[__FUNCTION__]; } - -// "Getter" for auto_purge -function getAutoPurge () { - // Is there cache? - if (!isset($GLOBALS[__FUNCTION__])) { - // Determine it - $GLOBALS[__FUNCTION__] = getConfig('auto_purge'); - } // END - if - - // Return cache - return $GLOBALS[__FUNCTION__]; -} - -// "Getter" for bonus_userid -function getBonusUserid () { - // Is there cache? - if (!isset($GLOBALS[__FUNCTION__])) { - // Determine it - $GLOBALS[__FUNCTION__] = getConfig('bonus_userid'); - } // END - if - - // Return cache - return $GLOBALS[__FUNCTION__]; -} - -// "Getter" for ap_inactive_time -function getApInactiveTime () { - // Is there cache? - if (!isset($GLOBALS[__FUNCTION__])) { - // Determine it - $GLOBALS[__FUNCTION__] = getConfig('ap_inactive_time'); - } // END - if - - // Return cache - return $GLOBALS[__FUNCTION__]; -} - -// "Getter" for ap_dm_timeout -function getApDmTimeout () { - // Is there cache? - if (!isset($GLOBALS[__FUNCTION__])) { - // Determine it - $GLOBALS[__FUNCTION__] = getConfig('ap_dm_timeout'); - } // END - if - - // Return cache - return $GLOBALS[__FUNCTION__]; -} - -// "Getter" for ap_tasks_time -function getApTasksTime () { - // Is there cache? - if (!isset($GLOBALS[__FUNCTION__])) { - // Determine it - $GLOBALS[__FUNCTION__] = getConfig('ap_tasks_time'); - } // END - if - - // Return cache - return $GLOBALS[__FUNCTION__]; -} - -// "Getter" for ap_unconfirmed_time -function getApUnconfirmedTime () { - // Is there cache? - if (!isset($GLOBALS[__FUNCTION__])) { - // Determine it - $GLOBALS[__FUNCTION__] = getConfig('ap_unconfirmed_time'); - } // END - if - - // Return cache - return $GLOBALS[__FUNCTION__]; -} - // "Getter" for points function getPoints () { // Is there cache? @@ -2541,6 +2507,126 @@ function isDisplayHomeInIndexEnabled () { return $GLOBALS[__FUNCTION__]; } +// Getter for 'show_points_unconfirmed' +function getShowPointsUnconfirmed () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = getConfig('show_points_unconfirmed'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Checks whether 'show_points_unconfirmed' is 'Y' +function isShowPointsUnconfirmedEnabled () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = (getShowPointsUnconfirmed() == 'Y'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Getter for 'youre_here' +function getYoureHere () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = getConfig('youre_here'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Checks whether 'show_timings' is 'Y' +function isYoureHereEnabled () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = (getYoureHere() == 'Y'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Getter for 'show_timings' +function getShowTimings () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = getConfig('show_timings'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Checks whether 'show_timings' is 'Y' +function isShowTimingsEnabled () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = (getShowTimings() == 'Y'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Getter for 'ap_server_name_since' +function getApServerNameSince () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = getConfig('ap_server_name_since'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Getter for 'ap_server_name' +function getApServerName () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = getConfig('ap_server_name'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Getter for 'index_delay' +function getIndexDelay () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = getConfig('index_delay'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Checks whether 'ap_server_name' is 'Y' +function isApServerNameEnabled () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = (getApServerName() == 'Y'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + // Getter for 'admin_menu_javascript' function getAdminMenuJavascript () { // Is the cache entry set? @@ -2565,6 +2651,90 @@ function getPointsRemoveAccount () { return $GLOBALS[__FUNCTION__]; } +// Getter for 'css_php' +function getCssPhp () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = getConfig('css_php'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Getter for 'guest_menu' +function getGuestMenu () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = getConfig('guest_menu'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Checks if guest menu is enabled +function isGuestMenuEnabled () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = (getGuestMenu() == 'Y'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Getter for 'member_menu' +function getMemberMenu () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = getConfig('member_menu'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Checks if member menu is enabled +function isMemberMenuEnabled () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // No, so determine it + $GLOBALS[__FUNCTION__] = (getMemberMenu() == 'Y'); + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + +// Getter for 'word_wrap' +function getWordWrap () { + // Is the cache entry set? + if (!isset($GLOBALS[__FUNCTION__])) { + // Construct config entry name + $configEntry = getMenuModeFromModule() . '_word_wrap_' . getWhat(); + + // Is a special config entry found or ext-sql_patches updated? + if (isConfigEntrySet($configEntry)) { + // A special config entry has been found, then use it + $GLOBALS[__FUNCTION__] = getConfig($configEntry); + } elseif (isExtensionInstalledAndNewer('other', '0.2.9')) { + // No special config entry found, then use it as "fall-back" + $GLOBALS[__FUNCTION__] = getConfig('word_wrap'); + } else { + // No, use default (15 characters) + $GLOBALS[__FUNCTION__] = 15; + } + } // END - if + + // Return cached entry + return $GLOBALS[__FUNCTION__]; +} + // Checks whether proxy configuration is used function isProxyUsed () { // Is there cache? @@ -2682,18 +2852,6 @@ function isExtensionTask ($content) { return $GLOBALS[__FUNCTION__][$content['task_type'] . '_' . $content['infos']]; } -// Getter for 'mt_start' -function getMtStart () { - // Is the cache entry set? - if (!isset($GLOBALS[__FUNCTION__])) { - // No, so determine it - $GLOBALS[__FUNCTION__] = getConfig('mt_start'); - } // END - if - - // Return cached entry - return $GLOBALS[__FUNCTION__]; -} - // Checks whether ALLOW_TESTER_ACCOUNTS is set function ifTesterAccountsAllowed () { // Is the cache entry set? @@ -2795,7 +2953,7 @@ function ifUserPointsLocked ($userid) { // This function does always add a new-line character to every line. function appendLineToFile ($file, $line) { $fp = fopen($file, 'a') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($file) . '!'); - fwrite($fp, $line . chr(10)); + fwrite($fp, $line . PHP_EOL); fclose($fp); } @@ -2896,18 +3054,20 @@ function search_array ($array, $key, $value, $parentIndex = NULL) { if (is_array($array)) { // Search for whole array foreach ($array as $idx => $dummy) { - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value=' . $value . ',idx=' . $idx); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value=' . $value . ',idx=' . $idx . ',parentIndex[' . gettype($parentIndex) . ']=' . $parentIndex); + //* DEBUG: */ print 'idx=' . $idx . ',parentIndex[' . gettype($parentIndex) . ']=' . $parentIndex . ',key=' . $key . ',value=' . $value . ',array=
'.print_r($array, TRUE).'
'; // Is dummy an array? - if (is_array($dummy)) { + if ((is_array($dummy)) && ((is_null($parentIndex)) || ($parentIndex === $value))) { // Then search again $subResult = search_array($dummy, $key, $value, $idx); //* DEBUG: */ print 'subResult=
' . print_r($subResult, TRUE).'
'; // And merge both $results = merge_array($results, $subResult, TRUE); - } elseif ((isset($array[$key])) && ($array[$key] == $value)) { + } elseif (($key == $idx) && (isset($array[$key])) && ($array[$key] === $value)) { // Is found, so add it $results[$parentIndex] = $array; + //* DEBUG: */ print 'ARRAY: key=' . $key . ',idx=' . $idx . ',value=' . $value . ',parentIndex[' . gettype($parentIndex) . ']=' . $parentIndex . ',array=
' . print_r($array, TRUE).'
'; } } // END - foreach } // END - if @@ -3200,5 +3360,38 @@ function SQL_DEBUG_ENABLED () { return $GLOBALS[__FUNCTION__]; } +// Wrapper function to wrap call of wordwrap() +function wrapWords ($text) { + // Wrap words + $wrapped = wordwrap($test, getWordWrap()); + + // Return it + return $wrapped; +} + +// Encodes given data into a JSON object +function encodeJson ($data) { + // Encode it + return json_encode($data, JSON_FORCE_OBJECT); +} + +// Get all extension files +function loadAllExtensionsByTemplate () { + // Get all + $extensions = getArrayFromDirectory( + 'templates/' . getLanguage() . '/html/ext/', + 'ext_', + false, + false, + array(), + '.tpl', + '@(\.|\.\.)$@', + false + ); + + // Return them + return $extensions; +} + // [EOF] ?>