+ return $GLOBALS['extra_title'];
+}
+
+// Checks if the extra title is set
+function isExtraTitleSet () {
+ return ((isset($GLOBALS['extra_title'])) && (!empty($GLOBALS['extra_title'])));
+}
+
+// Generates a 'extension foo inactive' message
+function generateExtensionInactiveMessage ($ext_name) {
+ // Is the extension empty?
+ if (empty($ext_name)) {
+ // This should not happen
+ debug_report_bug(__FUNCTION__ . ': Parameter ext is empty. This should not happen.');
+ } // END - if
+
+ // Default message
+ $message = getMaskedMessage('EXTENSION_PROBLEM_EXT_INACTIVE', $ext_name);
+
+ // Is an admin logged in?
+ if (isAdmin()) {
+ // Then output admin message
+ $message = getMaskedMessage('ADMIN_EXTENSION_PROBLEM_EXT_INACTIVE', $ext_name);
+ } // END - if
+
+ // Return prepared message
+ return $message;
+}
+
+// Generates a 'extension foo not installed' message
+function generateExtensionNotInstalledMessage ($ext_name) {
+ // Is the extension empty?
+ if (empty($ext_name)) {
+ // This should not happen
+ debug_report_bug(__FUNCTION__ . ': Parameter ext is empty. This should not happen.');
+ } // END - if
+
+ // Default message
+ $message = getMaskedMessage('EXTENSION_PROBLEM_EXT_NOT_INSTALLED', $ext_name);
+
+ // Is an admin logged in?
+ if (isAdmin()) {
+ // Then output admin message
+ $message = getMaskedMessage('ADMIN_EXTENSION_PROBLEM_EXT_NOT_INSTALLED', $ext_name);
+ } // END - if
+
+ // Return prepared message
+ return $message;
+}
+
+// Generates a message depending on if the extension is not installed or not
+// just activated
+function generateExtensionInactiveNotInstalledMessage ($ext_name) {
+ // Init message
+ $message = '';
+
+ // Is the extension not installed or just deactivated?
+ switch (isExtensionInstalled($ext_name)) {
+ case true; // Deactivated!
+ $message = generateExtensionInactiveMessage($ext_name);
+ break;
+
+ case false; // Not installed!
+ $message = generateExtensionNotInstalledMessage($ext_name);
+ break;
+
+ default: // Should not happen!
+ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Invalid state of extension %s detected.", $ext_name));
+ $message = sprintf("Invalid state of extension %s detected.", $ext_name);
+ break;
+ } // END - switch
+
+ // Return the message
+ return $message;
+}
+
+// Reads a directory recursively by default and searches for files not matching
+// an exclusion pattern. You can now keep the exclusion pattern empty for reading
+// a whole directory.
+function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = false, $addBaseDir = true, $excludeArray = array(), $extension = '.php', $excludePattern = '@(\.|\.\.)$@', $recursive = true, $suffix = '') {
+ // Add default entries we should exclude
+ $excludeArray[] = '.';
+ $excludeArray[] = '..';
+ $excludeArray[] = '.svn';
+ $excludeArray[] = '.htaccess';
+
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "baseDir={$baseDir},prefix={$prefix} - Entered!");
+ // Init includes
+ $files = array();
+
+ // Open directory
+ $dirPointer = opendir(getConfig('PATH') . $baseDir) or app_die(__FUNCTION__, __LINE__, 'Cannot read directory ' . basename($baseDir) . '.');
+
+ // Read all entries
+ while ($baseFile = readdir($dirPointer)) {
+ // Exclude '.', '..' and entries in $excludeArray automatically
+ if (in_array($baseFile, $excludeArray, true)) {
+ // Exclude them
+ //* DEBUG: */ outputHtml('excluded=' . $baseFile . '<br />');
+ continue;
+ } // END - if
+
+ // Construct include filename and FQFN
+ $fileName = $baseDir . $baseFile;
+ $FQFN = getConfig('PATH') . $fileName;
+
+ // Remove double slashes
+ $FQFN = str_replace('//', '/', $FQFN);
+
+ // Check if the base filenname matches an exclusion pattern and if the pattern is not empty
+ if ((!empty($excludePattern)) && (preg_match($excludePattern, $baseFile, $match))) {
+ // These Lines are only for debugging!!
+ //* DEBUG: */ outputHtml('baseDir:' . $baseDir . '<br />');
+ //* DEBUG: */ outputHtml('baseFile:' . $baseFile . '<br />');
+ //* DEBUG: */ outputHtml('FQFN:' . $FQFN . '<br />');
+
+ // Exclude this one
+ continue;
+ } // END - if
+
+ // Skip also files with non-matching prefix genericly
+ if (($recursive === true) && (isDirectory($FQFN))) {
+ // Is a redirectory so read it as well
+ $files = merge_array($files, getArrayFromDirectory($baseDir . $baseFile . '/', $prefix, $fileIncludeDirs, $addBaseDir, $excludeArray, $extension, $excludePattern, $recursive));
+
+ // And skip further processing
+ continue;
+ } elseif (substr($baseFile, 0, strlen($prefix)) != $prefix) {
+ // Skip this file
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "Invalid prefix in file " . $baseFile . ", prefix=" . $prefix);
+ continue;
+ } elseif ((!empty($suffix)) && (substr($baseFile, -(strlen($suffix . $extension)), (strlen($suffix . $extension))) != $suffix . $extension)) {
+ // Skip wrong suffix as well
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "Invalid suffix in file " . $baseFile . ", suffix=" . $suffix);
+ continue;
+ } elseif (!isFileReadable($FQFN)) {
+ // Not readable so skip it
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "File " . $FQFN . " is not readable!");
+ continue;
+ }
+
+ // Is the file a PHP script or other?
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "baseDir={$baseDir},prefix={$prefix},baseFile={$baseFile}");
+ if ((substr($baseFile, -4, 4) == '.php') || (($fileIncludeDirs === true) && (isDirectory($FQFN)))) {
+ // Is this a valid include file?
+ if ($extension == '.php') {
+ // Remove both for extension name
+ $extName = substr($baseFile, strlen($prefix), -4);
+
+ // Is the extension valid and active?
+ if (isExtensionNameValid($extName)) {
+ // Then add this file
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Extension entry ' . $baseFile . ' added.');
+ $files[] = $fileName;
+ } else {
+ // Add non-extension files as well
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Regular entry ' . $baseFile . ' added.');
+ if ($addBaseDir === true) {
+ $files[] = $fileName;
+ } else {
+ $files[] = $baseFile;
+ }
+ }
+ } else {
+ // We found .php file but should not search for them, why?
+ debug_report_bug('We should find files with extension=' . $extension . ', but we found a PHP script.');
+ }
+ } elseif (substr($baseFile, -4, 4) == $extension) {
+ // Other, generic file found
+ $files[] = $fileName;
+ }
+ } // END - while
+
+ // Close directory
+ closedir($dirPointer);
+
+ // Sort array
+ sort($files);
+
+ // Return array with include files
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '- Left!');
+ return $files;
+}
+
+// Maps a module name into a database table name
+function mapModuleToTable ($moduleName) {
+ // Map only these, still lame code...
+ switch ($moduleName) {
+ // 'index' is the guest's menu
+ case 'index': $moduleName = 'guest'; break;
+ // ... and 'login' the member's menu
+ case 'login': $moduleName = 'member'; break;
+ // Anything else will not be mapped, silently.
+ } // END - switch
+
+ // Return result
+ return $moduleName;
+}
+
+// Add SQL debug data to array for later output
+function addSqlToDebug ($result, $sqlString, $timing, $F, $L) {
+ // Already executed?
+ if (isset($GLOBALS['debug_sqls'][$F][$L][$sqlString])) {
+ // Then abort here, we don't need to profile a query twice
+ return;
+ } // END - if
+
+ // Remeber this as profiled (or not, but we don't care here)
+ $GLOBALS['debug_sqls'][$F][$L][$sqlString] = true;
+
+ // Do we have cache?
+ if (!isset($GLOBALS['debug_sql_available'])) {
+ // Check it and cache it in $GLOBALS
+ $GLOBALS['debug_sql_available'] = ((isConfigurationLoaded()) && (isExtensionInstalledAndNewer('other', '0.2.2')) && (getConfig('display_debug_sqls') == 'Y'));
+ } // END - if
+
+ // Don't execute anything here if we don't need or ext-other is missing
+ if ($GLOBALS['debug_sql_available'] === false) {
+ return;
+ } // END - if
+
+ // Generate record
+ $record = array(
+ 'num_rows' => SQL_NUMROWS($result),
+ 'affected' => SQL_AFFECTEDROWS(),
+ 'sql_str' => $sqlString,
+ 'timing' => $timing,
+ 'file' => basename($F),
+ 'line' => $L
+ );
+
+ // Add it
+ $GLOBALS['debug_sqls'][] = $record;
+}
+
+// Initializes the cache instance
+function initCacheInstance () {
+ // Load include for CacheSystem class
+ loadIncludeOnce('inc/classes/cachesystem.class.php');
+
+ // Initialize cache system only when it's needed
+ $GLOBALS['cache_instance'] = new CacheSystem();
+ if ($GLOBALS['cache_instance']->getStatus() != 'done') {
+ // Failed to initialize cache sustem
+ addFatalMessage(__FILE__, __LINE__, '(<font color="#0000aa">' . __LINE__ . '</font>): ' . getMessage('CACHE_CANNOT_INITIALIZE'));
+ } // END - if
+}
+
+// Getter for message from array or raw message
+function getMessageFromIndexedArray ($message, $pos, $array) {
+ // Check if the requested message was found in array
+ if (isset($array[$pos])) {
+ // ... if yes then use it!
+ $ret = $array[$pos];
+ } else {
+ // ... else use default message
+ $ret = $message;
+ }
+
+ // Return result
+ return $ret;
+}
+
+// Print code with line numbers
+function linenumberCode ($code) {
+ if (!is_array($code)) $codeE = explode("\n", $code); else $codeE = $code;
+ $count_lines = count($codeE);
+
+ $r = 'Line | Code:<br />';
+ foreach($codeE as $line => $c) {
+ $r .= '<div class="line"><span class="linenum">';
+ if ($count_lines == 1) {
+ $r .= 1;
+ } else {
+ $r .= ($line == ($count_lines - 1)) ? '' : ($line+1);
+ }
+ $r .= '</span>|';
+
+ // Add code
+ $r .= '<span class="linetext">' . htmlentities($c) . '</span></div>';
+ }
+
+ return '<div class="code">' . $r . '</div>';
+}
+
+// Convert ';' to ', ' for e.g. receiver list
+function convertReceivers ($old) {
+ return str_replace(';', ', ', $old);
+}
+
+// Determines the right page title
+function determinePageTitle () {
+ // Config and database connection valid?
+ if ((isConfigLocalLoaded()) && (isConfigurationLoaded()) && (SQL_IS_LINK_UP()) && (isExtensionInstalledAndNewer('sql_patches', '0.1.6'))) {
+ // Init title
+ $TITLE = '';
+
+ // Title decoration enabled?
+ if ((getConfig('enable_title_deco') == 'Y') && (getConfig('title_left') != '')) $TITLE .= trim(getConfig('title_left')) . ' ';
+
+ // Do we have some extra title?
+ if (isExtraTitleSet()) {
+ // Then prepent it
+ $TITLE .= getExtraTitle() . ' by ';
+ } // END - if
+
+ // Add main title
+ $TITLE .= getConfig('MAIN_TITLE');
+
+ // Add title of module? (middle decoration will also be added!)
+ if ((getConfig('enable_mod_title') == 'Y') || ((!isWhatSet()) && (!isActionSet())) || (getModule() == 'admin')) {
+ $TITLE .= ' ' . trim(getConfig('title_middle')) . ' ' . getModuleTitle(getModule());
+ } // END - if
+
+ // Add title from what file
+ $mode = '';
+ if (getModule() == 'login') $mode = 'member';
+ elseif (getModule() == 'index') $mode = 'guest';
+ if ((!empty($mode)) && (getConfig('enable_what_title') == 'Y')) $TITLE .= ' ' . trim(getConfig('title_middle')) . ' ' . getTitleFromMenu($mode, getWhat());
+
+ // Add title decorations? (right)
+ if ((getConfig('enable_title_deco') == 'Y') && (getConfig('title_right') != '')) $TITLE .= ' ' . trim(getConfig('title_right'));
+
+ // Remember title in constant for the template
+ $pageTitle = $TITLE;
+ } elseif ((isInstalled()) && (isAdminRegistered())) {
+ // Installed, admin registered but no ext-sql_patches
+ $pageTitle = '[-- ' . getConfig('MAIN_TITLE') . ' - ' . getModuleTitle(getModule()) . ' --]';
+ } elseif ((isInstalled()) && (!isAdminRegistered())) {
+ // Installed but no admin registered
+ $pageTitle = getMessage('SETUP_OF_MXCHANGE');
+ } elseif ((!isInstalled()) || (!isAdminRegistered())) {
+ // Installation mode
+ $pageTitle = getMessage('INSTALLATION_OF_MXCHANGE');
+ } else {
+ // Configuration not found!
+ $pageTitle = getMessage('NO_CONFIG_FOUND_TITLE');
+
+ // Do not add the fatal message in installation mode
+ if ((!isInstalling()) && (!isConfigurationLoaded())) addFatalMessage(__FILE__, __LINE__, getMessage('NO_CONFIG_FOUND'));
+ }
+
+ // Return title
+ return decodeEntities($pageTitle);