X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fmodule-functions.php;h=a0841a6a6015408d5697f5575c8d7807b13e6c95;hb=245c5812acaa3d845b03e1ead48cb7585444bcaf;hp=724822eda08382875976ae118a0c89fbf474ceaa;hpb=bd6c043a3124914a3dc541b56400f551add987bf;p=mailer.git diff --git a/inc/module-functions.php b/inc/module-functions.php index 724822eda0..a0841a6a60 100644 --- a/inc/module-functions.php +++ b/inc/module-functions.php @@ -6,9 +6,9 @@ * -------------------------------------------------------------------- * * File : module-functions.php * * -------------------------------------------------------------------- * - * Short description : All MySQL-related functions * + * Short description : Module functions * * -------------------------------------------------------------------- * - * Kurzbeschreibung : Alle MySQL-Relevanten Funktionen * + * Kurzbeschreibung : Modulfunktionen * * -------------------------------------------------------------------- * * $Revision:: $ * * $Date:: $ * @@ -16,7 +16,7 @@ * $Author:: $ * * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * - * Copyright (c) 2009, 2010 by Mailer Developer Team * + * Copyright (c) 2009 - 2011 by Mailer Developer Team * * For more information visit: http://www.mxchange.org * * * * This program is free software; you can redistribute it and/or modify * @@ -61,7 +61,7 @@ function getModuleTitle ($module) { array($module), __FUNCTION__, __LINE__); // Is the entry there? - if (SQL_NUMROWS($result)) { + if (SQL_NUMROWS($result) == 1) { // Get the title from database $data = SQL_FETCHARRAY($result); } // END - if @@ -79,10 +79,10 @@ function getModuleTitle ($module) { // Is it 'error'? if ($module == 'error') { // Error (real module was not found) - $data['title'] = getMessage('MODULE_ERROR_404'); + $data['title'] = '{--MODULE_ERROR_404--}'; } else { // No name found - $data['title'] = getMaskedMessage('UNKNOWN_MODULE_DETECTED', $module); + $data['title'] = '{%message,UNKNOWN_MODULE_DETECTED_TITLE=' . $module . '%}'; if ((is_resource($result)) && (SQL_HASZERONUMS($result))) { // Add module to database $dummy = checkModulePermissions($module); @@ -143,12 +143,18 @@ function isModuleRegistered ($module) { array($module), __FUNCTION__, __LINE__); if (SQL_NUMROWS($result) == 1) { // Read data - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Entry found.'); - $GLOBALS['cache_array']['modules'][$module] = SQL_FETCHARRAY($result); + $data = SQL_FETCHARRAY($result); + + // Set all entries + foreach ($data as $key=>$value) { + $GLOBALS['cache_array']['modules'][$key][$module] = $value; + } // END - foreach + + // Mark as found $found = true; } elseif (isDebugModeEnabled()) { // Debug message only in debug-mode... - logDebugMessage(__FUNCTION__, __LINE__, 'Module ' . $module . ' not found!'); + logDebugMessage(__FUNCTION__, __LINE__, 'Module ' . $module . ' not found.'); } // Free result @@ -159,10 +165,49 @@ function isModuleRegistered ($module) { return $found; } +// Checks wether the given module is locked by just checking the cache +function isModuleLocked ($module) { + // Determine if there a cache entry and is it set + $return = ((isset($GLOBALS['cache_array']['modules']['locked'][$module])) && ($GLOBALS['cache_array']['modules']['locked'][$module] == 'Y')); + + // Return determined value + return $return; +} + +// Checks wether the given module is hidden by just checking the cache +function isModuleHidden ($module) { + // Determine if there a cache entry and is it set + $return = ((isset($GLOBALS['cache_array']['modules']['hidden'][$module])) && ($GLOBALS['cache_array']['modules']['hidden'][$module] == 'Y')); + + // Return determined value + return $return; +} + +// Checks wether the given module is mem_only by just checking the cache +function isModuleMemberOnly ($module) { + // Determine if there a cache entry and is it set + $return = ((isset($GLOBALS['cache_array']['modules']['mem_only'][$module])) && ($GLOBALS['cache_array']['modules']['mem_only'][$module] == 'Y')); + + // Return determined value + return $return; +} + +// Checks wether the given module is admin_only by just checking the cache +function isModuleAdminOnly ($module) { + // Determine if there a cache entry and is it set + $return = ((isset($GLOBALS['cache_array']['modules']['admin_only'][$module])) && ($GLOBALS['cache_array']['modules']['admin_only'][$module] == 'Y')); + + // Return determined value + return $return; +} + // Check validity of a given module name (no file extension) function checkModulePermissions ($module = '') { // Is it empty (default), then take the current one - if (empty($module)) $module = getModule(); + if (empty($module)) { + // Use current module + $module = getModule(); + } // END - if // Do we have cache? if (isModuleStatusSet($module)) { @@ -192,7 +237,6 @@ function checkModulePermissions ($module = '') { // Check if script is installed if not return a 'done' to prevent some errors if ((isInstallationPhase()) || (!isAdminRegistered())) { // Not installed or no admin registered or in installation phase - // Set status setModuleStatus($module_chk, 'done'); // Return status @@ -207,49 +251,54 @@ function checkModulePermissions ($module = '') { // Check returned values against current access permissions // // Admin access ----- Guest access ----- --- Guest or member? --- - if ((isAdmin()) || (($GLOBALS['cache_array']['modules']['locked'][$module_chk] != 'Y') && ($GLOBALS['cache_array']['modules']['admin_only'][$module_chk] != 'Y') && (($GLOBALS['cache_array']['modules']['mem_only'][$module_chk] != 'Y') || (isMember())))) { + if ((isAdmin()) || ((!isModuleLocked($module_chk)) && (!isModuleAdminOnly($module_chk)) && ((!isModuleMemberOnly($module_chk)) || (isMember())))) { // If you are admin you are welcome for everything! setModuleStatus($module_chk, 'done'); - } elseif ($GLOBALS['cache_array']['modules']['locked'][$module_chk] == 'Y') { + } elseif (isModuleLocked($module_chk)) { // Module is locked setModuleStatus($module_chk, 'locked'); - } elseif (($GLOBALS['cache_array']['modules']['mem_only'][$module_chk] == 'Y') && (!isMember())) { + } elseif ((isModuleMemberOnly($module_chk)) && (!isMember())) { // You have to login first! setModuleStatus($module_chk, 'mem_only'); - } elseif (($GLOBALS['cache_array']['modules']['admin_only'][$module_chk] == 'Y') && (!isAdmin())) { + } elseif ((isModuleAdminOnly($module_chk)) && (!isAdmin())) { // Only the Admin is allowed to enter this module! setModuleStatus($module_chk, 'admin_only'); } else { // @TODO Nothing helped??? - logDebugMessage(__FUNCTION__, __LINE__, sprintf("ret=%s,locked=%s,admin=%s,mem=%s", + logDebugMessage(__FUNCTION__, __LINE__, sprintf("ret=%s,locked=%d,hidden=%d,mem=%d,admin=%d", getModuleStatus($module_chk), - $GLOBALS['cache_array']['modules']['locked'][$module_chk], - $GLOBALS['cache_array']['modules']['admin_only'][$module_chk], - $GLOBALS['cache_array']['modules']['mem_only'][$module_chk] + intval(isModuleLocked($module_chk)), + intval(isModuleHidden($module_chk)), + intval(isModuleMemberOnly($module_chk)), + intval(isModuleAdminOnly($module_chk)) )); } } // END - if // Still no luck or not found? if (($found === false) && (!isExtensionActive('cache')) && (getModuleStatus($module_chk) != 'done')) { - // ----- Legacy module ----- ---- Module in base folder ---- --- Module with extension's name --- + // ----- Default module ----- ---- Module in base folder ---- --- Module with extension's name --- if ((isIncludeReadable(sprintf("inc/modules/%s.php", $module))) || (isIncludeReadable(sprintf("%s.php", $module))) || (isIncludeReadable(sprintf("%s/%s.php", $extension, $module)))) { // Data is missing so we add it if (isExtensionInstalledAndNewer('sql_patches', '0.3.6')) { - // Since 0.3.6 we have a has_menu column, this took me a half hour - // to find a loop here... *sigh* + /* + * Since 0.3.6 we have a has_menu column, this took me a half + * hour to find a loop here... *sigh* + */ SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_mod_reg` -(`module`, `locked`, `hidden`, `mem_only`, `admin_only`, `has_menu`) VALUES +(`module`, `locked`, `hidden`, `mem_only`, `admin_only`, `has_menu`) +VALUES ('%s','Y','N','N','N','N')", array($module_chk), __FUNCTION__, __LINE__); } else { // Wrong/missing sql_patches! SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_mod_reg` -(`module`, `locked`, `hidden`, `mem_only`, `admin_only`) VALUES +(`module`, `locked`, `hidden`, `mem_only`, `admin_only`) +VALUES ('%s','Y','N','N','N')", array($module_chk), __FUNCTION__, __LINE__); } // Everthing is fine? - if (SQL_AFFECTEDROWS() < 1) { + if (SQL_HASZEROAFFECTED()) { // Something bad happend! setModuleStatus($module_chk, 'major'); return 'major'; @@ -257,7 +306,9 @@ function checkModulePermissions ($module = '') { // Destroy cache here // @TODO Rewrite this to a filter - if ((isHtmlOutputMode()) || (isRawOutputMode())) rebuildCache('modules', 'modules'); + if ((isHtmlOutputMode()) || (isRawOutputMode())) { + rebuildCache('modules', 'modules'); + } // END - if // And reload data unset($GLOBALS['module_status'][$module_chk]); @@ -271,48 +322,48 @@ function checkModulePermissions ($module = '') { rebuildCache('modules', 'modules'); } elseif ($found === false) { // Problem with module detected - logDebugMessage(__FUNCTION__, __LINE__, sprintf("Problem in module %s detected. ret=%s, locked=%s, hidden=%s, mem=%s, admin=%s, output_mode=%s", - $module, - $ret, - $GLOBALS['cache_array']['modules']['locked'][$module_chk], - $GLOBALS['cache_array']['modules']['hidden'][$module_chk], - $GLOBALS['cache_array']['modules']['mem_only'][$module_chk], - $GLOBALS['cache_array']['modules']['admin_only'][$module_chk], + logDebugMessage(__FUNCTION__, __LINE__, sprintf("Problem in module %s detected. getModuleStatus()=%s,locked=%d,hidden=%d,mem=%d,admin=%d,output_mode=%s", + $module_chk, + getModuleStatus($module_chk), + intval(isModuleLocked($module_chk)), + intval(isModuleHidden($module_chk)), + intval(isModuleMemberOnly($module_chk)), + intval(isModuleAdminOnly($module_chk)), getScriptOutputMode() )); } // Debug log - logDebugMessage(__FUNCTION__, __LINE__, sprintf("module=%s, statyus=%s", $module_chk, getModuleStatus($module_chk))); + logDebugMessage(__FUNCTION__, __LINE__, sprintf("module=%s, status=%s", $module_chk, getModuleStatus($module_chk))); // Return the value return getModuleStatus($module_chk); } // Checks if the module has a menu -function ifModuleHasMenu ($mod, $forceDb = false) { +function ifModuleHasMenu ($module, $forceDb = false) { // All is false by default $ret = false; // Extension installed and newer than or has version 0.1.2? if (isExtensionInstalledAndNewer('cache', '0.1.2')) { // Cache version is okay, so let's check the cache! - if (isset($GLOBALS['cache_array']['modules']['has_menu'][$mod])) { + if (isset($GLOBALS['cache_array']['modules']['has_menu'][$module])) { // Check module cache and count hit - $ret = ($GLOBALS['cache_array']['modules']['has_menu'][$mod] == 'Y'); + $ret = ($GLOBALS['cache_array']['modules']['has_menu'][$module] == 'Y'); incrementStatsEntry('cache_hits'); - } elseif (isset($GLOBALS['cache_array']['extension']['ext_menu'][$mod])) { + } elseif (isset($GLOBALS['cache_array']['extension']['ext_menu'][$module])) { // Check cache and count hit - $ret = ($GLOBALS['cache_array']['extension']['ext_menu'][$mod] == 'Y'); + $ret = ($GLOBALS['cache_array']['extension']['ext_menu'][$module] == 'Y'); incrementStatsEntry('cache_hits'); } else { // Admin/guest/member/sponsor modules have always a menu! - $ret = in_array($mod, array('admin', 'index', 'login', 'sponsor')); + $ret = in_array($module, array('admin', 'index', 'login', 'sponsor')); } } elseif ((isExtensionInstalledAndNewer('sql_patches', '0.3.6')) && ((!isExtensionActive('cache')) || ($forceDb === true))) { // Check database for entry $result = SQL_QUERY_ESC("SELECT `has_menu` FROM `{?_MYSQL_PREFIX?}_mod_reg` WHERE `module`='%s' LIMIT 1", - array($mod), __FUNCTION__, __LINE__); + array($module), __FUNCTION__, __LINE__); // Entry found? if (SQL_NUMROWS($result) == 1) { @@ -320,7 +371,7 @@ function ifModuleHasMenu ($mod, $forceDb = false) { $data = SQL_FETCHARRAY($result); // Fake cache... ;-) - $GLOBALS['cache_array']['extension']['ext_menu'][$mod] = $data['has_menu']; + $GLOBALS['cache_array']['extension']['ext_menu'][$module] = $data['has_menu']; // Does it have a menu? $ret = ($data['has_menu'] == 'Y'); @@ -330,7 +381,7 @@ function ifModuleHasMenu ($mod, $forceDb = false) { SQL_FREERESULT($result); } elseif (!isExtensionInstalled('sql_patches')) { // No sql_patches installed, so maybe in admin/guest/member/sponsor area or no admin registered? - $ret = in_array($mod, array('admin', 'index', 'login', 'sponsor')); // Then there is a menu! + $ret = in_array($module, array('admin', 'index', 'login', 'sponsor')); // Then there is a menu! } else { // Unsupported state! logDebugMessage(__FUNCTION__, __LINE__, 'This should never be reached.'); @@ -345,7 +396,7 @@ function addModuleSql ($module, $locked, $hidden, $adminOnly, $memOnly) { // Is the module already registered? if (!isModuleRegistered($module)) { // Add it - addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_mod_reg` (`module`,`locked`,`hidden`,`admin_only`,`mem_only`) VALUES('" . $module . "','" . $locked . "','" . $hidden . "','" . $adminOnly . "','" . $memOnly . "')"); + addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_mod_reg` (`module`, `locked`, `hidden`, `admin_only`, `mem_only`) VALUES ('" . $module . "','" . $locked . "','" . $hidden . "','" . $adminOnly . "','" . $memOnly . "')"); } else { // Already registered logDebugMessage(__FUNCTION__, __LINE__, sprintf("Already registered: module=%s,locked=%s,hidden=%s,admin=%s,mem=%s",