|
From: Jon O. <jon...@us...> - 2005-05-26 21:54:16
|
Update of /cvsroot/mxbb/core27x/includes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4750/core27x/includes Modified Files: mx_constants.php mx_functions.php template.php Added Files: mx_auth.php mx_cache.php mx_functions_phpbb.php Log Message: massive commit, for 2.7.7 http://www.mx-system.com/forum/viewtopic.php?t=6902 --- NEW FILE: mx_auth.php --- <?php /** ------------------------------------------------------------------------ * subject : mx-portal, CMS & portal * begin : june, 2002 * copyright : (C) 2002-2005 MX-System * email : jon...@ho... * project site : www.mx-system.com * * description : * ------------------------------------------------------------------------- * * $Id: mx_auth.php,v 1.1 2005/05/26 21:54:08 jonohlsson Exp $ */ /** * 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 * the Free Software Foundation; either version 2 of the License', or * ('at your option) any later version. */ /** * Included functions in this file: * - block_auth * - 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; case AUTH_VIEW: $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; case AUTH_EDIT: $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; case AUTH_DELETE: $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; default: break; } if( $module_id == 0 ) { if( $userdata['user_level'] == ADMIN && $userdata['session_logged_in'] ) { $auth_user[$auth_fields[0]] = 1; $auth_user[$auth_fields[0] . '_type'] = $lang['Auth_Moderators']; } else { $auth_user[$auth_fields[0]] = 0; $auth_user[$auth_fields[0] . '_type'] = $lang['Auth_Moderators']; } return $auth_user; } $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_is_group_member($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_is_group_member($f_access_group['auth_moderator_group']) || $is_admin : 0; $auth_user[$key . '_type'] = $lang['Auth_Moderators']; break; case AUTH_ADMIN: $auth_user[$key] = $is_admin; $auth_user[$key . '_type'] = $lang['Auth_Administrators']; break; default: $auth_user[$key] = 0; break; } } // // Is user a moderator? $auth_user['auth_mod'] = ( $userdata['session_logged_in'] ) ? mx_is_group_member($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; $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_is_group_member($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_is_group_member($f_access_group['auth_moderator_group']) || $is_admin : 0; $auth_user[$key . '_type'] = $lang['Auth_Moderators']; break; case AUTH_ADMIN: $auth_user[$key] = $is_admin; $auth_user[$key . '_type'] = $lang['Auth_Administrators']; break; default: $auth_user[$key] = 0; break; } } // // Is user a moderator? $auth_user['auth_mod'] = ( $userdata['session_logged_in'] ) ? mx_is_group_member($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_is_group_member($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_is_group_member($f_access_group) || $is_admin : 0; $auth_user[$key . '_type'] = $lang['Auth_Moderators']; break; case AUTH_ADMIN: $auth_user[$key] = $is_admin; $auth_user[$key . '_type'] = $lang['Auth_Administrators']; break; default: $auth_user[$key] = 0; break; } } // // Is user a moderator? // $auth_user['auth_mod'] = ( $userdata['session_logged_in'] ) ? mx_is_group_member($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_is_group_member($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; } ?> Index: template.php =================================================================== RCS file: /cvsroot/mxbb/core27x/includes/template.php,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** template.php 6 May 2005 06:47:58 -0000 1.1 --- template.php 26 May 2005 21:54:08 -0000 1.2 *************** *** 22,213 **** */ - /** - * Template class. By Nathan Codding of the phpBB group. - * The interface was originally inspired by PHPLib templates, - * and the template file formats are quite similar. - */ - - class Template - { - var $classname = "Template"; - // variable that holds all the data we'll be substituting into - // the compiled templates. - // ... - // This will end up being a multi-dimensional array like this: - // $this->_tpldata[block.][iteration#][child.][iteration#][child2.][iteration#][variablename] == value - // if it's a root-level variable, it'll be like this: - // $this->_tpldata[.][0][varname] == value - var $_tpldata = array(); - // Hash of filenames for each template handle. - var $files = array(); - // Root template directory. - var $root = ""; - // this will hash handle names to the compiled code for that handle. - var $compiled_code = array(); - // This will hold the uncompiled code for that handle. - var $uncompiled_code = array(); - - /** - * Constructor. Simply sets the root dir. - */ - function Template( $root = "." ) - { - $this->set_rootdir( $root ); - } - - /** - * Destroys this template object. Should be called when you're done with it, in order - * to clear out the template data so you can load/parse a new template set. - */ - function destroy() - { - $this->_tpldata = array(); - } - - /** - * Sets the template root directory for this Template object. - */ - function set_rootdir( $dir ) - { - if ( !is_dir( $dir ) ) - { - return false; - } - - $this->root = $dir; - return true; - } - - /** - * Sets the template filenames for handles. $filename_array - * should be a hash of handle => filename pairs. - */ - function set_filenames( $filename_array ) - { - if ( !is_array( $filename_array ) ) - { - return false; - } - - reset( $filename_array ); - while ( list( $handle, $filename ) = each( $filename_array ) ) - { - $this->files[$handle] = $this->make_filename( $filename ); - } - - return true; - } - - /** - * Load the file for the handle, compile the file, - * and run the compiled code. This will print out - * the results of executing the template. - */ - function pparse( $handle ) - { - if ( !$this->loadfile( $handle ) ) - { - die( "Template->pparse(): Couldn't load template file for handle $handle" ); - } - // actually compile the template now. - if ( !isset( $this->compiled_code[$handle] ) || empty( $this->compiled_code[$handle] ) ) - { - // Actually compile the code now. - $this->compiled_code[$handle] = $this->compile( $this->uncompiled_code[$handle] ); - } - // Run the compiled code. - eval( $this->compiled_code[$handle] ); - return true; - } - - /** - * Inserts the uncompiled code for $handle as the - * value of $varname in the root-level. This can be used - * to effectively include a template in the middle of another - * template. - * Note that all desired assignments to the variables in $handle should be done - * BEFORE calling this function. - */ - function assign_var_from_handle( $varname, $handle ) - { - if ( !$this->loadfile( $handle ) ) - { - die( "Template->assign_var_from_handle(): Couldn't load template file for handle $handle" ); - } - // Compile it, with the "no echo statements" option on. - $_str = ""; - $code = $this->compile( $this->uncompiled_code[$handle], true, '_str' ); - // evaluate the variable assignment. - eval( $code ); - // assign the value of the generated variable to the given varname. - $this->assign_var( $varname, $_str ); ! return true; ! } ! ! /** ! * Block-level variable assignment. Adds a new block iteration with the given ! * variable assignments. Note that this should only be called once per block ! * iteration. ! */ ! function assign_block_vars( $blockname, $vararray ) ! { ! if ( strstr( $blockname, '.' ) ) ! { ! // Nested block. ! $blocks = explode( '.', $blockname ); ! $blockcount = sizeof( $blocks ) - 1; ! $str = '$this->_tpldata'; ! for ( $i = 0; $i < $blockcount; $i++ ) ! { ! $str .= '[\'' . $blocks[$i] . '.\']'; ! eval( '$lastiteration = sizeof(' . $str . ') - 1;' ); ! $str .= '[' . $lastiteration . ']'; ! } ! // Now we add the block that we're actually assigning to. ! // We're adding a new iteration to this block with the given ! // variable assignments. ! $str .= '[\'' . $blocks[$blockcount] . '.\'][] = $vararray;'; ! // Now we evaluate this assignment we've built up. ! eval( $str ); ! } ! else ! { ! // Top-level block. ! // Add a new iteration to this block with the variable assignments ! // we were given. ! $this->_tpldata[$blockname . '.'][] = $vararray; ! } ! ! return true; ! } ! ! /** ! * Root-level variable assignment. Adds to current assignments, overriding ! * any existing variable assignment with the same name. ! */ ! function assign_vars( $vararray ) ! { ! reset ( $vararray ); ! while ( list( $key, $val ) = each( $vararray ) ) ! { ! $this->_tpldata['.'][0][$key] = $val; ! } - return true; - } /** ! * Root-level variable assignment. Adds to current assignments, overriding ! * any existing variable assignment with the same name. */ ! function assign_var( $varname, $varval ) { ! $this->_tpldata['.'][0][$varname] = $varval; ! ! return true; } /** * Generates a full path+filename for the given filename, which can either * be an absolute name, or a name relative to the rootdir for this Template --- 22,46 ---- */ ! // ! // Including phpBB version of the Template class ! // ! include_once($phpbb_root_path . "includes/template.$phpEx"); + class mx_Template extends Template + { /** ! * Constructor. Simply calling parent construtor. ! * This is required. Reason is constructors have different method names. */ ! function mx_Template( $root = "." ) { ! parent::Template($root); } /** + * This make_filename implementation overrides parent method. + * * Generates a full path+filename for the given filename, which can either * be an absolute name, or a name relative to the rootdir for this Template *************** *** 285,500 **** } ! /** ! * If not already done, load the file for the given handle and populate ! * the uncompiled_code[] hash with its code. Do not compile. ! */ ! function loadfile( $handle ) ! { ! // If the file for this handle is already loaded and compiled, do nothing. ! if ( isset( $this->uncompiled_code[$handle] ) && !empty( $this->uncompiled_code[$handle] ) ) ! { ! return true; ! } ! // If we don't have a file assigned to this handle, die. ! if ( !isset( $this->files[$handle] ) ) ! { ! die( "Template->loadfile(): No file specified for handle $handle" ); ! } ! ! $filename = $this->files[$handle]; ! ! $str = implode( "", @file( $filename ) ); ! if ( empty( $str ) ) ! { ! die( "Template->loadfile(): File $filename for handle $handle is empty" ); ! } ! ! $this->uncompiled_code[$handle] = $str; ! ! return true; ! } ! ! /** ! * Compiles the given string of code, and returns ! * the result in a string. ! * If "do_not_echo" is true, the returned code will not be directly ! * executable, but can be used as part of a variable assignment ! * for use in assign_code_from_handle(). ! */ ! function compile( $code, $do_not_echo = false, $retvar = '' ) ! { ! // replace \ with \\ and then ' with \'. ! $code = str_replace( '\\', '\\\\', $code ); ! $code = str_replace( '\'', '\\\'', $code ); ! // change template varrefs into PHP varrefs ! // This one will handle varrefs WITH namespaces ! $varrefs = array(); ! preg_match_all( '#\{(([a-z0-9\-_]+?\.)+?)([a-z0-9\-_]+?)\}#is', $code, $varrefs ); ! $varcount = sizeof( $varrefs[1] ); ! for ( $i = 0; $i < $varcount; $i++ ) ! { ! $namespace = $varrefs[1][$i]; ! $varname = $varrefs[3][$i]; ! $new = $this->generate_block_varref( $namespace, $varname ); ! ! $code = str_replace( $varrefs[0][$i], $new, $code ); ! } ! // This will handle the remaining root-level varrefs ! $code = preg_replace( '#\{([a-z0-9\-_]*?)\}#is', '\' . ( ( isset($this->_tpldata[\'.\'][0][\'\1\']) ) ? $this->_tpldata[\'.\'][0][\'\1\'] : \'\' ) . \'', $code ); ! // Break it up into lines. ! $code_lines = explode( "\n", $code ); ! ! $block_nesting_level = 0; ! $block_names = array(); ! $block_names[0] = "."; ! // Second: prepend echo ', append ' . "\n"; to each line. ! $line_count = sizeof( $code_lines ); ! for ( $i = 0; $i < $line_count; $i++ ) ! { ! $code_lines[$i] = chop( $code_lines[$i] ); ! if ( preg_match( '#<!-- BEGIN (.*?) -->#', $code_lines[$i], $m ) ) ! { ! $n[0] = $m[0]; ! $n[1] = $m[1]; ! // Added: dougk_ff7-Keeps templates from bombing if begin is on the same line as end.. I think. :) ! if ( preg_match( '#<!-- END (.*?) -->#', $code_lines[$i], $n ) ) ! { ! $block_nesting_level++; ! $block_names[$block_nesting_level] = $m[1]; ! if ( $block_nesting_level < 2 ) ! { ! // Block is not nested. ! $code_lines[$i] = '$_' . $n[1] . '_count = ( isset($this->_tpldata[\'' . $n[1] . '.\']) ) ? sizeof($this->_tpldata[\'' . $n[1] . '.\']) : 0;'; ! $code_lines[$i] .= "\n" . 'for ($_' . $n[1] . '_i = 0; $_' . $n[1] . '_i < $_' . $n[1] . '_count; $_' . $n[1] . '_i++)'; ! $code_lines[$i] .= "\n" . '{'; ! } ! else ! { ! // This block is nested. ! // Generate a namespace string for this block. ! $namespace = implode( '.', $block_names ); ! // strip leading period from root level.. ! $namespace = substr( $namespace, 2 ); ! // Get a reference to the data array for this block that depends on the ! // current indices of all parent blocks. ! $varref = $this->generate_block_data_ref( $namespace, false ); ! // Create the for loop code to iterate over this block. ! $code_lines[$i] = '$_' . $n[1] . '_count = ( isset(' . $varref . ') ) ? sizeof(' . $varref . ') : 0;'; ! $code_lines[$i] .= "\n" . 'for ($_' . $n[1] . '_i = 0; $_' . $n[1] . '_i < $_' . $n[1] . '_count; $_' . $n[1] . '_i++)'; ! $code_lines[$i] .= "\n" . '{'; ! } ! // We have the end of a block. ! unset( $block_names[$block_nesting_level] ); ! $block_nesting_level--; ! $code_lines[$i] .= '} // END ' . $n[1]; ! $m[0] = $n[0]; ! $m[1] = $n[1]; ! } ! else ! { ! // We have the start of a block. ! $block_nesting_level++; ! $block_names[$block_nesting_level] = $m[1]; ! if ( $block_nesting_level < 2 ) ! { ! // Block is not nested. ! $code_lines[$i] = '$_' . $m[1] . '_count = ( isset($this->_tpldata[\'' . $m[1] . '.\']) ) ? sizeof($this->_tpldata[\'' . $m[1] . '.\']) : 0;'; ! $code_lines[$i] .= "\n" . 'for ($_' . $m[1] . '_i = 0; $_' . $m[1] . '_i < $_' . $m[1] . '_count; $_' . $m[1] . '_i++)'; ! $code_lines[$i] .= "\n" . '{'; ! } ! else ! { ! // This block is nested. ! // Generate a namespace string for this block. ! $namespace = implode( '.', $block_names ); ! // strip leading period from root level.. ! $namespace = substr( $namespace, 2 ); ! // Get a reference to the data array for this block that depends on the ! // current indices of all parent blocks. ! $varref = $this->generate_block_data_ref( $namespace, false ); ! // Create the for loop code to iterate over this block. ! $code_lines[$i] = '$_' . $m[1] . '_count = ( isset(' . $varref . ') ) ? sizeof(' . $varref . ') : 0;'; ! $code_lines[$i] .= "\n" . 'for ($_' . $m[1] . '_i = 0; $_' . $m[1] . '_i < $_' . $m[1] . '_count; $_' . $m[1] . '_i++)'; ! $code_lines[$i] .= "\n" . '{'; ! } ! } ! } ! else if ( preg_match( '#<!-- END (.*?) -->#', $code_lines[$i], $m ) ) ! { ! // We have the end of a block. ! unset( $block_names[$block_nesting_level] ); ! $block_nesting_level--; ! $code_lines[$i] = '} // END ' . $m[1]; ! } ! else ! { ! // We have an ordinary line of code. ! if ( !$do_not_echo ) ! { ! $code_lines[$i] = 'echo \'' . $code_lines[$i] . '\' . "\\n";'; ! } ! else ! { ! $code_lines[$i] = '$' . $retvar . '.= \'' . $code_lines[$i] . '\' . "\\n";'; ! } ! } ! } ! // Bring it back into a single string of lines of code. ! $code = implode( "\n", $code_lines ); ! return $code ; ! } ! ! /** ! * Generates a reference to the given variable inside the given (possibly nested) ! * block namespace. This is a string of the form: ! * ' . $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['varname'] . ' ! * It's ready to be inserted into an "echo" line in one of the templates. ! * NOTE: expects a trailing "." on the namespace. ! */ ! function generate_block_varref( $namespace, $varname ) ! { ! // Strip the trailing period. ! $namespace = substr( $namespace, 0, strlen( $namespace ) - 1 ); ! // Get a reference to the data block for this namespace. ! $varref = $this->generate_block_data_ref( $namespace, true ); ! // Prepend the necessary code to stick this in an echo line. ! // Append the variable reference. ! $varref .= '[\'' . $varname . '\']'; ! ! $varref = '\' . ( ( isset(' . $varref . ') ) ? ' . $varref . ' : \'\' ) . \''; ! ! return $varref; ! } ! ! /** ! * Generates a reference to the array of data values for the given ! * (possibly nested) block namespace. This is a string of the form: ! * $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['$childN'] ! * ! * If $include_last_iterator is true, then [$_childN_i] will be appended to the form shown above. ! * NOTE: does not expect a trailing "." on the blockname. ! */ ! function generate_block_data_ref( $blockname, $include_last_iterator ) ! { ! // Get an array of the blocks involved. ! $blocks = explode( ".", $blockname ); ! $blockcount = sizeof( $blocks ) - 1; ! $varref = '$this->_tpldata'; ! // Build up the string with everything but the last child. ! for ( $i = 0; $i < $blockcount; $i++ ) ! { ! $varref .= '[\'' . $blocks[$i] . '.\'][$_' . $blocks[$i] . '_i]'; ! } ! // Add the block reference for the last child. ! $varref .= '[\'' . $blocks[$blockcount] . '.\']'; ! // Add the iterator for the last child if requried. ! if ( $include_last_iterator ) ! { ! $varref .= '[$_' . $blocks[$blockcount] . '_i]'; ! } ! ! return $varref; ! } ! } ?> \ No newline at end of file --- 118,122 ---- } ! } // class mx_Template ?> \ No newline at end of file --- NEW FILE: mx_cache.php --- <?php /** ------------------------------------------------------------------------ * subject : mx-portal, CMS & portal * begin : june, 2002 * copyright : (C) 2002-2005 MX-System * email : jon...@ho... * project site : www.mx-system.com * * description : * ------------------------------------------------------------------------- * * $Id: mx_cache.php,v 1.1 2005/05/26 21:54:08 jonohlsson Exp $ */ /** * 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ // -------------------------------------------------------------------------------- // Class: mx_cache // // // Following flags are options for the $type parameter in method _read() // define('MX_ALL_DATA' , -1); // Flag - write all data define('MX_BLOCK' , 0); // Block read mode define('MX_PAGE' , 1); // Page read mode define('MX_QUERY_DB' , true); // Flag - to force db query define('MX_CACHE_DEBUG' , false); // echo lots of debug info // // Additional notes: // // // This class IS instatiated in common.php ;-) // // Usage examples: // // The block and pages config data is either retrieved from its cache file od db queried (adminCP switch), or db query is forced using flag 'MX_QUERY_DB' // $block_config = $mx_cache->read( MX_BLOCK, $block_id, [MX_QUERY_DB] ); // Optional flag 'MX_QUERY_DB' to force db query // $page_config = $mx_cache->read( MX_PAGE, $page_id, [MX_QUERY_DB] ); // Optional flag 'MX_QUERY_DB' to force db query // $mx_cache->update( MX_ALL_DATA ); // Updates all cache // $mx_cache->update( MX_BLOCK, [$block_id] ); // Optional parameter $block_id to update only specific cache fle // $mx_cache->update( MX_PAGE, [$page_id] ); // Optional parameter $page_id to update only specific cache file class mx_cache { // ------------------------------ // Private Methods // // // Read cache function _read_config( $id, $sub_id, $type, $cache ) { global $portal_config, $mx_root_path; $cache_dir = $mx_root_path . 'cache/'; switch ( $type ) { case MX_BLOCK: $cache_file = $cache_dir . "block_" . $id . ".xml"; $block_config = ''; if ( file_exists( $cache_file ) && !empty($id) && $cache == true && $sub_id == 0 && $portal_config['mx_use_cache'] == 1 ) { if ( MX_CACHE_DEBUG ) { echo('using block cache'); } $block_config = $this->_cache2data( $id, $cache_file ); } else { if ( MX_CACHE_DEBUG ) { echo('using block db'); } $block_config = $this->_get_block_config( $id, $sub_id ); } return $block_config; break; case MX_PAGE: $cache_file = $cache_dir . "page_" . $id . ".xml"; $pages_config = ''; if ( file_exists( $cache_file ) && !empty($id) && $cache == true && $portal_config['mx_use_cache'] == 1 ) { if ( MX_CACHE_DEBUG ) { echo('using page cache'); } $pages_config = $this->_cache2data( $id, $cache_file ); } else { if ( MX_CACHE_DEBUG ) { echo('using page db'); } $pages_config = $this->_get_page_config( $id ); } return $pages_config; break; } } // Write cache function _write_config( $type, $id, $action ) { global $portal_config, $mx_root_path, $lang; $cache_dir = $mx_root_path . 'cache/'; @mkdir($cache_dir, 0777); @chmod($cache_dir, 0777); $cache_file = $cache_dir . ( $type == MX_BLOCK ? "block_" : "page_" ) . ( $action == 'single' ? $id . ".xml" : '' ); if ( !is_writable($cache_dir) ) { mx_message_die(GENERAL_MESSAGE, $lang['Cache_dir_write_protect'], ''); exit; } switch ( $type ) { case MX_BLOCK: switch ( $action ) { case 'all': if ( MX_CACHE_DEBUG ) { echo('writing all block cache'); } $block_config = $this->_get_block_config( '', 0 ); $this->_data2cache( $block_config, $cache_file, $action, $type ); break; case 'single': if ( MX_CACHE_DEBUG ) { echo('writing id block cache'); } $block_config = $this->_get_block_config( $id, 0 ); $this->_data2cache( $block_config[$id], $cache_file, $action, $type ); break; } break; case MX_PAGE: switch ( $action ) { case 'all': if ( MX_CACHE_DEBUG ) { echo('writing all page cache'); } $pages_config = $this->_get_page_config( ); $this->_data2cache( $pages_config, $cache_file, $action, $type ); break; case 'single': if ( MX_CACHE_DEBUG ) { echo('writing id page cache'); } $pages_config = $this->_get_page_config( $id ); $this->_data2cache( $pages_config, $cache_file, $action, $type ); break; } break; } } // -------------------------------------------------------------------WRITE CACHE // write cache from db query (or data) function _data2cache($data, $xml_file, $action, $type ) { global $db; switch ( $action ) { case 'all': if ( empty($data) || empty($xml_file) ) { return; } foreach ($data as $key => $value) { $OUTPUT = serialize($value); if ( $type == MX_PAGE ) { $fp = fopen($xml_file . $value['page_info']['page_id'] . $xml_file_type . ".xml","w"); // open file with Write permission } else { $fp = fopen($xml_file . $value['block_id'] . $xml_file_type . ".xml","w"); // open file with Write permission } fputs($fp, $OUTPUT); fclose($fp); } break; case 'single': if ( empty($data) || empty($xml_file) ) { return; } $OUTPUT = serialize($data); $fp = fopen($xml_file,"w"); // open file with Write permission fputs($fp, $OUTPUT); fclose($fp); break; } } // -------------------------------------------------------------------READ CACHE // read xml file to array function _cache2data( $id = '', $cache_file = '' ) { if ( empty($cache_file) ) { return; } $data = array(); if ( (@phpversion() < '4.3.0' ) ) { $data[$id] = unserialize(implode('',file($cache_file))); } else { $data[$id] = unserialize(file_get_contents($cache_file)); } return $data; } // -------------------------------------------------------------------GET DATA // Read the variable block configuration function _get_block_config( $id = '', $sub_id = 0 ) { global $db; $block_config = array(); // If this block doesn't have any parameters, we need this additional query :( $sql_block = !empty($id) ? " AND block_id = " . $id : ''; // Generate block parameter data $sql = "SELECT blk.*, mdl.module_path, fnc.function_file, fnc.function_admin FROM " . BLOCK_TABLE . " blk, " . FUNCTION_TABLE . " fnc, " . MODULE_TABLE . " mdl WHERE blk.function_id = fnc.function_id AND fnc.module_id = mdl.module_id"; $sql .= $sql_block; $sql .= " ORDER BY block_id"; if ( !( $result = $db->sql_query( $sql ) ) ) { mx_message_die( GENERAL_ERROR, 'Could not obtain block data information', '', __LINE__, __FILE__, $sql ); } while ( $row = $db->sql_fetchrow( $result ) ) { $block_row = array( "block_id" => $row['block_id'], "block_title" => $row['block_title'], "block_desc" => $row['block_desc'], "auth_view" => $row['auth_view'], "auth_view_group" => $row['auth_view_group'], "auth_edit" => $row['auth_edit'], "auth_edit_group" => $row['auth_edit_group'], // "auth_moderator_group" => $row['auth_moderator_group'], // "show_block" => $row['show_block'], // "show_title" => $row['show_title'], // "show_stats" => $row['show_stats'], // "block_time" => $row['block_time'], // "block_editor_id" => $row['block_editor_id'], "module_root_path" => $row['module_path'], "block_file" => $row['function_file'], "block_edit_file" => $row['function_admin'] ); $block_config[$row['block_id']] = $block_row; } $sql_block = !empty( $block_id ) ? " AND sys.block_id = " . $id : ''; // Generate block parameter data $sql = "SELECT blk.*, sys.parameter_id, par.parameter_name, sys.parameter_value, sys.bbcode_uid, mdl.module_path, fnc.function_file, fnc.function_admin FROM " . BLOCK_SYSTEM_PARAMETER_TABLE . " sys, " . PARAMETER_TABLE . " par, " . BLOCK_TABLE . " blk, " . FUNCTION_TABLE . " fnc, " . MODULE_TABLE . " mdl WHERE sys.parameter_id = par.parameter_id AND sys.block_id = blk.block_id AND blk.function_id = fnc.function_id AND fnc.module_id = mdl.module_id"; $sql .= $sql_block; $sql .= " ORDER BY sys.block_id, sys.parameter_id"; if ( !( $result = $db->sql_query( $sql ) ) ) { mx_message_die( GENERAL_ERROR, 'Could not obtain block data information', '', __LINE__, __FILE__, $sql ); } $block_id = 0; while ( $row = $db->sql_fetchrow( $result ) ) { $next_block = ( $block_id != $row['block_id'] ) ? true : false; $block_id = $row['block_id']; $block_row = array( "block_id" => $row['block_id'], "block_title" => $row['block_title'], "block_desc" => $row['block_desc'], "column_id" => $row['column_id'], "auth_view" => $row['auth_view'], "auth_view_group" => $row['auth_view_group'], "auth_edit" => $row['auth_edit'], "auth_edit_group" => $row['auth_edit_group'], // "auth_moderator_group" => $row['auth_moderator_group'], // "show_block" => $row['show_block'], // "show_title" => $row['show_title'], // "show_stats" => $row['show_stats'], // "block_time" => $row['block_time'], // "block_editor_id" => $row['block_editor_id'], "module_root_path" => $row['module_path'], "block_file" => $row['function_file'], "block_edit_file" => $row['function_admin'] ); $param_row = array( "parameter_id" => $row['parameter_id'], "parameter_name" => $row['parameter_name'], "parameter_value" => $row['parameter_value'], "bbcode_uid" => $row['bbcode_uid'] ); if ( $next_block ) { $block_config[$block_id] = $block_row; } $block_config[$block_id][$param_row['parameter_name']] = $param_row; } return $block_config; } function _get_page_config( $id = '' ) { global $db, $HTTP_SESSION_VARS; $sql_page = !empty($id) ? " AND col.page_id = '" . $id . "'" : ""; // Get page_blocks data $sql = "SELECT col.page_id, pag.page_name, pag.page_icon, pag.page_header, pag.auth_view AS pag_auth_view, pag.auth_view_group AS pag_auth_view_group, bct.column_id, col.column_title, col.column_order, col.column_size, blk.block_id, mdl.module_path, fnc.function_file, fnc.function_admin FROM " . COLUMN_BLOCK_TABLE . " bct, " . BLOCK_TABLE . " blk, " . FUNCTION_TABLE . " fnc, " . MODULE_TABLE . " mdl, " . PAGE_TABLE . " pag, " . COLUMN_TABLE . " col WHERE blk.function_id = fnc.function_id AND pag.page_id = col.page_id AND blk.block_id = bct.block_id AND fnc.module_id = mdl.module_id AND bct.column_id = col.column_id "; $sql .= $sql_page; $sql .= " ORDER BY col.page_id, column_id, column_order, block_order"; if ( !$result = $db->sql_query( $sql ) ) { mx_message_die( GENERAL_ERROR, "Could not query page information", "", __LINE__, __FILE__, $sql ); } $pages_config = array(); $page_id = 0; while ( $row = $db->sql_fetchrow( $result ) ) { $next_page = ( $page_id != $row['page_id'] ) ? true : false; $next_column = ( $column_id != $row['column_id'] ) ? true : false; $page_id = $row['page_id']; $column_id = $row['column_id']; $page_row = array( "page_id" => $row['page_id'], "page_name" => $row['page_name'], "page_icon" => $row['page_icon'], "page_header" => $row['page_header'], "page_auth_view" => $row['pag_auth_view'], "page_auth_view_group" => $row['pag_auth_view_group'] ); $column_row = array( "column_id" => $row['column_id'], "column_title" => $row['column_title'], "column_order" => $row['column_order'], "column_size" => $row['column_size'] ); $block_row = array( "block_id" => $row['block_id'], "column_id" => $row['column_id'], "module_root_path" => $row['module_path'], "function_file" => $row['function_file'], "function_admin" => $row['function_admin'] ); if ( $next_page ) { $temp_row = array(); $temp_row = array( 'page_info' => $page_row ); } if ( $next_column ) { $temp_row['columns'][] = $column_row; } $temp_row['blocks'][] = $block_row; // Compose the pages config array $pages_config[$page_id] = $temp_row; }; return $pages_config; } function _update_cache( ) { global $db, $HTTP_SESSION_VARS, $mx_root_path, $phpbb_root_path, $phpEx, $mx_use_cache, $portal_config; // $portal_cache_time = time(); // $sql = "UPDATE ".PORTAL_TABLE." // SET portal_recached = '$portal_cache_time' // WHERE portal_id = 1"; // if ( !( $result = $db->sql_query( $sql, BEGIN_TRANSACTION ) ) ) // { // mx_message_die( GENERAL_ERROR, "Could not update portal cache time.", "", __LINE__, __FILE__, $sql ); // } } // ------------------------------ // Public Methods // // $block_config = $mx_cache->read( MX_BLOCK, $block_id, [MX_QUERY_DB] ); // Optional flag 'MX_QUERY_DB' to force db query // $page_config = $mx_cache->read( MX_PAGE, $page_id, [MX_QUERY_DB] ); // Optional flag 'MX_QUERY_DB' to force db query // $mx_cache->update( MX_ALL_DATA ); // Updates all cache // $mx_cache->update( MX_BLOCK, [$block_id] ); // Optional parameter $block_id to update only specific cache fle // $mx_cache->update( MX_PAGE, [$page_id] ); // Optional parameter $page_id to update only specific cache file function read( $id = '', $type = MX_BLOCK, $force_query = false ) { if ( is_array( $id ) ) { $id = $id['id']; $sub_id = $id['sub_id']; } else { $sub_id = 0; } if ( $id > 0 ) { return $this->_read_config( $id, $sub_id, $type, !$force_query ); } else { die('invalid cache read call - no id'); } } // TYPE: MX_ALL_DATA, MX_PAGE, MX_BLOCK function update( $type = MX_ALL_DATA, $id = '' ) { if ( $type == MX_ALL_DATA || empty($id) ) { $this->_write_config( MX_BLOCK, '', 'all' ); $this->_write_config( MX_PAGE, '', 'all' ); } else if ( $id > 0 ) { $this->_write_config( $type, $id, 'single' ); } else { die('invalid cache write call - no id'); } $this->_update_cache( ); } } // class mx_cache // -------------------------------------------------------------------------------- // Class: mx_block // // // Usage examples: // class mx_block { // // Implementation Conventions: // Properties and methods prefixed with underscore are intented to be private. ;-) // // ------------------------------ // Vars // var $block_config = array(); var $block_id = ''; var $block_title = ''; var $block_desc = ''; // var $show_block = true; var $show_title = true; // var $show_stats = true; var $auth_view = ''; var $auth_view_group = ''; var $auth_edit = ''; var $auth_edit_group = ''; // var $block_time = ''; // var $editor_id = ''; var $module_root_path = ''; var $block_file = ''; var $block_edit_file = ''; // var $dynamic_block_id = ''; // var $is_dynamic = false; // var $total_subs = ''; // var $sub_block_ids = ''; // var $sub_block_sizes = ''; // var $sub_inner_space = ''; // var $is_sub = false; // ------------------------------ // Properties // // none in this class. // ------------------------------ // Constructor // // ------------------------------ // Private Methods // function _set_all( $block_id, $unset = false ) { global $userdata; $this->block_id = $this->block_config[$block_id]['block_id']; $this->block_title = $this->block_config[$block_id]['block_title']; $this->block_desc = $this->block_config[$block_id]['block_desc']; // $this->show_block = $this->block_config[$block_id]['show_block'] == '1'; // $this->show_title = $this->block_config[$block_id]['show_title'] == '1'; // $this->show_stats = $this->block_config[$block_id]['show_stats'] == '1'; $mx_is_auth_ary = array(); $mx_is_auth_ary = block_auth( AUTH_VIEW, $block_id, $userdata, $this->block_config[$block_id]['auth_view'], $this->block_config[$block_id]['auth_view_group'] ); $this->auth_view = $unset ? false : $mx_is_auth_ary['auth_view']; $mx_is_auth_ary = array(); $mx_is_auth_ary = block_auth( AUTH_EDIT, $block_id, $userdata, $this->block_config[$block_id]['auth_edit'], $this->block_config[$block_id]['auth_edit_group'] ); $this->auth_edit = $unset ? false : $mx_is_auth_ary['auth_edit']; $this->auth_mod = $unset ? false : $mx_is_auth_ary['auth_mod']; // $this->block_time = $this->block_config[$block_id]['block_time']; // $this->editor_id = $this->block_config[$block_id]['block_editor_id']; $this->module_root_path = $this->block_config[$block_id]['module_root_path']; $this->block_file = $this->block_config[$block_id]['block_file']; $this->block_edit_file = $this->block_config[$block_id]['block_edit_file']; // $this->is_dynamic = $unset ? false : $this->_is_dynamic( $block_id ); // $this->is_sub = $unset ? false : $this->_is_sub( $block_id ); } // ------------------------------ // Public Methods // function init( $block_id ) { global $mx_cache; $this->block_config = $mx_cache->read( $block_id, MX_BLOCK ); $this->_set_all( $block_id ); } } // class mx_block // -------------------------------------------------------------------------------- // Class: mx_block // // // Usage examples: // class mx_page { // // Implementation Conventions: // Properties and methods prefixed with underscore are intented to be private. ;-) // // ------------------------------ // Vars // var $page_config = array(); var $info = array(); var $columns = array(); var $blocks = array(); var $total_column = ''; var $total_block = ''; var $auth_view = ''; var $auth_view_group = ''; // ------------------------------ // Properties // // none in this class. // ------------------------------ // Constructor // // ------------------------------ // Private Methods // function _set_all( $page_id ) { global $userdata, $mx_root_path, $HTTP_GET_VARS; $this->info = $this->page_config[$page_id]['page_info']; $mx_is_auth_ary = array(); $mx_is_auth_ary = page_auth( AUTH_VIEW, $userdata, $this->info['page_auth_view'], $this->info['page_auth_view_group'] ); $this->auth_view = $mx_is_auth_ary['auth_view']; $this->columns = $this->page_config[$page_id]['columns']; $this->total_column = count($this->columns); $this->blocks = $this->page_config[$page_id]['blocks']; $this->total_block = count($this->blocks); } // ------------------------------ // Public Methods // function init( $page_id ) { global $mx_cache; $this->page_config = $mx_cache->read( $page_id, MX_PAGE ); $this->_set_all( $page_id ); } function drop( $page_id ) { global $mx_cache; $this->page_config = ''; } } // class mx_page // // ------------------------------------------------------------------------------------------------------------- // For compatibility with old block calls // function read_block_config( $block_id, $cache = true ) { global $mx_cache, $mx_block, $mx_split_block, $block_config; if ( !empty( $mx_block->block_config[$block_id] )) { return $mx_block->block_config; } if ( !empty( $mx_split_block->block_config[$block_id] ) ) { return $mx_split_block->block_config; } return $mx_cache->read( $block_id, MX_BLOCK, !$cache ); } function update_session_cache( $block_id = '' ) { global $mx_cache; $mx_cache->update( MX_BLOCK, $block_id ); } ?> Index: mx_constants.php =================================================================== RCS file: /cvsroot/mxbb/core27x/includes/mx_constants.php,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** mx_constants.php 6 May 2005 06:47:58 -0000 1.1 --- mx_constants.php 26 May 2005 21:54:08 -0000 1.2 *************** *** 29,33 **** define('PAGE_FORUM' , -20); define('PAGE_ADS' , -21); - define('PAGE_CALENDAR' , -22); define('PAGE_WELCOME' , -23); define('PAGE_LAST_MSG' , -24); --- 29,32 ---- *************** *** 35,43 **** define('PAGE_POLL' , -26); define('PAGE_URL' , -27); - define('PAGE_WEATHER' , -28); define('PAGE_NEWS' , -37); define('PAGE_MENU_NAV' , -29); - define('PAGE_ADS_POST' , -30); - define('PAGE_ALBUM' , -39); define('PAGE_MENU_ADMIN', -31); --- 34,39 ---- *************** *** 47,51 **** define('PAGE_ADS_ADMIN' , -35); define('PAGE_ANNOUNCEMENT', -36); - define('PAGE_WEATHER_EDIT', -38); define('PAGE_ANNOUNCEMENT_ADMIN' , -35); --- 43,46 ---- *************** *** 54,66 **** - define('ADS_TABLE', $mx_table_prefix.'block_ads'); - define('WELCOME_TABLE', $mx_table_prefix.'welcome_msg'); - define('WEB_LINKS_TABLE', $mx_table_prefix.'links'); define('PORTAL_TABLE', $mx_table_prefix.'portal'); - define('WEATHER_TABLE', $mx_table_prefix.'weather'); define('MENU_NAV_TABLE', $mx_table_prefix.'menu_nav'); define('MENU_CAT_TABLE', $mx_table_prefix.'menu_categories'); - define('CALENDAR_TABLE', $mx_table_prefix.'calendar'); - define('CALENDAR_CAT_TABLE', $mx_table_prefix.'calendar_categories'); define('MODULE_TABLE', $mx_table_prefix.'module'); --- 49,55 ---- *************** *** 77,90 **** define('BLOCK_USER_PARAMETER_TABLE', $mx_table_prefix.'block_user_parameter'); - - define('CONFIG_WEATHER_TABLE', $mx_table_prefix.'config_weather'); - define('CONFIG_WEATHER_DET_TABLE', $mx_table_prefix.'config_weather_det'); - - - define('DOWNLOAD_LICENSE_TABLE' , $mx_table_prefix.'download_license'); - define('DOWNLOAD_CATEGORIES_TABLE', $mx_table_prefix.'download_cat'); - define('DOWNLOAD_FILES_TABLE' , $mx_table_prefix.'download_files'); - define('DOWNLOAD_VOTES_TABLE' , $mx_table_prefix.'download_votes'); - define('AUTH_ANONYMOUS', 99); --- 66,69 ---- --- NEW FILE: mx_functions_phpbb.php --- <?php /** ------------------------------------------------------------------------ * subject : mx-portal, CMS & portal * begin : june, 2002 * copyright : (C) 2002-2005 MX-System * email : jon...@ho... * project site : www.mx-system.com * * description : * ------------------------------------------------------------------------- * * $Id: mx_functions_phpbb.php,v 1.1 2005/05/26 21:54:08 jonohlsson Exp $ */ /** * 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 * the Free Software Foundation; either version 2 of the License', or * ('at your option) any later version. */ /** * Included functions in this file: (validated for phpbb 2.0.10) * - mx_smilies_pass (from bbcode.php) * - mx_generate_smilies (from functions_post.php) * - mx_decode * - mx_init_userprefs (from functions.php) * - mx_setup_style (from functions.php) * - mx_message_die (from functions.php) * - mx_block_message (a message_die kind of function for blocks) * - mx_redirect (from functions.php) * - mx_generate_pagination (from functions.php) */ // // Hacking smilies_pass from phpbb/includes/bbcode.php // function mx_smilies_pass($message) { global $board_config; $smilies_path = $board_config['smilies_path']; $board_config['smilies_path'] = PHPBB_URL . $board_config['smilies_path']; $message = smilies_pass($message); $board_config['smilies_path'] = $smilies_path; return $message; } // // Hacking generate_smilies from phpbb/includes/functions_post.php // function mx_generate_smilies($mode, $page_id) { global $board_config, $template, $phpEx; $smilies_path = $board_config['smilies_path']; $board_config['smilies_path'] = PHPBB_URL . $board_config['smilies_path']; generate_smilies($mode, $page_id); $board_config['smilies_path'] = $smilies_path; $template->assign_vars(array( 'U_MORE_SMILIES' => append_sid(PHPBB_URL . "posting.$phpEx?mode=smilies")) ); } // // Convert the bbcode to html // function mx_decode($bbtext, $bbcode_uid) { $mytext = stripslashes($bbtext); $mytext = bbencode_second_pass($mytext, $bbcode_uid); $mytext = mx_smilies_pass($mytext); $mytext = str_replace("\n", "\n<br />\n", $mytext); $mytext = make_clickable($mytext); return $mytext; } // // Initialise user settings on page load function mx_init_userprefs($userdata) { global $board_config, $theme, $images; global $template, $lang, $phpEx, $phpbb_root_path, $mx_root_path; global $nav_links; if ( $userdata['user_id'] != ANONYMOUS ) { if ( !empty($userdata['user_lang'])) { $board_config['default_lang'] = $userdata['user_lang']; } if ( !empty($userdata['user_dateformat']) ) { $board_config['default_dateformat'] = $userdata['user_dateformat']; } if ( isset($userdata['user_timezone']) ) { $board_config['board_timezone'] = $userdata['user_timezone']; } } if ( !file_exists($mx_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.' . $phpEx) ) { $board_config['default_lang'] = 'english'; } if ( file_exists($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.' . $phpEx) ) { include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.' . $phpEx); } if ( file_exists($mx_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.' . $phpEx) ) { include($mx_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.' . $phpEx); } if ( defined('IN_ADMIN') ) { if( !file_exists($mx_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_admin.' . $phpEx) || !file_exists($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_admin.' . $phpEx) ) { $board_config['default_lang'] = 'english'; } include($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_admin.' . $phpEx); include($mx_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_admin.' . $phpEx); } // // Set up style // if ( !$board_config['override_user_style'] ) { if ( $userdata['user_id'] != ANONYMOUS && $userdata['user_style'] > 0 ) { if ( $theme = mx_setup_style($userdata['user_style']) ) { return; } } } $theme = mx_setup_style($board_config['default_style']); // // Mozilla navigation bar // Default items that should be valid on all pages. // Defined here to correctly assign the Language Variables // and be able to change the variables within code. // $nav_links['top'] = array ( 'url' => append_sid($phpbb_root_path . 'index.' . $phpEx), 'title' => sprintf($lang['Forum_Index'], $board_config['sitename']) ); $nav_links['search'] = array ( 'url' => append_sid($phpbb_root_path . 'search.' . $phpEx), 'title' => $lang['Search'] ); $nav_links['help'] = array ( 'url' => append_sid($phpbb_root_path . 'faq.' . $phpEx), 'title' => $lang['FAQ'] ); $nav_links['author'] = array ( 'url' => append_sid($phpbb_root_path . 'memberlist.' . $phpEx), 'title' => $lang['Memberlist'] ); return; } function mx_setup_style($style, $only_template = false) { global $db, $board_config, $template, $images, $phpbb_root_path, $mx_root_path; $sql = "SELECT * FROM " . THEMES_TABLE . " WHERE themes_id = $style"; if ( !($result = $db->sql_query($sql)) ) { $style = 1; $sql = "SELECT * FROM " . THEMES_TABLE . " WHERE themes_id = $style"; if ( !($result = $db->sql_query($sql)) ) { mx_message_die(CRITICAL_ERROR, 'Could not query database for theme info'); } } if ( !($row = $db->sql_fetchrow($result)) ) { mx_message_die(CRITICAL_ERROR, "Could not get theme data for themes_id [$style]"); } $template_path = 'templates/' ; $template_name = $row['template_name'] ; // MX FIX for uninstalled themes ... use subSilver instead if ( !file_exists($mx_root_path . $template_path . $template_name . '/mx_login.tpl') ) { $template_path = 'templates/'; $template_name = 'subSilver'; $style = 1; $sql = "SELECT * FROM " . THEMES_TABLE . " WHERE themes_id = $style"; if ( !($result = $db->sql_query($sql)) ) { mx_message_die(CRITICAL_ERROR, 'Could not query database for theme info'); } if ( !($row = $db->sql_fetchrow($result)) ) { mx_message_die(CRITICAL_ERROR, "Could not get theme data for themes_id [$style]"); } $template = new mx_Template($mx_root_path . $template_path . $template_name); } else { $template = new mx_Template($mx_root_path . $template_path . $template_name); } if ( $only_template ) { return $row; } // // call when only_template is false. // define('TEMPLATE_ROOT_PATH', $template_path . $template_name . '/'); if ( $template ) { $current_template_path = $template_path . $template_name; @include($phpbb_root_path . $template_path . $template_name . '/' . $template_name . '.cfg'); if ( !defined('TEMPLATE_CONFIG') ) { mx_message_die(CRITICAL_ERROR, "Could not open $template_name template config file", '', __LINE__, __FILE__); } $img_lang = ( file_exists($phpbb_root_path . $current_template_path . '/images/lang_' . $board_config['default_lang']) ) ? $board_config['default_lang'] : 'english'; while( list($key, $value) = @each($images) ) { if ( !is_array($value) ) { $images[$key] = str_replace('{LANG}', 'lang_' . $img_lang, $value); } } } return $row; } // // This is general replacement for die(), allows templated // output in users (or default) language, etc. // // $msg_code can be one of these constants: // // GENERAL_MESSAGE : Use for any simple text message, eg. results // of an operation, authorisation failures, etc. // // GENERAL ERROR : Use for any error which occurs _AFTER_ the // common.php include and session code, ie. most errors in // pages/functions // // CRITICAL_MESSAGE : Used when basic config data is available but // a session may not exist, eg. banned users // // CRITICAL_ERROR : Used when config da... [truncated message content] |