|
From: Markus P. <mar...@us...> - 2005-04-25 01:27:30
|
Update of /cvsroot/mxbb/core/includes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20130 Modified Files: mx_auth.php mx_cache.php mx_constants.php mx_functions.php Log Message: Massive code cleanup in the includes folder. Also optimized code in several functions. Index: mx_cache.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/mx_cache.php,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** mx_cache.php 3 Apr 2005 16:45:15 -0000 1.3 --- mx_cache.php 25 Apr 2005 01:27:20 -0000 1.4 *************** *** 13,17 **** */ ! /** * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by --- 13,17 ---- */ ! /** * This program is free software; you can redistribute it and/or modify [...1072 lines suppressed...] { $HTTP_SESSION_VARS['block_' . $block_id][$param_row[parameter_name]] = $param_row; *************** *** 657,662 **** } } ! return $block_config; } ?> \ No newline at end of file --- 685,691 ---- } } ! return $block_config; } + ?> \ No newline at end of file Index: mx_constants.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/mx_constants.php,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** mx_constants.php 6 Mar 2005 09:22:52 -0000 1.12 --- mx_constants.php 25 Apr 2005 01:27:20 -0000 1.13 *************** *** 19,54 **** */ ! if ( !defined( 'IN_PORTAL' ) ) { ! die( "Hacking attempt" ); } - // Page numbers for session handling ! // Table names ! define( 'PORTAL_TABLE', $mx_table_prefix . 'portal' ); ! define( 'MENU_NAV_TABLE', $mx_table_prefix . 'menu_nav' ); ! define( 'MENU_CAT_TABLE', $mx_table_prefix . 'menu_categories' ); ! define( 'MODULE_TABLE', $mx_table_prefix . 'module' ); ! define( 'FUNCTION_TABLE', $mx_table_prefix . 'function' ); ! define( 'PARAMETER_TABLE', $mx_table_prefix . 'parameter' ); ! define( 'PARAMETER_OPTION_TABLE', $mx_table_prefix . 'parameter_option' ); ! define( 'PAGE_TABLE' , $mx_table_prefix . 'page' ); ! define( 'COLUMN_TABLE' , $mx_table_prefix . 'column' ); ! define( 'COLUMN_BLOCK_TABLE', $mx_table_prefix . 'column_block' ); ! define( 'BLOCK_TABLE', $mx_table_prefix . 'block' ); ! define( 'BLOCK_SYSTEM_PARAMETER_TABLE', $mx_table_prefix . 'block_system_parameter' ); ! define( 'BLOCK_USER_PARAMETER_TABLE', $mx_table_prefix . 'block_user_parameter' ); ! define( 'COLUMN_TEMPLATES' , $mx_table_prefix . 'column_templates' ); ! define( 'PAGE_TEMPLATES' , $mx_table_prefix . 'page_templates' ); ! define( 'MX_MATCH_TABLE' , $mx_table_prefix . 'wordmatch' ); ! define( 'MX_WORD_TABLE' , $mx_table_prefix . 'wordlist' ); ! define( 'MX_SEARCH_TABLE' , $mx_table_prefix . 'search_results' ); ! define( 'AUTH_ANONYMOUS', 9 ); $current_template_images = $current_template_path . "/images"; --- 19,58 ---- */ ! if ( !defined('IN_PORTAL') ) { ! die("Hacking attempt"); } ! // ! // mxBB Core table names ! // ! define('PORTAL_TABLE', $mx_table_prefix . 'portal'); ! define('MENU_NAV_TABLE', $mx_table_prefix . 'menu_nav'); ! define('MENU_CAT_TABLE', $mx_table_prefix . 'menu_categories'); ! define('MODULE_TABLE', $mx_table_prefix . 'module'); ! define('FUNCTION_TABLE', $mx_table_prefix . 'function'); ! define('PARAMETER_TABLE', $mx_table_prefix . 'parameter'); ! define('PARAMETER_OPTION_TABLE', $mx_table_prefix . 'parameter_option'); ! define('PAGE_TABLE' , $mx_table_prefix . 'page'); ! define('COLUMN_TABLE' , $mx_table_prefix . 'column'); ! define('COLUMN_BLOCK_TABLE', $mx_table_prefix . 'column_block'); ! define('BLOCK_TABLE', $mx_table_prefix . 'block'); ! define('BLOCK_SYSTEM_PARAMETER_TABLE', $mx_table_prefix . 'block_system_parameter'); ! define('BLOCK_USER_PARAMETER_TABLE', $mx_table_prefix . 'block_user_parameter'); ! define('COLUMN_TEMPLATES' , $mx_table_prefix . 'column_templates'); ! define('PAGE_TEMPLATES' , $mx_table_prefix . 'page_templates'); ! define('MX_MATCH_TABLE' , $mx_table_prefix . 'wordmatch'); ! define('MX_WORD_TABLE' , $mx_table_prefix . 'wordlist'); ! define('MX_SEARCH_TABLE' , $mx_table_prefix . 'search_results'); ! // ! // Other common constants and definitions. ! // ! define('AUTH_ANONYMOUS', 9); $current_template_images = $current_template_path . "/images"; Index: mx_auth.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/mx_auth.php,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** mx_auth.php 13 Apr 2005 21:23:25 -0000 1.6 --- mx_auth.php 25 Apr 2005 01:27:20 -0000 1.7 *************** *** 25,72 **** * - page_auth * - menu_auth - * - mx_auth_check_user (from auth.php - validated for phpbb 2.0.10) * - get_auth_forum ! * - mx_auth_group_cache */ - - /* - $type's accepted (pre-pend with AUTH_): - VIEW, READ, POST, REPLY, EDIT, DELETE, STICKY, ANNOUNCE, VOTE, POLLCREATE - - Possible options ($type/module_id combinations): - - * If you include a type and module_id then a specific lookup will be done and - the single result returned - - * If you set type to AUTH_ALL and specify a module_id an array of all auth types - will be returned - - * If you provide a module_id a specific lookup on that module will be done - - * If you set module_id to AUTH_LIST_ALL and specify a type an array listing the - results for all modules will be returned - - * If you set module_id to AUTH_LIST_ALL and type to AUTH_ALL a multidimensional - array containing the auth permissions for all types and all modules for that - user is returned - - All results are returned as associative arrays, even when a single auth type is - specified. ! If available you can send an array (either one or two dimensional) containing the ! module auth levels, this will prevent the auth function having to do its own ! lookup ! */ ! function block_auth( $type, $module_id, $userdata, $f_access = '', $f_access_group = '' ) { global $db, $lang; ! switch ( $type ) { // case AUTH_ALL: // $a_sql = 'a.auth_view, a.auth_edit, a.auth_delete'; // $a_sql_groups = 'a.auth_view_group, a.auth_edit_group, a.auth_delete_group'; ! // $auth_fields = array( 'auth_view', 'auth_edit', 'auth_delete' ); ! // $auth_fields_groups = array( 'auth_view_group', 'auth_edit_group', 'auth_delete_group' ); // break; --- 25,72 ---- * - page_auth * - menu_auth * - get_auth_forum ! * - mx_auth_group ! * - mx_get_groups */ ! /********************************************************************************\ ! | $type's accepted (pre-pend with AUTH_): ! | VIEW, READ, POST, REPLY, EDIT, DELETE, STICKY, ANNOUNCE, VOTE, POLLCREATE ! | ! | Possible options ($type/module_id combinations): ! | ! | * If you include a type and module_id then a specific lookup will be done and ! | the single result returned ! | ! | * If you set type to AUTH_ALL and specify a module_id an array of all auth types ! | will be returned ! | ! | * If you provide a module_id a specific lookup on that module will be done ! | ! | * If you set module_id to AUTH_LIST_ALL and specify a type an array listing the ! | results for all modules will be returned ! | ! | * If you set module_id to AUTH_LIST_ALL and type to AUTH_ALL a multidimensional ! | array containing the auth permissions for all types and all modules for that ! | user is returned ! | ! | All results are returned as associative arrays, even when a single auth type is ! | specified. ! | ! | If available you can send an array (either one or two dimensional) containing the ! | module auth levels, this will prevent the auth function having to do its own ! | lookup ! \********************************************************************************/ ! function block_auth($type, $module_id, $userdata, $f_access = '', $f_access_group = '') { global $db, $lang; ! switch( $type ) { // case AUTH_ALL: // $a_sql = 'a.auth_view, a.auth_edit, a.auth_delete'; // $a_sql_groups = 'a.auth_view_group, a.auth_edit_group, a.auth_delete_group'; ! // $auth_fields = array('auth_view', 'auth_edit', 'auth_delete'); ! // $auth_fields_groups = array('auth_view_group', 'auth_edit_group', 'auth_delete_group'); // break; *************** *** 74,79 **** $a_sql = 'a.auth_view'; $a_sql_groups = 'a.auth_view_group'; ! $auth_fields = array( 'auth_view' ); ! $auth_fields_groups = array( 'auth_view_group' ); break; --- 74,79 ---- $a_sql = 'a.auth_view'; $a_sql_groups = 'a.auth_view_group'; ! $auth_fields = array('auth_view'); ! $auth_fields_groups = array('auth_view_group'); break; *************** *** 81,86 **** $a_sql = 'a.auth_edit'; $a_sql_groups = 'a.auth_edit_group'; ! $auth_fields = array( 'auth_edit' ); ! $auth_fields_groups = array( 'auth_edit_group' ); break; --- 81,86 ---- $a_sql = 'a.auth_edit'; $a_sql_groups = 'a.auth_edit_group'; ! $auth_fields = array('auth_edit'); ! $auth_fields_groups = array('auth_edit_group'); break; *************** *** 88,93 **** $a_sql = 'a.auth_delete'; $a_sql_groups = 'a.auth_delete_group'; ! $auth_fields = array( 'auth_delete' ); ! $auth_fields_groups = array( 'auth_delete_group' ); break; --- 88,93 ---- $a_sql = 'a.auth_delete'; $a_sql_groups = 'a.auth_delete_group'; ! $auth_fields = array('auth_delete'); ! $auth_fields_groups = array('auth_delete_group'); break; *************** *** 96,102 **** } ! if ( $module_id == 0 ) { ! if ( $userdata['user_level'] == ADMIN && $userdata['session_logged_in'] ) { $auth_user[$auth_fields[0]] = 1; --- 96,102 ---- } ! if( $module_id == 0 ) { ! if( $userdata['user_level'] == ADMIN && $userdata['session_logged_in'] ) { $auth_user[$auth_fields[0]] = 1; *************** *** 111,156 **** } ! $is_admin = ( $userdata['user_level'] == ADMIN && $userdata['session_logged_in'] ) ? true : 0; $auth_user = array(); ! for( $i = 0; $i < count( $auth_fields ); $i++ ) { $key = $auth_fields[$i]; $key_groups = $auth_fields_groups[$i]; // If the user is logged on and the module type is either ALL or REG then the user has access // If the type if ACL, MOD or ADMIN then we need to see if the user has specific permissions // to do whatever it is they want to do ... to do this we pull relevant information for the // user (and any groups they belong to) // Now we compare the users access level against the modules. We assume here that a moderator // and admin automatically have access to an ACL module, similarly we assume admins meet an // auth requirement of MOD $value = $f_access[$key]; // $value_groups = $f_access_group[$key_groups]; $value_groups = $f_access_group; ! switch ( $value ) { case AUTH_ALL: ! $auth_user[$key] = true; $auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; break; case AUTH_REG: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? true : 0; $auth_user[$key . '_type'] = $lang['Auth_Registered_Users']; break; case AUTH_ANONYMOUS: ! $auth_user[$key] = ( ! $userdata['session_logged_in'] ) ? true : 0; $auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; break; case AUTH_ACL: // PRIVATE ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_auth_group( $value_groups ) || $is_admin : 0; $auth_user[$key . '_type'] = $lang['Auth_Users_granted_access']; break; case AUTH_MOD: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_auth_group( $f_access_group['auth_moderator_group'] ) || $is_admin : 0; $auth_user[$key . '_type'] = $lang['Auth_Moderators']; break; --- 111,160 ---- } ! $is_admin = ( $userdata['user_level'] == ADMIN && $userdata['session_logged_in'] ) ? TRUE : 0; $auth_user = array(); ! for( $i = 0; $i < count($auth_fields); $i++ ) { $key = $auth_fields[$i]; $key_groups = $auth_fields_groups[$i]; + // // If the user is logged on and the module type is either ALL or REG then the user has access + // // If the type if ACL, MOD or ADMIN then we need to see if the user has specific permissions // to do whatever it is they want to do ... to do this we pull relevant information for the // user (and any groups they belong to) + // // Now we compare the users access level against the modules. We assume here that a moderator // and admin automatically have access to an ACL module, similarly we assume admins meet an // auth requirement of MOD + // $value = $f_access[$key]; // $value_groups = $f_access_group[$key_groups]; $value_groups = $f_access_group; ! switch( $value ) { case AUTH_ALL: ! $auth_user[$key] = TRUE; $auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; break; case AUTH_REG: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? TRUE : 0; $auth_user[$key . '_type'] = $lang['Auth_Registered_Users']; break; case AUTH_ANONYMOUS: ! $auth_user[$key] = ( ! $userdata['session_logged_in'] ) ? TRUE : 0; $auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; break; case AUTH_ACL: // PRIVATE ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_auth_group($value_groups) || $is_admin : 0; $auth_user[$key . '_type'] = $lang['Auth_Users_granted_access']; break; case AUTH_MOD: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_auth_group($f_access_group['auth_moderator_group']) || $is_admin : 0; $auth_user[$key . '_type'] = $lang['Auth_Moderators']; break; *************** *** 166,176 **** } } // Is user a moderator? ! $auth_user['auth_mod'] = ( $userdata['session_logged_in'] ) ? mx_auth_group( $f_access_group['auth_moderator_group'] ) || $is_admin : 0; return $auth_user; } ! function page_auth( $type, $userdata, $f_access = '', $f_access_group = '' ) { global $db, $lang; --- 170,186 ---- } } + + // // Is user a moderator? ! // ! $auth_user['auth_mod'] = ( $userdata['session_logged_in'] ) ? mx_auth_group($f_access_group['auth_moderator_group']) || $is_admin : 0; return $auth_user; } ! /********************************************************************************\ ! | ! \********************************************************************************/ ! function page_auth($type, $userdata, $f_access = '', $f_access_group = '') { global $db, $lang; *************** *** 178,220 **** $a_sql = 'a.auth_view'; $a_sql_groups = 'a.auth_view_group'; ! $auth_fields = array( 'auth_view' ); ! $auth_fields_groups = array( 'auth_view_group' ); ! ! $is_admin = ( $userdata['user_level'] == ADMIN && $userdata['session_logged_in'] ) ? true : 0; $auth_user = array(); ! for( $i = 0; $i < count( $auth_fields ); $i++ ) { $key = $auth_fields[$i]; $key_groups = $auth_fields_groups[$i]; ! $value = $f_access[$key]; // $value_groups = $f_access_group[$key_groups]; $value_groups = $f_access_group; ! ! switch ( $value ) { case AUTH_ALL: ! $auth_user[$key] = true; $auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; break; case AUTH_REG: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? true : 0; $auth_user[$key . '_type'] = $lang['Auth_Registered_Users']; break; case AUTH_ANONYMOUS: ! $auth_user[$key] = ( ! $userdata['session_logged_in'] ) ? true : 0; $auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; break; ! case AUTH_ACL: // PRIVATE ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_auth_group( $value_groups ) || $is_admin : 0; $auth_user[$key . '_type'] = $lang['Auth_Users_granted_access']; break; case AUTH_MOD: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_auth_group( $f_access_group['auth_moderator_group'] ) || $is_admin : 0; $auth_user[$key . '_type'] = $lang['Auth_Moderators']; break; --- 188,230 ---- $a_sql = 'a.auth_view'; $a_sql_groups = 'a.auth_view_group'; ! $auth_fields = array('auth_view'); ! $auth_fields_groups = array('auth_view_group'); ! ! $is_admin = ( $userdata['user_level'] == ADMIN && $userdata['session_logged_in'] ) ? TRUE : 0; $auth_user = array(); ! for( $i = 0; $i < count($auth_fields); $i++ ) { $key = $auth_fields[$i]; $key_groups = $auth_fields_groups[$i]; ! $value = $f_access[$key]; // $value_groups = $f_access_group[$key_groups]; $value_groups = $f_access_group; ! ! switch( $value ) { case AUTH_ALL: ! $auth_user[$key] = TRUE; $auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; break; case AUTH_REG: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? TRUE : 0; $auth_user[$key . '_type'] = $lang['Auth_Registered_Users']; break; case AUTH_ANONYMOUS: ! $auth_user[$key] = ( ! $userdata['session_logged_in'] ) ? TRUE : 0; $auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; break; ! case AUTH_ACL: // PRIVATE ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_auth_group($value_groups) || $is_admin : 0; $auth_user[$key . '_type'] = $lang['Auth_Users_granted_access']; break; case AUTH_MOD: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_auth_group($f_access_group['auth_moderator_group']) || $is_admin : 0; $auth_user[$key . '_type'] = $lang['Auth_Moderators']; break; *************** *** 230,299 **** } } // Is user a moderator? ! $auth_user['auth_mod'] = ( $userdata['session_logged_in'] ) ? mx_auth_group( $f_access_group['auth_moderator_group'] ) || $is_admin : 0; return $auth_user; } ! // ************************************************************************** ! function menu_auth( $type, $menu_id, $userdata, $f_access = '', $f_access_group = '' ) { global $db, $lang; ! switch ( $type ) { case AUTH_ALL: $a_sql = 'a.auth_view'; ! $auth_fields = array( 'auth_view' ); break; case AUTH_VIEW: $a_sql = 'a.auth_view'; ! $auth_fields = array( 'auth_view' ); break; default: break; ! } // If f_access has been passed, or auth is needed to return an array of menus // then we need to pull the auth information on the given menu (or all menus) ! $is_admin = ( $userdata['user_level'] == ADMIN && $userdata['session_logged_in'] ) ? true : 0; $auth_user = array(); ! for( $i = 0; $i < count( $auth_fields ); $i++ ) { $key = $auth_fields[$i]; // If the user is logged on and the menu type is either ALL or REG then the user has access // If the type if ACL, MOD or ADMIN then we need to see if the user has specific permissions // to do whatever it is they want to do ... to do this we pull relevant information for the // user (and any groups they belong to) // Now we compare the users access level against the menus. We assume here that a moderator // and admin automatically have access to an ACL menu, similarly we assume admins meet an // auth requirement of MOD $value = $f_access[$key]; ! switch ( $value ) { case AUTH_ALL: ! $auth_user[$key] = true; $auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; break; case AUTH_REG: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? true : 0; $auth_user[$key . '_type'] = $lang['Auth_Registered_Users']; break; case AUTH_ANONYMOUS: ! $auth_user[$key] = ( ! $userdata['session_logged_in'] ) ? true : 0; $auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; break; case AUTH_ACL: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_auth_group( $f_access_group ) || $is_admin : 0; $auth_user[$key . '_type'] = $lang['Auth_Users_granted_access']; break; case AUTH_MOD: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_auth_group( $f_access_group ) || $is_admin : 0; $auth_user[$key . '_type'] = $lang['Auth_Moderators']; break; --- 240,323 ---- } } + + // // Is user a moderator? ! // ! $auth_user['auth_mod'] = ( $userdata['session_logged_in'] ) ? mx_auth_group($f_access_group['auth_moderator_group']) || $is_admin : 0; return $auth_user; } ! ! /********************************************************************************\ ! | ! \********************************************************************************/ ! function menu_auth($type, $menu_id, $userdata, $f_access = '', $f_access_group = '') { global $db, $lang; ! switch( $type ) { case AUTH_ALL: $a_sql = 'a.auth_view'; ! $auth_fields = array('auth_view'); break; case AUTH_VIEW: $a_sql = 'a.auth_view'; ! $auth_fields = array('auth_view'); break; default: break; ! } ! ! // // If f_access has been passed, or auth is needed to return an array of menus // then we need to pull the auth information on the given menu (or all menus) ! // ! $is_admin = ( $userdata['user_level'] == ADMIN && $userdata['session_logged_in'] ) ? TRUE : 0; $auth_user = array(); ! for( $i = 0; $i < count($auth_fields); $i++ ) { $key = $auth_fields[$i]; + + // // If the user is logged on and the menu type is either ALL or REG then the user has access + // // If the type if ACL, MOD or ADMIN then we need to see if the user has specific permissions // to do whatever it is they want to do ... to do this we pull relevant information for the // user (and any groups they belong to) + // // Now we compare the users access level against the menus. We assume here that a moderator // and admin automatically have access to an ACL menu, similarly we assume admins meet an // auth requirement of MOD + // $value = $f_access[$key]; ! switch( $value ) { case AUTH_ALL: ! $auth_user[$key] = TRUE; $auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; break; case AUTH_REG: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? TRUE : 0; $auth_user[$key . '_type'] = $lang['Auth_Registered_Users']; break; case AUTH_ANONYMOUS: ! $auth_user[$key] = ( ! $userdata['session_logged_in'] ) ? TRUE : 0; $auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; break; case AUTH_ACL: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_auth_group($f_access_group) || $is_admin : 0; $auth_user[$key . '_type'] = $lang['Auth_Users_granted_access']; break; case AUTH_MOD: ! $auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_auth_group($f_access_group) || $is_admin : 0; $auth_user[$key . '_type'] = $lang['Auth_Moderators']; break; *************** *** 309,464 **** } } // Is user a moderator? ! // $auth_user['auth_mod'] = ( $userdata['session_logged_in'] ) ? mx_auth_group( $f_access_group ) || $is_admin : 0; return $auth_user; } ! // New optimized get_auth_forum ! // Credits to Markus_Petrux :-) ! function get_auth_forum( $mode = 'phpbb' ) { global $userdata, $mx_root_path, $phpEx; ! switch ( $mode ) { ! case 'phpbb': ! ! // Try to reuse auth_view query result. ! $userdata_key = 'mx_get_auth_forum' . $userdata['user_id']; ! if ( !empty( $userdata[$userdata_key] ) ) ! { ! $auth_data_sql = $userdata[$userdata_key]; ! return $auth_data_sql; ! } ! // Now, this tries to optimize DB access involved in auth(), ! // passing AUTH_LIST_ALL will load info for all forums at once. ! $is_auth_ary = auth( AUTH_VIEW, AUTH_LIST_ALL, $userdata ); ! // Loop through the list of forums to retrieve the ids for ! // those with AUTH_VIEW allowed. ! $auth_data_sql = ''; ! foreach( $is_auth_ary as $fid => $is_auth_row ) ! { ! if ( $is_auth_row['auth_view'] ) ! { ! $auth_data_sql .= ( $auth_data_sql != '' ) ? ', ' . $fid : $fid; ! } ! } ! ! if ( empty( $auth_data_sql ) ) ! { ! $auth_data_sql = -1; ! } ! $userdata[$userdata_key] = $auth_data_sql; ! return $auth_data_sql; ! break; ! ! case 'kb': ! ! // Try to reuse auth_view query result. ! $userdata_key = 'mx_get_auth_kb' . $userdata['user_id']; ! if ( !empty( $userdata[$userdata_key] ) ) ! { ! $auth_data_sql = $userdata[$userdata_key]; ! return $auth_data_sql; ! } ! // Now, this tries to optimize DB access involved in auth(), ! // passing AUTH_LIST_ALL will load info for all forums at once. ! ! include_once( $mx_root_path . 'modules/mx_kb/includes/functions_kb_auth.' . $phpEx ); ! $is_auth_ary = kb_auth( AUTH_VIEW, AUTH_LIST_ALL, $userdata ); ! // Loop through the list of forums to retrieve the ids for ! // those with AUTH_VIEW allowed. ! $auth_data_sql = ''; ! foreach( $is_auth_ary as $fid => $is_auth_row ) ! { ! if ( $is_auth_row['auth_view'] ) ! { ! $auth_data_sql .= ( $auth_data_sql != '' ) ? ', ' . $fid : $fid; ! } ! } ! ! if ( empty( $auth_data_sql ) ) ! { ! $auth_data_sql = -1; ! } ! $userdata[$userdata_key] = $auth_data_sql; ! return $auth_data_sql; ! break; ! default: ! //nothing ! break; ! } ! } ! // Validates if user belongs to group included in group_ids list ! // Also, adds all usergroups to userdata array ! function mx_auth_group( $group_ids = '', $group_mod_mode = false ) { global $userdata, $db; ! ! if ( $group_ids == '' ) { return false; } ! $group_ids_array = explode(",", $group_ids); ! ! // Try to reuse usergroups result. ! if ( $group_mod_mode ) ! { ! $userdata_key = 'mx_usergroups_mod' . $userdata['user_id']; ! if ( empty( $userdata[$userdata_key] ) ) ! { ! // Check if user is group moderator.. ! $sql = "SELECT gr.group_id ! FROM " . GROUPS_TABLE . " gr, ! " . USER_GROUP_TABLE . " ugr ! WHERE gr.group_id = ugr.group_id ! AND gr.group_moderator = '" . $userdata['user_id'] . "' ! AND ugr.user_pending = '0' "; ! ! if ( !( $result = $db->sql_query( $sql ) ) ) ! { ! message_die( GENERAL_ERROR, "Could not query group rights information", '', '', '', '' ); ! } ! ! $group_row = $db->sql_fetchrowset( $result ); ! ! $userdata[$userdata_key_mod] = $group_row; ! } ! } ! else { ! $userdata_key = 'mx_usergroups' . $userdata['user_id']; ! ! if ( empty( $userdata[$userdata_key] ) ) { ! // Check if user is member of the proper group.. ! $sql = "SELECT group_id FROM " . USER_GROUP_TABLE . " WHERE user_id='" . $userdata['user_id'] . "' AND user_pending = 0"; ! ! if ( !( $result = $db->sql_query( $sql ) ) ) ! { ! message_die( GENERAL_ERROR, "Could not query group rights information", '', '', '', '' ); ! } ! ! $group_row = $db->sql_fetchrowset( $result ); ! ! $userdata[$userdata_key] = $group_row; ! } } ! ! for ( $i = 0; $i < count( $userdata[$userdata_key] ); $i++ ) { ! if ( in_array( $userdata[$userdata_key][$i]['group_id'], $group_ids_array ) ) { ! $is_member = true; ! return $is_member; } ! } ! ! return false; } ?> \ No newline at end of file --- 333,478 ---- } } + + // // Is user a moderator? ! // ! // $auth_user['auth_mod'] = ( $userdata['session_logged_in'] ) ? mx_auth_group($f_access_group) || $is_admin : 0; return $auth_user; } ! /********************************************************************************\ ! | New optimized get_auth_forum ! | Credits to Markus_Petrux :-) ! \********************************************************************************/ ! function get_auth_forum($mode = 'phpbb') { global $userdata, $mx_root_path, $phpEx; ! // ! // Try to reuse auth_view query result. ! // ! $userdata_key = 'mx_get_auth_' . $mode . $userdata['user_id']; ! if( !empty($userdata[$userdata_key]) ) { ! $auth_data_sql = $userdata[$userdata_key]; ! return $auth_data_sql; ! } ! ! // ! // Now, this tries to optimize DB access involved in auth(), ! // passing AUTH_LIST_ALL will load info for all forums at once. ! // ! if( $mode = 'kb' ) ! { ! include_once($mx_root_path . 'modules/mx_kb/includes/functions_kb_auth.' . $phpEx); ! $auth_func = 'kb_auth'; ! } ! else ! { ! $auth_func = 'auth'; ! } ! $is_auth_ary = $auth_func(AUTH_VIEW, AUTH_LIST_ALL, $userdata); ! ! // ! // Loop through the list of forums to retrieve the ids for ! // those with AUTH_VIEW allowed. ! // ! $auth_data_sql = ''; ! foreach( $is_auth_ary as $fid => $is_auth_row ) ! { ! if( $is_auth_row['auth_view'] ) ! { ! $auth_data_sql .= ( $auth_data_sql != '' ) ? ', ' . $fid : $fid; ! } ! } ! ! if( empty($auth_data_sql) ) ! { ! $auth_data_sql = -1; ! } ! ! $userdata[$userdata_key] = $auth_data_sql; ! return $auth_data_sql; } ! /********************************************************************************\ ! | Validates if user belongs to group included in group_ids list ! | Also, adds all usergroups to userdata array ! \********************************************************************************/ ! function mx_auth_group($group_ids = '', $group_mod_mode = false) { global $userdata, $db; ! ! if( empty($group_ids) ) { return false; } ! // ! // Try to reuse group_id results. ! // ! $userdata_key = 'mx_usergroups' . ( $group_mod_mode ? '_mod' : '' ) . $userdata['user_id']; ! if( empty($userdata[$userdata_key]) ) { ! if( $group_mod_mode ) // Get the groups the user is moderator of. { ! $sql = "SELECT group_id FROM " . GROUPS_TABLE . " ! WHERE group_moderator = '" . $userdata['user_id'] . "' AND group_single_user = 0"; ! } ! else // Get the groups the user is member of. ! { ! $sql = "SELECT group_id FROM " . USER_GROUP_TABLE . " ! WHERE user_id = '" . $userdata['user_id'] . "' AND user_pending = 0"; ! } ! if ( !($result = $db->sql_query($sql)) ) ! { ! mx_message_die(GENERAL_ERROR, "Could not query group rights information"); ! } ! $userdata[$userdata_key] = $db->sql_fetchrowset($result); } ! ! $group_ids_array = explode(',', $group_ids); ! ! for( $i = 0; $i < count($userdata[$userdata_key]); $i++ ) { ! if( in_array($userdata[$userdata_key][$i]['group_id'], $group_ids_array) ) { ! return true; } ! } ! return false; ! } ! ! /********************************************************************************\ ! | ! \********************************************************************************/ ! function mx_get_groups($sel_id, $field_entry = 'auth_view_group') ! { ! global $db, $lang; ! ! $sql = "SELECT group_id, group_name ! FROM " . GROUPS_TABLE . " ! WHERE group_single_user <> " . TRUE . " ! ORDER BY group_name"; ! ! if( !($result = $db->sql_query($sql)) ) ! { ! message_die(GENERAL_ERROR, "Couldn't get list of groups", '', __LINE__, __FILE__, $sql); ! } ! ! $grouplist = '<select name="'.$field_entry.'">'; ! $grouplist .= '<option value="0">' . $lang['Select_group'] . '</option>'; ! ! while( $row = $db->sql_fetchrow($result) ) ! { ! $selected = ( $sel_id == $row['group_id'] ? ' selected="selected"' : '' ); ! $grouplist .= '<option value="' .$row['group_id'] . '"' . $selected . '>' . $row['group_name'] . '</option>'; ! } ! ! $grouplist .= '</select>'; ! return $grouplist; } + ?> \ No newline at end of file Index: mx_functions.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/mx_functions.php,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** mx_functions.php 24 Apr 2005 21:33:36 -0000 1.38 --- mx_functions.php 25 Apr 2005 01:27:20 -0000 1.39 *************** *** 36,40 **** * - post_icons * - get_page_id - * - mx_get_groups * - mx_add_search_words * - mx_remove_search_post --- 36,39 ---- *************** *** 48,54 **** */ ! // ****************************************************************** ! // ! // ****************************************************************** function get_info($table, $idfield = '', $id = 0, $idfield2 = '', $id2 = 0) { --- 47,53 ---- */ ! /********************************************************************************\ ! | ! \********************************************************************************/ function get_info($table, $idfield = '', $id = 0, $idfield2 = '', $id2 = 0) { *************** *** 68,74 **** } ! // ****************************************************************** ! // ! // ****************************************************************** function get_old_items($table, $idfield = '', $id = 0, $idfield2 = '', $item_ids = array()) { --- 67,73 ---- } ! /********************************************************************************\ ! | ! \********************************************************************************/ function get_old_items($table, $idfield = '', $id = 0, $idfield2 = '', $item_ids = array()) { *************** *** 94,100 **** } ! // ****************************************************************** ! // ! // ****************************************************************** function get_exists($table, $idfield = '', $id = 0) { --- 93,99 ---- } ! /********************************************************************************\ ! | ! \********************************************************************************/ function get_exists($table, $idfield = '', $id = 0) { *************** *** 115,121 **** } ! // ****************************************************************** ! // ! // ****************************************************************** function get_list($name_select, $table, $idfield, $namefield, $id, $select = false, $idfield2 = '' , $id2 = '') { --- 114,120 ---- } ! /********************************************************************************\ ! | ! \********************************************************************************/ function get_list($name_select, $table, $idfield, $namefield, $id, $select = false, $idfield2 = '' , $id2 = '') { *************** *** 151,157 **** } ! // ****************************************************************** ! // ! // ****************************************************************** function get_mx_select_list($type = 'includex', $id, $name_select) { --- 150,156 ---- } ! /********************************************************************************\ ! | ! \********************************************************************************/ function get_mx_select_list($type = 'includex', $id, $name_select) { *************** *** 178,192 **** } ! /* function get_list_formatted() ! --------------------------------------------------------------------------------------------------------------- ! This function creates a drop down select menu, either for pages, functions or blocks. ! The block dropdown may also be filtered for specific functions (by passing the function file) ! ! $type: 'page_list', 'function_list', 'block_list' or 'dyn_block_list' (core 2.8) ! $id: selected id ! $name_select: the name id for the select form ! $function_file: for filtering blocklists ! --------------------------------------------------------------------------------------------------------------- ! --------------------------------------------------------------------------------------------------------------- */ function get_list_formatted($type, $id, $name_select = '', $function_file = '') { --- 177,191 ---- } ! /********************************************************************************\ ! | function get_list_formatted() ! | ------------------------------------------------------------------------------- ! | This function creates a drop down select menu, either for pages, functions or blocks. ! | The block dropdown may also be filtered for specific functions (by passing the function file) ! | ! | $type: 'page_list', 'function_list', 'block_list' or 'dyn_block_list' (core 2.8) ! | $id: selected id ! | $name_select: the name id for the select form ! | $function_file: for filtering blocklists ! \********************************************************************************/ function get_list_formatted($type, $id, $name_select = '', $function_file = '') { *************** *** 314,320 **** } ! // ****************************************************************** ! // ! // ****************************************************************** function get_list_static($name_select, $row, $id) { --- 313,319 ---- } ! /********************************************************************************\ ! | ! \********************************************************************************/ function get_list_static($name_select, $row, $id) { *************** *** 333,339 **** } ! // ****************************************************************** ! // ! // ****************************************************************** function get_list_multiple($name_select, $table, $idfield, $namefield, $id_list, $select) { --- 332,338 ---- } ! /********************************************************************************\ ! | ! \********************************************************************************/ function get_list_multiple($name_select, $table, $idfield, $namefield, $id_list, $select) { *************** *** 370,376 **** } ! // ****************************************************************** ! // ! // ****************************************************************** function get_list_opt($name_select, $table, $idfield, $namefield, $id, $select) { --- 369,375 ---- } ! /********************************************************************************\ ! | ! \********************************************************************************/ function get_list_opt($name_select, $table, $idfield, $namefield, $id, $select) { *************** *** 405,411 **** } ! // ****************************************************************** ! // Pick a poll list combo, ! // ****************************************************************** function poll_select($default_poll, $select_name = 'Poll_Topic_id') { --- 404,410 ---- } ! /********************************************************************************\ ! | Pick a poll list combo ! \********************************************************************************/ function poll_select($default_poll, $select_name = 'Poll_Topic_id') { *************** *** 435,441 **** } ! // ****************************************************************** ! // ! // ****************************************************************** function mx_url() { --- 434,440 ---- } ! /********************************************************************************\ ! | ! \********************************************************************************/ function mx_url() { *************** *** 504,512 **** } ! // ****************************************************************** ! // MX add-on ! // Generate paths for page and standalone mode ! // ...function based on original function written by Markus :-) ! // ****************************************************************** function mx_this_url( $args = '', $force_standalone_mode = false, $file = '' ) { --- 503,511 ---- } ! /********************************************************************************\ ! | MX add-on ! | Generate paths for page and standalone mode ! | ...function based on original function written by Markus :-) ! \********************************************************************************/ function mx_this_url( $args = '', $force_standalone_mode = false, $file = '' ) { *************** *** 532,537 **** } ! // Generate icon lists ! // Snatched frompafilDB function post_icons( $icon_dir = '', $file_posticon = '', $modules_path = '' ) { --- 531,538 ---- } ! /********************************************************************************\ ! | Generate icon lists ! | Snatched frompafilDB ! \********************************************************************************/ function post_icons( $icon_dir = '', $file_posticon = '', $modules_path = '' ) { *************** *** 590,602 **** } ! /* function get_page_id() ! --------------------------------------------------------------------------------------------------------------- ! This function fill find the page on which a block is located, provided a block_id. First instance found is returned. ! Eg: get_page_id( $block_id ) ! ! If no block_id is available you can find the page provided the function file. First instance found is returned. ! Eg: get_page_id( 'dload.php', true ) ! --------------------------------------------------------------------------------------------------------------- ! --------------------------------------------------------------------------------------------------------------- */ function get_page_id($search_item, $use_function_file = false) { --- 591,605 ---- } ! /********************************************************************************\ ! | function get_page_id() ! | ------------------------------------------------------------------------------- ! | This function fill find the page on which a block is located, provided a block_id. ! | First instance found is returned. ! | Eg: get_page_id( $block_id ) ! | ! | If no block_id is available you can find the page provided the function file. ! | First instance found is returned. ! | Eg: get_page_id('dload.php', true) ! \********************************************************************************/ function get_page_id($search_item, $use_function_file = false) { *************** *** 668,700 **** } - function mx_get_groups($sel_id, $field_entry = 'auth_view_group') - { - global $db, $lang; ! $sql = "SELECT group_id, group_name ! FROM " . GROUPS_TABLE . " ! WHERE group_single_user <> " . TRUE . " ! ORDER BY group_name"; ! ! if( !($result = $db->sql_query($sql)) ) ! { ! message_die(GENERAL_ERROR, "Couldn't get list of groups", '', __LINE__, __FILE__, $sql); ! } ! ! $grouplist = '<select name="'.$field_entry.'">'; ! $grouplist .= '<option value="0">' . $lang['Select_group'] . '</option>'; ! ! while( $row = $db->sql_fetchrow($result) ) ! { ! $selected = ( $sel_id == $row['group_id'] ? ' selected="selected"' : '' ); ! $grouplist .= '<option value="' .$row['group_id'] . '"' . $selected . '>' . $row['group_name'] . '</option>'; ! } ! ! $grouplist .= '</select>'; ! return $grouplist; ! } ! ! ! // Add search words for blocks function mx_add_search_words($mode, $post_id, $post_text, $post_title = '', $mx_mode = 'mx') { --- 671,678 ---- } ! /********************************************************************************\ ! | Add search words for blocks ! \********************************************************************************/ function mx_add_search_words($mode, $post_id, $post_text, $post_title = '', $mx_mode = 'mx') { *************** *** 873,876 **** --- 851,857 ---- } + /********************************************************************************\ + | + \********************************************************************************/ function mx_remove_search_post($post_id_sql, $mx_mode = 'mx') { *************** *** 974,977 **** --- 955,961 ---- } + /********************************************************************************\ + | + \********************************************************************************/ function qsort_multiarray($array, $num = 0, $order = 'ASC', $left = 0, $right = -1) { *************** *** 1012,1015 **** --- 996,1002 ---- } + /********************************************************************************\ + | + \********************************************************************************/ function compose_mx_copy() { *************** *** 1044,1051 **** ! // -------------------------------------------------------------------------------- ! // Class: mx_request_vars ! // Encapsulate several functions related to GET/POST variables. ! // // --- 1031,1038 ---- ! /********************************************************************************\ ! | Class: mx_request_vars ! | Encapsulate several functions related to GET/POST variables. ! \********************************************************************************/ // |