X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Fmysql-manager.php;h=da948fbee81fbe68a32abe9adba2f5357564d939;hp=db1db43c106c11241a12ca79cf5915854f839db0;hb=1ba8d9449de1b6fea32e88d581fb7c121b0522b1;hpb=2df9f7a53f8b1dd5164f87824a324ccb3b6634cb diff --git a/inc/mysql-manager.php b/inc/mysql-manager.php index db1db43c10..da948fbee8 100644 --- a/inc/mysql-manager.php +++ b/inc/mysql-manager.php @@ -16,7 +16,7 @@ * $Author:: $ * * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * - * Copyright (c) 2009 - 2012 by Mailer Developer Team * + * Copyright (c) 2009 - 2013 by Mailer Developer Team * * For more information visit: http://mxchange.org * * * * This program is free software; you can redistribute it and/or modify * @@ -61,7 +61,7 @@ function getTitleFromMenu ($mode, $what, $column = 'what', $ADD = '') { $data['title'] = '??? (' . $what . ')'; // Look for title - $result = SQL_QUERY_ESC("SELECT `title` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `%s`='%s'" . $ADD . " LIMIT 1", + $result = sqlQueryEscaped("SELECT `title` FROM `{?_MYSQL_PREFIX?}_%s_menu` WHERE `%s`='%s'" . $ADD . " LIMIT 1", array( $mode, $column, @@ -69,20 +69,20 @@ function getTitleFromMenu ($mode, $what, $column = 'what', $ADD = '') { ), __FUNCTION__, __LINE__); // Is there an entry? - if (SQL_NUMROWS($result) == 1) { + if (sqlNumRows($result) == 1) { // Fetch the title - $data = SQL_FETCHARRAY($result); + $data = sqlFetchArray($result); } // END - if // Free result - SQL_FREERESULT($result); + sqlFreeResult($result); // Return it return $data['title']; } // Add link into output stream (or return it) for 'You Are Here' navigation -function addYouAreHereLink ($accessLevel, $FQFN, $return = false) { +function addYouAreHereLink ($accessLevel, $FQFN, $return = FALSE) { // Use only filename of the FQFN... $file = basename($FQFN); @@ -145,7 +145,7 @@ function addYouAreHereLink ($accessLevel, $FQFN, $return = false) { // Add default content $prefix .= '
{--YOU_ARE_HERE--} Home'; - } elseif ($return === false) { + } elseif ($return === FALSE) { // Count depth $GLOBALS['nav_depth']++; } @@ -160,8 +160,8 @@ function addYouAreHereLink ($accessLevel, $FQFN, $return = false) { } // END - if // Is ext-sql_patches installed? - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isExtensionInstalledAndNewer()=' . intval(isExtensionInstalledAndNewer('sql_patches', '0.2.3')) . ',youre_here=' . getConfig('youre_here') . ',isAdmin()=' . intval(isAdmin()) . ',modCheck=' . $modCheck); - if (((isExtensionInstalledAndNewer('sql_patches', '0.2.3')) && (getConfig('youre_here') == 'Y')) || ((isAdmin()) && ($modCheck == 'admin'))) { + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isExtensionInstalledAndNewer()=' . intval(isExtensionInstalledAndNewer('sql_patches', '0.2.3')) . ',youre_here=' . getYoureHere() . ',isAdmin()=' . intval(isAdmin()) . ',modCheck=' . $modCheck); + if (((isExtensionInstalledAndNewer('sql_patches', '0.2.3')) && (isYoureHereEnabled())) || ((isAdmin()) && ($modCheck == 'admin'))) { // Output HTML code $OUT = $prefix . '' . getTitleFromMenu($accessLevel, $search, $type, $ADD) . ''; @@ -184,7 +184,7 @@ function addYouAreHereLink ($accessLevel, $FQFN, $return = false) { } // END - if // Return or output HTML code? - if ($return === true) { + if ($return === TRUE) { // Return HTML code return $OUT; } else { @@ -199,7 +199,7 @@ function addMenu ($mode, $action, $what) { $main_cnt = '0'; // is the menu action valid? - if (!isMenuActionValid($mode, $action, $what, true)) { + if (!isMenuActionValid($mode, $action, $what, TRUE)) { return getCode('MENU_NOT_VALID'); } // END - if @@ -211,7 +211,7 @@ function addMenu ($mode, $action, $what) { } // END - if // Load SQL data and add the menu to the output stream... - $result_main = SQL_QUERY_ESC("SELECT + $result_main = sqlQueryEscaped("SELECT `title`, `what`, `action`, @@ -227,19 +227,19 @@ ORDER BY array($mode), __FUNCTION__, __LINE__); //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'main_cnt=' . $main_cnt . ',getWhat()=' . getWhat()); - if (!SQL_HASZERONUMS($result_main)) { + if (!ifSqlHasZeroNums($result_main)) { // There are menus available, so we simply display them... :) $GLOBALS['rows'] = ''; - while ($content = SQL_FETCHARRAY($result_main)) { + while ($content = sqlFetchArray($result_main)) { //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'main_cnt=' . $main_cnt . ',action=' . $content['action'] . ',getWhat()=' . getWhat()); // Disable the block-mode - enableBlockMode(false); + enableBlockMode(FALSE); // Load menu header template - $GLOBALS['rows'] .= loadTemplate($mode . '_menu_title', true, $content); + $GLOBALS['rows'] .= loadTemplate($mode . '_menu_title', TRUE, $content); // Sub menu - $result_sub = SQL_QUERY_ESC("SELECT + $result_sub = sqlQueryEscaped("SELECT `title` AS `sub_title`, `what` AS `sub_what`, `visible` AS `sub_visible`, @@ -259,12 +259,12 @@ ORDER BY ), __FUNCTION__, __LINE__); // Are there some entries? - if (!SQL_HASZERONUMS($result_sub)) { + if (!ifSqlHasZeroNums($result_sub)) { // Init counter $count = '0'; // Load all sub menus - while ($content2 = SQL_FETCHARRAY($result_sub)) { + while ($content2 = sqlFetchArray($result_sub)) { // Merge both arrays in one $content = merge_array($content, $content2); @@ -320,10 +320,10 @@ ORDER BY ); // Add regular menu row or bottom row? - if ($count < SQL_NUMROWS($result_sub)) { - $GLOBALS['rows'] .= loadTemplate($mode . '_menu_row', true, $content); + if ($count < sqlNumRows($result_sub)) { + $GLOBALS['rows'] .= loadTemplate($mode . '_menu_row', TRUE, $content); } else { - $GLOBALS['rows'] .= loadTemplate($mode . '_menu_bottom', true, $content); + $GLOBALS['rows'] .= loadTemplate($mode . '_menu_bottom', TRUE, $content); } } // END - while } else { @@ -334,48 +334,58 @@ ORDER BY $INC = sprintf("inc/modules/%s/action-%s.php", $mode, $content['action']); if (isFileReadable($INC)) { // Load include file - if ((!isExtensionActive($content['action'])) || ($content['action'] == 'online')) $GLOBALS['rows'] .= loadTemplate('menu_what_begin', true, $mode); + if ((!isExtensionActive($content['action'])) || ($content['action'] == 'online')) $GLOBALS['rows'] .= loadTemplate('menu_what_begin', TRUE, $mode); //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'main_cnt=' . $main_cnt . ',action=' . $content['action'] . ',getWhat()=' . getWhat()); loadInclude($INC); //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'main_cnt=' . $main_cnt . ',action=' . $content['action'] . ',getWhat()=' . getWhat()); - if ((!isExtensionActive($content['action'])) || ($content['action'] == 'online')) $GLOBALS['rows'] .= loadTemplate('menu_what_end', true, $mode); + if ((!isExtensionActive($content['action'])) || ($content['action'] == 'online')) $GLOBALS['rows'] .= loadTemplate('menu_what_end', TRUE, $mode); } //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'main_cnt=' . $main_cnt . ',action=' . $content['action'] . ',getWhat()=' . getWhat()); } // Free result - SQL_FREERESULT($result_sub); + sqlFreeResult($result_sub); // Count one up $main_cnt++; //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'main_cnt=' . $main_cnt . ',getWhat()=' . getWhat()); - if (SQL_NUMROWS($result_main) > $main_cnt) { + if (sqlNumRows($result_main) > $main_cnt) { // Add separator - $GLOBALS['rows'] .= loadTemplate('menu_separator', true, $mode); + $GLOBALS['rows'] .= loadTemplate('menu_separator', TRUE, $mode); + + // Prepare filter data array + $filterData = array( + 'output' => '', + 'exclusive' => FALSE, + 'action' => $action, + 'mode' => $mode, + ); - // Should we display adverts in this menu? - if ((isExtensionInstalledAndNewer('menu', '0.0.1')) && (getConfig($mode . '_menu_advert_enabled') == 'Y') && ($action != 'admin')) { - // Display advert template - $GLOBALS['rows'] .= loadTemplate('menu_' . $mode . '_advert_' . $action, true); + // Run filter chain + $filterData = runFilterChain($mode . '_menu_advert', $filterData); - // Add separator again - $GLOBALS['rows'] .= loadTemplate('menu_separator', true, $mode); - } // END - if + // Add content output + $GLOBALS['rows'] .= $filterData['output']; } // END - if } // END - while // Free memory - SQL_FREERESULT($result_main); + sqlFreeResult($result_main); + + // Prepare filter data array + $filterData = array( + 'output' => '', + 'exclusive' => FALSE, + 'action' => $action, + 'mode' => $mode, + ); - // Should we display adverts in this menu? - if ((isExtensionInstalledAndNewer('menu', '0.0.1')) && (getConfig($mode . '_menu_advert_enabled') == 'Y')) { - // Add separator again - $GLOBALS['rows'] .= loadTemplate('menu_separator', true, $mode); + // Run filter chain + $filterData = runFilterChain($mode . '_menu_advert_end', $filterData); - // Display advert template - $GLOBALS['rows'] .= loadTemplate('menu_' . $mode . '_advert_end', true); - } // END - if + // Add content output + $GLOBALS['rows'] .= $filterData['output']; // Prepare data $content = array( @@ -385,14 +395,14 @@ ORDER BY // Load main template //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'main_cnt=' . $main_cnt . ',getWhat()=' . getWhat()); - loadTemplate('menu_table', false, $content); + loadTemplate('menu_table', FALSE, $content); } // END - if } // Checks whether the current user is a member function isMember () { // By default no member - $ret = false; + $ret = FALSE; // Fix missing 'last_online' array, damn stupid code :((( // @TODO Try to rewrite this to one or more functions @@ -411,7 +421,7 @@ function isMember () { //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'No member set in cookie/session.'); // Abort further processing - return false; + return FALSE; } // Get userid secured from session @@ -427,7 +437,7 @@ function isMember () { fixDeletedCookies(array('userid', 'u_hash')); // Are cookies set and can the member data be loaded? - if ((isMemberIdSet()) && (isSessionVariableSet('u_hash')) && (fetchUserData(getMemberId()) === true)) { + if ((isMemberIdSet()) && (isSessionVariableSet('u_hash')) && (fetchUserData(getMemberId()) === TRUE)) { // Validate password by created the difference of it and the secret key $valPass = encodeHashForCookie(getUserData('password')); @@ -438,12 +448,12 @@ function isMember () { $GLOBALS['last_online']['online'] = getUserData('last_online'); // Account is confirmed and all cookie data is valid so he is definely logged in! :-) - $ret = true; + $ret = TRUE; } // END - if } // END - if // Is $ret still false? - if ($ret === false) { + if ($ret === FALSE) { // Yes, so destroy the session destroyMemberSession(); } // END - if @@ -461,7 +471,7 @@ function fetchUserData ($value, $column = 'userid') { // Extension ext-user must be there at any case if (!isExtensionActive('user')) { // Absent ext-user is really not good - return false; + return FALSE; } elseif (is_null($value)) { // This shall never happen, so please report it reportBug(__FUNCTION__, __LINE__, 'value=NULL,column=' . $column . ' - value can never be NULL'); @@ -473,7 +483,7 @@ function fetchUserData ($value, $column = 'userid') { $value = bigintval($value); // Don't look for invalid userids... - if (!isValidUserId($value)) { + if (!isValidId($value)) { // Invalid, so abort here reportBug(__FUNCTION__, __LINE__, 'User id ' . $value . ' is invalid.'); } // END - if @@ -482,34 +492,34 @@ function fetchUserData ($value, $column = 'userid') { if ((isCurrentUserIdSet()) && (getCurrentUserId() != $value)) { // Unset it unsetCurrentUserId(); - } elseif (isUserDataValid()) { + } elseif (isValidUserData()) { // Use cache, so it is fine //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ' is valid, using cache #1'); - return true; + return TRUE; } // END - if - } elseif (isUserDataValid()) { + } elseif (isValidUserData()) { // Using cache is fine //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ' is valid, using cache #2'); - return true; + return TRUE; } // By default none was found - $found = false; + $found = FALSE; // Extra SQL statements $ADD = runFilterChain('convert_user_data_columns', ' '); // Query for the user - $result = SQL_QUERY_ESC("SELECT *" . $ADD . " FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `%s`='%s' LIMIT 1", + $result = sqlQueryEscaped("SELECT *" . $ADD . " FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `%s`='%s' LIMIT 1", array( $column, $value ), __FUNCTION__, __LINE__); // Is there a record? - if (SQL_NUMROWS($result) == 1) { + if (sqlNumRows($result) == 1) { // Load data from cookies - $data = SQL_FETCHARRAY($result); + $data = sqlFetchArray($result); // Set the userid for later use setCurrentUserId($data['userid']); @@ -545,11 +555,11 @@ function fetchUserData ($value, $column = 'userid') { } // END - if // Found, but valid? - $found = isUserDataValid(); + $found = isValidUserData(); } // END - if // Free memory - SQL_FREERESULT($result); + sqlFreeResult($result); // Return result return $found; @@ -562,88 +572,88 @@ function fetchUserData ($value, $column = 'userid') { * login. */ function isAdmin () { + // Is there cache? + if (isset($GLOBALS[__FUNCTION__])) { + // Return it + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isAdmin()=' . intval($GLOBALS[__FUNCTION__])); + return $GLOBALS[__FUNCTION__]; + } // END - if + // No admin in installation phase! - if ((isInstallationPhase()) || (!isAdminRegistered())) { - return false; + if ((isInstaller()) || (!isAdminRegistered())) { + $GLOBALS[__FUNCTION__] = FALSE; + return FALSE; } // END - if // Init variables - $ret = false; + $ret = FALSE; $adminId = '0'; $passwordFromCookie = ''; - $valPass = ''; //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $adminId); // If admin login is not given take current from cookies... if ((isSessionVariableSet('admin_id')) && (isSessionVariableSet('admin_md5'))) { // Get admin login and password from session/cookies - $adminId = getCurrentAdminId(); + $adminId = getCurrentAdminId(); $passwordFromCookie = getAdminMd5(); } // END - if - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId . 'passwordFromCookie=' . $passwordFromCookie); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'adminId=' . $adminId . ',passwordFromCookie=' . $passwordFromCookie); // Abort if admin id is zero - if ($adminId == '0') { + if (($adminId == '0') || (empty($passwordFromCookie))) { // A very noisy debug message ... //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Current adminId is zero. isSessionVariableSet(admin_id)=' . intval(isSessionVariableSet('admin_id')) . ',isSessionVariableSet(admin_md5)=' . intval(isSessionVariableSet('admin_md5'))); // Abort here now - return false; + $GLOBALS[__FUNCTION__] = FALSE; + return FALSE; } // END - if - // Is there cache? - if (!isset($GLOBALS[__FUNCTION__][$adminId])) { - // Init it with failed - $GLOBALS[__FUNCTION__][$adminId] = false; - - // Search in array for entry - if (isset($GLOBALS['admin_hash'])) { - // Use cached string - $valPass = $GLOBALS['admin_hash']; - } elseif ((!empty($passwordFromCookie)) && (isAdminHashSet($adminId) === true) && (!empty($adminId))) { - // Login data is valid or not? - $valPass = encodeHashForCookie(getAdminHash($adminId)); - - // Cache it away - $GLOBALS['admin_hash'] = $valPass; - - // Count cache hits - incrementStatsEntry('cache_hits'); - } elseif ((!empty($adminId)) && ((!isExtensionActive('cache')) || (isAdminHashSet($adminId) === false))) { - // Get admin hash and hash it - $valPass = encodeHashForCookie(getAdminHash($adminId)); - - // Cache it away - $GLOBALS['admin_hash'] = $valPass; - } + // Init it with failed + $GLOBALS[__FUNCTION__] = FALSE; - if (!empty($valPass)) { - // Check if password is valid - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '(' . $valPass . '==' . $passwordFromCookie . ')='.intval($valPass == $passwordFromCookie)); - $GLOBALS[__FUNCTION__][$adminId] = ($GLOBALS['admin_hash'] == $passwordFromCookie); - } // END - if - } // END - if + // Search in array for entry + if (isset($GLOBALS['admin_hash'])) { + // Use cached string + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Using admin_hash=' . $GLOBALS['admin_hash'] . ' from cache'); + } elseif ((!empty($adminId)) && (!empty($passwordFromCookie)) && (isAdminHashSet($adminId) === TRUE)) { + // Get admin hash and hash it + $GLOBALS['admin_hash'] = encodeHashForCookie(getAdminHash($adminId)); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'valPass=' . $GLOBALS['admin_hash']); + + // Count cache hits + incrementStatsEntry('cache_hits'); + } elseif ((!empty($adminId)) && ((!isExtensionActive('cache')) || (isAdminHashSet($adminId) === FALSE))) { + // Get admin hash and hash it + $GLOBALS['admin_hash'] = encodeHashForCookie(getAdminHash($adminId)); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'valPass=' . $GLOBALS['admin_hash']); + } + + // Check if password is valid + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '(' . $GLOBALS['admin_hash'] . '==' . $passwordFromCookie . ')='.intval($GLOBALS['admin_hash'] == $passwordFromCookie)); + $GLOBALS[__FUNCTION__] = ((!empty($GLOBALS['admin_hash'])) && ($GLOBALS['admin_hash'] == $passwordFromCookie)); // Return result of comparision - return $GLOBALS[__FUNCTION__][$adminId]; + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isAdmin()=' . intval($GLOBALS[__FUNCTION__])); + return $GLOBALS[__FUNCTION__]; } // Generates a list of "max receiveable emails per day" function addMaxReceiveList ($mode, $default = '') { $OUT = ''; - $result = false; + $result = FALSE; switch ($mode) { case 'guest': // Guests (in the registration form) are not allowed to select 0 mails per day. - $result = SQL_QUERY('SELECT `value`, `comment` FROM `{?_MYSQL_PREFIX?}_max_receive` WHERE `value` > 0 ORDER BY `value` ASC', + $result = sqlQuery('SELECT `value`, `comment` FROM `{?_MYSQL_PREFIX?}_max_receive` WHERE `value` > 0 ORDER BY `value` ASC', __FUNCTION__, __LINE__); break; case 'admin': case 'member': // Members are allowed to set to zero mails per day (we will change this soon!) - $result = SQL_QUERY('SELECT `value`, `comment` FROM `{?_MYSQL_PREFIX?}_max_receive` ORDER BY `value` ASC', + $result = sqlQuery('SELECT `value`, `comment` FROM `{?_MYSQL_PREFIX?}_max_receive` ORDER BY `value` ASC', __FUNCTION__, __LINE__); break; @@ -653,9 +663,9 @@ function addMaxReceiveList ($mode, $default = '') { } // Some entries are found? - if (!SQL_HASZERONUMS($result)) { + if (!ifSqlHasZeroNums($result)) { $OUT = ''; - while ($content = SQL_FETCHARRAY($result)) { + while ($content = sqlFetchArray($result)) { $OUT .= '